docs(session): address remaining list tool review notes

- Name the model-visible page limits once and derive the schema text from them.
- Type the intermediate Session rows and make list_workspace's execute async.
- Document that blank Sessions are listed and that unscoped listing has unit
  coverage only.
- State that the Workspace registry adds no model-visible surface of its own
  while the optional listing tools expose its metadata.
This commit is contained in:
Dudu-0223 committed 2026-11-16 13:25:42 +08:00
1 parent a65aacaa6a
commit 01aafcb4e9
11 files changed
+26 -17

No files matched your search

+2 -2
View File
@@ -3,8 +3,8 @@
# After editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write docs/subsystems/workspace.md
/workspaces:
en: 183fd2f466e3279c
zh: 6e79009b7294c240
en: 70865308120d0b14
zh: fe5d7406141657e1
/workspaces/identity:
en: d61a7e78bbc1fb56
zh: 8397869f70cd5b28
+1 -1
View File
@@ -2,7 +2,7 @@
English | [中文](workspace.zh.md)
A workspace is the persistent record of a directory the user works in: a stable id over a canonical path, a display title, and the ordered account of sessions that belong to it. The subsystem is one package ([dsh-workspace](../../packages/workspace/workspace), `ctx.workspaceRegistry`) — an optional host-side capability, not part of the agent-loop spine, and invisible to models (no tools, no prompt text, no session events). It stores its records through the [storage domain form](storage.md) and validates session membership against [`SessionHeader.cwd`](persistence.md#sessionheader--metadata-beside-the-log), so `storageDomain` and `sessionPersistence` are mandatory startup dependencies: an unavailable persistence peer leaves the plugin pending rather than being mistaken for an empty history. Design record: [domain KV storage Agent Note](../../.agents/notes/proposed/architecture/2026-07-24-domain-kv-storage-and-workspace.md); bootstrap and GUI ordering: [Workspace UI product-flow Agent Note](../../.agents/notes/archived/feature/2026-07-25-workspace-ui-product-flow.md).
A workspace is the persistent record of a directory the user works in: a stable id over a canonical path, a display title, and the ordered account of sessions that belong to it. The subsystem is one package ([dsh-workspace](../../packages/workspace/workspace), `ctx.workspaceRegistry`) — an optional host-side capability, not part of the agent-loop spine, and adds no model-visible surface of its own (no tools, no prompt text, no session events); the optional [listing tools](../../packages/session-query/tool-session-list) expose Workspace IDs, titles, and paths to models that are granted them. It stores its records through the [storage domain form](storage.md) and validates session membership against [`SessionHeader.cwd`](persistence.md#sessionheader--metadata-beside-the-log), so `storageDomain` and `sessionPersistence` are mandatory startup dependencies: an unavailable persistence peer leaves the plugin pending rather than being mistaken for an empty history. Design record: [domain KV storage Agent Note](../../.agents/notes/proposed/architecture/2026-07-24-domain-kv-storage-and-workspace.md); bootstrap and GUI ordering: [Workspace UI product-flow Agent Note](../../.agents/notes/archived/feature/2026-07-25-workspace-ui-product-flow.md).
Source: [`packages/workspace/workspace/src/types.ts`](../../packages/workspace/workspace/src/types.ts)
+1 -1
View File
@@ -2,7 +2,7 @@
[English](workspace.md) | 中文
工作区(workspace)是用户工作目录的持久记录:一个建立在规范路径之上的稳定 id、一个显示标题,以及归属于它的会话的有序账本。该子系统是单个包(package)([dsh-workspace](../../packages/workspace/workspace),`ctx.workspaceRegistry`)——一项宿主侧可选能力,不属于 agent loop(智能体循环)主干,并且对模型不可见(没有工具、没有提示词文本、没有会话事件)。它通过[存储领域数据形式](storage.zh.md)存储自己的记录,并对照 [`SessionHeader.cwd`](persistence.zh.md#sessionheader--metadata-beside-the-log) 校验会话成员资格,因此 `storageDomain` 与 `sessionPersistence` 是必需的启动依赖:持久化这一依赖不可用时,插件保持 pending,而不是把这种不可用误当作空历史。设计记录:[领域 KV 存储 Agent Note(agent 决策记录)](../../.agents/notes/proposed/architecture/2026-07-24-domain-kv-storage-and-workspace.zh.md);引导与 GUI 顺序:[Workspace UI 产品流程 Agent Note](../../.agents/notes/archived/feature/2026-07-25-workspace-ui-product-flow.md)。
工作区(workspace)是用户工作目录的持久记录:一个建立在规范路径之上的稳定 id、一个显示标题,以及归属于它的会话的有序账本。该子系统是单个包(package)([dsh-workspace](../../packages/workspace/workspace),`ctx.workspaceRegistry`)——一项宿主侧可选能力,不属于 agent loop(智能体循环)主干,并且自身不增加模型可见内容(没有工具、没有提示词文本、没有会话事件);可选的[列表工具](../../packages/session-query/tool-session-list)会把 Workspace ID、标题与路径提供给获准使用它们的模型。它通过[存储领域数据形式](storage.zh.md)存储自己的记录,并对照 [`SessionHeader.cwd`](persistence.zh.md#sessionheader--metadata-beside-the-log) 校验会话成员资格,因此 `storageDomain` 与 `sessionPersistence` 是必需的启动依赖:持久化这一依赖不可用时,插件保持 pending,而不是把这种不可用误当作空历史。设计记录:[领域 KV 存储 Agent Note(agent 决策记录)](../../.agents/notes/proposed/architecture/2026-07-24-domain-kv-storage-and-workspace.zh.md);引导与 GUI 顺序:[Workspace UI 产品流程 Agent Note](../../.agents/notes/archived/feature/2026-07-25-workspace-ui-product-flow.md)。
源码:[`packages/workspace/workspace/src/types.ts`](../../packages/workspace/workspace/src/types.ts)
@@ -48,8 +48,8 @@
en: 0e201fbbe37798d8
zh: fd4bd41e7393c234
/deepseek-ai-dsh-tool-session-list/known-limitations-and-deferred-work:
en: f0b57c2f2e7a0984
zh: ed80800cb0d021c8
en: 2c53c1fc603e0ff2
zh: 99a58f1e0e3c27fc
/deepseek-ai-dsh-tool-session-list/known-limitations-and-deferred-work/dev-note:
en: e67f633dc6fe7773
zh: e88aeb617ffb74ea
@@ -111,6 +111,8 @@ These constraints affect consumers of the lists.
- **Cold metadata can be missing or stale** — listing never rebuilds it by reading the full log. A `null` title can mean either no title or unavailable title metadata.
- **Pagination is not a stable snapshot** — concurrent registry or Session changes can move entries between calls. Session listing reads every candidate before selecting a page, so the page size does not bound total work; an unscoped call scales with the Session count.
- **Blank sessions are listed** — a Session without a turn, such as a Workspace's unused new Session, is a regular result; its `updated_at` equals `created_at` and its title is usually `null`.
- **Unscoped listing has unit coverage only** — the recorded headless replay passes `workspace_id` on every `list_session` call, so enumeration without a Workspace runs only in unit tests.
- **Metadata access is runtime-wide** — callers needing per-agent Workspace authorization require a separately defined access policy before these tools are enabled for them.
<a id="dev-note"></a>
@@ -111,6 +111,8 @@ kind: "package-reference"
- **冷元数据可能缺失或过期**——列表不会通过读取完整日志重建它。标题为 `null` 可能表示没有标题,也可能表示标题元数据不可用。
- **分页不是稳定快照**——并发的注册表或 Session 变化可能让条目在多次调用间移动。会话列表先读取全部候选项,再选取一页,因此每页大小不限制总工作量;不指定范围的调用随 Session 总数增长。
- **空白会话也会列出**——还没有 turn 的 Session(例如 Workspace 中未使用的新 Session)是普通结果;它的 `updated_at` 等于 `created_at`,标题通常为 `null`。
- **不指定范围的列表只有单测覆盖**——录制的 headless 回放中每次 `list_session` 调用都带 `workspace_id`,因此不指定 Workspace 的枚举只在单元测试中运行。
- **元数据访问覆盖整个运行时**——需要逐 agent Workspace 授权的调用者,必须先定义独立的访问策略,再为其启用这些工具。
<a id="dev-note"></a>
@@ -5,7 +5,7 @@
import type { Context } from '@deepseek-ai/cordis'
import { defineTool } from '@deepseek-ai/dsh-tools'
import { listSessions, listWorkspaces } from './list.ts'
import { DEFAULT_PAGE_LIMIT, listSessions, listWorkspaces, MAX_PAGE_LIMIT } from './list.ts'
/** Cordis plugin identity. */
export const name = 'tool-session-list'
@@ -13,7 +13,7 @@ export const name = 'tool-session-list'
export const inject = ['tools', 'sessions', 'sessionQuery', 'workspaceRegistry', 'sessionProjections']
const pagination = {
limit: { type: 'integer', description: 'Maximum entries to return, from 1 to 100. Defaults to 20.' },
limit: { type: 'integer', description: `Maximum entries to return, from 1 to ${String(MAX_PAGE_LIMIT)}. Defaults to ${String(DEFAULT_PAGE_LIMIT)}.` },
offset: { type: 'integer', description: 'Number of matching entries to skip. Defaults to 0.' },
} as const
@@ -44,7 +44,7 @@ export function apply(ctx: Context): void {
render: (_args, value) => [{ type: 'text', text: JSON.stringify(value) }],
},
isConcurrencySafe: () => true,
execute: (args, exec) => Promise.resolve(listWorkspaces(ctx, args, exec.signal)),
execute: async (args, exec) => listWorkspaces(ctx, args, exec.signal),
presentCall: args => ({ card: 'generic', title: 'List workspaces', kind: 'read', rawInput: args }),
}))
ctx.tools.register(defineTool({
@@ -35,16 +35,21 @@ interface SessionListItem {
updated_at: string
}
/** Entries per page when the model passes no `limit`; part of the model-visible schema. */
export const DEFAULT_PAGE_LIMIT = 20
/** Largest accepted `limit`; part of the model-visible schema. */
export const MAX_PAGE_LIMIT = 100
/**
* Resolve pagination before reading any registry or persistence data.
* @param input - model pagination arguments.
* @returns the validated count and starting index.
*/
export function resolvePage(input: PageInput): { limit: number; offset: number } {
const limit = input.limit ?? 20
const limit = input.limit ?? DEFAULT_PAGE_LIMIT
const offset = input.offset ?? 0
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) {
throw new ToolArgsError(['limit must be an integer from 1 to 100'])
if (!Number.isSafeInteger(limit) || limit < 1 || limit > MAX_PAGE_LIMIT) {
throw new ToolArgsError([`limit must be an integer from 1 to ${String(MAX_PAGE_LIMIT)}`])
}
if (!Number.isSafeInteger(offset) || offset < 0) {
throw new ToolArgsError(['offset must be a non-negative safe integer'])
@@ -99,7 +104,7 @@ export async function listSessions(
headers = workspace.getSessionHeaders()
}
const archived = new Set(ctx.workspaceRegistry.archivedSessionIds)
const items = []
const items: Array<Omit<SessionListItem, 'updated_at'> & { updatedAt: number }> = []
for (const header of headers) {
if (header.origin === 'subagent') continue
if (archived.has(header.id) !== (input.archived ?? false)) continue
@@ -9,8 +9,8 @@
en: 7a12adba4e7766e3
zh: f6d5c8374f4512c8
/deepseek-ai-dsh-workspace/summary:
en: 30aea62cabd8e8a8
zh: b22b30ef08fd4713
en: 587ea2786e0c12a6
zh: 6bb61ba4379886b4
/deepseek-ai-dsh-workspace/table-of-contents:
en: d152484eb41ac6b4
zh: 09388d293f9be9cb
+1 -1
View File
@@ -9,7 +9,7 @@ English | [中文](README.zh.md)
## Summary
Use this package to keep an ordered, persistent list of project directories and the sessions run in each directory. Hosts can build project sidebars, hide sessions from grouping without deleting their histories, and remove projects without deleting folders, files, or sessions. Re-adding a removed directory creates a fresh project; an existing project's sessions stay grouped when its directory disappears. Choose it for GUI or host workflows that need durable project grouping; it is invisible to models and adds no prompt or request-context cost, but requires session persistence and storage backends.
Use this package to keep an ordered, persistent list of project directories and the sessions run in each directory. Hosts can build project sidebars, hide sessions from grouping without deleting their histories, and remove projects without deleting folders, files, or sessions. Re-adding a removed directory creates a fresh project; an existing project's sessions stay grouped when its directory disappears. Choose it for GUI or host workflows that need durable project grouping; it adds no model-visible surface or prompt or request-context cost of its own (the optional [listing tools](../../session-query/tool-session-list/README.md) expose Workspace metadata to models), but requires session persistence and storage backends.
## Table of Contents
+1 -1
View File
@@ -9,7 +9,7 @@ kind: "package-reference"
## 概述
使用此包可以维护一个有序、持久的项目目录列表,以及在每个目录中运行的会话。宿主可以构建项目侧边栏、在不删除历史的情况下把会话从分组中隐藏,并在不删除文件夹、文件或会话的情况下移除项目。重新添加已移除的目录会创建一个全新项目;已有项目的目录消失时,其会话仍保持原分组。需要持久项目分组的 GUI 或宿主工作流适合使用它;它对模型不可见,不增加提示词或请求上下文成本,但需要会话持久化与存储后端。
使用此包可以维护一个有序、持久的项目目录列表,以及在每个目录中运行的会话。宿主可以构建项目侧边栏、在不删除历史的情况下把会话从分组中隐藏,并在不删除文件夹、文件或会话的情况下移除项目。重新添加已移除的目录会创建一个全新项目;已有项目的目录消失时,其会话仍保持原分组。需要持久项目分组的 GUI 或宿主工作流适合使用它;它自身不增加模型可见内容,也不增加提示词或请求上下文成本(可选的[列表工具](../../session-query/tool-session-list/README.zh.md)会向模型提供 Workspace 元数据),但需要会话持久化与存储后端。
## 目录