ai-project-manage-cli 8.1.10 → 8.1.12

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 CHANGED
@@ -1203,6 +1203,25 @@ function validateCancel(o) {
1203
1203
  data: { type: "cancel", messageId: o.messageId.trim() }
1204
1204
  };
1205
1205
  }
1206
+ function validateSteer(o) {
1207
+ if (o.type !== "steer") {
1208
+ return { ok: false, reason: "\u671F\u671B steer" };
1209
+ }
1210
+ if (!nonEmptyString(o.messageId)) {
1211
+ return { ok: false, reason: "steer \u7F3A\u5C11 messageId" };
1212
+ }
1213
+ if (!nonEmptyString(o.text)) {
1214
+ return { ok: false, reason: "steer \u7F3A\u5C11 text" };
1215
+ }
1216
+ return {
1217
+ ok: true,
1218
+ data: {
1219
+ type: "steer",
1220
+ messageId: o.messageId.trim(),
1221
+ text: o.text.trim()
1222
+ }
1223
+ };
1224
+ }
1206
1225
  function validateWebIdeStopTerminals(o) {
1207
1226
  if (o.type !== "webide-stop-terminals") {
1208
1227
  return { ok: false, reason: "\u671F\u671B webide-stop-terminals" };
@@ -1319,7 +1338,7 @@ function validateAgentWsMessage(value, kind) {
1319
1338
  }
1320
1339
  const o = value;
1321
1340
  const type = o.type;
1322
- if (type !== "heartbeat" && type !== "webide-message" && type !== "cancel" && type !== "webide-start-project" && type !== "webide-stop-terminals" && type !== "webide-package") {
1341
+ if (type !== "heartbeat" && type !== "webide-message" && type !== "cancel" && type !== "steer" && type !== "webide-start-project" && type !== "webide-stop-terminals" && type !== "webide-package") {
1323
1342
  return { ok: false, reason: `\u672A\u77E5 type: ${String(type)}` };
1324
1343
  }
1325
1344
  if (kind === "heartbeat" || type === "heartbeat") {
@@ -1328,6 +1347,9 @@ function validateAgentWsMessage(value, kind) {
1328
1347
  if (type === "cancel") {
1329
1348
  return validateCancel(o);
1330
1349
  }
1350
+ if (type === "steer") {
1351
+ return validateSteer(o);
1352
+ }
1331
1353
  if (type === "webide-start-project") {
1332
1354
  return validateWebIdeStartProjectPush(o);
1333
1355
  }
@@ -1347,6 +1369,29 @@ function handleCancelAction(payload, ctx) {
1347
1369
  ctx.activeRuns.get(messageId)?.abort();
1348
1370
  }
1349
1371
 
1372
+ // src/commands/connect/actions/steer.ts
1373
+ function registerRunSteer(ctx, messageId, target) {
1374
+ const send = (text) => target.steer(messageId, text);
1375
+ ctx.steerRuns.set(messageId, send);
1376
+ const queued = ctx.pendingSteers.get(messageId);
1377
+ if (!queued) return;
1378
+ ctx.pendingSteers.delete(messageId);
1379
+ send(queued);
1380
+ }
1381
+ function unregisterRunSteer(ctx, messageId) {
1382
+ ctx.steerRuns.delete(messageId);
1383
+ ctx.pendingSteers.delete(messageId);
1384
+ }
1385
+ function handleSteerAction(payload, ctx) {
1386
+ const send = ctx.steerRuns.get(payload.messageId);
1387
+ if (!send) {
1388
+ ctx.pendingSteers.set(payload.messageId, payload.text);
1389
+ console.log(`[apm] steer \u5DF2\u6392\u961F messageId=${payload.messageId}`);
1390
+ return;
1391
+ }
1392
+ send(payload.text);
1393
+ }
1394
+
1350
1395
  // src/commands/connect/core/worker/worker.ts
1351
1396
  import { dirname as dirname3, join as join7 } from "path";
1352
1397
  import { fileURLToPath as fileURLToPath2 } from "url";
@@ -1473,6 +1518,9 @@ var ActionWorker = class {
1473
1518
  cancel(msg_id) {
1474
1519
  this.worker.postMessage({ type: "cancel", messageId: msg_id });
1475
1520
  }
1521
+ steer(msg_id, text) {
1522
+ this.worker.postMessage({ type: "steer", messageId: msg_id, text });
1523
+ }
1476
1524
  get done() {
1477
1525
  return this.promise;
1478
1526
  }
@@ -1512,6 +1560,7 @@ function handleWebIdeMessageAction(payload, ctx) {
1512
1560
  }
1513
1561
  const task = (async () => {
1514
1562
  const handle = new ActionWorker(payload);
1563
+ registerRunSteer(ctx, payload.messageId, handle);
1515
1564
  const onAbort = () => handle.cancel(payload.messageId);
1516
1565
  perMessageController.signal.addEventListener("abort", onAbort, {
1517
1566
  once: true
@@ -1520,6 +1569,7 @@ function handleWebIdeMessageAction(payload, ctx) {
1520
1569
  await handle.done;
1521
1570
  } finally {
1522
1571
  perMessageController.signal.removeEventListener("abort", onAbort);
1572
+ unregisterRunSteer(ctx, payload.messageId);
1523
1573
  ctx.activeRuns.delete(payload.messageId);
1524
1574
  }
1525
1575
  })();
@@ -1552,6 +1602,7 @@ function handleStartProjectAction(payload, ctx) {
1552
1602
  }
1553
1603
  const task = (async () => {
1554
1604
  const handle = new ActionWorker(payload);
1605
+ registerRunSteer(ctx, payload.messageId, handle);
1555
1606
  const onAbort = () => handle.cancel(payload.messageId);
1556
1607
  perMessageController.signal.addEventListener("abort", onAbort, {
1557
1608
  once: true
@@ -1560,6 +1611,7 @@ function handleStartProjectAction(payload, ctx) {
1560
1611
  await handle.done;
1561
1612
  } finally {
1562
1613
  perMessageController.signal.removeEventListener("abort", onAbort);
1614
+ unregisterRunSteer(ctx, payload.messageId);
1563
1615
  ctx.activeRuns.delete(payload.messageId);
1564
1616
  }
1565
1617
  })();
@@ -1688,6 +1740,7 @@ function handleWebIdePackageAction(payload, ctx) {
1688
1740
  }
1689
1741
  const task = (async () => {
1690
1742
  const handle = new ActionWorker(payload);
1743
+ registerRunSteer(ctx, payload.messageId, handle);
1691
1744
  const onAbort = () => handle.cancel(payload.messageId);
1692
1745
  perMessageController.signal.addEventListener("abort", onAbort, {
1693
1746
  once: true
@@ -1696,6 +1749,7 @@ function handleWebIdePackageAction(payload, ctx) {
1696
1749
  await handle.done;
1697
1750
  } finally {
1698
1751
  perMessageController.signal.removeEventListener("abort", onAbort);
1752
+ unregisterRunSteer(ctx, payload.messageId);
1699
1753
  ctx.activeRuns.delete(payload.messageId);
1700
1754
  }
1701
1755
  })();
@@ -1710,6 +1764,9 @@ function dispatchConnectAction(payload, ctx) {
1710
1764
  case "cancel":
1711
1765
  handleCancelAction(payload, ctx);
1712
1766
  return;
1767
+ case "steer":
1768
+ handleSteerAction(payload, ctx);
1769
+ return;
1713
1770
  case "webide-message":
1714
1771
  handleWebIdeMessageAction(payload, ctx);
1715
1772
  return;
@@ -1934,6 +1991,8 @@ async function runConnect(options) {
1934
1991
  const activeTasks = /* @__PURE__ */ new Set();
1935
1992
  const activeRuns = /* @__PURE__ */ new Map();
1936
1993
  const pendingCancels = /* @__PURE__ */ new Set();
1994
+ const steerRuns = /* @__PURE__ */ new Map();
1995
+ const pendingSteers = /* @__PURE__ */ new Map();
1937
1996
  let currentConnectionAbort = null;
1938
1997
  const connectCtx = {
1939
1998
  cfg,
@@ -1941,6 +2000,8 @@ async function runConnect(options) {
1941
2000
  activeTasks,
1942
2001
  activeRuns,
1943
2002
  pendingCancels,
2003
+ steerRuns,
2004
+ pendingSteers,
1944
2005
  isShuttingDown: () => shuttingDown
1945
2006
  };
1946
2007
  const drainAndExit = async (code = 0) => {
@@ -1996,6 +1996,14 @@ var MinioClient = class {
1996
1996
  async removeObject(bucket, objectKey) {
1997
1997
  await this.inner.removeObject(bucket, objectKey);
1998
1998
  }
1999
+ async getObjectBuffer(bucket, objectKey) {
2000
+ const stream = await this.inner.getObject(bucket, objectKey);
2001
+ const chunks = [];
2002
+ for await (const chunk of stream) {
2003
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
2004
+ }
2005
+ return Buffer.concat(chunks);
2006
+ }
1999
2007
  };
2000
2008
 
2001
2009
  // src/commands/connect/apm-log-minio.ts
@@ -2460,6 +2468,10 @@ function createPtySessionMcpServers(cfg2) {
2460
2468
  }
2461
2469
 
2462
2470
  // src/commands/connect/remote-local-agent-store.ts
2471
+ var INLINE_CHECKPOINT_MAX_BYTES = 256 * 1024;
2472
+ function checkpointObjectKey(agentId, blobId) {
2473
+ return `cursor-agents/${agentId}/checkpoints/${blobId}`;
2474
+ }
2463
2475
  function asCheckpointRef(value) {
2464
2476
  if (value === void 0) return void 0;
2465
2477
  if (value === null) return null;
@@ -2534,6 +2546,16 @@ function base64ToBytes(dataBase64) {
2534
2546
  }
2535
2547
  function createRemoteLocalAgentStore(cfg2) {
2536
2548
  const api = createApmApiClient(cfg2);
2549
+ let minioCache = null;
2550
+ function getMinio() {
2551
+ if (!minioCache) {
2552
+ minioCache = createApmLogMinioClient(cfg2).then(({ client, bucket }) => ({
2553
+ client,
2554
+ bucket
2555
+ }));
2556
+ }
2557
+ return minioCache;
2558
+ }
2537
2559
  async function upsertAgent(agent) {
2538
2560
  const row = await api.cli.cursorStoreUpsertAgent({
2539
2561
  agentId: agent.agentId,
@@ -2570,13 +2592,44 @@ function createRemoteLocalAgentStore(cfg2) {
2570
2592
  return fromApiRun(row);
2571
2593
  }
2572
2594
  async function putCheckpoint(input) {
2595
+ const createdAt = Date.now();
2596
+ if (input.data.byteLength > INLINE_CHECKPOINT_MAX_BYTES) {
2597
+ const { client, bucket } = await getMinio();
2598
+ const objectKey = checkpointObjectKey(input.agentId, input.blobId);
2599
+ await client.putObject(bucket, objectKey, Buffer.from(input.data), {
2600
+ "Content-Type": "application/octet-stream"
2601
+ });
2602
+ await api.cli.cursorStorePutCheckpoint({
2603
+ agentId: input.agentId,
2604
+ blobId: input.blobId,
2605
+ objectKey,
2606
+ byteSize: input.data.byteLength,
2607
+ createdAt
2608
+ });
2609
+ return;
2610
+ }
2573
2611
  await api.cli.cursorStorePutCheckpoint({
2574
2612
  agentId: input.agentId,
2575
2613
  blobId: input.blobId,
2576
2614
  dataBase64: bytesToBase64(input.data),
2577
2615
  byteSize: input.data.byteLength,
2578
- createdAt: Date.now()
2616
+ createdAt
2617
+ });
2618
+ }
2619
+ async function readCheckpointBytes(input) {
2620
+ const row = await api.cli.cursorStoreGetCheckpoint({
2621
+ agentId: input.agentId,
2622
+ blobId: input.blobId
2579
2623
  });
2624
+ if (!row) return null;
2625
+ if (row.dataBase64) {
2626
+ return base64ToBytes(row.dataBase64);
2627
+ }
2628
+ const objectKey = row.objectKey?.trim();
2629
+ if (!objectKey) return null;
2630
+ const { client, bucket } = await getMinio();
2631
+ const buf = await client.getObjectBuffer(bucket, objectKey);
2632
+ return new Uint8Array(buf);
2580
2633
  }
2581
2634
  return {
2582
2635
  agents: {
@@ -2732,12 +2785,7 @@ function createRemoteLocalAgentStore(cfg2) {
2732
2785
  },
2733
2786
  checkpoints: {
2734
2787
  async get(input) {
2735
- const row = await api.cli.cursorStoreGetCheckpoint({
2736
- agentId: input.agentId,
2737
- blobId: input.blobId
2738
- });
2739
- if (!row?.dataBase64) return null;
2740
- return base64ToBytes(row.dataBase64);
2788
+ return readCheckpointBytes(input);
2741
2789
  },
2742
2790
  async create(input) {
2743
2791
  await putCheckpoint(input);
@@ -2783,6 +2831,30 @@ function createRemoteLocalAgentStore(cfg2) {
2783
2831
  };
2784
2832
  }
2785
2833
 
2834
+ // src/commands/connect/core/worker/run-steer.ts
2835
+ var impl = null;
2836
+ var pending = null;
2837
+ function bindRunSteer(fn) {
2838
+ impl = fn;
2839
+ if (!pending) return;
2840
+ const text = pending;
2841
+ pending = null;
2842
+ void fn(text);
2843
+ }
2844
+ function clearRunSteer() {
2845
+ impl = null;
2846
+ pending = null;
2847
+ }
2848
+ function deliverRunSteer(text) {
2849
+ const trimmed = text.trim();
2850
+ if (!trimmed) return;
2851
+ if (impl) {
2852
+ void impl(trimmed);
2853
+ return;
2854
+ }
2855
+ pending = trimmed;
2856
+ }
2857
+
2786
2858
  // src/commands/connect/cursor-agent.ts
2787
2859
  var noopRemoteLogSync = {
2788
2860
  schedule(_session) {
@@ -2914,6 +2986,22 @@ async function runCursorAgent(cfg2, ctx, options) {
2914
2986
  });
2915
2987
  activeRun = run;
2916
2988
  console.log(`[apm] Cursor run id=${run.id} agentId=${agent.agentId}`);
2989
+ bindRunSteer(async (text) => {
2990
+ const steer = run.steer;
2991
+ if (!steer) {
2992
+ console.warn(`[apm] \u5F53\u524D run \u4E0D\u652F\u6301 steer runId=${run.id}`);
2993
+ return;
2994
+ }
2995
+ try {
2996
+ const outcome = await steer(text);
2997
+ console.log(`[apm] steer outcome=${outcome} runId=${run.id}`);
2998
+ } catch (err) {
2999
+ console.error(
3000
+ `[apm] steer \u5931\u8D25 runId=${run.id}:`,
3001
+ err instanceof Error ? err.message : err
3002
+ );
3003
+ }
3004
+ });
2917
3005
  await options.onRunStarted?.({ agentId: agent.agentId, runId: run.id });
2918
3006
  let lastRunErrorStatus;
2919
3007
  for await (const event of run.stream()) {
@@ -2999,6 +3087,7 @@ async function runCursorAgent(cfg2, ctx, options) {
2999
3087
  }
3000
3088
  throw err;
3001
3089
  } finally {
3090
+ clearRunSteer();
3002
3091
  signal?.removeEventListener("abort", abortRun);
3003
3092
  await agent[Symbol.asyncDispose]();
3004
3093
  }
@@ -5062,6 +5151,11 @@ async function handleWebIdeInboundMessage(cfg2, msg2, signal) {
5062
5151
  const savedAgentId = startLocalServices || useNewAgent ? void 0 : designAction ? loadWebIdeDesignAgentId(workdir, taskId) : loadWebIdeAgentId(workdir, taskId);
5063
5152
  const promptPayload = toolNames.includes("MysqlExecute") ? parseWebIdePromptPayload(msg2.content) : null;
5064
5153
  const sqlExecutionId = toolNames.includes("MysqlExecute") && typeof promptPayload?.executionId === "string" ? promptPayload.executionId.trim() : void 0;
5154
+ if (toolNames.includes("MysqlExecute") && !sqlExecutionId) {
5155
+ console.warn(
5156
+ "[apm] \u5DE5\u5177\u540D\u5355\u542B MysqlExecute\uFF0C\u4F46 prompt \u672B\u5C3E\u6CA1\u6709 executionId\uFF0C\u672C\u8F6E\u4E0D\u4F1A\u6302\u8F7D\u8BE5\u5DE5\u5177"
5157
+ );
5158
+ }
5065
5159
  const persistAgentId = (agentId) => {
5066
5160
  if (startLocalServices) return;
5067
5161
  if (designAction) {
@@ -5171,7 +5265,7 @@ ${assumptionAnswersText}` : msg2.content,
5171
5265
  detail,
5172
5266
  tokenUsage
5173
5267
  );
5174
- if (sqlExecutionId) {
5268
+ if (sqlExecutionId && msg2.action !== "request-bugfix") {
5175
5269
  try {
5176
5270
  await api.cli.webideFinalizeSqlExecution({
5177
5271
  executionId: sqlExecutionId,
@@ -5196,7 +5290,7 @@ ${assumptionAnswersText}` : msg2.content,
5196
5290
  "\u5DF2\u53D6\u6D88",
5197
5291
  tokenUsage
5198
5292
  );
5199
- if (sqlExecutionId) {
5293
+ if (sqlExecutionId && msg2.action !== "request-bugfix") {
5200
5294
  try {
5201
5295
  await api.cli.webideFinalizeSqlExecution({
5202
5296
  executionId: sqlExecutionId,
@@ -5417,11 +5511,19 @@ var cfg = tryReadApmConfig();
5417
5511
  var { msg } = workerData;
5418
5512
  if (!cfg || !msg) throw new Error("worker-script \u7F3A\u5C11 workerData");
5419
5513
  var controller = new AbortController();
5420
- port.on("message", (raw) => {
5421
- if (raw?.type === "cancel" && raw.messageId === msg.messageId) {
5422
- controller.abort();
5514
+ port.on(
5515
+ "message",
5516
+ (raw) => {
5517
+ if (raw?.messageId !== msg.messageId) return;
5518
+ if (raw.type === "cancel") {
5519
+ controller.abort();
5520
+ return;
5521
+ }
5522
+ if (raw.type === "steer" && typeof raw.text === "string") {
5523
+ deliverRunSteer(raw.text);
5524
+ }
5423
5525
  }
5424
- });
5526
+ );
5425
5527
  var reply = (body) => port.postMessage(body);
5426
5528
  try {
5427
5529
  await dispatchWorkerJob(cfg, msg, controller.signal);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-project-manage-cli",
3
- "version": "8.1.10",
3
+ "version": "8.1.12",
4
4
  "description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
5
5
  "type": "module",
6
6
  "private": false,
@@ -31,7 +31,7 @@
31
31
  "@bufbuild/protobuf": "1.10.0",
32
32
  "@connectrpc/connect": "~1.7.0",
33
33
  "@connectrpc/connect-node": "~1.7.0",
34
- "@cursor/sdk": "^1.0.22",
34
+ "@cursor/sdk": "^1.0.32",
35
35
  "commander": "~14.0.3",
36
36
  "listpage-http": "~0.0.318",
37
37
  "minio": "~8.0.7",