ai-project-manage-cli 7.1.32 → 7.1.34
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/index.js +90 -57
- package/dist/webide-message-worker.js +176 -99
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7244,7 +7244,7 @@ function cleanSessionWorkspaceCache(sessionId, workdir) {
|
|
|
7244
7244
|
// src/commands/clean-webide-cache.ts
|
|
7245
7245
|
import { existsSync as existsSync24, rmSync as rmSync5 } from "node:fs";
|
|
7246
7246
|
import { resolve as resolve7 } from "node:path";
|
|
7247
|
-
import {
|
|
7247
|
+
import { getDefaultSdkStateRoot } from "@cursor/sdk";
|
|
7248
7248
|
|
|
7249
7249
|
// src/commands/connect/webide-agent-registry.ts
|
|
7250
7250
|
import { existsSync as existsSync23, mkdirSync as mkdirSync10, readFileSync as readFileSync17, writeFileSync as writeFileSync15 } from "node:fs";
|
|
@@ -7259,10 +7259,27 @@ function readRegistry(path19) {
|
|
|
7259
7259
|
try {
|
|
7260
7260
|
const parsed = JSON.parse(readFileSync17(path19, "utf8"));
|
|
7261
7261
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
7262
|
-
const
|
|
7263
|
-
|
|
7264
|
-
|
|
7262
|
+
const raw = parsed;
|
|
7263
|
+
const state = {};
|
|
7264
|
+
if (typeof raw.agentId === "string" && raw.agentId.trim()) {
|
|
7265
|
+
state.agentId = raw.agentId.trim();
|
|
7265
7266
|
}
|
|
7267
|
+
if (typeof raw.taskId === "string" && raw.taskId.trim()) {
|
|
7268
|
+
state.taskId = raw.taskId.trim();
|
|
7269
|
+
}
|
|
7270
|
+
if (typeof raw.messageId === "string" && raw.messageId.trim()) {
|
|
7271
|
+
state.messageId = raw.messageId.trim();
|
|
7272
|
+
}
|
|
7273
|
+
if (typeof raw.action === "string" && raw.action.trim()) {
|
|
7274
|
+
state.action = raw.action.trim();
|
|
7275
|
+
}
|
|
7276
|
+
if (raw.status === "TYPING" || raw.status === "SUCCESS" || raw.status === "FAILED" || raw.status === "CANCELLED") {
|
|
7277
|
+
state.status = raw.status;
|
|
7278
|
+
}
|
|
7279
|
+
if (typeof raw.updatedAt === "string" && raw.updatedAt.trim()) {
|
|
7280
|
+
state.updatedAt = raw.updatedAt.trim();
|
|
7281
|
+
}
|
|
7282
|
+
return state;
|
|
7266
7283
|
}
|
|
7267
7284
|
} catch {
|
|
7268
7285
|
}
|
|
@@ -7273,37 +7290,44 @@ function loadWebIdeAgentId(workdir, taskId) {
|
|
|
7273
7290
|
}
|
|
7274
7291
|
|
|
7275
7292
|
// src/commands/clean-webide-cache.ts
|
|
7276
|
-
function cursorAgentStoreDir(workdir) {
|
|
7277
|
-
return resolve7(workdir, ".apm", "cursor-agent-store");
|
|
7278
|
-
}
|
|
7279
7293
|
async function purgeCursorAgentStoreForAgent(workdir, agentId) {
|
|
7280
7294
|
const trimmedAgentId = agentId.trim();
|
|
7281
7295
|
const trimmedWorkdir = workdir.trim();
|
|
7282
7296
|
if (!trimmedAgentId || !trimmedWorkdir) return false;
|
|
7283
|
-
const
|
|
7284
|
-
if (!existsSync24(
|
|
7285
|
-
const
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
7289
|
-
|
|
7290
|
-
|
|
7291
|
-
|
|
7292
|
-
|
|
7293
|
-
|
|
7297
|
+
const stateRoot = getDefaultSdkStateRoot(trimmedWorkdir);
|
|
7298
|
+
if (!existsSync24(stateRoot)) return false;
|
|
7299
|
+
const { SqliteLocalAgentStore } = await import(
|
|
7300
|
+
/* @vite-ignore */
|
|
7301
|
+
"@cursor/sdk/sqlite"
|
|
7302
|
+
);
|
|
7303
|
+
const store = await SqliteLocalAgentStore.open({
|
|
7304
|
+
workspaceRef: trimmedWorkdir
|
|
7305
|
+
});
|
|
7306
|
+
try {
|
|
7307
|
+
const runIds = [];
|
|
7308
|
+
let cursor;
|
|
7309
|
+
do {
|
|
7310
|
+
const page = await store.runs.list({
|
|
7311
|
+
filter: {
|
|
7312
|
+
agentIds: [trimmedAgentId],
|
|
7313
|
+
...cursor ? { cursor } : {},
|
|
7314
|
+
limit: 200
|
|
7315
|
+
}
|
|
7316
|
+
});
|
|
7317
|
+
for (const run of page.items) {
|
|
7318
|
+
runIds.push(run.runId);
|
|
7294
7319
|
}
|
|
7295
|
-
|
|
7296
|
-
|
|
7297
|
-
|
|
7298
|
-
|
|
7299
|
-
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
await store.
|
|
7320
|
+
cursor = page.nextCursor;
|
|
7321
|
+
} while (cursor);
|
|
7322
|
+
if (runIds.length > 0) {
|
|
7323
|
+
await store.runEvents.delete({ filter: { runIds } });
|
|
7324
|
+
}
|
|
7325
|
+
await store.runs.delete({ filter: { agentIds: [trimmedAgentId] } });
|
|
7326
|
+
await store.checkpoints.delete({ filter: { agentIds: [trimmedAgentId] } });
|
|
7327
|
+
await store.agents.delete({ filter: { agentIds: [trimmedAgentId] } });
|
|
7328
|
+
} finally {
|
|
7329
|
+
await store.dispose();
|
|
7303
7330
|
}
|
|
7304
|
-
await store.runs.delete({ filter: { agentIds: [trimmedAgentId] } });
|
|
7305
|
-
await store.checkpoints.delete({ filter: { agentIds: [trimmedAgentId] } });
|
|
7306
|
-
await store.agents.delete({ filter: { agentIds: [trimmedAgentId] } });
|
|
7307
7331
|
return true;
|
|
7308
7332
|
}
|
|
7309
7333
|
async function cleanWebIdeWorkspaceCache(taskId, workdir) {
|
|
@@ -7332,7 +7356,7 @@ async function cleanWebIdeWorkspaceCache(taskId, workdir) {
|
|
|
7332
7356
|
}
|
|
7333
7357
|
} else {
|
|
7334
7358
|
console.log(
|
|
7335
|
-
`[apm] \u65E0 WebIDE agentId\uFF0C\u8DF3\u8FC7
|
|
7359
|
+
`[apm] \u65E0 WebIDE agentId\uFF0C\u8DF3\u8FC7 agent store \u6E05\u7406 taskId=${trimmedTaskId}`
|
|
7336
7360
|
);
|
|
7337
7361
|
}
|
|
7338
7362
|
const dir = resolve7(trimmedWorkdir, ".apm", "webide", trimmedTaskId);
|
|
@@ -8348,16 +8372,6 @@ function withWorkspaceBoundaryHint(prompt) {
|
|
|
8348
8372
|
${WORKSPACE_BOUNDARY_HINT}`;
|
|
8349
8373
|
}
|
|
8350
8374
|
|
|
8351
|
-
// src/commands/connect/local-agent-store.ts
|
|
8352
|
-
import { mkdirSync as mkdirSync12 } from "node:fs";
|
|
8353
|
-
import { join as join19 } from "node:path";
|
|
8354
|
-
import { JsonlLocalAgentStore as JsonlLocalAgentStore2 } from "@cursor/sdk";
|
|
8355
|
-
function createWorkspaceLocalAgentStore(workdir) {
|
|
8356
|
-
const rootDir = join19(workdir, ".apm", "cursor-agent-store");
|
|
8357
|
-
mkdirSync12(rootDir, { recursive: true });
|
|
8358
|
-
return new JsonlLocalAgentStore2(rootDir);
|
|
8359
|
-
}
|
|
8360
|
-
|
|
8361
8375
|
// src/commands/connect/cursor-agent.ts
|
|
8362
8376
|
setMaxListeners2(100);
|
|
8363
8377
|
installAbortSignalDebug();
|
|
@@ -8385,13 +8399,25 @@ function formatCursorRunFailure(runId, options) {
|
|
|
8385
8399
|
}
|
|
8386
8400
|
return `Cursor run \u5931\u8D25: ${runId} \u2014 ${details.join("\uFF1B")}`;
|
|
8387
8401
|
}
|
|
8402
|
+
function persistSessionAgentId(ctx, agentId) {
|
|
8403
|
+
if (ctx.skipSessionAgentRegistry || !ctx.user) return;
|
|
8404
|
+
saveSessionAgentId(ctx.workdir, ctx.sessionId, ctx.user, agentId);
|
|
8405
|
+
}
|
|
8406
|
+
function invalidatePersistedAgentId(ctx) {
|
|
8407
|
+
if (ctx.skipSessionAgentRegistry) {
|
|
8408
|
+
ctx.onInvalidatePersistedAgentId?.();
|
|
8409
|
+
return;
|
|
8410
|
+
}
|
|
8411
|
+
if (ctx.user) {
|
|
8412
|
+
clearSessionAgentId(ctx.workdir, ctx.sessionId, ctx.user);
|
|
8413
|
+
}
|
|
8414
|
+
}
|
|
8388
8415
|
async function obtainAgent(ctx) {
|
|
8389
8416
|
const agentOptions = {
|
|
8390
8417
|
apiKey: ctx.apiKey,
|
|
8391
8418
|
model: { id: ctx.model || "default" },
|
|
8392
8419
|
local: {
|
|
8393
8420
|
cwd: ctx.cwd,
|
|
8394
|
-
store: createWorkspaceLocalAgentStore(ctx.workdir),
|
|
8395
8421
|
...ctx.customTools ? { customTools: ctx.customTools } : {},
|
|
8396
8422
|
...ctx.enableSandbox ? {
|
|
8397
8423
|
sandboxOptions: { enabled: true },
|
|
@@ -8403,32 +8429,28 @@ async function obtainAgent(ctx) {
|
|
|
8403
8429
|
...ctx.mcpServers ? { mcpServers: ctx.mcpServers } : {}
|
|
8404
8430
|
};
|
|
8405
8431
|
const explicitAgentId = ctx.resumeAgentId?.trim();
|
|
8406
|
-
const savedAgentId = explicitAgentId || (ctx.user ? loadSessionAgentId(ctx.workdir, ctx.sessionId, ctx.user) : void 0);
|
|
8432
|
+
const savedAgentId = explicitAgentId || (!ctx.skipSessionAgentRegistry && ctx.user ? loadSessionAgentId(ctx.workdir, ctx.sessionId, ctx.user) : void 0);
|
|
8407
8433
|
if (savedAgentId) {
|
|
8408
8434
|
try {
|
|
8409
8435
|
const agent = await Agent.resume(savedAgentId, agentOptions);
|
|
8410
8436
|
console.log(
|
|
8411
8437
|
`[apm] \u590D\u7528 Agent user=${ctx.user} agentId=${savedAgentId}${explicitAgentId ? "\uFF08\u53C2\u6570\u6307\u5B9A\uFF09" : ""}`
|
|
8412
8438
|
);
|
|
8413
|
-
|
|
8414
|
-
saveSessionAgentId(ctx.workdir, ctx.sessionId, ctx.user, agent.agentId);
|
|
8415
|
-
}
|
|
8439
|
+
persistSessionAgentId(ctx, agent.agentId);
|
|
8416
8440
|
return { agent, resumed: true };
|
|
8417
8441
|
} catch (err) {
|
|
8418
8442
|
console.warn(
|
|
8419
8443
|
`[apm] \u590D\u7528 Agent \u5931\u8D25\uFF08agentId=${savedAgentId}\uFF09\uFF0C\u56DE\u9000\u4E3A\u65B0\u5EFA:`,
|
|
8420
8444
|
err instanceof Error ? err.message : err
|
|
8421
8445
|
);
|
|
8422
|
-
if (!explicitAgentId
|
|
8423
|
-
|
|
8446
|
+
if (!explicitAgentId) {
|
|
8447
|
+
invalidatePersistedAgentId(ctx);
|
|
8424
8448
|
}
|
|
8425
8449
|
}
|
|
8426
8450
|
}
|
|
8427
8451
|
try {
|
|
8428
8452
|
const agent = await Agent.create(agentOptions);
|
|
8429
|
-
|
|
8430
|
-
saveSessionAgentId(ctx.workdir, ctx.sessionId, ctx.user, agent.agentId);
|
|
8431
|
-
}
|
|
8453
|
+
persistSessionAgentId(ctx, agent.agentId);
|
|
8432
8454
|
return { agent, resumed: false };
|
|
8433
8455
|
} catch (err) {
|
|
8434
8456
|
if (ctx.enableSandbox && err instanceof Error && /sandbox/i.test(err.message)) {
|
|
@@ -8474,8 +8496,19 @@ async function runCursorAgent(cfg, ctx, options) {
|
|
|
8474
8496
|
mode: ctx.mode,
|
|
8475
8497
|
resumeAgentId: ctx.resumeAgentId,
|
|
8476
8498
|
customTools,
|
|
8477
|
-
enableSandbox
|
|
8499
|
+
enableSandbox,
|
|
8500
|
+
skipSessionAgentRegistry: options?.skipSessionAgentRegistry,
|
|
8501
|
+
onInvalidatePersistedAgentId: options?.onInvalidatePersistedAgentId
|
|
8478
8502
|
});
|
|
8503
|
+
const invalidateAgentMapping = () => {
|
|
8504
|
+
invalidatePersistedAgentId({
|
|
8505
|
+
workdir,
|
|
8506
|
+
sessionId: ctx.sessionId,
|
|
8507
|
+
user: ctx.user,
|
|
8508
|
+
skipSessionAgentRegistry: options?.skipSessionAgentRegistry,
|
|
8509
|
+
onInvalidatePersistedAgentId: options?.onInvalidatePersistedAgentId
|
|
8510
|
+
});
|
|
8511
|
+
};
|
|
8479
8512
|
const eventSession = options?.eventSession ?? new EventSession(prompt);
|
|
8480
8513
|
const syncRemoteLog = options?.createRemoteLogSync ? options.createRemoteLogSync(agent.agentId) : options?.skipRemoteLogSync ? noopRemoteLogSync : createThrottledCursorMessageLogSync(
|
|
8481
8514
|
cfg,
|
|
@@ -8543,7 +8576,7 @@ async function runCursorAgent(cfg, ctx, options) {
|
|
|
8543
8576
|
});
|
|
8544
8577
|
console.error(`[apm] ${failureMessage}`);
|
|
8545
8578
|
if (resumed) {
|
|
8546
|
-
|
|
8579
|
+
invalidateAgentMapping();
|
|
8547
8580
|
}
|
|
8548
8581
|
throw new Error(failureMessage);
|
|
8549
8582
|
}
|
|
@@ -8582,7 +8615,7 @@ async function runCursorAgent(cfg, ctx, options) {
|
|
|
8582
8615
|
} catch (err) {
|
|
8583
8616
|
if (err instanceof CursorAgentError) {
|
|
8584
8617
|
if (resumed) {
|
|
8585
|
-
|
|
8618
|
+
invalidateAgentMapping();
|
|
8586
8619
|
}
|
|
8587
8620
|
throw new Error(
|
|
8588
8621
|
`Cursor \u542F\u52A8\u5931\u8D25: ${err.message}${err.isRetryable ? "\uFF08\u53EF\u91CD\u8BD5\uFF09" : ""}`
|
|
@@ -8636,10 +8669,10 @@ async function ensureMessageHasReply(cfg, sessionId, messageId, fallback) {
|
|
|
8636
8669
|
|
|
8637
8670
|
// src/commands/connect/cli-version-sync.ts
|
|
8638
8671
|
import { existsSync as existsSync26, readFileSync as readFileSync19, writeFileSync as writeFileSync17 } from "fs";
|
|
8639
|
-
import { join as
|
|
8672
|
+
import { join as join19 } from "path";
|
|
8640
8673
|
var CLI_VERSION_FILE = ".cli-version.json";
|
|
8641
8674
|
function manifestPath2(apmDir) {
|
|
8642
|
-
return
|
|
8675
|
+
return join19(apmDir, CLI_VERSION_FILE);
|
|
8643
8676
|
}
|
|
8644
8677
|
function loadManifest4(apmDir) {
|
|
8645
8678
|
const path19 = toFsPath(manifestPath2(apmDir));
|
|
@@ -8746,8 +8779,8 @@ init_webide_terminal_registry();
|
|
|
8746
8779
|
import { Worker } from "node:worker_threads";
|
|
8747
8780
|
import { totalmem } from "node:os";
|
|
8748
8781
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
8749
|
-
import { dirname as dirname9, join as
|
|
8750
|
-
var workerFile =
|
|
8782
|
+
import { dirname as dirname9, join as join20 } from "node:path";
|
|
8783
|
+
var workerFile = join20(
|
|
8751
8784
|
dirname9(fileURLToPath3(import.meta.url)),
|
|
8752
8785
|
"webide-message-worker.js"
|
|
8753
8786
|
);
|
|
@@ -2263,16 +2263,6 @@ function withWorkspaceBoundaryHint(prompt) {
|
|
|
2263
2263
|
${WORKSPACE_BOUNDARY_HINT}`;
|
|
2264
2264
|
}
|
|
2265
2265
|
|
|
2266
|
-
// src/commands/connect/local-agent-store.ts
|
|
2267
|
-
import { mkdirSync as mkdirSync5 } from "node:fs";
|
|
2268
|
-
import { join as join4 } from "node:path";
|
|
2269
|
-
import { JsonlLocalAgentStore } from "@cursor/sdk";
|
|
2270
|
-
function createWorkspaceLocalAgentStore(workdir) {
|
|
2271
|
-
const rootDir = join4(workdir, ".apm", "cursor-agent-store");
|
|
2272
|
-
mkdirSync5(rootDir, { recursive: true });
|
|
2273
|
-
return new JsonlLocalAgentStore(rootDir);
|
|
2274
|
-
}
|
|
2275
|
-
|
|
2276
2266
|
// src/commands/connect/cursor-agent.ts
|
|
2277
2267
|
setMaxListeners2(100);
|
|
2278
2268
|
installAbortSignalDebug();
|
|
@@ -2300,13 +2290,25 @@ function formatCursorRunFailure(runId, options) {
|
|
|
2300
2290
|
}
|
|
2301
2291
|
return `Cursor run \u5931\u8D25: ${runId} \u2014 ${details.join("\uFF1B")}`;
|
|
2302
2292
|
}
|
|
2293
|
+
function persistSessionAgentId(ctx, agentId) {
|
|
2294
|
+
if (ctx.skipSessionAgentRegistry || !ctx.user) return;
|
|
2295
|
+
saveSessionAgentId(ctx.workdir, ctx.sessionId, ctx.user, agentId);
|
|
2296
|
+
}
|
|
2297
|
+
function invalidatePersistedAgentId(ctx) {
|
|
2298
|
+
if (ctx.skipSessionAgentRegistry) {
|
|
2299
|
+
ctx.onInvalidatePersistedAgentId?.();
|
|
2300
|
+
return;
|
|
2301
|
+
}
|
|
2302
|
+
if (ctx.user) {
|
|
2303
|
+
clearSessionAgentId(ctx.workdir, ctx.sessionId, ctx.user);
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2303
2306
|
async function obtainAgent(ctx) {
|
|
2304
2307
|
const agentOptions = {
|
|
2305
2308
|
apiKey: ctx.apiKey,
|
|
2306
2309
|
model: { id: ctx.model || "default" },
|
|
2307
2310
|
local: {
|
|
2308
2311
|
cwd: ctx.cwd,
|
|
2309
|
-
store: createWorkspaceLocalAgentStore(ctx.workdir),
|
|
2310
2312
|
...ctx.customTools ? { customTools: ctx.customTools } : {},
|
|
2311
2313
|
...ctx.enableSandbox ? {
|
|
2312
2314
|
sandboxOptions: { enabled: true },
|
|
@@ -2318,32 +2320,28 @@ async function obtainAgent(ctx) {
|
|
|
2318
2320
|
...ctx.mcpServers ? { mcpServers: ctx.mcpServers } : {}
|
|
2319
2321
|
};
|
|
2320
2322
|
const explicitAgentId = ctx.resumeAgentId?.trim();
|
|
2321
|
-
const savedAgentId = explicitAgentId || (ctx.user ? loadSessionAgentId(ctx.workdir, ctx.sessionId, ctx.user) : void 0);
|
|
2323
|
+
const savedAgentId = explicitAgentId || (!ctx.skipSessionAgentRegistry && ctx.user ? loadSessionAgentId(ctx.workdir, ctx.sessionId, ctx.user) : void 0);
|
|
2322
2324
|
if (savedAgentId) {
|
|
2323
2325
|
try {
|
|
2324
2326
|
const agent = await Agent.resume(savedAgentId, agentOptions);
|
|
2325
2327
|
console.log(
|
|
2326
2328
|
`[apm] \u590D\u7528 Agent user=${ctx.user} agentId=${savedAgentId}${explicitAgentId ? "\uFF08\u53C2\u6570\u6307\u5B9A\uFF09" : ""}`
|
|
2327
2329
|
);
|
|
2328
|
-
|
|
2329
|
-
saveSessionAgentId(ctx.workdir, ctx.sessionId, ctx.user, agent.agentId);
|
|
2330
|
-
}
|
|
2330
|
+
persistSessionAgentId(ctx, agent.agentId);
|
|
2331
2331
|
return { agent, resumed: true };
|
|
2332
2332
|
} catch (err) {
|
|
2333
2333
|
console.warn(
|
|
2334
2334
|
`[apm] \u590D\u7528 Agent \u5931\u8D25\uFF08agentId=${savedAgentId}\uFF09\uFF0C\u56DE\u9000\u4E3A\u65B0\u5EFA:`,
|
|
2335
2335
|
err instanceof Error ? err.message : err
|
|
2336
2336
|
);
|
|
2337
|
-
if (!explicitAgentId
|
|
2338
|
-
|
|
2337
|
+
if (!explicitAgentId) {
|
|
2338
|
+
invalidatePersistedAgentId(ctx);
|
|
2339
2339
|
}
|
|
2340
2340
|
}
|
|
2341
2341
|
}
|
|
2342
2342
|
try {
|
|
2343
2343
|
const agent = await Agent.create(agentOptions);
|
|
2344
|
-
|
|
2345
|
-
saveSessionAgentId(ctx.workdir, ctx.sessionId, ctx.user, agent.agentId);
|
|
2346
|
-
}
|
|
2344
|
+
persistSessionAgentId(ctx, agent.agentId);
|
|
2347
2345
|
return { agent, resumed: false };
|
|
2348
2346
|
} catch (err) {
|
|
2349
2347
|
if (ctx.enableSandbox && err instanceof Error && /sandbox/i.test(err.message)) {
|
|
@@ -2389,8 +2387,19 @@ async function runCursorAgent(cfg, ctx, options) {
|
|
|
2389
2387
|
mode: ctx.mode,
|
|
2390
2388
|
resumeAgentId: ctx.resumeAgentId,
|
|
2391
2389
|
customTools,
|
|
2392
|
-
enableSandbox
|
|
2390
|
+
enableSandbox,
|
|
2391
|
+
skipSessionAgentRegistry: options?.skipSessionAgentRegistry,
|
|
2392
|
+
onInvalidatePersistedAgentId: options?.onInvalidatePersistedAgentId
|
|
2393
2393
|
});
|
|
2394
|
+
const invalidateAgentMapping = () => {
|
|
2395
|
+
invalidatePersistedAgentId({
|
|
2396
|
+
workdir,
|
|
2397
|
+
sessionId: ctx.sessionId,
|
|
2398
|
+
user: ctx.user,
|
|
2399
|
+
skipSessionAgentRegistry: options?.skipSessionAgentRegistry,
|
|
2400
|
+
onInvalidatePersistedAgentId: options?.onInvalidatePersistedAgentId
|
|
2401
|
+
});
|
|
2402
|
+
};
|
|
2394
2403
|
const eventSession = options?.eventSession ?? new EventSession(prompt);
|
|
2395
2404
|
const syncRemoteLog = options?.createRemoteLogSync ? options.createRemoteLogSync(agent.agentId) : options?.skipRemoteLogSync ? noopRemoteLogSync : createThrottledCursorMessageLogSync(
|
|
2396
2405
|
cfg,
|
|
@@ -2458,7 +2467,7 @@ async function runCursorAgent(cfg, ctx, options) {
|
|
|
2458
2467
|
});
|
|
2459
2468
|
console.error(`[apm] ${failureMessage}`);
|
|
2460
2469
|
if (resumed) {
|
|
2461
|
-
|
|
2470
|
+
invalidateAgentMapping();
|
|
2462
2471
|
}
|
|
2463
2472
|
throw new Error(failureMessage);
|
|
2464
2473
|
}
|
|
@@ -2497,7 +2506,7 @@ async function runCursorAgent(cfg, ctx, options) {
|
|
|
2497
2506
|
} catch (err) {
|
|
2498
2507
|
if (err instanceof CursorAgentError) {
|
|
2499
2508
|
if (resumed) {
|
|
2500
|
-
|
|
2509
|
+
invalidateAgentMapping();
|
|
2501
2510
|
}
|
|
2502
2511
|
throw new Error(
|
|
2503
2512
|
`Cursor \u542F\u52A8\u5931\u8D25: ${err.message}${err.isRetryable ? "\uFF08\u53EF\u91CD\u8BD5\uFF09" : ""}`
|
|
@@ -2513,7 +2522,7 @@ async function runCursorAgent(cfg, ctx, options) {
|
|
|
2513
2522
|
}
|
|
2514
2523
|
|
|
2515
2524
|
// src/commands/connect/webide-agent-registry.ts
|
|
2516
|
-
import { existsSync as existsSync4, mkdirSync as
|
|
2525
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
2517
2526
|
import { dirname as dirname4, resolve as resolve5 } from "node:path";
|
|
2518
2527
|
function registryPath2(workdir, taskId) {
|
|
2519
2528
|
return resolve5(workdir, ".apm", "webide", taskId, "cursor-agent.json");
|
|
@@ -2525,67 +2534,121 @@ function readRegistry2(path) {
|
|
|
2525
2534
|
try {
|
|
2526
2535
|
const parsed = JSON.parse(readFileSync5(path, "utf8"));
|
|
2527
2536
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
2528
|
-
const
|
|
2529
|
-
|
|
2530
|
-
|
|
2537
|
+
const raw = parsed;
|
|
2538
|
+
const state = {};
|
|
2539
|
+
if (typeof raw.agentId === "string" && raw.agentId.trim()) {
|
|
2540
|
+
state.agentId = raw.agentId.trim();
|
|
2541
|
+
}
|
|
2542
|
+
if (typeof raw.taskId === "string" && raw.taskId.trim()) {
|
|
2543
|
+
state.taskId = raw.taskId.trim();
|
|
2544
|
+
}
|
|
2545
|
+
if (typeof raw.messageId === "string" && raw.messageId.trim()) {
|
|
2546
|
+
state.messageId = raw.messageId.trim();
|
|
2547
|
+
}
|
|
2548
|
+
if (typeof raw.action === "string" && raw.action.trim()) {
|
|
2549
|
+
state.action = raw.action.trim();
|
|
2550
|
+
}
|
|
2551
|
+
if (raw.status === "TYPING" || raw.status === "SUCCESS" || raw.status === "FAILED" || raw.status === "CANCELLED") {
|
|
2552
|
+
state.status = raw.status;
|
|
2531
2553
|
}
|
|
2554
|
+
if (typeof raw.updatedAt === "string" && raw.updatedAt.trim()) {
|
|
2555
|
+
state.updatedAt = raw.updatedAt.trim();
|
|
2556
|
+
}
|
|
2557
|
+
return state;
|
|
2532
2558
|
}
|
|
2533
2559
|
} catch {
|
|
2534
2560
|
}
|
|
2535
2561
|
return {};
|
|
2536
2562
|
}
|
|
2537
2563
|
function writeRegistry2(path, registry) {
|
|
2538
|
-
|
|
2564
|
+
mkdirSync5(dirname4(path), { recursive: true });
|
|
2539
2565
|
writeFileSync5(path, `${JSON.stringify(registry, null, 2)}
|
|
2540
2566
|
`, "utf8");
|
|
2541
2567
|
}
|
|
2568
|
+
function syncWebIdeTaskState(workdir, taskId, patch) {
|
|
2569
|
+
const trimmedTaskId = taskId.trim();
|
|
2570
|
+
if (!trimmedTaskId) return;
|
|
2571
|
+
const path = registryPath2(workdir, trimmedTaskId);
|
|
2572
|
+
const current = readRegistry2(path);
|
|
2573
|
+
const next = {
|
|
2574
|
+
...current,
|
|
2575
|
+
taskId: trimmedTaskId,
|
|
2576
|
+
updatedAt: patch.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
2577
|
+
};
|
|
2578
|
+
if (patch.agentId !== void 0) {
|
|
2579
|
+
const agentId = patch.agentId.trim();
|
|
2580
|
+
if (agentId) next.agentId = agentId;
|
|
2581
|
+
else delete next.agentId;
|
|
2582
|
+
}
|
|
2583
|
+
if (patch.messageId !== void 0) {
|
|
2584
|
+
const messageId = patch.messageId.trim();
|
|
2585
|
+
if (messageId) next.messageId = messageId;
|
|
2586
|
+
else delete next.messageId;
|
|
2587
|
+
}
|
|
2588
|
+
if (patch.action !== void 0) {
|
|
2589
|
+
const action = patch.action.trim();
|
|
2590
|
+
if (action) next.action = action;
|
|
2591
|
+
else delete next.action;
|
|
2592
|
+
}
|
|
2593
|
+
if (patch.status !== void 0) {
|
|
2594
|
+
next.status = patch.status;
|
|
2595
|
+
}
|
|
2596
|
+
writeRegistry2(path, next);
|
|
2597
|
+
}
|
|
2542
2598
|
function loadWebIdeAgentId(workdir, taskId) {
|
|
2543
2599
|
return readRegistry2(registryPath2(workdir, taskId)).agentId;
|
|
2544
2600
|
}
|
|
2545
2601
|
function saveWebIdeAgentId(workdir, taskId, agentId) {
|
|
2546
|
-
|
|
2602
|
+
syncWebIdeTaskState(workdir, taskId, { agentId });
|
|
2547
2603
|
}
|
|
2548
2604
|
function clearWebIdeAgentId(workdir, taskId) {
|
|
2549
2605
|
const path = registryPath2(workdir, taskId);
|
|
2550
2606
|
if (!existsSync4(path)) return;
|
|
2551
|
-
|
|
2607
|
+
syncWebIdeTaskState(workdir, taskId, { agentId: "" });
|
|
2552
2608
|
}
|
|
2553
2609
|
|
|
2554
2610
|
// src/commands/clean-webide-cache.ts
|
|
2555
2611
|
import { existsSync as existsSync5, rmSync } from "node:fs";
|
|
2556
2612
|
import { resolve as resolve6 } from "node:path";
|
|
2557
|
-
import {
|
|
2558
|
-
function cursorAgentStoreDir(workdir) {
|
|
2559
|
-
return resolve6(workdir, ".apm", "cursor-agent-store");
|
|
2560
|
-
}
|
|
2613
|
+
import { getDefaultSdkStateRoot } from "@cursor/sdk";
|
|
2561
2614
|
async function purgeCursorAgentStoreForAgent(workdir, agentId) {
|
|
2562
2615
|
const trimmedAgentId = agentId.trim();
|
|
2563
2616
|
const trimmedWorkdir = workdir.trim();
|
|
2564
2617
|
if (!trimmedAgentId || !trimmedWorkdir) return false;
|
|
2565
|
-
const
|
|
2566
|
-
if (!existsSync5(
|
|
2567
|
-
const
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2618
|
+
const stateRoot = getDefaultSdkStateRoot(trimmedWorkdir);
|
|
2619
|
+
if (!existsSync5(stateRoot)) return false;
|
|
2620
|
+
const { SqliteLocalAgentStore } = await import(
|
|
2621
|
+
/* @vite-ignore */
|
|
2622
|
+
"@cursor/sdk/sqlite"
|
|
2623
|
+
);
|
|
2624
|
+
const store = await SqliteLocalAgentStore.open({
|
|
2625
|
+
workspaceRef: trimmedWorkdir
|
|
2626
|
+
});
|
|
2627
|
+
try {
|
|
2628
|
+
const runIds = [];
|
|
2629
|
+
let cursor;
|
|
2630
|
+
do {
|
|
2631
|
+
const page = await store.runs.list({
|
|
2632
|
+
filter: {
|
|
2633
|
+
agentIds: [trimmedAgentId],
|
|
2634
|
+
...cursor ? { cursor } : {},
|
|
2635
|
+
limit: 200
|
|
2636
|
+
}
|
|
2637
|
+
});
|
|
2638
|
+
for (const run of page.items) {
|
|
2639
|
+
runIds.push(run.runId);
|
|
2576
2640
|
}
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2641
|
+
cursor = page.nextCursor;
|
|
2642
|
+
} while (cursor);
|
|
2643
|
+
if (runIds.length > 0) {
|
|
2644
|
+
await store.runEvents.delete({ filter: { runIds } });
|
|
2580
2645
|
}
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
await store.checkpoints.delete({ filter: { agentIds: [trimmedAgentId] } });
|
|
2588
|
-
await store.agents.delete({ filter: { agentIds: [trimmedAgentId] } });
|
|
2646
|
+
await store.runs.delete({ filter: { agentIds: [trimmedAgentId] } });
|
|
2647
|
+
await store.checkpoints.delete({ filter: { agentIds: [trimmedAgentId] } });
|
|
2648
|
+
await store.agents.delete({ filter: { agentIds: [trimmedAgentId] } });
|
|
2649
|
+
} finally {
|
|
2650
|
+
await store.dispose();
|
|
2651
|
+
}
|
|
2589
2652
|
return true;
|
|
2590
2653
|
}
|
|
2591
2654
|
async function cleanWebIdeWorkspaceCache(taskId, workdir) {
|
|
@@ -2614,7 +2677,7 @@ async function cleanWebIdeWorkspaceCache(taskId, workdir) {
|
|
|
2614
2677
|
}
|
|
2615
2678
|
} else {
|
|
2616
2679
|
console.log(
|
|
2617
|
-
`[apm] \u65E0 WebIDE agentId\uFF0C\u8DF3\u8FC7
|
|
2680
|
+
`[apm] \u65E0 WebIDE agentId\uFF0C\u8DF3\u8FC7 agent store \u6E05\u7406 taskId=${trimmedTaskId}`
|
|
2618
2681
|
);
|
|
2619
2682
|
}
|
|
2620
2683
|
const dir = resolve6(trimmedWorkdir, ".apm", "webide", trimmedTaskId);
|
|
@@ -2936,11 +2999,11 @@ function resolveMessageReplyFallback(fallback) {
|
|
|
2936
2999
|
}
|
|
2937
3000
|
|
|
2938
3001
|
// src/commands/init.ts
|
|
2939
|
-
import { join as
|
|
3002
|
+
import { join as join6 } from "path";
|
|
2940
3003
|
import { readFileSync as readFileSync7, writeFileSync as writeFileSync8 } from "fs";
|
|
2941
3004
|
|
|
2942
3005
|
// src/deployment-config-sync.ts
|
|
2943
|
-
import { join as
|
|
3006
|
+
import { join as join4 } from "path";
|
|
2944
3007
|
import { writeFileSync as writeFileSync6 } from "fs";
|
|
2945
3008
|
var TEMPLATE_HINT = "\u4FDD\u7559\u6A21\u677F .apm/apm.config.json";
|
|
2946
3009
|
var SYNC_HINT = "\u767B\u8BB0\u5DE5\u4F5C\u7A7A\u95F4\u8DEF\u5F84\u3001\u7ED1\u5B9A\u4ED3\u5E93\u540E\uFF0C\u53EF\u6267\u884C: apm sync-deploy-config";
|
|
@@ -2966,7 +3029,7 @@ async function writeDeploymentConfigContent(apmDir, content, configName) {
|
|
|
2966
3029
|
);
|
|
2967
3030
|
return false;
|
|
2968
3031
|
}
|
|
2969
|
-
const apmConfigPath = toFsPath(
|
|
3032
|
+
const apmConfigPath = toFsPath(join4(apmDir, "apm.config.json"));
|
|
2970
3033
|
writeFileSync6(apmConfigPath, `${JSON.stringify(parsed, null, 2)}
|
|
2971
3034
|
`, "utf8");
|
|
2972
3035
|
console.log(`[apm] \u5DF2\u540C\u6B65\u5E73\u53F0\u90E8\u7F72\u914D\u7F6E: ${configName}`);
|
|
@@ -3028,7 +3091,7 @@ import {
|
|
|
3028
3091
|
writeFileSync as writeFileSync7
|
|
3029
3092
|
} from "fs";
|
|
3030
3093
|
import { createHash } from "crypto";
|
|
3031
|
-
import { dirname as dirname5, join as
|
|
3094
|
+
import { dirname as dirname5, join as join5, relative as relative2, sep } from "path";
|
|
3032
3095
|
var MANIFEST_FILE = "manifest.json";
|
|
3033
3096
|
function normalizeProjectIdForPath(projectId) {
|
|
3034
3097
|
const id = projectId.trim();
|
|
@@ -3042,11 +3105,11 @@ function normalizeProjectIdForPath(projectId) {
|
|
|
3042
3105
|
}
|
|
3043
3106
|
function projectDocumentsDir(apmRoot, projectId) {
|
|
3044
3107
|
const id = normalizeProjectIdForPath(projectId);
|
|
3045
|
-
return
|
|
3108
|
+
return join5(apmRoot ?? workspaceApmDir(), "project", id);
|
|
3046
3109
|
}
|
|
3047
3110
|
function projectDocumentLocalPath(apmRoot, projectId, documentPath) {
|
|
3048
3111
|
const normalized = normalizeLocalDocumentPath(documentPath);
|
|
3049
|
-
return
|
|
3112
|
+
return join5(
|
|
3050
3113
|
projectDocumentsDir(apmRoot, projectId),
|
|
3051
3114
|
...normalized.split("/")
|
|
3052
3115
|
);
|
|
@@ -3066,7 +3129,7 @@ function hashLocalFileContent(content) {
|
|
|
3066
3129
|
return createHash("sha256").update(content, "utf8").digest("hex");
|
|
3067
3130
|
}
|
|
3068
3131
|
function readLocalManifest(apmRoot, projectId) {
|
|
3069
|
-
const manifestPath3 =
|
|
3132
|
+
const manifestPath3 = join5(
|
|
3070
3133
|
projectDocumentsDir(apmRoot, projectId),
|
|
3071
3134
|
MANIFEST_FILE
|
|
3072
3135
|
);
|
|
@@ -3089,7 +3152,7 @@ function listLocalDocumentPaths(apmRoot, projectId) {
|
|
|
3089
3152
|
const paths = [];
|
|
3090
3153
|
const walk = (dir) => {
|
|
3091
3154
|
for (const entry of readdirSync3(dir, { withFileTypes: true })) {
|
|
3092
|
-
const abs =
|
|
3155
|
+
const abs = join5(dir, entry.name);
|
|
3093
3156
|
if (entry.isDirectory()) {
|
|
3094
3157
|
walk(abs);
|
|
3095
3158
|
continue;
|
|
@@ -3223,7 +3286,7 @@ ${diagnostic ?? ""}`);
|
|
|
3223
3286
|
}
|
|
3224
3287
|
}
|
|
3225
3288
|
writeFileSync7(
|
|
3226
|
-
toFsPath(
|
|
3289
|
+
toFsPath(join5(docsDir, MANIFEST_FILE)),
|
|
3227
3290
|
`${JSON.stringify(remoteManifest, null, 2)}
|
|
3228
3291
|
`,
|
|
3229
3292
|
"utf8"
|
|
@@ -3305,7 +3368,7 @@ async function ensureWorkspaceInitialized(workdir, options) {
|
|
|
3305
3368
|
await syncProjectDocumentsPull(workdir, apmDir);
|
|
3306
3369
|
const trimmedName = options?.name?.trim();
|
|
3307
3370
|
if (trimmedName) {
|
|
3308
|
-
const apmConfigPath = toFsPath(
|
|
3371
|
+
const apmConfigPath = toFsPath(join6(apmDir, "apm.config.json"));
|
|
3309
3372
|
const config = readFileSync7(apmConfigPath, "utf8");
|
|
3310
3373
|
const configJson = JSON.parse(config);
|
|
3311
3374
|
configJson.name = trimmedName;
|
|
@@ -3570,12 +3633,12 @@ async function ensureWebIdePullRequests(cfg, taskId, workdir) {
|
|
|
3570
3633
|
|
|
3571
3634
|
// src/version.ts
|
|
3572
3635
|
import { readFileSync as readFileSync8 } from "fs";
|
|
3573
|
-
import { dirname as dirname6, join as
|
|
3636
|
+
import { dirname as dirname6, join as join7 } from "path";
|
|
3574
3637
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3575
3638
|
function readCliVersion() {
|
|
3576
3639
|
try {
|
|
3577
3640
|
const dir = dirname6(fileURLToPath2(import.meta.url));
|
|
3578
|
-
const pkgPath =
|
|
3641
|
+
const pkgPath = join7(dir, "..", "package.json");
|
|
3579
3642
|
const pkg = JSON.parse(readFileSync8(pkgPath, "utf8"));
|
|
3580
3643
|
return pkg.version ?? "0.0.0";
|
|
3581
3644
|
} catch {
|
|
@@ -3584,24 +3647,24 @@ function readCliVersion() {
|
|
|
3584
3647
|
}
|
|
3585
3648
|
|
|
3586
3649
|
// src/commands/update-skills.ts
|
|
3587
|
-
import { existsSync as existsSync8, mkdirSync as
|
|
3588
|
-
import { join as
|
|
3650
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync7, statSync as statSync4 } from "fs";
|
|
3651
|
+
import { join as join9 } from "path";
|
|
3589
3652
|
|
|
3590
3653
|
// src/skills-sync.ts
|
|
3591
3654
|
import {
|
|
3592
3655
|
copyFileSync as copyFileSync2,
|
|
3593
3656
|
cpSync,
|
|
3594
3657
|
existsSync as existsSync7,
|
|
3595
|
-
mkdirSync as
|
|
3658
|
+
mkdirSync as mkdirSync6,
|
|
3596
3659
|
readdirSync as readdirSync4,
|
|
3597
3660
|
rmSync as rmSync3,
|
|
3598
3661
|
statSync as statSync3,
|
|
3599
3662
|
writeFileSync as writeFileSync9
|
|
3600
3663
|
} from "fs";
|
|
3601
|
-
import { join as
|
|
3602
|
-
var AGENTS_TEMPLATE_PATH =
|
|
3603
|
-
var BASE_SKILLS_TEMPLATE_DIR =
|
|
3604
|
-
var BASE_RULES_TEMPLATE_DIR =
|
|
3664
|
+
import { join as join8 } from "path";
|
|
3665
|
+
var AGENTS_TEMPLATE_PATH = join8(CLI_TEMPLATE_DIR, "AGENTS.md");
|
|
3666
|
+
var BASE_SKILLS_TEMPLATE_DIR = join8(CLI_TEMPLATE_DIR, "skills");
|
|
3667
|
+
var BASE_RULES_TEMPLATE_DIR = join8(CLI_TEMPLATE_DIR, "rules");
|
|
3605
3668
|
function sanitizeSkillDirName(name) {
|
|
3606
3669
|
const trimmed = name.trim();
|
|
3607
3670
|
if (!trimmed) return "skill";
|
|
@@ -3610,39 +3673,39 @@ function sanitizeSkillDirName(name) {
|
|
|
3610
3673
|
function listBaseSkillDirNames() {
|
|
3611
3674
|
if (!existsSync7(BASE_SKILLS_TEMPLATE_DIR)) return [];
|
|
3612
3675
|
return readdirSync4(BASE_SKILLS_TEMPLATE_DIR).filter((name) => {
|
|
3613
|
-
const path =
|
|
3676
|
+
const path = join8(BASE_SKILLS_TEMPLATE_DIR, name);
|
|
3614
3677
|
return statSync3(path).isDirectory();
|
|
3615
3678
|
});
|
|
3616
3679
|
}
|
|
3617
3680
|
function syncAgentsGuide(apmDir) {
|
|
3618
3681
|
if (!existsSync7(AGENTS_TEMPLATE_PATH)) return false;
|
|
3619
|
-
|
|
3620
|
-
copyFileSync2(AGENTS_TEMPLATE_PATH,
|
|
3682
|
+
mkdirSync6(apmDir, { recursive: true });
|
|
3683
|
+
copyFileSync2(AGENTS_TEMPLATE_PATH, join8(apmDir, "AGENTS.md"));
|
|
3621
3684
|
return true;
|
|
3622
3685
|
}
|
|
3623
3686
|
function listBaseRuleFileNames() {
|
|
3624
3687
|
if (!existsSync7(BASE_RULES_TEMPLATE_DIR)) return [];
|
|
3625
3688
|
return readdirSync4(BASE_RULES_TEMPLATE_DIR).filter((name) => {
|
|
3626
|
-
const path =
|
|
3689
|
+
const path = join8(BASE_RULES_TEMPLATE_DIR, name);
|
|
3627
3690
|
return statSync3(path).isFile();
|
|
3628
3691
|
});
|
|
3629
3692
|
}
|
|
3630
3693
|
function syncBaseRules(rulesDir) {
|
|
3631
|
-
|
|
3694
|
+
mkdirSync6(rulesDir, { recursive: true });
|
|
3632
3695
|
const names = listBaseRuleFileNames();
|
|
3633
3696
|
for (const name of names) {
|
|
3634
|
-
const src =
|
|
3635
|
-
const dest =
|
|
3697
|
+
const src = join8(BASE_RULES_TEMPLATE_DIR, name);
|
|
3698
|
+
const dest = join8(rulesDir, name);
|
|
3636
3699
|
copyFileSync2(src, dest);
|
|
3637
3700
|
}
|
|
3638
3701
|
return names;
|
|
3639
3702
|
}
|
|
3640
3703
|
function syncBaseSkills(skillsDir) {
|
|
3641
|
-
|
|
3704
|
+
mkdirSync6(skillsDir, { recursive: true });
|
|
3642
3705
|
const names = listBaseSkillDirNames();
|
|
3643
3706
|
for (const name of names) {
|
|
3644
|
-
const src =
|
|
3645
|
-
const dest =
|
|
3707
|
+
const src = join8(BASE_SKILLS_TEMPLATE_DIR, name);
|
|
3708
|
+
const dest = join8(skillsDir, name);
|
|
3646
3709
|
cpSync(src, dest, { recursive: true, force: true });
|
|
3647
3710
|
}
|
|
3648
3711
|
return names;
|
|
@@ -3659,15 +3722,15 @@ function syncSupplementarySkills(skillsDir, list) {
|
|
|
3659
3722
|
skipped.push(dirName);
|
|
3660
3723
|
continue;
|
|
3661
3724
|
}
|
|
3662
|
-
const skillDir =
|
|
3663
|
-
|
|
3664
|
-
writeFileSync9(
|
|
3725
|
+
const skillDir = join8(skillsDir, dirName);
|
|
3726
|
+
mkdirSync6(skillDir, { recursive: true });
|
|
3727
|
+
writeFileSync9(join8(skillDir, "SKILL.md"), skill.content ?? "", "utf8");
|
|
3665
3728
|
written.push(dirName);
|
|
3666
3729
|
}
|
|
3667
3730
|
const removed = [];
|
|
3668
3731
|
if (!existsSync7(skillsDir)) return { written, skipped, removed };
|
|
3669
3732
|
for (const entry of readdirSync4(skillsDir)) {
|
|
3670
|
-
const full =
|
|
3733
|
+
const full = join8(skillsDir, entry);
|
|
3671
3734
|
if (!statSync3(full).isDirectory()) continue;
|
|
3672
3735
|
if (baseNames.has(entry)) continue;
|
|
3673
3736
|
if (apiDirNames.has(entry)) continue;
|
|
@@ -3693,13 +3756,13 @@ async function syncWorkspaceSkills(cfg, workdir) {
|
|
|
3693
3756
|
if (syncAgentsGuide(apmDir)) {
|
|
3694
3757
|
console.log("[apm] \u5DF2\u540C\u6B65 APM \u6307\u5357: .apm/AGENTS.md");
|
|
3695
3758
|
}
|
|
3696
|
-
const rulesDir =
|
|
3759
|
+
const rulesDir = join9(apmDir, "rules");
|
|
3697
3760
|
const ruleNames = syncBaseRules(rulesDir);
|
|
3698
3761
|
for (const name of ruleNames) {
|
|
3699
3762
|
console.log(`[apm] \u5DF2\u540C\u6B65\u57FA\u7840\u89C4\u5219: rules/${name}`);
|
|
3700
3763
|
}
|
|
3701
|
-
const skillsDir =
|
|
3702
|
-
|
|
3764
|
+
const skillsDir = join9(apmDir, "skills");
|
|
3765
|
+
mkdirSync7(toFsPath(skillsDir), { recursive: true });
|
|
3703
3766
|
const baseNames = syncBaseSkills(skillsDir);
|
|
3704
3767
|
for (const name of baseNames) {
|
|
3705
3768
|
console.log(`[apm] \u5DF2\u540C\u6B65\u57FA\u7840\u6280\u80FD: skills/${name}/`);
|
|
@@ -3726,7 +3789,7 @@ async function syncWorkspaceSkills(cfg, workdir) {
|
|
|
3726
3789
|
|
|
3727
3790
|
// src/commands/sync-session-attachments.ts
|
|
3728
3791
|
import { existsSync as existsSync9, readFileSync as readFileSync9, writeFileSync as writeFileSync10 } from "fs";
|
|
3729
|
-
import { join as
|
|
3792
|
+
import { join as join10 } from "path";
|
|
3730
3793
|
var MANIFEST_FILE2 = ".sync-manifest.json";
|
|
3731
3794
|
async function downloadAttachment(cfg, attachmentId) {
|
|
3732
3795
|
const base = cfg.baseUrl.trim().replace(/\/+$/, "");
|
|
@@ -3742,7 +3805,7 @@ async function downloadAttachment(cfg, attachmentId) {
|
|
|
3742
3805
|
return Buffer.from(await res.arrayBuffer());
|
|
3743
3806
|
}
|
|
3744
3807
|
function loadManifest(dir) {
|
|
3745
|
-
const path =
|
|
3808
|
+
const path = join10(dir, MANIFEST_FILE2);
|
|
3746
3809
|
if (!existsSync9(path)) {
|
|
3747
3810
|
return { version: 1, attachments: {} };
|
|
3748
3811
|
}
|
|
@@ -3759,7 +3822,7 @@ function loadManifest(dir) {
|
|
|
3759
3822
|
}
|
|
3760
3823
|
function saveManifest(dir, manifest) {
|
|
3761
3824
|
writeFileSync10(
|
|
3762
|
-
|
|
3825
|
+
join10(dir, MANIFEST_FILE2),
|
|
3763
3826
|
`${JSON.stringify(manifest, null, 2)}
|
|
3764
3827
|
`,
|
|
3765
3828
|
"utf8"
|
|
@@ -3781,7 +3844,7 @@ async function syncAttachmentsToDirectory(cfg, attachments, dir, logLabel) {
|
|
|
3781
3844
|
const nextManifest = { version: 1, attachments: {} };
|
|
3782
3845
|
const names = [];
|
|
3783
3846
|
for (const item of attachments) {
|
|
3784
|
-
const dest =
|
|
3847
|
+
const dest = join10(dir, item.name);
|
|
3785
3848
|
const entry = manifest.attachments[item.id];
|
|
3786
3849
|
const createdAt = item.createdAt ?? "";
|
|
3787
3850
|
names.push(item.name);
|
|
@@ -3813,10 +3876,10 @@ async function syncWebIdeAttachments(cfg, taskId, workdir, attachments) {
|
|
|
3813
3876
|
|
|
3814
3877
|
// src/commands/connect/cli-version-sync.ts
|
|
3815
3878
|
import { existsSync as existsSync10, readFileSync as readFileSync10, writeFileSync as writeFileSync11 } from "fs";
|
|
3816
|
-
import { join as
|
|
3879
|
+
import { join as join11 } from "path";
|
|
3817
3880
|
var CLI_VERSION_FILE = ".cli-version.json";
|
|
3818
3881
|
function manifestPath2(apmDir) {
|
|
3819
|
-
return
|
|
3882
|
+
return join11(apmDir, CLI_VERSION_FILE);
|
|
3820
3883
|
}
|
|
3821
3884
|
function loadManifest2(apmDir) {
|
|
3822
3885
|
const path = toFsPath(manifestPath2(apmDir));
|
|
@@ -3873,6 +3936,13 @@ var WEBIDE_CODE_CHANGE_ACTIONS = /* @__PURE__ */ new Set([
|
|
|
3873
3936
|
function shouldCommitAfterWebIdeMessage(action) {
|
|
3874
3937
|
return WEBIDE_CODE_CHANGE_ACTIONS.has(action);
|
|
3875
3938
|
}
|
|
3939
|
+
function syncLocalTaskStatus(workdir, taskId, msg, status) {
|
|
3940
|
+
syncWebIdeTaskState(workdir, taskId, {
|
|
3941
|
+
messageId: msg.messageId,
|
|
3942
|
+
action: msg.action,
|
|
3943
|
+
status
|
|
3944
|
+
});
|
|
3945
|
+
}
|
|
3876
3946
|
async function updateStatus(cfg, messageId, status) {
|
|
3877
3947
|
const api = createApmApiClient(cfg);
|
|
3878
3948
|
await api.cli.webideUpdateMessageStatus({ id: messageId, status });
|
|
@@ -3894,6 +3964,7 @@ async function handleWebIdeInboundMessage(cfg, msg, signal, options) {
|
|
|
3894
3964
|
`[apm] webide-message action=${msg.action} taskId=${taskId} messageId=${messageId}`
|
|
3895
3965
|
);
|
|
3896
3966
|
await updateStatus(cfg, messageId, "TYPING");
|
|
3967
|
+
syncLocalTaskStatus(workdir, taskId, msg, "TYPING");
|
|
3897
3968
|
const eventSession = new EventSession(msg.content);
|
|
3898
3969
|
const prepAgentId = loadWebIdeAgentId(workdir, taskId) ?? "webide-cli-prep";
|
|
3899
3970
|
const logSyncRef = {
|
|
@@ -4101,6 +4172,8 @@ async function handleWebIdeInboundMessage(cfg, msg, signal, options) {
|
|
|
4101
4172
|
}),
|
|
4102
4173
|
enableWebIdePlanTools: true,
|
|
4103
4174
|
enableSandbox: false,
|
|
4175
|
+
skipSessionAgentRegistry: true,
|
|
4176
|
+
onInvalidatePersistedAgentId: () => clearWebIdeAgentId(workdir, taskId),
|
|
4104
4177
|
taskId,
|
|
4105
4178
|
terminalRpc: options?.terminalRpc,
|
|
4106
4179
|
createRemoteLogSync: (agentId) => {
|
|
@@ -4151,6 +4224,7 @@ async function handleWebIdeInboundMessage(cfg, msg, signal, options) {
|
|
|
4151
4224
|
tokenUsage
|
|
4152
4225
|
);
|
|
4153
4226
|
await setError(cfg, messageId, detail);
|
|
4227
|
+
syncLocalTaskStatus(workdir, taskId, msg, "FAILED");
|
|
4154
4228
|
return;
|
|
4155
4229
|
}
|
|
4156
4230
|
if (outcome.status === "cancelled" || signal.aborted) {
|
|
@@ -4161,6 +4235,7 @@ async function handleWebIdeInboundMessage(cfg, msg, signal, options) {
|
|
|
4161
4235
|
tokenUsage
|
|
4162
4236
|
);
|
|
4163
4237
|
await updateStatus(cfg, messageId, "CANCELLED");
|
|
4238
|
+
syncLocalTaskStatus(workdir, taskId, msg, "CANCELLED");
|
|
4164
4239
|
return;
|
|
4165
4240
|
}
|
|
4166
4241
|
const fallback = resolveMessageReplyFallback({
|
|
@@ -4260,6 +4335,7 @@ async function handleWebIdeInboundMessage(cfg, msg, signal, options) {
|
|
|
4260
4335
|
tokenUsage
|
|
4261
4336
|
);
|
|
4262
4337
|
await updateStatus(cfg, messageId, "SUCCESS");
|
|
4338
|
+
syncLocalTaskStatus(workdir, taskId, msg, "SUCCESS");
|
|
4263
4339
|
console.log(
|
|
4264
4340
|
`[apm] webide-message \u5B8C\u6210 action=${msg.action} messageId=${messageId} agentId=${outcome.agentId}`
|
|
4265
4341
|
);
|
|
@@ -4287,6 +4363,7 @@ async function handleWebIdeInboundMessage(cfg, msg, signal, options) {
|
|
|
4287
4363
|
statusErr instanceof Error ? statusErr.message : statusErr
|
|
4288
4364
|
);
|
|
4289
4365
|
}
|
|
4366
|
+
syncLocalTaskStatus(workdir, taskId, msg, "FAILED");
|
|
4290
4367
|
}
|
|
4291
4368
|
}
|
|
4292
4369
|
|