@@ -9,18 +9,12 @@ import { formatDurationCompact } from "../../../shared/subagents-format.js";
99import { findTaskByRunIdForOwner } from "../../../tasks/task-owner-access.js" ;
1010import { sanitizeTaskStatusText } from "../../../tasks/task-status.js" ;
1111import type { CommandHandlerResult } from "../commands-types.js" ;
12+ import { formatRunLabel , formatRunStatus } from "../subagents-utils.js" ;
1213import {
13- formatRunLabel ,
14- formatRunStatus ,
15- resolveSubagentTargetFromRuns ,
16- } from "../subagents-utils.js" ;
17- import { type SubagentsCommandContext } from "./shared.js" ;
18-
19- const RECENT_WINDOW_MINUTES = 30 ;
20-
21- function stopWithText ( text : string ) : CommandHandlerResult {
22- return { shouldContinue : false , reply : { text } } ;
23- }
14+ resolveSubagentEntryForToken ,
15+ stopWithText ,
16+ type SubagentsCommandContext ,
17+ } from "./shared.js" ;
2418
2519function formatTimestamp ( valueMs ?: number ) {
2620 if ( ! valueMs || ! Number . isFinite ( valueMs ) || valueMs <= 0 ) {
@@ -49,41 +43,6 @@ function resolveDisplayStatus(
4943 return status === "error" ? "failed" : status ;
5044}
5145
52- function resolveSubagentEntryForToken (
53- runs : SubagentsCommandContext [ "runs" ] ,
54- token : string | undefined ,
55- ) : { entry : SubagentsCommandContext [ "runs" ] [ number ] } | { reply : CommandHandlerResult } {
56- const resolved = resolveSubagentTargetFromRuns ( {
57- runs,
58- token,
59- recentWindowMinutes : RECENT_WINDOW_MINUTES ,
60- label : ( entry ) => formatRunLabel ( entry ) ,
61- aliases : ( entry ) => ( entry . taskName ? [ entry . taskName ] : [ ] ) ,
62- isActive : ( entry ) =>
63- ! entry . endedAt ||
64- Math . max (
65- 0 ,
66- countPendingDescendantRunsFromRuns (
67- getSubagentRunsSnapshotForRead ( subagentRuns ) ,
68- entry . childSessionKey ,
69- ) ,
70- ) > 0 ,
71- errors : {
72- missingTarget : "Missing subagent id." ,
73- invalidIndex : ( value ) => `Invalid subagent index: ${ value } ` ,
74- unknownSession : ( value ) => `Unknown subagent session: ${ value } ` ,
75- ambiguousLabel : ( value ) => `Ambiguous subagent label: ${ value } ` ,
76- ambiguousLabelPrefix : ( value ) => `Ambiguous subagent label prefix: ${ value } ` ,
77- ambiguousRunIdPrefix : ( value ) => `Ambiguous run id prefix: ${ value } ` ,
78- unknownTarget : ( value ) => `Unknown subagent id: ${ value } ` ,
79- } ,
80- } ) ;
81- if ( ! resolved . entry ) {
82- return { reply : stopWithText ( `⚠️ ${ resolved . error ?? "Unknown subagent." } ` ) } ;
83- }
84- return { entry : resolved . entry } ;
85- }
86-
8746function loadSubagentSessionEntry ( params : SubagentsCommandContext [ "params" ] , childKey : string ) {
8847 const parsed = parseAgentSessionKey ( childKey ) ;
8948 const storePath = resolveStorePath ( params . cfg . session ?. store , {
0 commit comments