@yandy0725/pi-subagents 0.4.0 → 0.5.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.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.4.0",
6
+ "version": "0.5.0",
7
7
  "description": "Focused, in-process sub-agent core for pi — autonomous agents plus a typed API and lifecycle events",
8
8
  "license": "MIT",
9
9
  "repository": {
@@ -38,6 +38,8 @@ export interface EvictedSubagent {
38
38
  readonly toolUses: number;
39
39
  /** Short display model name (always shown; falls back to parent model when unset). */
40
40
  readonly modelName?: string;
41
+ /** Thinking level when explicitly set (e.g. "high", "off"). */
42
+ readonly thinking?: string;
41
43
  readonly outputFile: string;
42
44
  }
43
45
 
@@ -371,6 +373,7 @@ function toEvictedSubagent(record: Subagent, outputFile: string): EvictedSubagen
371
373
  completedAt: record.completedAt,
372
374
  toolUses: record.toolUses,
373
375
  modelName: record.invocation?.modelName,
376
+ thinking: record.thinking,
374
377
  outputFile,
375
378
  };
376
379
  }
@@ -133,6 +133,10 @@ export class Subagent {
133
133
  get modelName(): string | undefined {
134
134
  return this.invocation?.modelName;
135
135
  }
136
+ /** Thinking level when explicitly set (e.g. "high", "off"). */
137
+ get thinking(): string | undefined {
138
+ return this.invocation?.thinking;
139
+ }
136
140
 
137
141
  readonly abortController: AbortController;
138
142
  private _promise?: Promise<void>;
@@ -64,6 +64,7 @@ export class SubagentEventsObserver implements SubagentManagerObserver {
64
64
  completedAt: record.completedAt,
65
65
  toolUses: record.toolUses,
66
66
  modelName: record.modelName,
67
+ thinking: record.thinking,
67
68
  outputFile: record.outputFile,
68
69
  });
69
70
 
@@ -10,7 +10,7 @@ import type { WorkspaceProvider } from "../lifecycle/workspace";
10
10
  import type { SpawnOptions, SubagentRecord, SubagentsService } from "../service/service";
11
11
  import type { ModelRegistry } from "../session/model-resolver";
12
12
  import { resolveModelName } from "../tools/spawn-config";
13
- import type { SessionContext, Subagent } from "../types";
13
+ import type { SessionContext, Subagent, ThinkingLevel, AgentInvocation } from "../types";
14
14
 
15
15
  /** Narrow interface for the SubagentManager — avoids coupling to the concrete class. */
16
16
  export interface SubagentManagerLike {
@@ -66,6 +66,11 @@ export class SubagentsServiceAdapter implements SubagentsService {
66
66
  const description = options?.description ?? prompt.slice(0, 80);
67
67
  const isBackground = !(options?.foreground ?? false);
68
68
 
69
+ // Build invocation with modelName + thinkingLevel (not just modelName as before)
70
+ const invocationObj: AgentInvocation = {};
71
+ if (modelName != null) invocationObj.modelName = modelName;
72
+ if (options?.thinkingLevel != null) invocationObj.thinking = options.thinkingLevel as ThinkingLevel;
73
+
69
74
  const snapshot = this.runtime.buildSnapshot(options?.inheritContext ?? false);
70
75
  return this.manager.spawn(snapshot, type, prompt, {
71
76
  description,
@@ -75,9 +80,7 @@ export class SubagentsServiceAdapter implements SubagentsService {
75
80
  inheritContext: options?.inheritContext,
76
81
  bypassQueue: options?.bypassQueue,
77
82
  isBackground,
78
- // Service API builds a display-minimal invocation (modelName only);
79
- // the tool path additionally carries thinking/maxTurns/inherit tags.
80
- invocation: modelName != null ? { modelName } : undefined,
83
+ invocation: Object.keys(invocationObj).length > 0 ? invocationObj : undefined,
81
84
  });
82
85
  }
83
86
 
@@ -37,6 +37,7 @@ interface PersistedSubagentRecord {
37
37
  completedAt: number | undefined;
38
38
  toolUses?: number;
39
39
  modelName?: string;
40
+ thinking?: string;
40
41
  outputFile?: string;
41
42
  }
42
43
 
@@ -100,6 +101,7 @@ export function recoverEvictedSubagents(
100
101
  completedAt: data.completedAt,
101
102
  toolUses: data.toolUses ?? 0,
102
103
  modelName: data.modelName,
104
+ thinking: data.thinking,
103
105
  outputFile,
104
106
  });
105
107
  }
@@ -181,6 +181,7 @@ export class AgentWidget implements SubagentManagerObserver {
181
181
  responseText: record.responseText,
182
182
  contextPercent: record.getContextPercent(),
183
183
  modelName: record.invocation?.modelName,
184
+ thinking: record.invocation?.thinking,
184
185
  };
185
186
  }
186
187
 
@@ -40,6 +40,8 @@ export interface NavigableSubagent {
40
40
  readonly agentMessages: readonly SessionMessage[];
41
41
  /** Short display model name (always shown; falls back to parent model when unset). */
42
42
  readonly modelName?: string;
43
+ /** Thinking level when explicitly set (e.g. "high", "off"). */
44
+ readonly thinking?: string;
43
45
  isSessionReady(): boolean;
44
46
  subscribeToUpdates(fn: (event: AgentSessionEvent) => void): (() => void) | undefined;
45
47
  getToolDefinition(name: string): ToolDefinition | undefined;
@@ -53,7 +55,7 @@ export interface NavigableSubagent {
53
55
  */
54
56
  export type NavigationEntry =
55
57
  | { readonly kind: "live"; readonly label: string; readonly record: NavigableSubagent }
56
- | { readonly kind: "evicted"; readonly label: string; readonly outputFile: string; readonly modelName?: string };
58
+ | { readonly kind: "evicted"; readonly label: string; readonly outputFile: string; readonly modelName?: string; readonly thinking?: string };
57
59
 
58
60
  /** The fields `buildLabel` reads — shared by a live record and an evicted descriptor. */
59
61
  interface LabelFields {
@@ -64,6 +66,7 @@ interface LabelFields {
64
66
  readonly completedAt: number | undefined;
65
67
  readonly toolUses: number;
66
68
  readonly modelName?: string;
69
+ readonly thinking?: string;
67
70
  }
68
71
 
69
72
  /** Running-agent streaming state, surfaced by a live source. */
@@ -104,6 +107,7 @@ export function listNavigableAgents(
104
107
  kind: "evicted",
105
108
  outputFile: descriptor.outputFile,
106
109
  modelName: descriptor.modelName,
110
+ thinking: descriptor.thinking,
107
111
  label: buildLabel(descriptor, registry, true),
108
112
  }),
109
113
  );
@@ -146,7 +150,9 @@ export function liveSource(record: NavigableSubagent): TranscriptSource {
146
150
  function buildLabel(fields: LabelFields, registry: AgentConfigLookup, evicted = false): string {
147
151
  const name = getDisplayName(fields.type, registry);
148
152
  const duration = formatDuration(fields.startedAt, fields.completedAt);
149
- const modelTag = fields.modelName ? ` · model:${fields.modelName}` : "";
153
+ const modelTag = fields.modelName
154
+ ? fields.thinking ? ` · ${fields.modelName} (${fields.thinking})` : ` · ${fields.modelName}`
155
+ : fields.thinking ? ` · think:${fields.thinking}` : "";
150
156
  const marker = evicted ? " · evicted (snapshot)" : "";
151
157
  return `${name} (${fields.description}) · ${fields.toolUses} tools · ${fields.status} · ${duration}${modelTag}${marker}`;
152
158
  }
@@ -94,6 +94,8 @@ export interface TranscriptOverlayOptions {
94
94
  markdownTheme: MarkdownTheme;
95
95
  /** Short model name to show in the header, or undefined to omit. */
96
96
  modelName?: string;
97
+ /** Thinking level to show alongside model name, or undefined to omit. */
98
+ thinking?: string;
97
99
  }
98
100
 
99
101
  /**
@@ -120,13 +122,16 @@ export class SessionNavigatorHandler {
120
122
 
121
123
  let source: TranscriptSource;
122
124
  let modelName: string | undefined;
125
+ let thinking: string | undefined;
123
126
  try {
124
127
  if (entry.kind === "live") {
125
128
  source = liveSource(entry.record);
126
129
  modelName = entry.record.modelName;
130
+ thinking = entry.record.thinking;
127
131
  } else {
128
132
  source = fileSnapshotSource(entry.outputFile, readFile);
129
133
  modelName = entry.modelName;
134
+ thinking = entry.thinking;
130
135
  }
131
136
  } catch {
132
137
  ui.notify("Could not read the session transcript file.", "error");
@@ -135,7 +140,7 @@ export class SessionNavigatorHandler {
135
140
  const markdownTheme = getMarkdownTheme();
136
141
  await ui.custom<undefined>(
137
142
  (tui, theme, _keybindings, done) =>
138
- new TranscriptOverlay({ tui, theme, source, done, cwd, markdownTheme, modelName }),
143
+ new TranscriptOverlay({ tui, theme, source, done, cwd, markdownTheme, modelName, thinking }),
139
144
  {
140
145
  overlay: true,
141
146
  overlayOptions: { anchor: "center", width: "90%", maxHeight: `${VIEWPORT_HEIGHT_PCT}%` },
@@ -186,6 +191,7 @@ export class TranscriptOverlay implements Component {
186
191
  private readonly cwd: string;
187
192
  private readonly markdownTheme: MarkdownTheme;
188
193
  private readonly modelName?: string;
194
+ private readonly thinking?: string;
189
195
  private content: Container;
190
196
 
191
197
  /** Throttle bookkeeping for coalescing live-source rebuilds. */
@@ -197,7 +203,7 @@ export class TranscriptOverlay implements Component {
197
203
  private renderedWidth = -1;
198
204
  private linesDirty = true;
199
205
 
200
- constructor({ tui, theme, source, done, cwd, markdownTheme, modelName }: TranscriptOverlayOptions) {
206
+ constructor({ tui, theme, source, done, cwd, markdownTheme, modelName, thinking }: TranscriptOverlayOptions) {
201
207
  this.tui = tui;
202
208
  this.theme = theme;
203
209
  this.source = source;
@@ -205,6 +211,7 @@ export class TranscriptOverlay implements Component {
205
211
  this.cwd = cwd;
206
212
  this.markdownTheme = markdownTheme;
207
213
  this.modelName = modelName;
214
+ this.thinking = thinking;
208
215
  this.content = this.rebuild();
209
216
  // Seed `lastRebuildAt` far in the past so the first source-change event
210
217
  // always rebuilds immediately (leading-edge throttle). The constructor
@@ -276,7 +283,10 @@ export class TranscriptOverlay implements Component {
276
283
  const hrMid = row(th.fg("dim", "─".repeat(innerW)));
277
284
 
278
285
  lines.push(hrTop);
279
- const title = this.modelName ? `Subagent session · ${this.modelName}` : "Subagent session";
286
+ const modelPart = this.modelName
287
+ ? this.thinking ? ` · ${this.modelName} (${this.thinking})` : ` · ${this.modelName}`
288
+ : "";
289
+ const title = modelPart ? `Subagent session${modelPart}` : "Subagent session";
280
290
  lines.push(row(th.bold(title)));
281
291
  lines.push(hrMid);
282
292
 
@@ -44,6 +44,8 @@ export interface WidgetAgent {
44
44
  readonly contextPercent: number | null;
45
45
  /** Short display model name (always shown; falls back to parent model when unset). */
46
46
  readonly modelName?: string;
47
+ /** Thinking level (e.g. "high", "off") when explicitly set. */
48
+ readonly thinking?: string;
47
49
  }
48
50
 
49
51
  // ── Per-agent rendering ──────────────────────────────────────────────────────
@@ -76,7 +78,11 @@ export function renderFinishedLine(agent: WidgetAgent, registry: AgentConfigLook
76
78
  }
77
79
 
78
80
  const parts: string[] = [];
79
- if (agent.modelName) parts.push(agent.modelName);
81
+ if (agent.modelName) {
82
+ parts.push(agent.thinking ? `${agent.modelName} (${agent.thinking})` : agent.modelName);
83
+ } else if (agent.thinking) {
84
+ parts.push(theme.fg("dim", `think:${agent.thinking}`));
85
+ }
80
86
  parts.push(formatTurns(agent.turnCount, agent.maxTurns));
81
87
  if (agent.toolUses > 0) parts.push(`${agent.toolUses} tool use${agent.toolUses === 1 ? "" : "s"}`);
82
88
  parts.push(duration);
@@ -101,7 +107,11 @@ export function renderRunningLines(
101
107
  const tokenText = tokens > 0 ? formatSessionTokens(tokens, agent.contextPercent, theme, agent.compactionCount) : "";
102
108
 
103
109
  const parts: string[] = [];
104
- if (agent.modelName) parts.push(agent.modelName);
110
+ if (agent.modelName) {
111
+ parts.push(agent.thinking ? `${agent.modelName} (${agent.thinking})` : agent.modelName);
112
+ } else if (agent.thinking) {
113
+ parts.push(theme.fg("dim", `think:${agent.thinking}`));
114
+ }
105
115
  parts.push(formatTurns(agent.turnCount, agent.maxTurns));
106
116
  if (agent.toolUses > 0) parts.push(`${agent.toolUses} tool use${agent.toolUses === 1 ? "" : "s"}`);
107
117
  if (tokenText) parts.push(tokenText);