oira666_pi-subagent 0.6.0 → 0.6.2

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.
@@ -72,7 +72,7 @@ export function registerActivityWidget(state: ExtensionState): void {
72
72
  (tui, theme) => {
73
73
  requestRender = () => tui.requestRender();
74
74
  return {
75
- render: (width) => [theme.fg("dim", formatActivityLine(entries, width))],
75
+ render: (width) => [theme.fg("accent", formatActivityLine(entries, width))],
76
76
  invalidate() {},
77
77
  };
78
78
  },
@@ -7,11 +7,13 @@ export function startedResult(
7
7
  name: string | undefined,
8
8
  budget: SubagentBudget | undefined,
9
9
  sessionDir: string,
10
+ intelligence?: string,
10
11
  ): SingleResult {
11
12
  return {
12
13
  agent: task.agent,
13
14
  task: task.task,
14
15
  name,
16
+ intelligence,
15
17
  budget,
16
18
  sessionDir,
17
19
  agentSource: "unknown",
@@ -233,7 +233,6 @@ export function registerSubagentsTool(state: ExtensionState) {
233
233
  if (resumePlanIndex >= 0) state.pendingResumePlans.splice(resumePlanIndex, 1);
234
234
  state.recoveryPlansByToolCallId?.delete(toolCallId);
235
235
 
236
- // Names are unique across the tree and reused during recovery.
237
236
  const names: Array<string | undefined> = tasks.map(
238
237
  (_task, index) => resumePlan?.details?.results[index]?.name,
239
238
  );
@@ -317,6 +316,7 @@ export function registerSubagentsTool(state: ExtensionState) {
317
316
  names[index],
318
317
  budgets[index],
319
318
  getSessionDirForTask(state, resumePlan?.previousToolCallId ?? toolCallId, index),
319
+ selectIntelligence(state.intelligencePresets, task.intelligence, state.settings)?.name,
320
320
  ),
321
321
  ),
322
322
  ),
@@ -0,0 +1,19 @@
1
+ import { readCurrentRegistry } from "./expand-command.js";
2
+ import type { ExtensionState } from "./state.js";
3
+
4
+ export interface MessageRecipient {
5
+ name: string;
6
+ agent?: string;
7
+ intelligence?: string;
8
+ }
9
+
10
+ /** Original launch identity, never inferred from the lead's model or current presets. */
11
+ export function resolveMessageRecipient(state: ExtensionState, name: string): MessageRecipient {
12
+ try {
13
+ const record = readCurrentRegistry(state)?.agents[name];
14
+ if (record) return { name: record.name, agent: record.agent, intelligence: record.intelligence };
15
+ } catch {
16
+ // A missing registry must not break historical rendering or live steering.
17
+ }
18
+ return { name };
19
+ }
@@ -14,7 +14,9 @@ import {
14
14
  updateNameRecord,
15
15
  } from "../names.js";
16
16
  import { originalModelSettings } from "../storage/session-settings.js";
17
- import { recordToolCallStart, renderResult } from "../render.js";
17
+ import { formatSubagentLabel } from "../ui/agent-label.js";
18
+ import { resolveMessageRecipient, type MessageRecipient } from "./message-identity.js";
19
+ import { recordToolCallStart, renderMessageResult } from "../render.js";
18
20
  import { buildSubagentDetails, DEFAULT_DELEGATION_MODE } from "../types.js";
19
21
  import { startBackground } from "./async-jobs.js";
20
22
  import { updateLatestBroadcastTargets } from "./broadcast.js";
@@ -49,6 +51,7 @@ export function registerMessageSubagentTool(state: ExtensionState) {
49
51
  const namesFile = state.currentNamesFile;
50
52
  const ownerId = state.currentOwnerId;
51
53
  const localGuards = state.activeResumeNames;
54
+ let recipient: MessageRecipient | undefined;
52
55
  let guardedName: string | undefined;
53
56
  let marked = false;
54
57
  let backgroundOwnsCleanup = false;
@@ -66,10 +69,14 @@ export function registerMessageSubagentTool(state: ExtensionState) {
66
69
  };
67
70
  const result = (text: string) => ({
68
71
  content: [{ type: "text" as const, text }],
69
- details: buildSubagentDetails("parallel", DEFAULT_DELEGATION_MODE, null, []),
72
+ details: Object.assign(
73
+ buildSubagentDetails("parallel", DEFAULT_DELEGATION_MODE, null, []),
74
+ recipient ? { recipient } : {},
75
+ ),
70
76
  });
71
77
  try {
72
78
  const { name, message, max_subagents_allowed } = validatePreparedArguments(MessageSubagentParams, rawParams);
79
+ recipient = resolveMessageRecipient(state, name);
73
80
  checkCurrent();
74
81
  if (!state.canDelegate || resumableSubagentsDisabled(state.settings))
75
82
  throw new Error("Subagent messaging is disabled for this session.");
@@ -144,6 +151,11 @@ export function registerMessageSubagentTool(state: ExtensionState) {
144
151
  const resolution = await resolveResumeTarget(namesFile, name, ownerId);
145
152
  checkCurrent();
146
153
  if ("error" in resolution) throw new Error(resolution.error);
154
+ recipient = {
155
+ name: resolution.record.name,
156
+ agent: resolution.record.agent,
157
+ intelligence: resolution.record.intelligence,
158
+ };
147
159
  const definition = discovery.agents.find((agent) => agent.name === resolution.record.agent);
148
160
  if (definition && !isAgentEnabledAtLayer(definition, state.currentDepth + 1, state.maxDepth)) {
149
161
  throw new Error(
@@ -235,12 +247,16 @@ export function registerMessageSubagentTool(state: ExtensionState) {
235
247
  }
236
248
  },
237
249
 
238
- renderCall: (args, theme) =>
239
- new Text(
240
- `${theme.fg("toolTitle", theme.bold("message subagent "))}${theme.fg("accent", typeof args.name === "string" ? args.name : "")}`,
250
+ renderCall: (args, theme, context) => {
251
+ const name = typeof args.name === "string" ? args.name : "";
252
+ const cache = context?.state ?? {};
253
+ if (!cache.recipient || cache.recipient.name !== name) cache.recipient = resolveMessageRecipient(state, name);
254
+ return new Text(
255
+ `${theme.fg("toolTitle", theme.bold("message subagent "))}${theme.fg("accent", formatSubagentLabel(cache.recipient))}`,
241
256
  0,
242
257
  0,
243
- ),
244
- renderResult: (result, { expanded }, theme, context) => renderResult(result, expanded, theme, context),
258
+ );
259
+ },
260
+ renderResult: (result, { expanded }, theme, context) => renderMessageResult(result, expanded, theme, context),
245
261
  });
246
262
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oira666_pi-subagent",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Subagent extension for Pi coding agent. Delegate tasks to specialized agents.",
5
5
  "type": "module",
6
6
  "main": "index.ts",
package/render.ts CHANGED
@@ -14,6 +14,7 @@ const fitLine = (text: string, width: number) =>
14
14
  truncateToWidth(text, width, "").replace(/\u001b\[0m/g, "\u001b[22;23;24;25;27;28;29;39m");
15
15
 
16
16
  import { MAX_LIVE_LOG_ENTRIES, isSubagentDetails, type SubagentDetails } from "./types.js";
17
+ import { isRecord } from "./types/records.js";
17
18
  import { formatSubagentLabel } from "./ui/agent-label.js";
18
19
  import {
19
20
  type ThemeFg,
@@ -145,6 +146,46 @@ function takePromptLine(text: string, width: number): { line: string; rest: stri
145
146
  return { line: normalized.slice(0, split), rest: normalized.slice(split).trimStart() };
146
147
  }
147
148
 
149
+ function promptPreviewLines(prefix: string, prompt: string, width: number, theme: { fg: ThemeFg }): string[] {
150
+ if (width <= 0) return [];
151
+ const prefixWidth = visibleWidth(prefix);
152
+ const first = takePromptLine(prompt, Math.max(0, width - prefixWidth));
153
+ const indent = " ".repeat(Math.min(prefixWidth, Math.max(0, width - 8)));
154
+ const secondWidth = Math.max(0, width - indent.length);
155
+ const second = takePromptLine(first.rest, secondWidth);
156
+ const lines = [fitLine(`${prefix}${theme.fg("dim", first.line)}`, width)];
157
+ if (first.rest) {
158
+ const text = second.rest ? truncateToWidth(first.rest, secondWidth) : second.line;
159
+ lines.push(fitLine(`${indent}${theme.fg("dim", text)}`, width));
160
+ }
161
+ return lines;
162
+ }
163
+
164
+ export function renderMessageResult(
165
+ result: { content: Array<{ type: string; text?: string }>; details?: unknown },
166
+ expanded: boolean,
167
+ theme: { fg: ThemeFg; bold: (s: string) => string },
168
+ context?: ResultRenderContext & { args?: { name?: string; message?: string }; isError?: boolean },
169
+ ): Component {
170
+ const message = context?.args?.message;
171
+ if (context?.isError || typeof message !== "string") return renderResult(result, expanded, theme, context);
172
+ const recipient =
173
+ isRecord(result.details) && isRecord(result.details.recipient) ? result.details.recipient : undefined;
174
+ const label = formatSubagentLabel({
175
+ name: recipient?.name ?? context?.args?.name,
176
+ agent: recipient?.agent,
177
+ intelligence: recipient?.intelligence,
178
+ });
179
+ const prefix = ` ${statusEmoji("success", theme)} ${theme.fg("accent", label)} `;
180
+ return {
181
+ render: (width) =>
182
+ expanded
183
+ ? new Text(`${prefix}${theme.fg("dim", message)}`, 0, 0).render(width).map((line) => fitLine(line, width))
184
+ : promptPreviewLines(prefix, message, width, theme),
185
+ invalidate() {},
186
+ };
187
+ }
188
+
148
189
  class CollapsedSubagentComponent implements Component {
149
190
  constructor(
150
191
  private readonly details: SubagentDetails,
@@ -157,19 +198,7 @@ class CollapsedSubagentComponent implements Component {
157
198
  const lines: string[] = [];
158
199
  for (const node of nodes) {
159
200
  const prefix = ` ${statusEmoji(node.status, this.theme)} ${this.theme.fg("accent", node.label)} `;
160
- const prefixWidth = visibleWidth(prefix);
161
- const firstWidth = Math.max(0, width - prefixWidth);
162
- const first = takePromptLine(node.task ?? "", firstWidth);
163
- const continuationIndent = " ".repeat(Math.min(prefixWidth, Math.max(0, width - 8)));
164
- const secondWidth = Math.max(0, width - continuationIndent.length);
165
- const second = takePromptLine(first.rest, secondWidth);
166
- const firstLine = `${prefix}${this.theme.fg("dim", first.line)}`;
167
- lines.push(fitLine(firstLine, width));
168
- if (first.rest) {
169
- const hasMore = second.rest.length > 0;
170
- const secondText = hasMore ? truncateToWidth(first.rest, secondWidth) : second.line;
171
- lines.push(fitLine(`${continuationIndent}${this.theme.fg("dim", secondText)}`, width));
172
- }
201
+ lines.push(...promptPreviewLines(prefix, node.task ?? "", width, this.theme));
173
202
  const actionAt = node.lastActionAt ?? node.startedAt;
174
203
  if (actionAt !== undefined) {
175
204
  lines.push(fitLine(` ${this.theme.fg("muted", `last action: ${formatClockTime(actionAt)}`)}`, width));