feat(working-directory): route sandbox, file views, and discovery through the Session workspace root
Every consumer that describes the project to the user or draws the write boundary reads rootOf(session) instead of the header directory: the sandbox workspace-write policy, the workspace file service and desktop file drag, the change recorder, the client Files tree, deliverables, open-in-app actions and Session rows, new sidebar terminals, @ file candidates, the skill catalog, project-instruction discovery, and the LSP workspace. The model's relative paths keep resolving from the current directory. The sandbox policy derives a linked checkout's Git administration directory and common directory from its .git pointer and grants them as extra writable roots; tool executions wait for that derivation through prepare(), and Session creation and directory changes start it early. Windows ACL confinement grants each extra root a standing ACE through a repeatable --writable runner argument instead of refusing the policy. Refs #2658
This commit is contained in:
1 parent
a657b6b187
commit
b6aa7b437c
146 files changed
+1426
-466
No files matched your search
+2
-2
@@ -9,8 +9,8 @@
|
||||
en: 31fba384d90ce7d2
|
||||
zh: f8b814868f3280c3
|
||||
/agent-note-session-working-directory/decision:
|
||||
en: f8af193899e790ad
|
||||
zh: b3df4a59727ff3a3
|
||||
en: 6456081e9e73dbd2
|
||||
zh: 78a46fb83a4f0868
|
||||
/agent-note-session-working-directory/alternatives-considered:
|
||||
en: f0995feb9b6bcce8
|
||||
zh: 97417085fd17f70f
|
||||
|
||||
@@ -16,11 +16,11 @@ The `dsh-base` composition mounts `working_directory({ cd? })` globally. The too
|
||||
|
||||
Required user-context snapshots carry the current value; each committed change attempts to queue a notice through the ordinary Agent inbox. Cancellation or disposal may discard unadmitted notices while the directory event survives for subsequent requests. The original project is the recovery destination when the selected directory disappears. Missing recovery destinations produce an error. Write permissions remain independent.
|
||||
|
||||
Subagents capture the parent's current directory or an explicit override and commit their selected directory after inherited history. Existing processes, terminals, and persistent shells keep their process-local directory. Project instructions, skills, and completion follow the effective directory without changing Session identity, grouping, or runtime composition.
|
||||
Subagents capture the parent's current directory or an explicit override and commit their selected directory after inherited history. Existing processes, terminals, and persistent shells keep their process-local directory. The model's file and process tools follow the effective directory; project instructions, skills, completion, and the sandbox boundary follow the [workspace root](2026-11-03-session-workspace-root.md) without changing Session identity, grouping, or runtime composition.
|
||||
|
||||
Live Session skill catalogs and file completion validate through the same directory owner. These reads can commit recovery and queue its notice before discovery, keeping discovered files and subsequent operations tied to the committed Session directory. Cold skill catalogs read the recorded projection without activating an Agent.
|
||||
Live Session skill catalogs and file completion validate through the same directory owner, then read the workspace root. These reads can commit recovery and queue its notice before discovery, keeping discovered files and subsequent operations tied to the committed Session directories. Cold skill catalogs read the recorded root projection without activating an Agent.
|
||||
|
||||
Web sidebar terminal environment lookup reads the effective directory without filesystem validation or recovery, so a missing directory does not prevent reconnecting to a retained terminal. New terminal creation validates and recovers through the directory owner before spawning; the process keeps that directory independently of later Session changes.
|
||||
Web sidebar terminal environment lookup reads the workspace root without filesystem validation or recovery, so a missing directory does not prevent reconnecting to a retained terminal. New terminal creation validates and recovers through the directory owner before spawning in the workspace root; the process keeps that directory independently of later Session changes.
|
||||
|
||||
Playwright MCP and Chrome DevTools MCP validate the effective directory when acquiring a Session's MCP connection and use it to launch the server. Later directory changes do not restart the retained server or change its process directory.
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@ Status: implemented
|
||||
|
||||
必需的用户上下文快照携带当前值;每次已提交变更都会尝试通过普通 Agent 收件箱排入通知。取消或销毁可能丢弃尚未进入请求的通知,但目录事件仍然保留,供后续请求使用。所选目录消失时恢复到原始项目。恢复目录也消失时返回错误。写权限保持独立。
|
||||
|
||||
子代理捕获父代理当前目录或显式覆盖值,并在继承历史之后提交选定目录。已有进程、终端和持久 shell 保留进程局部目录。项目指令、技能和补全跟随有效目录,不改变 Session 身份、归属或运行时组合。
|
||||
子代理捕获父代理当前目录或显式覆盖值,并在继承历史之后提交选定目录。已有进程、终端和持久 shell 保留进程局部目录。模型的文件与进程工具跟随有效目录;项目指令、技能、补全和沙箱边界跟随[工作区根](2026-11-03-session-workspace-root.zh.md),不改变 Session 身份、归属或运行时组合。
|
||||
|
||||
活跃 Session 的技能目录与文件补全通过同一个目录 owner 验证目录。这些读取可在发现操作之前提交恢复并排入通知,使发现的文件与后续操作关联到已提交的 Session 目录。冷态技能目录读取已记录的投影,不激活 Agent。
|
||||
活跃 Session 的技能目录与文件补全通过同一个目录 owner 验证目录,再读取工作区根。这些读取可在发现操作之前提交恢复并排入通知,使发现的文件与后续操作关联到已提交的 Session 目录。冷态技能目录读取已记录的根投影,不激活 Agent。
|
||||
|
||||
Web 侧栏终端的环境查询读取有效目录,不验证文件系统或执行恢复,因此目录缺失不会阻止重新连接保留的终端。新终端在创建进程前通过目录 owner 验证和恢复目录;后续 Session 目录变更不会改变该进程的目录。
|
||||
Web 侧栏终端的环境查询读取工作区根,不验证文件系统或执行恢复,因此目录缺失不会阻止重新连接保留的终端。新终端在创建进程前通过目录 owner 验证和恢复目录,并在工作区根中启动;后续 Session 目录变更不会改变该进程的目录。
|
||||
|
||||
Playwright MCP 和 Chrome DevTools MCP 在获取 Session 的 MCP 连接时验证有效目录,并在该目录启动服务器。后续目录变更不会重启保留的服务器,也不会改变其进程目录。
|
||||
|
||||
|
||||
@@ -11,12 +11,9 @@
|
||||
/agent-note-session-workspace-root/decision:
|
||||
en: 2aa85360b92e618d
|
||||
zh: 079b815ab1e6ece4
|
||||
/agent-note-session-workspace-root/deferred:
|
||||
en: d8167590081dfa4e
|
||||
zh: 208630aac853773b
|
||||
/agent-note-session-workspace-root/alternatives-considered:
|
||||
en: 9d267bf955897821
|
||||
zh: 45b7d2cddd34a811
|
||||
en: d41da217dfc05ac5
|
||||
zh: 3b4a17c255c2c5ae
|
||||
/agent-note-session-workspace-root/consequences:
|
||||
en: 9a6bdd11a719b7ea
|
||||
zh: 9350f11c1097804b
|
||||
en: 726aa3a9da3295c8
|
||||
zh: 569cb4c99d644fd2
|
||||
@@ -16,10 +16,6 @@ Each Session has three directories with one owner each. `header.cwd` remains the
|
||||
|
||||
Worktree creation enters the checkout through `relocate`; leaving it is the existing `set` back into the original project, which the anchor rule turns into a root change. A child subagent keeps the parent's original project in its header; when the parent's root is another checkout and the child starts inside it, the child relocates into that root, so its root matches the parent's. The user-context snapshot adds a `Workspace root` line while the cursor differs from the root, and a change notice ends with the new root when the change selects another root. The SDK working-directory methods return `{ cwd, root }`, and `getWorkspaceRoot` (`get_workspace_root` in Python) reads the root.
|
||||
|
||||
## Deferred
|
||||
|
||||
The sandbox write boundary, the workspace file service, desktop file drag, the change recorder, and the client file tree, deliverables, open-in-app actions, and Session rows still read `header.cwd`. The sidebar terminal, `@` file candidates, the skill catalog, project-instruction discovery, and the LSP workspace still read the current directory although they belong to the root. Until those consumers move, they behave as they did before this decision, and a worktree outside the original project is writable only where the original project's boundary already allows it.
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
**Rewrite the header on relocation.** The header is identity metadata for storage, grouping, and permission roots; the [working-directory note](2026-09-13-session-working-directory.md) rejected rewriting it, and every peer product keeps an immutable origin.
|
||||
@@ -32,6 +28,10 @@ The sandbox write boundary, the workspace file service, desktop file drag, the c
|
||||
|
||||
**One new Session per worktree, never a relocation.** The model-facing worktree tool already continues one Session in the new checkout; forge's new-Session worktree path and that tool both resolve to the same relocation.
|
||||
|
||||
The consumers divide by who perceives the directory. The model's file, search, and process tools resolve relative paths from the current directory. Everything the user sees or that describes the project reads the workspace root: the sandbox `workspace-write` boundary, the workspace file service and desktop file drag, the change recorder, the Files tree, deliverables, open-in-app actions and Session rows, new sidebar terminals, `@` file candidates, the skill catalog, project-instruction discovery, and the LSP workspace. The user context names the root beside the current directory while they differ, so the model can resolve a user's root-relative `@` reference.
|
||||
|
||||
The sandbox policy derives the Git administration directories of a linked checkout from the root's `.git` pointer and `commondir` through the execution-world filesystem, keeps them per root for the process lifetime, and adds them to the resolved extra writable roots; tool executions wait for that derivation, and Session creation and directory changes start it early. Windows ACL confinement grants each extra root a standing ACE under the workspace SID instead of refusing the policy. After a relocation the original project is writable only through the Git administration directories, not as a whole.
|
||||
|
||||
## Consequences
|
||||
|
||||
Consumers can ask the directory service three questions with three answers: where the Session started, which checkout it works in, and where relative paths resolve. Existing logs change meaning for no reader: they hold no anchor, so the root is the original project. Anchors compare as recorded, so a header recorded through a symlink or with different casing never contains the canonical paths later changes record; the root then stays on the original project. The worktree snapshot fixture and the directory notices carry the root text. Moving the consumers listed under Deferred is a separate change.
|
||||
Consumers can ask the directory service three questions with three answers: where the Session started, which checkout it works in, and where relative paths resolve. Existing logs change meaning for no reader: they hold no anchor, so the root is the original project. Anchors compare as recorded, so a header recorded through a symlink or with different casing never contains the canonical paths later changes record; the root then stays on the original project. A Session opened inside a linked worktree can run `git commit` under `workspace-write`, and the shared `.git`, including its hooks and configuration, is writable from that Session as it already is from a Session in the main checkout. A `cd` inside the root no longer reloads the project-instruction baseline or the skill catalog. The worktree snapshot fixture and the directory notices carry the root text.
|
||||
@@ -16,10 +16,6 @@ Status: implemented
|
||||
|
||||
工作树创建通过 `relocate` 进入检出目录;离开它就是既有的 `set` 回到原始项目,锚规则将其变为根的变化。子代理在 header 中保留父级的原始项目;当父级的根是另一个检出目录且子级在其中启动时,子级迁入该根,因此子级的根与父级一致。光标与根不同时,用户上下文快照增加一行 `Workspace root`,选中另一个根的变更在通知末尾给出新根。SDK 的工作目录方法返回 `{ cwd, root }`,`getWorkspaceRoot`(Python 中为 `get_workspace_root`)读取根。
|
||||
|
||||
## Deferred
|
||||
|
||||
沙箱写边界、工作区文件服务、桌面文件拖拽、变更记录器,以及客户端的文件树、交付物、在应用中打开操作和 Session 行仍读取 `header.cwd`。侧栏终端、`@` 文件候选、技能目录、项目指令发现和 LSP 工作区仍读取当前目录,尽管它们属于根。在这些消费方迁移之前,它们的行为与本决策之前相同,原始项目之外的工作树仅在原始项目的边界已经允许之处可写。
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
**迁移时改写 header。** header 是用于存储、分组和权限根的身份元数据;[工作目录记录](2026-09-13-session-working-directory.zh.md)否决了改写它,所有同类产品也都保留不可变的起点。
|
||||
@@ -32,6 +28,10 @@ Status: implemented
|
||||
|
||||
**每个工作树一个新 Session,从不迁移。** 面向模型的工作树工具已经让同一个 Session 在新检出目录中继续;forge 的新 Session 工作树路径与该工具最终都落到同一种迁移。
|
||||
|
||||
消费方按感知目录的对象划分。模型的文件、搜索与进程工具从当前目录解析相对路径。用户看到的、以及描述项目的一切都读取工作区根:沙箱 `workspace-write` 边界、工作区文件服务与桌面文件拖拽、变更记录器、文件树、交付物、在应用中打开操作与 Session 行、新开的侧栏终端、`@` 文件候选、技能目录、项目指令发现和 LSP 工作区。光标与根不同时,用户上下文在当前目录旁给出根,使模型能够解析用户以根为基准的 `@` 引用。
|
||||
|
||||
沙箱策略通过执行环境的文件系统,从根的 `.git` 指针与 `commondir` 推导出链接检出目录的 Git 管理目录,在进程生命周期内按根保留,并加入解析出的额外可写根;工具执行等待该推导完成,会话创建与目录变更提前启动它。Windows ACL 限制为每个额外根添加一条工作区 SID 的常驻 ACE,而不是拒绝该策略。迁移之后,原始项目只能通过 Git 管理目录写入,不再整体可写。
|
||||
|
||||
## Consequences
|
||||
|
||||
消费方可以向目录服务提出三个问题并得到三个答案:Session 从哪里开始、在哪个检出目录中工作、相对路径从哪里解析。既有日志对任何读者的含义都不变:它们没有锚,因此根就是原始项目。锚按记录原样比较,因此通过符号链接或以不同大小写记录的 header 永远不包含后续变更记录的规范路径;此时根停留在原始项目上。工作树快照夹具与目录通知携带根的文本。迁移 Deferred 中列出的消费方是另一次变更。
|
||||
消费方可以向目录服务提出三个问题并得到三个答案:Session 从哪里开始、在哪个检出目录中工作、相对路径从哪里解析。既有日志对任何读者的含义都不变:它们没有锚,因此根就是原始项目。锚按记录原样比较,因此通过符号链接或以不同大小写记录的 header 永远不包含后续变更记录的规范路径;此时根停留在原始项目上。在链接工作树内打开的 Session 可以在 `workspace-write` 下运行 `git commit`,共享的 `.git`(包括其钩子与配置)对该 Session 可写,正如它对主检出目录中的 Session 一样。根内部的 `cd` 不再重新加载项目指令基线或技能目录。工作树快照夹具与目录通知携带根的文本。
|
||||
@@ -39,6 +39,7 @@
|
||||
"@deepseek-ai/dsh-sandbox-policy": "workspace:*",
|
||||
"@deepseek-ai/dsh-util-workspace-path": "workspace:*",
|
||||
"@deepseek-ai/dsh-brand": "workspace:*",
|
||||
"@deepseek-ai/dsh-tool-executor-native": "workspace:*"
|
||||
"@deepseek-ai/dsh-tool-executor-native": "workspace:*",
|
||||
"@deepseek-ai/dsh-api-workspace-files": "workspace:*"
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
/** Resolve desktop-only file references through the active Host filesystem and Session. */
|
||||
import { createHash } from 'node:crypto'
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import { resolveWorkspaceFileScope } from '@deepseek-ai/dsh-api-workspace-files'
|
||||
import type {} from '@deepseek-ai/dsh-fs'
|
||||
import type {} from '@deepseek-ai/dsh-session'
|
||||
import type {} from '@deepseek-ai/dsh-session-persistence'
|
||||
import type {} from '@deepseek-ai/dsh-sandbox-policy'
|
||||
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
import { parseFileAddress } from '@deepseek-ai/dsh-util-workspace-path'
|
||||
@@ -17,6 +17,7 @@ export interface LocalDragResource {
|
||||
|
||||
/**
|
||||
* Authorize an unmodified local file through the composed filesystem's actual read operations.
|
||||
* Relative paths resolve from the same workspace root the workspace file service uses for the Session.
|
||||
* @param ctx - booted Desktop Host.
|
||||
* @param address - Session-scoped resource reference.
|
||||
* @param cancellation - caller cancellation, combined with the read deadline.
|
||||
@@ -25,17 +26,13 @@ export interface LocalDragResource {
|
||||
export async function localDragResource(ctx: Context, address: string, cancellation?: AbortSignal): Promise<LocalDragResource | null> {
|
||||
const resource = parseFileAddress(address)
|
||||
if (resource?.scope !== 'session') throw new Error('File drag requires a Session resource')
|
||||
const sessions = ctx.get('sessions')
|
||||
const persistence = ctx.get('sessionPersistence')
|
||||
const fs = ctx.get('fs')
|
||||
const policy = ctx.get('sandboxPolicy')
|
||||
if (fs === undefined || sessions === undefined || policy === undefined) throw new Error('File access unavailable')
|
||||
const sessionId = resource.sessionId as SessionId
|
||||
const header = sessions.get(sessionId)?.header ?? (await persistence?.stat(sessionId))?.header
|
||||
if (header === undefined) throw new Error('File drag Session unavailable')
|
||||
if (fs === undefined || ctx.get('sessions') === undefined || ctx.get('sandboxPolicy') === undefined) throw new Error('File access unavailable')
|
||||
const signal = cancellation === undefined ? AbortSignal.timeout(10_000) : AbortSignal.any([cancellation, AbortSignal.timeout(10_000)])
|
||||
signal.throwIfAborted()
|
||||
const cwd = header.cwd ?? policy.workspaceRoot
|
||||
const scope = await resolveWorkspaceFileScope(ctx, resource.sessionId as SessionId, signal)
|
||||
if (scope === undefined) throw new Error('File drag Session unavailable')
|
||||
const cwd = scope.workspaceRoot
|
||||
const entry = await fs.lstat(resource.path, { cwd }, signal)
|
||||
if (entry?.type !== 'file') return null
|
||||
const target = await fs.resolve(resource.path, { cwd, signal })
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"references": [
|
||||
{ "path": "../../vendor/cordis" },
|
||||
{ "path": "../../packages/core/agent" },
|
||||
{ "path": "../../packages/api/workspace-files/tsconfig.host.json" },
|
||||
{ "path": "../../packages/jobs/jobs" },
|
||||
{ "path": "../../packages/schedule/schedule" },
|
||||
{ "path": "../../packages/workspace/workspace" },
|
||||
|
||||
@@ -6,5 +6,5 @@
|
||||
en: 41d772192075e133
|
||||
zh: 5ef3da69b4de1d8a
|
||||
/capability-seams-and-core-services:
|
||||
en: 55650614a3f15f6a
|
||||
zh: 5c61a3b1085a700e
|
||||
en: 2a8998fb919f4e2e
|
||||
zh: eb7d61cb7c66d38c
|
||||
@@ -54,6 +54,14 @@ flowchart LR
|
||||
pkg_tool_pwsh["tool-pwsh"]
|
||||
pkg_subagent["subagent"]
|
||||
pkg_sdk_jsonrpc_server["sdk-jsonrpc-server"]
|
||||
pkg_sandbox_policy["sandbox-policy"]
|
||||
pkg_workspace_files["workspace-files"]
|
||||
pkg_terminal_controller["terminal-controller"]
|
||||
pkg_workspace_changes["workspace-changes"]
|
||||
pkg_file_reference_local["file-reference-local"]
|
||||
pkg_tool_skill["tool-skill"]
|
||||
pkg_agent_instructions["agent-instructions"]
|
||||
pkg_tool_lsp["tool-lsp"]
|
||||
pkg_mcp_resources["mcp-resources"]
|
||||
svc_mcpResources["ctx.mcpResources<br/>Scoped MCP resource access"]
|
||||
pkg_mcp_client["mcp-client"]
|
||||
@@ -112,7 +120,6 @@ flowchart LR
|
||||
svc_settingsController["ctx.settingsController<br/>Host settings-surface Remote controller"]
|
||||
pkg_api_workspace_files["api-workspace-files"]
|
||||
svc_workspaceFiles["ctx.workspaceFiles<br/>Host workspace file Remote service"]
|
||||
pkg_workspace_changes["workspace-changes"]
|
||||
svc_workspaceChanges["ctx.workspaceChanges<br/>Host per-turn changed-file summaries"]
|
||||
pkg_api_terminal_controller["api-terminal-controller"]
|
||||
svc_terminalController["ctx.terminalController<br/>Session interactive terminal Remote controller"]
|
||||
@@ -170,7 +177,6 @@ flowchart LR
|
||||
pkg_tool_session_query["tool-session-query"]
|
||||
pkg_file_reference["file-reference"]
|
||||
svc_fileReferences["ctx.fileReferences<br/>File reference discovery"]
|
||||
pkg_file_reference_local["file-reference-local"]
|
||||
svc_sessionReferenceResolver["ctx.sessionReferenceResolver<br/>Cross-session snapshot preparation"]
|
||||
pkg_session_title["session-title"]
|
||||
svc_sessionTitle["ctx.sessionTitle<br/>Log-backed session titles"]
|
||||
@@ -184,7 +190,6 @@ flowchart LR
|
||||
svc_tools["ctx.tools<br/>Scoped tool registry and executor selection"]
|
||||
pkg_tool_ask_user["tool-ask-user"]
|
||||
pkg_tool_cordis["tool-cordis"]
|
||||
pkg_tool_skill["tool-skill"]
|
||||
pkg_tool_todo["tool-todo"]
|
||||
pkg_user_questions["user-questions"]
|
||||
svc_userQuestions["ctx.userQuestions<br/>Human question/answer seam"]
|
||||
@@ -241,7 +246,6 @@ flowchart LR
|
||||
pkg_sandbox["sandbox"]
|
||||
svc_sandbox["ctx.sandbox<br/>Process-sandbox seam"]
|
||||
pkg_sandbox_local["sandbox-local"]
|
||||
pkg_sandbox_policy["sandbox-policy"]
|
||||
svc_sandboxPolicy["ctx.sandboxPolicy<br/>Sandbox policy home"]
|
||||
pkg_fs_sandbox["fs-sandbox"]
|
||||
pkg_user_approval["user-approval"]
|
||||
@@ -309,7 +313,6 @@ flowchart LR
|
||||
pkg_webhook_github["webhook-github"]
|
||||
pkg_lsp["lsp"]
|
||||
svc_lsp["ctx.lsp<br/>Language-server navigation seam"]
|
||||
pkg_tool_lsp["tool-lsp"]
|
||||
pkg_cordis_host_runner["cordis-host-runner"]
|
||||
svc_dynamicCordisRunner["ctx.dynamicCordisRunner<br/>Dynamic Cordis package host runner"]
|
||||
svc_cordisInspect["ctx.cordisInspect<br/>Dynamic Cordis inspect registry"]
|
||||
@@ -635,12 +638,20 @@ flowchart LR
|
||||
svc_webhookRuntime --> pkg_webhook_github
|
||||
svc_workflowEngine --> pkg_tool_ralph
|
||||
svc_workflowEngine --> pkg_tool_workflow
|
||||
svc_workingDirectory --> pkg_agent_instructions
|
||||
svc_workingDirectory --> pkg_file_reference_local
|
||||
svc_workingDirectory --> pkg_sandbox_policy
|
||||
svc_workingDirectory --> pkg_sdk_jsonrpc_server
|
||||
svc_workingDirectory --> pkg_subagent
|
||||
svc_workingDirectory --> pkg_terminal_controller
|
||||
svc_workingDirectory --> pkg_tool_bash
|
||||
svc_workingDirectory --> pkg_tool_fs
|
||||
svc_workingDirectory --> pkg_tool_lsp
|
||||
svc_workingDirectory --> pkg_tool_pwsh
|
||||
svc_workingDirectory --> pkg_tool_skill
|
||||
svc_workingDirectory --> pkg_tool_working_directory
|
||||
svc_workingDirectory --> pkg_workspace_changes
|
||||
svc_workingDirectory --> pkg_workspace_files
|
||||
svc_workspaceRegistry --> pkg_api_session_controller
|
||||
svc_workspaceRegistry --> pkg_api_workspace_controller
|
||||
svc_worktrees --> pkg_experimental_tool_worktree
|
||||
@@ -664,7 +675,7 @@ flowchart LR
|
||||
| `ctx.forgeSession` | `service` | [`experimental-forge-session`](../packages/experimental/forge-session) | - | [`experimental-client-ui-forge`](../packages/experimental/client-ui-forge) | - | A Session projection derives bindings from shell results and binding records and publishes their URLs without status to clients; push results trigger head-branch discovery, and Session watchers poll bound change requests through the forge registry. |
|
||||
| `ctx.forgePanel` | `service` | [`experimental-client-ui-forge`](../packages/experimental/client-ui-forge) | - | - | - | Streams one panel state per followed Session: Git inspection using Session permissions, the recognized code host and its sign-in, and the bound change requests with polled status. |
|
||||
| `ctx.worktrees` | `seam` | [`experimental-worktree`](../packages/experimental/worktree) | [`experimental-worktree`](../packages/experimental/worktree) | [`experimental-tool-worktree`](../packages/experimental/tool-worktree) | - | Explicit experimental creation from a pinned local commit. Existing write permissions govern checkout and shared Git metadata; the working-directory service owns the resulting Session directory. |
|
||||
| `ctx.workingDirectory` | `seam` | [`working-directory`](../packages/session/working-directory) | [`working-directory`](../packages/session/working-directory) | [`tool-working-directory`](../packages/session/tool-working-directory), [`tool-fs`](../packages/fs/tool-fs), [`tool-bash`](../packages/shell/tool-bash), [`tool-pwsh`](../packages/shell/tool-pwsh), [`subagent`](../packages/subagent/subagent), [`sdk-jsonrpc-server`](../packages/sdk/server) | - | Two Session projections own the effective execution directory and the workspace root it is in. The filesystem validates changes; user context reports them while original metadata and write grants stay fixed. |
|
||||
| `ctx.workingDirectory` | `seam` | [`working-directory`](../packages/session/working-directory) | [`working-directory`](../packages/session/working-directory) | [`tool-working-directory`](../packages/session/tool-working-directory), [`tool-fs`](../packages/fs/tool-fs), [`tool-bash`](../packages/shell/tool-bash), [`tool-pwsh`](../packages/shell/tool-pwsh), [`subagent`](../packages/subagent/subagent), [`sdk-jsonrpc-server`](../packages/sdk/server), [`sandbox-policy`](../packages/sandbox/sandbox-policy), `workspace-files`, `terminal-controller`, [`workspace-changes`](../packages/deliverables/workspace-changes), [`file-reference-local`](../packages/context/file-reference-local), [`tool-skill`](../packages/skill/tool-skill), [`agent-instructions`](../packages/context/agent-instructions), [`tool-lsp`](../packages/lsp/tool-lsp) | - | Two Session projections own the effective execution directory and the workspace root it is in. The filesystem validates changes and user context reports them; model tools follow the directory while the sandbox boundary, file views, and discovery follow the root, and original metadata stays fixed. |
|
||||
| `ctx.mcpResources` | `seam` | [`mcp-resources`](../packages/mcp/mcp-resources) | [`mcp-client`](../packages/mcp/mcp-client) | [`mcp-resources`](../packages/mcp/mcp-resources) | - | Connection-owned providers serve shared resource tools in the calling agent scope. |
|
||||
| `ctx.browserUse` | `seam` | [`browser-use`](../packages/browser-use/browser-use) | [`experimental-browser-use-playwright-mcp`](../packages/experimental/browser-use-playwright-mcp), [`experimental-browser-use-chrome-devtools-mcp`](../packages/experimental/browser-use-chrome-devtools-mcp), [`experimental-browser-use-stagehand-native`](../packages/experimental/browser-use-stagehand-native) | [`experimental-browser-use-playwright-mcp`](../packages/experimental/browser-use-playwright-mcp), [`experimental-browser-use-chrome-devtools-mcp`](../packages/experimental/browser-use-chrome-devtools-mcp), [`experimental-browser-use-stagehand-native`](../packages/experimental/browser-use-stagehand-native) | - | One provider-owned name per service instance. Providers own their tools and browser resources per live Session; the shared service has no browser operation API. |
|
||||
| `ctx.computerUse` | `seam` | [`computer-use`](../packages/computer-use/computer-use) | [`experimental-computer-use-cua-driver-mcp`](../packages/experimental/computer-use-cua-driver-mcp), [`experimental-computer-use-cua-driver-native`](../packages/experimental/computer-use-cua-driver-native) | [`experimental-computer-use-cua-driver-mcp`](../packages/experimental/computer-use-cua-driver-mcp), [`experimental-computer-use-cua-driver-native`](../packages/experimental/computer-use-cua-driver-native) | - | One provider-owned name per service instance. Each provider also owns its model tools; the service has no common action API, runtime selection, or Session workflow lock. |
|
||||
|
||||
@@ -56,6 +56,14 @@ flowchart LR
|
||||
pkg_tool_pwsh["tool-pwsh"]
|
||||
pkg_subagent["subagent"]
|
||||
pkg_sdk_jsonrpc_server["sdk-jsonrpc-server"]
|
||||
pkg_sandbox_policy["sandbox-policy"]
|
||||
pkg_workspace_files["workspace-files"]
|
||||
pkg_terminal_controller["terminal-controller"]
|
||||
pkg_workspace_changes["workspace-changes"]
|
||||
pkg_file_reference_local["file-reference-local"]
|
||||
pkg_tool_skill["tool-skill"]
|
||||
pkg_agent_instructions["agent-instructions"]
|
||||
pkg_tool_lsp["tool-lsp"]
|
||||
pkg_mcp_resources["mcp-resources"]
|
||||
svc_mcpResources["ctx.mcpResources<br/>Scoped MCP resource access"]
|
||||
pkg_mcp_client["mcp-client"]
|
||||
@@ -114,7 +122,6 @@ flowchart LR
|
||||
svc_settingsController["ctx.settingsController<br/>Host settings-surface Remote controller"]
|
||||
pkg_api_workspace_files["api-workspace-files"]
|
||||
svc_workspaceFiles["ctx.workspaceFiles<br/>Host workspace file Remote service"]
|
||||
pkg_workspace_changes["workspace-changes"]
|
||||
svc_workspaceChanges["ctx.workspaceChanges<br/>Host per-turn changed-file summaries"]
|
||||
pkg_api_terminal_controller["api-terminal-controller"]
|
||||
svc_terminalController["ctx.terminalController<br/>Session interactive terminal Remote controller"]
|
||||
@@ -172,7 +179,6 @@ flowchart LR
|
||||
pkg_tool_session_query["tool-session-query"]
|
||||
pkg_file_reference["file-reference"]
|
||||
svc_fileReferences["ctx.fileReferences<br/>File reference discovery"]
|
||||
pkg_file_reference_local["file-reference-local"]
|
||||
svc_sessionReferenceResolver["ctx.sessionReferenceResolver<br/>Cross-session snapshot preparation"]
|
||||
pkg_session_title["session-title"]
|
||||
svc_sessionTitle["ctx.sessionTitle<br/>Log-backed session titles"]
|
||||
@@ -186,7 +192,6 @@ flowchart LR
|
||||
svc_tools["ctx.tools<br/>Scoped tool registry and executor selection"]
|
||||
pkg_tool_ask_user["tool-ask-user"]
|
||||
pkg_tool_cordis["tool-cordis"]
|
||||
pkg_tool_skill["tool-skill"]
|
||||
pkg_tool_todo["tool-todo"]
|
||||
pkg_user_questions["user-questions"]
|
||||
svc_userQuestions["ctx.userQuestions<br/>Human question/answer seam"]
|
||||
@@ -243,7 +248,6 @@ flowchart LR
|
||||
pkg_sandbox["sandbox"]
|
||||
svc_sandbox["ctx.sandbox<br/>Process-sandbox seam"]
|
||||
pkg_sandbox_local["sandbox-local"]
|
||||
pkg_sandbox_policy["sandbox-policy"]
|
||||
svc_sandboxPolicy["ctx.sandboxPolicy<br/>Sandbox policy home"]
|
||||
pkg_fs_sandbox["fs-sandbox"]
|
||||
pkg_user_approval["user-approval"]
|
||||
@@ -311,7 +315,6 @@ flowchart LR
|
||||
pkg_webhook_github["webhook-github"]
|
||||
pkg_lsp["lsp"]
|
||||
svc_lsp["ctx.lsp<br/>Language-server navigation seam"]
|
||||
pkg_tool_lsp["tool-lsp"]
|
||||
pkg_cordis_host_runner["cordis-host-runner"]
|
||||
svc_dynamicCordisRunner["ctx.dynamicCordisRunner<br/>Dynamic Cordis package host runner"]
|
||||
svc_cordisInspect["ctx.cordisInspect<br/>Dynamic Cordis inspect registry"]
|
||||
@@ -637,12 +640,20 @@ flowchart LR
|
||||
svc_webhookRuntime --> pkg_webhook_github
|
||||
svc_workflowEngine --> pkg_tool_ralph
|
||||
svc_workflowEngine --> pkg_tool_workflow
|
||||
svc_workingDirectory --> pkg_agent_instructions
|
||||
svc_workingDirectory --> pkg_file_reference_local
|
||||
svc_workingDirectory --> pkg_sandbox_policy
|
||||
svc_workingDirectory --> pkg_sdk_jsonrpc_server
|
||||
svc_workingDirectory --> pkg_subagent
|
||||
svc_workingDirectory --> pkg_terminal_controller
|
||||
svc_workingDirectory --> pkg_tool_bash
|
||||
svc_workingDirectory --> pkg_tool_fs
|
||||
svc_workingDirectory --> pkg_tool_lsp
|
||||
svc_workingDirectory --> pkg_tool_pwsh
|
||||
svc_workingDirectory --> pkg_tool_skill
|
||||
svc_workingDirectory --> pkg_tool_working_directory
|
||||
svc_workingDirectory --> pkg_workspace_changes
|
||||
svc_workingDirectory --> pkg_workspace_files
|
||||
svc_workspaceRegistry --> pkg_api_session_controller
|
||||
svc_workspaceRegistry --> pkg_api_workspace_controller
|
||||
svc_worktrees --> pkg_experimental_tool_worktree
|
||||
@@ -666,7 +677,7 @@ flowchart LR
|
||||
| `ctx.forgeSession` | `service` | [`experimental-forge-session`](../packages/experimental/forge-session) | - | [`experimental-client-ui-forge`](../packages/experimental/client-ui-forge) | - | Session 投影从 shell 结果与绑定记录派生绑定,并把不含状态的 URL 发布给客户端;推送结果触发按 head 分支的发现,Session 监听方通过 forge 注册表轮询已绑定的变更请求。 |
|
||||
| `ctx.forgePanel` | `service` | [`experimental-client-ui-forge`](../packages/experimental/client-ui-forge) | - | - | - | 为每个被跟随的 Session 推送一份面板状态:使用 Session 权限进行的 Git 检查、识别出的代码托管平台及其登录状态,以及带轮询状态的已绑定变更请求。 |
|
||||
| `ctx.worktrees` | `seam` | [`experimental-worktree`](../packages/experimental/worktree) | [`experimental-worktree`](../packages/experimental/worktree) | [`experimental-tool-worktree`](../packages/experimental/tool-worktree) | - | 显式实验组合从固定的本地提交创建工作树。检出目录与共享 Git 元数据受现有写权限约束;工作目录服务拥有创建后的 Session 目录。 |
|
||||
| `ctx.workingDirectory` | `seam` | [`working-directory`](../packages/session/working-directory) | [`working-directory`](../packages/session/working-directory) | [`tool-working-directory`](../packages/session/tool-working-directory), [`tool-fs`](../packages/fs/tool-fs), [`tool-bash`](../packages/shell/tool-bash), [`tool-pwsh`](../packages/shell/tool-pwsh), [`subagent`](../packages/subagent/subagent), [`sdk-jsonrpc-server`](../packages/sdk/server) | - | 两个 Session 投影拥有有效执行目录及其所在的工作区根。文件系统验证变更,用户上下文报告目录信息,原始元数据与写入授权保持不变。 |
|
||||
| `ctx.workingDirectory` | `seam` | [`working-directory`](../packages/session/working-directory) | [`working-directory`](../packages/session/working-directory) | [`tool-working-directory`](../packages/session/tool-working-directory), [`tool-fs`](../packages/fs/tool-fs), [`tool-bash`](../packages/shell/tool-bash), [`tool-pwsh`](../packages/shell/tool-pwsh), [`subagent`](../packages/subagent/subagent), [`sdk-jsonrpc-server`](../packages/sdk/server), [`sandbox-policy`](../packages/sandbox/sandbox-policy), `workspace-files`, `terminal-controller`, [`workspace-changes`](../packages/deliverables/workspace-changes), [`file-reference-local`](../packages/context/file-reference-local), [`tool-skill`](../packages/skill/tool-skill), [`agent-instructions`](../packages/context/agent-instructions), [`tool-lsp`](../packages/lsp/tool-lsp) | - | 两个 Session 投影拥有有效执行目录及其所在的工作区根。文件系统验证变更并由用户上下文报告;模型工具跟随当前目录,而沙箱边界、文件视图与发现跟随根,原始元数据保持不变。 |
|
||||
| `ctx.mcpResources` | `seam` | [`mcp-resources`](../packages/mcp/mcp-resources) | [`mcp-client`](../packages/mcp/mcp-client) | [`mcp-resources`](../packages/mcp/mcp-resources) | - | 连接所有者提供的操作在调用 agent 的作用域内服务于共享资源工具。 |
|
||||
| `ctx.browserUse` | `seam` | [`browser-use`](../packages/browser-use/browser-use) | [`experimental-browser-use-playwright-mcp`](../packages/experimental/browser-use-playwright-mcp), [`experimental-browser-use-chrome-devtools-mcp`](../packages/experimental/browser-use-chrome-devtools-mcp), [`experimental-browser-use-stagehand-native`](../packages/experimental/browser-use-stagehand-native) | [`experimental-browser-use-playwright-mcp`](../packages/experimental/browser-use-playwright-mcp), [`experimental-browser-use-chrome-devtools-mcp`](../packages/experimental/browser-use-chrome-devtools-mcp), [`experimental-browser-use-stagehand-native`](../packages/experimental/browser-use-stagehand-native) | - | 每个服务实例注册一个提供方拥有的名称。提供方按实时 Session 拥有自己的工具与浏览器资源;共享服务不提供浏览器操作 API。 |
|
||||
| `ctx.computerUse` | `seam` | [`computer-use`](../packages/computer-use/computer-use) | [`experimental-computer-use-cua-driver-mcp`](../packages/experimental/computer-use-cua-driver-mcp), [`experimental-computer-use-cua-driver-native`](../packages/experimental/computer-use-cua-driver-native) | [`experimental-computer-use-cua-driver-mcp`](../packages/experimental/computer-use-cua-driver-mcp), [`experimental-computer-use-cua-driver-native`](../packages/experimental/computer-use-cua-driver-native) | - | 每个服务实例只注册一个提供方自定的名称。各提供方也拥有自己的模型工具;服务不提供通用操作 API、运行时选择或 Session 流程锁。 |
|
||||
|
||||
+11
-9
@@ -362,7 +362,7 @@ export interface Config {
|
||||
## `@deepseek-ai/dsh-api-workspace-files`
|
||||
|
||||
- `inject`: `fs` · `sandboxPolicy` · `sessions` · `typert`
|
||||
- `source`: [`packages/api/workspace-files/src/index.ts:70`](../packages/api/workspace-files/src/index.ts)
|
||||
- `source`: [`packages/api/workspace-files/src/index.ts:101`](../packages/api/workspace-files/src/index.ts)
|
||||
|
||||
```ts config-catalog
|
||||
/** Deployment caps on one page or one listing. */
|
||||
@@ -2960,7 +2960,7 @@ export interface Config {
|
||||
|
||||
- `inject`: `sessionProjections`
|
||||
- `refs`: [`SandboxMode`](subsystems/sandbox.md)
|
||||
- `source`: [`packages/sandbox/sandbox-policy/src/index.ts:94`](../packages/sandbox/sandbox-policy/src/index.ts)
|
||||
- `source`: [`packages/sandbox/sandbox-policy/src/index.ts:119`](../packages/sandbox/sandbox-policy/src/index.ts)
|
||||
|
||||
```ts config-catalog
|
||||
/**
|
||||
@@ -2974,16 +2974,18 @@ export interface Config {
|
||||
/** File-sandbox mode a session starts from (default: `read-only`). */
|
||||
mode?: SandboxMode
|
||||
/**
|
||||
* Absolute fallback root for agentless calls and sessions without a cwd (default:
|
||||
* `process.cwd()`). Normal agent calls use their session cwd instead.
|
||||
* Absolute fallback root for agentless calls and sessions without a recorded
|
||||
* directory (default: `process.cwd()`). Normal agent calls use their
|
||||
* session's workspace root instead.
|
||||
*/
|
||||
workspaceRoot?: string
|
||||
/**
|
||||
* Extra physical absolute directories that `workspace-write` may also write under
|
||||
* (default: none). The supervisor names them explicitly; there is no
|
||||
* automatic repository or gitfile discovery. Entries are execution-world
|
||||
* paths: this service validates absoluteness and detaches the list, while
|
||||
* the enforcing host rejects missing, non-directory, or symlinked paths. They grant nothing under
|
||||
* (default: none). The supervisor names them explicitly; the Git
|
||||
* administration directories of a linked checkout are derived separately
|
||||
* and need no entry here. Entries are execution-world paths: this service
|
||||
* validates absoluteness and detaches the list, while the enforcing host
|
||||
* rejects missing, non-directory, or symlinked paths. They grant nothing under
|
||||
* `read-only`.
|
||||
*/
|
||||
additionalWritableRoots?: string[]
|
||||
@@ -4859,7 +4861,7 @@ export interface Config {
|
||||
## `@deepseek-ai/dsh-workspace-changes`
|
||||
|
||||
- `inject`: `subprocess` · `fs`
|
||||
- `source`: [`packages/deliverables/workspace-changes/src/index.ts:34`](../packages/deliverables/workspace-changes/src/index.ts)
|
||||
- `source`: [`packages/deliverables/workspace-changes/src/index.ts:35`](../packages/deliverables/workspace-changes/src/index.ts)
|
||||
|
||||
```ts config-catalog
|
||||
/** Snapshot, capture, and comparison bounds. Invalid values fail plugin load. */
|
||||
|
||||
@@ -364,7 +364,7 @@ export interface Config {
|
||||
## `@deepseek-ai/dsh-api-workspace-files`
|
||||
|
||||
- `inject`: `fs` · `sandboxPolicy` · `sessions` · `typert`
|
||||
- `source`: [`packages/api/workspace-files/src/index.ts:70`](../packages/api/workspace-files/src/index.ts)
|
||||
- `source`: [`packages/api/workspace-files/src/index.ts:101`](../packages/api/workspace-files/src/index.ts)
|
||||
|
||||
```ts config-catalog
|
||||
/** Deployment caps on one page or one listing. */
|
||||
@@ -2962,7 +2962,7 @@ export interface Config {
|
||||
|
||||
- `inject`: `sessionProjections`
|
||||
- `refs`: [`SandboxMode`](subsystems/sandbox.zh.md)
|
||||
- `source`: [`packages/sandbox/sandbox-policy/src/index.ts:94`](../packages/sandbox/sandbox-policy/src/index.ts)
|
||||
- `source`: [`packages/sandbox/sandbox-policy/src/index.ts:119`](../packages/sandbox/sandbox-policy/src/index.ts)
|
||||
|
||||
```ts config-catalog
|
||||
/**
|
||||
@@ -2976,16 +2976,18 @@ export interface Config {
|
||||
/** File-sandbox mode a session starts from (default: `read-only`). */
|
||||
mode?: SandboxMode
|
||||
/**
|
||||
* Absolute fallback root for agentless calls and sessions without a cwd (default:
|
||||
* `process.cwd()`). Normal agent calls use their session cwd instead.
|
||||
* Absolute fallback root for agentless calls and sessions without a recorded
|
||||
* directory (default: `process.cwd()`). Normal agent calls use their
|
||||
* session's workspace root instead.
|
||||
*/
|
||||
workspaceRoot?: string
|
||||
/**
|
||||
* Extra physical absolute directories that `workspace-write` may also write under
|
||||
* (default: none). The supervisor names them explicitly; there is no
|
||||
* automatic repository or gitfile discovery. Entries are execution-world
|
||||
* paths: this service validates absoluteness and detaches the list, while
|
||||
* the enforcing host rejects missing, non-directory, or symlinked paths. They grant nothing under
|
||||
* (default: none). The supervisor names them explicitly; the Git
|
||||
* administration directories of a linked checkout are derived separately
|
||||
* and need no entry here. Entries are execution-world paths: this service
|
||||
* validates absoluteness and detaches the list, while the enforcing host
|
||||
* rejects missing, non-directory, or symlinked paths. They grant nothing under
|
||||
* `read-only`.
|
||||
*/
|
||||
additionalWritableRoots?: string[]
|
||||
@@ -4861,7 +4863,7 @@ export interface Config {
|
||||
## `@deepseek-ai/dsh-workspace-changes`
|
||||
|
||||
- `inject`: `subprocess` · `fs`
|
||||
- `source`: [`packages/deliverables/workspace-changes/src/index.ts:34`](../packages/deliverables/workspace-changes/src/index.ts)
|
||||
- `source`: [`packages/deliverables/workspace-changes/src/index.ts:35`](../packages/deliverables/workspace-changes/src/index.ts)
|
||||
|
||||
```ts config-catalog
|
||||
/** Snapshot, capture, and comparison bounds. Invalid values fail plugin load. */
|
||||
|
||||
@@ -71,9 +71,9 @@ Application listeners are outside this package matrix. Desktop Host subscribes t
|
||||
| `schedule/changed` | `emit` | [`packages/schedule/schedule/src/types.ts:634`](../packages/schedule/schedule/src/types.ts) | [`schedule`](../packages/schedule/schedule) (`emit`) | `remotes` |
|
||||
| `schedule/resolve-agent` | `waterfall` | [`packages/schedule/schedule/src/index.ts:71`](../packages/schedule/schedule/src/index.ts) | [`schedule`](../packages/schedule/schedule) (`waterfall`) | `server` |
|
||||
| `session-telemetry/record` | `waterfall` | [`packages/session/session-telemetry/src/index.ts:44`](../packages/session/session-telemetry/src/index.ts) | [`session-telemetry`](../packages/session/session-telemetry) (`waterfall`) | - |
|
||||
| `session/created` | `emit` | [`packages/core/session/src/index.ts:56`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | `server`, `session-controller`, [`session-projection`](../packages/session/session-projection), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry) |
|
||||
| `session/created` | `emit` | [`packages/core/session/src/index.ts:56`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`sandbox-policy`](../packages/sandbox/sandbox-policy), `server`, `session-controller`, [`session-projection`](../packages/session/session-projection), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry) |
|
||||
| `session/disposed` | `emit` | [`packages/core/session/src/index.ts:65`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`agent-loop`](../packages/core/agent-loop), `file-upload`, `forge-session`, `session-controller`, [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry), [`session-title`](../packages/session/session-title), `ui-trajectory`, [`workspace-changes`](../packages/deliverables/workspace-changes) |
|
||||
| `session/event` | `emit` | [`packages/core/session/src/index.ts:76`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`acp`](../packages/acp/acp), [`agent-instructions`](../packages/context/agent-instructions), [`agent-loop`](../packages/core/agent-loop), [`agent-preset-registry`](../packages/preset/agent-preset-registry), `claude-code-mods`, `client-ui-forge`, [`compaction-basic`](../packages/compaction/compaction-basic), [`file-reference-local`](../packages/context/file-reference-local), `file-upload`, `forge-session`, [`goal`](../packages/goal/goal), [`goal-round-driver`](../packages/goal/goal-round-driver), [`headless`](../packages/bundle/headless), [`loader-smoke`](../packages/test-support/loader-smoke), `product-analytics`, [`ptc-runtime-node`](../packages/ptc-runtime/ptc-runtime-node), `server`, `session-controller`, [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-projection`](../packages/session/session-projection), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry), [`session-telemetry-otel`](../packages/session/session-telemetry-otel), [`session-title`](../packages/session/session-title), [`subagent`](../packages/subagent/subagent), [`token-meter`](../packages/llm/token-meter), [`tool-executor-ptc`](../packages/core/tool-executor-ptc), [`tool-jobs`](../packages/jobs/tool-jobs), `ui-trajectory`, [`user-questions`](../packages/interaction/user-questions), [`workspace-changes`](../packages/deliverables/workspace-changes) |
|
||||
| `session/event` | `emit` | [`packages/core/session/src/index.ts:76`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`acp`](../packages/acp/acp), [`agent-instructions`](../packages/context/agent-instructions), [`agent-loop`](../packages/core/agent-loop), [`agent-preset-registry`](../packages/preset/agent-preset-registry), `claude-code-mods`, `client-ui-forge`, [`compaction-basic`](../packages/compaction/compaction-basic), [`file-reference-local`](../packages/context/file-reference-local), `file-upload`, `forge-session`, [`goal`](../packages/goal/goal), [`goal-round-driver`](../packages/goal/goal-round-driver), [`headless`](../packages/bundle/headless), [`loader-smoke`](../packages/test-support/loader-smoke), `product-analytics`, [`ptc-runtime-node`](../packages/ptc-runtime/ptc-runtime-node), [`sandbox-policy`](../packages/sandbox/sandbox-policy), `server`, `session-controller`, [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-projection`](../packages/session/session-projection), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry), [`session-telemetry-otel`](../packages/session/session-telemetry-otel), [`session-title`](../packages/session/session-title), [`subagent`](../packages/subagent/subagent), [`token-meter`](../packages/llm/token-meter), [`tool-executor-ptc`](../packages/core/tool-executor-ptc), [`tool-jobs`](../packages/jobs/tool-jobs), `ui-trajectory`, [`user-questions`](../packages/interaction/user-questions), [`workspace-changes`](../packages/deliverables/workspace-changes) |
|
||||
| `session/flush` | `parallel` | [`packages/core/session/src/index.ts:84`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-telemetry`](../packages/session/session-telemetry) |
|
||||
| `settings/document-updated` | `emit` | [`packages/settings/settings/src/types.ts:75`](../packages/settings/settings/src/types.ts) | [`settings`](../packages/settings/settings) (`emit`) | `remotes` |
|
||||
| `skills/change` | `emit` | [`packages/skill/skill/src/index.ts:296`](../packages/skill/skill/src/index.ts) | [`skill`](../packages/skill/skill) (`events.dispatch`) | - |
|
||||
@@ -86,7 +86,7 @@ Application listeners are outside this package matrix. Desktop Host subscribes t
|
||||
| `tools/change` | `emit` | [`packages/core/tools/src/events.ts:56`](../packages/core/tools/src/events.ts) | [`agent-preset-registry`](../packages/preset/agent-preset-registry) (`emit`), [`tools`](../packages/core/tools) (`emit`) | `browser-use-runtime` |
|
||||
| `tools/execute` | `waterfall` | [`packages/core/tools/src/events.ts:29`](../packages/core/tools/src/events.ts) | [`tools`](../packages/core/tools) (`waterfall`) | `browser-use-runtime`, `browser-use-stagehand-native`, `claude-code-mods`, `computer-use-cua-driver-native`, [`session-checkpoint-policy`](../packages/session/session-checkpoint-policy), `timeout-policy` |
|
||||
| `tools/post-execute` | `waterfall` | [`packages/core/tools/src/events.ts:41`](../packages/core/tools/src/events.ts) | [`tools`](../packages/core/tools) (`waterfall`) | `claude-code-mods`, [`hooks-claude-code`](../packages/experimental/hooks-claude-code), [`hooks-codex`](../packages/experimental/hooks-codex), [`repeat-tool-reminder`](../packages/guard/repeat-tool-reminder), [`spill-policy`](../packages/spill/spill-policy), [`tool-fs-search`](../packages/fs/tool-fs-search) |
|
||||
| `tools/pre-execute` | `waterfall` | [`packages/core/tools/src/events.ts:18`](../packages/core/tools/src/events.ts) | [`tools`](../packages/core/tools) (`waterfall`) | `auto-review`, [`hooks-claude-code`](../packages/experimental/hooks-claude-code), [`hooks-codex`](../packages/experimental/hooks-codex), `liveshare`, [`tool-jobs`](../packages/jobs/tool-jobs), [`workspace-changes`](../packages/deliverables/workspace-changes) |
|
||||
| `tools/pre-execute` | `waterfall` | [`packages/core/tools/src/events.ts:18`](../packages/core/tools/src/events.ts) | [`tools`](../packages/core/tools) (`waterfall`) | `auto-review`, [`hooks-claude-code`](../packages/experimental/hooks-claude-code), [`hooks-codex`](../packages/experimental/hooks-codex), `liveshare`, [`sandbox-policy`](../packages/sandbox/sandbox-policy), [`tool-jobs`](../packages/jobs/tool-jobs), [`workspace-changes`](../packages/deliverables/workspace-changes) |
|
||||
| `tools/ptc-dispatch-log` | `waterfall` | [`packages/core/tool-executor-ptc/src/runtime-types.ts:46`](../packages/core/tool-executor-ptc/src/runtime-types.ts) | [`tool-executor-ptc`](../packages/core/tool-executor-ptc) (`waterfall`) | [`spill-policy`](../packages/spill/spill-policy) |
|
||||
| `tools/result` | `emit` | [`packages/core/tools/src/events.ts:49`](../packages/core/tools/src/events.ts) | [`tools`](../packages/core/tools) (`events.dispatch`) | [`action-cards`](../packages/experimental/action-cards), [`agent-instructions`](../packages/context/agent-instructions), `claude-code-mods`, `forge-session`, `liveshare`, [`subagent`](../packages/subagent/subagent), [`tool-present`](../packages/deliverables/tool-present), `ui-trajectory` |
|
||||
| `user-questions/request` | `waterfall` | [`packages/interaction/user-questions/src/types.ts:174`](../packages/interaction/user-questions/src/types.ts) | [`user-questions`](../packages/interaction/user-questions) (`waterfall`) | `remotes`, `server` |
|
||||
|
||||
@@ -73,9 +73,9 @@
|
||||
| `schedule/changed` | `emit` | [`packages/schedule/schedule/src/types.ts:634`](../packages/schedule/schedule/src/types.ts) | [`schedule`](../packages/schedule/schedule) (`emit`) | `remotes` |
|
||||
| `schedule/resolve-agent` | `waterfall` | [`packages/schedule/schedule/src/index.ts:71`](../packages/schedule/schedule/src/index.ts) | [`schedule`](../packages/schedule/schedule) (`waterfall`) | `server` |
|
||||
| `session-telemetry/record` | `waterfall` | [`packages/session/session-telemetry/src/index.ts:44`](../packages/session/session-telemetry/src/index.ts) | [`session-telemetry`](../packages/session/session-telemetry) (`waterfall`) | - |
|
||||
| `session/created` | `emit` | [`packages/core/session/src/index.ts:56`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | `server`, `session-controller`, [`session-projection`](../packages/session/session-projection), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry) |
|
||||
| `session/created` | `emit` | [`packages/core/session/src/index.ts:56`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`sandbox-policy`](../packages/sandbox/sandbox-policy), `server`, `session-controller`, [`session-projection`](../packages/session/session-projection), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry) |
|
||||
| `session/disposed` | `emit` | [`packages/core/session/src/index.ts:65`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`agent-loop`](../packages/core/agent-loop), `file-upload`, `forge-session`, `session-controller`, [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry), [`session-title`](../packages/session/session-title), `ui-trajectory`, [`workspace-changes`](../packages/deliverables/workspace-changes) |
|
||||
| `session/event` | `emit` | [`packages/core/session/src/index.ts:76`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`acp`](../packages/acp/acp), [`agent-instructions`](../packages/context/agent-instructions), [`agent-loop`](../packages/core/agent-loop), [`agent-preset-registry`](../packages/preset/agent-preset-registry), `claude-code-mods`, `client-ui-forge`, [`compaction-basic`](../packages/compaction/compaction-basic), [`file-reference-local`](../packages/context/file-reference-local), `file-upload`, `forge-session`, [`goal`](../packages/goal/goal), [`goal-round-driver`](../packages/goal/goal-round-driver), [`headless`](../packages/bundle/headless), [`loader-smoke`](../packages/test-support/loader-smoke), `product-analytics`, [`ptc-runtime-node`](../packages/ptc-runtime/ptc-runtime-node), `server`, `session-controller`, [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-projection`](../packages/session/session-projection), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry), [`session-telemetry-otel`](../packages/session/session-telemetry-otel), [`session-title`](../packages/session/session-title), [`subagent`](../packages/subagent/subagent), [`token-meter`](../packages/llm/token-meter), [`tool-executor-ptc`](../packages/core/tool-executor-ptc), [`tool-jobs`](../packages/jobs/tool-jobs), `ui-trajectory`, [`user-questions`](../packages/interaction/user-questions), [`workspace-changes`](../packages/deliverables/workspace-changes) |
|
||||
| `session/event` | `emit` | [`packages/core/session/src/index.ts:76`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`acp`](../packages/acp/acp), [`agent-instructions`](../packages/context/agent-instructions), [`agent-loop`](../packages/core/agent-loop), [`agent-preset-registry`](../packages/preset/agent-preset-registry), `claude-code-mods`, `client-ui-forge`, [`compaction-basic`](../packages/compaction/compaction-basic), [`file-reference-local`](../packages/context/file-reference-local), `file-upload`, `forge-session`, [`goal`](../packages/goal/goal), [`goal-round-driver`](../packages/goal/goal-round-driver), [`headless`](../packages/bundle/headless), [`loader-smoke`](../packages/test-support/loader-smoke), `product-analytics`, [`ptc-runtime-node`](../packages/ptc-runtime/ptc-runtime-node), [`sandbox-policy`](../packages/sandbox/sandbox-policy), `server`, `session-controller`, [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-projection`](../packages/session/session-projection), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry), [`session-telemetry-otel`](../packages/session/session-telemetry-otel), [`session-title`](../packages/session/session-title), [`subagent`](../packages/subagent/subagent), [`token-meter`](../packages/llm/token-meter), [`tool-executor-ptc`](../packages/core/tool-executor-ptc), [`tool-jobs`](../packages/jobs/tool-jobs), `ui-trajectory`, [`user-questions`](../packages/interaction/user-questions), [`workspace-changes`](../packages/deliverables/workspace-changes) |
|
||||
| `session/flush` | `parallel` | [`packages/core/session/src/index.ts:84`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-telemetry`](../packages/session/session-telemetry) |
|
||||
| `settings/document-updated` | `emit` | [`packages/settings/settings/src/types.ts:75`](../packages/settings/settings/src/types.ts) | [`settings`](../packages/settings/settings) (`emit`) | `remotes` |
|
||||
| `skills/change` | `emit` | [`packages/skill/skill/src/index.ts:296`](../packages/skill/skill/src/index.ts) | [`skill`](../packages/skill/skill) (`events.dispatch`) | - |
|
||||
@@ -88,7 +88,7 @@
|
||||
| `tools/change` | `emit` | [`packages/core/tools/src/events.ts:56`](../packages/core/tools/src/events.ts) | [`agent-preset-registry`](../packages/preset/agent-preset-registry) (`emit`), [`tools`](../packages/core/tools) (`emit`) | `browser-use-runtime` |
|
||||
| `tools/execute` | `waterfall` | [`packages/core/tools/src/events.ts:29`](../packages/core/tools/src/events.ts) | [`tools`](../packages/core/tools) (`waterfall`) | `browser-use-runtime`, `browser-use-stagehand-native`, `claude-code-mods`, `computer-use-cua-driver-native`, [`session-checkpoint-policy`](../packages/session/session-checkpoint-policy), `timeout-policy` |
|
||||
| `tools/post-execute` | `waterfall` | [`packages/core/tools/src/events.ts:41`](../packages/core/tools/src/events.ts) | [`tools`](../packages/core/tools) (`waterfall`) | `claude-code-mods`, [`hooks-claude-code`](../packages/experimental/hooks-claude-code), [`hooks-codex`](../packages/experimental/hooks-codex), [`repeat-tool-reminder`](../packages/guard/repeat-tool-reminder), [`spill-policy`](../packages/spill/spill-policy), [`tool-fs-search`](../packages/fs/tool-fs-search) |
|
||||
| `tools/pre-execute` | `waterfall` | [`packages/core/tools/src/events.ts:18`](../packages/core/tools/src/events.ts) | [`tools`](../packages/core/tools) (`waterfall`) | `auto-review`, [`hooks-claude-code`](../packages/experimental/hooks-claude-code), [`hooks-codex`](../packages/experimental/hooks-codex), `liveshare`, [`tool-jobs`](../packages/jobs/tool-jobs), [`workspace-changes`](../packages/deliverables/workspace-changes) |
|
||||
| `tools/pre-execute` | `waterfall` | [`packages/core/tools/src/events.ts:18`](../packages/core/tools/src/events.ts) | [`tools`](../packages/core/tools) (`waterfall`) | `auto-review`, [`hooks-claude-code`](../packages/experimental/hooks-claude-code), [`hooks-codex`](../packages/experimental/hooks-codex), `liveshare`, [`sandbox-policy`](../packages/sandbox/sandbox-policy), [`tool-jobs`](../packages/jobs/tool-jobs), [`workspace-changes`](../packages/deliverables/workspace-changes) |
|
||||
| `tools/ptc-dispatch-log` | `waterfall` | [`packages/core/tool-executor-ptc/src/runtime-types.ts:46`](../packages/core/tool-executor-ptc/src/runtime-types.ts) | [`tool-executor-ptc`](../packages/core/tool-executor-ptc) (`waterfall`) | [`spill-policy`](../packages/spill/spill-policy) |
|
||||
| `tools/result` | `emit` | [`packages/core/tools/src/events.ts:49`](../packages/core/tools/src/events.ts) | [`tools`](../packages/core/tools) (`events.dispatch`) | [`action-cards`](../packages/experimental/action-cards), [`agent-instructions`](../packages/context/agent-instructions), `claude-code-mods`, `forge-session`, `liveshare`, [`subagent`](../packages/subagent/subagent), [`tool-present`](../packages/deliverables/tool-present), `ui-trajectory` |
|
||||
| `user-questions/request` | `waterfall` | [`packages/interaction/user-questions/src/types.ts:174`](../packages/interaction/user-questions/src/types.ts) | [`user-questions`](../packages/interaction/user-questions) (`waterfall`) | `remotes`, `server` |
|
||||
|
||||
@@ -25,10 +25,10 @@ interface PresentedFile {
|
||||
```ts type-equiv
|
||||
/** One file changed during a turn, with line counts from git or from the whole-file captures around its file-tool edits. */
|
||||
interface WorkspaceChangedFile {
|
||||
/** Path relative to the Session working directory, or an absolute Host path outside it. */
|
||||
/** Path relative to the Session workspace root, or an absolute Host path outside it. */
|
||||
path: string
|
||||
/**
|
||||
* Sort key and label: the relative path inside the working directory, a
|
||||
* Sort key and label: the relative path inside the workspace root, a
|
||||
* `../` path for repository files above it, a `~` path under the home
|
||||
* directory, otherwise the absolute path. Always slash-separated.
|
||||
*/
|
||||
@@ -51,8 +51,8 @@ interface WorkspaceChangedFile {
|
||||
interface WorkspaceChangesSummary {
|
||||
/** The turn whose file changes this summary describes. */
|
||||
turn: number
|
||||
/** The Session working directory `path` values are relative to. */
|
||||
cwd: string
|
||||
/** The Session workspace root `path` values are relative to, as it stood when the turn started. */
|
||||
root: string
|
||||
/** Changed files in `display` order, capped at the plugin's `maxFiles`. */
|
||||
files: WorkspaceChangedFile[]
|
||||
/** Complete changed-file count, including files omitted by the cap. */
|
||||
|
||||
@@ -25,10 +25,10 @@ interface PresentedFile {
|
||||
```ts type-equiv
|
||||
/** One file changed during a turn, with line counts from git or from the whole-file captures around its file-tool edits. */
|
||||
interface WorkspaceChangedFile {
|
||||
/** Path relative to the Session working directory, or an absolute Host path outside it. */
|
||||
/** Path relative to the Session workspace root, or an absolute Host path outside it. */
|
||||
path: string
|
||||
/**
|
||||
* Sort key and label: the relative path inside the working directory, a
|
||||
* Sort key and label: the relative path inside the workspace root, a
|
||||
* `../` path for repository files above it, a `~` path under the home
|
||||
* directory, otherwise the absolute path. Always slash-separated.
|
||||
*/
|
||||
@@ -51,8 +51,8 @@ interface WorkspaceChangedFile {
|
||||
interface WorkspaceChangesSummary {
|
||||
/** The turn whose file changes this summary describes. */
|
||||
turn: number
|
||||
/** The Session working directory `path` values are relative to. */
|
||||
cwd: string
|
||||
/** The Session workspace root `path` values are relative to, as it stood when the turn started. */
|
||||
root: string
|
||||
/** Changed files in `display` order, capped at the plugin's `maxFiles`. */
|
||||
files: WorkspaceChangedFile[]
|
||||
/** Complete changed-file count, including files omitted by the cap. */
|
||||
|
||||
@@ -76,7 +76,7 @@ interface SandboxExecutionPolicy {
|
||||
```ts type-equiv
|
||||
/** Inputs that select the sandbox policy for one capability call. */
|
||||
interface SandboxPolicyRequest {
|
||||
/** Calling session; its immutable cwd becomes the workspace boundary. */
|
||||
/** Calling session; its workspace root becomes the workspace boundary. */
|
||||
session?: Session
|
||||
/** Explicit approved mode override, which outranks session policy. */
|
||||
mode?: SandboxMode
|
||||
@@ -200,17 +200,21 @@ Source: [`packages/sandbox/sandbox/src/index.ts`](../../packages/sandbox/sandbox
|
||||
|
||||
### `ctx.sandboxPolicy` — `SandboxPolicyService`
|
||||
|
||||
The sandbox-policy service (`ctx.sandboxPolicy`). Owns the deployment default mode, fallback workspace root, and current request-time policy section. Tool layers call resolve for each execution so a session's mode log and immutable cwd travel together to every enforcing capability.
|
||||
The sandbox-policy service (`ctx.sandboxPolicy`). Owns the deployment default mode, fallback workspace root, and current request-time policy section. Tool layers call resolve for each execution so a session's mode log and workspace root travel together to every enforcing capability.
|
||||
|
||||
A session's workspace root comes from the working-directory service when it is mounted: the checkout the Session works in, which a worktree relocation moves. A linked checkout keeps its Git administration directory and the repository's common directory outside that root; prepare derives them through the execution-world filesystem once per root, and `resolve` adds the derived directories to `additionalWritableRoots`. Tool executions await that derivation in `tools/pre-execute`; Session creation and every directory change start it early.
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Resolve the complete policy for one capability call. An approved explicit
|
||||
* mode outranks the session's last `sandbox/mode` event, which outranks the
|
||||
* deployment default. A session cwd is its workspace-write boundary; the
|
||||
* deployment default. A session's workspace root is its workspace-write
|
||||
* boundary, and the Git administration directories {@link prepare} derived
|
||||
* for that root join the configured extra writable directories; the
|
||||
* configured root is the fallback for agentless calls and sessions without a
|
||||
* cwd.
|
||||
* recorded directory.
|
||||
* @param request - optional session and approved mode override.
|
||||
* @returns the fully resolved per-call mode and absolute workspace root.
|
||||
* @returns the fully resolved per-call mode, absolute workspace root, and extra writable directories.
|
||||
*/
|
||||
resolve(request: SandboxPolicyRequest = {}): SandboxExecutionPolicy
|
||||
|
||||
@@ -220,6 +224,20 @@ resolve(request: SandboxPolicyRequest = {}): SandboxExecutionPolicy
|
||||
* @returns the last logged mode, or `undefined` without one.
|
||||
*/
|
||||
overrideOf(session: Session): SandboxMode | undefined
|
||||
|
||||
/**
|
||||
* Derive the Git administration directories of the session's workspace root
|
||||
* so the next {@link resolve} grants them: a linked checkout's `.git` file
|
||||
* names its administration directory, whose `commondir` names the
|
||||
* repository's common directory. Directories inside the root, missing
|
||||
* directories, and a root without a `.git` entry add nothing. One derivation
|
||||
* runs per root; its result is kept once the root's `.git` entry was read,
|
||||
* and a failed read is logged and retried on the next call.
|
||||
* @param session - session whose workspace root is inspected.
|
||||
* @param signal - caller cancellation, checked before and after the shared derivation.
|
||||
* @returns the derived directories outside the root, canonical in the execution world.
|
||||
*/
|
||||
async prepare(session: Session, signal?: AbortSignal): Promise<readonly string[]>
|
||||
```
|
||||
|
||||
Types: [Session](session.md)
|
||||
|
||||
@@ -76,7 +76,7 @@ interface SandboxExecutionPolicy {
|
||||
```ts type-equiv
|
||||
/** Inputs that select the sandbox policy for one capability call. */
|
||||
interface SandboxPolicyRequest {
|
||||
/** Calling session; its immutable cwd becomes the workspace boundary. */
|
||||
/** Calling session; its workspace root becomes the workspace boundary. */
|
||||
session?: Session
|
||||
/** Explicit approved mode override, which outranks session policy. */
|
||||
mode?: SandboxMode
|
||||
@@ -200,17 +200,21 @@ Source: [`packages/sandbox/sandbox/src/index.ts`](../../packages/sandbox/sandbox
|
||||
|
||||
### `ctx.sandboxPolicy` — `SandboxPolicyService`
|
||||
|
||||
The sandbox-policy service (`ctx.sandboxPolicy`). Owns the deployment default mode, fallback workspace root, and current request-time policy section. Tool layers call resolve for each execution so a session's mode log and immutable cwd travel together to every enforcing capability.
|
||||
The sandbox-policy service (`ctx.sandboxPolicy`). Owns the deployment default mode, fallback workspace root, and current request-time policy section. Tool layers call resolve for each execution so a session's mode log and workspace root travel together to every enforcing capability.
|
||||
|
||||
A session's workspace root comes from the working-directory service when it is mounted: the checkout the Session works in, which a worktree relocation moves. A linked checkout keeps its Git administration directory and the repository's common directory outside that root; prepare derives them through the execution-world filesystem once per root, and `resolve` adds the derived directories to `additionalWritableRoots`. Tool executions await that derivation in `tools/pre-execute`; Session creation and every directory change start it early.
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Resolve the complete policy for one capability call. An approved explicit
|
||||
* mode outranks the session's last `sandbox/mode` event, which outranks the
|
||||
* deployment default. A session cwd is its workspace-write boundary; the
|
||||
* deployment default. A session's workspace root is its workspace-write
|
||||
* boundary, and the Git administration directories {@link prepare} derived
|
||||
* for that root join the configured extra writable directories; the
|
||||
* configured root is the fallback for agentless calls and sessions without a
|
||||
* cwd.
|
||||
* recorded directory.
|
||||
* @param request - optional session and approved mode override.
|
||||
* @returns the fully resolved per-call mode and absolute workspace root.
|
||||
* @returns the fully resolved per-call mode, absolute workspace root, and extra writable directories.
|
||||
*/
|
||||
resolve(request: SandboxPolicyRequest = {}): SandboxExecutionPolicy
|
||||
|
||||
@@ -220,6 +224,20 @@ resolve(request: SandboxPolicyRequest = {}): SandboxExecutionPolicy
|
||||
* @returns the last logged mode, or `undefined` without one.
|
||||
*/
|
||||
overrideOf(session: Session): SandboxMode | undefined
|
||||
|
||||
/**
|
||||
* Derive the Git administration directories of the session's workspace root
|
||||
* so the next {@link resolve} grants them: a linked checkout's `.git` file
|
||||
* names its administration directory, whose `commondir` names the
|
||||
* repository's common directory. Directories inside the root, missing
|
||||
* directories, and a root without a `.git` entry add nothing. One derivation
|
||||
* runs per root; its result is kept once the root's `.git` entry was read,
|
||||
* and a failed read is logged and retried on the next call.
|
||||
* @param session - session whose workspace root is inspected.
|
||||
* @param signal - caller cancellation, checked before and after the shared derivation.
|
||||
* @returns the derived directories outside the root, canonical in the execution world.
|
||||
*/
|
||||
async prepare(session: Session, signal?: AbortSignal): Promise<readonly string[]>
|
||||
```
|
||||
|
||||
Types: [Session](session.zh.md)
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
en: 0882d8b4c09c2890
|
||||
zh: a75af7ce19f661fa
|
||||
/working-directory/directory-selection:
|
||||
en: d0461ccad1bf9474
|
||||
zh: f503835eb2937e3e
|
||||
en: d98d6c3190ad2245
|
||||
zh: ddce20f8bf6f491e
|
||||
/working-directory/model-context:
|
||||
en: 2c27d5dfe7abbd4c
|
||||
zh: 4e6dc26dff03edad
|
||||
|
||||
@@ -10,7 +10,7 @@ A Session's active directory is owned by [`dsh-working-directory`](../../package
|
||||
|
||||
`rootOf(session)` reads the workspace root: the longest registered anchor that contains the current directory. The anchors are the original project and every checkout `relocate(agent, root, { cwd? })` entered; that operation validates the root and the directory inside it, then records both in one `working-directory/change` whose `anchor` names the root. `anchorsOf(session)` lists them. A `set` inside the root moves only the current directory; a `set` into another anchor selects that anchor as the root; a `set` outside every anchor leaves the root unchanged. Recovery to the original project selects it as the root again. Anchors are compared as recorded.
|
||||
|
||||
Changes are local to one Session. Relative filesystem operations, newly started processes, instruction discovery, skills, and file completion use the active directory. Existing terminals and persistent shells retain their own directories. Sandbox writable roots and project membership remain anchored to the original project.
|
||||
Changes are local to one Session. The model's relative filesystem operations and the processes its tools start use the current directory. What the user sees follows the workspace root: the sandbox `workspace-write` boundary, the Files tree and directory listings, the change summaries, new sidebar terminals, `@` file completion, the skill catalog, project-instruction discovery, and the LSP workspace. Existing terminals and persistent shells retain their own directories. Project membership remains anchored to the original project.
|
||||
|
||||
## Model context
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ Session 的当前目录由 [`dsh-working-directory`](../../packages/session/work
|
||||
|
||||
`rootOf(session)` 读取工作区根:包含当前目录的最长已登记锚。锚是原始项目以及 `relocate(agent, root, { cwd? })` 进入过的每个检出目录;该操作验证根及其内部的目录,然后用一条 `anchor` 指向该根的 `working-directory/change` 同时记录两者。`anchorsOf(session)` 列出这些锚。根内部的 `set` 只移动当前目录;进入另一个锚的 `set` 把该锚选为根;所有锚之外的 `set` 不改变根。恢复到原始项目时再次把它选为根。锚按记录的原样比较。
|
||||
|
||||
变更仅影响一个 Session。相对路径文件系统操作、新启动的进程、指令发现、技能和文件补全使用当前目录。已有终端和持久 shell 保留自己的目录。沙箱可写根目录与项目归属继续绑定原始项目。
|
||||
变更仅影响一个 Session。模型的相对路径文件系统操作以及其工具启动的进程使用当前目录。用户看到的内容跟随工作区根:沙箱 `workspace-write` 边界、文件树与目录列举、变更摘要、新开的侧栏终端、`@` 文件补全、技能目录、项目指令发现和 LSP 工作区。已有终端和持久 shell 保留自己的目录。项目归属继续绑定原始项目。
|
||||
|
||||
## 模型上下文
|
||||
|
||||
|
||||
@@ -236,10 +236,10 @@ Typed Remote control of transient Session-owned terminal processes.
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Read the Session's current directory and terminal limits without filesystem validation or shell lookup.
|
||||
* Read the Session's workspace root and terminal limits without filesystem validation or shell lookup.
|
||||
* @param agent - Session owner supplied by the Gateway.
|
||||
* @param signal - request cancellation.
|
||||
* @returns the logged current directory and terminal limits; retained terminals keep their own process directories.
|
||||
* @returns the logged workspace root and terminal limits; retained terminals keep their own process directories.
|
||||
*/
|
||||
@Remote environment(agent: Agent, signal: AbortSignal): TerminalEnvironment
|
||||
|
||||
|
||||
@@ -236,10 +236,10 @@ Typed Remote control of transient Session-owned terminal processes.
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Read the Session's current directory and terminal limits without filesystem validation or shell lookup.
|
||||
* Read the Session's workspace root and terminal limits without filesystem validation or shell lookup.
|
||||
* @param agent - Session owner supplied by the Gateway.
|
||||
* @param signal - request cancellation.
|
||||
* @returns the logged current directory and terminal limits; retained terminals keep their own process directories.
|
||||
* @returns the logged workspace root and terminal limits; retained terminals keep their own process directories.
|
||||
*/
|
||||
@Remote environment(agent: Agent, signal: AbortSignal): TerminalEnvironment
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
en: 60090e418482277a
|
||||
zh: 65db84704ed19c2d
|
||||
/git-worktrees/creation-and-retention:
|
||||
en: 195894ced2e675dc
|
||||
zh: 5ed3a6ff729496c2
|
||||
en: 8658dff762819f6b
|
||||
zh: 01f84a68b7ff9c59
|
||||
/git-worktrees/request-and-result:
|
||||
en: fbab866bf824d6e0
|
||||
zh: 73d2a1ee350e1434
|
||||
@@ -8,7 +8,7 @@ The experimental [`dsh-experimental-worktree`](../../packages/experimental/workt
|
||||
|
||||
The calling Session's current directory selects the source repository. Creation pins the requested local commit, branch, or tag before allocating the checkout; omission selects `HEAD`. Each name must identify a new branch and an unused checkout path. The operation neither fetches missing objects nor copies staged, unstaged, untracked, or ignored files from the source checkout.
|
||||
|
||||
The default destination is `<current checkout root>/.agents/worktrees/<name>`. `repositoryRoot` is the top-level directory of the caller’s current checkout; a linked checkout therefore contains its own pool. The service writes a `.gitignore` containing `*` and a trailing newline only when its allocation creates the configured pool directory. Existing files and ignore rules are preserved. The calling Session’s existing sandbox policy must permit writes to the destination and shared Git administration directory. Successful Git setup precedes the working-directory relocation.
|
||||
The default destination is `<current checkout root>/.agents/worktrees/<name>`. `repositoryRoot` is the top-level directory of the caller’s current checkout; a linked checkout therefore contains its own pool. The service writes a `.gitignore` containing `*` and a trailing newline only when its allocation creates the configured pool directory. Existing files and ignore rules are preserved. The calling Session’s resolved sandbox policy must permit writes to the destination and shared Git administration directory; for a linked checkout the [sandbox policy](sandbox.md) grants that directory before creation writes. Successful Git setup precedes the working-directory relocation.
|
||||
|
||||
Leaving through `working_directory({ cd: path })` retains the checkout and branch. Cancellation or failure can also retain partial artifacts; the error identifies their location. The service aborts and drains pending operations on disposal. The [package README](../../packages/experimental/worktree/README.md) owns configuration and Git requirements.
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
调用方 Session 的当前目录决定源仓库。创建操作在分配检出目录前,将请求的本地提交、分支或标签固定为具体提交;省略时选择 `HEAD`。每个名称必须对应新分支与未使用的检出路径。操作既不获取缺失对象,也不复制源检出目录中的暂存、未暂存、未跟踪或被忽略文件。
|
||||
|
||||
默认目标为 `<current checkout root>/.agents/worktrees/<name>`。`repositoryRoot` 是调用方当前检出目录的顶层目录;因此,链接检出目录会在自身内部保存工作树父目录。仅当服务的分配操作创建了配置指定的父目录时,服务才会写入内容为 `*` 加换行符的 `.gitignore`。已有文件与忽略规则保持不变。调用方 Session 的现有沙箱策略必须允许写入目标目录与共享 Git 管理目录。Git 初始化成功后才迁移工作目录。
|
||||
默认目标为 `<current checkout root>/.agents/worktrees/<name>`。`repositoryRoot` 是调用方当前检出目录的顶层目录;因此,链接检出目录会在自身内部保存工作树父目录。仅当服务的分配操作创建了配置指定的父目录时,服务才会写入内容为 `*` 加换行符的 `.gitignore`。已有文件与忽略规则保持不变。调用方 Session 解析后的沙箱策略必须允许写入目标目录与共享 Git 管理目录;对于链接检出目录,[沙箱策略](sandbox.zh.md)会在创建写入之前授权该目录。Git 初始化成功后才迁移工作目录。
|
||||
|
||||
通过 `working_directory({ cd: path })` 离开时,会保留检出目录与分支。取消或失败也可能留下部分产物;错误会指出它们的位置。服务销毁时会中止待完成操作并等待它们结束。[包 README](../../packages/experimental/worktree/README.zh.md)拥有配置与 Git 要求。
|
||||
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
# Bilingual-pair consistency record for guide.md (docs/i18n/README.md): per heading
|
||||
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
|
||||
# After editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write docs/upgrade-guide/v0.2.2-alpha.3/workspace-write-boundary-follows-root/guide.md
|
||||
/:
|
||||
en: f131cda0e3227062
|
||||
zh: 5572dc4578fee32c
|
||||
/the-workspace-write-boundary-follows-the-session-s-workspace-root:
|
||||
en: ec12813704224d37
|
||||
zh: eaa9928729aa7b2b
|
||||
/the-workspace-write-boundary-follows-the-session-s-workspace-root/change:
|
||||
en: e2598f5769c9c133
|
||||
zh: efaac55c356b43b5
|
||||
/the-workspace-write-boundary-follows-the-session-s-workspace-root/migration:
|
||||
en: 6f499a1dca41de9b
|
||||
zh: 76c99218e0832771
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
kind: upgrade-guide
|
||||
description: "The workspace-write boundary follows the Session's workspace root instead of its original project, and a linked worktree's Git directories become writable."
|
||||
---
|
||||
# The `workspace-write` boundary follows the Session's workspace root
|
||||
|
||||
English | [中文](guide.zh.md)
|
||||
|
||||
## Change
|
||||
|
||||
`ctx.sandboxPolicy.resolve({ session })` returns the Session's workspace root as `workspaceRoot`: the checkout the Session works in. Before, it returned the original project recorded in the Session header for the whole Session. A Session that enters a worktree through `create_worktree` or the forge New worktree option can now write only inside that worktree; the original project is no longer writable as a whole, and a `cd` inside the root does not move the boundary.
|
||||
|
||||
For a linked worktree, the policy derives the checkout's Git administration directory and the repository's common directory from its `.git` pointer and `commondir`, and adds them to `additionalWritableRoots`, so `git commit` and `git checkout` work inside a worktree under `workspace-write`. That grant also covers the shared `.git/hooks` and `.git/config`, as a Session in the main checkout already had. Windows ACL confinement accepts additional writable roots instead of failing with `SANDBOX_UNSUPPORTED_POLICY`.
|
||||
|
||||
The Files tree, directory listings and watches, deliverables and change summaries, new sidebar terminals, `@` file completion, the skill catalog, project-instruction discovery, and the LSP workspace read the same root. `WorkspaceChangesSummary.cwd` is replaced by `root`, and `TerminalEnvironment.cwd` names the root.
|
||||
|
||||
Who observes it: operators who relied on a worktree Session still writing its original project, deployments that granted a worktree's `.git` through `additionalWritableRoots`, and Host plugins that read `WorkspaceChangesSummary.cwd`.
|
||||
|
||||
## Migration
|
||||
|
||||
1. Remove `additionalWritableRoots` entries that only named a linked worktree's `.git/worktrees/<name>` or common `.git` directory from `cordis.yml`; keep entries for unrelated directories.
|
||||
2. Where a task must write the original project after entering a worktree, change back with `working_directory({ cd: "<original project>" })` or keep the Session in the original project; the boundary follows that change.
|
||||
3. Replace reads of `WorkspaceChangesSummary.cwd` with `root` in Host plugins that consume `ctx.workspaceChanges.summary`.
|
||||
4. Confirm: in a Session opened inside a linked worktree, `git commit` succeeds under `workspace-write`, and the runtime context shows `Additional writable directories` naming the repository's `.git`; after `create_worktree`, a write to the original project outside the worktree is denied.
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
kind: upgrade-guide
|
||||
description: "workspace-write 边界跟随 Session 的工作区根而不是原始项目,链接 worktree 的 Git 目录变为可写。"
|
||||
---
|
||||
# `workspace-write` 边界跟随 Session 的工作区根
|
||||
|
||||
[English](guide.md) | 中文
|
||||
|
||||
## 变更
|
||||
|
||||
`ctx.sandboxPolicy.resolve({ session })` 返回的 `workspaceRoot` 是 Session 的工作区根,即它所在的检出目录。此前整个 Session 期间返回的都是 Session header 记录的原始项目。通过 `create_worktree` 或 forge 的"新建工作树"选项进入 worktree 的 Session 现在只能在该 worktree 内写入;原始项目不再整体可写,根内部的 `cd` 不会移动边界。
|
||||
|
||||
对于链接 worktree,策略从其 `.git` 指针与 `commondir` 推导出检出目录的 Git 管理目录和仓库公共目录,并加入 `additionalWritableRoots`,因此在 `workspace-write` 下可以在 worktree 内运行 `git commit` 与 `git checkout`。该授权也覆盖共享的 `.git/hooks` 与 `.git/config`,与主检出目录中的 Session 此前拥有的权限相同。Windows ACL 限制接受额外可写根目录,不再以 `SANDBOX_UNSUPPORTED_POLICY` 失败。
|
||||
|
||||
文件树、目录列举与监听、交付物与变更摘要、新开的侧栏终端、`@` 文件补全、技能目录、项目指令发现和 LSP 工作区读取同一个根。`WorkspaceChangesSummary.cwd` 由 `root` 取代,`TerminalEnvironment.cwd` 表示该根。
|
||||
|
||||
受影响者:依赖 worktree Session 仍可写入原始项目的运维人员、通过 `additionalWritableRoots` 授权 worktree `.git` 的部署,以及读取 `WorkspaceChangesSummary.cwd` 的 Host 插件。
|
||||
|
||||
## 迁移
|
||||
|
||||
1. 从 `cordis.yml` 中删除只为链接 worktree 的 `.git/worktrees/<name>` 或公共 `.git` 目录而设置的 `additionalWritableRoots` 条目;保留无关目录的条目。
|
||||
2. 任务在进入 worktree 后仍需写入原始项目时,用 `working_directory({ cd: "<原始项目>" })` 切换回去,或让 Session 留在原始项目中;边界跟随该变更。
|
||||
3. 在消费 `ctx.workspaceChanges.summary` 的 Host 插件中,把对 `WorkspaceChangesSummary.cwd` 的读取改为 `root`。
|
||||
4. 确认:在链接 worktree 内打开的 Session 中,`workspace-write` 下 `git commit` 成功,运行时上下文的 `Additional writable directories` 列出仓库的 `.git`;`create_worktree` 之后,对 worktree 之外原始项目的写入被拒绝。
|
||||
@@ -18,8 +18,8 @@
|
||||
en: 300f02be359a3170
|
||||
zh: ac7fb4abbe78eddf
|
||||
/session-controller/client-references:
|
||||
en: e8979a803ec3e194
|
||||
zh: c567efcd971728ba
|
||||
en: 361c7b7c797c9d2b
|
||||
zh: b66b5c926760bfc0
|
||||
/session-controller/session-media-references:
|
||||
en: 954923654eebe2dc
|
||||
zh: 6bd9a7d2ea965aed
|
||||
|
||||
@@ -85,6 +85,8 @@ The controller composes `ArchivedSessionGate` through `ctx.plugin`: it loads onc
|
||||
|
||||
References keep local Session data, scoped Contexts, and history streams alive, not Host Agents. Ordinary Session retention never adds a catalog row. Retained subagents with a known direct-parent address keep a fallback row and notify list readers even before the parent catalog arrives; these rows do not join Host-list membership. Fork-title assignment sends rename directly and applies the returned title projection without retaining the child or opening its history. Final release withdraws the generation before teardown; later acquisition can create a new generation with the same id. `binding(id)` and `scope(id)` only borrow an existing generation. `retainInfo(id)` observes stable read-only source counts independently of catalog membership and performs no history I/O. Consumer source keys are declaration-merge extensible; navigation and completion acknowledgement belong to UI consumers, not this Controller. See [Client Session references](../../../.agents/notes/implemented/architecture/2026-09-15-client-session-references.md) for ownership and teardown rules. An unknown-mode subagent address permits history reads with direct-parent consistency validation; access is checked separately on the child Session. Successful descriptor restoration determines the displayed mode; failures remain local to the child. Control requests carry only the target id, and the Host checks continuation availability. Client snapshots retain only the subagent address; runtime admission owns continuation availability.
|
||||
|
||||
`@deepseek-ai/dsh-api-session-controller/client/directories` exports the import-free directory readers client plugins inline instead of importing this plugin's bundle: `selectSessionRoot(state, sessionId)` selects a Session's workspace root from a list snapshot (the projected `workspaceRoot`, else the row's header directory) for `useSessions` selectors, and `sessionDirectories(sessions, sessionId)` reads the original project, the workspace root, and the current directory at gesture time from the connected Session's projection faces before the list snapshot. File views, address bases, and open-in-app actions read the root; only the model's relative paths follow the current directory.
|
||||
|
||||
<a id="session-media-references"></a>
|
||||
## Session media references
|
||||
|
||||
|
||||
@@ -85,6 +85,8 @@ Client 的首次 `follow`、重连首屏与 `loadOlder()` 至少请求 50 条以
|
||||
|
||||
引用保活本地会话数据、作用域 Context 和历史流,不保活 Host Agent。普通 Session 不因保留引用而添加目录行。已保留且具有明确直接父子地址的 subagent 即使尚未收到父目录,也会保留兜底行并通知列表读取方;这些行不加入 Host 列表成员集合。Fork 标题设置直接发送 rename 并应用返回的标题投影,不 retain 子会话,也不打开其历史。最后一个引用释放时,generation 先退出可访问映射,再执行清理;后续获取可以为同一 id 创建新 generation。`binding(id)` 和 `scope(id)` 只借用已有 generation。`retainInfo(id)` 独立于目录成员关系观察稳定的只读来源计数,不执行历史 I/O。消费方来源键可通过声明合并扩展;导航和完成确认属于 UI 消费方,不属于本控制器。所有权与清理规则见 [Client 会话引用](../../../.agents/notes/implemented/architecture/2026-09-15-client-session-references.zh.md)。 模式未知的子代理地址允许读取历史,但仍校验直接父级的一致性;访问权单独按子 Session 检查。成功恢复 descriptor 后确定展示模式;失败只影响该子会话。控制请求仅携带目标 id,由 Host 检查是否支持继续执行。Client 快照仅保留子代理地址;是否能接收续接输入由运行时校验。
|
||||
|
||||
`@deepseek-ai/dsh-api-session-controller/client/directories` 导出无运行时导入的目录读取函数,客户端插件内联它们而不是导入本插件的 bundle:`selectSessionRoot(state, sessionId)` 从列表快照选出 Session 的工作区根(投影的 `workspaceRoot`,否则为该行的 header 目录),供 `useSessions` 选择器使用;`sessionDirectories(sessions, sessionId)` 在手势发生时先读已连接 Session 的投影面、再读列表快照,返回原始项目、工作区根与当前目录。文件视图、地址基准与在应用中打开操作读取根;只有模型的相对路径跟随当前目录。
|
||||
|
||||
<a id="session-media-references"></a>
|
||||
## 会话媒体引用
|
||||
|
||||
|
||||
@@ -30,6 +30,10 @@
|
||||
"types": "./lib/types/client/index.d.ts",
|
||||
"default": "./lib/client.js"
|
||||
},
|
||||
"./client/directories": {
|
||||
"types": "./lib/types/client/sessions/directories.d.ts",
|
||||
"default": "./lib/types/client/sessions/directories.js"
|
||||
},
|
||||
"./typert": {
|
||||
"types": "./lib/typert.host.d.ts",
|
||||
"default": "./lib/typert.host.js"
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* The directories of one Session as the Client knows them: the list row's
|
||||
* header directory and the projected root and cursor. Pure reads with
|
||||
* type-only imports, so client plugins inline this module instead of
|
||||
* requesting a module-table row this package does not publish.
|
||||
* @module @deepseek-ai/dsh-api-session-controller/client/directories
|
||||
*/
|
||||
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
import type { ISessions } from '../contract/sessions.ts'
|
||||
import type { SessionListState } from './service.ts'
|
||||
|
||||
/** Where a Session started, which checkout it works in, and where its relative paths resolve. */
|
||||
export interface SessionDirectories {
|
||||
/** The original project the Session header records; undefined for a row without one. */
|
||||
readonly original: string | undefined
|
||||
/**
|
||||
* The workspace root: the checkout the Session works in, which file views and address bases use;
|
||||
* the original project before any relocation.
|
||||
*/
|
||||
readonly root: string | undefined
|
||||
/** The current directory the model's relative paths resolve from; the root while the Session reports none. */
|
||||
readonly cwd: string | undefined
|
||||
}
|
||||
|
||||
/** A projected string value by key, from a values object whose keys the Client compilation does not declare. */
|
||||
function projectedString(values: object | undefined, key: string): string | undefined {
|
||||
if (values === undefined) return undefined
|
||||
const value: unknown = Reflect.get(values, key)
|
||||
return typeof value === 'string' ? value : undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a Session's workspace root from a list snapshot, for `useSessions` selectors.
|
||||
* @param state - the sessions list snapshot.
|
||||
* @param sessionId - the Session whose root is selected.
|
||||
* @returns the projected `workspaceRoot`, else the header directory, else undefined for an unknown row.
|
||||
*/
|
||||
export function selectSessionRoot(state: SessionListState, sessionId: SessionId): string | undefined {
|
||||
return projectedString(state.projectionsBySession[sessionId]?.values, 'workspaceRoot')
|
||||
?? projectedString(state.byId[sessionId]?.projectionValues, 'workspaceRoot')
|
||||
?? state.byId[sessionId]?.cwd
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a Session's directories at gesture time: the connected Session's projection faces first, then the list snapshot.
|
||||
* @param sessions - the sessions service.
|
||||
* @param sessionId - the Session whose directories are read.
|
||||
* @returns the original project, the workspace root, and the current directory, each undefined when unknown.
|
||||
*/
|
||||
export function sessionDirectories(sessions: ISessions, sessionId: SessionId): SessionDirectories {
|
||||
const state = sessions.list.getSnapshot()
|
||||
const original = state.byId[sessionId]?.cwd
|
||||
const projections = sessions.binding(sessionId)?.session.projections
|
||||
const liveRoot: unknown = projections?.faceOf('workspaceRoot').getSnapshot()
|
||||
const root = (typeof liveRoot === 'string' ? liveRoot : undefined) ?? selectSessionRoot(state, sessionId) ?? original
|
||||
const liveCwd: unknown = projections?.faceOf('workingDirectory').getSnapshot()
|
||||
const cwd = (typeof liveCwd === 'string' ? liveCwd : undefined) ?? root
|
||||
return { original, root, cwd }
|
||||
}
|
||||
@@ -42,12 +42,15 @@ export class SessionSkillCatalog extends TypertRemoteService {
|
||||
if (observation.projections === undefined) {
|
||||
throw new Error('skill catalog requires a projected Session observation')
|
||||
}
|
||||
cwd = observation.projections.values.workingDirectory
|
||||
cwd = observation.projections.values.workspaceRoot
|
||||
?? observation.header.cwd
|
||||
?? this.ctx.workingDirectory.defaultDirectory
|
||||
agentPreset = observation.projections.values.agentPreset ?? undefined
|
||||
const live = this.ctx.agents.get(sessionId)
|
||||
if (live !== undefined) cwd = await this.ctx.workingDirectory.ensure(live, signal)
|
||||
if (live !== undefined) {
|
||||
await this.ctx.workingDirectory.ensure(live, signal)
|
||||
cwd = this.ctx.workingDirectory.rootOf(live.session)
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof SessionQueryError
|
||||
&& error.code === 'SESSION_QUERY_SESSION_NOT_FOUND') {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { SessionSkillCatalog } from '../src/skill-catalog.ts'
|
||||
|
||||
function observation(
|
||||
sessionId: SessionId,
|
||||
options: { readonly cwd?: string; readonly workingDirectory?: string | null; readonly agentPreset?: string } = {},
|
||||
options: { readonly cwd?: string; readonly workspaceRoot?: string | null; readonly agentPreset?: string } = {},
|
||||
): SessionObservation {
|
||||
const events = Object.freeze([])
|
||||
const lease = (): SessionObservation => ({
|
||||
@@ -30,7 +30,7 @@ function observation(
|
||||
asOfSeq: -1,
|
||||
values: {
|
||||
...options.agentPreset === undefined ? {} : { agentPreset: options.agentPreset },
|
||||
...options.workingDirectory === undefined ? {} : { workingDirectory: options.workingDirectory },
|
||||
...options.workspaceRoot === undefined ? {} : { workspaceRoot: options.workspaceRoot },
|
||||
},
|
||||
},
|
||||
retain: lease,
|
||||
@@ -49,10 +49,10 @@ async function context(): Promise<Context> {
|
||||
}
|
||||
|
||||
describe('SessionSkillCatalog', () => {
|
||||
it('reads a moved cold Session catalog from its recorded current directory without resuming an Agent', async () => {
|
||||
it('reads a moved cold Session catalog from its recorded workspace root without resuming an Agent', async () => {
|
||||
const ctx = await context()
|
||||
const sessionId = SessionId('cold-skills')
|
||||
const observed = observation(sessionId, { cwd: '/cold/original', workingDirectory: '/cold/project' })
|
||||
const observed = observation(sessionId, { cwd: '/cold/original', workspaceRoot: '/cold/project' })
|
||||
const dispose = vi.spyOn(observed, Symbol.dispose)
|
||||
const observeSession = vi.fn(() => Promise.resolve(observed))
|
||||
ctx.provide('sessionQuery', { observeSession } as never)
|
||||
@@ -93,18 +93,18 @@ describe('SessionSkillCatalog', () => {
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ cwd: undefined, workingDirectory: '/cold/current', expected: '/cold/current' },
|
||||
{ cwd: '/cold/original', workingDirectory: null, expected: '/cold/original' },
|
||||
{ cwd: undefined, workingDirectory: null, expected: '/catalog/default' },
|
||||
{ cwd: undefined, workingDirectory: undefined, expected: '/catalog/default' },
|
||||
])('resolves cold directory metadata $cwd / $workingDirectory to $expected without filesystem checks', async ({ cwd, workingDirectory, expected }) => {
|
||||
{ cwd: undefined, workspaceRoot: '/cold/current', expected: '/cold/current' },
|
||||
{ cwd: '/cold/original', workspaceRoot: null, expected: '/cold/original' },
|
||||
{ cwd: undefined, workspaceRoot: null, expected: '/catalog/default' },
|
||||
{ cwd: undefined, workspaceRoot: undefined, expected: '/catalog/default' },
|
||||
])('resolves cold directory metadata $cwd / $workspaceRoot to $expected without filesystem checks', async ({ cwd, workspaceRoot, expected }) => {
|
||||
const ctx = await context()
|
||||
try {
|
||||
const sessionId = SessionId('cold-directory-fallback')
|
||||
ctx.provide('sessionQuery', {
|
||||
observeSession: () => Promise.resolve(observation(sessionId, {
|
||||
...cwd === undefined ? {} : { cwd },
|
||||
...workingDirectory === undefined ? {} : { workingDirectory },
|
||||
...workspaceRoot === undefined ? {} : { workspaceRoot },
|
||||
})),
|
||||
} as never)
|
||||
const list = vi.fn(() => Promise.resolve([]))
|
||||
@@ -150,7 +150,8 @@ describe('SessionSkillCatalog', () => {
|
||||
modelInvocable: false,
|
||||
}],
|
||||
})
|
||||
expect(scopedList).toHaveBeenCalledWith({ cwd: '/live/current', scope: agent })
|
||||
// The live catalog reads the Session's workspace root after the directory was validated, not the validated cursor.
|
||||
expect(scopedList).toHaveBeenCalledWith({ cwd: '/live/project', scope: agent })
|
||||
expect(ensureDirectory).toHaveBeenCalledWith(agent, expect.any(AbortSignal))
|
||||
expect(session.header.cwd).toBe('/live/project')
|
||||
expect(acquireScope).not.toHaveBeenCalled()
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
en: d5eb7912c65b4e26
|
||||
zh: 7deb2a8167a82c90
|
||||
/deepseek-ai-dsh-api-terminal-controller/summary:
|
||||
en: afcf6f0d2f899ecc
|
||||
zh: e38e2c0830e42ac9
|
||||
en: b894229b0a468b8c
|
||||
zh: cd55581c0db30bb4
|
||||
/deepseek-ai-dsh-api-terminal-controller/table-of-contents:
|
||||
en: d152484eb41ac6b4
|
||||
zh: 1fa9a72d1ee045cc
|
||||
|
||||
@@ -9,7 +9,7 @@ English | [中文](README.zh.md)
|
||||
|
||||
## Summary
|
||||
|
||||
Open the execution environment's default shell in the Session's current working directory from the Web sidebar. Reconnect to existing processes and close their complete provider-owned process ranges. Terminal output stays outside the Agent transcript. Keeping a terminal open retains its process and a bounded screen buffer.
|
||||
Open the execution environment's default shell in the Session's workspace root from the Web sidebar. Reconnect to existing processes and close their complete provider-owned process ranges. Terminal output stays outside the Agent transcript. Keeping a terminal open retains its process and a bounded screen buffer.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ kind: "package-reference"
|
||||
|
||||
## 概述
|
||||
|
||||
从 Web 侧栏在 Session 当前工作目录打开执行环境的默认 shell。重新连接已有进程,并关闭 provider 管理的完整进程范围。终端输出不进入 Agent 对话记录。保留终端会占用进程和有界屏幕缓存。
|
||||
从 Web 侧栏在 Session 工作区根打开执行环境的默认 shell。重新连接已有进程,并关闭 provider 管理的完整进程范围。终端输出不进入 Agent 对话记录。保留终端会占用进程和有界屏幕缓存。
|
||||
|
||||
## 目录
|
||||
|
||||
|
||||
@@ -110,16 +110,16 @@ export class TerminalController extends TypertRemoteService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the Session's current directory and terminal limits without filesystem validation or shell lookup.
|
||||
* Read the Session's workspace root and terminal limits without filesystem validation or shell lookup.
|
||||
* @param agent - Session owner supplied by the Gateway.
|
||||
* @param signal - request cancellation.
|
||||
* @returns the logged current directory and terminal limits; retained terminals keep their own process directories.
|
||||
* @returns the logged workspace root and terminal limits; retained terminals keep their own process directories.
|
||||
*/
|
||||
@Remote
|
||||
environment(agent: Agent, signal: AbortSignal): TerminalEnvironment {
|
||||
signal.throwIfAborted()
|
||||
const { workingDirectory } = this.execution(agent)
|
||||
return { cwd: workingDirectory.get(agent.session),
|
||||
return { cwd: workingDirectory.rootOf(agent.session),
|
||||
maxInputBytes: this.config.maxInputBytes, maxBufferedBytes: this.config.maxBufferedBytes, maxCols: this.config.maxCols,
|
||||
maxRows: this.config.maxRows, scrollback: this.config.scrollback }
|
||||
}
|
||||
@@ -312,7 +312,9 @@ export class TerminalController extends TypertRemoteService {
|
||||
|
||||
private async spawn(agent: Agent, owner: OwnedSession, request: TerminalCreateRequest, signal: AbortSignal): Promise<BrowserTerminal> {
|
||||
const { subprocess, workingDirectory } = this.execution(agent)
|
||||
const cwd = await workingDirectory.ensure(agent, signal)
|
||||
// A user terminal starts in the checkout the Session works in, not at the model's cursor.
|
||||
await workingDirectory.ensure(agent, signal)
|
||||
const cwd = workingDirectory.rootOf(agent.session)
|
||||
const shell = request.shellPath === undefined
|
||||
? await resolveShell(subprocess, this.config.shell, signal)
|
||||
: (await this.shells(agent, signal)).find(candidate => candidate.path === request.shellPath)
|
||||
|
||||
@@ -30,7 +30,7 @@ export interface TerminalShell {
|
||||
|
||||
/** Current Session directory and terminal limits; retained terminals keep their own process directories. */
|
||||
export interface TerminalEnvironment {
|
||||
/** Logged current directory, read without filesystem validation. */
|
||||
/** Logged workspace root a new terminal starts in, read without filesystem validation. */
|
||||
readonly cwd: string
|
||||
readonly maxInputBytes: number
|
||||
/** Maximum complete encoded Client input bytes retained until acknowledgement. */
|
||||
|
||||
@@ -34,6 +34,7 @@ function fixture(overrides: Partial<Config> = {}) {
|
||||
const sandboxPolicy = { defaultMode: 'danger-full-access', workspaceRoot: '/workspace', resolve: vi.fn((): SandboxExecutionPolicy => ({ mode: 'danger-full-access', workspaceRoot: '/workspace' })) }
|
||||
const workingDirectory = {
|
||||
get: vi.fn<(session: Agent['session']) => string>(session => session.header.cwd ?? '/workspace'),
|
||||
rootOf: vi.fn<(session: Agent['session']) => string>(session => session.header.cwd ?? '/workspace'),
|
||||
ensure: vi.fn<(agent: Agent, signal?: AbortSignal) => Promise<string>>(async agent => agent.session.header.cwd ?? '/workspace'),
|
||||
}
|
||||
ctx.provide('sandboxPolicy', sandboxPolicy as never)
|
||||
@@ -107,15 +108,17 @@ describe('TerminalController', () => {
|
||||
expect(sandboxPolicy.resolve).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('uses the current directory for new user terminals while retaining earlier directories and permissions', async () => {
|
||||
it('uses the workspace root for new user terminals while retaining earlier directories and permissions', async () => {
|
||||
const { ctx, controller, agent, subprocess, sandboxPolicy, workingDirectory } = fixture()
|
||||
const policy: SandboxExecutionPolicy = { mode: 'workspace-write', workspaceRoot: '/workspace', sessionId: agent.id }
|
||||
sandboxPolicy.resolve.mockReturnValue(policy)
|
||||
const confine = vi.fn(async (argv: readonly string[], _policy: SandboxExecutionPolicy) => ({ argv: [...argv] }))
|
||||
ctx.provide('sandbox', { confine } as never)
|
||||
const first = await controller.create(agent, request, signal())
|
||||
workingDirectory.get.mockReturnValue('/workspace/selected')
|
||||
workingDirectory.ensure.mockResolvedValue('/workspace/selected')
|
||||
// The Session relocates into a worktree: its root moves while the model's cursor may sit deeper inside it.
|
||||
workingDirectory.rootOf.mockReturnValue('/workspace/selected')
|
||||
workingDirectory.get.mockReturnValue('/workspace/selected/packages')
|
||||
workingDirectory.ensure.mockResolvedValue('/workspace/selected/packages')
|
||||
|
||||
expect(controller.environment(agent, signal()).cwd).toBe('/workspace/selected')
|
||||
expect(workingDirectory.ensure).toHaveBeenCalledOnce()
|
||||
@@ -131,8 +134,9 @@ describe('TerminalController', () => {
|
||||
expect(controller.list(agent.id).map(terminal => terminal.cwd)).toEqual(['/workspace', '/workspace/selected'])
|
||||
})
|
||||
|
||||
it('captures the validated directory before a delayed shell lookup', async () => {
|
||||
it('captures the validated root before a delayed shell lookup', async () => {
|
||||
const { controller, agent, subprocess, workingDirectory } = fixture()
|
||||
workingDirectory.rootOf.mockReturnValue('/workspace/starting')
|
||||
workingDirectory.ensure.mockResolvedValue('/workspace/starting')
|
||||
const entered = Promise.withResolvers<undefined>()
|
||||
const release = Promise.withResolvers<undefined>()
|
||||
@@ -144,7 +148,7 @@ describe('TerminalController', () => {
|
||||
const creating = controller.create(agent, request, signal())
|
||||
try {
|
||||
await entered.promise
|
||||
workingDirectory.get.mockReturnValue('/workspace/later')
|
||||
workingDirectory.rootOf.mockReturnValue('/workspace/later')
|
||||
workingDirectory.ensure.mockResolvedValue('/workspace/later')
|
||||
release.resolve(undefined)
|
||||
expect((await creating).cwd).toBe('/workspace/starting')
|
||||
@@ -158,8 +162,12 @@ describe('TerminalController', () => {
|
||||
|
||||
it('uses recovered directory values for new creation and leaves environment reads unvalidated', async () => {
|
||||
const { controller, agent, subprocess, workingDirectory } = fixture()
|
||||
workingDirectory.get.mockReturnValue('/missing')
|
||||
workingDirectory.ensure.mockResolvedValue('/workspace/recovered')
|
||||
workingDirectory.rootOf.mockReturnValue('/missing')
|
||||
// Recovery commits the original project as the root again before the directory is handed back.
|
||||
workingDirectory.ensure.mockImplementation(async () => {
|
||||
workingDirectory.rootOf.mockReturnValue('/workspace/recovered')
|
||||
return '/workspace/recovered'
|
||||
})
|
||||
expect(controller.environment(agent, signal()).cwd).toBe('/missing')
|
||||
expect(workingDirectory.ensure).not.toHaveBeenCalled()
|
||||
|
||||
@@ -169,7 +177,7 @@ describe('TerminalController', () => {
|
||||
expect(workingDirectory.ensure).toHaveBeenCalledWith(agent, expect.any(AbortSignal))
|
||||
expect(subprocess.spawnTerminal).toHaveBeenCalledWith(expect.objectContaining({ cwd: '/workspace/recovered' }))
|
||||
workingDirectory.ensure.mockRejectedValue(new Error('original directory is unavailable'))
|
||||
expect(controller.environment(agent, signal()).cwd).toBe('/missing')
|
||||
expect(controller.environment(agent, signal()).cwd).toBe('/workspace/recovered')
|
||||
expect(await controller.create(agent, request, signal())).toBe(created)
|
||||
await expect(controller.create(agent, { ...request, id: 'unavailable' as WebTerminalId }, signal()))
|
||||
.rejects.toThrow('original directory is unavailable')
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
en: d152484eb41ac6b4
|
||||
zh: 09388d293f9be9cb
|
||||
/deepseek-ai-dsh-api-workspace-files/use-this-package:
|
||||
en: 874054ed5e950973
|
||||
zh: e8b55d62939c4c2f
|
||||
en: 0dcc561a32c95842
|
||||
zh: af6355823a56bbf0
|
||||
/deepseek-ai-dsh-api-workspace-files/use-this-package/addressing-and-paths:
|
||||
en: b9565cfa7a1da451
|
||||
zh: fc4078a58322fc7f
|
||||
@@ -45,8 +45,8 @@
|
||||
en: 42b15ac6321706aa
|
||||
zh: ce1d25bffb6948cd
|
||||
/deepseek-ai-dsh-api-workspace-files/understand-the-implementation/design-concept:
|
||||
en: c3a8852c33dcc0e9
|
||||
zh: d24fd47da7faaa29
|
||||
en: 97a9235f16708751
|
||||
zh: 43551f0115b408d1
|
||||
/deepseek-ai-dsh-api-workspace-files/understand-the-implementation/source-map:
|
||||
en: 596a75f43bfafda3
|
||||
zh: 3cb267a0946cd75e
|
||||
|
||||
@@ -25,7 +25,7 @@ Use this package to preview files readable through a Session's filesystem from t
|
||||
<a id="use-this-package"></a>
|
||||
## Use this package
|
||||
|
||||
Mount the package beside `dsh-fs`, `dsh-sandbox-policy`, the Session store, and the Typert Gateway; the bundle does so right after the Session Controller. Every method takes the Session identity on the wire, so a Client calls `remote.workspaceFiles.read(sessionId, path, range, signal)`, `stat(sessionId, path, signal)`, `readBytes(sessionId, path, options, signal)`, `list(sessionId, path, signal)`, or `changes(sessionId, path, signal)` and never names a root itself. The Host reads a live Session header or uses persistence `stat` for a cold Session; it does not activate an Agent, read the event body, or borrow a parent Session's root. Session persistence is optional for live reads, but without it a cold Session cannot resolve and the Gateway returns `gateway/lookup-not-found`.
|
||||
Mount the package beside `dsh-fs`, `dsh-sandbox-policy`, the Session store, and the Typert Gateway; the bundle does so right after the Session Controller. Every method takes the Session identity on the wire, so a Client calls `remote.workspaceFiles.read(sessionId, path, range, signal)`, `stat(sessionId, path, signal)`, `readBytes(sessionId, path, options, signal)`, `list(sessionId, path, signal)`, or `changes(sessionId, path, signal)` and never names a root itself. The Host reads a live Session's workspace root from the working-directory service, or a cold Session's recorded root from the projection cache beside its persisted header, falling back to the header directory; it does not activate an Agent, read the event body, or borrow a parent Session's root. `resolveWorkspaceFileScope(ctx, sessionId, signal)` exports that resolution for other Host services that open the same `session/<id>/<path>` addresses. Session persistence is optional for live reads, but without it a cold Session cannot resolve and the Gateway returns `gateway/lookup-not-found`.
|
||||
|
||||
| Method | Returns | Purpose |
|
||||
|---|---|---|
|
||||
@@ -92,7 +92,7 @@ One supervised `changes` stream serves each Session and requested path; consumer
|
||||
|
||||
### Design concept
|
||||
|
||||
Reads through `ctx.fs` use the backend's read authority; the sandboxing backend fences writes and edits, not reads. A Typert lookup derives `WorkspaceFileScope` from a live Session header or the persistence service's header-only `stat`, so cold subagent Sessions need neither Agent activation nor event-body reads. The service adds regular-file checks and bounded transfer, while workspace containment belongs only to directory listing and directory watching. A page is cut from `streamText`, which decodes and rejects non-UTF-8 chunk by chunk: the cutter counts lines before the window without keeping them, admits each in-window segment against the byte cap before buffering it, and returns at the first character past the window. One `stat` before the stream names the version and size the page reports.
|
||||
Reads through `ctx.fs` use the backend's read authority; the sandboxing backend fences writes and edits, not reads. A Typert lookup derives `WorkspaceFileScope` from a live Session's workspace root or a stored Session's cached root beside the persistence service's header-only `stat`, so cold subagent Sessions need neither Agent activation nor event-body reads. The service adds regular-file checks and bounded transfer, while workspace containment belongs only to directory listing and directory watching. A page is cut from `streamText`, which decodes and rejects non-UTF-8 chunk by chunk: the cutter counts lines before the window without keeping them, admits each in-window segment against the byte cap before buffering it, and returns at the first character past the window. One `stat` before the stream names the version and size the page reports.
|
||||
|
||||
Complete-file reads delegate size enforcement to `fs.readBytes` and return raw bytes through the binary Remote.
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ kind: "package-reference"
|
||||
<a id="use-this-package"></a>
|
||||
## 使用本包
|
||||
|
||||
把本包与 `dsh-fs`、`dsh-sandbox-policy`、Session store 和 Typert Gateway 一起挂载;bundle 把它紧随 Session Controller 之后挂载。每个方法都在线路上携带 Session 身份,Client 调用 `remote.workspaceFiles.read(sessionId, path, range, signal)`、`stat(sessionId, path, signal)`、`readBytes(sessionId, path, options, signal)`、`list(sessionId, path, signal)` 或 `changes(sessionId, path, signal)`,从不自己指定根。Host 读取 live Session header,cold Session 则使用持久层 `stat`;它不会激活 Agent、读取事件正文或借用父 Session 的根。live 读取不要求挂载 Session persistence;未挂载时 cold Session 无法解析,Gateway 返回 `gateway/lookup-not-found`。
|
||||
把本包与 `dsh-fs`、`dsh-sandbox-policy`、Session store 和 Typert Gateway 一起挂载;bundle 把它紧随 Session Controller 之后挂载。每个方法都在线路上携带 Session 身份,Client 调用 `remote.workspaceFiles.read(sessionId, path, range, signal)`、`stat(sessionId, path, signal)`、`readBytes(sessionId, path, options, signal)`、`list(sessionId, path, signal)` 或 `changes(sessionId, path, signal)`,从不自己指定根。Host 从工作目录服务读取 live Session 的工作区根,cold Session 则读取持久化 header 旁投影缓存中记录的根,再回退到 header 目录;它不会激活 Agent、读取事件正文或借用父 Session 的根。`resolveWorkspaceFileScope(ctx, sessionId, signal)` 把这一解析导出给打开同一种 `session/<id>/<path>` 地址的其他 Host 服务。live 读取不要求挂载 Session persistence;未挂载时 cold Session 无法解析,Gateway 返回 `gateway/lookup-not-found`。
|
||||
|
||||
| 方法 | 返回 | 用途 |
|
||||
|---|---|---|
|
||||
@@ -92,7 +92,7 @@ kind: "package-reference"
|
||||
|
||||
### 设计概念
|
||||
|
||||
经 `ctx.fs` 的读取使用后端的读取权限;沙箱后端限制写与编辑,而不限制读取。Typert lookup 从 live Session header 或持久层的 header-only `stat` 导出 `WorkspaceFileScope`,所以 cold subagent Session 不需要激活 Agent 或读取事件正文。本服务增加普通文件检查与有界传输,工作区包含要求只属于目录列举与目录监听。页从 `streamText` 切出,后者逐块解码并拒绝非 UTF-8:切页器对窗口之前的行只计数不保留,对窗口内的每个片段先按字节上限验收再缓冲,并在窗口之后的第一个字符处返回。流之前的一次 `stat` 给出页所报告的版本与大小。
|
||||
经 `ctx.fs` 的读取使用后端的读取权限;沙箱后端限制写与编辑,而不限制读取。Typert lookup 从 live Session 的工作区根,或 stored Session 在持久层 header-only `stat` 旁缓存的根导出 `WorkspaceFileScope`,所以 cold subagent Session 不需要激活 Agent 或读取事件正文。本服务增加普通文件检查与有界传输,工作区包含要求只属于目录列举与目录监听。页从 `streamText` 切出,后者逐块解码并拒绝非 UTF-8:切页器对窗口之前的行只计数不保留,对窗口内的每个片段先按字节上限验收再缓冲,并在窗口之后的第一个字符处返回。流之前的一次 `stat` 给出页所报告的版本与大小。
|
||||
|
||||
完整文件读取将大小上限检查交给 `fs.readBytes`,并通过二进制 Remote 返回原始字节。
|
||||
|
||||
|
||||
@@ -59,7 +59,9 @@
|
||||
"zod": "4.4.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@deepseek-ai/cordis": "workspace:~"
|
||||
"@deepseek-ai/cordis": "workspace:~",
|
||||
"@deepseek-ai/dsh-session-projection-cache": "workspace:*",
|
||||
"@deepseek-ai/dsh-working-directory": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@deepseek-ai/cordis": "workspace:~",
|
||||
@@ -73,7 +75,9 @@
|
||||
"@deepseek-ai/dsh-sandbox-policy": "workspace:*",
|
||||
"@deepseek-ai/dsh-session": "workspace:*",
|
||||
"@deepseek-ai/dsh-session-persistence": "workspace:*",
|
||||
"@deepseek-ai/dsh-util-workspace-path": "workspace:*"
|
||||
"@deepseek-ai/dsh-session-projection-cache": "workspace:*",
|
||||
"@deepseek-ai/dsh-util-workspace-path": "workspace:*",
|
||||
"@deepseek-ai/dsh-working-directory": "workspace:*"
|
||||
},
|
||||
"files": [
|
||||
"locale/*.json",
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* `workspaceFiles`.
|
||||
*
|
||||
* File reads follow the composed filesystem's read access, including paths
|
||||
* outside the workspace. The selected Session header supplies the base for
|
||||
* relative paths, with the sandbox policy root as its no-cwd fallback, not a
|
||||
* read-containment restriction. Directory listings and change observations
|
||||
* outside the workspace. The selected Session's workspace root supplies the
|
||||
* base for relative paths, with the header directory and then the sandbox
|
||||
* policy root as fallbacks, not a read-containment restriction. Directory listings and change observations
|
||||
* remain workspace-scoped. File-kind checks and configured read caps apply to
|
||||
* every preview; this service exposes no mutations.
|
||||
*
|
||||
@@ -27,8 +27,10 @@ import type { FsDirEntry, FsInfo, FsPathInfo, FsTarget } from '@deepseek-ai/dsh-
|
||||
import type {} from '@deepseek-ai/dsh-sandbox-policy'
|
||||
import type {} from '@deepseek-ai/dsh-session'
|
||||
import type {} from '@deepseek-ai/dsh-session-persistence'
|
||||
import type {} from '@deepseek-ai/dsh-session-projection-cache'
|
||||
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
import { Remote, RemoteError, TypertRemoteService, type TypertLookup } from '@deepseek-ai/dsh-typert-protocol'
|
||||
import type {} from '@deepseek-ai/dsh-working-directory'
|
||||
import { WorkspaceChangeFeed } from './changes.ts'
|
||||
import type {
|
||||
WorkspaceByteRange,
|
||||
@@ -55,10 +57,39 @@ declare module '@deepseek-ai/cordis' {
|
||||
export interface WorkspaceFileScope {
|
||||
/** Session identity received on the wire. */
|
||||
readonly sessionId: SessionId
|
||||
/** Session workspace root, or the deployment fallback when its header has no cwd. */
|
||||
/**
|
||||
* Session workspace root: the checkout the Session works in, read from the
|
||||
* working-directory service for a live Session and from the projection cache
|
||||
* for a stored one; its header directory when neither records a root, and
|
||||
* the deployment fallback when the header has no directory.
|
||||
*/
|
||||
readonly workspaceRoot: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the workspace root a Session's file views and directory listings
|
||||
* use, without loading its event body or activating an Agent.
|
||||
* @param ctx - Host context carrying the Session store and the sandbox policy fallback, and optionally persistence,
|
||||
* the projection cache, and the working-directory service.
|
||||
* @param sessionId - Session identity received on the wire.
|
||||
* @param signal - cancellation for the persistence read of a stored Session.
|
||||
* @returns the scope, or undefined when no live or stored Session has that identity.
|
||||
*/
|
||||
export async function resolveWorkspaceFileScope(
|
||||
ctx: Context, sessionId: SessionId, signal?: AbortSignal,
|
||||
): Promise<WorkspaceFileScope | undefined> {
|
||||
const live = ctx.get('sessions')?.get(sessionId)
|
||||
if (live !== undefined) {
|
||||
const directories = ctx.get('workingDirectory')
|
||||
const root = directories !== undefined && directories.anchorsOf(live).length > 0 ? directories.rootOf(live) : live.header.cwd
|
||||
return { sessionId, workspaceRoot: root ?? ctx.sandboxPolicy.workspaceRoot }
|
||||
}
|
||||
const stored = await ctx.get('sessionPersistence')?.stat(sessionId, signal === undefined ? undefined : { signal })
|
||||
if (stored === undefined) return undefined
|
||||
const cached = ctx.get('sessionProjectionCache')?.cachedSnapshot(stored.header, ['workspaceRoot'])?.values.workspaceRoot
|
||||
return { sessionId, workspaceRoot: cached ?? stored.header.cwd ?? ctx.sandboxPolicy.workspaceRoot }
|
||||
}
|
||||
|
||||
declare module '@deepseek-ai/dsh-typert-protocol' {
|
||||
interface TypertLookupMap {
|
||||
/** Resolve a Session id to its workspace root without loading its event body or activating an Agent. */
|
||||
@@ -206,18 +237,7 @@ export class WorkspaceFiles extends TypertRemoteService {
|
||||
resource: 'session',
|
||||
hostTypeSymbol: '@deepseek-ai/dsh-api-workspace-files#WorkspaceFileScope',
|
||||
wireTypeSymbol: '@deepseek-ai/dsh-session/types#SessionId',
|
||||
resolve: async (sessionId) => {
|
||||
const live = scope.sessions.get(sessionId)?.header
|
||||
const stored = live === undefined
|
||||
? await scope.get('sessionPersistence')?.stat(sessionId)
|
||||
: undefined
|
||||
const header = live ?? stored?.header
|
||||
if (header === undefined) return undefined
|
||||
return {
|
||||
sessionId,
|
||||
workspaceRoot: header.cwd ?? scope.sandboxPolicy.workspaceRoot,
|
||||
}
|
||||
},
|
||||
resolve: sessionId => resolveWorkspaceFileScope(scope, sessionId),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Context } from '@deepseek-ai/cordis'
|
||||
import SessionStore, { SESSION_FORMAT_VERSION, SessionId, type SessionHeader } from '@deepseek-ai/dsh-session'
|
||||
import TypertRegistry from '@deepseek-ai/dsh-typert-registry'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import WorkspaceFiles from '../src/index.ts'
|
||||
import WorkspaceFiles, { resolveWorkspaceFileScope } from '../src/index.ts'
|
||||
|
||||
const CAPS = {
|
||||
maxBytes: 1024,
|
||||
@@ -24,10 +24,54 @@ function header(id: SessionId, cwd?: string): SessionHeader {
|
||||
}
|
||||
|
||||
describe('Workspace Files Session scope lookup', () => {
|
||||
it('prefers the recorded workspace root of a live or stored Session over its header directory', async () => {
|
||||
const liveId = SessionId('live-relocated')
|
||||
const coldId = SessionId('cold-relocated')
|
||||
const plainId = SessionId('cold-plain')
|
||||
const liveRoot = resolve('live-workspace')
|
||||
const liveWorktree = resolve('live-workspace', '.agents', 'worktrees', 'topic')
|
||||
const coldRoot = resolve('cold-workspace')
|
||||
const coldWorktree = resolve('elsewhere', 'cold-topic')
|
||||
const stat = vi.fn(async (id: SessionId) => {
|
||||
if (id === coldId) return { header: header(coldId, coldRoot) }
|
||||
if (id === plainId) return { header: header(plainId, coldRoot) }
|
||||
return undefined
|
||||
})
|
||||
const cachedSnapshot = vi.fn((meta: SessionHeader) =>
|
||||
meta.id === coldId ? { asOfSeq: 4, values: { workspaceRoot: coldWorktree } } : undefined)
|
||||
const ctx = new Context()
|
||||
ctx.provide('fs', {} as never)
|
||||
ctx.provide('sandboxPolicy', { workspaceRoot: resolve('fallback-workspace') } as never)
|
||||
ctx.provide('sessionPersistence', { stat } as never)
|
||||
ctx.provide('sessionProjectionCache', { cachedSnapshot } as never)
|
||||
ctx.provide('workingDirectory', {
|
||||
anchorsOf: () => [liveRoot, liveWorktree],
|
||||
rootOf: () => liveWorktree,
|
||||
} as never)
|
||||
const sessions = await ctx.plugin(SessionStore)
|
||||
const typert = await ctx.plugin(TypertRegistry)
|
||||
const workspaceFiles = await ctx.plugin(WorkspaceFiles, CAPS)
|
||||
try {
|
||||
ctx.sessions.create(liveId, { meta: { cwd: liveRoot, origin: 'subagent' } })
|
||||
await expect(resolveWorkspaceFileScope(ctx, liveId)).resolves.toEqual({ sessionId: liveId, workspaceRoot: liveWorktree })
|
||||
await expect(resolveWorkspaceFileScope(ctx, coldId)).resolves.toEqual({ sessionId: coldId, workspaceRoot: coldWorktree })
|
||||
await expect(resolveWorkspaceFileScope(ctx, plainId)).resolves.toEqual({ sessionId: plainId, workspaceRoot: coldRoot })
|
||||
expect(cachedSnapshot).toHaveBeenCalledWith(expect.objectContaining({ id: coldId }), ['workspaceRoot'])
|
||||
const lookup = ctx.typert.lookups.get('workspaceFileScope')
|
||||
if (lookup === undefined) throw new Error('workspaceFileScope lookup did not register')
|
||||
await expect(lookup.resolve(liveId)).resolves.toEqual({ sessionId: liveId, workspaceRoot: liveWorktree })
|
||||
} finally {
|
||||
await workspaceFiles.dispose()
|
||||
await sessions.dispose()
|
||||
await typert.dispose()
|
||||
}
|
||||
})
|
||||
|
||||
it('uses live or stored headers without an Agent and leaves with its plugin', async () => {
|
||||
const liveId = SessionId('live-subagent')
|
||||
const coldId = SessionId('cold-subagent')
|
||||
const fallbackId = SessionId('cold-without-cwd')
|
||||
const liveFallbackId = SessionId('live-without-cwd')
|
||||
const missingId = SessionId('missing')
|
||||
const liveRoot = resolve('live-workspace')
|
||||
const coldRoot = resolve('cold-workspace')
|
||||
@@ -47,6 +91,7 @@ describe('Workspace Files Session scope lookup', () => {
|
||||
|
||||
try {
|
||||
ctx.sessions.create(liveId, { meta: { cwd: liveRoot, origin: 'subagent' } })
|
||||
ctx.sessions.create(liveFallbackId, { meta: { origin: 'subagent' } })
|
||||
expect(ctx.get('agents')).toBeUndefined()
|
||||
const lookup = ctx.typert.lookups.get('workspaceFileScope')
|
||||
expect(lookup).toMatchObject({
|
||||
@@ -60,11 +105,15 @@ describe('Workspace Files Session scope lookup', () => {
|
||||
if (lookup === undefined) throw new Error('workspaceFileScope lookup did not register')
|
||||
|
||||
await expect(lookup.resolve(liveId)).resolves.toEqual({ sessionId: liveId, workspaceRoot: liveRoot })
|
||||
await expect(lookup.resolve(liveFallbackId)).resolves.toEqual({ sessionId: liveFallbackId, workspaceRoot: fallbackRoot })
|
||||
expect(stat).not.toHaveBeenCalled()
|
||||
const signal = new AbortController().signal
|
||||
await expect(resolveWorkspaceFileScope(ctx, coldId, signal)).resolves.toEqual({ sessionId: coldId, workspaceRoot: coldRoot })
|
||||
expect(stat).toHaveBeenLastCalledWith(coldId, { signal })
|
||||
await expect(lookup.resolve(coldId)).resolves.toEqual({ sessionId: coldId, workspaceRoot: coldRoot })
|
||||
await expect(lookup.resolve(fallbackId)).resolves.toEqual({ sessionId: fallbackId, workspaceRoot: fallbackRoot })
|
||||
await expect(lookup.resolve(missingId)).resolves.toBeUndefined()
|
||||
expect(stat.mock.calls.map(([id]) => id)).toEqual([coldId, fallbackId, missingId])
|
||||
expect(stat.mock.calls.map(([id]) => id)).toEqual([coldId, coldId, fallbackId, missingId])
|
||||
|
||||
await workspaceFiles.dispose()
|
||||
expect(ctx.typert.lookups.get('workspaceFileScope')).toBeUndefined()
|
||||
|
||||
@@ -34,6 +34,12 @@
|
||||
},
|
||||
{
|
||||
"path": "../../util/deque"
|
||||
},
|
||||
{
|
||||
"path": "../../session/session-projection-cache"
|
||||
},
|
||||
{
|
||||
"path": "../../session/working-directory"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -6,6 +6,12 @@
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.client.json"
|
||||
},
|
||||
{
|
||||
"path": "../../session/session-projection-cache"
|
||||
},
|
||||
{
|
||||
"path": "../../session/working-directory"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -82,7 +82,7 @@ function styleInjectionModule(
|
||||
* Everything else under @deepseek-ai/* is either a module-table entry
|
||||
* (external) or a leak the purity gate rejects.
|
||||
*/
|
||||
export const INLINE_SAFE = /^(?:@deepseek-ai\/dsh-(?:file-reference|session|llm|tools|brand|official-bundles|deque|output-retention|typert-protocol|util-crypto|util-time|util-values|util-workspace-path)(?:\/|$)|@deepseek-ai\/dsh-util-file-drag$|@deepseek-ai\/dsh-token-meter\/client$|@deepseek-ai\/dsh-commands\/builtin$|@deepseek-ai\/dsh-native-command\/types$|@deepseek-ai\/dsh-host-open-in-app\/shared$|@deepseek-ai\/dsh-plugin-manager\/registry$|@deepseek-ai\/dsh-agent-preset-registry\/display$|@deepseek-ai\/dsh-api-workspace-controller\/default-workspace$|@deepseek-ai\/dsh-spill-policy\/notice$)/
|
||||
export const INLINE_SAFE = /^(?:@deepseek-ai\/dsh-(?:file-reference|session|llm|tools|brand|official-bundles|deque|output-retention|typert-protocol|util-crypto|util-time|util-values|util-workspace-path)(?:\/|$)|@deepseek-ai\/dsh-util-file-drag$|@deepseek-ai\/dsh-token-meter\/client$|@deepseek-ai\/dsh-commands\/builtin$|@deepseek-ai\/dsh-native-command\/types$|@deepseek-ai\/dsh-host-open-in-app\/shared$|@deepseek-ai\/dsh-plugin-manager\/registry$|@deepseek-ai\/dsh-agent-preset-registry\/display$|@deepseek-ai\/dsh-api-workspace-controller\/default-workspace$|@deepseek-ai\/dsh-api-session-controller\/client\/directories$|@deepseek-ai\/dsh-spill-policy\/notice$)/
|
||||
|
||||
/**
|
||||
* Vendored framework libraries: rescoped into @deepseek-ai, so the gate below
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { Context } from '@deepseek-ai/cordis'
|
||||
import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment'
|
||||
import type {} from '@deepseek-ai/dsh-api-remotes/client'
|
||||
import type { SessionBinding } from '@deepseek-ai/dsh-api-session-controller/client'
|
||||
import { sessionDirectories } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
import type { GroupKey } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
||||
import { createSnapshotStore, type ObservableSnapshot } from '@deepseek-ai/dsh-client-store'
|
||||
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
@@ -270,9 +271,8 @@ export function apply(ctx: Context): void {
|
||||
// its top or at line 400, so the same tab is revealed and told where
|
||||
// to land.
|
||||
openFile: async (path, options) => {
|
||||
const cwd = ctx.sessions.list.getSnapshot().byId[sessionId]?.cwd
|
||||
const current = session.projections.faceOf('workingDirectory').getSnapshot() as string | null | undefined
|
||||
const url = fileAddressFor(sessionId, cwd, resolveWorkspacePath(current ?? undefined, path))
|
||||
const directories = sessionDirectories(ctx.sessions, sessionId)
|
||||
const url = fileAddressFor(sessionId, directories.root, resolveWorkspacePath(directories.cwd, path))
|
||||
if (options?.line === undefined) ctx.sidebarRight.openResource(url)
|
||||
else ctx.sidebarRight.openResource(url, { params: { line: options.line } })
|
||||
await Promise.resolve()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
import { resolveWorkspacePath } from '@deepseek-ai/dsh-util-workspace-path'
|
||||
import type {} from '@deepseek-ai/dsh-api-session-controller/client'
|
||||
import { sessionDirectories } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
|
||||
/**
|
||||
* Bind path resolution to the originating Session without capturing its current directory.
|
||||
@@ -11,9 +11,5 @@ import type {} from '@deepseek-ai/dsh-api-session-controller/client'
|
||||
* @returns Resolver using the live working directory, falling back to the workspace root.
|
||||
*/
|
||||
export function sessionFilePath(ctx: Context, sessionId: SessionId): (path: string) => string {
|
||||
return (path) => {
|
||||
const cwd = ctx.sessions.list.getSnapshot().byId[sessionId]?.cwd
|
||||
const current = ctx.sessions.binding(sessionId)?.session.projections.faceOf('workingDirectory').getSnapshot() as string | null | undefined
|
||||
return resolveWorkspacePath(current ?? cwd, path)
|
||||
}
|
||||
return path => resolveWorkspacePath(sessionDirectories(ctx.sessions, sessionId).cwd, path)
|
||||
}
|
||||
@@ -34,10 +34,10 @@ function Counts({ added, deleted, t }: { added: number; deleted: number } & Prop
|
||||
* @param props - the recorded summary, the review opener, and localized copy.
|
||||
* @returns the card.
|
||||
*/
|
||||
export function ChangedFiles({ changes, cwd, openReview, t, sessionId, useChangesDiff, loadChangesDiff }: {
|
||||
export function ChangedFiles({ changes, workspaceRoot, openReview, t, sessionId, useChangesDiff, loadChangesDiff }: {
|
||||
/** The served summary with the sequence of the event that announced it. */
|
||||
changes: Pick<ChangesSummary, 'files' | 'total' | 'added' | 'deleted'> & { seq: number }
|
||||
cwd: string | undefined
|
||||
workspaceRoot: string | undefined
|
||||
/** Open the turn's review on the file at an original summary index. */
|
||||
openReview: (index: number) => void
|
||||
} & PropsLocale<typeof NS> & PreviewProps) {
|
||||
@@ -70,16 +70,17 @@ export function ChangedFiles({ changes, cwd, openReview, t, sessionId, useChange
|
||||
{singleFile === undefined ? header : <>
|
||||
<HoverCard variant="preview" widthAnchorRef={cardRef} openDelayMs={500} anchor={header}
|
||||
content={<ChangedFilePreview sessionId={sessionId} seq={changes.seq} index={0}
|
||||
display={resolveWorkspacePath(cwd, singleFile.path)} useChangesDiff={useChangesDiff}
|
||||
display={resolveWorkspacePath(workspaceRoot, singleFile.path)} useChangesDiff={useChangesDiff}
|
||||
loadChangesDiff={loadChangesDiff} t={t} />} />
|
||||
<span id={pathDescriptionId} hidden>{resolveWorkspacePath(cwd, singleFile.path)}</span>
|
||||
<span id={pathDescriptionId} hidden>{resolveWorkspacePath(workspaceRoot, singleFile.path)}</span>
|
||||
</>}
|
||||
{singleFile === undefined && <ul className={css.list}>
|
||||
{rows.map((file, index) => (
|
||||
<li key={file.display}>
|
||||
<HoverCard variant="preview" widthAnchorRef={cardRef} openDelayMs={500}
|
||||
content={<ChangedFilePreview sessionId={sessionId} seq={changes.seq} index={index}
|
||||
display={resolveWorkspacePath(cwd, file.path)} useChangesDiff={useChangesDiff} loadChangesDiff={loadChangesDiff} t={t} />}
|
||||
display={resolveWorkspacePath(workspaceRoot, file.path)} useChangesDiff={useChangesDiff}
|
||||
loadChangesDiff={loadChangesDiff} t={t} />}
|
||||
anchor={<button type="button" className={css.row}
|
||||
aria-label={t('changes.viewDiff', { name: file.display })}
|
||||
aria-describedby={`${pathDescriptionId}-${index}`}
|
||||
@@ -91,7 +92,7 @@ export function ChangedFiles({ changes, cwd, openReview, t, sessionId, useChange
|
||||
: <Counts t={t} added={file.added} deleted={file.deleted} />}
|
||||
</span>
|
||||
</button>} />
|
||||
<span id={`${pathDescriptionId}-${index}`} hidden>{resolveWorkspacePath(cwd, file.path)}</span>
|
||||
<span id={`${pathDescriptionId}-${index}`} hidden>{resolveWorkspacePath(workspaceRoot, file.path)}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/** The changed-files card, shown only while the Host serves the turn's summary, and explicitly declared files for a closing turn. */
|
||||
import { selectSessionRoot } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
import { useEffect, useState } from 'react'
|
||||
import type { TurnTailOwnerProps } from '@deepseek-ai/dsh-client-ui-chat/client'
|
||||
import { Button, IconChevronDownOutlineRegular, IconChevronUpOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
@@ -74,7 +75,7 @@ export function Deliverables({
|
||||
const { getTriggerProps } = useContextMenu()
|
||||
const [expanded, setExpanded] = useState(false)
|
||||
const showCodeDiff = useShowCodeDiff(value => value)
|
||||
const cwd = useSessions(state => state.byId[sessionId]?.cwd)
|
||||
const workspaceRoot = useSessions(state => selectSessionRoot(state, sessionId))
|
||||
const states = usePresentedOpen(value => value)
|
||||
const host = usePresentedHost(value => value)
|
||||
const announced = showCodeDiff ? matched.changes : null
|
||||
@@ -93,7 +94,7 @@ export function Deliverables({
|
||||
if (host === null) void reloadPresentedHost()
|
||||
}, [host, reloadPresentedHost])
|
||||
return <>
|
||||
{changes !== null && <ChangedFiles changes={changes} cwd={cwd} t={t}
|
||||
{changes !== null && <ChangedFiles changes={changes} workspaceRoot={workspaceRoot} t={t}
|
||||
sessionId={sessionId} useChangesDiff={useChangesDiff} loadChangesDiff={loadChangesDiff}
|
||||
openReview={(index) => { openChangesReview({ sessionId, seq: changes.seq, turn: changes.turn }, index) }} />}
|
||||
{matched.presented.length > 0 && <div
|
||||
@@ -106,7 +107,7 @@ export function Deliverables({
|
||||
</div>}
|
||||
{host !== null && host !== 'error' && !host.available && <span className={css.hostStatus}>{t('presented.unavailable')}</span>}
|
||||
<div className={css.presented} data-presented-files-row data-single={matched.presented.length === 1 ? true : undefined}>
|
||||
{presented.map(file => <PresentedFileCard key={`${file.seq}:${file.index}`} file={file} cwd={cwd}
|
||||
{presented.map(file => <PresentedFileCard key={`${file.seq}:${file.index}`} file={file} workspaceRoot={workspaceRoot}
|
||||
phase={states[presentedFileUrl(sessionId, file.seq, file.index)]}
|
||||
host={host === 'error' ? null : host} t={t}
|
||||
onPreview={() => { openFile(file.path) }}
|
||||
|
||||
@@ -20,9 +20,9 @@ function cardDescription(description: string | undefined, fallback: string): str
|
||||
* @param props - durable file metadata, Sidebar preview, Host capabilities, gesture status, and localized copy.
|
||||
* @returns the file card and its anchored action menu.
|
||||
*/
|
||||
export function PresentedFileCard({ file, cwd, phase, host, onPreview, contextMenuProps, actions, t }: {
|
||||
export function PresentedFileCard({ file, workspaceRoot, phase, host, onPreview, contextMenuProps, actions, t }: {
|
||||
file: PresentedPath
|
||||
cwd: string | undefined
|
||||
workspaceRoot: string | undefined
|
||||
phase: PresentedOpenPhase | undefined
|
||||
host: PresentedHost | null
|
||||
onPreview: () => void
|
||||
@@ -37,7 +37,7 @@ export function PresentedFileCard({ file, cwd, phase, host, onPreview, contextMe
|
||||
: t(reveal === 'directory' && phase === 'revealing' ? 'presented.directoryOpening'
|
||||
: reveal === 'directory' && phase === 'revealError' ? 'presented.directoryError' : `presented.${phase}`)
|
||||
return <div className={css.file} data-presented-file>
|
||||
<button type="button" className={css.cardPreview} title={resolveWorkspacePath(cwd, file.path)}
|
||||
<button type="button" className={css.cardPreview} title={resolveWorkspacePath(workspaceRoot, file.path)}
|
||||
aria-label={t('presented.previewCard', { name: file.path })} onClick={onPreview}
|
||||
{...contextMenuProps} />
|
||||
<span className={css.fileIcon}><FileTypeIcon path={file.path} size={20} /></span>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* selected file's turn-start and turn-end comparison drawn unified or side by
|
||||
* side, wrapped or scrolling, and controls to open the file itself.
|
||||
*/
|
||||
import { selectSessionRoot } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import type { ReactNode } from 'react'
|
||||
import {
|
||||
@@ -74,7 +75,7 @@ export function ReviewTab({
|
||||
const coordinates = useMemo(() => parseChangesReviewAddress(tab.contentId), [tab.contentId])
|
||||
if (coordinates === undefined) throw new Error(`ui-deliverables: not a review address "${tab.contentId}"`)
|
||||
const { seq } = coordinates
|
||||
const cwd = useSessions(sessions => sessions.byId[sessionId]?.cwd)
|
||||
const workspaceRoot = useSessions(sessions => selectSessionRoot(sessions, sessionId))
|
||||
const summary = useChangesSummary(value => value[changesSummaryUrl(sessionId, seq)])
|
||||
const state = useStore(store => store.byTab[tab.id])
|
||||
const host = usePresentedHost(value => value)
|
||||
@@ -142,7 +143,8 @@ export function ReviewTab({
|
||||
</Tooltip>
|
||||
{file !== undefined && <Tooltip label={t('review.openFile')} side="bottom" delayMs={500}>
|
||||
<button type="button" className={css.tool} aria-label={t('review.openFileAria', { name: file.display })} data-review-tool="open-file"
|
||||
onClick={() => { tab.actions.openResource(fileAddressFor(sessionId, cwd, file.path)) }}><IconInspectOutlineRegular /></button>
|
||||
onClick={() => { tab.actions.openResource(fileAddressFor(sessionId, workspaceRoot, file.path)) }}>
|
||||
<IconInspectOutlineRegular /></button>
|
||||
</Tooltip>}
|
||||
{file !== undefined && renderSlot('deliverables.review.file.actions', {
|
||||
actionUrl: changedFileUrl(sessionId, seq, index), available: native,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/** Serve change summaries and comparisons, and open declared or changed workspace files verified by the viewed Session's filesystem. */
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import type {} from '@deepseek-ai/dsh-api-session-controller'
|
||||
import type {} from '@deepseek-ai/dsh-api-workspace-files'
|
||||
import { resolveWorkspaceFileScope } from '@deepseek-ai/dsh-api-workspace-files'
|
||||
import type {} from '@deepseek-ai/dsh-fs'
|
||||
import type {} from '@deepseek-ai/dsh-sandbox-policy'
|
||||
import { remoteErrorOf } from '@deepseek-ai/dsh-typert-protocol'
|
||||
@@ -112,14 +112,13 @@ async function handlePresentOpen(ctx: Context, request: Request): Promise<Respon
|
||||
try {
|
||||
const read = await readTarget(ctx, request, id, seq)
|
||||
if (read instanceof Response) return read
|
||||
const { target, session } = read
|
||||
const { target } = read
|
||||
const file = target.type === 'deliverables/presented' && isPresentedData(target.data) ? target.data.files[index] : undefined
|
||||
if (!isPresentedFile(file)) return new Response('Presented file not found in this Session result.', { status: 404 })
|
||||
request.signal.throwIfAborted()
|
||||
const { absolutePath: path } = await ctx.workspaceFiles.stat({
|
||||
sessionId: id as SessionId,
|
||||
workspaceRoot: session.cwd ?? ctx.sandboxPolicy.workspaceRoot,
|
||||
}, file.path, request.signal)
|
||||
const scope = await resolveWorkspaceFileScope(ctx, id as SessionId, request.signal)
|
||||
if (scope === undefined) return new Response('Presented file Session not found.', { status: 404 })
|
||||
const { absolutePath: path } = await ctx.workspaceFiles.stat(scope, file.path, request.signal)
|
||||
return await openVerified(ctx, request, path, action)
|
||||
} catch (error: unknown) {
|
||||
request.signal.throwIfAborted()
|
||||
@@ -127,7 +126,7 @@ async function handlePresentOpen(ctx: Context, request: Request): Promise<Respon
|
||||
}
|
||||
}
|
||||
|
||||
/** The summary one `workspace/changes` event announced, without the Host working directory; 404 once the Host no longer serves it. */
|
||||
/** The summary one `workspace/changes` event announced, without the Host workspace root; 404 once the Host no longer serves it. */
|
||||
function handleChangesSummary(ctx: Context, request: Request): Response {
|
||||
const query = new URL(request.url).searchParams
|
||||
const id = query.get('sessionId')
|
||||
@@ -175,7 +174,7 @@ async function handleChangesOpen(ctx: Context, request: Request): Promise<Respon
|
||||
if (!ctx.sessionController.workspaceDesktop().available) return new Response('Host desktop unavailable.', { status: 409 })
|
||||
const changes = ctx.workspaceChanges.summary(id, seq)
|
||||
if (changes === undefined) return new Response('Change summary unavailable.', { status: 404 })
|
||||
const workspaceRoot = changes.cwd
|
||||
const workspaceRoot = changes.root
|
||||
const file = changes.files[index]
|
||||
if (file === undefined) return new Response('Changed file not found in this summary.', { status: 404 })
|
||||
const { absolutePath: path } = await ctx.workspaceFiles.stat({ sessionId: id, workspaceRoot }, file.path, request.signal)
|
||||
|
||||
@@ -24,7 +24,7 @@ function mount(fileCount = 2) {
|
||||
const getSnapshot = diffs.state.getSnapshot.bind(diffs.state)
|
||||
const changes = { seq: 5, files: files.slice(0, fileCount), total: fileCount, added: fileCount, deleted: fileCount }
|
||||
const view = render(<ChangedFiles changes={changes}
|
||||
cwd="/workspace" sessionId={sessionId} t={makeTranslate(en)} openReview={openReview}
|
||||
workspaceRoot="/workspace" sessionId={sessionId} t={makeTranslate(en)} openReview={openReview}
|
||||
loadChangesDiff={loadChangesDiff}
|
||||
useChangesDiff={select => select(useSyncExternalStore(subscribe, getSnapshot))} />)
|
||||
return { view, diffs, loadChangesDiff, openReview, row: screen.getByRole('button', { name: 'View changes to main.ts' }) }
|
||||
|
||||
@@ -37,7 +37,7 @@ async function fixture() {
|
||||
const outside = join(root, 'outside.txt')
|
||||
await writeFile(outside, 'outside')
|
||||
const data: WorkspaceChangesSummary = {
|
||||
turn: 1, cwd, total: 3, added: 3, deleted: 0, snapshot: { before: 'a'.repeat(40), after: 'b'.repeat(40) },
|
||||
turn: 1, root: cwd, total: 3, added: 3, deleted: 0, snapshot: { before: 'a'.repeat(40), after: 'b'.repeat(40) },
|
||||
files: [changed('src/lib/a.ts'), changed('src/b.ts'), changed(outside, '~/outside.txt')],
|
||||
}
|
||||
const ctx = new Context()
|
||||
|
||||
@@ -45,6 +45,9 @@ async function fixture() {
|
||||
return { session, target: { type: 'deliverables/presented', data: { turn: 1, callId: 'present-call', files: [file] } } as SessionEvent }
|
||||
})
|
||||
ctx.provide('sessionQuery', { readEvent } as never)
|
||||
// Every viewed Session is live with that header, so the workspace scope reads its original project without an Agent.
|
||||
const live = vi.fn((id: SessionId) => ({ id, header: session }))
|
||||
ctx.provide('sessions', { get: live } as never)
|
||||
const opener = vi.fn(async (_request: { path: string; action?: 'reveal' }, _signal: AbortSignal) => ({ opened: true as const }))
|
||||
const applications = vi.fn(async () => [{ id: 'player', name: 'Player', default: true, icon: null }])
|
||||
ctx.provide('sessionController', { workspacePathApplications: applications, resolveAgent, openWorkspacePath: opener, workspaceDesktop: () => ({ name: 'desktop', available: true, fileManager: 'finder' }) } as never)
|
||||
@@ -56,7 +59,8 @@ async function fixture() {
|
||||
`http://localhost${PRESENT_OPEN_PATH}${query}`, { method: 'POST', signal: signal ?? null },
|
||||
), connection.browserPeer)
|
||||
return {
|
||||
browserPeer: connection.browserPeer, applications, root, cwd, ctx, fiber, file, session, readEvent, open, opener, handler, resolveAgent,
|
||||
browserPeer: connection.browserPeer, applications, root, cwd, ctx, fiber, file, session, readEvent, open, opener, handler,
|
||||
resolveAgent, live,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +234,14 @@ it('opens a viewed child Session without activating an Agent', async () => {
|
||||
expect(resolveAgent).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('refuses a presented file whose Session is neither live nor stored once its event was read', async () => {
|
||||
const { session, readEvent, live, open, opener } = await fixture()
|
||||
readEvent.mockResolvedValueOnce({ session, target: { type: 'deliverables/presented', data: { turn: 1, callId: 'gone', files: [{ path: '日记模板.docx' }] } } as SessionEvent })
|
||||
live.mockReturnValueOnce(undefined as never)
|
||||
expect((await open('?sessionId=gone&seq=7&index=0')).status).toBe(404)
|
||||
expect(opener).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('uses the deployment workspace root when the viewed Session has no cwd', async () => {
|
||||
const { session, open, cwd, file, opener } = await fixture()
|
||||
delete session.cwd
|
||||
|
||||
@@ -10,7 +10,7 @@ afterEach(cleanup)
|
||||
const props = () => {
|
||||
const onMenu = vi.fn()
|
||||
return {
|
||||
cwd: undefined,
|
||||
workspaceRoot: undefined,
|
||||
file: { path: 'out/report.pdf', description: 'Final report', seq: 4, index: 1 },
|
||||
host: { name: 'remote-desktop', available: true, fileManager: 'finder' as const },
|
||||
phase: undefined,
|
||||
@@ -34,10 +34,10 @@ it('localizes reveal failures and restores the description when progress clears'
|
||||
it('shows the basename while retaining the full location for hover and actions', () => {
|
||||
const p = props()
|
||||
const path = '/work/reports/result.pdf'
|
||||
const view = render(<PresentedFileCard {...p} cwd="/work" file={{ ...p.file, path }} />)
|
||||
const view = render(<PresentedFileCard {...p} workspaceRoot="/work" file={{ ...p.file, path }} />)
|
||||
expect(view.getByTitle(path)).toBeTruthy()
|
||||
expect(view.getByText('result.pdf')).toBeTruthy()
|
||||
view.rerender(<PresentedFileCard {...p} cwd="/work" />)
|
||||
view.rerender(<PresentedFileCard {...p} workspaceRoot="/work" />)
|
||||
expect(view.getByTitle('/work/out/report.pdf')).toBeTruthy()
|
||||
expect(view.getByText('report.pdf')).toBeTruthy()
|
||||
})
|
||||
|
||||
@@ -9,6 +9,7 @@ import type {} from '@deepseek-ai/dsh-api-workspace-files/remote'
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-sidebar-browser/client'
|
||||
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
import type { OpenInAppController } from './controller.ts'
|
||||
import { selectSessionRoot } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
import { fileAddressFor, resolveWorkspacePath } from '@deepseek-ai/dsh-util-workspace-path'
|
||||
import type { OpenInAppPathController } from './open-path.ts'
|
||||
import type { OpenInAppKey } from './locales.ts'
|
||||
@@ -62,7 +63,7 @@ export function registerContextMenus(
|
||||
id: 'open-in-app.directory', target: 'directory', order: 100,
|
||||
resolve: async ({ sessionId, path }, signal) => {
|
||||
await paths.load()
|
||||
const cwd = ctx.sessions.list.getSnapshot().byId[sessionId]?.cwd
|
||||
const cwd = selectSessionRoot(ctx.sessions.list.getSnapshot(), sessionId)
|
||||
const absolutePath = resolveWorkspacePath(cwd, path)
|
||||
signal.throwIfAborted()
|
||||
return [
|
||||
@@ -88,7 +89,7 @@ export function registerContextMenus(
|
||||
const application = apps?.find(app => app.default)
|
||||
// The menu names a host, not the pane it was raised in: a floating pane is never a docked landing place.
|
||||
const openIn = (destination: 'sidebar' | 'float') => () => {
|
||||
const cwd = ctx.sessions.list.getSnapshot().byId[sessionId]?.cwd
|
||||
const cwd = selectSessionRoot(ctx.sessions.list.getSnapshot(), sessionId)
|
||||
ctx.sidebarRight.openResourceIn(sessionId, fileAddressFor(sessionId, cwd, path), {
|
||||
destination, ...(line === undefined ? {} : { params: { line } }),
|
||||
})
|
||||
@@ -104,7 +105,7 @@ export function registerContextMenus(
|
||||
...absolutePath === undefined || application === undefined ? {} : { run: () => open(absolutePath, 'open', application.id) } },
|
||||
{ id: 'copyPath', icon: { key: 'open-in-app.copy' }, failureLabel: t('menu.copyFailed'), label: t('menu.copyPath'),
|
||||
run: async () => {
|
||||
const cwd = ctx.sessions.list.getSnapshot().byId[sessionId]?.cwd
|
||||
const cwd = selectSessionRoot(ctx.sessions.list.getSnapshot(), sessionId)
|
||||
await navigator.clipboard.writeText(absolutePath ?? resolveWorkspacePath(cwd, path))
|
||||
ctx.contextMenus.notify(t('menu.copied'), true)
|
||||
} },
|
||||
|
||||
@@ -20,6 +20,7 @@ import type {} from '@deepseek-ai/dsh-client-ui-sidebar-documentpreview/client'
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-sidebar-files/client'
|
||||
import type {} from '@deepseek-ai/dsh-api-gateway/client'
|
||||
import type {} from '@deepseek-ai/dsh-api-remotes/client'
|
||||
import { selectSessionRoot } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
import type {} from '@deepseek-ai/dsh-api-session-controller/remote'
|
||||
import { OPEN_IN_APP_ICON_PREFIX_ROUTE } from '@deepseek-ai/dsh-host-open-in-app/shared'
|
||||
import { OpenInAppController } from './controller.ts'
|
||||
@@ -77,10 +78,11 @@ export function apply(ctx: ClientContext): void {
|
||||
}, OpenInAppToast))
|
||||
const target = () => {
|
||||
if (ctx.layout.panelInfo.getSnapshot().activePanelId !== null) return undefined
|
||||
const session = Object.values(ctx.sessions.list.getSnapshot().byId)
|
||||
.find(row => (row.retainedBy.mainView ?? 0) > 0)
|
||||
const list = ctx.sessions.list.getSnapshot()
|
||||
const session = Object.values(list.byId).find(row => (row.retainedBy.mainView ?? 0) > 0)
|
||||
const root = session === undefined ? undefined : selectSessionRoot(list, session.id)
|
||||
const appId = controller.currentApp()
|
||||
return session?.cwd && appId !== undefined ? { appId, path: session.cwd } : undefined
|
||||
return root && appId !== undefined ? { appId, path: root } : undefined
|
||||
}
|
||||
ctx.effect(() => ctx.shortcuts.register({
|
||||
id: 'workspace.openLocal' as ShortcutCommandId, label: () => t('open.tooltip'), aliases: ['open workspace locally', 'open in app'],
|
||||
@@ -117,8 +119,8 @@ export function apply(ctx: ClientContext): void {
|
||||
props: PropsRuntime<'conversation.session.header.utilities'> & Omit<OpenInAppActionProps, 'absolutePath'>,
|
||||
) {
|
||||
const { sessionId, useSessions } = props
|
||||
const cwd = useSessions(state => state.byId[sessionId]?.cwd)
|
||||
return cwd ? createElement(OpenInAppAction, { ...props, absolutePath: cwd }) : null
|
||||
const root = useSessions(state => selectSessionRoot(state, sessionId))
|
||||
return root ? createElement(OpenInAppAction, { ...props, absolutePath: root }) : null
|
||||
}
|
||||
ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({
|
||||
name: 'conversation.session.header.utilities',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/** Native directory reveal contributed to the captured Session's structured menu. */
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import { selectSessionRoot } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import type { OpenInAppController } from './controller.ts'
|
||||
import type { OpenInAppToastSource } from './open-toast.tsx'
|
||||
@@ -21,7 +22,7 @@ export function registerSessionReveal(
|
||||
id: 'open-in-app.reveal', target: 'session', order: 500,
|
||||
observe: () => [controller.apps, ctx.sessions.list, ctx.locale],
|
||||
resolve: ({ sessionId }) => {
|
||||
const directory = ctx.sessions.list.getSnapshot().byId[sessionId]?.cwd
|
||||
const directory = selectSessionRoot(ctx.sessions.list.getSnapshot(), sessionId)
|
||||
const applications = controller.apps.getSnapshot()
|
||||
const manager = applications?.find(id => ['finder', 'explorer', 'filemanager'].includes(id))
|
||||
return [{
|
||||
|
||||
@@ -41,7 +41,7 @@ async function boot() {
|
||||
.mockResolvedValue({ status: 'saved', path: '/downloads/file.svg' })
|
||||
const copyImage = vi.fn<(source: FileActionSource) => Promise<void>>().mockResolvedValue()
|
||||
const fileActions = { save, copyImage, canSaveAs: true }
|
||||
const sessions = createSnapshotStore({ byId: { [sessionId]: { cwd: '/workspace' } } })
|
||||
const sessions = createSnapshotStore({ byId: { [sessionId]: { cwd: '/workspace' } }, projectionsBySession: {} })
|
||||
const sidebar = { openResourceIn: vi.fn(), openTabIn: vi.fn() }
|
||||
const browserTab = vi.fn(() => ({}))
|
||||
const directoryFetch = vi.fn(async () => new Response(JSON.stringify({ apps: ['vscode', 'finder'] })))
|
||||
@@ -242,10 +242,10 @@ it('offers only folder reveal and path copy, retaining the captured directory',
|
||||
const menu = await h.resolve(target)
|
||||
expect(menu.source.getSnapshot().map(item => item.id)).toEqual(['open-in-app.directory/reveal', 'open-in-app.directory/copyPath'])
|
||||
expect(h.remote.workspaceFiles.stat).not.toHaveBeenCalled()
|
||||
h.sessions.set({ byId: { [sessionId]: { cwd: '/changed' } } })
|
||||
h.sessions.set({ byId: { [sessionId]: { cwd: '/changed' } }, projectionsBySession: {} })
|
||||
menu.select('open-in-app.directory/reveal')
|
||||
await vi.waitFor(() => { expect(h.remote.session.openWorkspacePath).toHaveBeenCalledWith({ path: '/workspace/src', action: 'reveal' }) })
|
||||
h.sessions.set({ byId: { [sessionId]: { cwd: '/workspace' } } })
|
||||
h.sessions.set({ byId: { [sessionId]: { cwd: '/workspace' } }, projectionsBySession: {} })
|
||||
await h.choose(target, 'open-in-app.directory/copyPath')
|
||||
expect(h.writeText).toHaveBeenLastCalledWith('/workspace/src')
|
||||
h.paths.desktop.set(false)
|
||||
|
||||
@@ -34,7 +34,7 @@ it('offers image actions on file targets, copies absolute paths, and keeps save
|
||||
} }
|
||||
ctx.provide('remote', remote as never)
|
||||
ctx.provide('contextMenus', { register: registry.register.bind(registry), notify } as never)
|
||||
ctx.provide('sessions', { list: createSnapshotStore({ byId: { [id]: { cwd: '/workspace' } } }) } as never)
|
||||
ctx.provide('sessions', { list: createSnapshotStore({ byId: { [id]: { cwd: '/workspace' } }, projectionsBySession: {} }) } as never)
|
||||
ctx.provide('fileActions', { save, copyImage: copy, canSaveAs: true } as never)
|
||||
const paths = new OpenInAppPathController(remote)
|
||||
const directories = new OpenInAppController()
|
||||
|
||||
@@ -21,6 +21,7 @@ import type {} from '@deepseek-ai/dsh-client-ui-sidebar-right/client'
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
|
||||
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
||||
import type { ISessions } from '@deepseek-ai/dsh-api-session-controller/client'
|
||||
import { sessionDirectories } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
import { relativeTime } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import type { UserTextNodeProps } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
||||
import { FileReference, FolderReference, type FileReferenceInjected } from './FileReference.tsx'
|
||||
@@ -62,10 +63,10 @@ export function apply(ctx: ClientContext): void {
|
||||
yield ctx.slots.register({
|
||||
name: 'conversation.user.text.node', key: 'file', priority: 100, locale: NS,
|
||||
inject: (sessionId: UserTextNodeProps<'file'>['sessionId']): FileReferenceInjected => ({
|
||||
resolveFilePath: path => resolveWorkspacePath(sessions.list.getSnapshot().byId[sessionId]?.cwd, path),
|
||||
// A user reference is relative to the workspace root the user sees, not to the model's current directory.
|
||||
resolveFilePath: path => resolveWorkspacePath(sessionDirectories(sessions, sessionId).root, path),
|
||||
openFile: (path) => {
|
||||
const cwd = sessions.list.getSnapshot().byId[sessionId]?.cwd
|
||||
ctx.sidebarRight.openResource(fileAddressFor(sessionId, cwd, path))
|
||||
ctx.sidebarRight.openResource(fileAddressFor(sessionId, sessionDirectories(sessions, sessionId).root, path))
|
||||
},
|
||||
}),
|
||||
}, FileReference)
|
||||
@@ -165,8 +166,7 @@ export function apply(ctx: ClientContext): void {
|
||||
openReference(session, { ref, appearance }) {
|
||||
if (appearance !== 'file') return false
|
||||
const path = ref.startsWith('@"') ? ref.slice(2, -1) : ref.slice(1)
|
||||
const cwd = sessions.list.getSnapshot().byId[session.sessionId]?.cwd
|
||||
ctx.sidebarRight.openResource(fileAddressFor(session.sessionId, cwd, path))
|
||||
ctx.sidebarRight.openResource(fileAddressFor(session.sessionId, sessionDirectories(sessions, session.sessionId).root, path))
|
||||
return true
|
||||
},
|
||||
codec: {
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
en: 803d10142360264b
|
||||
zh: 042568a8ba293037
|
||||
/deepseek-ai-dsh-client-ui-sidebar-files/the-tree:
|
||||
en: c6d5d2d068bdec7b
|
||||
zh: dd41bcfa3e9080ad
|
||||
en: 50426845c6d77ccd
|
||||
zh: 4eded68d11addbab
|
||||
/deepseek-ai-dsh-client-ui-sidebar-files/reusable-tree-factory:
|
||||
en: 0a3e9645426b4203
|
||||
zh: 0478669e4157f15c
|
||||
@@ -33,8 +33,8 @@
|
||||
en: 5a6febb45089991a
|
||||
zh: b17ed755fd098b83
|
||||
/deepseek-ai-dsh-client-ui-sidebar-files/known-limitations-and-deferred-work:
|
||||
en: dd317b62980a9269
|
||||
zh: 0be3b9924f6b6c67
|
||||
en: ca59c47fa68bc440
|
||||
zh: ebe18d06be6fd739
|
||||
/deepseek-ai-dsh-client-ui-sidebar-files/known-limitations-and-deferred-work/dev-note:
|
||||
en: 1ec99e9fb6b4c948
|
||||
zh: c4f7883934307c3c
|
||||
@@ -55,7 +55,7 @@ The tree marks the row of the current file with `aria-current`. While the tree i
|
||||
<a id="the-tree"></a>
|
||||
## The tree
|
||||
|
||||
The root is the session's working directory, read from `useSessions().byId[sessionId].cwd`. Filesystem roots such as `/` and Windows drive roots are valid tree roots. Every level is keyed by absolute path; a child's path is its parent's joined with the entry name by `/`. A level is listed when it is first expanded, through `remote.workspaceFiles.list(sessionId, absolutePath)` on the `@deepseek-ai/dsh-api-workspace-files` namespace. The rows are drawn by the [tree Factory](#tree-factory), which orders them; `workspace-tree.ts` passes every listed entry with its listing's name and type as `meta.kind`, the root key without trailing separators, and localized failure lines. The Factory reads its own copy from the files locale. Dotfiles are shown like any other entry.
|
||||
The root is the session's workspace root, selected with `selectSessionRoot` from the list snapshot: the projected `workspaceRoot`, else the header directory. Filesystem roots such as `/` and Windows drive roots are valid tree roots. Every level is keyed by absolute path; a child's path is its parent's joined with the entry name by `/`. A level is listed when it is first expanded, through `remote.workspaceFiles.list(sessionId, absolutePath)` on the `@deepseek-ai/dsh-api-workspace-files` namespace. The rows are drawn by the [tree Factory](#tree-factory), which orders them; `workspace-tree.ts` passes every listed entry with its listing's name and type as `meta.kind`, the root key without trailing separators, and localized failure lines. The Factory reads its own copy from the files locale. Dotfiles are shown like any other entry.
|
||||
|
||||
| Entry type | Row |
|
||||
|---|---|
|
||||
@@ -95,7 +95,7 @@ None; directory listings travel over the Remote and assemble no model request.
|
||||
|
||||
<a id="known-limitations-and-deferred-work"></a>
|
||||
- **Listing only.** No search, artifact filter, drag-and-drop, or rename.
|
||||
- **One root.** The tree is rooted at the session's working directory; there is no way to browse above it, and the Host refuses paths outside the workspace root anyway.
|
||||
- **One root.** The tree is rooted at the session's workspace root; there is no way to browse above it, and the Host refuses paths outside the workspace root anyway.
|
||||
|
||||
<a id="dev-note"></a>
|
||||
### Dev Note
|
||||
|
||||
@@ -55,7 +55,7 @@ kind: "package-reference"
|
||||
<a id="the-tree"></a>
|
||||
## 树
|
||||
|
||||
根是会话的工作目录,读自 `useSessions().byId[sessionId].cwd`。`/` 和 Windows 盘根等文件系统根路径均可作为树的根。每一层以绝对路径为键;子路径是父路径以 `/` 拼上条目名。一层在首次展开时经 `@deepseek-ai/dsh-api-workspace-files` 命名空间的 `remote.workspaceFiles.list(sessionId, absolutePath)` 列出。各行由[目录树 Factory](#tree-factory) 绘制并排序;`workspace-tree.ts` 传入每个已列出的条目,名字取目录列表中的拼写,类型作为 `meta.kind`,根的键去掉末尾分隔符,并传入已本地化的失败行。Factory 自行从 files locale 读取文案。dotfiles 与其他条目一样显示。
|
||||
根是会话的工作区根,用 `selectSessionRoot` 从列表快照选出:投影的 `workspaceRoot`,否则为 header 目录。`/` 和 Windows 盘根等文件系统根路径均可作为树的根。每一层以绝对路径为键;子路径是父路径以 `/` 拼上条目名。一层在首次展开时经 `@deepseek-ai/dsh-api-workspace-files` 命名空间的 `remote.workspaceFiles.list(sessionId, absolutePath)` 列出。各行由[目录树 Factory](#tree-factory) 绘制并排序;`workspace-tree.ts` 传入每个已列出的条目,名字取目录列表中的拼写,类型作为 `meta.kind`,根的键去掉末尾分隔符,并传入已本地化的失败行。Factory 自行从 files locale 读取文案。dotfiles 与其他条目一样显示。
|
||||
|
||||
| 条目类型 | 行 |
|
||||
|---|---|
|
||||
@@ -95,7 +95,7 @@ kind: "package-reference"
|
||||
|
||||
<a id="known-limitations-and-deferred-work"></a>
|
||||
- **只有列目录。**没有搜索、产物过滤、拖拽或重命名。
|
||||
- **只有一个根。**树以会话工作目录为根;没有办法浏览到它之上,而 Host 本来也拒绝工作区根之外的路径。
|
||||
- **只有一个根。**树以会话工作区根为根;没有办法浏览到它之上,而 Host 本来也拒绝工作区根之外的路径。
|
||||
|
||||
<a id="dev-note"></a>
|
||||
### 开发备注
|
||||
|
||||
@@ -50,10 +50,13 @@
|
||||
"devDependencies": {
|
||||
"@deepseek-ai/cordis": "workspace:~",
|
||||
"@deepseek-ai/dsh-api-remotes": "workspace:*",
|
||||
"@deepseek-ai/dsh-api-session-controller": "workspace:*",
|
||||
"@deepseek-ai/dsh-api-workspace-files": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-locale": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-shortcuts": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-store": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-test-runtime": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-context-menu": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-dockkit": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-primitives": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-renderer": "workspace:*",
|
||||
@@ -64,11 +67,9 @@
|
||||
"@deepseek-ai/dsh-typert-protocol": "workspace:*",
|
||||
"@deepseek-ai/dsh-util-workspace-path": "workspace:*",
|
||||
"@testing-library/react": "^16.3.3",
|
||||
"react": "^18.2.0",
|
||||
"clsx": "^2.0.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"@deepseek-ai/dsh-client-shortcuts": "workspace:*",
|
||||
"@deepseek-ai/dsh-client-ui-context-menu": "workspace:*"
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
},
|
||||
"files": [
|
||||
"locale/*.json",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* follows `PUSH_FROM`, `FILL_BELOW`, and `FULLSCREEN_QUERY`; the package
|
||||
* README describes its behavior.
|
||||
*/
|
||||
import { selectSessionRoot } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import type { CSSProperties, ReactNode } from 'react'
|
||||
import clsx from 'clsx'
|
||||
@@ -75,14 +76,14 @@ export function FileNavigator({
|
||||
const { tab, panel } = useTabInfo()
|
||||
const { getTriggerProps } = useContextMenu()
|
||||
const paneId = panel.id
|
||||
const cwd = useSessions(sessions => sessions.byId[sessionId]?.cwd)
|
||||
const workspaceRoot = useSessions(sessions => selectSessionRoot(sessions, sessionId))
|
||||
const state = useStore(store => store.byPane[paneId])
|
||||
const rowWidth = useRowWidth(paneId)
|
||||
const canOpen = useCanOpen(check => check)
|
||||
const open = page || state?.open === true
|
||||
// Measured by the face; the viewport rule is CSS's, read again when a file opens.
|
||||
const mode = navigatorMode(rowWidth)
|
||||
const tree = state?.tree?.root === cwd ? state?.tree : undefined
|
||||
const tree = state?.tree?.root === workspaceRoot ? state?.tree : undefined
|
||||
const [dragging, setDragging] = useState(false)
|
||||
const drag = useRef<{ readonly x: number; readonly width: number } | undefined>(undefined)
|
||||
// Stable, so each element registers once per drawing rather than on every render.
|
||||
@@ -98,8 +99,8 @@ export function FileNavigator({
|
||||
|
||||
useEffect(() => attach(paneId, tab.id, tab.signal), [attach, paneId, tab.id, tab.signal])
|
||||
// Only a navigator that can draw a tree keeps the workspace command on its tab.
|
||||
useEffect(() => page || cwd === undefined ? undefined : placeBeside(tab.id), [page, cwd, placeBeside, tab.id])
|
||||
useEffect(() => cwd === undefined || !open ? undefined : hold(paneId, cwd), [cwd, open, paneId, hold])
|
||||
useEffect(() => page || workspaceRoot === undefined ? undefined : placeBeside(tab.id), [page, workspaceRoot, placeBeside, tab.id])
|
||||
useEffect(() => workspaceRoot === undefined || !open ? undefined : hold(paneId, workspaceRoot), [workspaceRoot, open, paneId, hold])
|
||||
|
||||
const relativePath = tree === undefined ? undefined : relativeFileOf(tab.contentId, sessionId, tree.root)
|
||||
const location = useMemo(
|
||||
@@ -132,7 +133,7 @@ export function FileNavigator({
|
||||
}
|
||||
}, [tree, paneId, sessionId, toggle, canOpen, onOpen, getTriggerProps])
|
||||
|
||||
if (cwd === undefined || !open) return null
|
||||
if (workspaceRoot === undefined || !open) return null
|
||||
const geometry = navigatorGeometry(rowWidth, state?.width ?? DEFAULT_NAVIGATOR_WIDTH)
|
||||
// The page's tree always fills the page; a preview's follows its row.
|
||||
const shown = page ? undefined : mode
|
||||
@@ -146,7 +147,7 @@ export function FileNavigator({
|
||||
data-files-navigator={paneId}
|
||||
data-files-navigator-mode={shown}
|
||||
data-files-state="tree"
|
||||
data-files-root={cwd}
|
||||
data-files-root={workspaceRoot}
|
||||
>
|
||||
{shown !== undefined && shown !== 'fill' && (
|
||||
<div
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* it is and opens the file where the right Sidebar places it by default
|
||||
* (`FileNavigator`).
|
||||
*/
|
||||
import { selectSessionRoot } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
import { useCallback, useEffect } from 'react'
|
||||
import type { ReactNode } from 'react'
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-context-menu/client'
|
||||
@@ -49,14 +50,14 @@ export function FilesBody(props: FilesBodyProps): ReactNode {
|
||||
() => tab.actions.bindCommands({ refresh: () => { refresh(panel.id) } }),
|
||||
[tab.actions, panel.id, refresh],
|
||||
)
|
||||
const cwd = useSessions(sessions => sessions.byId[sessionId]?.cwd)
|
||||
const workspaceRoot = useSessions(sessions => selectSessionRoot(sessions, sessionId))
|
||||
// The setting belongs to a listed tree, so there is nothing to set before one.
|
||||
const autoRefresh = useStore((store) => {
|
||||
const tree = store.byPane[panel.id]?.tree
|
||||
return tree?.root === cwd ? tree?.autoRefresh : undefined
|
||||
return tree?.root === workspaceRoot ? tree?.autoRefresh : undefined
|
||||
})
|
||||
|
||||
if (cwd === undefined) {
|
||||
if (workspaceRoot === undefined) {
|
||||
return (
|
||||
<div className={css.status} data-files-state="no-workspace">
|
||||
<p className={css.statusLine}>{t('noWorkspace')}</p>
|
||||
@@ -68,8 +69,8 @@ export function FilesBody(props: FilesBodyProps): ReactNode {
|
||||
return (
|
||||
<div className={css.page} data-files-page>
|
||||
<div className={css.header}>
|
||||
<PathLabel path={cwd} className={css.path} data-files-path
|
||||
{...getTriggerProps({ kind: 'directory', value: { sessionId, path: cwd } })} />
|
||||
<PathLabel path={workspaceRoot} className={css.path} data-files-path
|
||||
{...getTriggerProps({ kind: 'directory', value: { sessionId, path: workspaceRoot } })} />
|
||||
<span hidden>
|
||||
<button type="button" className={css.tool} aria-label={t('autoRefresh')}
|
||||
aria-pressed={automatic} disabled={autoRefresh === undefined} data-files-auto-refresh
|
||||
@@ -90,7 +91,7 @@ export function FilesBody(props: FilesBodyProps): ReactNode {
|
||||
<IconRefreshOutlineRegular />
|
||||
</button>
|
||||
</Tooltip>
|
||||
{renderSlot('sidebar.right.tab.files.actions', { absolutePath: cwd })}
|
||||
{renderSlot('sidebar.right.tab.files.actions', { absolutePath: workspaceRoot })}
|
||||
</div>
|
||||
<div className={css.content} data-files-content>{navigator}</div>
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* the pane reads, and registers itself with the face, which hands it the
|
||||
* keyboard when Escape closes the navigator.
|
||||
*/
|
||||
import { selectSessionRoot } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
import { useCallback } from 'react'
|
||||
import type { ReactNode } from 'react'
|
||||
import type { FactoryComponentPropsOf } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
@@ -42,11 +43,11 @@ export function NavigatorToggle(
|
||||
{ useTabInfo, sessionId, useSessions, useStore, actions, toggleDrawn, t }: FactoryComponentPropsOf<'sidebar.files.navigator.toggle'>,
|
||||
): ReactNode {
|
||||
const { panel } = useTabInfo()
|
||||
const cwd = useSessions(sessions => sessions.byId[sessionId]?.cwd)
|
||||
const workspaceRoot = useSessions(sessions => selectSessionRoot(sessions, sessionId))
|
||||
const open = useStore(store => store.byPane[panel.id]?.open) === true
|
||||
// Stable, so the control registers once per drawing rather than on every render.
|
||||
const toggleRef = useCallback((button: HTMLElement | null) => { toggleDrawn(panel.id, button) }, [toggleDrawn, panel.id])
|
||||
if (cwd === undefined) return null
|
||||
if (workspaceRoot === undefined) return null
|
||||
const label = t(open ? 'navigator.hide' : 'navigator.show')
|
||||
return (
|
||||
<Tooltip label={label} side="bottom" delayMs={500}>
|
||||
|
||||
@@ -131,7 +131,7 @@ function harness(placement: Placement, controller: AbortController) {
|
||||
close: vi.fn<SidebarRightTabActions['close']>(),
|
||||
}
|
||||
const sessionsAt = (cwd: string | null): SessionListState =>
|
||||
({ byId: cwd === null ? {} : { [SESSION]: { cwd } } } as unknown as SessionListState)
|
||||
({ byId: cwd === null ? {} : { [SESSION]: { cwd } }, projectionsBySession: {} } as unknown as SessionListState)
|
||||
const useTabInfo = (): SidebarRightTabInfo => ({
|
||||
sidebar: { expanded: true, fullscreen: false },
|
||||
panel: { id: PANE, isFloating: placement.isFloating ?? false },
|
||||
|
||||
@@ -49,6 +49,9 @@
|
||||
},
|
||||
{
|
||||
"path": "../ui-context-menu"
|
||||
},
|
||||
{
|
||||
"path": "../../api/session-controller/tsconfig.client.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/** Tool-owned path resolution supplied by the existing toolview registration. */
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
import type {} from '@deepseek-ai/dsh-api-session-controller/client'
|
||||
import { sessionDirectories } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
import { resolveWorkspacePath } from '@deepseek-ai/dsh-util-workspace-path'
|
||||
|
||||
/** File paths are resolved when a gesture begins, not when the Slot is mounted. */
|
||||
@@ -17,10 +17,6 @@ export interface ToolFileInjected {
|
||||
*/
|
||||
export function toolFileInject(ctx: Context): (sessionId: SessionId) => ToolFileInjected {
|
||||
return sessionId => ({
|
||||
resolveFilePath: (path) => {
|
||||
const cwd = ctx.sessions.list.getSnapshot().byId[sessionId]?.cwd
|
||||
const current = ctx.sessions.binding(sessionId)?.session.projections.faceOf('workingDirectory').getSnapshot() as string | null | undefined
|
||||
return resolveWorkspacePath(current ?? cwd, path)
|
||||
},
|
||||
resolveFilePath: path => resolveWorkspacePath(sessionDirectories(ctx.sessions, sessionId).cwd, path),
|
||||
})
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
import {
|
||||
type SessionListState, type SessionSearchResultItem, type SessionSummary,
|
||||
} from '@deepseek-ai/dsh-api-session-controller/client'
|
||||
import { selectSessionRoot } from '@deepseek-ai/dsh-api-session-controller/client/directories'
|
||||
import type { WorkspaceId, WorkspaceView } from '@deepseek-ai/dsh-api-workspace-controller/client'
|
||||
import type {
|
||||
SessionStatusSnapshot,
|
||||
@@ -59,7 +60,7 @@ export interface SessionNode {
|
||||
/** In the registry-global archive set: shown grayed in place and not openable. */
|
||||
archived: boolean
|
||||
updatedAt: number
|
||||
/** Session working directory; absent when the Host reports none or an empty path. */
|
||||
/** Workspace root the Session works in; absent when the Host reports none or an empty path. */
|
||||
cwd?: string
|
||||
}
|
||||
|
||||
@@ -394,6 +395,8 @@ function sessionNode(
|
||||
): SessionNode {
|
||||
const status = statuses.get(s.id)
|
||||
const pendingInteraction = visiblePendingKind(status?.pendingInteraction?.kind)
|
||||
// Rows show the checkout the Session works in; grouping stays with the header's original project.
|
||||
const root = selectSessionRoot(list, s.id)
|
||||
return {
|
||||
id: s.id,
|
||||
title: sessionTitle(s),
|
||||
@@ -404,7 +407,7 @@ function sessionNode(
|
||||
pinned: !archived.has(s.id) && pinned.has(s.id),
|
||||
archived: archived.has(s.id),
|
||||
updatedAt: s.updatedAt,
|
||||
...(s.cwd === undefined || s.cwd === '' ? {} : { cwd: s.cwd }),
|
||||
...(root === undefined || root === '' ? {} : { cwd: root }),
|
||||
...(pendingInteraction === undefined ? {} : { pendingInteraction }),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
en: d152484eb41ac6b4
|
||||
zh: 09388d293f9be9cb
|
||||
/deepseek-ai-dsh-agent-instructions/use-this-package:
|
||||
en: a6f5c0d19634d0e9
|
||||
zh: 74c88e1f76381a30
|
||||
en: c6e8901a72b403cc
|
||||
zh: 2e88224dbb3c96b5
|
||||
/deepseek-ai-dsh-agent-instructions/use-this-package/what-the-agent-gets:
|
||||
en: 1435be3e04948c50
|
||||
zh: a3946e05a9a221dd
|
||||
|
||||
@@ -25,7 +25,7 @@ English | [中文](README.zh.md)
|
||||
<a id="use-this-package"></a>
|
||||
## Use this package
|
||||
|
||||
Changing the Session's working directory reloads the applicable project instruction chain before the next request.
|
||||
Entering another checkout reloads the applicable project instruction chain before the next request; a directory change inside the workspace root keeps the baseline.
|
||||
|
||||
Mount this plugin when agents should work from the workspace's own instruction files. `dsh-base` already includes it with a 65,536-byte budget for each instruction chain, so base-backed profiles only need to replace the row when they want another `maxBytes`; providerless trees load nothing until a filesystem provider is present.
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ kind: "package-reference"
|
||||
<a id="use-this-package"></a>
|
||||
## 使用本包
|
||||
|
||||
切换 Session 工作目录后,下一次请求前会重新加载适用的项目指令链。
|
||||
进入另一个检出目录后,下一次请求前会重新加载适用的项目指令链;工作区根内部的目录切换保持基线不变。
|
||||
|
||||
当 agent 需要依据工作区自身的指令文件工作时,挂载此插件。`dsh-base` 已包含它,并为每条指令链给予 65,536 字节预算,因此基于 base 的 profile 仅在需要其他 `maxBytes` 时替换该配置行;没有文件系统提供方的树加载不到任何内容,直到提供方出现。
|
||||
|
||||
|
||||
@@ -123,7 +123,9 @@ export function apply(ctx: Context, config: Config): void {
|
||||
const changes: AgentInstructionChange[] = []
|
||||
let desiredBaseline = false
|
||||
const authorityMessages = [...claimed]
|
||||
const cwd = await ctx.workingDirectory.ensure(agent, signal)
|
||||
// The baseline describes the checkout the Session works in; a cd inside it keeps the same baseline.
|
||||
await ctx.workingDirectory.ensure(agent, signal)
|
||||
const cwd = ctx.workingDirectory.rootOf(agent.session)
|
||||
const projectRoot = await findProjectRoot(cwd, resolved.projectRootMarkers, fileSystem, signal)
|
||||
const identity = workspaceBaselineIdentity(resolved, cwd, projectRoot)
|
||||
if (touchedPaths.length === 0 && pending.length > 0
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
en: d152484eb41ac6b4
|
||||
zh: 09388d293f9be9cb
|
||||
/deepseek-ai-dsh-file-reference-local/use-this-package:
|
||||
en: 1fd922f09d15163f
|
||||
zh: e1d68a27a676256d
|
||||
en: 39ca139cd37ecf34
|
||||
zh: d7a240da196bdff8
|
||||
/deepseek-ai-dsh-file-reference-local/use-this-package/enabling-the-provider:
|
||||
en: 62b9ce096fa4a94e
|
||||
zh: 53081797c34d64eb
|
||||
|
||||
@@ -25,9 +25,9 @@ Agents and host UIs can complete `@file` mentions with ranked paths from each ag
|
||||
<a id="use-this-package"></a>
|
||||
## Use this package
|
||||
|
||||
Changing the Session's working directory discards the previous directory's search index; the next completion searches the new directory.
|
||||
Entering another checkout discards the previous workspace root's search index; the next completion searches the new root. A directory change inside the root keeps the index.
|
||||
|
||||
Mount this provider when `@file` completion should discover the Harness host's own filesystem — the namespace the shipped `read` tool operates on. Each agent's workspace is indexed from its Session's current working directory.
|
||||
Mount this provider when `@file` completion should discover the Harness host's own filesystem — the namespace the shipped `read` tool operates on. Each agent's workspace is indexed from its Session's workspace root.
|
||||
|
||||
### Enabling the provider
|
||||
|
||||
|
||||
@@ -25,9 +25,9 @@ agent(智能体)及宿主 UI 可以用各 agent 本地工作区中经过排
|
||||
<a id="use-this-package"></a>
|
||||
## 使用本包
|
||||
|
||||
切换 Session 工作目录后,旧目录的搜索索引会被丢弃;下一次补全会搜索新目录。
|
||||
进入另一个检出目录后,旧工作区根的搜索索引会被丢弃;下一次补全会搜索新的根。根内部的目录切换保留索引。
|
||||
|
||||
当 `@file` 补全应发现 Harness 宿主自身的文件系统——即随附 `read` 工具所操作的命名空间——时,挂载此提供方。每个 agent 的工作区从其 Session 当前工作目录开始建立索引。
|
||||
当 `@file` 补全应发现 Harness 宿主自身的文件系统——即随附 `read` 工具所操作的命名空间——时,挂载此提供方。每个 agent 的工作区从其 Session 工作区根开始建立索引。
|
||||
|
||||
### 启用提供方
|
||||
|
||||
|
||||
@@ -118,7 +118,9 @@ export class LocalFileReferenceService extends FileReferenceService {
|
||||
query: string,
|
||||
signal: AbortSignal,
|
||||
): Promise<FileReferenceCandidate[]> {
|
||||
const cwd = await this.ctx.workingDirectory.ensure(agent, signal)
|
||||
// Candidates are listed from the workspace root the user sees, after the current directory was validated.
|
||||
await this.ctx.workingDirectory.ensure(agent, signal)
|
||||
const cwd = this.ctx.workingDirectory.rootOf(agent.session)
|
||||
let cached = this.searches.get(agent)
|
||||
if (cached?.cwd !== cwd) {
|
||||
cached?.search.dispose()
|
||||
|
||||
@@ -69,7 +69,7 @@ describe('LocalFileReferenceService', () => {
|
||||
await ctx.plugin(SessionStore)
|
||||
await ctx.plugin(SessionProjectionRegistry)
|
||||
await ctx.plugin(AgentRegistry)
|
||||
ctx.provide('workingDirectory', { ensure: vi.fn<WorkingDirectory['ensure']>() })
|
||||
ctx.provide('workingDirectory', { ensure: vi.fn<WorkingDirectory['ensure']>(), rootOf: vi.fn<WorkingDirectory['rootOf']>() })
|
||||
await ctx.plugin(LocalFileReferenceService)
|
||||
try {
|
||||
expect(ctx.fileReferences).toBeInstanceOf(LocalFileReferenceService)
|
||||
@@ -111,7 +111,7 @@ describe('LocalFileReferenceService', () => {
|
||||
expect(renderPrompt(await ctx.systemPrompt.assemble())).not.toContain(FILE_REFERENCE_PROMPT)
|
||||
})
|
||||
|
||||
it('rebuilds completion from the current directory after a Session directory change', async () => {
|
||||
it('rebuilds completion from the workspace root after the Session enters another checkout', async () => {
|
||||
const ctx = await harness()
|
||||
try {
|
||||
const { agent } = await stubAgent(ctx)
|
||||
@@ -122,7 +122,7 @@ describe('LocalFileReferenceService', () => {
|
||||
const signal = new AbortController().signal
|
||||
expect(await ctx.fileReferences.list(agent, '', signal)).toEqual([{ path: 'README.md', kind: 'file' }])
|
||||
const original = agent.session.header.cwd
|
||||
await ctx.workingDirectory.set(agent, nextRoot, signal)
|
||||
await ctx.workingDirectory.relocate(agent, nextRoot, { signal })
|
||||
expect(await ctx.fileReferences.list(agent, '', signal)).toEqual([{ path: 'NEXT.md', kind: 'file' }])
|
||||
expect(agent.session.header.cwd).toBe(original)
|
||||
} finally {
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
en: d152484eb41ac6b4
|
||||
zh: 09388d293f9be9cb
|
||||
/deepseek-ai-dsh-workspace-changes/use-this-package:
|
||||
en: 0ab7680d831598aa
|
||||
zh: 2594f3c8c99cef24
|
||||
en: 0d13b6aa2a5f604e
|
||||
zh: 18349da659029d2c
|
||||
/deepseek-ai-dsh-workspace-changes/understand-the-implementation:
|
||||
en: 9bfc66bea548bda2
|
||||
zh: 7023c42cdb44569b
|
||||
@@ -30,8 +30,8 @@
|
||||
en: e7ba08477bf22c4e
|
||||
zh: f365439c69beb722
|
||||
/deepseek-ai-dsh-workspace-changes/known-limitations-and-deferred-work:
|
||||
en: c7091685e5065a40
|
||||
zh: 1e9b85962ea04187
|
||||
en: 04ab0c538589bfc2
|
||||
zh: 343e5af6ea36b5f4
|
||||
/deepseek-ai-dsh-workspace-changes/known-limitations-and-deferred-work/dev-note:
|
||||
en: e67f633dc6fe7773
|
||||
zh: 3bb0c20c93f16f98
|
||||
@@ -45,7 +45,7 @@ This plugin requires the `subprocess` and `fs` services. Every Session with a wo
|
||||
|
||||
After a `write`, `edit`, or mutating `str_replace_editor` call resolves its target and obtains its mutation guard, the recorder copies that exact file before the mutation into the Session's temporary directory, once per path per turn, and copies it again at turn end; the copies are named by the SHA-1 of their bytes, so identical content is stored once. This needs no git. Repository discovery and display paths retain the original project; file captures follow the operation's resolved target even after the Session changes directories. Paths the snapshots cover keep their git counts; the copies serve the other paths — files matching an ignore pattern, files outside the repository, and every file-tool edit when there is no snapshot — with counts from a line comparison of the two copies, so repeated edits to one file count once and a shell edit after a file-tool edit is included. A path whose content is unchanged at turn end is not listed. A copy larger than `maxFileBytes` is not stored: the file is listed with `oversized` and no counts, and a path whose both sides are that large is listed too, since unread content is never known to be unchanged. A path whose only difference is a missing final newline compares as unchanged, while git still counts that line. Files under `/tmp` or the platform temporary directory are excluded unless they lie inside the repository. Changes made only through shell commands outside the snapshot coverage are not recorded.
|
||||
|
||||
Each file carries a durable `path` — relative to the working directory inside it, absolute elsewhere — and a `display` path used for ordering and labels: the relative path, a `../` path for repository files above the working directory, a `~` path under the home directory, otherwise the absolute path. Files sort by `display` in code-unit order, which lists parent and absolute paths before the working directory's own files. The `workspace/changes` event carries only the turn number; `ctx.workspaceChanges.summary(sessionId, seq)` returns the summary the event with that sequence announced, or undefined once the Session is disposed or when this Host process never recorded it. `ctx.workspaceChanges.diff(sessionId, seq, index, signal)` compares the listed file at that index: hunks with three context lines from the two snapshot trees or the two copies, `binary` for a side git reported as binary or that holds a NUL byte, `oversized` for a side larger than `maxFileBytes`. A line comparison that runs longer than `diffTimeoutMs` degrades to one hunk replacing every line, marked `coarse`. A conversation reopened after a Host restart therefore has no card, and no comparison, for its earlier turns.
|
||||
Each turn reads the Session's current directory and workspace root when it starts, so a Session that entered a worktree is snapshotted in that checkout and lists paths relative to that root. Each file carries a durable `path` — relative to the workspace root inside it, absolute elsewhere — and a `display` path used for ordering and labels: the relative path, a `../` path for repository files above the workspace root, a `~` path under the home directory, otherwise the absolute path. Files sort by `display` in code-unit order, which lists parent and absolute paths before the workspace root's own files. The `workspace/changes` event carries only the turn number; `ctx.workspaceChanges.summary(sessionId, seq)` returns the summary the event with that sequence announced, or undefined once the Session is disposed or when this Host process never recorded it. `ctx.workspaceChanges.diff(sessionId, seq, index, signal)` compares the listed file at that index: hunks with three context lines from the two snapshot trees or the two copies, `binary` for a side git reported as binary or that holds a NUL byte, `oversized` for a side larger than `maxFileBytes`. A line comparison that runs longer than `diffTimeoutMs` degrades to one hunk replacing every line, marked `coarse`. A conversation reopened after a Host restart therefore has no card, and no comparison, for its earlier turns.
|
||||
|
||||
The intent listeners capture every add, update, delete, and move target of `apply_patch` after policy admission and before provider mutation; a move captures both ends. Review compares each path against its first baseline and lists net changes, including the completed effects of a stopped patch.
|
||||
|
||||
@@ -90,10 +90,10 @@ Nothing here enters a model request, so provider cache reuse is unaffected.
|
||||
- git 2.13 or later is required for `rev-parse --absolute-git-dir`; an unsupported repository format or another git failure abandons the turn with a warning rather than being treated as a plain directory.
|
||||
- The first snapshot of a Session writes every untracked, non-ignored file of the work tree into the Session's temporary directory; a repository without a `.gitignore` that carries large build outputs costs that much temporary space until the Session is disposed.
|
||||
- Edits the user makes during a turn are attributed to that turn.
|
||||
- A working directory outside any git repository lists file-tool edits only, so shell edits are missing from its card; a shadow repository under the Harness home is deferred until its exclude rules can replace a missing `.gitignore` reliably.
|
||||
- A current directory outside any git repository lists file-tool edits only, so shell edits are missing from its card; a shadow repository under the Harness home is deferred until its exclude rules can replace a missing `.gitignore` reliably.
|
||||
- Outside snapshot coverage only paths a file tool names are captured: a file only a shell command changes there is absent, and a file both changed before its first file-tool call is compared from that call onward.
|
||||
- Every file-tool edit copies its whole file once per turn, up to `maxFileBytes`, even for paths the snapshots also cover; the copies go with the Session's temporary directory.
|
||||
- A comparison serves the listed file's complete text to the client, including ignored files, repository files above the working directory, and files outside the workspace; the summary route serves only paths and counts. A deployment that must keep such content on the Host composes this plugin out.
|
||||
- A comparison serves the listed file's complete text to the client, including ignored files, repository files above the workspace root, and files outside the workspace; the summary route serves only paths and counts. A deployment that must keep such content on the Host composes this plugin out.
|
||||
- A comparison that degrades to whole-file replacement carries every line of both sides, up to twice `maxFileBytes`.
|
||||
- Windows paths keep native separators in `path`; `display` is always slash-separated.
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ kind: "package-reference"
|
||||
|
||||
在 `write`、`edit`、`apply_patch` 或有修改作用的 `str_replace_editor` 调用解析目标并取得修改防护之后,记录器在实际修改前把该文件复制到 Session 的临时目录,每轮每个路径只复制第一次,轮次结束时再复制一次;副本按其字节的 SHA-1 命名,相同内容只存一份。这一步不需要 git。仓库定位与显示路径保留原始项目;即使 Session 切换目录,文件捕获仍跟随该操作已解析的目标。快照覆盖到的路径保留 git 的行数;其余路径由副本提供,也就是匹配忽略模式的文件、仓库之外的文件,以及没有快照时的每一次文件工具编辑,行数来自两份副本的逐行对比,因此同一文件的重复编辑只计一次,文件工具编辑之后的 shell 改动也包含在内。轮次结束时内容没有变化的路径不会列出。超过 `maxFileBytes` 的副本不会保存:该文件列出时带 `oversized`,没有行数;两侧都这么大的路径同样列出,因为没读过的内容永远不能认定为没有改动。只差一个末尾换行的路径对比为两侧相同,而 git 仍会把那一行计入行数。`/tmp` 与平台临时目录下的文件被排除,除非它们位于仓库内。快照覆盖范围之外只通过 shell 命令做出的改动不会被记录。
|
||||
|
||||
每个文件携带持久的 `path`——位于工作目录内时为相对路径,否则为绝对路径——以及用于排序和标签的 `display` 路径:相对路径,仓库内位于工作目录之上的文件为 `../` 路径,家目录下的文件为 `~` 路径,其余为绝对路径。文件按 `display` 的码元顺序排序,因此上级路径和绝对路径排在工作目录自身文件之前。`workspace/changes` 事件只携带轮号;`ctx.workspaceChanges.summary(sessionId, seq)` 返回该序号的事件宣告的摘要,Session 已释放或本 Host 进程从未记录时返回 undefined。`ctx.workspaceChanges.diff(sessionId, seq, index, signal)` 对比该下标所列的文件:从两棵快照树或两份副本得出带三行上下文的 hunk;git 报告为二进制或某一侧含 NUL 字节时返回 `binary`;某一侧超过 `maxFileBytes` 时返回 `oversized`。逐行对比运行超过 `diffTimeoutMs` 时退化为一个替换全部行的 hunk,并标记 `coarse`。因此 Host 重启后重新打开的对话,先前轮次既没有卡片也没有对比。
|
||||
每个 turn 开始时读取 Session 的当前目录和工作区根,因此进入 worktree 的 Session 在该检出目录中拍快照,并以该根为基准列出相对路径。每个文件携带持久的 `path`——位于工作区根内时为相对路径,否则为绝对路径——以及用于排序和标签的 `display` 路径:相对路径,仓库内位于工作区根之上的文件为 `../` 路径,家目录下的文件为 `~` 路径,其余为绝对路径。文件按 `display` 的码元顺序排序,因此上级路径和绝对路径排在工作区根自身文件之前。`workspace/changes` 事件只携带轮号;`ctx.workspaceChanges.summary(sessionId, seq)` 返回该序号的事件宣告的摘要,Session 已释放或本 Host 进程从未记录时返回 undefined。`ctx.workspaceChanges.diff(sessionId, seq, index, signal)` 对比该下标所列的文件:从两棵快照树或两份副本得出带三行上下文的 hunk;git 报告为二进制或某一侧含 NUL 字节时返回 `binary`;某一侧超过 `maxFileBytes` 时返回 `oversized`。逐行对比运行超过 `diffTimeoutMs` 时退化为一个替换全部行的 hunk,并标记 `coarse`。因此 Host 重启后重新打开的对话,先前轮次既没有卡片也没有对比。
|
||||
|
||||
intent 监听器在策略准入后、提供方修改前捕获 `apply_patch` 的每个新增、更新、删除和移动目标;移动捕获两端。Review 将每个路径与首次基线比较并列出净变化,包括中止补丁已经完成的效果。
|
||||
|
||||
@@ -90,10 +90,10 @@ git 通过 `subprocess` 能力运行,使用净化后的环境、`GIT_CONFIG_CO
|
||||
- 需要 git 2.13 或更高版本以支持 `rev-parse --absolute-git-dir`;不支持的仓库格式或其他 git 失败会带着警告放弃本轮,而不是被当成普通目录。
|
||||
- Session 的首次快照会把工作树里所有未跟踪且未被忽略的文件写进 Session 的临时目录;没有 `.gitignore` 却带着大体积构建产物的仓库,在 Session 释放前会占用同等的临时空间。
|
||||
- 用户在轮次进行中自己做的编辑会被算到该轮。
|
||||
- 不在任何 git 仓库内的工作目录只列文件工具的编辑,卡片里因此没有 shell 改动;Harness home 下的影子仓库暂缓,直到其排除规则能可靠地代替缺失的 `.gitignore`。
|
||||
- 不在任何 git 仓库内的当前目录只列文件工具的编辑,卡片里因此没有 shell 改动;Harness home 下的影子仓库暂缓,直到其排除规则能可靠地代替缺失的 `.gitignore`。
|
||||
- 快照覆盖范围之外只捕获文件工具点名的路径:那里只被 shell 命令改动的文件不会出现,在首次文件工具调用之前被两者都改过的文件从该调用起开始对比。
|
||||
- 每次文件工具编辑都会把整个文件复制一次,每轮每个路径一次,上限 `maxFileBytes`,即使快照也覆盖该路径;副本随 Session 的临时目录一起删除。
|
||||
- 对比会把所列文件的完整文本送到客户端,包括被忽略的文件、工作目录之上的仓库文件和工作区外的文件;摘要路由只送路径和行数。必须把这类内容留在 Host 上的部署应把本插件组合出去。
|
||||
- 对比会把所列文件的完整文本送到客户端,包括被忽略的文件、工作区根之上的仓库文件和工作区外的文件;摘要路由只送路径和行数。必须把这类内容留在 Host 上的部署应把本插件组合出去。
|
||||
- 退化为整文件替换的对比携带两侧的全部行,最多两倍 `maxFileBytes`。
|
||||
- Windows 路径在 `path` 中保留原生分隔符;`display` 始终用斜杠分隔。
|
||||
|
||||
|
||||
@@ -40,31 +40,32 @@
|
||||
"peerDependencies": {
|
||||
"@deepseek-ai/cordis": "workspace:~",
|
||||
"@deepseek-ai/dsh-agent": "workspace:*",
|
||||
"@deepseek-ai/dsh-fs": "workspace:*",
|
||||
"@deepseek-ai/dsh-session": "workspace:*",
|
||||
"@deepseek-ai/dsh-subprocess": "workspace:*",
|
||||
"@deepseek-ai/dsh-tools": "workspace:*",
|
||||
"@deepseek-ai/dsh-fs": "workspace:*"
|
||||
"@deepseek-ai/dsh-working-directory": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@deepseek-ai/cordis": "workspace:~",
|
||||
"@deepseek-ai/cordis-plugin-include": "workspace:~",
|
||||
"@deepseek-ai/cordis-plugin-loader": "workspace:~",
|
||||
"@deepseek-ai/dsh-agent": "workspace:*",
|
||||
"@deepseek-ai/dsh-agent-loop": "workspace:*",
|
||||
"@deepseek-ai/dsh-agent-loop-testkit": "workspace:*",
|
||||
"@deepseek-ai/dsh-fs": "workspace:*",
|
||||
"@deepseek-ai/dsh-fs-local": "workspace:*",
|
||||
"@deepseek-ai/dsh-fs-observation-policy": "workspace:*",
|
||||
"@deepseek-ai/dsh-llm": "workspace:*",
|
||||
"@deepseek-ai/dsh-session": "workspace:*",
|
||||
"@deepseek-ai/dsh-subprocess": "workspace:*",
|
||||
"@deepseek-ai/dsh-subprocess-local": "workspace:*",
|
||||
"@deepseek-ai/dsh-tools": "workspace:*",
|
||||
"@deepseek-ai/dsh-llm": "workspace:*",
|
||||
"@deepseek-ai/dsh-fs": "workspace:*",
|
||||
"@deepseek-ai/dsh-fs-local": "workspace:*",
|
||||
"@deepseek-ai/dsh-agent-loop-testkit": "workspace:*",
|
||||
"@deepseek-ai/dsh-agent-loop": "workspace:*",
|
||||
"@deepseek-ai/dsh-working-directory": "workspace:*",
|
||||
"@deepseek-ai/dsh-system-prompt": "workspace:*",
|
||||
"@deepseek-ai/dsh-tool-executor-native": "workspace:*",
|
||||
"@deepseek-ai/dsh-tool-fs": "workspace:*",
|
||||
"@deepseek-ai/dsh-tool-testkit": "workspace:*",
|
||||
"@deepseek-ai/dsh-tool-str-replace-editor": "workspace:*",
|
||||
"@deepseek-ai/dsh-fs-observation-policy": "workspace:*",
|
||||
"@deepseek-ai/dsh-system-prompt": "workspace:*"
|
||||
"@deepseek-ai/dsh-tool-testkit": "workspace:*",
|
||||
"@deepseek-ai/dsh-tools": "workspace:*",
|
||||
"@deepseek-ai/dsh-working-directory": "workspace:*"
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,10 @@ import type {} from '@deepseek-ai/dsh-agent'
|
||||
import type { Session, SessionId } from '@deepseek-ai/dsh-session'
|
||||
import type {} from '@deepseek-ai/dsh-subprocess'
|
||||
import type {} from '@deepseek-ai/dsh-tools'
|
||||
import type {} from '@deepseek-ai/dsh-working-directory'
|
||||
import type { FsTarget } from '@deepseek-ai/dsh-fs'
|
||||
import { GitRunner } from './git.ts'
|
||||
import { TurnRecorder } from './recorder.ts'
|
||||
import { TurnRecorder, type TurnDirectories } from './recorder.ts'
|
||||
import type { WorkspaceChanges } from './types.ts'
|
||||
|
||||
export type {
|
||||
@@ -56,11 +57,25 @@ export const Config: z<Config> = z.object({
|
||||
diffTimeoutMs: z.number().default(100),
|
||||
})
|
||||
|
||||
/** The original directory of a summarized Session: a top-level Session with a recorded directory. */
|
||||
function eligible(session: Session): string | undefined {
|
||||
const { cwd, origin, delegationDepth } = session.header
|
||||
return origin === 'subagent' || (delegationDepth ?? 0) > 0 ? undefined : cwd
|
||||
}
|
||||
|
||||
/**
|
||||
* The directories a turn starts from: the Session's current directory, which
|
||||
* locates the repository, and its workspace root, which listed paths are
|
||||
* relative to. Without the working-directory service both are the original
|
||||
* project.
|
||||
*/
|
||||
function directoriesOf(ctx: Context, session: Session, original: string): TurnDirectories {
|
||||
const directories = ctx.get('workingDirectory')
|
||||
return directories === undefined
|
||||
? { cwd: original, root: original }
|
||||
: { cwd: directories.get(session), root: directories.rootOf(session) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the git executable once. On macOS the Xcode stub at `/usr/bin/git`
|
||||
* opens an installer dialog instead of running, so it counts as absent until
|
||||
@@ -129,10 +144,10 @@ export function apply(ctx: Context, config: Config): void {
|
||||
})
|
||||
return runner
|
||||
}
|
||||
const recorderFor = (session: Session, cwd: string): TurnRecorder => {
|
||||
const recorderFor = (session: Session, original: string): TurnRecorder => {
|
||||
let recorder = recorders.get(session)
|
||||
if (recorder === undefined) {
|
||||
recorder = new TurnRecorder(session, cwd, {
|
||||
recorder = new TurnRecorder(session, () => directoriesOf(ctx, session, original), {
|
||||
git: gitRunner(), tempRoot: tmpdir(), maxFiles: config.maxFiles,
|
||||
maxFileBytes: config.maxFileBytes, diffTimeoutMs: config.diffTimeoutMs,
|
||||
warn: (message) => { ctx.logger.warn(message) },
|
||||
@@ -144,8 +159,8 @@ export function apply(ctx: Context, config: Config): void {
|
||||
}
|
||||
ctx.on('session/event', (session, event) => {
|
||||
if (event.type === 'turn/start') {
|
||||
const cwd = eligible(session)
|
||||
if (cwd !== undefined) recorderFor(session, cwd).start(event.data.turn)
|
||||
const original = eligible(session)
|
||||
if (original !== undefined) recorderFor(session, original).start(event.data.turn)
|
||||
return
|
||||
}
|
||||
if (event.type === 'tool/result') recorders.get(session)?.observe(event)
|
||||
|
||||
@@ -76,7 +76,7 @@ export function isTemporaryPath(path: string, roots: readonly string[]): boolean
|
||||
/**
|
||||
* Sort key and label of a changed file; see `WorkspaceChangedFile.display`.
|
||||
* @param absolute - canonical absolute file path.
|
||||
* @param cwd - canonical Session working directory.
|
||||
* @param cwd - canonical Session workspace root.
|
||||
* @param root - repository top-level directory.
|
||||
* @param home - canonical home directory, or empty to skip the `~` form.
|
||||
* @returns the slash-separated display path.
|
||||
@@ -88,9 +88,9 @@ export function displayPathOf(absolute: string, cwd: string, root: string, home:
|
||||
}
|
||||
|
||||
/**
|
||||
* The durable `path` field: relative inside the working directory, absolute elsewhere.
|
||||
* The durable `path` field: relative inside the workspace root, absolute elsewhere.
|
||||
* @param absolute - canonical absolute file path.
|
||||
* @param cwd - canonical Session working directory.
|
||||
* @param cwd - canonical Session workspace root.
|
||||
* @returns the path the Web client opens the file through.
|
||||
*/
|
||||
export function durablePathOf(absolute: string, cwd: string): string {
|
||||
|
||||
@@ -27,10 +27,20 @@ export interface RecorderEnvironment {
|
||||
warn: (message: string) => void
|
||||
}
|
||||
|
||||
/** Canonical paths every comparison and display uses, resolved once per Session. */
|
||||
interface Paths {
|
||||
/** Canonical original project directory for repository discovery and display paths. */
|
||||
/** The directories a turn starts from, read when the turn opens. */
|
||||
export interface TurnDirectories {
|
||||
/** The Session's current directory, which locates the repository the turn is snapshotted in. */
|
||||
cwd: string
|
||||
/** The Session's workspace root, which listed paths are relative to. */
|
||||
root: string
|
||||
}
|
||||
|
||||
/** Canonical paths every comparison and display uses, resolved when a turn opens. */
|
||||
interface Paths {
|
||||
/** Canonical current directory for repository discovery. */
|
||||
cwd: string
|
||||
/** Canonical workspace root that listed paths are relative to. */
|
||||
root: string
|
||||
/** Canonical home directory abbreviated as `~` in display paths. */
|
||||
home: string
|
||||
/** Temporary roots whose files outside the workspace never enter a summary. */
|
||||
@@ -69,6 +79,8 @@ interface TurnRecord {
|
||||
/** Everything one turn accumulates; a new turn gets a new object so queued work for an older turn keeps its own. */
|
||||
interface TurnState {
|
||||
readonly turn: number
|
||||
/** The workspace root recorded for the turn, as the directory service spells it. */
|
||||
readonly root: string
|
||||
/**
|
||||
* The turn-start snapshot once it exists. `null` means no repository or no git, so the turn summarizes file-tool
|
||||
* captures only; `'failed'` means the repository exists but its snapshot failed, so the turn records nothing.
|
||||
@@ -83,8 +95,8 @@ interface TurnState {
|
||||
recordedAfterSeq: number
|
||||
}
|
||||
|
||||
function freshState(turn: number): TurnState {
|
||||
return { turn, baseline: null, captures: new Map(), lastToolResultSeq: -1, attemptedAfterSeq: -1, recordedAfterSeq: -1 }
|
||||
function freshState(turn: number, root: string): TurnState {
|
||||
return { turn, root, baseline: null, captures: new Map(), lastToolResultSeq: -1, attemptedAfterSeq: -1, recordedAfterSeq: -1 }
|
||||
}
|
||||
|
||||
/** A listed file with the sources of its two sides. */
|
||||
@@ -100,18 +112,22 @@ const OVERSIZED = Symbol('oversized')
|
||||
* comparisons this recorder keeps. Snapshot objects and captured copies live in
|
||||
* a temporary directory owned by the recorder; disposal removes it together
|
||||
* with the summaries. Tool execution waits for pending work so a snapshot or
|
||||
* capture never races a mutation. A working directory outside any repository,
|
||||
* capture never races a mutation. A current directory outside any repository,
|
||||
* or a Host without git, gets no snapshot; its summary lists the files the file
|
||||
* tools changed.
|
||||
* tools changed. Each turn reads the Session's directories again, so a turn
|
||||
* that starts in another checkout is snapshotted there and lists paths
|
||||
* relative to that workspace root.
|
||||
*/
|
||||
export class TurnRecorder {
|
||||
private chain: Promise<void> = Promise.resolve()
|
||||
/** The open turn; before the first `turn/start` it is an empty placeholder no event can match. */
|
||||
private state = freshState(0)
|
||||
/** Canonical paths, resolved by the first turn. */
|
||||
private state = freshState(0, '')
|
||||
/** Canonical paths of the open turn, resolved when it starts. */
|
||||
private paths: Paths | undefined
|
||||
/** The located repository, reused across turns once found; null keeps retrying each turn. */
|
||||
private repository: Repository | null = null
|
||||
/** Host facts shared by every turn, resolved by the first. */
|
||||
private host: Pick<Paths, 'home' | 'temporaryRoots'> | undefined
|
||||
/** Located repositories by canonical current directory, reused across turns; an absent entry keeps retrying each turn. */
|
||||
private readonly repositories = new Map<string, Repository>()
|
||||
/** Temporary directory holding this Session's snapshot objects, scratch indexes, and captured copies. */
|
||||
private scratch: Promise<string> | undefined
|
||||
/** Records by the sequence of the event that announced them. */
|
||||
@@ -120,7 +136,7 @@ export class TurnRecorder {
|
||||
|
||||
constructor(
|
||||
private readonly session: Session,
|
||||
private readonly cwd: string,
|
||||
private readonly directories: () => TurnDirectories,
|
||||
private readonly env: RecorderEnvironment,
|
||||
) {}
|
||||
|
||||
@@ -129,11 +145,13 @@ export class TurnRecorder {
|
||||
* @param turn - the turn number from `turn/start`.
|
||||
*/
|
||||
start(turn: number): void {
|
||||
const state = freshState(turn)
|
||||
const { cwd, root } = this.directories()
|
||||
const state = freshState(turn, root)
|
||||
this.state = state
|
||||
void this.enqueue(async (signal) => {
|
||||
try {
|
||||
this.paths ??= { cwd: await realpath(this.cwd), home: await canonicalPath(homedir()), temporaryRoots: await temporaryRoots() }
|
||||
this.host ??= { home: await canonicalPath(homedir()), temporaryRoots: await temporaryRoots() }
|
||||
this.paths = { cwd: await realpath(cwd), root: await realpath(root), ...this.host }
|
||||
const repository = await this.locate(this.paths.cwd, signal)
|
||||
if (repository === null) return
|
||||
const tree = await snapshotTree(repository.git, repository.workspace, signal)
|
||||
@@ -271,15 +289,17 @@ export class TurnRecorder {
|
||||
return this.scratch
|
||||
}
|
||||
|
||||
/** The repository enclosing the working directory, located once; null keeps retrying each turn. */
|
||||
/** The repository enclosing one current directory, located once per directory; null keeps retrying each turn. */
|
||||
private async locate(cwd: string, signal: AbortSignal): Promise<Repository | null> {
|
||||
if (this.repository !== null) return this.repository
|
||||
const located = this.repositories.get(cwd)
|
||||
if (located !== undefined) return located
|
||||
const git = await this.env.git
|
||||
if (git === null) return null
|
||||
const workspace = await locateGitWorkspace(git, cwd, () => this.scratchDir(), signal)
|
||||
if (workspace === null) return null
|
||||
this.repository = { git, workspace }
|
||||
return this.repository
|
||||
const repository = { git, workspace }
|
||||
this.repositories.set(cwd, repository)
|
||||
return repository
|
||||
}
|
||||
|
||||
/** One side's text, null for an absent file, or {@link OVERSIZED} for a snapshot side beyond the byte cap. */
|
||||
@@ -302,7 +322,7 @@ export class TurnRecorder {
|
||||
const { baseline } = state
|
||||
if (paths === undefined || baseline === 'failed' || state.lastToolResultSeq < 0) return
|
||||
state.attemptedAfterSeq = state.lastToolResultSeq
|
||||
// Without a snapshot the working directory itself bounds the workspace.
|
||||
// Without a snapshot the current directory itself bounds the workspace.
|
||||
const root = baseline?.workspace.root ?? paths.cwd
|
||||
const listed = new Map<string, Listed>()
|
||||
let snapshot: WorkspaceChangesSummary['snapshot']
|
||||
@@ -353,7 +373,7 @@ export class TurnRecorder {
|
||||
this.records.set(event.seq, {
|
||||
summary: {
|
||||
turn: state.turn,
|
||||
cwd: this.cwd,
|
||||
root: state.root,
|
||||
files: kept.map(entry => entry.file),
|
||||
total: sorted.length,
|
||||
added: sorted.reduce((sum, entry) => sum + entry.file.added, 0),
|
||||
@@ -389,10 +409,10 @@ function isBinary(capture: Capture): boolean {
|
||||
|
||||
interface Counts { added: number; deleted: number; binary: boolean; oversized?: boolean }
|
||||
|
||||
function changedFile({ cwd, home }: Paths, root: string, absolute: string, counts: Counts): WorkspaceChangedFile {
|
||||
function changedFile({ root: workspaceRoot, home }: Paths, root: string, absolute: string, counts: Counts): WorkspaceChangedFile {
|
||||
return {
|
||||
path: durablePathOf(absolute, cwd),
|
||||
display: displayPathOf(absolute, cwd, root, home),
|
||||
path: durablePathOf(absolute, workspaceRoot),
|
||||
display: displayPathOf(absolute, workspaceRoot, root, home),
|
||||
added: counts.added,
|
||||
deleted: counts.deleted,
|
||||
...counts.binary ? { binary: true as const } : {},
|
||||
|
||||
@@ -3,10 +3,10 @@ import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
|
||||
/** One file changed during a turn, with line counts from git or from the whole-file captures around its file-tool edits. */
|
||||
export interface WorkspaceChangedFile {
|
||||
/** Path relative to the Session working directory, or an absolute Host path outside it. */
|
||||
/** Path relative to the Session workspace root, or an absolute Host path outside it. */
|
||||
path: string
|
||||
/**
|
||||
* Sort key and label: the relative path inside the working directory, a
|
||||
* Sort key and label: the relative path inside the workspace root, a
|
||||
* `../` path for repository files above it, a `~` path under the home
|
||||
* directory, otherwise the absolute path. Always slash-separated.
|
||||
*/
|
||||
@@ -25,8 +25,8 @@ export interface WorkspaceChangedFile {
|
||||
export interface WorkspaceChangesSummary {
|
||||
/** The turn whose file changes this summary describes. */
|
||||
turn: number
|
||||
/** The Session working directory `path` values are relative to. */
|
||||
cwd: string
|
||||
/** The Session workspace root `path` values are relative to, as it stood when the turn started. */
|
||||
root: string
|
||||
/** Changed files in `display` order, capped at the plugin's `maxFiles`. */
|
||||
files: WorkspaceChangedFile[]
|
||||
/** Complete changed-file count, including files omitted by the cap. */
|
||||
|
||||
@@ -62,7 +62,7 @@ it.each(['write', 'edit', 'str_replace_editor'] as const)('captures the resolved
|
||||
const announcement = events.findLast(event => event.type === 'workspace/changes')
|
||||
expect(announcement).toBeDefined()
|
||||
const summary = ctx.workspaceChanges.summary(agent.id, announcement!.seq)
|
||||
expect(summary).toMatchObject({ cwd: origin, total: 1, files: [{ path: 'current/witness.txt', added: 1, deleted: 1 }] })
|
||||
expect(summary).toMatchObject({ root: origin, total: 1, files: [{ path: 'current/witness.txt', added: 1, deleted: 1 }] })
|
||||
expect(summary!.snapshot).toBeUndefined()
|
||||
expect(await ctx.workspaceChanges.diff(agent.id, announcement!.seq, 0, new AbortController().signal)).toMatchObject({ kind: 'text', hunks: [{ lines: ['-before', '+after'] }] })
|
||||
})
|
||||
|
||||
@@ -176,7 +176,7 @@ describe('TurnRecorder', () => {
|
||||
const gate = new Promise<GitRunner | null>((resolve) => { release = resolve })
|
||||
const tempRoot = await scratchDir('dsh-git-store-', cleanups)
|
||||
const env = { git: gate, tempRoot, maxFiles: 10, maxFileBytes: 1024, diffTimeoutMs: 100, warn: (m: string) => { warnings.push(m) } }
|
||||
const disposed = new TurnRecorder(session, cwd, env)
|
||||
const disposed = new TurnRecorder(session, () => ({ cwd: cwd, root: cwd }), env)
|
||||
disposed.start(1)
|
||||
await new Promise(resolve => setTimeout(resolve, 5))
|
||||
const disposal = disposed.dispose()
|
||||
@@ -188,7 +188,7 @@ describe('TurnRecorder', () => {
|
||||
expect(disposed.summary(1)).toBeUndefined()
|
||||
|
||||
const { git: missing } = await runner(undefined, '/nonexistent/git-binary')
|
||||
const failing = new TurnRecorder(session, cwd, { ...env, git: Promise.resolve(missing) })
|
||||
const failing = new TurnRecorder(session, () => ({ cwd: cwd, root: cwd }), { ...env, git: Promise.resolve(missing) })
|
||||
failing.start(1)
|
||||
await failing.settled()
|
||||
expect(warnings).toHaveLength(1)
|
||||
@@ -202,13 +202,13 @@ describe('TurnRecorder', () => {
|
||||
git: Promise.resolve(runnerGit), tempRoot, maxFiles: 10, maxFileBytes: 1024, diffTimeoutMs: 100,
|
||||
warn: (m: string) => { throw new Error(m) },
|
||||
}
|
||||
const plain = new TurnRecorder(ctx.sessions.create(SessionId('plain'), { meta: { cwd: tempRoot } }), tempRoot, env)
|
||||
const plain = new TurnRecorder(ctx.sessions.create(SessionId('plain'), { meta: { cwd: tempRoot } }), () => ({ cwd: tempRoot, root: tempRoot }), env)
|
||||
plain.start(1)
|
||||
await plain.settled()
|
||||
await plain.dispose()
|
||||
const cwd = await scratchDir('dsh-recorder-repo-', cleanups)
|
||||
git(cwd, 'init', '-q', '-b', 'main')
|
||||
const repo = new TurnRecorder(ctx.sessions.create(SessionId('repo'), { meta: { cwd } }), cwd, env)
|
||||
const repo = new TurnRecorder(ctx.sessions.create(SessionId('repo'), { meta: { cwd } }), () => ({ cwd, root: cwd }), env)
|
||||
repo.start(1)
|
||||
await repo.settled()
|
||||
const [objects, ...others] = (await readdir(tempRoot)).filter(entry => entry.startsWith('dsh-workspace-changes-'))
|
||||
@@ -231,7 +231,7 @@ describe('TurnRecorder', () => {
|
||||
git: Promise.resolve(runnerGit), tempRoot, maxFiles: 10, maxFileBytes: 1024, diffTimeoutMs: 100,
|
||||
warn: (m: string) => { throw new Error(m) },
|
||||
}
|
||||
const recorder = new TurnRecorder(session, cwd, env)
|
||||
const recorder = new TurnRecorder(session, () => ({ cwd: cwd, root: cwd }), env)
|
||||
startTurn(session, 1)
|
||||
recorder.start(1)
|
||||
await recorder.settled()
|
||||
|
||||
Loaded 100 of 146 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user