mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-08-29 04:26:38 +00:00
# Conflicts: # docs/subsystems/agent-team.i18n.yaml # docs/subsystems/approval.i18n.yaml # docs/subsystems/client-modules.i18n.yaml # docs/subsystems/client-modules.md # docs/subsystems/client-modules.zh.md # docs/subsystems/code-runtime.i18n.yaml # docs/subsystems/commands.i18n.yaml # docs/subsystems/commands.md # docs/subsystems/commands.zh.md # docs/subsystems/compaction.i18n.yaml # docs/subsystems/compaction.md # docs/subsystems/compaction.zh.md # docs/subsystems/core.i18n.yaml # docs/subsystems/core.md # docs/subsystems/core.zh.md # docs/subsystems/credentials.i18n.yaml # docs/subsystems/credentials.md # docs/subsystems/credentials.zh.md # docs/subsystems/feedback.i18n.yaml # docs/subsystems/filesystem.i18n.yaml # docs/subsystems/goal.i18n.yaml # docs/subsystems/http-server.md # docs/subsystems/http-server.zh.md # docs/subsystems/invariants.i18n.yaml # docs/subsystems/invariants.md # docs/subsystems/invariants.zh.md # docs/subsystems/jobs.i18n.yaml # docs/subsystems/llm-streaming.i18n.yaml # docs/subsystems/llm-streaming.md # docs/subsystems/llm-streaming.zh.md # docs/subsystems/permission-presets.md # docs/subsystems/permission-presets.zh.md # docs/subsystems/persistence.i18n.yaml # docs/subsystems/persistence.md # docs/subsystems/persistence.zh.md # docs/subsystems/plan.i18n.yaml # docs/subsystems/plan.md # docs/subsystems/plan.zh.md # docs/subsystems/sandbox.i18n.yaml # docs/subsystems/sandbox.md # docs/subsystems/sandbox.zh.md # docs/subsystems/schedule.i18n.yaml # docs/subsystems/session-projection.i18n.yaml # docs/subsystems/session-projection.md # docs/subsystems/session-projection.zh.md # docs/subsystems/session-query.i18n.yaml # docs/subsystems/session-reference.i18n.yaml # docs/subsystems/session-reference.md # docs/subsystems/session-reference.zh.md # docs/subsystems/session-telemetry.md # docs/subsystems/session-telemetry.zh.md # docs/subsystems/session-title.i18n.yaml # docs/subsystems/session.i18n.yaml # docs/subsystems/session.md # docs/subsystems/session.zh.md # docs/subsystems/settings.i18n.yaml # docs/subsystems/settings.md # docs/subsystems/settings.zh.md # docs/subsystems/shell.i18n.yaml # docs/subsystems/shell.md # docs/subsystems/shell.zh.md # docs/subsystems/skills.i18n.yaml # docs/subsystems/skills.md # docs/subsystems/skills.zh.md # docs/subsystems/spill.i18n.yaml # docs/subsystems/storage.i18n.yaml # docs/subsystems/subagent.i18n.yaml # docs/subsystems/subagent.md # docs/subsystems/subagent.zh.md # docs/subsystems/subprocess.i18n.yaml # docs/subsystems/system-prompt.i18n.yaml # docs/subsystems/system-prompt.md # docs/subsystems/system-prompt.zh.md # docs/subsystems/tasks.md # docs/subsystems/tasks.zh.md # docs/subsystems/terminal.md # docs/subsystems/terminal.zh.md # docs/subsystems/token-meter.i18n.yaml # docs/subsystems/tools.i18n.yaml # docs/subsystems/tools.md # docs/subsystems/tools.zh.md # docs/subsystems/typert.i18n.yaml # docs/subsystems/typert.md # docs/subsystems/typert.zh.md # docs/subsystems/user-interaction.i18n.yaml # docs/subsystems/user-questions.i18n.yaml # docs/subsystems/user-questions.md # docs/subsystems/user-questions.zh.md # docs/subsystems/web.i18n.yaml # docs/subsystems/workflow.i18n.yaml # docs/subsystems/workflow.md # docs/subsystems/workflow.zh.md # docs/subsystems/workspace.i18n.yaml # docs/subsystems/workspace.md # docs/subsystems/workspace.zh.md # packages/typert/generator/tests/cordis-catalog.spec.ts
175 lines
7.8 KiB
Markdown
175 lines
7.8 KiB
Markdown
# 会话引用
|
|
|
|
[English](session-reference.md) | 中文
|
|
|
|
由 Host 支撑的文件发现,以及结构化的跨会话引用请求与准备后的消息上下文。[文件引用约定](../../packages/context/file-reference)负责仅含路径的补全记录与语法;[会话引用约定](../../packages/context/session-reference)定义规范 URI、当前表层投影、标签安全的 JSON 与字节保留、稳定错误和不可信的模型提示词。宿主适配器使用这些类型,而不会把各自 UI 的提及语法传入 agent(智能体)核心。
|
|
|
|
来源:[`packages/context/file-reference/src/types.ts`](../../packages/context/file-reference/src/types.ts) · [`packages/context/session-reference/src/types.ts`](../../packages/context/session-reference/src/types.ts)
|
|
|
|
## 文件候选项
|
|
|
|
`FileReferenceCandidate` 是仅含路径的发现结果。被寻址的 agent 提供工作目录范围;提供方负责排序和命名空间访问,但不会读取文件内容。
|
|
|
|
```ts type-equiv
|
|
/** One path-only completion candidate inside the target session cwd. */
|
|
interface FileReferenceCandidate {
|
|
/** User-facing path accepted by normal prompts and filesystem tools. */
|
|
path: string
|
|
/** Directories keep completion open; files finish the mention. */
|
|
kind: 'file' | 'directory'
|
|
}
|
|
```
|
|
|
|
## 输入与候选项
|
|
|
|
`SessionReferenceInput` 是与宿主无关的选择。id 具有权威性;label 是随快照携带的显示元数据。
|
|
|
|
```ts type-equiv
|
|
/** One source session selected by a host. */
|
|
interface SessionReferenceInput {
|
|
/** Opaque source session identity. */
|
|
sessionId: SessionId
|
|
/** Optional user-facing mention label. */
|
|
label?: string
|
|
}
|
|
```
|
|
|
|
`SessionReferenceCandidate` 是面向宿主的发现输出。存在最新会话标题时,它的 label 使用该标题;筛选仍只搜索 session id 和 cwd,绝不搜索 transcript(文本记录)。
|
|
|
|
```ts type-equiv
|
|
/** One host-facing candidate from exact session metadata. */
|
|
interface SessionReferenceCandidate {
|
|
/** Opaque source session identity. */
|
|
sessionId: SessionId
|
|
/** Latest log-backed title, falling back to the opaque session id. */
|
|
label: string
|
|
/** Source session working directory, when recorded. */
|
|
cwd?: string
|
|
/** Source session creation time in Unix epoch milliseconds. */
|
|
createdAt: number
|
|
}
|
|
```
|
|
|
|
`sessionReferenceResolver/candidates` Remote 方法向浏览器消费方提供同一发现能力,并为每个候选附上规范提示词 mention。
|
|
|
|
```ts type-equiv
|
|
/** One discovery candidate carrying its canonical prompt mention. */
|
|
interface SessionReferenceMentionCandidate extends SessionReferenceCandidate {
|
|
/** Canonical `@[label](dsh-session:…)` mention serialized into the prompt draft. */
|
|
mention: string
|
|
}
|
|
```
|
|
|
|
## 准备后的消息
|
|
|
|
准备过程保留可读的当前消息内容,并最多返回一个聚合上下文。
|
|
|
|
```ts type-equiv
|
|
/** Direct message content and optional referenced-session context. */
|
|
interface PreparedReferencedMessage {
|
|
/** Readable message content after host mention tokens are removed. */
|
|
content: ContentBlock[]
|
|
/** Aggregated untrusted snapshot, absent when the message has no references. */
|
|
additionalContext?: UserMessage
|
|
}
|
|
```
|
|
|
|
## 错误
|
|
|
|
`SessionReferenceError.code` 区分无效配置或输入、自引用、数量限制、源读取失败、预算失败和取消。宿主协议会把这些 code 映射到各自的错误封装,无需检查提示词字节。
|
|
|
|
```ts type-equiv
|
|
/** Stable failure codes exposed to host adapters. */
|
|
type SessionReferenceErrorCode =
|
|
| 'SESSION_REFERENCE_INVALID_CONFIG'
|
|
| 'SESSION_REFERENCE_INVALID_REFERENCE'
|
|
| 'SESSION_REFERENCE_SELF_REFERENCE'
|
|
| 'SESSION_REFERENCE_TOO_MANY'
|
|
| 'SESSION_REFERENCE_READ_FAILED'
|
|
| 'SESSION_REFERENCE_BUDGET_EXCEEDED'
|
|
| 'SESSION_REFERENCE_CANCELLED'
|
|
```
|
|
|
|
<!-- BEGIN GENERATED cordis-surface (gen-cordis-catalog.ts) — do not edit between markers -->
|
|
|
|
<a id="cordis-surface"></a>
|
|
|
|
## Cordis API
|
|
|
|
Generated from source by `scripts/gen-cordis-catalog.ts` (verified fresh by `pnpm run verify-cordis-catalog` in doc-sync; regenerate with `pnpm run gen-cordis-catalog`) — the language sides differ only in locale-specific paired document paths. Signature blocks use a `ts cordis-catalog` fence and keep the original source JSDoc; dispatch modes are defined in the [primer](../cordis-primer.zh.md#dispatch-modes), and the framework-inherited `ctx` API lives in [cordis-api/inherited.md](../cordis-api/inherited.md).
|
|
|
|
<a id="ctxfilereferences--filereferenceservice-abstract-seam"></a>
|
|
|
|
### `ctx.fileReferences` — `FileReferenceService` (abstract seam)
|
|
|
|
Host capability for cancellable file-reference discovery.
|
|
|
|
```ts cordis-catalog
|
|
/**
|
|
* List file and directory candidates for one agent's working directory.
|
|
* @param agent - target agent whose session cwd bounds discovery.
|
|
* @param query - path text following `@` or `@"`.
|
|
* @param signal - caller cancellation.
|
|
* @returns deterministic path-only candidates.
|
|
*/
|
|
abstract list( agent: Agent, query: string, signal: AbortSignal, ): Promise<FileReferenceCandidate[]>
|
|
|
|
/**
|
|
* Remote face of {@link list}; the decorator cannot mark the abstract
|
|
* member, so this concrete adapter carries the identical contract.
|
|
* @param agent - target agent whose session cwd bounds discovery.
|
|
* @param query - path text following `@` or `@"`.
|
|
* @param signal - caller cancellation.
|
|
* @returns deterministic path-only candidates.
|
|
*/
|
|
@Remote('list') remoteExportList( agent: Agent, query: string, signal: AbortSignal, ): Promise<FileReferenceCandidate[]>
|
|
```
|
|
|
|
Types: [Agent](core.zh.md)
|
|
|
|
Source: [`packages/context/file-reference/src/index.ts`](../../packages/context/file-reference/src/index.ts)
|
|
|
|
<a id="ctxsessionreferenceresolver--sessionreferenceresolver"></a>
|
|
|
|
### `ctx.sessionReferenceResolver` — `SessionReferenceResolver`
|
|
|
|
Exact-read consumer that prepares immutable cross-session message context.
|
|
|
|
```ts cordis-catalog
|
|
/**
|
|
* List reference candidates, ranked by working-directory affinity.
|
|
* @param agent - target agent; self is excluded and its cwd drives ranking.
|
|
* @param query - optional case-insensitive session-id/cwd/title substring.
|
|
* @param limit - optional positive result cap.
|
|
* @param signal - optional cancellation boundary for host autocomplete teardown.
|
|
* @returns candidates labeled by latest title or, when absent, session id.
|
|
*/
|
|
async listCandidates( agent: Agent, query: string = '', limit: number = this.config.candidateLimit, signal?: AbortSignal, ): Promise<SessionReferenceCandidate[]>
|
|
|
|
/**
|
|
* Remote face of {@link listCandidates}: the configured candidate limit
|
|
* applies, and every candidate carries the canonical mention a host inserts
|
|
* into the prompt draft.
|
|
* @param agent - target agent; self is excluded and its cwd drives ranking.
|
|
* @param query - optional case-insensitive session-id/cwd/title substring.
|
|
* @param signal - caller cancellation.
|
|
* @returns mention-carrying candidates in rank order.
|
|
*/
|
|
@Remote('candidates') async remoteExportCandidates( agent: Agent, query: string, signal: AbortSignal, ): Promise<SessionReferenceMentionCandidate[]>
|
|
|
|
/**
|
|
* Snapshot all references for one accepted direct message and return one aggregated durable context.
|
|
* @param agent - target agent; references to it are rejected.
|
|
* @param content - already host-normalized readable message content.
|
|
* @param references - structured source sessions in mention order.
|
|
* @param signal - optional cancellation boundary for the active turn.
|
|
* @returns detached content and optional referenced-session context.
|
|
*/
|
|
async prepare( agent: Agent, content: ContentBlock[], references: SessionReferenceInput[], signal?: AbortSignal, ): Promise<PreparedReferencedMessage>
|
|
```
|
|
|
|
Types: [Agent](core.zh.md) · [ContentBlock](llm-streaming.zh.md)
|
|
|
|
Source: [`packages/context/session-reference/src/index.ts`](../../packages/context/session-reference/src/index.ts)
|
|
<!-- END GENERATED cordis-surface -->
|