@@ -29,7 +29,7 @@ import { Markdown, Text } from "@earendil-works/pi-tui";
2929import { Type } from "typebox" ;
3030import { formatElapsed , latestText , REASONING_EFFORTS , type SubagentSnapshot } from "./src/domain.ts" ;
3131import { formatContextUtilization } from "../shared/context-utilization.ts" ;
32- import { registerTransientSegment } from "../shared/footer-segments.ts" ;
32+ import { registerBackgroundCost , registerTransientSegment } from "../shared/footer-segments.ts" ;
3333import { resolveStandaloneChildProjectTrust } from "../shared/child-session.ts" ;
3434import { SubagentManager , type SubagentManagerShape } from "./src/manager.ts" ;
3535import {
@@ -86,6 +86,7 @@ export function setupSubagents(pi: ExtensionAPI, background: BackgroundHub) {
8686 let sessionContext : ExtensionContext | undefined ;
8787 let ui : ExtensionUIContext | undefined ;
8888 let unsubStatus : ( ( ) => void ) | undefined ;
89+ let costKey : string | undefined ;
8990 const resultDelivery = createDeferredResultDelivery < SubagentSnapshot > ( ) ;
9091
9192 const getRuntime = ( ) => ( runtime ??= createSubagentRuntime ( ) ) ;
@@ -106,17 +107,21 @@ export function setupSubagents(pi: ExtensionAPI, background: BackgroundHub) {
106107 } ;
107108
108109 const updateStatus = ( manager : SubagentManagerShape ) => {
109- if ( ! ui ) return ;
110110 const subs = manager . view . list ( ) ;
111+ if ( costKey )
112+ registerBackgroundCost (
113+ costKey ,
114+ subs . reduce ( ( total , snap ) => total + snap . cost , 0 ) ,
115+ ) ;
116+ if ( ! ui ) return ;
111117 if ( subs . length === 0 ) {
112118 registerTransientSegment ( "subagents" , null ) ;
113119 return ;
114120 }
115121 const running = subs . filter ( ( snap ) => snap . status === "running" ) . length ;
116122 const failed = subs . filter ( ( snap ) => snap . status === "error" ) . length ;
117123 const done = subs . length - running - failed ;
118- const cost = subs . reduce ( ( total , snap ) => total + snap . cost , 0 ) ;
119- const parts : string [ ] = [ `$${ cost . toFixed ( 2 ) } sub` ] ;
124+ const parts : string [ ] = [ ] ;
120125 if ( running > 0 ) parts . push ( `${ running } running` ) ;
121126 if ( done > 0 ) parts . push ( `${ done } done` ) ;
122127 if ( failed > 0 ) parts . push ( `${ failed } failed` ) ;
@@ -163,6 +168,7 @@ export function setupSubagents(pi: ExtensionAPI, background: BackgroundHub) {
163168
164169 pi . on ( "session_start" , ( _event , ctx ) => {
165170 sessionContext = ctx ;
171+ costKey = `subagents:${ ctx . sessionManager . getSessionId ( ) } ` ;
166172 if ( ctx . hasUI ) ui = ctx . ui ;
167173 unregisterProvider ?.( ) ;
168174 unregisterProvider = background . registerProvider ( "subagents" , {
@@ -203,6 +209,8 @@ export function setupSubagents(pi: ExtensionAPI, background: BackgroundHub) {
203209 unsubStatus ?.( ) ;
204210 unsubStatus = undefined ;
205211 registerTransientSegment ( "subagents" , null ) ;
212+ if ( costKey ) registerBackgroundCost ( costKey , null ) ;
213+ costKey = undefined ;
206214 const closing = runtime ;
207215 runtime = undefined ;
208216 managerPromise = undefined ;
@@ -246,11 +254,14 @@ export function setupSubagents(pi: ExtensionAPI, background: BackgroundHub) {
246254 ) ,
247255 } ) ,
248256 renderCall ( args , theme ) {
249- return new Text (
250- theme . fg ( "toolTitle" , "subagent_spawn" ) + ( args . name ? " " + theme . fg ( "dim" , String ( args . name ) ) : "" ) ,
251- 0 ,
252- 0 ,
253- ) ;
257+ const lines = [
258+ theme . fg ( "toolTitle" , "subagent_spawn" ) + ( args . name ? " " + theme . fg ( "dim" , args . name ) : "" ) ,
259+ ...( args . prompt ? [ theme . fg ( "text" , args . prompt ) ] : [ ] ) ,
260+ ...( args . working_dir ? [ theme . fg ( "muted" , `cwd: ${ args . working_dir } ` ) ] : [ ] ) ,
261+ ...( args . model ? [ theme . fg ( "muted" , `model: ${ args . model } ` ) ] : [ ] ) ,
262+ ...( args . reasoning_effort ? [ theme . fg ( "muted" , `effort: ${ args . reasoning_effort } ` ) ] : [ ] ) ,
263+ ] ;
264+ return new Text ( lines . join ( "\n" ) , 0 , 0 ) ;
254265 } ,
255266 async execute ( _toolCallId , params , _signal , _onUpdate , ctx ) {
256267 const manager = await getManager ( ) ;
0 commit comments