background.ts 1.2 KB

123456789101112131415161718192021222324252627
  1. /**
  2. * Generic-task adaptation for background bash process handles.
  3. *
  4. * @module @deepseek-ai/dsh-tool-bash/background
  5. */
  6. import type { BashProcess } from '@deepseek-ai/dsh-bash'
  7. /**
  8. * Map a settled background process onto the generic task-outcome vocabulary:
  9. * `killed` stays `killed` (detail: the signal when one is known), everything
  10. * else is `completed` with the exit code as detail. A nonzero command exit is
  11. * reported, not failed, exactly like the foreground rendering.
  12. * @param proc - the settled process handle.
  13. * @returns the outcome for the `ctx.tasks` registration.
  14. */
  15. export function processOutcome(proc: BashProcess): { status: 'completed' | 'killed'; detail: string } {
  16. // TODO(background-infrastructure-outcome): widen BashProcess with an explicit
  17. // infrastructure-failure outcome, then map it to task `failed`. Restricted
  18. // runner failures expose sandbox.runnerFailed, but unconfined spawn failures
  19. // still alias a signal-less kill; real nonzero command exits must remain
  20. // `completed`.
  21. if (proc.status === 'killed') {
  22. return { status: 'killed', detail: proc.signal !== null ? `signal: ${proc.signal}` : 'killed before exit' }
  23. }
  24. return { status: 'completed', detail: `exit code: ${proc.exitCode ?? 0}` }
  25. }