parley-chat 0.2.2 → 0.2.3

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.
Files changed (2) hide show
  1. package/main.mjs +32 -7
  2. package/package.json +2 -2
package/main.mjs CHANGED
@@ -83,7 +83,7 @@ import { join as join3 } from "path";
83
83
  import { promisify } from "util";
84
84
 
85
85
  // ../shared/src/protocol.ts
86
- var cliVersion = "0.2.2";
86
+ var cliVersion = "0.2.3";
87
87
  var skillDocument = `---
88
88
  name: parley
89
89
  description: Ask a mutual contact's local agent a question through Parley, with both inbound execution and outbound replies approved in Discord.
@@ -200,7 +200,7 @@ async function fileExists2(path) {
200
200
  import { spawn } from "node:child_process";
201
201
 
202
202
  // ../shared/src/protocol.ts
203
- var cliVersion2 = "0.2.2";
203
+ var cliVersion2 = "0.2.3";
204
204
 
205
205
  // src/http.ts
206
206
  init_files();
@@ -221,13 +221,23 @@ async function draft(requestId, asker, question) {
221
221
  Asker: ${asker}
222
222
  Question: ${question}
223
223
  `;
224
- const child = spawn("sh", ["-c", local.command], { stdio: ["pipe", "pipe", "ignore"] });
224
+ const child = spawn("sh", ["-c", local.command], { stdio: ["pipe", "pipe", "pipe"] });
225
225
  child.stdin.write(prompt);
226
226
  child.stdin.end();
227
227
  const chunks = [];
228
+ const errChunks = [];
228
229
  child.stdout.on("data", (chunk) => chunks.push(chunk));
230
+ child.stderr.on("data", (chunk) => errChunks.push(chunk));
229
231
  const code = await new Promise((resolve) => child.on("close", (value) => resolve(value ?? 1)));
230
232
  const output = Buffer.concat(chunks).toString("utf8").trim();
233
+ if (code !== 0 || output.length === 0) {
234
+ const errText = Buffer.concat(errChunks).toString("utf8").trim().split(`
235
+ `).slice(-5).join(`
236
+ `);
237
+ process.stderr.write(`draft failed (exit ${code})${errText ? `:
238
+ ${errText}` : " with no stderr"}
239
+ `);
240
+ }
231
241
  await api2(`/v1/asks/${requestId}/draft`, { method: "POST", body: JSON.stringify({ draft: code === 0 ? output : "" }) });
232
242
  }
233
243
  async function listen() {
@@ -435,13 +445,23 @@ function plist(entry) {
435
445
  async function install() {
436
446
  if (process.platform !== "darwin") {
437
447
  process.stderr.write(`not supported yet
448
+ `);
449
+ return 1;
450
+ }
451
+ const uid = process.getuid?.() ?? 501;
452
+ if (uid === 0) {
453
+ process.stderr.write(`do not run parley install with sudo \u2014 launchd user agents belong to your own account. Re-run as yourself:
454
+ parley install
438
455
  `);
439
456
  return 1;
440
457
  }
441
458
  const path = join3(homedir3(), "Library/LaunchAgents/sh.parley.listen.plist");
459
+ await execute("launchctl", ["bootout", `gui/${uid}`, path]).catch(() => {
460
+ return;
461
+ });
442
462
  await mkdir3(join3(parleyHome2(), "logs"), { recursive: true, mode: 448 });
443
463
  await writeFile3(path, plist(process.argv[1] ?? "parley"), { mode: 384 });
444
- await execute("launchctl", ["bootstrap", `gui/${process.getuid?.() ?? 501}`, path]);
464
+ await execute("launchctl", ["bootstrap", `gui/${uid}`, path]);
445
465
  process.stdout.write(`installed
446
466
  `);
447
467
  return 0;
@@ -584,12 +604,17 @@ Question: reply with the single word "pong" and nothing else
584
604
  }
585
605
  }
586
606
  }
587
- checks.push(["launchagent", await launchAgentState(), await launchAgentState() === "loaded"]);
607
+ const agentState = await launchAgentState();
608
+ checks.push(["launchagent", agentState, agentState === "loaded"]);
588
609
  const online = hasCredentials ? object(await apiJson("/v1/status").catch(() => null))?.online === true : false;
589
610
  checks.push(["responder online", online ? "yes" : "no \u2014 run: parley install (or parley listen)", online]);
590
611
  const logPath = join3(parleyHome2(), "logs/listen.log");
591
- const recentLog = await readFile3(logPath, "utf8").then((value) => value.split(`
592
- `).filter((line) => line.length > 0).slice(-3)).catch(() => []);
612
+ const logLines = await readFile3(logPath, "utf8").then((value) => value.split(`
613
+ `).filter((line) => line.length > 0)).catch(() => []);
614
+ const crashing = agentState === "loaded" && !online && logLines.slice(-20).some((line) => /error|throw|at .*\(node:/i.test(line));
615
+ if (crashing)
616
+ checks.push(["responder process", "crashing on startup \u2014 run `parley listen` to see the error directly, or `parley install` to regenerate the launch agent", false]);
617
+ const recentLog = logLines.slice(crashing ? -20 : -3);
593
618
  let failures = 0;
594
619
  for (const [name, detail, ok] of checks) {
595
620
  if (!ok)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "parley-chat",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Ask your friends' local agents questions, with every reply approved by its human in Discord.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,6 +16,6 @@
16
16
  "license": "MIT",
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "https://github.com/rhyssullivan/parley"
19
+ "url": "https://github.com/UsefulSoftwareCo/parley"
20
20
  }
21
21
  }