@poncho-ai/harness 0.31.2 → 0.31.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @poncho-ai/harness@0.31.2 build /home/runner/work/poncho-ai/poncho-ai/packages/harness
2
+ > @poncho-ai/harness@0.31.3 build /home/runner/work/poncho-ai/poncho-ai/packages/harness
3
3
  > node scripts/embed-docs.js && tsup src/index.ts --format esm --dts
4
4
 
5
5
  [embed-docs] Generated poncho-docs.ts with 4 topics
@@ -8,8 +8,8 @@
8
8
  CLI tsup v8.5.1
9
9
  CLI Target: es2022
10
10
  ESM Build start
11
- ESM dist/index.js 327.57 KB
12
- ESM ⚡️ Build success in 170ms
11
+ ESM dist/index.js 327.98 KB
12
+ ESM ⚡️ Build success in 137ms
13
13
  DTS Build start
14
- DTS ⚡️ Build success in 7684ms
14
+ DTS ⚡️ Build success in 7094ms
15
15
  DTS dist/index.d.ts 33.43 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @poncho-ai/harness
2
2
 
3
+ ## 0.31.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#56](https://github.com/cesr/poncho-ai/pull/56) [`28b2913`](https://github.com/cesr/poncho-ai/commit/28b291379e640dec53a66c41a2795d0a9fbb9ee7) Thanks [@cesr](https://github.com/cesr)! - Fix historical tool result truncation reliability for deployed conversations.
8
+
9
+ This stamps `runId` on all harness-authored assistant messages and adds a fallback truncation boundary for legacy histories that lack `runId` metadata.
10
+
3
11
  ## 0.31.2
4
12
 
5
13
  ### Patch Changes
package/dist/index.js CHANGED
@@ -5808,8 +5808,12 @@ var AgentHarness = class _AgentHarness {
5808
5808
  }
5809
5809
  truncateHistoricalToolResults(messages, conversationId) {
5810
5810
  let latestRunId;
5811
+ let latestToolMessageIndex = -1;
5811
5812
  for (let i = messages.length - 1; i >= 0; i -= 1) {
5812
5813
  const msg = messages[i];
5814
+ if (latestToolMessageIndex === -1 && msg.role === "tool" && typeof msg.content === "string") {
5815
+ latestToolMessageIndex = i;
5816
+ }
5813
5817
  const meta = msg.metadata;
5814
5818
  const runId = typeof meta?.runId === "string" ? meta.runId : void 0;
5815
5819
  if (runId) {
@@ -5817,7 +5821,7 @@ var AgentHarness = class _AgentHarness {
5817
5821
  break;
5818
5822
  }
5819
5823
  }
5820
- if (!latestRunId) {
5824
+ if (!latestRunId && latestToolMessageIndex === -1) {
5821
5825
  return { changed: false, truncatedCount: 0, archivedCount: 0, omittedChars: 0 };
5822
5826
  }
5823
5827
  const archive = this.archivedToolResultsByConversation.get(conversationId) ?? {};
@@ -5826,11 +5830,16 @@ var AgentHarness = class _AgentHarness {
5826
5830
  let truncatedCount = 0;
5827
5831
  let archivedCount = 0;
5828
5832
  let omittedChars = 0;
5829
- for (const msg of messages) {
5833
+ for (let index = 0; index < messages.length; index += 1) {
5834
+ const msg = messages[index];
5830
5835
  if (msg.role !== "tool" || typeof msg.content !== "string") continue;
5831
5836
  const meta = msg.metadata;
5832
5837
  const runId = typeof meta?.runId === "string" ? meta.runId : void 0;
5833
- if (runId === latestRunId) continue;
5838
+ if (latestRunId) {
5839
+ if (runId === latestRunId) continue;
5840
+ } else if (index === latestToolMessageIndex) {
5841
+ continue;
5842
+ }
5834
5843
  let parsed;
5835
5844
  try {
5836
5845
  parsed = JSON.parse(msg.content);
@@ -7165,7 +7174,7 @@ ${textContent}` };
7165
7174
  messages.push({
7166
7175
  role: "assistant",
7167
7176
  content: fullText,
7168
- metadata: { timestamp: now(), id: randomUUID3(), step }
7177
+ metadata: { timestamp: now(), id: randomUUID3(), step, runId }
7169
7178
  });
7170
7179
  }
7171
7180
  const result_ = {
@@ -7198,7 +7207,7 @@ ${textContent}` };
7198
7207
  messages.push({
7199
7208
  role: "assistant",
7200
7209
  content: fullText,
7201
- metadata: { timestamp: now(), id: randomUUID3(), step }
7210
+ metadata: { timestamp: now(), id: randomUUID3(), step, runId }
7202
7211
  });
7203
7212
  }
7204
7213
  const result_ = {
@@ -7302,7 +7311,7 @@ ${textContent}` };
7302
7311
  messages.push({
7303
7312
  role: "assistant",
7304
7313
  content: fullText,
7305
- metadata: { timestamp: now(), id: randomUUID3(), step }
7314
+ metadata: { timestamp: now(), id: randomUUID3(), step, runId }
7306
7315
  });
7307
7316
  }
7308
7317
  responseText = fullText;
@@ -7384,7 +7393,7 @@ ${textContent}` };
7384
7393
  const assistantMsg = {
7385
7394
  role: "assistant",
7386
7395
  content: assistantContent2,
7387
- metadata: { timestamp: now(), id: randomUUID3(), step }
7396
+ metadata: { timestamp: now(), id: randomUUID3(), step, runId }
7388
7397
  };
7389
7398
  const deltaMessages = [...messages.slice(inputMessageCount), assistantMsg];
7390
7399
  yield pushEvent({
@@ -7469,7 +7478,7 @@ ${textContent}` };
7469
7478
  messages.push({
7470
7479
  role: "assistant",
7471
7480
  content: fullText,
7472
- metadata: { timestamp: now(), id: randomUUID3(), step }
7481
+ metadata: { timestamp: now(), id: randomUUID3(), step, runId }
7473
7482
  });
7474
7483
  }
7475
7484
  const result_ = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poncho-ai/harness",
3
- "version": "0.31.2",
3
+ "version": "0.31.3",
4
4
  "description": "Agent execution runtime - conversation loop, tool dispatch, streaming",
5
5
  "repository": {
6
6
  "type": "git",
package/src/harness.ts CHANGED
@@ -846,8 +846,12 @@ export class AgentHarness {
846
846
  conversationId: string,
847
847
  ): { changed: boolean; truncatedCount: number; archivedCount: number; omittedChars: number } {
848
848
  let latestRunId: string | undefined;
849
+ let latestToolMessageIndex = -1;
849
850
  for (let i = messages.length - 1; i >= 0; i -= 1) {
850
851
  const msg = messages[i]!;
852
+ if (latestToolMessageIndex === -1 && msg.role === "tool" && typeof msg.content === "string") {
853
+ latestToolMessageIndex = i;
854
+ }
851
855
  const meta = msg.metadata as Record<string, unknown> | undefined;
852
856
  const runId = typeof meta?.runId === "string" ? meta.runId : undefined;
853
857
  if (runId) {
@@ -855,7 +859,7 @@ export class AgentHarness {
855
859
  break;
856
860
  }
857
861
  }
858
- if (!latestRunId) {
862
+ if (!latestRunId && latestToolMessageIndex === -1) {
859
863
  return { changed: false, truncatedCount: 0, archivedCount: 0, omittedChars: 0 };
860
864
  }
861
865
  const archive = this.archivedToolResultsByConversation.get(conversationId) ?? {};
@@ -865,11 +869,17 @@ export class AgentHarness {
865
869
  let archivedCount = 0;
866
870
  let omittedChars = 0;
867
871
 
868
- for (const msg of messages) {
872
+ for (let index = 0; index < messages.length; index += 1) {
873
+ const msg = messages[index]!;
869
874
  if (msg.role !== "tool" || typeof msg.content !== "string") continue;
870
875
  const meta = msg.metadata as Record<string, unknown> | undefined;
871
876
  const runId = typeof meta?.runId === "string" ? meta.runId : undefined;
872
- if (runId === latestRunId) continue;
877
+ if (latestRunId) {
878
+ if (runId === latestRunId) continue;
879
+ } else if (index === latestToolMessageIndex) {
880
+ // Legacy fallback for pre-runId conversations: keep newest tool turn intact.
881
+ continue;
882
+ }
873
883
  let parsed: unknown;
874
884
  try {
875
885
  parsed = JSON.parse(msg.content);
@@ -2446,7 +2456,7 @@ ${boundedMainMemory.trim()}`
2446
2456
  messages.push({
2447
2457
  role: "assistant",
2448
2458
  content: fullText,
2449
- metadata: { timestamp: now(), id: randomUUID(), step },
2459
+ metadata: { timestamp: now(), id: randomUUID(), step, runId },
2450
2460
  });
2451
2461
  }
2452
2462
  const result_: RunResult = {
@@ -2483,7 +2493,7 @@ ${boundedMainMemory.trim()}`
2483
2493
  messages.push({
2484
2494
  role: "assistant",
2485
2495
  content: fullText,
2486
- metadata: { timestamp: now(), id: randomUUID(), step },
2496
+ metadata: { timestamp: now(), id: randomUUID(), step, runId },
2487
2497
  });
2488
2498
  }
2489
2499
  const result_: RunResult = {
@@ -2612,7 +2622,7 @@ ${boundedMainMemory.trim()}`
2612
2622
  messages.push({
2613
2623
  role: "assistant",
2614
2624
  content: fullText,
2615
- metadata: { timestamp: now(), id: randomUUID(), step },
2625
+ metadata: { timestamp: now(), id: randomUUID(), step, runId },
2616
2626
  });
2617
2627
  }
2618
2628
  responseText = fullText;
@@ -2726,7 +2736,7 @@ ${boundedMainMemory.trim()}`
2726
2736
  const assistantMsg: Message = {
2727
2737
  role: "assistant",
2728
2738
  content: assistantContent,
2729
- metadata: { timestamp: now(), id: randomUUID(), step },
2739
+ metadata: { timestamp: now(), id: randomUUID(), step, runId },
2730
2740
  };
2731
2741
  const deltaMessages = [...messages.slice(inputMessageCount), assistantMsg];
2732
2742
  yield pushEvent({
@@ -2826,7 +2836,7 @@ ${boundedMainMemory.trim()}`
2826
2836
  messages.push({
2827
2837
  role: "assistant",
2828
2838
  content: fullText,
2829
- metadata: { timestamp: now(), id: randomUUID(), step },
2839
+ metadata: { timestamp: now(), id: randomUUID(), step, runId },
2830
2840
  });
2831
2841
  }
2832
2842
  const result_: RunResult = {