| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572 |
- /**
- * Model-facing `bash` tool over the `ctx.bash` executor seam. Background calls
- * register process handles with `ctx.tasks`; their work uses task cancellation
- * rather than the tool-call signal after an id is returned.
- *
- * TODO(permissions): deployment policy belongs in `tools/pre-execute` and
- * sandboxing executors; see docs/architecture.md § Extending The Harness.
- * @module @deepseek-ai/dsh-tool-bash
- */
- import { Service, type Context } from 'cordis'
- import z from 'schemastery'
- import { isAbsolute, resolve as resolvePath } from 'node:path'
- import { defineTool, TOOL_ABORTED } from '@deepseek-ai/dsh-tools'
- import type { GenericCallView, TerminalCallView, ToolExecution, ToolResult, ToolResultView } from '@deepseek-ai/dsh-tools'
- import { HarnessError } from '@deepseek-ai/dsh-llm'
- import type { Agent } from '@deepseek-ai/dsh-agent'
- import type {} from '@deepseek-ai/dsh-session-persistence'
- import type {} from '@deepseek-ai/dsh-system-prompt'
- import type {} from '@deepseek-ai/dsh-tasks'
- import type {} from '@deepseek-ai/dsh-user-approval'
- import type { SandboxExecutionPolicy, SandboxMode } from '@deepseek-ai/dsh-sandbox'
- import { ESCALATION_TARGETS, approveEscalation, canonicalPath, validateEscalationArgs } from '@deepseek-ai/dsh-sandbox'
- import type { SandboxPolicyService } from '@deepseek-ai/dsh-sandbox-policy'
- import { DSH_ENV_PREFIX } from '@deepseek-ai/dsh-bash'
- import type { BashRunResult, DshEnvironment, DshEnvironmentKey } from '@deepseek-ai/dsh-bash'
- import { DSH_HOME_ENV, resolveDshHome } from '@deepseek-ai/dsh-paths'
- import { processOutcome } from './background.ts'
- import { parseExitStatus, renderProcessRead, renderResult } from './render.ts'
- declare module 'cordis' {
- interface Context {
- bashEnv: BashEnvRegistry
- }
- }
- export const name = 'tool-bash'
- export const inject = ['tools', 'bash', 'systemPrompt']
- /** Configuration for the bash tool and its managed child environment. */
- export interface Config {
- /** Expose `run_in_background` (default true); disabled calls are also rejected. */
- enableRunInBackground?: boolean
- /** DeepSeek Harness home directory exposed as `DSH_HOME`; defaults to `$DSH_HOME` or `~/.dsh`. */
- dshHome?: string
- }
- /** Runtime configuration schema for the bash tool plugin. */
- export const Config: z<Config> = z.object({
- enableRunInBackground: z.boolean().default(true),
- dshHome: z.string(),
- })
- /** Model-visible metadata for one managed `DSH_*` environment variable. */
- export interface BashEnvVariable {
- /** Concise description of the environment fact represented by the variable. */
- description: string
- }
- /**
- * A plugin contribution to the managed environment of each model bash call.
- * Declared keys make ownership conflicts detectable before the first command;
- * `resolve` computes only the values available for the current execution.
- */
- export interface BashEnvContributor {
- /** Stable contributor name used in diagnostics and duplicate detection. */
- name: string
- /** Complete set of `DSH_*` keys this contributor may return. */
- variables: Readonly<Record<DshEnvironmentKey, BashEnvVariable>>
- /**
- * Resolve this contributor's available values for one tool execution.
- * @param execution - the bash tool execution and its optional calling agent.
- * @returns a partial map containing only keys declared in {@link variables}.
- */
- resolve(execution: ToolExecution): Readonly<Partial<Record<DshEnvironmentKey, string>>>
- }
- /** An enumerable declaration returned by {@link BashEnvRegistry.list}. */
- export interface BashEnvVariableInfo extends BashEnvVariable {
- /** Contributor that owns the variable. */
- contributor: string
- /** Declared `DSH_*` environment variable name. */
- key: DshEnvironmentKey
- }
- const DSH_SHELL_KEY = `${DSH_ENV_PREFIX}SHELL` as const
- const DSH_SESSION_ID_KEY = `${DSH_ENV_PREFIX}SESSION_ID` as const
- const DSH_SESSION_JSONL_KEY = `${DSH_ENV_PREFIX}SESSION_JSONL` as const
- const RESERVED_BASH_ENV_KEYS = new Set<DshEnvironmentKey>([
- DSH_HOME_ENV,
- DSH_SHELL_KEY,
- DSH_SESSION_ID_KEY,
- ])
- const BASH_ENV_KEY_SUFFIX = /^[A-Z][A-Z0-9_]*$/
- /**
- * Registry (`ctx.bashEnv`) for trusted, per-execution `DSH_*` variables.
- * The namespace is rebuilt for every model bash call: ambient `DSH_*` values
- * are discarded by the executor, then the registry's current snapshot is
- * injected. Built-in shell facts remain owned by the registry itself while
- * plugins can register additional, enumerable facts with effect-scoped
- * disposal.
- */
- export class BashEnvRegistry extends Service {
- private readonly contributors = new Map<string, BashEnvContributor>()
- private readonly keyOwners = new Map<DshEnvironmentKey, string>()
- private readonly dshHome: string
- /**
- * Create and install the `ctx.bashEnv` service.
- * @param ctx - Cordis context that owns the service and registrations.
- * @param config - home-directory configuration for the built-in variables.
- */
- constructor(ctx: Context, config: Config = {}) {
- super(ctx, 'bashEnv')
- this.dshHome = resolveDshHome(config.dshHome)
- }
- /**
- * Register one environment contributor. Names and keys are unique; built-in
- * keys are reserved. Registration is disposed with the calling plugin fiber.
- * @param contributor - declared key ownership and per-execution resolver.
- * @returns the disposer that unregisters the contribution.
- */
- register(contributor: BashEnvContributor): () => void {
- const dispose = this.ctx.effect(function* (this: BashEnvRegistry) {
- if (contributor.name.trim().length === 0) {
- throw new Error('bash env contributor name must be non-empty')
- }
- if (this.contributors.has(contributor.name)) {
- throw new Error(`bash env contributor "${contributor.name}" is already registered`)
- }
- const variables = Object.entries(contributor.variables) as [DshEnvironmentKey, BashEnvVariable][]
- for (const [key, variable] of variables) {
- if (!key.startsWith(DSH_ENV_PREFIX)
- || !BASH_ENV_KEY_SUFFIX.test(key.slice(DSH_ENV_PREFIX.length))) {
- throw new Error(`bash env contributor "${contributor.name}" declared invalid key "${key}"`)
- }
- if (RESERVED_BASH_ENV_KEYS.has(key)) {
- throw new Error(`bash env contributor "${contributor.name}" cannot own reserved key "${key}"`)
- }
- if (variable.description.trim().length === 0) {
- throw new Error(`bash env contributor "${contributor.name}" must describe "${key}"`)
- }
- const owner = this.keyOwners.get(key)
- if (owner !== undefined) {
- throw new Error(`bash env key "${key}" is already owned by contributor "${owner}"; contributor "${contributor.name}" cannot also own it`)
- }
- }
- this.contributors.set(contributor.name, contributor)
- for (const [key] of variables) this.keyOwners.set(key, contributor.name)
- yield () => {
- this.contributors.delete(contributor.name)
- for (const [key] of variables) this.keyOwners.delete(key)
- }
- }.bind(this), 'bashEnv.register()')
- return () => void dispose()
- }
- /**
- * Build the trusted `DSH_*` snapshot for one bash tool execution.
- * @param execution - the current tool execution.
- * @returns an immutable environment overlay containing built-ins and current contributions.
- */
- collect(execution: ToolExecution): DshEnvironment {
- const values: Record<DshEnvironmentKey, string> = {
- [DSH_HOME_ENV]: this.dshHome,
- [DSH_SHELL_KEY]: '1',
- }
- if (execution.agent !== undefined) {
- values[DSH_SESSION_ID_KEY] = execution.agent.session.header.id
- }
- for (const contributor of [...this.contributors.values()].sort((left, right) => left.name.localeCompare(right.name))) {
- const resolved = contributor.resolve(execution)
- for (const [rawKey, value] of Object.entries(resolved)) {
- const key = rawKey as DshEnvironmentKey
- if (!Object.hasOwn(contributor.variables, key)) {
- throw new Error(`bash env contributor "${contributor.name}" returned undeclared key "${key}"`)
- }
- if (typeof value !== 'string') {
- throw new Error(`bash env contributor "${contributor.name}" returned a non-string value for "${key}"`)
- }
- values[key] = value
- }
- }
- return Object.freeze(Object.fromEntries(Object.entries(values).sort(([left], [right]) => left.localeCompare(right))))
- }
- // TODO(bash-env-list-builtins): Include registry-owned built-ins before diagnostics,
- // prompt, or UI code treats list() as an exhaustive environment catalog.
- /**
- * Enumerate plugin-contributed variables without executing their resolvers.
- * @returns declarations sorted by environment variable name.
- */
- list(): BashEnvVariableInfo[] {
- return [...this.contributors.values()]
- .flatMap(contributor => Object.entries(contributor.variables).map(([key, variable]) => ({
- contributor: contributor.name,
- description: variable.description,
- key: key as DshEnvironmentKey,
- })))
- .sort((left, right) => left.key.localeCompare(right.key))
- }
- }
- /** Parsed tool args; execute validates value constraints absent from ParameterSchemaSpec. */
- interface BashToolArgs {
- command: string
- description: string
- timeoutMs?: number
- workdir?: string
- run_in_background?: boolean
- sandbox_permissions?: string
- justification?: string
- }
- function validateBashArgs(args: BashToolArgs): void {
- if (args.command.trim().length === 0) {
- throw new Error('invalid command: expected a non-empty string')
- }
- if (args.description.trim().length === 0) {
- throw new Error('invalid description: expected a non-empty string')
- }
- if (args.timeoutMs !== undefined && (!Number.isFinite(args.timeoutMs) || args.timeoutMs <= 0)) {
- throw new Error(`invalid timeoutMs: expected a positive number, got ${JSON.stringify(args.timeoutMs)}`)
- }
- // The escalation pairing (sandbox_permissions ⇔ justification, non-empty) is
- // the shared rule both enforcing families validate identically.
- validateEscalationArgs(args.sandbox_permissions, args.justification)
- }
- function bashDescription(backgroundEnabled: boolean, escalationModes: readonly SandboxMode[]): string {
- const background = backgroundEnabled
- ? 'Set `run_in_background: true` for long-running commands: the call returns a task id immediately; read its output with `task_output` and stop it with `task_kill`.'
- : 'Background execution is not available; long-running commands must finish within the timeout.'
- const base = 'Execute a bash command (`bash -c`) and return its stdout/stderr. '
- + 'Each call runs in a fresh shell: no state (cwd, variables, functions) persists between calls — '
- + 'pass `workdir` instead of using `cd`. Non-zero exits are reported as `[exit code: N]`. '
- + `Current harness environment facts are exposed through managed \`$${DSH_ENV_PREFIX}*\` variables; inspect them when needed. `
- + '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. '
- + 'Long output is truncated to its tail; the full output is saved to a file whose path is reported when available. '
- + background
- if (escalationModes.length === 0) return base
- return base + ' Attempting a command the sandbox may deny is safe and expected: run it and read the '
- + 'marker rather than assuming the denial. When a command is denied and a wider mode would let it '
- + 'succeed, escalate immediately in the same turn — the one sanctioned exception to a denial: retry '
- + 'the exact same command once with `sandbox_permissions` (the narrowest wider mode that suffices) '
- + 'plus a one-sentence `justification`. Do not detour through chat to ask permission first — the '
- + 'approval prompt raised by that retry is how the user consents. If the session states approval '
- + 'prompts are disabled, there is no exception: a denial is final — do not set `sandbox_permissions`. '
- + 'Never escalate speculatively: ground the request in a real denial — normally the one this command '
- + 'just hit; escalating up front is fine only when this session already denied the same access. '
- + 'A rejected escalation is final for that command — stop and explain, never work around '
- + 'it — but it does not forbid attempting or escalating other commands later.'
- }
- /**
- * Present foreground calls as terminals and background starts as generic cards.
- * The command remains the title on both paths; foreground cwd is passed through
- * for the bridge to resolve, while background descriptions remain card content.
- */
- type BashCallArgs = { command: string; description: string; workdir?: string; run_in_background?: boolean }
- function presentBashCall(args: BashCallArgs): GenericCallView | TerminalCallView {
- if (args.run_in_background === true) {
- return {
- card: 'generic',
- title: args.command,
- kind: 'execute',
- rawInput: args.command,
- content: [{ type: 'text', text: args.description }],
- }
- }
- return {
- card: 'terminal',
- title: args.command,
- description: args.description,
- ...args.workdir !== undefined ? { cwd: args.workdir } : {},
- }
- }
- /**
- * Present completed foreground output as a terminal; background acknowledgements
- * and execution errors use generic fenced output without an exit-status pill.
- */
- function presentBashResult(args: unknown, result: ToolResult): ToolResultView | undefined {
- const block = result.content.length === 1 ? result.content[0] : undefined
- if (block === undefined || block.type !== 'text') return undefined
- const raw = block.text
- const isBackground = typeof args === 'object' && args !== null && (args as { run_in_background?: unknown }).run_in_background === true
- // Background acknowledgements and errors have no terminal exit status.
- if (isBackground || result.isError) {
- return { card: 'generic', content: [{ type: 'text', text: `\`\`\`console\n${raw.replace(/\n+$/, '')}\n\`\`\`` }] }
- }
- // The exit marker becomes the card's exit pill, so it leaves the output body.
- const { body, ...exit } = parseExitStatus(raw)
- return { card: 'terminal', output: body, ...exit }
- }
- /**
- * Resolve an explicit workdir first, making a relative one session-workspace-relative;
- * otherwise use the filesystem identity of the session cwd and leave executor
- * defaulting as the fallback. A resolved sandbox-policy root wins so workdir
- * and confinement use the exact same per-call identity.
- */
- function resolveWorkdir(
- modelWorkdir: string | undefined,
- exec: { agent?: Agent },
- policyWorkspaceRoot?: string,
- ): string | undefined {
- const headerCwd = exec.agent?.session.header.cwd
- const sessionCwd = policyWorkspaceRoot ?? (headerCwd === undefined ? undefined : canonicalPath(headerCwd))
- if (modelWorkdir === undefined) return sessionCwd
- if (sessionCwd !== undefined && !isAbsolute(modelWorkdir)) {
- return resolvePath(sessionCwd, modelWorkdir)
- }
- return modelWorkdir
- }
- /** Detach the executor DTO from readonly seam interfaces into plain JSON data. */
- function canonicalBashResult(result: BashRunResult) {
- const output = (stream: BashRunResult['stdout']) => ({
- text: stream.text,
- truncated: stream.truncated,
- ...stream.spillPath !== undefined ? { spillPath: stream.spillPath } : {},
- })
- return {
- exitCode: result.exitCode,
- signal: result.signal,
- timedOut: result.timedOut,
- aborted: result.aborted,
- timeoutMs: result.timeoutMs,
- stdout: output(result.stdout),
- stderr: output(result.stderr),
- ...result.sandbox !== undefined ? {
- sandbox: {
- mode: result.sandbox.mode,
- denied: result.sandbox.denied,
- ...result.sandbox.enforcement !== undefined ? { enforcement: result.sandbox.enforcement } : {},
- ...result.sandbox.runnerFailed !== undefined ? { runnerFailed: result.sandbox.runnerFailed } : {},
- },
- } : {},
- }
- }
- /** Canonical background-handle properties shared by the bash output union. */
- const BACKGROUND_OUTPUT_PROPERTIES = {
- kind: { type: 'string', required: true, const: 'background' },
- taskId: { type: 'string', required: true },
- } as const
- export function apply(ctx: Context, config: Config = {}): void {
- const bashEnv = new BashEnvRegistry(ctx, config)
- bashEnv.register({
- name: 'session-persistence',
- variables: {
- [DSH_SESSION_JSONL_KEY]: {
- description: 'Absolute target path of the current session JSONL when the active persistence backend provides one.',
- },
- },
- resolve(execution) {
- const agent = execution.agent
- if (agent === undefined) return {}
- const location = ctx.get('sessionPersistence')?.locate(agent.session.header)
- return location?.kind === 'jsonl' ? { [DSH_SESSION_JSONL_KEY]: location.path } : {}
- },
- })
- const backgroundEnabled = config.enableRunInBackground ?? true
- const defaultMode = ctx.bash.sandboxMode
- const escalationModes: readonly SandboxMode[] = defaultMode === undefined ? [] : ESCALATION_TARGETS
- const sandboxPolicy: SandboxPolicyService | undefined = defaultMode === undefined ? undefined : ctx.get('sandboxPolicy')
- if (defaultMode !== undefined && sandboxPolicy === undefined) {
- throw new Error('tool-bash: the mounted bash executor confines but ctx.sandboxPolicy is missing')
- }
- /** Resolve the complete standing policy for this call when a confining executor is mounted. */
- const resolveSandboxPolicy = (exec: ToolExecution): SandboxExecutionPolicy | undefined =>
- sandboxPolicy?.resolve(exec.agent === undefined ? {} : { session: exec.agent.session })
- /**
- * Resolve a sandbox-escalation request through `ctx.approval` BEFORE
- * anything executes, delegating the shared fail-closed sequence (strict
- * widening, channel resolution, outcome mapping) to
- * {@link approveEscalation}. This tool contributes only the composition
- * guard (the fields are unadvertised without a sandboxing executor, yet
- * schema validation checks advertised keys only, so an unadvertised
- * `sandbox_permissions` still reaches execute) and the approval ingredients
- * The shared policy resolver is required whenever the executor advertises
- * confinement, so a split composition fails at tool-plugin load.
- */
- const approveBashEscalation = (
- mode: string,
- justification: string,
- exec: ToolExecution,
- standingPolicy: SandboxExecutionPolicy | undefined,
- ): Promise<SandboxMode> => {
- if (escalationModes.length === 0) {
- throw new Error('sandbox_permissions is not available in this composition (no sandboxing executor to escalate)')
- }
- const effectiveMode = (standingPolicy as SandboxExecutionPolicy).mode
- return approveEscalation(
- { requestedMode: mode, justification, effectiveMode, subject: 'command' },
- {
- approver: ctx.get('approval'),
- agent: exec.agent,
- callId: exec.callId,
- toolName: 'bash',
- signal: exec.signal,
- },
- )
- }
- // Cross-call guidance belongs in the prompt rather than one-call schema prose.
- ctx.systemPrompt.section({
- name: 'tool:bash',
- order: 105,
- text: 'Check the [exit code: N] marker on every bash result; investigate failures before moving on.',
- })
- ctx.tools.register(defineTool({
- name: 'bash',
- description: bashDescription(backgroundEnabled, escalationModes),
- parameters: {
- command: { type: 'string', required: true, description: 'The bash command to execute.' },
- description: {
- type: 'string',
- required: true,
- description: 'Clear, concise description of what this command does in active voice, '
- + '5-10 words (shown in the UI). Examples: "ls" → "List files in current directory"; '
- + '"git status" → "Show working tree status"; "npm install" → "Install package dependencies".',
- },
- timeoutMs: { type: 'number', description: 'Timeout in milliseconds. The executor applies its configured default and cap, and kills the command on expiry.' },
- workdir: { type: 'string', description: 'Working directory for this command. Defaults to the session workspace; a relative path is resolved against it.' },
- ...backgroundEnabled ? {
- run_in_background: { type: 'boolean' as const, description: 'Run in the background and return a task id immediately (collect with task_output, stop with task_kill). No timeout applies.' },
- } : {},
- ...escalationModes.length > 0 ? {
- sandbox_permissions: {
- type: 'string' as const,
- enum: [...escalationModes],
- description: 'The wider sandbox mode this command needs. Only valid as a one-shot retry of a command the sandbox just denied; requires justification and user approval.',
- },
- justification: {
- type: 'string' as const,
- description: 'Required with sandbox_permissions: one sentence for the user explaining why this exact command needs the wider access.',
- },
- } : {},
- },
- output: {
- schema: {
- oneOf: [
- {
- type: 'object',
- additionalProperties: false,
- properties: BACKGROUND_OUTPUT_PROPERTIES,
- },
- {
- type: 'object',
- additionalProperties: false,
- properties: {
- kind: { type: 'string', required: true, const: 'foreground' },
- exitCode: { required: true, oneOf: [{ type: 'integer' }, { type: 'null' }] },
- signal: { required: true, oneOf: [{ type: 'string' }, { type: 'null' }] },
- timedOut: { type: 'boolean', required: true },
- aborted: { type: 'boolean', required: true },
- timeoutMs: { type: 'number', required: true },
- stdout: {
- type: 'object',
- additionalProperties: false,
- required: true,
- properties: {
- text: { type: 'string', required: true },
- truncated: { type: 'boolean', required: true },
- spillPath: { type: 'string' },
- },
- },
- stderr: {
- type: 'object',
- additionalProperties: false,
- required: true,
- properties: {
- text: { type: 'string', required: true },
- truncated: { type: 'boolean', required: true },
- spillPath: { type: 'string' },
- },
- },
- sandbox: {
- type: 'object',
- additionalProperties: false,
- properties: {
- mode: { type: 'string', required: true },
- denied: { type: 'boolean', required: true },
- enforcement: { type: 'string' },
- runnerFailed: { type: 'boolean' },
- },
- },
- },
- },
- ],
- },
- render: (_args, value) => [{
- type: 'text',
- text: value.kind === 'background'
- ? `started background task ${value.taskId}`
- : renderResult(value as { kind: 'foreground' } & BashRunResult, escalationModes),
- }],
- },
- async execute(args: BashToolArgs, exec) {
- validateBashArgs(args)
- // Description is display metadata; workdir defaults to the caller's session.
- const standingPolicy = resolveSandboxPolicy(exec)
- const approvedMode = args.sandbox_permissions !== undefined && args.justification !== undefined
- ? await approveBashEscalation(args.sandbox_permissions, args.justification, exec, standingPolicy)
- : undefined
- const policy = approvedMode === undefined
- ? standingPolicy
- : { ...(standingPolicy as SandboxExecutionPolicy), mode: approvedMode }
- const workdir = resolveWorkdir(args.workdir, exec, standingPolicy?.workspaceRoot)
- const dshEnv = bashEnv.collect(exec)
- const request = {
- command: args.command,
- ...workdir !== undefined ? { workdir } : {},
- ...args.timeoutMs !== undefined ? { timeoutMs: args.timeoutMs } : {},
- dshEnv,
- ...policy !== undefined ? { sandboxPolicy: policy } : {},
- }
- if (args.run_in_background === true) {
- // Undeclared keys are allowed, so schema omission also needs enforcement.
- if (!backgroundEnabled) {
- throw new Error('run_in_background is disabled for this deployment (enableRunInBackground: false)')
- }
- const tasks = ctx.get('tasks')
- if (tasks === undefined) {
- throw new Error('background tasks unavailable: load @deepseek-ai/dsh-tasks and @deepseek-ai/dsh-tool-tasks')
- }
- // The caller owns cancellation until ctx.tasks commits detached ownership.
- if (exec.signal.aborted) {
- const error = new HarnessError('tool call aborted', TOOL_ABORTED)
- error.name = 'AbortError'
- throw error
- }
- // Task preflight finishes before the starter can spawn a process.
- const id = tasks.start({
- kind: 'bash',
- label: args.command,
- ...exec.agent ? { owner: exec.agent } : {},
- run: () => {
- const proc = ctx.bash.start(ctx.bash.resolve(request))
- return {
- cancel: () => void proc.kill(),
- done: proc.done.then(() => processOutcome(proc)),
- readOutput: () => renderProcessRead(proc.readOutput(), proc.sandbox, escalationModes),
- }
- },
- })
- return { kind: 'background' as const, taskId: id }
- }
- const result = await ctx.bash.run(ctx.bash.resolve({
- ...request,
- signal: exec.signal,
- }))
- if (result.aborted) throw new Error('command aborted')
- return { kind: 'foreground' as const, ...canonicalBashResult(result) }
- },
- presentCall: presentBashCall,
- presentResult: presentBashResult,
- }))
- }
|