gnhf 0.1.13 → 0.1.15

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/dist/cli.mjs +27 -25
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -433,6 +433,17 @@ function getLastIterationNumber(runInfo) {
433
433
  }
434
434
  return max;
435
435
  }
436
+ function toStringArray(value) {
437
+ if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
438
+ if (typeof value === "string") {
439
+ try {
440
+ const parsed = JSON.parse(value);
441
+ if (Array.isArray(parsed)) return parsed.filter((v) => typeof v === "string");
442
+ } catch {}
443
+ return [value];
444
+ }
445
+ return [];
446
+ }
436
447
  function formatListSection(title, items) {
437
448
  if (items.length === 0) return "";
438
449
  return `**${title}:**\n${items.map((item) => `- ${item}`).join("\n")}\n`;
@@ -1516,7 +1527,7 @@ var OpenCodeAgent = class {
1516
1527
  let messageRequestError = null;
1517
1528
  const messageRequest = (async () => {
1518
1529
  try {
1519
- const body = await this.requestText(server, `/session/${sessionId}/message`, {
1530
+ await this.request(server, `/session/${sessionId}/prompt_async`, {
1520
1531
  method: "POST",
1521
1532
  body: {
1522
1533
  role: "user",
@@ -1530,12 +1541,11 @@ var OpenCodeAgent = class {
1530
1541
  });
1531
1542
  appendDebugLog("opencode:message-post:end", {
1532
1543
  sessionId,
1533
- elapsedMs: Date.now() - messagePostStartedAt,
1534
- bodyLength: body.length
1544
+ elapsedMs: Date.now() - messagePostStartedAt
1535
1545
  });
1536
1546
  return {
1537
1547
  ok: true,
1538
- body
1548
+ body: ""
1539
1549
  };
1540
1550
  } catch (error) {
1541
1551
  messageRequestError = error;
@@ -1565,6 +1575,7 @@ var OpenCodeAgent = class {
1565
1575
  let lastText = null;
1566
1576
  let lastFinalAnswerText = null;
1567
1577
  let lastUsageSignature = "0:0:0:0";
1578
+ let structuredOutputFromSSE = null;
1568
1579
  const eventCounts = {};
1569
1580
  let firstEventAtMs = null;
1570
1581
  let lastEventAtMs = null;
@@ -1689,6 +1700,7 @@ var OpenCodeAgent = class {
1689
1700
  }
1690
1701
  if (payload?.type === "message.updated") {
1691
1702
  if (properties.info?.role === "assistant") updateUsage(properties.info.id, properties.info.tokens);
1703
+ if (properties.info?.structured) structuredOutputFromSSE = properties.info.structured;
1692
1704
  return false;
1693
1705
  }
1694
1706
  return payload?.type === "session.idle";
@@ -1796,9 +1808,8 @@ var OpenCodeAgent = class {
1796
1808
  throw messageResult.error;
1797
1809
  }
1798
1810
  const body = messageResult.body;
1799
- let response;
1800
- try {
1801
- response = JSON.parse(body);
1811
+ if (body) try {
1812
+ JSON.parse(body);
1802
1813
  } catch (error) {
1803
1814
  appendDebugLog("opencode:response:parse-error", {
1804
1815
  sessionId,
@@ -1806,22 +1817,14 @@ var OpenCodeAgent = class {
1806
1817
  bodySample: body.slice(0, 512),
1807
1818
  error: serializeError(error)
1808
1819
  });
1809
- throw new Error(`Failed to parse opencode response: ${error instanceof Error ? error.message : String(error)}`);
1810
- }
1811
- if (response.info?.role === "assistant") updateUsage(response.info.id, response.info.tokens);
1812
- for (const part of response.parts ?? []) {
1813
- if (part.type !== "text" || typeof part.text !== "string") continue;
1814
- if (!part.text.trim()) continue;
1815
- lastText = part.text;
1816
- if (part.metadata?.openai?.phase === "final_answer") lastFinalAnswerText = part.text;
1817
1820
  }
1818
- if (response.info?.structured) {
1821
+ if (structuredOutputFromSSE) {
1819
1822
  appendDebugLog("opencode:output:structured", {
1820
1823
  sessionId,
1821
- source: "response.info.structured"
1824
+ source: "sse"
1822
1825
  });
1823
1826
  return {
1824
- output: response.info.structured,
1827
+ output: structuredOutputFromSSE,
1825
1828
  usage
1826
1829
  };
1827
1830
  }
@@ -1829,8 +1832,7 @@ var OpenCodeAgent = class {
1829
1832
  if (!outputText) {
1830
1833
  appendDebugLog("opencode:output:missing", {
1831
1834
  sessionId,
1832
- hasInfo: response.info !== void 0,
1833
- partCount: response.parts?.length ?? 0
1835
+ hasStructuredOutput: structuredOutputFromSSE !== null
1834
1836
  });
1835
1837
  throw new Error("opencode returned no text output");
1836
1838
  }
@@ -2893,7 +2895,7 @@ var Orchestrator = class extends EventEmitter {
2893
2895
  }
2894
2896
  }
2895
2897
  recordSuccess(output) {
2896
- appendNotes(this.runInfo.notesPath, this.state.currentIteration, output.summary, output.key_changes_made, output.key_learnings);
2898
+ appendNotes(this.runInfo.notesPath, this.state.currentIteration, output.summary, toStringArray(output.key_changes_made), toStringArray(output.key_learnings));
2897
2899
  commitAll(`gnhf #${this.state.currentIteration}: ${output.summary}`, this.cwd);
2898
2900
  this.state.commitCount = getBranchCommitCount(this.runInfo.baseCommit, this.cwd);
2899
2901
  this.state.successCount++;
@@ -2902,13 +2904,13 @@ var Orchestrator = class extends EventEmitter {
2902
2904
  number: this.state.currentIteration,
2903
2905
  success: true,
2904
2906
  summary: output.summary,
2905
- keyChanges: output.key_changes_made,
2906
- keyLearnings: output.key_learnings,
2907
+ keyChanges: toStringArray(output.key_changes_made),
2908
+ keyLearnings: toStringArray(output.key_learnings),
2907
2909
  timestamp: /* @__PURE__ */ new Date()
2908
2910
  };
2909
2911
  }
2910
2912
  recordFailure(notesSummary, recordSummary, learnings) {
2911
- appendNotes(this.runInfo.notesPath, this.state.currentIteration, notesSummary, [], learnings);
2913
+ appendNotes(this.runInfo.notesPath, this.state.currentIteration, notesSummary, [], toStringArray(learnings));
2912
2914
  resetHard(this.cwd);
2913
2915
  this.state.failCount++;
2914
2916
  this.state.consecutiveFailures++;
@@ -2917,7 +2919,7 @@ var Orchestrator = class extends EventEmitter {
2917
2919
  success: false,
2918
2920
  summary: recordSummary,
2919
2921
  keyChanges: [],
2920
- keyLearnings: learnings,
2922
+ keyLearnings: toStringArray(learnings),
2921
2923
  timestamp: /* @__PURE__ */ new Date()
2922
2924
  };
2923
2925
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gnhf",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "Before I go to bed, I tell my agents: good night, have fun",
5
5
  "type": "module",
6
6
  "bin": {