# midas - Doramagic AI Context Pack

> 定位：安装前体验与判断资产。它帮助宿主 AI 有一个好的开始，但不代表已经安装、执行或验证目标项目。

## 充分原则

- **充分原则，不是压缩原则**：AI Context Pack 应该充分到让宿主 AI 在开工前理解项目价值、能力边界、使用入口、风险和证据来源；它可以分层组织，但不以最短摘要为目标。
- **压缩策略**：只压缩噪声和重复内容，不压缩会影响判断和开工质量的上下文。

## 给宿主 AI 的使用方式

你正在读取 Doramagic 为 midas 编译的 AI Context Pack。请把它当作开工前上下文：帮助用户理解适合谁、能做什么、如何开始、哪些必须安装后验证、风险在哪里。不要声称你已经安装、运行或执行了目标项目。

## Claim 消费规则

- **事实来源**：Repo Evidence + Claim/Evidence Graph；Human Wiki 只提供显著性、术语和叙事结构。
- **事实最低状态**：`supported`
- `supported`：可以作为项目事实使用，但回答中必须引用 claim_id 和证据路径。
- `weak`：只能作为低置信度线索，必须要求用户继续核实。
- `inferred`：只能用于风险提示或待确认问题，不能包装成项目事实。
- `unverified`：不得作为事实使用，应明确说证据不足。
- `contradicted`：必须展示冲突来源，不得替用户强行选择一个版本。

## 它最适合谁

- **AI 研究者或研究型 Agent 构建者**：README 明确围绕研究、实验或论文工作流展开。 证据：`README.md` Claim：`clm_0002` supported 0.86
- **正在使用 Claude/Codex/Cursor/Gemini 等宿主 AI 的开发者**：README 或插件配置提到多个宿主 AI。 证据：`README.md` Claim：`clm_0003` supported 0.86

## 它能做什么

- **命令行启动或安装流程**（需要安装后验证）：项目文档中存在可执行命令，真实使用需要在本地或宿主环境中运行这些命令。 证据：`README.md`, `packages/midas-memory-mcp/README.md`, `packages/midas-ts/README.md` Claim：`clm_0001` supported 0.86

## 怎么开始

- `uv tool install "midas-memory[mcp,local]"     # the midas-mcp command, for any MCP client` 证据：`README.md` Claim：`clm_0004` supported 0.86
- `claude mcp add midas -s user \` 证据：`README.md` Claim：`clm_0005` supported 0.86, `clm_0008` supported 0.86
- `pipx install midas-memory-mcp` 证据：`packages/midas-memory-mcp/README.md` Claim：`clm_0006` supported 0.86
- `pip install midas-memory-mcp` 证据：`packages/midas-memory-mcp/README.md` Claim：`clm_0007` supported 0.86
- `claude mcp add midas -s user -- midas-memory-mcp` 证据：`packages/midas-memory-mcp/README.md` Claim：`clm_0008` supported 0.86
- `npx midas-memory-mcp        # or: npm i -g midas-memory-mcp && midas-mcp` 证据：`packages/midas-ts/README.md` Claim：`clm_0009` supported 0.86

## 继续前判断卡

- **当前建议**：先做研究框架试用
- **为什么**：这个项目面向研究工作流，核心风险是资料可信度和输出质量；先用 Prompt Preview 验证研究框架，再在隔离环境试装。

### 30 秒判断

- **现在怎么做**：先做研究框架试用
- **最小安全下一步**：先用 Prompt Preview 验证研究框架；满意后再隔离试装
- **先别相信**：研究结论、引用和实验结果不能在安装前相信。
- **继续会触碰**：研究判断、命令执行、本地环境或项目文件

### 现在可以相信

- **适合人群线索：AI 研究者或研究型 Agent 构建者**（supported）：有 supported claim 或项目证据支撑，但仍不等于真实安装效果。 证据：`README.md` Claim：`clm_0002` supported 0.86
- **适合人群线索：正在使用 Claude/Codex/Cursor/Gemini 等宿主 AI 的开发者**（supported）：有 supported claim 或项目证据支撑，但仍不等于真实安装效果。 证据：`README.md` Claim：`clm_0003` supported 0.86
- **能力存在：命令行启动或安装流程**（supported）：可以相信项目包含这类能力线索；是否适合你的具体任务仍要试用或安装后验证。 证据：`README.md`, `packages/midas-memory-mcp/README.md`, `packages/midas-ts/README.md` Claim：`clm_0001` supported 0.86
- **存在 Quick Start / 安装命令线索**（supported）：可以相信项目文档出现过启动或安装入口；不要因此直接在主力环境运行。 证据：`README.md` Claim：`clm_0004` supported 0.86

### 现在还不能相信

- **研究结论、引用和实验结果不能在安装前相信。**（unverified）：研究 Skill 可以组织问题和路径，但不能替代真实资料检索、论文核验和实验复现。
- **是否适合你的具体研究领域不能直接相信。**（unverified）：Skill 覆盖很多研究主题，不代表对你的领域、资料要求和可信度标准足够。
- **真实输出质量不能在安装前相信。**（unverified）：Prompt Preview 只能展示引导方式，不能证明真实项目中的结果质量。
- **宿主 AI 版本兼容性不能在安装前相信。**（unverified）：Claude、Cursor、Codex、Gemini 等宿主加载规则和版本差异必须在真实环境验证。
- **不会污染现有宿主 AI 行为，不能直接相信。**（inferred）：Skill、plugin、AGENTS/CLAUDE/GEMINI 指令可能改变宿主 AI 的默认行为。
- **可安全回滚不能默认相信。**（unverified）：除非项目明确提供卸载和恢复说明，否则必须先在隔离环境验证。
- **真实安装后是否与用户当前宿主 AI 版本兼容？**（unverified）：兼容性只能通过实际宿主环境验证。
- **项目输出质量是否满足用户具体任务？**（unverified）：安装前预览只能展示流程和边界，不能替代真实评测。

### 继续会触碰什么

- **研究判断**：问题拆解、资料路径、实验路径、结论结构和可信度判断。 原因：研究型 Skill 可能让输出看起来更专业，但不能替代真实证据核验。
- **命令执行**：包管理器、网络下载、本地插件目录、项目配置或用户主目录。 原因：运行第一条命令就可能产生环境改动；必须先判断是否值得跑。 证据：`README.md`, `packages/midas-memory-mcp/README.md`, `packages/midas-ts/README.md`
- **本地环境或项目文件**：安装结果、插件缓存、项目配置或本地依赖目录。 原因：安装前无法证明写入范围和回滚方式，需要隔离验证。 证据：`README.md`, `packages/midas-memory-mcp/README.md`, `packages/midas-ts/README.md`
- **宿主 AI 上下文**：AI Context Pack、Prompt Preview、Skill 路由、风险规则和项目事实。 原因：导入上下文会影响宿主 AI 后续判断，必须避免把未验证项包装成事实。

### 最小安全下一步

- **先跑 Prompt Preview**：先验证它能否正确界定研究问题和证据边界，不要先相信研究输出。（适用：任何项目都适用，尤其是输出质量未知时。）
- **只在隔离目录或测试账号试装**：避免安装命令污染主力宿主 AI、真实项目或用户主目录。（适用：存在命令执行、插件配置或本地写入线索时。）
- **安装后只验证一个最小任务**：先验证加载、兼容、输出质量和回滚，再决定是否深用。（适用：准备从试用进入真实工作流时。）

### 退出方式

- **保留安装前状态**：记录原始宿主配置和项目状态，后续才能判断是否可恢复。
- **保留资料和结论核验清单**：如果后续发现引用或实验路径不可靠，可以回到证据边界阶段重新校验。
- **记录安装命令和写入路径**：没有明确卸载说明时，至少要知道哪些目录或配置需要手动清理。
- **如果没有回滚路径，不进入主力环境**：不可回滚是继续前阻断项，不应靠信任或运气继续。

## 哪些只能预览

- 解释项目适合谁和能做什么
- 基于项目文档演示典型对话流程
- 帮助用户判断是否值得安装或继续研究

## 哪些必须安装后验证

- 真实安装 Skill、插件或 CLI
- 执行脚本、修改本地文件或访问外部服务
- 验证真实输出质量、性能和兼容性

## 边界与风险判断卡

- **把安装前预览误认为真实运行**：用户可能高估项目已经完成的配置、权限和兼容性验证。 处理方式：明确区分 prompt_preview_can_do 与 runtime_required。 Claim：`clm_0010` inferred 0.45
- **命令执行会修改本地环境**：安装命令可能写入用户主目录、宿主插件目录或项目配置。 处理方式：先在隔离环境或测试账号中运行。 证据：`README.md`, `packages/midas-memory-mcp/README.md`, `packages/midas-ts/README.md` Claim：`clm_0011` supported 0.86
- **待确认**：真实安装后是否与用户当前宿主 AI 版本兼容？。原因：兼容性只能通过实际宿主环境验证。
- **待确认**：项目输出质量是否满足用户具体任务？。原因：安装前预览只能展示流程和边界，不能替代真实评测。
- **待确认**：安装命令是否需要网络、权限或全局写入？。原因：这影响企业环境和个人环境的安装风险。

## 开工前工作上下文

### 加载顺序

- 先读取 how_to_use.host_ai_instruction，建立安装前判断资产的边界。
- 读取 claim_graph_summary，确认事实来自 Claim/Evidence Graph，而不是 Human Wiki 叙事。
- 再读取 intended_users、capabilities 和 quick_start_candidates，判断用户是否匹配。
- 需要执行具体任务时，优先查 role_skill_index，再查 evidence_index。
- 遇到真实安装、文件修改、网络访问、性能或兼容性问题时，转入 risk_card 和 boundaries.runtime_required。

### 任务路由

- **命令行启动或安装流程**：先说明这是安装后验证能力，再给出安装前检查清单。 边界：必须真实安装或运行后验证。 证据：`README.md`, `packages/midas-memory-mcp/README.md`, `packages/midas-ts/README.md` Claim：`clm_0001` supported 0.86

### 上下文规模

- 文件总数：97
- 重要文件覆盖：40/97
- 证据索引条目：74
- 角色 / Skill 条目：16

### 证据不足时的处理

- **missing_evidence**：说明证据不足，要求用户提供目标文件、README 段落或安装后验证记录；不要补全事实。
- **out_of_scope_request**：说明该任务超出当前 AI Context Pack 证据范围，并建议用户先查看 Human Manual 或真实安装后验证。
- **runtime_request**：给出安装前检查清单和命令来源，但不要替用户执行命令或声称已执行。
- **source_conflict**：同时展示冲突来源，标记为待核实，不要强行选择一个版本。

## Prompt Recipes

### 适配判断

- 目标：判断这个项目是否适合用户当前任务。
- 预期输出：适配结论、关键理由、证据引用、安装前可预览内容、必须安装后验证内容、下一步建议。

```text
请基于 midas 的 AI Context Pack，先问我 3 个必要问题，然后判断它是否适合我的任务。回答必须包含：适合谁、能做什么、不能做什么、是否值得安装、证据来自哪里。所有项目事实必须引用 evidence_refs、source_paths 或 claim_id。
```

### 安装前体验

- 目标：让用户在安装前感受核心工作流，同时避免把预览包装成真实能力或营销承诺。
- 预期输出：一段带边界标签的体验剧本、安装后验证清单和谨慎建议；不含真实运行承诺或强营销表述。

```text
请把 midas 当作安装前体验资产，而不是已安装工具或真实运行环境。

请严格输出四段：
1. 先问我 3 个必要问题。
2. 给出一段“体验剧本”：用 [安装前可预览]、[必须安装后验证]、[证据不足] 三种标签展示它可能如何引导工作流。
3. 给出安装后验证清单：列出哪些能力只有真实安装、真实宿主加载、真实项目运行后才能确认。
4. 给出谨慎建议：只能说“值得继续研究/试装”“先补充信息后再判断”或“不建议继续”，不得替项目背书。

硬性边界：
- 不要声称已经安装、运行、执行测试、修改文件或产生真实结果。
- 不要写“自动适配”“确保通过”“完美适配”“强烈建议安装”等承诺性表达。
- 如果描述安装后的工作方式，必须使用“如果安装成功且宿主正确加载 Skill，它可能会……”这种条件句。
- 体验剧本只能写成“示例台词/假设流程”：使用“可能会询问/可能会建议/可能会展示”，不要写“已写入、已生成、已通过、正在运行、正在生成”。
- Prompt Preview 不负责给安装命令；如用户准备试装，只能提示先阅读 Quick Start 和 Risk Card，并在隔离环境验证。
- 所有项目事实必须来自 supported claim、evidence_refs 或 source_paths；inferred/unverified 只能作风险或待确认项。

```

### 角色 / Skill 选择

- 目标：从项目里的角色或 Skill 中挑选最匹配的资产。
- 预期输出：候选角色或 Skill 列表，每项包含适用场景、证据路径、风险边界和是否需要安装后验证。

```text
请读取 role_skill_index，根据我的目标任务推荐 3-5 个最相关的角色或 Skill。每个推荐都要说明适用场景、可能输出、风险边界和 evidence_refs。
```

### 风险预检

- 目标：安装或引入前识别环境、权限、规则冲突和质量风险。
- 预期输出：环境、权限、依赖、许可、宿主冲突、质量风险和未知项的检查清单。

```text
请基于 risk_card、boundaries 和 quick_start_candidates，给我一份安装前风险预检清单。不要替我执行命令，只说明我应该检查什么、为什么检查、失败会有什么影响。
```

### 宿主 AI 开工指令

- 目标：把项目上下文转成一次对话开始前的宿主 AI 指令。
- 预期输出：一段边界明确、证据引用明确、适合复制给宿主 AI 的开工前指令。

```text
请基于 midas 的 AI Context Pack，生成一段我可以粘贴给宿主 AI 的开工前指令。这段指令必须遵守 not_runtime=true，不能声称项目已经安装、运行或产生真实结果。
```

## 角色 / Skill 索引

- 共索引 16 个角色 / Skill / 项目文档条目。

- **Contributing to Midas**（project_doc）：Thanks for considering a contribution. Midas is eval-first : the project's one durable asset is that its reported numbers are true. A few principles keep it that way. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`CONTRIBUTING.md`
- **or, no Python: npx -y midas-memory-mcp TypeScript port**（project_doc）：The local memory layer for long-horizon AI agents — remembers across sessions, keeps what's current, and won't act on stale memory. No LLM at ingest · $0 per message · fully local · every recall traces to its source. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`README.md`
- **midas-memory-mcp**（project_doc）：The MCP server for Midas https://github.com/vornicx/Midas — local-first, source-traceable agent memory with no LLM at ingest . Local embeddings + ranking only: ingest is $0, nothing leaves your machine, and every recalled memory points back to its source turn no LLM-rewritten facts . 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`packages/midas-memory-mcp/README.md`
- **midas-memory-mcp TypeScript — experimental**（project_doc）：midas-memory-mcp TypeScript — experimental 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`packages/midas-ts/README.md`
- **Midas — The Complete Picture**（project_doc）：The local, governed memory & trust plane for long-horizon coding agents — no LLM at ingest, $0 per message, fully local, every recall traceable to its source. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/MIDAS.md`
- **Agent-Memory Audit**（project_doc）：Can your agent be trusted to act on what it remembers? We measure it. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/agent-memory-audit.md`
- **The Agent-Memory Bench Suite**（project_doc）：A standard for evaluating agent memory beyond recall@k — what a governed memory layer must guarantee for an agent to act on it safely. Deterministic, $0, no LLM, reproducible. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/agent-memory-benches.md`
- **The agent-memory frontier mid-2026 — landscape, positioning, roadmap**（project_doc）：The agent-memory frontier mid-2026 — landscape, positioning, roadmap 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/frontier-2026.md`
- **Midas — Go-To-Market dev / enterprise-led**（project_doc）：Midas — Go-To-Market dev / enterprise-led 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/gtm.md`
- **Long-Horizon Agent Memory — Design Concept**（project_doc）：Long-Horizon Agent Memory — Design Concept 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/long-horizon-memory.md`
- **Eval methodology — where the bodies are not buried**（project_doc）：Eval methodology — where the bodies are not buried 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/methodology.md`
- **Overnight autonomous experiments — Midas recall / precision / speed levers**（project_doc）：Overnight autonomous experiments — Midas recall / precision / speed levers 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/overnight-experiments.md`
- **Notes from building an honest agent-memory benchmark**（project_doc）：Notes from building an honest agent-memory benchmark 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/research-notes.md`
- **Midas Benchmarks**（project_doc）：Honest, reproducible benchmarks for the Midas agentic-memory SDK. Every number here comes from a real run with the command to reproduce it. We deliberately lead with reader-independent metrics retrieval + cost and treat end-to-end answer correctness as a secondary, noisy signal — see docs/methodology.md docs/methodology.md for why that is the honest choice, not a convenient one, plus the verbatim MCP policy, failure… 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`BENCHMARKS.md`
- **Changelog**（project_doc）：Notable changes to Midas. Pre-1.0 — the API may change. Format loosely follows Keep a Changelog https://keepachangelog.com/ . 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`CHANGELOG.md`
- **Midas — Privacy Policy**（project_doc）：Midas is a local-first memory connector. It is designed so that your data never leaves your own computer. This policy describes exactly what Midas does and does not do with your data. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`PRIVACY.md`

## 证据索引

- 共索引 74 条证据。

- **Contributing to Midas**（documentation）：Thanks for considering a contribution. Midas is eval-first : the project's one durable asset is that its reported numbers are true. A few principles keep it that way. 证据：`CONTRIBUTING.md`
- **or, no Python: npx -y midas-memory-mcp TypeScript port**（documentation）：The local memory layer for long-horizon AI agents — remembers across sessions, keeps what's current, and won't act on stale memory. No LLM at ingest · $0 per message · fully local · every recall traces to its source. 证据：`README.md`
- **midas-memory-mcp**（documentation）：The MCP server for Midas https://github.com/vornicx/Midas — local-first, source-traceable agent memory with no LLM at ingest . Local embeddings + ranking only: ingest is $0, nothing leaves your machine, and every recalled memory points back to its source turn no LLM-rewritten facts . 证据：`packages/midas-memory-mcp/README.md`
- **midas-memory-mcp TypeScript — experimental**（documentation）：midas-memory-mcp TypeScript — experimental 证据：`packages/midas-ts/README.md`
- **Package**（package_manifest）：{ "name": "midas-memory-mcp", "version": "0.0.4", "description": "Midas \u2014 local-first, source-traceable agent memory over MCP TypeScript port, experimental . No LLM at ingest or query.", "license": "Apache-2.0", "type": "module", "engines": { "node": " =22.5" }, "bin": { "midas-mcp": "dist/bin/midas-mcp.js" }, "main": "dist/index.js", "types": "dist/index.d.ts", "files": "dist", "README.md" , "repository": { "type": "git", "url": "https://github.com/vornicx/Midas.git", "directory": "packages/midas-ts" }, "scripts": { "build": "tsc", "test": "npm run build && node --test test/ .test.mjs" }, "keywords": "mcp", "agent", "memory", "local-first", "llm" , "dependencies": { "@modelcontextprot… 证据：`packages/midas-ts/package.json`
- **License**（source_file）：Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ 证据：`LICENSE`
- **Midas — The Complete Picture**（documentation）：The local, governed memory & trust plane for long-horizon coding agents — no LLM at ingest, $0 per message, fully local, every recall traceable to its source. 证据：`docs/MIDAS.md`
- **Agent-Memory Audit**（documentation）：Can your agent be trusted to act on what it remembers? We measure it. 证据：`docs/agent-memory-audit.md`
- **The Agent-Memory Bench Suite**（documentation）：A standard for evaluating agent memory beyond recall@k — what a governed memory layer must guarantee for an agent to act on it safely. Deterministic, $0, no LLM, reproducible. 证据：`docs/agent-memory-benches.md`
- **The agent-memory frontier mid-2026 — landscape, positioning, roadmap**（documentation）：The agent-memory frontier mid-2026 — landscape, positioning, roadmap 证据：`docs/frontier-2026.md`
- **Midas — Go-To-Market dev / enterprise-led**（documentation）：Midas — Go-To-Market dev / enterprise-led 证据：`docs/gtm.md`
- **Long-Horizon Agent Memory — Design Concept**（documentation）：Long-Horizon Agent Memory — Design Concept 证据：`docs/long-horizon-memory.md`
- **Eval methodology — where the bodies are not buried**（documentation）：Eval methodology — where the bodies are not buried 证据：`docs/methodology.md`
- **Overnight autonomous experiments — Midas recall / precision / speed levers**（documentation）：Overnight autonomous experiments — Midas recall / precision / speed levers 证据：`docs/overnight-experiments.md`
- **Notes from building an honest agent-memory benchmark**（documentation）：Notes from building an honest agent-memory benchmark 证据：`docs/research-notes.md`
- **Manifest**（structured_config）：{ "manifest version": "0.3", "name": "midas-memory", "display name": "Midas — Local Agent Memory", "version": "0.0.4", "description": "Local-first, source-traceable memory for Claude — no LLM at ingest, fully offline.", "long description": "Midas gives Claude a persistent, local memory. Everything is stored on your own machine in a SQLite file, recall returns the exact source text no LLM rewriting at ingest or query, so every memory is auditable , and capture/forget run with no network calls — your memories never leave your computer. Midas auto-scores what is worth keeping facts, decisions, preferences, constraints, corrections and drops chit-chat and duplicates, and it keeps the store boun… 证据：`mcpb/manifest.json`
- **Server**（structured_config）：{ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json", "name": "io.github.vornicx/midas", "description": "Local-first, source-traceable agent memory \u2014 no LLM at ingest, fully offline", "title": "Midas", "repository": { "url": "https://github.com/vornicx/Midas", "source": "github" }, "version": "0.0.4", "packages": { "registryType": "pypi", "registryBaseUrl": "https://pypi.org", "identifier": "midas-memory-mcp", "version": "0.0.4", "runtimeHint": "uvx", "transport": { "type": "stdio" }, "environmentVariables": { "name": "MIDAS MCP DB", "description": "Path to a SQLite file to persist memory across restarts default: in-memory ", "isRequired": false,… 证据：`server.json`
- **green when every attack is stopped and every other metric is perfect**（source_file）：def run verbose: bool = True - dict ⋮---- cont = continuity.run verbose=False safe = memory safety.run verbose=False code = coding bench.run verbose=False rows = ⋮---- green when every attack is stopped and every other metric is perfect green = safe "ASR" == 0.0 and all 证据：`eval/benches.py`
- **LongMemEval timestamps look like '2023/05/20 Sat 02:21'. Parse to epoch seconds so memories**（source_file）：DATA DIR = Path file .resolve .parent.parent / "data" SESSION RE = re.compile r"^session \d+ $" LongMemEval timestamps look like '2023/05/20 Sat 02:21'. Parse to epoch seconds so memories carry real event time the benchmark's temporal-reasoning / knowledge-update signal . LME DATE RE = re.compile r" \d{4} / \d{2} / \d{2} \D+ \d{2} : \d{2} " def parse lme date value: str None - float None ⋮---- m = LME DATE RE.search value ⋮---- def synthetic - Dataset ⋮---- """An evolving project where a handful of durable facts/decisions are interleaved with disposable chatter, then queried later. Distractors + a tight token budget make recall non-trivial — the 'needle survives the noise' property real lon… 证据：`eval/datasets.py`
- **Memory Safety**（source_file）：@dataclass frozen=True class SafetyCase ⋮---- name: str kind: str build: Callable , Memory query: str intended use: MemoryUse expect allowed: bool acting agent: str None = None def mem - Memory def superseded confirmation - Memory ⋮---- m = mem old = m.remember "User confirmed: deleting the staging bucket is approved.", new = m.remember "Update: keep the staging bucket — we still need it for QA.", ⋮---- def unconfirmed observation - Memory def plan only - Memory def cross agent action - Memory def injected source - Memory def forgotten confirmation - Memory ⋮---- rec = m.remember "User confirmed: deleting /var/data is approved.", ⋮---- def current confirmation - Memory def observation for p… 证据：`eval/memory_safety.py`
- **Optional columns appear only when some adapter produced them: answer dumb with**（source_file）：COLUMNS = "recall@k", "precision@k", "answer", "avg tokens", "eff ans/1k tok " DEFAULT JUDGE MAX QUESTIONS = 40 DEFAULTS = { ⋮---- tracks recall = getattr adapter, "tracks event ids", True recalls: list float = precisions: list float = answers: list float = dumb answers: list float = answers grounded: list float = abstentions: list float = abstentions grounded: list float = token costs: list int = judged: list tuple = question traces: list dict str, object = asked = 0 ingest seconds = 0.0 query seconds = 0.0 n ingested = 0 stale updated = 0 stale hits = 0 stale contradictions = 0 category recalls: dict str, list float = {} category precisions: dict str, list float = {} category answers: dic… 证据：`eval/runner.py`
- **Summarization Ab**（source_file）：STRUCT PROMPT = SUMM SYS = RUBRIC SYS = THINK RE = re.compile r"", re.IGNORECASE re.DOTALL YESNO RE = re.compile r"\b YES NO \b" PREAMBLE = def strip think text: str - str def is card line: str - bool ⋮---- """Keep only lines carrying the card SIGNATURE — a entity head or the when: … temporal slot. This enforces the exact structure under test AND rejects what a weak extractor leaks on code-heavy conversations: raw code/HTML/markup which contains = but never the temporal slot or an entity head , markdown headers, and conversational preamble. If a model can't produce the signature, its 'cards' are correctly dropped — that null is a real result, not a bug.""" s = line.strip ⋮---- def distill s… 证据：`eval/summarization_ab.py`
- **Coding Agent Demo**（source_file）：def build memory - Memory mem = build memory thread = {"session": "build-acme-api"} 证据：`examples/coding_agent_demo.py`
- **Audit**（source_file）：def audit record r: MemoryRecord - dict str, Any ⋮---- """The complete, source-traceable audit fields of one memory no embedding .""" ⋮---- def belief history mem: "Memory", record id: str - list MemoryRecord ⋮---- by id = {r.id: r for r in mem.store.all } ⋮---- replaced by new = {r.superseded by: r.id for r in by id.values if r.superseded by} ⋮---- oldest = replaced by new oldest ⋮---- chain: list MemoryRecord = cur: str None = oldest walked: set str = set ⋮---- rec = by id cur ⋮---- cur = rec.superseded by ⋮---- def audit completeness records: list MemoryRecord - float ⋮---- full = sum 1 for r in records if r.source and r.actor ⋮---- decision = mem.guard reliance query, intended use=inten… 证据：`midas/audit.py`
- **Distill**（source_file）：@runtime checkable class Distiller Protocol ⋮---- def distill self, texts: list str - list str : ... DISTILL PROMPT = class OllamaDistiller ⋮---- def distill self, texts: list str - list str ⋮---- prompt = DISTILL PROMPT.format turns="\n".join texts body = json.dumps req = urllib.request.Request ⋮---- out = json.loads resp.read "response" ⋮---- class HTTPDistiller ⋮---- out = json.loads resp.read "choices" 0 "message" "content" ⋮---- def parse facts out: str - list str 证据：`midas/distill.py`
- **Proper-noun-like: a capitalised alpha token 2 chars, not a stopword that does NOT start a**（source_file）：STOP = { WORD = re.compile r" A-Za-z A-Za-z'- " HAS DIGIT = re.compile r"\d" SENT END = re.compile r" .!? $" class ContentImportance ⋮---- """Score a turn's importance in 1..5 from its content alone no LLM . Callable: scorer text .""" def init self, , min importance: int = 1, max importance: int = 5 - None def score self, text: str - int ⋮---- text = text or "" .strip ⋮---- tokens = text.split n tokens = len tokens content: set str = set ⋮---- m = WORD.fullmatch w.strip ".,;:!?\"' " ⋮---- n content = len content n digit = sum 1 for w in tokens if HAS DIGIT.search w Proper-noun-like: a capitalised alpha token 2 chars, not a stopword that does NOT start a sentence — the first word of every se… 证据：`midas/importance.py`
- **instructions are surfaced to the model by the MCP client on connect — this is how installing Midas**（source_file）：MAX RECORDS = int os.getenv "MIDAS MCP MAX RECORDS", "0" or None POLICY = MemoryPolicy min importance=int os.getenv "MIDAS MCP MIN IMPORTANCE", "2" ACTOR = os.getenv "MIDAS MCP ACTOR", "midas-mcp" NAMESPACE = os.getenv "MIDAS MCP NAMESPACE", "" def ns namespace: str - str def ns metadata namespace: str, session: str - dict ⋮---- ns = ns namespace ⋮---- def ns filter namespace: str - dict None SUPERSEDE = os.getenv "MIDAS MCP SUPERSEDE", "1" != "0" SUPERSEDE CONVO = os.getenv "MIDAS MCP SUPERSEDE CONVO", "0" == "1" USE NLI = os.getenv "MIDAS MCP NLI", "0" == "1" PINNED = int os.getenv "MIDAS MCP PINNED", "2" or "0" MULTILINGUAL MODEL = "sentence-transformers/paraphrase-multilingual-MiniLM-L1… 证据：`midas/mcp_server.py`
- **No turn entails an answer - drop the tempting snippets so the only honest reply is**（source_file）：RECENCY HALF LIFE DAYS = 30.0 DEFAULT RECALL LIMIT = 6 SHORT TERM DAYS = 1.0 MEDIUM TERM DAYS = 7.0 DURABLE KINDS: tuple MemoryKind, ... = "fact", "preference", "constraint" UPDATE PATTERNS = UPDATE RE = re.compile " ".join UPDATE PATTERNS , re.IGNORECASE CONVO UPDATE PATTERNS = CONVO UPDATE RE = re.compile " ".join CONVO UPDATE PATTERNS , re.IGNORECASE SUPERSEDE STOPWORDS = { SUPERSEDE ENTITY STOPWORDS = { PROPER ENTITY RE = re.compile r"\b A-Z A-Za-z0-9 - {2,}\b" PROVENANCE RANK = { def content words text: str - set str def proper entities text: str - set str ⋮---- @runtime checkable class Reranker Protocol ⋮---- def rerank self, query: str, documents: list str - list float : ... ⋮---- @d… 证据：`midas/memory.py`
- **Sqlite Store**（source_file）：class SQLiteStore InMemoryStore ⋮---- def migrate self - None ⋮---- columns = {row 1 for row in self. conn.execute "PRAGMA table info memories " .fetchall } ⋮---- def load self - None ⋮---- cur = self. conn.execute ⋮---- def current data version self - int def refresh if stale self - None ⋮---- version = self. current data version ⋮---- @staticmethod def row to record row - MemoryRecord ⋮---- embedding = None ⋮---- embedding = np.frombuffer emb blob, dtype=" None ⋮---- emb blob = ⋮---- def get self, record id: str - MemoryRecord None def all self - list MemoryRecord ⋮---- def delete self, record id: str - bool ⋮---- existed = super .delete record id ⋮---- def clear self - None def close sel… 证据：`midas/sqlite_store.py`
- **Midas Adapter**（source_file）：VALID KINDS = {"note", "chat", "mission", "fact", "preference", "constraint"} class MidasAdapter ⋮---- name = "midas" uses internal llm = False ⋮---- def get nli self def get reranker self def get sparse backend self def get store self def reset self - None ⋮---- reranker = self. get reranker ⋮---- def ingest self, events: list Event - None ⋮---- items = ⋮---- kind = event.kind if event.kind in VALID KINDS else "note" ⋮---- @property def store size self - int def forget decayed self, kwargs - list str def consolidate self, kwargs - list str def query self, question: str, , token budget: int, now: float None = None - RetrievalResult ⋮---- block = self. mem.build context ids: list str = ⋮----… 证据：`eval/adapters/midas_adapter.py`
- **Midas Mcp**（source_file）：import { main } from "../mcp.js"; 证据：`packages/midas-ts/src/bin/midas-mcp.ts`
- **Mcp**（source_file）：import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { z } from "zod"; import { decideMemoryUse, MEMORY USES, type MemoryUse } from "./guard.js"; import { Memory, DEFAULT POLICY } from "./memory.js"; import { structuralImportance } from "./importance.js"; import { AGENT MEMORY INSTRUCTIONS, policySummary } from "./policy.js"; import { InMemoryStore, SQLiteStore } from "./store.js"; import { MEMORY PROVENANCE, type MemoryKind, type MemoryProvenance, type MemoryRecord } from "./types.js"; ⋮---- function buildMemory : Memory ⋮---- function ns namespace: string : string function nsMetadata n… 证据：`packages/midas-ts/src/mcp.ts`
- **Midas Benchmarks**（documentation）：Honest, reproducible benchmarks for the Midas agentic-memory SDK. Every number here comes from a real run with the command to reproduce it. We deliberately lead with reader-independent metrics retrieval + cost and treat end-to-end answer correctness as a secondary, noisy signal — see docs/methodology.md docs/methodology.md for why that is the honest choice, not a convenient one, plus the verbatim MCP policy, failure-case traces, and how conflicting memories are handled. 证据：`BENCHMARKS.md`
- **Changelog**（documentation）：Notable changes to Midas. Pre-1.0 — the API may change. Format loosely follows Keep a Changelog https://keepachangelog.com/ . 证据：`CHANGELOG.md`
- **Midas — Privacy Policy**（documentation）：Midas is a local-first memory connector. It is designed so that your data never leaves your own computer. This policy describes exactly what Midas does and does not do with your data. 证据：`PRIVACY.md`
- **Tsconfig**（structured_config）：{ "compilerOptions": { "target": "ES2022", "module": "NodeNext", "moduleResolution": "NodeNext", "outDir": "dist", "rootDir": "src", "strict": true, "declaration": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true }, "include": "src" } 证据：`packages/midas-ts/tsconfig.json`
- **Copy to .env and fill in. Only needed for --openai real embeddings / LLM-judge .**（source_file）：Copy to .env and fill in. Only needed for --openai real embeddings / LLM-judge . OPENAI API KEY= 证据：`.env.example`
- **Python**（source_file）：Python pycache / .py cod .egg-info/ .pytest cache/ .ruff cache/ dist/ build/ 证据：`.gitignore`
- **2 Recall / latency vs nprobe at full N.**（source_file）：DB = os.environ.get N QUERIES = 500 K = 10 def normalize x: np.ndarray - np.ndarray def load vectors - tuple np.ndarray, str ⋮---- con = sqlite3.connect DB rows = con.execute "select embedding from embeddings where dim=768" .fetchall ⋮---- x = np.frombuffer b"".join r 0 for r in rows , dtype=np.float32 .reshape len rows , 768 ⋮---- rng = np.random.default rng 0 ⋮---- centers = normalize rng.normal size= k, d .astype np.float32 x = centers rng.integers 0, k, n + 0.35 rng.normal size= n, d .astype np.float32 ⋮---- def exact topk corpus: np.ndarray, q: np.ndarray, k: int - np.ndarray ⋮---- sims = corpus @ q part = np.argpartition -sims, k - 1 :k ⋮---- def time per query fn, queries: np.ndarray… 证据：`eval/bench_ann.py`
- **Bench Perf**（source_file）：def pct xs: list float , p: float - float ⋮---- xs = sorted xs i = min len xs - 1, int round p / 100 len xs - 1 ⋮---- def ms x: float - str def main - None ⋮---- ap = argparse.ArgumentParser description="Midas latency / throughput / footprint benchmark" ⋮---- args = ap.parse args ⋮---- embedder = LocalEmbedder label = f"local:{embedder.model name}" ⋮---- embedder = HashingEmbedder label = "hashing offline " mem = Memory embedder=embedder ⋮---- records = queries = f"timeout for service-{i % 50} in payments" for i in range args.q ⋮---- mem before = tracemalloc.get traced memory 0 t0 = time.perf counter ⋮---- s = time.perf counter ⋮---- ingest wall = time.perf counter - t0 mem after = tracemal… 证据：`eval/bench_perf.py`
- **forbidden accuracy — violations flagged, benign actions not.**（source_file）：PROJECT = "apollo" def build project - Memory ⋮---- mem = Memory embedder=HashingEmbedder old = remember architecture decision mem, "Apollo's primary database is MySQL.", project=PROJECT, created at=100 new = remember architecture decision mem, "Apollo's primary database is PostgreSQL.", project=PROJECT, created at=300 ⋮---- MISTAKES = ACTIONS = def run verbose: bool = True - dict str, float ⋮---- mem = build project decisions = project state mem, PROJECT .get "architecture decision", db = r for r in decisions if "database" in r.content.lower decision ok = bool db and "PostgreSQL" in db 0 .content and all "MySQL" not in r.content for r in db avoided = 0 ⋮---- ok = any marker in h.record.con… 证据：`eval/coding_bench.py`
- **Adhered = the current value is present AND the stale value isn't quoted on a line of its own.**（source_file）：@dataclass frozen=True class ActionCase ⋮---- query: str intended use: MemoryUse expect allowed: bool note: str ⋮---- @dataclass frozen=True class AdherenceCase ⋮---- current: str stale: str ⋮---- @dataclass frozen=True class MistakeCase ⋮---- must resurface: str ⋮---- def build memory - Memory ⋮---- mem = Memory embedder=HashingEmbedder , supersede=True, supersede threshold=0.85 ⋮---- cache old = mem.remember ⋮---- artifacts old = mem.remember cache new = mem.remember artifacts new = mem.remember ⋮---- ACTION CASES: tuple ActionCase, ... = ADHERENCE CASES: tuple AdherenceCase, ... = MISTAKE CASES: tuple MistakeCase, ... = def run verbose: bool = True - dict str, float ⋮---- mem = build mem… 证据：`eval/continuity.py`
- **Distill Ab**（source_file）：def distiller model: str - HTTPDistiller def build raw turns: list str , embedder - Memory ⋮---- mem = Memory embedder=embedder, importance scorer=StructuralImportance ⋮---- def build distilled turns: list str , embedder, distiller, batch: int, keep raw: bool = False - Memory ⋮---- mem = Memory embedder=embedder, importance scorer=StructuralImportance , distiller=distiller ⋮---- def main - None ⋮---- ap = argparse.ArgumentParser ⋮---- args = ap.parse args embedder = LocalEmbedder distiller = distiller args.distill model reader: ChatLLM = from env args.reader model judge: ChatLLM = from env args.judge model dataset = beam tier=args.tier, max conversations=args.convs raw hits: dict str, list… 证据：`eval/distill_ab.py`
- **Forbidden Eval**（source_file）：PROJECT = "p" RULES = POSITIVES = NEGATIVES = def rule act rule: str - str def sweep pos: list float , neg: list float , lo: float, hi: float, step: float ⋮---- best = {"f1": -1.0, "thr": lo, "prec": 0.0, "recall": 0.0} rows = t = lo ⋮---- tp = sum s = t for s in pos fp = sum s = t for s in neg prec = tp / tp + fp if tp + fp else 0.0 rec = tp / len pos f1 = 2 prec rec / prec + rec if prec + rec else 0.0 ⋮---- best = {"thr": t, "prec": prec, "recall": rec, "f1": f1} ⋮---- def logreg loo X, y, , epochs: int = 400, lr: float = 0.3, l2: float = 0.02 ⋮---- X = np.asarray X, float y = np.asarray y, float ⋮---- Xn = X - mu / sd preds = np.zeros len y ⋮---- mask = np.ones len y , bool ⋮---- w = np.… 证据：`eval/forbidden_eval.py`
- **Reasoning models sometimes spend the whole token budget in a separate reasoning channel**（source_file）：PROVIDERS = def retry after resp: httpx.Response - float None ⋮---- value = resp.headers.get "retry-after" ⋮---- def load dotenv path: str Path None = None - None ⋮---- path = Path path if path else Path file .resolve .parent.parent / ".env" ⋮---- line = line.strip ⋮---- class ChatLLM ⋮---- def init self, , base url: str, api key: str, model: str - None ⋮---- payload = { ⋮---- headers = {"Authorization": f"Bearer {self.api key}"} ⋮---- resp = self. client.post ⋮---- msg = resp.json "choices" 0 "message" content = msg.get "content" or "" .strip Reasoning models sometimes spend the whole token budget in a separate reasoning channel and return empty content; fall back to that channel so we sti… 证据：`eval/llm.py`
- **Robust to verbose/reasoning models: take the LAST standalone YES/NO in the reply.**（source_file）：def recall at k result: RetrievalResult, question: Question - float None ⋮---- retrieved = set result.retrieved event ids hit = sum 1 for gid in question.gold event ids if gid in retrieved ⋮---- def precision at k result: RetrievalResult, question: Question - float None ⋮---- retrieved = list dict.fromkeys result.retrieved event ids ⋮---- gold = set question.gold event ids hit = sum 1 for rid in retrieved if rid in gold ⋮---- def answer recoverable result: RetrievalResult, question: Question - float None def contains answer text: str, needle: str None - bool def has stale conflict context: str, current: str None, stale: str None - bool TOKEN RE = re.compile r" a-z0-9 +" DUMB STOPWORDS = fro… 证据：`eval/metrics.py`
- **Midas Sweep**（source_file）：def fmt value: float None - str def main - None ⋮---- parser = argparse.ArgumentParser description="Sweep Midas LoCoMo settings" ⋮---- args = parser.parse args embedder = None embedder label = "hashing" ⋮---- embedder = LocalEmbedder embedder label = f"local:{embedder.model name}" dataset = locomo max conversations=args.max convs ⋮---- budgets = int x.strip for x in args.budgets.split "," if x.strip min relevances: list float None = max record chars = int x.strip for x in args.max record chars.split "," if x.strip ⋮---- adapter = MidasAdapter metrics = run adapter 证据：`eval/midas_sweep.py`
- **Multiday**（source_file）：ANSWER SYS = def last text: str, options: list str - str None ⋮---- found = re.findall r"\b " + " ".join options + r" \b", text.upper ⋮---- def answer llm, context: str, question: str - str def classify value llm, predicted: str, current: str, outdated: str None - str ⋮---- out = outdated if outdated is not None else " no outdated value " verdict = llm.complete ⋮---- def classify abstain llm, predicted: str - str def verdict llm, question: Question, context: str - tuple str, str ⋮---- predicted = answer llm, context, question.text ⋮---- def context quality pairs: list tuple Question, RetrievalResult - dict str, float ⋮---- """Deterministic context diagnostics before spending LLM-judge calls… 证据：`eval/multiday.py`
- **The value-vs-fifo diff at each retained fraction: where did the importance×recency rank**（source_file）：def load args: argparse.Namespace def now ref sample - float None ⋮---- """Reference 'now' for recency/value: the latest event time, so 'recent' means the freshest turn. None when the dataset carries no event timestamps recency then falls back to ingest order .""" times = e.metadata.get "timestamp" for e in sample.events if e.metadata.get "timestamp" ⋮---- def evict oldest store, target: int - None ⋮---- recs = sorted store.all , key=lambda r: r.created at ⋮---- def evict random store, target: int, seed: int - None ⋮---- recs = list store.all ⋮---- def measure adapter: MidasAdapter, sample, , budget: int - dict str, float ⋮---- pairs = q, adapter.query q.text, token budget=budget for q in s… 证据：`eval/retention.py`
- **Retrieval Adapter**（source_file）：def normalize x: np.ndarray - np.ndarray ⋮---- W = np.eye dim, dtype=np.float64 eye = np.eye dim, dtype=np.float64 rng = random.Random seed order = list range len triplets ⋮---- Wq = W @ q grad = l2 W - eye ⋮---- grad = grad + np.outer n - p, q ⋮---- def recall at k query rows: list tuple set int , np.ndarray , k: int - float ⋮---- recalls = ⋮---- topk = set np.argsort -scores :k .tolist ⋮---- def main - None ⋮---- ap = argparse.ArgumentParser ⋮---- args = ap.parse args embedder = LocalEmbedder dataset = beam tier=args.tier, max conversations=args.convs samples: list dict = dim = 0 ⋮---- ids = e.id for e in sample.events row of = {eid: i for i, eid in enumerate ids } E = normalize np.array… 证据：`eval/retrieval_adapter.py`
- **Schema**（source_file）：@dataclass class Event ⋮---- id: str content: str kind: str = "chat" importance: int = 1 speaker: str None = None metadata: dict str, Any = field default factory=dict ⋮---- @dataclass class Question ⋮---- text: str answer: str None = None gold event ids: list str = field default factory=list category: str = "fact" stale answer: str None = None ⋮---- @dataclass class Sample ⋮---- events: list Event questions: list Question ⋮---- @dataclass class Dataset ⋮---- name: str samples: list Sample 证据：`eval/schema.py`
- **Distillation Demo**（source_file）：def build embedder CHATTER = RAW DECISION TURN = DISTILLED FACT = QUERY = "which environment do we deploy to?" def main - None ⋮---- raw = Memory embedder=embedder, importance scorer=StructuralImportance ⋮---- distilled = Memory embedder=embedder, importance scorer=StructuralImportance ⋮---- star = " <- the deploy answer" if "staging" in hit.record.content.lower else "" 证据：`examples/distillation_demo.py`
- **Turbovec Backend**（source_file）：def main - None ⋮---- embedder = LocalEmbedder store = TurboVecStore mem = Memory store=store, embedder=embedder 证据：`examples/turbovec_backend.py`
- **Init**（source_file）：SQLiteStore = None ⋮---- IVFIndex = IVFStore = None ⋮---- TurboVecIndex = TurboVecStore = None all = version = "0.0.4" 证据：`midas/__init__.py`
- **Access**（source_file）：scope = record.metadata.get scope key ⋮---- allowed = set allowed scopes 证据：`midas/access.py`
- **Ann**（source_file）：def kmeans x: np.ndarray, k: int, , n iter: int, rng: np.random.Generator - np.ndarray ⋮---- centroids = x rng.choice x.shape 0 , k, replace=False .copy ⋮---- assign = np.argmax x @ centroids.T, axis=1 ⋮---- members = x assign == c ⋮---- v = members.sum axis=0 norm = float np.linalg.norm v ⋮---- class IVFIndex ⋮---- def fit self, vectors: Sequence Sequence float np.ndarray - "IVFIndex" ⋮---- x = np.asarray vectors, dtype=np.float32 ⋮---- n = x.shape 0 nlist = self.nlist or max 1, int round np.sqrt n nlist = min nlist, n ⋮---- rng = np.random.default rng self.seed train = x if n None def put self, record: MemoryRecord - None def get self, record id: str - MemoryRecord None def delete self, r… 证据：`midas/ann.py`
- **Bm25**（source_file）：K1 = 1.5 B = 0.75 class BM25 ⋮---- def init self, records: list MemoryRecord - None ⋮---- doc = tokenize record.content ⋮---- n = len records ⋮---- def scores self, query: str - dict str, float ⋮---- q terms = tokenize query avgdl = self. avgdl or 1.0 by doc: dict int, float = {} ⋮---- postings = self. postings.get term ⋮---- idf = self. idf term ⋮---- dl = self. dls i 证据：`midas/bm25.py`
- **Glue words that shouldn't count toward an action↔rule match the rule's negation — "never", "don't"**（source_file）：CODE KIND MAP: dict str, tuple MemoryKind, int, MemoryProvenance = { CODE KINDS: tuple str, ... = tuple CODE KIND MAP ⋮---- meta = { metadata or {} , "code kind": code kind, "project": project} ⋮---- def remember architecture decision mem: "Memory", content: str, , project: str, kw: Any - MemoryRecord def remember bug fixed mem: "Memory", content: str, , project: str, kw: Any - MemoryRecord def remember convention mem: "Memory", content: str, , project: str, kw: Any - MemoryRecord def remember forbidden action mem: "Memory", content: str, , project: str, kw: Any - MemoryRecord def project state mem: "Memory", project: str, , limit: int = 200 - dict str, list MemoryRecord ⋮---- records = ⋮--… 证据：`midas/coding.py`
- **Colbert**（source_file）：class ColBERTReranker ⋮---- name = "colbert" ⋮---- MAX QUERY CHARS = 400 MAX DOC CHARS = 1200 def rerank self, query: str, documents: list str - list float ⋮---- q = query : self. MAX QUERY CHARS docs = d : self. MAX DOC CHARS for d in documents ⋮---- q emb = np.asarray next iter self. model.query embed q , dtype=np.float32 nq = max 1, q emb.shape 0 out: list float = ⋮---- d = np.asarray d emb, dtype=np.float32 ⋮---- maxsim = float q emb @ d.T .max axis=1 .sum / nq p = min 1.0 - 1e-6, max 1e-6, maxsim 证据：`midas/colbert.py`
- **Embeddings**（source_file）：WORD = re.compile r"\w+", re.UNICODE def tokenize text: str - list str ⋮---- """Lowercase word tokens of length 2 Unicode-aware .""" ⋮---- @runtime checkable class Embedder Protocol ⋮---- dim: int def embed self, text: str - list float : ... def embed many self, texts: list str - list list float : ... class HashingEmbedder ⋮---- """Offline, deterministic bag-of-words hashed into a fixed-dim unit vector.""" def init self, dim: int = 256 - None def embed self, text: str - list float ⋮---- vec = 0.0 self.dim ⋮---- digest = hashlib.md5 tok.encode "utf-8" .digest h = int.from bytes digest :8 , "big" idx = h % self.dim sign = 1.0 if h 8 & 1 else -1.0 ⋮---- def embed many self, texts: list str - l… 证据：`midas/embeddings.py`
- 其余 14 条证据见 `AI_CONTEXT_PACK.json` 或 `EVIDENCE_INDEX.json`。

## 宿主 AI 必须遵守的规则

- **把本资产当作开工前上下文，而不是运行环境。**：AI Context Pack 只包含证据化项目理解，不包含目标项目的可执行状态。 证据：`CONTRIBUTING.md`, `README.md`, `packages/midas-memory-mcp/README.md`
- **回答用户时区分可预览内容与必须安装后才能验证的内容。**：安装前体验的消费者价值来自降低误装和误判，而不是伪装成真实运行。 证据：`CONTRIBUTING.md`, `README.md`, `packages/midas-memory-mcp/README.md`

## 用户开工前应该回答的问题

- 你准备在哪个宿主 AI 或本地环境中使用它？
- 你只是想先体验工作流，还是准备真实安装？
- 你最在意的是安装成本、输出质量、还是和现有规则的冲突？

## 验收标准

- 所有能力声明都能回指到 evidence_refs 中的文件路径。
- AI_CONTEXT_PACK.md 没有把预览包装成真实运行。
- 用户能在 3 分钟内看懂适合谁、能做什么、如何开始和风险边界。

---

## Doramagic Context Augmentation

下面内容用于强化 Repomix/AI Context Pack 主体。Human Manual 只提供阅读骨架；踩坑日志会被转成宿主 AI 必须遵守的工作约束。

## Human Manual 骨架

使用规则：这里只是项目阅读路线和显著性信号，不是事实权威。具体事实仍必须回到 repo evidence / Claim Graph。

宿主 AI 硬性规则：
- 不得把页标题、章节顺序、摘要或 importance 当作项目事实证据。
- 解释 Human Manual 骨架时，必须明确说它只是阅读路线/显著性信号。
- 能力、安装、兼容性、运行状态和风险判断必须引用 repo evidence、source path 或 Claim Graph。

- **核心记忆引擎与存储抽象**：importance `high`
  - source_paths: midas/memory.py, midas/index.py, midas/store.py, midas/ann.py, midas/sqlite_store.py
- **MCP 服务器与多客户端集成**：importance `high`
  - source_paths: midas/mcp_server.py, packages/midas-memory-mcp/README.md, packages/midas-memory-mcp/pyproject.toml, packages/midas-ts/src/mcp.ts, packages/midas-ts/src/memory.ts
- **来源治理护栏与信念修订**：importance `high`
  - source_paths: midas/guard.py, midas/access.py, midas/audit.py, midas/nli.py, midas/state.py
- **评估套件与蒸馏档位**：importance `high`
  - source_paths: eval/benches.py, eval/runner.py, eval/continuity.py, eval/memory_safety.py, eval/coding_bench.py

## Repo Inspection Evidence / 源码检查证据

- repo_clone_verified: true
- repo_inspection_verified: true
- repo_commit: `07c39d0f876a127e87ec26a05c9c96ba65534d97`
- inspected_files: `README.md`, `pyproject.toml`, `docs/MIDAS.md`, `docs/agent-memory-audit.md`, `docs/agent-memory-benches.md`, `docs/frontier-2026.md`, `docs/gtm.md`, `docs/long-horizon-memory.md`, `docs/methodology.md`, `docs/overnight-experiments.md`, `docs/research-notes.md`, `examples/coding_agent_demo.py`, `examples/distillation_demo.py`, `examples/turbovec_backend.py`, `packages/midas-memory-mcp/README.md`, `packages/midas-memory-mcp/midas_memory_mcp/__init__.py`, `packages/midas-memory-mcp/pyproject.toml`, `packages/midas-ts/README.md`, `packages/midas-ts/package-lock.json`, `packages/midas-ts/package.json`

宿主 AI 硬性规则：
- 没有 repo_clone_verified=true 时，不得声称已经读过源码。
- 没有 repo_inspection_verified=true 时，不得把 README/docs/package 文件判断写成事实。
- 没有 quick_start_verified=true 时，不得声称 Quick Start 已跑通。

## Doramagic Pitfall Constraints / 踩坑约束

这些规则来自 Doramagic 发现、验证或编译过程中的项目专属坑点。宿主 AI 必须把它们当作工作约束，而不是普通说明文字。

### Constraint 1: 可能修改宿主 AI 配置

- Trigger: 项目面向 Claude/Cursor/Codex/Gemini/OpenCode 等宿主，或安装命令涉及用户配置目录。
- Host AI rule: 列出会写入的配置文件、目录和卸载/回滚步骤。
- Why it matters: 安装可能改变本机 AI 工具行为，用户需要知道写入位置和回滚方法。
- Evidence: capability.host_targets | https://github.com/vornicx/Midas | host_targets=mcp_host, claude_code, claude, cursor
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 2: 能力判断依赖假设

- Trigger: README/documentation is current enough for a first validation pass.
- Host AI rule: 将假设转成下游验证清单。
- Why it matters: 假设不成立时，用户拿不到承诺的能力。
- Evidence: capability.assumptions | https://github.com/vornicx/Midas | README/documentation is current enough for a first validation pass.
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 3: 维护活跃度未知

- Trigger: 未记录 last_activity_observed。
- Host AI rule: 补 GitHub 最近 commit、release、issue/PR 响应信号。
- Why it matters: 新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。
- Evidence: evidence.maintainer_signals | https://github.com/vornicx/Midas | last_activity_observed missing
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

- Trigger: no_demo
- Evidence: downstream_validation.risk_items | https://github.com/vornicx/Midas | no_demo; severity=medium
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 5: 存在评分风险

- Trigger: no_demo
- Why it matters: 风险会影响是否适合普通用户安装。
- Evidence: risks.scoring_risks | https://github.com/vornicx/Midas | no_demo; severity=medium
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 6: issue/PR 响应质量未知

- Trigger: issue_or_pr_quality=unknown。
- Host AI rule: 抽样最近 issue/PR，判断是否长期无人处理。
- Why it matters: 用户无法判断遇到问题后是否有人维护。
- Evidence: evidence.maintainer_signals | https://github.com/vornicx/Midas | issue_or_pr_quality=unknown
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 7: 发布节奏不明确

- Trigger: release_recency=unknown。
- Host AI rule: 确认最近 release/tag 和 README 安装命令是否一致。
- Why it matters: 安装命令和文档可能落后于代码，用户踩坑概率升高。
- Evidence: evidence.maintainer_signals | https://github.com/vornicx/Midas | release_recency=unknown
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。
