Merge branch 'feat/session-workspace-root' into feat/session-workspace-root-consumers

The lower branch removed `rootOf` and the `workspaceRoot` projection: a Session
has one directory, read through `ctx.workingDirectory.get`. This merge moves the
consumers of this branch to that read.

- sandbox-policy, workspace-files, and workspace-changes read `get`; the
  `recordedRootOf` read is removed. With the working-directory service mounted,
  a Session without a header directory is bounded by that service's default
  directory.
- The skill catalog, sidebar terminals, project instructions, `@` file
  candidates, the LSP workspace, and skill lookup return to the lower branch's
  code, which already reads the directory.
- The client helper exports `selectSessionDirectory` and `sessionDirectory`
  in place of the `{ root, cwd }` pair; `WorkspaceChangesSummary` keeps `cwd`,
  now the directory the turn started in.
- A stored `working-directory/change` inside the project moves the write
  boundary and file views with the directory; one outside returns to the project.
This commit is contained in:
LegGasai committed 2026-11-16 22:33:13 +08:00
commit c9b9859b74
955 files changed
+25445 -11344

No files matched your search

@@ -1,25 +1,14 @@
/**
* The directories of one Session as the Client knows them: the projected
* workspace root and current directory. Pure reads with type-only imports, so
* client plugins inline this module instead of requesting a module-table row
* this package does not publish.
* The directory one Session works in, as the Client knows it: the projected
* `workingDirectory`. 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'
/** Which checkout a Session works in and where its relative paths resolve. */
export interface SessionDirectories {
/**
* 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
@@ -28,28 +17,25 @@ function projectedString(values: object | undefined, key: string): string | unde
}
/**
* Select a Session's workspace root from a list snapshot, for `useSessions` selectors.
* Select a Session's directory from a list snapshot, for `useSessions` selectors. File views, address
* bases, and relative paths all use it; the header directory stays the original project.
* @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.
* @param sessionId - the Session whose directory is selected.
* @returns the projected `workingDirectory`, 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')
export function selectSessionDirectory(state: SessionListState, sessionId: SessionId): string | undefined {
return projectedString(state.projectionsBySession[sessionId]?.values, 'workingDirectory')
?? projectedString(state.byId[sessionId]?.projectionValues, 'workingDirectory')
?? state.byId[sessionId]?.cwd
}
/**
* Read a Session's directories at gesture time: the connected Session's projection faces first, then the list snapshot.
* Read a Session's directory at gesture time: the connected Session's projection face first, then the list snapshot.
* @param sessions - the sessions service.
* @param sessionId - the Session whose directories are read.
* @returns the workspace root and the current directory, each undefined when unknown.
* @param sessionId - the Session whose directory is read.
* @returns the directory, or undefined when unknown.
*/
export function sessionDirectories(sessions: ISessions, sessionId: SessionId): SessionDirectories {
const projections = sessions.binding(sessionId)?.session.projections
const liveRoot: unknown = projections?.faceOf('workspaceRoot').getSnapshot()
const root = (typeof liveRoot === 'string' ? liveRoot : undefined) ?? selectSessionRoot(sessions.list.getSnapshot(), sessionId)
const liveCwd: unknown = projections?.faceOf('workingDirectory').getSnapshot()
const cwd = (typeof liveCwd === 'string' ? liveCwd : undefined) ?? root
return { root, cwd }
export function sessionDirectory(sessions: ISessions, sessionId: SessionId): string | undefined {
const live: unknown = sessions.binding(sessionId)?.session.projections.faceOf('workingDirectory').getSnapshot()
return (typeof live === 'string' ? live : undefined) ?? selectSessionDirectory(sessions.list.getSnapshot(), sessionId)
}
+2 -30
View File
@@ -13,7 +13,7 @@ import { canOpenNativePath, nativeFileManager, nativeFileApplications, openNativ
import type { SessionId } from '@deepseek-ai/dsh-session'
import type {} from '@deepseek-ai/dsh-session-projection-cache'
import type { SessionObservation } from '@deepseek-ai/dsh-session-query'
import { Remote, RemoteError, TypertRemoteService, principalOf, type TypertResourceResolveInput } from '@deepseek-ai/dsh-typert-protocol'
import { Remote, RemoteError, TypertRemoteService, principalOf } from '@deepseek-ai/dsh-typert-protocol'
import { canonicalClientTimeZone } from '@deepseek-ai/dsh-util-time'
import { assertNever } from '@deepseek-ai/dsh-util-values'
import type {} from '@deepseek-ai/dsh-api-remote-access'
@@ -22,6 +22,7 @@ import {
type ApiSessionAgentResult,
} from './agent.ts'
import { SessionCommandController, hasPromptContent } from './commands.ts'
import { resolveSessionResource } from './session-resource.ts'
import { SessionControlController } from './control.ts'
import { HistoryController } from './history/controller.ts'
import { StateController } from './state/controller.ts'
@@ -35,7 +36,6 @@ import { ArchivedSessionGate } from './archived-session-gate.ts'
import type {
ModelCatalog,
SessionWorkspacePathApplication,
SessionAddress,
SessionAttachmentRequest,
SessionAttachmentValue,
SessionCancelRequest,
@@ -79,34 +79,6 @@ declare module '@deepseek-ai/cordis' {
}
}
/**
* Extract the Session resource from an ID or a history address.
*
* Registers as the `session` kind default, so it applies to every Remote method of
* every namespace: a top-level `sessionId` parameter, otherwise the first object
* parameter carrying `sessionId` or an `address`. A new request type whose first
* object parameter has an unrelated `address` field would be read as an address.
* @param input - validated wire arguments and their ordered parameter descriptions.
* @returns the named Session identity, otherwise the first object's Session identity or history address.
* @throws Error when the request object supplies both sessionId and address.
*/
function resolveSessionResource({ args, parameters }: TypertResourceResolveInput): SessionId | undefined {
const sessionParameter = parameters.find(parameter => parameter.name === 'sessionId' || parameter.wire === 'sessionId')
if (sessionParameter !== undefined) return args[sessionParameter.wire] as SessionId | undefined
for (const parameter of parameters) {
const value = args[parameter.wire]
if (typeof value !== 'object' || value === null || Array.isArray(value)) continue
const request = value as { readonly sessionId?: SessionId; readonly address?: SessionAddress }
const address = request.address
if (request.sessionId !== undefined && address !== undefined) {
throw new Error('Session resource request must not contain both sessionId and address')
}
return request.sessionId ?? (address === undefined ? undefined
: address.kind === 'session' ? address.sessionId : address.childSessionId)
}
return undefined
}
/** Session Controller deployment policy. */
export interface Config {
/** Override platform desktop-opener detection. */
+6 -40
View File
@@ -5,8 +5,8 @@ import { scheduler } from 'node:timers/promises'
import type { Context } from '@deepseek-ai/cordis'
import type {} from '@deepseek-ai/dsh-agent-preset-registry'
import type { ImageAttachmentLimits } from '@deepseek-ai/dsh-attachment'
import type { Session, SessionEvent, SessionHeader, SessionId } from '@deepseek-ai/dsh-session'
import type { ProjectionHandle, ProjectionSnapshot } from '@deepseek-ai/dsh-session-projection'
import type { Session, SessionHeader, SessionId } from '@deepseek-ai/dsh-session'
import type { ProjectionSnapshot } from '@deepseek-ai/dsh-session-projection'
import type {} from '@deepseek-ai/dsh-session-projection-cache'
import { SessionQueryError, type SessionRecord, type SessionSearchCursor } from '@deepseek-ai/dsh-session-query'
import { RemoteError } from '@deepseek-ai/dsh-typert-protocol'
@@ -24,11 +24,6 @@ const SEARCH_PROVIDER_CALL_LIMIT = 100
const SESSION_SEARCH_QUERY_MAX_CHARS = 500
const MESSAGE_TYPES = new Set(['user/message', 'assistant/message'])
const sessionListMetadataSchema: z.ZodType<SessionListMetadata> = z.object({
blank: z.boolean(),
lastPromptAt: z.number().nullable(),
})
const imageLimitsSchema = z.object({
maxImageBytes: z.number().int().positive(),
maxImagesPerMessage: z.number().int().positive(),
@@ -38,25 +33,6 @@ const imageLimitsSchema = z.object({
mediaTypes: z.array(z.string()),
}) as unknown as z.ZodType<ImageAttachmentLimits>
/**
* Advance the Session-list metadata projection by one committed event.
* @param state - metadata before the event.
* @param event - next committed Session event.
* @returns the original or advanced metadata value.
*/
export function applySessionListMetadata(
state: SessionListMetadata,
event: SessionEvent,
): SessionListMetadata {
const blank = state.blank && event.type !== 'turn/start'
const lastPromptAt = event.type === 'user/message' && event.data.source.kind === 'user'
? event.time
: state.lastPromptAt
return blank === state.blank && lastPromptAt === state.lastPromptAt
? state
: { blank, lastPromptAt }
}
/**
* Return the longest prefix containing at most `maximum` Unicode code points.
* @param value - source text.
@@ -76,8 +52,6 @@ export function truncateUnicodeCodePoints(value: string, maximum: number): strin
/** Owns list projection registration, bounded cold summaries, and authorized search. */
export class ApiSessionList {
private listMetadata!: ProjectionHandle<SessionListMetadata>
/**
* @param ctx - Host context carrying Session, query, persistence, and projection services.
* @param workSliceMs - Resolved positive integral list-work budget in milliseconds.
@@ -89,14 +63,6 @@ export class ApiSessionList {
* @returns when all required registrations are ready.
*/
async initialize(): Promise<void> {
this.listMetadata = await this.ctx.sessionProjections.register<'sessionListMetadata', SessionListMetadata>({
key: 'sessionListMetadata',
stateSchema: sessionListMetadataSchema,
init: () => ({ blank: true, lastPromptAt: null }),
apply: applySessionListMetadata,
wire: { viewSchema: sessionListMetadataSchema, view: state => state },
stateVersion: 1,
})
await this.ctx.sessionProjections.register<'imageLimits', null>({
key: 'imageLimits',
stateSchema: z.null(),
@@ -113,17 +79,17 @@ export class ApiSessionList {
/**
* Build one current attached-Session summary.
* Blankness and recency come from the `sessionListMetadata` handle; projection
* Blankness and recency come from `sessionQuery.getListMetadata`; projection
* hints carry every summary key computed through `snapshot`. The first call
* for a Session computes these projections over its whole in-memory log, and
* later calls advance them incrementally. The handle read and the hint with
* the same key come from one cell; the handle read does not depend on any
* later calls advance them incrementally. The metadata read and the hint with
* the same key come from one cell; the metadata read does not depend on any
* other unit's view.
* @param session - attached Session to summarize.
* @returns current list metadata and available projections.
*/
summaryFor(session: Session): SessionSummary {
const metadata = this.listMetadata.stateOf(session)
const metadata = this.ctx.sessionQuery.getListMetadata(session)
const projections = this.projectionsFor(session.header, session)
return {
sessionId: session.id,
@@ -0,0 +1,38 @@
/**
* The `session` resource kind's default identity extraction: the Session one
* Remote call names, read from its validated wire arguments.
* @module @deepseek-ai/dsh-api-session-controller/session-resource
*/
import type { SessionId } from '@deepseek-ai/dsh-session'
import type { TypertResourceResolveInput } from '@deepseek-ai/dsh-typert-protocol'
import type { SessionAddress } from './types.ts'
/**
* Extract the Session resource from an ID or a history address.
*
* Registers as the `session` kind default, so it applies to every Remote method of
* every namespace: a top-level `sessionId` parameter, otherwise the first object
* parameter carrying `sessionId` or an `address`. A new request type whose first
* object parameter has an unrelated `address` field would be read as an address.
* @param input - validated wire arguments and their ordered parameter descriptions.
* @returns the named Session identity, otherwise the first object's Session identity or history address.
* @throws Error when the request object supplies both sessionId and address.
*/
export function resolveSessionResource(input: TypertResourceResolveInput): SessionId | undefined {
const { args, parameters } = input
const sessionParameter = parameters.find(parameter => parameter.name === 'sessionId' || parameter.wire === 'sessionId')
if (sessionParameter !== undefined) return args[sessionParameter.wire] as SessionId | undefined
for (const parameter of parameters) {
const value = args[parameter.wire]
if (typeof value !== 'object' || value === null || Array.isArray(value)) continue
const request = value as { readonly sessionId?: SessionId; readonly address?: SessionAddress }
const address = request.address
if (request.sessionId !== undefined && address !== undefined) {
throw new Error('Session resource request must not contain both sessionId and address')
}
return request.sessionId ?? (address === undefined ? undefined
: address.kind === 'session' ? address.sessionId : address.childSessionId)
}
return undefined
}
@@ -42,15 +42,12 @@ export class SessionSkillCatalog extends TypertRemoteService {
if (observation.projections === undefined) {
throw new Error('skill catalog requires a projected Session observation')
}
cwd = observation.projections.values.workspaceRoot
cwd = observation.projections.values.workingDirectory
?? observation.header.cwd
?? this.ctx.workingDirectory.defaultDirectory
agentPreset = observation.projections.values.agentPreset ?? undefined
const live = this.ctx.agents.get(sessionId)
if (live !== undefined) {
await this.ctx.workingDirectory.ensure(live, signal)
cwd = this.ctx.workingDirectory.rootOf(live.session)
}
if (live !== undefined) cwd = await this.ctx.workingDirectory.ensure(live, signal)
} catch (error: unknown) {
if (error instanceof SessionQueryError
&& error.code === 'SESSION_QUERY_SESSION_NOT_FOUND') {
+2 -10
View File
@@ -14,12 +14,12 @@ import type { Principal } from '@deepseek-ai/dsh-typert-protocol'
import type { JsonValue } from '@deepseek-ai/dsh-util-values'
import type { WorkspaceId } from '@deepseek-ai/dsh-workspace/types'
export type { SessionListMetadata } from '@deepseek-ai/dsh-session-query/types'
declare module '@deepseek-ai/dsh-session-projection/types' {
interface SessionProjectionMap {
/** Eligible latest failed turn/end for an empty prompt, or null. */
conversationContinuation: SessionSeq | null
/** Persisted facts used to summarize a Session without activating it. */
sessionListMetadata: SessionListMetadata
/**
* Image-intake limits enforced by the Session prompt endpoint. Boot
* constant, excluded from Session summary payloads: every Session shares
@@ -29,14 +29,6 @@ declare module '@deepseek-ai/dsh-session-projection/types' {
}
}
/** Persisted hints used to summarize a cold Session. */
export interface SessionListMetadata {
/** Whether the folded prefix contains no turn. */
readonly blank: boolean
/** Latest human-authored prompt time in the folded prefix. */
readonly lastPromptAt: number | null
}
/**
* Summary wire values a Session-list row carries. A `sequenced` block carries
* every summary key computed at its `asOfSeq`; a `cached` block carries the