@trim21/personal-pi-extensions 0.0.284 → 0.0.286
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 +1 -1
- package/src/spawn-agent.ts +25 -12
package/package.json
CHANGED
package/src/spawn-agent.ts
CHANGED
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
} from "@earendil-works/pi-coding-agent";
|
|
43
43
|
import { Type } from "typebox";
|
|
44
44
|
|
|
45
|
+
import { type ToolPendant } from "./lib/pendant.js";
|
|
45
46
|
import { type AgentConfig, discoverAgents, formatAgentList } from "./spawn-agent-agents.js";
|
|
46
47
|
|
|
47
48
|
// ── constants ────────────────────────────────────────────────────────────────
|
|
@@ -99,8 +100,6 @@ const spawnAgentSchema = Type.Object({
|
|
|
99
100
|
interface UsageStats {
|
|
100
101
|
input: number;
|
|
101
102
|
output: number;
|
|
102
|
-
cacheRead: number;
|
|
103
|
-
cacheWrite: number;
|
|
104
103
|
cost: number;
|
|
105
104
|
contextTokens: number;
|
|
106
105
|
turns: number;
|
|
@@ -116,6 +115,8 @@ interface SubagentDetails {
|
|
|
116
115
|
model?: string;
|
|
117
116
|
stopReason?: string;
|
|
118
117
|
errorMessage?: string;
|
|
118
|
+
/** 折叠 markdown 面板:父 agent 的 prompt 与父 agent 看到的子 agent 结果。 */
|
|
119
|
+
pendant?: ToolPendant;
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
// ── helpers ──────────────────────────────────────────────────────────────────
|
|
@@ -156,14 +157,17 @@ function formatUsageStats(usage: UsageStats, model?: string): string {
|
|
|
156
157
|
if (usage.turns) parts.push(`${usage.turns} turn${usage.turns > 1 ? "s" : ""}`);
|
|
157
158
|
if (usage.input) parts.push(`↑${formatTokens(usage.input)}`);
|
|
158
159
|
if (usage.output) parts.push(`↓${formatTokens(usage.output)}`);
|
|
159
|
-
if (usage.cacheRead) parts.push(`R${formatTokens(usage.cacheRead)}`);
|
|
160
|
-
if (usage.cacheWrite) parts.push(`W${formatTokens(usage.cacheWrite)}`);
|
|
161
160
|
if (usage.cost) parts.push(`$${usage.cost.toFixed(4)}`);
|
|
162
161
|
if (usage.contextTokens > 0) parts.push(`ctx:${formatTokens(usage.contextTokens)}`);
|
|
163
162
|
if (model) parts.push(model);
|
|
164
163
|
return parts.join(" ");
|
|
165
164
|
}
|
|
166
165
|
|
|
166
|
+
/** 子 agent 结果的折叠面板 markdown:父 agent 的 prompt 与父 agent 看到的结果。 */
|
|
167
|
+
function formatPendantMarkdown(task: string, response: string): string {
|
|
168
|
+
return `# prompt:\n${task.trim()}\n# response\n${response.trim()}`;
|
|
169
|
+
}
|
|
170
|
+
|
|
167
171
|
/**
|
|
168
172
|
* Resolve how to spawn the subagent process. Running through the current
|
|
169
173
|
* entry script (when available) keeps model/tool/extension config identical
|
|
@@ -339,8 +343,6 @@ export async function runAgent(
|
|
|
339
343
|
usage: {
|
|
340
344
|
input: 0,
|
|
341
345
|
output: 0,
|
|
342
|
-
cacheRead: 0,
|
|
343
|
-
cacheWrite: 0,
|
|
344
346
|
cost: 0,
|
|
345
347
|
contextTokens: 0,
|
|
346
348
|
turns: 0,
|
|
@@ -492,8 +494,6 @@ export async function runAgent(
|
|
|
492
494
|
result.usage.turns++;
|
|
493
495
|
result.usage.input += msg.usage.input;
|
|
494
496
|
result.usage.output += msg.usage.output;
|
|
495
|
-
result.usage.cacheRead += msg.usage.cacheRead;
|
|
496
|
-
result.usage.cacheWrite += msg.usage.cacheWrite;
|
|
497
497
|
result.usage.cost += msg.usage.cost.total;
|
|
498
498
|
result.usage.contextTokens = msg.usage.totalTokens;
|
|
499
499
|
if (!result.model) result.model = msg.model;
|
|
@@ -648,8 +648,6 @@ export default function spawnAgent(pi: ExtensionAPI) {
|
|
|
648
648
|
usage: {
|
|
649
649
|
input: 0,
|
|
650
650
|
output: 0,
|
|
651
|
-
cacheRead: 0,
|
|
652
|
-
cacheWrite: 0,
|
|
653
651
|
cost: 0,
|
|
654
652
|
contextTokens: 0,
|
|
655
653
|
turns: 0,
|
|
@@ -679,7 +677,13 @@ export default function spawnAgent(pi: ExtensionAPI) {
|
|
|
679
677
|
content: [
|
|
680
678
|
{ type: "text", text: `Subagent "${result.agent}" failed (${reason}): ${message}` },
|
|
681
679
|
],
|
|
682
|
-
details:
|
|
680
|
+
details: {
|
|
681
|
+
...result,
|
|
682
|
+
pendant: {
|
|
683
|
+
markdown: formatPendantMarkdown(params.task, message),
|
|
684
|
+
expanded: true,
|
|
685
|
+
} satisfies ToolPendant,
|
|
686
|
+
},
|
|
683
687
|
isError: true,
|
|
684
688
|
};
|
|
685
689
|
}
|
|
@@ -689,7 +693,16 @@ export default function spawnAgent(pi: ExtensionAPI) {
|
|
|
689
693
|
const text = truncation.truncated
|
|
690
694
|
? `${truncation.content}\n\n[Output truncated to ${formatTokens(truncation.content.length)} bytes. Full result preserved in tool details.]`
|
|
691
695
|
: output;
|
|
692
|
-
return {
|
|
696
|
+
return {
|
|
697
|
+
content: [{ type: "text", text }],
|
|
698
|
+
details: {
|
|
699
|
+
...result,
|
|
700
|
+
pendant: {
|
|
701
|
+
markdown: formatPendantMarkdown(params.task, text),
|
|
702
|
+
expanded: false,
|
|
703
|
+
} satisfies ToolPendant,
|
|
704
|
+
},
|
|
705
|
+
};
|
|
693
706
|
},
|
|
694
707
|
|
|
695
708
|
renderCall(args, theme) {
|