dsh-better-session-query: Chunk-Level Parallel Indexing for Session History

Preface

When developing agents in DeepSeek Harness (DSH), with many sessions, questions like “what was written in a certain thought segment last time” or “what did the agent say in a certain hour in a certain workspace” often require going through event logs one by one. The official @deepseek-ai/dsh-session-query-sqlite sets the index unit at the event level: one event extracts a text segment, one document line, and hit results are usually “which session’s event number X”, which doesn’t match the granularity of text, reasoning, tool-call blocks within messages.

The following introduces the community plugin dsh-better-session-query (maintainer leolee9086, SkillHub category: Memory). Without replacing the official sessionQuery or modifying DSH source code, it attaches a block-level parallel index to session history, making blocks the index rows, thereby answering block-level retrieval and metadata filtering questions.

What is This

In one sentence: A DSH plugin that builds a block-level FTS5 index for session history, existing in parallel with the official event-level session-query.

  • Repository: leolee9086/dsh-better-session-query
  • Current version (package.json): 0.1.1, License MIT
  • Dependencies: Chunking logic from @leolee9086/dsh-session-blocks@0.1.0; storage uses Node’s built-in node:sqlite (FTS5)
  • Hard boundaries (from README):
  • Does not replace the provider, only consumes the runtime-injected sessionQuery to read sessions
  • Does not import any @deepseek-ai/* packages
  • Can be enabled alongside the official session-query

v0.1.1 also exports pure functions under dsh-better-session-query/blocks (extractRawBlocks, walkContentBlocks, parseToolArguments), which can be used independently without loading the index service. Memory synchronization, vector and hybrid recall are still under development and not included in this release.

Core Features

Differences from Official Index

The official index uses events as rows; this plugin lowers the granularity to blocks: text / reasoning / tool-call / tool-result in a message each become a block. Block identity is blockId = <sessionId>#<seq>#<path>, where path indicates the block’s position within the event (e.g., top-level "0", inner tool-result "3.0").

Questions It Can Answer (Summary)

Question Method
Which blocks contain a certain word FTS5 + bm25; Chinese supports ≥1 character substring recall through character decomposition
Reasoning blocks with 2000~5000 characters Metadata: blockTypes:["reasoning"] + lengthMin / lengthMax
Agent messages in a certain time period granularity:"messages", eventTypes:["assistant/message"], timeFrom / timeTo
Which sessions/contents in a certain workspace session_blocks_workspaces; retrieval with workspace (= session header cwd)
Sessions with titles containing a certain word session_blocks_workspaces(groupBy="session", titleContains="…")
Block content session_blocks_read(blockId) or sessionId + seq (+ path)

Length is counted by Unicode code points; time uses the event’s own Unix epoch milliseconds (SessionEvent.time).

Block and Inverted Index Strategy

By default, text, tool-call, and todo enter the full-text inverted index. Reasoning, tool-result shells, image/file etc. do not enter the inverted index by default, but metadata queries and read are still available (consistent with the official “reasoning blocks do not enter index” semantics). If reasoning content needs to be hit by search, you need to enable include.reasoning and rebuild the index.

Background Indexing

Indexing updates progressively in the background (default reconcileOnSearch: "background", and a 30s scheduled cycle); retrieval does not wait for indexing to complete. First cold start requires complete log reading and block building for each unindexed session, which may take some time when there are many sessions. You can specify session IDs via session_blocks_list, or manually advance with session_blocks_status {reindex:true}.

Default index database path: <DSH_HOME>/session-blocks.db. Inverted index and filter tables are stored separately (block_fts, block_meta, block_text, etc.), independent of session persistence JSONL.

Model Tools and Services

Main tools on the agent side (README “Model Tools” section):

session_blocks_search(query="并发模型", sessionId?, workspace?, excludeWorkspaces?, blockTypes?, surface?, limit?, offset?)
session_blocks_query(granularity="blocks"|"messages", workspace?, excludeWorkspaces?, blockTypes?, eventTypes?, surface?, lengthMin?, lengthMax?, timeFrom?, timeTo?, orderBy?, descending?, limit?, offset?, withText?)
session_blocks_list(sessionId, seq?, limit?, offset?)
session_blocks_workspaces(groupBy="workspace"|"session", workspace?, titleContains?, limit?, offset?)
session_blocks_read(blockId) | session_blocks_read(sessionId, seq, path?)
session_blocks_sql(sql, limit?)
session_blocks_status(sessionId?, reindex?, force?)

At runtime, ctx.sessionBlockQuery is also provided (deliberately not reusing the sessionQuery name), containing methods like searchBlocks, queryBlocks, queryMessages, reconcile, compact.

Optional Web sidebar “Session Block Index” monitoring (dsh.client.platform: "web"); data plane only local loopback. Set monitor.enabled: false when no interface is needed.

Installation and Activation

Environment requirements: Node.js 22.19.0 or higher (node:sqlite; Node 22.x may print ExperimentalWarning).

README instructions: The package is located in the dsh-better-session-query/ subdirectory of the SAC_search repository. For development, you can put this directory into $DSH_HOME/plugins/, or link it in the profile:

dsh-better-session-query/  # 会话块级并行索引

Mount it in the profile’s cordis.patch.yml (if there’s already an insert list, just append this item):

- insert:
    - id: dsh-better-session-query
      name: dsh-better-session-query
      config:
        # path 留空 = <DSH_HOME>/session-blocks.db;要关后台索引更新就设 backgroundReconcileMs: 0
        {}

The package already contains cordis.patch.yml, so it can also be directly mounted as a bundle:

- name: dsh-better-session-query

Takes effect after reloading the plugin or restarting DSH. No need to modify the official session-query-sqlite configuration; this plugin can still be used when the official index is disabled.

Common configuration items (excerpt, full table in README “Configuration” section):

Key Default Description
path <DSH_HOME>/session-blocks.db Index database path
backgroundReconcileMs 30000 Background scheduled index interval; 0 disables scheduling
maxSessionsPerReconcile 25 Maximum number of sessions processed in one cycle
includeWorkspaces / excludeWorkspaces [] Index layer whitelist/blacklist (excluded workspaces won’t even have logs read)
reconcileOnSearch "background" Whether to trigger index updates during retrieval

Typical Usage

The following examples are from the README and can be reproduced in Agent tool calls.

Filter reasoning blocks by type and length:

session_blocks_query(blockTypes=["reasoning"], lengthMin=2000, lengthMax=5000, orderBy="length")

Query assistant messages by time window:

session_blocks_query(granularity="messages", eventTypes=["assistant/message"], timeFrom="2026-09-13 10:00", timeTo="2026-09-13 12:00")

Workspace and session lists, full-text retrieval limited to workspace:

session_blocks_workspaces()

session_blocks_workspaces(groupBy="session", workspace="D:\\work")
session_blocks_search(query="并发模型", workspace="D:\\work")

Read blocks of a certain event:

session_blocks_read(sessionId="session-xxxx", seq=42)

For custom statistics, you can use session_blocks_sql to execute a single read-only SELECT/WITH against the public table structure (write operations and multiple statements will be rejected; query_only is enabled at the connection layer).

Use Cases and Notes

Who it’s for: Developers who run multiple sessions and workspaces in DSH long-term; those who need to search content by block, filter agent output by reasoning length or time window, isolate retrieval scope by cwd, or want to coexist with the official event index without modifying Harness source code.

Be aware:

  • The plugin runs with current DSH process permissions, reading session logs and building indexes in local SQLite. Before installation, please read the GitHub source code and MIT license, and evaluate whether to include it in your profile.
  • Only indexed sessions are searchable; sessions not scanned before the first full completion will be missing, you can specify IDs via session_blocks_list to pull them in first.
  • Chinese FTS uses substring semantics, single-character queries have a wide surface, suggest using small limit; upgrades involving STORE_SCHEMA_VERSION changes will automatically rebuild derived tables, index size may increase (README provides magnitude explanations: mixed Chinese-English about +14%, pure Chinese about +71%).
  • SkillHub (directory page) is a community plugin directory, with no official affiliation with DeepSeek / 幻方; the DSH ecosystem itself is an “everything is a plugin” extension model.

Conclusion

dsh-better-session-query provides block-level FTS5 index in addition to the official session-query: blocks can be searched, filtered, and read, with progressive background database building, and runs in parallel with the event-level index. If your pain point is “events are too coarse, reasoning blocks and tool blocks can’t be separated”, you can follow the README to install the package into your profile, first check coverage with session_blocks_status, then query by combining workspace and block types.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye