The TUI's referenced-prompt snapshot now rides the prompt's own admission transaction instead of a pre-admission inject: while idle, a one-shot prepended agent/prompt-submit wrapper appends the snapshot to the allow decision's additionalContexts, so a blocking hook discards the prompt and its attached context together instead of stranding the snapshot in history for the next unrelated prompt. A prompt discarded before admission releases the wrapper; steering keeps the inject path since it bypasses admission and drains at the same boundary. The session-reference snapshot adapter pinned the old context-before-prompt order; the branch-wide order (prompt first, its contexts after) is now asserted and the fixture re-recorded. tool-tasks drops the last consumer of the removed thrown-disposed contract: completion notices now inject unconditionally, which is well-defined during owner teardown — the loop treats disposal like any cancel, so the notice appends as durable idle context (persisted for resume while the session is attached, dropped with the detached log after). README pair and the owner-disposal tests state the new delivery contract.
5.3 KiB
@deepseek-ai/dsh-tool-tasks
English | 中文
ctx.tasks 的面向模型控制表层:三个与 kind 无关的工具、完成通知和一个后台工作提示词区段。加载该插件会附加 ctx.tasks.start() 所要求的表层。
工具
task_output(task_id, wait?, timeout_ms?)默认以非阻塞方式读取。流任务只返回下一个增量;最终输出任务在终止后返回结果。每个响应都以[status: ...]结尾。wait: true最多等待到配置上限,超时时仍让运行中的任务保持存活。task_list()以<id> [<kind>] <status> — <label>返回调用方可见的任务。task_kill(task_id, reason?)立即请求取消并转发已记录的原因。终止任务返回非消费式快照。
三个工具都使用通用 UI 卡片:output 和 list 使用 read,kill 使用 execute。
它们的规范值依次为 { text, task }、PublicTaskSnapshot[] 和 { outcome: 'cancellation-requested' | 'already-finished', task }。公共快照携带 id、kind、label、status/detail 及开始/结束时间;它有意省略 ownerSession 和内部 reported 通知位。原生 renderer 保留上述状态与确认文本。
当生产方提供 outputLimitBytes 时,task_output、终止 task_kill 和完成通知会在添加状态或通知文本后,对完整的原生 UTF-8 结果施加上限。只要能够容纳,读取就会保留输出尾部与控制后缀;有界完成通知则先为 background task <id> 和 task_output 收集指令预留空间,再把剩余字节用于可变的 kind、label、status、detail 与截断标记。一个前置 pre-execute 监听器会在策略运行前捕获调用方可见任务;每个任务控制定义的 final-content 回调会把其生产方上限应用到单文本拒绝、短路、规范化工具或流水线失败、替换和阻止;结构化多块策略结果保持自身形状。已有的生产方截断标记会复用,不会重复添加。省略该字段的生产方保留现有的无界控制表层行为。
完成通知
一项尚未报告的完成会向精确 owner 的会话注入 background task <id> (<kind>: <label>) finished [status: ...]. Read its output with task_output.。应用上限时,在 PTY 支持的 64 字节下限内,稳定 id 前缀和收集命令的优先级高于可变 label/detail,因此通知仍可操作。注入是下一次请求使用的持久上下文,并非唤醒。kill 或终止性 read/wait 会把交付标为已报告,并抑制重复通知。owner 释放竞态无需特殊处理:循环没有终结状态,teardown 期间注入的通知作为空闲上下文追加——会话仍挂接时随之持久化以供恢复,脱离后随无引用日志一并丢弃。
配置
| key | 默认值 | 含义 |
|---|---|---|
waitTimeoutMs |
30000 |
wait: true 省略 timeout_ms 时使用的等待时间 |
maxWaitTimeoutMs |
600000 |
模型所给等待时间的上限 |
默认值高于上限时,插件会在加载时失败。
模型体验
系统提示词
模型看到的内容
该插件注册 scope 中的每次请求都包含以下指引。按 agent scope 过滤工具时,可能会隐藏工具,却不会移除独立注册的提示词区段。
后台任务指引
Track every background task id you start. You are notified in-session when a task finishes — do not busy-poll or sleep on one; keep working on independent steps and do not duplicate a running task's work. Before giving a final answer, collect every still-relevant task with task_output (set wait: true only when you are genuinely blocked on it), and task_kill tasks that stopped mattering.
Token 影响
激活期间,每次请求承担少量固定输入成本。
KV Cache 影响
只要插件 scope 与指引文本不变,前缀就保持稳定。激活或释放可能使从该提示词区段起的复用失效。
工具 schema
模型看到的内容
该表层可见时,会看到生成的 task_output、task_list 和 task_kill schema。
Token 影响
工具可见的每次请求承担固定 schema 成本。
KV Cache 影响
只要工具定义与可见性不变,前缀就保持稳定。注册生命周期或 scope 限制可能使从第一个发生变化的 schema token 起的复用失效。
结果与通知
模型看到的内容
读取会返回输出或 (no new output),随后是 [status: <status>] 和可选 detail。空列表返回 (no background tasks)。kill 返回 requested cancellation of task <id> 或现有终止状态。尚未报告且有 owner 的完成使用上述通知。
Token 影响
结果与通知在压缩前保留于父级历史。流读取不会重复已消费的输出;生产方提供的 outputLimitBytes 会限制每次完整读取或通知。
KV Cache 影响
仅追加;新可见内容位于可复用请求前缀之后,不会使现有 KV-cache 配置项失效。
已知限制与暂缓事项
- 完成通知不会唤醒空闲 agent:需要立即获得结果的调用方必须使用
task_output。 - 流读取只有单一消费方:独立观察者需要另一套运行时 API。
- 无 owner 的任务没有会话隔离:外部表层必须提供调用方策略或避开这些任务。