pi-subagentura 1.0.5 → 1.0.7
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/helpers.ts +46 -9
- package/package.json +1 -1
- package/subagent.ts +2 -3
package/helpers.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { randomBytes } from "node:crypto";
|
|
9
|
+
import { appendFileSync, mkdirSync, existsSync } from "node:fs";
|
|
10
|
+
import { resolve } from "node:path";
|
|
9
11
|
import { getModel, getProviders } from "@mariozechner/pi-ai";
|
|
10
12
|
import type { Model } from "@mariozechner/pi-ai";
|
|
11
13
|
|
|
@@ -21,6 +23,49 @@ import {
|
|
|
21
23
|
type AgentSession,
|
|
22
24
|
} from "@mariozechner/pi-coding-agent";
|
|
23
25
|
|
|
26
|
+
// ── Debug Logging ─────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
const DEBUG_LOG_DIR = process.env.SUBAGENT_DEBUG_LOG_DIR
|
|
29
|
+
? resolve(process.env.SUBAGENT_DEBUG_LOG_DIR)
|
|
30
|
+
: resolve(process.cwd(), ".pi/subagent-logs");
|
|
31
|
+
|
|
32
|
+
export function debugLog(level: string, event: string, data: Record<string, unknown> = {}) {
|
|
33
|
+
try {
|
|
34
|
+
if (!existsSync(DEBUG_LOG_DIR)) {
|
|
35
|
+
mkdirSync(DEBUG_LOG_DIR, { recursive: true });
|
|
36
|
+
}
|
|
37
|
+
const entry = JSON.stringify({
|
|
38
|
+
timestamp: new Date().toISOString(),
|
|
39
|
+
level,
|
|
40
|
+
event,
|
|
41
|
+
...data,
|
|
42
|
+
}) + "\n";
|
|
43
|
+
const fileName = resolve(DEBUG_LOG_DIR, `debug-${new Date().toISOString().slice(0, 10)}.jsonl`);
|
|
44
|
+
appendFileSync(fileName, entry);
|
|
45
|
+
} catch {
|
|
46
|
+
// Silently fail to avoid polluting output
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function extractTextFromContent(content: unknown): string {
|
|
51
|
+
if (Array.isArray(content)) {
|
|
52
|
+
return content
|
|
53
|
+
.filter((c): c is { type: "text"; text: string } =>
|
|
54
|
+
typeof c === "object" && c !== null && c.type === "text" && typeof c.text === "string"
|
|
55
|
+
)
|
|
56
|
+
.map((c) => c.text)
|
|
57
|
+
.join("\n");
|
|
58
|
+
}
|
|
59
|
+
if (typeof content === "string") {
|
|
60
|
+
return content;
|
|
61
|
+
}
|
|
62
|
+
debugLog("warn", "unexpected_content_type", {
|
|
63
|
+
contentType: typeof content,
|
|
64
|
+
content: String(String(content).slice(0, 200)),
|
|
65
|
+
});
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
|
|
24
69
|
// ── Constants ────────────────────────────────────────────────────────
|
|
25
70
|
|
|
26
71
|
/**
|
|
@@ -468,15 +513,7 @@ export async function startSubagentJob(
|
|
|
468
513
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
469
514
|
const msg = messages[i];
|
|
470
515
|
if (msg.role === "assistant") {
|
|
471
|
-
const textParts = msg.content
|
|
472
|
-
?.filter(
|
|
473
|
-
(c: {
|
|
474
|
-
type: string;
|
|
475
|
-
text?: string;
|
|
476
|
-
}): c is { type: "text"; text: string } => c.type === "text",
|
|
477
|
-
)
|
|
478
|
-
.map((c) => c.text)
|
|
479
|
-
.join("\n");
|
|
516
|
+
const textParts = extractTextFromContent(msg.content);
|
|
480
517
|
if (textParts) {
|
|
481
518
|
finalOutput = textParts;
|
|
482
519
|
break;
|
package/package.json
CHANGED
package/subagent.ts
CHANGED
|
@@ -902,8 +902,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
902
902
|
pi.registerTool({
|
|
903
903
|
name: "get_subagent_status",
|
|
904
904
|
label: "Get Subagent Status",
|
|
905
|
-
description:
|
|
906
|
-
"Poll an async subagent job by jobId. Returns live preview of the subagent's current turn, active tool, and output.",
|
|
905
|
+
description: "Poll an async subagent job by jobId. Returns live preview of the subagent's current turn, active tool, and output.",
|
|
907
906
|
parameters: StatusParams,
|
|
908
907
|
|
|
909
908
|
async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
|
|
@@ -917,7 +916,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
917
916
|
text: `Job ${params.jobId} not found. It may have been cancelled.`,
|
|
918
917
|
},
|
|
919
918
|
],
|
|
920
|
-
|
|
919
|
+
details: { jobId: params.jobId, status: "not_found" },
|
|
921
920
|
isError: true,
|
|
922
921
|
};
|
|
923
922
|
}
|