@eleboucher/opencode-memini 0.3.8 → 0.3.9

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/memini.js +7 -4
  2. package/package.json +1 -1
package/memini.js CHANGED
@@ -162,22 +162,25 @@ function createClient(cfg, log) {
162
162
 
163
163
  // extractLastTurn returns the latest user and assistant text from the message
164
164
  // list returned by client.session.messages ([{info, parts}, ...]), plus the id
165
- // of the assistant message (for dedup). Exported for testing.
165
+ // of the assistant message (for dedup). Iterates in reverse to short-circuit.
166
+ // Exported for testing.
166
167
  export function extractLastTurn(messages) {
167
168
  let userText = "";
168
169
  let assistantText = "";
169
170
  let assistantID = "";
170
171
  if (!Array.isArray(messages)) return { userText, assistantText, assistantID };
171
- for (const entry of messages) {
172
+ for (const entry of [...messages].reverse()) {
172
173
  const info = entry && entry.info;
173
174
  if (!info) continue;
174
175
  const text = extractPartsText(entry.parts);
175
176
  if (!text) continue;
176
- if (info.role === "user") userText = text;
177
- else if (info.role === "assistant") {
177
+ if (info.role === "user" && !userText) {
178
+ userText = text;
179
+ } else if (info.role === "assistant" && !assistantText) {
178
180
  assistantText = text;
179
181
  assistantID = info.id || "";
180
182
  }
183
+ if (userText && assistantText) break;
181
184
  }
182
185
  return { userText, assistantText, assistantID };
183
186
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleboucher/opencode-memini",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "Automatic cross-session memory for opencode via memini — recall before each turn, capture after.",
5
5
  "keywords": [
6
6
  "memini",