Skip to content

Extend readBackgroundJobOutput to support reading Task output #1023

Description

@wsxiaoys

Is your feature request related to a problem? Please describe.
With the proposed feature to allow `newTask` to run as a background child task (#1022), the parent agent needs a way to monitor the progress and output of these tasks, similar to how it monitors terminal background jobs.

Describe the solution you'd like
Extend the existing `readBackgroundJobOutput` tool to support Task IDs in addition to Terminal Job IDs. This would provide a unified interface for agents to monitor any background activity.

Detailed Design Proposal

  1. Unified Interface:

    • The tool signature remains the same: `readBackgroundJobOutput(backgroundJobId: string)`.
    • The `backgroundJobId` can be either a Terminal Job ID or a Task ID.
  2. Task Output Adaptation:

    • When a Task ID is provided, the system should retrieve the task's message history.
    • State Tracking: Similar to `OutputManager` for terminals, we need a mechanism to track the 'read cursor' (e.g., last read message ID) for the task so that only new content is returned on subsequent calls.
    • Output Formatting: Task messages (User/Assistant exchanges) should be serialized into a text format suitable for the `output` string field (e.g., `[Assistant]: I have updated the file...`).
    • Status Mapping: Map Task statuses to `readBackgroundJobOutput` statuses:
      • Task `pending` -> Job `idle`
      • Task `in-progress` -> Job `running`
      • Task `completed` / `failed` -> Job `completed`
  3. Implementation Considerations:

    • Refactor `readBackgroundJobOutput` implementation in `packages/vscode/src/tools/read-background-job-output.ts` to delegate to either `OutputManager` (for terminals) or a new `TaskOutputManager` (for tasks) based on the ID format or lookup success.
    • Ensure `TaskOutputManager` can handle the persistence of the read cursor, potentially per-consumer if needed, or just ephemeral for the monitoring session.

Alternative Considered

  • Creating a separate `readTaskOutput` tool.
  • Pros: Could return structured JSON data.
  • Cons: Increases API surface area. The text-based output of `readBackgroundJobOutput` is often sufficient and easier for LLMs to digest as a log stream.

Additional context
Depends on #1022.


🤖 Generated with Pochi

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions