概述
project-scoped 安装下,recall / auto-recall 的 scope 隔离没有真正生效:搜索(尤其是自动触发的 recall)返回的数据实质上来自 user scope (~/.teamai),而不是当前项目 scope。根因是 learnings 同步/索引构建以及索引读取路径被写死/默认到了 user 位置。
复现
- 在某个项目目录用 project scope 安装并
teamai pull(<projectRoot>/.teamai/config.yaml 中 scope: project)。
- 触发自动 recall(如 Bash 命令报错 / Grep / WebSearch),或手动
teamai recall <query>。
- 观察结果。
期望: project scope 下应检索项目 scope 的 learnings,结果应标记/来自 project。
实际: 结果全部来自 user scope([user],File: 指向 ~/.teamai/learnings/);自动 recall 完全不看 project。
三层根因
层 1 — teamai pull 根本不为 project scope 建索引
src/pull.ts:517
// Step 3.5: Sync learnings and rebuild search index (user scope only)
if (!options.dryRun && localConfig.scope === 'user') {
...
const elapsed = await buildIndex(LEARNINGS_LOCAL_DIR, votesDir); // 未传 indexPath
}
- 整段 learnings 同步 + 索引构建被
localConfig.scope === 'user' 门控,project scope 的 pullForScope 直接跳过。
- 即便进入,
buildIndex(...) 未传 indexPath,内部 fallback 到 getSearchIndexPath() = ~/.teamai/search-index.json(src/utils/search-index.ts:251 与 :13)。
- 结果:
<projectRoot>/.teamai/search-index.json 与 <projectRoot>/.teamai/learnings/ 永远不会被 pull 创建。
层 2 — 自动 recall(PostToolUse hook)永远读 user 索引
src/auto-recall.ts:528
const index = await loadIndex(); // 无参数 → getSearchIndexPath() → ~/.teamai/search-index.json
- 自动触发路径调用
loadIndex() 不传路径,无论是否在 project scope,永远只读 user 索引。
- 紧随其后的 auto-upvote(
src/auto-recall.ts:589)用 requireInit()(永远读 ~/.teamai/config.yaml)拿 user config 写票。
层 3 — 手动 teamai recall 偏离全局 scope 约定
src/recall.ts:196-251
- 其它命令统一用 "project 覆盖 user"(
projectConfig ?? (await requireInit()).localConfig,见 env-commands.ts / members.ts / contribute.ts / digest.ts 及 autoDetectInit)。
- 唯独
recall 同时搜 user + project 再合并,且去重按 filename user 先入为主(recall.ts:242-251)。当 user 与 project 指向同一团队 repo(最常见用法)时,文件名完全重叠 → 所有结果都被标成 [user]、路径指向 ~/.teamai/learnings/,project 永远轮不到。
建议修复方向
pull:对 project scope 也构建索引,显式传 indexPath = path.join(getTeamaiHome('project', projectRoot), 'search-index.json')。
auto-recall:先 detectProjectConfig(),据此选择索引路径(project 优先),votes 同理。
recall.ts:与全局保持一致,改为 "project 优先",或至少让 project 在去重中优先。
概述
project-scoped 安装下,recall / auto-recall 的 scope 隔离没有真正生效:搜索(尤其是自动触发的 recall)返回的数据实质上来自 user scope (
~/.teamai),而不是当前项目 scope。根因是 learnings 同步/索引构建以及索引读取路径被写死/默认到了 user 位置。复现
teamai pull(<projectRoot>/.teamai/config.yaml中scope: project)。teamai recall <query>。期望: project scope 下应检索项目 scope 的 learnings,结果应标记/来自 project。
实际: 结果全部来自 user scope(
[user],File:指向~/.teamai/learnings/);自动 recall 完全不看 project。三层根因
层 1 —
teamai pull根本不为 project scope 建索引src/pull.ts:517localConfig.scope === 'user'门控,project scope 的pullForScope直接跳过。buildIndex(...)未传indexPath,内部 fallback 到getSearchIndexPath()=~/.teamai/search-index.json(src/utils/search-index.ts:251与:13)。<projectRoot>/.teamai/search-index.json与<projectRoot>/.teamai/learnings/永远不会被 pull 创建。层 2 — 自动 recall(PostToolUse hook)永远读 user 索引
src/auto-recall.ts:528loadIndex()不传路径,无论是否在 project scope,永远只读 user 索引。src/auto-recall.ts:589)用requireInit()(永远读~/.teamai/config.yaml)拿 user config 写票。层 3 — 手动
teamai recall偏离全局 scope 约定src/recall.ts:196-251projectConfig ?? (await requireInit()).localConfig,见env-commands.ts/members.ts/contribute.ts/digest.ts及autoDetectInit)。recall同时搜 user + project 再合并,且去重按 filename user 先入为主(recall.ts:242-251)。当 user 与 project 指向同一团队 repo(最常见用法)时,文件名完全重叠 → 所有结果都被标成[user]、路径指向~/.teamai/learnings/,project 永远轮不到。建议修复方向
pull:对 project scope 也构建索引,显式传indexPath = path.join(getTeamaiHome('project', projectRoot), 'search-index.json')。auto-recall:先detectProjectConfig(),据此选择索引路径(project 优先),votes 同理。recall.ts:与全局保持一致,改为 "project 优先",或至少让 project 在去重中优先。