@autonoma-ai/planner 0.1.12 → 0.1.13

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/dist/index.js CHANGED
@@ -1412,7 +1412,7 @@ var init_pages_finder = __esm({
1412
1412
  import * as p3 from "@clack/prompts";
1413
1413
  import { access } from "fs/promises";
1414
1414
  import { join as join12, isAbsolute } from "path";
1415
- import { spawn } from "child_process";
1415
+ import spawn from "cross-spawn";
1416
1416
  import which from "which";
1417
1417
  function resolvePath(artifact, outputDir) {
1418
1418
  if (isAbsolute(artifact)) return artifact;
@@ -1430,13 +1430,28 @@ async function detectEditors() {
1430
1430
  }
1431
1431
  async function launchEditor(editor, files) {
1432
1432
  const args = editor.args(files);
1433
- const proc = spawn(editor.command, args, { stdio: "inherit" });
1434
- if (["nano", "vim"].includes(editor.command)) {
1435
- await new Promise((resolve5, reject) => {
1436
- proc.on("close", () => resolve5());
1437
- proc.on("error", reject);
1433
+ const isTerminalEditor = TERMINAL_EDITORS.has(editor.command);
1434
+ await new Promise((resolve5) => {
1435
+ let settled = false;
1436
+ const settle = () => {
1437
+ if (settled) return;
1438
+ settled = true;
1439
+ resolve5();
1440
+ };
1441
+ const proc = spawn(editor.command, args, { stdio: "inherit" });
1442
+ proc.on("error", (err) => {
1443
+ p3.log.warn(
1444
+ `Couldn't open ${editor.label} (${err.message}). Review the files manually:`
1445
+ );
1446
+ for (const f of files) console.log(` ${CYAN2}${f}${RESET3}`);
1447
+ settle();
1438
1448
  });
1439
- }
1449
+ if (isTerminalEditor) {
1450
+ proc.on("close", () => settle());
1451
+ } else {
1452
+ proc.on("spawn", () => settle());
1453
+ }
1454
+ });
1440
1455
  }
1441
1456
  async function openInEditor(files) {
1442
1457
  const editors = await detectEditors();
@@ -1553,7 +1568,7 @@ async function reviewLoop(result, options) {
1553
1568
  await showResults(result, options);
1554
1569
  }
1555
1570
  }
1556
- var DIM3, CYAN2, GREEN2, RESET3, EDITORS, cachedEditors, preferredEditor;
1571
+ var DIM3, CYAN2, GREEN2, RESET3, EDITORS, cachedEditors, preferredEditor, TERMINAL_EDITORS;
1557
1572
  var init_review = __esm({
1558
1573
  "src/core/review.ts"() {
1559
1574
  "use strict";
@@ -1572,6 +1587,7 @@ var init_review = __esm({
1572
1587
  ];
1573
1588
  cachedEditors = null;
1574
1589
  preferredEditor = null;
1590
+ TERMINAL_EDITORS = /* @__PURE__ */ new Set(["nano", "vim"]);
1575
1591
  }
1576
1592
  });
1577
1593
 
@@ -3800,7 +3816,7 @@ import * as p5 from "@clack/prompts";
3800
3816
  import { writeFile as writeFile8, readFile as readFile16 } from "fs/promises";
3801
3817
  import { join as join23 } from "path";
3802
3818
  import { tmpdir } from "os";
3803
- import { spawn as spawn2 } from "child_process";
3819
+ import spawn2 from "cross-spawn";
3804
3820
  import { tool as tool14 } from "ai";
3805
3821
  import { z as z17 } from "zod";
3806
3822
  function summarizeCompletedAliases(completedEntities, excludeName) {
@@ -4011,11 +4027,17 @@ async function reviewRecipeData(entityName, entityIndex, totalEntities, proposed
4011
4027
  await writeFile8(tmpPath, JSON.stringify(proposed, null, 2), "utf-8");
4012
4028
  const editor = process.env.EDITOR ?? process.env.VISUAL ?? "vi";
4013
4029
  p5.log.info(`Opening ${editor}... Save and close when done.`);
4014
- await new Promise((resolve5, reject) => {
4030
+ const launched = await new Promise((resolve5) => {
4015
4031
  const proc = spawn2(editor, [tmpPath], { stdio: "inherit" });
4016
- proc.on("close", () => resolve5());
4017
- proc.on("error", reject);
4032
+ proc.on("close", () => resolve5(true));
4033
+ proc.on("error", (err) => {
4034
+ p5.log.error(
4035
+ `Couldn't open ${editor} (${err.message}). Edit this file manually, then choose "edit" again: ${tmpPath}`
4036
+ );
4037
+ resolve5(false);
4038
+ });
4018
4039
  });
4040
+ if (!launched) continue;
4019
4041
  const edited = await readFile16(tmpPath, "utf-8");
4020
4042
  try {
4021
4043
  proposed = JSON.parse(edited);