@sorbetai/acp 0.1.0-alpha.6 → 0.1.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/COMPATIBILITY.md +50 -50
  2. package/README.md +17 -7
  3. package/agent.json +1 -1
  4. package/dist/{agent-S0BFq45U.d.ts → agent-C4eZ3fM5.d.ts} +2 -2
  5. package/dist/{agent-BovB-tw0.js → agent-Hg6W1x79.js} +60 -11
  6. package/dist/agent-Hg6W1x79.js.map +1 -0
  7. package/dist/{authentication-BIVmLfrb.js → authentication-DqnfuE1j.js} +2 -2
  8. package/dist/{authentication-BIVmLfrb.js.map → authentication-DqnfuE1j.js.map} +1 -1
  9. package/dist/{compatibility-DbQl9fV9.js → compatibility-B8zJ4Hvy.js} +4 -4
  10. package/dist/compatibility-B8zJ4Hvy.js.map +1 -0
  11. package/dist/{compatibility-87fR9ZAa.d.ts → compatibility-Ct84-yRf.d.ts} +4 -4
  12. package/dist/compatibility.d.ts +1 -1
  13. package/dist/compatibility.js +1 -1
  14. package/dist/{credentials-CHHCSH_7.d.ts → credentials-Bx8QHoD8.d.ts} +125 -48
  15. package/dist/{experimental-v2-CY-_9I4S.js → experimental-v2-BNgyrD04.js} +13 -4
  16. package/dist/experimental-v2-BNgyrD04.js.map +1 -0
  17. package/dist/{experimental-v2-BoLcFf2t.d.ts → experimental-v2-CRebIPzb.d.ts} +2 -2
  18. package/dist/experimental-v2.d.ts +2 -2
  19. package/dist/experimental-v2.js +3 -3
  20. package/dist/index.d.ts +3 -3
  21. package/dist/index.js +5 -5
  22. package/dist/{mcp-host-profile-RdE3910q.js → mcp-host-profile-DwqBWLFr.js} +3 -3
  23. package/dist/{mcp-host-profile-RdE3910q.js.map → mcp-host-profile-DwqBWLFr.js.map} +1 -1
  24. package/dist/mcp-host.js +1 -1
  25. package/dist/{otlp-BUnHo5Yu.js → otlp-DkgxJDmt.js} +2 -2
  26. package/dist/{otlp-BUnHo5Yu.js.map → otlp-DkgxJDmt.js.map} +1 -1
  27. package/dist/{prompt-work-GOaSft-m.js → prompt-work-CuU_ae0j.js} +1110 -616
  28. package/dist/prompt-work-CuU_ae0j.js.map +1 -0
  29. package/dist/{src-Bc3Cz0DW.js → src-BS-YX8_H.js} +3 -3
  30. package/dist/{src-Bc3Cz0DW.js.map → src-BS-YX8_H.js.map} +1 -1
  31. package/dist/{stdio-cli-main-C2eTBZdr.js → stdio-cli-main-LPIpwqu4.js} +12 -12
  32. package/dist/{stdio-cli-main-C2eTBZdr.js.map → stdio-cli-main-LPIpwqu4.js.map} +1 -1
  33. package/dist/stdio-cli.js +1 -1
  34. package/dist/{stdio-CR8vZgia.js → stdio-kKREJ6jP.js} +3 -3
  35. package/dist/{stdio-CR8vZgia.js.map → stdio-kKREJ6jP.js.map} +1 -1
  36. package/dist/stdio.d.ts +3 -3
  37. package/dist/stdio.js +5 -5
  38. package/package.json +10 -10
  39. package/dist/agent-BovB-tw0.js.map +0 -1
  40. package/dist/compatibility-DbQl9fV9.js.map +0 -1
  41. package/dist/experimental-v2-CY-_9I4S.js.map +0 -1
  42. package/dist/prompt-work-GOaSft-m.js.map +0 -1
package/COMPATIBILITY.md CHANGED
@@ -99,23 +99,23 @@ supported behavior is connected and operational.
99
99
 
100
100
  ## Stable v1 Session updates
101
101
 
102
- | Protocol item | Status | Notes |
103
- | --------------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------- |
104
- | `user_message_chunk` | ✅ Supported | Emitted while replaying durable user conversation entries. |
105
- | `agent_message_chunk` | ✅ Supported | Streams Pi assistant text and replays durable assistant messages. |
106
- | `agent_thought_chunk` | ✅ Supported | Streams Pi thinking deltas when the model produces them. |
107
- | `tool_call` | ✅ Supported | Publishes complete Pi Tool calls after argument streaming finishes. |
108
- | `tool_call_update` | ✅ Supported | Publishes Tool execution status, partial results, and terminal outcomes. |
109
- | `plan` | ✅ Supported | Projects durable checklist entries for Clients using the stable legacy Plan update. |
110
- | `plan_update` | ✅ Supported | Projects durable item and Markdown Plans when the Client advertises Plan capability. |
111
- | `plan_removed` | ✅ Supported | Removes a projected Plan when the Client advertises Plan capability. |
112
- | `available_commands_update` | ✅ Supported | Publishes Session slash command snapshots and routes client prompt invocations through the Session command owner. |
113
- | `compaction_summary_chunk` | ❌ Unsupported | Sorbet does not yet stream standard ACP compaction summary chunks. |
114
- | `compaction_update` | ❌ Unsupported | Sorbet compaction is currently projected through the Lody extension only. |
115
- | `current_mode_update` | ✅ Supported | Emitted when the Client selects the sole advertised default mode. |
116
- | `config_option_update` | ✅ Supported | Emitted after an advertised Session config option changes. |
117
- | `session_info_update` | ✅ Supported | Publishes durable titles with Lody titleSource provenance, activity timestamps, and MCP startup warnings. |
118
- | `usage_update` | ✅ Supported | Publishes current context occupancy, model context size, and cumulative Session cost. |
102
+ | Protocol item | Status | Notes |
103
+ | --------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
104
+ | `user_message_chunk` | ✅ Supported | Emitted while replaying durable user conversation entries. |
105
+ | `agent_message_chunk` | ✅ Supported | Streams Pi assistant text and replays durable assistant messages. |
106
+ | `agent_thought_chunk` | ✅ Supported | Streams Pi thinking deltas when the model produces them. |
107
+ | `tool_call` | ✅ Supported | Publishes complete Pi Tool calls after argument streaming finishes. |
108
+ | `tool_call_update` | ✅ Supported | Publishes Tool execution status, partial results, and terminal outcomes. |
109
+ | `plan` | ✅ Supported | Projects durable checklist entries for Clients using the stable legacy Plan update. |
110
+ | `plan_update` | ✅ Supported | Projects durable item and Markdown Plans when the Client advertises Plan capability. |
111
+ | `plan_removed` | ✅ Supported | Removes a projected Plan when the Client advertises Plan capability. |
112
+ | `available_commands_update` | ✅ Supported | Publishes Session slash command snapshots and routes client prompt invocations through the Session command owner. |
113
+ | `compaction_summary_chunk` | ❌ Unsupported | Sorbet does not yet stream standard ACP compaction summary chunks. |
114
+ | `compaction_update` | ❌ Unsupported | Sorbet compaction is currently projected through the Lody extension only. |
115
+ | `current_mode_update` | ✅ Supported | Emitted when the Client selects the sole advertised default mode. |
116
+ | `config_option_update` | ✅ Supported | Emitted after an advertised Session config option changes. |
117
+ | `session_info_update` | ✅ Supported | Publishes durable titles with Lody titleSource provenance, activity timestamps, and MCP startup warnings. |
118
+ | `usage_update` | ✅ Supported | Publishes Session cost and context occupancy; the newest Run subtotal, unsettled request counters, and occupancy provenance travel under _meta.sorbet. |
119
119
 
120
120
  ## Experimental v2 Agent methods
121
121
 
@@ -162,27 +162,27 @@ supported behavior is connected and operational.
162
162
 
163
163
  ## Experimental v2 Session updates
164
164
 
165
- | Protocol item | Status | Notes |
166
- | --------------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------- |
167
- | `user_message_chunk` | ✅ Supported | Emitted for accepted prompts and replay before the authoritative user_message upsert. |
168
- | `user_message` | ✅ Supported | Emitted for accepted prompts and durable conversation replay. |
169
- | `agent_message_chunk` | ✅ Supported | Streams Pi assistant text with stable message IDs. |
170
- | `agent_message` | ✅ Supported | Publishes authoritative final assistant message upserts. |
171
- | `agent_thought_chunk` | ✅ Supported | Streams Pi thinking deltas with stable thought message IDs. |
172
- | `agent_thought` | ✅ Supported | Publishes authoritative final Pi thinking content for live runs and replay. |
173
- | `state_update` | ✅ Supported | Publishes running and exactly one terminal idle transition per prompt. |
174
- | `tool_call_content_chunk` | ✅ Supported | Appends proven Tool content deltas and falls back to replacement updates on rewrites. |
175
- | `tool_call_update` | ✅ Supported | Publishes Tool input, execution status, progress, and terminal output. |
176
- | `terminal_update` | ❌ Unsupported | The v2 adapter has no terminal projection. |
177
- | `terminal_output_chunk` | ❌ Unsupported | The v2 adapter has no terminal projection. |
178
- | `plan_update` | ✅ Supported | Projects durable item and Markdown Plans for live work and replay. |
179
- | `plan_removed` | ✅ Supported | Removes the current durable Plan projection. |
180
- | `available_commands_update` | ✅ Supported | Publishes Session slash command snapshots and routes client prompt invocations through the Session command owner. |
181
- | `compaction_summary_chunk` | ❌ Unsupported | Sorbet does not yet stream standard ACP v2 compaction summary chunks. |
182
- | `compaction_update` | ❌ Unsupported | Sorbet has no standard ACP v2 compaction projection yet. |
183
- | `config_option_update` | ✅ Supported | Emitted after an advertised Session config option changes. |
184
- | `session_info_update` | ✅ Supported | Publishes durable titles with Lody titleSource provenance, activity timestamps, and MCP startup warnings. |
185
- | `usage_update` | ✅ Supported | Publishes current context occupancy, model context size, and cumulative Session cost. |
165
+ | Protocol item | Status | Notes |
166
+ | --------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
167
+ | `user_message_chunk` | ✅ Supported | Emitted for accepted prompts and replay before the authoritative user_message upsert. |
168
+ | `user_message` | ✅ Supported | Emitted for accepted prompts and durable conversation replay. |
169
+ | `agent_message_chunk` | ✅ Supported | Streams Pi assistant text with stable message IDs. |
170
+ | `agent_message` | ✅ Supported | Publishes authoritative final assistant message upserts. |
171
+ | `agent_thought_chunk` | ✅ Supported | Streams Pi thinking deltas with stable thought message IDs. |
172
+ | `agent_thought` | ✅ Supported | Publishes authoritative final Pi thinking content for live runs and replay. |
173
+ | `state_update` | ✅ Supported | Publishes running and exactly one terminal idle transition per prompt. |
174
+ | `tool_call_content_chunk` | ✅ Supported | Appends proven Tool content deltas and falls back to replacement updates on rewrites. |
175
+ | `tool_call_update` | ✅ Supported | Publishes Tool input, execution status, progress, and terminal output. |
176
+ | `terminal_update` | ❌ Unsupported | The v2 adapter has no terminal projection. |
177
+ | `terminal_output_chunk` | ❌ Unsupported | The v2 adapter has no terminal projection. |
178
+ | `plan_update` | ✅ Supported | Projects durable item and Markdown Plans for live work and replay. |
179
+ | `plan_removed` | ✅ Supported | Removes the current durable Plan projection. |
180
+ | `available_commands_update` | ✅ Supported | Publishes Session slash command snapshots and routes client prompt invocations through the Session command owner. |
181
+ | `compaction_summary_chunk` | ❌ Unsupported | Sorbet does not yet stream standard ACP v2 compaction summary chunks. |
182
+ | `compaction_update` | ❌ Unsupported | Sorbet has no standard ACP v2 compaction projection yet. |
183
+ | `config_option_update` | ✅ Supported | Emitted after an advertised Session config option changes. |
184
+ | `session_info_update` | ✅ Supported | Publishes durable titles with Lody titleSource provenance, activity timestamps, and MCP startup warnings. |
185
+ | `usage_update` | ✅ Supported | Publishes Session cost and context occupancy; the newest Run subtotal, unsettled request counters, and occupancy provenance travel under _meta.sorbet. |
186
186
 
187
187
  ## Shared protocol methods
188
188
 
@@ -208,18 +208,18 @@ supported behavior is connected and operational.
208
208
 
209
209
  ## Lody custom methods
210
210
 
211
- | Protocol item | Status | Notes |
212
- | ----------------------------- | -------------- | --------------------------------------------------------------------------------- |
213
- | `_lody/session/usage_update` | ✅ Supported | Emits cumulative Session and per-model usage after each assistant message. |
214
- | `_lody/rate_limits/get` | ❌ Unsupported | No Provider rate-limit query source is connected. |
215
- | `_lody/rate_limits/update` | ❌ Unsupported | No Provider rate-limit update source is connected. |
216
- | `_lody/session/steer` | ✅ Supported | Injects content into the active Run and returns failed while the Session is idle. |
217
- | `_lody/session/steer_applied` | ✅ Supported | Acknowledges the exact steer identity after Runtime injection succeeds. |
218
- | `_lody/session/goal` | ✅ Supported | Controls the durable Goal through set, pause, resume, and clear actions. |
219
- | `_lody/session/history/read` | ✅ Supported | Replays durable user and assistant conversation through standard Session updates. |
220
- | `_lody/subagents/list` | ✅ Supported | Lists durable Sorbet child-agent snapshots owned by the attached parent Session. |
221
- | `_lody/subagents/cancel` | ✅ Supported | Cancels and closes the requested Sorbet child agent. |
222
- | `_lody/subagents/output` | ✅ Supported | Returns the durable completed child response with optional line tailing. |
211
+ | Protocol item | Status | Notes |
212
+ | ----------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
213
+ | `_lody/session/usage_update` | ✅ Supported | Emits the newest Run subtotal in `usage`, cumulative per-model totals keyed by model id, an optional per-step delta, and subagent spend folded into the owning Session after each assistant message. |
214
+ | `_lody/rate_limits/get` | ❌ Unsupported | No Provider rate-limit query source is connected. |
215
+ | `_lody/rate_limits/update` | ❌ Unsupported | No Provider rate-limit update source is connected. |
216
+ | `_lody/session/steer` | ✅ Supported | Injects content into the active Run and returns failed while the Session is idle. |
217
+ | `_lody/session/steer_applied` | ✅ Supported | Acknowledges the exact steer identity after Runtime injection succeeds. |
218
+ | `_lody/session/goal` | ✅ Supported | Controls the durable Goal through set, pause, resume, and clear actions. |
219
+ | `_lody/session/history/read` | ✅ Supported | Replays durable user and assistant conversation through standard Session updates. |
220
+ | `_lody/subagents/list` | ✅ Supported | Lists durable Sorbet child-agent snapshots owned by the attached parent Session. |
221
+ | `_lody/subagents/cancel` | ✅ Supported | Cancels and closes the requested Sorbet child agent. |
222
+ | `_lody/subagents/output` | ✅ Supported | Returns the durable completed child response with optional line tailing. |
223
223
 
224
224
  ## Sorbet extensions
225
225
 
package/README.md CHANGED
@@ -349,16 +349,26 @@ for measured costs and rejected simplifications.
349
349
  Both protocol versions publish `usage_update.used` as current context occupancy,
350
350
  including cached tokens, and `size` as the active Session model's context window.
351
351
  They never sum successive requests to calculate occupancy. `cost` is cumulative
352
- Session cost, including committed compaction responses and metered failed attempts.
353
- Usage is reconstructed from the Journal and refreshed after compaction, restore,
354
- and model changes. Before a Provider measurement is available, occupancy is an
352
+ Session cost, including committed compaction responses and metered failed attempts; it
353
+ is `null` when the Provider reported no price, because unknown cost must not read as
354
+ free. `_meta.sorbet` states what the numbers cannot: the occupancy measurement
355
+ (`measured` or `estimated`), the newest Run carrying the top-level `usage` scope, and
356
+ the open, unknown, and partial-usage request counters that make a cumulative total
357
+ provisional. Usage is reconstructed from the Journal and refreshed after compaction,
358
+ restore, and model changes. Before a Provider measurement is available, occupancy is an
355
359
  estimate of the reconstructed request; no context update is sent for an empty
356
360
  Session without request evidence. Estimates are not clamped to the window size.
357
361
 
358
- The v1 detailed Lody notification contains cumulative Session and per-model
359
- billing totals across Runs. A fork inherits context but starts its own billing
360
- history. Model window metadata comes from the runtime model configuration;
361
- custom endpoints with different limits must set `contextWindow` explicitly.
362
+ The v1 detailed Lody notification keeps the two scopes apart: `usage` is the newest
363
+ Run's subtotal, `modelUsage` is cumulative per-model billing across Runs keyed by model
364
+ id, and `delta` reports what the preceding notification newly accounted for. A
365
+ Provider that reports no price leaves `costUSD` absent instead of claiming zero. Child
366
+ Session spend is folded into the owning Session's cumulative rows and reported as
367
+ `_meta.sorbet.subagents`, because a child is not an ACP Session and has no other
368
+ accounting channel; a Client polling `_lody/subagents/list` also refreshes that fold.
369
+ A fork inherits context but starts its own billing history. Model window metadata comes
370
+ from the runtime model configuration; custom endpoints with different limits must set
371
+ `contextWindow` explicitly.
362
372
 
363
373
  ## Lody Extensions
364
374
 
package/agent.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "sorbet",
3
3
  "name": "Sorbet",
4
- "version": "0.1.0-alpha.6",
4
+ "version": "0.1.0-alpha.7",
5
5
  "description": "A durable Agent Harness with Pi-backed model access and ACP v1 plus experimental ACP v2 support.",
6
6
  "repository": "https://github.com/lodyspeak/sorbet",
7
7
  "license": "MIT",
@@ -1,5 +1,5 @@
1
1
  import { n as McpCompositionOptions } from "./index-B1Rr3ylL.js";
2
- import { a as AcpMcpComposition, i as UserPrompt, n as NodeAgent, r as ElicitationComposition, t as AcpCredentialManagement } from "./credentials-CHHCSH_7.js";
2
+ import { a as AcpMcpComposition, i as UserPrompt, n as NodeAgent, r as ElicitationComposition, t as AcpCredentialManagement } from "./credentials-Bx8QHoD8.js";
3
3
  import * as acp from "@agentclientprotocol/sdk";
4
4
 
5
5
  //#region src/prompt.d.ts
@@ -49,4 +49,4 @@ interface SorbetAcpAgent {
49
49
  declare function createSorbetAcpAgent(options: SorbetAcpAgentOptions): SorbetAcpAgent;
50
50
  //#endregion
51
51
  export { createSorbetAcpAgent as a, SorbetAcpAgentOptions as i, AcpAuthenticationMethod as n, AcpAudioDecoder as o, SorbetAcpAgent as r, AcpAuthentication as t };
52
- //# sourceMappingURL=agent-S0BFq45U.d.ts.map
52
+ //# sourceMappingURL=agent-C4eZ3fM5.d.ts.map
@@ -1,6 +1,6 @@
1
- import { A as nodeAgentCredentialManagement, C as SORBET_ACP_VERSION, D as createV1RequestElicitation, E as observeSessionUsage, F as isAuthoritativeSessionTitleSource, H as pluginApplyParser, I as NodeAgentError, L as NodeAgentErrorCode, M as coordinateNodeAgentBehavior, Mt as getGoal, Nt as parseSlashCommand, O as createV1SessionElicitation, Pt as watchSlashCommands, R as JournalCursorSchema, T as detailedUsageUpdate, U as pluginQueryParser, V as AcpPluginComposition, W as pluginWatchParser, a as AcpSessionAttachments, b as AcpMcpAttachment, c as projectBackgroundRun, d as projectedToolTitle, f as toolTitle, g as createV1McpElicitationOptions, h as modelsIncludingCurrent, i as readGoalPromptControl, jt as commandGoal, l as presentationTools, m as modelConfigOptions, n as applyGoalControl, o as lodyTitleSource, p as listRefreshedModels, r as cancelSessionWork, s as sessionRequestError, t as AcpPromptWork, u as projectedToolLabels, v as mcpElicitationProfile, w as contextUsageUpdate, x as connectMcpServers, y as AcpMcpHost } from "./prompt-work-GOaSft-m.js";
1
+ import { C as SORBET_ACP_VERSION, D as withSubagentUsage, E as observeSessionUsage, Ft as watchSlashCommands, G as pluginWatchParser, H as AcpPluginComposition, I as isAuthoritativeSessionTitleSource, L as NodeAgentError, Mt as commandGoal, N as coordinateNodeAgentBehavior, Nt as getGoal, O as createV1RequestElicitation, Pt as parseSlashCommand, R as NodeAgentErrorCode, T as detailedUsageUpdate, U as pluginApplyParser, W as pluginQueryParser, a as AcpSessionAttachments, b as AcpMcpAttachment, c as projectBackgroundRun, d as projectedToolTitle, f as toolTitle, g as createV1McpElicitationOptions, h as modelsIncludingCurrent, i as readGoalPromptControl, j as nodeAgentCredentialManagement, k as createV1SessionElicitation, l as presentationTools, m as modelConfigOptions, n as applyGoalControl, o as lodyTitleSource, p as listRefreshedModels, r as cancelSessionWork, s as sessionRequestError, t as AcpPromptWork, u as projectedToolLabels, v as mcpElicitationProfile, w as contextUsageUpdate, x as connectMcpServers, y as AcpMcpHost, z as JournalCursorSchema } from "./prompt-work-CuU_ae0j.js";
2
2
  import { a as SORBET_CREDENTIALS_VERSION, c as SORBET_PLUGINS_CHANGED, d as SORBET_REPLAY_METHOD, f as SORBET_RUN_INSPECT_METHOD, i as SORBET_CREDENTIALS_LOGOUT_METHOD, l as SORBET_PLUGINS_QUERY, o as SORBET_EXTENSION_VERSION, r as SORBET_CREDENTIALS_LIST_METHOD, s as SORBET_PLUGINS_APPLY, t as SESSION_STEERING_METHOD, u as SORBET_PLUGINS_WATCH } from "./extensions-Eaix9kSN.js";
3
- import { a as SORBET_MCP_QUERY, d as mcpControlParser, f as mcpQueryParser, m as mcpRootsChangedParser, n as SORBET_MCP_CONTROL, o as SORBET_MCP_READ, p as mcpReadParser, s as SORBET_MCP_ROOTS_CHANGED, t as SORBET_MCP_CALL, u as mcpCallParser } from "./mcp-host-profile-RdE3910q.js";
3
+ import { a as SORBET_MCP_QUERY, d as mcpControlParser, f as mcpQueryParser, m as mcpRootsChangedParser, n as SORBET_MCP_CONTROL, o as SORBET_MCP_READ, p as mcpReadParser, s as SORBET_MCP_ROOTS_CHANGED, t as SORBET_MCP_CALL, u as mcpCallParser } from "./mcp-host-profile-DwqBWLFr.js";
4
4
  import { Type } from "typebox";
5
5
  import { Check, Parse } from "typebox/schema";
6
6
  import * as acp from "@agentclientprotocol/sdk";
@@ -1076,10 +1076,12 @@ function buildConnectionApp(options, state) {
1076
1076
  await replayConversation(options.agent, params.sessionId, attached.session, client, presentationTools(attached.bindings, attached.session), state.capabilities.plan != null);
1077
1077
  return {};
1078
1078
  }).onRequest(LODY_EXTENSION_METHODS.subagentsList, lodySubagentsListParser, async ({ params }) => {
1079
- requireAttached(state, params.sessionId);
1079
+ const attached = requireAttached(state, params.sessionId);
1080
1080
  const [children, sessions] = await Promise.all([options.agent.listChildAgents(params.sessionId, { includeClosed: params.activeOnly !== true }), options.agent.listSessions()]);
1081
1081
  const metadata = new Map(sessions.map((session) => [session.sessionId, session]));
1082
- return { tasks: (params.activeOnly === true ? children.agents.filter(({ state: childState }) => ACTIVE_CHILD_STATES.has(childState)) : children.agents).map((child) => lodySubagentTask(child, metadata.get(child.childSessionId))) };
1082
+ const agents = params.activeOnly === true ? children.agents.filter(({ state: childState }) => ACTIVE_CHILD_STATES.has(childState)) : children.agents;
1083
+ await attached.projection.refresh();
1084
+ return { tasks: agents.map((child) => lodySubagentTask(child, metadata.get(child.childSessionId))) };
1083
1085
  }).onRequest(LODY_EXTENSION_METHODS.subagentsCancel, lodySubagentCancelParser, async ({ params, signal }) => {
1084
1086
  requireAttached(state, params.sessionId);
1085
1087
  await options.agent.closeChildAgent(params.sessionId, params.taskId, {
@@ -1521,17 +1523,41 @@ async function replayEntry(sessionId$1, entry, client, tools, children, labels)
1521
1523
  function startSessionProjection(agent, session, client) {
1522
1524
  let closed = false;
1523
1525
  let subscription;
1526
+ const sessionId$1 = session.metadata.sessionId;
1527
+ let childUsage = [];
1528
+ let published;
1529
+ const reloadChildren = async () => {
1530
+ try {
1531
+ const { agents } = await agent.listChildAgents(sessionId$1, { includeClosed: true });
1532
+ childUsage = agents.map(({ modelUsage }) => ({ modelUsage }));
1533
+ } catch {}
1534
+ };
1524
1535
  const usage = observeSessionUsage(session.runtime, async (snapshot) => {
1525
- const context = contextUsageUpdate(snapshot);
1526
- if (context !== void 0) await update(client, session.metadata.sessionId, context);
1527
- if (snapshot.models.length === 0) return;
1528
- await client.notify(LODY_EXTENSION_METHODS.sessionUsageUpdate, detailedUsageUpdate(session.metadata.sessionId, snapshot, agent));
1536
+ const merged = withSubagentUsage(snapshot, childUsage);
1537
+ if (published !== void 0 && isEqual({
1538
+ ...published,
1539
+ cursor: void 0
1540
+ }, {
1541
+ ...merged.snapshot,
1542
+ cursor: void 0
1543
+ })) return;
1544
+ const value = {
1545
+ snapshot: merged.snapshot,
1546
+ ...merged.subagents === void 0 ? {} : { subagents: merged.subagents },
1547
+ ...published === void 0 ? {} : { previous: published }
1548
+ };
1549
+ published = merged.snapshot;
1550
+ const context = contextUsageUpdate(value);
1551
+ if (context !== void 0) await update(client, sessionId$1, context);
1552
+ if (merged.snapshot.models.length === 0) return;
1553
+ await client.notify(LODY_EXTENSION_METHODS.sessionUsageUpdate, detailedUsageUpdate(sessionId$1, value, agent));
1529
1554
  });
1530
1555
  const compactionStartedAt = /* @__PURE__ */ new Map();
1531
1556
  const task = (async () => {
1532
1557
  const { cursor } = await session.runtime.getUsage();
1533
1558
  if (closed) return;
1534
1559
  await publishGoal(session, client);
1560
+ await reloadChildren();
1535
1561
  subscription = session.runtime.facts(cursor === void 0 ? {} : { after: cursor });
1536
1562
  if (closed) {
1537
1563
  subscription.close();
@@ -1540,11 +1566,19 @@ function startSessionProjection(agent, session, client) {
1540
1566
  for await (const fact of subscription) {
1541
1567
  if (closed) return;
1542
1568
  if (factAffectsGoal(fact)) await publishGoal(session, client);
1543
- await projectCompaction(session.metadata.sessionId, fact, compactionStartedAt, client);
1569
+ await projectCompaction(sessionId$1, fact, compactionStartedAt, client);
1570
+ if (factAffectsChildren(fact)) {
1571
+ await reloadChildren();
1572
+ await usage.refresh();
1573
+ }
1544
1574
  }
1545
1575
  })().catch(() => void 0);
1546
1576
  return {
1547
- refresh: usage.refresh,
1577
+ refresh: async () => {
1578
+ if (closed) return;
1579
+ await reloadChildren();
1580
+ await usage.refresh();
1581
+ },
1548
1582
  close: async () => {
1549
1583
  closed = true;
1550
1584
  subscription?.close();
@@ -1603,6 +1637,21 @@ function factAffectsGoal(fact) {
1603
1637
  default: return false;
1604
1638
  }
1605
1639
  }
1640
+ /**
1641
+ * Child Sessions journal their own model requests, so the owning Session sees their spend only when
1642
+ * an `agent` Tool result returns, or when a background completion reaches the Session as input.
1643
+ */
1644
+ function factAffectsChildren(fact) {
1645
+ switch (fact.kind) {
1646
+ case "tool.result.message.committed": {
1647
+ const { source } = fact.payload;
1648
+ return (source.kind === "effect" ? source.toolName : source.message.toolName) === "agent";
1649
+ }
1650
+ case "submission.accepted":
1651
+ case "submission.placed": return true;
1652
+ default: return false;
1653
+ }
1654
+ }
1606
1655
  async function publishGoal(session, client) {
1607
1656
  const goal = await getGoal(session.runtime);
1608
1657
  await update(client, session.metadata.sessionId, {
@@ -1761,4 +1810,4 @@ async function attachOpeningSlashCommands(state, attached, client) {
1761
1810
 
1762
1811
  //#endregion
1763
1812
  export { createSorbetAcpAgent as t };
1764
- //# sourceMappingURL=agent-BovB-tw0.js.map
1813
+ //# sourceMappingURL=agent-Hg6W1x79.js.map