Merge pull request #1250 from richardanaya/master
fix(pi-local): fix not using skills, fix poor parsing of pi output, fix pi-local not showing up in pi-config section
This commit is contained in:
@@ -246,7 +246,7 @@ export type TranscriptEntry =
|
|||||||
| { kind: "thinking"; ts: string; text: string; delta?: boolean }
|
| { kind: "thinking"; ts: string; text: string; delta?: boolean }
|
||||||
| { kind: "user"; ts: string; text: string }
|
| { kind: "user"; ts: string; text: string }
|
||||||
| { kind: "tool_call"; ts: string; name: string; input: unknown; toolUseId?: string }
|
| { kind: "tool_call"; ts: string; name: string; input: unknown; toolUseId?: string }
|
||||||
| { kind: "tool_result"; ts: string; toolUseId: string; content: string; isError: boolean }
|
| { kind: "tool_result"; ts: string; toolUseId: string; toolName?: string; content: string; isError: boolean }
|
||||||
| { kind: "init"; ts: string; model: string; sessionId: string }
|
| { kind: "init"; ts: string; model: string; sessionId: string }
|
||||||
| { kind: "result"; ts: string; text: string; inputTokens: number; outputTokens: number; cachedTokens: number; costUsd: number; subtype: string; isError: boolean; errors: string[] }
|
| { kind: "result"; ts: string; text: string; inputTokens: number; outputTokens: number; cachedTokens: number; costUsd: number; subtype: string; isError: boolean; errors: string[] }
|
||||||
| { kind: "stderr"; ts: string; text: string }
|
| { kind: "stderr"; ts: string; text: string }
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { ensurePiModelConfiguredAndAvailable } from "./models.js";
|
|||||||
const __moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
const __moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
const PAPERCLIP_SESSIONS_DIR = path.join(os.homedir(), ".pi", "paperclips");
|
const PAPERCLIP_SESSIONS_DIR = path.join(os.homedir(), ".pi", "paperclips");
|
||||||
|
const PI_AGENT_SKILLS_DIR = path.join(os.homedir(), ".pi", "agent", "skills");
|
||||||
|
|
||||||
function firstNonEmptyLine(text: string): string {
|
function firstNonEmptyLine(text: string): string {
|
||||||
return (
|
return (
|
||||||
@@ -56,35 +57,35 @@ function resolvePiBiller(env: Record<string, string>, provider: string | null):
|
|||||||
|
|
||||||
async function ensurePiSkillsInjected(onLog: AdapterExecutionContext["onLog"]) {
|
async function ensurePiSkillsInjected(onLog: AdapterExecutionContext["onLog"]) {
|
||||||
const skillsEntries = await listPaperclipSkillEntries(__moduleDir);
|
const skillsEntries = await listPaperclipSkillEntries(__moduleDir);
|
||||||
|
|
||||||
|
await fs.mkdir(PI_AGENT_SKILLS_DIR, { recursive: true });
|
||||||
if (skillsEntries.length === 0) return;
|
if (skillsEntries.length === 0) return;
|
||||||
|
|
||||||
const piSkillsHome = path.join(os.homedir(), ".pi", "agent", "skills");
|
|
||||||
await fs.mkdir(piSkillsHome, { recursive: true });
|
|
||||||
const removedSkills = await removeMaintainerOnlySkillSymlinks(
|
const removedSkills = await removeMaintainerOnlySkillSymlinks(
|
||||||
piSkillsHome,
|
PI_AGENT_SKILLS_DIR,
|
||||||
skillsEntries.map((entry) => entry.name),
|
skillsEntries.map((entry) => entry.name),
|
||||||
);
|
);
|
||||||
for (const skillName of removedSkills) {
|
for (const skillName of removedSkills) {
|
||||||
await onLog(
|
await onLog(
|
||||||
"stderr",
|
"stderr",
|
||||||
`[paperclip] Removed maintainer-only Pi skill "${skillName}" from ${piSkillsHome}\n`,
|
`[paperclip] Removed maintainer-only Pi skill "${skillName}" from ${PI_AGENT_SKILLS_DIR}\n`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const entry of skillsEntries) {
|
for (const entry of skillsEntries) {
|
||||||
const target = path.join(piSkillsHome, entry.name);
|
const target = path.join(PI_AGENT_SKILLS_DIR, entry.name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await ensurePaperclipSkillSymlink(entry.source, target);
|
const result = await ensurePaperclipSkillSymlink(entry.source, target);
|
||||||
if (result === "skipped") continue;
|
if (result === "skipped") continue;
|
||||||
await onLog(
|
await onLog(
|
||||||
"stderr",
|
"stderr",
|
||||||
`[paperclip] ${result === "repaired" ? "Repaired" : "Injected"} Pi skill "${entry.name}" into ${piSkillsHome}\n`,
|
`[paperclip] ${result === "repaired" ? "Repaired" : "Injected"} Pi skill "${entry.name}" into ${PI_AGENT_SKILLS_DIR}\n`,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await onLog(
|
await onLog(
|
||||||
"stderr",
|
"stderr",
|
||||||
`[paperclip] Failed to inject Pi skill "${entry.name}" into ${piSkillsHome}: ${err instanceof Error ? err.message : String(err)}\n`,
|
`[paperclip] Failed to inject Pi skill "${entry.name}" into ${PI_AGENT_SKILLS_DIR}: ${err instanceof Error ? err.message : String(err)}\n`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -336,6 +337,9 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
|
|||||||
args.push("--tools", "read,bash,edit,write,grep,find,ls");
|
args.push("--tools", "read,bash,edit,write,grep,find,ls");
|
||||||
args.push("--session", sessionFile);
|
args.push("--session", sessionFile);
|
||||||
|
|
||||||
|
// Add Paperclip skills directory so Pi can load the paperclip skill
|
||||||
|
args.push("--skill", PI_AGENT_SKILLS_DIR);
|
||||||
|
|
||||||
if (extraArgs.length > 0) args.push(...extraArgs);
|
if (extraArgs.length > 0) args.push(...extraArgs);
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
|
|||||||
@@ -72,11 +72,22 @@ export function parsePiStdoutLine(line: string, ts: string): TranscriptEntry[] {
|
|||||||
for (const tr of toolResults) {
|
for (const tr of toolResults) {
|
||||||
const content = tr.content;
|
const content = tr.content;
|
||||||
const isError = tr.isError === true;
|
const isError = tr.isError === true;
|
||||||
const contentStr = typeof content === "string" ? content : JSON.stringify(content);
|
|
||||||
|
// Extract text from Pi's content array format
|
||||||
|
let contentStr: string;
|
||||||
|
if (typeof content === "string") {
|
||||||
|
contentStr = content;
|
||||||
|
} else if (Array.isArray(content)) {
|
||||||
|
contentStr = extractTextContent(content as Array<{ type: string; text?: string }>);
|
||||||
|
} else {
|
||||||
|
contentStr = JSON.stringify(content);
|
||||||
|
}
|
||||||
|
|
||||||
entries.push({
|
entries.push({
|
||||||
kind: "tool_result",
|
kind: "tool_result",
|
||||||
ts,
|
ts,
|
||||||
toolUseId: asString(tr.toolCallId, "unknown"),
|
toolUseId: asString(tr.toolCallId, "unknown"),
|
||||||
|
toolName: asString(tr.toolName),
|
||||||
content: contentStr,
|
content: contentStr,
|
||||||
isError,
|
isError,
|
||||||
});
|
});
|
||||||
@@ -130,14 +141,35 @@ export function parsePiStdoutLine(line: string, ts: string): TranscriptEntry[] {
|
|||||||
|
|
||||||
if (type === "tool_execution_end") {
|
if (type === "tool_execution_end") {
|
||||||
const toolCallId = asString(parsed.toolCallId);
|
const toolCallId = asString(parsed.toolCallId);
|
||||||
|
const toolName = asString(parsed.toolName);
|
||||||
const result = parsed.result;
|
const result = parsed.result;
|
||||||
const isError = parsed.isError === true;
|
const isError = parsed.isError === true;
|
||||||
const contentStr = typeof result === "string" ? result : JSON.stringify(result);
|
|
||||||
|
// Extract text from Pi's content array format
|
||||||
|
// Can be: {"content": [{"type": "text", "text": "..."}]} or [{"type": "text", "text": "..."}]
|
||||||
|
let contentStr: string;
|
||||||
|
if (typeof result === "string") {
|
||||||
|
contentStr = result;
|
||||||
|
} else if (Array.isArray(result)) {
|
||||||
|
// Direct array format: result is [{"type": "text", "text": "..."}]
|
||||||
|
contentStr = extractTextContent(result as Array<{ type: string; text?: string }>);
|
||||||
|
} else if (result && typeof result === "object") {
|
||||||
|
const resultObj = result as Record<string, unknown>;
|
||||||
|
if (Array.isArray(resultObj.content)) {
|
||||||
|
// Wrapped format: result is {"content": [{"type": "text", "text": "..."}]}
|
||||||
|
contentStr = extractTextContent(resultObj.content as Array<{ type: string; text?: string }>);
|
||||||
|
} else {
|
||||||
|
contentStr = JSON.stringify(result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
contentStr = JSON.stringify(result);
|
||||||
|
}
|
||||||
|
|
||||||
return [{
|
return [{
|
||||||
kind: "tool_result",
|
kind: "tool_result",
|
||||||
ts,
|
ts,
|
||||||
toolUseId: toolCallId || "unknown",
|
toolUseId: toolCallId || "unknown",
|
||||||
|
toolName,
|
||||||
content: contentStr,
|
content: contentStr,
|
||||||
isError,
|
isError,
|
||||||
}];
|
}];
|
||||||
|
|||||||
@@ -939,7 +939,7 @@ function AdapterEnvironmentResult({ result }: { result: AdapterEnvironmentTestRe
|
|||||||
|
|
||||||
/* ---- Internal sub-components ---- */
|
/* ---- Internal sub-components ---- */
|
||||||
|
|
||||||
const ENABLED_ADAPTER_TYPES = new Set(["claude_local", "codex_local", "gemini_local", "opencode_local", "cursor"]);
|
const ENABLED_ADAPTER_TYPES = new Set(["claude_local", "codex_local", "gemini_local", "opencode_local", "pi_local", "cursor"]);
|
||||||
|
|
||||||
/** Display list includes all real adapter types plus UI-only coming-soon entries. */
|
/** Display list includes all real adapter types plus UI-only coming-soon entries. */
|
||||||
const ADAPTER_DISPLAY_LIST: { value: string; label: string; comingSoon: boolean }[] = [
|
const ADAPTER_DISPLAY_LIST: { value: string; label: string; comingSoon: boolean }[] = [
|
||||||
|
|||||||
@@ -400,7 +400,7 @@ export function normalizeTranscript(entries: TranscriptEntry[], streaming: boole
|
|||||||
type: "tool",
|
type: "tool",
|
||||||
ts: entry.ts,
|
ts: entry.ts,
|
||||||
endTs: entry.ts,
|
endTs: entry.ts,
|
||||||
name: "tool",
|
name: entry.toolName ?? "tool",
|
||||||
toolUseId: entry.toolUseId,
|
toolUseId: entry.toolUseId,
|
||||||
input: null,
|
input: null,
|
||||||
result: entry.content,
|
result: entry.content,
|
||||||
|
|||||||
Reference in New Issue
Block a user