@fanchao8609/agent_brain_sync 1.23.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/abs.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // bin/abs.js — abs CLI 入口。
3
3
  // abs <cmd> [args]
4
4
  // 命令: init / board / status / load / task / install / uninstall / help
5
- import { cmdInit, cmdStatus, cmdLoad, cmdTask, cmdLog, cmdQuery, cmdLint, cmdNote, cmdConcept, cmdShow, cmdRepair, cmdWrapup, cmdRule, cmdTeardownCheck, cmdTodoArchive, cmdResolve, cmdSupersede, cmdReview } from '../src/store.js';
5
+ import { cmdInit, cmdStatus, cmdLoad, cmdRecall, cmdTask, cmdLog, cmdQuery, cmdLint, cmdNote, cmdConcept, cmdShow, cmdRepair, cmdWrapup, cmdRule, cmdTeardownCheck, cmdTodoArchive, cmdResolve, cmdSupersede, cmdReview } from '../src/store.js';
6
6
  import { cmdDbRebuild, cmdDbSearch, cmdDbStatus, cmdDbEvolve, addProject } from '../src/brain/db-cmd.js';
7
7
  import { cmdCapture } from '../src/brain/capture.js';
8
8
  import { cmdSummon } from '../src/brain/summon-cmd.js';
@@ -135,6 +135,8 @@ const FLAG_SPEC = {
135
135
  'by': { type: 'string' },
136
136
  'all': { type: 'boolean' },
137
137
  'keep-days': { type: 'string' },
138
+ // db evolve 用:多少天没动且无人链算 stale。未声明会被静默吞成 true(同 keep-days 坑)。
139
+ 'stale-days': { type: 'string' },
138
140
  'help': { type: 'boolean' },
139
141
  'dry-run': { type: 'boolean' },
140
142
  'full': { type: 'boolean' },
@@ -145,7 +147,7 @@ const FLAG_SPEC = {
145
147
  };
146
148
 
147
149
  /** 已被"规范键"接管的 raw flag:不再原样漏出(见 parseArgv 返回处的白名单注释)。 */
148
- const KNOWN_RAW = new Set(['keep-days', 'dry-run', 'no-mcp', 'no-skill']);
150
+ const KNOWN_RAW = new Set(['keep-days', 'stale-days', 'dry-run', 'no-mcp', 'no-skill']);
149
151
 
150
152
  function parseArgv(args) {
151
153
  // 坑: parseArgs 会把**任何** `-` 开头的 token 当选项,连正文一起吃:
@@ -220,6 +222,7 @@ function parseArgv(args) {
220
222
  repair: !!values.repair,
221
223
  full: !!values.full,
222
224
  keepDays: values['keep-days'],
225
+ staleDays: values['stale-days'],
223
226
  dryRun: !!values['dry-run'],
224
227
  mcp: !values['no-mcp'],
225
228
  skill: !values['no-skill'],
@@ -239,6 +242,7 @@ const usage = `abs — 跨会话记忆工具(.brain/ 图谱)
239
242
  abs todo add X --note "做什么" 登记任务 (done/state/note 管后续)
240
243
  abs note "经验一句话" 随手记经验; abs log "完成 X" 记成果
241
244
  abs query <词…> 检索 .brain/; abs todo 看任务板
245
+ abs recall [词…] 卡住时主动取相关页(不给词就按当前处境推)
242
246
 
243
247
  全部命令 (细节: abs <命令> --help):
244
248
  init [--repair] 建图谱 (当前目录)
@@ -363,6 +367,18 @@ const subUsage = {
363
367
  '参数:',
364
368
  ' --all 连 superseded(已失效)页一起返回',
365
369
  ].join('\n'),
370
+ recall: [
371
+ 'abs recall — 卡住时主动取相关页(不需先想到检索词)',
372
+ '',
373
+ '用法:',
374
+ ' abs recall [词1 词2 …] [--limit N]',
375
+ '',
376
+ '不给词时,从当前处境推:活跃 todo 的关键词 + 最近改过的文件名。',
377
+ '给了词就只用你给的词,不混处境词。',
378
+ '',
379
+ '与 load 的区别: load 只在开工跑一次;recall 随时可跑(卡住/换方向时)。',
380
+ '与 query 的区别: query 枚全图命中;recall 只给按亮度亮的几页。',
381
+ ].join('\n'),
366
382
  config: [
367
383
  'abs config — 使用者姓名(写操作的作者标记)',
368
384
  '',
@@ -457,6 +473,11 @@ async function main() {
457
473
  rejectExtra(opts._, 'abs load');
458
474
  console.log(await cmdLoad({ dir: opts.dir }));
459
475
  break;
476
+ case 'recall': {
477
+ const limit = Number(opts.limit) > 0 ? Number(opts.limit) : 5;
478
+ console.log(await cmdRecall({ dir: opts.dir, terms: opts._, limit }));
479
+ break;
480
+ }
460
481
  case 'index':
461
482
  rejectExtra(opts._, 'abs index');
462
483
  console.log(await cmdShow({ dir: opts.dir, view: 'index' }));
@@ -582,7 +603,7 @@ async function main() {
582
603
  if (sub === 'rebuild') { console.log(await cmdDbRebuild({ dir: opts.dir })); break; }
583
604
  if (sub === 'search') { console.log(await cmdDbSearch({ query: rest.join(' '), limit: Number(opts.limit) || 8, full: !!opts.full })); break; }
584
605
  if (sub === 'status') { console.log(await cmdDbStatus()); break; }
585
- if (sub === 'evolve') { console.log(await cmdDbEvolve({ staleDays: Number(opts['stale-days']) || 90 })); break; }
606
+ if (sub === 'evolve') { console.log(await cmdDbEvolve({ staleDays: Number(opts.staleDays) || 90 })); break; }
586
607
  if (sub === 'add') {
587
608
  const r = await addProject(opts.dir || process.cwd());
588
609
  console.log(`✓ 已登记项目: ${r}\n 建库: abs db rebuild`);
package/bin/mcp.js CHANGED
@@ -11,7 +11,7 @@ import { appendFile, mkdir } from 'node:fs/promises';
11
11
  import { readFileSync } from 'node:fs';
12
12
  import { join, dirname } from 'node:path';
13
13
  import { fileURLToPath } from 'node:url';
14
- import { findBrainRoot, absLogDir } from '../src/index.js';
14
+ import { findBrainRoot, absLogDir, AbsError } from '../src/index.js';
15
15
  import { cmdBoard, cmdLoad, cmdStatus, cmdTask, cmdQuery, cmdLint, cmdNote, cmdConcept, cmdWrapup, cmdRule, cmdResolve, cmdSupersede } from '../src/store.js';
16
16
 
17
17
  // ---------- 技术日志: MCP 请求跟踪(调试用, 与图谱 log.md 完全分开) ----------
@@ -40,6 +40,12 @@ function withTrace(name, handler) {
40
40
  return r;
41
41
  } catch (e) {
42
42
  await tlog(`tool=${name} cwd=${args?.cwd || '-'} args=${argBrief} → THROW ${Date.now() - t0}ms | ${String(e?.message || e).slice(0, 200)}`);
43
+ // 带 code 的 AbsError(如 requireUser 的 NO_USER)必须走 err() 结构化返回,
44
+ // 保留 code + fallback 自救指引 —— 裸 rethrow 只带 message,LLM 拿到后
45
+ // 不知道下一步跑什么(与 CLI 侧 `[CODE] + → fallback` 的既有行为不一致)。
46
+ if (e instanceof AbsError) {
47
+ return err(e.message, { code: e.code, fallback: e.fallback || undefined });
48
+ }
43
49
  throw e;
44
50
  }
45
51
  };
package/hooks/abs.pi.ts CHANGED
@@ -231,6 +231,10 @@ const TODO_GUIDELINES = [
231
231
  // ⑦ 文档精简九条(用户 2026-10-22 定,原文见 skill 的「文档精简」一节):
232
232
  // 管每一行写进 .brain 的文字;与上面六条行为规则不重叠,故不合并。
233
233
  'Every line you write into .brain/ (todo rows, log rows, knowledge pages, session snapshots) must pass the nine-bullet doc-slimming rule in the abs skill: only what serves the topic (drop the rest), no unverified summaries, ordered and layered, plain declarative wording (no rhetorical questions, no guessing), no duplication (cite the other doc instead), terse prohibitions, nothing the user did not ask for, plain Chinese.',
234
+ // ⑧ 有疑惑先查记忆(用户 2026-11-03 定):主动搜索不是等报错才应激,
235
+ // 而是「心里形成关键词/有疑问的那一刻」自己查。上面七条只讲了登记,
236
+ // 没讲「记下来的东西怎么取」——实测一场会话从头到尾没查过一次记忆。
237
+ 'When a doubt forms about something the project has likely dealt with before (a design choice, a past bug, a convention), run `abs recall <关键词>` (or `abs query <词>` for wider matches) BEFORE acting on the assumption. Do not wait for an error or for the user to remind you — asking the memory is your own decision, made the moment the question arises.',
234
238
  ]
235
239
 
236
240
  /** 当前项目是否有 .brain 图谱 —— 有才加指引(没图谱的项目里这指引是噪音)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fanchao8609/agent_brain_sync",
3
- "version": "1.23.0",
3
+ "version": "1.24.0",
4
4
  "description": "agent-brain-sync: 跨会话 AI 编码记忆 — hook 纯触发 + CLI/MCP 读写 .brain markdown 图谱, 防并发写保护。",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -5,6 +5,23 @@ description: "USE FOR abs / agent-brain-sync 跨会话记忆与任务续接。
5
5
 
6
6
  # abs — 跨会话记忆 (agent-brain-sync)
7
7
 
8
+ ## 你有知识库,随时都能查
9
+
10
+ `.brain/` 是**你自己的跨会话记忆库**:踩过的坑、做过的决定、验证过的做法都在里面。
11
+
12
+ **查它是你的决定,不是别人提醒你才做。** 干活中一旦心里形成关键词、对某件事有疑问(这个坑以前踩过吗?这个约定是谁定的?),那一刻就主动查,**不要等报错、不要等用户提醒、不要等开工那一秒**。
13
+
14
+ 怎么查:
15
+
16
+ ```bash
17
+ abs recall <关键词> # 有疑问时用:按亮度出最相关的几页(不给词就从当前处境推)
18
+ ab query <词> # 想拿更全:多词 OR,枚举全图命中
19
+ db search <词> # 更高级:种子扩散亮起相关页,先出铁律
20
+ abs resolve <页名> # 拿到页名后反查路径,只读那一页
21
+ ```
22
+
23
+ 查完只读命中那几页,**绝不通读 `.brain/`**。答用 `[[页面名]]` 标来源。
24
+
8
25
  ## 触发器
9
26
 
10
27
  **关键词不是触发器,意图才是。**句子里出现 todo / 沉淀 / load / note 这些词,若是谈论、提问、定规则,只回应不执行。
@@ -54,7 +54,21 @@ export function uniqueProjectNames(roots) {
54
54
  for (const [r, v] of cand) out.set(r, v);
55
55
  break;
56
56
  }
57
- if (depth === 4) for (const [r, v] of cand) out.set(r, v); // 兜底:认了
57
+ if (depth === 4) {
58
+ // 深度到 4 仍重名(如 ~/a/x/软件/.agents 与 ~/b/y/软件/.agents 共享 4 层尾路径):
59
+ // 不能「认了」直接塞 —— 那会让两个项目拿到同一个项目名,rebuild 撞
60
+ // UNIQUE(project,dir,slug) 约束整体崩溃(正是本函数要避免的场景)。
61
+ // 给仍碰撞的条目追加序号(-2/-3…),保证互不重名且可读。
62
+ const byVal = new Map();
63
+ for (const [r, v] of cand) {
64
+ if (!byVal.has(v)) { byVal.set(v, []); }
65
+ byVal.get(v).push(r);
66
+ }
67
+ for (const [v, rs] of byVal) {
68
+ if (rs.length === 1) { out.set(rs[0], v); continue; }
69
+ rs.forEach((r, i) => out.set(r, `${v}-${i + 2}`));
70
+ }
71
+ }
58
72
  }
59
73
  }
60
74
  return out;
package/src/brain/load.js CHANGED
@@ -322,6 +322,107 @@ async function queryHintSection(root, todo) {
322
322
  return queryHint(root, todo);
323
323
  }
324
324
 
325
+ /**
326
+ * recall:卡住时主动取「跟当前处境相关的几页」,不需要先想到检索词。
327
+ *
328
+ * 为何要它(2026-11-03 实测):hotPages 只挂在 load 上,于是只有开工那一刻会送页。
329
+ * 实测一场完整会话从头到尾没调过一次 abs —— 不是检索不准(命中确实准),
330
+ * 而是「要人先想到发起查询」这一步天然被跳过。一个出口只开一次,就等于没开。
331
+ *
332
+ * 与 hotPages 的分工:hotPages 是开机首屏(自动、固定 3 页);
333
+ * recall 是随时可调(agent 卡住/换方向时自己跑),且能补词。
334
+ * 两者共用 contextKeywords + 亮度搜索,不各算一套。
335
+ *
336
+ * 词从哪来:
337
+ * - 传了词 → 用它(这时它就是个带上下文的搜索,仍会补处境词)
338
+ * - 没传词 → 纯靠处境(活跃 todo 的关键词 + 最近改过的文件)
339
+ * 全部凭空无词 → 说清楚缺什么,不返回空列表充数。
340
+ *
341
+ * @param {{dir?:string, terms?:string[], limit?:number}} opts
342
+ */
343
+ export async function cmdRecall({ dir, terms, limit = 5 } = {}) {
344
+ const given = (terms || []).flatMap((t) => String(t).trim().split(/\s+/)).filter(Boolean);
345
+ let root;
346
+ try {
347
+ root = await requireBrain(dir || process.cwd());
348
+ } catch {
349
+ return '未找到 .brain/ 图谱(无记忆可查)。先在项目根运行: abs init';
350
+ }
351
+ const todo = await readTodo(root).catch(() => '');
352
+ let kws = [];
353
+ let files = [];
354
+ try {
355
+ ({ kws, files } = await contextKeywords(root, todo));
356
+ } catch {
357
+ // 拔词失败不该拦住整个 recall
358
+ }
359
+ // 手动传的词优先级最高:用户/agent 已经想清楚要什么,就别把处境词混进去稀释
360
+ const words = given.length ? given : kws.slice(0, 5);
361
+ if (!words.length) {
362
+ return 'recall: 无从判断当前处境(todo 空、近期无改动、也没给词)。\n'
363
+ + '→ 直接给词: abs recall <词1> <词2>;或先 abs todo add 把在干的事登记上。';
364
+ }
365
+ try {
366
+ const { openDb, search, illuminate, dbPath } = await import('./db.js');
367
+ const { promises: fsp } = await import('node:fs');
368
+ const exists = await fsp.stat(dbPath()).then(() => true).catch(() => false);
369
+ if (!exists) return 'recall: 图数据库还没建(亮度检索需要它)。先跑: abs db rebuild';
370
+
371
+ const project = String(root).split('/').filter(Boolean).pop() || '';
372
+ const h = openDb(dbPath());
373
+ let lit;
374
+ try {
375
+ const seeds = new Map();
376
+ // 整串先查(实测:`db search "并发 锁"` 能出 file-write-locking,
377
+ // 而逐词分开查的种子表里根本没它 —— 2-gram 索引对整串和单词的切法不同,
378
+ // 拆开就把最有用的命中拆没了。所以整串优先,再用逐词兜底补漏。
379
+ const whole = given.length ? words.join(' ') : words.join(' ');
380
+ for (const s of search(h, whole, { limit: 12 })) seeds.set(s.id, s);
381
+ for (const w of words) {
382
+ for (const s of search(h, w, { limit: 6 })) {
383
+ const prev = seeds.get(s.id);
384
+ if (!prev || s.bright > prev.bright) seeds.set(s.id, s);
385
+ }
386
+ }
387
+ if (!seeds.size) {
388
+ return `recall [${words.join(', ')}]: 库里没搜到相关页。\n`
389
+ + '→ 换个说法: abs recall <别的词>;看图谱全貌: abs query <词>。';
390
+ }
391
+ // 流水页降权(2026-11-03 实测):不加时前 5 位里挤进 2 页 sessions/log-*,
392
+ // 还被排到第一,把 file-write-locking 这种真经验页顶下去。
393
+ // 与 query 用同一套判据(lint.js 的 isTerminal),不另造。只降权不剔除。
394
+ const isFlow = (r) => r.dir === 'sources' || (r.dir === 'sessions' && /^log-/.test(r.slug));
395
+ lit = illuminate(h, [...seeds.values()], { limit: limit * 8 })
396
+ .filter((r) => r.project === project)
397
+ .sort((a, b) => (b.bright - (isFlow(b) ? 1 : 0)) - (a.bright - (isFlow(a) ? 1 : 0)))
398
+ .slice(0, limit);
399
+ } finally {
400
+ h.close();
401
+ }
402
+ if (!lit.length) {
403
+ return `recall [${words.join(', ')}]: 搜到了种子,但本项目的页没有亮起来。\n`
404
+ + '→ 试试 abs query <词> 看全图命中。';
405
+ }
406
+ const rows = [`recall [${words.join(', ')}] → ${lit.length} 页(按亮度;看全文: abs resolve <页名>)`];
407
+ if (!given.length) {
408
+ const why = [
409
+ files.length ? `近期改动 ${files.length} 个文件` : '',
410
+ todo ? '活跃 todo' : '',
411
+ ].filter(Boolean).join(' + ');
412
+ if (why) rows.push(` 处境: ${why}`);
413
+ }
414
+ rows.push('');
415
+ for (const r of lit) {
416
+ const one = await fsp.readFile(brainPath(root, r.dir, `${r.slug}.md`), 'utf8').catch(() => '');
417
+ const about = one ? digest(one, 80) : '';
418
+ rows.push(` ${r.bright.toFixed(2)} L${r.layer} [[${r.slug}]]${about ? ' — ' + about : ''}`);
419
+ }
420
+ return rows.join('\n');
421
+ } catch (e) {
422
+ return `recall 失败: ${e instanceof Error ? e.message : String(e)}`;
423
+ }
424
+ }
425
+
325
426
  /** sources 堆积提醒:返回 [标题行, ...内容行] 或 null。失败静默。 */
326
427
  async function sourcesCountSection(root) {
327
428
  const nsrc = await countSources(root);
@@ -57,38 +57,45 @@ export async function cmdTodoArchive({ dir, keepDays = 3, dryRun = false } = {})
57
57
  return `[dry-run] 将归档 ${plan.archived.length} 天 / ${plan.count} 条(每天一个文件)\n ${brief}${why}`;
58
58
  }
59
59
 
60
- // 1) 归档目标 = 当天的会话快照文件(log-<日期>.md),写进其「任务归档」段。
60
+ // 1) todo.md:锁内重算(拿最新内容,避免与并发 done 互相覆盖),
61
+ // todo 是权威 —— 会话页/ index 都跟随它,不反向。
62
+ // 先写 todo 再写会话页:todo 写失败(闸门拒绝/SKIP)时会话页不写,
63
+ // 避免「会话页已写、看板没动」的两边不一致(原顺序相反,且会话页裸写绕过锁)。
64
+ let archivedFinal = [];
65
+ await editFile(todoP, (cur) => {
66
+ // 坑(2026-10-05 实测抓到): 这里漏传 maxLines → 锁内重算的 archived 为空 →
67
+ // 返回 SKIP → 磁盘上的 todo.md 一个字没动(而 sessions/ 归档页已经写了,
68
+ // 两边不一致)。**同参数的每个调用点都要一起改**。
69
+ const p2 = archiveDoneInText(cur ?? '', { keepDays: days, from: today(), maxLines: TODO_MAX_LINES });
70
+ if (!p2.archived.length) return SKIP;
71
+ archivedFinal = p2.archived; // 锁内算出的权威清单,后续写会话页/index 用它
72
+ return { text: p2.text };
73
+ });
74
+ if (!archivedFinal.length) {
75
+ return `(todo 锁内重算无归档项,已跳过)${why}`;
76
+ }
77
+
78
+ // 2) 归档目标 = 当天的会话快照文件(log-<日期>.md),写进其「任务归档」段。
61
79
  // 为何合一(2026-09-15 用户定): 归档与会话快照是**同一天的记录**,分两个文件查着要开两处。
62
80
  // 边界: ① 文件不存在→建只有归档段的页(那天可能没写快照)
63
81
  // ② 文件已存在(含 AI 手写快照)→ 只替换归档段,段外逐字保留
64
82
  // (硬规则「已存在的人工内容一律不覆盖」由 upsertArchiveSection 保证)。
83
+ // 走 editFile 锁(2026-11-03 审查修复):append 语义必须与 setMemo 同一路数,
84
+ // 裸 readFile+tmp+rename 会让并发 archive 互相覆盖,丢一批归档任务行。
65
85
  const sessDir = brainPath(root, 'sessions');
66
- for (const g of plan.archived) {
86
+ await fs.mkdir(sessDir, { recursive: true });
87
+ for (const g of archivedFinal) {
67
88
  const pageP = join(sessDir, `${g.slug}.md`);
68
- let page = null;
69
- try { page = await fs.readFile(pageP, 'utf8'); } catch { /* 首次 */ }
70
- const nextPage = upsertArchiveSection(page, g);
71
- const tmp = join(sessDir, `.${g.slug}.tmp-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`);
72
- await fs.writeFile(tmp, nextPage, 'utf8');
73
- await fs.rename(tmp, pageP);
89
+ await editFile(pageP, (cur) => ({ text: upsertArchiveSection(cur, g) }));
74
90
  }
75
91
 
76
- // 2) todo.md:锁内重算(拿最新内容,避免与并发 done 互相覆盖)
77
- await editFile(todoP, (cur) => {
78
- // 坑(2026-10-05 实测抓到): 这里漏传 maxLines → 锁内重算的 archived 为空 →
79
- // 返回 SKIP → 磁盘上的 todo.md 一个字没动(而 sessions/ 归档页已经写了,
80
- // 两边不一致:"说归档了但看板没变")。**同参数的每个调用点都要一起改**。
81
- const p2 = archiveDoneInText(cur ?? '', { keepDays: days, from: today(), maxLines: TODO_MAX_LINES });
82
- return p2.archived.length ? { text: p2.text } : SKIP;
83
- });
84
-
85
92
  // 3) index 登记(每个日期页一行,幂等)
86
93
  // 坑(2026-09-15 修): 原先把归档页登记到 `## Sources` 区 —— 但它们在 sessions/ 里,
87
94
  // 旧数据实测就是错位的(09-10/09-12 两条曾键在 Sources 段,人工才发现)。现改登 `## Sessions`。
88
95
  const iP = brainPath(root, 'index.md');
89
96
  await editFile(iP, (index) => {
90
97
  if (!index) return SKIP;
91
- const missing = plan.archived.filter((g) => !index.includes(`[[${g.slug}]]`));
98
+ const missing = archivedFinal.filter((g) => !index.includes(`[[${g.slug}]]`));
92
99
  if (!missing.length) return SKIP;
93
100
  const sIdx = index.indexOf('## Sessions');
94
101
  if (sIdx === -1) return SKIP;
@@ -100,8 +107,10 @@ export async function cmdTodoArchive({ dir, keepDays = 3, dryRun = false } = {})
100
107
  return { text: next };
101
108
  });
102
109
 
103
- const files = plan.archived.map((g) => `sessions/${g.slug}.md`).join('\n ');
104
- return `✓ 已归档 ${plan.archived.length} 天 / ${plan.count} 条\n ${brief}\n → ${files}${why}`;
110
+ const files = archivedFinal.map((g) => `sessions/${g.slug}.md`).join('\n ');
111
+ const count = archivedFinal.reduce((n, g) => n + g.count, 0);
112
+ const briefFinal = archivedFinal.map((g) => `${g.date}(${g.count})`).join(' ');
113
+ return `✓ 已归档 ${archivedFinal.length} 天 / ${count} 条\n ${briefFinal}\n → ${files}${why}`;
105
114
  }
106
115
 
107
116
  /**
package/src/query.js CHANGED
@@ -53,7 +53,7 @@ export async function cmdQuery({ dir, terms, includeSuperseded }) {
53
53
  continue;
54
54
  }
55
55
  hits.push({
56
- full, slug, matched: rank.matched, kind: rank.kind, fuzzyScore: rank.score, via: rank.via,
56
+ full, slug, dir: d, matched: rank.matched, kind: rank.kind, fuzzyScore: rank.score, via: rank.via,
57
57
  author: au ? au[1].trim() : '',
58
58
  id: idOfPage(body, slug),
59
59
  status: st,
@@ -68,11 +68,18 @@ export async function cmdQuery({ dir, terms, includeSuperseded }) {
68
68
  // 坑(2026-09-16 实测): 不加区分时查 file-write-locking 返回 26 页(几乎全图)——
69
69
  // 连字符词的 2-gram 太通用,模糊命中把无关页也拉进来。
70
70
  // 规则:只要有任何精确命中,模糊命中的就不排在前面(但也不丢弃,单列一段)。
71
+ // 流水页降权(2026-11-02 实测):查「并发 写 锁」时前 10 位里挤进 4 页
72
+ // sessions/log-*,内容页被顶下去。流水页只是「那天做了什么」的草稿记录,
73
+ // 正文里碰巧出现检索词不代表它是这条经验所在。判据沿用 lint.js 的
74
+ // isTerminal(sources/ 与 sessions/log-*),不另造一套。
75
+ // 只降权不剔除:真要查某天的流水,它仍在结果里,只是排到内容页之后。
76
+ const isFlow = (h) => h.dir === 'sources' || (h.dir === 'sessions' && /^log-/.test(h.slug));
77
+ const rankBy = (h) => h.fuzzyScore - (isFlow(h) ? 20 : 0);
71
78
  const exactHits = hits.filter((h) => !h.hidden && h.kind === 'exact')
72
- .map((h) => ({ ...h, score: h.fuzzyScore }))
79
+ .map((h) => ({ ...h, score: rankBy(h) }))
73
80
  .sort((a, b) => b.score - a.score);
74
81
  const fuzzyHits = hits.filter((h) => !h.hidden && h.kind === 'fuzzy')
75
- .map((h) => ({ ...h, score: h.fuzzyScore }))
82
+ .map((h) => ({ ...h, score: rankBy(h) }))
76
83
  .sort((a, b) => b.score - a.score);
77
84
  // 有精确命中 → 模糊全藏起来(但不静默:告知数量 + 怎么看)
78
85
  const fuzzySuppressed = exactHits.length > 0 && fuzzyHits.length > 0;
package/src/store.js CHANGED
@@ -19,7 +19,7 @@ export { BRAIN_SHAPE, LEGACY_MARKS, checkBrainShape } from './brain/shape.js';
19
19
  import './brain/gate.js';
20
20
 
21
21
  // ---- 只读呈现 ----
22
- export { cmdBoard, cmdStatus, cmdLoad, cmdShow, extractBlocks } from './brain/load.js';
22
+ export { cmdBoard, cmdStatus, cmdLoad, cmdShow, cmdRecall, extractBlocks } from './brain/load.js';
23
23
 
24
24
  // ---- Rules ----
25
25
  export { RULES_HEADING, RULES_MAX, RULE_BODY_MAX, readRules, cmdRule } from './brain/rules.js';