Merge remote-tracking branch 'origin/master' into feat/session-panel
# Conflicts: # docs/config-catalog.md # docs/config-catalog.zh.md # docs/event-producer-consumer.md # docs/event-producer-consumer.zh.md # docs/module-graph.md # docs/module-graph.zh.md # packages/client/README.i18n.yaml # packages/preset/agent-preset/skills/dsh-doc/references/packages.md # pnpm-lock.yaml
This commit is contained in:
commit
3c5d888751
2193 files changed
+42659
-27574
No files matched your search
@@ -3,11 +3,11 @@
|
||||
# After editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write docs/subsystems/computer-use.md
|
||||
/computer-use:
|
||||
en: e02a2e4cc9970cba
|
||||
zh: 29aac6c0530a582f
|
||||
en: 45a0f430190937de
|
||||
zh: 7b48603bebfcd1c6
|
||||
/computer-use/choose-a-provider:
|
||||
en: fa2e0d7b41c0450b
|
||||
zh: af9a799711f901e6
|
||||
en: 4a72c1987678a47b
|
||||
zh: b039d15b4e782cc4
|
||||
/computer-use/lifetime-and-desktop-sharing:
|
||||
en: 08ff155ad3d75953
|
||||
zh: 48821856b6dff051
|
||||
|
||||
@@ -4,9 +4,9 @@ English | [中文](computer-use.zh.md)
|
||||
|
||||
Computer use lets a model observe and operate the local desktop through a configured provider. The shared DSH capability is called **computer use**; **Cua Driver** names the upstream implementation.
|
||||
|
||||
[Computer Use](../../packages/experimental/cua-bundle/README.md) provides an optional experimental switch for macOS CUA permission setup.
|
||||
[Computer Use](../../packages/experimental/cua-bundle/README.md) is an optional experimental bundle for macOS and Windows.
|
||||
|
||||
The [`macOS CUA provider`](../../packages/experimental/cua-macos/README.md) uses the [shared CUA objects and executor](../../packages/experimental/cua/README.md), which enforce application consent through User Questions and profile configuration.
|
||||
Both native providers use the [shared CUA library](../../packages/experimental/cua/README.md#use-this-package) to check configured and saved application grants. When a decision is needed, the library asks the user through User Questions.
|
||||
|
||||
The CUA provider owns `ctx.cuaAccess` for system-permission status, explicit system requests, and application revocation. Its [permission page](../../packages/experimental/cua/README.md) projects these controls; app/window operations enforce the provider's consent policy before dispatch.
|
||||
|
||||
@@ -14,21 +14,23 @@ The CUA provider owns `ctx.cuaAccess` for system-permission status, explicit sys
|
||||
|---|---|
|
||||
| `CuaApplicationId`, `CuaApplicationGrant` | A platform-provided application identity and its displayed saved decision. |
|
||||
| `CuaSystemPermission` | Accessibility or Screen Recording, selected by the human. |
|
||||
| `CuaPermissionProcess`, `CuaSystemPermissionState` | Native access observations tagged `darwin` or `win32`, with helper process identity. macOS includes permission checks, parent identity and responsible-application metadata when available (falling back to the helper’s own bundle); Windows includes desktop lock, capture availability and elevation status. |
|
||||
| `CuaPermissionProcess`, `CuaSystemPermissionState` | Native access observations tagged `darwin` or `windows`, with the helper’s name and path when available. macOS includes permission checks, numeric helper and parent PIDs, and responsible-application metadata when available (falling back to the helper’s own bundle); Windows includes desktop lock, capture availability and elevation status, and omits the helper PID. |
|
||||
| `CuaApplicationState` | Saved grants, refused applications, and whether persistence is available. Session-only grants remain internal to the provider. System observations and application icons are queried separately so the page can display each result as it arrives. |
|
||||
|
||||
The [shared object API](../../packages/experimental/cua/README.md) uses `connectCua` to select an application, then `app.getWindows()` and `app.getWindow(windowId)` to select a window for screenshots and pointer input. Accessibility operations use element IDs from the latest tree for that application handle. Providers declare keyboard scopes and application-level accessibility in `getCapabilities()`.
|
||||
|
||||
## Choose a provider
|
||||
|
||||
Mount [`dsh-computer-use`](../../packages/computer-use/computer-use/README.md) and one provider in the same composition. Both Cua Driver providers are experimental public npm packages and require explicit activation.
|
||||
Mount [`dsh-computer-use`](../../packages/computer-use/computer-use/README.md) and one provider in the same composition. The Computer Use bundle selects the native provider for the host platform. Custom compositions can also mount a provider directly.
|
||||
|
||||
| Provider | Runtime |
|
||||
|---|---|
|
||||
| [macOS CUA](../../packages/experimental/cua-macos/README.md) | Swift helper using macOS Accessibility |
|
||||
| [Windows CUA](../../packages/experimental/cua-windows/README.md) | .NET helper using Windows UI Automation |
|
||||
| [Cua Driver MCP](../../packages/experimental/computer-use-cua-driver-mcp/README.md) | An already installed `cua-driver` executable connected through MCP |
|
||||
| [Cua Driver native](../../packages/experimental/computer-use-cua-driver-native/README.md) | The platform-native runtime installed with the npm dependency |
|
||||
|
||||
Each provider supplies its upstream tool catalog. The shared service registers only a name and rejects any second provider, including another instance with the same name. It has no common desktop-operation methods or model-controlled selector.
|
||||
The two Cua Driver providers are public experimental npm packages. Mount one explicitly to expose its upstream tool catalog. The shared service registers only a name and rejects any second provider, including another instance with the same name. It has no common desktop-operation methods or model-controlled selector.
|
||||
|
||||
## Lifetime and desktop sharing
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
计算机操作让模型通过配置的提供方观察并操作本地桌面。DSH 的共享能力称为 **computer use(计算机操作)**;**Cua Driver** 是上游实现的名称。
|
||||
|
||||
[Computer Use](../../packages/experimental/cua-bundle/README.zh.md) 提供 macOS CUA 及权限设置 的可选实验性开关。
|
||||
[Computer Use](../../packages/experimental/cua-bundle/README.zh.md) 是适用于 macOS 和 Windows 的可选实验性插件组合。
|
||||
|
||||
[macOS CUA 提供方](../../packages/experimental/cua-macos/README.zh.md)使用[共享 CUA 对象与执行器](../../packages/experimental/cua/README.zh.md),通过 User Questions 和配置档设置执行应用授权。
|
||||
两个原生提供方都通过[共享 CUA 库](../../packages/experimental/cua/README.zh.md#use-this-package)检查配置中指定或已保存的应用授权。需要用户决定时,共享库通过 User Questions 询问用户。
|
||||
|
||||
CUA provider 通过 `ctx.cuaAccess` 提供系统权限状态、用户主动申请和应用授权撤销。[权限页面](../../packages/experimental/cua/README.zh.md)投影这些控件;app/window 操作在分派前执行 provider 的授权检查。
|
||||
|
||||
@@ -14,21 +14,23 @@ CUA provider 通过 `ctx.cuaAccess` 提供系统权限状态、用户主动申
|
||||
|---|---|
|
||||
| `CuaApplicationId`、`CuaApplicationGrant` | 平台提供的应用身份,以及显示给用户的已保存决定。 |
|
||||
| `CuaSystemPermission` | 用户选择申请的辅助功能或屏幕录制权限。 |
|
||||
| `CuaPermissionProcess`、`CuaSystemPermissionState` | 以 `darwin` 或 `win32` 标记的原生访问状态和 helper 进程身份。macOS 包含权限检查、父进程身份和责任应用信息(系统无法识别时使用 helper 自身的应用包);Windows 包含桌面锁定、截图可用性和提权状态。 |
|
||||
| `CuaPermissionProcess`、`CuaSystemPermissionState` | 以 `darwin` 或 `windows` 标记的原生访问状态,包含可获取的 helper 名称和路径。macOS 包含权限检查、helper 和父进程的数字 PID,以及责任应用信息(系统无法识别时使用 helper 自身的应用包);Windows 包含桌面锁定、截图可用性和提权状态,省略 helper 的 PID。 |
|
||||
| `CuaApplicationState` | 持久授权、拒绝记录,以及能否持久保存。会话授权只保留在 provider 内部。系统权限和应用图标分别查询,页面在各项结果返回后分别显示。 |
|
||||
|
||||
调用[共享对象 API](../../packages/experimental/cua/README.zh.md) 时,通过 `connectCua` 连接,选择应用后用 `app.getWindows()` 和 `app.getWindow(windowId)` 选择要截图或进行鼠标操作的窗口。辅助功能操作使用该应用句柄最近一次读取的树中的元素 ID。提供方通过 `getCapabilities()` 声明键盘输入支持的范围,以及是否支持应用级辅助功能。
|
||||
|
||||
## 选择提供方
|
||||
|
||||
在同一组合中挂载 [`dsh-computer-use`](../../packages/computer-use/computer-use/README.zh.md) 和一个提供方。两个 Cua Driver 提供方都是公开发布到 npm 的实验性包,均需显式启用。
|
||||
在同一组合中挂载 [`dsh-computer-use`](../../packages/computer-use/computer-use/README.zh.md) 和一个提供方。Computer Use 组合会按宿主平台选择原生提供方。自定义组合也可以直接挂载提供方。
|
||||
|
||||
| 提供方 | 运行时 |
|
||||
|---|---|
|
||||
| [macOS CUA](../../packages/experimental/cua-macos/README.zh.md) | 使用 macOS 辅助功能的 Swift helper |
|
||||
| [Windows CUA](../../packages/experimental/cua-windows/README.zh.md) | 使用 Windows UI Automation 的 .NET helper |
|
||||
| [Cua Driver MCP](../../packages/experimental/computer-use-cua-driver-mcp/README.zh.md) | 通过 MCP 连接已安装的 `cua-driver` 可执行文件 |
|
||||
| [Cua Driver 原生](../../packages/experimental/computer-use-cua-driver-native/README.zh.md) | 随 npm 依赖安装的平台原生运行时 |
|
||||
|
||||
各提供方提供上游工具目录。共享服务只注册名称,并拒绝任何第二个提供方,包括使用相同名称的另一个实例。服务不包含通用桌面操作方法或模型控制的选择器。
|
||||
两个 Cua Driver 提供方都是公开发布到 npm 的实验性包。显式挂载其中一个即可使用它的上游工具目录。共享服务只注册名称,并拒绝任何第二个提供方,包括使用相同名称的另一个实例。服务不包含通用桌面操作方法或模型控制的选择器。
|
||||
|
||||
## 生命周期和桌面共享
|
||||
|
||||
|
||||
@@ -24,5 +24,8 @@
|
||||
en: 13dfd36f2166bba0
|
||||
zh: a369434f52f04d57
|
||||
/forges/panel:
|
||||
en: 0e0348e9a38215ed
|
||||
zh: affcc0231e15d682
|
||||
en: 7dcefe2825490257
|
||||
zh: 38cec4d1ae3b0d6e
|
||||
/forges/extension-api:
|
||||
en: f35345e482e84f4f
|
||||
zh: 2ecb7d9498decb31
|
||||
+197
-3
@@ -101,6 +101,12 @@ interface ForgeProvider {
|
||||
* with `a/` and `b/` path prefixes. Both are full object names; `head` descends from `base`.
|
||||
*/
|
||||
compare?(ref: ChangeRequestRef, base: string, head: string, signal: AbortSignal): Promise<string | ForgeFailure>
|
||||
/**
|
||||
* Find the merge base of commits `base` and `head` in the change request's repository, as a full object name: the
|
||||
* commit whose files the old side of a change request's diff shows. Omission declares that the provider cannot name
|
||||
* it, so readers of the old side get `unsupported`.
|
||||
*/
|
||||
mergeBase?(ref: ChangeRequestRef, base: string, head: string, signal: AbortSignal): Promise<string | ForgeFailure>
|
||||
/**
|
||||
* Read the signed-in user's viewed marks on the change request's files at head commit `headSha`. The marks are
|
||||
* returned only when the read names `headSha` as the head; once the head is another commit, the read resolves to a
|
||||
@@ -928,6 +934,11 @@ interface ForgePanelWorktree {
|
||||
interface ForgePanelChangeRequest extends SessionChangeRequest {
|
||||
/** Latest snapshot a poll returned, kept while later polls fail, or null before the first successful poll. */
|
||||
readonly snapshot: ChangeRequestSnapshot | null
|
||||
/**
|
||||
* Number of review changes `forge/review-changed` announced for the change request since the panel host started; it
|
||||
* grows when any plugin's write is accepted, so a reader shows threads and viewed marks read after it.
|
||||
*/
|
||||
readonly reviewRevision: number
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1187,6 +1198,120 @@ interface ForgeLocalChanges {
|
||||
}
|
||||
```
|
||||
|
||||
<a id="extension-api"></a>
|
||||
|
||||
## Extension API
|
||||
|
||||
Other plugins extend change request review through the services above and five more extension points; each registration returns its disposer and ends with the plugin that made it. The surface is experimental and pre-stable like the rest of this capability. Adding an optional field, method, slot, event, error code, or defaulted Config key is compatible; removing or renaming a type, method, slot, owner prop, event, Config key, or the `dsh-resource://forge-changes/` address, or narrowing what one means, needs an [upgrade guide](../../.agents/skills/dsh-create-upgrade-guide/SKILL.md). None of these extension points sends anything to a model: a plugin that shows forge data, lens results, or annotations to a model does so through its own tool results or `agent.inject()`, which the Session log records.
|
||||
|
||||
| Extension point | Service Definition | Service Provider | Consumer |
|
||||
|---|---|---|---|
|
||||
| Review data | `ctx.forge` and the `forge/review-changed` event | The forge providers | The panel host and other Host plugins |
|
||||
| Filter lenses | `ctx.forgePanel.registerLens` | Host plugins | The changes view through `changesLens` |
|
||||
| Changes view face | `ctx.forgeChanges` | The forge panel's Client plugin | Client plugins that open views, name lenses, and add annotations |
|
||||
| Slots | `forge.changes.toolbar`, `forge.changes.file.menu`, `forge.diff.line.annotation`, `forge.diff.comment.actions`, `forge.change-request.card.actions` | Client plugins | The changes view and the change request card |
|
||||
| Session data | The `forgeChangeRequests` and `forgeWorktree` projections | forge-session and the forge panel | Client plugins through `useProjection`, Host plugins through `ctx.forgeSession.changeRequests` or `ctx.sessionProjections.snapshot` |
|
||||
|
||||
`ctx.forge` announces `forge/review-changed` after a review write, a submitted review, or a viewed mark the host accepted, whichever plugin made it; an outcome that is unknown, refused, stale, or unsupported is not announced. The panel host then drops the threads it keeps for the change request and raises `reviewRevision` on its entries, so an open changes view reads the threads and the viewed marks again without a refresh.
|
||||
|
||||
```ts type-equiv
|
||||
/**
|
||||
* One review change the host accepted, which `forge/review-changed` announces: a write to the threads or the pending
|
||||
* review, a submitted review, or a viewed mark. Each names the head commit the change was made against.
|
||||
*/
|
||||
type ForgeReviewChange =
|
||||
| { readonly kind: 'write'; readonly write: ForgeReviewWrite['kind']; readonly headSha: string }
|
||||
| { readonly kind: 'submit'; readonly headSha: string }
|
||||
| { readonly kind: 'viewed'; readonly path: string; readonly viewed: boolean; readonly headSha: string }
|
||||
```
|
||||
|
||||
A Host plugin registers a filter lens with `ctx.forgePanel.registerLens(lens)`, and a Client plugin names it with `ctx.forgeChanges.describeLens({ id, title })`; a lens without a description shows its identity. A lens filters the shown files and does not place them in layers: the changes view shows the files that both the chosen layer and the chosen lens keep, the test switch still hides test files, and a lens cannot move a file to another layer. Hunks that meet none of a kept file's `ranges` fold into one row the reader can expand. The view asks for the chosen lens only, through the streaming Remote `changesLens`, which reads the same files as the view, refuses other files with `forgePanel/lens-stale`, and runs `classify` within `lensTimeoutMs` and `maxLensReadBytes`; results are kept up to `maxCachedLensBytes`. `text` reads a local old side at the fork point, HEAD, the index, or the parent of the first chosen commit, and a change request's old side at the chosen commits' parent or at the merge base its provider names through the optional `mergeBase`.
|
||||
|
||||
```ts type-equiv
|
||||
/** A filter over the files of a changes view, which a plugin registers with `ctx.forgePanel.registerLens()`. */
|
||||
interface ForgeLens {
|
||||
/** Identity the plugin chooses; one registration holds an id at a time. */
|
||||
readonly id: ForgeLensId
|
||||
/** Changes whenever `classify` may answer differently for the same input, which drops results kept under another version. */
|
||||
readonly version: string
|
||||
/**
|
||||
* Decide which files the lens keeps and which lines it is about. The signal aborts when the reader stops waiting, the
|
||||
* registration ends, or `lensTimeoutMs` passes; a rejection fails the request without a partial result.
|
||||
*/
|
||||
classify(input: ForgeLensInput, signal: AbortSignal): Promise<ForgeLensResult>
|
||||
}
|
||||
```
|
||||
|
||||
```ts type-equiv
|
||||
/** What one `classify` call receives. */
|
||||
interface ForgeLensInput {
|
||||
/** What the view shows. */
|
||||
readonly source: ForgeLensSource
|
||||
/** Every file of the diff in display order, with the layer the panel gave it. */
|
||||
readonly files: readonly ForgeLensFile[]
|
||||
/**
|
||||
* Read one side of a file of `files`, by its `path`: the old side reads `previousPath` for a renamed file. Resolves to
|
||||
* null when the side does not exist, as the old side of an added file, or holds binary content. Rejects for a path not
|
||||
* in `files`, once the reads of one call exceed the panel's `maxLensReadBytes`, for an old side the provider cannot
|
||||
* locate, and when the read fails.
|
||||
*/
|
||||
text(side: 'old' | 'new', path: string, signal: AbortSignal): Promise<string | null>
|
||||
/** Report how many of `total` units the lens finished; the changes view shows it while the lens runs. */
|
||||
progress(done: number, total: number): void
|
||||
}
|
||||
```
|
||||
|
||||
```ts type-equiv
|
||||
/** The files a lens keeps, by path; a file the result does not name is filtered out. */
|
||||
interface ForgeLensResult {
|
||||
readonly files: Readonly<Record<string, ForgeLensKeep>>
|
||||
}
|
||||
```
|
||||
|
||||
```ts type-equiv
|
||||
/** What a lens keeps of one file. */
|
||||
interface ForgeLensKeep {
|
||||
/**
|
||||
* Lines the lens is about on each side; hunks that touch none of them fold into one row the reader can expand.
|
||||
* Omitted: every hunk of the file shows.
|
||||
*/
|
||||
readonly ranges?: { readonly old: readonly ForgeLineRange[]; readonly new: readonly ForgeLineRange[] }
|
||||
}
|
||||
```
|
||||
|
||||
`ctx.forgeChanges` also mints and reads changes addresses, names the tab `kinds`, and opens a view with `open(target, { path, lens })` in the Session the sidebar shows. `registerAnnotations(source)` adds line annotations: the source observes each view's annotations by path, and its `forge.diff.line.annotation` entry, keyed by the source's identity, draws each one inside a frame the view draws. Annotations stack on the row of their last line after the comment form, the browser drafts, and the host threads, in the column of their side; whole-file annotations come first, and those written on another `digest` follow the file in their own section. A file shows at most `maxAnnotationsPerFile`, and a file that draws its lines draws no annotation before its section comes within reach of the scrollport. The owner props of every slot live in [`src/client/slots.ts`](../../packages/experimental/client-ui-forge/src/client/slots.ts).
|
||||
|
||||
```ts type-equiv
|
||||
/** Where one line annotation sits in a file of a changes view. */
|
||||
interface ForgeLineAnnotation {
|
||||
/** Identity within its source, stable across updates; it keys the drawn entry. */
|
||||
readonly key: string
|
||||
/** Inclusive 1-based lines on the old (`L`) or new (`R`) side, or `file` for the whole file. */
|
||||
readonly place: { readonly side: 'L' | 'R'; readonly startLine: number; readonly endLine: number } | 'file'
|
||||
/** Digest of the file change it was written on; a file whose `digest` differs shows it in its outdated section. */
|
||||
readonly digest?: string
|
||||
/** Changes whenever the entry should draw again; equal keys and versions keep the drawn entry's props. */
|
||||
readonly version: string | number
|
||||
}
|
||||
```
|
||||
|
||||
```ts type-equiv
|
||||
/** A Client plugin's line annotations, drawn through its `forge.diff.line.annotation` entry. */
|
||||
interface ForgeAnnotationSource {
|
||||
/** Unique source identity, also the key of its `forge.diff.line.annotation` entry. */
|
||||
readonly id: string
|
||||
/** Position among sources in one stack, lower first; equal positions keep registration order. Default 0. */
|
||||
readonly order?: number
|
||||
/**
|
||||
* Observe the annotations of one view, by path. The changes view calls it once per view and source registration;
|
||||
* the source republishes through the same observable whenever the annotations change.
|
||||
* @param target - the view's Session and source.
|
||||
* @returns annotations by repository-relative path.
|
||||
*/
|
||||
observe(target: ChangesTarget): HostObservable<ReadonlyMap<string, readonly ForgeLineAnnotation[]>>
|
||||
}
|
||||
```
|
||||
|
||||
<!-- BEGIN GENERATED cordis-surface (gen-cordis-catalog.ts) — do not edit between markers -->
|
||||
|
||||
<a id="cordis-surface"></a>
|
||||
@@ -1355,7 +1480,7 @@ async readReview(ref: ChangeRequestRef, headSha: string, signal: AbortSignal): P
|
||||
/**
|
||||
* Write to the review threads or the pending review of a change request while its head is still `write.headSha`, then
|
||||
* poll the change request at once when it is watched, unless the provider cannot write reviews. A `stale` result polls
|
||||
* it as a stale read does.
|
||||
* it as a stale read does; a write the host took is announced with `forge/review-changed`.
|
||||
* @param ref - change request served by a registered provider.
|
||||
* @param write - the write and the head commit the user saw.
|
||||
* @param signal - cancellation of the write.
|
||||
@@ -1379,7 +1504,8 @@ async viewedFiles(ref: ChangeRequestRef, headSha: string, signal: AbortSignal):
|
||||
|
||||
/**
|
||||
* Set or clear the signed-in user's viewed mark on one file of a change request while its head is still
|
||||
* `request.headSha`. A `stale` failure polls a watched change request again as {@link ForgeService.diff} does.
|
||||
* `request.headSha`. A `stale` failure polls a watched change request again as {@link ForgeService.diff} does; a saved
|
||||
* mark is announced with `forge/review-changed`.
|
||||
* @param ref - change request served by a registered provider.
|
||||
* @param request - the file, its mark, and the head commit the user saw.
|
||||
* @param signal - cancellation of the request.
|
||||
@@ -1410,7 +1536,21 @@ async commits(ref: ChangeRequestRef, signal: AbortSignal): Promise<ForgeCommitLi
|
||||
async compare(ref: ChangeRequestRef, base: string, head: string, signal: AbortSignal): Promise<string | ForgeFailure>
|
||||
|
||||
/**
|
||||
* Publish one comment or a completed review, then refresh the watched status.
|
||||
* Find the merge base of two commits of a change request's repository: the commit whose files the old side of the
|
||||
* change request's diff shows when `base` is the snapshot's `baseSha` and `head` its `headSha`.
|
||||
* @param ref - change request served by a registered provider.
|
||||
* @param base - full object name of the base commit.
|
||||
* @param head - full object name of the head commit.
|
||||
* @param signal - cancellation of the read.
|
||||
* @returns the merge base's full object name, or why the host did not provide it; `unsupported` when the provider
|
||||
* cannot name merge bases.
|
||||
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
|
||||
*/
|
||||
async mergeBase(ref: ChangeRequestRef, base: string, head: string, signal: AbortSignal): Promise<string | ForgeFailure>
|
||||
|
||||
/**
|
||||
* Publish one comment or a completed review, then refresh the watched status; a publication the host took is announced
|
||||
* with `forge/review-changed`.
|
||||
* @param ref - change request served by a registered provider.
|
||||
* @param request - explicitly selected commit, comments, and review decision.
|
||||
* @param signal - request cancellation.
|
||||
@@ -1658,6 +1798,40 @@ Serves the forge panel. Following a Session inspects the checkout of its current
|
||||
*/
|
||||
@Remote async changeRequestText(session: Session, url: string, commit: string, path: string, signal: AbortSignal): Promise<string>
|
||||
|
||||
/**
|
||||
* Register a filter lens as an effect on the calling fiber. The changes views list it while it is registered; ending
|
||||
* the registration aborts its running classifications and waits for them.
|
||||
* @param lens - the lens.
|
||||
* @returns the disposer that unregisters the lens and waits for its classifications to stop.
|
||||
* @throws when another registration holds `lens.id`.
|
||||
*/
|
||||
registerLens(lens: ForgeLens): () => Promise<void>
|
||||
|
||||
/**
|
||||
* Stream the facts every changes view reads about the panel's extensions: the current facts first, then the facts
|
||||
* after each lens registration or withdrawal. The stream ends when `signal` aborts or the Remote stops.
|
||||
* @param signal - ends the stream.
|
||||
* @returns the registered lenses and the annotation limit, in publication order.
|
||||
*/
|
||||
@Remote({ mode: 'stream' }) async *extensions(signal: AbortSignal): AsyncIterable<ForgeExtensionState>
|
||||
|
||||
/**
|
||||
* Classify the files a changes view of a Session shows with one registered lens: progress frames while the lens
|
||||
* runs, then the files it keeps. Results for the same files, lens, and lens version are reused from memory until
|
||||
* `maxCachedLensBytes` evicts them. Local changes are read with the Session's permissions; a change request's files
|
||||
* are those `changeRequestDiff` reads.
|
||||
* @param session - Session whose checkout or binding the view shows.
|
||||
* @param request - the view's source, the version of the files it shows, and the lens.
|
||||
* @param signal - ends the classification.
|
||||
* @returns progress frames, then one result frame.
|
||||
* @throws `forgePanel/lens-missing` while no lens holds the identity or once its registration ends;
|
||||
* `forgePanel/lens-stale` before a change request's status was read, when the files differ from `request.version`, and
|
||||
* when local files changed while the lens ran;
|
||||
* `forgePanel/lens-failed` when the lens fails, runs past `lensTimeoutMs`, reads past `maxLensReadBytes`, or answers
|
||||
* over `maxCachedLensBytes`; the errors of `localDiff` and `changeRequestDiff` for the files.
|
||||
*/
|
||||
@Remote({ mode: 'stream' }) async *changesLens(session: Session, request: ForgeLensRequest, signal: AbortSignal): AsyncIterable<ForgeLensFrame>
|
||||
|
||||
/**
|
||||
* Read the signed-in user's viewed marks on the files of a change request of a Session, which the host keeps for the
|
||||
* whole change request.
|
||||
@@ -1971,5 +2145,25 @@ Announces a provider registration or withdrawal after the registry changes. List
|
||||
'forge/providers-changed'(forge: string): void | Promise<void>
|
||||
```
|
||||
|
||||
Source: [`packages/experimental/forge/src/index.ts`](../../packages/experimental/forge/src/index.ts)
|
||||
|
||||
<a id="forgereview-changed--parallel"></a>
|
||||
|
||||
#### `forge/review-changed` — parallel
|
||||
|
||||
Announces a review change the host accepted through this service: a thread or pending-review write, a submitted review, or a viewed mark. Changes whose outcome is unknown, refused, stale, or unsupported are not announced. Listener failures are logged without preventing other listeners from running.
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Announces a review change the host accepted through this service: a thread or pending-review write, a submitted
|
||||
* review, or a viewed mark. Changes whose outcome is unknown, refused, stale, or unsupported are not announced.
|
||||
* Listener failures are logged without preventing other listeners from running.
|
||||
* @param ref - change request the change went to.
|
||||
* @param change - what changed and the head commit it was made against.
|
||||
* @mode parallel
|
||||
*/
|
||||
'forge/review-changed'(ref: ChangeRequestRef, change: ForgeReviewChange): void | Promise<void>
|
||||
```
|
||||
|
||||
Source: [`packages/experimental/forge/src/index.ts`](../../packages/experimental/forge/src/index.ts)
|
||||
<!-- END GENERATED cordis-surface -->
|
||||
+197
-3
@@ -101,6 +101,12 @@ interface ForgeProvider {
|
||||
* with `a/` and `b/` path prefixes. Both are full object names; `head` descends from `base`.
|
||||
*/
|
||||
compare?(ref: ChangeRequestRef, base: string, head: string, signal: AbortSignal): Promise<string | ForgeFailure>
|
||||
/**
|
||||
* Find the merge base of commits `base` and `head` in the change request's repository, as a full object name: the
|
||||
* commit whose files the old side of a change request's diff shows. Omission declares that the provider cannot name
|
||||
* it, so readers of the old side get `unsupported`.
|
||||
*/
|
||||
mergeBase?(ref: ChangeRequestRef, base: string, head: string, signal: AbortSignal): Promise<string | ForgeFailure>
|
||||
/**
|
||||
* Read the signed-in user's viewed marks on the change request's files at head commit `headSha`. The marks are
|
||||
* returned only when the read names `headSha` as the head; once the head is another commit, the read resolves to a
|
||||
@@ -930,6 +936,11 @@ interface ForgePanelWorktree {
|
||||
interface ForgePanelChangeRequest extends SessionChangeRequest {
|
||||
/** Latest snapshot a poll returned, kept while later polls fail, or null before the first successful poll. */
|
||||
readonly snapshot: ChangeRequestSnapshot | null
|
||||
/**
|
||||
* Number of review changes `forge/review-changed` announced for the change request since the panel host started; it
|
||||
* grows when any plugin's write is accepted, so a reader shows threads and viewed marks read after it.
|
||||
*/
|
||||
readonly reviewRevision: number
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1189,6 +1200,120 @@ interface ForgeLocalChanges {
|
||||
}
|
||||
```
|
||||
|
||||
<a id="extension-api"></a>
|
||||
|
||||
## 扩展 API
|
||||
|
||||
其他插件通过上面的服务和另外五个扩展点扩展变更请求评审;每次注册都返回 disposer,并随做出注册的插件一起结束。与这一能力的其余部分一样,这些接口处于实验阶段,尚未稳定。新增可选字段、方法、slot、事件、错误码或带默认值的 Config 键是兼容的;删除或改名类型、方法、slot、owner props、事件、Config 键或 `dsh-resource://forge-changes/` 地址,或收窄其含义,需要写[升级指南](../../.agents/skills/dsh-create-upgrade-guide/SKILL.md)。这些扩展点都不向模型发送任何内容:插件要让模型看到 forge 数据、透镜结果或注解,须经由它自己的工具结果或 `agent.inject()`,Session log 会记录它们。
|
||||
|
||||
| 扩展点 | Service Definition | Service Provider | Consumer |
|
||||
|---|---|---|---|
|
||||
| 评审数据 | `ctx.forge` 与 `forge/review-changed` 事件 | 各 forge 提供方 | 面板 Host 与其他 Host 插件 |
|
||||
| 筛选透镜 | `ctx.forgePanel.registerLens` | Host 插件 | 经 `changesLens` 使用它的变更视图 |
|
||||
| 变更视图接口 | `ctx.forgeChanges` | forge 面板的 Client 插件 | 打开视图、给透镜起名、添加注解的 Client 插件 |
|
||||
| Slot | `forge.changes.toolbar`、`forge.changes.file.menu`、`forge.diff.line.annotation`、`forge.diff.comment.actions`、`forge.change-request.card.actions` | Client 插件 | 变更视图与变更请求卡片 |
|
||||
| Session 数据 | `forgeChangeRequests` 与 `forgeWorktree` 投影 | forge-session 与 forge 面板 | Client 插件经 `useProjection` 读取,Host 插件经 `ctx.forgeSession.changeRequests` 或 `ctx.sessionProjections.snapshot` 读取 |
|
||||
|
||||
托管平台接受一次评审写入、一次评审提交或一个已审阅标记后,`ctx.forge` 发出 `forge/review-changed`,无论是哪个插件做的;结果未知、被拒绝、已过时或不支持时不发出。面板 Host 随后丢弃为该变更请求保留的讨论,并让对应条目的 `reviewRevision` 加一,因此已打开的变更视图无需刷新就会重新读取讨论和已审阅标记。
|
||||
|
||||
```ts type-equiv
|
||||
/**
|
||||
* One review change the host accepted, which `forge/review-changed` announces: a write to the threads or the pending
|
||||
* review, a submitted review, or a viewed mark. Each names the head commit the change was made against.
|
||||
*/
|
||||
type ForgeReviewChange =
|
||||
| { readonly kind: 'write'; readonly write: ForgeReviewWrite['kind']; readonly headSha: string }
|
||||
| { readonly kind: 'submit'; readonly headSha: string }
|
||||
| { readonly kind: 'viewed'; readonly path: string; readonly viewed: boolean; readonly headSha: string }
|
||||
```
|
||||
|
||||
Host 插件用 `ctx.forgePanel.registerLens(lens)` 注册筛选透镜,Client 插件用 `ctx.forgeChanges.describeLens({ id, title })` 给它起名;没有名字的透镜显示其身份。透镜筛选显示的文件,不给文件分层:变更视图显示所选分层与所选透镜都保留的文件,测试文件开关仍然隐藏测试文件,透镜也不能把文件移到另一层。被保留文件中与 `ranges` 都不相交的 hunk 折叠成一行,读者可以展开。视图只请求所选的透镜,经流式 Remote `changesLens` 进行:它读取与视图相同的文件,文件不同时以 `forgePanel/lens-stale` 拒绝,并在 `lensTimeoutMs` 与 `maxLensReadBytes` 之内运行 `classify`;结果最多保留 `maxCachedLensBytes`。`text` 在分叉点、HEAD、暂存区或第一个所选提交的父提交上读取本地变更的旧侧,在所选提交的父提交上,或在提供方经可选的 `mergeBase` 给出的合并基准上读取变更请求的旧侧。
|
||||
|
||||
```ts type-equiv
|
||||
/** A filter over the files of a changes view, which a plugin registers with `ctx.forgePanel.registerLens()`. */
|
||||
interface ForgeLens {
|
||||
/** Identity the plugin chooses; one registration holds an id at a time. */
|
||||
readonly id: ForgeLensId
|
||||
/** Changes whenever `classify` may answer differently for the same input, which drops results kept under another version. */
|
||||
readonly version: string
|
||||
/**
|
||||
* Decide which files the lens keeps and which lines it is about. The signal aborts when the reader stops waiting, the
|
||||
* registration ends, or `lensTimeoutMs` passes; a rejection fails the request without a partial result.
|
||||
*/
|
||||
classify(input: ForgeLensInput, signal: AbortSignal): Promise<ForgeLensResult>
|
||||
}
|
||||
```
|
||||
|
||||
```ts type-equiv
|
||||
/** What one `classify` call receives. */
|
||||
interface ForgeLensInput {
|
||||
/** What the view shows. */
|
||||
readonly source: ForgeLensSource
|
||||
/** Every file of the diff in display order, with the layer the panel gave it. */
|
||||
readonly files: readonly ForgeLensFile[]
|
||||
/**
|
||||
* Read one side of a file of `files`, by its `path`: the old side reads `previousPath` for a renamed file. Resolves to
|
||||
* null when the side does not exist, as the old side of an added file, or holds binary content. Rejects for a path not
|
||||
* in `files`, once the reads of one call exceed the panel's `maxLensReadBytes`, for an old side the provider cannot
|
||||
* locate, and when the read fails.
|
||||
*/
|
||||
text(side: 'old' | 'new', path: string, signal: AbortSignal): Promise<string | null>
|
||||
/** Report how many of `total` units the lens finished; the changes view shows it while the lens runs. */
|
||||
progress(done: number, total: number): void
|
||||
}
|
||||
```
|
||||
|
||||
```ts type-equiv
|
||||
/** The files a lens keeps, by path; a file the result does not name is filtered out. */
|
||||
interface ForgeLensResult {
|
||||
readonly files: Readonly<Record<string, ForgeLensKeep>>
|
||||
}
|
||||
```
|
||||
|
||||
```ts type-equiv
|
||||
/** What a lens keeps of one file. */
|
||||
interface ForgeLensKeep {
|
||||
/**
|
||||
* Lines the lens is about on each side; hunks that touch none of them fold into one row the reader can expand.
|
||||
* Omitted: every hunk of the file shows.
|
||||
*/
|
||||
readonly ranges?: { readonly old: readonly ForgeLineRange[]; readonly new: readonly ForgeLineRange[] }
|
||||
}
|
||||
```
|
||||
|
||||
`ctx.forgeChanges` 还可以生成和解析变更视图地址,给出标签的 `kinds`,并用 `open(target, { path, lens })` 在侧栏所显示的 Session 中打开视图。`registerAnnotations(source)` 添加行注解:数据源按路径观察每个视图的注解,它在 `forge.diff.line.annotation` 中按数据源身份登记的条目,负责绘制视图所画外框里的内容。注解放在其最后一行之后,位于评论框、浏览器草稿和托管平台讨论之后,落在所在一侧的那一栏;整个文件的注解排在最前,写在另一个 `digest` 上的注解在文件之后单独成段。每个文件最多显示 `maxAnnotationsPerFile` 条;逐行绘制的文件在文件段进入可视区附近之前不绘制注解。所有 slot 的 owner props 见 [`src/client/slots.ts`](../../packages/experimental/client-ui-forge/src/client/slots.ts)。
|
||||
|
||||
```ts type-equiv
|
||||
/** Where one line annotation sits in a file of a changes view. */
|
||||
interface ForgeLineAnnotation {
|
||||
/** Identity within its source, stable across updates; it keys the drawn entry. */
|
||||
readonly key: string
|
||||
/** Inclusive 1-based lines on the old (`L`) or new (`R`) side, or `file` for the whole file. */
|
||||
readonly place: { readonly side: 'L' | 'R'; readonly startLine: number; readonly endLine: number } | 'file'
|
||||
/** Digest of the file change it was written on; a file whose `digest` differs shows it in its outdated section. */
|
||||
readonly digest?: string
|
||||
/** Changes whenever the entry should draw again; equal keys and versions keep the drawn entry's props. */
|
||||
readonly version: string | number
|
||||
}
|
||||
```
|
||||
|
||||
```ts type-equiv
|
||||
/** A Client plugin's line annotations, drawn through its `forge.diff.line.annotation` entry. */
|
||||
interface ForgeAnnotationSource {
|
||||
/** Unique source identity, also the key of its `forge.diff.line.annotation` entry. */
|
||||
readonly id: string
|
||||
/** Position among sources in one stack, lower first; equal positions keep registration order. Default 0. */
|
||||
readonly order?: number
|
||||
/**
|
||||
* Observe the annotations of one view, by path. The changes view calls it once per view and source registration;
|
||||
* the source republishes through the same observable whenever the annotations change.
|
||||
* @param target - the view's Session and source.
|
||||
* @returns annotations by repository-relative path.
|
||||
*/
|
||||
observe(target: ChangesTarget): HostObservable<ReadonlyMap<string, readonly ForgeLineAnnotation[]>>
|
||||
}
|
||||
```
|
||||
|
||||
<!-- BEGIN GENERATED cordis-surface (gen-cordis-catalog.ts) — do not edit between markers -->
|
||||
|
||||
<a id="cordis-surface"></a>
|
||||
@@ -1357,7 +1482,7 @@ async readReview(ref: ChangeRequestRef, headSha: string, signal: AbortSignal): P
|
||||
/**
|
||||
* Write to the review threads or the pending review of a change request while its head is still `write.headSha`, then
|
||||
* poll the change request at once when it is watched, unless the provider cannot write reviews. A `stale` result polls
|
||||
* it as a stale read does.
|
||||
* it as a stale read does; a write the host took is announced with `forge/review-changed`.
|
||||
* @param ref - change request served by a registered provider.
|
||||
* @param write - the write and the head commit the user saw.
|
||||
* @param signal - cancellation of the write.
|
||||
@@ -1381,7 +1506,8 @@ async viewedFiles(ref: ChangeRequestRef, headSha: string, signal: AbortSignal):
|
||||
|
||||
/**
|
||||
* Set or clear the signed-in user's viewed mark on one file of a change request while its head is still
|
||||
* `request.headSha`. A `stale` failure polls a watched change request again as {@link ForgeService.diff} does.
|
||||
* `request.headSha`. A `stale` failure polls a watched change request again as {@link ForgeService.diff} does; a saved
|
||||
* mark is announced with `forge/review-changed`.
|
||||
* @param ref - change request served by a registered provider.
|
||||
* @param request - the file, its mark, and the head commit the user saw.
|
||||
* @param signal - cancellation of the request.
|
||||
@@ -1412,7 +1538,21 @@ async commits(ref: ChangeRequestRef, signal: AbortSignal): Promise<ForgeCommitLi
|
||||
async compare(ref: ChangeRequestRef, base: string, head: string, signal: AbortSignal): Promise<string | ForgeFailure>
|
||||
|
||||
/**
|
||||
* Publish one comment or a completed review, then refresh the watched status.
|
||||
* Find the merge base of two commits of a change request's repository: the commit whose files the old side of the
|
||||
* change request's diff shows when `base` is the snapshot's `baseSha` and `head` its `headSha`.
|
||||
* @param ref - change request served by a registered provider.
|
||||
* @param base - full object name of the base commit.
|
||||
* @param head - full object name of the head commit.
|
||||
* @param signal - cancellation of the read.
|
||||
* @returns the merge base's full object name, or why the host did not provide it; `unsupported` when the provider
|
||||
* cannot name merge bases.
|
||||
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
|
||||
*/
|
||||
async mergeBase(ref: ChangeRequestRef, base: string, head: string, signal: AbortSignal): Promise<string | ForgeFailure>
|
||||
|
||||
/**
|
||||
* Publish one comment or a completed review, then refresh the watched status; a publication the host took is announced
|
||||
* with `forge/review-changed`.
|
||||
* @param ref - change request served by a registered provider.
|
||||
* @param request - explicitly selected commit, comments, and review decision.
|
||||
* @param signal - request cancellation.
|
||||
@@ -1660,6 +1800,40 @@ Serves the forge panel. Following a Session inspects the checkout of its current
|
||||
*/
|
||||
@Remote async changeRequestText(session: Session, url: string, commit: string, path: string, signal: AbortSignal): Promise<string>
|
||||
|
||||
/**
|
||||
* Register a filter lens as an effect on the calling fiber. The changes views list it while it is registered; ending
|
||||
* the registration aborts its running classifications and waits for them.
|
||||
* @param lens - the lens.
|
||||
* @returns the disposer that unregisters the lens and waits for its classifications to stop.
|
||||
* @throws when another registration holds `lens.id`.
|
||||
*/
|
||||
registerLens(lens: ForgeLens): () => Promise<void>
|
||||
|
||||
/**
|
||||
* Stream the facts every changes view reads about the panel's extensions: the current facts first, then the facts
|
||||
* after each lens registration or withdrawal. The stream ends when `signal` aborts or the Remote stops.
|
||||
* @param signal - ends the stream.
|
||||
* @returns the registered lenses and the annotation limit, in publication order.
|
||||
*/
|
||||
@Remote({ mode: 'stream' }) async *extensions(signal: AbortSignal): AsyncIterable<ForgeExtensionState>
|
||||
|
||||
/**
|
||||
* Classify the files a changes view of a Session shows with one registered lens: progress frames while the lens
|
||||
* runs, then the files it keeps. Results for the same files, lens, and lens version are reused from memory until
|
||||
* `maxCachedLensBytes` evicts them. Local changes are read with the Session's permissions; a change request's files
|
||||
* are those `changeRequestDiff` reads.
|
||||
* @param session - Session whose checkout or binding the view shows.
|
||||
* @param request - the view's source, the version of the files it shows, and the lens.
|
||||
* @param signal - ends the classification.
|
||||
* @returns progress frames, then one result frame.
|
||||
* @throws `forgePanel/lens-missing` while no lens holds the identity or once its registration ends;
|
||||
* `forgePanel/lens-stale` before a change request's status was read, when the files differ from `request.version`, and
|
||||
* when local files changed while the lens ran;
|
||||
* `forgePanel/lens-failed` when the lens fails, runs past `lensTimeoutMs`, reads past `maxLensReadBytes`, or answers
|
||||
* over `maxCachedLensBytes`; the errors of `localDiff` and `changeRequestDiff` for the files.
|
||||
*/
|
||||
@Remote({ mode: 'stream' }) async *changesLens(session: Session, request: ForgeLensRequest, signal: AbortSignal): AsyncIterable<ForgeLensFrame>
|
||||
|
||||
/**
|
||||
* Read the signed-in user's viewed marks on the files of a change request of a Session, which the host keeps for the
|
||||
* whole change request.
|
||||
@@ -1973,5 +2147,25 @@ Announces a provider registration or withdrawal after the registry changes. List
|
||||
'forge/providers-changed'(forge: string): void | Promise<void>
|
||||
```
|
||||
|
||||
Source: [`packages/experimental/forge/src/index.ts`](../../packages/experimental/forge/src/index.ts)
|
||||
|
||||
<a id="forgereview-changed--parallel"></a>
|
||||
|
||||
#### `forge/review-changed` — parallel
|
||||
|
||||
Announces a review change the host accepted through this service: a thread or pending-review write, a submitted review, or a viewed mark. Changes whose outcome is unknown, refused, stale, or unsupported are not announced. Listener failures are logged without preventing other listeners from running.
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Announces a review change the host accepted through this service: a thread or pending-review write, a submitted
|
||||
* review, or a viewed mark. Changes whose outcome is unknown, refused, stale, or unsupported are not announced.
|
||||
* Listener failures are logged without preventing other listeners from running.
|
||||
* @param ref - change request the change went to.
|
||||
* @param change - what changed and the head commit it was made against.
|
||||
* @mode parallel
|
||||
*/
|
||||
'forge/review-changed'(ref: ChangeRequestRef, change: ForgeReviewChange): void | Promise<void>
|
||||
```
|
||||
|
||||
Source: [`packages/experimental/forge/src/index.ts`](../../packages/experimental/forge/src/index.ts)
|
||||
<!-- END GENERATED cordis-surface -->
|
||||
@@ -27,8 +27,8 @@
|
||||
en: cbab49d689311d4d
|
||||
zh: 76246140eabaa55e
|
||||
/llm-streaming/appidentity-app-attribution:
|
||||
en: e053f18c7dc070a8
|
||||
zh: 90ded9a892ed2fd5
|
||||
en: 2da6911c03ea8195
|
||||
zh: ae55da1a7e22be3a
|
||||
/llm-streaming/tokenusage:
|
||||
en: 33830f78fdb845fa
|
||||
zh: f43a4502c4c3bfff
|
||||
|
||||
@@ -311,7 +311,7 @@ Retry configuration resolves before route registration into an immutable discrim
|
||||
|
||||
## `AppIdentity` — app attribution
|
||||
|
||||
The static public application identity every adapter sends to providers ([`packages/llm/llm/src/attribution.ts`](../../packages/llm/llm/src/attribution.ts)). `attributionHeaders(identity?)` maps it to the standard `User-Agent` header only; OpenRouter-specific app attribution headers are intentionally not supported by this contract. The default `APP_IDENTITY` sources its version from the package manifest; every field is a public product fact - no secrets, paths, session ids, or per-user identifiers, and nothing per-request may influence the values.
|
||||
The static public application identity every adapter sends to providers ([`packages/llm/llm/src/attribution.ts`](../../packages/llm/llm/src/attribution.ts)). `attributionHeaders(identity?)` maps it to the standard `User-Agent` header only; OpenRouter-specific app attribution headers are intentionally not supported by this contract. The default `APP_IDENTITY` sources its version from the package manifest; every field is a public product fact - no secrets, paths, session ids, or per-user identifiers, and nothing per-request may influence the values. `APP_IDENTITY.suffix` reads `DSH_USER_AGENT_SUFFIX` on each use, and `userAgent()` appends it after the comment; a value that is not an RFC 9110 product token fails the request. The `dsh` launcher sets it to `dsh-profile/<profile>` before any plugin loads, percent-encoding profile-name bytes outside `tchar` and `%` itself, so Desktop sends `deepseek-harness/<version> (+<url>) dsh-profile/desktop` and a profile named `my web` sends `dsh-profile/my%20web`. A dsh subagent child reports its own profile, because child processes do not inherit `DSH_*` variables.
|
||||
|
||||
```ts type-equiv
|
||||
/**
|
||||
@@ -328,6 +328,8 @@ interface AppIdentity {
|
||||
version: string
|
||||
/** Repository home URL of the app, used as the `User-Agent` comment. */
|
||||
url: string
|
||||
/** RFC 9110 product token appended after the comment, such as `dsh-profile/web`. */
|
||||
suffix?: string | undefined
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -313,7 +313,7 @@ interface LlmImageRequestPricing {
|
||||
|
||||
## `AppIdentity`:应用归属
|
||||
|
||||
每个适配器都会向提供方发送的静态公开应用标识([`packages/llm/llm/src/attribution.ts`](../../packages/llm/llm/src/attribution.ts))。`attributionHeaders(identity?)` 只把它映射到标准 `User-Agent` header;该约定有意不支持 OpenRouter 特有的应用归属 header。默认 `APP_IDENTITY` 从包 manifest(元数据清单)获取版本;每个字段都是公开产品事实——不含 secret、路径、会话 id 或逐用户标识,且任何逐请求信息都不得影响这些值。
|
||||
每个适配器都会向提供方发送的静态公开应用标识([`packages/llm/llm/src/attribution.ts`](../../packages/llm/llm/src/attribution.ts))。`attributionHeaders(identity?)` 只把它映射到标准 `User-Agent` header;该约定有意不支持 OpenRouter 特有的应用归属 header。默认 `APP_IDENTITY` 从包 manifest(元数据清单)获取版本;每个字段都是公开产品事实——不含 secret、路径、会话 id 或逐用户标识,且任何逐请求信息都不得影响这些值。`APP_IDENTITY.suffix` 在每次使用时读取 `DSH_USER_AGENT_SUFFIX`,`userAgent()` 将其追加在注释之后;不是 RFC 9110 product token 的值使请求失败。`dsh` 启动器在任何插件加载前将其设为 `dsh-profile/<profile>`,并对 profile 名中 `tchar` 以外的字节及 `%` 本身做百分号编码,因此 Desktop 发送 `deepseek-harness/<version> (+<url>) dsh-profile/desktop`,名为 `my web` 的 profile 发送 `dsh-profile/my%20web`。dsh 子代理子进程报告自己的 profile,因为子进程不继承 `DSH_*` 变量。
|
||||
|
||||
```ts type-equiv
|
||||
/**
|
||||
@@ -330,6 +330,8 @@ interface AppIdentity {
|
||||
version: string
|
||||
/** Repository home URL of the app, used as the `User-Agent` comment. */
|
||||
url: string
|
||||
/** RFC 9110 product token appended after the comment, such as `dsh-profile/web`. */
|
||||
suffix?: string | undefined
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
en: ee04468005fae8e1
|
||||
zh: 1347d554102951f2
|
||||
/plan-mode/the-exit-tool-and-the-plan-command:
|
||||
en: 32ecfb7086dd1578
|
||||
zh: 0aaeaa69bb63f255
|
||||
en: c9e86f6312dab80f
|
||||
zh: 41b763216d6b1a54
|
||||
/plan-mode/the-service:
|
||||
en: f3e6d5a7fe0b67f0
|
||||
zh: 774cc97e493991fa
|
||||
@@ -30,7 +30,7 @@ A missing, blank, or non-string `section` and any unknown key fail at plugin loa
|
||||
|
||||
## The exit tool and the `/plan` command
|
||||
|
||||
[`exit_plan_mode`](../tool-catalog.md#deepseek-aidsh-plan-mode) is disclosed progressively: it is admitted from the first step whose selected plan state is active and stays admitted for the rest of the Session, so the first plan-mode entry adds it to the request tool declarations and later transitions change only the plan guidance. Native and PTC execution use the same admitted set; a call before the first entry returns `UNKNOWN_TOOL`, and a call while plan mode is not committed fails. In plan mode it requires a complete markdown plan starting with a `#` heading and presents it for review through the [user-questions seam](user-questions.md). Approval returns `{ approved: true }` and records a silent (non-narrated) pending exit that is appended at the next accepted in-turn pre-step. Plan guidance therefore remains active for the rest of the assistant's current tool batch, and the tool result itself reports the transition. Keep-planning is a failed call carrying the user's feedback, so the model revises and presents again. A dismissed review returns `{ approved: false }` and concludes the turn, so plan mode stays active until the user's next message. A missing interaction channel and a service reload during review also fail the call rather than silently leaving plan mode.
|
||||
[`exit_plan_mode`](../tool-catalog.md#deepseek-aidsh-plan-mode) is disclosed progressively: it is admitted from the first step whose selected plan state is active and stays admitted for the rest of the Session, so the first plan-mode entry adds it to the request tool declarations and later transitions change only the plan guidance. Native and PTC execution use the same admitted set; a call before the first entry returns `UNKNOWN_TOOL`, and a call while plan mode is not committed fails with `PlanModeError` `PLAN_NOT_ACTIVE`. In plan mode it requires a complete markdown plan starting with a `#` heading, rejecting any other plan with `ToolArgsError`, and presents it for review through the [user-questions seam](user-questions.md). Approval returns `{ approved: true }` and records a silent (non-narrated) pending exit that is appended at the next accepted in-turn pre-step. Plan guidance therefore remains active for the rest of the assistant's current tool batch, and the tool result itself reports the transition. Keep-planning is a failed call with `PlanModeError` `PLAN_REVISION_REQUESTED` carrying the user's feedback, so the model revises and presents again. A dismissed review returns `{ approved: false }` and concludes the turn, so plan mode stays active until the user's next message. A missing interaction channel (`ToolContextUnavailableError`) and a service reload during review (`PLAN_REVIEW_INTERRUPTED`) also fail the call rather than silently leaving plan mode.
|
||||
|
||||
When [`ctx.commands`](commands.md) is composed, the plugin registers `/plan [off|message]`: bare `/plan` selects plan mode, any other non-empty message selects it and then submits the text through `agent.steer()` so it becomes the next step's ordinary logged user message under plan guidance, and the exact argument `off` selects inactive, which also cancels a pending entry before it is appended and becomes visible to a request.
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ interface PlanModeConfig {
|
||||
|
||||
## 退出工具与 `/plan` 命令
|
||||
|
||||
[`exit_plan_mode`](../tool-catalog.zh.md#deepseek-aidsh-plan-mode) 采用渐进式披露:从已选计划状态首次为激活的步骤起准入,并在会话剩余部分保持准入,因此首次进入计划模式时它进入请求的工具声明,之后的切换只改变计划指引。原生与 PTC 执行使用同一准入集合;首次进入之前调用返回 `UNKNOWN_TOOL`,计划模式未提交时调用会失败。在计划模式中,它要求一份以 `#` 标题开头的完整 markdown 计划,并通过[用户交互 seam](user-questions.zh.md) 呈交评审。批准返回 `{ approved: true }`,并记录一个静默(不叙述)的待生效退出,由下一个被接受的轮内 pre-step 追加。因此,计划指引在 assistant 当前这批工具调用的剩余部分继续生效,而工具结果本身会报告这次转换。「继续规划」则是一次携带用户反馈的失败调用,模型据此修订并再次呈交。放弃评审返回 `{ approved: false }` 并结束当前轮次,计划模式保持激活,直到用户发出下一条消息。评审期间交互通道缺失或服务重载同样使调用失败,而不是静默离开计划模式。
|
||||
[`exit_plan_mode`](../tool-catalog.zh.md#deepseek-aidsh-plan-mode) 采用渐进式披露:从已选计划状态首次为激活的步骤起准入,并在会话剩余部分保持准入,因此首次进入计划模式时它进入请求的工具声明,之后的切换只改变计划指引。原生与 PTC 执行使用同一准入集合;首次进入之前调用返回 `UNKNOWN_TOOL`,计划模式未提交时调用以 `PlanModeError` `PLAN_NOT_ACTIVE` 失败。在计划模式中,它要求一份以 `#` 标题开头的完整 markdown 计划,其他计划以 `ToolArgsError` 拒绝,并通过[用户交互 seam](user-questions.zh.md) 呈交评审。批准返回 `{ approved: true }`,并记录一个静默(不叙述)的待生效退出,由下一个被接受的轮内 pre-step 追加。因此,计划指引在 assistant 当前这批工具调用的剩余部分继续生效,而工具结果本身会报告这次转换。「继续规划」则是一次以 `PlanModeError` `PLAN_REVISION_REQUESTED` 失败并携带用户反馈的调用,模型据此修订并再次呈交。放弃评审返回 `{ approved: false }` 并结束当前轮次,计划模式保持激活,直到用户发出下一条消息。交互通道缺失(`ToolContextUnavailableError`)或评审期间服务重载(`PLAN_REVIEW_INTERRUPTED`)同样使调用失败,而不是静默离开计划模式。
|
||||
|
||||
当 [`ctx.commands`](commands.zh.md) 被组合时,插件注册 `/plan [off|message]`:单独的 `/plan` 选择计划模式;任何其他非空消息先选择计划模式,再通过 `agent.steer()` 提交该文本,使其在计划指引下成为下一步骤的普通已记录用户消息;确切参数 `off` 选择未激活,这还会在待生效条目被追加并对请求可见之前将其取消。
|
||||
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
en: 337a6580d7571274
|
||||
zh: f4ae98899120d122
|
||||
/ptc-runtime/the-run-request-in-result-out:
|
||||
en: 6dfa7da8b13a4f17
|
||||
zh: 09a3c8c4922239ef
|
||||
en: 94ba725bef6684b7
|
||||
zh: f113745a4a07952a
|
||||
/ptc-runtime/bindings-host-functions-as-program-globals:
|
||||
en: 182147ddf388c600
|
||||
zh: c0a7d77602c78bcd
|
||||
/ptc-runtime/captured-output-and-the-failure-taxonomy:
|
||||
en: 8eb1607888ab6efc
|
||||
zh: 580c852d17b9413f
|
||||
en: ef553620e77bd638
|
||||
zh: 40ff2f5ba3de5ed5
|
||||
/ptc-runtime/the-service:
|
||||
en: a82f828fa006c7e9
|
||||
zh: 2279d36867335b57
|
||||
@@ -19,13 +19,15 @@ interface PtcRunRequest {
|
||||
/**
|
||||
* The program source, in the runtime's {@link ../index.ts | language}. It
|
||||
* follows the provider's programFormat: an async function body supports
|
||||
* top-level `await` and `return`; REPL and Script programs support top-level
|
||||
* top-level `await` and `return`; REPL (`repl`, `scoped-repl`) and Script programs support top-level
|
||||
* declarations, `await`, and a final expression, but not top-level `return`.
|
||||
* The Script provider lowers top-level await; its executionInstructions and
|
||||
* documentation define retained-binding semantics. The completion value
|
||||
* becomes {@link PtcRunResult.value}.
|
||||
*/
|
||||
program: string
|
||||
/** Discard the completion without JSON validation when true; omission preserves the completion value. */
|
||||
discardCompletion?: boolean
|
||||
/**
|
||||
* Object-identity owner for optional in-memory state. Omission requests a fresh
|
||||
* environment. Consumers must await runtime.release(owner) when the owner ends.
|
||||
@@ -93,11 +95,12 @@ interface PtcRunResult {
|
||||
*/
|
||||
value?: PtcJsonValue
|
||||
/**
|
||||
* Captured text. Each source channel preserves emission order; interleaving
|
||||
* Captured text fragments retain their emitted line breaks. Concatenate adjacent text without separators.
|
||||
* Each source channel preserves emission order; interleaving
|
||||
* across independent channels is backend-dependent. Bounded only as part of
|
||||
* the outer result.
|
||||
*/
|
||||
logs: string[]
|
||||
output: PtcOutput[]
|
||||
/** Present iff the run failed; see {@link PtcRunFailure} for the taxonomy. */
|
||||
error?: PtcRunFailure
|
||||
}
|
||||
@@ -105,10 +108,10 @@ interface PtcRunResult {
|
||||
|
||||
```ts type-equiv
|
||||
/** Source evaluation form, independent of retained program state. */
|
||||
type PtcProgramFormat = 'function-body' | 'repl' | 'script'
|
||||
type PtcProgramFormat = 'function-body' | 'repl' | 'script' | 'scoped-repl'
|
||||
```
|
||||
|
||||
`programFormat` distinguishes async function bodies, REPL statements, and scripts. REPL and Script programs accept top-level `await`, declarations, and a final expression; top-level `return` is not supported. The Node Script provider lowers top-level await and awaits the completion value; its [declaration limitations](../../packages/ptc-runtime/ptc-runtime-node/README.md#known-limitations-and-deferred-work) apply to transformed programs. `retainsState` reports memory retention independently of source syntax. `stateOwner` is an in-process object identity for optional retained memory; distinct objects remain isolated. Consumers await `release(owner)` when that owner ends; cleanup failures reject that call. Omitted owners are one-shot, and stateless providers ignore ownership. The [persistent Node provider](../../packages/ptc-runtime/ptc-runtime-node/README.md#persistent-repl) defines reset and recovery behavior; no retained object enters the durable Session format.
|
||||
`programFormat` distinguishes async function bodies, REPL statements, scoped REPL statements, and scripts. REPL, scoped REPL, and Script programs accept top-level `await`, declarations, and a final expression; top-level `return` is not supported. Retained REPL calls share one scope, while each scoped REPL call starts with copies of the top-level bindings that earlier calls left, so it can declare those names again without changing earlier code. The Node Script provider lowers top-level await and awaits the completion value; its [declaration limitations](../../packages/ptc-runtime/ptc-runtime-node/README.md#known-limitations-and-deferred-work) apply to transformed programs. `retainsState` reports memory retention independently of source syntax. `stateOwner` is an in-process object identity for optional retained memory; distinct objects remain isolated. Consumers await `release(owner)` when that owner ends; cleanup failures reject that call. Omitted owners are one-shot, and stateless providers ignore ownership. The [persistent Node provider](../../packages/ptc-runtime/ptc-runtime-node/README.md#persistent-repl) defines reset and recovery behavior; no retained object enters the durable Session format.
|
||||
|
||||
## Bindings: host functions as program globals
|
||||
|
||||
@@ -148,9 +151,9 @@ interface PtcBindingNamespace {
|
||||
* The global identifier the program sees. Must match the LANGUAGE-PORTABLE
|
||||
* identifier subset `[A-Za-z_][A-Za-z0-9_]*` and no language's reserved
|
||||
* words, so the same namespace list works against every backend regardless
|
||||
* of `language` — a JS-only spelling like `$tools` is rejected by design,
|
||||
* not just by the Python backend. Names that satisfy the identifier rule but
|
||||
* name a backend-owned slot (`RESERVED_BINDING_GLOBALS`, e.g. `console`,
|
||||
* of `language` — a JS-only spelling like `$tools` is always rejected.
|
||||
* Names that satisfy the identifier rule but
|
||||
* name a backend-owned slot (`RESERVED_BINDING_GLOBALS`, e.g. `inspect`, `console`, `Image`,
|
||||
* `__dsh_main__`) are also refused everywhere; see its declaration for the
|
||||
* exact set and why each entry is reserved.
|
||||
*/
|
||||
@@ -171,7 +174,7 @@ type PtcJsonValue = null | boolean | number | string | PtcJsonValue[] | { [key:
|
||||
/**
|
||||
* One host-side function exposed to the program as an async callable. The
|
||||
* runtime bridges calls to it (possibly across a serialization boundary), so
|
||||
* `args` and the resolution value MUST be lossless JSON. A runtime rejects a
|
||||
* `args` must be lossless JSON; resolutions also support host-issued PtcImage values. A runtime rejects a
|
||||
* lossy or non-cloneable value with a descriptive error rather than corrupting
|
||||
* the run. No seam-level byte cap applies to a binding resolution. A rejection
|
||||
* of this function surfaces inside the program as a rejection of the
|
||||
@@ -182,7 +185,29 @@ type PtcBindingFunction = (args: unknown) => Promise<PtcJsonValue>
|
||||
|
||||
## Captured output and the failure taxonomy
|
||||
|
||||
Logs are plain strings. Each source channel preserves emission order, while interleaving across independent channels is backend-dependent because channel metadata is not part of the seam. The runtime captures the program's console and stream output, and consumers render only the text. Implementations cap the serialized outer log-array plus completion-value or failure-message payload; fixed result-envelope syntax and consumer presentation whitespace are not part of that variable-payload ledger. Overflow is an explicit failure rather than in-band value substitution.
|
||||
`output` contains text and image entries in emission order: `{ type: 'text', text }` or `{ type: 'image', attachment }`. Text entries retain emitted newline characters; concatenate adjacent text without separators. Each source channel preserves emission order; interleaving across independent channels is backend-dependent. Host bindings return `PtcImage` descriptors containing the attachment reference and a readable execution-world `path`; the program receives an `Image` with that path and the stored pixel dimensions. The Node provider caps serialized text, image descriptors, and completion or diagnostic payloads together; overflow is an explicit failure.
|
||||
|
||||
```ts public-api
|
||||
/** A stored image readable from the program's execution environment. */
|
||||
declare class PtcImage {
|
||||
readonly [key: string]: PtcJsonValue;
|
||||
/** Absolute attachment file path readable in the execution world. */
|
||||
readonly path: string;
|
||||
/** Stored image selected when the program inspects this value. */
|
||||
readonly attachment: Readonly<ImageAttachmentRef>;
|
||||
/**
|
||||
* Describe one immutable image file in the execution world.
|
||||
* @param path - Absolute path to the stored image.
|
||||
* @param attachment - Reference to the immutable stored image.
|
||||
*/
|
||||
constructor(path: string, attachment: ImageAttachmentRef);
|
||||
}
|
||||
```
|
||||
|
||||
```ts type-equiv
|
||||
/** Raw text fragments and inspected images in emission order; concatenate adjacent text without separators. */
|
||||
type PtcOutput = { type: 'text'; text: string } | { type: 'image'; attachment: ImageAttachmentRef }
|
||||
```
|
||||
|
||||
Failure kinds are **orthogonal outcomes reported independently** (per [defensive-patterns](../defensive-patterns/general.md)): a budget expiry is not an exception, an abort is not a timeout, and a substrate death (e.g. OOM) is neither:
|
||||
|
||||
@@ -237,6 +262,21 @@ Registers one `ctx.ptcRuntime` implementation. Program, budget, abort, and subst
|
||||
*/
|
||||
release(owner: object): Promise<void>
|
||||
|
||||
/**
|
||||
* Register source evaluated once when each execution environment is created.
|
||||
* Registration must precede the first run admission; only one initializer may
|
||||
* be registered. Current bindings are installed before initialization. Its
|
||||
* completion is discarded; logs, timeout, cancellation and output bounds share
|
||||
* the first run. Initialization failure discards the environment without
|
||||
* executing the user program or rolling back external effects.
|
||||
* @param program - Initialization source in the provider's language and format.
|
||||
* @returns An idempotent async disposer that stops admission, cancels and drains
|
||||
* admitted runs, and releases environments. Failed cleanup blocks execution
|
||||
* until the disposer succeeds on retry. The caller owns this disposer.
|
||||
* @throws When unsupported, registered twice, registered after admission, or invalid.
|
||||
*/
|
||||
registerEnvironmentInitializer(program: string): () => Promise<void>
|
||||
|
||||
/**
|
||||
* Resolve supported options and provider defaults before execution.
|
||||
* @param request - Program, bindings, cancellation and optional execution choices.
|
||||
|
||||
@@ -19,13 +19,15 @@ interface PtcRunRequest {
|
||||
/**
|
||||
* The program source, in the runtime's {@link ../index.ts | language}. It
|
||||
* follows the provider's programFormat: an async function body supports
|
||||
* top-level `await` and `return`; REPL and Script programs support top-level
|
||||
* top-level `await` and `return`; REPL (`repl`, `scoped-repl`) and Script programs support top-level
|
||||
* declarations, `await`, and a final expression, but not top-level `return`.
|
||||
* The Script provider lowers top-level await; its executionInstructions and
|
||||
* documentation define retained-binding semantics. The completion value
|
||||
* becomes {@link PtcRunResult.value}.
|
||||
*/
|
||||
program: string
|
||||
/** Discard the completion without JSON validation when true; omission preserves the completion value. */
|
||||
discardCompletion?: boolean
|
||||
/**
|
||||
* Object-identity owner for optional in-memory state. Omission requests a fresh
|
||||
* environment. Consumers must await runtime.release(owner) when the owner ends.
|
||||
@@ -93,11 +95,12 @@ interface PtcRunResult {
|
||||
*/
|
||||
value?: PtcJsonValue
|
||||
/**
|
||||
* Captured text. Each source channel preserves emission order; interleaving
|
||||
* Captured text fragments retain their emitted line breaks. Concatenate adjacent text without separators.
|
||||
* Each source channel preserves emission order; interleaving
|
||||
* across independent channels is backend-dependent. Bounded only as part of
|
||||
* the outer result.
|
||||
*/
|
||||
logs: string[]
|
||||
output: PtcOutput[]
|
||||
/** Present iff the run failed; see {@link PtcRunFailure} for the taxonomy. */
|
||||
error?: PtcRunFailure
|
||||
}
|
||||
@@ -105,10 +108,10 @@ interface PtcRunResult {
|
||||
|
||||
```ts type-equiv
|
||||
/** Source evaluation form, independent of retained program state. */
|
||||
type PtcProgramFormat = 'function-body' | 'repl' | 'script'
|
||||
type PtcProgramFormat = 'function-body' | 'repl' | 'script' | 'scoped-repl'
|
||||
```
|
||||
|
||||
`programFormat` 区分异步函数体、REPL 语句与脚本。REPL 与 Script 程序接受顶层 `await`、声明和末尾表达式,不支持顶层 `return`。Node Script 提供方转换顶层 await 并等待完成值;其[声明限制](../../packages/ptc-runtime/ptc-runtime-node/README.zh.md#known-limitations-and-deferred-work)适用于转换后的程序。`retainsState` 独立于源码语法报告是否保留内存。`stateOwner` 是标识可选保留内存的进程内对象身份;不同对象相互隔离。消费者在所有者结束时等待 `release(owner)`;清理失败时该调用拒绝。省略所有者时仅执行一次,无状态提供方忽略所有权。[持久 Node 提供方](../../packages/ptc-runtime/ptc-runtime-node/README.zh.md#persistent-repl)定义重置和恢复行为;保留对象不会进入持久 Session 格式。
|
||||
`programFormat` 区分异步函数体、REPL 语句、scoped REPL 语句与脚本。REPL、scoped REPL 与 Script 程序接受顶层 `await`、声明和末尾表达式,不支持顶层 `return`。保留状态的 REPL 各次调用共用一个作用域;scoped REPL 每次调用开始时拿到之前调用留下的顶层绑定的拷贝,因此可以再次声明这些名字,而不改变之前的代码。Node Script 提供方转换顶层 await 并等待完成值;其[声明限制](../../packages/ptc-runtime/ptc-runtime-node/README.zh.md#known-limitations-and-deferred-work)适用于转换后的程序。`retainsState` 独立于源码语法报告是否保留内存。`stateOwner` 是标识可选保留内存的进程内对象身份;不同对象相互隔离。消费者在所有者结束时等待 `release(owner)`;清理失败时该调用拒绝。省略所有者时仅执行一次,无状态提供方忽略所有权。[持久 Node 提供方](../../packages/ptc-runtime/ptc-runtime-node/README.zh.md#persistent-repl)定义重置和恢复行为;保留对象不会进入持久 Session 格式。
|
||||
|
||||
## 绑定:宿主函数作为程序全局变量
|
||||
|
||||
@@ -148,9 +151,9 @@ interface PtcBindingNamespace {
|
||||
* The global identifier the program sees. Must match the LANGUAGE-PORTABLE
|
||||
* identifier subset `[A-Za-z_][A-Za-z0-9_]*` and no language's reserved
|
||||
* words, so the same namespace list works against every backend regardless
|
||||
* of `language` — a JS-only spelling like `$tools` is rejected by design,
|
||||
* not just by the Python backend. Names that satisfy the identifier rule but
|
||||
* name a backend-owned slot (`RESERVED_BINDING_GLOBALS`, e.g. `console`,
|
||||
* of `language` — a JS-only spelling like `$tools` is always rejected.
|
||||
* Names that satisfy the identifier rule but
|
||||
* name a backend-owned slot (`RESERVED_BINDING_GLOBALS`, e.g. `inspect`, `console`, `Image`,
|
||||
* `__dsh_main__`) are also refused everywhere; see its declaration for the
|
||||
* exact set and why each entry is reserved.
|
||||
*/
|
||||
@@ -171,7 +174,7 @@ type PtcJsonValue = null | boolean | number | string | PtcJsonValue[] | { [key:
|
||||
/**
|
||||
* One host-side function exposed to the program as an async callable. The
|
||||
* runtime bridges calls to it (possibly across a serialization boundary), so
|
||||
* `args` and the resolution value MUST be lossless JSON. A runtime rejects a
|
||||
* `args` must be lossless JSON; resolutions also support host-issued PtcImage values. A runtime rejects a
|
||||
* lossy or non-cloneable value with a descriptive error rather than corrupting
|
||||
* the run. No seam-level byte cap applies to a binding resolution. A rejection
|
||||
* of this function surfaces inside the program as a rejection of the
|
||||
@@ -182,7 +185,29 @@ type PtcBindingFunction = (args: unknown) => Promise<PtcJsonValue>
|
||||
|
||||
## 捕获的输出与失败分类体系
|
||||
|
||||
日志是纯字符串。每个来源通道保留自身的发出顺序;由于通道元数据不属于 seam,相互独立的通道如何交错由后端决定。运行时捕获程序的 console 与流输出,Consumer 只渲染文本。实现会对序列化后的外层日志数组,以及完成值或失败消息的组合载荷设置上限;固定的结果封装语法与 Consumer 展示空白不计入这份可变载荷计量。超限会显式失败,而不会在值中插入替代内容。
|
||||
`output` 按发出顺序保存文本和图片条目:文本使用 `{ type: 'text', text }`,图片使用 `{ type: 'image', attachment }`。文本条目保留实际输出的换行,相邻文本直接拼接,不额外插入分隔符。每个来源通道都保留发出顺序;独立通道之间的交错顺序由后端决定。宿主绑定返回 `PtcImage` 描述符,包含附件引用和可在执行环境读取的 `path`;程序收到带有该路径和存储像素尺寸的 `Image`。Node 提供方对序列化文本、图片描述符、完成值或诊断一起计量;超限会显式失败。
|
||||
|
||||
```ts public-api
|
||||
/** A stored image readable from the program's execution environment. */
|
||||
declare class PtcImage {
|
||||
readonly [key: string]: PtcJsonValue;
|
||||
/** Absolute attachment file path readable in the execution world. */
|
||||
readonly path: string;
|
||||
/** Stored image selected when the program inspects this value. */
|
||||
readonly attachment: Readonly<ImageAttachmentRef>;
|
||||
/**
|
||||
* Describe one immutable image file in the execution world.
|
||||
* @param path - Absolute path to the stored image.
|
||||
* @param attachment - Reference to the immutable stored image.
|
||||
*/
|
||||
constructor(path: string, attachment: ImageAttachmentRef);
|
||||
}
|
||||
```
|
||||
|
||||
```ts type-equiv
|
||||
/** Raw text fragments and inspected images in emission order; concatenate adjacent text without separators. */
|
||||
type PtcOutput = { type: 'text'; text: string } | { type: 'image'; attachment: ImageAttachmentRef }
|
||||
```
|
||||
|
||||
失败类型是**正交的结果,独立报告**(见 [defensive-patterns](../defensive-patterns/general.zh.md)):预算耗尽不是异常,中止不是超时,基底崩溃(如 OOM)也不是二者中的任何一个:
|
||||
|
||||
@@ -237,6 +262,21 @@ Registers one `ctx.ptcRuntime` implementation. Program, budget, abort, and subst
|
||||
*/
|
||||
release(owner: object): Promise<void>
|
||||
|
||||
/**
|
||||
* Register source evaluated once when each execution environment is created.
|
||||
* Registration must precede the first run admission; only one initializer may
|
||||
* be registered. Current bindings are installed before initialization. Its
|
||||
* completion is discarded; logs, timeout, cancellation and output bounds share
|
||||
* the first run. Initialization failure discards the environment without
|
||||
* executing the user program or rolling back external effects.
|
||||
* @param program - Initialization source in the provider's language and format.
|
||||
* @returns An idempotent async disposer that stops admission, cancels and drains
|
||||
* admitted runs, and releases environments. Failed cleanup blocks execution
|
||||
* until the disposer succeeds on retry. The caller owns this disposer.
|
||||
* @throws When unsupported, registered twice, registered after admission, or invalid.
|
||||
*/
|
||||
registerEnvironmentInitializer(program: string): () => Promise<void>
|
||||
|
||||
/**
|
||||
* Resolve supported options and provider defaults before execution.
|
||||
* @param request - Program, bindings, cancellation and optional execution choices.
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
en: 278b2eee160be413
|
||||
zh: d6e0fd1e9f4a4b27
|
||||
/web-client-slots/framework-provided-hooks:
|
||||
en: c9f8d836214623ae
|
||||
zh: 76dec55006396535
|
||||
en: e1090f50013a2483
|
||||
zh: fd8db6ff6d4d0936
|
||||
/web-client-slots/developer-provided-injection:
|
||||
en: 3481dfa6cd3097da
|
||||
zh: acbd6f06a7da1752
|
||||
|
||||
@@ -108,7 +108,8 @@ The shipped adapters add these standard props. They are available according to t
|
||||
|
||||
| Availability | Props | Owner |
|
||||
|---|---|---|
|
||||
| every scope | `useSessions`, `useSessionStatus`, `useSessionRetainInfo`, `useSessionAccess` | `ui-session` |
|
||||
| every scope | `useSessions`, `useSessionRetainInfo`, `useSessionAccess` | `ui-session` |
|
||||
| every scope | `useSessionStatus` | `ui-session-status` |
|
||||
| every scope | `useWorkspaces`, `useWorkspaceAccess` | `ui-workspace` |
|
||||
| every scope | `useRemoteAccess` (the `global` resource) | `api-remote-access` |
|
||||
| every scope | `usePanelInfo` | `ui-layout` |
|
||||
|
||||
@@ -110,7 +110,8 @@ hoc entry 是以必填 `id` 和可选 `key` 寻址的一层。不带 `key` 的
|
||||
|
||||
| 可用范围 | Props | Owner |
|
||||
|---|---|---|
|
||||
| 所有 scope | `useSessions`、`useSessionStatus`、`useSessionRetainInfo`、`useSessionAccess` | `ui-session` |
|
||||
| 所有 scope | `useSessions`、`useSessionRetainInfo`、`useSessionAccess` | `ui-session` |
|
||||
| 所有 scope | `useSessionStatus` | `ui-session-status` |
|
||||
| 所有 scope | `useWorkspaces`、`useWorkspaceAccess` | `ui-workspace` |
|
||||
| 所有 scope | `useRemoteAccess`(`global` 资源) | `api-remote-access` |
|
||||
| 所有作用域 | `usePanelInfo` | `ui-layout` |
|
||||
|
||||
@@ -24,5 +24,5 @@
|
||||
en: 74fa698d4a115e80
|
||||
zh: 4e9b03b5eab2ae5e
|
||||
/user-interaction/errors:
|
||||
en: 5762b1498a426ab6
|
||||
zh: bb9987ec82103620
|
||||
en: 832b165cfa48839d
|
||||
zh: 6989f734b373c1f9
|
||||
@@ -209,7 +209,7 @@ After a Host restart, the Remote layer resumes the root agent when the Session r
|
||||
|
||||
## Errors
|
||||
|
||||
`UserQuestionError` extends `HarnessError`, so `ctx.tools.execute()` preserves `{ name, code }` for model-facing tool failures such as `EMPTY_QUESTIONS`, `BAD_INTENT`, `NO_PROVIDER`, `ASK_ABORTED`, or UI-side cancellation.
|
||||
`UserQuestionError` extends `HarnessError`, so `ctx.tools.execute()` preserves `{ name, code }` for model-facing tool failures such as `EMPTY_QUESTIONS`, `BAD_INTENT`, `NO_PROVIDER`, `ASK_ABORTED`, or UI-side cancellation. An answerer failure that is not a `HarnessError` becomes `PROVIDER_ERROR` with the original message and the original as `cause`; another `HarnessError` keeps its own `name` and `code`.
|
||||
|
||||
```ts type-equiv
|
||||
/** Stable error taxonomy for user-questions failures. */
|
||||
@@ -286,8 +286,11 @@ async askTimed( request: AskUserQuestionRequest & { agent: Agent }, callId: Tool
|
||||
* @returns The answer chosen or typed by the human.
|
||||
* @throws {UserQuestionError} code `ASK_ABORTED` when the supplied signal
|
||||
* is already or becomes aborted, `CALLER_NOT_LIVE` when a supplied agent
|
||||
* is not the registry's exact live instance, or `DELEGATED_CALLER` when
|
||||
* that live agent has subagent origin.
|
||||
* is not the registry's exact live instance, `DELEGATED_CALLER` when
|
||||
* that live agent has subagent origin, or `PROVIDER_ERROR`, keeping the
|
||||
* original message, when an answerer fails with a value that is not a
|
||||
* `HarnessError`; a coded `HarnessError` from an answerer keeps its `name`
|
||||
* and `code`.
|
||||
*/
|
||||
async ask(request: AskUserQuestionRequest): Promise<AskUserQuestionAnswer>
|
||||
```
|
||||
|
||||
@@ -209,7 +209,7 @@ Host 重启后,Session 重开时 Remote 层会恢复根 agent。之后的迟
|
||||
|
||||
## 错误
|
||||
|
||||
`UserQuestionError` 继承 `HarnessError`,因此 `ctx.tools.execute()` 会保留 `{ name, code }`,用于面向模型的工具失败,如 `EMPTY_QUESTIONS`、`BAD_INTENT`、`NO_PROVIDER`、`ASK_ABORTED` 或 UI 侧取消。
|
||||
`UserQuestionError` 继承 `HarnessError`,因此 `ctx.tools.execute()` 会保留 `{ name, code }`,用于面向模型的工具失败,如 `EMPTY_QUESTIONS`、`BAD_INTENT`、`NO_PROVIDER`、`ASK_ABORTED` 或 UI 侧取消。不是 `HarnessError` 的应答方失败会变为 `PROVIDER_ERROR`,保留原 message,原错误作为 `cause`;其他 `HarnessError` 保留自身的 `name` 与 `code`。
|
||||
|
||||
```ts type-equiv
|
||||
/** Stable error taxonomy for user-questions failures. */
|
||||
@@ -286,8 +286,11 @@ async askTimed( request: AskUserQuestionRequest & { agent: Agent }, callId: Tool
|
||||
* @returns The answer chosen or typed by the human.
|
||||
* @throws {UserQuestionError} code `ASK_ABORTED` when the supplied signal
|
||||
* is already or becomes aborted, `CALLER_NOT_LIVE` when a supplied agent
|
||||
* is not the registry's exact live instance, or `DELEGATED_CALLER` when
|
||||
* that live agent has subagent origin.
|
||||
* is not the registry's exact live instance, `DELEGATED_CALLER` when
|
||||
* that live agent has subagent origin, or `PROVIDER_ERROR`, keeping the
|
||||
* original message, when an answerer fails with a value that is not a
|
||||
* `HarnessError`; a coded `HarnessError` from an answerer keeps its `name`
|
||||
* and `code`.
|
||||
*/
|
||||
async ask(request: AskUserQuestionRequest): Promise<AskUserQuestionAnswer>
|
||||
```
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
en: c063711f8247c240
|
||||
zh: 5e54758bbaf1670c
|
||||
/web-client-architecture/conversation-and-presentation:
|
||||
en: 9a22492f0d4359c6
|
||||
zh: 55d449e383e88f62
|
||||
en: f37ba948a8838fb0
|
||||
zh: df19542d87860221
|
||||
/web-client-architecture/data-paths:
|
||||
en: a254278432416473
|
||||
zh: 567c2d3c6a20b304
|
||||
|
||||
@@ -57,7 +57,7 @@ This pairing is not a second source of business truth. Host controllers decide d
|
||||
|
||||
Web and desktop share the [Coding Tools preference](../../packages/client/ui-settings/README.md#use-this-package). It controls diagnostic Views, [available preset choices](../../packages/client/ui-agent-preset/README.md), changed-file cards, and the builtin HTML preview policy without changing Session records.
|
||||
|
||||
`ui-session` installs the Session scope adapter and publishes `useSessions`, `useSessionStatus`, `useSessionRetainInfo`, `useSessionAccess`, `useSession`, `sessionId`, `useProjection`, and the Session-scope `useAccess` over the [remote-access](../../packages/api/remote-access/README.md) Client service. `SessionProvider` inherits an outer binding or binds an explicit `SessionReference`, so concurrent subtrees can target different Sessions. Domain adapters add further standard sources without putting React hooks on the model objects.
|
||||
`ui-session` installs the Session scope adapter and publishes `useSessions`, `useSessionRetainInfo`, `useSessionAccess`, `useSession`, `sessionId`, `useProjection`, and the Session-scope `useAccess` over the [remote-access](../../packages/api/remote-access/README.md) Client service. `SessionProvider` inherits an outer binding or binds an explicit `SessionReference`, so concurrent subtrees can target different Sessions. [`ui-session-status`](../../packages/client/ui-session-status/README.md) publishes `useSessionStatus` from the `ctx.uiSession.sessionStatus` table of running state, the effective pending interaction, and completion reminders. Domain adapters add further standard sources without putting React hooks on the model objects.
|
||||
|
||||
`ui-conversation` binds once to each `SessionBinding.eventSource`. Its event registry correlates durable Session events and Client-only `assistant/live-chunk` updates into stable business Contexts, and its view registry materializes target snapshots. Chat Assistant, Trajectory Assistant, and Turn Tail interpret both live chunks and the compact streams embedded in durable settlements, so reconnect and paged history reproduce the same Assistant state without durable token rows. `ui-chat` and `ui-trajectory` register separate Definitions and builders: they may interpret the same event family, but they do not import or share each other's final display model. The shell selects a registered view and passes its snapshot through standard hooks and Slots. [Conversation](conversation.md) defines Context identity, replay, Location data, target builders, and keyed renderers.
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ Connection 拥有请求 URL 解析、request correlation、`/api` carrier、trus
|
||||
|
||||
Web 和桌面端共享[代码工作工具偏好](../../packages/client/ui-settings/README.zh.md#use-this-package)。它控制诊断 View、[可用的预设选项](../../packages/client/ui-agent-preset/README.zh.md)、改动文件卡片和内置 HTML 预览策略,不改变 Session 记录。
|
||||
|
||||
`ui-session` 安装 Session scope adapter,并在 [remote-access](../../packages/api/remote-access/README.zh.md) Client 服务之上提供 `useSessions`、`useSessionStatus`、`useSessionRetainInfo`、`useSessionAccess`、`useSession`、`sessionId`、`useProjection` 和会话作用域的 `useAccess`。`SessionProvider` 可以继承外围 binding,也可以绑定显式 `SessionReference`,因此并存子树可以指向不同 Session。领域 adapter 可以继续添加标准 source,但不会把 React hook 放进 model object。
|
||||
`ui-session` 安装 Session scope adapter,并在 [remote-access](../../packages/api/remote-access/README.zh.md) Client 服务之上提供 `useSessions`、`useSessionRetainInfo`、`useSessionAccess`、`useSession`、`sessionId`、`useProjection` 和会话作用域的 `useAccess`。`SessionProvider` 可以继承外围 binding,也可以绑定显式 `SessionReference`,因此并存子树可以指向不同 Session。[`ui-session-status`](../../packages/client/ui-session-status/README.zh.md) 从 `ctx.uiSession.sessionStatus` 状态表提供 `useSessionStatus`,该表汇总运行状态、生效的待交互请求和完成提醒。领域 adapter 可以继续添加标准 source,但不会把 React hook 放进 model object。
|
||||
|
||||
`ui-conversation` 对每个 `SessionBinding.eventSource` 只绑定一次。它的 event registry 把持久 Session event 与 Client-only `assistant/live-chunk` update 关联成稳定的业务 Context,view registry 则 materialize target snapshot。Chat Assistant、Trajectory Assistant 与 Turn Tail 同时解释 live chunk 和持久 settlement 中嵌入的紧凑 stream,因此重连与分页历史无需持久 token 行即可复现相同 Assistant 状态。`ui-chat` 与 `ui-trajectory` 分别注册自己的 Definition 和 builder:它们可以解释同一 event family,但不会导入或共享彼此的最终 display model。Shell 选择一个已注册 view,再通过标准 hook 与 Slot 交付其 snapshot。[Conversation](conversation.zh.md)定义 Context identity、replay、Location data、target builder 与 keyed renderer。
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
en: a86b204323005042
|
||||
zh: 82b691e28ed4dcd3
|
||||
/workflow/failure-discipline-workflowerror-fatal:
|
||||
en: 4d390801bb07374c
|
||||
zh: 1099f053c2ee26ec
|
||||
en: 4a66b379e32c2583
|
||||
zh: 9745625863b836a8
|
||||
/workflow/events:
|
||||
en: de123821a128c1d1
|
||||
zh: e50bcaea2812575a
|
||||
|
||||
@@ -79,6 +79,11 @@ interface WorkflowResult {
|
||||
stopReason: WorkflowStopReason
|
||||
/** The failure message (present iff `stopReason` is not `completed`). */
|
||||
error?: string
|
||||
/**
|
||||
* The code of the fatal {@link WorkflowError} that ended an `error` run;
|
||||
* absent when the script's own exception or the engine runtime ended it.
|
||||
*/
|
||||
errorCode?: WorkflowErrorCode
|
||||
/**
|
||||
* How many `agent()` calls the run accepted over its whole lifetime. On a
|
||||
* graceful settlement this is the script-side count (calls still queued for
|
||||
@@ -113,7 +118,7 @@ interface WorkflowRun {
|
||||
|
||||
## Failure discipline: `WorkflowError.fatal`
|
||||
|
||||
Hook misuse inside a script — bad arguments, unknown/deferred `agent()` options, a schema outside the [structured-output subset](../../packages/core/tools/README.md), a tripped cap, a seam start failure, cancellation — throws a `WorkflowError` with `fatal: true`. The `parallel()`/`pipeline()` combinators RE-THROW fatal errors instead of mapping the item to `null`: a typo'd option must kill the script loudly, never dissolve into something that reads as an ordinary child failure. The per-item `null` is reserved for child-run failures (a non-`completed` stop reason) and ordinary in-stage script errors.
|
||||
Hook misuse inside a script — bad arguments, unknown/deferred `agent()` options, a schema outside the [structured-output subset](../../packages/core/tools/README.md), a tripped cap, a seam start failure, cancellation — throws a `WorkflowError` with `fatal: true`. The `parallel()`/`pipeline()` combinators RE-THROW fatal errors instead of mapping the item to `null`: a typo'd option must kill the script loudly, never dissolve into something that reads as an ordinary child failure. The per-item `null` is reserved for child-run failures (a non-`completed` stop reason) and ordinary in-stage script errors. When a fatal error ends a run, the engine reports its code as `WorkflowResult.errorCode`, and the `workflow` tool fails with that code, such as `AGENT_CAP`; a run that settled as `error` without one (the script's own exception or an engine runtime failure) fails with `RUN_FAILED`, and one that settled as `cancelled` with `CANCELLED`; when the calling step itself was aborted, the tool runtime's `AbortError` `ABORTED` result applies instead.
|
||||
|
||||
## Events
|
||||
|
||||
|
||||
@@ -79,6 +79,11 @@ interface WorkflowResult {
|
||||
stopReason: WorkflowStopReason
|
||||
/** The failure message (present iff `stopReason` is not `completed`). */
|
||||
error?: string
|
||||
/**
|
||||
* The code of the fatal {@link WorkflowError} that ended an `error` run;
|
||||
* absent when the script's own exception or the engine runtime ended it.
|
||||
*/
|
||||
errorCode?: WorkflowErrorCode
|
||||
/**
|
||||
* How many `agent()` calls the run accepted over its whole lifetime. On a
|
||||
* graceful settlement this is the script-side count (calls still queued for
|
||||
@@ -113,7 +118,7 @@ interface WorkflowRun {
|
||||
|
||||
## 失败纪律:`WorkflowError.fatal`
|
||||
|
||||
脚本内部的钩子误用:错误参数、未知或延迟的 `agent()` 选项、超出[结构化输出子集](../../packages/core/tools/README.zh.md)的 schema、超出上限、seam 启动失败、取消,都会抛出 `fatal: true` 的 `WorkflowError`。`parallel()`/`pipeline()` 组合器对 fatal 错误直接重新抛出,而非将该项映射为 `null`:一个拼写错误的选项必须明确报错并终止脚本,绝不能消融为看似普通子 agent 失败的结果。逐项的 `null` 保留给子运行失败(非 `completed` 的 stop reason)和阶段内的普通脚本错误。
|
||||
脚本内部的钩子误用:错误参数、未知或延迟的 `agent()` 选项、超出[结构化输出子集](../../packages/core/tools/README.zh.md)的 schema、超出上限、seam 启动失败、取消,都会抛出 `fatal: true` 的 `WorkflowError`。`parallel()`/`pipeline()` 组合器对 fatal 错误直接重新抛出,而非将该项映射为 `null`:一个拼写错误的选项必须明确报错并终止脚本,绝不能消融为看似普通子 agent 失败的结果。逐项的 `null` 保留给子运行失败(非 `completed` 的 stop reason)和阶段内的普通脚本错误。致命错误结束运行时,引擎把其 code 报告为 `WorkflowResult.errorCode`,`workflow` 工具以该 code(如 `AGENT_CAP`)失败;以 `error` 结束但没有该 code 的运行(脚本自身抛出的异常或引擎运行时失败)以 `RUN_FAILED` 失败,以 `cancelled` 结束的运行以 `CANCELLED` 失败;调用方步骤本身被中止时,改为使用工具运行时的 `AbortError` `ABORTED` 结果。
|
||||
|
||||
## 事件
|
||||
|
||||
|
||||
Reference in new issue
Block a user