Files
deepseek-harness/packages/api/session-controller/src/skill-catalog.ts
T
LegGasai b6aa7b437c 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
2026-11-03 18:49:34 +08:00

109 lines
4.5 KiB
TypeScript

/** Session-addressed, cold-readable skill catalog Remote. */
import type { Context } from '@deepseek-ai/cordis'
import type {} from '@deepseek-ai/dsh-agent-preset-registry/types'
import { SessionQueryError } from '@deepseek-ai/dsh-session-query'
import { isUserInvocable } from '@deepseek-ai/dsh-skill'
import type {} from '@deepseek-ai/dsh-working-directory'
import type { ScopeKey } from '@deepseek-ai/dsh-scope'
import { Remote, RemoteError, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol'
import type { SkillListRequest, SkillListValue } from './types.ts'
declare module '@deepseek-ai/cordis' {
interface Context {
/** Host owner of the Session-addressed `skills` Remote namespace. */
sessionSkillCatalog: SessionSkillCatalog
}
}
/** Host service backing `ctx.remote.skills` without activating a cold Agent. */
export class SessionSkillCatalog extends TypertRemoteService {
static inject = ['agents', 'sessionQuery', 'typert', 'workingDirectory']
/** @param ctx - Host context carrying Session reads and optional skill/preset services. */
constructor(ctx: Context) {
super(ctx, 'sessionSkillCatalog', { namespace: 'skills' })
}
/**
* List the user-invocable skills visible to one Session composition.
* @param request - Session identity whose cwd and preset select the catalog view.
* @param signal - caller lifetime carried by the Remote transport; admitted catalog reads retain their existing completion semantics.
* @returns user-invocable skill metadata without loading skill bodies.
* @throws RemoteError when the Session cannot be inspected or no registry can serve it.
*/
@Remote
async list(request: SkillListRequest, signal: AbortSignal): Promise<SkillListValue> {
const { sessionId } = request
let cwd: string
let agentPreset: string | undefined
try {
using observation = await this.ctx.sessionQuery.observeSession(sessionId)
if (observation.projections === undefined) {
throw new Error('skill catalog requires a projected Session observation')
}
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) cwd = await this.ctx.workingDirectory.ensure(live, signal)
} catch (error: unknown) {
if (error instanceof SessionQueryError
&& error.code === 'SESSION_QUERY_SESSION_NOT_FOUND') {
throw new RemoteError('session/not-found', `session "${sessionId}" not found`, { sessionId })
}
throw new RemoteError(
'gateway/internal',
`session "${sessionId}" could not be inspected: ${String(error)}`,
{},
)
}
const live = this.ctx.agents.get(sessionId)
const presets = this.ctx.get('agentPresets')
const scoped = live === undefined ? undefined : presets?.serviceFor(live, 'skills')
const skillRegistry = scoped ?? this.ctx.get('skills')
if (skillRegistry === undefined) {
throw new RemoteError(
'gateway/internal',
'skill registry is absent: neither this session\'s agent preset nor the host composition mounts @deepseek-ai/dsh-skill',
{},
)
}
await using lease = live === undefined ? await this.scopeFor(agentPreset) : undefined
const scope = live ?? lease?.key
try {
const skills = (await skillRegistry.list({ cwd, scope })).filter(isUserInvocable)
return {
skills: skills.map(skill => ({
name: skill.name,
...skill.path === undefined ? {} : { path: skill.path },
description: skill.description,
...skill.whenToUse === undefined ? {} : { whenToUse: skill.whenToUse },
modelInvocable: skill.invocation.modelInvocable,
})),
}
} catch (error: unknown) {
throw new RemoteError('gateway/internal', `skill listing failed: ${String(error)}`, {})
}
}
/** Resolve a live or standing preset scope without creating an Agent. */
private async scopeFor(
agentPreset: string | undefined,
): Promise<({ key: ScopeKey } & AsyncDisposable) | undefined> {
const presets = this.ctx.get('agentPresets')
if (presets === undefined) return undefined
try {
return await presets.acquireScope(agentPreset)
} catch {
// An unknown or unusable recorded preset falls back to the global registry.
return undefined
}
}
}
export default SessionSkillCatalog