parley-chat 0.2.0 → 0.2.1
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/main.mjs +35 -1
- package/package.json +1 -1
package/main.mjs
CHANGED
|
@@ -76,7 +76,7 @@ async function fileExists(path) {
|
|
|
76
76
|
var init_files = () => {};
|
|
77
77
|
|
|
78
78
|
// src/main.ts
|
|
79
|
-
import { execFile } from "child_process";
|
|
79
|
+
import { execFile, spawn as spawn2 } from "child_process";
|
|
80
80
|
import { mkdir as mkdir3, readFile as readFile3, rm as rm3, stat as stat3, writeFile as writeFile3 } from "fs/promises";
|
|
81
81
|
import { homedir as homedir3 } from "os";
|
|
82
82
|
import { join as join3 } from "path";
|
|
@@ -538,6 +538,40 @@ async function doctor() {
|
|
|
538
538
|
}, 5000);
|
|
539
539
|
});
|
|
540
540
|
checks.push(["handler command found", handler ? "yes" : "no \u2014 the command in config.toml is not on PATH", handler]);
|
|
541
|
+
if (handler) {
|
|
542
|
+
process.stdout.write(`running a test draft through your handler (this is what answers your friends; may take a minute)\u2026
|
|
543
|
+
`);
|
|
544
|
+
const probe = await new Promise((resolve) => {
|
|
545
|
+
const child = spawn2("sh", ["-c", local.command], { stdio: ["pipe", "pipe", "pipe"] });
|
|
546
|
+
const out = [];
|
|
547
|
+
const err = [];
|
|
548
|
+
child.stdout.on("data", (chunk) => out.push(chunk));
|
|
549
|
+
child.stderr.on("data", (chunk) => err.push(chunk));
|
|
550
|
+
const timer = setTimeout(() => {
|
|
551
|
+
child.kill();
|
|
552
|
+
resolve({ ok: false, detail: "timed out after 120s \u2014 the handler hung instead of answering" });
|
|
553
|
+
}, 120000);
|
|
554
|
+
child.on("close", (code) => {
|
|
555
|
+
clearTimeout(timer);
|
|
556
|
+
const text2 = Buffer.concat(out).toString("utf8").trim();
|
|
557
|
+
const errText = Buffer.concat(err).toString("utf8").trim().split(`
|
|
558
|
+
`).at(-1) ?? "";
|
|
559
|
+
if (code !== 0)
|
|
560
|
+
resolve({ ok: false, detail: `exited ${code}${errText ? ` \u2014 ${errText}` : ""}` });
|
|
561
|
+
else if (text2.length === 0)
|
|
562
|
+
resolve({ ok: false, detail: "produced no output \u2014 a real ask would auto-deny" });
|
|
563
|
+
else
|
|
564
|
+
resolve({ ok: true, detail: `replied: ${text2.slice(0, 60)}${text2.length > 60 ? "\u2026" : ""}` });
|
|
565
|
+
});
|
|
566
|
+
child.stdin.write(`${local.context}
|
|
567
|
+
|
|
568
|
+
Asker: parley doctor
|
|
569
|
+
Question: reply with the single word "pong" and nothing else
|
|
570
|
+
`);
|
|
571
|
+
child.stdin.end();
|
|
572
|
+
});
|
|
573
|
+
checks.push(["handler test draft", probe.detail, probe.ok]);
|
|
574
|
+
}
|
|
541
575
|
}
|
|
542
576
|
}
|
|
543
577
|
checks.push(["launchagent", await launchAgentState(), await launchAgentState() === "loaded"]);
|