@x1a0f3n9/dsh-session-query 0.1.5-alpha.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ # Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
2
+ # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
+ # after editing either side, bring the other along and re-record with:
4
+ # pnpm run verify-translation-pairing --write packages/session-query/session-query/README.md
5
+ README.md: cbd7379b290397101ab3178e9d742c87a4afab08
6
+ README.zh.md: 02bf708e4e8dc0104f5f031c8b963f29a5675b75
package/README.md ADDED
@@ -0,0 +1,167 @@
1
+ ---
2
+ description: "The unified session-history query service for consumers and backend authors: exact reads, relationship traces, and provider-independent filters over live and durable session logs."
3
+ kind: "package-reference"
4
+ ---
5
+
6
+ # @x1a0f3n9/dsh-session-query
7
+
8
+ English | [中文](README.zh.md)
9
+
10
+ ## Summary
11
+
12
+ `dsh-session-query` lets application code list, filter, read, and search session history, inspect bounded event context, and trace session or event relationships. Reads prefer live sessions over persisted copies and return detached clones from one consistent observation. Exact reads, filters, and traces work with any supported storage setup; ranked full-text search requires a backend such as `dsh-session-query-sqlite`. Use it when application code needs programmatic access to the history presented to the model.
13
+
14
+ ## Table of Contents
15
+
16
+ - [Use this package](#use-this-package)
17
+ - [Understand the implementation](#understand-the-implementation)
18
+ - [Further Exploration](#further-exploration)
19
+ - [Model Experience](#model-experience)
20
+ - [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
21
+ - [Dev Note](#dev-note)
22
+
23
+ -----
24
+
25
+ <a id="use-this-package"></a>
26
+ ## Use this package
27
+
28
+ Use `ctx.sessionQuery` from application code when you need to read or search session history without touching the session service or a storage backend directly. The service is provided by a concrete backend plugin — the shipped composition mounts `@x1a0f3n9/dsh-session-query-sqlite` ([README](../session-query-sqlite/README.md)) — so this package is never mounted alone. Everything below is available on `ctx.sessionQuery` once a backend is composed.
29
+
30
+ ### What you can do
31
+
32
+ | Operation | What you get |
33
+ |---|---|
34
+ | `listSessions()` | Every logical session, newest first, with `live` and `persisted` availability flags |
35
+ | `readSession(id)` | The complete replay-validated raw event log, without making the session live |
36
+ | `filterSessions(filters)` | Sessions matching ANDed metadata and availability predicates |
37
+ | `filterEvents(id, filters)` | Semantic event documents matching metadata and literal-text predicates |
38
+ | `readTitleSnapshots(ids)` | The latest folded title per session, bound to its source header |
39
+ | `listEvents(id)` / `readSurface(id)` | Lightweight per-event records, or the complete current model surface |
40
+ | `readEvent(request)` | One full event plus a bounded raw-log window around it |
41
+ | `traceSession(id)` | The known ancestor chain and recursive descendant trees |
42
+ | `traceEvent(request)` | One event's positional replacements and cited source-event relationships |
43
+ | `searchSessions(request)` / `searchEvents(request)` | Full-text search pages, implemented by the mounted backend |
44
+
45
+ Body-free records expose only `SessionHeader.isSeeded`. Reads that return event bodies (`readSession`, `readSurface`, `readEvent`) and retained `SessionObservation` values also carry the exact `inheritedEventCount`, so callers can distinguish inherited and owned events without inferring a cut from the log.
46
+
47
+ ### Filters
48
+
49
+ `SessionResultFilter` narrows sessions by id, nullable cwd, created-at range, nullable parent, or source availability; `SessionEventResultFilter` narrows events by seq/time range, event type, surface, or literal text. Filter arrays are ANDed and list values within one clause are ORed; empty list values match nothing, ranges are inclusive, and malformed ranges or unknown closed-union values fail with `SESSION_QUERY_INVALID_FILTER`.
50
+
51
+ The text clause is a literal, case-insensitive, whitespace-flexible scan of extracted semantic text — not a full-text query. Use it for arbitrary substring recall; use the mounted backend's search methods when you need ranked full-text results.
52
+
53
+ ### Configuration
54
+
55
+ The inherited knobs are set through the mounted backend's config:
56
+
57
+ | Field | Default | Meaning |
58
+ |---|---|---|
59
+ | `readWindowMax` | `50` | Maximum `before`/`after` raw events accepted by `readEvent` |
60
+ | `persistedReadConcurrency` | `4` | Concurrent persisted-log reads in one batch title read |
61
+ | `preparedSessionCacheSize` | `5` | Cold prepared-Session observations retained for reuse across `observeSession` reads |
62
+
63
+ ### Failures and recovery
64
+
65
+ Failures are typed with a stable `SessionQueryError.code`. The ones you will meet: `SESSION_QUERY_SESSION_NOT_FOUND` when an id is absent; `SESSION_QUERY_SOURCE_CONFLICT` when live and persisted observations of one session disagree on immutable headers; `SESSION_QUERY_PERSISTENCE_FAILED` when mounted persistence is unreadable; `SESSION_QUERY_CORRUPT_SESSION` when a durable record fails Session validation; and `SESSION_QUERY_INVALID_SURFACE` when a loaded log breaks the surface contract. Reads targeting a known live session never consult persistence, so a failing backend cannot make current in-memory history unreadable.
66
+
67
+ -----
68
+
69
+ <a id="understand-the-implementation"></a>
70
+ ## Understand the implementation
71
+
72
+ <details>
73
+ <summary>Implementation internals — click to expand</summary>
74
+
75
+ This section explains the design decisions behind the service and points at the code that realizes them; the observable behavior is fully covered in [Use this package](#use-this-package).
76
+
77
+ ### Design philosophy
78
+
79
+ The service is built on one separation and three commitments:
80
+
81
+ - **Live-preferred logical corpus.** Every read resolves one consistent observation: live `ctx.sessions` wins, optional `ctx.sessionPersistence` fills the rest, and conflicting immutable headers fail rather than merge.
82
+ - **Detached results.** All returned headers, events, and records are cloned; nothing exposes live state or a retained subscription.
83
+ - **Exact reads concrete, search abstract.** Reads, filters, and traces are implemented here once; the two full-text methods are the only abstract surface a backend owns.
84
+ - **One canonical surface fold.** `listEvents`, `readSurface`, and `traceEvent` validate the whole log with the same `dsh-session` fold, so search and traces agree with model-history derivation.
85
+
86
+ The decision history lives in the [unified service decision](../../../.agents/notes/archived/architecture/2026-07-23-unified-session-query-service.md), the [tracing note](../../../.agents/notes/archived/feature/2026-07-13-session-query-tracing.md), and the [SQLite provider note](../../../.agents/notes/archived/feature/2026-07-10-sqlite-session-query-provider.md).
87
+
88
+ ### Source map
89
+
90
+ | File | Role |
91
+ |---|---|
92
+ | [`src/index.ts`](src/index.ts) | Service definition: the abstract `SessionQueryEngine`, concrete reads, config validation |
93
+ | [`src/corpus.ts`](src/corpus.ts) | Live-preferred corpus resolution, optional persistence binding, batch projections |
94
+ | [`src/observation.ts`](src/observation.ts) | Live-preferred point observations with a bounded revision-keyed prepared-Session cache |
95
+ | [`src/cold-read.ts`](src/cold-read.ts) | Handle-based cold log read with in-memory interrupted-turn closers |
96
+ | [`src/types.ts`](src/types.ts) | Public records, filters, requests, and page types |
97
+ | [`src/config.ts`](src/config.ts) | Inherited config and the closed `SessionQueryError` taxonomy |
98
+ | [`src/filters.ts`](src/filters.ts) | Provider-independent predicates and the literal text scan |
99
+ | [`src/extraction.ts`](src/extraction.ts) | First-party semantic text extraction per event type |
100
+ | [`src/documents.ts`](src/documents.ts) | Surface-aware semantic document projection |
101
+ | [`src/tracing.ts`](src/tracing.ts) | One-shot session-lineage and event-relationship tracing |
102
+ | [`src/sources.ts`](src/sources.ts) | Immutable-header compatibility check |
103
+ | — | No runtime invariant companion is published; query results are immutable per-call projections whose lineage and event relations are validated while they are built; the service retains no observable result state. |
104
+
105
+ ### Corpus resolution
106
+
107
+ `SessionCorpus` binds optional `ctx.sessionPersistence` through a fiber and resolves each read live-first: a known live target is snapshotted without consulting persistence; otherwise the session is listed, read completely through a short-lived read handle, and re-checked for a live attachment before cloning. A cold log whose writer crashed mid-turn is balanced in memory with `interruptedTurnClosers` — persistence is never mutated by a read. Header compatibility is asserted between listed and loaded observations. Batch title reads run one metadata listing and bounded-concurrency reads, isolating per-session failures while cancellation rejects the whole batch.
108
+
109
+ ### Observation cache
110
+
111
+ `observeSession` builds point observations without a listing preflight. A live observation fixes its cut as the current log length and materializes `events` on first read, so header-, cursor-, or projection-only consumers never copy the log; the log only appends, so a late first read still yields exactly that prefix. The cold path stats the stored session first and consults an own bounded cache keyed by the persistence instance and the `stat` revision: an unchanged revision reuses the restored unpublished Session without re-reading the log; a changed revision, or a replaced persistence instance, reloads through the handle seam and replaces the entry. The cache holds `preparedSessionCacheSize` entries with least-recently-used eviction, entries pinned by active observation leases are never evicted, and a session that goes live mid-read retries the live path.
112
+
113
+ ### Reads and traces
114
+
115
+ `readSession` replays the log through `Session.create` to reuse resume's validation. `readSurface`, `listEvents`, and `traceEvent` share one `foldSurface` pass that classifies events as `current`, `shadowed`, or `log-only` and validates zero-based contiguous seqs, surface-marker eligibility, and replacement or citation integrity; any violation fails with `SESSION_QUERY_INVALID_SURFACE`. Traces are one-shot: session lineage reads the corpus once and walks parents and descendant trees deterministically, and event traces follow positional replacers to the final node while keeping cited-source links non-transitive.
116
+
117
+ </details>
118
+
119
+ -----
120
+
121
+ <a id="further-exploration"></a>
122
+ ## Further Exploration
123
+
124
+ Read these pages when the package-level contract is not enough. They move from the shared query vocabulary to the concrete backend and the decision evidence.
125
+
126
+ - [Session Query subsystem reference](../../../docs/subsystems/session-query.md) — the full type-level contract: records, filters, search pages, lineage, bounded reads, and errors.
127
+ - [dsh-session-query-sqlite](../session-query-sqlite/README.md) — the shipped full-text backend and its index lifecycle.
128
+ - [dsh-tool-session-query](../tool-session-query/README.md) — the model-facing consumer built on this service.
129
+ - [Session query relationship tracing](../../../.agents/notes/archived/feature/2026-07-13-session-query-tracing.md) — trace semantics and the validation boundary.
130
+ - [SQLite FTS5 session search](../../../.agents/notes/archived/feature/2026-07-10-sqlite-session-query-provider.md) — how the search surface is implemented and reconciled.
131
+
132
+ -----
133
+
134
+ <a id="model-experience"></a>
135
+ ## Model Experience
136
+
137
+ None, as the trusted query service exposes cloned records only to callers and registers nothing model-facing.
138
+
139
+ #### KV Cache effect
140
+
141
+ None; this package neither assembles nor sends a provider request.
142
+
143
+ ## Known Limitations and Deferred Work
144
+
145
+ <a id="known-limitations-and-deferred-work"></a>
146
+
147
+
148
+ These limits define when this package is a poor fit or needs special operational care. They are current package constraints, not a task backlog.
149
+
150
+ - **No caller authorization** — this is trusted context-wide infrastructure; a model tool or UI must constrain which sessions its caller may inspect.
151
+ - **No provider coordinator or fallback** — the service is abstract over search, so a composition must mount a concrete backend; there is no search-provider registry or fallback implementation.
152
+ - **Exact reads replay whole logs** — `readSession`, `readSurface`, `filterEvents`, and event traces load and validate the complete logical log, so very large histories pay full inspection per call; `listSessions` stays lightweight.
153
+ - **Literal text scan, not full-text search** — the `text` filter scans extracted documents with a regular expression and does not rank; ranked search requires the mounted backend.
154
+
155
+ <a id="dev-note"></a>
156
+ ### Dev Note
157
+
158
+ <details>
159
+ <summary>Working context for maintainers — click to expand</summary>
160
+
161
+ This Dev Note is working context for maintainers: open design questions and directions that are not decided. It is explicitly non-authoritative — shipped behavior, limits, and accepted rationale live in the sections above, the package code, and the linked Agent Notes.
162
+
163
+ #### Future: extractor and search-provider registries
164
+
165
+ Recursive traversal through cited source events, extractor and search-provider registries, and additional model-facing surfaces are deferred; the [tool-session-query README](../tool-session-query/README.md) documents the current consumer surface.
166
+
167
+ </details>
package/README.zh.md ADDED
@@ -0,0 +1,167 @@
1
+ ---
2
+ description: "面向消费方与后端作者的统一会话历史查询服务:对实时与持久会话日志的精确读取、关系追踪与提供方无关过滤。"
3
+ kind: "package-reference"
4
+ ---
5
+
6
+ # @x1a0f3n9/dsh-session-query
7
+
8
+ [English](README.md) | 中文
9
+
10
+ ## 概述
11
+
12
+ `dsh-session-query` 让应用代码可以列出、过滤、读取和搜索会话历史,检查带边界的事件上下文,并追踪会话或事件关系。读取优先使用实时会话而非持久化副本,并返回来自同一次一致观察的脱离存储克隆。精确读取、过滤与追踪可用于任何受支持的存储设置;排序全文搜索需要 `dsh-session-query-sqlite` 等后端。当应用代码需要以编程方式访问呈现给模型的历史时,请使用本包。
13
+
14
+ ## 目录
15
+
16
+ - [使用本包](#use-this-package)
17
+ - [理解实现](#understand-the-implementation)
18
+ - [进一步探索](#further-exploration)
19
+ - [模型体验](#model-experience)
20
+ - [已知限制与延期工作](#known-limitations-and-deferred-work)
21
+ - [开发备注](#dev-note)
22
+
23
+ -----
24
+
25
+ <a id="use-this-package"></a>
26
+ ## 使用本包
27
+
28
+ 当你需要读取或搜索会话历史、而不直接触碰会话服务或存储后端时,从应用代码使用 `ctx.sessionQuery`。该服务由具体后端插件提供——已发布组合挂载 `@x1a0f3n9/dsh-session-query-sqlite`([README](../session-query-sqlite/README.zh.md))——因此本包从不单独挂载。一旦组合了后端,以下全部能力都可在 `ctx.sessionQuery` 上使用。
29
+
30
+ ### 你可以做什么
31
+
32
+ | 操作 | 你得到什么 |
33
+ |---|---|
34
+ | `listSessions()` | 每个逻辑会话,最新的在前,带 `live` 与 `persisted` 可用性标志 |
35
+ | `readSession(id)` | 经过回放校验的完整原始事件日志,且不会让该会话变为实时 |
36
+ | `filterSessions(filters)` | 匹配 AND 连接的元数据与可用性谓词的会话 |
37
+ | `filterEvents(id, filters)` | 匹配元数据与字面文本谓词的语义事件文档 |
38
+ | `readTitleSnapshots(ids)` | 每个会话的最新折叠标题,绑定到其来源 header |
39
+ | `listEvents(id)` / `readSurface(id)` | 轻量逐事件记录,或完整的当前模型表层 |
40
+ | `readEvent(request)` | 一个完整事件加其周围有界的原始日志窗口 |
41
+ | `traceSession(id)` | 已知祖先链与递归后代树 |
42
+ | `traceEvent(request)` | 一个事件的位置替换与被引用源事件关系 |
43
+ | `searchSessions(request)` / `searchEvents(request)` | 全文搜索分页结果,由挂载的后端实现 |
44
+
45
+ 不带正文的记录只公开 `SessionHeader.isSeeded`。返回事件正文的读取(`readSession`、`readSurface`、`readEvent`)与保留的 `SessionObservation` 值还携带精确 `inheritedEventCount`,因此调用方无需从日志推断切点即可区分继承事件与自有事件。
46
+
47
+ ### 过滤器
48
+
49
+ `SessionResultFilter` 按 id、可空 cwd、创建时间范围、可空父级或来源可用性缩小会话范围;`SessionEventResultFilter` 按 seq/时间范围、事件类型、表层或字面文本缩小事件范围。过滤器数组使用 AND 连接,同一子句内的列表值使用 OR;空列表值不匹配任何内容,范围包含端点,格式错误的范围或未知的封闭联合值以 `SESSION_QUERY_INVALID_FILTER` 失败。
50
+
51
+ 文本子句是对所提取语义文本的字面、不区分大小写、空白灵活的扫描——而非全文查询。需要任意子字符串召回时使用它;需要排序后的全文结果时使用挂载后端的搜索方法。
52
+
53
+ ### 配置
54
+
55
+ 继承的旋钮通过挂载后端的配置设置:
56
+
57
+ | 字段 | 默认值 | 含义 |
58
+ |---|---|---|
59
+ | `readWindowMax` | `50` | `readEvent` 接受的 `before`/`after` 原始事件数上限 |
60
+ | `persistedReadConcurrency` | `4` | 一次批量标题读取中的并发持久化日志读取数 |
61
+ | `preparedSessionCacheSize` | `5` | 为跨 `observeSession` 读取复用而保留的冷 prepared-Session 观察数 |
62
+
63
+ ### 失败与恢复
64
+
65
+ 失败带有稳定的 `SessionQueryError.code` 类型。你会遇到的包括:id 不存在时 `SESSION_QUERY_SESSION_NOT_FOUND`;同一会话的实时与持久化观察在不可变 header 上不一致时 `SESSION_QUERY_SOURCE_CONFLICT`;已挂载持久化不可读时 `SESSION_QUERY_PERSISTENCE_FAILED`;持久化记录未通过 Session 校验时 `SESSION_QUERY_CORRUPT_SESSION`;加载的日志破坏表层约定时 `SESSION_QUERY_INVALID_SURFACE`。针对已知实时会话的读取从不查询持久化,因此后端故障不会让当前内存历史变得不可读。
66
+
67
+ -----
68
+
69
+ <a id="understand-the-implementation"></a>
70
+ ## 理解实现
71
+
72
+ <details>
73
+ <summary>实现细节——点击展开</summary>
74
+
75
+ 本节解释服务背后的设计决策,并指出实现它们的代码位置;可观察行为已在[使用本包](#use-this-package)中完整说明。
76
+
77
+ ### 设计理念
78
+
79
+ 本服务建立在一个分离与三项承诺之上:
80
+
81
+ - **实时优先的逻辑语料库。** 每次读取都解析一个一致的观察:实时 `ctx.sessions` 优先,可选的 `ctx.sessionPersistence` 补充其余部分,冲突的不可变 header 宁可失败也不合并。
82
+ - **脱离存储的结果。** 所有返回的 header、事件与记录都是克隆;不暴露实时状态,也不保留订阅。
83
+ - **精确读取具体,搜索抽象。** 读取、过滤与追踪在此只实现一次;两个全文方法是由后端拥有的唯一抽象表面。
84
+ - **一次规范的表层折叠。** `listEvents`、`readSurface` 与 `traceEvent` 使用同一个 `dsh-session` 折叠校验整个日志,因此搜索与追踪和模型历史推导一致。
85
+
86
+ 决策历史记录在[统一服务决策](../../../.agents/notes/archived/architecture/2026-07-23-unified-session-query-service.md)、[追踪笔记](../../../.agents/notes/archived/feature/2026-07-13-session-query-tracing.md)与 [SQLite 提供方笔记](../../../.agents/notes/archived/feature/2026-07-10-sqlite-session-query-provider.md)中。
87
+
88
+ ### 源码地图
89
+
90
+ | 文件 | 职责 |
91
+ |---|---|
92
+ | [`src/index.ts`](src/index.ts) | 服务定义:抽象 `SessionQueryEngine`、具体读取、配置校验 |
93
+ | [`src/corpus.ts`](src/corpus.ts) | 实时优先的语料库解析、可选持久化绑定、批量投影 |
94
+ | [`src/observation.ts`](src/observation.ts) | 实时优先的定点观察,带按修订键控的有界 prepared-Session 缓存 |
95
+ | [`src/cold-read.ts`](src/cold-read.ts) | 基于 handle 的冷日志读取,附内存中的中断轮次闭合事件 |
96
+ | [`src/types.ts`](src/types.ts) | 公共记录、过滤器、请求与分页类型 |
97
+ | [`src/config.ts`](src/config.ts) | 继承配置与封闭的 `SessionQueryError` 分类体系 |
98
+ | [`src/filters.ts`](src/filters.ts) | 提供方无关谓词与字面文本扫描 |
99
+ | [`src/extraction.ts`](src/extraction.ts) | 按事件类型的第一方语义文本提取 |
100
+ | [`src/documents.ts`](src/documents.ts) | 表层感知的语义文档投影 |
101
+ | [`src/tracing.ts`](src/tracing.ts) | 一次性会话血缘与事件关系追踪 |
102
+ | [`src/sources.ts`](src/sources.ts) | 不可变 header 兼容性检查 |
103
+ | — | 不发布运行时不变式伴生入口;结果均为按调用投影。 |
104
+
105
+ ### 语料库解析
106
+
107
+ `SessionCorpus` 通过 fiber 绑定可选的 `ctx.sessionPersistence`,并实时优先解析每次读取:已知实时目标直接快照,不查询持久化;否则先列出会话,再通过短生命周期的读取 handle 完整读出日志,并在克隆前重新检查是否出现实时挂载。写入者在轮次中途崩溃的冷日志用 `interruptedTurnClosers` 在内存中补齐 —— 读取从不修改持久化。列表与加载观察之间会断言 header 兼容性。批量标题读取执行一次元数据列表与有界并发读取,把逐会话失败隔离,而取消会拒绝整个批次。
108
+
109
+ ### 观察缓存
110
+
111
+ `observeSession` 不经过列表预检直接构建定点观察。实时观察以当前日志长度固定 cut,并在首次读取时才物化 `events`,因此只需要 header、cursor 或 projection 的消费者永远不会复制日志;日志只会追加,所以延后的首次读取得到的仍然正好是该前缀。冷路径先对存储会话执行 `stat`,再查询自有的有界缓存,缓存键为持久化实例加 `stat` 修订:修订未变则复用已恢复的未发布 Session,不再重读日志;修订变化或持久化实例被替换则经 handle 缝重新加载并替换条目。缓存保留 `preparedSessionCacheSize` 个条目并按最久未用淘汰,被活跃观察租约钉住的条目从不被淘汰;读取中途转为实时的会话会重试实时路径。
112
+
113
+ ### 读取与追踪
114
+
115
+ `readSession` 通过 `Session.create` 回放日志,复用恢复的校验。`readSurface`、`listEvents` 与 `traceEvent` 共用一次 `foldSurface` 遍历,把事件分类为 `current`、`shadowed` 或 `log-only`,并校验从零开始且连续的 seq、表层标记的适用性以及替换或引用完整性;任何违规都以 `SESSION_QUERY_INVALID_SURFACE` 失败。追踪是一次性的:会话血缘只读取一次语料库并确定性遍历父级与后代树;事件追踪沿位置替换者跟进到最终节点,同时保持被引用源事件链接不传递。
116
+
117
+ </details>
118
+
119
+ -----
120
+
121
+ <a id="further-exploration"></a>
122
+ ## 进一步探索
123
+
124
+ 当包级约定不够用时阅读以下页面。它们从共享查询词汇逐步进入具体后端与决策证据。
125
+
126
+ - [会话查询子系统参考](../../../docs/subsystems/session-query.zh.md)——完整类型级约定:记录、过滤器、搜索页、血缘、有界读取与错误。
127
+ - [dsh-session-query-sqlite](../session-query-sqlite/README.zh.md)——已发布的全文后端及其索引生命周期。
128
+ - [dsh-tool-session-query](../tool-session-query/README.zh.md)——构建在本服务之上的面向模型消费方。
129
+ - [会话查询关系追踪](../../../.agents/notes/archived/feature/2026-07-13-session-query-tracing.md)——追踪语义与校验边界。
130
+ - [SQLite FTS5 会话搜索](../../../.agents/notes/archived/feature/2026-07-10-sqlite-session-query-provider.md)——搜索表面如何实现与对账。
131
+
132
+ -----
133
+
134
+ <a id="model-experience"></a>
135
+ ## 模型体验
136
+
137
+ 无,因为该可信查询服务只向调用方返回克隆记录,且不注册任何面向模型的内容。
138
+
139
+ #### KV Cache 影响
140
+
141
+ 无;本包既不组装也不发送提供方请求。
142
+
143
+ ## 已知限制与延期工作
144
+
145
+ <a id="known-limitations-and-deferred-work"></a>
146
+
147
+
148
+ 这些限制说明本包何时不合适,或何时需要特别的运维注意。它们是当前包约束,不是任务积压。
149
+
150
+ - **无调用方授权**——这是上下文范围内的可信基础设施;模型工具或 UI 必须限制调用方可检查的会话。
151
+ - **无提供方协调器或回退**——服务在搜索上是抽象的,组合必须挂载具体后端;没有搜索提供方注册表或回退实现。
152
+ - **精确读取回放整个日志**——`readSession`、`readSurface`、`filterEvents` 与事件追踪会加载并校验完整逻辑日志,因此非常大的历史每次调用都要付出完整检查;`listSessions` 保持轻量。
153
+ - **字面文本扫描,而非全文搜索**——`text` 过滤器用正则表达式扫描提取出的文档且不排序;排序搜索需要挂载后端。
154
+
155
+ <a id="dev-note"></a>
156
+ ### 开发备注
157
+
158
+ <details>
159
+ <summary>维护者的工作上下文——点击展开</summary>
160
+
161
+ 本开发备注是维护者的工作上下文:开放设计问题与尚未决定的探索方向。它明确不具权威性——已交付的行为、限制与既定理由以上文、包代码和相关 Agent Note 为准。
162
+
163
+ #### 未来:提取器与搜索提供方注册表
164
+
165
+ 对被引用源事件的递归遍历、提取器与搜索提供方注册表以及更多面向模型表面均被推迟;[tool-session-query README](../tool-session-query/README.zh.md)说明了当前的消费方表面。
166
+
167
+ </details>