Merge remote-tracking branch 'origin/master' into xtr/agent-loop-message-machine
# Conflicts: # packages/context/workspace-context/README.md # packages/llm/llm-retry/README.md # packages/session-persistence/session-checkpoint-policy/README.md # scripts/type-equiv.manifest.json
This commit is contained in:
6
packages/pty/README.i18n.yaml
Normal file
6
packages/pty/README.i18n.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write
|
||||
README.md: a9121455519a5f83a63a005cb857fec0f0e06b92
|
||||
README.zh.md: 9fc262787b960d5bf03a59cd01bf36bd5c76614b
|
||||
@@ -1,5 +1,7 @@
|
||||
# pty/ — persistent PTY capability family
|
||||
|
||||
English | [中文](README.zh.md)
|
||||
|
||||
`PTY` stands for **Pseudo-Terminal**(伪终端). This capability provides persistent, owner-scoped terminal sessions for workflows that require state across tool calls or interactive stdin. PTY complements the one-shot bash and filesystem tools; it does not replace their stronger per-operation contracts.
|
||||
|
||||
| Package | Role | ctx key |
|
||||
|
||||
13
packages/pty/README.zh.md
Normal file
13
packages/pty/README.zh.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# pty/:持久 PTY 能力家族
|
||||
|
||||
[English](README.md) | 中文
|
||||
|
||||
`PTY` 的全称是 **Pseudo-Terminal(伪终端)**。这项能力提供持久且限定所有者范围的终端会话,适用于需要跨工具调用保留状态或使用交互式 stdin 的工作流。PTY 是单次 bash 与文件系统工具的补充,不会取代后两者更严格的逐操作契约。
|
||||
|
||||
| 包 | 职责 | ctx 键 |
|
||||
|---|---|---|
|
||||
| [`pty`](pty/README.md)(`@deepseek-ai/dsh-pty`) | 后端注册表、品牌化 id、精确的 Agent 所有权、会话操作与等待完成的清理 | `ctx.pty` |
|
||||
| `pty-local`(`@deepseek-ai/dsh-pty-local`) | 本地 `node-pty` 后端、就绪检测、有界终端状态、沙箱与进程会话监管 | 注册到 `ctx.pty` |
|
||||
| `tool-pty`(`@deepseek-ai/dsh-tool-pty`) | 6 个面向模型的工具,并为后台发送集成通用任务 | 注册到 `ctx.tools` |
|
||||
|
||||
设计与暂缓边界记录在[持久 PTY Agent Note](../../.agents/notes/implemented/feature/2026-07-16-persistent-pty-sessions.md) 中。
|
||||
6
packages/pty/pty-local/README.i18n.yaml
Normal file
6
packages/pty/pty-local/README.i18n.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write
|
||||
README.md: 0ac80db3571a1c9a8c472e12a675eba17031cf5e
|
||||
README.zh.md: d6f7c3639bcff570dd9d7be8615bfeadc222f2b3
|
||||
@@ -1,5 +1,7 @@
|
||||
# @deepseek-ai/dsh-pty-local
|
||||
|
||||
English | [中文](README.zh.md)
|
||||
|
||||
Local Linux/macOS `node-pty` backend for `ctx.pty`; loading it on another platform fails as unsupported. It starts an interactive shell under the shared `ctx.sandboxPolicy`, strips credential-shaped ambient environment variables, retains bounded line-oriented output, detects readiness, and tears down the captured process tree rooted at the `node-pty` child.
|
||||
|
||||
## Plugin (`pty-local`)
|
||||
|
||||
36
packages/pty/pty-local/README.zh.md
Normal file
36
packages/pty/pty-local/README.zh.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# @deepseek-ai/dsh-pty-local
|
||||
|
||||
[English](README.md) | 中文
|
||||
|
||||
这个本地 Linux/macOS `node-pty` 后端实现 `ctx.pty`;在其他平台加载时会以不支持为由失败。它在共享 `ctx.sandboxPolicy` 下启动交互式 shell,移除形似凭据的环境变量,保留有界的逐行输出,检测就绪状态,并清理以 `node-pty` 子进程为根的已捕获进程树。
|
||||
|
||||
## 插件(`pty-local`)
|
||||
|
||||
该插件注入 `pty`、`sandbox` 和 `sandboxPolicy`,然后注册所配置的后端类型(`shell`)。`danger-full-access` 会直接启动 shell;受限模式则通过 `ctx.sandbox` 包装确切的 shell argv。系统在 spawn 时解析会话的实际模式。当某个所有者存在开放的 PTY 或正在进行 spawn 时,如果配置变更会得到不同的实际模式,系统会在对应 `sandbox/mode` 事件提交前拒绝该变更。该限制绑定到确切所有者,因此即使本地提供方重新加载并保留现有会话,它仍然有效。更改模式前,请等待创建结算并关闭会话,避免以更宽权限打开的终端在权限降级后继续存在。
|
||||
|
||||
Linux 的就绪检测结合以下机制:由前台状态验证的私有 bash 提示符标记、前台进程组 syscall 检查、静默回退和绝对超时。macOS 没有 `/proc` syscall 接口,因此使用经过验证的提示符标记以及静默/超时。当可打印的提示符文本尚未到达时,即使 OSC 标记和 `PS1` 被拆到多个数据回调中,系统也不会把标记视为就绪。如果 bash 在内核发布其重新取得前台进程组的状态前打印标记,轮询会将该候选状态保留到普通静默上限之后的最后一次轮询,使恰好同时发生的前台交接有机会胜出。因此,继承 `PROMPT_COMMAND` 的交互式子进程无法持续压制推断空闲就绪,最多只能延续到绝对超时。无法识别或读取的进程状态绝不会作为精确空闲的正向信号。尚未发布的启动过程中,回退路径要求已经观察到输出;零输出静默不能发布空会话,超时则拒绝 spawn。取消操作会关闭尚未发布的 shell,并以调用方提供的确切中止原因拒绝,即使当时还无法观察其前台进程组。如果关闭失败,`PtyBackendCleanupError` 会单独保留清理失败,供注册表释放资源时处理。未完成的终端控制序列受 `maxReadBytes` 限制;超过上限后,系统会丢弃内容直到其终止符。末尾的回车会跨回调保留,使拆分的 CRLF 合并为一个换行。
|
||||
|
||||
取消发送时,系统会解析当前前台进程组并发送真正的 `SIGINT`;它绝不会通过写入 `\x03` 模拟中断,因此原始模式程序仍可取消。关闭操作先向后代发送 `SIGTERM` 并等待,再向已捕获的存活进程与新扫描到的后代之并集发送 `SIGKILL`,防止进程通过重新设定父进程而逃避清理。系统确认每个保留的进程身份都已消失;在 Linux 上,非执行中的僵尸进程也视为完全停稳,并会随 shell 退出而回收。如果仍有进程存活,失败结果不会缓存成永久拒绝的关闭操作;后续关闭仍会重试清理。
|
||||
|
||||
## 模型体验
|
||||
|
||||
### 间接消费方
|
||||
|
||||
#### 模型看到的内容
|
||||
|
||||
没有直接可见内容。模型通过 `@deepseek-ai/dsh-tool-pty` 可能收到有界的 MOTD、发送增量、scrollback 页、就绪原因和清理错误。
|
||||
|
||||
#### Token 影响
|
||||
|
||||
消费方返回有界的后端输出前没有影响。此包不会把保留的 PTY scrollback 放入模型历史。
|
||||
|
||||
#### KV Cache 影响
|
||||
|
||||
不会直接失效;提示词、schema 与追加结果由消费方负责。
|
||||
|
||||
## 已知限制与暂缓工作
|
||||
|
||||
- 输出按行规范化;不支持全屏备用缓冲区交互。
|
||||
- Linux 精确探针支持 x64 与 arm64 UAPI 表;其他架构使用提示符标记和静默/超时就绪机制。
|
||||
- 如果后代进程在清理前守护化并重新设定父进程,它会脱离已捕获的进程树;清理绝不会扩大到启动器 PID 所属的整个 POSIX 会话,因为其中可能包含无关进程。
|
||||
- 会话无法跨 harness 进程退出保留。
|
||||
6
packages/pty/pty/README.i18n.yaml
Normal file
6
packages/pty/pty/README.i18n.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write
|
||||
README.md: 0f8b8e499dc81ce91e249f44bb38c8cc1af89d3f
|
||||
README.zh.md: 9158afd6a7c82db27820d94cdbebd4eaa537daab
|
||||
@@ -1,5 +1,7 @@
|
||||
# @deepseek-ai/dsh-pty
|
||||
|
||||
English | [中文](README.zh.md)
|
||||
|
||||
Owner-scoped persistent PTY seam. `PtyService` registers as `ctx.pty`, mints opaque session ids, routes creation through named backends, fences every operation to the exact live `Agent`, and awaits backend quiescence when that agent or the service disposes.
|
||||
|
||||
## Contract
|
||||
|
||||
41
packages/pty/pty/README.zh.md
Normal file
41
packages/pty/pty/README.zh.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# @deepseek-ai/dsh-pty
|
||||
|
||||
[English](README.md) | 中文
|
||||
|
||||
限定所有者范围的持久 PTY seam。`PtyService` 注册为 `ctx.pty`,生成不透明的会话 id,通过具名后端路由创建操作,将每个操作限制在完全相同的活跃 `Agent` 内,并在该 agent 或服务释放资源时等待后端完全停稳。
|
||||
|
||||
## 契约
|
||||
|
||||
- 后端注册一个稳定的 `type`,并返回尚未发布的 `PtyBackendSession`;失败或取消的设置过程必须清理部分资源。若清理失败,则以 `PtyBackendCleanupError` 拒绝,使注册表能在取消之后继续保留该资源。
|
||||
- spawn 取消会保留调用方提供的确切中止原因。后端设置完成后,服务资源释放与所有者消失仍分别对应可供机器路由的不同失败。
|
||||
- 所有者与服务的资源释放会通过服务所有的信号中止尚未发布的设置,并等待后端结算和回滚后才返回。
|
||||
- 如果回滚关闭失败,或后端报告启动清理失败,资源释放生命周期会以拒绝结束,不会声称已经完全停稳。调用方触发的取消仍收到其确切原因;生命周期触发的回滚失败也会拒绝待完成的 spawn。
|
||||
- 调用方取消后发生的后端清理失败仍算作所有者活动,直到所有者或服务释放资源并消费、报告该失败,避免生命周期策略把失败的清理误判为完全停稳。
|
||||
- `hasOwnerActivity(owner)` 覆盖从尚未发布的设置到最终关闭的全过程,使生命周期策略能精确限制对应所有者,不受发布竞态影响。
|
||||
- 成功的 spawn 会发布一个 `PtySessionId`。可选的 `name` 只是所有者本地的显示元数据,绝不代表权限。
|
||||
- 一个会话最多接受一个活跃的发送操作。读取和信号操作可以观察该发送;在当前操作结算前,另一项发送会失败。
|
||||
- `PtySendResult.waitReason` 与 `sessionStatus` 相互独立。`session_exit` 描述顶层 PTY 进程,而不是任意前台命令。
|
||||
- `kill()` 与资源释放只会在后端捕获的进程树完全停稳后完成。清理失败会以拒绝结束,而非声称成功;同时它会清除匹配的后端和注册表限制,使后续关闭能够重试,且不会干扰较新的尝试。
|
||||
|
||||
该 seam 不包含 `node-pty`、沙箱、工具 schema、提示词、任务或终端渲染策略。实现负责终端机制;消费方负责模型呈现和可选的后台任务注册。
|
||||
|
||||
## 模型体验
|
||||
|
||||
### 间接消费方
|
||||
|
||||
#### 模型看到的内容
|
||||
|
||||
没有直接可见内容。此包不注册提示词或工具;可见 schema 和结果文本由 `@deepseek-ai/dsh-tool-pty` 负责。
|
||||
|
||||
#### Token 影响
|
||||
|
||||
没有直接影响。活跃会话状态会保留在进程本地,直到消费方返回有界结果。
|
||||
|
||||
#### KV Cache 影响
|
||||
|
||||
不会直接失效;由具名消费方负责请求前缀变更。
|
||||
|
||||
## 已知限制与暂缓工作
|
||||
|
||||
- 会话只存在于进程本地,harness 重启后不会恢复。
|
||||
- 系统有意不支持跨 agent 共享;未来的共享会话设计需要独立的权限契约。
|
||||
6
packages/pty/tool-pty/README.i18n.yaml
Normal file
6
packages/pty/tool-pty/README.i18n.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write
|
||||
README.md: 417cf7bd0e7881f6ffefc47f5200164464b516f6
|
||||
README.zh.md: cdce3c25a6364676a6cd69c30dd877cbc8091778
|
||||
@@ -1,5 +1,7 @@
|
||||
# @deepseek-ai/dsh-tool-pty
|
||||
|
||||
English | [中文](README.zh.md)
|
||||
|
||||
Six model-facing tools over `ctx.pty`: `terminal_open`, `terminal_send`, `terminal_read`, `terminal_signal`, `terminal_close`, and `terminal_list`. Every operation requires the exact initiating `Agent`, so a model cannot address another agent's terminal even if it learns the id.
|
||||
|
||||
`terminal_send(run_in_background: true)` reuses `ctx.tasks`; task preflight and the PTY service's exclusive per-session send reservation occur before the task id is returned, completion is collected with `task_output`, and `task_kill` delivers `SIGINT` to the foreground process group. Foreground sends use terminal call/result cards. Background sends use a generic execute card; open, read, signal, close, and list use generic `execute`, `read`, `execute`, `delete`, and `read` cards respectively. None declares source locations.
|
||||
|
||||
71
packages/pty/tool-pty/README.zh.md
Normal file
71
packages/pty/tool-pty/README.zh.md
Normal file
@@ -0,0 +1,71 @@
|
||||
# @deepseek-ai/dsh-tool-pty
|
||||
|
||||
[English](README.md) | 中文
|
||||
|
||||
基于 `ctx.pty` 提供 6 个面向模型的工具:`terminal_open`、`terminal_send`、`terminal_read`、`terminal_signal`、`terminal_close` 和 `terminal_list`。每项操作都要求提供完全相同的发起 `Agent`,因此即使模型获知另一个 agent 的 id,也无法操作其终端。
|
||||
|
||||
`terminal_send(run_in_background: true)` 会复用 `ctx.tasks`;任务预检和 PTY 服务对每会话发送的独占预留都发生在返回 task id 之前。系统通过 `task_output` 收集完成结果,`task_kill` 则向前台进程组发送 `SIGINT`。前台发送使用终端调用/结果卡片。后台发送使用通用执行卡片;打开、读取、发送信号、关闭和列出操作则分别使用通用 `execute`、`read`、`execute`、`delete` 和 `read` 卡片。所有操作都不声明源位置。
|
||||
|
||||
## 配置
|
||||
|
||||
| 键 | 默认值 | 含义 |
|
||||
|---|---:|---|
|
||||
| `enableRunInBackground` | `true` | 公开并接受 `run_in_background`;设为 false 时,schema 会省略该字段,并拒绝强行传入未声明的参数 |
|
||||
| `maxResultBytes` | `262144` | 每个完整终端结果或 PTY 任务输出的 UTF-8 上限(最小值 `64`);在等待、会话、分页、截断和任务状态元数据全部加入后计算 |
|
||||
|
||||
两个值都会在加载时验证。最小结果上限可保证注册表签发的每个会话或 task id 都能出现在创建确认中。结果超过 `maxResultBytes` 时,只要空间允许,渲染会为控制元数据和截断标记预留空间;截断会保留 UTF-8 边界。每个终端定义的最终内容回调都会应用同一个上限,涵盖经过规范化的 pre-execute、around-execute 与 post-execute 策略失败、拒绝、短路、替换或阻止;结构化的多块策略结果保留其形状。
|
||||
|
||||
## 模型体验
|
||||
|
||||
### 系统提示词
|
||||
|
||||
#### 模型看到的内容
|
||||
|
||||
该插件贡献以下固定指引章节:
|
||||
|
||||
##### 终端指引
|
||||
|
||||
```markdown
|
||||
Use a terminal session only when work needs persistent terminal state or interactive stdin; prefer bash/read/write/edit for bounded one-shot operations. Track every terminal session id and close sessions that no longer matter. An inferred_idle or timeout result does not prove the foreground command exited.
|
||||
```
|
||||
|
||||
#### Token 影响
|
||||
|
||||
插件活跃期间,每次请求都会产生少量固定输入成本。
|
||||
|
||||
#### KV Cache 影响
|
||||
|
||||
注册范围和指引文本不变时,前缀保持稳定。
|
||||
|
||||
### 工具 schema
|
||||
|
||||
#### 模型看到的内容
|
||||
|
||||
6 个生成的 schema 列在 [`dsh-tool-pty` 目录章节](../../../docs/tool-catalog.md#deepseek-aidsh-tool-pty)中。此插件活跃时,请求中会包含它们的固定 schema token;按 agent 范围过滤工具时可能隐藏这些 schema。
|
||||
|
||||
#### Token 影响
|
||||
|
||||
工具可见的请求会产生固定的 schema 成本。
|
||||
|
||||
#### KV Cache 影响
|
||||
|
||||
工具可见性与定义不变时,前缀保持稳定。
|
||||
|
||||
### 工具结果与任务上下文
|
||||
|
||||
#### 模型看到的内容
|
||||
|
||||
spawn 会返回 id 和有界 MOTD。发送/读取会返回有界终端文本以及就绪/历史标记。后台模式返回通用 task id。所有终端自身或策略产生的单文本结果,在经过规范化的工具或流水线错误、拒绝、短路、替换、阻止与通用任务状态文本之后,都受 `maxResultBytes` 限制。结构化的多块策略结果保留其形状。结果会保留在会话历史中直到压缩;增量任务读取不会重复已经消费的输出。编程调用方会收到带类型的会话快照、有界的提供方读取/发送 DTO、信号与关闭结果,或 `{ kind: "background", taskId }`;Native 渲染会应用上述呈现上限。
|
||||
|
||||
#### Token 影响
|
||||
|
||||
终端自身与策略产生的单文本结果随数据变化,并受 `maxResultBytes` 限制;如果策略有意替换为结构化多块内容,则由该策略负责限制内容。每个返回结果都会保留在历史中直到压缩。
|
||||
|
||||
#### KV Cache 影响
|
||||
|
||||
仅追加;新结果位于可复用请求前缀之后。
|
||||
|
||||
## 已知限制与暂缓工作
|
||||
|
||||
- 不公开具名按键序列、TUI、BEL、调整大小、自动启动或跨 agent 共享 schema。
|
||||
- 后台模式同时依赖 `@deepseek-ai/dsh-tasks` 及其面向模型的控制接口。
|
||||
Reference in New Issue
Block a user