index.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. /**
  2. * Model-facing `bash`, `bash_output`, and `bash_kill` tools over the executor
  3. * seam. Background tasks are fenced by owning session, completion injects a
  4. * durable notice, and confining executors add one-shot approval-based escalation.
  5. * Notices do not wake idle agents. Ownership is stored with the executor task so
  6. * it survives this plugin's reload; per-call authority is escalation grant,
  7. * session override, then executor default. See the package README for the tool contract.
  8. * @module @deepseek-ai/dsh-tool-bash
  9. */
  10. import type { Context } from 'cordis'
  11. import { isAbsolute, resolve as resolvePath } from 'node:path'
  12. import { defineTool } from '@deepseek-ai/dsh-tools'
  13. import type { GenericCallView, TerminalCallView, ToolExecution, ToolResult, ToolResultView } from '@deepseek-ai/dsh-tools'
  14. import type { Agent } from '@deepseek-ai/dsh-agent'
  15. import { assertNever } from '@deepseek-ai/dsh-llm'
  16. import type {} from '@deepseek-ai/dsh-system-prompt'
  17. // Side-effect type import: declaration-merges `ctx.approval`, consumed
  18. // opportunistically by the escalation gate (`ctx.get('approval')` — the seam
  19. // stays optional at runtime, same pattern as dsh-tools' ask routing).
  20. import type {} from '@deepseek-ai/dsh-user-approval'
  21. import type { SandboxMode } from '@deepseek-ai/dsh-sandbox'
  22. import { BashTaskId, OwnerToken, effectiveSandboxMode } from '@deepseek-ai/dsh-bash'
  23. import type { BashRunResult, BashTask, CollectedOutput } from '@deepseek-ai/dsh-bash'
  24. export const name = 'tool-bash'
  25. export const inject = ['tools', 'bash', 'systemPrompt']
  26. /**
  27. * Validate value constraints absent from SchemaSpec: non-empty strings, a
  28. * positive finite timeout, and paired escalation mode and justification.
  29. */
  30. function validateBashArgs(args: BashToolArgs): void {
  31. if (args.command.trim().length === 0) {
  32. throw new Error('invalid command: expected a non-empty string')
  33. }
  34. if (args.description.trim().length === 0) {
  35. throw new Error('invalid description: expected a non-empty string')
  36. }
  37. if (args.timeoutMs !== undefined && (!Number.isFinite(args.timeoutMs) || args.timeoutMs <= 0)) {
  38. throw new Error(`invalid timeoutMs: expected a positive number, got ${JSON.stringify(args.timeoutMs)}`)
  39. }
  40. if (args.sandbox_permissions !== undefined && args.justification === undefined) {
  41. throw new Error('invalid escalation: sandbox_permissions requires a justification')
  42. }
  43. if (args.justification !== undefined && args.sandbox_permissions === undefined) {
  44. throw new Error('invalid escalation: justification is only valid together with sandbox_permissions')
  45. }
  46. if (args.justification !== undefined && args.justification.trim().length === 0) {
  47. throw new Error('invalid justification: expected a non-empty sentence')
  48. }
  49. }
  50. /**
  51. * Reject an empty `task_id`; SchemaSpec already validates type and presence.
  52. */
  53. function validateTaskId(value: string): BashTaskId {
  54. if (value.length === 0) {
  55. throw new Error(`invalid task_id: expected a string, got ${JSON.stringify(value)}`)
  56. }
  57. return BashTaskId(value)
  58. }
  59. /**
  60. * Validated bash arguments. Escalation fields are advertised only when the
  61. * mounted executor reports a confining mode.
  62. */
  63. interface BashToolArgs {
  64. command: string
  65. description: string
  66. timeoutMs?: number
  67. workdir?: string
  68. run_in_background?: boolean
  69. sandbox_permissions?: string
  70. justification?: string
  71. }
  72. /**
  73. * Strictly wider modes for each effective mode. Execution checks this table
  74. * because the schema is global while the effective mode is per call.
  75. */
  76. const WIDER_MODES: Record<string, readonly SandboxMode[]> = {
  77. 'read-only': ['workspace-write', 'danger-full-access'],
  78. 'workspace-write': ['danger-full-access'],
  79. }
  80. /**
  81. * All possible escalation targets. Advertise the global set because a session
  82. * override may be narrower than the executor default; execution rejects a
  83. * target that is not wider for that call.
  84. */
  85. const ESCALATION_TARGETS: readonly SandboxMode[] = ['workspace-write', 'danger-full-access']
  86. /**
  87. * The bash tool's byte-stable base description. Escalation guidance is added
  88. * only when the mounted executor can honor it, as the one exception to the
  89. * ordinary no-retry guidance.
  90. */
  91. function bashDescription(escalationModes: readonly SandboxMode[]): string {
  92. const base = 'Execute a bash command (`bash -c`) and return its stdout/stderr. '
  93. + 'Each call runs in a fresh shell: no state (cwd, variables, functions) persists between calls — '
  94. + 'pass `workdir` instead of using `cd`. Non-zero exits are reported as `[exit code: N]`. '
  95. + 'Commands may run under a file sandbox; a blocked file operation is reported as `[sandbox: file access denied under <mode> mode]` — a policy denial, not a bug in the command; do not retry another way (a background task reports the same marker via bash_output once it has finished). '
  96. + 'Long output is truncated to its tail; the full output is saved to a file whose path is reported when available. '
  97. + 'Set `run_in_background: true` for long-running commands: the call returns a task id immediately; '
  98. + 'poll it with `bash_output` and stop it with `bash_kill`.'
  99. if (escalationModes.length === 0) return base
  100. return base + ' Attempting a command the sandbox may deny is safe and expected: run it and read the '
  101. + 'marker rather than assuming the denial. When a command is denied and a wider mode would let it '
  102. + 'succeed, escalate immediately in the same turn — the one sanctioned exception to a denial: retry '
  103. + 'the exact same command once with `sandbox_permissions` (the narrowest wider mode that suffices) '
  104. + 'plus a one-sentence `justification`. Do not detour through chat to ask permission first — the '
  105. + 'approval prompt raised by that retry is how the user consents. If the session states approval '
  106. + 'prompts are disabled, there is no exception: a denial is final — do not set `sandbox_permissions`. '
  107. + 'Never escalate speculatively: ground the request in a real denial — normally the one this command '
  108. + 'just hit; escalating up front is fine only when this session already denied the same access. '
  109. + 'A rejected escalation is final for that command — stop and explain, never work around '
  110. + 'it — but it does not forbid attempting or escalating other commands later.'
  111. }
  112. /** Append the truncation notice (with the full-output spill path) to a stream's text. */
  113. function streamText(output: CollectedOutput): string {
  114. if (!output.truncated) return output.text
  115. return `${output.text}\n[output truncated; full output: ${output.spillPath ?? '(unavailable)'}]`
  116. }
  117. /**
  118. * Shape one finished run into model-visible stdout, marked stderr, and status
  119. * facts. Non-zero exits and sandbox denials remain ordinary results; only
  120. * infrastructure failure or abort makes the tool call itself fail.
  121. *
  122. * @param result - the completed foreground run from the executor.
  123. * @param escalationModes - the escalation targets this composition advertises; non-empty
  124. * adds the same-turn escalation hint after a denial marker (default `[]`: no hint).
  125. * @returns the model-facing text: output body (or `(no output)`), then any
  126. * timeout/signal/exit markers, each on its own line.
  127. */
  128. export function renderResult(
  129. result: BashRunResult,
  130. escalationModes: readonly SandboxMode[] = [],
  131. ): string {
  132. const out = streamText(result.stdout)
  133. const err = streamText(result.stderr)
  134. let body = out
  135. if (err.length > 0) {
  136. // Single newline between sections (stdout usually ends with one already).
  137. if (body.length > 0 && !body.endsWith('\n')) body += '\n'
  138. body += `[stderr]\n${err}`
  139. }
  140. if (body.length === 0) body = '(no output)'
  141. const markers: string[] = []
  142. // Keep `[exit code: N]` last so parseExitStatus() can recover it. A denial,
  143. // like a timeout, remains a reported fact for the model to handle.
  144. if (result.sandbox?.denied) {
  145. markers.push(`[sandbox: file access denied under ${result.sandbox.mode} mode]`)
  146. // Add the retry hint only when the schema advertises escalation, before
  147. // the final exit marker.
  148. if (escalationModes.length > 0) {
  149. markers.push('[sandbox: escalation available — retry this exact command once with sandbox_permissions (the narrowest wider mode that suffices) + justification; the approval prompt asks the user]')
  150. }
  151. }
  152. // Timeout is reported independently of how the process actually ended: a
  153. // command can trap SIGTERM and exit 0 after our timer fired (e.g.
  154. // `trap "exit 0" TERM; sleep 60`), giving timedOut:true / exitCode:0 /
  155. // signal:null — the model must still see that the command was cut short.
  156. if (result.timedOut) markers.push(`[timed out after ${result.timeoutMs}ms]`)
  157. if (result.signal !== null) {
  158. markers.push(`[killed by signal: ${result.signal}]`)
  159. } else if (result.exitCode !== 0) {
  160. markers.push(`[exit code: ${result.exitCode}]`)
  161. }
  162. if (markers.length === 0) return body
  163. if (!body.endsWith('\n')) body += '\n'
  164. return body + markers.join('\n')
  165. }
  166. // Pure tool-owned presentation used for both live events and replay.
  167. /**
  168. * Present foreground calls as terminals and background starts as generic cards.
  169. */
  170. type BashCallArgs = { command: string; description: string; workdir?: string; run_in_background?: boolean }
  171. function presentBashCall(args: BashCallArgs): GenericCallView | TerminalCallView {
  172. // A background start is not an interactive terminal — a generic execute card
  173. // with the command as rawInput and the description as a content block.
  174. if (args.run_in_background === true) {
  175. return {
  176. card: 'generic',
  177. title: args.command,
  178. kind: 'execute',
  179. rawInput: args.command,
  180. content: [{ type: 'text', text: args.description }],
  181. }
  182. }
  183. // A foreground run is a terminal; an explicit workdir supplies its cwd.
  184. return {
  185. card: 'terminal',
  186. title: args.command,
  187. description: args.description,
  188. ...args.workdir !== undefined ? { cwd: args.workdir } : {},
  189. }
  190. }
  191. /**
  192. * Present completed foreground output as a terminal; background acknowledgements
  193. * and execution errors use generic fenced output without an exit-status pill.
  194. */
  195. function presentBashResult(args: unknown, result: ToolResult): ToolResultView | undefined {
  196. const block = result.content.length === 1 ? result.content[0] : undefined
  197. if (block === undefined || block.type !== 'text') return undefined
  198. const raw = block.text
  199. const isBackground = typeof args === 'object' && args !== null && (args as { run_in_background?: unknown }).run_in_background === true
  200. // A background ack or an errored run is not a real terminal exit: render the
  201. // fenced ```console fallback as generic content (no exit pill).
  202. if (isBackground || result.isError) {
  203. return { card: 'generic', content: [{ type: 'text', text: `\`\`\`console\n${raw.replace(/\n+$/, '')}\n\`\`\`` }] }
  204. }
  205. // A finished foreground run supplies raw output and parsed exit status.
  206. // The bridge derives the no-capability fenced fallback from `output`.
  207. return { card: 'terminal', output: raw, ...parseExitStatus(raw) }
  208. }
  209. /**
  210. * Recover exit status from the final marked line emitted by {@link renderResult}.
  211. * A program whose own final line exactly mimics a marker remains ambiguous for UI display.
  212. */
  213. function parseExitStatus(text: string): { exitCode: number } | { signal: string } {
  214. const signal = /\n\[killed by signal: ([^\]\n]+)\]$/.exec(text)
  215. if (signal?.[1] !== undefined) return { signal: signal[1] }
  216. const exit = /\n\[exit code: (\d+)\]$/.exec(text)
  217. if (exit?.[1] !== undefined) return { exitCode: Number(exit[1]) }
  218. return { exitCode: 0 }
  219. }
  220. /** Pending-state presentation for `bash_output`/`bash_kill` (background-task tools). */
  221. function presentTaskCall(verb: string, args: { task_id: string }): GenericCallView {
  222. return { card: 'generic', title: `${verb} background task ${args.task_id}`, kind: 'execute', rawInput: args.task_id }
  223. }
  224. /**
  225. * Resolve an explicit workdir first, making a relative one session-cwd-relative;
  226. * otherwise use the session cwd and leave executor defaulting as the fallback.
  227. */
  228. function resolveWorkdir(modelWorkdir: string | undefined, exec: { agent?: Agent }): string | undefined {
  229. const sessionCwd = exec.agent?.session.header.cwd
  230. if (modelWorkdir === undefined) return sessionCwd
  231. if (sessionCwd !== undefined && !isAbsolute(modelWorkdir)) {
  232. return resolvePath(sessionCwd, modelWorkdir)
  233. }
  234. return modelWorkdir
  235. }
  236. /** Status line for background task reads. */
  237. function statusLine(task: BashTask): string {
  238. switch (task.status) {
  239. case 'running': return '[status: running]'
  240. case 'killed': return `[status: killed${task.signal !== null ? ` by ${task.signal}` : ''}]`
  241. case 'completed': return `[status: completed, exit code: ${task.exitCode ?? 0}]`
  242. }
  243. }
  244. export function apply(ctx: Context): void {
  245. // Cross-call guidance belongs in the prompt rather than one tool description.
  246. ctx.systemPrompt.section({
  247. name: 'tool:bash',
  248. order: 105,
  249. text: 'Check the [exit code: N] marker on every bash result; investigate failures before moving on.',
  250. })
  251. /**
  252. * Return the canonical session-header id used by ACP and persistence as the
  253. * task owner, or undefined for a non-agent caller.
  254. */
  255. const callerToken = (exec: { agent?: Agent }): OwnerToken | undefined =>
  256. exec.agent ? OwnerToken(exec.agent.session.header.id) : undefined
  257. /**
  258. * Reject access when a task has a different session owner. Unowned tasks are
  259. * allowed; unknown ids still fail in the subsequent read or kill.
  260. */
  261. const assertTaskAccess = (taskId: BashTaskId, exec: { agent?: Agent }): void => {
  262. const owner = ctx.bash.ownerOf(taskId)
  263. if (owner !== undefined && owner !== callerToken(exec)) {
  264. throw new Error(`task ${taskId} belongs to another session`)
  265. }
  266. }
  267. // Completion runs on the bash fiber, so use topology-independent lookup and
  268. // match the executor's stored session-owner token to a live agent.
  269. ctx.bash.onTaskDone((task) => {
  270. const ownerToken = ctx.bash.ownerOf(task.id)
  271. if (ownerToken === undefined) return
  272. const agent = ctx.get('agents')?.list().find(a => OwnerToken(a.session.header.id) === ownerToken)
  273. if (!agent) return
  274. try {
  275. agent.inject(
  276. [{ type: 'text', text: `background bash task ${task.id} finished ${statusLine(task)}. Read its output with bash_output.` }],
  277. { source: { kind: 'plugin', plugin: 'tool-bash' } },
  278. )
  279. } catch (error: unknown) {
  280. // The one expected failure: the agent was disposed between task completion and this
  281. // injection (ReactLoopAgent.inject throws `agent "<id>" is disposed`).
  282. if (error instanceof Error && error.message.includes('is disposed')) return
  283. throw error
  284. }
  285. })
  286. // The escalation surface exists whenever the mounted executor confines.
  287. // Advertise the closed target vocabulary globally, then enforce strict
  288. // widening against each call's effective session mode.
  289. const defaultMode = ctx.bash.sandboxMode
  290. const escalationModes: readonly SandboxMode[] = defaultMode === undefined ? [] : ESCALATION_TARGETS
  291. /**
  292. * Return the calling session's folded standing mode. Approval outranks this
  293. * value and the executor default applies when it is absent; non-sandboxing
  294. * and agent-less calls have no override.
  295. */
  296. const sessionOverride = (exec: ToolExecution): SandboxMode | undefined =>
  297. defaultMode === undefined || exec.agent === undefined ? undefined : effectiveSandboxMode(exec.agent.session.events)
  298. /**
  299. * Request one-shot escalation before execution. Missing approval context,
  300. * rejection, cancellation, and unavailable answers throw without running the
  301. * command; the optional seam is resolved per call through `ctx.get`.
  302. */
  303. const approveEscalation = async (mode: string, justification: string, exec: ToolExecution): Promise<SandboxMode> => {
  304. // Reject an unadvertised escalation before prompting for a nonexistent sandbox.
  305. if (escalationModes.length === 0) {
  306. throw new Error('sandbox_permissions is not available in this composition (no sandboxing executor to escalate)')
  307. }
  308. // Reject sandbox widening against the call's effective mode before requesting approval.
  309. const effectiveMode = (sessionOverride(exec) ?? defaultMode) as SandboxMode
  310. if (!(WIDER_MODES[effectiveMode] ?? []).includes(mode as SandboxMode)) {
  311. throw new Error(`sandbox escalation to "${mode}" is not strictly wider than this call's current "${effectiveMode}" mode`)
  312. }
  313. const approval = ctx.get('approval')
  314. if (approval === undefined) {
  315. throw new Error(`sandbox escalation to "${mode}" requires approval, but no approval service is composed`)
  316. }
  317. if (exec.agent === undefined) {
  318. throw new Error(`sandbox escalation to "${mode}" requires approval, but the call has no agent to route it through`)
  319. }
  320. const outcome = await approval.request({
  321. agent: exec.agent,
  322. toolName: 'bash',
  323. callId: exec.callId,
  324. // Self-contained for the audit trail: approval/asked stores this
  325. // reason, and the target mode is part of the grant's identity.
  326. reason: `escalate sandbox to ${mode}: ${justification}`,
  327. ...exec.signal ? { signal: exec.signal } : {},
  328. })
  329. switch (outcome) {
  330. // Schema validation pins the vocabulary; the per-call check proves widening.
  331. case 'allowed-once': return mode as SandboxMode
  332. case 'rejected': throw new Error(`the user rejected escalating this command to "${mode}"`)
  333. case 'cancelled': throw new Error(`approval for escalating to "${mode}" was cancelled`)
  334. case 'unavailable': throw new Error(`sandbox escalation to "${mode}" requires approval, but no approval channel is available`)
  335. default: return assertNever(outcome, 'ApprovalOutcome')
  336. }
  337. }
  338. ctx.tools.register(defineTool({
  339. name: 'bash',
  340. description: bashDescription(escalationModes),
  341. parameters: {
  342. command: { type: 'string', required: true, description: 'The bash command to execute.' },
  343. description: {
  344. type: 'string',
  345. required: true,
  346. description: 'Clear, concise description of what this command does in active voice, '
  347. + '5-10 words (shown in the UI). Examples: "ls" → "List files in current directory"; '
  348. + '"git status" → "Show working tree status"; "npm install" → "Install package dependencies".',
  349. },
  350. timeoutMs: { type: 'number', description: 'Timeout in milliseconds. The executor applies its configured default and cap, and kills the command on expiry.' },
  351. workdir: { type: 'string', description: 'Working directory for this command. Defaults to the session workspace; a relative path is resolved against it.' },
  352. run_in_background: { type: 'boolean', description: 'Run in the background and return a task id immediately. No timeout applies.' },
  353. ...escalationModes.length > 0 ? {
  354. sandbox_permissions: {
  355. type: 'string' as const,
  356. enum: [...escalationModes],
  357. description: 'The wider sandbox mode this command needs. Only valid as a one-shot retry '
  358. + 'of a command the sandbox just denied; requires justification and user approval.',
  359. },
  360. justification: {
  361. type: 'string' as const,
  362. description: 'Required with sandbox_permissions: one sentence for the user explaining '
  363. + 'why this exact command needs the wider access.',
  364. },
  365. } : {},
  366. },
  367. async execute(args: BashToolArgs, exec) {
  368. validateBashArgs(args)
  369. // `description` is display/logging metadata only. Escalation approval
  370. // completes before execution; grant > session override > executor default.
  371. const sandboxMode = args.sandbox_permissions !== undefined && args.justification !== undefined
  372. ? await approveEscalation(args.sandbox_permissions, args.justification, exec)
  373. : sessionOverride(exec)
  374. // Default the workdir to the calling agent's session cwd so each ACP
  375. // session runs in its own workspace (see resolveWorkdir); an explicit
  376. // model workdir still wins.
  377. const workdir = resolveWorkdir(args.workdir, exec)
  378. const request = {
  379. command: args.command,
  380. ...workdir !== undefined ? { workdir } : {},
  381. ...args.timeoutMs !== undefined ? { timeoutMs: args.timeoutMs } : {},
  382. ...exec.signal ? { signal: exec.signal } : {},
  383. ...sandboxMode !== undefined ? { sandboxMode } : {},
  384. }
  385. if (args.run_in_background === true) {
  386. // Store the session owner on the task for bash_output/bash_kill isolation.
  387. const task = ctx.bash.start(ctx.bash.resolve({ ...request, owner: callerToken(exec) }))
  388. return [{ type: 'text', text: `started background task ${task.id}` }]
  389. }
  390. const result = await ctx.bash.run(ctx.bash.resolve(request))
  391. if (result.aborted) throw new Error('command aborted')
  392. return [{ type: 'text', text: renderResult(result, escalationModes) }]
  393. },
  394. presentCall: presentBashCall,
  395. presentResult: presentBashResult,
  396. }))
  397. ctx.tools.register(defineTool({
  398. name: 'bash_output',
  399. description: 'Read new output from a background bash task started with `bash` + `run_in_background`. '
  400. + 'Returns only output produced since the previous bash_output call, plus the task status. '
  401. + 'Tasks keep running while you do other work; poll again later for more output.',
  402. parameters: {
  403. task_id: { type: 'string', required: true, description: 'Task id returned by the bash tool.' },
  404. },
  405. // execute is synchronous (registry reads + string shaping) but the
  406. // ToolDefinition contract wants a Promise — hence resolve(), not async.
  407. execute(args, exec) {
  408. const id = validateTaskId(args.task_id)
  409. assertTaskAccess(id, exec)
  410. const read = ctx.bash.readOutput(id)
  411. let text = read.delta.length > 0 ? read.delta : '(no new output)'
  412. if (read.lossy) {
  413. const paths = [read.stdoutSpillPath, read.stderrSpillPath].filter((p): p is string => p !== undefined)
  414. const fullOutput = paths.length > 0 ? paths.join(', ') : '(unavailable)'
  415. text += `\n[some output was dropped from memory; full output: ${fullOutput}]`
  416. }
  417. text += `\n${statusLine(read.task)}`
  418. if (read.task.sandbox?.runnerFailed) {
  419. // Background settlement carries the runner-failure fact that a
  420. // foreground call exposes as SANDBOX_UNAVAILABLE.
  421. text += `\n[sandbox: the sandbox runner itself failed under ${read.task.sandbox.mode} mode — the command did not run; this is a sandbox problem, not a command failure]`
  422. } else if (read.task.sandbox?.denied) {
  423. // Mirrors the foreground result marker (and its same-turn escalation hint).
  424. text += `\n[sandbox: file access denied under ${read.task.sandbox.mode} mode]`
  425. if (escalationModes.length > 0) {
  426. text += '\n[sandbox: escalation available — retry this exact command once with sandbox_permissions (the narrowest wider mode that suffices) + justification; the approval prompt asks the user]'
  427. }
  428. }
  429. return Promise.resolve([{ type: 'text', text }])
  430. },
  431. presentCall: args => presentTaskCall('Read output from', args),
  432. }))
  433. ctx.tools.register(defineTool({
  434. name: 'bash_kill',
  435. description: 'Ask the executor to kill a running background bash task by task id.',
  436. parameters: {
  437. task_id: { type: 'string', required: true, description: 'Task id returned by the bash tool.' },
  438. },
  439. execute(args, exec) {
  440. const id = validateTaskId(args.task_id)
  441. assertTaskAccess(id, exec)
  442. const killed = ctx.bash.kill(id)
  443. return Promise.resolve([{
  444. type: 'text',
  445. text: killed ? `killed background task ${id}` : `task ${id} had already finished`,
  446. }])
  447. },
  448. presentCall: args => presentTaskCall('Kill', args),
  449. }))
  450. }