Skip to content

feat(node-sdk): expose subagent task query API#37

Merged
ZhiXiao-Lin merged 2 commits into
mainfrom
feat/subagent-node-sdk
May 23, 2026
Merged

feat(node-sdk): expose subagent task query API#37
ZhiXiao-Lin merged 2 commits into
mainfrom
feat/subagent-node-sdk

Conversation

@ZhiXiao-Lin
Copy link
Copy Markdown
Contributor

Stacked on #36 (which is stacked on #35). When the upstream PRs land the base of this PR will retarget to `main` automatically.

Summary

Mirrors the core-side subagent query API (#35) onto the Node SDK so JS/TS callers don't have to parse the raw event stream.

```ts
const snap = await session.subagentTask('task-abc')
// { taskId, parentSessionId, childSessionId, agent, description,
// status: 'running' | 'completed' | 'failed',
// startedMs, updatedMs, finishedMs?, output?, success?, progress: [...] }

const all = await session.subagentTasks()
const pending = await session.pendingSubagentTasks()
```

Notes on the regenerated `index.d.ts`

The file is `auto-generated by NAPI-RS` per its header. Building picked up:

  • The three new methods.
  • Docstring drift — several `errorKindJson` comments in the previous .d.ts were richer than the current Rust source; napi regenerated them to match the Rust truth. No semantic change.
  • Reordering of generated interfaces (e.g. `AutoDelegationOptions` moved earlier in the file). Every `export` declaration from the previous file is still present (verified with a sorted-export diff).

The hand-added type aliases that aren't generated from Rust — `ToolErrorKind`, `VerificationStatus`, `VerificationCheck`, `VerificationReport`, `ToolArtifact` — were lost by the regeneration and restored as part of this commit. They probably belong in a separate non-generated `index.types.ts` long-term, but that's out of scope here.

Test plan

  • `npm run build:debug` succeeds.
  • `npm test` passes, including the new smoke block:
    • `subagentTasks()` returns `[]` for a fresh session
    • `pendingSubagentTasks()` returns `[]` for a fresh session
    • `subagentTask('task-does-not-exist')` returns `null`
  • Sorted-export diff confirms no exported symbols were dropped.

Follow-ups

claude added 2 commits May 24, 2026 00:01
The `SubagentProgress` event variant exists but until now was never sent —
the subagent task tracker introduced in the previous commit observed
Start and End but had no mid-task signal to update from.

Adds a `synthesize_subagent_progress()` helper called by the mpsc → broadcast
forwarder inside `TaskExecutor::execute_with_task_id`. It translates two
child-loop events into compact progress milestones on the parent broadcast:

- `ToolEnd` → `status = "tool_completed"`, metadata `{ tool, exit_code,
  output_bytes, error_kind? }`
- `TurnEnd` → `status = "turn_completed"`, metadata `{ turn, total_tokens,
  prompt_tokens, completion_tokens }`

Noisy events (TextDelta / ToolStart / ToolOutputDelta / nested Subagent*)
are intentionally not translated — consumers needing token-level detail
should subscribe to the raw event stream directly.

The original child events are still forwarded unchanged; progress is
additive, so downstream consumers see both the synthesized milestone
and the underlying event.
Mirrors the new Session APIs from the core crate so JS/TS callers can
introspect delegated subagent tasks without parsing run_events.

- `Session.subagentTask(taskId)` → snapshot or null
- `Session.subagentTasks()` → snapshots from this session
- `Session.pendingSubagentTasks()` → only `running` entries

Regenerated index.d.ts also picks up doc-comment drift and napi-rs
ordering churn that had accumulated since the last build. The hand-added
type aliases (ToolErrorKind union, VerificationStatus / VerificationCheck
/ VerificationReport / ToolArtifact) are preserved — they aren't
generatable from Rust and have to be reinserted around each rebuild.

test.mjs gains a small smoke block confirming the three methods exist
and return the expected empty-state shapes (array, array, null).
@ZhiXiao-Lin ZhiXiao-Lin force-pushed the feat/subagent-node-sdk branch from d5b3b1d to 8f0fd3a Compare May 23, 2026 16:01
@ZhiXiao-Lin ZhiXiao-Lin merged commit c8a77f9 into main May 23, 2026
1 check passed
@ZhiXiao-Lin ZhiXiao-Lin deleted the feat/subagent-node-sdk branch May 23, 2026 16:08
@ZhiXiao-Lin ZhiXiao-Lin mentioned this pull request May 23, 2026
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants