@deepseek-ai/dsh-tool-jobs 0.2.2-rc.1 → 0.2.2-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +2 -2
- package/README.md +2 -0
- package/README.zh.md +2 -0
- package/lib/index.js +9 -3
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/render.d.ts.map +1 -0
- package/lib/types/render.js.map +1 -0
- package/package.json +21 -18
- package/src/index.ts +613 -0
- package/src/render.ts +84 -0
package/README.i18n.yaml
CHANGED
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
en: 823e94910a15e2e1
|
|
19
19
|
zh: c23e0b605f32f0bd
|
|
20
20
|
/deepseek-ai-dsh-tool-jobs/use-this-package/the-three-tools:
|
|
21
|
-
en:
|
|
22
|
-
zh:
|
|
21
|
+
en: 618467d160f47332
|
|
22
|
+
zh: f064a74fe4b08d3e
|
|
23
23
|
/deepseek-ai-dsh-tool-jobs/use-this-package/completion-notices:
|
|
24
24
|
en: 99577924f3d65112
|
|
25
25
|
zh: 521dac5540f9c1b7
|
package/README.md
CHANGED
|
@@ -35,6 +35,8 @@ Load this plugin in any composition where the agent should start, observe, and s
|
|
|
35
35
|
|
|
36
36
|
The three tools return `{ text, job }`, `PublicJobSnapshot[]`, and `{ outcome: 'cancellation-requested' | 'already-finished', job }` respectively. A public snapshot carries id, kind, label, status with the live progress line or the terminal detail, and start/finish times, and omits ownership and ring offsets. All three render through generic UI cards: `read` for output and list, `execute` for kill.
|
|
37
37
|
|
|
38
|
+
`job_list` opts into concurrent scheduling with sibling parallel-safe calls because it reads a status snapshot. `job_output` stays exclusive because each read consumes the stream cursor and the one-time result delivery, and `job_kill` stays exclusive because it requests cancellation.
|
|
39
|
+
|
|
38
40
|
### Completion notices
|
|
39
41
|
|
|
40
42
|
When a job finishes, the owning agent receives `background job <id> (<kind>: <label>) finished [status: ...]. Output:` followed by the output it has not read and the job's final result, or `. No new output.` when there is none. A notice is inlined only when the complete text fits `inlineOutputBytes` (2048 bytes by default) and the producer's `outputLimitBytes`; otherwise it ends `. Read its output with job_output.` instead, so large output and large final results reach the model as a `job_output` result, which the tool pipeline's spill policy bounds. The label is its first line, bounded to 120 characters. A `job_output` call that collects the job while its notice is still pending withdraws the notice, and a notice that never reaches the model leaves its output for `job_output`. A busy agent has the notice injected into its next step — the turn cannot close while the inbox holds it, so several jobs settling together cost one step rather than one turn each. An idle agent is instead woken with a follow-up turn, because an unclaimed notice is a completion the model never learns about. Completions the model already collected get no notice: the registry reports a settlement that released a live `wait` as `awaited` — whether a `job_output` wait or a shell tool waiting on its own foreground command — and the plugin remembers the kills the model requested through `job_kill`; a settlement caused by owner or service teardown is skipped because nobody is left to read it. A settlement that lands after a user steer ended the wait but before that call's read carries the terminal state is delivered by that read, so the plugin withholds the notice instead of reporting the completion twice.
|
package/README.zh.md
CHANGED
|
@@ -35,6 +35,8 @@ kind: "package-reference"
|
|
|
35
35
|
|
|
36
36
|
三个工具依次返回 `{ text, job }`、`PublicJobSnapshot[]` 与 `{ outcome: 'cancellation-requested' | 'already-finished', job }`。公共快照携带 id、kind、label、带实时进度行或终态 detail 的状态,以及开始/结束时间,并省略归属与环偏移。三个工具都通过通用 UI 卡片渲染:output 和 list 用 `read`,kill 用 `execute`。
|
|
37
37
|
|
|
38
|
+
`job_list` 选择与同批并行安全调用并发调度,因为它读取的是状态快照。`job_output` 仍按独占方式执行,因为每次读取都会消费流游标和一次性的结果投递;`job_kill` 仍按独占方式执行,因为它会请求取消。
|
|
39
|
+
|
|
38
40
|
### 完成通知
|
|
39
41
|
|
|
40
42
|
任务完成时,拥有它的 agent 会收到 `background job <id> (<kind>: <label>) finished [status: ...]. Output:`,其后是它尚未读取的输出和任务的最终结果;没有输出时则以 `. No new output.` 结尾。只有完整文本同时不超过 `inlineOutputBytes`(默认 2048 字节)和生产方的 `outputLimitBytes` 时,通知才会内联;否则改以 `. Read its output with job_output.` 结尾,因此较大的输出和较大的最终结果会以 `job_output` 结果的形式抵达模型,由工具管线的 spill 策略限制其大小。label 取其首行,上限 120 个字符。在通知仍待领时收走该任务的 `job_output` 调用会撤回该通知;从未抵达模型的通知会把输出留给 `job_output`。繁忙的 agent 会在下一步收到注入的通知——inbox 尚有内容时轮次无法结束,因此同时结算的多个任务只花掉一步,而不是各占一轮。空闲的 agent 则被一个 follow-up 轮次唤醒,因为无人领取的通知就是模型永远不会知道的完成。模型已经收走的完成不再通知:注册表把释放了存活 `wait` 的结算报告为 `awaited`——无论是 `job_output` 的等待,还是 shell 工具在等待自己的前台命令——插件则记着模型经 `job_kill` 请求的杀停;所有者或服务 teardown 导致的结算会被跳过,因为没有人能读它。若结算发生在用户 steer 结束等待之后、该次调用的读取之前,终态由那次读取携带,插件因此不再发出通知,避免把同一个完成报告两次。
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import z from "@deepseek-ai/schemastery";
|
|
2
2
|
import { boundContextSummary, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
3
3
|
import { TextRetainer } from "@deepseek-ai/dsh-output-retention";
|
|
4
|
-
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
4
|
+
import { ToolArgsError, defineTool } from "@deepseek-ai/dsh-tools";
|
|
5
5
|
import { JobId } from "@deepseek-ai/dsh-jobs";
|
|
6
6
|
//#region lib/types/render.js
|
|
7
7
|
/**
|
|
@@ -229,7 +229,7 @@ function visibleOutputLimit(ctx, exec) {
|
|
|
229
229
|
}
|
|
230
230
|
/** Validate the non-empty constraint that ParameterSchemaSpec cannot express. */
|
|
231
231
|
function validateJobId(value) {
|
|
232
|
-
if (value.length === 0) throw new
|
|
232
|
+
if (value.length === 0) throw new ToolArgsError([`invalid job_id: expected a non-empty string, got ${JSON.stringify(value)}`]);
|
|
233
233
|
return JobId(value);
|
|
234
234
|
}
|
|
235
235
|
/** Pending presentation shared by the three generic job controls. */
|
|
@@ -414,6 +414,7 @@ function apply(ctx, config) {
|
|
|
414
414
|
},
|
|
415
415
|
async execute(args, exec) {
|
|
416
416
|
const id = validateJobId(args.job_id);
|
|
417
|
+
if (args.timeout_ms !== void 0 && (!Number.isFinite(args.timeout_ms) || args.timeout_ms <= 0)) throw new ToolArgsError([`invalid timeout_ms: expected a positive number of milliseconds, got ${JSON.stringify(args.timeout_ms)}`]);
|
|
417
418
|
const jobs = ctx.jobs;
|
|
418
419
|
const agent = exec.agent;
|
|
419
420
|
let endReleasedRead;
|
|
@@ -437,7 +438,11 @@ function apply(ctx, config) {
|
|
|
437
438
|
await jobs.wait(id, Math.min(args.timeout_ms ?? waitDefault, waitCap), agent?.id, AbortSignal.any([exec.signal, input.signal]));
|
|
438
439
|
} catch (error) {
|
|
439
440
|
if (!input.signal.aborted) throw error;
|
|
440
|
-
if (exec.signal.aborted)
|
|
441
|
+
if (exec.signal.aborted) {
|
|
442
|
+
const aborted = /* @__PURE__ */ new Error("wait aborted");
|
|
443
|
+
aborted.name = "AbortError";
|
|
444
|
+
throw aborted;
|
|
445
|
+
}
|
|
441
446
|
} finally {
|
|
442
447
|
unsubscribe();
|
|
443
448
|
}
|
|
@@ -462,6 +467,7 @@ function apply(ctx, config) {
|
|
|
462
467
|
name: "job_list",
|
|
463
468
|
description: "List your background jobs (running and finished) with their ids, kinds, and statuses.",
|
|
464
469
|
parameters: {},
|
|
470
|
+
isConcurrencySafe: () => true,
|
|
465
471
|
output: {
|
|
466
472
|
schema: {
|
|
467
473
|
type: "array",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAExC,OAAO,KAAK,EAAE,aAAa,EAAa,MAAM,sBAAsB,CAAA;AAUpE,OAAO,QAAQ,sB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DAAsD,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,eAAe,GAAG,CAAA;IACvI,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,CAAA;AACjF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-tool-jobs",
|
|
3
3
|
"description": "Model-facing background job control tools (job_output, job_list, job_kill) over the ctx.jobs registry",
|
|
4
|
-
"version": "0.2.2-rc.
|
|
4
|
+
"version": "0.2.2-rc.3",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -25,32 +25,35 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"locale/*.json",
|
|
27
27
|
"lib/index.js",
|
|
28
|
-
"lib/types/**/*.d.ts"
|
|
28
|
+
"lib/types/**/*.d.ts",
|
|
29
|
+
"lib/types/**/*.d.ts.map",
|
|
30
|
+
"lib/**/*.js.map",
|
|
31
|
+
"src"
|
|
29
32
|
],
|
|
30
33
|
"license": "MIT",
|
|
31
34
|
"dependencies": {
|
|
32
35
|
"@deepseek-ai/schemastery": "~3.19.0"
|
|
33
36
|
},
|
|
34
37
|
"peerDependencies": {
|
|
35
|
-
"@deepseek-ai/dsh-agent": "0.2.2-rc.
|
|
36
|
-
"@deepseek-ai/dsh-llm": "0.2.2-rc.
|
|
37
|
-
"@deepseek-ai/dsh-output-retention": "0.2.2-rc.
|
|
38
|
-
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.
|
|
39
|
-
"@deepseek-ai/dsh-jobs": "0.2.2-rc.
|
|
40
|
-
"@deepseek-ai/dsh-tools": "0.2.2-rc.
|
|
38
|
+
"@deepseek-ai/dsh-agent": "0.2.2-rc.3",
|
|
39
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.3",
|
|
40
|
+
"@deepseek-ai/dsh-output-retention": "0.2.2-rc.3",
|
|
41
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.3",
|
|
42
|
+
"@deepseek-ai/dsh-jobs": "0.2.2-rc.3",
|
|
43
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.3",
|
|
41
44
|
"@deepseek-ai/cordis": "~4.1.0"
|
|
42
45
|
},
|
|
43
46
|
"devDependencies": {
|
|
44
|
-
"@deepseek-ai/dsh-agent": "0.2.2-rc.
|
|
45
|
-
"@deepseek-ai/dsh-llm": "0.2.2-rc.
|
|
46
|
-
"@deepseek-ai/dsh-output-retention": "0.2.2-rc.
|
|
47
|
-
"@deepseek-ai/dsh-session": "0.2.2-rc.
|
|
48
|
-
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.
|
|
49
|
-
"@deepseek-ai/dsh-jobs": "0.2.2-rc.
|
|
50
|
-
"@deepseek-ai/dsh-jobs-local": "0.2.2-rc.
|
|
51
|
-
"@deepseek-ai/dsh-tool-executor-native": "0.2.2-rc.
|
|
52
|
-
"@deepseek-ai/dsh-tool-testkit": "0.2.2-rc.
|
|
53
|
-
"@deepseek-ai/dsh-tools": "0.2.2-rc.
|
|
47
|
+
"@deepseek-ai/dsh-agent": "0.2.2-rc.3",
|
|
48
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.3",
|
|
49
|
+
"@deepseek-ai/dsh-output-retention": "0.2.2-rc.3",
|
|
50
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.3",
|
|
51
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.3",
|
|
52
|
+
"@deepseek-ai/dsh-jobs": "0.2.2-rc.3",
|
|
53
|
+
"@deepseek-ai/dsh-jobs-local": "0.2.2-rc.3",
|
|
54
|
+
"@deepseek-ai/dsh-tool-executor-native": "0.2.2-rc.3",
|
|
55
|
+
"@deepseek-ai/dsh-tool-testkit": "0.2.2-rc.3",
|
|
56
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.3",
|
|
54
57
|
"@deepseek-ai/cordis": "~4.1.0"
|
|
55
58
|
}
|
|
56
59
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing `job_output`, `job_list`, and `job_kill` tools over
|
|
3
|
+
* `ctx.jobs`. Loading the plugin attaches the controller required by
|
|
4
|
+
* producers. It also delivers completions the model has not already
|
|
5
|
+
* collected to the owning agent: injected into a busy owner's next step, or
|
|
6
|
+
* opening a turn on an idle one under the default `wakeup` delivery, unbounded
|
|
7
|
+
* unless `maxConsecutiveWakes` caps it per owner. A notice carries the job's
|
|
8
|
+
* output and result when it fits `inlineOutputBytes`, and `job_output`
|
|
9
|
+
* withdraws a notice still pending.
|
|
10
|
+
* @module @deepseek-ai/dsh-tool-jobs
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
14
|
+
import z from '@deepseek-ai/schemastery'
|
|
15
|
+
import { boundContextSummary, createUserMessage, type ContentBlock } from '@deepseek-ai/dsh-llm'
|
|
16
|
+
import type { ContextFormed, MessageId } from '@deepseek-ai/dsh-llm'
|
|
17
|
+
import { TextRetainer } from '@deepseek-ai/dsh-output-retention'
|
|
18
|
+
import { defineTool, ToolArgsError } from '@deepseek-ai/dsh-tools'
|
|
19
|
+
import type { GenericCallView, ToolDefinition, ToolExecution } from '@deepseek-ai/dsh-tools'
|
|
20
|
+
import { JobId } from '@deepseek-ai/dsh-jobs'
|
|
21
|
+
import type { JobEvent, JobView, JobRead } from '@deepseek-ai/dsh-jobs'
|
|
22
|
+
import type { Agent } from '@deepseek-ai/dsh-agent'
|
|
23
|
+
import type {} from '@deepseek-ai/dsh-agent'
|
|
24
|
+
import { publicJob, renderModelDelta, statusLine } from './render.ts'
|
|
25
|
+
import type { PublicJobSnapshot } from './render.ts'
|
|
26
|
+
declare module '@deepseek-ai/dsh-llm' {
|
|
27
|
+
interface MessageSourceMap {
|
|
28
|
+
'tool-jobs': { kind: 'tool-jobs' } & ContextFormed
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const name = 'tool-jobs'
|
|
33
|
+
export const inject = ['tools', 'jobs', 'systemPrompt']
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* How an uncollected completion reaches an owner that is already idle: `wakeup`
|
|
37
|
+
* opens a turn for it, `quiet` leaves it pending until something else wakes the
|
|
38
|
+
* owner. A busy owner is injected either way.
|
|
39
|
+
*/
|
|
40
|
+
export type CompletionDelivery = 'quiet' | 'wakeup'
|
|
41
|
+
|
|
42
|
+
/** Configures bounded `job_output` waits and completion-notice delivery. */
|
|
43
|
+
export interface Config {
|
|
44
|
+
/** Wait duration applied when `job_output` sets `wait` without `timeout_ms` (default 30s). */
|
|
45
|
+
waitTimeoutMs?: number
|
|
46
|
+
/** Hard cap on any single wait; a larger model-supplied `timeout_ms` is clamped down to it (default 10min). */
|
|
47
|
+
maxWaitTimeoutMs?: number
|
|
48
|
+
/** Whether a completion opens a turn on an idle owner (default `wakeup`). */
|
|
49
|
+
completionDelivery?: CompletionDelivery
|
|
50
|
+
/**
|
|
51
|
+
* Turns one owner may have opened by completion wakes before the next
|
|
52
|
+
* notice degrades to injection, reset by any user-authored input. Absent by
|
|
53
|
+
* default: every idle completion wakes its owner. Set it to bound the
|
|
54
|
+
* self-exciting chain where a woken turn starts the job whose completion
|
|
55
|
+
* wakes it again, at the cost of notices past the cap waiting silently for
|
|
56
|
+
* the next user input.
|
|
57
|
+
*/
|
|
58
|
+
maxConsecutiveWakes?: number
|
|
59
|
+
/**
|
|
60
|
+
* Largest complete completion notice, in UTF-8 bytes, that carries the
|
|
61
|
+
* job's output and final result inline (default 2048); a larger one, or one
|
|
62
|
+
* over the producer's `outputLimitBytes`, leaves them for `job_output`. 0
|
|
63
|
+
* never inlines.
|
|
64
|
+
*/
|
|
65
|
+
inlineOutputBytes?: number
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const Config: z<Config> = z.object({
|
|
69
|
+
waitTimeoutMs: z.number().min(1).default(30_000),
|
|
70
|
+
maxWaitTimeoutMs: z.number().min(1).default(600_000),
|
|
71
|
+
completionDelivery: z.union(['quiet', 'wakeup'] as const).default('wakeup'),
|
|
72
|
+
maxConsecutiveWakes: z.number().min(1),
|
|
73
|
+
inlineOutputBytes: z.natural().default(2048),
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
/** Shared schema for job-control outputs. */
|
|
77
|
+
const PUBLIC_JOB_SCHEMA = {
|
|
78
|
+
type: 'object',
|
|
79
|
+
additionalProperties: false,
|
|
80
|
+
properties: {
|
|
81
|
+
id: { type: 'string', required: true },
|
|
82
|
+
kind: { type: 'string', required: true },
|
|
83
|
+
label: { type: 'string', required: true },
|
|
84
|
+
status: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
required: true,
|
|
87
|
+
enum: ['running', 'stopping', 'completed', 'killed', 'failed'],
|
|
88
|
+
},
|
|
89
|
+
detail: { type: 'string' },
|
|
90
|
+
startedAt: { type: 'integer', required: true },
|
|
91
|
+
finishedAt: { type: 'integer' },
|
|
92
|
+
},
|
|
93
|
+
} as const
|
|
94
|
+
|
|
95
|
+
const encoder = new TextEncoder()
|
|
96
|
+
|
|
97
|
+
function retainTail(text: string, maxBytes: number): string {
|
|
98
|
+
const retainer = new TextRetainer({ kind: 'tail', maxBytes })
|
|
99
|
+
retainer.push(text)
|
|
100
|
+
return retainer.finish().text
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function retainHead(text: string, maxBytes: number): string {
|
|
104
|
+
const retainer = new TextRetainer({ kind: 'head', maxBytes })
|
|
105
|
+
retainer.push(text)
|
|
106
|
+
return retainer.finish().text
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function fitWithSuffix(
|
|
110
|
+
content: string,
|
|
111
|
+
suffix: string,
|
|
112
|
+
maxBytes: number | undefined,
|
|
113
|
+
omitted: string,
|
|
114
|
+
): string {
|
|
115
|
+
const complete = `${content}${suffix}`
|
|
116
|
+
if (maxBytes === undefined || encoder.encode(complete).byteLength <= maxBytes) return complete
|
|
117
|
+
const fixed = `${content.endsWith(omitted.trimStart()) ? '' : omitted}${suffix}`
|
|
118
|
+
const fixedBytes = encoder.encode(fixed).byteLength
|
|
119
|
+
if (fixedBytes >= maxBytes) return retainTail(fixed, maxBytes)
|
|
120
|
+
return `${retainTail(content, maxBytes - fixedBytes)}${fixed}`
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* One-line account of a settled job for the `notice` form's collapsed row.
|
|
125
|
+
* @param job - the settled job.
|
|
126
|
+
* @returns its kind, label, and status, bounded like every notice summary.
|
|
127
|
+
*/
|
|
128
|
+
function completionSummary(job: JobView): string {
|
|
129
|
+
return boundContextSummary(`${job.kind} ${job.label} ${statusLine(publicJob(job))}`)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The job's label as a notice names it: the first non-empty line, bounded
|
|
134
|
+
* like a notice summary. The model wrote the full command and holds the job id.
|
|
135
|
+
* @param job - the settled job.
|
|
136
|
+
* @returns ` (kind: label) finished [status: …]`.
|
|
137
|
+
*/
|
|
138
|
+
function noticeDetail(job: JobView): string {
|
|
139
|
+
const text = job.label.trimStart()
|
|
140
|
+
const newline = text.indexOf('\n')
|
|
141
|
+
const label = boundContextSummary(newline === -1 ? text : `${text.slice(0, newline)}…`)
|
|
142
|
+
return ` (${job.kind}: ${label}) finished ${statusLine(publicJob(job))}`
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The notice that carries the job's output and final result, when the
|
|
147
|
+
* complete text fits both `maxBytes` and the producer's cap.
|
|
148
|
+
* @param job - the settled job.
|
|
149
|
+
* @param output - the consuming read taken at settlement.
|
|
150
|
+
* @param maxBytes - the configured inline bound.
|
|
151
|
+
* @returns the notice text, or undefined when it does not fit.
|
|
152
|
+
*/
|
|
153
|
+
function inlineCompletionNotice(job: JobView, output: string, maxBytes: number): string | undefined {
|
|
154
|
+
const head = `background job ${job.id}${noticeDetail(job)}`
|
|
155
|
+
const text = output.length === 0 ? `${head}. No new output.` : `${head}. Output:\n${output.replace(/\n$/, '')}`
|
|
156
|
+
const bytes = encoder.encode(text).byteLength
|
|
157
|
+
return bytes <= maxBytes && bytes <= (job.outputLimitBytes ?? Infinity) ? text : undefined
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function fitCompletionNotice(job: JobView): string {
|
|
161
|
+
const prefix = `background job ${job.id}`
|
|
162
|
+
const detail = noticeDetail(job)
|
|
163
|
+
const action = '\nDone; job_output.'
|
|
164
|
+
const complete = `${prefix}${detail}. Read its output with job_output.`
|
|
165
|
+
const maxBytes = job.outputLimitBytes
|
|
166
|
+
if (maxBytes === undefined || encoder.encode(complete).byteLength <= maxBytes) return complete
|
|
167
|
+
const omitted = '\n[notice truncated]'
|
|
168
|
+
const fixed = `${prefix}${omitted}${action}`
|
|
169
|
+
const fixedBytes = encoder.encode(fixed).byteLength
|
|
170
|
+
if (fixedBytes <= maxBytes) {
|
|
171
|
+
return fixedBytes === maxBytes
|
|
172
|
+
? fixed
|
|
173
|
+
: `${prefix}${retainHead(detail, maxBytes - fixedBytes)}${omitted}${action}`
|
|
174
|
+
}
|
|
175
|
+
const compact = `${prefix}${action}`
|
|
176
|
+
const compactBytes = encoder.encode(compact).byteLength
|
|
177
|
+
if (compactBytes <= maxBytes) return compact
|
|
178
|
+
// A partial UUID cannot identify the job. Point the model at the listing instead.
|
|
179
|
+
const recovery = 'background job ended; use job_list for id.'
|
|
180
|
+
if (encoder.encode(recovery).byteLength <= maxBytes) return recovery
|
|
181
|
+
return retainHead('job_list', maxBytes)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function rawSingleText(content: readonly ContentBlock[]): string | undefined {
|
|
185
|
+
if (content.length !== 1) return undefined
|
|
186
|
+
const block = content[0]
|
|
187
|
+
if (block?.type !== 'text') return undefined
|
|
188
|
+
return block.text
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function boundSingleText(content: readonly ContentBlock[], maxBytes: number): ContentBlock[] | undefined {
|
|
192
|
+
const text = rawSingleText(content)
|
|
193
|
+
if (text === undefined) return undefined
|
|
194
|
+
return [{
|
|
195
|
+
type: 'text',
|
|
196
|
+
text: fitWithSuffix(text, '', maxBytes, '\n[result truncated]'),
|
|
197
|
+
}]
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The producer's cap for the job a `job_output` or `job_kill` call names, when it is visible to the caller. */
|
|
201
|
+
function visibleOutputLimit(ctx: Context, exec: ToolExecution): number | undefined {
|
|
202
|
+
if (exec.name !== 'job_output' && exec.name !== 'job_kill') return undefined
|
|
203
|
+
const jobId = (exec.arguments as { job_id?: unknown } | null | undefined)?.job_id
|
|
204
|
+
if (typeof jobId !== 'string' || jobId.length === 0) return undefined
|
|
205
|
+
return ctx.jobs.list(exec.agent?.id).find(job => job.id === jobId)?.outputLimitBytes
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Validate the non-empty constraint that ParameterSchemaSpec cannot express. */
|
|
209
|
+
function validateJobId(value: string): JobId {
|
|
210
|
+
if (value.length === 0) {
|
|
211
|
+
throw new ToolArgsError([`invalid job_id: expected a non-empty string, got ${JSON.stringify(value)}`])
|
|
212
|
+
}
|
|
213
|
+
return JobId(value)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Pending presentation shared by the three generic job controls. */
|
|
217
|
+
function presentJobCall(title: string, kind: 'read' | 'execute', rawInput?: string): GenericCallView {
|
|
218
|
+
return { card: 'generic', title, kind, ...rawInput !== undefined ? { rawInput } : {} }
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** A completion notice not yet logged; see the `pending` map in {@link apply}. */
|
|
222
|
+
interface PendingNotice {
|
|
223
|
+
readonly owner: NonNullable<JobView['owner']>
|
|
224
|
+
readonly messageId: MessageId
|
|
225
|
+
/** Whether the notice carries `held`; otherwise `job_output` returns it. */
|
|
226
|
+
readonly inline: boolean
|
|
227
|
+
/** The consuming read taken at settlement, absent when the read stayed in the registry. */
|
|
228
|
+
readonly held?: string
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** The consuming read as the model sees it: the delta, then the result once, then the status line. */
|
|
232
|
+
function readBody(read: JobRead): { text: string; job: PublicJobSnapshot } {
|
|
233
|
+
const delta = renderModelDelta(read.chunks, read.lossy, read.job.output.spillPaths ?? [])
|
|
234
|
+
const text = read.result === undefined
|
|
235
|
+
? delta
|
|
236
|
+
: `${delta}${delta.length > 0 && !delta.endsWith('\n') ? '\n' : ''}${read.result}`
|
|
237
|
+
return { text, job: publicJob(read.job) }
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function apply(ctx: Context, config: Config): void {
|
|
241
|
+
const waitDefault = config.waitTimeoutMs ?? 30_000
|
|
242
|
+
const waitCap = config.maxWaitTimeoutMs ?? 600_000
|
|
243
|
+
const delivery = config.completionDelivery ?? 'wakeup'
|
|
244
|
+
const wakeBudget = config.maxConsecutiveWakes
|
|
245
|
+
const inlineBytes = config.inlineOutputBytes ?? 2048
|
|
246
|
+
|
|
247
|
+
// Turns this plugin opened on each owner since that owner last consumed
|
|
248
|
+
// human input. Keyed by the exact Agent, so a same-session replacement
|
|
249
|
+
// starts with a full budget.
|
|
250
|
+
const spentWakes = new WeakMap<Agent, number>()
|
|
251
|
+
if (waitDefault > waitCap) {
|
|
252
|
+
throw new Error(`tool-jobs: waitTimeoutMs (${waitDefault}) exceeds maxWaitTimeoutMs (${waitCap})`)
|
|
253
|
+
}
|
|
254
|
+
// A budget is a count of turns: a fraction never names a turn, and
|
|
255
|
+
// `Infinity` would spell an "unbounded" that omitting the field already means.
|
|
256
|
+
if (wakeBudget !== undefined && !Number.isSafeInteger(wakeBudget)) {
|
|
257
|
+
throw new Error(`tool-jobs: maxConsecutiveWakes (${wakeBudget}) must be a whole number of turns`)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Each completion notice until the model receives its output. A notice
|
|
261
|
+
// whose job wrote at most `inlineOutputBytes` took the consuming read at
|
|
262
|
+
// settlement. When the complete notice fits, it carries that read until it
|
|
263
|
+
// is logged as a `user/message`; a notice claimed by a step that is then
|
|
264
|
+
// rejected or cancelled leaves the read for `job_output`. Otherwise
|
|
265
|
+
// `job_output` returns the held read. `job_output` also withdraws a notice
|
|
266
|
+
// still pending, which would only repeat its result.
|
|
267
|
+
const pending = new Map<JobId, PendingNotice>()
|
|
268
|
+
|
|
269
|
+
if (delivery === 'wakeup' && wakeBudget !== undefined) {
|
|
270
|
+
ctx.on('agent/inbox/claimed', ({ agent, message }) => {
|
|
271
|
+
// Claiming is the point the human's input actually enters a step; a notice
|
|
272
|
+
// this plugin itself queued must not refill the budget it just spent.
|
|
273
|
+
if (message.source.kind === 'user') spentWakes.delete(agent)
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
ctx.on('session/event', (session, event) => {
|
|
277
|
+
if (event.type !== 'user/message' || event.data.source.kind !== 'tool-jobs') return
|
|
278
|
+
for (const [id, notice] of pending) {
|
|
279
|
+
if (notice.messageId !== event.data.id || notice.owner !== session.id) continue
|
|
280
|
+
// A logged notice keeps only a read it did not carry, for `job_output`.
|
|
281
|
+
if (notice.inline || notice.held === undefined) pending.delete(id)
|
|
282
|
+
}
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
const outputLimits = new WeakMap<ToolExecution, number>()
|
|
286
|
+
ctx.on('tools/pre-execute', (exec, next) => {
|
|
287
|
+
const maxBytes = visibleOutputLimit(ctx, exec)
|
|
288
|
+
if (maxBytes !== undefined) outputLimits.set(exec, maxBytes)
|
|
289
|
+
return next()
|
|
290
|
+
}, { prepend: true })
|
|
291
|
+
const finalizeJobContent: NonNullable<ToolDefinition['finalizeContent']> = (exec, result) => {
|
|
292
|
+
const maxBytes = outputLimits.get(exec) ?? visibleOutputLimit(ctx, exec)
|
|
293
|
+
outputLimits.delete(exec)
|
|
294
|
+
if (maxBytes === undefined) return undefined
|
|
295
|
+
if (exec.name === 'job_output' && !result.isError) {
|
|
296
|
+
// This definition owns and schema-validates the canonical value. Preserve
|
|
297
|
+
// its output/status split only while policy left the default rendering intact.
|
|
298
|
+
const value = result.value as unknown as { text: string; job: PublicJobSnapshot }
|
|
299
|
+
const body = value.text.length > 0 ? value.text : '(no new output)'
|
|
300
|
+
const content = body.endsWith('\n') ? body.slice(0, -1) : body
|
|
301
|
+
const suffix = `\n${statusLine(value.job)}`
|
|
302
|
+
if (rawSingleText(result.content) === `${content}${suffix}`) {
|
|
303
|
+
return [{
|
|
304
|
+
type: 'text',
|
|
305
|
+
text: fitWithSuffix(content, suffix, maxBytes, '\n[output truncated]'),
|
|
306
|
+
}]
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return boundSingleText(result.content, maxBytes)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Producers may start work only while a controller is attached.
|
|
313
|
+
ctx.jobs.attachController('tool-jobs')
|
|
314
|
+
|
|
315
|
+
// Cross-call guidance follows the filesystem sections and precedes product sections.
|
|
316
|
+
ctx.systemPrompt.section({
|
|
317
|
+
name: 'tool:jobs',
|
|
318
|
+
order: ctx.systemPrompt.getSectionOrder('TOOL_JOBS'),
|
|
319
|
+
text: 'Track every background job id you start. You are notified in-session when a job finishes — do not busy-poll or sleep on one; keep working on independent steps and do not duplicate a running job\'s work. Before giving a final answer, collect every still-relevant job with job_output (set wait: true only when you are genuinely blocked on it), and job_kill jobs that stopped mattering.',
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
// Live jobs whose kill the model itself requested through `job_kill`: that
|
|
323
|
+
// tool result is the model's delivery, so the settlement notice would only
|
|
324
|
+
// repeat it. A wait needs no entry here — the registry reports a settlement
|
|
325
|
+
// that released a live wait as `awaited`, whichever plugin was waiting.
|
|
326
|
+
const killedByModel = new Set<JobId>()
|
|
327
|
+
|
|
328
|
+
// Waits this plugin ended on next-step input whose consuming read has not
|
|
329
|
+
// committed yet. A settlement inside that window is carried by that read's
|
|
330
|
+
// terminal state and result, so its notice would repeat them; the registry
|
|
331
|
+
// cannot report it `awaited`, because releasing the wait already left the
|
|
332
|
+
// waiter set. One pending claim per released read keeps parallel waits on the
|
|
333
|
+
// same job covered until the last of their reads commits.
|
|
334
|
+
const releasedReads = new Map<JobId, { pending: number }>()
|
|
335
|
+
/** A settlement a released read is expected to carry; delivered at once if that read never commits. */
|
|
336
|
+
const suppressedSettlements = new Map<JobId, SettledEvent>()
|
|
337
|
+
/** A settlement event, the one kind this plugin delivers. */
|
|
338
|
+
type SettledEvent = Extract<JobEvent, { type: 'settled' }>
|
|
339
|
+
const beginReleasedRead = (id: JobId): (() => void) => {
|
|
340
|
+
const claim = releasedReads.get(id) ?? { pending: 0 }
|
|
341
|
+
releasedReads.set(id, claim)
|
|
342
|
+
claim.pending += 1
|
|
343
|
+
return () => {
|
|
344
|
+
claim.pending -= 1
|
|
345
|
+
if (claim.pending !== 0) return
|
|
346
|
+
releasedReads.delete(id)
|
|
347
|
+
// Every released read committed: the result carried the settlement.
|
|
348
|
+
const pending = suppressedSettlements.get(id)
|
|
349
|
+
if (pending === undefined) return
|
|
350
|
+
suppressedSettlements.delete(id)
|
|
351
|
+
deliverSettlement(pending)
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// A busy owner is injected: the notice waits in its next-step inbox, which
|
|
356
|
+
// the turn cannot close over, so jobs settling together cost one step. An
|
|
357
|
+
// idle owner is woken instead, because an undelivered notice is a completion
|
|
358
|
+
// the model never learns about. Either way, disposal before delivery
|
|
359
|
+
// discards it with the owner, and a teardown settlement has no reader left.
|
|
360
|
+
// A settlement this plugin's own released wait is about to collect is
|
|
361
|
+
// skipped too, so the model receives it once, in that tool result.
|
|
362
|
+
//
|
|
363
|
+
// The registry routes each settlement to the scope this plugin was mounted
|
|
364
|
+
// under, so a mount under one preset never sees another preset's agents;
|
|
365
|
+
// this listener owns delivery, not the choice of whom to deliver to.
|
|
366
|
+
/**
|
|
367
|
+
* Deliver one settlement that no caller already collected.
|
|
368
|
+
* @param event - the settlement to announce.
|
|
369
|
+
*/
|
|
370
|
+
const deliverSettlement = (event: SettledEvent): void => {
|
|
371
|
+
if (event.cause === 'teardown' || event.job.owner === undefined) return
|
|
372
|
+
// The destination is the agent registered for the owner session now. An
|
|
373
|
+
// owned job needed the agent registry to start, so the registry is only
|
|
374
|
+
// absent here when it left before settlement — and then no inbox is left.
|
|
375
|
+
const owner = ctx.get('agents')?.get(event.job.owner)
|
|
376
|
+
if (owner === undefined) return
|
|
377
|
+
// A stream longer than the bound cannot fit, so the read stays in the
|
|
378
|
+
// registry. A read whose result makes the notice too long is held for
|
|
379
|
+
// `job_output`, whose result the tool pipeline bounds and spills.
|
|
380
|
+
const held = inlineBytes > 0 && event.job.output.total <= inlineBytes
|
|
381
|
+
? readBody(ctx.jobs.read(event.job.id, event.job.owner)).text
|
|
382
|
+
: undefined
|
|
383
|
+
const inline = held === undefined ? undefined : inlineCompletionNotice(event.job, held, inlineBytes)
|
|
384
|
+
const message = createUserMessage({
|
|
385
|
+
content: [{
|
|
386
|
+
type: 'text',
|
|
387
|
+
text: inline ?? fitCompletionNotice(event.job),
|
|
388
|
+
}],
|
|
389
|
+
source: {
|
|
390
|
+
kind: 'tool-jobs',
|
|
391
|
+
form: 'notice',
|
|
392
|
+
summary: completionSummary(event.job),
|
|
393
|
+
},
|
|
394
|
+
})
|
|
395
|
+
pending.set(event.job.id, {
|
|
396
|
+
owner: event.job.owner, messageId: message.id, inline: inline !== undefined, ...held === undefined ? {} : { held },
|
|
397
|
+
})
|
|
398
|
+
if (delivery === 'wakeup' && owner.status === 'idle') {
|
|
399
|
+
if (wakeBudget === undefined) {
|
|
400
|
+
owner.followup(message)
|
|
401
|
+
return
|
|
402
|
+
}
|
|
403
|
+
const spent = spentWakes.get(owner) ?? 0
|
|
404
|
+
if (spent < wakeBudget) {
|
|
405
|
+
spentWakes.set(owner, spent + 1)
|
|
406
|
+
owner.followup(message)
|
|
407
|
+
return
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
owner.inject(message)
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
ctx.jobs.events.subscribe({ owners: 'scope' }, (event) => {
|
|
414
|
+
if (event.type === 'removed') {
|
|
415
|
+
killedByModel.delete(event.job.id)
|
|
416
|
+
pending.delete(event.job.id)
|
|
417
|
+
return
|
|
418
|
+
}
|
|
419
|
+
if (event.type !== 'settled') return
|
|
420
|
+
// The model's own kill result and a live waiter's collection both deliver
|
|
421
|
+
// this settlement; only a settlement no caller collected is held for a
|
|
422
|
+
// released read that has not committed yet. Holding an already-delivered
|
|
423
|
+
// settlement would repeat it when that read never commits.
|
|
424
|
+
if (killedByModel.delete(event.job.id) || event.awaited) return
|
|
425
|
+
if (releasedReads.has(event.job.id)) {
|
|
426
|
+
suppressedSettlements.set(event.job.id, event)
|
|
427
|
+
return
|
|
428
|
+
}
|
|
429
|
+
deliverSettlement(event)
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
ctx.tools.register(defineTool({
|
|
433
|
+
name: 'job_output',
|
|
434
|
+
description: 'Read a background job: output since the previous read for stream jobs, or the result of a finished final-output job.',
|
|
435
|
+
// A timed-out wait returns job state rather than a TOOL_TIMEOUT error, so
|
|
436
|
+
// this tool owns its deadline instead of using ToolDefinition.timeoutMs.
|
|
437
|
+
parameters: {
|
|
438
|
+
job_id: { type: 'string', required: true, description: 'Job id returned by the tool that started the background work.' },
|
|
439
|
+
wait: { type: 'boolean', description: 'Block until the job finishes or the timeout expires; a timed-out wait leaves the job running. Defaults to false.' },
|
|
440
|
+
timeout_ms: { type: 'number', description: 'Max wait in milliseconds with wait: true. Defaults to and is capped by configuration.' },
|
|
441
|
+
},
|
|
442
|
+
finalizeContent: finalizeJobContent,
|
|
443
|
+
output: {
|
|
444
|
+
schema: {
|
|
445
|
+
type: 'object',
|
|
446
|
+
additionalProperties: false,
|
|
447
|
+
properties: {
|
|
448
|
+
text: { type: 'string', required: true },
|
|
449
|
+
job: { ...PUBLIC_JOB_SCHEMA, required: true },
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
render: (_args, value) => {
|
|
453
|
+
const body = value.text.length > 0 ? value.text : '(no new output)'
|
|
454
|
+
const separator = body.endsWith('\n') ? '' : '\n'
|
|
455
|
+
return [{ type: 'text', text: `${body}${separator}${statusLine(value.job)}` }]
|
|
456
|
+
},
|
|
457
|
+
},
|
|
458
|
+
async execute(args, exec) {
|
|
459
|
+
const id = validateJobId(args.job_id)
|
|
460
|
+
if (args.timeout_ms !== undefined && (!Number.isFinite(args.timeout_ms) || args.timeout_ms <= 0)) {
|
|
461
|
+
throw new ToolArgsError([`invalid timeout_ms: expected a positive number of milliseconds, got ${JSON.stringify(args.timeout_ms)}`])
|
|
462
|
+
}
|
|
463
|
+
const jobs = ctx.jobs
|
|
464
|
+
const agent = exec.agent
|
|
465
|
+
// A wait this execution ends on next-step input claims the read that
|
|
466
|
+
// follows it: the claim stays open until that read commits, so a
|
|
467
|
+
// settlement landing first is delivered by the result, not a notice.
|
|
468
|
+
// The registry keeps its own abort semantics; this tool's input
|
|
469
|
+
// controller only ends the wait early, and the catch below reads the
|
|
470
|
+
// reason from the caller's signals.
|
|
471
|
+
let endReleasedRead: (() => void) | undefined
|
|
472
|
+
let releasedBy: string | undefined
|
|
473
|
+
try {
|
|
474
|
+
if (args.wait === true) {
|
|
475
|
+
const input = new AbortController()
|
|
476
|
+
// FIXME: this treats an inbox insertion whose source is `user` as a
|
|
477
|
+
// user steer, but the source only says who authored the message: hooks,
|
|
478
|
+
// subagents, and future hosts also deliver current-step input, and a
|
|
479
|
+
// plugin may label its own context as `user`. The decision to stop
|
|
480
|
+
// waiting belongs to the operation that delivered the input, not to
|
|
481
|
+
// this consumer; a shared steer signal (a broadcast or AbortSignal
|
|
482
|
+
// raised by the user-input entry points) should let waiters subscribe
|
|
483
|
+
// and decide locally instead. Tracked in #5965.
|
|
484
|
+
const checkInput = (): void => {
|
|
485
|
+
// Only a user-authored message releases the wait. Other current-step
|
|
486
|
+
// inputs — completion notices and injected context — stay queued for
|
|
487
|
+
// the next step instead of interrupting a wait the user did not.
|
|
488
|
+
if (agent === undefined || !agent.inbox.nextStep.some(message => message.source.kind === 'user')) return
|
|
489
|
+
if (endReleasedRead === undefined) {
|
|
490
|
+
endReleasedRead = beginReleasedRead(id)
|
|
491
|
+
releasedBy = 'user steered'
|
|
492
|
+
}
|
|
493
|
+
input.abort()
|
|
494
|
+
}
|
|
495
|
+
// Subscribe before reading pending input; each parallel wait owns its
|
|
496
|
+
// listener. The notification follows the durable insertion commit.
|
|
497
|
+
// FIXME: only this wait stops on the signal. Other blocking waits
|
|
498
|
+
// (`wait_agent`, future subagent waits) keep waiting for the same
|
|
499
|
+
// input and need the shared steer signal rather than their own copy of
|
|
500
|
+
// this release logic. Tracked in #5965.
|
|
501
|
+
const unsubscribe = agent === undefined ? () => {} : ctx.on('agent/inbox/inserted', ({ agent: subject }) => {
|
|
502
|
+
if (subject === agent) checkInput()
|
|
503
|
+
})
|
|
504
|
+
try {
|
|
505
|
+
checkInput()
|
|
506
|
+
await jobs.wait(id, Math.min(args.timeout_ms ?? waitDefault, waitCap), agent?.id, AbortSignal.any([exec.signal, input.signal]))
|
|
507
|
+
} catch (error) {
|
|
508
|
+
// The registry reports every abort as a cancellation. A wait this
|
|
509
|
+
// tool released with its own input controller ends the same way,
|
|
510
|
+
// so the abort reason is read from the caller's own signal here.
|
|
511
|
+
if (!input.signal.aborted) throw error
|
|
512
|
+
// An input released this wait, so the read below carries the
|
|
513
|
+
// current state; a cancellation leaves no consumer for that read,
|
|
514
|
+
// and the claim's release delivers the settlement it withheld.
|
|
515
|
+
if (exec.signal.aborted) {
|
|
516
|
+
const aborted = new Error('wait aborted')
|
|
517
|
+
aborted.name = 'AbortError'
|
|
518
|
+
throw aborted
|
|
519
|
+
}
|
|
520
|
+
} finally {
|
|
521
|
+
unsubscribe()
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
const body = readBody(jobs.read(id, exec.agent?.id))
|
|
525
|
+
// This result carries any settlement the released wait suppressed.
|
|
526
|
+
if (releasedBy !== undefined) suppressedSettlements.delete(id)
|
|
527
|
+
const notice = pending.get(id)
|
|
528
|
+
if (notice !== undefined) {
|
|
529
|
+
pending.delete(id)
|
|
530
|
+
// This result covers everything the pending notice reports.
|
|
531
|
+
ctx.get('agents')?.get(notice.owner)?.inbox.remove(notice.messageId)
|
|
532
|
+
body.text = `${notice.held ?? ''}${body.text}`
|
|
533
|
+
}
|
|
534
|
+
// The result, not the schema, explains an interruption: the model sees
|
|
535
|
+
// why a running job came back early beside its unchanged progress line.
|
|
536
|
+
if (releasedBy !== undefined && (body.job.status === 'running' || body.job.status === 'stopping')) {
|
|
537
|
+
body.job.detail = body.job.detail === undefined ? releasedBy : `${body.job.detail}; ${releasedBy}`
|
|
538
|
+
}
|
|
539
|
+
return body
|
|
540
|
+
} finally {
|
|
541
|
+
endReleasedRead?.()
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
presentCall: args => presentJobCall(`Read output from background job ${args.job_id}`, 'read', args.job_id),
|
|
545
|
+
}))
|
|
546
|
+
|
|
547
|
+
ctx.tools.register(defineTool({
|
|
548
|
+
name: 'job_list',
|
|
549
|
+
description: 'List your background jobs (running and finished) with their ids, kinds, and statuses.',
|
|
550
|
+
parameters: {},
|
|
551
|
+
// Listing reads a status snapshot and consumes no output cursor or completion notice.
|
|
552
|
+
isConcurrencySafe: () => true,
|
|
553
|
+
output: {
|
|
554
|
+
schema: { type: 'array', items: PUBLIC_JOB_SCHEMA },
|
|
555
|
+
render: (_args, jobs) => [{
|
|
556
|
+
type: 'text',
|
|
557
|
+
text: jobs.length === 0
|
|
558
|
+
? '(no background jobs)'
|
|
559
|
+
: jobs.map(t => `${t.id} [${t.kind}] ${t.status} — ${t.label}`).join('\n'),
|
|
560
|
+
}],
|
|
561
|
+
},
|
|
562
|
+
execute(_args, exec) {
|
|
563
|
+
const jobs = ctx.jobs.list(exec.agent?.id)
|
|
564
|
+
return Promise.resolve(jobs.map(publicJob))
|
|
565
|
+
},
|
|
566
|
+
presentCall: () => presentJobCall('List background jobs', 'read'),
|
|
567
|
+
}))
|
|
568
|
+
|
|
569
|
+
ctx.tools.register(defineTool({
|
|
570
|
+
name: 'job_kill',
|
|
571
|
+
description: 'Request cancellation of a running background job.',
|
|
572
|
+
parameters: {
|
|
573
|
+
job_id: { type: 'string', required: true, description: 'Job id returned by the tool that started the background work.' },
|
|
574
|
+
reason: { type: 'string', description: 'Optional short reason, recorded in the log and forwarded to the job.' },
|
|
575
|
+
},
|
|
576
|
+
finalizeContent: finalizeJobContent,
|
|
577
|
+
output: {
|
|
578
|
+
schema: {
|
|
579
|
+
type: 'object',
|
|
580
|
+
additionalProperties: false,
|
|
581
|
+
properties: {
|
|
582
|
+
outcome: {
|
|
583
|
+
type: 'string',
|
|
584
|
+
required: true,
|
|
585
|
+
enum: ['cancellation-requested', 'already-finished'],
|
|
586
|
+
},
|
|
587
|
+
job: { ...PUBLIC_JOB_SCHEMA, required: true },
|
|
588
|
+
},
|
|
589
|
+
},
|
|
590
|
+
render: (_args, value) => [{
|
|
591
|
+
type: 'text',
|
|
592
|
+
text: value.outcome === 'already-finished'
|
|
593
|
+
? `job ${value.job.id} had already finished ${statusLine(value.job)}`
|
|
594
|
+
: `requested cancellation of job ${value.job.id}`,
|
|
595
|
+
}],
|
|
596
|
+
},
|
|
597
|
+
execute(args, exec) {
|
|
598
|
+
const id = validateJobId(args.job_id)
|
|
599
|
+
const jobs = ctx.jobs
|
|
600
|
+
const result = jobs.kill(id, exec.agent?.id, args.reason)
|
|
601
|
+
// The model's own kill is its delivery: the settlement notice would only
|
|
602
|
+
// repeat what this tool result already said.
|
|
603
|
+
if (result === 'requested') killedByModel.add(id)
|
|
604
|
+
// A projection describes current state without consuming pending output.
|
|
605
|
+
const job = publicJob(jobs.get(id, exec.agent?.id))
|
|
606
|
+
return Promise.resolve({
|
|
607
|
+
outcome: result === 'already-finished' ? 'already-finished' as const : 'cancellation-requested' as const,
|
|
608
|
+
job,
|
|
609
|
+
})
|
|
610
|
+
},
|
|
611
|
+
presentCall: args => presentJobCall(`Kill background job ${args.job_id}`, 'execute', args.job_id),
|
|
612
|
+
}))
|
|
613
|
+
}
|
package/src/render.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing rendering of registry reads: the consuming delta as the
|
|
3
|
+
* shell tools have always shown it (stdout, then one marked stderr section),
|
|
4
|
+
* the `[status: …]` line, and the public job projection the tool schemas
|
|
5
|
+
* expose.
|
|
6
|
+
* @module @deepseek-ai/dsh-tool-jobs/render
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { JobChunk, JobView } from '@deepseek-ai/dsh-jobs/view'
|
|
10
|
+
|
|
11
|
+
/** Job state safe for model-authored programs; ownership and offsets are omitted. */
|
|
12
|
+
export interface PublicJobSnapshot {
|
|
13
|
+
id: string
|
|
14
|
+
kind: string
|
|
15
|
+
label: string
|
|
16
|
+
status: JobView['status']
|
|
17
|
+
/** The live progress line while running, the terminal reason once settled. */
|
|
18
|
+
detail?: string
|
|
19
|
+
startedAt: number
|
|
20
|
+
finishedAt?: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The one-line qualifier the model reads beside a status: live progress while
|
|
25
|
+
* the job runs, the terminal reason once it settled.
|
|
26
|
+
* @param job - the job projection.
|
|
27
|
+
* @returns the qualifier, or undefined when the job carries neither.
|
|
28
|
+
*/
|
|
29
|
+
export function jobDetail(job: Pick<JobView, 'progress' | 'detail'>): string | undefined {
|
|
30
|
+
return job.progress ?? job.detail
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Remove ownership, offsets, and limits from a registry projection.
|
|
35
|
+
* @param job - the registry projection.
|
|
36
|
+
* @returns the model-safe projection.
|
|
37
|
+
*/
|
|
38
|
+
export function publicJob(job: JobView): PublicJobSnapshot {
|
|
39
|
+
const detail = jobDetail(job)
|
|
40
|
+
return {
|
|
41
|
+
id: job.id,
|
|
42
|
+
kind: job.kind,
|
|
43
|
+
label: job.label,
|
|
44
|
+
status: job.status,
|
|
45
|
+
...detail !== undefined ? { detail } : {},
|
|
46
|
+
startedAt: job.startedAt,
|
|
47
|
+
...job.finishedAt !== undefined ? { finishedAt: job.finishedAt } : {},
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Render generic status with optional detail.
|
|
53
|
+
* @param snapshot - job state to render.
|
|
54
|
+
* @returns a bracketed status line.
|
|
55
|
+
*/
|
|
56
|
+
export function statusLine(snapshot: Pick<PublicJobSnapshot, 'status' | 'detail'>): string {
|
|
57
|
+
return snapshot.detail !== undefined
|
|
58
|
+
? `[status: ${snapshot.status}, ${snapshot.detail}]`
|
|
59
|
+
: `[status: ${snapshot.status}]`
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Render one consuming read for the model: stdout and unlabeled chunks in
|
|
64
|
+
* order, then every stderr chunk in one `[stderr]` section, exactly as the
|
|
65
|
+
* shell tools render a foreground result. `log` chunks are producer
|
|
66
|
+
* narration for observers and never reach the model. Lost bytes — the cursor
|
|
67
|
+
* fell behind the ring's retention, or a model-visible chunk carries a
|
|
68
|
+
* producer-side gap — end the read with the shell tools' dropped-output
|
|
69
|
+
* notice, naming the spill files the job's sources keep.
|
|
70
|
+
* @param chunks - the chunks since the model cursor, in offset order.
|
|
71
|
+
* @param lossy - whether bytes before `chunks` were evicted unread.
|
|
72
|
+
* @param spillPaths - the complete-stream files the job currently advertises (`JobView.output.spillPaths`).
|
|
73
|
+
* @returns the delta text, possibly empty.
|
|
74
|
+
*/
|
|
75
|
+
export function renderModelDelta(chunks: readonly JobChunk[], lossy: boolean, spillPaths: readonly string[]): string {
|
|
76
|
+
const visible = chunks.filter(chunk => chunk.channel !== 'log')
|
|
77
|
+
const out = visible.filter(chunk => chunk.channel !== 'stderr').map(chunk => chunk.text).join('')
|
|
78
|
+
const err = visible.filter(chunk => chunk.channel === 'stderr').map(chunk => chunk.text).join('')
|
|
79
|
+
const separator = out.length > 0 && !out.endsWith('\n') ? '\n' : ''
|
|
80
|
+
const body = out + (err.length > 0 ? `${separator}[stderr]\n${err}` : '')
|
|
81
|
+
if (!lossy && !visible.some(chunk => chunk.gapBefore === true)) return body
|
|
82
|
+
const notice = `[some output was dropped from memory; full output: ${spillPaths.length > 0 ? spillPaths.join(', ') : '(unavailable)'}]`
|
|
83
|
+
return `${body}${body.length > 0 && !body.endsWith('\n') ? '\n' : ''}${notice}`
|
|
84
|
+
}
|