@hasna-internal/kai-session-query 0.1.1-rc.2 → 0.1.1-rc.3
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/README.md +1 -54
- package/index.js +2 -0
- package/package.json +10 -51
- package/LICENSE +0 -21
- package/README.i18n.yaml +0 -6
- package/README.zh.md +0 -56
- package/lib/index.js +0 -969
- package/lib/invariant.js +0 -23
- package/lib/types/config.d.ts +0 -21
- package/lib/types/corpus.d.ts +0 -64
- package/lib/types/cursor.d.ts +0 -11
- package/lib/types/documents.d.ts +0 -18
- package/lib/types/extraction.d.ts +0 -12
- package/lib/types/filters.d.ts +0 -35
- package/lib/types/index.d.ts +0 -143
- package/lib/types/invariant.d.ts +0 -16
- package/lib/types/sources.d.ts +0 -9
- package/lib/types/tracing.d.ts +0 -33
- package/lib/types/types.d.ts +0 -259
package/README.md
CHANGED
|
@@ -1,56 +1,3 @@
|
|
|
1
1
|
# @hasna-internal/kai-session-query
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
`SessionQueryEngine` is the combined abstract `ctx.sessionQuery` contract. It implements exact session-history retrieval, relationship tracing, and provider-independent filtering over live `ctx.sessions` plus optional dynamically mounted `ctx.sessionPersistence`; concrete backends implement its two full-text methods. Matching ids produce one record: live events win, while `live` and `persisted` report both source availabilities. Conflicting immutable headers fail with `SESSION_QUERY_SOURCE_CONFLICT`.
|
|
6
|
-
|
|
7
|
-
## Reads
|
|
8
|
-
|
|
9
|
-
- `listSessions(signal?)` reads current persistence metadata, merges live records with live precedence, and returns cloned records in deterministic newest-first order.
|
|
10
|
-
- `readSession(sessionId)` returns one complete detached raw log after the same core replay validation used by resume; it never enters the session into the live store.
|
|
11
|
-
- `filterSessions(filters, signal?)` applies provider-independent session metadata and availability predicates to that same cloned logical corpus.
|
|
12
|
-
- `filterEvents(sessionId, filters)` extracts first-party semantic documents and applies provider-independent metadata and literal-text predicates in ascending seq order.
|
|
13
|
-
- `readTitleSnapshots(sessionIds, signal?)` resolves unique ids from one live-preferred corpus observation, passes cancellation through persisted listing and inspection, and returns ordered per-session settlements so one missing or malformed title source does not discard its peers. Each live source is folded directly, and each persisted worker folds to a detached header/title result and releases the full log before dequeuing another id. Cancellation rejects the whole batch. `readTitleSnapshot(sessionId, signal?)` is the one-observation view; `readTitle(sessionId, signal?)` returns only its optional folded `session/title`.
|
|
14
|
-
- `listEvents(sessionId)` loads the live-preferred raw log and classifies each event as `current`, `shadowed`, or `log-only` with the shared `dsh-session` surface fold.
|
|
15
|
-
- `readSurface(sessionId)` returns one cloned header, raw-log capture boundary, and the complete folded current surface in model-history order. A live session wins over persistence; compaction is observed before or after its replacement append, never as a synthetic mixture.
|
|
16
|
-
- `readEvent(request, signal?)` returns a cloned header, the full target event, and a bounded raw-seq window. `before` and `after` default to zero and may not exceed `readWindowMax`.
|
|
17
|
-
- `traceSession(sessionId, signal?)` reads the corpus once and returns immediate-to-outward ancestors plus deterministic recursive descendant trees. `complete: false` identifies the first missing parent; a target-connected cycle fails with `SESSION_QUERY_INVALID_LINEAGE`.
|
|
18
|
-
- `traceEvent(request, signal?)` loads the logical log once and returns its cloned source header with direct positional replacements and direct cited source-event links. `replacementChain` follows positional replacers to the final replacement; source-event links remain non-transitive.
|
|
19
|
-
|
|
20
|
-
Persistence is optional and may mount or unmount dynamically. Cross-corpus listing and lineage tracing fail with `SESSION_QUERY_PERSISTENCE_FAILED` while mounted persistence is unreadable; a successfully read durable record that fails Session validation reports `SESSION_QUERY_CORRUPT_SESSION` instead. A title read, event trace, or event read targeting a known live session does not consult persistence, so durable backend health cannot make current in-memory state unreadable. Persisted title and event operations list before loading and reject a metadata mismatch rather than combining inconsistent observations. Lineage-trace cancellation is passed to persisted listing; event-trace and event-read cancellation is passed to persisted listing and inspection. Each waits for the started backend call to settle, then rejects with the signal's exact reason even when the backend ignored that signal. A pre-aborted known-live title read, event trace, or event read rejects before folding or snapshotting without consulting persistence. A batch title observation performs one metadata listing, inspects its unique persisted ids with at most `persistedInspectConcurrency` workers, and preserves each title's own observed header for downstream authorization. Cancellation starts no queued inspections and rejects only after already-started workers settle. `listSessions()` remains lightweight and does not load logs or index titles.
|
|
21
|
-
|
|
22
|
-
## Filtering and extraction
|
|
23
|
-
|
|
24
|
-
`SessionResultFilter` covers id, nullable cwd, created-at range, nullable parent, and source availability. `SessionEventResultFilter` covers seq/time ranges, event type, surface, and semantic text. Filter arrays are ANDed; values within one list clause are ORed. Empty list values match nothing, ranges are inclusive, and malformed ranges or closed-union values fail with `SESSION_QUERY_INVALID_FILTER`.
|
|
25
|
-
|
|
26
|
-
The text clause is deliberately independent of FTS providers: caller text is escaped into a Unicode, case-insensitive regular expression, and each whitespace run matches one or more whitespace characters. It is a literal semantic-text scan, not a full-text query. `extractSessionEventText()` and `buildSessionEventSearchDocuments()` define the shared first-party document projection; reasoning blocks, structural boundaries, stream chunks, request headers, and unknown declaration-merged variants produce no document.
|
|
27
|
-
|
|
28
|
-
## Full-text methods
|
|
29
|
-
|
|
30
|
-
`SessionQueryEngine.searchSessions(request, exec?)` groups the logical corpus by strongest matching event; `searchEvents(request, exec?)` searches one logical session. These are the service's only abstract methods. Both return pages whose continuation is an owned branded `SessionSearchCursor`, accept optional cancellation, and expose snippets without provider-specific numeric scores. An event-search page also carries the cloned target header from the same indexed generation as its hits, allowing authorization consumers to bind policy to the payload observation. Search requests accept only metadata event filters, because literal-text filtering is the scan path described above.
|
|
31
|
-
|
|
32
|
-
The package has no provider coordinator, fallback implementation, or standalone concrete plugin. A concrete service backend inherits the implemented reads, filters, and traces while owning full-text observation, reconciliation, ranking, cursor generations, and query execution; the first implementation is [`@hasna-internal/kai-session-query-sqlite`](../session-query-sqlite/README.md).
|
|
33
|
-
|
|
34
|
-
`SessionQueryError.code` is a closed union covering request validation, missing targets, malformed surfaces, source conflicts, persistence/index failures, cancellation, and invalid or stale cursors; the exact literals are defined in [`src/config.ts`](src/config.ts).
|
|
35
|
-
|
|
36
|
-
`listEvents()`, `readSurface()`, and `traceEvent()` run the same one-pass `dsh-session` surface fold. A loaded log is valid only when event seqs are zero-based and contiguous, surface markers obey event-type eligibility, source-event arrays are nonempty and duplicate-free, references name earlier events, and each positional replacement names and cites every surface node it removes; every violation fails with `SESSION_QUERY_INVALID_SURFACE`.
|
|
37
|
-
|
|
38
|
-
## Configuration
|
|
39
|
-
|
|
40
|
-
| Key | Default | Contract |
|
|
41
|
-
|---|---:|---|
|
|
42
|
-
| `readWindowMax` | `50` | Maximum `before` or `after` raw-event count. |
|
|
43
|
-
| `persistedInspectConcurrency` | `4` | Maximum concurrent persisted-log inspections in one batch read; must be a positive safe integer. |
|
|
44
|
-
|
|
45
|
-
## Model Experience
|
|
46
|
-
|
|
47
|
-
None, as this trusted query service returns cloned session records only to its callers and registers no model-facing prompt, schema, tool, or message.
|
|
48
|
-
|
|
49
|
-
#### KV Cache effect
|
|
50
|
-
|
|
51
|
-
None; this package neither assembles nor sends a provider request.
|
|
52
|
-
|
|
53
|
-
## Known Limitations and Deferred Work
|
|
54
|
-
|
|
55
|
-
- **No caller authorization** — this is trusted context-wide infrastructure; a future model tool or UI must constrain which sessions its caller may inspect.
|
|
56
|
-
- **No registries or model-facing tool** — extractor and search-provider registries, recursive traversal through cited source events, and a model-facing tool are absent. The [tracing decision](../../../.agents/notes/implemented/feature/2026-07-13-session-query-tracing.md) owns relationship semantics; SQLite ownership and tokenizer decisions live in the [implemented search note](../../../.agents/notes/implemented/feature/2026-07-10-sqlite-session-query-provider.md).
|
|
3
|
+
This package has been retired by its owner. This release is an empty placeholder with no dependencies or supported functionality. Do not use it.
|
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,57 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasna-internal/kai-session-query",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"access": "public"
|
|
7
|
-
},
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
|
|
11
|
-
"directory": "packages/session-query/session-query"
|
|
12
|
-
},
|
|
13
|
-
"type": "module",
|
|
14
|
-
"main": "lib/index.js",
|
|
15
|
-
"types": "lib/types/index.d.ts",
|
|
16
|
-
"exports": {
|
|
17
|
-
".": {
|
|
18
|
-
"types": "./lib/types/index.d.ts",
|
|
19
|
-
"default": "./lib/index.js"
|
|
20
|
-
},
|
|
21
|
-
"./invariant": {
|
|
22
|
-
"types": "./lib/types/invariant.d.ts",
|
|
23
|
-
"default": "./lib/invariant.js"
|
|
24
|
-
},
|
|
25
|
-
"./src/*": "./src/*",
|
|
26
|
-
"./package.json": "./package.json"
|
|
27
|
-
},
|
|
3
|
+
"version": "0.1.1-rc.3",
|
|
4
|
+
"description": "Retired package. Empty placeholder with no dependencies.",
|
|
5
|
+
"main": "index.js",
|
|
28
6
|
"files": [
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"lib/types/**/*.d.ts"
|
|
7
|
+
"index.js",
|
|
8
|
+
"README.md"
|
|
32
9
|
],
|
|
33
10
|
"license": "MIT",
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"@hasna-internal/kai-session-title": "^0.1.1-rc.2",
|
|
39
|
-
"@hasna-internal/kai-llm": "^0.1.1-rc.2",
|
|
40
|
-
"@hasna-internal/kai-invariants": "^0.1.1-rc.2",
|
|
41
|
-
"@deepseek-ai/cordis": "^4.0.1"
|
|
42
|
-
},
|
|
43
|
-
"peerDependenciesMeta": {
|
|
44
|
-
"@hasna-internal/kai-session-persistence": {
|
|
45
|
-
"optional": true
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"@hasna-internal/kai-llm": "^0.1.1-rc.2",
|
|
50
|
-
"@hasna-internal/kai-session": "^0.1.1-rc.2",
|
|
51
|
-
"@hasna-internal/kai-brand": "^0.1.1-rc.2",
|
|
52
|
-
"@hasna-internal/kai-session-persistence": "^0.1.1-rc.2",
|
|
53
|
-
"@hasna-internal/kai-invariants": "^0.1.1-rc.2",
|
|
54
|
-
"@deepseek-ai/cordis": "^4.0.1",
|
|
55
|
-
"@hasna-internal/kai-session-title": "^0.1.1-rc.2"
|
|
11
|
+
"deprecated": "Retired by the package owner. Empty placeholder; do not use.",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"registry": "https://registry.npmjs.org/",
|
|
14
|
+
"access": "public"
|
|
56
15
|
}
|
|
57
|
-
}
|
|
16
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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.
|
package/README.i18n.yaml
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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: 02640bee4b3eb7f6877756a2ce84b26f698c9f58
|
|
6
|
-
README.zh.md: dbac518b2c295825459475dba5a9c6c38f53afc8
|
package/README.zh.md
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# @hasna-internal/kai-session-query
|
|
2
|
-
|
|
3
|
-
[English](README.md) | 中文
|
|
4
|
-
|
|
5
|
-
`SessionQueryEngine` 是组合式抽象 `ctx.sessionQuery` 约定。它对实时 `ctx.sessions` 和可选的动态挂载 `ctx.sessionPersistence` 实现精确会话历史取回、关系跟踪和与提供方无关的过滤;具体后端实现它的两个全文方法。匹配 id 只产生一条记录:实时事件优先,而 `live` 和 `persisted` 会报告两种来源的可用性。如果不可变 header 存在冲突,则以 `SESSION_QUERY_SOURCE_CONFLICT` 失败。
|
|
6
|
-
|
|
7
|
-
## 读取
|
|
8
|
-
|
|
9
|
-
- `listSessions(signal?)` 读取当前持久化元数据,以实时记录优先的方式合并它们,并按确定性的最新优先顺序返回克隆记录。
|
|
10
|
-
- `readSession(sessionId)` 在执行与恢复相同的核心回放验证后,返回一份完整、脱离存储的原始日志;它绝不会将该会话放入实时存储。
|
|
11
|
-
- `filterSessions(filters, signal?)` 对同一份克隆逻辑语料库应用与提供方无关的会话元数据和可用性谓词。
|
|
12
|
-
- `filterEvents(sessionId, filters)` 提取第一方语义文档,并按 seq 升序应用与提供方无关的元数据和字面文本谓词。
|
|
13
|
-
- `readTitleSnapshots(sessionIds, signal?)` 从一次实时优先的语料库观察中解析唯一 id,将取消信号传递给持久化列表查询和检查,并按顺序返回每个会话的结算结果,使某个缺失或格式错误的标题来源不会导致其他会话的结果被丢弃。每个实时来源直接 fold,每个持久化 worker fold 为脱离存储的 header/标题结果,并在出队下一个 id 前释放完整日志。取消会拒绝整个批次。`readTitleSnapshot(sessionId, signal?)` 是单次观察视图;`readTitle(sessionId, signal?)` 只返回其可选的 folded `session/title`。
|
|
14
|
-
- `listEvents(sessionId)` 加载实时优先的原始日志,将每个事件分类为 `current`、`shadowed` 或 `log-only`;该分类使用共享 `dsh-session` 表层 fold。
|
|
15
|
-
- `readSurface(sessionId)` 返回一个克隆 header、原始日志捕获边界,以及按模型历史顺序排列的完整折叠后当前表层。实时会话优先于持久化;压缩(compaction)只会在其替换追加之前或之后被观察,绝不会出现合成混合。
|
|
16
|
-
- `readEvent(request, signal?)` 返回一个克隆 header、完整目标事件和有界的原始 seq 窗口。`before` 和 `after` 默认为 0,且不得超过 `readWindowMax`。
|
|
17
|
-
- `traceSession(sessionId, signal?)` 只读取一次语料库,返回从直接父级向外的祖先,以及确定性的递归后代树。`complete: false` 标识第一个缺失父级;与目标相连的循环会以 `SESSION_QUERY_INVALID_LINEAGE` 失败。
|
|
18
|
-
- `traceEvent(request, signal?)` 只加载一次逻辑日志,返回其克隆源 header、直接位置替换和直接引用的源事件链接。`replacementChain` 沿位置替换者跟踪到最终替换;源事件链接仍不传递。
|
|
19
|
-
|
|
20
|
-
持久化是可选的,可动态挂载或卸载。已挂载持久化无法读取时,跨语料库列表和血缘跟踪以 `SESSION_QUERY_PERSISTENCE_FAILED` 失败;已经成功读取、但无法通过 Session 校验的持久化记录则以 `SESSION_QUERY_CORRUPT_SESSION` 失败。针对已知实时会话的标题读取、事件跟踪或事件读取不会查询持久化,因此持久化后端的健康状态无法使当前内存状态变得不可读。持久化标题和事件操作在加载前先执行列表查询,并在元数据不匹配时拒绝,而不会组合不一致的观察。血缘跟踪的取消信号会传递给持久化列表查询;事件跟踪和事件读取的取消信号会传递给持久化列表查询和检查。每项操作都会等待已启动的后端调用结算,然后使用信号的精确原因拒绝,即使后端忽略了该信号。针对已知实时会话且预先中止的标题读取、事件跟踪或事件读取会在 fold 或快照之前拒绝,且不查询持久化。批量标题观察执行一次元数据列表查询,使用最多 `persistedInspectConcurrency` 个 worker 检查唯一持久化 id,并保留每个标题自己观察到的 header,供下游授权使用。取消不会启动已排队检查,且只在已启动 worker 结算后拒绝。`listSessions()` 仍保持轻量,不加载日志或索引标题。
|
|
21
|
-
|
|
22
|
-
## 过滤与提取
|
|
23
|
-
|
|
24
|
-
`SessionResultFilter` 覆盖 id、可空 cwd、创建时间范围、可空父级和来源可用性。`SessionEventResultFilter` 覆盖 seq/时间范围、事件类型、表层和语义文本。过滤器数组使用 AND;同一列表子句内的值使用 OR。空列表值不匹配任何内容,范围包含端点,而格式错误的范围或封闭联合值以 `SESSION_QUERY_INVALID_FILTER` 失败。
|
|
25
|
-
|
|
26
|
-
文本子句刻意与 FTS 提供方无关:调用方文本会被转义为不区分大小写的 Unicode 正则表达式,每段连续空白匹配一个或多个空白字符。它是字面语义文本扫描,而非全文查询。`extractSessionEventText()` 和 `buildSessionEventSearchDocuments()` 定义共享的第一方文档投影;推理(reasoning)块、结构边界、流分片、请求 header 和未知声明合并变体不产生文档。
|
|
27
|
-
|
|
28
|
-
## 全文方法
|
|
29
|
-
|
|
30
|
-
`SessionQueryEngine.searchSessions(request, exec?)` 按匹配最强的事件对逻辑语料库分组;`searchEvents(request, exec?)` 搜索一个逻辑会话。这两个是服务仅有的抽象方法。两者都返回分页结果,其延续信息是由服务持有的带品牌 `SessionSearchCursor`;接受可选取消,并在不使用提供方专用数值分数的情况下提供摘录。事件搜索分页结果还携带来自与命中相同索引世代的克隆目标 header,使授权消费方可将策略绑定到此次载荷观察。搜索请求只接受事件元数据过滤器,因为字面文本过滤使用上文所述扫描路径。
|
|
31
|
-
|
|
32
|
-
该包没有提供方协调器、回退实现或独立具体插件。具体服务后端继承已实现的读取、过滤和跟踪,同时负责全文观察、对账、排名、游标世代和查询执行;第一个实现是 [`@hasna-internal/kai-session-query-sqlite`](../session-query-sqlite/README.zh.md)。
|
|
33
|
-
|
|
34
|
-
`SessionQueryError.code` 是一个封闭联合,覆盖请求验证、缺失目标、格式错误的表层、来源冲突、持久化/索引失败、取消,以及无效或陈旧游标;精确字面值在 [`src/config.ts`](src/config.ts) 中定义。
|
|
35
|
-
|
|
36
|
-
`listEvents()`、`readSurface()` 和 `traceEvent()` 执行同一个单遍 `dsh-session` 表层 fold。只有当事件 seq 从零开始且连续、表层标记符合事件类型的适用性要求、源事件数组非空且无重复、引用指向较早事件,且每个位置替换都命名并引用它移除的每个表层节点时,加载的日志才有效;任何违规都以 `SESSION_QUERY_INVALID_SURFACE` 失败。
|
|
37
|
-
|
|
38
|
-
## 配置
|
|
39
|
-
|
|
40
|
-
| 键 | 默认值 | 约定 |
|
|
41
|
-
|---|---:|---|
|
|
42
|
-
| `readWindowMax` | `50` | `before` 或 `after` 的最大原始事件数。 |
|
|
43
|
-
| `persistedInspectConcurrency` | `4` | 一次批量读取中的最大并发持久化日志检查数;必须是正的安全整数。 |
|
|
44
|
-
|
|
45
|
-
## 模型体验
|
|
46
|
-
|
|
47
|
-
无。该可信查询服务只向调用方返回克隆会话记录,不注册面向模型的提示词、schema、工具或消息。
|
|
48
|
-
|
|
49
|
-
#### KV Cache 影响
|
|
50
|
-
|
|
51
|
-
无;该包既不组装也不发送提供方请求。
|
|
52
|
-
|
|
53
|
-
## 已知限制与暂缓事项
|
|
54
|
-
|
|
55
|
-
- **无调用方授权**:这是上下文范围内的可信基础设施;未来的模型工具或 UI 必须限制调用方可检查的会话。
|
|
56
|
-
- **无注册表或面向模型工具**:尚未提供提取器和搜索提供方注册表、递归遍历所引用的源事件的能力,以及面向模型的工具。[跟踪决策](../../../.agents/notes/implemented/feature/2026-07-13-session-query-tracing.zh.md) 负责关系语义;SQLite 归属和 tokenizer 决策位于[已实现搜索记录](../../../.agents/notes/implemented/feature/2026-07-10-sqlite-session-query-provider.zh.md)。
|