opencode-lore 0.2.7 → 0.2.8

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/package.json +1 -1
  2. package/src/index.ts +16 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-lore",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Three-tier memory architecture for OpenCode — distillation, not summarization",
package/src/index.ts CHANGED
@@ -395,28 +395,31 @@ export const LorePlugin: Plugin = async (ctx) => {
395
395
  // so the append-only sequence stays intact for prompt caching.
396
396
  if (result.layer > 0) {
397
397
  // The API requires the conversation to end with a user message.
398
- // Drop trailing non-user messages, but stop if we hit an assistant message
399
- // with an in-progress (non-completed) tool call dropping it would cause
400
- // the model to lose its pending tool invocation and re-issue it in an
401
- // infinite loop. A completed tool part is safe to drop; a pending one is not.
398
+ // Drop trailing pure-text assistant messages (no tool parts), which would
399
+ // cause an Anthropic "does not support assistant message prefill" error.
400
+ //
401
+ // Crucially, assistant messages that contain tool parts (completed OR pending)
402
+ // must NOT be dropped:
403
+ // - Completed tool parts: OpenCode's SDK converts these into tool_result blocks
404
+ // sent as user-role messages at the API level. The conversation already ends
405
+ // with a user message — dropping would strip the entire current agentic turn
406
+ // and cause an infinite tool-call loop (the model restarts from scratch).
407
+ // - Pending tool parts: the tool call hasn't returned yet; dropping would make
408
+ // the model re-issue the same tool call on the next turn.
402
409
  while (
403
410
  result.messages.length > 0 &&
404
411
  result.messages.at(-1)!.info.role !== "user"
405
412
  ) {
406
413
  const last = result.messages.at(-1)!;
407
- const hasPendingTool = last.parts.some(
408
- (p) => p.type === "tool" && p.state.status !== "completed",
409
- );
410
- if (hasPendingTool) {
411
- console.error(
412
- "[lore] WARN: cannot drop trailing assistant message with pending tool call — may cause prefill error. id:",
413
- last.info.id,
414
- );
414
+ const hasToolParts = last.parts.some((p) => p.type === "tool");
415
+ if (hasToolParts) {
416
+ // Tool parts → tool_result (user-role) at the API level → no prefill error.
417
+ // Stop dropping; the conversation ends correctly as-is.
415
418
  break;
416
419
  }
417
420
  const dropped = result.messages.pop()!;
418
421
  console.error(
419
- "[lore] WARN: dropping trailing",
422
+ "[lore] WARN: dropping trailing pure-text",
420
423
  dropped.info.role,
421
424
  "message to prevent prefill error. id:",
422
425
  dropped.info.id,