@ian-pascoe/pi-minimal-subagents 0.11.0 → 0.13.0

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.
@@ -41,11 +41,16 @@ export interface SpawnParameters {
41
41
  delegation?: DelegationMode;
42
42
  }
43
43
 
44
- /** Returns persistent agent and turn identities immediately after launch scheduling. */
45
- export interface SpawnResult {
44
+ /** Returns persistent agent and turn identities plus the resolved grant immediately after launch scheduling. */
45
+ export interface SpawnResult extends RuntimeProfile {
46
46
  agent_id: string;
47
47
  turn_id: string;
48
48
  status: "running";
49
+ /** Concrete ordinary tools granted by the Launch Contract. */
50
+ tools: string[];
51
+ delegation: DelegationMode;
52
+ /** Non-fatal tool-resolution warnings, such as skipped configured tools. */
53
+ warnings?: string[];
49
54
  }
50
55
 
51
56
  /** Retains one keyed terminal turn result for waits and durable delivery recovery. */
@@ -59,13 +64,18 @@ export interface TurnResult {
59
64
  elapsed_ms?: number;
60
65
  }
61
66
 
62
- /** Reports whether one direct message was handed to a wait, queued, or failed. */
63
- export type AgentMessageDisposition = "delivered-via-wait" | "queued" | "failed";
67
+ /**
68
+ * Reports whether one direct message was handed to a wait, queued into an active turn, started a
69
+ * new turn on an idle recipient, or failed.
70
+ */
71
+ export type AgentMessageDisposition = "delivered-via-wait" | "queued" | "started-turn" | "failed";
64
72
 
65
73
  export interface AgentMessageResult {
66
74
  agent_id: string;
67
75
  message_id: string;
68
76
  disposition: AgentMessageDisposition;
77
+ /** Turn started on an idle recipient; present only for `started-turn`. */
78
+ turn_id?: string;
69
79
  error?: string;
70
80
  }
71
81
 
@@ -112,7 +122,8 @@ export interface AgentSummary extends RuntimeProfile {
112
122
  latest_activity_at?: string;
113
123
  task?: string;
114
124
  child_count: number;
115
- children: AgentSummary[];
125
+ /** Nested summaries; omitted from caller-scoped status, which reports only `child_count`. */
126
+ children?: AgentSummary[];
116
127
  }
117
128
 
118
129
  /** Provides bounded recent child conversation text for detailed status. */
@@ -129,6 +140,12 @@ export interface RecentAgentActivity {
129
140
  truncated: boolean;
130
141
  }
131
142
 
143
+ /** Live progress of a Child Agent's running turn, shown while its parent waits. */
144
+ export interface ActiveTurnProgress {
145
+ turn_id: string;
146
+ tool_calls: number;
147
+ }
148
+
132
149
  /** Holds the complete selected-branch Child Session Transcript for trusted status UI. */
133
150
  export interface ChildAgentTranscriptSnapshot {
134
151
  messages: AgentMessage[];
@@ -59,7 +59,7 @@ function flattenAgentHierarchy(agents: readonly AgentSummary[]): FlattenedAgentS
59
59
  const flattened: FlattenedAgentSummary[] = [];
60
60
  const visit = (agent: AgentSummary, depth: number, parentId?: string) => {
61
61
  flattened.push({ agent, depth, parentId, order: flattened.length });
62
- for (const child of agent.children) visit(child, depth + 1, agent.agent_id);
62
+ for (const child of agent.children ?? []) visit(child, depth + 1, agent.agent_id);
63
63
  };
64
64
  for (const agent of agents) visit(agent, 0);
65
65
  return flattened;
@@ -1,17 +1,28 @@
1
1
  import type { Usage } from "@earendil-works/pi-ai";
2
2
 
3
+ /** Return a clone with optional counters present, so every reported usage has one shape. */
4
+ export function normalizeMinimalSubagentsUsage(usage: Usage): Usage {
5
+ return {
6
+ ...structuredClone(usage),
7
+ cacheWrite1h: usage.cacheWrite1h ?? 0,
8
+ reasoning: usage.reasoning ?? 0,
9
+ };
10
+ }
11
+
3
12
  /** Add two optional Pi usage totals without retaining mutable references to either input. */
4
13
  export function addMinimalSubagentsUsage(
5
14
  left: Usage | undefined,
6
15
  right: Usage | undefined,
7
16
  ): Usage | undefined {
8
- if (!left) return right ? structuredClone(right) : undefined;
9
- if (!right) return structuredClone(left);
17
+ if (!left) return right ? normalizeMinimalSubagentsUsage(right) : undefined;
18
+ if (!right) return normalizeMinimalSubagentsUsage(left);
10
19
  return {
11
20
  input: left.input + right.input,
12
21
  output: left.output + right.output,
13
22
  cacheRead: left.cacheRead + right.cacheRead,
14
23
  cacheWrite: left.cacheWrite + right.cacheWrite,
24
+ cacheWrite1h: (left.cacheWrite1h ?? 0) + (right.cacheWrite1h ?? 0),
25
+ reasoning: (left.reasoning ?? 0) + (right.reasoning ?? 0),
15
26
  totalTokens: left.totalTokens + right.totalTokens,
16
27
  cost: {
17
28
  input: left.cost.input + right.cost.input,