baro-ai 0.43.0 → 0.43.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/dist/cli.mjs CHANGED
@@ -10753,10 +10753,9 @@ function extractVerdictJson(text) {
10753
10753
  }
10754
10754
 
10755
10755
  // ../baro-orchestrator/src/codex-one-shot.ts
10756
- import { execFile as execFile3 } from "child_process";
10757
- import { promisify as promisify3 } from "util";
10758
- var execFileAsync2 = promisify3(execFile3);
10756
+ import { spawn } from "child_process";
10759
10757
  async function runCodexOneShot(opts) {
10758
+ const label = opts.label ?? "codex";
10760
10759
  const args = ["exec", "--json"];
10761
10760
  if (opts.skipGitRepoCheck) args.push("--skip-git-repo-check");
10762
10761
  if (opts.bypassSandbox !== false) {
@@ -10764,43 +10763,111 @@ async function runCodexOneShot(opts) {
10764
10763
  }
10765
10764
  if (opts.model) args.push("--model", opts.model);
10766
10765
  args.push(opts.prompt);
10767
- const { stdout } = await execFileAsync2(opts.codexBin ?? "codex", args, {
10768
- cwd: opts.cwd,
10769
- timeout: opts.timeoutMs ?? 18e4,
10770
- maxBuffer: opts.maxBuffer ?? 16 * 1024 * 1024
10771
- });
10772
- let result = "";
10773
- for (const rawLine of stdout.split("\n")) {
10774
- const line = rawLine.trim();
10775
- if (!line) continue;
10776
- let event;
10766
+ const timeoutMs = opts.timeoutMs ?? 6e5;
10767
+ return await new Promise((resolve4, reject) => {
10768
+ let proc;
10777
10769
  try {
10778
- event = JSON.parse(line);
10779
- } catch {
10780
- continue;
10770
+ proc = spawn(opts.codexBin ?? "codex", args, {
10771
+ cwd: opts.cwd,
10772
+ stdio: ["ignore", "pipe", "pipe"]
10773
+ });
10774
+ } catch (e) {
10775
+ reject(e instanceof Error ? e : new Error(String(e)));
10776
+ return;
10781
10777
  }
10782
- if (event.type === "turn.completed") {
10783
- const usage = event.usage;
10784
- if (usage) {
10785
- process.stderr.write(
10786
- `[codex] usage: in=${usage.input_tokens ?? 0} out=${usage.output_tokens ?? 0}
10787
- `
10788
- );
10778
+ let agentMessage = "";
10779
+ let stdoutBuffer = "";
10780
+ const eventTypesSeen = [];
10781
+ const itemTypesSeen = [];
10782
+ let timedOut = false;
10783
+ const startedAt = Date.now();
10784
+ const timer = setTimeout(() => {
10785
+ timedOut = true;
10786
+ try {
10787
+ proc.kill("SIGTERM");
10788
+ } catch {
10789
10789
  }
10790
- continue;
10791
- }
10792
- if (event.type !== "item.completed") continue;
10793
- const item = event.item;
10794
- if (!item) continue;
10795
- if (item.type === "agent_message" && typeof item.text === "string") {
10796
- result = result ? `${result}
10790
+ }, timeoutMs);
10791
+ proc.stdout.setEncoding("utf8");
10792
+ proc.stdout.on("data", (chunk) => {
10793
+ stdoutBuffer += chunk;
10794
+ let nl;
10795
+ while ((nl = stdoutBuffer.indexOf("\n")) >= 0) {
10796
+ const line = stdoutBuffer.slice(0, nl).trim();
10797
+ stdoutBuffer = stdoutBuffer.slice(nl + 1);
10798
+ if (!line) continue;
10799
+ let event;
10800
+ try {
10801
+ event = JSON.parse(line);
10802
+ } catch {
10803
+ continue;
10804
+ }
10805
+ const type = typeof event.type === "string" ? event.type : "";
10806
+ if (type) eventTypesSeen.push(type);
10807
+ if (type === "turn.completed") {
10808
+ const usage = event.usage;
10809
+ if (usage) {
10810
+ process.stderr.write(
10811
+ `[${label}] usage: in=${usage.input_tokens ?? 0} out=${usage.output_tokens ?? 0}
10812
+ `
10813
+ );
10814
+ }
10815
+ continue;
10816
+ }
10817
+ if (type === "item.completed") {
10818
+ const item = event.item;
10819
+ if (item) {
10820
+ const innerType = typeof item.type === "string" ? item.type : "?";
10821
+ itemTypesSeen.push(innerType);
10822
+ if (item.type === "agent_message" && typeof item.text === "string") {
10823
+ agentMessage = agentMessage ? `${agentMessage}
10797
10824
  ${item.text}` : item.text;
10798
- }
10799
- }
10800
- if (!result.trim()) {
10801
- throw new Error("runCodexOneShot: codex produced no agent_message");
10802
- }
10803
- return result;
10825
+ } else if (innerType === "command_execution") {
10826
+ const cmd = typeof item.command === "string" ? item.command.slice(0, 120) : "?";
10827
+ process.stderr.write(`[${label}] $ ${cmd}
10828
+ `);
10829
+ }
10830
+ }
10831
+ continue;
10832
+ }
10833
+ }
10834
+ });
10835
+ proc.stderr.setEncoding("utf8");
10836
+ proc.stderr.on("data", (chunk) => {
10837
+ const trimmed = chunk.trimEnd();
10838
+ if (trimmed) {
10839
+ process.stderr.write(`[${label}/stderr] ${trimmed}
10840
+ `);
10841
+ }
10842
+ });
10843
+ proc.on("error", (err) => {
10844
+ clearTimeout(timer);
10845
+ reject(err);
10846
+ });
10847
+ proc.on("exit", (code, signal) => {
10848
+ clearTimeout(timer);
10849
+ const elapsedMs = Date.now() - startedAt;
10850
+ if (agentMessage.trim()) {
10851
+ resolve4(agentMessage);
10852
+ return;
10853
+ }
10854
+ const ctx = [
10855
+ `elapsed=${elapsedMs}ms`,
10856
+ `exit=${code}`,
10857
+ signal ? `signal=${signal}` : null,
10858
+ timedOut ? `timedOut=true (cap=${timeoutMs}ms)` : null,
10859
+ `events=${eventTypesSeen.length}`,
10860
+ `items=${itemTypesSeen.length}`,
10861
+ eventTypesSeen.length > 0 ? `event_types=[${[...new Set(eventTypesSeen)].join(",")}]` : null,
10862
+ itemTypesSeen.length > 0 ? `item_types=[${[...new Set(itemTypesSeen)].join(",")}]` : null
10863
+ ].filter((x) => x !== null).join(" ");
10864
+ reject(
10865
+ new Error(
10866
+ `runCodexOneShot: codex produced no agent_message (${ctx})`
10867
+ )
10868
+ );
10869
+ });
10870
+ });
10804
10871
  }
10805
10872
 
10806
10873
  // ../baro-orchestrator/src/participants/critic-codex.ts
@@ -10815,7 +10882,7 @@ var CriticCodex = class extends BaseObserver {
10815
10882
  maxEmissionsPerAgent: opts.maxEmissionsPerAgent ?? 2,
10816
10883
  model: opts.model,
10817
10884
  codexBin: opts.codexBin ?? "codex",
10818
- timeoutMs: opts.timeoutMs ?? 6e4,
10885
+ timeoutMs: opts.timeoutMs ?? 18e4,
10819
10886
  targets: opts.targets
10820
10887
  };
10821
10888
  }
@@ -10880,17 +10947,13 @@ ${userPrompt}`;
10880
10947
  try {
10881
10948
  const text = await runCodexOneShot({
10882
10949
  prompt,
10883
- // Critic doesn't operate on the worktree — but Codex
10884
- // still insists on running inside a git repo unless we
10885
- // skip the check. Pass through skipGitRepoCheck so the
10886
- // critic can be invoked from anywhere (including baro's
10887
- // own cwd that may not be the story worktree).
10888
10950
  cwd: process.cwd(),
10889
10951
  skipGitRepoCheck: true,
10890
10952
  bypassSandbox: true,
10891
10953
  model: this.opts.model,
10892
10954
  codexBin: this.opts.codexBin,
10893
- timeoutMs: this.opts.timeoutMs
10955
+ timeoutMs: this.opts.timeoutMs,
10956
+ label: "codex-critic"
10894
10957
  });
10895
10958
  const verdictJson = extractVerdictJson(text.trim());
10896
10959
  const parsed = JSON.parse(verdictJson);
@@ -11084,9 +11147,9 @@ var CriticOpenAI = class extends BaseObserver {
11084
11147
  };
11085
11148
 
11086
11149
  // ../baro-orchestrator/src/participants/finalizer.ts
11087
- import { execFile as execFile4 } from "child_process";
11088
- import { promisify as promisify4 } from "util";
11089
- var execFileAsync3 = promisify4(execFile4);
11150
+ import { execFile as execFile3 } from "child_process";
11151
+ import { promisify as promisify3 } from "util";
11152
+ var execFileAsync2 = promisify3(execFile3);
11090
11153
  var Finalizer = class extends BaseObserver {
11091
11154
  opts;
11092
11155
  envRef = null;
@@ -11335,7 +11398,7 @@ var Finalizer = class extends BaseObserver {
11335
11398
  async collectCommitsSinceBase() {
11336
11399
  if (!this.baseSha) return [];
11337
11400
  try {
11338
- const { stdout } = await execFileAsync3(
11401
+ const { stdout } = await execFileAsync2(
11339
11402
  "git",
11340
11403
  ["log", `${this.baseSha}..HEAD`, "--pretty=format:%H%x09%s"],
11341
11404
  { cwd: this.opts.cwd }
@@ -11351,7 +11414,7 @@ var Finalizer = class extends BaseObserver {
11351
11414
  async collectFileStats() {
11352
11415
  if (!this.baseSha) return { created: 0, modified: 0 };
11353
11416
  try {
11354
- const { stdout } = await execFileAsync3(
11417
+ const { stdout } = await execFileAsync2(
11355
11418
  "git",
11356
11419
  ["diff", "--name-status", this.baseSha, "HEAD"],
11357
11420
  { cwd: this.opts.cwd }
@@ -11370,7 +11433,7 @@ var Finalizer = class extends BaseObserver {
11370
11433
  }
11371
11434
  async detectBranch() {
11372
11435
  try {
11373
- const { stdout } = await execFileAsync3(
11436
+ const { stdout } = await execFileAsync2(
11374
11437
  "git",
11375
11438
  ["branch", "--show-current"],
11376
11439
  { cwd: this.opts.cwd }
@@ -11382,7 +11445,7 @@ var Finalizer = class extends BaseObserver {
11382
11445
  }
11383
11446
  async detectDefaultBaseBranch() {
11384
11447
  try {
11385
- const { stdout } = await execFileAsync3(
11448
+ const { stdout } = await execFileAsync2(
11386
11449
  "gh",
11387
11450
  ["repo", "view", "--json", "defaultBranchRef", "--jq", ".defaultBranchRef.name"],
11388
11451
  { cwd: this.opts.cwd }
@@ -11392,7 +11455,7 @@ var Finalizer = class extends BaseObserver {
11392
11455
  } catch {
11393
11456
  }
11394
11457
  try {
11395
- const { stdout } = await execFileAsync3(
11458
+ const { stdout } = await execFileAsync2(
11396
11459
  "git",
11397
11460
  ["symbolic-ref", "--short", "refs/remotes/origin/HEAD"],
11398
11461
  { cwd: this.opts.cwd }
@@ -11480,7 +11543,7 @@ var Finalizer = class extends BaseObserver {
11480
11543
  }
11481
11544
  async hasGhBinary() {
11482
11545
  try {
11483
- await execFileAsync3("gh", ["--version"], { cwd: this.opts.cwd });
11546
+ await execFileAsync2("gh", ["--version"], { cwd: this.opts.cwd });
11484
11547
  return true;
11485
11548
  } catch {
11486
11549
  return false;
@@ -11488,7 +11551,7 @@ var Finalizer = class extends BaseObserver {
11488
11551
  }
11489
11552
  async openPr(args) {
11490
11553
  try {
11491
- const { stdout } = await execFileAsync3(
11554
+ const { stdout } = await execFileAsync2(
11492
11555
  "gh",
11493
11556
  [
11494
11557
  "pr",
@@ -11926,7 +11989,7 @@ function extractPath(item) {
11926
11989
  import { setTimeout as setTimeoutPromise } from "timers/promises";
11927
11990
 
11928
11991
  // ../baro-orchestrator/src/participants/codex-cli-participant.ts
11929
- import { spawn } from "child_process";
11992
+ import { spawn as spawn2 } from "child_process";
11930
11993
 
11931
11994
  // ../baro-orchestrator/src/codex-stream-mapper.ts
11932
11995
  function mapCodexEvent(agentId, event) {
@@ -12148,7 +12211,7 @@ var CodexCliParticipant = class _CodexCliParticipant extends BaseObserver {
12148
12211
  const args = this.buildArgs();
12149
12212
  let proc;
12150
12213
  try {
12151
- proc = spawn(this.options.codexBin, args, {
12214
+ proc = spawn2(this.options.codexBin, args, {
12152
12215
  cwd: this.options.cwd,
12153
12216
  stdio: ["ignore", "pipe", "pipe"]
12154
12217
  });
@@ -13293,7 +13356,7 @@ function sleep2(ms) {
13293
13356
  import { setTimeout as setTimeoutPromise2 } from "timers/promises";
13294
13357
 
13295
13358
  // ../baro-orchestrator/src/participants/claude-cli-participant.ts
13296
- import { spawn as spawn2 } from "child_process";
13359
+ import { spawn as spawn3 } from "child_process";
13297
13360
 
13298
13361
  // ../baro-orchestrator/src/stream-json-mapper.ts
13299
13362
  function mapClaudeEvent(agentId, event) {
@@ -13466,7 +13529,7 @@ var ClaudeCliParticipant = class _ClaudeCliParticipant extends BaseObserver {
13466
13529
  const args = this.buildArgs();
13467
13530
  let proc;
13468
13531
  try {
13469
- proc = spawn2(this.options.claudeBin, args, {
13532
+ proc = spawn3(this.options.claudeBin, args, {
13470
13533
  cwd: this.options.cwd,
13471
13534
  stdio: ["pipe", "pipe", "pipe"]
13472
13535
  });
@@ -14001,9 +14064,9 @@ var StoryFactory = class extends BaseObserver {
14001
14064
  };
14002
14065
 
14003
14066
  // ../baro-orchestrator/src/participants/surgeon.ts
14004
- import { execFile as execFile5 } from "child_process";
14005
- import { promisify as promisify5 } from "util";
14006
- var execFileAsync4 = promisify5(execFile5);
14067
+ import { execFile as execFile4 } from "child_process";
14068
+ import { promisify as promisify4 } from "util";
14069
+ var execFileAsync3 = promisify4(execFile4);
14007
14070
  var SURGEON_SYSTEM_PROMPT = `You are the Surgeon \u2014 an autonomous planner that adapts a software-project
14008
14071
  DAG when stories fail. Given:
14009
14072
  1. A snapshot of the current PRD (project, story list with dependencies +
@@ -14109,7 +14172,7 @@ var Surgeon = class extends BaseObserver {
14109
14172
  const snap = this.opts.snapshot();
14110
14173
  const prompt = buildSurgeonPrompt(snap, failure);
14111
14174
  try {
14112
- const { stdout } = await execFileAsync4(
14175
+ const { stdout } = await execFileAsync3(
14113
14176
  this.opts.claudeBin,
14114
14177
  [
14115
14178
  "--print",
@@ -14222,7 +14285,7 @@ var SurgeonCodex = class extends BaseObserver {
14222
14285
  model: opts.model,
14223
14286
  maxReplans: opts.maxReplans ?? 10,
14224
14287
  codexBin: opts.codexBin ?? "codex",
14225
- timeoutMs: opts.timeoutMs ?? 12e4,
14288
+ timeoutMs: opts.timeoutMs ?? 3e5,
14226
14289
  snapshot: opts.snapshot
14227
14290
  };
14228
14291
  }
@@ -14259,7 +14322,8 @@ ${userPrompt}`;
14259
14322
  bypassSandbox: true,
14260
14323
  model: this.opts.model,
14261
14324
  codexBin: this.opts.codexBin,
14262
- timeoutMs: this.opts.timeoutMs
14325
+ timeoutMs: this.opts.timeoutMs,
14326
+ label: "codex-surgeon"
14263
14327
  });
14264
14328
  const verdictText = text.trim();
14265
14329
  if (!verdictText) throw new Error("empty result");