fix: add pi-package keyword for pi discovery
This commit is contained in:
parent
c800ed4e61
commit
e1516c44c6
|
|
@ -223,6 +223,34 @@ export class FanoutController {
|
||||||
proc.unref();
|
proc.unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readJobOutput(job: FanoutJob): string {
|
||||||
|
if (!fs.existsSync(job.outputFile)) return "";
|
||||||
|
try {
|
||||||
|
const lines = fs
|
||||||
|
.readFileSync(job.outputFile, "utf-8")
|
||||||
|
.split("\n")
|
||||||
|
.filter(Boolean);
|
||||||
|
const messages: Message[] = [];
|
||||||
|
for (const line of lines) {
|
||||||
|
try {
|
||||||
|
const event = JSON.parse(line);
|
||||||
|
if (event.type === "message_end" && event.message) messages.push(event.message as Message);
|
||||||
|
if (event.type === "tool_result_end" && event.message) messages.push(event.message as Message);
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
return getFinalOutput(messages);
|
||||||
|
} catch {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getJobPreview(job: FanoutJob, maxChars = 500): string {
|
||||||
|
const output = this.readJobOutput(job);
|
||||||
|
if (!output) return "";
|
||||||
|
if (output.length <= maxChars) return output;
|
||||||
|
return output.slice(0, maxChars) + "\n… (truncated)";
|
||||||
|
}
|
||||||
|
|
||||||
private processOutputLine(job: FanoutJob, line: string) {
|
private processOutputLine(job: FanoutJob, line: string) {
|
||||||
let event: any;
|
let event: any;
|
||||||
try { event = JSON.parse(line); } catch { return; }
|
try { event = JSON.parse(line); } catch { return; }
|
||||||
|
|
@ -283,11 +311,18 @@ export class FanoutController {
|
||||||
job.notified = true;
|
job.notified = true;
|
||||||
this.persist(job);
|
this.persist(job);
|
||||||
const outcome = job.status === "done" ? "completed" : `failed (exit ${job.exitCode ?? "?"})`;
|
const outcome = job.status === "done" ? "completed" : `failed (exit ${job.exitCode ?? "?"})`;
|
||||||
|
const preview = this.getJobPreview(job, 2000);
|
||||||
try {
|
try {
|
||||||
this.pi.sendUserMessage(
|
const parts = [
|
||||||
`Fanout job \`${job.id}\` (${job.agent}) ${outcome}. Use \`fanout_collect\` to retrieve results.`,
|
`Fanout job \`${job.id}\` (${job.agent}) ${outcome}.`,
|
||||||
{ deliverAs: "followUp" },
|
];
|
||||||
);
|
if (preview) {
|
||||||
|
parts.push(`\n\`\`\`\n${preview}\n\`\`\``);
|
||||||
|
}
|
||||||
|
if (preview && preview.length >= 2000) {
|
||||||
|
parts.push("\n*(output truncated — run `fanout_collect` for full result)*");
|
||||||
|
}
|
||||||
|
this.pi.sendUserMessage(parts.join(""), { deliverAs: "followUp" });
|
||||||
} catch {
|
} catch {
|
||||||
// If sendUserMessage fails (e.g. no active session), ignore.
|
// If sendUserMessage fails (e.g. no active session), ignore.
|
||||||
}
|
}
|
||||||
|
|
@ -309,6 +344,7 @@ export class FanoutController {
|
||||||
pid: job.pid,
|
pid: job.pid,
|
||||||
turns: job.usage.turns,
|
turns: job.usage.turns,
|
||||||
cost: job.usage.cost,
|
cost: job.usage.cost,
|
||||||
|
preview: this.getJobPreview(job, 300),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return { jobs };
|
return { jobs };
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@
|
||||||
"name": "pi-fanout",
|
"name": "pi-fanout",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Non-blocking async agent fanout for pi",
|
"description": "Non-blocking async agent fanout for pi",
|
||||||
|
"keywords": ["pi-package"],
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
|
"license": "MIT",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@earendil-works/pi-coding-agent": "*",
|
"@earendil-works/pi-coding-agent": "*",
|
||||||
"@earendil-works/pi-agent-core": "*",
|
"@earendil-works/pi-agent-core": "*",
|
||||||
|
|
|
||||||
Reference in New Issue