fix(workspace-files): expose the Session scope as a service method and repair the consumer gates
ui-deliverables and the desktop host resolve a Session's workspace file scope through workspaceFiles.scopeOf instead of a cross-package value import, which the dependency policy refuses for a client-host package; the two type-only peers of workspace-files become devDependencies. The sidebar-files fixture builds a complete SessionListState instead of an unknown assertion, and the testkit directory fixture reports no anchor for a Session without a recorded directory, so the sandbox policy falls back to its configured root as the real service does.
This commit is contained in:
1 parent
c65519b92a
commit
bb078f4e2b
15 files changed
+72
-28
No files matched your search
@@ -1,10 +1,8 @@
|
||||
/** 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-api-workspace-files'
|
||||
import type {} from '@deepseek-ai/dsh-fs'
|
||||
import type {} from '@deepseek-ai/dsh-session'
|
||||
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'
|
||||
|
||||
@@ -27,10 +25,11 @@ export async function localDragResource(ctx: Context, address: string, cancellat
|
||||
const resource = parseFileAddress(address)
|
||||
if (resource?.scope !== 'session') throw new Error('File drag requires a Session resource')
|
||||
const fs = ctx.get('fs')
|
||||
if (fs === undefined || ctx.get('sessions') === undefined || ctx.get('sandboxPolicy') === undefined) throw new Error('File access unavailable')
|
||||
const workspaceFiles = ctx.get('workspaceFiles')
|
||||
if (fs === undefined || workspaceFiles === 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 scope = await resolveWorkspaceFileScope(ctx, resource.sessionId as SessionId, signal)
|
||||
const scope = await workspaceFiles.scopeOf(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)
|
||||
|
||||
@@ -16,9 +16,13 @@ async function fixture() {
|
||||
onTestFinished(async () => { await ctx.fiber.dispose(); await rm(root, { recursive: true, force: true }) })
|
||||
await ctx.plugin(LocalFileSystem, { cwd: root })
|
||||
await ctx.plugin(SessionStore)
|
||||
ctx.provide('sandboxPolicy', { workspaceRoot: root } as never)
|
||||
const id = SessionId('file-drag-test')
|
||||
ctx.sessions.create(id, { meta: { cwd: root, origin: 'subagent' } })
|
||||
// The workspace file service resolves a live Session's root; its own tests cover that resolution.
|
||||
ctx.provide('workspaceFiles', {
|
||||
scopeOf: (sessionId: SessionId) =>
|
||||
Promise.resolve(ctx.sessions.get(sessionId) === undefined ? undefined : { sessionId, workspaceRoot: root }),
|
||||
} as never)
|
||||
const path = join(root, '报告.pdf')
|
||||
const bytes = Buffer.from('%PDF-1.4\n原始内容\n%%EOF')
|
||||
await writeFile(path, bytes)
|
||||
|
||||
@@ -409,6 +409,15 @@ Source: [`packages/api/workspace-controller/src/index.ts`](../../packages/api/wo
|
||||
Host Remote file reads and workspace directory observations over the composed filesystem.
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Resolve the scope other Host services use to open the same `session/<id>/<path>` addresses:
|
||||
* a live Session's workspace root, else a stored Session's recorded root, else its header directory.
|
||||
* @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.
|
||||
*/
|
||||
scopeOf(sessionId: SessionId, signal?: AbortSignal): Promise<WorkspaceFileScope | undefined>
|
||||
|
||||
/**
|
||||
* Read one page of lines from a UTF-8 file readable by the filesystem backend.
|
||||
* @param workspaceFileScope - header-derived workspace root for the Session identity on the wire.
|
||||
@@ -459,6 +468,8 @@ Host Remote file reads and workspace directory observations over the composed fi
|
||||
@Remote({ mode: 'stream' }) changes(workspaceFileScope: WorkspaceFileScope, path: string, signal: AbortSignal): AsyncIterable<WorkspaceFileWatchFrame>
|
||||
```
|
||||
|
||||
Types: [SessionId](core.md)
|
||||
|
||||
Source: [`packages/api/workspace-files/src/index.ts`](../../packages/api/workspace-files/src/index.ts)
|
||||
|
||||
<a id="ctxworkspaceregistry--workspaceregistry"></a>
|
||||
|
||||
@@ -409,6 +409,15 @@ Source: [`packages/api/workspace-controller/src/index.ts`](../../packages/api/wo
|
||||
Host Remote file reads and workspace directory observations over the composed filesystem.
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Resolve the scope other Host services use to open the same `session/<id>/<path>` addresses:
|
||||
* a live Session's workspace root, else a stored Session's recorded root, else its header directory.
|
||||
* @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.
|
||||
*/
|
||||
scopeOf(sessionId: SessionId, signal?: AbortSignal): Promise<WorkspaceFileScope | undefined>
|
||||
|
||||
/**
|
||||
* Read one page of lines from a UTF-8 file readable by the filesystem backend.
|
||||
* @param workspaceFileScope - header-derived workspace root for the Session identity on the wire.
|
||||
@@ -459,6 +468,8 @@ Host Remote file reads and workspace directory observations over the composed fi
|
||||
@Remote({ mode: 'stream' }) changes(workspaceFileScope: WorkspaceFileScope, path: string, signal: AbortSignal): AsyncIterable<WorkspaceFileWatchFrame>
|
||||
```
|
||||
|
||||
Types: [SessionId](core.zh.md)
|
||||
|
||||
Source: [`packages/api/workspace-files/src/index.ts`](../../packages/api/workspace-files/src/index.ts)
|
||||
|
||||
<a id="ctxworkspaceregistry--workspaceregistry"></a>
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
en: d152484eb41ac6b4
|
||||
zh: 09388d293f9be9cb
|
||||
/deepseek-ai-dsh-api-workspace-files/use-this-package:
|
||||
en: 0dcc561a32c95842
|
||||
zh: af6355823a56bbf0
|
||||
en: 903c1548b14a0ffd
|
||||
zh: d900442c7445710a
|
||||
/deepseek-ai-dsh-api-workspace-files/use-this-package/addressing-and-paths:
|
||||
en: b9565cfa7a1da451
|
||||
zh: fc4078a58322fc7f
|
||||
|
||||
@@ -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'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`.
|
||||
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. `workspaceFiles.scopeOf(sessionId, signal)` offers that resolution to 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 |
|
||||
|---|---|---|
|
||||
|
||||
@@ -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 的工作区根,cold Session 则读取持久化 header 旁投影缓存中记录的根,再回退到 header 目录;它不会激活 Agent、读取事件正文或借用父 Session 的根。`resolveWorkspaceFileScope(ctx, sessionId, signal)` 把这一解析导出给打开同一种 `session/<id>/<path>` 地址的其他 Host 服务。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 的根。`workspaceFiles.scopeOf(sessionId, signal)` 把这一解析提供给打开同一种 `session/<id>/<path>` 地址的其他 Host 服务。live 读取不要求挂载 Session persistence;未挂载时 cold Session 无法解析,Gateway 返回 `gateway/lookup-not-found`。
|
||||
|
||||
| 方法 | 返回 | 用途 |
|
||||
|---|---|---|
|
||||
|
||||
@@ -59,9 +59,7 @@
|
||||
"zod": "4.4.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@deepseek-ai/cordis": "workspace:~",
|
||||
"@deepseek-ai/dsh-session-projection-cache": "workspace:*",
|
||||
"@deepseek-ai/dsh-working-directory": "workspace:*"
|
||||
"@deepseek-ai/cordis": "workspace:~"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@deepseek-ai/cordis": "workspace:~",
|
||||
|
||||
@@ -75,7 +75,7 @@ export interface WorkspaceFileScope {
|
||||
* @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(
|
||||
async function workspaceFileScopeOf(
|
||||
ctx: Context, sessionId: SessionId, signal?: AbortSignal,
|
||||
): Promise<WorkspaceFileScope | undefined> {
|
||||
const live = ctx.get('sessions')?.get(sessionId)
|
||||
@@ -237,11 +237,22 @@ export class WorkspaceFiles extends TypertRemoteService {
|
||||
resource: 'session',
|
||||
hostTypeSymbol: '@deepseek-ai/dsh-api-workspace-files#WorkspaceFileScope',
|
||||
wireTypeSymbol: '@deepseek-ai/dsh-session/types#SessionId',
|
||||
resolve: sessionId => resolveWorkspaceFileScope(scope, sessionId),
|
||||
resolve: sessionId => workspaceFileScopeOf(scope, sessionId),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the scope other Host services use to open the same `session/<id>/<path>` addresses:
|
||||
* a live Session's workspace root, else a stored Session's recorded root, else its header directory.
|
||||
* @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.
|
||||
*/
|
||||
scopeOf(sessionId: SessionId, signal?: AbortSignal): Promise<WorkspaceFileScope | undefined> {
|
||||
return workspaceFileScopeOf(this.ctx, sessionId, signal)
|
||||
}
|
||||
|
||||
/**
|
||||
* Read one page of lines from a UTF-8 file readable by the filesystem backend.
|
||||
* @param workspaceFileScope - header-derived workspace root for the Session identity on the wire.
|
||||
|
||||
@@ -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, { resolveWorkspaceFileScope } from '../src/index.ts'
|
||||
import WorkspaceFiles from '../src/index.ts'
|
||||
|
||||
const CAPS = {
|
||||
maxBytes: 1024,
|
||||
@@ -53,9 +53,9 @@ describe('Workspace Files Session scope lookup', () => {
|
||||
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 })
|
||||
await expect(ctx.workspaceFiles.scopeOf(liveId)).resolves.toEqual({ sessionId: liveId, workspaceRoot: liveWorktree })
|
||||
await expect(ctx.workspaceFiles.scopeOf(coldId)).resolves.toEqual({ sessionId: coldId, workspaceRoot: coldWorktree })
|
||||
await expect(ctx.workspaceFiles.scopeOf(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')
|
||||
@@ -108,7 +108,7 @@ describe('Workspace Files Session scope lookup', () => {
|
||||
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 })
|
||||
await expect(ctx.workspaceFiles.scopeOf(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 })
|
||||
|
||||
@@ -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 { resolveWorkspaceFileScope } from '@deepseek-ai/dsh-api-workspace-files'
|
||||
import type {} 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'
|
||||
@@ -116,7 +116,7 @@ async function handlePresentOpen(ctx: Context, request: Request): Promise<Respon
|
||||
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 scope = await resolveWorkspaceFileScope(ctx, id as SessionId, request.signal)
|
||||
const scope = await ctx.workspaceFiles.scopeOf(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)
|
||||
|
||||
@@ -130,8 +130,12 @@ function harness(placement: Placement, controller: AbortController) {
|
||||
openTab: vi.fn<SidebarRightTabActions['openTab']>(),
|
||||
close: vi.fn<SidebarRightTabActions['close']>(),
|
||||
}
|
||||
const sessionsAt = (cwd: string | null): SessionListState =>
|
||||
({ byId: cwd === null ? {} : { [SESSION]: { cwd } }, projectionsBySession: {} } as unknown as SessionListState)
|
||||
const sessionsAt = (cwd: string | null): SessionListState => ({
|
||||
ids: cwd === null ? [] : [SESSION],
|
||||
byId: cwd === null ? {} : { [SESSION]: { id: SESSION, displayTitle: 'files', running: false, retainedBy: {}, blank: false, updatedAt: 0, cwd } },
|
||||
phase: 'ready',
|
||||
projectionsBySession: {},
|
||||
})
|
||||
const useTabInfo = (): SidebarRightTabInfo => ({
|
||||
sidebar: { expanded: true, fullscreen: false },
|
||||
panel: { id: PANE, isFloating: placement.isFloating ?? false },
|
||||
|
||||
@@ -4586,6 +4586,12 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
|
||||
summary: 'Host Remote file reads and workspace directory observations over the composed filesystem.',
|
||||
description: 'Host Remote file reads and workspace directory observations over the composed filesystem.',
|
||||
methods: [
|
||||
{
|
||||
signature: 'scopeOf(sessionId: SessionId, signal?: AbortSignal): Promise<WorkspaceFileScope | undefined>',
|
||||
description: 'Resolve the scope other Host services use to open the same `session/<id>/<path>` addresses: a live Session\'s workspace root, else a stored Session\'s recorded root, else its header directory.',
|
||||
parameters: [{ name: 'sessionId', description: 'Session identity received on the wire.' }, { name: 'signal', description: 'cancellation for the persistence read of a stored Session.' }],
|
||||
returns: 'the scope, or undefined when no live or stored Session has that identity.',
|
||||
},
|
||||
{
|
||||
signature: '@Remote async read( workspaceFileScope: WorkspaceFileScope, path: string, range: WorkspaceFileRange, signal: AbortSignal, ): Promise<WorkspaceFileText>',
|
||||
description: 'Read one page of lines from a UTF-8 file readable by the filesystem backend.',
|
||||
|
||||
@@ -5,7 +5,8 @@ import type { Session } from '@deepseek-ai/dsh-session'
|
||||
|
||||
/**
|
||||
* Supply fixed directory values without filesystem checks or durable changes.
|
||||
* The workspace root equals the directory, which is the Session's only anchor.
|
||||
* The workspace root equals the directory, which is the Session's only anchor; a Session without a
|
||||
* recorded directory has no anchor, so consumers fall back as they do with the real service.
|
||||
* @param ctx - context owning this test collaborator.
|
||||
* @param defaultDirectory - fallback for fixtures without a Session directory.
|
||||
*/
|
||||
@@ -15,7 +16,7 @@ export function provideWorkingDirectoryFixture(ctx: Context, defaultDirectory =
|
||||
defaultDirectory,
|
||||
get,
|
||||
rootOf: get,
|
||||
anchorsOf: (session: Session): readonly string[] => [get(session)],
|
||||
anchorsOf: (session: Session): readonly string[] => session.header.cwd === undefined ? [] : [get(session)],
|
||||
ensure: (agent: Agent): Promise<string> => Promise.resolve(get(agent.session)),
|
||||
})
|
||||
}
|
||||
@@ -639,8 +639,7 @@
|
||||
"1bbd18e22567ce0529d02b770533f9bda84ff379b161dda8b9548053a18a0e97": 1
|
||||
},
|
||||
"packages/client/ui-sidebar-files/tests/mount.client.tsx": {
|
||||
"2caa9ae382deea09b4ac64586c1ab49bd935b1e689218e3d485bd7b918e22066": 1,
|
||||
"684eae6dc3d4dbe526c5a5b11ebd84e35e335bebd519cf09c0f3a24ba9280fc1": 1
|
||||
"2caa9ae382deea09b4ac64586c1ab49bd935b1e689218e3d485bd7b918e22066": 1
|
||||
},
|
||||
"packages/client/ui-sidebar-files/tests/watch.client.spec.ts": {
|
||||
"a5cc084c7b08798fed2de12497312800c3d9bbb8911d859364876cfbf4adf8e7": 1
|
||||
|
||||
Reference in new issue
Block a user