{
  "canonical_name": "RNBBarrett/thought-mcp",
  "compilation_id": "pack_1fc189c9a0084c36a5a819341e0a7e18",
  "created_at": "2026-05-24T13:35:16.960197+00:00",
  "created_by": "project-pack-compiler",
  "feedback": {
    "carrier_selection_notes": [
      "viable_asset_types=mcp_config, recipe, host_instruction, eval, preflight",
      "recommended_asset_types=mcp_config, recipe, host_instruction, eval, preflight"
    ],
    "evidence_delta": {
      "confirmed_claims": [
        "identity_anchor_present",
        "capability_and_host_targets_present",
        "install_path_declared_or_better"
      ],
      "missing_required_fields": [],
      "must_verify_forwarded": [
        "Run or inspect `pip install thought-mcp` in an isolated environment.",
        "Confirm the project exposes the claimed capability to at least one target host."
      ],
      "quickstart_execution_scope": "allowlisted_sandbox_smoke",
      "sandbox_command": "pip install thought-mcp",
      "sandbox_container_image": "python:3.12-slim",
      "sandbox_execution_backend": "docker",
      "sandbox_planner_decision": "deterministic_isolated_install",
      "sandbox_validation_id": "sbx_bec078e506444e22b79f089a57d1df63"
    },
    "feedback_event_type": "project_pack_compilation_feedback",
    "learning_candidate_reasons": [],
    "template_gaps": []
  },
  "identity": {
    "canonical_id": "project_b46554c512d7b03b1abcdaf45a206ccb",
    "canonical_name": "RNBBarrett/thought-mcp",
    "homepage_url": null,
    "license": "unknown",
    "repo_url": "https://github.com/RNBBarrett/thought-mcp",
    "slug": "thought-mcp",
    "source_packet_id": "phit_221d051f07004b45a19002f6c360c9ac",
    "source_validation_id": "dval_1115cfafb5dd48f8842d7e45e3fc9b07"
  },
  "merchandising": {
    "best_for": "需要工具连接与集成能力，并使用 mcp_host的用户",
    "github_forks": 0,
    "github_stars": 0,
    "one_liner_en": "Local MCP memory server for LLMs. Bi-temporal graph + vector + Cypher queries + auto-write/auto-recall hooks for Claude Code. Works with Ollama, LM Studio, Anthropic, OpenAI.",
    "one_liner_zh": "Local MCP memory server for LLMs. Bi-temporal graph + vector + Cypher queries + auto-write/auto-recall hooks for Claude Code. Works with Ollama, LM Studio, Anthropic, OpenAI.",
    "primary_category": {
      "category_id": "tool-integrations",
      "confidence": "high",
      "name_en": "Tool Integrations",
      "name_zh": "工具连接与集成",
      "reason": "matched_keywords:mcp, server, github"
    },
    "target_user": "使用 mcp_host, claude, claude_code 等宿主 AI 的用户",
    "title_en": "thought-mcp",
    "title_zh": "thought-mcp 能力包",
    "visible_tags": [
      {
        "label_en": "Security & Permissions",
        "label_zh": "安全审查与权限治理",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "product_domain-security-permissions",
        "type": "product_domain"
      },
      {
        "label_en": "Knowledge Base Q&A",
        "label_zh": "知识库问答",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "user_job-knowledge-base-q-a",
        "type": "user_job"
      },
      {
        "label_en": "Workflow Automation",
        "label_zh": "流程自动化",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "core_capability-workflow-automation",
        "type": "core_capability"
      },
      {
        "label_en": "Checkpoint Resume",
        "label_zh": "断点恢复流程",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "workflow_pattern-checkpoint-resume",
        "type": "workflow_pattern"
      },
      {
        "label_en": "Evaluation Suite",
        "label_zh": "评测体系",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "selection_signal-evaluation-suite",
        "type": "selection_signal"
      }
    ]
  },
  "packet_id": "phit_221d051f07004b45a19002f6c360c9ac",
  "page_model": {
    "artifacts": {
      "artifact_slug": "thought-mcp",
      "files": [
        "PROJECT_PACK.json",
        "QUICK_START.md",
        "PROMPT_PREVIEW.md",
        "HUMAN_MANUAL.md",
        "AI_CONTEXT_PACK.md",
        "BOUNDARY_RISK_CARD.md",
        "PITFALL_LOG.md",
        "REPO_INSPECTION.json",
        "REPO_INSPECTION.md",
        "CAPABILITY_CONTRACT.json",
        "EVIDENCE_INDEX.json",
        "CLAIM_GRAPH.json"
      ],
      "required_files": [
        "PROJECT_PACK.json",
        "QUICK_START.md",
        "PROMPT_PREVIEW.md",
        "HUMAN_MANUAL.md",
        "AI_CONTEXT_PACK.md",
        "BOUNDARY_RISK_CARD.md",
        "PITFALL_LOG.md",
        "REPO_INSPECTION.json"
      ]
    },
    "detail": {
      "capability_source": "Project Hit Packet + DownstreamValidationResult",
      "commands": [
        {
          "command": "pip install thought-mcp",
          "label": "Python / pip · 官方安装入口",
          "source": "https://github.com/RNBBarrett/thought-mcp#readme",
          "verified": true
        }
      ],
      "display_tags": [
        "安全审查与权限治理",
        "知识库问答",
        "流程自动化",
        "断点恢复流程",
        "评测体系"
      ],
      "eyebrow": "工具连接与集成",
      "glance": [
        {
          "body": "判断自己是不是目标用户。",
          "label": "最适合谁",
          "value": "需要工具连接与集成能力，并使用 mcp_host的用户"
        },
        {
          "body": "先理解能力边界，再决定是否继续。",
          "label": "核心价值",
          "value": "Local MCP memory server for LLMs. Bi-temporal graph + vector + Cypher queries + auto-write/auto-recall hooks for Claude Code. Works with Ollama, LM Studio, Anthropic, OpenAI."
        },
        {
          "body": "未完成验证前保持审慎。",
          "label": "继续前",
          "value": "publish to Doramagic.ai project surfaces"
        }
      ],
      "guardrail_source": "Boundary & Risk Card",
      "guardrails": [
        {
          "body": "Prompt Preview 只展示流程，不证明项目已安装或运行。",
          "label": "Check 1",
          "value": "不要把试用当真实运行"
        },
        {
          "body": "mcp_host, claude, claude_code, chatgpt",
          "label": "Check 2",
          "value": "确认宿主兼容"
        },
        {
          "body": "publish to Doramagic.ai project surfaces",
          "label": "Check 3",
          "value": "先隔离验证"
        }
      ],
      "mode": "mcp_config, recipe, host_instruction, eval, preflight",
      "pitfall_log": {
        "items": [
          {
            "body": "项目面向 Claude/Cursor/Codex/Gemini/OpenCode 等宿主，或安装命令涉及用户配置目录。",
            "category": "配置坑",
            "evidence": [
              "capability.host_targets | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | host_targets=mcp_host, claude, claude_code, chatgpt"
            ],
            "severity": "medium",
            "suggested_check": "列出会写入的配置文件、目录和卸载/回滚步骤。",
            "title": "可能修改宿主 AI 配置",
            "user_impact": "安装可能改变本机 AI 工具行为，用户需要知道写入位置和回滚方法。"
          },
          {
            "body": "README/documentation is current enough for a first validation pass.",
            "category": "能力坑",
            "evidence": [
              "capability.assumptions | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | README/documentation is current enough for a first validation pass."
            ],
            "severity": "medium",
            "suggested_check": "将假设转成下游验证清单。",
            "title": "能力判断依赖假设",
            "user_impact": "假设不成立时，用户拿不到承诺的能力。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.2.1 — thought upgrade + mcp-extras fix",
            "category": "维护坑",
            "evidence": [
              "community_evidence:github | cevd_dc6434cd71064812ae14d01e7f5d9ef0 | https://github.com/RNBBarrett/thought-mcp/releases/tag/v0.2.1 | 来源类型 github_release 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v0.2.1 — thought upgrade + mcp-extras fix",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "未记录 last_activity_observed。",
            "category": "维护坑",
            "evidence": [
              "evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | last_activity_observed missing"
            ],
            "severity": "medium",
            "suggested_check": "补 GitHub 最近 commit、release、issue/PR 响应信号。",
            "title": "维护活跃度未知",
            "user_impact": "新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。"
          },
          {
            "body": "no_demo",
            "category": "安全/权限坑",
            "evidence": [
              "downstream_validation.risk_items | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | no_demo; severity=medium"
            ],
            "severity": "medium",
            "suggested_check": "进入安全/权限治理复核队列。",
            "title": "下游验证发现风险项",
            "user_impact": "下游已经要求复核，不能在页面中弱化。"
          },
          {
            "body": "no_demo",
            "category": "安全/权限坑",
            "evidence": [
              "risks.scoring_risks | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | no_demo; severity=medium"
            ],
            "severity": "medium",
            "suggested_check": "把风险写入边界卡，并确认是否需要人工复核。",
            "title": "存在评分风险",
            "user_impact": "风险会影响是否适合普通用户安装。"
          },
          {
            "body": "issue_or_pr_quality=unknown。",
            "category": "维护坑",
            "evidence": [
              "evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | issue_or_pr_quality=unknown"
            ],
            "severity": "low",
            "suggested_check": "抽样最近 issue/PR，判断是否长期无人处理。",
            "title": "issue/PR 响应质量未知",
            "user_impact": "用户无法判断遇到问题后是否有人维护。"
          },
          {
            "body": "release_recency=unknown。",
            "category": "维护坑",
            "evidence": [
              "evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | release_recency=unknown"
            ],
            "severity": "low",
            "suggested_check": "确认最近 release/tag 和 README 安装命令是否一致。",
            "title": "发布节奏不明确",
            "user_impact": "安装命令和文档可能落后于代码，用户踩坑概率升高。"
          }
        ],
        "source": "ProjectPitfallLog + ProjectHitPacket + validation + community signals",
        "summary": "发现 8 个潜在踩坑项，其中 0 个为 high/blocking；最高优先级：配置坑 - 可能修改宿主 AI 配置。",
        "title": "踩坑日志"
      },
      "snapshot": {
        "contributors": 1,
        "forks": 0,
        "license": "unknown",
        "note": "站点快照，非实时质量证明；用于开工前背景判断。",
        "stars": 0
      },
      "source_url": "https://github.com/RNBBarrett/thought-mcp",
      "steps": [
        {
          "body": "不安装项目，先体验能力节奏。",
          "code": "preview",
          "title": "先试 Prompt"
        },
        {
          "body": "理解输入、输出、失败模式和边界。",
          "code": "manual",
          "title": "读说明书"
        },
        {
          "body": "把上下文交给宿主 AI 继续工作。",
          "code": "context",
          "title": "带给 AI"
        },
        {
          "body": "进入主力环境前先完成安装入口与风险边界验证。",
          "code": "verify",
          "title": "沙箱验证"
        }
      ],
      "subtitle": "Local MCP memory server for LLMs. Bi-temporal graph + vector + Cypher queries + auto-write/auto-recall hooks for Claude Code. Works with Ollama, LM Studio, Anthropic, OpenAI.",
      "title": "thought-mcp 能力包",
      "trial_prompt": "# thought-mcp - Prompt Preview\n\n> Copy the prompt below into your AI host before installing anything.\n> Its purpose is to let you safely feel the project's workflow, not to claim the project has already run.\n\n## Copy this prompt\n\n```text\nYou are using an independent Doramagic capability pack for RNBBarrett/thought-mcp.\n\nProject:\n- Name: thought-mcp\n- Repository: https://github.com/RNBBarrett/thought-mcp\n- Summary: Local MCP memory server for LLMs. Bi-temporal graph + vector + Cypher queries + auto-write/auto-recall hooks for Claude Code. Works with Ollama, LM Studio, Anthropic, OpenAI.\n- Host target: mcp_host, claude, claude_code, chatgpt\n\nGoal:\nHelp me evaluate this project for the following task without installing it yet: Local MCP memory server for LLMs. Bi-temporal graph + vector + Cypher queries + auto-write/auto-recall hooks for Claude Code. Works with Ollama, LM Studio, Anthropic, OpenAI.\n\nBefore taking action:\n1. Restate my task, success standard, and boundary.\n2. Identify whether the next step requires tools, browser access, network access, filesystem access, credentials, package installation, or host configuration.\n3. Use only the Doramagic Project Pack, the upstream repository, and the source-linked evidence listed below.\n4. If a real command, install step, API call, file write, or host integration is required, mark it as \"requires post-install verification\" and ask for approval first.\n5. If evidence is missing, say \"evidence is missing\" instead of filling the gap.\n\nPreviewable capabilities:\n- Capability 1: Local MCP memory server for LLMs. Bi-temporal graph + vector + Cypher queries + auto-write/auto-recall hooks for Claude Code. Works with Ollama, LM Studio, Anthropic, OpenAI.\n\nCapabilities that require post-install verification:\n- Capability 1: Use the source-backed project context to guide one small, checkable workflow step.\n\nCore service flow:\n1. page-introduction: Introduction to THOUGHT. Produce one small intermediate artifact and wait for confirmation.\n2. page-quickstart: Quickstart Guide. Produce one small intermediate artifact and wait for confirmation.\n3. page-installation: Installation and Setup. Produce one small intermediate artifact and wait for confirmation.\n4. page-architecture: System Architecture. Produce one small intermediate artifact and wait for confirmation.\n5. page-storage-layer: Storage and Database Layer. Produce one small intermediate artifact and wait for confirmation.\n\nSource-backed evidence to keep in mind:\n- https://github.com/RNBBarrett/thought-mcp\n- https://github.com/RNBBarrett/thought-mcp#readme\n- README.md\n- docs/comparison.md\n- src/thought/models.py\n- src/thought/demo.py\n- src/thought/cli.py\n- pyproject.toml\n- src/thought/config.py\n- Dockerfile\n\nFirst response rules:\n1. Start Step 1 only.\n2. Explain the one service action you will perform first.\n3. Ask exactly three questions about my target workflow, success standard, and sandbox boundary.\n4. Stop and wait for my answers.\n\nStep 1 follow-up protocol:\n- After I answer the first three questions, stay in Step 1.\n- Produce six parts only: clarified task, success standard, boundary conditions, two or three options, tradeoffs for each option, and one recommendation.\n- End by asking whether I confirm the recommendation.\n- Do not move to Step 2 until I explicitly confirm.\n\nConversation rules:\n- Advance one step at a time and wait for confirmation after each small artifact.\n- Write outputs as recommendations or planned checks, not as completed execution.\n- Do not claim tests passed, files changed, commands ran, APIs were called, or the project was installed.\n- If the user asks for execution, first provide the sandbox setup, expected output, rollback, and approval checkpoint.\n```\n",
      "voices": [
        {
          "body": "来源平台：github。github/github_release: v0.2.2 — MCP stdio transport fix（https://github.com/RNBBarrett/thought-mcp/releases/tag/v0.2.2）；github/github_release: v0.2.1 — thought upgrade + mcp-extras fix（https://github.com/RNBBarrett/thought-mcp/releases/tag/v0.2.1）。这些是项目级外部声音，不作为单独质量证明。",
          "items": [
            {
              "kind": "github_release",
              "source": "github",
              "title": "v0.2.2 — MCP stdio transport fix",
              "url": "https://github.com/RNBBarrett/thought-mcp/releases/tag/v0.2.2"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v0.2.1 — thought upgrade + mcp-extras fix",
              "url": "https://github.com/RNBBarrett/thought-mcp/releases/tag/v0.2.1"
            }
          ],
          "status": "已收录 2 条来源",
          "title": "社区讨论"
        }
      ]
    },
    "homepage_card": {
      "category": "工具连接与集成",
      "desc": "Local MCP memory server for LLMs. Bi-temporal graph + vector + Cypher queries + auto-write/auto-recall hooks for Claude Code. Works with Ollama, LM Studio, Anthropic, OpenAI.",
      "effort": "安装已验证",
      "forks": 0,
      "icon": "link",
      "name": "thought-mcp 能力包",
      "risk": "需复核",
      "slug": "thought-mcp",
      "stars": 0,
      "tags": [
        "安全审查与权限治理",
        "知识库问答",
        "流程自动化",
        "断点恢复流程",
        "评测体系"
      ],
      "thumb": "gray",
      "type": "MCP 配置"
    },
    "manual": {
      "markdown": "# https://github.com/RNBBarrett/thought-mcp 项目说明书\n\n生成时间：2026-05-16 09:34:00 UTC\n\n## 目录\n\n- [Introduction to THOUGHT](#page-introduction)\n- [Quickstart Guide](#page-quickstart)\n- [Installation and Setup](#page-installation)\n- [System Architecture](#page-architecture)\n- [Storage and Database Layer](#page-storage-layer)\n- [Memory Model and Data Structures](#page-memory-model)\n- [Query and Retrieval System](#page-query-system)\n- [Multi-Language Code Parsing](#page-code-parsing)\n- [Git History Integration](#page-git-integration)\n- [Agent Adapters and SDK Integration](#page-agent-adapters)\n\n<a id='page-introduction'></a>\n\n## Introduction to THOUGHT\n\n### 相关页面\n\n相关主题：[Quickstart Guide](#page-quickstart), [Installation and Setup](#page-installation), [System Architecture](#page-architecture)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/RNBBarrett/thought-mcp/blob/main/README.md)\n- [docs/comparison.md](https://github.com/RNBBarrett/thought-mcp/blob/main/docs/comparison.md)\n- [src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n- [src/thought/demo.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n- [src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n- [src/thought/storage/sqlite/backend.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/backend.py)\n- [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n</details>\n\n# Introduction to THOUGHT\n\nTHOUGHT is a local AI memory tool designed to help developers, researchers, writers, and investigators maintain persistent, queryable knowledge graphs of their work. It combines graph database technology with natural language processing to create a bi-temporal knowledge base that tracks information across time—answering questions like \"what was true on date X\" and \"what did the system know on date X.\" 资料来源：[README.md](https://github.com/RNBBarrett/thought-mcp/blob/main/README.md)\n\n## What is THOUGHT?\n\nTHOUGHT operates as a self-hosted memory layer that runs entirely on your local machine. Unlike cloud-based AI memory solutions, THOUGHT stores everything in a local SQLite database, giving you full control over your data while still providing powerful querying capabilities through natural language or Cypher graph queries. 资料来源：[src/thought/cli.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\nThe core philosophy is to treat memory as a first-class citizen in the development workflow—something that persists across sessions, understands context, and can be queried like a real database rather than a simple key-value store.\n\n## Core Architecture\n\nTHOUGHT's architecture consists of several interconnected layers that work together to provide a complete memory solution.\n\n```mermaid\ngraph TD\n    A[CLI / MCP Server] --> B[Query Layer]\n    B --> C[Graph Layer]\n    B --> D[Code Layer]\n    C --> E[Storage Backend]\n    D --> E\n    E --> F[SQLite Database]\n    B --> G[LLM Providers]\n    G --> H[Ollama / LM Studio / OpenAI]\n```\n\n### Storage Layer\n\nThe storage layer uses SQLite with a carefully designed schema that supports bi-temporal modeling. Every entity and edge in the knowledge graph has timestamps tracking when facts became valid and when they were learned. 资料来源：[src/thought/storage/sqlite/backend.py:1-100](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/backend.py)\n\n| Component | Purpose |\n|-----------|---------|\n| `SQLiteBackend` | Core database operations with upsert, query, and embedding storage |\n| WAL Mode | Write-Ahead Logging for crash recovery and concurrent reads |\n| Migration System | Tracks applied migrations in `applied_migrations` table |\n| Bi-temporal Columns | `valid_from`, `valid_until`, `learned_at`, `unlearned_at` |\n\n### Query Layer\n\nThe query layer provides multiple interfaces for accessing your memory:\n\n- **Natural Language**: Ask questions in plain English, translated to Cypher\n- **Code Queries**: Find callers, callees, and impact sets\n- **Recall**: Semantic search using embeddings\n- **Cypher Direct**: Execute graph queries directly 资料来源：[src/thought/query/ask.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n\n### Graph Layer\n\nThe graph layer provides the core graph operations that power all THOUGHT functionality. It handles entity and edge management with support for scopes (shared/private) and owner-based access control. 资料来源：[src/thought/layers/graph.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/graph.py)\n\n## Entity Model\n\nTHOUGHT uses a flexible entity model that can represent code elements, prose content, legal documents, and research claims.\n\n```mermaid\nclassDiagram\n    class Entity {\n        +str id\n        +str type\n        +str name\n        +str canonical_name\n        +ScopeName scope\n        +Tier tier\n        +float importance\n        +datetime valid_from\n        +datetime valid_until\n        +datetime learned_at\n        +dict~str, object~ attrs\n    }\n    \n    class Edge {\n        +str id\n        +str source_id\n        +str target_id\n        +str relation_type\n    }\n    \n    Entity \"1\" --> \"*\" Edge : source\n    Entity \"1\" --> \"*\" Edge : target\n```\n\n资料来源：[src/thought/models.py:50-100](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n\n### Entity Attributes\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `id` | str | Unique identifier |\n| `type` | str | Entity type (function, class, module, claim, etc.) |\n| `name` | str | Human-readable name |\n| `canonical_name` | str | Fully qualified name for disambiguation |\n| `scope` | ScopeName | \"shared\" or \"private\" |\n| `owner_id` | str | Owner for private entities |\n| `tier` | Tier | \"hot\", \"warm\", or \"cold\" |\n| `valid_from` | datetime | When this fact became true |\n| `valid_until` | datetime | When this fact stopped being true (null = current) |\n| `learned_at` | datetime | When THOUGHT learned this fact |\n| `attrs` | dict | Additional type-specific metadata |\n\n### Edge Relations\n\nEdges represent relationships between entities with the following relation types:\n\n| Relation Type | Description |\n|---------------|-------------|\n| `CALLS` | Function/method invocation |\n| `INHERITS_FROM` | Class inheritance |\n| `DEFINES` | Container defines member |\n| `IMPORTS` | Module import statement |\n| `CONTRADICTS` | Logical contradiction between facts |\n| `CITES` | Source citation relationship |\n\n## Audience Verticals\n\nTHOUGHT is designed to serve multiple audiences, each with specialized commands and entity taxonomies optimized for their use case. 资料来源：[src/thought/demo.py:1-80](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n\n```mermaid\ngraph LR\n    A[THOUGHT] --> B[Code Developers]\n    A --> C[Writers]\n    A --> D[Legal Investigators]\n    A --> E[Researchers]\n    \n    B --> B1[thought scan]\n    B --> B2[thought impact]\n    B --> B3[thought callers]\n    \n    C --> C1[thought ingest-prose]\n    C --> C2[thought timeline]\n    C --> C3[contradiction-check]\n    \n    D --> D1[thought ingest-legal]\n    D --> D2[unique_predicates]\n    D --> D3[contradiction-graph]\n    \n    E --> E1[thought ingest-claim]\n    E --> E2[citation-analysis]\n    E --> E3[reliability-filter]\n```\n\n### Code Developers\n\nThe code vertical provides tools for understanding, navigating, and analyzing source code:\n\n- **`thought scan`**: Incremental code scanning with change detection\n- **`thought impact <name>`**: Transitive impact set—what's affected if I change this?\n- **`thought callers <name>`**: Direct callers ranked by Personalized PageRank\n- **`thought recall`**: Semantic search across code by intent 资料来源：[src/thought/layers/code.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n\n### Writers\n\nThe writing vertical supports fiction and academic prose:\n\n- Ingest chapter/section facts about characters\n- Detect contradictions via the bi-temporal model\n- Query chronological mentions across documents\n- Time-travel `as_of` recall for historical consistency\n\n### Legal Investigators\n\nThe legal vertical is designed for investigation workflows:\n\n- **`thought ingest-legal`**: Ingest witness statements with unique predicates\n- **`thought contradiction-graph`**: Trigger CONTRADICTS edges between testimonies\n- Query the contradiction graph for investigation leads\n\n### Researchers\n\nThe research vertical supports academic workflows:\n\n- **`thought ingest-claim`**: Ingest claim/source pairs\n- Cypher queries to find uncited claims\n- Most-cited source identification\n- Citation reliability filtering\n\n## CLI Commands Overview\n\n| Command | Description |\n|---------|-------------|\n| `thought init` | Create database file + config + CLAUDE.md |\n| `thought recall <query>` | Semantic recall with embeddings |\n| `thought ask <question>` | Natural language query → Cypher → results |\n| `thought scan <repo>` | Incremental code scan with change detection |\n| `thought callers <name>` | Find direct callers ranked by PageRank |\n| `thought impact <name>` | Transitive impact set |\n| `thought db size` | Disk usage + entity/edge counts |\n| `thought db flush` | Wipe the knowledge base |\n| `thought db backup <file>` | SQLite online-backup snapshot |\n| `thought db load <file>` | Load backup file |\n| `thought hook install` | Install Claude Code hooks |\n| `thought diff --from <sha1> --to <sha2>` | Entity diff between commits |\n\n资料来源：[src/thought/cli.py:50-150](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n## Database Lifecycle Management\n\nTHOUGHT provides comprehensive database management commands under `thought db`:\n\n### Backup and Restore\n\n```mermaid\ngraph LR\n    A[Production DB] -->|thought db backup| B[backup.db]\n    B -->|thought db load| C[Production DB]\n    B -->|thought db inspect| D[Inspection Report]\n```\n\nThe backup system uses SQLite's online backup API, ensuring consistent snapshots even during active writes. Date filters can produce clean, self-contained subset files. 资料来源：[src/thought/storage/sqlite/backend.py:100-200](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/backend.py)\n\n### Flush Operations\n\nFlush commands support date-bounded deletion:\n- `--before X`: Delete facts valid before date X\n- `--since X`: Delete facts learned since date X\n- `--time-axis valid|learned|created`: Choose which time axis to filter\n\nAll destructive operations automatically back up to `<db>.bak.<timestamp>` before proceeding.\n\n## Git History Integration\n\nTHOUGHT can ingest git repositories with two modes:\n\n| Mode | Behavior | Use Case |\n|------|----------|----------|\n| `snapshot` (default) | Ingest HEAD only, stamp with HEAD SHA | Fast code analysis |\n| `full` | Walk every commit, stamp with commit SHA | Bi-temporal historical queries |\n\nThe `GitWalker` class shells out to `git` commands rather than using native libraries, avoiding C extension dependencies while maintaining cross-platform compatibility. 资料来源：[src/thought/ingest/code/git_walker.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/git_walker.py)\n\n```mermaid\ngraph TD\n    A[thought ingest-git] --> B{Snapshot Mode?}\n    B -->|Yes| C[Ingest HEAD only]\n    B -->|No| D[Walk all commits]\n    C --> E[Stamp with HEAD SHA]\n    D --> F[Stamp each entity with commit SHA]\n    E --> G[Enable as_of queries]\n    F --> G\n```\n\n## Bi-temporal Model\n\nTHOUGHT's bi-temporal model tracks two independent timelines for every fact:\n\n| Time Axis | Description | Question Answered |\n|-----------|-------------|-------------------|\n| **Valid Time** | When a fact was true in reality | \"What was true on date X?\" |\n| **Learned Time** | When THOUGHT learned the fact | \"What did the system know on date X?\" |\n\nThis distinction enables sophisticated queries like:\n\n```cypher\nMATCH (e:Entity)\nWHERE e.valid_from <= date('2024-01-01')\n  AND (e.valid_until IS NULL OR e.valid_until > date('2024-01-01'))\nRETURN e\n```\n\nContradictions surface as `CONTRADICTS` edges—they're treated as data rather than warnings, allowing you to query them directly. 资料来源：[src/thought/cli.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n## LLM Provider Integration\n\nTHOUGHT supports multiple LLM providers for natural language processing:\n\n| Provider | Features |\n|----------|----------|\n| **Ollama** | Native `/api/embed` (batched), OpenAI-compatible fallback |\n| **LM Studio** | OpenAI-compatible API |\n| **Any OpenAI-compatible server** | Standard embedding endpoints |\n\nThe embedder selection defaults to `auto`, which probes for `sentence_transformers` and falls back to a deterministic embedder when the optional dependency is unavailable. 资料来源：[src/thought/storage/sqlite/backend.py:200-300](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/backend.py)\n\n## Code Extraction Support\n\nTHOUGHT can parse and extract entities from multiple programming languages:\n\n| Language | Extractor | Key Features |\n|----------|-----------|--------------|\n| Python | `python_extractor.py` | AST-based import tracking, class/function detection |\n| TypeScript | `typescript_extractor.py` | Tree-sitter parsing, heritage analysis |\n| Rust | `rust_extractor.py` | Module system, impl block handling |\n| PHP | `php_extractor.py` | Namespace handling, method visibility |\n\nAll extractors produce consistent `CodeEntity` and `CodeEdge` objects that integrate with the unified graph model. 资料来源：[src/thought/ingest/code/python_extractor.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/python_extractor.py)\n\n## Getting Started\n\n### Initialization\n\n```bash\nthought init --db-path .thought/thought.db --embedder auto\n```\n\nThis creates:\n1. The SQLite database file\n2. A `thought.toml` configuration file\n3. A `CLAUDE.md` file for MCP client integration\n\n### Quick Start Commands\n\n```bash\n# Ingest a git repository\nthought ingest-git ./my-project --mode snapshot\n\n# Recall something semantically\nthought recall \"authentication middleware\"\n\n# Ask a natural language question\nthought ask \"what calls the authenticate_user function?\"\n\n# Find impact of changing a function\nthought impact MyClass.my_method\n```\n\n## Configuration\n\nTHOUGHT uses a `thought.toml` file for configuration:\n\n| Section | Option | Default | Description |\n|---------|--------|---------|-------------|\n| `database` | `path` | `.thought/thought.db` | Database file path |\n| `llm` | `provider` | `auto` | LLM provider selection |\n| `embedder` | `model` | `auto` | Embedding model |\n| `scopes` | `default` | `shared` | Default scope for new entities |\n\nConfiguration can be overridden via CLI flags or environment variables.\n\n---\n\n<a id='page-quickstart'></a>\n\n## Quickstart Guide\n\n### 相关页面\n\n相关主题：[Introduction to THOUGHT](#page-introduction), [Installation and Setup](#page-installation)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/demo.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n- [src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n- [src/thought/ingest/code/pipeline.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/pipeline.py)\n- [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n- [src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n- [CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n</details>\n\n# Quickstart Guide\n\n## Overview\n\n**THOUGHT** is a local-AI memory tool designed to manage knowledge bases, run on local models, write graph queries, and query in natural language. It provides a comprehensive CLI for ingesting information, recalling facts, and performing code analysis with graph-based relationships.\n\n资料来源：[CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n\n## Architecture Overview\n\n```mermaid\ngraph TD\n    subgraph \"THOUGHT Core\"\n        CLI[CLI Interface]\n        DB[(SQLite Database)]\n        EMB[Embedder Layer]\n        GRAPH[Graph Layer]\n    end\n    \n    subgraph \"Ingestion Sources\"\n        CODE[Code Ingest]\n        PROSE[Prose Ingest]\n        LEGAL[Legal Ingest]\n    end\n    \n    subgraph \"Query Interface\"\n        RECALL[Recall Command]\n        REPL[Interactive REPL]\n        MCP[MCP Server]\n    end\n    \n    CLI --> DB\n    CLI --> EMB\n    EMB --> DB\n    CODE --> CLI\n    PROSE --> CLI\n    LEGAL --> CLI\n    RECALL --> GRAPH\n    REPL --> GRAPH\n    MCP --> GRAPH\n    GRAPH --> DB\n```\n\n资料来源：[src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n## Installation and Initialization\n\n### Initial Setup\n\nRun the `init` command to create the database, configuration file, and CLAUDE.md helper:\n\n```bash\nthought init\n```\n\nThe init command accepts several options:\n\n| Option | Default | Description |\n|--------|---------|-------------|\n| `--config` | `thought.toml` | Path to configuration file |\n| `--db-path` | `.thought/thought.db` | SQLite database path |\n| `--embedder` | `auto` | Embedder type: `auto`, `sentence-transformers`, or `deterministic` |\n| `--write-claude-md` | `true` | Drop a CLAUDE.md for MCP clients |\n| `--quick` | `false` | Skip first-run embedder warmup |\n\n资料来源：[src/thought/cli.py:57-78](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n### Configuration File\n\nThe init command creates a `thought.toml` configuration file with the following structure:\n\n```toml\n[database]\npath = \".thought/thought.db\"\n\n[embedder]\ntype = \"auto\"  # or \"ollama\", \"lm_studio\", \"openai_compatible\"\n\n[llm]\nprovider = \"auto\"\n```\n\n## Core Commands\n\n### Ingest Commands\n\nTHOUGHT supports multiple ingestion modes:\n\n| Command | Purpose |\n|---------|---------|\n| `thought ingest TEXT` | One-shot remember from command line |\n| `thought ingest --file PATH` | Ingest a single file |\n| `thought ingest --glob PAT` | Bulk-ingest matching files |\n| `thought ingest --stdin` | Bulk-ingest one line-per-item from stdin |\n\n资料来源：[src/thought/cli.py:30-42](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n### Code Ingestion\n\nThe code ingest pipeline extracts entities and relationships from source files:\n\n```bash\nthought ingest --file src/main.py\nthought ingest --glob \"**/*.py\"\n```\n\nThe code extractor produces:\n\n- **Entities**: modules, functions, classes, methods\n- **Edges**: `IMPORTS`, `INHERITS_FROM`, `DEFINES`, `OVERRIDES`\n\n资料来源：[src/thought/ingest/code/pipeline.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/pipeline.py)\n\n### Git-Aware Ingest\n\nFor bi-temporal code analysis:\n\n```bash\nthought ingest-git <repo> --mode snapshot  # Fast: HEAD only\nthought ingest-git <repo> --mode full      # Walk every commit\n```\n\nThis enables `as_of` queries against historical commits.\n\n资料来源：[CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n\n### Recall and Query\n\n```bash\nthought recall \"what did I learn about authentication?\"\nthought repl\n```\n\nThe `recall` command returns up to 10 results with ranked relevance. Use `as_of` and `scope` to narrow results further.\n\n资料来源：[src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n### Database Management\n\n| Command | Description |\n|---------|-------------|\n| `thought db size` | Disk usage + entity/edge counts |\n| `thought db flush` | Wipe the KB (with backup) |\n| `thought db backup <file>` | SQLite backup snapshot |\n| `thought db load <file>` | Load a backup file |\n| `thought db inspect <file>` | Inspect backup without loading |\n\n资料来源：[CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n\n## Code Analysis Commands\n\n### Callers and Impact Analysis\n\n```bash\n# Find who calls a function (ranked by PageRank)\nthought callers authenticate_user\n\n# Transitive impact: what's affected if I change this?\nthought impact JWTValidator\n```\n\n资料来源：[src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n\n### Diff Between Commits\n\n```bash\nthought diff --from abc1234 --to def5678\n```\n\nThis shows entities added/removed between two ingested commits.\n\n## Built-in Demos\n\nRun audience-specific walkthroughs:\n\n```bash\nthought demo code        # Agent/developer flow (14-stage walkthrough)\nthought demo writer       # Novelist/paper author\nthought demo legal        # Investigator/paralegal\nthought demo researcher   # Academic use case\nthought demo all          # Run all demos sequentially\n```\n\nEach demo runs end-to-end in a self-cleaning temporary directory and produces a structured `DemoReport`.\n\n资料来源：[src/thought/demo.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n\n## Entity Data Model\n\n```python\n@dataclass(frozen=True)\nclass CodeEntity:\n    name: str           # Qualified name (e.g., \"ClassName.method_name\")\n    type_: CodeEntityType  # \"module\" | \"function\" | \"class\" | \"method\" | \"file\"\n    language: str       # Programming language\n    file_path: str      # POSIX-style relative path\n    line_start: int     # Starting line number\n    line_end: int       # Ending line number\n    signature: str      # Function/class signature\n    docstring: str | None\n    visibility: Literal[\"public\", \"private\"]\n```\n\n资料来源：[src/thought/ingest/code/types.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/types.py)\n\n## Supported Languages\n\nThe code ingestion pipeline supports:\n\n| Language | Extractor | File Extension |\n|----------|-----------|----------------|\n| Python | `python_extractor.py` | `.py` |\n| TypeScript | `typescript_extractor.py` | `.ts`, `.tsx` |\n| PHP | `php_extractor.py` | `.php` |\n| Rust | `rust_extractor.py` | `.rs` |\n\n## MCP Server\n\nStart the MCP server for integration with Claude Code:\n\n```bash\nthought serve                          # stdio transport (default)\nthought serve --transport streamable-http  # HTTP transport\n```\n\n资料来源：[src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n## Utility Commands\n\n| Command | Description |\n|---------|-------------|\n| `thought stats` | Display knowledge base statistics |\n| `thought forget PATTERN` | Soft-delete entities matching SQL LIKE pattern |\n| `thought consolidate` | Run one consolidation cycle |\n| `thought doctor` | Environment health check |\n\n## Bi-Temporal Model\n\nTHOUGHT uses a bi-temporal model for knowledge tracking:\n\n- **`valid_from` / `valid_until`**: When facts were true in reality\n- **`learned_at` / `unlearned_at`**: When the system learned/corrected facts\n\nQuery variants:\n- `as_of_kind='valid'` — \"what was true on date X\"\n- `as_of_kind='learned'` — \"what did the system know on date X\"\n\n资料来源：[src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n\n---\n\n<a id='page-installation'></a>\n\n## Installation and Setup\n\n### 相关页面\n\n相关主题：[Quickstart Guide](#page-quickstart), [System Architecture](#page-architecture)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n- [src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n- [src/thought/hooks/install.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n- [src/thought/demo.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n- [CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n- [CONTRIBUTING.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CONTRIBUTING.md)\n</details>\n\n# Installation and Setup\n\n## Overview\n\nThe `thought-mcp` project provides a comprehensive CLI tool and MCP (Model Context Protocol) server for AI-powered memory and knowledge management. The installation and setup process involves initializing the local SQLite database, configuring MCP clients (Claude Code, Cursor, etc.), and optionally setting up Claude Code hooks for automated memory operations.\n\nThe setup system is designed with idempotency in mind — installations can be safely re-run without disrupting existing configurations.\n\n## System Architecture\n\n```mermaid\ngraph TD\n    A[User] --> B[thought CLI]\n    B --> C[init command]\n    C --> D[SQLite Database]\n    C --> E[thought.toml Config]\n    C --> F[CLAUDE.md Agent Hint]\n    B --> G[MCP Server]\n    G --> D\n    B --> H[Client Install]\n    H --> I[Claude Code]\n    H --> J[Cursor]\n    H --> K[VS Code]\n    B --> L[Hook Install]\n    L --> M[.claude/settings.json]\n```\n\n## Prerequisites\n\n| Component | Requirement | Notes |\n|-----------|-------------|-------|\n| Python | >= 3.10 | Core runtime |\n| Git | On PATH | Used by git pipeline for code ingestion |\n| SQLite | 3.x | Bundled with Python stdlib |\n| pip/pipx | Latest | Package installation |\n\n资料来源：[CONTRIBUTING.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CONTRIBUTING.md)\n\n## Installation Methods\n\n### Standard Installation\n\n```bash\npip install thought-mcp\n```\n\n### Development Installation\n\n```bash\ngit clone https://github.com/RNBBarrett/thought-mcp.git\ncd thought-mcp\npip install -e \".[dev]\"\n```\n\n## CLI Initialization\n\nThe `thought init` command establishes the complete working environment. It creates three essential components in sequence.\n\n### Init Command Signature\n\n```python\n@app.command()\ndef init(\n    config: Path = typer.Option(\"thought.toml\", help=\"Path to config file.\"),\n    db_path: str = typer.Option(\".thought/thought.db\", help=\"SQLite database path.\"),\n    embedder: str = typer.Option(\n        \"auto\", help=\"'auto' picks sentence-transformers if available, else deterministic.\",\n    ),\n    write_claude_md: bool = typer.Option(\n        True, \"--write-claude-md/--no-claude-md\",\n        help=\"Drop a CLAUDE.md so MCP clients learn how to use the tool.\",\n    ),\n    quick: bool = typer.Option(\n        False, \"--quick\", help=\"Skip first-run embedder warmup.\",\n    ),\n) -> None:\n```\n\n资料来源：[src/thought/cli.py:35-56](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n### What Init Creates\n\n```mermaid\ngraph LR\n    A[thought init] --> B[Create .thought/ directory]\n    A --> C[Create SQLite DB file]\n    A --> D[Write thought.toml config]\n    A --> E[Write CLAUDE.md]\n    \n    B --> F[parents=True<br/>exist_ok=True]\n    C --> G[DB auto-backed up<br/>before destructive ops]\n```\n\n#### 1. Database Initialization\n\nThe command creates the SQLite database at the specified path. Parent directories are created automatically using `parents=True` to ensure the path exists.\n\n```python\nPath(db_path).parent.mkdir(parents=True, exist_ok=True)\n```\n\n资料来源：[src/thought/cli.py:52-53](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n#### 2. Configuration File\n\nThe `thought.toml` file contains runtime configuration including embedder settings and database paths.\n\n#### 3. CLAUDE.md Agent Hint\n\nWhen `write_claude_md=True` (default), the init command drops a `CLAUDE.md` file that teaches MCP clients how to interact with the tool.\n\n### Embedder Configuration\n\nThe init command supports three embedder modes:\n\n| Mode | Behavior | Dependencies |\n|------|----------|--------------|\n| `auto` (default) | Uses `sentence-transformers` if available, falls back to deterministic embeddings | Optional: sentence-transformers |\n| `sentence-transformers` | Uses local transformer models for embeddings | Required: sentence-transformers |\n| `deterministic` | Uses hash-based embeddings, no ML dependencies | None |\n\nThe `--quick` flag skips the first-run embedder warmup process.\n\n## MCP Client Installation\n\nThe `thought clients install` command merges a `thought` MCP server entry into your client's configuration file.\n\n### Supported Clients\n\n| Client | Config Location |\n|--------|-----------------|\n| Claude Code | `.claude/settings.json` |\n| Cursor | `~/.cursor/settings.json` |\n| VS Code | `~/.cursor/settings.json` |\n\n### Installation Workflow\n\n```mermaid\ngraph TD\n    A[thought clients install] --> B{Check config exists?}\n    B -->|No| C[Create new config file]\n    B -->|Yes| D[Read existing JSON]\n    C --> E{Valid JSON object?}\n    D --> E\n    E -->|Yes| F[Merge mcpServers entry]\n    E -->|No| G[Return error]\n    F --> H{Backup enabled?}\n    H -->|Yes| I[Create .thought.bak backup]\n    H -->|No| J[Write merged config]\n    I --> J\n    J --> K[Return ClientInstallResult]\n```\n\n### Client Install Result States\n\n```python\n@dataclass(frozen=True)\nclass ClientInstallResult:\n    client: ClientName\n    path: Path\n    status: Literal[\"installed\", \"already_present\", \"no_path\", \"error\"]\n    detail: str = \"\"\n```\n\n资料来源：[src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n\n### Server Block Structure\n\nThe MCP server configuration block includes:\n\n- Server name (`thought`)\n- Command to execute\n- Server arguments\n- Environment variables for database path\n\n## Claude Code Hook Installation\n\nThe `thought hooks install` command adds hook entries to Claude Code's settings for automated memory operations.\n\n### Hook Types\n\n| Hook Kind | Claude Code Event | Command |\n|-----------|-------------------|---------|\n| `recall` | UserPromptSubmit | `thought hook recall` |\n| `write` | Stop | `thought hook write` |\n| `context` | SessionStart | `thought hook context` |\n\n资料来源：[src/thought/hooks/install.py:17-22](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n\n### Hook Installation Options\n\n```python\ndef settings_path(*, scope: Literal[\"project\", \"user\"] = \"project\") -> Path:\n    \"\"\"Return the ``.claude/settings.json`` path for the requested scope.\n\n    Project scope is the recommended default — it travels with the repo and\n    is what most users actually want for THOUGHT-flavoured auto-memory.\n    \"\"\"\n    if scope == \"project\":\n        return Path.cwd() / \".claude\" / \"settings.json\"\n```\n\n### Hook Install Process\n\n```mermaid\ngraph TD\n    A[thought hooks install recall] --> B{Backup enabled?}\n    B -->|Yes| C[Create settings.json.thought.bak]\n    B -->|No| D[Read settings.json]\n    C --> D\n    D --> E{Valid JSON?}\n    E -->|Yes| F[Merge recall hook entry]\n    E -->|No| G[Return error]\n    F --> H{Entry exists?}\n    H -->|Yes| I[Return already_present]\n    H -->|No| J[Write updated settings.json]\n    J --> K[Return HookInstallResult]\n```\n\n### Hook Install Result\n\n```python\n@dataclass(frozen=True)\nclass HookInstallResult:\n    kind: HookKind\n    path: Path\n    status: Literal[\"installed\", \"already_present\", \"error\"]\n    detail: str = \"\"\n```\n\n资料来源：[src/thought/hooks/install.py:28-32](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n\n## Quick Start Guide\n\n### Step 1: Initialize the Environment\n\n```bash\n# Standard initialization\nthought init\n\n# Skip embedder warmup for faster startup\nthought init --quick\n\n# Custom database location\nthought init --db-path /path/to/custom.db\n```\n\n### Step 2: Install MCP Client\n\n```bash\n# Install for Claude Code\nthought clients install claude_code\n\n# Install for Cursor\nthought clients install cursor\n```\n\n### Step 3: Install Claude Code Hooks (Optional)\n\n```bash\n# Install recall hook (automatic memory on user input)\nthought hooks install recall\n\n# Install write hook (save memory on session stop)\nthought hooks install write\n\n# Install context hook (load memory on session start)\nthought hooks install context\n\n# Install all hooks\nthought hooks install recall --kind write --kind context\n```\n\n## Database Lifecycle Management\n\n### Database Size Check\n\n```bash\nthought db size\n```\n\nShows disk usage of main + WAL + SHM sidecars plus entity/edge counts.\n\n### Database Backup\n\n```bash\nthought db backup <file>\n```\n\nCreates an SQLite online-backup snapshot. Date filters produce a clean, self-contained subset file with DELETE + VACUUM after backup.\n\n### Database Restore\n\n```bash\nthought db load <file>\n```\n\nAtomically replaces the active database with the backup file. Use `--merge` to INSERT-OR-IGNORE rows from the snapshot instead of replacing.\n\n### Database Flush\n\n```bash\n# Full flush with confirmation\nthought db flush\n\n# Skip confirmation\nthought db flush --yes\n\n# Date-bounded flush\nthought db flush --before 2024-01-01\nthought db flush --since 2024-06-01\n```\n\n> **Note**: All destructive operations auto-backup to `<db>.bak.<timestamp>` before proceeding.\n\n## Verifying Installation\n\n### Run the Demo\n\n```bash\n# Run code audience demo\nthought demo code\n\n# Run all demos\nthought demo all\n```\n\nThe demo runs an audience-specific walkthrough end-to-end in a self-cleaning temporary directory, verifying the installation works correctly.\n\n### Health Check\n\n```bash\nthought doctor\n```\n\nPerforms an environment health check to verify all dependencies and configurations are correct.\n\n## Configuration File Format\n\n### thought.toml\n\n```toml\n[database]\npath = \".thought/thought.db\"\n\n[embedder]\ntype = \"auto\"  # or \"sentence-transformers\", \"deterministic\"\n\n[server]\nname = \"thought\"\ntransport = \"stdio\"  # or \"streamable-http\"\n```\n\n## Troubleshooting\n\n### Common Issues\n\n| Issue | Solution |\n|-------|----------|\n| Config file not found | Run `thought init` first |\n| Database locked | Check for other `thought` processes |\n| Embedder initialization slow | Use `--quick` flag or `deterministic` embedder |\n| MCP client not connecting | Verify client config has correct server entry |\n\n### Reset Installation\n\n```bash\n# Backup current database\nthought db backup /path/to/backup.db\n\n# Flush and reinitialize\nthought db flush --yes\nthought init --db-path .thought/thought.db\n```\n\n## Next Steps\n\nAfter installation and setup, users typically:\n\n1. **Ingest code**: `thought ingest-git <repo>` to analyze repository code\n2. **Recall information**: `thought recall <query>` to query the knowledge base\n3. **Run agents**: Use reference agents like the vulnerability scanner or OSINT aggregator\n\n---\n\n<a id='page-architecture'></a>\n\n## System Architecture\n\n### 相关页面\n\n相关主题：[Introduction to THOUGHT](#page-introduction), [Storage and Database Layer](#page-storage-layer), [Memory Model and Data Structures](#page-memory-model)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/server.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/server.py)\n- [src/thought/ingest/code/pipeline.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/pipeline.py)\n- [src/thought/ingest/code/git_pipeline.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/git_pipeline.py)\n- [src/thought/query/ask.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n- [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n- [src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n- [src/thought/demo.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n- [src/thought/hooks/install.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n- [src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n</details>\n\n# System Architecture\n\n## Overview\n\nThe thought-mcp project is a Model Context Protocol (MCP) server implementation that provides an intelligent memory and code analysis system for AI-assisted development. The system combines semantic memory storage with code graph analysis, enabling natural language queries against codebases through a bi-temporal knowledge graph.\n\n## High-Level Architecture\n\n```mermaid\ngraph TD\n    subgraph \"Client Layer\"\n        MCP[MCP Client]\n        CLI[Thought CLI]\n        Hooks[Claude Code Hooks]\n    end\n    \n    subgraph \"Server Layer\"\n        Server[MCP Server]\n        Router[Query Router]\n        Classifier[Query Classifier]\n    end\n    \n    subgraph \"Memory Layer\"\n        Memory[Memory Manager]\n        Recall[Recall Engine]\n        Ask[Ask - NL to Cypher]\n    end\n    \n    subgraph \"Storage Layer\"\n        Backend[SQLite Backend]\n        Entities[Entity Store]\n        Edges[Edge Store]\n        Embeddings[Vector Embeddings]\n    end\n    \n    subgraph \"Ingest Layer\"\n        CodePipeline[Code Pipeline]\n        GitPipeline[Git Pipeline]\n        Extractors[Language Extractors]\n    end\n    \n    MCP --> Server\n    CLI --> Server\n    Hooks --> Server\n    Server --> Router\n    Router --> Classifier\n    Classifier --> Memory\n    Memory --> Backend\n    CodePipeline --> Backend\n    GitPipeline --> Backend\n    Ask --> Recall\n```\n\n## Core Components\n\n### MCP Server (`src/thought/server.py`)\n\nThe MCP server exposes the primary tool interface for AI clients. It implements async tool handlers that delegate to the memory layer.\n\n**Key Tools:**\n\n| Tool | Purpose |\n|------|---------|\n| `recall` | Semantic recall of entities using embeddings |\n| `ask` | Natural language queries translated to Cypher |\n| `working_context` | Context primitive for agent awareness |\n| `scan` | Incremental code scanning with change detection |\n\n资料来源：[src/thought/server.py:1-100]()\n\n### Query Router and Classifier\n\nThe system routes queries through a classification system that detects:\n\n- **CODE** queries: Triggered by code-shaped keywords (`function`, `class`, `caller`, `callee`, file extensions) plus camelCase/snake_case identifiers\n- **CHANGE** queries: Historical or diff-based queries\n- **HYBRID** combinations: CODE × CHANGE patterns like \"what changed in auth.middleware since v1.0\"\n\n```mermaid\ngraph LR\n    Q[Query] --> C[Classifier]\n    C --> |CODE| CR[Code Route]\n    C --> |CHANGE| CH[Change Route]\n    C --> |HYBRID| HY[Hybrid Route]\n    C --> |DEFAULT| DF[Default Recall]\n```\n\n资料来源：[CHANGELOG.md:1-80]()\n\n### Code Layer (`src/thought/layers/code.py`)\n\nThe code layer provides a high-level API for code-specific graph queries against the currently-valid view of the code graph.\n\n```python\nclass CodeLayer:\n    def callers_of(name)    # Who calls this function\n    def callees_of(name)    # What this function calls\n    def impact_set(name)    # Transitive callers, ranked\n    def defines_in_file()   # Entities in a given file\n```\n\n资料来源：[src/thought/layers/code.py:1-60]()\n\n## Storage Architecture\n\n### SQLite Backend\n\nThe system uses SQLite as its primary storage with the following schema features:\n\n- **Bi-temporal model**: Tracks `valid_from`/`valid_until` (business time) and `learned_at` (system knowledge time)\n- **Entity/Edge tables** with code-specific columns (`code_file`, `code_language`, `code_commit_sha`)\n- **Partial indexes** for efficient queries\n- **WAL mode** with checkpointing for consistent backups\n\n### Data Models\n\n**Entity Structure:**\n```python\n@dataclass\nclass CodeEntity:\n    name: str\n    type_: str           # function, class, module, method\n    language: str        # python, typescript, rust, php\n    file_path: str\n    line_start: int\n    line_end: int\n    signature: str\n    docstring: str\n    visibility: str      # public, private, protected\n    attrs: dict\n```\n\n**Edge Types:**\n- `CALLS` - Function/method invocations\n- `INHERITS_FROM` - Class inheritance\n- `IMPORTS` - Module imports\n- `DEFINES` - Member definitions within classes\n- `OVERRIDES` - Method overrides (TypeScript)\n\n资料来源：[src/thought/ingest/code/pipeline.py:1-100]()\n\n## Code Ingestion Pipeline\n\n### Language Extractors\n\nThe system uses tree-sitter parsers for multi-language code extraction:\n\n| Language | File | Capabilities |\n|----------|------|--------------|\n| Python | `python_extractor.py` | Functions, classes, imports, inheritance |\n| TypeScript | `typescript_extractor.py` | Functions, classes, imports, exports, inheritance, overrides |\n| Rust | `rust_extractor.py` | Functions, impl blocks, traits |\n| PHP | `php_extractor.py` | Functions, classes, methods, namespaces |\n\nAll extractors output `CodeEntity` and `CodeEdge` tuples parsed from AST nodes.\n\n资料来源：[src/thought/ingest/code/python_extractor.py:1-80]()\n\n### Code Pipeline Flow\n\n```mermaid\ngraph TD\n    F[File Input] --> LD[Language Detection]\n    LD --> EX[Extract Entities/Edges]\n    EX --> SI[Upsert Source]\n    SI --> WE[_write_entities]\n    WE --> EE[Embed Signatures]\n    EE --> WEd[_write_edges]\n    WEd --> CM[Commit Transaction]\n    \n    subgraph \"Entities Processing\"\n        WE --> |\"name_to_id map\"| WEd\n    end\n```\n\n资料来源：[src/thought/ingest/code/pipeline.py:100-200]()\n\n### Git Pipeline (`src/thought/ingest/code/git_pipeline.py`)\n\nThe git pipeline enables historical code analysis with two modes:\n\n| Mode | Behavior |\n|------|----------|\n| `snapshot` | Fast - ingest HEAD only, stamp entities with HEAD SHA |\n| `full` | Walk every commit chronologically, stamp each entity with its commit SHA |\n\nThe `full` mode enables bi-temporal `as_of` queries against historical commits.\n\n资料来源：[src/thought/ingest/code/git_pipeline.py:1-50]()\n\n## Query System\n\n### Recall Engine\n\nSemantic recall uses vector embeddings to find entities by intent rather than exact name:\n\n```python\ndef recall(\n    query: str,\n    scope: str = \"all\",\n    owner_id: str | None = None,\n    limit: int = 10,\n) -> list[RecallHit]\n```\n\nThe system embeds entity signatures and docstrings during ingestion, enabling natural queries like \"who calls authenticate_user\".\n\n### Ask Engine (`src/thought/query/ask.py`)\n\nNatural language to Cypher translation with validation:\n\n```mermaid\ngraph LR\n    NL[Natural Language] --> PROMPT[Build Prompt]\n    PROMPT --> LLM[LLM Provider]\n    LLM --> CY[Cypher Query]\n    CY --> VAL[Validate]\n    VAL --> |Valid| EXE[Execute]\n    VAL --> |Invalid| FB[Fallback to Recall]\n```\n\n**Constraint System:**\n- Read-only Cypher features only (MATCH, WHERE, RETURN)\n- Validates against actual schema before execution\n- Falls back to `recall()` on translation failures\n\n资料来源：[src/thought/query/ask.py:1-80]()\n\n## Integration Points\n\n### MCP Client Installation (`src/thought/clients.py`)\n\nThe system installs as an MCP server for AI coding tools:\n\n```python\ndef install(client: ClientName, *, server_name: str = \"thought\")\n```\n\nSupported clients include Claude Code and other MCP-compatible tools. Installation merges configuration without disturbing existing settings.\n\n### Claude Code Hooks (`src/thought/hooks/install.py`)\n\nHooks provide automatic memory integration:\n\n| Hook | Event | Action |\n|------|-------|--------|\n| `recall` | UserPromptSubmit | Memory recall on user input |\n| `write` | Stop | Context capture on completion |\n| `context` | SessionStart | Session initialization |\n\n资料来源：[src/thought/hooks/install.py:1-50]()\n\n## CLI Architecture (`src/thought/cli.py`)\n\nThe command-line interface provides database lifecycle management:\n\n| Command | Function |\n|---------|----------|\n| `thought init` | Create database + config + CLAUDE.md |\n| `thought db size` | Disk usage + entity/edge counts |\n| `thought db flush` | Wipe KB with backup |\n| `thought db backup` | SQLite online-backup snapshot |\n| `thought db load` | Load snapshot atomically |\n| `thought db inspect` | Count + schema summary |\n| `thought ingest-git` | Git-history-aware ingestion |\n| `thought callers` | Direct callers via PageRank |\n| `thought impact` | Transitive impact set |\n| `thought diff` | Entity diff between commits |\n\n资料来源：[src/thought/cli.py:1-100]()\n\n## Demo System (`src/thought/demo.py`)\n\nThe built-in demo provides audience-specific walkthroughs:\n\n| Audience | Purpose |\n|----------|---------|\n| `code` | Agent/developer flow - 14-stage code vertical |\n| `writer` | Novelist/paper author - bi-temporal recall |\n| `legal` | Investigator - contradiction detection |\n| `researcher` | Academic - claim/source relationships |\n\n资料来源：[src/thought/demo.py:1-50]()\n\n## Configuration\n\n### Database Initialization\n\n```toml\n# thought.toml\n[database]\npath = \".thought/thought.db\"\n\n[llm]\nprovider = \"anthropic\"  # or ollama, lmstudio, openai-compat\n\n[embedder]\ntype = \"auto\"  # sentence-transformers if available, else deterministic\n```\n\n资料来源：[src/thought/cli.py:50-80]()\n\n## Summary\n\nThe thought-mcp architecture combines:\n\n1. **MCP Server** - Tool interface for AI clients\n2. **Bi-temporal Storage** - SQLite with code-specific schema\n3. **Multi-language Extractors** - Tree-sitter based AST parsing\n4. **Git Integration** - Historical code analysis\n5. **Query Routing** - Classification-based query dispatch\n6. **Natural Language Interface** - NL to Cypher translation\n\nThis design enables both real-time code assistance and deep historical analysis of codebases through a unified query interface.\n\n---\n\n<a id='page-storage-layer'></a>\n\n## Storage and Database Layer\n\n### 相关页面\n\n相关主题：[System Architecture](#page-architecture), [Memory Model and Data Structures](#page-memory-model)\n\n<details>\n<summary>Relevant Source Files</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/storage/__init__.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/__init__.py)\n- [src/thought/storage/base.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/base.py)\n- [src/thought/storage/sqlite/backend.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/backend.py)\n- [src/thought/storage/sqlite/migrations/0001_initial.sql](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/migrations/0001_initial.sql)\n- [src/thought/storage/sqlite/migrations/0002_v0.2_code.sql](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/migrations/0002_v0.2_code.sql)\n- [src/thought/storage/sqlite/migrations/0003_views.sql](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/migrations/0003_views.sql)\n- [src/thought/storage/sqlite/migrations/0004_agents.sql](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/migrations/0004_agents.sql)\n</details>\n\n# Storage and Database Layer\n\n## Overview\n\nThe Storage and Database Layer is the persistence backbone of the THOUGHT system, providing a structured SQLite-based knowledge base (KB) for storing entities, edges, embeddings, and operational metadata. This layer abstracts database operations through a modular backend interface, enabling CRUD operations, bi-temporal data tracking, and specialized queries for code analysis.\n\nThe architecture supports:\n- **Entity/Edge persistence** with bi-temporal validity tracking (valid_from, valid_until, learned_at)\n- **Vector embeddings** for semantic recall operations\n- **Source tracking** for ingested content provenance\n- **Code-specific metadata** including language, file path, and commit SHA\n- **Agent and scan logging** for operational auditability\n\n资料来源：[src/thought/storage/__init__.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/__init__.py)\n\n---\n\n## Architecture\n\n### Layer Stack\n\n```mermaid\ngraph TD\n    A[CLI / API Layer] --> B[GraphLayer / CodeLayer]\n    B --> C[BaseBackend Interface]\n    C --> D[SQLiteBackend]\n    D --> E[(SQLite Database)]\n    \n    F[Ingest Pipelines] --> C\n    G[Recall Queries] --> B\n```\n\n### Backend Interface Hierarchy\n\nThe system defines a base interface (`BaseBackend`) that all storage implementations must satisfy, with `SQLiteBackend` as the primary concrete implementation.\n\n| Component | Responsibility |\n|-----------|-----------------|\n| `BaseBackend` | Abstract interface defining all storage operations |\n| `SQLiteBackend` | Concrete SQLite implementation with WAL mode and migrations |\n| `GraphLayer` | Query layer wrapping backend for graph traversal operations |\n| `CodeLayer` | Specialized wrapper for code-specific queries (callers, callees, impact) |\n\n资料来源：[src/thought/storage/base.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/base.py), [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n\n---\n\n## Data Models\n\n### Entity Model\n\nThe `Entity` model represents atomic units of knowledge stored in the database.\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `id` | `str` | Unique identifier (UUID) |\n| `type` | `str` | Entity type (e.g., \"function\", \"class\", \"claim\") |\n| `name` | `str` | Display name |\n| `canonical_name` | `str` | Normalized identifier for lookups |\n| `owner_id` | `str \\| None` | Owner for private entities |\n| `scope` | `ScopeName` | \"shared\" or \"private\" visibility |\n| `tier` | `Tier` | Importance tier (\"hot\", \"warm\", \"cold\") |\n| `importance` | `float` | 0.0-1.0 importance score |\n| `valid_from` | `datetime` | When entity became valid |\n| `valid_until` | `datetime \\| None` | When entity expired (NULL = currently valid) |\n| `learned_at` | `datetime` | When system learned this fact |\n| `unlearned_at` | `datetime \\| None` | When system discarded this fact |\n| `created_at` | `datetime` | Record creation timestamp |\n| `last_accessed_at` | `datetime` | Last access timestamp |\n| `access_count` | `int` | Query frequency counter |\n| `attrs` | `dict[str, object]` | Extensible metadata |\n| `code_file` | `str \\| None` | Source file path (code entities) |\n| `code_language` | `str \\| None` | Programming language (code entities) |\n| `code_commit_sha` | `str \\| None` | Git commit SHA (code entities) |\n\n资料来源：[src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n\n### Edge Model\n\nThe `Edge` model represents relationships between entities.\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `id` | `str` | Unique identifier |\n| `source_id` | `str` | Source entity ID |\n| `target_id` | `str` | Target entity ID |\n| `relation_type` | `str` | Relationship type (e.g., \"CALLS\", \"INHERITS_FROM\") |\n| `attrs` | `dict[str, object]` | Edge metadata |\n\n资料来源：[src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n\n---\n\n## Database Schema\n\n### Core Tables\n\n```mermaid\nerDiagram\n    entities ||--o{ edges : source\n    entities ||--o{ edges : target\n    entities ||--o{ embeddings : \"\"\n    entities ||--o{ sources : references\n    sources ||--o{ entities : \"\"\n    \n    entities {\n        string id PK\n        string type\n        string name\n        string canonical_name\n        string scope\n        string owner_id FK\n        string tier\n        float importance\n        datetime valid_from\n        datetime valid_until\n        datetime learned_at\n        datetime unlearned_at\n        datetime created_at\n        datetime last_accessed_at\n        int access_count\n        json attrs\n        string code_file\n        string code_language\n        string code_commit_sha\n    }\n    \n    edges {\n        string id PK\n        string source_id FK\n        string target_id FK\n        string relation_type\n        json attrs\n        datetime valid_from\n        datetime valid_until\n    }\n    \n    embeddings {\n        string id PK\n        string entity_id FK\n        string model_name\n        string model_version\n        int dim\n        blob vector\n    }\n    \n    sources {\n        string id PK\n        string content\n        string mime_type\n    }\n```\n\n### Migration System\n\nThe database uses a migration-based schema evolution system. Migrations are tracked in the `applied_migrations` table to ensure idempotent execution.\n\n| Migration | Purpose |\n|-----------|---------|\n| `0001_initial.sql` | Core schema: entities, edges, sources, embeddings |\n| `0002_v0.2_code.sql` | Code-specific columns: code_file, code_language, code_commit_sha |\n| `0003_views.sql` | Database views for common queries |\n| `0004_agents.sql` | Agent management and scan logging tables |\n\n资料来源：[src/thought/storage/sqlite/migrations/0001_initial.sql](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/migrations/0001_initial.sql) - [0004_agents.sql](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/migrations/0004_agents.sql)\n\n---\n\n## Backend Operations\n\n### Core CRUD Operations\n\n| Operation | Description |\n|-----------|-------------|\n| `upsert_entity()` | Insert or update an entity with identity `(name, scope, owner_id, code_file, code_commit_sha)` |\n| `upsert_edge()` | Insert or update an edge between entities |\n| `find_entity()` | Retrieve entity by ID |\n| `find_code_entity()` | Fast lookup by canonical name with optional code_file/code_commit_sha disambiguation |\n| `list_entities()` | Paginated entity listing with scope filtering |\n\n### Backup and Restore Operations\n\n| Operation | Description |\n|-----------|-------------|\n| `backup_to(path)` | Create SQLite online-backup snapshot |\n| `merge_from(path)` | INSERT-OR-IGNORE rows from backup file |\n| `open_readonly(path)` | Classmethod for read-only inspection of backup files |\n| Auto-backup | Automatic `.bak.<timestamp>` backup before destructive operations |\n\n### WAL Checkpointing\n\nThe backend performs WAL checkpointing on `close()` to ensure backups always see a consistent database state.\n\n资料来源：[src/thought/storage/sqlite/backend.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/backend.py)\n\n---\n\n## Bi-Temporal Data Model\n\nThe storage layer implements bi-temporal tracking, enabling both temporal validity and temporal knowledge queries.\n\n```mermaid\ngraph LR\n    A[valid_from] --> B[Entity Validity Period]\n    B --> C[valid_until]\n    \n    D[learned_at] --> E[Knowledge Period]\n    E --> F[unlearned_at]\n```\n\n| Time Axis | Purpose | Query Use |\n|-----------|---------|-----------|\n| `valid_from` / `valid_until` | Temporal validity | `as_of_kind='valid'` — \"what was true on date X\" |\n| `learned_at` / `unlearned_at` | System knowledge | `as_of_kind='learned'` — \"what did the system know on date X\" |\n\nThis separation allows querying historical states even after facts are corrected.\n\n资料来源：[src/thought/storage/__init__.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/__init__.py)\n\n---\n\n## Code-Specific Features\n\n### Entity Identity for Code\n\nCode entities use a composite identity to prevent method name collisions across files and commits:\n\n```\n(name, scope, owner_id, code_file, code_commit_sha)\n```\n\nThis ensures that `auth.middleware.authenticate_user` and `billing.middleware.authenticate_user` remain distinct entities, and methods from different commits are preserved separately.\n\n### Fast Code Entity Lookup\n\nThe `find_code_entity()` method provides optimized lookup with:\n\n- Primary: exact `canonical_name` match\n- Secondary: `code_file` disambiguation\n- Tertiary: `code_commit_sha` filtering for historical queries\n\n### Call Graph Resolution\n\nThe `call_graph.py` module implements multi-stage resolution:\n\n1. Intra-file qualified match (`file.method`)\n2. Unique qualified suffix match\n3. Cross-file bare-name match\n4. Stub creation for unresolved references\n\n资料来源：[src/thought/ingest/code/call_graph.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/call_graph.py)\n\n---\n\n## CLI Commands\n\nThe storage layer is accessible via the `thought db` command group.\n\n| Command | Description |\n|---------|-------------|\n| `thought db size` | Disk usage of main + WAL + SHM files + entity/edge counts |\n| `thought db flush` | Wipe KB with optional date/scope filters |\n| `thought db backup <file>` | Create SQLite snapshot with optional date filters |\n| `thought db load <file>` | Replace active DB or merge from snapshot |\n| `thought db inspect <file>` | Inspect backup without loading |\n\n```bash\n# Flush entities valid before a date\nthought db flush --before 2025-01-01\n\n# Flush with time-axis filter\nthought db flush --time-axis valid --since 2024-06-01\n\n# Backup with date subset\nthought db backup backup.db --since 2024-01-01\n```\n\n资料来源：[src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n---\n\n## Query Layer Wrappers\n\n### GraphLayer\n\nBase wrapper providing graph traversal operations including:\n\n- Personalized PageRank for ranking entities\n- Transitive reachability queries\n- Edge type filtering\n\n### CodeLayer\n\nSpecialized wrapper for code-specific operations:\n\n| Method | Description |\n|--------|-------------|\n| `callers_of(name)` | Direct callers ranked by PageRank |\n| `callees_of(name)` | Direct callees within package |\n| `impact_set(name)` | Transitive callers (all affected entities) |\n| `defines_in_file(path)` | All entities in a source file |\n\nBoth layers support `as_of=` parameter for historical queries against the bi-temporal git ingest data.\n\n资料来源：[src/thought/layers/graph.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/graph.py), [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n\n---\n\n## Configuration\n\n### Database Path\n\nConfigured via `thought.toml`:\n\n```toml\ndb_path = \".thought/thought.db\"\n```\n\n### Initialization Options\n\n| Option | Default | Description |\n|--------|---------|-------------|\n| `config` | `\"thought.toml\"` | Config file path |\n| `db_path` | `\".thought/thought.db\"` | SQLite database path |\n| `embedder` | `\"auto\"` | Embedder selection |\n| `write_claude_md` | `true` | Generate CLAUDE.md for MCP clients |\n| `quick` | `false` | Skip embedder warmup |\n\n资料来源：[src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n---\n\n## Summary\n\nThe Storage and Database Layer provides THOUGHT's persistent memory through:\n\n1. **SQLite with WAL mode** for reliable concurrent access\n2. **Bi-temporal modeling** for historical queries and fact correction tracking\n3. **Migration-based schema evolution** with idempotent execution\n4. **Code-aware entity identity** preventing cross-file/commits collisions\n5. **Specialized query layers** (GraphLayer, CodeLayer) for semantic and structural queries\n6. **Backup/restore operations** with atomic replacements and auto-backup safety\n\nThis architecture enables the \"second brain\" functionality, allowing agents to recall, query, and analyze information across code, prose, legal, and research domains.\n\n---\n\n<a id='page-memory-model'></a>\n\n## Memory Model and Data Structures\n\n### 相关页面\n\n相关主题：[System Architecture](#page-architecture), [Storage and Database Layer](#page-storage-layer), [Query and Retrieval System](#page-query-system)\n\n<details>\n<summary>Relevant Source Files</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n- [src/thought/ingest/entities.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/entities.py)\n- [src/thought/consolidation/engine.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/consolidation/engine.py)\n- [src/thought/layers/vector.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/vector.py)\n- [src/thought/layers/graph.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/graph.py)\n- [src/thought/layers/temporal.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/temporal.py)\n</details>\n\n# Memory Model and Data Structures\n\n## Overview\n\nThe thought-mcp repository implements a multi-layered memory architecture designed for AI-assisted knowledge management. The memory model combines vector embeddings for semantic search, graph relationships for structural querying, and temporal versioning for historical analysis. This hybrid approach enables both intuitive natural-language recall and precise code-intent queries.\n\nThe core memory system operates as a knowledge base (KB) with bi-temporal semantics, tracking when facts became true (`valid_from`) versus when the system learned them (`learned_at`). This design supports time-travel queries that answer \"what was true on date X\" or \"what did the system know on date X\".\n\n## Architecture Layers\n\nThe memory system is organized into three distinct but interconnected layers:\n\n```mermaid\ngraph TD\n    A[User Input] --> B[Memory Layer]\n    B --> C[Vector Layer]\n    B --> D[Graph Layer]\n    B --> E[Temporal Layer]\n    C --> F[SQLite Backend]\n    D --> F\n    E --> F\n    G[Query/Recall] --> B\n```\n\n### Vector Layer (`src/thought/layers/vector.py`)\n\nThe vector layer handles semantic embedding and similarity search. It stores dense vector representations of entities enabling natural-language recall based on meaning rather than exact keyword matching.\n\n**Core Responsibilities:**\n\n- Embed text content (entity names, signatures, docstrings) into high-dimensional vectors\n- Store embeddings with model metadata (name, version, dimensions)\n- Perform similarity searches against the embedded corpus\n- Support fallback to deterministic embeddings when ML models are unavailable\n\n**Key Components:**\n\n| Component | Purpose |\n|-----------|---------|\n| `VectorStore` | Persists embeddings in SQLite with metadata |\n| `Embedder` | Base protocol for embedding models |\n| `OllamaEmbedder` | Integration with Ollama's `/api/embed` endpoint |\n| `DeterministicEmbedder` | Fallback using hash-based vectors |\n\n资料来源：[src/thought/layers/vector.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/vector.py)\n\n### Graph Layer (`src/thought/layers/graph.py`)\n\nThe graph layer manages entity-relationship data structures and supports Cypher-style traversals. It maintains the structural knowledge of how entities connect to each other.\n\n**Entity Types Supported:**\n\n| Type | Description |\n|------|-------------|\n| `module` | Source file or namespace unit |\n| `class` | Class or type declarations |\n| `function` | Function definitions |\n| `method` | Class methods |\n| `fact` | General knowledge facts |\n| `claim` | Academic/research claims |\n| `source` | Citation or reference |\n| `witness` | Legal testimony statements |\n\n**Edge Relation Types:**\n\n| Relation | Meaning |\n|----------|---------|\n| `IMPORTS` | Module dependency relationship |\n| `INHERITS_FROM` | Class inheritance |\n| `DEFINES` | Container defines a member |\n| `OVERRIDES` | Method overrides parent |\n| `CALLS` | Function invocation |\n| `REFERS_TO` | General reference |\n| `CONTRADICTS` | Logical opposition between facts |\n\n资料来源：[src/thought/layers/graph.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/graph.py)\n\n### Temporal Layer (`src/thought/layers/temporal.py`)\n\nThe temporal layer implements bi-temporal data modeling, tracking both valid time and learned time for all entities. This enables sophisticated time-travel queries and contradiction detection.\n\n**Bi-Temporal Model:**\n\n```mermaid\ngraph LR\n    A[Entity] --> B[valid_from<br/>When fact became true]\n    A --> C[learned_at<br/>When KB learned fact]\n    D[as_of valid] --> E[Historical state query]\n    D --> F[as_of learned<br/>System knowledge query]\n```\n\n**Key Temporal Features:**\n\n- `valid_from`: Timestamp when the fact became true in reality\n- `learned_at`: Timestamp when the system recorded the fact\n- `valid_until`: Optional expiration of fact validity\n- `CONTRADICTS` edges: Automatically surface when facts conflict across time axes\n\n资料来源：[src/thought/layers/temporal.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/temporal.py)\n\n## Core Data Models\n\n### Entity Model (`src/thought/models.py`)\n\nThe base `Entity` model represents all stored knowledge items in the system.\n\n```python\nclass Entity:\n    id: str                    # Unique identifier\n    name: str                  # Canonical name\n    type: str                  # Entity type (see table above)\n    scope: str                  # \"shared\" or \"private\"\n    owner_id: str | None        # Owner for private entities\n    valid_from: datetime        # When fact became true\n    learned_at: datetime        # When system learned it\n    source_ref: str | None      # Reference to source document\n    tier: str                   # \"hot\", \"warm\", \"cold\" (access frequency)\n    attrs: dict                 # Type-specific attributes\n```\n\n**Entity Attributes by Type:**\n\n| Entity Type | Key Attributes |\n|-------------|----------------|\n| `code_*` | `code_file`, `code_language`, `code_commit_sha`, `signature`, `visibility`, `line_start`, `line_end` |\n| `fact` | `predicates`, `unique_predicates`, `source_doc` |\n| `claim` | `citation_key`, `reliability_score` |\n\n资料来源：[src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n\n### Code Entities (`src/thought/ingest/entities.py`)\n\nCode-specific entities extend the base model with language-aware attributes:\n\n```python\nclass CodeEntity:\n    name: str\n    type_: str                  # \"module\", \"class\", \"function\", \"method\"\n    language: str               # \"python\", \"typescript\", \"rust\", \"php\"\n    file_path: str\n    line_start: int\n    line_end: int\n    signature: str              # Function/class signature\n    visibility: str             # \"public\", \"private\", \"protected\"\n    docstring: str | None\n    attrs: dict                 # Language-specific (e.g., `class` for methods)\n```\n\n### Edge Model (`src/thought/ingest/entities.py`)\n\nRelationships between entities are modeled as typed, directed edges:\n\n```python\nclass CodeEdge:\n    source_name: str             # Origin entity\n    target_name: str             # Destination entity\n    relation_type: str          # IMPORTS, DEFINES, INHERITS_FROM, etc.\n    line_number: int | None\n    attrs: dict\n```\n\n资料来源：[src/thought/ingest/entities.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/entities.py)\n\n## Consolidation Engine (`src/thought/consolidation/engine.py`)\n\nThe consolidation engine handles fact deduplication, merging, and contradiction detection. It processes incoming data through a pipeline that ensures data quality and consistency.\n\n```mermaid\ngraph TD\n    A[Raw Input] --> B[Jaccard Deduplication]\n    B --> C[Fact Extraction]\n    C --> D[Predicate Matching]\n    D --> E{Conflict?}\n    E -->|Yes| F[Create CONTRADICTS Edge]\n    E -->|No| G[Merge into KB]\n    F --> G\n```\n\n**Consolidation Pipeline Steps:**\n\n1. **Jaccard Deduplication**: Skip content with >50% overlap to existing facts\n2. **Fact Extraction**: Parse structured predicates from unstructured text\n3. **Predicate Matching**: Match against existing knowledge using unique predicates\n4. **Contradiction Detection**: Create `CONTRADICTS` edges when facts conflict\n5. **Entity Merging**: Upsert with identity `(name, code_file, code_commit_sha)`\n\n资料来源：[src/thought/consolidation/engine.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/consolidation/engine.py)\n\n## Storage Backend\n\nThe system uses SQLite as its primary storage engine with the following schema:\n\n```mermaid\ngraph TD\n    A[SQLite Database] --> B[entities table]\n    A --> C[edges table]\n    A --> D[embeddings table]\n    A --> E[applied_migrations table]\n    B --> F[code_file<br/>code_language<br/>code_commit_sha]\n    C --> G[relation_type<br/>source_name<br/>target_name]\n    D --> H[model_name<br/>model_version<br/>vector BLOB]\n```\n\n**Key Backend Classes:**\n\n| Class | Responsibility |\n|-------|----------------|\n| `Backend` | Core CRUD operations on entities/edges |\n| `find_code_entity()` | Fast lookup by name + file/commit disambiguators |\n| `upsert_entity()` | Insert or update with identity awareness |\n| `store_embedding()` | Persist vectors with model metadata |\n\n资料来源：[src/thought/storage/sqlite/backend.py](src/thought/storage/sqlite/backend.py) (inferred from CHANGELOG.md)\n\n## Query Pathways\n\nThe memory system supports multiple query mechanisms:\n\n### Recall (Vector Search)\n\n```python\ndef recall(\n    query: str,\n    scope: str = \"all\",\n    owner_id: str | None = None,\n    max_results: int = 10,\n) -> list[RecallResult]\n```\n\nReturns up to 10 semantically similar entities based on embedding similarity.\n\n### Ask (Natural Language to Cypher)\n\nRoutes natural-language questions through an LLM to generate Cypher queries:\n\n```\nQUESTION: \"who calls authenticate_user\"\n→ CYPHER: MATCH (caller)-[:CALLS]->(f:Function {name: 'authenticate_user'}) \n          RETURN caller.name\n```\n\n资料来源：[src/thought/query/ask.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n\n### Code Intelligence Queries\n\n| Command | Purpose |\n|---------|---------|\n| `thought callers <name>` | Direct callers via Personalized PageRank |\n| `thought impact <name>` | Transitive impact set (what breaks if changed) |\n| `thought diff --from SHA1 --to SHA2` | Entity diff between commits |\n\n## Ingest Pipelines\n\nCode ingestion follows a standardized pipeline:\n\n```mermaid\ngraph TD\n    A[Source File] --> B[Language Detection]\n    B --> C[AST Parser<br/>tree-sitter]\n    C --> D[Extractor<br/>Language-specific]\n    D --> E[CodeEntity list]\n    D --> F[CodeEdge list]\n    E --> G[Embedding]\n    G --> H[Backend upsert]\n    F --> H\n    H --> I[Call Graph Builder<br/>optional]\n```\n\n**Supported Languages:**\n\n- Python (`.py`) - via tree-sitter-python\n- TypeScript (`.ts`, `.tsx`) - via tree-sitter-typescript\n- Rust (`.rs`) - via tree-sitter-rust\n- PHP (`.php`) - via tree-sitter-php\n\n**Extracted Metadata:**\n\n- Module/namespace names\n- Class declarations with heritage (extends, implements)\n- Function and method definitions\n- Import/use declarations\n- Visibility modifiers (public, private, protected)\n\n资料来源：[src/thought/ingest/code/python_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/python_extractor.py), [src/thought/ingest/code/typescript_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/typescript_extractor.py)\n\n## Auto-Memory Hooks\n\nThe system integrates with Claude Code via hooks for automatic memory management:\n\n| Hook | Event | Action |\n|------|-------|--------|\n| `recall` | `UserPromptSubmit` | Embeds prompt, recalls relevant context |\n| `write` | `Stop` | Extracts facts from session transcript |\n| `context` | `SessionStart` | Loads relevant context for new session |\n\n资料来源：[src/thought/hooks/install.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n\n## Versioning and Snapshots\n\nThe storage layer supports full database lifecycle management:\n\n| Operation | Description |\n|-----------|-------------|\n| `db size` | Disk usage + entity/edge counts |\n| `db flush` | Wipe KB with date-bounded options |\n| `db backup <file>` | SQLite online backup snapshot |\n| `db load <file>` | Restore or merge from snapshot |\n| `db inspect <file>` | Preview backup without loading |\n\nWAL (Write-Ahead Logging) checkpoints ensure consistent backups.\n\n## Summary\n\nThe thought-mcp memory model implements a production-grade knowledge management system with:\n\n1. **Three-layer architecture**: Vector for semantics, Graph for structure, Temporal for history\n2. **Bi-temporal semantics**: Tracks both validity and knowledge acquisition times\n3. **Code-aware extraction**: AST-based parsing for multiple programming languages\n4. **Contradiction detection**: Automatic `CONTRADICTS` edges between conflicting facts\n5. **Multiple query pathways**: Semantic recall, natural-language Cypher, and code-intelligence commands\n6. **Git-aware versioning**: Commits can be stamped on entities for historical queries\n\nThis architecture enables sophisticated AI memory capabilities while maintaining query performance through strategic use of SQLite with proper indexing.\n\n---\n\n<a id='page-query-system'></a>\n\n## Query and Retrieval System\n\n### 相关页面\n\n相关主题：[Memory Model and Data Structures](#page-memory-model), [Storage and Database Layer](#page-storage-layer), [Agent Adapters and SDK Integration](#page-agent-adapters)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/query/__init__.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/__init__.py)\n- [src/thought/query/ask.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n- [src/thought/query/cypher.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/cypher.py)\n- [src/thought/query/views.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/views.py)\n- [src/thought/hooks/recall.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/recall.py)\n</details>\n\n# Query and Retrieval System\n\nThe Query and Retrieval System is a core subsystem within the thought-mcp project that enables users to query the knowledge graph using natural language. It translates human-readable questions into structured Cypher queries or SQL statements, executes them against the underlying SQLite backend, and returns ranked, relevant results. The system serves as the primary interface for retrieving facts, code entities, relationships, and historical data stored in the memory database.\n\n## Architecture Overview\n\nThe Query and Retrieval System is composed of several interconnected modules that work together to process, route, and execute queries. At its core, the system leverages a Router to classify incoming queries into semantic categories, then delegates processing to specialized handlers based on the query type.\n\n```mermaid\ngraph TD\n    A[User Query] --> B[Router]\n    B --> C{Code Query?}\n    B --> D{Natural Language?}\n    B --> E{Search Query?}\n    C --> F[Code Layer]\n    D --> G[Ask Module]\n    G --> H[Cypher Translator]\n    H --> I[Query Validator]\n    I --> J[SQLite Backend]\n    E --> K[Recall Hook]\n    K --> J\n    J --> L[Results]\n    F --> L\n```\n\nThe system follows a layered approach where queries are first classified by intent, then transformed into appropriate database queries. Natural language queries are translated to Cypher through an LLM-based translator, while code-specific queries bypass translation and directly execute predefined graph traversal operations.\n\n## Query Classification\n\nThe Router module plays a critical role in determining how each query should be processed. Based on keyword detection and pattern matching, queries are classified into distinct types that trigger different handling paths.\n\n### Query Types\n\n| Query Type | Trigger Keywords | Handler | Use Case |\n|------------|------------------|---------|----------|\n| CODE | `function`, `class`, `caller`, `callee`, `impact`, file extensions, camelCase identifiers | CodeLayer | Code graph traversal |\n| CHANGE | `since v1.0`, `before this commit`, `diff` | GitIngestReport | Version-aware queries |\n| HYBRID | CODE × CHANGE combinations | GraphLayer + GitWalker | Historical code analysis |\n| SEARCH | General text | Recall Hook | Semantic search |\n| ASK | Natural language questions | Ask Module | Natural language to Cypher |\n\n资料来源：[src/thought/query/ask.py:1-30](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n\n### CODE Query Detection\n\nThe CODE query class is triggered by code-shaped keywords and identifier patterns. This includes function names, class declarations, caller/callee relationships, file extensions such as `.py` or `.ts`, and version-related phrases like `since v1.0` or `before this commit`. Additionally, camelCase and snake_case identifiers automatically route to the CODE handler, enabling queries like \"who calls authenticate_user\" to be processed through the call-graph machinery without explicit CLI invocation.\n\n资料来源：[src/thought/query/ask.py:1-30](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n\n## Natural Language to Cypher Translation\n\nThe Ask module (`src/thought/query/ask.py`) is responsible for translating natural language questions into Cypher queries. This translation is performed by an LLM provider configured in the `[llm]` section of the configuration file, supporting multiple backends through a unified interface.\n\n### Translation Process\n\n```mermaid\nsequenceDiagram\n    participant U as User\n    participant A as Ask Module\n    participant L as LLM Provider\n    participant V as Cypher Validator\n    participant B as SQLite Backend\n    \n    U->>A: \"What functions call authenticate_user?\"\n    A->>A: Build Prompt with Schema\n    A->>L: Send Prompt\n    L-->>A: Cypher Query\n    A->>V: Validate Cypher\n    alt Valid\n        V->>B: Execute Query\n        B-->>V: Results\n        V-->>U: Ranked Results\n    else Invalid\n        A->>A: Fallback to Recall\n        A-->>U: Semantic Search Results\n    end\n```\n\nThe translation process begins with constructing a prompt that includes the database schema, entity types, and relationship types. The LLM generates a Cypher query that is then validated against a parser before execution. If validation fails or the query cannot be executed, the system gracefully falls back to a plain `recall()` call, ensuring the user always receives some response.\n\n### Prompt Constraints\n\nThe Ask module enforces strict constraints on generated queries to maintain system safety and performance:\n\n- Only read-only Cypher features are permitted, including `MATCH`, `WHERE`, `RETURN`, `LIMIT`, and `AS_OF`\n- Query types are restricted to `MERGE`, `CREATE`, `DELETE`, `SET`, and `WITH` being explicitly forbidden\n- All entity types and relationship types must come from the defined schema\n- Single Cypher queries are required without explanations or markdown formatting\n\n资料来源：[src/thought/query/ask.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n\n### AskResult Data Model\n\nThe `AskResult` dataclass encapsulates the outcome of a query translation and execution attempt:\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `cypher` | `str \\| None` | The generated Cypher query |\n| `sql` | `str \\| None` | Alternative SQL query if applicable |\n| `rows` | `list[dict[str, Any]] \\| None` | Query results |\n| `fallback_used` | `bool` | Whether fallback to recall was triggered |\n| `fallback_reason` | `str` | Explanation if fallback occurred |\n\n资料来源：[src/thought/query/ask.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n\n## Recall Hook\n\nThe recall hook (`src/thought/hooks/recall.py`) provides semantic search functionality as a fallback mechanism and primary retrieval method. It uses embedding vectors to find semantically similar entities in the knowledge graph, supporting the core recall operation used throughout the system.\n\n### Recall Behavior\n\nRecall operations are bounded by design to prevent overwhelming the user with too many results. The system never returns more than 10 hits regardless of knowledge base size, encouraging users to narrow their queries using `as_of` and `scope` parameters for more targeted retrieval.\n\nThe recall mechanism supports bi-temporal queries through the `as_of_kind` parameter:\n\n- `valid`: Returns what was true on a given date, answering \"what was true on date X\"\n- `learned`: Returns what the system knew on a given date, answering \"what did the system know on date X\"\n\nThese two modes differ when facts are corrected after the fact, enabling users to perform historical analysis of their knowledge graph.\n\n资料来源：[src/thought/query/views.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/views.py)\n\n## Code Layer\n\nThe Code Layer (`src/thought/layers/code.py`) provides a specialized interface for code-specific graph queries. It wraps the GraphLayer with operations native to programmers, operating against the currently-valid view of the code graph using the `valid_until IS NULL` filter.\n\n### Core Operations\n\n| Method | Description | Use Case |\n|--------|-------------|----------|\n| `callers_of(name)` | Direct callers ranked by PageRank | Finding who uses a function |\n| `callees_of(name)` | Direct callees within the package | Finding what a function calls |\n| `impact_set(name)` | Transitive callers ranked | Dependency analysis |\n| `defines_in_file()` | All entities in a file | File-level inspection |\n\nAll four operations support optional `as_of` parameters to query historical snapshots when bi-temporal git ingest has been configured. The `code_commit_sha` field enables time-travel queries against the code graph.\n\n资料来源：[src/thought/layers/code.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n\n### Entity Resolution\n\nThe `_resolve_entity_id` method handles name resolution with multiple fallback strategies:\n\n1. Intra-file match with exact name\n2. Cross-file match with unique qualified suffix\n3. Cross-file bare-name match for top-level functions\n4. Stub creation for unresolved references\n\nThis multi-stage resolution ensures that queries like `obj.method()` can resolve to `ClassName.method` when it is unique in the knowledge base, and that bare function names can be found across different files.\n\n资料来源：[src/thought/query/cypher.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/cypher.py)\n\n## Cypher Query Engine\n\nThe Cypher module (`src/thought/query/cypher.py`) handles the parsing, validation, and execution of Cypher queries against the SQLite backend. It provides a bridge between the graph query language and the relational database storage.\n\n### Query Validation\n\nBefore executing any Cypher query, the system validates it against the defined grammar to prevent malformed queries from reaching the database. This validation step catches syntax errors, unsupported features, and schema violations before they can cause runtime errors.\n\n### Execution Model\n\nCypher queries are translated into equivalent SQL statements that operate against the SQLite schema. The translation preserves the semantic meaning of graph patterns while adapting them to the relational storage model used by the backend.\n\n## Views and Data Models\n\nThe views module (`src/thought/query/views.py`) defines the data structures and return formats used throughout the Query and Retrieval System.\n\n### Entity Model\n\nThe `Entity` model represents nodes in the knowledge graph with the following key attributes:\n\n| Attribute | Type | Description |\n|-----------|------|-------------|\n| `id` | `str` | Unique identifier |\n| `type` | `str` | Entity type (PERSON, function, class, etc.) |\n| `name` | `str` | Display name |\n| `canonical_name` | `str` | Normalized name for matching |\n| `scope` | `ScopeName` | shared, private, or all |\n| `tier` | `Tier` | hot, warm, or cold |\n| `valid_from` | `datetime` | Start of validity period |\n| `valid_until` | `datetime \\| None` | End of validity period |\n| `attrs` | `dict[str, object]` | Additional attributes |\n\n### Scope Filter\n\nThe `ScopeFilter` class determines visibility of entities based on ownership and scope:\n\n- `shared`: All entities with scope = \"shared\"\n- `private`: Entities matching both scope = \"private\" AND owner_id\n- `all`: Shared entities plus private entities owned by the requesting user\n\nThe scope filter generates SQL fragments that join against the entity table aliased as `e`, enabling fine-grained access control across the query system.\n\n资料来源：[src/thought/models.py:1-80](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n\n## CLI Commands\n\nThe Query and Retrieval System is exposed through several CLI commands under the `thought` command group:\n\n| Command | Description |\n|---------|-------------|\n| `thought recall <query>` | Semantic search across the knowledge graph |\n| `thought ask <question>` | Natural language query with Cypher translation |\n| `thought callers <name>` | Find direct callers ranked by PageRank |\n| `thought callees <name>` | Find direct callees within the package |\n| `thought impact <name>` | Transitive impact set analysis |\n| `thought browse <name>` | Drill into a topic with PPR-ranked neighborhood |\n| `thought diff --from <sha1> --to <sha2>` | Compare entities between commits |\n\n### Browse Command\n\nThe browse command (`mcp__thought__browse_topic`) implements a two-step resolution process. First, the name is matched against entity types for a type facet. If no type matches, the name is resolved as an entity using canonical-name matching, and the PPR-ranked neighborhood is returned. The `via` field in results indicates whether the hit came from `type_facet`, `ppr`, or `bfs` matching.\n\n资料来源：[src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n## Configuration\n\nThe Query and Retrieval System respects configuration from the `thought.toml` file and environment variables:\n\n| Option | Default | Description |\n|--------|---------|-------------|\n| `embedder` | `auto` | Embedder selection: auto, sentence-transformers, or deterministic |\n| `llm.provider` | `openai` | LLM provider for Ask module |\n| `llm.model` | varies | Model name for translation |\n| `db_path` | `.thought/thought.db` | SQLite database path |\n\nThe `auto` embedder selector probes the `sentence_transformers` package via `importlib.util.find_spec` before returning the wrapper, falling back to the deterministic embedder when the optional dependency is missing.\n\n## Integration Points\n\nThe Query and Retrieval System integrates with several other subsystems:\n\n- **Storage Layer**: SQLite backend provides entity and edge persistence\n- **Ingest System**: Code extractors populate entities that are later queried\n- **Memory Module**: Coordinates between recall, browse, and scan operations\n- **Server**: Exposes query functionality via MCP protocol\n\nThe bidirectional relationship between the Code Layer and the Cypher query engine enables both natural language queries like \"who calls authenticate_user\" and structured queries using the CODE query class, providing flexibility for different user interaction patterns.\n\n## Error Handling\n\nThe system implements graceful degradation throughout the query pipeline. If Cypher translation fails or validation rejects the generated query, execution falls back to the recall hook, ensuring users always receive results. Bounded result sets prevent resource exhaustion, and the contradiction detection mechanism surfaces conflicts as `CONTRADICTS` edges in the graph rather than throwing errors, allowing downstream applications to handle them as data.\n\n---\n\nThis documentation reflects the Query and Retrieval System as implemented in thought-mcp, providing the foundation for natural language interaction with the code knowledge graph.\n\n---\n\n<a id='page-code-parsing'></a>\n\n## Multi-Language Code Parsing\n\n### 相关页面\n\n相关主题：[Git History Integration](#page-git-integration), [Storage and Database Layer](#page-storage-layer)\n\n<details>\n<summary>Related Source Files</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/ingest/code/__init__.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/__init__.py)\n- [src/thought/ingest/code/ast_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/ast_extractor.py)\n- [src/thought/ingest/code/call_graph.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/call_graph.py)\n- [src/thought/ingest/code/pipeline.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/pipeline.py)\n- [src/thought/ingest/code/python_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/python_extractor.py)\n- [src/thought/ingest/code/typescript_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/typescript_extractor.py)\n- [src/thought/ingest/code/go_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/go_extractor.py)\n- [src/thought/ingest/code/rust_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/rust_extractor.py)\n- [src/thought/ingest/code/java_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/java_extractor.py)\n- [src/thought/ingest/code/php_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/php_extractor.py)\n- [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n</details>\n\n# Multi-Language Code Parsing\n\nThe Multi-Language Code Parsing system is the foundational code-vertical layer in THOUGHT. It provides language-agnostic AST extraction across six programming languages using tree-sitter grammars, produces standardized code entities and relationship edges, and enables downstream features like caller analysis, impact queries, and cross-file call-graph resolution.\n\n## Overview\n\nThe parsing system operates in two phases:\n\n1. **Phase 1 – AST Extraction**: Each language has a dedicated extractor that walks the tree-sitter parse tree and emits `CodeEntity` and `CodeEdge` objects.\n2. **Phase 2 – Call Graph Resolution**: After all files are ingested, a separate pass resolves `CALLS` edges by matching callee names against the entity index.\n\n资料来源：[src/thought/ingest/code/ast_extractor.py:1-15]()\n\n## Supported Languages\n\nThe system supports six languages through language-specific extractors:\n\n| Language | Extractor File | Tree-sitter Grammar |\n|----------|----------------|---------------------|\n| Python | `python_extractor.py` | `tree-sitter-python` |\n| TypeScript / TSX / JSX | `typescript_extractor.py` | `tree-sitter-typescript` |\n| Go | `go_extractor.py` | `tree-sitter-go` |\n| Rust | `rust_extractor.py` | `tree-sitter-rust` |\n| Java | `java_extractor.py` | `tree-sitter-java` |\n| PHP | `php_extractor.py` | `tree-sitter-php` |\n\n资料来源：[src/thought/ingest/code/ast_extractor.py:30-55]()\n\n## Architecture\n\n```mermaid\ngraph TD\n    A[Code File] --> B[Language Detection]\n    B --> C[ast_extractor.py Dispatcher]\n    C --> D{Python?}\n    C --> E{TypeScript?}\n    C --> F{Go?}\n    C --> G{Rust?}\n    C --> H{Java?}\n    C --> I{PHP?}\n    D --> J[python_extractor.extract]\n    E --> K[typescript_extractor.extract]\n    F --> L[go_extractor.extract]\n    G --> M[rust_extractor.extract]\n    H --> N[java_extractor.extract]\n    I --> O[php_extractor.extract]\n    J --> P[(CodeEntity, CodeEdge)]\n    K --> P\n    L --> P\n    M --> P\n    N --> P\n    O --> P\n    P --> Q[CodeIngestPipeline]\n    Q --> R[build_call_graph]\n    R --> S[(CALLS Edges)]\n```\n\n### Dispatcher Pattern\n\nThe `ast_extractor.py` module uses lazy loading to avoid importing heavy tree-sitter C extensions at module load time:\n\n```python\n_REGISTRY: dict[str, Callable[[str, str], tuple[list[CodeEntity], list[CodeEdge]]]] = {}\n\ndef _python_extractor():\n    from . import python_extractor\n    return python_extractor.extract\n```\n\nEach language loader is registered in `_LOADERS` and invoked only when that language is first requested. 资料来源：[src/thought/ingest/code/ast_extractor.py:9-35]()\n\n## Data Models\n\n### CodeEntity\n\nRepresents a code element extracted from the AST:\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `name` | `str` | Canonical identifier (module, function, class, method) |\n| `type_` | `str` | Entity kind: `module`, `function`, `class`, `method` |\n| `language` | `str` | Source language: `python`, `typescript`, `go`, `rust`, `java`, `php` |\n| `file_path` | `str` | Path to source file (relative to repo root) |\n| `line_start` | `int` | 1-indexed start line |\n| `line_end` | `int` | 1-indexed end line |\n| `signature` | `str` | Declaration signature (e.g., `module foo`, `def bar(self, x)`) |\n| `docstring` | `str \\| None` | Extracted docstring text |\n| `visibility` | `str` | `public` or `private` based on naming conventions |\n| `attrs` | `dict` | Language-specific metadata |\n\n资料来源：[src/thought/ingest/code/python_extractor.py:14-25]()\n\n### CodeEdge\n\nRepresents a relationship between entities:\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `source_name` | `str` | Entity that is the subject of the relation |\n| `target_name` | `str` | Entity that is the object of the relation |\n| `relation_type` | `str` | One of: `IMPORTS`, `INHERITS_FROM`, `DEFINES`, `OVERRIDES`, `CALLS` |\n| `line_number` | `int` | Source line where the relationship was discovered |\n| `attrs` | `dict` | Additional metadata (e.g., `from_import: true`) |\n\n资料来源：[src/thought/ingest/code/typescript_extractor.py:110-115]()\n\n## Extractor Interface\n\nAll language extractors share a common signature:\n\n```python\ndef extract(source: str, file_path: str) -> tuple[list[CodeEntity], list[CodeEdge]]:\n    ...\n```\n\nThis uniform interface allows the dispatcher to route to any language without knowing implementation details. 资料来源：[src/thought/ingest/code/python_extractor.py:28-40]()\n\n## Supported Edge Types\n\n| Relation | Source | Target | Languages |\n|----------|--------|--------|-----------|\n| `IMPORTS` | module | imported module | Python, TypeScript, PHP, Go, Rust, Java |\n| `INHERITS_FROM` | class | parent class | Python, TypeScript, Java, PHP |\n| `DEFINES` | class/module | contained member | All languages |\n| `OVERRIDES` | method | overridden method | TypeScript (currently) |\n| `CALLS` | function/method | called function | All (via call-graph pass) |\n\n资料来源：[src/thought/ingest/code/python_extractor.py:1-15](), [src/thought/ingest/code/typescript_extractor.py:1-20]()\n\n## Language-Specific Extractors\n\n### Python Extractor\n\nThe Python extractor uses `tree-sitter-python` and handles:\n\n- Module entities as the root node\n- Function definitions (`function_item`)\n- Class declarations (`class_declaration`)\n- Method definitions within classes\n- Import statements (`import_from_statement`, `import_statement`)\n- Class inheritance via `base` field\n\n```python\ndef extract(source: str, file_path: str) -> tuple[list[CodeEntity], list[CodeEdge]]:\n    parser = _get_parser()\n    source_bytes = source.encode(\"utf-8\")\n    tree = parser.parse(source_bytes)\n    root = tree.root_node\n\n    module_name = _module_name_from_path(file_path)\n    entities: list[CodeEntity] = []\n    edges: list[CodeEdge] = []\n\n    entities.append(CodeEntity(\n        name=module_name,\n        type_=\"module\",\n        language=\"python\",\n        ...\n    ))\n```\n\n资料来源：[src/thought/ingest/code/python_extractor.py:28-50]()\n\n### TypeScript Extractor\n\nThe TypeScript extractor supports both `.ts` and `.tsx` files using separate tree-sitter grammars:\n\n```python\ndef extract(source: str, file_path: str) -> tuple[list[CodeEntity], list[CodeEdge]]:\n    use_tsx = file_path.endswith((\".tsx\", \".jsx\"))\n    parser = _get_parser(use_tsx=use_tsx)\n    ...\n```\n\nNode types processed include `function_declaration`, `arrow_function`, `class_declaration`, `method_definition`, `import_statement`, and `export_statement`. 资料来源：[src/thought/ingest/code/typescript_extractor.py:120-145]()\n\n### PHP Extractor\n\nThe PHP extractor handles files starting with `<?php` and recursively scans for definitions nested under `namespace_definition` blocks:\n\n```python\ndef _scan(node: Node) -> None:\n    for child in node.named_children:\n        ...\n```\n\n资料来源：[src/thought/ingest/code/php_extractor.py:45-60]()\n\n### Rust Extractor\n\nThe Rust extractor uses `tree-sitter-rust` and tracks method visibility through `impl_type` attributes:\n\n```python\nout_entities.append(CodeEntity(\n    name=qualified, type_=\"method\", language=\"rust\",\n    visibility=_rust_visibility(child, source_bytes),\n    attrs={\"impl_type\": type_name},\n))\n```\n\n资料来源：[src/thought/ingest/code/rust_extractor.py:1-30]()\n\n## Call Graph Resolution\n\nThe call graph is built in a separate Phase 2 pass after all files are ingested. The `build_call_graph` function resolves callee references using a cascade of strategies:\n\n1. **Exact match within same file** — direct intra-file resolution\n2. **Qualified suffix match** — `obj.method()` resolves to `ClassName.method`\n3. **Cross-file bare-name match** — top-level functions defined elsewhere\n4. **Stub creation** — synthetic stub for unknown callees (filtered from impact graphs)\n\n```python\ntgt_id = backend.find_code_entity(\n    canonical_name=callee_name, scope_filter=sf, code_file=file_path,\n)\nif tgt_id is None and \".\" not in callee_name:\n    # Unique qualified suffix match.\n    rows = backend._conn.execute(\n        \"SELECT id FROM entities \"\n        \"WHERE type IN ('method','function') AND valid_until IS NULL \"\n        \"AND canonical_name LIKE ? ...\",\n        (f\"%.{callee_name.lower()}\", commit_sha),\n    ).fetchall()\n```\n\n资料来源：[src/thought/ingest/code/call_graph.py:1-60]()\n\n## CodeIngestPipeline\n\nThe `CodeIngestPipeline` orchestrates the full ingest workflow:\n\n1. Reads source file content\n2. Detects or validates language\n3. Calls the appropriate extractor\n4. Creates a source reference record\n5. Writes entities within a single transaction\n6. Embeds entity signatures and docstrings for VIBE recall\n7. Writes edges and resolves call graph\n\n```mermaid\ngraph LR\n    A[Source File] --> B[detect_language]\n    B --> C[extract entities/edges]\n    C --> D[upsert_source]\n    D --> E[begin transaction]\n    E --> F[_write_entities + embed]\n    F --> G[_write_edges]\n    G --> H[build_call_graph]\n    H --> I[commit]\n```\n\nThe pipeline embeds entity signatures and docstrings so that queries like \"who calls authenticate_user\" can find functions by intent rather than exact name. 资料来源：[src/thought/ingest/code/pipeline.py:1-80]()\n\n## CodeLayer API\n\nThe `CodeLayer` provides a high-level interface for code graph queries:\n\n| Method | Description |\n|--------|-------------|\n| `callers_of(name)` | Direct callers, ranked by Personalized PageRank |\n| `callees_of(name)` | Direct callees (intra-package) |\n| `impact_set(name)` | Transitive callers, ranked — for `thought impact` command |\n| `defines_in_file(path)` | All entities discovered in a file |\n\nAll methods operate against the currently-valid view (`valid_until IS NULL`). Pass `as_of=` for historical snapshots. 资料来源：[src/thought/layers/code.py:1-40]()\n\n## Git-Aware Ingest\n\nThe `GitWalker` enables two ingestion modes:\n\n| Mode | Behavior |\n|------|----------|\n| `snapshot` (default) | Ingest HEAD only, stamp every entity with HEAD SHA |\n| `full` | Walk every commit chronologically, stamp each entity with its commit SHA |\n\nThis enables bi-temporal `as_of` queries against historical commits. 资料来源：[src/thought/ingest/code/git_pipeline.py:1-50]()\n\n## Configuration\n\nLanguage is auto-detected by file extension when `language=None`:\n\n| Extension | Language |\n|-----------|----------|\n| `.py` | `python` |\n| `.ts`, `.tsx`, `.js`, `.jsx` | `typescript` |\n| `.go` | `go` |\n| `.rs` | `rust` |\n| `.java` | `java` |\n| `.php` | `php` |\n\nPass `language=` explicitly to override detection. 资料来源：[src/thought/ingest/code/pipeline.py:25-35]()\n\n---\n\n<a id='page-git-integration'></a>\n\n## Git History Integration\n\n### 相关页面\n\n相关主题：[Multi-Language Code Parsing](#page-code-parsing), [Memory Model and Data Structures](#page-memory-model)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/ingest/code/git_pipeline.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/git_pipeline.py)\n- [src/thought/ingest/code/git_walker.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/git_walker.py)\n- [src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n- [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n- [CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n</details>\n\n# Git History Integration\n\n## Overview\n\nGit History Integration enables thought-mcp to ingest source code with full commit-level provenance, allowing bi-temporal queries that can reconstruct what a codebase looked like at any point in its history. This feature stamps every extracted code entity (functions, classes, modules) with the exact git commit SHA where it was discovered, creating a temporal graph that supports \"as-of\" queries.\n\nThe system provides two ingestion modes: a fast **snapshot mode** for current-state analysis and a comprehensive **full-history mode** for complete historical reconstruction.\n\n资料来源：[CHANGELOG.md]()\n\n## Architecture\n\n### Component Overview\n\n```mermaid\ngraph TD\n    subgraph \"Git History Integration\"\n        CLI[\"thought ingest-git CLI\"]\n        Pipeline[\"GitIngestPipeline\"]\n        Walker[\"GitWalker\"]\n        Storage[\"SQLite Backend\"]\n    end\n    \n    subgraph \"Git Operations\"\n        Git[\"git executable\"]\n        RevParse[\"rev-parse HEAD\"]\n        Log[\"log --format\"]\n        LsTree[\"ls-tree -r\"]\n        Show[\"show <sha>:<path>\"]\n    end\n    \n    CLI --> Pipeline\n    Pipeline --> Walker\n    Walker --> Git\n    Git --> RevParse\n    Git --> Log\n    Git --> LsTree\n    Git --> Show\n    Pipeline --> Storage\n```\n\n### Data Flow\n\n```mermaid\nsequenceDiagram\n    participant User\n    participant CLI\n    participant Pipeline\n    participant Walker\n    participant Extractor\n    participant Backend\n    \n    User->>CLI: thought ingest-git /repo --mode full\n    CLI->>Pipeline: run(repo_path, mode)\n    \n    alt snapshot mode\n        Pipeline->>Walker: get_head_commit()\n        Walker->>Git: rev-parse HEAD\n        Git-->>Walker: sha\n        Pipeline->>Pipeline: ingest single snapshot\n    else full mode\n        Pipeline->>Walker: get_all_commits()\n        Walker->>Git: log --format\n        Git-->>Walker: commit list\n        Loop for each commit\n            Pipeline->>Git: ls-tree -r sha\n            Pipeline->>Git: show sha:path\n            Git-->>Pipeline: file content\n            Pipeline->>Extractor: extract(entities, edges)\n            Extractor-->>Pipeline: CodeEntity[], CodeEdge[]\n            Pipeline->>Backend: upsert with commit_sha\n        end\n    end\n    \n    Pipeline-->>User: GitIngestReport\n```\n\n资料来源：[src/thought/ingest/code/git_pipeline.py:1-95]()\n资料来源：[src/thought/ingest/code/git_walker.py:1-60]()\n\n## Core Components\n\n### GitWalker\n\nThe `GitWalker` class provides a read-only interface to git repositories using pure subprocess calls. It deliberately avoids native dependencies like `pygit2` to minimize installation footprint.\n\n| Method | Git Command | Purpose |\n|--------|-------------|---------|\n| `get_head_sha()` | `rev-parse HEAD` | Get current HEAD commit SHA |\n| `get_all_commits()` | `log --format=...` | List all commits chronologically |\n| `get_files_at_commit(sha)` | `ls-tree -r <sha>` | List files in tree at commit |\n| `get_file_at_commit(sha, path)` | `show <sha>:<path>` | Get file content at commit |\n\n#### Commit Data Model\n\n```python\n@dataclass(frozen=True)\nclass Commit:\n    sha: str                    # Full commit SHA\n    author: str                 # Author name\n    author_email: str           # Author email\n    author_date: datetime      # Commit timestamp\n    subject: str                # Commit message first line\n```\n\n资料来源：[src/thought/ingest/code/git_walker.py:24-31]()\n\n#### Initialization Validation\n\n```python\ndef __init__(self, repo_path: Path | str) -> None:\n    self.repo = Path(repo_path)\n    if shutil.which(\"git\") is None:\n        raise RuntimeError(\"git executable not on PATH\")\n    if not (self.repo / \".git\").exists():\n        raise ValueError(f\"not a git repository: {self.repo}\")\n```\n\nThe walker validates that:\n1. The `git` executable exists on PATH\n2. The target path is a valid git repository (contains `.git` directory)\n\n资料来源：[src/thought/ingest/code/git_walker.py:35-42]()\n\n### GitIngestPipeline\n\nThe pipeline orchestrates the complete ingestion process, coordinating between git history traversal and code extraction.\n\n| Parameter | Type | Description |\n|-----------|------|-------------|\n| `repo_path` | `Path` | Path to git repository |\n| `mode` | `GitMode` | `\"snapshot\"` (HEAD only) or `\"full\"` (all commits) |\n| `patterns` | `tuple[str, ...]` | Glob patterns to filter files (e.g., `*.py`) |\n\n#### Ingestion Report\n\n```python\n@dataclass(frozen=True)\nclass GitIngestReport:\n    head_sha: str           # SHA of HEAD at time of ingest\n    mode: GitMode           # Mode used for ingestion\n    commits_visited: int    # Number of commits processed\n    files_ingested: int     # Total files ingested\n    call_edges: int         # Call graph edges created\n```\n\n资料来源：[src/thought/ingest/code/git_pipeline.py:35-41]()\n\n## Ingestion Modes\n\n### Snapshot Mode (Default)\n\nSnapshot mode ingests only the current HEAD commit. This is the recommended mode for:\n\n- Initial repository ingestion\n- Quick code analysis workflows\n- When historical queries are not needed\n\n**Performance characteristics:**\n- Single-pass through current tree\n- No duplicate processing\n- Typical runtime: seconds to minutes depending on repository size\n\n**Entity stamping:**\nAll extracted entities receive the HEAD SHA as their `code_commit_sha` attribute, enabling queries like \"what did auth.middleware look like at HEAD?\" or future comparisons.\n\n资料来源：[src/thought/ingest/code/git_pipeline.py:7-16]()\n\n### Full History Mode\n\nFull mode walks every commit in chronological order, ingesting the file tree at each point. This enables:\n\n- Historical queries: \"what did function X look like at commit Y?\"\n- Diff analysis between any two commits\n- Complete temporal reconstruction of code evolution\n\n**Performance considerations:**\n\n| Repository Size | Estimated Commits | Estimated Time |\n|-----------------|-------------------|----------------|\n| Small (<100 files) | ~100 | ~30 seconds |\n| Medium (500 files) | ~1000 | ~5 minutes |\n| Large (1000+ files) | ~5000+ | ~25+ minutes |\n\n> Note: Full-history ingest is bounded by file count × commits. The per-commit cost is dominated by tree-sitter parsing, not git operations.\n\n资料来源：[src/thought/ingest/code/git_pipeline.py:16-25]()\n\n## CLI Usage\n\n### Command Syntax\n\n```bash\nthought ingest-git <repo_path> [OPTIONS]\n```\n\n#### Options\n\n| Option | Short | Default | Description |\n|--------|-------|---------|-------------|\n| `--mode` | `--mode snapshot` or `--mode full` | `snapshot` | Ingestion mode |\n| `--paths` | `--paths \"*.py,*.js\"` | `*.py` | Comma-separated glob patterns |\n| `--config` | `--config path/to/config` | `thought.toml` | Configuration file |\n\n### Examples\n\n```bash\n# Ingest current directory as git repo (HEAD only)\nthought ingest-git .\n\n# Ingest specific repository with full history\nthought ingest-git /path/to/repo --mode full\n\n# Ingest Python and TypeScript files only\nthought ingest-git . --paths \"*.py,*.ts,*.tsx\"\n\n# Ingest with full git history, multiple file types\nthought ingest-git /project --mode full --paths \"*.py,*.js,*.go\"\n```\n\n资料来源：[src/thought/cli.py:90-120]()\n\n## Code Commit Stamping\n\nEvery extracted code entity receives metadata linking it to its source commit:\n\n```python\neid = self._backend.upsert_entity(\n    # ... other fields ...\n    code_file=ent.file_path,\n    code_language=language,\n    code_commit_sha=commit_sha,  # Links entity to specific commit\n)\n```\n\nThe database schema includes:\n\n| Column | Type | Purpose |\n|--------|------|---------|\n| `code_file` | `TEXT` | File path relative to repo root |\n| `code_language` | `TEXT` | Programming language detected |\n| `code_commit_sha` | `TEXT` | Git commit where entity was found |\n\nThese columns have partial indexes for fast lookups by commit.\n\n资料来源：[CHANGELOG.md]()\n资料来源：[src/thought/ingest/code/pipeline.py:60-75]()\n\n## CodeLayer Query Interface\n\nThe `CodeLayer` class provides convenience methods for querying the code graph with temporal awareness:\n\n```python\nclass CodeLayer:\n    def callers_of(name, *, code_commit_sha=None)  # Find who calls this function\n    def callees_of(name, *, code_commit_sha=None)  # Find what this function calls\n    def impact_set(name)                            # Transitive callers, ranked\n    def defines_in_file(path)                       # Entities in a file\n```\n\n### Temporal Queries\n\nAll lookups operate against the currently-valid view of the code graph. To query historical snapshots, pass the `as_of` parameter or filter by `code_commit_sha`:\n\n```python\n# Query current state\nimpact = code_layer.impact_set(\"authenticate_user\")\n\n# Query historical state (when full-history ingest was used)\nimpact_historical = code_layer.impact_set(\n    \"authenticate_user\",\n    code_commit_sha=\"abc123...\"\n)\n```\n\n资料来源：[src/thought/layers/code.py:1-50]()\n\n## Diff Between Commits\n\nThe system supports computing the difference between any two ingested commits:\n\n```bash\nthought diff --from <sha1> --to <sha2>\n```\n\nThis returns:\n- **Added entities**: Entities present at `--to` but not at `--from`\n- **Removed entities**: Entities present at `--from` but not at `--to`\n\nThe diff operates on the set of entities by name, comparing their commit stamps.\n\n资料来源：[CHANGELOG.md]()\n\n## Supported Languages\n\nThe git ingestion pipeline uses language-specific extractors:\n\n| Language | Extractor | Extensions |\n|----------|-----------|------------|\n| Python | `python_extractor.py` | `.py` |\n| Rust | `rust_extractor.py` | `.rs` |\n| TypeScript | `typescript_extractor.py` | `.ts`, `.tsx` |\n| PHP | `php_extractor.py` | `.php` |\n\nEach extractor uses tree-sitter for AST parsing, extracting:\n- **Entities**: modules, functions, classes, methods\n- **Edges**: IMPORTS, DEFINES, CALLS, INHERITS_FROM, OVERRIDES\n\n资料来源：[src/thought/ingest/code/python_extractor.py]()\n资料来源：[src/thought/ingest/code/rust_extractor.py]()\n资料来源：[src/thought/ingest/code/typescript_extractor.py]()\n资料来源：[src/thought/ingest/code/php_extractor.py]()\n\n## Configuration\n\n### Thought Configuration (thought.toml)\n\n```toml\n[embedder]\ntype = \"auto\"  # or \"ollama\", \"openai\", \"deterministic\"\n\n[storage]\npath = \"thought.db\"\n```\n\n### Environment Variables\n\n| Variable | Description |\n|----------|-------------|\n| `OLLAMA_BASE_URL` | Ollama server URL for embeddings |\n| `OPENAI_API_KEY` | OpenAI API key for embeddings |\n\n## Best Practices\n\n### Initial Ingestion\n\n1. Start with **snapshot mode** to verify the setup works\n2. Run `thought stats` to confirm entities were created\n3. Query a function to verify call graph edges exist\n\n### Full History Ingestion\n\n1. Ensure adequate disk space (full mode creates temporary copies)\n2. Use `--paths` to filter to relevant file types on large repos\n3. Consider running during off-peak hours for large repositories\n\n### Query Optimization\n\n- Use `code_file` filter when querying specific files\n- Use `code_commit_sha` filter for historical lookups\n- Combine with vector similarity for intent-based queries\n\n## Troubleshooting\n\n### \"git executable not on PATH\"\n\n**Solution**: Install git or ensure it's in your system PATH.\n\n```bash\n# Verify git is available\ngit --version\n```\n\n### \"not a git repository\"\n\n**Solution**: Ensure the path contains a `.git` directory:\n\n```bash\n# Initialize if needed\ngit init\n```\n\n### Slow Full-History Ingestion\n\n**Mitigation**:\n- Use `--paths` to filter file types\n- Use snapshot mode for initial setup\n- Consider parallelizing with multiple `--paths` passes\n\n## Summary\n\nGit History Integration transforms thought-mcp from a current-state code analysis tool into a full temporal code repository that can answer questions about code at any point in history. By combining git's commit tracking with bi-temporal database queries, users can reconstruct how functions evolved, who called what across commits, and the complete impact chain of changes over time.\n\nThe architecture prioritizes:\n- **No native dependencies**: Pure subprocess git operations\n- **Two-mode flexibility**: Fast snapshots or complete history\n- **Temporal provenance**: Every entity stamped with its commit SHA\n- **Language generality**: Support for multiple programming languages via tree-sitter\n\n---\n\n<a id='page-agent-adapters'></a>\n\n## Agent Adapters and SDK Integration\n\n### 相关页面\n\n相关主题：[Query and Retrieval System](#page-query-system)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/adapters/__init__.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/adapters/__init__.py)\n- [src/thought/adapters/claude_sdk.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/adapters/claude_sdk.py)\n- [src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n- [src/thought/server.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/server.py)\n- [src/thought/hooks/install.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n</details>\n\n# Agent Adapters and SDK Integration\n\n## Overview\n\nThe Agent Adapters and SDK Integration subsystem provides a seamless bridge between THOUGHT's knowledge base and external AI agent frameworks. This system enables any Claude-Agent-SDK-shaped agent to interact with THOUGHT's memory, context retrieval, and code analysis capabilities through a standardized adapter interface.\n\nThe integration layer consists of three primary components:\n\n1. **Claude SDK Adapter** (`ThoughtMemoryProvider`) — A drop-in memory adapter for Claude Agent SDK\n2. **MCP Server Surface** — Exposes core primitives via the Model Context Protocol\n3. **Claude Code Hook Installer** — Integrates THOUGHT directly into Claude Code's event loop\n\n资料来源：[CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n\n## Architecture Overview\n\n```mermaid\ngraph TD\n    subgraph \"Agent Frameworks\"\n        ClaudeSDK[Claude Agent SDK]\n        ClaudeCode[Claude Code CLI]\n        MCPClients[MCP-Compatible Clients]\n    end\n\n    subgraph \"THOUGHT Integration Layer\"\n        ClaudeSDKAdapter[ThoughtMemoryProvider]\n        MCPServer[MCP Server Surface]\n        HookInstaller[Claude Code Hook Installer]\n    end\n\n    subgraph \"Core THOUGHT\"\n        Memory[Memory / Knowledge Base]\n        Embedder[Embedder Service]\n        CodeAnalysis[Code Analysis Engine]\n        Backend[SQLite Backend]\n    end\n\n    ClaudeSDK --> ClaudeSDKAdapter\n    ClaudeSDKAdapter --> Memory\n    ClaudeSDKAdapter --> Embedder\n    \n    ClaudeCode --> HookInstaller\n    HookInstaller --> Memory\n    \n    MCPClients --> MCPServer\n    MCPServer --> Memory\n    MCPServer --> CodeAnalysis\n    MCPServer --> Backend\n\n    Memory --> Backend\n    Embedder --> Backend\n    CodeAnalysis --> Backend\n```\n\n## The Claude SDK Adapter\n\n### Purpose and Scope\n\nThe `ThoughtMemoryProvider` class serves as a drop-in memory adapter for any Claude-Agent-SDK-shaped agent. It wraps THOUGHT's core memory primitives and exposes them through a familiar interface that agent developers expect.\n\n资料来源：[src/thought/adapters/claude_sdk.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/adapters/claude_sdk.py)\n\n### Core Methods\n\nThe adapter implements three primary methods that cover the complete agent loop:\n\n| Method | Purpose | Returns |\n|--------|---------|---------|\n| `context_for(target, role)` | Returns a working-context dict for a specific target entity and role | `dict` with anchor, neighbours, recent_contradictions, role_view |\n| `render_context(target)` | Returns the same payload as a plain-text system-prompt augmentation | `str` formatted for LLM consumption |\n| `record(content)` | Persists what the agent learned to the knowledge base | `str` — source ID of recorded content |\n| `scan(repo_path)` | Runs an incremental scan under the agent's name | `dict` with scan results |\n\n资料来源：[src/thought/adapters/claude_sdk.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/adapters/claude_sdk.py)\n\n### Working Context Structure\n\nThe `context_for()` method returns a ranked, role-aware payload containing:\n\n```python\n{\n    \"anchor\": \"<entity-name>\",           # The target entity\n    \"neighbours\": [...],                  # Top-K related entities\n    \"recent_contradictions\": [...],       # Entities that contradict this one\n    \"role_view\": \"<saved-view-name>\"      # Optional named view for the role\n}\n```\n\nThe context is token-budgeted to prevent overwhelming the agent's context window.\n\n资料来源：[CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n\n### Integration Flow\n\n```mermaid\nsequenceDiagram\n    participant Agent as Claude Agent SDK\n    participant Adapter as ThoughtMemoryProvider\n    participant Memory as THOUGHT Memory\n    participant Embedder as Embedder Service\n    participant Backend as SQLite Backend\n\n    Agent->>Adapter: context_for(\"authenticate\", role=\"code\")\n    Adapter->>Memory: working_context(target, role, budget_tokens)\n    Memory->>Embedder: embed(\"authenticate\")\n    Embedder->>Memory: vector embedding\n    Memory->>Backend: query similar entities\n    Backend-->>Memory: ranked entity results\n    Memory-->>Adapter: structured context dict\n    Adapter-->>Agent: context payload\n\n    Agent->>Adapter: record(\"Learned: auth uses JWT\")\n    Adapter->>Backend: upsert_source(content, mime_type)\n    Adapter->>Backend: store entity + edges\n    Backend-->>Adapter: source_id\n    Adapter-->>Agent: source_id\n```\n\n## MCP Server Surface\n\nThe MCP (Model Context Protocol) server exposes THOUGHT's primitives as tools that any MCP-compatible client can invoke.\n\n资料来源：[src/thought/server.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/server.py)\n\n### Available Tools\n\n#### `working_context`\n\nUniversal \"what does my agent need to know about X right now\" primitive.\n\n```python\n@app.tool()\nasync def working_context(\n    target: str,           # \"function:authenticate\" / \"chapter:5\" / entity name\n    role: str = \"default\", # Contextual role for view filtering\n    budget_tokens: int = 1024,\n    scope: str | None = None,\n    owner_id: str | None = None,\n) -> dict\n```\n\nReturns:\n```python\n{\n    \"anchor\": str,\n    \"neighbours\": list[dict],\n    \"recent_contradictions\": list[dict],\n    \"role_view\": str | None\n}\n```\n\n资料来源：[src/thought/server.py:48-63](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/server.py)\n\n#### `scan`\n\nIncremental code-scan primitive for keeping the knowledge base current.\n\n```python\n@app.tool()\nasync def scan(\n    repo_path: str,           # Repository to scan\n    agent: str | None = None, # Agent name for scan attribution\n    since: str | None = None, # Only files changed since this time/commit\n    max_files: int | None = None,\n    note: str | None = None,\n) -> dict\n```\n\n资料来源：[src/thought/server.py:65-78](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/server.py)\n\n#### `scan_log_list`\n\nLists recent scan runs for tracking incremental progress.\n\n```python\n@app.tool()\nasync def scan_log_list(\n    agent: str | None = None,\n    limit: int = 10,\n) -> dict\n```\n\nReturns:\n```python\n{\n    \"scans\": [\n        {\n            \"scan_id\": str,\n            \"agent\": str,\n            \"timestamp\": str,\n            \"files_processed\": int,\n            \"note\": str | None\n        },\n        ...\n    ]\n}\n```\n\n资料来源：[src/thought/server.py:80-91](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/server.py)\n\n## Client Installation\n\nTHOUGHT supports installation into multiple MCP-compatible clients. The installation process merges a `thought` MCP server entry into the client's configuration file.\n\n资料来源：[src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n\n### Supported Clients\n\n| Client | Configuration Path |\n|--------|-------------------|\n| Project | `.claude/settings.json` |\n| User | `~/.claude/settings.json` |\n\n资料来源：[src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n\n### Installation Function\n\n```python\ndef install(\n    client: ClientName,\n    *,\n    server_name: str = \"thought\",\n    block: dict | None = None,\n    backup: bool = True,\n) -> ClientInstallResult\n```\n\n**Parameters:**\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `client` | `ClientName` | Required | Target client name |\n| `server_name` | `str` | `\"thought\"` | Name for the server entry |\n| `block` | `dict \\| None` | `None` | Custom server block; defaults to `server_block()` |\n| `backup` | `bool` | `True` | Backup existing config before modification |\n\n**Return Type:** `ClientInstallResult`\n\n```python\n@dataclass\nclass ClientInstallResult:\n    client: ClientName\n    path: Path | None\n    status: Literal[\"installed\", \"already_present\", \"error\", \"no_path\"]\n    detail: str = \"\"\n```\n\n资料来源：[src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n\n### Installation Behavior\n\nThe `install()` function performs the following:\n\n1. **Read existing config** — Parses the client's JSON configuration\n2. **Merge server entry** — Adds the `thought` server block under `mcpServers`\n3. **Backup** — Creates `settings.json.thought.bak` before any write\n4. **Idempotency check** — Returns `already_present` if entry exists and matches\n\n资料来源：[src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n\n```mermaid\ngraph TD\n    A[install called] --> B{Config exists?}\n    B -->|No| C[Create new config]\n    B -->|Yes| D{Valid JSON?}\n    D -->|No| E[Return error]\n    D -->|Yes| F{Server entry exists?}\n    F -->|Yes, matches| G[Return already_present]\n    F -->|Yes, differs| H[Backup config]\n    F -->|No| I[Add server entry]\n    H --> J[Write merged config]\n    I --> J\n    C --> J\n    J --> K[Return installed]\n```\n\n## Claude Code Hook Integration\n\nThe hook installer provides Claude Code event-driven integration, enabling THOUGHT to automatically capture context at key points in the development workflow.\n\n资料来源：[src/thought/hooks/install.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n\n### Hook Kinds\n\n| Hook Kind | Claude Code Event | Command | Trigger |\n|-----------|------------------|---------|---------|\n| `recall` | `UserPromptSubmit` | `thought hook recall` | After user submits a prompt |\n| `write` | `Stop` | `thought hook write` | After agent completes work |\n| `context` | `SessionStart` | `thought hook context` | When session begins |\n\n资料来源：[src/thought/hooks/install.py:15-22](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n\n### Hook Installation Result\n\n```python\n@dataclass(frozen=True)\nclass HookInstallResult:\n    kind: HookKind\n    path: Path\n    status: Literal[\"installed\", \"already_present\", \"error\"]\n    detail: str = \"\"\n```\n\n### Settings Path Resolution\n\n```python\ndef settings_path(*, scope: Literal[\"project\", \"user\"] = \"project\") -> Path\n```\n\n- **Project scope** — `.claude/settings.json` (recommended default)\n- **User scope** — `~/.claude/settings.json`\n\n资料来源：[src/thought/hooks/install.py:41-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n\n## Demo Integration\n\nThe `thought demo` command includes a built-in walkthrough specifically for the Claude Agent SDK adapter:\n\n```python\n- ``code``  Agent / developer flow — the 14-stage code-vertical\n            walkthrough including agent identity, ``thought scan``,\n            ``working_context``, 4 new-language extractors, and the\n            Claude Agent SDK adapter.\n```\n\n资料来源：[src/thought/demo.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n\n### Demo Audiences\n\n| Audience | Purpose | Key Features |\n|----------|---------|--------------|\n| `code` | Agent/developer flow | SDK adapter, scan, working_context |\n| `writer` | Novelist/paper author | Bi-temporal model, contradiction detection |\n| `legal` | Investigator/paralegal | `unique_predicates`, CONTRADICTS edges |\n| `researcher` | Academic | Claim/source pairs, Cypher queries |\n| `all` | Sequential all audiences | Full demonstration suite |\n\n## Configuration\n\n### Environment Variables\n\nThe integration layer respects the following environment variables for embedder configuration:\n\n| Variable | Purpose |\n|----------|---------|\n| `THOUGHT_DB_PATH` | Override database path |\n| `THOUGHT_EMBEDDER` | Embedder choice (`auto`, `sentence-transformers`, etc.) |\n| `THOUGHT_OLLAMA_HOST` | Ollama server host |\n| `THOUGHT_OLLAMA_MODEL` | Ollama model name |\n| `THOUGHT_LMSTUDIO_URL` | LM Studio server URL |\n| `THOUGHT_LMSTUDIO_MODEL` | LM Studio model name |\n| `THOUGHT_OPENAI_COMPAT_URL` | OpenAI-compatible API URL |\n| `THOUGHT_OPENAI_COMPAT_MODEL` | OpenAI-compatible model name |\n| `THOUGHT_OPENAI_COMPAT_API_KEY` | API key for OpenAI-compatible endpoints |\n\n资料来源：[src/thought/config.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/config.py)\n\n### Config File (`thought.toml`)\n\n```toml\n[embedding]\nchoice = \"auto\"  # or specific embedder name\n\n[db]\npath = \".thought/thought.db\"\n```\n\n## Dependencies\n\nThe adapter package requires the following extras:\n\n```toml\n[project.optional-dependencies]\nadapters = [\"httpx>=0.27\"]\n```\n\n资料来源：[CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n\n## Usage Example\n\n```python\nfrom thought.adapters.claude_sdk import ThoughtMemoryProvider\n\n# Initialize adapter\nmemory = ThoughtMemoryProvider()\n\n# Get working context for a function\ncontext = memory.context_for(\n    target=\"authenticate_user\",\n    role=\"security-reviewer\",\n    budget_tokens=2048,\n)\n\n# Record what the agent learned\nsource_id = memory.record(\n    \"Session token validation happens in this function. \"\n    \"Uses HMAC-SHA256 for signature verification.\"\n)\n\n# Run incremental scan\nresult = memory.scan(\n    repo_path=\"/path/to/project\",\n    agent=\"security-audit\",\n    note=\"Weekly security review scan\"\n)\n```\n\n## Summary\n\nThe Agent Adapters and SDK Integration system provides three complementary pathways for integrating THOUGHT with external agents:\n\n1. **Direct SDK Integration** — `ThoughtMemoryProvider` for Claude Agent SDK agents\n2. **MCP Protocol** — Standard tool interface for any MCP-compatible client\n3. **Claude Code Hooks** — Event-driven integration for Claude Code CLI users\n\nAll pathways share the same underlying memory primitives, ensuring consistent behavior regardless of how the agent connects to THOUGHT.\n\n---\n\n---\n\n## Doramagic Pitfall Log\n\nProject: RNBBarrett/thought-mcp\n\nSummary: Found 8 potential pitfall items; 0 are high/blocking. Highest priority: configuration - 可能修改宿主 AI 配置.\n\n## 1. configuration · 可能修改宿主 AI 配置\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: 项目面向 Claude/Cursor/Codex/Gemini/OpenCode 等宿主，或安装命令涉及用户配置目录。\n- User impact: 安装可能改变本机 AI 工具行为，用户需要知道写入位置和回滚方法。\n- Suggested check: 列出会写入的配置文件、目录和卸载/回滚步骤。\n- Guardrail action: 涉及宿主配置目录时必须给回滚路径，不能只给安装命令。\n- Evidence: capability.host_targets | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | host_targets=mcp_host, claude, claude_code, chatgpt\n\n## 2. capability · 能力判断依赖假设\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: README/documentation is current enough for a first validation pass.\n- User impact: 假设不成立时，用户拿不到承诺的能力。\n- Suggested check: 将假设转成下游验证清单。\n- Guardrail action: 假设必须转成验证项；没有验证结果前不能写成事实。\n- Evidence: capability.assumptions | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | README/documentation is current enough for a first validation pass.\n\n## 3. maintenance · 来源证据：v0.2.1 — thought upgrade + mcp-extras fix\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.2.1 — thought upgrade + mcp-extras fix\n- User impact: 可能增加新用户试用和生产接入成本。\n- Suggested check: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Guardrail action: 不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- Evidence: community_evidence:github | cevd_dc6434cd71064812ae14d01e7f5d9ef0 | https://github.com/RNBBarrett/thought-mcp/releases/tag/v0.2.1 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 4. maintenance · 维护活跃度未知\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: 未记录 last_activity_observed。\n- User impact: 新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- Suggested check: 补 GitHub 最近 commit、release、issue/PR 响应信号。\n- Guardrail action: 维护活跃度未知时，推荐强度不能标为高信任。\n- Evidence: evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | last_activity_observed missing\n\n## 5. security_permissions · 下游验证发现风险项\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: no_demo\n- User impact: 下游已经要求复核，不能在页面中弱化。\n- Suggested check: 进入安全/权限治理复核队列。\n- Guardrail action: 下游风险存在时必须保持 review/recommendation 降级。\n- Evidence: downstream_validation.risk_items | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | no_demo; severity=medium\n\n## 6. security_permissions · 存在评分风险\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: no_demo\n- User impact: 风险会影响是否适合普通用户安装。\n- Suggested check: 把风险写入边界卡，并确认是否需要人工复核。\n- Guardrail action: 评分风险必须进入边界卡，不能只作为内部分数。\n- Evidence: risks.scoring_risks | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | no_demo; severity=medium\n\n## 7. maintenance · issue/PR 响应质量未知\n\n- Severity: low\n- Evidence strength: source_linked\n- Finding: issue_or_pr_quality=unknown。\n- User impact: 用户无法判断遇到问题后是否有人维护。\n- Suggested check: 抽样最近 issue/PR，判断是否长期无人处理。\n- Guardrail action: issue/PR 响应未知时，必须提示维护风险。\n- Evidence: evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | issue_or_pr_quality=unknown\n\n## 8. maintenance · 发布节奏不明确\n\n- Severity: low\n- Evidence strength: source_linked\n- Finding: release_recency=unknown。\n- User impact: 安装命令和文档可能落后于代码，用户踩坑概率升高。\n- Suggested check: 确认最近 release/tag 和 README 安装命令是否一致。\n- Guardrail action: 发布节奏未知或过期时，安装说明必须标注可能漂移。\n- Evidence: evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | release_recency=unknown\n\n<!-- canonical_name: RNBBarrett/thought-mcp; human_manual_source: deepwiki_human_wiki -->\n",
      "markdown_key": "thought-mcp",
      "pages": "draft",
      "source_refs": [
        {
          "evidence_id": "github_repo:1238261514",
          "kind": "repo",
          "supports_claim_ids": [
            "claim_identity",
            "claim_distribution",
            "claim_capability"
          ],
          "url": "https://github.com/RNBBarrett/thought-mcp"
        },
        {
          "evidence_id": "art_8d2c2921d2514add891eadc2ade2f9ab",
          "kind": "docs",
          "supports_claim_ids": [
            "claim_identity",
            "claim_distribution",
            "claim_capability"
          ],
          "url": "https://github.com/RNBBarrett/thought-mcp#readme"
        }
      ],
      "summary": "DeepWiki/Human Wiki output with a Doramagic pitfall appendix.",
      "title": "thought-mcp 说明书",
      "toc": [
        "https://github.com/RNBBarrett/thought-mcp 项目说明书",
        "目录",
        "Introduction to THOUGHT",
        "What is THOUGHT?",
        "Core Architecture",
        "Entity Model",
        "Audience Verticals",
        "CLI Commands Overview",
        "Doramagic 踩坑日志"
      ]
    }
  },
  "quality_gate": {
    "blocking_gaps": [],
    "category_confidence": "medium",
    "compile_status": "ready_for_review",
    "five_assets_present": true,
    "install_sandbox_verified": true,
    "missing_evidence": [],
    "next_action": "publish to Doramagic.ai project surfaces",
    "prompt_preview_boundary_ok": true,
    "publish_status": "publishable",
    "quick_start_verified": true,
    "repo_clone_verified": true,
    "repo_commit": "a84a387fca07fbccfeb8d38f22c1c17661552b9d",
    "repo_inspection_error": null,
    "repo_inspection_files": [
      "pyproject.toml",
      "Dockerfile",
      "README.md",
      "docs/ablation.md",
      "docs/comparison.md",
      "src/thought/cli.py",
      "src/thought/models.py",
      "src/thought/demo.py",
      "src/thought/memory.py",
      "src/thought/server.py",
      "src/thought/__init__.py",
      "src/thought/config.py",
      "src/thought/clients.py",
      "src/thought/embeddings/deterministic.py",
      "src/thought/embeddings/ollama.py",
      "src/thought/embeddings/openai_compat.py",
      "src/thought/embeddings/__init__.py",
      "src/thought/embeddings/sentence_transformer.py",
      "src/thought/embeddings/base.py",
      "src/thought/llm/__init__.py",
      "src/thought/hooks/setup.py",
      "src/thought/hooks/write.py",
      "src/thought/hooks/recall.py",
      "src/thought/hooks/__init__.py",
      "src/thought/hooks/install.py",
      "src/thought/consolidation/engine.py",
      "src/thought/consolidation/__init__.py",
      "src/thought/adapters/claude_sdk.py",
      "src/thought/adapters/__init__.py",
      "src/thought/ingest/entities.py",
      "src/thought/ingest/pipeline.py",
      "src/thought/ingest/__init__.py",
      "src/thought/storage/__init__.py",
      "src/thought/storage/base.py",
      "src/thought/router/rules.yaml",
      "src/thought/router/dispatcher.py",
      "src/thought/router/classifier.py",
      "src/thought/router/__init__.py",
      "src/thought/layers/code.py",
      "src/thought/layers/graph.py"
    ],
    "repo_inspection_verified": true,
    "review_reasons": [
      "community_discussion_evidence_below_public_threshold"
    ],
    "tag_count_ok": true,
    "unsupported_claims": []
  },
  "schema_version": "0.1",
  "user_assets": {
    "ai_context_pack": {
      "asset_id": "ai_context_pack",
      "filename": "AI_CONTEXT_PACK.md",
      "markdown": "# thought-mcp - Doramagic AI Context Pack\n\n> 定位：安装前体验与判断资产。它帮助宿主 AI 有一个好的开始，但不代表已经安装、执行或验证目标项目。\n\n## 充分原则\n\n- **充分原则，不是压缩原则**：AI Context Pack 应该充分到让宿主 AI 在开工前理解项目价值、能力边界、使用入口、风险和证据来源；它可以分层组织，但不以最短摘要为目标。\n- **压缩策略**：只压缩噪声和重复内容，不压缩会影响判断和开工质量的上下文。\n\n## 给宿主 AI 的使用方式\n\n你正在读取 Doramagic 为 thought-mcp 编译的 AI Context Pack。请把它当作开工前上下文：帮助用户理解适合谁、能做什么、如何开始、哪些必须安装后验证、风险在哪里。不要声称你已经安装、运行或执行了目标项目。\n\n## Claim 消费规则\n\n- **事实来源**：Repo Evidence + Claim/Evidence Graph；Human Wiki 只提供显著性、术语和叙事结构。\n- **事实最低状态**：`supported`\n- `supported`：可以作为项目事实使用，但回答中必须引用 claim_id 和证据路径。\n- `weak`：只能作为低置信度线索，必须要求用户继续核实。\n- `inferred`：只能用于风险提示或待确认问题，不能包装成项目事实。\n- `unverified`：不得作为事实使用，应明确说证据不足。\n- `contradicted`：必须展示冲突来源，不得替用户强行选择一个版本。\n\n## 它最适合谁\n\n- **AI 研究者或研究型 Agent 构建者**：README 明确围绕研究、实验或论文工作流展开。 证据：`README.md` Claim：`clm_0002` supported 0.86\n- **正在使用 Claude/Codex/Cursor/Gemini 等宿主 AI 的开发者**：README 或插件配置提到多个宿主 AI。 证据：`README.md` Claim：`clm_0003` supported 0.86\n\n## 它能做什么\n\n- **命令行启动或安装流程**（需要安装后验证）：项目文档中存在可执行命令，真实使用需要在本地或宿主环境中运行这些命令。 证据：`README.md` Claim：`clm_0001` supported 0.86\n\n## 怎么开始\n\n- `pip install 'thought-mcp[all]'` 证据：`README.md` Claim：`clm_0004` supported 0.86\n- `pip install thought-mcp` 证据：`README.md` Claim：`clm_0004` supported 0.86, `clm_0005` supported 0.86\n- `curl http://localhost:11434/api/tags` 证据：`README.md` Claim：`clm_0006` supported 0.86\n- `curl http://localhost:1234/v1/models` 证据：`README.md` Claim：`clm_0007` supported 0.86\n- `pip install --upgrade thought-mcp     # pull the new package` 证据：`README.md` Claim：`clm_0008` supported 0.86\n- `pip install pysqlite3-binary` 证据：`README.md` Claim：`clm_0009` supported 0.86\n\n## 继续前判断卡\n\n- **当前建议**：先做权限沙盒试用\n- **为什么**：项目存在安装命令、宿主配置或本地写入线索，不建议直接进入主力环境，应先在隔离环境试装。\n\n### 30 秒判断\n\n- **现在怎么做**：先做权限沙盒试用\n- **最小安全下一步**：先跑 Prompt Preview；若仍要安装，只在隔离环境试装\n- **先别相信**：工具权限边界不能在安装前相信。\n- **继续会触碰**：命令执行、本地环境或项目文件、宿主 AI 上下文\n\n### 现在可以相信\n\n- **适合人群线索：AI 研究者或研究型 Agent 构建者**（supported）：有 supported claim 或项目证据支撑，但仍不等于真实安装效果。 证据：`README.md` Claim：`clm_0002` supported 0.86\n- **适合人群线索：正在使用 Claude/Codex/Cursor/Gemini 等宿主 AI 的开发者**（supported）：有 supported claim 或项目证据支撑，但仍不等于真实安装效果。 证据：`README.md` Claim：`clm_0003` supported 0.86\n- **能力存在：命令行启动或安装流程**（supported）：可以相信项目包含这类能力线索；是否适合你的具体任务仍要试用或安装后验证。 证据：`README.md` Claim：`clm_0001` supported 0.86\n- **存在 Quick Start / 安装命令线索**（supported）：可以相信项目文档出现过启动或安装入口；不要因此直接在主力环境运行。 证据：`README.md` Claim：`clm_0004` supported 0.86\n\n### 现在还不能相信\n\n- **工具权限边界不能在安装前相信。**（unverified）：MCP/tool 类项目通常会触碰文件、网络、浏览器或外部 API，必须真实检查权限和日志。\n- **真实输出质量不能在安装前相信。**（unverified）：Prompt Preview 只能展示引导方式，不能证明真实项目中的结果质量。\n- **宿主 AI 版本兼容性不能在安装前相信。**（unverified）：Claude、Cursor、Codex、Gemini 等宿主加载规则和版本差异必须在真实环境验证。\n- **不会污染现有宿主 AI 行为，不能直接相信。**（inferred）：Skill、plugin、AGENTS/CLAUDE/GEMINI 指令可能改变宿主 AI 的默认行为。\n- **可安全回滚不能默认相信。**（unverified）：除非项目明确提供卸载和恢复说明，否则必须先在隔离环境验证。\n- **真实安装后是否与用户当前宿主 AI 版本兼容？**（unverified）：兼容性只能通过实际宿主环境验证。\n- **项目输出质量是否满足用户具体任务？**（unverified）：安装前预览只能展示流程和边界，不能替代真实评测。\n- **安装命令是否需要网络、权限或全局写入？**（unverified）：这影响企业环境和个人环境的安装风险。 证据：`README.md`\n\n### 继续会触碰什么\n\n- **命令执行**：包管理器、网络下载、本地插件目录、项目配置或用户主目录。 原因：运行第一条命令就可能产生环境改动；必须先判断是否值得跑。 证据：`README.md`\n- **本地环境或项目文件**：安装结果、插件缓存、项目配置或本地依赖目录。 原因：安装前无法证明写入范围和回滚方式，需要隔离验证。 证据：`README.md`\n- **宿主 AI 上下文**：AI Context Pack、Prompt Preview、Skill 路由、风险规则和项目事实。 原因：导入上下文会影响宿主 AI 后续判断，必须避免把未验证项包装成事实。\n\n### 最小安全下一步\n\n- **先跑 Prompt Preview**：用安装前交互式试用判断工作方式是否匹配，不需要授权或改环境。（适用：任何项目都适用，尤其是输出质量未知时。）\n- **只在隔离目录或测试账号试装**：避免安装命令污染主力宿主 AI、真实项目或用户主目录。（适用：存在命令执行、插件配置或本地写入线索时。）\n- **安装后只验证一个最小任务**：先验证加载、兼容、输出质量和回滚，再决定是否深用。（适用：准备从试用进入真实工作流时。）\n\n### 退出方式\n\n- **保留安装前状态**：记录原始宿主配置和项目状态，后续才能判断是否可恢复。\n- **记录安装命令和写入路径**：没有明确卸载说明时，至少要知道哪些目录或配置需要手动清理。\n- **如果没有回滚路径，不进入主力环境**：不可回滚是继续前阻断项，不应靠信任或运气继续。\n\n## 哪些只能预览\n\n- 解释项目适合谁和能做什么\n- 基于项目文档演示典型对话流程\n- 帮助用户判断是否值得安装或继续研究\n\n## 哪些必须安装后验证\n\n- 真实安装 Skill、插件或 CLI\n- 执行脚本、修改本地文件或访问外部服务\n- 验证真实输出质量、性能和兼容性\n\n## 边界与风险判断卡\n\n- **把安装前预览误认为真实运行**：用户可能高估项目已经完成的配置、权限和兼容性验证。 处理方式：明确区分 prompt_preview_can_do 与 runtime_required。 Claim：`clm_0010` inferred 0.45\n- **命令执行会修改本地环境**：安装命令可能写入用户主目录、宿主插件目录或项目配置。 处理方式：先在隔离环境或测试账号中运行。 证据：`README.md` Claim：`clm_0011` supported 0.86\n- **待确认**：真实安装后是否与用户当前宿主 AI 版本兼容？。原因：兼容性只能通过实际宿主环境验证。\n- **待确认**：项目输出质量是否满足用户具体任务？。原因：安装前预览只能展示流程和边界，不能替代真实评测。\n- **待确认**：安装命令是否需要网络、权限或全局写入？。原因：这影响企业环境和个人环境的安装风险。\n\n## 开工前工作上下文\n\n### 加载顺序\n\n- 先读取 how_to_use.host_ai_instruction，建立安装前判断资产的边界。\n- 读取 claim_graph_summary，确认事实来自 Claim/Evidence Graph，而不是 Human Wiki 叙事。\n- 再读取 intended_users、capabilities 和 quick_start_candidates，判断用户是否匹配。\n- 需要执行具体任务时，优先查 role_skill_index，再查 evidence_index。\n- 遇到真实安装、文件修改、网络访问、性能或兼容性问题时，转入 risk_card 和 boundaries.runtime_required。\n\n### 任务路由\n\n- **命令行启动或安装流程**：先说明这是安装后验证能力，再给出安装前检查清单。 边界：必须真实安装或运行后验证。 证据：`README.md` Claim：`clm_0001` supported 0.86\n\n### 上下文规模\n\n- 文件总数：127\n- 重要文件覆盖：11/127\n- 证据索引条目：10\n- 角色 / Skill 条目：5\n\n### 证据不足时的处理\n\n- **missing_evidence**：说明证据不足，要求用户提供目标文件、README 段落或安装后验证记录；不要补全事实。\n- **out_of_scope_request**：说明该任务超出当前 AI Context Pack 证据范围，并建议用户先查看 Human Manual 或真实安装后验证。\n- **runtime_request**：给出安装前检查清单和命令来源，但不要替用户执行命令或声称已执行。\n- **source_conflict**：同时展示冲突来源，标记为待核实，不要强行选择一个版本。\n\n## Prompt Recipes\n\n### 适配判断\n\n- 目标：判断这个项目是否适合用户当前任务。\n- 预期输出：适配结论、关键理由、证据引用、安装前可预览内容、必须安装后验证内容、下一步建议。\n\n```text\n请基于 thought-mcp 的 AI Context Pack，先问我 3 个必要问题，然后判断它是否适合我的任务。回答必须包含：适合谁、能做什么、不能做什么、是否值得安装、证据来自哪里。所有项目事实必须引用 evidence_refs、source_paths 或 claim_id。\n```\n\n### 安装前体验\n\n- 目标：让用户在安装前感受核心工作流，同时避免把预览包装成真实能力或营销承诺。\n- 预期输出：一段带边界标签的体验剧本、安装后验证清单和谨慎建议；不含真实运行承诺或强营销表述。\n\n```text\n请把 thought-mcp 当作安装前体验资产，而不是已安装工具或真实运行环境。\n\n请严格输出四段：\n1. 先问我 3 个必要问题。\n2. 给出一段“体验剧本”：用 [安装前可预览]、[必须安装后验证]、[证据不足] 三种标签展示它可能如何引导工作流。\n3. 给出安装后验证清单：列出哪些能力只有真实安装、真实宿主加载、真实项目运行后才能确认。\n4. 给出谨慎建议：只能说“值得继续研究/试装”“先补充信息后再判断”或“不建议继续”，不得替项目背书。\n\n硬性边界：\n- 不要声称已经安装、运行、执行测试、修改文件或产生真实结果。\n- 不要写“自动适配”“确保通过”“完美适配”“强烈建议安装”等承诺性表达。\n- 如果描述安装后的工作方式，必须使用“如果安装成功且宿主正确加载 Skill，它可能会……”这种条件句。\n- 体验剧本只能写成“示例台词/假设流程”：使用“可能会询问/可能会建议/可能会展示”，不要写“已写入、已生成、已通过、正在运行、正在生成”。\n- Prompt Preview 不负责给安装命令；如用户准备试装，只能提示先阅读 Quick Start 和 Risk Card，并在隔离环境验证。\n- 所有项目事实必须来自 supported claim、evidence_refs 或 source_paths；inferred/unverified 只能作风险或待确认项。\n\n```\n\n### 角色 / Skill 选择\n\n- 目标：从项目里的角色或 Skill 中挑选最匹配的资产。\n- 预期输出：候选角色或 Skill 列表，每项包含适用场景、证据路径、风险边界和是否需要安装后验证。\n\n```text\n请读取 role_skill_index，根据我的目标任务推荐 3-5 个最相关的角色或 Skill。每个推荐都要说明适用场景、可能输出、风险边界和 evidence_refs。\n```\n\n### 风险预检\n\n- 目标：安装或引入前识别环境、权限、规则冲突和质量风险。\n- 预期输出：环境、权限、依赖、许可、宿主冲突、质量风险和未知项的检查清单。\n\n```text\n请基于 risk_card、boundaries 和 quick_start_candidates，给我一份安装前风险预检清单。不要替我执行命令，只说明我应该检查什么、为什么检查、失败会有什么影响。\n```\n\n### 宿主 AI 开工指令\n\n- 目标：把项目上下文转成一次对话开始前的宿主 AI 指令。\n- 预期输出：一段边界明确、证据引用明确、适合复制给宿主 AI 的开工前指令。\n\n```text\n请基于 thought-mcp 的 AI Context Pack，生成一段我可以粘贴给宿主 AI 的开工前指令。这段指令必须遵守 not_runtime=true，不能声称项目已经安装、运行或产生真实结果。\n```\n\n\n## 角色 / Skill 索引\n\n- 共索引 5 个角色 / Skill / 项目文档条目。\n\n- **THOUGHT**（project_doc）：! PyPI https://img.shields.io/pypi/v/thought-mcp.svg https://pypi.org/project/thought-mcp/ ! Python https://img.shields.io/pypi/pyversions/thought-mcp.svg https://pypi.org/project/thought-mcp/ ! License: MIT https://img.shields.io/badge/License-MIT-yellow.svg LICENSE ! CI https://github.com/RNBBarrett/thought-mcp/actions/workflows/ci.yml/badge.svg https://github.com/RNBBarrett/thought-mcp/actions/workflows/ci.yml !… 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`README.md`\n- **Contributing to thought-mcp**（project_doc）：Thanks for picking this up. The project is small enough that one focused PR per topic is the right shape. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`CONTRIBUTING.md`\n- **Ablation study — marginal contribution of Tier A techniques**（project_doc）：Ablation study — marginal contribution of Tier A techniques 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/ablation.md`\n- **Comparison harness — measured results**（project_doc）：Comparison harness — measured results 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/comparison.md`\n- **Changelog**（project_doc）：All notable changes to thought-mcp are documented here. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`CHANGELOG.md`\n\n## 证据索引\n\n- 共索引 10 条证据。\n\n- **THOUGHT**（documentation）：! PyPI https://img.shields.io/pypi/v/thought-mcp.svg https://pypi.org/project/thought-mcp/ ! Python https://img.shields.io/pypi/pyversions/thought-mcp.svg https://pypi.org/project/thought-mcp/ ! License: MIT https://img.shields.io/badge/License-MIT-yellow.svg LICENSE ! CI https://github.com/RNBBarrett/thought-mcp/actions/workflows/ci.yml/badge.svg https://github.com/RNBBarrett/thought-mcp/actions/workflows/ci.yml ! Docker https://github.com/RNBBarrett/thought-mcp/actions/workflows/docker.yml/badge.svg https://github.com/RNBBarrett/thought-mcp/actions/workflows/docker.yml ! GHCR https://img.shields.io/badge/ghcr.io-thought--mcp-blue?logo=docker https://github.com/RNBBarrett/thought-mcp/pkgs/… 证据：`README.md`\n- **Contributing to thought-mcp**（documentation）：Thanks for picking this up. The project is small enough that one focused PR per topic is the right shape. 证据：`CONTRIBUTING.md`\n- **License**（source_file）：Copyright c 2026 Richard Barrett and THOUGHT contributors 证据：`LICENSE`\n- **Ablation study — marginal contribution of Tier A techniques**（documentation）：Ablation study — marginal contribution of Tier A techniques 证据：`docs/ablation.md`\n- **Comparison harness — measured results**（documentation）：Comparison harness — measured results 证据：`docs/comparison.md`\n- **Changelog**（documentation）：All notable changes to thought-mcp are documented here. 证据：`CHANGELOG.md`\n- **.dockerignore**（source_file）：.venv/ pycache / .pyc .pyo .pytest cache/ .mypy cache/ .ruff cache/ .coverage htmlcov/ build/ dist/ .egg-info/ .db .db-journal .thought/ .cache/ models/ .git/ .github/ docs/ tests/perf/.tmp/ plan.md 证据：`.dockerignore`\n- **Build artifacts**（source_file）：Build artifacts build/ dist/ .egg-info/ .egg pycache / .py cod $py.class .pytest cache/ .ruff cache/ .mypy cache/ .coverage htmlcov/ coverage.xml .tox/ .nox/ 证据：`.gitignore`\n- **---- build stage ---------------------------------------------------------**（source_file）：---- build stage --------------------------------------------------------- FROM python:${PYTHON VERSION}-slim AS build WORKDIR /src RUN pip install --no-cache-dir --upgrade pip build COPY pyproject.toml README.md LICENSE ./ COPY src ./src RUN python -m build --wheel --outdir /wheels 证据：`Dockerfile`\n- **The MCP server can't start without these — they're not really optional**（source_file）：build-system requires = \"hatchling =1.24\" build-backend = \"hatchling.build\" 证据：`pyproject.toml`\n\n## 宿主 AI 必须遵守的规则\n\n- **把本资产当作开工前上下文，而不是运行环境。**：AI Context Pack 只包含证据化项目理解，不包含目标项目的可执行状态。 证据：`README.md`, `CONTRIBUTING.md`, `LICENSE`\n- **回答用户时区分可预览内容与必须安装后才能验证的内容。**：安装前体验的消费者价值来自降低误装和误判，而不是伪装成真实运行。 证据：`README.md`, `CONTRIBUTING.md`, `LICENSE`\n\n## 用户开工前应该回答的问题\n\n- 你准备在哪个宿主 AI 或本地环境中使用它？\n- 你只是想先体验工作流，还是准备真实安装？\n- 你最在意的是安装成本、输出质量、还是和现有规则的冲突？\n\n## 验收标准\n\n- 所有能力声明都能回指到 evidence_refs 中的文件路径。\n- AI_CONTEXT_PACK.md 没有把预览包装成真实运行。\n- 用户能在 3 分钟内看懂适合谁、能做什么、如何开始和风险边界。\n\n---\n\n## Doramagic Context Augmentation\n\nThe following material strengthens the Repomix/AI Context Pack body. Human Manual is only a reading skeleton; pitfall logs become hard operating constraints for the host AI.\n\n## Human Manual Skeleton\n\nUsage rule: this is only a reading path and salience signal, not factual authority. Concrete facts must still come from repo evidence / Claim Graph.\n\nHard rules for the host AI:\n- Do not treat page titles, order, summaries, or importance as project facts.\n- When explaining the Human Manual skeleton, state that it is only a reading path / salience signal.\n- Capability, installation, compatibility, runtime status, and risk judgments must cite repo evidence, source paths, or Claim Graph.\n\n- **Introduction to THOUGHT**：importance `high`\n  - source_paths: README.md, docs/comparison.md, src/thought/models.py\n- **Quickstart Guide**：importance `high`\n  - source_paths: src/thought/demo.py, src/thought/cli.py\n- **Installation and Setup**：importance `high`\n  - source_paths: pyproject.toml, src/thought/config.py, Dockerfile\n- **System Architecture**：importance `high`\n  - source_paths: src/thought/server.py, src/thought/memory.py, src/thought/layers/__init__.py, src/thought/router/dispatcher.py, src/thought/router/classifier.py\n- **Storage and Database Layer**：importance `high`\n  - source_paths: src/thought/storage/__init__.py, src/thought/storage/base.py, src/thought/storage/sqlite/backend.py, src/thought/storage/sqlite/migrations/0001_initial.sql, src/thought/storage/sqlite/migrations/0002_v0.2_code.sql\n- **Memory Model and Data Structures**：importance `high`\n  - source_paths: src/thought/models.py, src/thought/ingest/entities.py, src/thought/consolidation/engine.py, src/thought/layers/vector.py, src/thought/layers/graph.py\n- **Query and Retrieval System**：importance `high`\n  - source_paths: src/thought/query/__init__.py, src/thought/query/ask.py, src/thought/query/cypher.py, src/thought/query/views.py, src/thought/hooks/recall.py\n- **Multi-Language Code Parsing**：importance `medium`\n  - source_paths: src/thought/ingest/code/__init__.py, src/thought/ingest/code/ast_extractor.py, src/thought/ingest/code/call_graph.py, src/thought/ingest/code/pipeline.py, src/thought/ingest/code/python_extractor.py\n\n## Repo Inspection Evidence\n\n- repo_clone_verified: true\n- repo_inspection_verified: true\n- repo_commit: `a84a387fca07fbccfeb8d38f22c1c17661552b9d`\n- inspected_files: `pyproject.toml`, `Dockerfile`, `README.md`, `docs/ablation.md`, `docs/comparison.md`, `src/thought/cli.py`, `src/thought/models.py`, `src/thought/demo.py`, `src/thought/memory.py`, `src/thought/server.py`, `src/thought/__init__.py`, `src/thought/config.py`, `src/thought/clients.py`, `src/thought/embeddings/deterministic.py`, `src/thought/embeddings/ollama.py`, `src/thought/embeddings/openai_compat.py`, `src/thought/embeddings/__init__.py`, `src/thought/embeddings/sentence_transformer.py`, `src/thought/embeddings/base.py`, `src/thought/llm/__init__.py`\n\nHard rules for the host AI:\n- Without repo_clone_verified=true, do not claim the source code has been read.\n- Without repo_inspection_verified=true, do not turn README/docs/package observations into facts.\n- Without quick_start_verified=true, do not claim the Quick Start has been successfully run.\n\n## Doramagic Pitfall Constraints\n\nThese rules come from Doramagic discovery, validation, or compilation pitfalls. The host AI must treat them as operating constraints, not general background notes.\n\n### Constraint 1: 可能修改宿主 AI 配置\n\n- Trigger: 项目面向 Claude/Cursor/Codex/Gemini/OpenCode 等宿主，或安装命令涉及用户配置目录。\n- Host AI rule: 列出会写入的配置文件、目录和卸载/回滚步骤。\n- Why it matters: 安装可能改变本机 AI 工具行为，用户需要知道写入位置和回滚方法。\n- Evidence: capability.host_targets | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | host_targets=mcp_host, claude, claude_code, chatgpt\n- Hard boundary: do not present this pitfall as solved, verified, or safe to ignore unless later validation evidence explicitly closes it.\n\n### Constraint 2: 能力判断依赖假设\n\n- Trigger: README/documentation is current enough for a first validation pass.\n- Host AI rule: 将假设转成下游验证清单。\n- Why it matters: 假设不成立时，用户拿不到承诺的能力。\n- Evidence: capability.assumptions | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | README/documentation is current enough for a first validation pass.\n- Hard boundary: do not present this pitfall as solved, verified, or safe to ignore unless later validation evidence explicitly closes it.\n\n### Constraint 3: 来源证据：v0.2.1 — thought upgrade + mcp-extras fix\n\n- Trigger: GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.2.1 — thought upgrade + mcp-extras fix\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能增加新用户试用和生产接入成本。\n- Evidence: community_evidence:github | cevd_dc6434cd71064812ae14d01e7f5d9ef0 | https://github.com/RNBBarrett/thought-mcp/releases/tag/v0.2.1 | 来源类型 github_release 暴露的待验证使用条件。\n- Hard boundary: do not present this pitfall as solved, verified, or safe to ignore unless later validation evidence explicitly closes it.\n\n### Constraint 4: 维护活跃度未知\n\n- Trigger: 未记录 last_activity_observed。\n- Host AI rule: 补 GitHub 最近 commit、release、issue/PR 响应信号。\n- Why it matters: 新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- Evidence: evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | last_activity_observed missing\n- Hard boundary: do not present this pitfall as solved, verified, or safe to ignore unless later validation evidence explicitly closes it.\n\n### Constraint 5: 下游验证发现风险项\n\n- Trigger: no_demo\n- Host AI rule: 进入安全/权限治理复核队列。\n- Why it matters: 下游已经要求复核，不能在页面中弱化。\n- Evidence: downstream_validation.risk_items | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | no_demo; severity=medium\n- Hard boundary: do not present this pitfall as solved, verified, or safe to ignore unless later validation evidence explicitly closes it.\n\n### Constraint 6: 存在评分风险\n\n- Trigger: no_demo\n- Host AI rule: 把风险写入边界卡，并确认是否需要人工复核。\n- Why it matters: 风险会影响是否适合普通用户安装。\n- Evidence: risks.scoring_risks | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | no_demo; severity=medium\n- Hard boundary: do not present this pitfall as solved, verified, or safe to ignore unless later validation evidence explicitly closes it.\n\n### Constraint 7: issue/PR 响应质量未知\n\n- Trigger: issue_or_pr_quality=unknown。\n- Host AI rule: 抽样最近 issue/PR，判断是否长期无人处理。\n- Why it matters: 用户无法判断遇到问题后是否有人维护。\n- Evidence: evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | issue_or_pr_quality=unknown\n- Hard boundary: do not present this pitfall as solved, verified, or safe to ignore unless later validation evidence explicitly closes it.\n\n### Constraint 8: 发布节奏不明确\n\n- Trigger: release_recency=unknown。\n- Host AI rule: 确认最近 release/tag 和 README 安装命令是否一致。\n- Why it matters: 安装命令和文档可能落后于代码，用户踩坑概率升高。\n- Evidence: evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | release_recency=unknown\n- Hard boundary: do not present this pitfall as solved, verified, or safe to ignore unless later validation evidence explicitly closes it.\n",
      "summary": "Context and operating boundaries for host AI agents.",
      "title": "AI Context Pack"
    },
    "boundary_risk_card": {
      "asset_id": "boundary_risk_card",
      "filename": "BOUNDARY_RISK_CARD.md",
      "markdown": "# Boundary & Risk Card\n\nProject: RNBBarrett/thought-mcp\n\n## Doramagic Trial Decision\n\nCurrent decision: it can enter pre-publication recommendation checks. First use should still start with least privilege, a temporary directory, and reversible configuration.\n\n## What The User Can Do Now\n\n- Read the Human Manual first to understand the project purpose and main workflows.\n- Use Prompt Preview for pre-install exploration; it validates interaction shape, not real execution.\n- Run official Quick Start commands only inside an isolated environment, not a primary setup.\n\n## Do Not Do Yet\n\n- Do not treat Prompt Preview as a real project execution result.\n- Do not treat metadata-only validation as sandbox installation validation.\n- Do not describe unverified capabilities as supported, working, or safe to install.\n- Do not provide production data, private files, real secrets, or primary host configuration on first trial.\n\n## Pre-Install Checklist\n\n- Host AI match: mcp_host, claude, claude_code, chatgpt\n- Official installation entry status: official entry point found\n- Isolated temporary directory, temporary host, or container validation: required\n- Configuration rollback path: required\n- API keys, network access, file access, or host configuration changes: treat as high risk until confirmed\n- Installation command, actual output, and failure logs: must be recorded\n\n## Current Blockers\n\n- review_required: community_discussion_evidence_below_public_threshold\n\n## Project-Specific Pitfalls\n\n- 可能修改宿主 AI 配置 (medium): 安装可能改变本机 AI 工具行为，用户需要知道写入位置和回滚方法。 Suggested check: 列出会写入的配置文件、目录和卸载/回滚步骤。\n- 能力判断依赖假设 (medium): 假设不成立时，用户拿不到承诺的能力。 Suggested check: 将假设转成下游验证清单。\n- 来源证据：v0.2.1 — thought upgrade + mcp-extras fix (medium): 可能增加新用户试用和生产接入成本。 Suggested check: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 维护活跃度未知 (medium): 新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。 Suggested check: 补 GitHub 最近 commit、release、issue/PR 响应信号。\n- 下游验证发现风险项 (medium): 下游已经要求复核，不能在页面中弱化。 Suggested check: 进入安全/权限治理复核队列。\n\n## Risk And Permission Notes\n\n- no_demo: medium\n\n## Evidence Gaps\n\n- No structured evidence gaps are currently visible.\n",
      "summary": "Installation, permission, validation, and pre-recommendation risks.",
      "title": "Boundary & Risk Card"
    },
    "human_manual": {
      "asset_id": "human_manual",
      "filename": "HUMAN_MANUAL.md",
      "markdown": "# https://github.com/RNBBarrett/thought-mcp 项目说明书\n\n生成时间：2026-05-16 09:34:00 UTC\n\n## 目录\n\n- [Introduction to THOUGHT](#page-introduction)\n- [Quickstart Guide](#page-quickstart)\n- [Installation and Setup](#page-installation)\n- [System Architecture](#page-architecture)\n- [Storage and Database Layer](#page-storage-layer)\n- [Memory Model and Data Structures](#page-memory-model)\n- [Query and Retrieval System](#page-query-system)\n- [Multi-Language Code Parsing](#page-code-parsing)\n- [Git History Integration](#page-git-integration)\n- [Agent Adapters and SDK Integration](#page-agent-adapters)\n\n<a id='page-introduction'></a>\n\n## Introduction to THOUGHT\n\n### 相关页面\n\n相关主题：[Quickstart Guide](#page-quickstart), [Installation and Setup](#page-installation), [System Architecture](#page-architecture)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/RNBBarrett/thought-mcp/blob/main/README.md)\n- [docs/comparison.md](https://github.com/RNBBarrett/thought-mcp/blob/main/docs/comparison.md)\n- [src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n- [src/thought/demo.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n- [src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n- [src/thought/storage/sqlite/backend.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/backend.py)\n- [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n</details>\n\n# Introduction to THOUGHT\n\nTHOUGHT is a local AI memory tool designed to help developers, researchers, writers, and investigators maintain persistent, queryable knowledge graphs of their work. It combines graph database technology with natural language processing to create a bi-temporal knowledge base that tracks information across time—answering questions like \"what was true on date X\" and \"what did the system know on date X.\" 资料来源：[README.md](https://github.com/RNBBarrett/thought-mcp/blob/main/README.md)\n\n## What is THOUGHT?\n\nTHOUGHT operates as a self-hosted memory layer that runs entirely on your local machine. Unlike cloud-based AI memory solutions, THOUGHT stores everything in a local SQLite database, giving you full control over your data while still providing powerful querying capabilities through natural language or Cypher graph queries. 资料来源：[src/thought/cli.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\nThe core philosophy is to treat memory as a first-class citizen in the development workflow—something that persists across sessions, understands context, and can be queried like a real database rather than a simple key-value store.\n\n## Core Architecture\n\nTHOUGHT's architecture consists of several interconnected layers that work together to provide a complete memory solution.\n\n```mermaid\ngraph TD\n    A[CLI / MCP Server] --> B[Query Layer]\n    B --> C[Graph Layer]\n    B --> D[Code Layer]\n    C --> E[Storage Backend]\n    D --> E\n    E --> F[SQLite Database]\n    B --> G[LLM Providers]\n    G --> H[Ollama / LM Studio / OpenAI]\n```\n\n### Storage Layer\n\nThe storage layer uses SQLite with a carefully designed schema that supports bi-temporal modeling. Every entity and edge in the knowledge graph has timestamps tracking when facts became valid and when they were learned. 资料来源：[src/thought/storage/sqlite/backend.py:1-100](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/backend.py)\n\n| Component | Purpose |\n|-----------|---------|\n| `SQLiteBackend` | Core database operations with upsert, query, and embedding storage |\n| WAL Mode | Write-Ahead Logging for crash recovery and concurrent reads |\n| Migration System | Tracks applied migrations in `applied_migrations` table |\n| Bi-temporal Columns | `valid_from`, `valid_until`, `learned_at`, `unlearned_at` |\n\n### Query Layer\n\nThe query layer provides multiple interfaces for accessing your memory:\n\n- **Natural Language**: Ask questions in plain English, translated to Cypher\n- **Code Queries**: Find callers, callees, and impact sets\n- **Recall**: Semantic search using embeddings\n- **Cypher Direct**: Execute graph queries directly 资料来源：[src/thought/query/ask.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n\n### Graph Layer\n\nThe graph layer provides the core graph operations that power all THOUGHT functionality. It handles entity and edge management with support for scopes (shared/private) and owner-based access control. 资料来源：[src/thought/layers/graph.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/graph.py)\n\n## Entity Model\n\nTHOUGHT uses a flexible entity model that can represent code elements, prose content, legal documents, and research claims.\n\n```mermaid\nclassDiagram\n    class Entity {\n        +str id\n        +str type\n        +str name\n        +str canonical_name\n        +ScopeName scope\n        +Tier tier\n        +float importance\n        +datetime valid_from\n        +datetime valid_until\n        +datetime learned_at\n        +dict~str, object~ attrs\n    }\n    \n    class Edge {\n        +str id\n        +str source_id\n        +str target_id\n        +str relation_type\n    }\n    \n    Entity \"1\" --> \"*\" Edge : source\n    Entity \"1\" --> \"*\" Edge : target\n```\n\n资料来源：[src/thought/models.py:50-100](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n\n### Entity Attributes\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `id` | str | Unique identifier |\n| `type` | str | Entity type (function, class, module, claim, etc.) |\n| `name` | str | Human-readable name |\n| `canonical_name` | str | Fully qualified name for disambiguation |\n| `scope` | ScopeName | \"shared\" or \"private\" |\n| `owner_id` | str | Owner for private entities |\n| `tier` | Tier | \"hot\", \"warm\", or \"cold\" |\n| `valid_from` | datetime | When this fact became true |\n| `valid_until` | datetime | When this fact stopped being true (null = current) |\n| `learned_at` | datetime | When THOUGHT learned this fact |\n| `attrs` | dict | Additional type-specific metadata |\n\n### Edge Relations\n\nEdges represent relationships between entities with the following relation types:\n\n| Relation Type | Description |\n|---------------|-------------|\n| `CALLS` | Function/method invocation |\n| `INHERITS_FROM` | Class inheritance |\n| `DEFINES` | Container defines member |\n| `IMPORTS` | Module import statement |\n| `CONTRADICTS` | Logical contradiction between facts |\n| `CITES` | Source citation relationship |\n\n## Audience Verticals\n\nTHOUGHT is designed to serve multiple audiences, each with specialized commands and entity taxonomies optimized for their use case. 资料来源：[src/thought/demo.py:1-80](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n\n```mermaid\ngraph LR\n    A[THOUGHT] --> B[Code Developers]\n    A --> C[Writers]\n    A --> D[Legal Investigators]\n    A --> E[Researchers]\n    \n    B --> B1[thought scan]\n    B --> B2[thought impact]\n    B --> B3[thought callers]\n    \n    C --> C1[thought ingest-prose]\n    C --> C2[thought timeline]\n    C --> C3[contradiction-check]\n    \n    D --> D1[thought ingest-legal]\n    D --> D2[unique_predicates]\n    D --> D3[contradiction-graph]\n    \n    E --> E1[thought ingest-claim]\n    E --> E2[citation-analysis]\n    E --> E3[reliability-filter]\n```\n\n### Code Developers\n\nThe code vertical provides tools for understanding, navigating, and analyzing source code:\n\n- **`thought scan`**: Incremental code scanning with change detection\n- **`thought impact <name>`**: Transitive impact set—what's affected if I change this?\n- **`thought callers <name>`**: Direct callers ranked by Personalized PageRank\n- **`thought recall`**: Semantic search across code by intent 资料来源：[src/thought/layers/code.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n\n### Writers\n\nThe writing vertical supports fiction and academic prose:\n\n- Ingest chapter/section facts about characters\n- Detect contradictions via the bi-temporal model\n- Query chronological mentions across documents\n- Time-travel `as_of` recall for historical consistency\n\n### Legal Investigators\n\nThe legal vertical is designed for investigation workflows:\n\n- **`thought ingest-legal`**: Ingest witness statements with unique predicates\n- **`thought contradiction-graph`**: Trigger CONTRADICTS edges between testimonies\n- Query the contradiction graph for investigation leads\n\n### Researchers\n\nThe research vertical supports academic workflows:\n\n- **`thought ingest-claim`**: Ingest claim/source pairs\n- Cypher queries to find uncited claims\n- Most-cited source identification\n- Citation reliability filtering\n\n## CLI Commands Overview\n\n| Command | Description |\n|---------|-------------|\n| `thought init` | Create database file + config + CLAUDE.md |\n| `thought recall <query>` | Semantic recall with embeddings |\n| `thought ask <question>` | Natural language query → Cypher → results |\n| `thought scan <repo>` | Incremental code scan with change detection |\n| `thought callers <name>` | Find direct callers ranked by PageRank |\n| `thought impact <name>` | Transitive impact set |\n| `thought db size` | Disk usage + entity/edge counts |\n| `thought db flush` | Wipe the knowledge base |\n| `thought db backup <file>` | SQLite online-backup snapshot |\n| `thought db load <file>` | Load backup file |\n| `thought hook install` | Install Claude Code hooks |\n| `thought diff --from <sha1> --to <sha2>` | Entity diff between commits |\n\n资料来源：[src/thought/cli.py:50-150](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n## Database Lifecycle Management\n\nTHOUGHT provides comprehensive database management commands under `thought db`:\n\n### Backup and Restore\n\n```mermaid\ngraph LR\n    A[Production DB] -->|thought db backup| B[backup.db]\n    B -->|thought db load| C[Production DB]\n    B -->|thought db inspect| D[Inspection Report]\n```\n\nThe backup system uses SQLite's online backup API, ensuring consistent snapshots even during active writes. Date filters can produce clean, self-contained subset files. 资料来源：[src/thought/storage/sqlite/backend.py:100-200](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/backend.py)\n\n### Flush Operations\n\nFlush commands support date-bounded deletion:\n- `--before X`: Delete facts valid before date X\n- `--since X`: Delete facts learned since date X\n- `--time-axis valid|learned|created`: Choose which time axis to filter\n\nAll destructive operations automatically back up to `<db>.bak.<timestamp>` before proceeding.\n\n## Git History Integration\n\nTHOUGHT can ingest git repositories with two modes:\n\n| Mode | Behavior | Use Case |\n|------|----------|----------|\n| `snapshot` (default) | Ingest HEAD only, stamp with HEAD SHA | Fast code analysis |\n| `full` | Walk every commit, stamp with commit SHA | Bi-temporal historical queries |\n\nThe `GitWalker` class shells out to `git` commands rather than using native libraries, avoiding C extension dependencies while maintaining cross-platform compatibility. 资料来源：[src/thought/ingest/code/git_walker.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/git_walker.py)\n\n```mermaid\ngraph TD\n    A[thought ingest-git] --> B{Snapshot Mode?}\n    B -->|Yes| C[Ingest HEAD only]\n    B -->|No| D[Walk all commits]\n    C --> E[Stamp with HEAD SHA]\n    D --> F[Stamp each entity with commit SHA]\n    E --> G[Enable as_of queries]\n    F --> G\n```\n\n## Bi-temporal Model\n\nTHOUGHT's bi-temporal model tracks two independent timelines for every fact:\n\n| Time Axis | Description | Question Answered |\n|-----------|-------------|-------------------|\n| **Valid Time** | When a fact was true in reality | \"What was true on date X?\" |\n| **Learned Time** | When THOUGHT learned the fact | \"What did the system know on date X?\" |\n\nThis distinction enables sophisticated queries like:\n\n```cypher\nMATCH (e:Entity)\nWHERE e.valid_from <= date('2024-01-01')\n  AND (e.valid_until IS NULL OR e.valid_until > date('2024-01-01'))\nRETURN e\n```\n\nContradictions surface as `CONTRADICTS` edges—they're treated as data rather than warnings, allowing you to query them directly. 资料来源：[src/thought/cli.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n## LLM Provider Integration\n\nTHOUGHT supports multiple LLM providers for natural language processing:\n\n| Provider | Features |\n|----------|----------|\n| **Ollama** | Native `/api/embed` (batched), OpenAI-compatible fallback |\n| **LM Studio** | OpenAI-compatible API |\n| **Any OpenAI-compatible server** | Standard embedding endpoints |\n\nThe embedder selection defaults to `auto`, which probes for `sentence_transformers` and falls back to a deterministic embedder when the optional dependency is unavailable. 资料来源：[src/thought/storage/sqlite/backend.py:200-300](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/backend.py)\n\n## Code Extraction Support\n\nTHOUGHT can parse and extract entities from multiple programming languages:\n\n| Language | Extractor | Key Features |\n|----------|-----------|--------------|\n| Python | `python_extractor.py` | AST-based import tracking, class/function detection |\n| TypeScript | `typescript_extractor.py` | Tree-sitter parsing, heritage analysis |\n| Rust | `rust_extractor.py` | Module system, impl block handling |\n| PHP | `php_extractor.py` | Namespace handling, method visibility |\n\nAll extractors produce consistent `CodeEntity` and `CodeEdge` objects that integrate with the unified graph model. 资料来源：[src/thought/ingest/code/python_extractor.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/python_extractor.py)\n\n## Getting Started\n\n### Initialization\n\n```bash\nthought init --db-path .thought/thought.db --embedder auto\n```\n\nThis creates:\n1. The SQLite database file\n2. A `thought.toml` configuration file\n3. A `CLAUDE.md` file for MCP client integration\n\n### Quick Start Commands\n\n```bash\n# Ingest a git repository\nthought ingest-git ./my-project --mode snapshot\n\n# Recall something semantically\nthought recall \"authentication middleware\"\n\n# Ask a natural language question\nthought ask \"what calls the authenticate_user function?\"\n\n# Find impact of changing a function\nthought impact MyClass.my_method\n```\n\n## Configuration\n\nTHOUGHT uses a `thought.toml` file for configuration:\n\n| Section | Option | Default | Description |\n|---------|--------|---------|-------------|\n| `database` | `path` | `.thought/thought.db` | Database file path |\n| `llm` | `provider` | `auto` | LLM provider selection |\n| `embedder` | `model` | `auto` | Embedding model |\n| `scopes` | `default` | `shared` | Default scope for new entities |\n\nConfiguration can be overridden via CLI flags or environment variables.\n\n---\n\n<a id='page-quickstart'></a>\n\n## Quickstart Guide\n\n### 相关页面\n\n相关主题：[Introduction to THOUGHT](#page-introduction), [Installation and Setup](#page-installation)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/demo.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n- [src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n- [src/thought/ingest/code/pipeline.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/pipeline.py)\n- [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n- [src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n- [CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n</details>\n\n# Quickstart Guide\n\n## Overview\n\n**THOUGHT** is a local-AI memory tool designed to manage knowledge bases, run on local models, write graph queries, and query in natural language. It provides a comprehensive CLI for ingesting information, recalling facts, and performing code analysis with graph-based relationships.\n\n资料来源：[CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n\n## Architecture Overview\n\n```mermaid\ngraph TD\n    subgraph \"THOUGHT Core\"\n        CLI[CLI Interface]\n        DB[(SQLite Database)]\n        EMB[Embedder Layer]\n        GRAPH[Graph Layer]\n    end\n    \n    subgraph \"Ingestion Sources\"\n        CODE[Code Ingest]\n        PROSE[Prose Ingest]\n        LEGAL[Legal Ingest]\n    end\n    \n    subgraph \"Query Interface\"\n        RECALL[Recall Command]\n        REPL[Interactive REPL]\n        MCP[MCP Server]\n    end\n    \n    CLI --> DB\n    CLI --> EMB\n    EMB --> DB\n    CODE --> CLI\n    PROSE --> CLI\n    LEGAL --> CLI\n    RECALL --> GRAPH\n    REPL --> GRAPH\n    MCP --> GRAPH\n    GRAPH --> DB\n```\n\n资料来源：[src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n## Installation and Initialization\n\n### Initial Setup\n\nRun the `init` command to create the database, configuration file, and CLAUDE.md helper:\n\n```bash\nthought init\n```\n\nThe init command accepts several options:\n\n| Option | Default | Description |\n|--------|---------|-------------|\n| `--config` | `thought.toml` | Path to configuration file |\n| `--db-path` | `.thought/thought.db` | SQLite database path |\n| `--embedder` | `auto` | Embedder type: `auto`, `sentence-transformers`, or `deterministic` |\n| `--write-claude-md` | `true` | Drop a CLAUDE.md for MCP clients |\n| `--quick` | `false` | Skip first-run embedder warmup |\n\n资料来源：[src/thought/cli.py:57-78](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n### Configuration File\n\nThe init command creates a `thought.toml` configuration file with the following structure:\n\n```toml\n[database]\npath = \".thought/thought.db\"\n\n[embedder]\ntype = \"auto\"  # or \"ollama\", \"lm_studio\", \"openai_compatible\"\n\n[llm]\nprovider = \"auto\"\n```\n\n## Core Commands\n\n### Ingest Commands\n\nTHOUGHT supports multiple ingestion modes:\n\n| Command | Purpose |\n|---------|---------|\n| `thought ingest TEXT` | One-shot remember from command line |\n| `thought ingest --file PATH` | Ingest a single file |\n| `thought ingest --glob PAT` | Bulk-ingest matching files |\n| `thought ingest --stdin` | Bulk-ingest one line-per-item from stdin |\n\n资料来源：[src/thought/cli.py:30-42](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n### Code Ingestion\n\nThe code ingest pipeline extracts entities and relationships from source files:\n\n```bash\nthought ingest --file src/main.py\nthought ingest --glob \"**/*.py\"\n```\n\nThe code extractor produces:\n\n- **Entities**: modules, functions, classes, methods\n- **Edges**: `IMPORTS`, `INHERITS_FROM`, `DEFINES`, `OVERRIDES`\n\n资料来源：[src/thought/ingest/code/pipeline.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/pipeline.py)\n\n### Git-Aware Ingest\n\nFor bi-temporal code analysis:\n\n```bash\nthought ingest-git <repo> --mode snapshot  # Fast: HEAD only\nthought ingest-git <repo> --mode full      # Walk every commit\n```\n\nThis enables `as_of` queries against historical commits.\n\n资料来源：[CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n\n### Recall and Query\n\n```bash\nthought recall \"what did I learn about authentication?\"\nthought repl\n```\n\nThe `recall` command returns up to 10 results with ranked relevance. Use `as_of` and `scope` to narrow results further.\n\n资料来源：[src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n### Database Management\n\n| Command | Description |\n|---------|-------------|\n| `thought db size` | Disk usage + entity/edge counts |\n| `thought db flush` | Wipe the KB (with backup) |\n| `thought db backup <file>` | SQLite backup snapshot |\n| `thought db load <file>` | Load a backup file |\n| `thought db inspect <file>` | Inspect backup without loading |\n\n资料来源：[CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n\n## Code Analysis Commands\n\n### Callers and Impact Analysis\n\n```bash\n# Find who calls a function (ranked by PageRank)\nthought callers authenticate_user\n\n# Transitive impact: what's affected if I change this?\nthought impact JWTValidator\n```\n\n资料来源：[src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n\n### Diff Between Commits\n\n```bash\nthought diff --from abc1234 --to def5678\n```\n\nThis shows entities added/removed between two ingested commits.\n\n## Built-in Demos\n\nRun audience-specific walkthroughs:\n\n```bash\nthought demo code        # Agent/developer flow (14-stage walkthrough)\nthought demo writer       # Novelist/paper author\nthought demo legal        # Investigator/paralegal\nthought demo researcher   # Academic use case\nthought demo all          # Run all demos sequentially\n```\n\nEach demo runs end-to-end in a self-cleaning temporary directory and produces a structured `DemoReport`.\n\n资料来源：[src/thought/demo.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n\n## Entity Data Model\n\n```python\n@dataclass(frozen=True)\nclass CodeEntity:\n    name: str           # Qualified name (e.g., \"ClassName.method_name\")\n    type_: CodeEntityType  # \"module\" | \"function\" | \"class\" | \"method\" | \"file\"\n    language: str       # Programming language\n    file_path: str      # POSIX-style relative path\n    line_start: int     # Starting line number\n    line_end: int       # Ending line number\n    signature: str      # Function/class signature\n    docstring: str | None\n    visibility: Literal[\"public\", \"private\"]\n```\n\n资料来源：[src/thought/ingest/code/types.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/types.py)\n\n## Supported Languages\n\nThe code ingestion pipeline supports:\n\n| Language | Extractor | File Extension |\n|----------|-----------|----------------|\n| Python | `python_extractor.py` | `.py` |\n| TypeScript | `typescript_extractor.py` | `.ts`, `.tsx` |\n| PHP | `php_extractor.py` | `.php` |\n| Rust | `rust_extractor.py` | `.rs` |\n\n## MCP Server\n\nStart the MCP server for integration with Claude Code:\n\n```bash\nthought serve                          # stdio transport (default)\nthought serve --transport streamable-http  # HTTP transport\n```\n\n资料来源：[src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n## Utility Commands\n\n| Command | Description |\n|---------|-------------|\n| `thought stats` | Display knowledge base statistics |\n| `thought forget PATTERN` | Soft-delete entities matching SQL LIKE pattern |\n| `thought consolidate` | Run one consolidation cycle |\n| `thought doctor` | Environment health check |\n\n## Bi-Temporal Model\n\nTHOUGHT uses a bi-temporal model for knowledge tracking:\n\n- **`valid_from` / `valid_until`**: When facts were true in reality\n- **`learned_at` / `unlearned_at`**: When the system learned/corrected facts\n\nQuery variants:\n- `as_of_kind='valid'` — \"what was true on date X\"\n- `as_of_kind='learned'` — \"what did the system know on date X\"\n\n资料来源：[src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n\n---\n\n<a id='page-installation'></a>\n\n## Installation and Setup\n\n### 相关页面\n\n相关主题：[Quickstart Guide](#page-quickstart), [System Architecture](#page-architecture)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n- [src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n- [src/thought/hooks/install.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n- [src/thought/demo.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n- [CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n- [CONTRIBUTING.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CONTRIBUTING.md)\n</details>\n\n# Installation and Setup\n\n## Overview\n\nThe `thought-mcp` project provides a comprehensive CLI tool and MCP (Model Context Protocol) server for AI-powered memory and knowledge management. The installation and setup process involves initializing the local SQLite database, configuring MCP clients (Claude Code, Cursor, etc.), and optionally setting up Claude Code hooks for automated memory operations.\n\nThe setup system is designed with idempotency in mind — installations can be safely re-run without disrupting existing configurations.\n\n## System Architecture\n\n```mermaid\ngraph TD\n    A[User] --> B[thought CLI]\n    B --> C[init command]\n    C --> D[SQLite Database]\n    C --> E[thought.toml Config]\n    C --> F[CLAUDE.md Agent Hint]\n    B --> G[MCP Server]\n    G --> D\n    B --> H[Client Install]\n    H --> I[Claude Code]\n    H --> J[Cursor]\n    H --> K[VS Code]\n    B --> L[Hook Install]\n    L --> M[.claude/settings.json]\n```\n\n## Prerequisites\n\n| Component | Requirement | Notes |\n|-----------|-------------|-------|\n| Python | >= 3.10 | Core runtime |\n| Git | On PATH | Used by git pipeline for code ingestion |\n| SQLite | 3.x | Bundled with Python stdlib |\n| pip/pipx | Latest | Package installation |\n\n资料来源：[CONTRIBUTING.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CONTRIBUTING.md)\n\n## Installation Methods\n\n### Standard Installation\n\n```bash\npip install thought-mcp\n```\n\n### Development Installation\n\n```bash\ngit clone https://github.com/RNBBarrett/thought-mcp.git\ncd thought-mcp\npip install -e \".[dev]\"\n```\n\n## CLI Initialization\n\nThe `thought init` command establishes the complete working environment. It creates three essential components in sequence.\n\n### Init Command Signature\n\n```python\n@app.command()\ndef init(\n    config: Path = typer.Option(\"thought.toml\", help=\"Path to config file.\"),\n    db_path: str = typer.Option(\".thought/thought.db\", help=\"SQLite database path.\"),\n    embedder: str = typer.Option(\n        \"auto\", help=\"'auto' picks sentence-transformers if available, else deterministic.\",\n    ),\n    write_claude_md: bool = typer.Option(\n        True, \"--write-claude-md/--no-claude-md\",\n        help=\"Drop a CLAUDE.md so MCP clients learn how to use the tool.\",\n    ),\n    quick: bool = typer.Option(\n        False, \"--quick\", help=\"Skip first-run embedder warmup.\",\n    ),\n) -> None:\n```\n\n资料来源：[src/thought/cli.py:35-56](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n### What Init Creates\n\n```mermaid\ngraph LR\n    A[thought init] --> B[Create .thought/ directory]\n    A --> C[Create SQLite DB file]\n    A --> D[Write thought.toml config]\n    A --> E[Write CLAUDE.md]\n    \n    B --> F[parents=True<br/>exist_ok=True]\n    C --> G[DB auto-backed up<br/>before destructive ops]\n```\n\n#### 1. Database Initialization\n\nThe command creates the SQLite database at the specified path. Parent directories are created automatically using `parents=True` to ensure the path exists.\n\n```python\nPath(db_path).parent.mkdir(parents=True, exist_ok=True)\n```\n\n资料来源：[src/thought/cli.py:52-53](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n#### 2. Configuration File\n\nThe `thought.toml` file contains runtime configuration including embedder settings and database paths.\n\n#### 3. CLAUDE.md Agent Hint\n\nWhen `write_claude_md=True` (default), the init command drops a `CLAUDE.md` file that teaches MCP clients how to interact with the tool.\n\n### Embedder Configuration\n\nThe init command supports three embedder modes:\n\n| Mode | Behavior | Dependencies |\n|------|----------|--------------|\n| `auto` (default) | Uses `sentence-transformers` if available, falls back to deterministic embeddings | Optional: sentence-transformers |\n| `sentence-transformers` | Uses local transformer models for embeddings | Required: sentence-transformers |\n| `deterministic` | Uses hash-based embeddings, no ML dependencies | None |\n\nThe `--quick` flag skips the first-run embedder warmup process.\n\n## MCP Client Installation\n\nThe `thought clients install` command merges a `thought` MCP server entry into your client's configuration file.\n\n### Supported Clients\n\n| Client | Config Location |\n|--------|-----------------|\n| Claude Code | `.claude/settings.json` |\n| Cursor | `~/.cursor/settings.json` |\n| VS Code | `~/.cursor/settings.json` |\n\n### Installation Workflow\n\n```mermaid\ngraph TD\n    A[thought clients install] --> B{Check config exists?}\n    B -->|No| C[Create new config file]\n    B -->|Yes| D[Read existing JSON]\n    C --> E{Valid JSON object?}\n    D --> E\n    E -->|Yes| F[Merge mcpServers entry]\n    E -->|No| G[Return error]\n    F --> H{Backup enabled?}\n    H -->|Yes| I[Create .thought.bak backup]\n    H -->|No| J[Write merged config]\n    I --> J\n    J --> K[Return ClientInstallResult]\n```\n\n### Client Install Result States\n\n```python\n@dataclass(frozen=True)\nclass ClientInstallResult:\n    client: ClientName\n    path: Path\n    status: Literal[\"installed\", \"already_present\", \"no_path\", \"error\"]\n    detail: str = \"\"\n```\n\n资料来源：[src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n\n### Server Block Structure\n\nThe MCP server configuration block includes:\n\n- Server name (`thought`)\n- Command to execute\n- Server arguments\n- Environment variables for database path\n\n## Claude Code Hook Installation\n\nThe `thought hooks install` command adds hook entries to Claude Code's settings for automated memory operations.\n\n### Hook Types\n\n| Hook Kind | Claude Code Event | Command |\n|-----------|-------------------|---------|\n| `recall` | UserPromptSubmit | `thought hook recall` |\n| `write` | Stop | `thought hook write` |\n| `context` | SessionStart | `thought hook context` |\n\n资料来源：[src/thought/hooks/install.py:17-22](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n\n### Hook Installation Options\n\n```python\ndef settings_path(*, scope: Literal[\"project\", \"user\"] = \"project\") -> Path:\n    \"\"\"Return the ``.claude/settings.json`` path for the requested scope.\n\n    Project scope is the recommended default — it travels with the repo and\n    is what most users actually want for THOUGHT-flavoured auto-memory.\n    \"\"\"\n    if scope == \"project\":\n        return Path.cwd() / \".claude\" / \"settings.json\"\n```\n\n### Hook Install Process\n\n```mermaid\ngraph TD\n    A[thought hooks install recall] --> B{Backup enabled?}\n    B -->|Yes| C[Create settings.json.thought.bak]\n    B -->|No| D[Read settings.json]\n    C --> D\n    D --> E{Valid JSON?}\n    E -->|Yes| F[Merge recall hook entry]\n    E -->|No| G[Return error]\n    F --> H{Entry exists?}\n    H -->|Yes| I[Return already_present]\n    H -->|No| J[Write updated settings.json]\n    J --> K[Return HookInstallResult]\n```\n\n### Hook Install Result\n\n```python\n@dataclass(frozen=True)\nclass HookInstallResult:\n    kind: HookKind\n    path: Path\n    status: Literal[\"installed\", \"already_present\", \"error\"]\n    detail: str = \"\"\n```\n\n资料来源：[src/thought/hooks/install.py:28-32](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n\n## Quick Start Guide\n\n### Step 1: Initialize the Environment\n\n```bash\n# Standard initialization\nthought init\n\n# Skip embedder warmup for faster startup\nthought init --quick\n\n# Custom database location\nthought init --db-path /path/to/custom.db\n```\n\n### Step 2: Install MCP Client\n\n```bash\n# Install for Claude Code\nthought clients install claude_code\n\n# Install for Cursor\nthought clients install cursor\n```\n\n### Step 3: Install Claude Code Hooks (Optional)\n\n```bash\n# Install recall hook (automatic memory on user input)\nthought hooks install recall\n\n# Install write hook (save memory on session stop)\nthought hooks install write\n\n# Install context hook (load memory on session start)\nthought hooks install context\n\n# Install all hooks\nthought hooks install recall --kind write --kind context\n```\n\n## Database Lifecycle Management\n\n### Database Size Check\n\n```bash\nthought db size\n```\n\nShows disk usage of main + WAL + SHM sidecars plus entity/edge counts.\n\n### Database Backup\n\n```bash\nthought db backup <file>\n```\n\nCreates an SQLite online-backup snapshot. Date filters produce a clean, self-contained subset file with DELETE + VACUUM after backup.\n\n### Database Restore\n\n```bash\nthought db load <file>\n```\n\nAtomically replaces the active database with the backup file. Use `--merge` to INSERT-OR-IGNORE rows from the snapshot instead of replacing.\n\n### Database Flush\n\n```bash\n# Full flush with confirmation\nthought db flush\n\n# Skip confirmation\nthought db flush --yes\n\n# Date-bounded flush\nthought db flush --before 2024-01-01\nthought db flush --since 2024-06-01\n```\n\n> **Note**: All destructive operations auto-backup to `<db>.bak.<timestamp>` before proceeding.\n\n## Verifying Installation\n\n### Run the Demo\n\n```bash\n# Run code audience demo\nthought demo code\n\n# Run all demos\nthought demo all\n```\n\nThe demo runs an audience-specific walkthrough end-to-end in a self-cleaning temporary directory, verifying the installation works correctly.\n\n### Health Check\n\n```bash\nthought doctor\n```\n\nPerforms an environment health check to verify all dependencies and configurations are correct.\n\n## Configuration File Format\n\n### thought.toml\n\n```toml\n[database]\npath = \".thought/thought.db\"\n\n[embedder]\ntype = \"auto\"  # or \"sentence-transformers\", \"deterministic\"\n\n[server]\nname = \"thought\"\ntransport = \"stdio\"  # or \"streamable-http\"\n```\n\n## Troubleshooting\n\n### Common Issues\n\n| Issue | Solution |\n|-------|----------|\n| Config file not found | Run `thought init` first |\n| Database locked | Check for other `thought` processes |\n| Embedder initialization slow | Use `--quick` flag or `deterministic` embedder |\n| MCP client not connecting | Verify client config has correct server entry |\n\n### Reset Installation\n\n```bash\n# Backup current database\nthought db backup /path/to/backup.db\n\n# Flush and reinitialize\nthought db flush --yes\nthought init --db-path .thought/thought.db\n```\n\n## Next Steps\n\nAfter installation and setup, users typically:\n\n1. **Ingest code**: `thought ingest-git <repo>` to analyze repository code\n2. **Recall information**: `thought recall <query>` to query the knowledge base\n3. **Run agents**: Use reference agents like the vulnerability scanner or OSINT aggregator\n\n---\n\n<a id='page-architecture'></a>\n\n## System Architecture\n\n### 相关页面\n\n相关主题：[Introduction to THOUGHT](#page-introduction), [Storage and Database Layer](#page-storage-layer), [Memory Model and Data Structures](#page-memory-model)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/server.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/server.py)\n- [src/thought/ingest/code/pipeline.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/pipeline.py)\n- [src/thought/ingest/code/git_pipeline.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/git_pipeline.py)\n- [src/thought/query/ask.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n- [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n- [src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n- [src/thought/demo.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n- [src/thought/hooks/install.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n- [src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n</details>\n\n# System Architecture\n\n## Overview\n\nThe thought-mcp project is a Model Context Protocol (MCP) server implementation that provides an intelligent memory and code analysis system for AI-assisted development. The system combines semantic memory storage with code graph analysis, enabling natural language queries against codebases through a bi-temporal knowledge graph.\n\n## High-Level Architecture\n\n```mermaid\ngraph TD\n    subgraph \"Client Layer\"\n        MCP[MCP Client]\n        CLI[Thought CLI]\n        Hooks[Claude Code Hooks]\n    end\n    \n    subgraph \"Server Layer\"\n        Server[MCP Server]\n        Router[Query Router]\n        Classifier[Query Classifier]\n    end\n    \n    subgraph \"Memory Layer\"\n        Memory[Memory Manager]\n        Recall[Recall Engine]\n        Ask[Ask - NL to Cypher]\n    end\n    \n    subgraph \"Storage Layer\"\n        Backend[SQLite Backend]\n        Entities[Entity Store]\n        Edges[Edge Store]\n        Embeddings[Vector Embeddings]\n    end\n    \n    subgraph \"Ingest Layer\"\n        CodePipeline[Code Pipeline]\n        GitPipeline[Git Pipeline]\n        Extractors[Language Extractors]\n    end\n    \n    MCP --> Server\n    CLI --> Server\n    Hooks --> Server\n    Server --> Router\n    Router --> Classifier\n    Classifier --> Memory\n    Memory --> Backend\n    CodePipeline --> Backend\n    GitPipeline --> Backend\n    Ask --> Recall\n```\n\n## Core Components\n\n### MCP Server (`src/thought/server.py`)\n\nThe MCP server exposes the primary tool interface for AI clients. It implements async tool handlers that delegate to the memory layer.\n\n**Key Tools:**\n\n| Tool | Purpose |\n|------|---------|\n| `recall` | Semantic recall of entities using embeddings |\n| `ask` | Natural language queries translated to Cypher |\n| `working_context` | Context primitive for agent awareness |\n| `scan` | Incremental code scanning with change detection |\n\n资料来源：[src/thought/server.py:1-100]()\n\n### Query Router and Classifier\n\nThe system routes queries through a classification system that detects:\n\n- **CODE** queries: Triggered by code-shaped keywords (`function`, `class`, `caller`, `callee`, file extensions) plus camelCase/snake_case identifiers\n- **CHANGE** queries: Historical or diff-based queries\n- **HYBRID** combinations: CODE × CHANGE patterns like \"what changed in auth.middleware since v1.0\"\n\n```mermaid\ngraph LR\n    Q[Query] --> C[Classifier]\n    C --> |CODE| CR[Code Route]\n    C --> |CHANGE| CH[Change Route]\n    C --> |HYBRID| HY[Hybrid Route]\n    C --> |DEFAULT| DF[Default Recall]\n```\n\n资料来源：[CHANGELOG.md:1-80]()\n\n### Code Layer (`src/thought/layers/code.py`)\n\nThe code layer provides a high-level API for code-specific graph queries against the currently-valid view of the code graph.\n\n```python\nclass CodeLayer:\n    def callers_of(name)    # Who calls this function\n    def callees_of(name)    # What this function calls\n    def impact_set(name)    # Transitive callers, ranked\n    def defines_in_file()   # Entities in a given file\n```\n\n资料来源：[src/thought/layers/code.py:1-60]()\n\n## Storage Architecture\n\n### SQLite Backend\n\nThe system uses SQLite as its primary storage with the following schema features:\n\n- **Bi-temporal model**: Tracks `valid_from`/`valid_until` (business time) and `learned_at` (system knowledge time)\n- **Entity/Edge tables** with code-specific columns (`code_file`, `code_language`, `code_commit_sha`)\n- **Partial indexes** for efficient queries\n- **WAL mode** with checkpointing for consistent backups\n\n### Data Models\n\n**Entity Structure:**\n```python\n@dataclass\nclass CodeEntity:\n    name: str\n    type_: str           # function, class, module, method\n    language: str        # python, typescript, rust, php\n    file_path: str\n    line_start: int\n    line_end: int\n    signature: str\n    docstring: str\n    visibility: str      # public, private, protected\n    attrs: dict\n```\n\n**Edge Types:**\n- `CALLS` - Function/method invocations\n- `INHERITS_FROM` - Class inheritance\n- `IMPORTS` - Module imports\n- `DEFINES` - Member definitions within classes\n- `OVERRIDES` - Method overrides (TypeScript)\n\n资料来源：[src/thought/ingest/code/pipeline.py:1-100]()\n\n## Code Ingestion Pipeline\n\n### Language Extractors\n\nThe system uses tree-sitter parsers for multi-language code extraction:\n\n| Language | File | Capabilities |\n|----------|------|--------------|\n| Python | `python_extractor.py` | Functions, classes, imports, inheritance |\n| TypeScript | `typescript_extractor.py` | Functions, classes, imports, exports, inheritance, overrides |\n| Rust | `rust_extractor.py` | Functions, impl blocks, traits |\n| PHP | `php_extractor.py` | Functions, classes, methods, namespaces |\n\nAll extractors output `CodeEntity` and `CodeEdge` tuples parsed from AST nodes.\n\n资料来源：[src/thought/ingest/code/python_extractor.py:1-80]()\n\n### Code Pipeline Flow\n\n```mermaid\ngraph TD\n    F[File Input] --> LD[Language Detection]\n    LD --> EX[Extract Entities/Edges]\n    EX --> SI[Upsert Source]\n    SI --> WE[_write_entities]\n    WE --> EE[Embed Signatures]\n    EE --> WEd[_write_edges]\n    WEd --> CM[Commit Transaction]\n    \n    subgraph \"Entities Processing\"\n        WE --> |\"name_to_id map\"| WEd\n    end\n```\n\n资料来源：[src/thought/ingest/code/pipeline.py:100-200]()\n\n### Git Pipeline (`src/thought/ingest/code/git_pipeline.py`)\n\nThe git pipeline enables historical code analysis with two modes:\n\n| Mode | Behavior |\n|------|----------|\n| `snapshot` | Fast - ingest HEAD only, stamp entities with HEAD SHA |\n| `full` | Walk every commit chronologically, stamp each entity with its commit SHA |\n\nThe `full` mode enables bi-temporal `as_of` queries against historical commits.\n\n资料来源：[src/thought/ingest/code/git_pipeline.py:1-50]()\n\n## Query System\n\n### Recall Engine\n\nSemantic recall uses vector embeddings to find entities by intent rather than exact name:\n\n```python\ndef recall(\n    query: str,\n    scope: str = \"all\",\n    owner_id: str | None = None,\n    limit: int = 10,\n) -> list[RecallHit]\n```\n\nThe system embeds entity signatures and docstrings during ingestion, enabling natural queries like \"who calls authenticate_user\".\n\n### Ask Engine (`src/thought/query/ask.py`)\n\nNatural language to Cypher translation with validation:\n\n```mermaid\ngraph LR\n    NL[Natural Language] --> PROMPT[Build Prompt]\n    PROMPT --> LLM[LLM Provider]\n    LLM --> CY[Cypher Query]\n    CY --> VAL[Validate]\n    VAL --> |Valid| EXE[Execute]\n    VAL --> |Invalid| FB[Fallback to Recall]\n```\n\n**Constraint System:**\n- Read-only Cypher features only (MATCH, WHERE, RETURN)\n- Validates against actual schema before execution\n- Falls back to `recall()` on translation failures\n\n资料来源：[src/thought/query/ask.py:1-80]()\n\n## Integration Points\n\n### MCP Client Installation (`src/thought/clients.py`)\n\nThe system installs as an MCP server for AI coding tools:\n\n```python\ndef install(client: ClientName, *, server_name: str = \"thought\")\n```\n\nSupported clients include Claude Code and other MCP-compatible tools. Installation merges configuration without disturbing existing settings.\n\n### Claude Code Hooks (`src/thought/hooks/install.py`)\n\nHooks provide automatic memory integration:\n\n| Hook | Event | Action |\n|------|-------|--------|\n| `recall` | UserPromptSubmit | Memory recall on user input |\n| `write` | Stop | Context capture on completion |\n| `context` | SessionStart | Session initialization |\n\n资料来源：[src/thought/hooks/install.py:1-50]()\n\n## CLI Architecture (`src/thought/cli.py`)\n\nThe command-line interface provides database lifecycle management:\n\n| Command | Function |\n|---------|----------|\n| `thought init` | Create database + config + CLAUDE.md |\n| `thought db size` | Disk usage + entity/edge counts |\n| `thought db flush` | Wipe KB with backup |\n| `thought db backup` | SQLite online-backup snapshot |\n| `thought db load` | Load snapshot atomically |\n| `thought db inspect` | Count + schema summary |\n| `thought ingest-git` | Git-history-aware ingestion |\n| `thought callers` | Direct callers via PageRank |\n| `thought impact` | Transitive impact set |\n| `thought diff` | Entity diff between commits |\n\n资料来源：[src/thought/cli.py:1-100]()\n\n## Demo System (`src/thought/demo.py`)\n\nThe built-in demo provides audience-specific walkthroughs:\n\n| Audience | Purpose |\n|----------|---------|\n| `code` | Agent/developer flow - 14-stage code vertical |\n| `writer` | Novelist/paper author - bi-temporal recall |\n| `legal` | Investigator - contradiction detection |\n| `researcher` | Academic - claim/source relationships |\n\n资料来源：[src/thought/demo.py:1-50]()\n\n## Configuration\n\n### Database Initialization\n\n```toml\n# thought.toml\n[database]\npath = \".thought/thought.db\"\n\n[llm]\nprovider = \"anthropic\"  # or ollama, lmstudio, openai-compat\n\n[embedder]\ntype = \"auto\"  # sentence-transformers if available, else deterministic\n```\n\n资料来源：[src/thought/cli.py:50-80]()\n\n## Summary\n\nThe thought-mcp architecture combines:\n\n1. **MCP Server** - Tool interface for AI clients\n2. **Bi-temporal Storage** - SQLite with code-specific schema\n3. **Multi-language Extractors** - Tree-sitter based AST parsing\n4. **Git Integration** - Historical code analysis\n5. **Query Routing** - Classification-based query dispatch\n6. **Natural Language Interface** - NL to Cypher translation\n\nThis design enables both real-time code assistance and deep historical analysis of codebases through a unified query interface.\n\n---\n\n<a id='page-storage-layer'></a>\n\n## Storage and Database Layer\n\n### 相关页面\n\n相关主题：[System Architecture](#page-architecture), [Memory Model and Data Structures](#page-memory-model)\n\n<details>\n<summary>Relevant Source Files</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/storage/__init__.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/__init__.py)\n- [src/thought/storage/base.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/base.py)\n- [src/thought/storage/sqlite/backend.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/backend.py)\n- [src/thought/storage/sqlite/migrations/0001_initial.sql](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/migrations/0001_initial.sql)\n- [src/thought/storage/sqlite/migrations/0002_v0.2_code.sql](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/migrations/0002_v0.2_code.sql)\n- [src/thought/storage/sqlite/migrations/0003_views.sql](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/migrations/0003_views.sql)\n- [src/thought/storage/sqlite/migrations/0004_agents.sql](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/migrations/0004_agents.sql)\n</details>\n\n# Storage and Database Layer\n\n## Overview\n\nThe Storage and Database Layer is the persistence backbone of the THOUGHT system, providing a structured SQLite-based knowledge base (KB) for storing entities, edges, embeddings, and operational metadata. This layer abstracts database operations through a modular backend interface, enabling CRUD operations, bi-temporal data tracking, and specialized queries for code analysis.\n\nThe architecture supports:\n- **Entity/Edge persistence** with bi-temporal validity tracking (valid_from, valid_until, learned_at)\n- **Vector embeddings** for semantic recall operations\n- **Source tracking** for ingested content provenance\n- **Code-specific metadata** including language, file path, and commit SHA\n- **Agent and scan logging** for operational auditability\n\n资料来源：[src/thought/storage/__init__.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/__init__.py)\n\n---\n\n## Architecture\n\n### Layer Stack\n\n```mermaid\ngraph TD\n    A[CLI / API Layer] --> B[GraphLayer / CodeLayer]\n    B --> C[BaseBackend Interface]\n    C --> D[SQLiteBackend]\n    D --> E[(SQLite Database)]\n    \n    F[Ingest Pipelines] --> C\n    G[Recall Queries] --> B\n```\n\n### Backend Interface Hierarchy\n\nThe system defines a base interface (`BaseBackend`) that all storage implementations must satisfy, with `SQLiteBackend` as the primary concrete implementation.\n\n| Component | Responsibility |\n|-----------|-----------------|\n| `BaseBackend` | Abstract interface defining all storage operations |\n| `SQLiteBackend` | Concrete SQLite implementation with WAL mode and migrations |\n| `GraphLayer` | Query layer wrapping backend for graph traversal operations |\n| `CodeLayer` | Specialized wrapper for code-specific queries (callers, callees, impact) |\n\n资料来源：[src/thought/storage/base.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/base.py), [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n\n---\n\n## Data Models\n\n### Entity Model\n\nThe `Entity` model represents atomic units of knowledge stored in the database.\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `id` | `str` | Unique identifier (UUID) |\n| `type` | `str` | Entity type (e.g., \"function\", \"class\", \"claim\") |\n| `name` | `str` | Display name |\n| `canonical_name` | `str` | Normalized identifier for lookups |\n| `owner_id` | `str \\| None` | Owner for private entities |\n| `scope` | `ScopeName` | \"shared\" or \"private\" visibility |\n| `tier` | `Tier` | Importance tier (\"hot\", \"warm\", \"cold\") |\n| `importance` | `float` | 0.0-1.0 importance score |\n| `valid_from` | `datetime` | When entity became valid |\n| `valid_until` | `datetime \\| None` | When entity expired (NULL = currently valid) |\n| `learned_at` | `datetime` | When system learned this fact |\n| `unlearned_at` | `datetime \\| None` | When system discarded this fact |\n| `created_at` | `datetime` | Record creation timestamp |\n| `last_accessed_at` | `datetime` | Last access timestamp |\n| `access_count` | `int` | Query frequency counter |\n| `attrs` | `dict[str, object]` | Extensible metadata |\n| `code_file` | `str \\| None` | Source file path (code entities) |\n| `code_language` | `str \\| None` | Programming language (code entities) |\n| `code_commit_sha` | `str \\| None` | Git commit SHA (code entities) |\n\n资料来源：[src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n\n### Edge Model\n\nThe `Edge` model represents relationships between entities.\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `id` | `str` | Unique identifier |\n| `source_id` | `str` | Source entity ID |\n| `target_id` | `str` | Target entity ID |\n| `relation_type` | `str` | Relationship type (e.g., \"CALLS\", \"INHERITS_FROM\") |\n| `attrs` | `dict[str, object]` | Edge metadata |\n\n资料来源：[src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n\n---\n\n## Database Schema\n\n### Core Tables\n\n```mermaid\nerDiagram\n    entities ||--o{ edges : source\n    entities ||--o{ edges : target\n    entities ||--o{ embeddings : \"\"\n    entities ||--o{ sources : references\n    sources ||--o{ entities : \"\"\n    \n    entities {\n        string id PK\n        string type\n        string name\n        string canonical_name\n        string scope\n        string owner_id FK\n        string tier\n        float importance\n        datetime valid_from\n        datetime valid_until\n        datetime learned_at\n        datetime unlearned_at\n        datetime created_at\n        datetime last_accessed_at\n        int access_count\n        json attrs\n        string code_file\n        string code_language\n        string code_commit_sha\n    }\n    \n    edges {\n        string id PK\n        string source_id FK\n        string target_id FK\n        string relation_type\n        json attrs\n        datetime valid_from\n        datetime valid_until\n    }\n    \n    embeddings {\n        string id PK\n        string entity_id FK\n        string model_name\n        string model_version\n        int dim\n        blob vector\n    }\n    \n    sources {\n        string id PK\n        string content\n        string mime_type\n    }\n```\n\n### Migration System\n\nThe database uses a migration-based schema evolution system. Migrations are tracked in the `applied_migrations` table to ensure idempotent execution.\n\n| Migration | Purpose |\n|-----------|---------|\n| `0001_initial.sql` | Core schema: entities, edges, sources, embeddings |\n| `0002_v0.2_code.sql` | Code-specific columns: code_file, code_language, code_commit_sha |\n| `0003_views.sql` | Database views for common queries |\n| `0004_agents.sql` | Agent management and scan logging tables |\n\n资料来源：[src/thought/storage/sqlite/migrations/0001_initial.sql](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/migrations/0001_initial.sql) - [0004_agents.sql](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/migrations/0004_agents.sql)\n\n---\n\n## Backend Operations\n\n### Core CRUD Operations\n\n| Operation | Description |\n|-----------|-------------|\n| `upsert_entity()` | Insert or update an entity with identity `(name, scope, owner_id, code_file, code_commit_sha)` |\n| `upsert_edge()` | Insert or update an edge between entities |\n| `find_entity()` | Retrieve entity by ID |\n| `find_code_entity()` | Fast lookup by canonical name with optional code_file/code_commit_sha disambiguation |\n| `list_entities()` | Paginated entity listing with scope filtering |\n\n### Backup and Restore Operations\n\n| Operation | Description |\n|-----------|-------------|\n| `backup_to(path)` | Create SQLite online-backup snapshot |\n| `merge_from(path)` | INSERT-OR-IGNORE rows from backup file |\n| `open_readonly(path)` | Classmethod for read-only inspection of backup files |\n| Auto-backup | Automatic `.bak.<timestamp>` backup before destructive operations |\n\n### WAL Checkpointing\n\nThe backend performs WAL checkpointing on `close()` to ensure backups always see a consistent database state.\n\n资料来源：[src/thought/storage/sqlite/backend.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/sqlite/backend.py)\n\n---\n\n## Bi-Temporal Data Model\n\nThe storage layer implements bi-temporal tracking, enabling both temporal validity and temporal knowledge queries.\n\n```mermaid\ngraph LR\n    A[valid_from] --> B[Entity Validity Period]\n    B --> C[valid_until]\n    \n    D[learned_at] --> E[Knowledge Period]\n    E --> F[unlearned_at]\n```\n\n| Time Axis | Purpose | Query Use |\n|-----------|---------|-----------|\n| `valid_from` / `valid_until` | Temporal validity | `as_of_kind='valid'` — \"what was true on date X\" |\n| `learned_at` / `unlearned_at` | System knowledge | `as_of_kind='learned'` — \"what did the system know on date X\" |\n\nThis separation allows querying historical states even after facts are corrected.\n\n资料来源：[src/thought/storage/__init__.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/storage/__init__.py)\n\n---\n\n## Code-Specific Features\n\n### Entity Identity for Code\n\nCode entities use a composite identity to prevent method name collisions across files and commits:\n\n```\n(name, scope, owner_id, code_file, code_commit_sha)\n```\n\nThis ensures that `auth.middleware.authenticate_user` and `billing.middleware.authenticate_user` remain distinct entities, and methods from different commits are preserved separately.\n\n### Fast Code Entity Lookup\n\nThe `find_code_entity()` method provides optimized lookup with:\n\n- Primary: exact `canonical_name` match\n- Secondary: `code_file` disambiguation\n- Tertiary: `code_commit_sha` filtering for historical queries\n\n### Call Graph Resolution\n\nThe `call_graph.py` module implements multi-stage resolution:\n\n1. Intra-file qualified match (`file.method`)\n2. Unique qualified suffix match\n3. Cross-file bare-name match\n4. Stub creation for unresolved references\n\n资料来源：[src/thought/ingest/code/call_graph.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/call_graph.py)\n\n---\n\n## CLI Commands\n\nThe storage layer is accessible via the `thought db` command group.\n\n| Command | Description |\n|---------|-------------|\n| `thought db size` | Disk usage of main + WAL + SHM files + entity/edge counts |\n| `thought db flush` | Wipe KB with optional date/scope filters |\n| `thought db backup <file>` | Create SQLite snapshot with optional date filters |\n| `thought db load <file>` | Replace active DB or merge from snapshot |\n| `thought db inspect <file>` | Inspect backup without loading |\n\n```bash\n# Flush entities valid before a date\nthought db flush --before 2025-01-01\n\n# Flush with time-axis filter\nthought db flush --time-axis valid --since 2024-06-01\n\n# Backup with date subset\nthought db backup backup.db --since 2024-01-01\n```\n\n资料来源：[src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n---\n\n## Query Layer Wrappers\n\n### GraphLayer\n\nBase wrapper providing graph traversal operations including:\n\n- Personalized PageRank for ranking entities\n- Transitive reachability queries\n- Edge type filtering\n\n### CodeLayer\n\nSpecialized wrapper for code-specific operations:\n\n| Method | Description |\n|--------|-------------|\n| `callers_of(name)` | Direct callers ranked by PageRank |\n| `callees_of(name)` | Direct callees within package |\n| `impact_set(name)` | Transitive callers (all affected entities) |\n| `defines_in_file(path)` | All entities in a source file |\n\nBoth layers support `as_of=` parameter for historical queries against the bi-temporal git ingest data.\n\n资料来源：[src/thought/layers/graph.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/graph.py), [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n\n---\n\n## Configuration\n\n### Database Path\n\nConfigured via `thought.toml`:\n\n```toml\ndb_path = \".thought/thought.db\"\n```\n\n### Initialization Options\n\n| Option | Default | Description |\n|--------|---------|-------------|\n| `config` | `\"thought.toml\"` | Config file path |\n| `db_path` | `\".thought/thought.db\"` | SQLite database path |\n| `embedder` | `\"auto\"` | Embedder selection |\n| `write_claude_md` | `true` | Generate CLAUDE.md for MCP clients |\n| `quick` | `false` | Skip embedder warmup |\n\n资料来源：[src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n---\n\n## Summary\n\nThe Storage and Database Layer provides THOUGHT's persistent memory through:\n\n1. **SQLite with WAL mode** for reliable concurrent access\n2. **Bi-temporal modeling** for historical queries and fact correction tracking\n3. **Migration-based schema evolution** with idempotent execution\n4. **Code-aware entity identity** preventing cross-file/commits collisions\n5. **Specialized query layers** (GraphLayer, CodeLayer) for semantic and structural queries\n6. **Backup/restore operations** with atomic replacements and auto-backup safety\n\nThis architecture enables the \"second brain\" functionality, allowing agents to recall, query, and analyze information across code, prose, legal, and research domains.\n\n---\n\n<a id='page-memory-model'></a>\n\n## Memory Model and Data Structures\n\n### 相关页面\n\n相关主题：[System Architecture](#page-architecture), [Storage and Database Layer](#page-storage-layer), [Query and Retrieval System](#page-query-system)\n\n<details>\n<summary>Relevant Source Files</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n- [src/thought/ingest/entities.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/entities.py)\n- [src/thought/consolidation/engine.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/consolidation/engine.py)\n- [src/thought/layers/vector.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/vector.py)\n- [src/thought/layers/graph.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/graph.py)\n- [src/thought/layers/temporal.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/temporal.py)\n</details>\n\n# Memory Model and Data Structures\n\n## Overview\n\nThe thought-mcp repository implements a multi-layered memory architecture designed for AI-assisted knowledge management. The memory model combines vector embeddings for semantic search, graph relationships for structural querying, and temporal versioning for historical analysis. This hybrid approach enables both intuitive natural-language recall and precise code-intent queries.\n\nThe core memory system operates as a knowledge base (KB) with bi-temporal semantics, tracking when facts became true (`valid_from`) versus when the system learned them (`learned_at`). This design supports time-travel queries that answer \"what was true on date X\" or \"what did the system know on date X\".\n\n## Architecture Layers\n\nThe memory system is organized into three distinct but interconnected layers:\n\n```mermaid\ngraph TD\n    A[User Input] --> B[Memory Layer]\n    B --> C[Vector Layer]\n    B --> D[Graph Layer]\n    B --> E[Temporal Layer]\n    C --> F[SQLite Backend]\n    D --> F\n    E --> F\n    G[Query/Recall] --> B\n```\n\n### Vector Layer (`src/thought/layers/vector.py`)\n\nThe vector layer handles semantic embedding and similarity search. It stores dense vector representations of entities enabling natural-language recall based on meaning rather than exact keyword matching.\n\n**Core Responsibilities:**\n\n- Embed text content (entity names, signatures, docstrings) into high-dimensional vectors\n- Store embeddings with model metadata (name, version, dimensions)\n- Perform similarity searches against the embedded corpus\n- Support fallback to deterministic embeddings when ML models are unavailable\n\n**Key Components:**\n\n| Component | Purpose |\n|-----------|---------|\n| `VectorStore` | Persists embeddings in SQLite with metadata |\n| `Embedder` | Base protocol for embedding models |\n| `OllamaEmbedder` | Integration with Ollama's `/api/embed` endpoint |\n| `DeterministicEmbedder` | Fallback using hash-based vectors |\n\n资料来源：[src/thought/layers/vector.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/vector.py)\n\n### Graph Layer (`src/thought/layers/graph.py`)\n\nThe graph layer manages entity-relationship data structures and supports Cypher-style traversals. It maintains the structural knowledge of how entities connect to each other.\n\n**Entity Types Supported:**\n\n| Type | Description |\n|------|-------------|\n| `module` | Source file or namespace unit |\n| `class` | Class or type declarations |\n| `function` | Function definitions |\n| `method` | Class methods |\n| `fact` | General knowledge facts |\n| `claim` | Academic/research claims |\n| `source` | Citation or reference |\n| `witness` | Legal testimony statements |\n\n**Edge Relation Types:**\n\n| Relation | Meaning |\n|----------|---------|\n| `IMPORTS` | Module dependency relationship |\n| `INHERITS_FROM` | Class inheritance |\n| `DEFINES` | Container defines a member |\n| `OVERRIDES` | Method overrides parent |\n| `CALLS` | Function invocation |\n| `REFERS_TO` | General reference |\n| `CONTRADICTS` | Logical opposition between facts |\n\n资料来源：[src/thought/layers/graph.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/graph.py)\n\n### Temporal Layer (`src/thought/layers/temporal.py`)\n\nThe temporal layer implements bi-temporal data modeling, tracking both valid time and learned time for all entities. This enables sophisticated time-travel queries and contradiction detection.\n\n**Bi-Temporal Model:**\n\n```mermaid\ngraph LR\n    A[Entity] --> B[valid_from<br/>When fact became true]\n    A --> C[learned_at<br/>When KB learned fact]\n    D[as_of valid] --> E[Historical state query]\n    D --> F[as_of learned<br/>System knowledge query]\n```\n\n**Key Temporal Features:**\n\n- `valid_from`: Timestamp when the fact became true in reality\n- `learned_at`: Timestamp when the system recorded the fact\n- `valid_until`: Optional expiration of fact validity\n- `CONTRADICTS` edges: Automatically surface when facts conflict across time axes\n\n资料来源：[src/thought/layers/temporal.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/temporal.py)\n\n## Core Data Models\n\n### Entity Model (`src/thought/models.py`)\n\nThe base `Entity` model represents all stored knowledge items in the system.\n\n```python\nclass Entity:\n    id: str                    # Unique identifier\n    name: str                  # Canonical name\n    type: str                  # Entity type (see table above)\n    scope: str                  # \"shared\" or \"private\"\n    owner_id: str | None        # Owner for private entities\n    valid_from: datetime        # When fact became true\n    learned_at: datetime        # When system learned it\n    source_ref: str | None      # Reference to source document\n    tier: str                   # \"hot\", \"warm\", \"cold\" (access frequency)\n    attrs: dict                 # Type-specific attributes\n```\n\n**Entity Attributes by Type:**\n\n| Entity Type | Key Attributes |\n|-------------|----------------|\n| `code_*` | `code_file`, `code_language`, `code_commit_sha`, `signature`, `visibility`, `line_start`, `line_end` |\n| `fact` | `predicates`, `unique_predicates`, `source_doc` |\n| `claim` | `citation_key`, `reliability_score` |\n\n资料来源：[src/thought/models.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n\n### Code Entities (`src/thought/ingest/entities.py`)\n\nCode-specific entities extend the base model with language-aware attributes:\n\n```python\nclass CodeEntity:\n    name: str\n    type_: str                  # \"module\", \"class\", \"function\", \"method\"\n    language: str               # \"python\", \"typescript\", \"rust\", \"php\"\n    file_path: str\n    line_start: int\n    line_end: int\n    signature: str              # Function/class signature\n    visibility: str             # \"public\", \"private\", \"protected\"\n    docstring: str | None\n    attrs: dict                 # Language-specific (e.g., `class` for methods)\n```\n\n### Edge Model (`src/thought/ingest/entities.py`)\n\nRelationships between entities are modeled as typed, directed edges:\n\n```python\nclass CodeEdge:\n    source_name: str             # Origin entity\n    target_name: str             # Destination entity\n    relation_type: str          # IMPORTS, DEFINES, INHERITS_FROM, etc.\n    line_number: int | None\n    attrs: dict\n```\n\n资料来源：[src/thought/ingest/entities.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/entities.py)\n\n## Consolidation Engine (`src/thought/consolidation/engine.py`)\n\nThe consolidation engine handles fact deduplication, merging, and contradiction detection. It processes incoming data through a pipeline that ensures data quality and consistency.\n\n```mermaid\ngraph TD\n    A[Raw Input] --> B[Jaccard Deduplication]\n    B --> C[Fact Extraction]\n    C --> D[Predicate Matching]\n    D --> E{Conflict?}\n    E -->|Yes| F[Create CONTRADICTS Edge]\n    E -->|No| G[Merge into KB]\n    F --> G\n```\n\n**Consolidation Pipeline Steps:**\n\n1. **Jaccard Deduplication**: Skip content with >50% overlap to existing facts\n2. **Fact Extraction**: Parse structured predicates from unstructured text\n3. **Predicate Matching**: Match against existing knowledge using unique predicates\n4. **Contradiction Detection**: Create `CONTRADICTS` edges when facts conflict\n5. **Entity Merging**: Upsert with identity `(name, code_file, code_commit_sha)`\n\n资料来源：[src/thought/consolidation/engine.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/consolidation/engine.py)\n\n## Storage Backend\n\nThe system uses SQLite as its primary storage engine with the following schema:\n\n```mermaid\ngraph TD\n    A[SQLite Database] --> B[entities table]\n    A --> C[edges table]\n    A --> D[embeddings table]\n    A --> E[applied_migrations table]\n    B --> F[code_file<br/>code_language<br/>code_commit_sha]\n    C --> G[relation_type<br/>source_name<br/>target_name]\n    D --> H[model_name<br/>model_version<br/>vector BLOB]\n```\n\n**Key Backend Classes:**\n\n| Class | Responsibility |\n|-------|----------------|\n| `Backend` | Core CRUD operations on entities/edges |\n| `find_code_entity()` | Fast lookup by name + file/commit disambiguators |\n| `upsert_entity()` | Insert or update with identity awareness |\n| `store_embedding()` | Persist vectors with model metadata |\n\n资料来源：[src/thought/storage/sqlite/backend.py](src/thought/storage/sqlite/backend.py) (inferred from CHANGELOG.md)\n\n## Query Pathways\n\nThe memory system supports multiple query mechanisms:\n\n### Recall (Vector Search)\n\n```python\ndef recall(\n    query: str,\n    scope: str = \"all\",\n    owner_id: str | None = None,\n    max_results: int = 10,\n) -> list[RecallResult]\n```\n\nReturns up to 10 semantically similar entities based on embedding similarity.\n\n### Ask (Natural Language to Cypher)\n\nRoutes natural-language questions through an LLM to generate Cypher queries:\n\n```\nQUESTION: \"who calls authenticate_user\"\n→ CYPHER: MATCH (caller)-[:CALLS]->(f:Function {name: 'authenticate_user'}) \n          RETURN caller.name\n```\n\n资料来源：[src/thought/query/ask.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n\n### Code Intelligence Queries\n\n| Command | Purpose |\n|---------|---------|\n| `thought callers <name>` | Direct callers via Personalized PageRank |\n| `thought impact <name>` | Transitive impact set (what breaks if changed) |\n| `thought diff --from SHA1 --to SHA2` | Entity diff between commits |\n\n## Ingest Pipelines\n\nCode ingestion follows a standardized pipeline:\n\n```mermaid\ngraph TD\n    A[Source File] --> B[Language Detection]\n    B --> C[AST Parser<br/>tree-sitter]\n    C --> D[Extractor<br/>Language-specific]\n    D --> E[CodeEntity list]\n    D --> F[CodeEdge list]\n    E --> G[Embedding]\n    G --> H[Backend upsert]\n    F --> H\n    H --> I[Call Graph Builder<br/>optional]\n```\n\n**Supported Languages:**\n\n- Python (`.py`) - via tree-sitter-python\n- TypeScript (`.ts`, `.tsx`) - via tree-sitter-typescript\n- Rust (`.rs`) - via tree-sitter-rust\n- PHP (`.php`) - via tree-sitter-php\n\n**Extracted Metadata:**\n\n- Module/namespace names\n- Class declarations with heritage (extends, implements)\n- Function and method definitions\n- Import/use declarations\n- Visibility modifiers (public, private, protected)\n\n资料来源：[src/thought/ingest/code/python_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/python_extractor.py), [src/thought/ingest/code/typescript_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/typescript_extractor.py)\n\n## Auto-Memory Hooks\n\nThe system integrates with Claude Code via hooks for automatic memory management:\n\n| Hook | Event | Action |\n|------|-------|--------|\n| `recall` | `UserPromptSubmit` | Embeds prompt, recalls relevant context |\n| `write` | `Stop` | Extracts facts from session transcript |\n| `context` | `SessionStart` | Loads relevant context for new session |\n\n资料来源：[src/thought/hooks/install.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n\n## Versioning and Snapshots\n\nThe storage layer supports full database lifecycle management:\n\n| Operation | Description |\n|-----------|-------------|\n| `db size` | Disk usage + entity/edge counts |\n| `db flush` | Wipe KB with date-bounded options |\n| `db backup <file>` | SQLite online backup snapshot |\n| `db load <file>` | Restore or merge from snapshot |\n| `db inspect <file>` | Preview backup without loading |\n\nWAL (Write-Ahead Logging) checkpoints ensure consistent backups.\n\n## Summary\n\nThe thought-mcp memory model implements a production-grade knowledge management system with:\n\n1. **Three-layer architecture**: Vector for semantics, Graph for structure, Temporal for history\n2. **Bi-temporal semantics**: Tracks both validity and knowledge acquisition times\n3. **Code-aware extraction**: AST-based parsing for multiple programming languages\n4. **Contradiction detection**: Automatic `CONTRADICTS` edges between conflicting facts\n5. **Multiple query pathways**: Semantic recall, natural-language Cypher, and code-intelligence commands\n6. **Git-aware versioning**: Commits can be stamped on entities for historical queries\n\nThis architecture enables sophisticated AI memory capabilities while maintaining query performance through strategic use of SQLite with proper indexing.\n\n---\n\n<a id='page-query-system'></a>\n\n## Query and Retrieval System\n\n### 相关页面\n\n相关主题：[Memory Model and Data Structures](#page-memory-model), [Storage and Database Layer](#page-storage-layer), [Agent Adapters and SDK Integration](#page-agent-adapters)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/query/__init__.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/__init__.py)\n- [src/thought/query/ask.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n- [src/thought/query/cypher.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/cypher.py)\n- [src/thought/query/views.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/views.py)\n- [src/thought/hooks/recall.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/recall.py)\n</details>\n\n# Query and Retrieval System\n\nThe Query and Retrieval System is a core subsystem within the thought-mcp project that enables users to query the knowledge graph using natural language. It translates human-readable questions into structured Cypher queries or SQL statements, executes them against the underlying SQLite backend, and returns ranked, relevant results. The system serves as the primary interface for retrieving facts, code entities, relationships, and historical data stored in the memory database.\n\n## Architecture Overview\n\nThe Query and Retrieval System is composed of several interconnected modules that work together to process, route, and execute queries. At its core, the system leverages a Router to classify incoming queries into semantic categories, then delegates processing to specialized handlers based on the query type.\n\n```mermaid\ngraph TD\n    A[User Query] --> B[Router]\n    B --> C{Code Query?}\n    B --> D{Natural Language?}\n    B --> E{Search Query?}\n    C --> F[Code Layer]\n    D --> G[Ask Module]\n    G --> H[Cypher Translator]\n    H --> I[Query Validator]\n    I --> J[SQLite Backend]\n    E --> K[Recall Hook]\n    K --> J\n    J --> L[Results]\n    F --> L\n```\n\nThe system follows a layered approach where queries are first classified by intent, then transformed into appropriate database queries. Natural language queries are translated to Cypher through an LLM-based translator, while code-specific queries bypass translation and directly execute predefined graph traversal operations.\n\n## Query Classification\n\nThe Router module plays a critical role in determining how each query should be processed. Based on keyword detection and pattern matching, queries are classified into distinct types that trigger different handling paths.\n\n### Query Types\n\n| Query Type | Trigger Keywords | Handler | Use Case |\n|------------|------------------|---------|----------|\n| CODE | `function`, `class`, `caller`, `callee`, `impact`, file extensions, camelCase identifiers | CodeLayer | Code graph traversal |\n| CHANGE | `since v1.0`, `before this commit`, `diff` | GitIngestReport | Version-aware queries |\n| HYBRID | CODE × CHANGE combinations | GraphLayer + GitWalker | Historical code analysis |\n| SEARCH | General text | Recall Hook | Semantic search |\n| ASK | Natural language questions | Ask Module | Natural language to Cypher |\n\n资料来源：[src/thought/query/ask.py:1-30](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n\n### CODE Query Detection\n\nThe CODE query class is triggered by code-shaped keywords and identifier patterns. This includes function names, class declarations, caller/callee relationships, file extensions such as `.py` or `.ts`, and version-related phrases like `since v1.0` or `before this commit`. Additionally, camelCase and snake_case identifiers automatically route to the CODE handler, enabling queries like \"who calls authenticate_user\" to be processed through the call-graph machinery without explicit CLI invocation.\n\n资料来源：[src/thought/query/ask.py:1-30](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n\n## Natural Language to Cypher Translation\n\nThe Ask module (`src/thought/query/ask.py`) is responsible for translating natural language questions into Cypher queries. This translation is performed by an LLM provider configured in the `[llm]` section of the configuration file, supporting multiple backends through a unified interface.\n\n### Translation Process\n\n```mermaid\nsequenceDiagram\n    participant U as User\n    participant A as Ask Module\n    participant L as LLM Provider\n    participant V as Cypher Validator\n    participant B as SQLite Backend\n    \n    U->>A: \"What functions call authenticate_user?\"\n    A->>A: Build Prompt with Schema\n    A->>L: Send Prompt\n    L-->>A: Cypher Query\n    A->>V: Validate Cypher\n    alt Valid\n        V->>B: Execute Query\n        B-->>V: Results\n        V-->>U: Ranked Results\n    else Invalid\n        A->>A: Fallback to Recall\n        A-->>U: Semantic Search Results\n    end\n```\n\nThe translation process begins with constructing a prompt that includes the database schema, entity types, and relationship types. The LLM generates a Cypher query that is then validated against a parser before execution. If validation fails or the query cannot be executed, the system gracefully falls back to a plain `recall()` call, ensuring the user always receives some response.\n\n### Prompt Constraints\n\nThe Ask module enforces strict constraints on generated queries to maintain system safety and performance:\n\n- Only read-only Cypher features are permitted, including `MATCH`, `WHERE`, `RETURN`, `LIMIT`, and `AS_OF`\n- Query types are restricted to `MERGE`, `CREATE`, `DELETE`, `SET`, and `WITH` being explicitly forbidden\n- All entity types and relationship types must come from the defined schema\n- Single Cypher queries are required without explanations or markdown formatting\n\n资料来源：[src/thought/query/ask.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n\n### AskResult Data Model\n\nThe `AskResult` dataclass encapsulates the outcome of a query translation and execution attempt:\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `cypher` | `str \\| None` | The generated Cypher query |\n| `sql` | `str \\| None` | Alternative SQL query if applicable |\n| `rows` | `list[dict[str, Any]] \\| None` | Query results |\n| `fallback_used` | `bool` | Whether fallback to recall was triggered |\n| `fallback_reason` | `str` | Explanation if fallback occurred |\n\n资料来源：[src/thought/query/ask.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/ask.py)\n\n## Recall Hook\n\nThe recall hook (`src/thought/hooks/recall.py`) provides semantic search functionality as a fallback mechanism and primary retrieval method. It uses embedding vectors to find semantically similar entities in the knowledge graph, supporting the core recall operation used throughout the system.\n\n### Recall Behavior\n\nRecall operations are bounded by design to prevent overwhelming the user with too many results. The system never returns more than 10 hits regardless of knowledge base size, encouraging users to narrow their queries using `as_of` and `scope` parameters for more targeted retrieval.\n\nThe recall mechanism supports bi-temporal queries through the `as_of_kind` parameter:\n\n- `valid`: Returns what was true on a given date, answering \"what was true on date X\"\n- `learned`: Returns what the system knew on a given date, answering \"what did the system know on date X\"\n\nThese two modes differ when facts are corrected after the fact, enabling users to perform historical analysis of their knowledge graph.\n\n资料来源：[src/thought/query/views.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/views.py)\n\n## Code Layer\n\nThe Code Layer (`src/thought/layers/code.py`) provides a specialized interface for code-specific graph queries. It wraps the GraphLayer with operations native to programmers, operating against the currently-valid view of the code graph using the `valid_until IS NULL` filter.\n\n### Core Operations\n\n| Method | Description | Use Case |\n|--------|-------------|----------|\n| `callers_of(name)` | Direct callers ranked by PageRank | Finding who uses a function |\n| `callees_of(name)` | Direct callees within the package | Finding what a function calls |\n| `impact_set(name)` | Transitive callers ranked | Dependency analysis |\n| `defines_in_file()` | All entities in a file | File-level inspection |\n\nAll four operations support optional `as_of` parameters to query historical snapshots when bi-temporal git ingest has been configured. The `code_commit_sha` field enables time-travel queries against the code graph.\n\n资料来源：[src/thought/layers/code.py:1-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n\n### Entity Resolution\n\nThe `_resolve_entity_id` method handles name resolution with multiple fallback strategies:\n\n1. Intra-file match with exact name\n2. Cross-file match with unique qualified suffix\n3. Cross-file bare-name match for top-level functions\n4. Stub creation for unresolved references\n\nThis multi-stage resolution ensures that queries like `obj.method()` can resolve to `ClassName.method` when it is unique in the knowledge base, and that bare function names can be found across different files.\n\n资料来源：[src/thought/query/cypher.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/query/cypher.py)\n\n## Cypher Query Engine\n\nThe Cypher module (`src/thought/query/cypher.py`) handles the parsing, validation, and execution of Cypher queries against the SQLite backend. It provides a bridge between the graph query language and the relational database storage.\n\n### Query Validation\n\nBefore executing any Cypher query, the system validates it against the defined grammar to prevent malformed queries from reaching the database. This validation step catches syntax errors, unsupported features, and schema violations before they can cause runtime errors.\n\n### Execution Model\n\nCypher queries are translated into equivalent SQL statements that operate against the SQLite schema. The translation preserves the semantic meaning of graph patterns while adapting them to the relational storage model used by the backend.\n\n## Views and Data Models\n\nThe views module (`src/thought/query/views.py`) defines the data structures and return formats used throughout the Query and Retrieval System.\n\n### Entity Model\n\nThe `Entity` model represents nodes in the knowledge graph with the following key attributes:\n\n| Attribute | Type | Description |\n|-----------|------|-------------|\n| `id` | `str` | Unique identifier |\n| `type` | `str` | Entity type (PERSON, function, class, etc.) |\n| `name` | `str` | Display name |\n| `canonical_name` | `str` | Normalized name for matching |\n| `scope` | `ScopeName` | shared, private, or all |\n| `tier` | `Tier` | hot, warm, or cold |\n| `valid_from` | `datetime` | Start of validity period |\n| `valid_until` | `datetime \\| None` | End of validity period |\n| `attrs` | `dict[str, object]` | Additional attributes |\n\n### Scope Filter\n\nThe `ScopeFilter` class determines visibility of entities based on ownership and scope:\n\n- `shared`: All entities with scope = \"shared\"\n- `private`: Entities matching both scope = \"private\" AND owner_id\n- `all`: Shared entities plus private entities owned by the requesting user\n\nThe scope filter generates SQL fragments that join against the entity table aliased as `e`, enabling fine-grained access control across the query system.\n\n资料来源：[src/thought/models.py:1-80](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/models.py)\n\n## CLI Commands\n\nThe Query and Retrieval System is exposed through several CLI commands under the `thought` command group:\n\n| Command | Description |\n|---------|-------------|\n| `thought recall <query>` | Semantic search across the knowledge graph |\n| `thought ask <question>` | Natural language query with Cypher translation |\n| `thought callers <name>` | Find direct callers ranked by PageRank |\n| `thought callees <name>` | Find direct callees within the package |\n| `thought impact <name>` | Transitive impact set analysis |\n| `thought browse <name>` | Drill into a topic with PPR-ranked neighborhood |\n| `thought diff --from <sha1> --to <sha2>` | Compare entities between commits |\n\n### Browse Command\n\nThe browse command (`mcp__thought__browse_topic`) implements a two-step resolution process. First, the name is matched against entity types for a type facet. If no type matches, the name is resolved as an entity using canonical-name matching, and the PPR-ranked neighborhood is returned. The `via` field in results indicates whether the hit came from `type_facet`, `ppr`, or `bfs` matching.\n\n资料来源：[src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n\n## Configuration\n\nThe Query and Retrieval System respects configuration from the `thought.toml` file and environment variables:\n\n| Option | Default | Description |\n|--------|---------|-------------|\n| `embedder` | `auto` | Embedder selection: auto, sentence-transformers, or deterministic |\n| `llm.provider` | `openai` | LLM provider for Ask module |\n| `llm.model` | varies | Model name for translation |\n| `db_path` | `.thought/thought.db` | SQLite database path |\n\nThe `auto` embedder selector probes the `sentence_transformers` package via `importlib.util.find_spec` before returning the wrapper, falling back to the deterministic embedder when the optional dependency is missing.\n\n## Integration Points\n\nThe Query and Retrieval System integrates with several other subsystems:\n\n- **Storage Layer**: SQLite backend provides entity and edge persistence\n- **Ingest System**: Code extractors populate entities that are later queried\n- **Memory Module**: Coordinates between recall, browse, and scan operations\n- **Server**: Exposes query functionality via MCP protocol\n\nThe bidirectional relationship between the Code Layer and the Cypher query engine enables both natural language queries like \"who calls authenticate_user\" and structured queries using the CODE query class, providing flexibility for different user interaction patterns.\n\n## Error Handling\n\nThe system implements graceful degradation throughout the query pipeline. If Cypher translation fails or validation rejects the generated query, execution falls back to the recall hook, ensuring users always receive results. Bounded result sets prevent resource exhaustion, and the contradiction detection mechanism surfaces conflicts as `CONTRADICTS` edges in the graph rather than throwing errors, allowing downstream applications to handle them as data.\n\n---\n\nThis documentation reflects the Query and Retrieval System as implemented in thought-mcp, providing the foundation for natural language interaction with the code knowledge graph.\n\n---\n\n<a id='page-code-parsing'></a>\n\n## Multi-Language Code Parsing\n\n### 相关页面\n\n相关主题：[Git History Integration](#page-git-integration), [Storage and Database Layer](#page-storage-layer)\n\n<details>\n<summary>Related Source Files</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/ingest/code/__init__.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/__init__.py)\n- [src/thought/ingest/code/ast_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/ast_extractor.py)\n- [src/thought/ingest/code/call_graph.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/call_graph.py)\n- [src/thought/ingest/code/pipeline.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/pipeline.py)\n- [src/thought/ingest/code/python_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/python_extractor.py)\n- [src/thought/ingest/code/typescript_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/typescript_extractor.py)\n- [src/thought/ingest/code/go_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/go_extractor.py)\n- [src/thought/ingest/code/rust_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/rust_extractor.py)\n- [src/thought/ingest/code/java_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/java_extractor.py)\n- [src/thought/ingest/code/php_extractor.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/php_extractor.py)\n- [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n</details>\n\n# Multi-Language Code Parsing\n\nThe Multi-Language Code Parsing system is the foundational code-vertical layer in THOUGHT. It provides language-agnostic AST extraction across six programming languages using tree-sitter grammars, produces standardized code entities and relationship edges, and enables downstream features like caller analysis, impact queries, and cross-file call-graph resolution.\n\n## Overview\n\nThe parsing system operates in two phases:\n\n1. **Phase 1 – AST Extraction**: Each language has a dedicated extractor that walks the tree-sitter parse tree and emits `CodeEntity` and `CodeEdge` objects.\n2. **Phase 2 – Call Graph Resolution**: After all files are ingested, a separate pass resolves `CALLS` edges by matching callee names against the entity index.\n\n资料来源：[src/thought/ingest/code/ast_extractor.py:1-15]()\n\n## Supported Languages\n\nThe system supports six languages through language-specific extractors:\n\n| Language | Extractor File | Tree-sitter Grammar |\n|----------|----------------|---------------------|\n| Python | `python_extractor.py` | `tree-sitter-python` |\n| TypeScript / TSX / JSX | `typescript_extractor.py` | `tree-sitter-typescript` |\n| Go | `go_extractor.py` | `tree-sitter-go` |\n| Rust | `rust_extractor.py` | `tree-sitter-rust` |\n| Java | `java_extractor.py` | `tree-sitter-java` |\n| PHP | `php_extractor.py` | `tree-sitter-php` |\n\n资料来源：[src/thought/ingest/code/ast_extractor.py:30-55]()\n\n## Architecture\n\n```mermaid\ngraph TD\n    A[Code File] --> B[Language Detection]\n    B --> C[ast_extractor.py Dispatcher]\n    C --> D{Python?}\n    C --> E{TypeScript?}\n    C --> F{Go?}\n    C --> G{Rust?}\n    C --> H{Java?}\n    C --> I{PHP?}\n    D --> J[python_extractor.extract]\n    E --> K[typescript_extractor.extract]\n    F --> L[go_extractor.extract]\n    G --> M[rust_extractor.extract]\n    H --> N[java_extractor.extract]\n    I --> O[php_extractor.extract]\n    J --> P[(CodeEntity, CodeEdge)]\n    K --> P\n    L --> P\n    M --> P\n    N --> P\n    O --> P\n    P --> Q[CodeIngestPipeline]\n    Q --> R[build_call_graph]\n    R --> S[(CALLS Edges)]\n```\n\n### Dispatcher Pattern\n\nThe `ast_extractor.py` module uses lazy loading to avoid importing heavy tree-sitter C extensions at module load time:\n\n```python\n_REGISTRY: dict[str, Callable[[str, str], tuple[list[CodeEntity], list[CodeEdge]]]] = {}\n\ndef _python_extractor():\n    from . import python_extractor\n    return python_extractor.extract\n```\n\nEach language loader is registered in `_LOADERS` and invoked only when that language is first requested. 资料来源：[src/thought/ingest/code/ast_extractor.py:9-35]()\n\n## Data Models\n\n### CodeEntity\n\nRepresents a code element extracted from the AST:\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `name` | `str` | Canonical identifier (module, function, class, method) |\n| `type_` | `str` | Entity kind: `module`, `function`, `class`, `method` |\n| `language` | `str` | Source language: `python`, `typescript`, `go`, `rust`, `java`, `php` |\n| `file_path` | `str` | Path to source file (relative to repo root) |\n| `line_start` | `int` | 1-indexed start line |\n| `line_end` | `int` | 1-indexed end line |\n| `signature` | `str` | Declaration signature (e.g., `module foo`, `def bar(self, x)`) |\n| `docstring` | `str \\| None` | Extracted docstring text |\n| `visibility` | `str` | `public` or `private` based on naming conventions |\n| `attrs` | `dict` | Language-specific metadata |\n\n资料来源：[src/thought/ingest/code/python_extractor.py:14-25]()\n\n### CodeEdge\n\nRepresents a relationship between entities:\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `source_name` | `str` | Entity that is the subject of the relation |\n| `target_name` | `str` | Entity that is the object of the relation |\n| `relation_type` | `str` | One of: `IMPORTS`, `INHERITS_FROM`, `DEFINES`, `OVERRIDES`, `CALLS` |\n| `line_number` | `int` | Source line where the relationship was discovered |\n| `attrs` | `dict` | Additional metadata (e.g., `from_import: true`) |\n\n资料来源：[src/thought/ingest/code/typescript_extractor.py:110-115]()\n\n## Extractor Interface\n\nAll language extractors share a common signature:\n\n```python\ndef extract(source: str, file_path: str) -> tuple[list[CodeEntity], list[CodeEdge]]:\n    ...\n```\n\nThis uniform interface allows the dispatcher to route to any language without knowing implementation details. 资料来源：[src/thought/ingest/code/python_extractor.py:28-40]()\n\n## Supported Edge Types\n\n| Relation | Source | Target | Languages |\n|----------|--------|--------|-----------|\n| `IMPORTS` | module | imported module | Python, TypeScript, PHP, Go, Rust, Java |\n| `INHERITS_FROM` | class | parent class | Python, TypeScript, Java, PHP |\n| `DEFINES` | class/module | contained member | All languages |\n| `OVERRIDES` | method | overridden method | TypeScript (currently) |\n| `CALLS` | function/method | called function | All (via call-graph pass) |\n\n资料来源：[src/thought/ingest/code/python_extractor.py:1-15](), [src/thought/ingest/code/typescript_extractor.py:1-20]()\n\n## Language-Specific Extractors\n\n### Python Extractor\n\nThe Python extractor uses `tree-sitter-python` and handles:\n\n- Module entities as the root node\n- Function definitions (`function_item`)\n- Class declarations (`class_declaration`)\n- Method definitions within classes\n- Import statements (`import_from_statement`, `import_statement`)\n- Class inheritance via `base` field\n\n```python\ndef extract(source: str, file_path: str) -> tuple[list[CodeEntity], list[CodeEdge]]:\n    parser = _get_parser()\n    source_bytes = source.encode(\"utf-8\")\n    tree = parser.parse(source_bytes)\n    root = tree.root_node\n\n    module_name = _module_name_from_path(file_path)\n    entities: list[CodeEntity] = []\n    edges: list[CodeEdge] = []\n\n    entities.append(CodeEntity(\n        name=module_name,\n        type_=\"module\",\n        language=\"python\",\n        ...\n    ))\n```\n\n资料来源：[src/thought/ingest/code/python_extractor.py:28-50]()\n\n### TypeScript Extractor\n\nThe TypeScript extractor supports both `.ts` and `.tsx` files using separate tree-sitter grammars:\n\n```python\ndef extract(source: str, file_path: str) -> tuple[list[CodeEntity], list[CodeEdge]]:\n    use_tsx = file_path.endswith((\".tsx\", \".jsx\"))\n    parser = _get_parser(use_tsx=use_tsx)\n    ...\n```\n\nNode types processed include `function_declaration`, `arrow_function`, `class_declaration`, `method_definition`, `import_statement`, and `export_statement`. 资料来源：[src/thought/ingest/code/typescript_extractor.py:120-145]()\n\n### PHP Extractor\n\nThe PHP extractor handles files starting with `<?php` and recursively scans for definitions nested under `namespace_definition` blocks:\n\n```python\ndef _scan(node: Node) -> None:\n    for child in node.named_children:\n        ...\n```\n\n资料来源：[src/thought/ingest/code/php_extractor.py:45-60]()\n\n### Rust Extractor\n\nThe Rust extractor uses `tree-sitter-rust` and tracks method visibility through `impl_type` attributes:\n\n```python\nout_entities.append(CodeEntity(\n    name=qualified, type_=\"method\", language=\"rust\",\n    visibility=_rust_visibility(child, source_bytes),\n    attrs={\"impl_type\": type_name},\n))\n```\n\n资料来源：[src/thought/ingest/code/rust_extractor.py:1-30]()\n\n## Call Graph Resolution\n\nThe call graph is built in a separate Phase 2 pass after all files are ingested. The `build_call_graph` function resolves callee references using a cascade of strategies:\n\n1. **Exact match within same file** — direct intra-file resolution\n2. **Qualified suffix match** — `obj.method()` resolves to `ClassName.method`\n3. **Cross-file bare-name match** — top-level functions defined elsewhere\n4. **Stub creation** — synthetic stub for unknown callees (filtered from impact graphs)\n\n```python\ntgt_id = backend.find_code_entity(\n    canonical_name=callee_name, scope_filter=sf, code_file=file_path,\n)\nif tgt_id is None and \".\" not in callee_name:\n    # Unique qualified suffix match.\n    rows = backend._conn.execute(\n        \"SELECT id FROM entities \"\n        \"WHERE type IN ('method','function') AND valid_until IS NULL \"\n        \"AND canonical_name LIKE ? ...\",\n        (f\"%.{callee_name.lower()}\", commit_sha),\n    ).fetchall()\n```\n\n资料来源：[src/thought/ingest/code/call_graph.py:1-60]()\n\n## CodeIngestPipeline\n\nThe `CodeIngestPipeline` orchestrates the full ingest workflow:\n\n1. Reads source file content\n2. Detects or validates language\n3. Calls the appropriate extractor\n4. Creates a source reference record\n5. Writes entities within a single transaction\n6. Embeds entity signatures and docstrings for VIBE recall\n7. Writes edges and resolves call graph\n\n```mermaid\ngraph LR\n    A[Source File] --> B[detect_language]\n    B --> C[extract entities/edges]\n    C --> D[upsert_source]\n    D --> E[begin transaction]\n    E --> F[_write_entities + embed]\n    F --> G[_write_edges]\n    G --> H[build_call_graph]\n    H --> I[commit]\n```\n\nThe pipeline embeds entity signatures and docstrings so that queries like \"who calls authenticate_user\" can find functions by intent rather than exact name. 资料来源：[src/thought/ingest/code/pipeline.py:1-80]()\n\n## CodeLayer API\n\nThe `CodeLayer` provides a high-level interface for code graph queries:\n\n| Method | Description |\n|--------|-------------|\n| `callers_of(name)` | Direct callers, ranked by Personalized PageRank |\n| `callees_of(name)` | Direct callees (intra-package) |\n| `impact_set(name)` | Transitive callers, ranked — for `thought impact` command |\n| `defines_in_file(path)` | All entities discovered in a file |\n\nAll methods operate against the currently-valid view (`valid_until IS NULL`). Pass `as_of=` for historical snapshots. 资料来源：[src/thought/layers/code.py:1-40]()\n\n## Git-Aware Ingest\n\nThe `GitWalker` enables two ingestion modes:\n\n| Mode | Behavior |\n|------|----------|\n| `snapshot` (default) | Ingest HEAD only, stamp every entity with HEAD SHA |\n| `full` | Walk every commit chronologically, stamp each entity with its commit SHA |\n\nThis enables bi-temporal `as_of` queries against historical commits. 资料来源：[src/thought/ingest/code/git_pipeline.py:1-50]()\n\n## Configuration\n\nLanguage is auto-detected by file extension when `language=None`:\n\n| Extension | Language |\n|-----------|----------|\n| `.py` | `python` |\n| `.ts`, `.tsx`, `.js`, `.jsx` | `typescript` |\n| `.go` | `go` |\n| `.rs` | `rust` |\n| `.java` | `java` |\n| `.php` | `php` |\n\nPass `language=` explicitly to override detection. 资料来源：[src/thought/ingest/code/pipeline.py:25-35]()\n\n---\n\n<a id='page-git-integration'></a>\n\n## Git History Integration\n\n### 相关页面\n\n相关主题：[Multi-Language Code Parsing](#page-code-parsing), [Memory Model and Data Structures](#page-memory-model)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/ingest/code/git_pipeline.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/git_pipeline.py)\n- [src/thought/ingest/code/git_walker.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/ingest/code/git_walker.py)\n- [src/thought/cli.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/cli.py)\n- [src/thought/layers/code.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/layers/code.py)\n- [CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n</details>\n\n# Git History Integration\n\n## Overview\n\nGit History Integration enables thought-mcp to ingest source code with full commit-level provenance, allowing bi-temporal queries that can reconstruct what a codebase looked like at any point in its history. This feature stamps every extracted code entity (functions, classes, modules) with the exact git commit SHA where it was discovered, creating a temporal graph that supports \"as-of\" queries.\n\nThe system provides two ingestion modes: a fast **snapshot mode** for current-state analysis and a comprehensive **full-history mode** for complete historical reconstruction.\n\n资料来源：[CHANGELOG.md]()\n\n## Architecture\n\n### Component Overview\n\n```mermaid\ngraph TD\n    subgraph \"Git History Integration\"\n        CLI[\"thought ingest-git CLI\"]\n        Pipeline[\"GitIngestPipeline\"]\n        Walker[\"GitWalker\"]\n        Storage[\"SQLite Backend\"]\n    end\n    \n    subgraph \"Git Operations\"\n        Git[\"git executable\"]\n        RevParse[\"rev-parse HEAD\"]\n        Log[\"log --format\"]\n        LsTree[\"ls-tree -r\"]\n        Show[\"show <sha>:<path>\"]\n    end\n    \n    CLI --> Pipeline\n    Pipeline --> Walker\n    Walker --> Git\n    Git --> RevParse\n    Git --> Log\n    Git --> LsTree\n    Git --> Show\n    Pipeline --> Storage\n```\n\n### Data Flow\n\n```mermaid\nsequenceDiagram\n    participant User\n    participant CLI\n    participant Pipeline\n    participant Walker\n    participant Extractor\n    participant Backend\n    \n    User->>CLI: thought ingest-git /repo --mode full\n    CLI->>Pipeline: run(repo_path, mode)\n    \n    alt snapshot mode\n        Pipeline->>Walker: get_head_commit()\n        Walker->>Git: rev-parse HEAD\n        Git-->>Walker: sha\n        Pipeline->>Pipeline: ingest single snapshot\n    else full mode\n        Pipeline->>Walker: get_all_commits()\n        Walker->>Git: log --format\n        Git-->>Walker: commit list\n        Loop for each commit\n            Pipeline->>Git: ls-tree -r sha\n            Pipeline->>Git: show sha:path\n            Git-->>Pipeline: file content\n            Pipeline->>Extractor: extract(entities, edges)\n            Extractor-->>Pipeline: CodeEntity[], CodeEdge[]\n            Pipeline->>Backend: upsert with commit_sha\n        end\n    end\n    \n    Pipeline-->>User: GitIngestReport\n```\n\n资料来源：[src/thought/ingest/code/git_pipeline.py:1-95]()\n资料来源：[src/thought/ingest/code/git_walker.py:1-60]()\n\n## Core Components\n\n### GitWalker\n\nThe `GitWalker` class provides a read-only interface to git repositories using pure subprocess calls. It deliberately avoids native dependencies like `pygit2` to minimize installation footprint.\n\n| Method | Git Command | Purpose |\n|--------|-------------|---------|\n| `get_head_sha()` | `rev-parse HEAD` | Get current HEAD commit SHA |\n| `get_all_commits()` | `log --format=...` | List all commits chronologically |\n| `get_files_at_commit(sha)` | `ls-tree -r <sha>` | List files in tree at commit |\n| `get_file_at_commit(sha, path)` | `show <sha>:<path>` | Get file content at commit |\n\n#### Commit Data Model\n\n```python\n@dataclass(frozen=True)\nclass Commit:\n    sha: str                    # Full commit SHA\n    author: str                 # Author name\n    author_email: str           # Author email\n    author_date: datetime      # Commit timestamp\n    subject: str                # Commit message first line\n```\n\n资料来源：[src/thought/ingest/code/git_walker.py:24-31]()\n\n#### Initialization Validation\n\n```python\ndef __init__(self, repo_path: Path | str) -> None:\n    self.repo = Path(repo_path)\n    if shutil.which(\"git\") is None:\n        raise RuntimeError(\"git executable not on PATH\")\n    if not (self.repo / \".git\").exists():\n        raise ValueError(f\"not a git repository: {self.repo}\")\n```\n\nThe walker validates that:\n1. The `git` executable exists on PATH\n2. The target path is a valid git repository (contains `.git` directory)\n\n资料来源：[src/thought/ingest/code/git_walker.py:35-42]()\n\n### GitIngestPipeline\n\nThe pipeline orchestrates the complete ingestion process, coordinating between git history traversal and code extraction.\n\n| Parameter | Type | Description |\n|-----------|------|-------------|\n| `repo_path` | `Path` | Path to git repository |\n| `mode` | `GitMode` | `\"snapshot\"` (HEAD only) or `\"full\"` (all commits) |\n| `patterns` | `tuple[str, ...]` | Glob patterns to filter files (e.g., `*.py`) |\n\n#### Ingestion Report\n\n```python\n@dataclass(frozen=True)\nclass GitIngestReport:\n    head_sha: str           # SHA of HEAD at time of ingest\n    mode: GitMode           # Mode used for ingestion\n    commits_visited: int    # Number of commits processed\n    files_ingested: int     # Total files ingested\n    call_edges: int         # Call graph edges created\n```\n\n资料来源：[src/thought/ingest/code/git_pipeline.py:35-41]()\n\n## Ingestion Modes\n\n### Snapshot Mode (Default)\n\nSnapshot mode ingests only the current HEAD commit. This is the recommended mode for:\n\n- Initial repository ingestion\n- Quick code analysis workflows\n- When historical queries are not needed\n\n**Performance characteristics:**\n- Single-pass through current tree\n- No duplicate processing\n- Typical runtime: seconds to minutes depending on repository size\n\n**Entity stamping:**\nAll extracted entities receive the HEAD SHA as their `code_commit_sha` attribute, enabling queries like \"what did auth.middleware look like at HEAD?\" or future comparisons.\n\n资料来源：[src/thought/ingest/code/git_pipeline.py:7-16]()\n\n### Full History Mode\n\nFull mode walks every commit in chronological order, ingesting the file tree at each point. This enables:\n\n- Historical queries: \"what did function X look like at commit Y?\"\n- Diff analysis between any two commits\n- Complete temporal reconstruction of code evolution\n\n**Performance considerations:**\n\n| Repository Size | Estimated Commits | Estimated Time |\n|-----------------|-------------------|----------------|\n| Small (<100 files) | ~100 | ~30 seconds |\n| Medium (500 files) | ~1000 | ~5 minutes |\n| Large (1000+ files) | ~5000+ | ~25+ minutes |\n\n> Note: Full-history ingest is bounded by file count × commits. The per-commit cost is dominated by tree-sitter parsing, not git operations.\n\n资料来源：[src/thought/ingest/code/git_pipeline.py:16-25]()\n\n## CLI Usage\n\n### Command Syntax\n\n```bash\nthought ingest-git <repo_path> [OPTIONS]\n```\n\n#### Options\n\n| Option | Short | Default | Description |\n|--------|-------|---------|-------------|\n| `--mode` | `--mode snapshot` or `--mode full` | `snapshot` | Ingestion mode |\n| `--paths` | `--paths \"*.py,*.js\"` | `*.py` | Comma-separated glob patterns |\n| `--config` | `--config path/to/config` | `thought.toml` | Configuration file |\n\n### Examples\n\n```bash\n# Ingest current directory as git repo (HEAD only)\nthought ingest-git .\n\n# Ingest specific repository with full history\nthought ingest-git /path/to/repo --mode full\n\n# Ingest Python and TypeScript files only\nthought ingest-git . --paths \"*.py,*.ts,*.tsx\"\n\n# Ingest with full git history, multiple file types\nthought ingest-git /project --mode full --paths \"*.py,*.js,*.go\"\n```\n\n资料来源：[src/thought/cli.py:90-120]()\n\n## Code Commit Stamping\n\nEvery extracted code entity receives metadata linking it to its source commit:\n\n```python\neid = self._backend.upsert_entity(\n    # ... other fields ...\n    code_file=ent.file_path,\n    code_language=language,\n    code_commit_sha=commit_sha,  # Links entity to specific commit\n)\n```\n\nThe database schema includes:\n\n| Column | Type | Purpose |\n|--------|------|---------|\n| `code_file` | `TEXT` | File path relative to repo root |\n| `code_language` | `TEXT` | Programming language detected |\n| `code_commit_sha` | `TEXT` | Git commit where entity was found |\n\nThese columns have partial indexes for fast lookups by commit.\n\n资料来源：[CHANGELOG.md]()\n资料来源：[src/thought/ingest/code/pipeline.py:60-75]()\n\n## CodeLayer Query Interface\n\nThe `CodeLayer` class provides convenience methods for querying the code graph with temporal awareness:\n\n```python\nclass CodeLayer:\n    def callers_of(name, *, code_commit_sha=None)  # Find who calls this function\n    def callees_of(name, *, code_commit_sha=None)  # Find what this function calls\n    def impact_set(name)                            # Transitive callers, ranked\n    def defines_in_file(path)                       # Entities in a file\n```\n\n### Temporal Queries\n\nAll lookups operate against the currently-valid view of the code graph. To query historical snapshots, pass the `as_of` parameter or filter by `code_commit_sha`:\n\n```python\n# Query current state\nimpact = code_layer.impact_set(\"authenticate_user\")\n\n# Query historical state (when full-history ingest was used)\nimpact_historical = code_layer.impact_set(\n    \"authenticate_user\",\n    code_commit_sha=\"abc123...\"\n)\n```\n\n资料来源：[src/thought/layers/code.py:1-50]()\n\n## Diff Between Commits\n\nThe system supports computing the difference between any two ingested commits:\n\n```bash\nthought diff --from <sha1> --to <sha2>\n```\n\nThis returns:\n- **Added entities**: Entities present at `--to` but not at `--from`\n- **Removed entities**: Entities present at `--from` but not at `--to`\n\nThe diff operates on the set of entities by name, comparing their commit stamps.\n\n资料来源：[CHANGELOG.md]()\n\n## Supported Languages\n\nThe git ingestion pipeline uses language-specific extractors:\n\n| Language | Extractor | Extensions |\n|----------|-----------|------------|\n| Python | `python_extractor.py` | `.py` |\n| Rust | `rust_extractor.py` | `.rs` |\n| TypeScript | `typescript_extractor.py` | `.ts`, `.tsx` |\n| PHP | `php_extractor.py` | `.php` |\n\nEach extractor uses tree-sitter for AST parsing, extracting:\n- **Entities**: modules, functions, classes, methods\n- **Edges**: IMPORTS, DEFINES, CALLS, INHERITS_FROM, OVERRIDES\n\n资料来源：[src/thought/ingest/code/python_extractor.py]()\n资料来源：[src/thought/ingest/code/rust_extractor.py]()\n资料来源：[src/thought/ingest/code/typescript_extractor.py]()\n资料来源：[src/thought/ingest/code/php_extractor.py]()\n\n## Configuration\n\n### Thought Configuration (thought.toml)\n\n```toml\n[embedder]\ntype = \"auto\"  # or \"ollama\", \"openai\", \"deterministic\"\n\n[storage]\npath = \"thought.db\"\n```\n\n### Environment Variables\n\n| Variable | Description |\n|----------|-------------|\n| `OLLAMA_BASE_URL` | Ollama server URL for embeddings |\n| `OPENAI_API_KEY` | OpenAI API key for embeddings |\n\n## Best Practices\n\n### Initial Ingestion\n\n1. Start with **snapshot mode** to verify the setup works\n2. Run `thought stats` to confirm entities were created\n3. Query a function to verify call graph edges exist\n\n### Full History Ingestion\n\n1. Ensure adequate disk space (full mode creates temporary copies)\n2. Use `--paths` to filter to relevant file types on large repos\n3. Consider running during off-peak hours for large repositories\n\n### Query Optimization\n\n- Use `code_file` filter when querying specific files\n- Use `code_commit_sha` filter for historical lookups\n- Combine with vector similarity for intent-based queries\n\n## Troubleshooting\n\n### \"git executable not on PATH\"\n\n**Solution**: Install git or ensure it's in your system PATH.\n\n```bash\n# Verify git is available\ngit --version\n```\n\n### \"not a git repository\"\n\n**Solution**: Ensure the path contains a `.git` directory:\n\n```bash\n# Initialize if needed\ngit init\n```\n\n### Slow Full-History Ingestion\n\n**Mitigation**:\n- Use `--paths` to filter file types\n- Use snapshot mode for initial setup\n- Consider parallelizing with multiple `--paths` passes\n\n## Summary\n\nGit History Integration transforms thought-mcp from a current-state code analysis tool into a full temporal code repository that can answer questions about code at any point in history. By combining git's commit tracking with bi-temporal database queries, users can reconstruct how functions evolved, who called what across commits, and the complete impact chain of changes over time.\n\nThe architecture prioritizes:\n- **No native dependencies**: Pure subprocess git operations\n- **Two-mode flexibility**: Fast snapshots or complete history\n- **Temporal provenance**: Every entity stamped with its commit SHA\n- **Language generality**: Support for multiple programming languages via tree-sitter\n\n---\n\n<a id='page-agent-adapters'></a>\n\n## Agent Adapters and SDK Integration\n\n### 相关页面\n\n相关主题：[Query and Retrieval System](#page-query-system)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [src/thought/adapters/__init__.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/adapters/__init__.py)\n- [src/thought/adapters/claude_sdk.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/adapters/claude_sdk.py)\n- [src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n- [src/thought/server.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/server.py)\n- [src/thought/hooks/install.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n</details>\n\n# Agent Adapters and SDK Integration\n\n## Overview\n\nThe Agent Adapters and SDK Integration subsystem provides a seamless bridge between THOUGHT's knowledge base and external AI agent frameworks. This system enables any Claude-Agent-SDK-shaped agent to interact with THOUGHT's memory, context retrieval, and code analysis capabilities through a standardized adapter interface.\n\nThe integration layer consists of three primary components:\n\n1. **Claude SDK Adapter** (`ThoughtMemoryProvider`) — A drop-in memory adapter for Claude Agent SDK\n2. **MCP Server Surface** — Exposes core primitives via the Model Context Protocol\n3. **Claude Code Hook Installer** — Integrates THOUGHT directly into Claude Code's event loop\n\n资料来源：[CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n\n## Architecture Overview\n\n```mermaid\ngraph TD\n    subgraph \"Agent Frameworks\"\n        ClaudeSDK[Claude Agent SDK]\n        ClaudeCode[Claude Code CLI]\n        MCPClients[MCP-Compatible Clients]\n    end\n\n    subgraph \"THOUGHT Integration Layer\"\n        ClaudeSDKAdapter[ThoughtMemoryProvider]\n        MCPServer[MCP Server Surface]\n        HookInstaller[Claude Code Hook Installer]\n    end\n\n    subgraph \"Core THOUGHT\"\n        Memory[Memory / Knowledge Base]\n        Embedder[Embedder Service]\n        CodeAnalysis[Code Analysis Engine]\n        Backend[SQLite Backend]\n    end\n\n    ClaudeSDK --> ClaudeSDKAdapter\n    ClaudeSDKAdapter --> Memory\n    ClaudeSDKAdapter --> Embedder\n    \n    ClaudeCode --> HookInstaller\n    HookInstaller --> Memory\n    \n    MCPClients --> MCPServer\n    MCPServer --> Memory\n    MCPServer --> CodeAnalysis\n    MCPServer --> Backend\n\n    Memory --> Backend\n    Embedder --> Backend\n    CodeAnalysis --> Backend\n```\n\n## The Claude SDK Adapter\n\n### Purpose and Scope\n\nThe `ThoughtMemoryProvider` class serves as a drop-in memory adapter for any Claude-Agent-SDK-shaped agent. It wraps THOUGHT's core memory primitives and exposes them through a familiar interface that agent developers expect.\n\n资料来源：[src/thought/adapters/claude_sdk.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/adapters/claude_sdk.py)\n\n### Core Methods\n\nThe adapter implements three primary methods that cover the complete agent loop:\n\n| Method | Purpose | Returns |\n|--------|---------|---------|\n| `context_for(target, role)` | Returns a working-context dict for a specific target entity and role | `dict` with anchor, neighbours, recent_contradictions, role_view |\n| `render_context(target)` | Returns the same payload as a plain-text system-prompt augmentation | `str` formatted for LLM consumption |\n| `record(content)` | Persists what the agent learned to the knowledge base | `str` — source ID of recorded content |\n| `scan(repo_path)` | Runs an incremental scan under the agent's name | `dict` with scan results |\n\n资料来源：[src/thought/adapters/claude_sdk.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/adapters/claude_sdk.py)\n\n### Working Context Structure\n\nThe `context_for()` method returns a ranked, role-aware payload containing:\n\n```python\n{\n    \"anchor\": \"<entity-name>\",           # The target entity\n    \"neighbours\": [...],                  # Top-K related entities\n    \"recent_contradictions\": [...],       # Entities that contradict this one\n    \"role_view\": \"<saved-view-name>\"      # Optional named view for the role\n}\n```\n\nThe context is token-budgeted to prevent overwhelming the agent's context window.\n\n资料来源：[CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n\n### Integration Flow\n\n```mermaid\nsequenceDiagram\n    participant Agent as Claude Agent SDK\n    participant Adapter as ThoughtMemoryProvider\n    participant Memory as THOUGHT Memory\n    participant Embedder as Embedder Service\n    participant Backend as SQLite Backend\n\n    Agent->>Adapter: context_for(\"authenticate\", role=\"code\")\n    Adapter->>Memory: working_context(target, role, budget_tokens)\n    Memory->>Embedder: embed(\"authenticate\")\n    Embedder->>Memory: vector embedding\n    Memory->>Backend: query similar entities\n    Backend-->>Memory: ranked entity results\n    Memory-->>Adapter: structured context dict\n    Adapter-->>Agent: context payload\n\n    Agent->>Adapter: record(\"Learned: auth uses JWT\")\n    Adapter->>Backend: upsert_source(content, mime_type)\n    Adapter->>Backend: store entity + edges\n    Backend-->>Adapter: source_id\n    Adapter-->>Agent: source_id\n```\n\n## MCP Server Surface\n\nThe MCP (Model Context Protocol) server exposes THOUGHT's primitives as tools that any MCP-compatible client can invoke.\n\n资料来源：[src/thought/server.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/server.py)\n\n### Available Tools\n\n#### `working_context`\n\nUniversal \"what does my agent need to know about X right now\" primitive.\n\n```python\n@app.tool()\nasync def working_context(\n    target: str,           # \"function:authenticate\" / \"chapter:5\" / entity name\n    role: str = \"default\", # Contextual role for view filtering\n    budget_tokens: int = 1024,\n    scope: str | None = None,\n    owner_id: str | None = None,\n) -> dict\n```\n\nReturns:\n```python\n{\n    \"anchor\": str,\n    \"neighbours\": list[dict],\n    \"recent_contradictions\": list[dict],\n    \"role_view\": str | None\n}\n```\n\n资料来源：[src/thought/server.py:48-63](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/server.py)\n\n#### `scan`\n\nIncremental code-scan primitive for keeping the knowledge base current.\n\n```python\n@app.tool()\nasync def scan(\n    repo_path: str,           # Repository to scan\n    agent: str | None = None, # Agent name for scan attribution\n    since: str | None = None, # Only files changed since this time/commit\n    max_files: int | None = None,\n    note: str | None = None,\n) -> dict\n```\n\n资料来源：[src/thought/server.py:65-78](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/server.py)\n\n#### `scan_log_list`\n\nLists recent scan runs for tracking incremental progress.\n\n```python\n@app.tool()\nasync def scan_log_list(\n    agent: str | None = None,\n    limit: int = 10,\n) -> dict\n```\n\nReturns:\n```python\n{\n    \"scans\": [\n        {\n            \"scan_id\": str,\n            \"agent\": str,\n            \"timestamp\": str,\n            \"files_processed\": int,\n            \"note\": str | None\n        },\n        ...\n    ]\n}\n```\n\n资料来源：[src/thought/server.py:80-91](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/server.py)\n\n## Client Installation\n\nTHOUGHT supports installation into multiple MCP-compatible clients. The installation process merges a `thought` MCP server entry into the client's configuration file.\n\n资料来源：[src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n\n### Supported Clients\n\n| Client | Configuration Path |\n|--------|-------------------|\n| Project | `.claude/settings.json` |\n| User | `~/.claude/settings.json` |\n\n资料来源：[src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n\n### Installation Function\n\n```python\ndef install(\n    client: ClientName,\n    *,\n    server_name: str = \"thought\",\n    block: dict | None = None,\n    backup: bool = True,\n) -> ClientInstallResult\n```\n\n**Parameters:**\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `client` | `ClientName` | Required | Target client name |\n| `server_name` | `str` | `\"thought\"` | Name for the server entry |\n| `block` | `dict \\| None` | `None` | Custom server block; defaults to `server_block()` |\n| `backup` | `bool` | `True` | Backup existing config before modification |\n\n**Return Type:** `ClientInstallResult`\n\n```python\n@dataclass\nclass ClientInstallResult:\n    client: ClientName\n    path: Path | None\n    status: Literal[\"installed\", \"already_present\", \"error\", \"no_path\"]\n    detail: str = \"\"\n```\n\n资料来源：[src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n\n### Installation Behavior\n\nThe `install()` function performs the following:\n\n1. **Read existing config** — Parses the client's JSON configuration\n2. **Merge server entry** — Adds the `thought` server block under `mcpServers`\n3. **Backup** — Creates `settings.json.thought.bak` before any write\n4. **Idempotency check** — Returns `already_present` if entry exists and matches\n\n资料来源：[src/thought/clients.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/clients.py)\n\n```mermaid\ngraph TD\n    A[install called] --> B{Config exists?}\n    B -->|No| C[Create new config]\n    B -->|Yes| D{Valid JSON?}\n    D -->|No| E[Return error]\n    D -->|Yes| F{Server entry exists?}\n    F -->|Yes, matches| G[Return already_present]\n    F -->|Yes, differs| H[Backup config]\n    F -->|No| I[Add server entry]\n    H --> J[Write merged config]\n    I --> J\n    C --> J\n    J --> K[Return installed]\n```\n\n## Claude Code Hook Integration\n\nThe hook installer provides Claude Code event-driven integration, enabling THOUGHT to automatically capture context at key points in the development workflow.\n\n资料来源：[src/thought/hooks/install.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n\n### Hook Kinds\n\n| Hook Kind | Claude Code Event | Command | Trigger |\n|-----------|------------------|---------|---------|\n| `recall` | `UserPromptSubmit` | `thought hook recall` | After user submits a prompt |\n| `write` | `Stop` | `thought hook write` | After agent completes work |\n| `context` | `SessionStart` | `thought hook context` | When session begins |\n\n资料来源：[src/thought/hooks/install.py:15-22](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n\n### Hook Installation Result\n\n```python\n@dataclass(frozen=True)\nclass HookInstallResult:\n    kind: HookKind\n    path: Path\n    status: Literal[\"installed\", \"already_present\", \"error\"]\n    detail: str = \"\"\n```\n\n### Settings Path Resolution\n\n```python\ndef settings_path(*, scope: Literal[\"project\", \"user\"] = \"project\") -> Path\n```\n\n- **Project scope** — `.claude/settings.json` (recommended default)\n- **User scope** — `~/.claude/settings.json`\n\n资料来源：[src/thought/hooks/install.py:41-50](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/hooks/install.py)\n\n## Demo Integration\n\nThe `thought demo` command includes a built-in walkthrough specifically for the Claude Agent SDK adapter:\n\n```python\n- ``code``  Agent / developer flow — the 14-stage code-vertical\n            walkthrough including agent identity, ``thought scan``,\n            ``working_context``, 4 new-language extractors, and the\n            Claude Agent SDK adapter.\n```\n\n资料来源：[src/thought/demo.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/demo.py)\n\n### Demo Audiences\n\n| Audience | Purpose | Key Features |\n|----------|---------|--------------|\n| `code` | Agent/developer flow | SDK adapter, scan, working_context |\n| `writer` | Novelist/paper author | Bi-temporal model, contradiction detection |\n| `legal` | Investigator/paralegal | `unique_predicates`, CONTRADICTS edges |\n| `researcher` | Academic | Claim/source pairs, Cypher queries |\n| `all` | Sequential all audiences | Full demonstration suite |\n\n## Configuration\n\n### Environment Variables\n\nThe integration layer respects the following environment variables for embedder configuration:\n\n| Variable | Purpose |\n|----------|---------|\n| `THOUGHT_DB_PATH` | Override database path |\n| `THOUGHT_EMBEDDER` | Embedder choice (`auto`, `sentence-transformers`, etc.) |\n| `THOUGHT_OLLAMA_HOST` | Ollama server host |\n| `THOUGHT_OLLAMA_MODEL` | Ollama model name |\n| `THOUGHT_LMSTUDIO_URL` | LM Studio server URL |\n| `THOUGHT_LMSTUDIO_MODEL` | LM Studio model name |\n| `THOUGHT_OPENAI_COMPAT_URL` | OpenAI-compatible API URL |\n| `THOUGHT_OPENAI_COMPAT_MODEL` | OpenAI-compatible model name |\n| `THOUGHT_OPENAI_COMPAT_API_KEY` | API key for OpenAI-compatible endpoints |\n\n资料来源：[src/thought/config.py](https://github.com/RNBBarrett/thought-mcp/blob/main/src/thought/config.py)\n\n### Config File (`thought.toml`)\n\n```toml\n[embedding]\nchoice = \"auto\"  # or specific embedder name\n\n[db]\npath = \".thought/thought.db\"\n```\n\n## Dependencies\n\nThe adapter package requires the following extras:\n\n```toml\n[project.optional-dependencies]\nadapters = [\"httpx>=0.27\"]\n```\n\n资料来源：[CHANGELOG.md](https://github.com/RNBBarrett/thought-mcp/blob/main/CHANGELOG.md)\n\n## Usage Example\n\n```python\nfrom thought.adapters.claude_sdk import ThoughtMemoryProvider\n\n# Initialize adapter\nmemory = ThoughtMemoryProvider()\n\n# Get working context for a function\ncontext = memory.context_for(\n    target=\"authenticate_user\",\n    role=\"security-reviewer\",\n    budget_tokens=2048,\n)\n\n# Record what the agent learned\nsource_id = memory.record(\n    \"Session token validation happens in this function. \"\n    \"Uses HMAC-SHA256 for signature verification.\"\n)\n\n# Run incremental scan\nresult = memory.scan(\n    repo_path=\"/path/to/project\",\n    agent=\"security-audit\",\n    note=\"Weekly security review scan\"\n)\n```\n\n## Summary\n\nThe Agent Adapters and SDK Integration system provides three complementary pathways for integrating THOUGHT with external agents:\n\n1. **Direct SDK Integration** — `ThoughtMemoryProvider` for Claude Agent SDK agents\n2. **MCP Protocol** — Standard tool interface for any MCP-compatible client\n3. **Claude Code Hooks** — Event-driven integration for Claude Code CLI users\n\nAll pathways share the same underlying memory primitives, ensuring consistent behavior regardless of how the agent connects to THOUGHT.\n\n---\n\n---\n\n## Doramagic Pitfall Log\n\nProject: RNBBarrett/thought-mcp\n\nSummary: Found 8 potential pitfall items; 0 are high/blocking. Highest priority: configuration - 可能修改宿主 AI 配置.\n\n## 1. configuration · 可能修改宿主 AI 配置\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: 项目面向 Claude/Cursor/Codex/Gemini/OpenCode 等宿主，或安装命令涉及用户配置目录。\n- User impact: 安装可能改变本机 AI 工具行为，用户需要知道写入位置和回滚方法。\n- Suggested check: 列出会写入的配置文件、目录和卸载/回滚步骤。\n- Guardrail action: 涉及宿主配置目录时必须给回滚路径，不能只给安装命令。\n- Evidence: capability.host_targets | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | host_targets=mcp_host, claude, claude_code, chatgpt\n\n## 2. capability · 能力判断依赖假设\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: README/documentation is current enough for a first validation pass.\n- User impact: 假设不成立时，用户拿不到承诺的能力。\n- Suggested check: 将假设转成下游验证清单。\n- Guardrail action: 假设必须转成验证项；没有验证结果前不能写成事实。\n- Evidence: capability.assumptions | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | README/documentation is current enough for a first validation pass.\n\n## 3. maintenance · 来源证据：v0.2.1 — thought upgrade + mcp-extras fix\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.2.1 — thought upgrade + mcp-extras fix\n- User impact: 可能增加新用户试用和生产接入成本。\n- Suggested check: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Guardrail action: 不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- Evidence: community_evidence:github | cevd_dc6434cd71064812ae14d01e7f5d9ef0 | https://github.com/RNBBarrett/thought-mcp/releases/tag/v0.2.1 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 4. maintenance · 维护活跃度未知\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: 未记录 last_activity_observed。\n- User impact: 新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- Suggested check: 补 GitHub 最近 commit、release、issue/PR 响应信号。\n- Guardrail action: 维护活跃度未知时，推荐强度不能标为高信任。\n- Evidence: evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | last_activity_observed missing\n\n## 5. security_permissions · 下游验证发现风险项\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: no_demo\n- User impact: 下游已经要求复核，不能在页面中弱化。\n- Suggested check: 进入安全/权限治理复核队列。\n- Guardrail action: 下游风险存在时必须保持 review/recommendation 降级。\n- Evidence: downstream_validation.risk_items | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | no_demo; severity=medium\n\n## 6. security_permissions · 存在评分风险\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: no_demo\n- User impact: 风险会影响是否适合普通用户安装。\n- Suggested check: 把风险写入边界卡，并确认是否需要人工复核。\n- Guardrail action: 评分风险必须进入边界卡，不能只作为内部分数。\n- Evidence: risks.scoring_risks | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | no_demo; severity=medium\n\n## 7. maintenance · issue/PR 响应质量未知\n\n- Severity: low\n- Evidence strength: source_linked\n- Finding: issue_or_pr_quality=unknown。\n- User impact: 用户无法判断遇到问题后是否有人维护。\n- Suggested check: 抽样最近 issue/PR，判断是否长期无人处理。\n- Guardrail action: issue/PR 响应未知时，必须提示维护风险。\n- Evidence: evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | issue_or_pr_quality=unknown\n\n## 8. maintenance · 发布节奏不明确\n\n- Severity: low\n- Evidence strength: source_linked\n- Finding: release_recency=unknown。\n- User impact: 安装命令和文档可能落后于代码，用户踩坑概率升高。\n- Suggested check: 确认最近 release/tag 和 README 安装命令是否一致。\n- Guardrail action: 发布节奏未知或过期时，安装说明必须标注可能漂移。\n- Evidence: evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | release_recency=unknown\n\n<!-- canonical_name: RNBBarrett/thought-mcp; human_manual_source: deepwiki_human_wiki -->\n",
      "summary": "DeepWiki/Human Wiki output with a Doramagic pitfall appendix.",
      "title": "Human Manual"
    },
    "pitfall_log": {
      "asset_id": "pitfall_log",
      "filename": "PITFALL_LOG.md",
      "markdown": "# Pitfall Log\n\nProject: RNBBarrett/thought-mcp\n\nSummary: Found 8 potential pitfall items; 0 are high/blocking. Highest priority: configuration - 可能修改宿主 AI 配置.\n\n## 1. configuration · 可能修改宿主 AI 配置\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: 项目面向 Claude/Cursor/Codex/Gemini/OpenCode 等宿主，或安装命令涉及用户配置目录。\n- User impact: 安装可能改变本机 AI 工具行为，用户需要知道写入位置和回滚方法。\n- Suggested check: 列出会写入的配置文件、目录和卸载/回滚步骤。\n- Guardrail action: 涉及宿主配置目录时必须给回滚路径，不能只给安装命令。\n- Evidence: capability.host_targets | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | host_targets=mcp_host, claude, claude_code, chatgpt\n\n## 2. capability · 能力判断依赖假设\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: README/documentation is current enough for a first validation pass.\n- User impact: 假设不成立时，用户拿不到承诺的能力。\n- Suggested check: 将假设转成下游验证清单。\n- Guardrail action: 假设必须转成验证项；没有验证结果前不能写成事实。\n- Evidence: capability.assumptions | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | README/documentation is current enough for a first validation pass.\n\n## 3. maintenance · 来源证据：v0.2.1 — thought upgrade + mcp-extras fix\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.2.1 — thought upgrade + mcp-extras fix\n- User impact: 可能增加新用户试用和生产接入成本。\n- Suggested check: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Guardrail action: 不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- Evidence: community_evidence:github | cevd_dc6434cd71064812ae14d01e7f5d9ef0 | https://github.com/RNBBarrett/thought-mcp/releases/tag/v0.2.1 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 4. maintenance · 维护活跃度未知\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: 未记录 last_activity_observed。\n- User impact: 新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- Suggested check: 补 GitHub 最近 commit、release、issue/PR 响应信号。\n- Guardrail action: 维护活跃度未知时，推荐强度不能标为高信任。\n- Evidence: evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | last_activity_observed missing\n\n## 5. security_permissions · 下游验证发现风险项\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: no_demo\n- User impact: 下游已经要求复核，不能在页面中弱化。\n- Suggested check: 进入安全/权限治理复核队列。\n- Guardrail action: 下游风险存在时必须保持 review/recommendation 降级。\n- Evidence: downstream_validation.risk_items | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | no_demo; severity=medium\n\n## 6. security_permissions · 存在评分风险\n\n- Severity: medium\n- Evidence strength: source_linked\n- Finding: no_demo\n- User impact: 风险会影响是否适合普通用户安装。\n- Suggested check: 把风险写入边界卡，并确认是否需要人工复核。\n- Guardrail action: 评分风险必须进入边界卡，不能只作为内部分数。\n- Evidence: risks.scoring_risks | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | no_demo; severity=medium\n\n## 7. maintenance · issue/PR 响应质量未知\n\n- Severity: low\n- Evidence strength: source_linked\n- Finding: issue_or_pr_quality=unknown。\n- User impact: 用户无法判断遇到问题后是否有人维护。\n- Suggested check: 抽样最近 issue/PR，判断是否长期无人处理。\n- Guardrail action: issue/PR 响应未知时，必须提示维护风险。\n- Evidence: evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | issue_or_pr_quality=unknown\n\n## 8. maintenance · 发布节奏不明确\n\n- Severity: low\n- Evidence strength: source_linked\n- Finding: release_recency=unknown。\n- User impact: 安装命令和文档可能落后于代码，用户踩坑概率升高。\n- Suggested check: 确认最近 release/tag 和 README 安装命令是否一致。\n- Guardrail action: 发布节奏未知或过期时，安装说明必须标注可能漂移。\n- Evidence: evidence.maintainer_signals | github_repo:1238261514 | https://github.com/RNBBarrett/thought-mcp | release_recency=unknown\n",
      "summary": "Identity, installation, configuration, runtime, and safety pitfalls before user trial.",
      "title": "Pitfall Log"
    },
    "prompt_preview": {
      "asset_id": "prompt_preview",
      "filename": "PROMPT_PREVIEW.md",
      "markdown": "# thought-mcp - Prompt Preview\n\n> Copy the prompt below into your AI host before installing anything.\n> Its purpose is to let you safely feel the project's workflow, not to claim the project has already run.\n\n## Copy this prompt\n\n```text\nYou are using an independent Doramagic capability pack for RNBBarrett/thought-mcp.\n\nProject:\n- Name: thought-mcp\n- Repository: https://github.com/RNBBarrett/thought-mcp\n- Summary: Local MCP memory server for LLMs. Bi-temporal graph + vector + Cypher queries + auto-write/auto-recall hooks for Claude Code. Works with Ollama, LM Studio, Anthropic, OpenAI.\n- Host target: mcp_host, claude, claude_code, chatgpt\n\nGoal:\nHelp me evaluate this project for the following task without installing it yet: Local MCP memory server for LLMs. Bi-temporal graph + vector + Cypher queries + auto-write/auto-recall hooks for Claude Code. Works with Ollama, LM Studio, Anthropic, OpenAI.\n\nBefore taking action:\n1. Restate my task, success standard, and boundary.\n2. Identify whether the next step requires tools, browser access, network access, filesystem access, credentials, package installation, or host configuration.\n3. Use only the Doramagic Project Pack, the upstream repository, and the source-linked evidence listed below.\n4. If a real command, install step, API call, file write, or host integration is required, mark it as \"requires post-install verification\" and ask for approval first.\n5. If evidence is missing, say \"evidence is missing\" instead of filling the gap.\n\nPreviewable capabilities:\n- Capability 1: Local MCP memory server for LLMs. Bi-temporal graph + vector + Cypher queries + auto-write/auto-recall hooks for Claude Code. Works with Ollama, LM Studio, Anthropic, OpenAI.\n\nCapabilities that require post-install verification:\n- Capability 1: Use the source-backed project context to guide one small, checkable workflow step.\n\nCore service flow:\n1. page-introduction: Introduction to THOUGHT. Produce one small intermediate artifact and wait for confirmation.\n2. page-quickstart: Quickstart Guide. Produce one small intermediate artifact and wait for confirmation.\n3. page-installation: Installation and Setup. Produce one small intermediate artifact and wait for confirmation.\n4. page-architecture: System Architecture. Produce one small intermediate artifact and wait for confirmation.\n5. page-storage-layer: Storage and Database Layer. Produce one small intermediate artifact and wait for confirmation.\n\nSource-backed evidence to keep in mind:\n- https://github.com/RNBBarrett/thought-mcp\n- https://github.com/RNBBarrett/thought-mcp#readme\n- README.md\n- docs/comparison.md\n- src/thought/models.py\n- src/thought/demo.py\n- src/thought/cli.py\n- pyproject.toml\n- src/thought/config.py\n- Dockerfile\n\nFirst response rules:\n1. Start Step 1 only.\n2. Explain the one service action you will perform first.\n3. Ask exactly three questions about my target workflow, success standard, and sandbox boundary.\n4. Stop and wait for my answers.\n\nStep 1 follow-up protocol:\n- After I answer the first three questions, stay in Step 1.\n- Produce six parts only: clarified task, success standard, boundary conditions, two or three options, tradeoffs for each option, and one recommendation.\n- End by asking whether I confirm the recommendation.\n- Do not move to Step 2 until I explicitly confirm.\n\nConversation rules:\n- Advance one step at a time and wait for confirmation after each small artifact.\n- Write outputs as recommendations or planned checks, not as completed execution.\n- Do not claim tests passed, files changed, commands ran, APIs were called, or the project was installed.\n- If the user asks for execution, first provide the sandbox setup, expected output, rollback, and approval checkpoint.\n```\n",
      "summary": "不安装项目也能感受能力节奏的安全试用 Prompt。",
      "title": "Prompt Preview / 安装前试用 Prompt"
    },
    "quick_start": {
      "asset_id": "quick_start",
      "filename": "QUICK_START.md",
      "markdown": "# Quick Start\n\nProject: RNBBarrett/thought-mcp\n\n## Official Entry Points\n\n### Python / pip · 官方安装入口\n\n```bash\npip install thought-mcp\n```\n\nSource：https://github.com/RNBBarrett/thought-mcp#readme\n\n## Sources\n\n- repo: https://github.com/RNBBarrett/thought-mcp\n- docs: https://github.com/RNBBarrett/thought-mcp#readme\n",
      "summary": "Entry points extracted from official README or installation documentation.",
      "title": "Quick Start"
    }
  },
  "validation_id": "dval_1115cfafb5dd48f8842d7e45e3fc9b07"
}
