micode 0.7.1 → 0.7.2

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.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "OpenCode plugin with Brainstorm-Research-Plan-Implement workflow",
5
5
  "module": "src/index.ts",
6
6
  "main": "src/index.ts",
@@ -165,13 +165,21 @@ export class BackgroundTaskManager {
165
165
  const sessionStatus = statusMap[task.sessionID];
166
166
  const statusType = sessionStatus?.type;
167
167
 
168
- if (statusType === "idle") {
169
- task.status = "completed";
170
- task.completedAt = new Date();
171
- await this.getTaskResult(task.id);
172
- }
173
168
  // Store last known session status for debugging
174
169
  (task as BackgroundTask & { _sessionStatus?: string })._sessionStatus = statusType;
170
+
171
+ if (statusType === "idle" || statusType === undefined) {
172
+ // Session is idle OR not in status map (likely finished and cleaned up)
173
+ // Try to get result - if successful, mark as completed
174
+ const result = await this.fetchTaskResult(task);
175
+ if (result !== undefined || statusType === "idle") {
176
+ task.status = "completed";
177
+ task.completedAt = new Date();
178
+ task.result = result;
179
+ }
180
+ // If result is undefined and statusType is undefined, keep waiting
181
+ // (might be a timing issue with status propagation)
182
+ }
175
183
  }
176
184
  } catch (error) {
177
185
  console.error("[background-task] Failed to refresh task status:", error);
@@ -193,7 +201,18 @@ export class BackgroundTaskManager {
193
201
  return task.result;
194
202
  }
195
203
 
196
- // Fetch result from session messages
204
+ const result = await this.fetchTaskResult(task);
205
+ if (result !== undefined) {
206
+ task.result = result;
207
+ }
208
+ return result;
209
+ }
210
+
211
+ /**
212
+ * Fetch result from session messages without checking task status.
213
+ * Used during polling to check if a session has completed.
214
+ */
215
+ private async fetchTaskResult(task: BackgroundTask): Promise<string | undefined> {
197
216
  try {
198
217
  const resp = await this.ctx.client.session.messages({
199
218
  path: { id: task.sessionID },
@@ -206,11 +225,10 @@ export class BackgroundTaskManager {
206
225
 
207
226
  if (lastAssistant) {
208
227
  const textParts = lastAssistant.parts?.filter((p) => p.type === "text") || [];
209
- task.result = textParts.map((p) => p.text || "").join("\n");
210
- return task.result;
228
+ return textParts.map((p) => p.text || "").join("\n");
211
229
  }
212
230
  } catch (error) {
213
- console.error(`[background-task] Failed to fetch result for task ${taskId}:`, error);
231
+ console.error(`[background-task] Failed to fetch result for task ${task.id}:`, error);
214
232
  }
215
233
 
216
234
  return undefined;
@@ -295,25 +313,30 @@ export class BackgroundTaskManager {
295
313
 
296
314
  console.log(`[background-task] Poll ${task.id}: session=${task.sessionID} status=${statusType}`);
297
315
 
298
- if (statusType === "idle") {
299
- // Task completed
300
- task.status = "completed";
301
- task.completedAt = new Date();
302
- await this.getTaskResult(task.id); // Cache the result
303
- this.markForNotification(task);
304
-
305
- await this.ctx.client.tui
306
- .showToast({
307
- body: {
308
- title: "Background Task Complete",
309
- message: task.description,
310
- variant: "success",
311
- duration: 5000,
312
- },
313
- })
314
- .catch((error) => {
315
- console.error(`[background-task] Failed to show toast for task ${task.id}:`, error);
316
- });
316
+ if (statusType === "idle" || statusType === undefined) {
317
+ // Session is idle OR not in status map (likely finished and cleaned up)
318
+ // Try to get result - if successful, mark as completed
319
+ const result = await this.fetchTaskResult(task);
320
+ if (result !== undefined || statusType === "idle") {
321
+ task.status = "completed";
322
+ task.completedAt = new Date();
323
+ task.result = result;
324
+ this.markForNotification(task);
325
+
326
+ await this.ctx.client.tui
327
+ .showToast({
328
+ body: {
329
+ title: "Background Task Complete",
330
+ message: task.description,
331
+ variant: "success",
332
+ duration: 5000,
333
+ },
334
+ })
335
+ .catch((error) => {
336
+ console.error(`[background-task] Failed to show toast for task ${task.id}:`, error);
337
+ });
338
+ }
339
+ // If result is undefined and statusType is undefined, keep waiting
317
340
  }
318
341
  }
319
342
  } catch (error) {