dsh-reference-session-collector 0.1.0 → 0.2.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/dsh.plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "dsh-reference-session-collector",
3
3
  "name": "dsh-reference-session-collector",
4
- "version": "0.1.0",
4
+ "version": "0.2.0-beta.0",
5
5
  "description": {
6
6
  "en": "Session reference projector (DRS): read-only scan of ~/.dsh/sessions logs, decoded into a private SQLite (segments/replaces/FTS5) with surface flags, recall-pair accounting and a Chinese-capable search face, served via /api/dsh-reference-session-collector. Never writes session files.",
7
7
  "zh": "会话原文投影同步器(DRS):只读扫描 ~/.dsh/sessions 会话日志,解码后投影进自有 SQLite(segments/replaces/FTS5),经 /api/dsh-reference-session-collector 提供 surface 标记、召回对账与中文可用的内容检索面。绝不写会话文件。"
package/lib/index.d.ts CHANGED
@@ -229,12 +229,14 @@ declare function projectSessionEvents(events: readonly DecodedEvent[], options:
229
229
  //#region src/schema.d.ts
230
230
  /** schema 版本(meta 表;断裂式迁移的比对基线)。
231
231
  * v2=加 sessions.format_generation;
232
- * v3=search_text 视界变更(剥离宿主注入样板段,strip-injected horizon v2);
233
- * v4=账目双修(真机取证 2026-10-20):① text/tokens 视界补 data.content 双臂
234
- * (checkpoint 替身/用户消息旧视界全计 0);② replaces 加 live 列——替身行
235
- * 被后续区间再覆盖时 delta 清除不入 gross(用户定标:checkpoint 只影响其后
236
- * 的积分)。旧行两项口径均错,整库清空重建(投影可重建,丢行无损)。 */
237
- declare const PROJECTION_SCHEMA_VERSION = "4";
232
+ * v3=search_text 视界变更(剥离宿主注入样板段);
233
+ * v4=账目双修(data.content 双臂 + replaces.live);
234
+ * v5=字块共享 + 脱敏派生臂(2026-10-20 用户定标):text/search_text/
235
+ * surface_text 实列退役→blocks 字典 hash 引用(surface 经 replaced_by
236
+ * 链派生);新 redacted_text_hash/redacted_search_text_hash(redactSecrets
237
+ * 派生臂,CCI 口径 text 的 token 数学不动);旧库列形状断裂→DROP 重建
238
+ * + VACUUM(投影可重建,丢行无损)。 */
239
+ declare const PROJECTION_SCHEMA_VERSION = "5";
238
240
  /** sessions 表原始行(snake_case 与 DDL 一致)。 */
239
241
  interface SessionRow {
240
242
  session_id: string;
@@ -322,15 +324,23 @@ declare function listSessions(ctx: QueryContext, offset?: number, limit?: number
322
324
  total: number;
323
325
  rows: SessionRow[];
324
326
  };
325
- /**
326
- * segments 明细。
327
- * @param turn - `turn=` 区间过滤(`a-b` 闭区间或单值)。
328
- * @param fields - `'search'` 返检索面字段(time/search_text/on_surface)。
329
- */
330
- declare function sessionDetail(ctx: QueryContext, sessionId: string, opts?: {
327
+ /** sessionDetail 选项(turn 区间 / fields 检索臂 / tail 尾窗 / redact 脱敏臂)。 */
328
+ interface SessionDetailOptions {
331
329
  turn?: string;
332
330
  fields?: string;
333
- }): {
331
+ /** R4 尾窗:正整数=会话尾 N 段(过滤后),升序返回;非法/缺省=全量。 */
332
+ tail?: number;
333
+ /** R3:true=切 redacted 列(含派生 surface_text 用链头 redacted 正文)。 */
334
+ redact?: boolean;
335
+ }
336
+ /**
337
+ * segments 明细(v4 逐字段同形还原)。
338
+ * @param opts.turn - `turn=` 区间过滤(`a-b` 闭区间或单值)。
339
+ * @param opts.fields - `'search'` 返检索面字段(time/search_text/on_surface)。
340
+ * @param opts.tail - 尾窗 N:先取 seq 降序 N 行再翻升序(与会话文件真实尾部对拍)。
341
+ * @param opts.redact - 脱敏臂:text/search_text/surface_text 取 redacted_* 列。
342
+ */
343
+ declare function sessionDetail(ctx: QueryContext, sessionId: string, opts?: SessionDetailOptions): {
334
344
  session: SessionRow | undefined;
335
345
  rows: unknown[];
336
346
  };
@@ -341,10 +351,15 @@ declare function surfaceLedger(ctx: QueryContext, sessionId: string): Record<str
341
351
  * 毛节省只计 live=1 的对——替身被后续 checkpoint 再覆盖时 delta 清除(用户定标)。
342
352
  */
343
353
  declare function recallReport(ctx: QueryContext, sessionId: string): Record<string, unknown>;
344
- /** FTS5 BM25 内容搜索(中英同构切词,走 sanitizeFtsQuery)。 */
354
+ /**
355
+ * FTS5 BM25 内容搜索(中英同构切词,走 sanitizeFtsQuery)。
356
+ * v5:fts 仍索引原文(R3);snippet 经 blocks 还原,`redact` 只切 snippet
357
+ * 取材列(redacted_search_text_hash),命中/排序语义两臂一致。
358
+ */
345
359
  declare function search(ctx: QueryContext, query: string, opts?: {
346
360
  session?: string;
347
361
  limit?: number;
362
+ redact?: boolean;
348
363
  }): {
349
364
  query: string;
350
365
  match: string;
@@ -371,6 +386,14 @@ interface GroupedSearchRequest {
371
386
  /** 排序:缺省 relevance;'time'=会话 updated_at 降序、分数平手。 */
372
387
  sortBy?: 'relevance' | 'time';
373
388
  limit?: number;
389
+ /** R3:true=snippet 取材切 redacted_search_text(命中/排序不变,fts 仍原文)。 */
390
+ redact?: boolean;
391
+ /**
392
+ * 命中展开(steward「分开显示」开关,wire `expand=1`):true=每条候选行
393
+ * 各自成命中(同会话多行按全局分数序出现);缺省 false=会话分组各取
394
+ * 最强命中(既有聚合臂行为零改动,limit 语义随之从会话数变行数)。
395
+ */
396
+ expand?: boolean;
374
397
  }
375
398
  /** 分组命中(wire 蛇形,会话级最强命中)。 */
376
399
  interface GroupedSearchHit {
@@ -386,6 +409,7 @@ interface GroupedSearchHit {
386
409
  * 会话分组全文搜索(op=search&group=session):BM25 候选窗 → 按会话取
387
410
  * 加权最强命中 → 排序分页。数学/视界与 steward engine.search 逐字同构:
388
411
  * score = −rank × weight(type),时间排序键是会话 updated_at(非命中 time)。
412
+ * snippet 锚定文本经 blocks 还原(redact 臂切 redacted_search_text_hash)。
389
413
  */
390
414
  declare function searchGrouped(ctx: QueryContext, request: GroupedSearchRequest): {
391
415
  query: string;
@@ -532,7 +556,7 @@ interface SyncReplaceMeta {
532
556
  }
533
557
  /**
534
558
  * 投影库端口。真身 = schema.ts 的 ProjectionStore(L1);单测注入内存 mock。
535
- * 五个方法恰好是 sync 需要的全部写/读面——真身实现不得要求更多。
559
+ * 七个方法恰好是 sync 需要的全部写/读面——真身实现不得要求更多。
536
560
  */
537
561
  interface SyncStorePort {
538
562
  /** 目录水位预查(stat 命中免解码的关键);无记录返回 undefined。 */
@@ -548,6 +572,17 @@ interface SyncStorePort {
548
572
  }[];
549
573
  /** 级联清除一个会话的投影(WAL 事务内 segments/fts/replaces/sessions 四表+常驻 Map)。 */
550
574
  deleteSession(sessionId: string): void;
575
+ /**
576
+ * R5(v5 字块字典水位):current=blocks 现 max(rowid, 空典=0),
577
+ * last=上轮持久化值(meta 缺失=0)。current<last=字典被清/换——
578
+ * hash 引用悬空,stat 命中也不得 skip(防静默缺块)。
579
+ */
580
+ blocksWatermark(): {
581
+ current: number;
582
+ last: number;
583
+ };
584
+ /** 轮尾持久化本轮字典水位(下轮 skip 判定基线)。 */
585
+ setBlocksWatermark(value: number): void;
551
586
  }
552
587
  type SyncLog = (level: 'info' | 'warn', message: string, ...args: unknown[]) => void;
553
588
  /** DS 精确计数器探测:flash → pro 逐个试;全缺席 undefined(chars/4 降级)。 */