ai-project-manage-cli 8.1.26 → 8.1.27
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/dist/worker-script.js +105 -35
- package/package.json +1 -1
package/dist/worker-script.js
CHANGED
|
@@ -2401,6 +2401,17 @@ async function createApmCursorAgentStore(cfg2, workspaceRef) {
|
|
|
2401
2401
|
runEvents: mirrorRunEventsForVisualization(cfg2, sqlite.runEvents)
|
|
2402
2402
|
});
|
|
2403
2403
|
}
|
|
2404
|
+
async function purgeLocalSqliteAgentData(input) {
|
|
2405
|
+
const agentId = input.agentId.trim();
|
|
2406
|
+
const workspaceRef = input.workspaceRef.trim();
|
|
2407
|
+
if (!agentId || !workspaceRef) return;
|
|
2408
|
+
const sqlite = await openSqliteLocalAgentStore(workspaceRef);
|
|
2409
|
+
const runIds = [...input.runIds ?? []];
|
|
2410
|
+
if (runIds.length > 0) {
|
|
2411
|
+
await sqlite.runEvents.delete({ filter: { runIds } });
|
|
2412
|
+
}
|
|
2413
|
+
await sqlite.checkpoints.delete({ filter: { agentIds: [agentId] } });
|
|
2414
|
+
}
|
|
2404
2415
|
|
|
2405
2416
|
// src/commands/connect/core/worker/run-steer.ts
|
|
2406
2417
|
var impl = null;
|
|
@@ -2427,6 +2438,10 @@ function deliverRunSteer(text) {
|
|
|
2427
2438
|
}
|
|
2428
2439
|
|
|
2429
2440
|
// src/commands/connect/cursor-agent.ts
|
|
2441
|
+
function isCorruptLocalAgentCheckpointError(err) {
|
|
2442
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2443
|
+
return /Corrupt local agent checkpoint/i.test(message) || /missing root blob/i.test(message);
|
|
2444
|
+
}
|
|
2430
2445
|
var noopRemoteLogSync = {
|
|
2431
2446
|
schedule(_session) {
|
|
2432
2447
|
},
|
|
@@ -2475,6 +2490,19 @@ async function obtainAgent(ctx) {
|
|
|
2475
2490
|
err instanceof Error ? err.message : err
|
|
2476
2491
|
);
|
|
2477
2492
|
ctx.onInvalidatePersistedAgentId?.();
|
|
2493
|
+
if (isCorruptLocalAgentCheckpointError(err)) {
|
|
2494
|
+
try {
|
|
2495
|
+
await purgeLocalSqliteAgentData({
|
|
2496
|
+
workspaceRef: ctx.cwd,
|
|
2497
|
+
agentId: savedAgentId
|
|
2498
|
+
});
|
|
2499
|
+
} catch (purgeErr) {
|
|
2500
|
+
console.warn(
|
|
2501
|
+
`[apm] \u6E05\u7406\u635F\u574F checkpoint \u5931\u8D25 agentId=${savedAgentId}:`,
|
|
2502
|
+
purgeErr instanceof Error ? purgeErr.message : purgeErr
|
|
2503
|
+
);
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2478
2506
|
}
|
|
2479
2507
|
}
|
|
2480
2508
|
try {
|
|
@@ -2489,6 +2517,9 @@ async function obtainAgent(ctx) {
|
|
|
2489
2517
|
}
|
|
2490
2518
|
}
|
|
2491
2519
|
async function runCursorAgent(cfg2, ctx, options) {
|
|
2520
|
+
return runCursorAgentAttempt(cfg2, ctx, options, { allowCorruptRetry: true });
|
|
2521
|
+
}
|
|
2522
|
+
async function runCursorAgentAttempt(cfg2, ctx, options, attempt) {
|
|
2492
2523
|
const signal = options.signal;
|
|
2493
2524
|
if (signal?.aborted) {
|
|
2494
2525
|
throw new Error("\u8FDE\u63A5\u5DF2\u5173\u95ED\uFF0C\u4EFB\u52A1\u4E2D\u65AD");
|
|
@@ -2535,6 +2566,8 @@ async function runCursorAgent(cfg2, ctx, options) {
|
|
|
2535
2566
|
const eventSession = options.eventSession ?? new EventSession(prompt);
|
|
2536
2567
|
const syncRemoteLog = options.createRemoteLogSync ? options.createRemoteLogSync(agent.agentId) : noopRemoteLogSync;
|
|
2537
2568
|
let activeRun;
|
|
2569
|
+
let retryCorruptWithNewAgent = false;
|
|
2570
|
+
const corruptAgentId = agent.agentId?.trim() || ctx.resumeAgentId?.trim();
|
|
2538
2571
|
const abortRun = () => {
|
|
2539
2572
|
if (!activeRun?.supports("cancel")) return;
|
|
2540
2573
|
void activeRun.cancel().catch(() => void 0);
|
|
@@ -2603,58 +2636,94 @@ async function runCursorAgent(cfg2, ctx, options) {
|
|
|
2603
2636
|
resultText: result.result
|
|
2604
2637
|
});
|
|
2605
2638
|
console.error(`[apm] ${failureMessage}`);
|
|
2606
|
-
if (resumed) {
|
|
2639
|
+
if (attempt.allowCorruptRetry && resumed && isCorruptLocalAgentCheckpointError(failureMessage)) {
|
|
2640
|
+
retryCorruptWithNewAgent = true;
|
|
2607
2641
|
invalidateAgentMapping();
|
|
2642
|
+
} else {
|
|
2643
|
+
if (resumed) {
|
|
2644
|
+
invalidateAgentMapping();
|
|
2645
|
+
}
|
|
2646
|
+
throw new Error(failureMessage);
|
|
2608
2647
|
}
|
|
2609
|
-
|
|
2610
|
-
}
|
|
2611
|
-
if (result.status === "cancelled") {
|
|
2648
|
+
} else if (result.status === "cancelled") {
|
|
2612
2649
|
throw new Error(`Cursor run \u5DF2\u53D6\u6D88: ${result.id}`);
|
|
2613
|
-
}
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
)
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
);
|
|
2650
|
+
} else {
|
|
2651
|
+
console.log(`[apm] Cursor Agent \u5B8C\u6210 messageId=${ctx.messageId}`);
|
|
2652
|
+
const artifacts = await agent.listArtifacts().catch(() => []);
|
|
2653
|
+
const artifactDocuments = [];
|
|
2654
|
+
for (const artifact of artifacts) {
|
|
2655
|
+
try {
|
|
2656
|
+
const content = (await agent.downloadArtifact(artifact.path)).toString("utf8");
|
|
2657
|
+
artifactDocuments.push({ path: artifact.path, content });
|
|
2658
|
+
} catch (err) {
|
|
2659
|
+
console.warn(
|
|
2660
|
+
`[apm] \u8BFB\u53D6\u4EA7\u7269\u5931\u8D25 path=${artifact.path}:`,
|
|
2661
|
+
err instanceof Error ? err.message : err
|
|
2662
|
+
);
|
|
2663
|
+
}
|
|
2628
2664
|
}
|
|
2665
|
+
return {
|
|
2666
|
+
runId: result.id,
|
|
2667
|
+
agentId: agent.agentId,
|
|
2668
|
+
status: result.status,
|
|
2669
|
+
result: result.result,
|
|
2670
|
+
durationMs: result.durationMs,
|
|
2671
|
+
usage: result.usage,
|
|
2672
|
+
modelId: result.model?.id?.trim() || ctx.model?.trim() || void 0,
|
|
2673
|
+
assistantText: eventSession.getAssistantText(),
|
|
2674
|
+
createPlan: eventSession.getCreatePlanContent(),
|
|
2675
|
+
artifacts,
|
|
2676
|
+
artifactDocuments
|
|
2677
|
+
};
|
|
2629
2678
|
}
|
|
2630
|
-
return {
|
|
2631
|
-
runId: result.id,
|
|
2632
|
-
agentId: agent.agentId,
|
|
2633
|
-
status: result.status,
|
|
2634
|
-
result: result.result,
|
|
2635
|
-
durationMs: result.durationMs,
|
|
2636
|
-
usage: result.usage,
|
|
2637
|
-
modelId: result.model?.id?.trim() || ctx.model?.trim() || void 0,
|
|
2638
|
-
assistantText: eventSession.getAssistantText(),
|
|
2639
|
-
createPlan: eventSession.getCreatePlanContent(),
|
|
2640
|
-
artifacts,
|
|
2641
|
-
artifactDocuments
|
|
2642
|
-
};
|
|
2643
2679
|
} catch (err) {
|
|
2644
|
-
if (
|
|
2680
|
+
if (retryCorruptWithNewAgent) {
|
|
2681
|
+
} else if (attempt.allowCorruptRetry && resumed && isCorruptLocalAgentCheckpointError(err)) {
|
|
2682
|
+
console.warn(
|
|
2683
|
+
`[apm] checkpoint \u635F\u574F\uFF08agentId=${corruptAgentId ?? "?"}\uFF09\uFF0C\u672C\u8F6E\u6539\u7528\u65B0 Agent`
|
|
2684
|
+
);
|
|
2685
|
+
retryCorruptWithNewAgent = true;
|
|
2686
|
+
invalidateAgentMapping();
|
|
2687
|
+
} else if (err instanceof CursorAgentError) {
|
|
2645
2688
|
if (resumed) {
|
|
2646
2689
|
invalidateAgentMapping();
|
|
2647
2690
|
}
|
|
2648
2691
|
throw new Error(
|
|
2649
2692
|
`Cursor \u542F\u52A8\u5931\u8D25: ${err.message}${err.isRetryable ? "\uFF08\u53EF\u91CD\u8BD5\uFF09" : ""}`
|
|
2650
2693
|
);
|
|
2694
|
+
} else {
|
|
2695
|
+
throw err;
|
|
2651
2696
|
}
|
|
2652
|
-
throw err;
|
|
2653
2697
|
} finally {
|
|
2654
2698
|
clearRunSteer();
|
|
2655
2699
|
signal?.removeEventListener("abort", abortRun);
|
|
2656
2700
|
await agent[Symbol.asyncDispose]();
|
|
2657
2701
|
}
|
|
2702
|
+
if (retryCorruptWithNewAgent) {
|
|
2703
|
+
if (corruptAgentId) {
|
|
2704
|
+
try {
|
|
2705
|
+
await purgeLocalSqliteAgentData({
|
|
2706
|
+
workspaceRef: workdir,
|
|
2707
|
+
agentId: corruptAgentId
|
|
2708
|
+
});
|
|
2709
|
+
} catch (purgeErr) {
|
|
2710
|
+
console.warn(
|
|
2711
|
+
`[apm] \u6E05\u7406\u635F\u574F checkpoint \u5931\u8D25 agentId=${corruptAgentId}:`,
|
|
2712
|
+
purgeErr instanceof Error ? purgeErr.message : purgeErr
|
|
2713
|
+
);
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
console.warn(
|
|
2717
|
+
`[apm] \u4E22\u5F03\u635F\u574F Agent${corruptAgentId ? ` agentId=${corruptAgentId}` : ""}\uFF0C\u65B0\u5EFA\u540E\u91CD\u8BD5 messageId=${ctx.messageId}`
|
|
2718
|
+
);
|
|
2719
|
+
return runCursorAgentAttempt(
|
|
2720
|
+
cfg2,
|
|
2721
|
+
{ ...ctx, resumeAgentId: void 0 },
|
|
2722
|
+
options,
|
|
2723
|
+
{ allowCorruptRetry: false }
|
|
2724
|
+
);
|
|
2725
|
+
}
|
|
2726
|
+
throw new Error("Cursor Agent \u672A\u8FD4\u56DE\u7ED3\u679C");
|
|
2658
2727
|
}
|
|
2659
2728
|
|
|
2660
2729
|
// src/commands/connect/webide-agent-registry.ts
|
|
@@ -4304,8 +4373,9 @@ ${assumptionAnswersText}` : msg2.content,
|
|
|
4304
4373
|
if (startAction) {
|
|
4305
4374
|
await webIdeDiscardTransitionPrepDraft(cfg2, taskId, startAction);
|
|
4306
4375
|
}
|
|
4307
|
-
if (detail.includes("\u590D\u7528 Agent") || detail.includes("resume")) {
|
|
4376
|
+
if (detail.includes("\u590D\u7528 Agent") || detail.includes("resume") || /Corrupt local agent checkpoint/i.test(detail) || /missing root blob/i.test(detail)) {
|
|
4308
4377
|
clearWebIdeAgentId(workdir, taskId);
|
|
4378
|
+
clearWebIdeDesignAgentId(workdir, taskId);
|
|
4309
4379
|
}
|
|
4310
4380
|
try {
|
|
4311
4381
|
await setError(cfg2, messageId, detail);
|