micode 0.8.2 → 0.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "micode",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "OpenCode plugin with Brainstorm-Research-Plan-Implement workflow",
5
5
  "module": "src/index.ts",
6
6
  "main": "src/index.ts",
@@ -133,6 +133,10 @@ ${summaryText}
133
133
  })
134
134
  .catch(() => {});
135
135
 
136
+ // Set up listener BEFORE calling summarize to avoid race condition
137
+ // (summary message event could fire before we start listening)
138
+ const compactionPromise = waitForCompaction(sessionID);
139
+
136
140
  // Start the compaction - this returns immediately while compaction runs async
137
141
  await ctx.client.session.summarize({
138
142
  path: { id: sessionID },
@@ -140,8 +144,8 @@ ${summaryText}
140
144
  query: { directory: ctx.directory },
141
145
  });
142
146
 
143
- // Wait for the session.compacted event to confirm completion
144
- await waitForCompaction(sessionID);
147
+ // Wait for the summary message to be created (message.updated with summary: true)
148
+ await compactionPromise;
145
149
 
146
150
  state.lastCompactTime.set(sessionID, Date.now());
147
151
 
@@ -179,20 +183,6 @@ ${summaryText}
179
183
  event: async ({ event }: { event: { type: string; properties?: unknown } }) => {
180
184
  const props = event.properties as Record<string, unknown> | undefined;
181
185
 
182
- // Handle compaction completion
183
- if (event.type === "session.compacted") {
184
- const sessionID = props?.sessionID as string | undefined;
185
- if (sessionID) {
186
- const pending = state.pendingCompactions.get(sessionID);
187
- if (pending) {
188
- clearTimeout(pending.timeoutId);
189
- state.pendingCompactions.delete(sessionID);
190
- pending.resolve();
191
- }
192
- }
193
- return;
194
- }
195
-
196
186
  // Cleanup on session delete
197
187
  if (event.type === "session.deleted") {
198
188
  const sessionInfo = props?.info as { id?: string } | undefined;
@@ -209,15 +199,26 @@ ${summaryText}
209
199
  return;
210
200
  }
211
201
 
212
- // Monitor usage on assistant message completion
202
+ // Monitor message events
213
203
  if (event.type === "message.updated") {
214
204
  const info = props?.info as Record<string, unknown> | undefined;
215
205
  const sessionID = info?.sessionID as string | undefined;
216
206
 
217
207
  if (!sessionID || info?.role !== "assistant") return;
218
208
 
219
- // Skip if this is already a summary message
220
- if (info?.summary === true) return;
209
+ // Check if this is a summary message - signals compaction complete
210
+ if (info?.summary === true) {
211
+ const pending = state.pendingCompactions.get(sessionID);
212
+ if (pending) {
213
+ clearTimeout(pending.timeoutId);
214
+ state.pendingCompactions.delete(sessionID);
215
+ pending.resolve();
216
+ }
217
+ return;
218
+ }
219
+
220
+ // Skip triggering compaction if we're already waiting for one
221
+ if (state.pendingCompactions.has(sessionID)) return;
221
222
 
222
223
  const tokens = info?.tokens as { input?: number; cache?: { read?: number } } | undefined;
223
224
  const inputTokens = tokens?.input || 0;