@linxin666/dsh-client-ui-task-board-ssh 0.4.20 → 0.4.22
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 +13 -2
- package/README.zh.md +13 -2
- package/lib/client.js +14 -22
- package/lib/index.js +1071 -89
- package/lib/types/core/contract.d.ts +8 -0
- package/lib/types/core/target.d.ts +6 -0
- package/lib/types/core/task-record.d.ts +11 -0
- package/lib/types/host/board.d.ts +4 -0
- package/lib/types/host/engine.d.ts +145 -0
- package/lib/types/host/extension.d.ts +2 -0
- package/lib/types/host/inspect.d.ts +99 -0
- package/lib/types/host/remote.d.ts +17 -0
- package/lib/types/host/tools.d.ts +5 -3
- package/package.json +14 -14
- package/src/core/contract.ts +5 -0
- package/src/core/ledger.ts +5 -0
- package/src/core/target.ts +10 -3
- package/src/core/task-record.ts +8 -0
- package/src/host/board.ts +4 -0
- package/src/host/engine.ts +430 -6
- package/src/host/extension.ts +6 -0
- package/src/host/inspect.ts +264 -0
- package/src/host/remote.ts +28 -0
- package/src/host/tools.ts +250 -60
package/src/host/tools.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The model-visible tools this extension contributes: `task_board_ssh` (one
|
|
3
|
+
* surface: create, bind, read, run, status, log, followup) and the three older
|
|
4
|
+
* tools, kept as a compatibility layer over the same engine calls.
|
|
3
5
|
*
|
|
4
6
|
* They live with the provider — the board's own agent-tools module never learns
|
|
5
7
|
* SSH vocabulary — and they register through the extension capability face, so
|
|
@@ -16,11 +18,12 @@
|
|
|
16
18
|
import type { ContentBlock } from '@deepseek-ai/dsh-llm'
|
|
17
19
|
import { defineTool, type ToolDefinition } from '@deepseek-ai/dsh-tools'
|
|
18
20
|
import { TASK_BOARD_MESSAGE_MAX_LENGTH, type DshSshHost } from '../core/contract.ts'
|
|
19
|
-
import { SSH_AGENT_KINDS, parseSshTarget, type SshExecutionMode } from '../core/target.ts'
|
|
21
|
+
import { SSH_AGENT_KINDS, parseSshTarget, type SshExecutionMode, type SshTarget } from '../core/target.ts'
|
|
20
22
|
import type { SshRunEngine } from './engine.ts'
|
|
23
|
+
import { SSH_PREFLIGHT_CODES } from './inspect.ts'
|
|
21
24
|
|
|
22
|
-
/** Tool names, in registration order. */
|
|
23
|
-
export const SSH_TOOL_NAMES = ['task_board_ssh_target', 'task_board_ssh_status', 'task_board_ssh_follow_up'] as const
|
|
25
|
+
/** Tool names, in registration order; the first is the one surface, the rest are the compatibility layer. */
|
|
26
|
+
export const SSH_TOOL_NAMES = ['task_board_ssh', 'task_board_ssh_target', 'task_board_ssh_status', 'task_board_ssh_follow_up'] as const
|
|
24
27
|
|
|
25
28
|
/** One tool name. */
|
|
26
29
|
export type SshToolName = (typeof SSH_TOOL_NAMES)[number]
|
|
@@ -129,24 +132,231 @@ function targetFromArgs(args: Record<string, unknown>): unknown {
|
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
|
|
132
|
-
/**
|
|
135
|
+
/** What the error codes of this surface mean, shared by every tool description. */
|
|
136
|
+
const CODE_HELP = 'Stable refusal codes: host-unreachable (alias unknown to dsh-ssh or the host did not answer: fix the alias or the dsh-ssh credentials), agent-missing (the agent name is not one of dsh/claude/codex/custom, or its program is not on the host PATH), path-missing (an in-place directory does not exist; it is never created), permission-required (the directory exists but the ssh user cannot write it, or a human must confirm in the board UI), run-active (the card already has a run in flight: wait for it or cancel it), invalid-target (the other target fields are malformed; issues says which).'
|
|
137
|
+
|
|
138
|
+
/** The target parameters every binding entry shares. */
|
|
139
|
+
const TARGET_PARAMETERS = {
|
|
140
|
+
host: { type: 'string', description: 'dsh-ssh host alias the card addresses (read the available aliases with action "read").' },
|
|
141
|
+
mode: { type: 'string', enum: ['direct', 'proxy'], description: 'direct (default): a headless agent runs on the host, no local session, best for self-contained jobs; proxy: a local session drives the host through ssh_* tools, best when the work needs local context or tools.' },
|
|
142
|
+
// Deliberately not an enum: a bad name must reach the handler and come back as the stable agent-missing code, not as a schema error.
|
|
143
|
+
agent: { type: 'string', description: `Agent CLI the remote run starts: ${SSH_AGENT_KINDS.join(', ')} (default dsh; custom needs agentCommand). Its program must exist on the host; any other name is refused with agent-missing.` },
|
|
144
|
+
workspaceKind: { type: 'string', enum: ['in-place', 'git'], description: 'in-place (default): work directly inside the existing remote directory workspacePath, nothing is copied or cleaned up; git: a per-run worktree on its own branch dsh-task/<runId>, from repositoryUrl or the local repository workspaceId.' },
|
|
145
|
+
workspacePath: { type: 'string', description: 'Absolute remote directory of an in-place target. It must exist and be writable.' },
|
|
146
|
+
repositoryUrl: { type: 'string', description: 'Clone URL a git target prepares its worktree from, when the host can reach it.' },
|
|
147
|
+
repositoryBase: { type: 'string', description: 'Base branch that worktree starts from; the remote HEAD when absent.' },
|
|
148
|
+
workspaceId: { type: 'string', description: 'Local workspace id a git target runs from, when its repository is not reachable from the host.' },
|
|
149
|
+
agentCommand: { type: 'string', description: 'Start command template of a custom agent; must reference {prompt_file}.' },
|
|
150
|
+
agentResumeCommand: { type: 'string', description: 'Resume command template of a custom agent; without one a follow-up runs fresh.' },
|
|
151
|
+
preflight: { type: 'boolean', description: 'Check the host, the agent program and the directory before binding (default true).' },
|
|
152
|
+
} as const
|
|
153
|
+
|
|
154
|
+
/** Read a boolean argument; undefined when absent. */
|
|
155
|
+
function flag(value: unknown): boolean | undefined {
|
|
156
|
+
return typeof value === 'boolean' ? value : undefined
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Parse the flat target arguments, mapping parser issues onto the stable codes
|
|
161
|
+
* the caller can act on: a bad host alias or agent name is a host/agent refusal,
|
|
162
|
+
* anything else stays `invalid-target`.
|
|
163
|
+
*/
|
|
164
|
+
function parseTarget(args: Record<string, unknown>): { ok: true; target: SshTarget } | { ok: false; reply: Json } {
|
|
165
|
+
const parsed = parseSshTarget(targetFromArgs(args))
|
|
166
|
+
if (parsed.ok) return { ok: true, target: parsed.value }
|
|
167
|
+
const first = parsed.errors[0]
|
|
168
|
+
const issues = parsed.errors.map(issue => ({ path: issue.path, message: issue.message }))
|
|
169
|
+
if (first !== undefined && first.path === 'host') {
|
|
170
|
+
return { ok: false, reply: json({ ok: false, code: 'host-unreachable', message: `host ${JSON.stringify(text(args.host) ?? '')} is not a valid dsh-ssh alias. Read the configured aliases with task_board_ssh {action:"read"} and pass one of them.`, issues }) }
|
|
171
|
+
}
|
|
172
|
+
if (first !== undefined && first.path.startsWith('agent') && !(SSH_AGENT_KINDS as readonly string[]).includes(String(args.agent ?? 'dsh'))) {
|
|
173
|
+
return { ok: false, reply: json({ ok: false, code: 'agent-missing', message: `agent ${JSON.stringify(args.agent)} is not supported. Use one of: ${SSH_AGENT_KINDS.join(', ')}.`, issues }) }
|
|
174
|
+
}
|
|
175
|
+
return { ok: false, reply: json({ ok: false, code: 'invalid-target', message: 'the target is malformed; issues lists each field.', issues }) }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Run the preflight and answer its refusal as a tool reply, or undefined when the target is usable. */
|
|
179
|
+
async function preflightReply(engine: SshRunEngine, target: SshTarget, args: Record<string, unknown>): Promise<Json | undefined> {
|
|
180
|
+
if (flag(args.preflight) === false) return undefined
|
|
181
|
+
const failure = await engine.preflight(target)
|
|
182
|
+
return failure === undefined ? undefined : json({ ok: false, code: failure.code, message: failure.message, hint: failure.hint })
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Bind a target to an existing card, after parsing and preflight. */
|
|
186
|
+
async function bindResult(engine: SshRunEngine, taskId: string, args: Record<string, unknown>): Promise<Json> {
|
|
187
|
+
const parsed = parseTarget(args)
|
|
188
|
+
if (!parsed.ok) return parsed.reply
|
|
189
|
+
const refusal = await preflightReply(engine, parsed.target, args)
|
|
190
|
+
if (refusal !== undefined) return refusal
|
|
191
|
+
const reply = engine.setTarget(taskId, parsed.target)
|
|
192
|
+
if (!reply.ok) return refused(reply.code, reply.error)
|
|
193
|
+
return json({ ok: true, target: parsed.target, preflight: flag(args.preflight) === false ? 'skipped' : 'passed', hosts: hostViews(engine) })
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** One run in the uniform shape, optionally blocking until it settles. */
|
|
197
|
+
async function statusResult(engine: SshRunEngine, taskId: string, args: Record<string, unknown>): Promise<Json> {
|
|
198
|
+
const wait = args.wait === true
|
|
199
|
+
const waited = wait ? await engine.waitStatus(taskId, count(args.timeoutMs)) : undefined
|
|
200
|
+
const view = waited?.view ?? engine.statusView(taskId)
|
|
201
|
+
const running = !view.settled && view.phase !== 'none'
|
|
202
|
+
const activity = running && flag(args.activity) !== false ? await engine.activityOf(taskId) : undefined
|
|
203
|
+
return json({
|
|
204
|
+
ok: true,
|
|
205
|
+
...view,
|
|
206
|
+
...(waited === undefined ? {} : { timedOut: waited.timedOut }),
|
|
207
|
+
...(activity === undefined ? {} : { lastActivity: activity }),
|
|
208
|
+
...(view.settled ? { next: 'The run settled; the verdict is on the card (task_board_get) and the log is still readable with action "log".' } : running ? { next: 'Still running: call status again with wait:true, or read progress with action "log".' } : {}),
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** One filtered page of the log, with its cost stated first. */
|
|
213
|
+
async function logResult(engine: SshRunEngine, taskId: string, args: Record<string, unknown>): Promise<Json> {
|
|
214
|
+
const runId = text(args.runId)
|
|
215
|
+
const tail = count(args.tail)
|
|
216
|
+
const since = count(args.since)
|
|
217
|
+
const maxBytes = count(args.maxBytes)
|
|
218
|
+
const page = await engine.queryLog(taskId, {
|
|
219
|
+
...(runId === undefined ? {} : { runId }),
|
|
220
|
+
...(tail === undefined ? {} : { tail }),
|
|
221
|
+
...(since === undefined ? {} : { since }),
|
|
222
|
+
...(maxBytes === undefined ? {} : { maxBytes }),
|
|
223
|
+
...(args.raw === true ? { raw: true } : {}),
|
|
224
|
+
...(args.statsOnly === true ? { statsOnly: true } : {}),
|
|
225
|
+
})
|
|
226
|
+
if (!page.ok) return json({ ok: false, code: page.code, message: page.error })
|
|
227
|
+
return json({
|
|
228
|
+
ok: true,
|
|
229
|
+
runId: page.runId,
|
|
230
|
+
filtered: page.filtered,
|
|
231
|
+
stats: { rawBytes: page.stats.rawBytes, filteredLines: page.stats.lines, filteredBytes: page.stats.bytes },
|
|
232
|
+
from: page.from,
|
|
233
|
+
lines: page.lines,
|
|
234
|
+
nextSince: page.nextSince,
|
|
235
|
+
more: page.more,
|
|
236
|
+
text: page.text,
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Queue one instruction for the card's remote session. */
|
|
241
|
+
async function followUpResult(engine: SshRunEngine, args: Record<string, unknown>): Promise<Json> {
|
|
242
|
+
const taskId = text(args.taskId)
|
|
243
|
+
const rawText = typeof args.text === 'string' ? args.text : ''
|
|
244
|
+
const instruction = rawText.trim()
|
|
245
|
+
if (taskId === undefined) return refused('task-required', 'taskId is required')
|
|
246
|
+
if (instruction === '') return refused('text-required', 'text must be a non-blank instruction')
|
|
247
|
+
if (rawText.length > TASK_BOARD_MESSAGE_MAX_LENGTH) {
|
|
248
|
+
return refused('text-too-long', `text must be at most ${TASK_BOARD_MESSAGE_MAX_LENGTH} characters`)
|
|
249
|
+
}
|
|
250
|
+
const rawKind = args.kind
|
|
251
|
+
if (rawKind !== undefined && rawKind !== 'follow-up' && rawKind !== 'rework') {
|
|
252
|
+
return refused('invalid-kind', 'kind must be "follow-up" or "rework"')
|
|
253
|
+
}
|
|
254
|
+
const kind = rawKind ?? 'follow-up'
|
|
255
|
+
try {
|
|
256
|
+
const reply = await engine.instruct(taskId, instruction, kind)
|
|
257
|
+
if (!reply.ok) return refused(reply.code, reply.error)
|
|
258
|
+
return json({
|
|
259
|
+
ok: true,
|
|
260
|
+
taskId: reply.taskId,
|
|
261
|
+
...(reply.runId === undefined ? {} : { runId: reply.runId }),
|
|
262
|
+
...(reply.phase === undefined ? {} : { phase: reply.phase }),
|
|
263
|
+
message: reply.message ?? '',
|
|
264
|
+
})
|
|
265
|
+
} catch (error) {
|
|
266
|
+
return refused('follow-up-failed', messageOf(error))
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** The run handle plus, when asked, the settled status: what one `run` answers. */
|
|
271
|
+
async function runResult(engine: SshRunEngine, taskId: string, args: Record<string, unknown>): Promise<Json> {
|
|
272
|
+
const reply = await engine.runCard(taskId)
|
|
273
|
+
if (!reply.ok) return refused(reply.code, reply.error)
|
|
274
|
+
const handle = engine.describeRun(taskId)
|
|
275
|
+
const status = args.wait === true ? await statusResult(engine, taskId, args) : undefined
|
|
276
|
+
return json({ ok: true, taskId, ...handle, ...(status === undefined ? {} : { status }) })
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** The one surface: every action an agent needs against a remote card. */
|
|
280
|
+
function buildUnifiedTool(engine: SshRunEngine): ToolDefinition {
|
|
281
|
+
return defineTool({
|
|
282
|
+
name: 'task_board_ssh',
|
|
283
|
+
description: [
|
|
284
|
+
'Run a task board card on a remote host over SSH, end to end, with the fewest calls: task_board_ssh {action:"create", title, prompt, host, workspacePath, run:true, wait:true} creates the card WITH its target, checks the host/agent/directory first, starts the run and blocks until it settles - one call.',
|
|
285
|
+
'Actions: create (new card bound to a target; run:true starts it, wait:true blocks for the verdict), bind (set or replace the target of an existing card), read (current target plus the host aliases), run (start a bound direct card and get its handle: executionId, runId, logPath, target, estimatedDurationMs), status (one uniform shape whether running or settled: phase, exitCode, result, summary, error{code,message,retryHint}, durationMs, remoteSessionId, lastActivityAt, plus lastActivity = the agent\'s last tool call while running; wait:true with timeoutMs blocks until it settles), log (the run log with thinking_tokens/system noise removed; tail N lines or since a cursor, at most 64 KB per reply, stats.filteredLines/filteredBytes tell the cost first; statsOnly:true returns only the counts; raw:true skips the filter), followup (one more instruction for the remote session; kind rework asks again for wrong work).',
|
|
286
|
+
'Choosing a target: direct mode is for self-contained jobs and keeps no local session; proxy mode runs a local session that drives the host and fits work needing local context. in-place edits an existing remote directory; git makes a per-run worktree on branch dsh-task/<runId>. Agents: dsh, claude, codex, custom.',
|
|
287
|
+
'A succeeded run records its conclusion as the execution summary; error carries failures only. ' + CODE_HELP,
|
|
288
|
+
].join(' '),
|
|
289
|
+
parameters: {
|
|
290
|
+
action: { type: 'string', required: true, enum: ['create', 'bind', 'read', 'run', 'status', 'log', 'followup'], description: 'What to do; see the tool description.' },
|
|
291
|
+
taskId: { type: 'string', description: 'Card to act on. Required by every action except create.' },
|
|
292
|
+
title: { type: 'string', description: 'create: card title (one line).' },
|
|
293
|
+
prompt: { type: 'string', description: 'create: the instruction the remote agent runs; the title when blank.' },
|
|
294
|
+
description: { type: 'string', description: 'create: longer human description.' },
|
|
295
|
+
parentId: { type: 'string', description: 'create: parent card id, to make a subtask.' },
|
|
296
|
+
run: { type: 'boolean', description: 'create: start the run right after creating the card.' },
|
|
297
|
+
wait: { type: 'boolean', description: 'create (with run), run and status: block until the run settles or timeoutMs passes.' },
|
|
298
|
+
timeoutMs: { type: 'number', description: 'Longest a wait blocks, in milliseconds (default 120000, at most 600000). A timeout is not a failure: the run keeps going, call status with wait again.' },
|
|
299
|
+
activity: { type: 'boolean', description: 'status: include lastActivity while running (default true).' },
|
|
300
|
+
tail: { type: 'number', description: 'log: last N filtered lines (default 40).' },
|
|
301
|
+
since: { type: 'number', description: 'log: first filtered line to return, the nextSince of an earlier reply.' },
|
|
302
|
+
raw: { type: 'boolean', description: 'log: skip the noise filter.' },
|
|
303
|
+
statsOnly: { type: 'boolean', description: 'log: return only the filtered line count and size.' },
|
|
304
|
+
maxBytes: { type: 'number', description: 'log: cap on the returned text in bytes (default 65536, at most 131072).' },
|
|
305
|
+
runId: { type: 'string', description: 'log: a specific earlier run; the latest when absent.' },
|
|
306
|
+
text: { type: 'string', description: 'followup: the instruction itself.' },
|
|
307
|
+
kind: { type: 'string', enum: ['follow-up', 'rework'], description: 'followup: follow-up adds work; rework asks again for work the previous run got wrong.' },
|
|
308
|
+
...TARGET_PARAMETERS,
|
|
309
|
+
},
|
|
310
|
+
output: { schema: { type: 'json' }, render: renderJson },
|
|
311
|
+
async execute(rawArgs) {
|
|
312
|
+
const args = rawArgs as Record<string, unknown>
|
|
313
|
+
const action = text(args.action)
|
|
314
|
+
const taskId = text(args.taskId)
|
|
315
|
+
if (action === 'create') {
|
|
316
|
+
const prompt = text(args.prompt) ?? text(args.title)
|
|
317
|
+
const title = text(args.title) ?? (prompt === undefined ? undefined : prompt.split('\n')[0]?.slice(0, 80))
|
|
318
|
+
if (title === undefined || prompt === undefined) return refused('title-required', 'create needs a title or a prompt')
|
|
319
|
+
const parsed = parseTarget(args)
|
|
320
|
+
if (!parsed.ok) return parsed.reply
|
|
321
|
+
const target = parsed.target
|
|
322
|
+
if (flag(args.preflight) !== false) {
|
|
323
|
+
const refusal = await preflightReply(engine, target, args)
|
|
324
|
+
if (refusal !== undefined) return refusal
|
|
325
|
+
}
|
|
326
|
+
const created = await engine.createBound({
|
|
327
|
+
title,
|
|
328
|
+
prompt,
|
|
329
|
+
...(text(args.description) === undefined ? {} : { description: text(args.description) as string }),
|
|
330
|
+
...(text(args.parentId) === undefined ? {} : { parentId: text(args.parentId) as string }),
|
|
331
|
+
}, target, { preflight: false })
|
|
332
|
+
if (!created.ok) return refused(created.code, created.error)
|
|
333
|
+
if (args.run !== true) return json({ ok: true, taskId: created.taskId, target, next: 'Start it with task_board_ssh {action:"run"} or task_board_run.' })
|
|
334
|
+
return json({ created: true, ...(await runResult(engine, created.taskId, args) as Record<string, Json>) })
|
|
335
|
+
}
|
|
336
|
+
if (action === 'read' && taskId === undefined) return json({ ok: true, target: null, hosts: hostViews(engine) })
|
|
337
|
+
if (taskId === undefined) return refused('task-required', 'taskId is required')
|
|
338
|
+
switch (action) {
|
|
339
|
+
case 'read': return json({ ok: true, target: engine.targetOf(taskId) ?? null, hosts: hostViews(engine) })
|
|
340
|
+
case 'bind': return await bindResult(engine, taskId, args)
|
|
341
|
+
case 'run': return await runResult(engine, taskId, args)
|
|
342
|
+
case 'status': return await statusResult(engine, taskId, args)
|
|
343
|
+
case 'log': return await logResult(engine, taskId, args)
|
|
344
|
+
case 'followup': return await followUpResult(engine, args)
|
|
345
|
+
default: return refused('unknown-action', 'action must be create, bind, read, run, status, log or followup')
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
})
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** The target tool (compatibility): read or pin where one card runs. */
|
|
133
352
|
function buildTargetTool(engine: SshRunEngine): ToolDefinition {
|
|
134
353
|
return defineTool({
|
|
135
354
|
name: 'task_board_ssh_target',
|
|
136
|
-
description: 'Read or pin the SSH execution target of one task board card
|
|
355
|
+
description: 'Compatibility entry of task_board_ssh (actions read and bind). Read or pin the SSH execution target of one task board card; pinning now checks the host, the agent program and the directory first and refuses with a stable code before anything is saved. direct mode starts a headless agent on the host and keeps no local session; proxy mode runs a local session that drives the host. ' + CODE_HELP,
|
|
137
356
|
parameters: {
|
|
138
357
|
action: { type: 'string', required: true, enum: ['read', 'set'], description: 'read reports the current pin and the hosts available; set stores a new pin.' },
|
|
139
358
|
taskId: { type: 'string', required: true, description: 'Card to read or retarget.' },
|
|
140
|
-
|
|
141
|
-
host: { type: 'string', description: 'dsh-ssh host alias the card addresses. Required by set.' },
|
|
142
|
-
agent: { type: 'string', enum: [...SSH_AGENT_KINDS], description: 'Agent CLI the remote run starts (default dsh).' },
|
|
143
|
-
workspaceKind: { type: 'string', enum: ['in-place', 'git'], description: 'in-place works in an existing remote directory; git creates a per-run worktree. Defaults to in-place.' },
|
|
144
|
-
workspacePath: { type: 'string', description: 'Absolute remote directory of an in-place target.' },
|
|
145
|
-
repositoryUrl: { type: 'string', description: 'Clone URL a git target prepares its worktree from, when the host can reach it.' },
|
|
146
|
-
repositoryBase: { type: 'string', description: 'Base branch that worktree starts from; the remote HEAD when absent.' },
|
|
147
|
-
workspaceId: { type: 'string', description: 'Local workspace id a git target runs from, when its repository is not reachable from the host.' },
|
|
148
|
-
agentCommand: { type: 'string', description: 'Start command template of a custom agent; must reference {prompt_file}.' },
|
|
149
|
-
agentResumeCommand: { type: 'string', description: 'Resume command template of a custom agent; without one a follow-up runs fresh.' },
|
|
359
|
+
...TARGET_PARAMETERS,
|
|
150
360
|
},
|
|
151
361
|
output: { schema: { type: 'json' }, render: renderJson },
|
|
152
362
|
async execute(args) {
|
|
@@ -158,57 +368,61 @@ function buildTargetTool(engine: SshRunEngine): ToolDefinition {
|
|
|
158
368
|
return json({ ok: true, target: target ?? null, hosts: hostViews(engine) })
|
|
159
369
|
}
|
|
160
370
|
if (action !== 'set') return refused('unknown-action', 'action must be read or set')
|
|
161
|
-
|
|
162
|
-
if (!parsed.ok) {
|
|
163
|
-
return json({ ok: false, code: 'invalid-target', issues: parsed.errors.map(issue => ({ path: issue.path, message: issue.message })) })
|
|
164
|
-
}
|
|
165
|
-
const reply = engine.setTarget(taskId, parsed.value)
|
|
166
|
-
if (!reply.ok) return refused(reply.code, reply.error)
|
|
167
|
-
return json({ ok: true, target: parsed.value, hosts: hostViews(engine) })
|
|
371
|
+
return await bindResult(engine, taskId, args as Record<string, unknown>)
|
|
168
372
|
},
|
|
169
373
|
})
|
|
170
374
|
}
|
|
171
375
|
|
|
172
|
-
/** The status tool: one card's remote run, and optionally a page of its log. */
|
|
376
|
+
/** The status tool (compatibility): one card's remote run, and optionally a page of its log. */
|
|
173
377
|
function buildStatusTool(engine: SshRunEngine): ToolDefinition {
|
|
174
378
|
return defineTool({
|
|
175
379
|
name: 'task_board_ssh_status',
|
|
176
|
-
description: 'Read the remote run state of one
|
|
380
|
+
description: 'Compatibility entry of task_board_ssh (actions status and log). Read the remote run state of one card. `state` is the uniform shape (phase, exitCode, result, summary, error, durationMs, remoteSessionId, lastActivityAt) for a running and a settled run alike; wait:true with timeoutMs blocks until it settles. `status` keeps the older shape with the run history. Pass logOffset/logLimit for one raw byte page of the log, or tail/since for the filtered log (at most 64 KB by default).',
|
|
177
381
|
parameters: {
|
|
178
382
|
taskId: { type: 'string', required: true, description: 'Card whose remote run to inspect.' },
|
|
383
|
+
wait: { type: 'boolean', description: 'Block until the run settles or timeoutMs passes.' },
|
|
384
|
+
timeoutMs: { type: 'number', description: 'Longest a wait blocks, in milliseconds (default 120000, at most 600000).' },
|
|
179
385
|
runId: { type: 'string', description: 'One specific run to read the log of; the active run when absent.' },
|
|
180
|
-
|
|
181
|
-
|
|
386
|
+
tail: { type: 'number', description: 'Filtered log: last N lines.' },
|
|
387
|
+
since: { type: 'number', description: 'Filtered log: first line to return (nextSince of an earlier reply).' },
|
|
388
|
+
raw: { type: 'boolean', description: 'Filtered log: skip the noise filter.' },
|
|
389
|
+
logOffset: { type: 'number', description: 'Raw byte offset the log page starts at (default 0).' },
|
|
390
|
+
logLimit: { type: 'number', description: 'Largest raw page to return, in bytes (default 65536, at most 131072).' },
|
|
182
391
|
},
|
|
183
392
|
output: { schema: { type: 'json' }, render: renderJson },
|
|
184
|
-
async execute(
|
|
393
|
+
async execute(rawArgs) {
|
|
394
|
+
const args = rawArgs as Record<string, unknown>
|
|
185
395
|
const taskId = text(args.taskId)
|
|
186
396
|
if (taskId === undefined) return refused('task-required', 'taskId is required')
|
|
397
|
+
const state = await statusResult(engine, taskId, args)
|
|
187
398
|
const status = engine.status(taskId)
|
|
188
399
|
const runId = text(args.runId)
|
|
189
400
|
const offset = count(args.logOffset)
|
|
190
401
|
const limit = count(args.logLimit)
|
|
191
|
-
|
|
402
|
+
const filtered = count(args.tail) !== undefined || count(args.since) !== undefined
|
|
403
|
+
if (filtered) return json({ ok: true, status, state, log: await logResult(engine, taskId, args) })
|
|
404
|
+
if (runId === undefined && offset === undefined && limit === undefined) return json({ ok: true, status, state })
|
|
192
405
|
const page = await engine.readLog(taskId, {
|
|
193
406
|
...(runId === undefined ? {} : { runId }),
|
|
194
407
|
...(offset === undefined ? {} : { offset }),
|
|
195
408
|
...(limit === undefined ? {} : { limit }),
|
|
196
409
|
})
|
|
197
|
-
if (!page.ok) return json({ ok: false, status, code: page.code, message: page.error })
|
|
410
|
+
if (!page.ok) return json({ ok: false, status, state, code: page.code, message: page.error })
|
|
198
411
|
return json({
|
|
199
412
|
ok: true,
|
|
200
413
|
status,
|
|
414
|
+
state,
|
|
201
415
|
log: { runId: page.runId, offset: page.offset, nextOffset: page.nextOffset, bytes: page.bytes, eof: page.eof, text: page.text },
|
|
202
416
|
})
|
|
203
417
|
},
|
|
204
418
|
})
|
|
205
419
|
}
|
|
206
420
|
|
|
207
|
-
/** The follow-up tool: one more instruction for the card's remote session. */
|
|
421
|
+
/** The follow-up tool (compatibility): one more instruction for the card's remote session. */
|
|
208
422
|
function buildFollowUpTool(engine: SshRunEngine): ToolDefinition {
|
|
209
423
|
return defineTool({
|
|
210
424
|
name: 'task_board_ssh_follow_up',
|
|
211
|
-
description: 'Send one more instruction to the remote agent session of a task board card. On a card whose run is still going the instruction waits for that run to finish and then continues the same remote session; on a settled card it re-enters the card run with the earlier session resumed. An agent that cannot resume degrades to a fresh run that carries the previous summary, which the execution record says.',
|
|
425
|
+
description: 'Compatibility entry of task_board_ssh (action followup). Send one more instruction to the remote agent session of a task board card. On a card whose run is still going the instruction waits for that run to finish and then continues the same remote session; on a settled card it re-enters the card run with the earlier session resumed. An agent that cannot resume degrades to a fresh run that carries the previous summary, which the execution record says.',
|
|
212
426
|
parameters: {
|
|
213
427
|
taskId: { type: 'string', required: true, description: 'Card whose remote session receives the instruction.' },
|
|
214
428
|
text: { type: 'string', required: true, description: 'The instruction itself.' },
|
|
@@ -216,32 +430,7 @@ function buildFollowUpTool(engine: SshRunEngine): ToolDefinition {
|
|
|
216
430
|
},
|
|
217
431
|
output: { schema: { type: 'json' }, render: renderJson },
|
|
218
432
|
async execute(args) {
|
|
219
|
-
|
|
220
|
-
const rawText = typeof args.text === 'string' ? args.text : ''
|
|
221
|
-
const instruction = rawText.trim()
|
|
222
|
-
if (taskId === undefined) return refused('task-required', 'taskId is required')
|
|
223
|
-
if (instruction === '') return refused('text-required', 'text must be a non-blank instruction')
|
|
224
|
-
if (rawText.length > TASK_BOARD_MESSAGE_MAX_LENGTH) {
|
|
225
|
-
return refused('text-too-long', `text must be at most ${TASK_BOARD_MESSAGE_MAX_LENGTH} characters`)
|
|
226
|
-
}
|
|
227
|
-
const rawKind = args.kind
|
|
228
|
-
if (rawKind !== undefined && rawKind !== 'follow-up' && rawKind !== 'rework') {
|
|
229
|
-
return refused('invalid-kind', 'kind must be "follow-up" or "rework"')
|
|
230
|
-
}
|
|
231
|
-
const kind = rawKind ?? 'follow-up'
|
|
232
|
-
try {
|
|
233
|
-
const reply = await engine.instruct(taskId, instruction, kind)
|
|
234
|
-
if (!reply.ok) return refused(reply.code, reply.error)
|
|
235
|
-
return json({
|
|
236
|
-
ok: true,
|
|
237
|
-
taskId: reply.taskId,
|
|
238
|
-
...(reply.runId === undefined ? {} : { runId: reply.runId }),
|
|
239
|
-
...(reply.phase === undefined ? {} : { phase: reply.phase }),
|
|
240
|
-
message: reply.message ?? '',
|
|
241
|
-
})
|
|
242
|
-
} catch (error) {
|
|
243
|
-
return refused('follow-up-failed', messageOf(error))
|
|
244
|
-
}
|
|
433
|
+
return await followUpResult(engine, args as Record<string, unknown>)
|
|
245
434
|
},
|
|
246
435
|
})
|
|
247
436
|
}
|
|
@@ -252,8 +441,9 @@ function buildFollowUpTool(engine: SshRunEngine): ToolDefinition {
|
|
|
252
441
|
* @returns the tool definitions, in registration order.
|
|
253
442
|
*/
|
|
254
443
|
export function buildSshTools(engine: SshRunEngine): ToolDefinition[] {
|
|
255
|
-
return [buildTargetTool(engine), buildStatusTool(engine), buildFollowUpTool(engine)]
|
|
444
|
+
return [buildUnifiedTool(engine), buildTargetTool(engine), buildStatusTool(engine), buildFollowUpTool(engine)]
|
|
256
445
|
}
|
|
257
446
|
|
|
258
|
-
/** Re-exported for the specs: the modes a target may pin. */
|
|
447
|
+
/** Re-exported for the specs: the modes a target may pin and the stable preflight codes. */
|
|
259
448
|
export type { SshExecutionMode }
|
|
449
|
+
export { SSH_PREFLIGHT_CODES }
|