ai-project-manage-cli 3.0.10 → 3.0.11

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.
Files changed (2) hide show
  1. package/dist/index.js +86 -30
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -231,6 +231,8 @@ import { execSync } from "child_process";
231
231
  import { randomUUID } from "crypto";
232
232
  import WebSocket from "ws";
233
233
  import { Agent } from "@cursor/sdk";
234
+ import { appendFileSync } from "fs";
235
+ import { resolve as resolve2 } from "path";
234
236
  function runConnect(opts) {
235
237
  void (async () => {
236
238
  const cfg = await ensureApmConfig();
@@ -291,50 +293,94 @@ function runConnect(opts) {
291
293
  requirementId: payload.requirementId,
292
294
  status: "WORKING"
293
295
  });
296
+ let IN_PROGRESS = false;
297
+ const events = [];
298
+ let data2 = {};
294
299
  const run = await agent.send(payload.prompt);
295
300
  for await (const event of run.stream()) {
296
- if (event.type === "system") {
297
- console.log("[Ready]", JSON.stringify(event));
301
+ if (!IN_PROGRESS) {
298
302
  await api.cliRequirements.updateTaskStatus({
299
303
  taskId: payload.taskId,
300
304
  requirementId: payload.requirementId,
301
305
  status: "IN_PROGRESS"
302
306
  });
307
+ IN_PROGRESS = true;
303
308
  }
304
- if (event.type === "user") {
305
- console.log(
306
- `[Input]`,
307
- JSON.stringify(event.message.content[0].text)
308
- );
309
- }
309
+ data2 = {};
310
310
  if (event.type === "assistant") {
311
- console.log(`[Output]`, JSON.stringify(event.message.content));
311
+ const output = event.message.content[0].text;
312
+ console.log(`[Output]`, output);
313
+ if (data2.type && data2.type !== "output") {
314
+ events.push(data2);
315
+ data2 = {};
316
+ } else {
317
+ data2.type = "output";
318
+ if (!data2.content) {
319
+ data2.content = "";
320
+ }
321
+ data2.content += output;
322
+ }
312
323
  }
313
324
  if (event.type === "thinking") {
314
- console.log(`[Thinking]`, JSON.stringify(event.text));
325
+ const thinking = event.text;
326
+ console.log(`[Thinking]`, thinking);
327
+ if (data2.type && data2.type !== "thinking") {
328
+ events.push(data2);
329
+ data2 = {};
330
+ } else {
331
+ data2.type = "thinking";
332
+ if (!data2.content) {
333
+ data2.content = "";
334
+ }
335
+ data2.content += thinking;
336
+ }
315
337
  }
316
338
  if (event.type === "tool_call") {
317
- if (event.result) {
318
- console.log(
319
- `[ToolCall(${event.call_id}) Result]`,
320
- JSON.stringify(event.result)
321
- );
339
+ if (event.status === "completed" || event.status === "error") {
340
+ console.log(`[ToolCall(${event.call_id}) Result]`);
341
+ console.log(JSON.stringify(event.args));
342
+ console.log(JSON.stringify(event.result, null, 2));
343
+ console.log("---------------\u8C03\u7528\u5B8C\u6210-----------------");
344
+ if (data2.type && data2.type !== "tool_call") {
345
+ events.push(data2);
346
+ data2 = {};
347
+ } else {
348
+ data2.type = "tool_call";
349
+ data2.call_id = event.call_id;
350
+ data2.args = event.args;
351
+ data2.result = event.result;
352
+ data2.status = event.status;
353
+ }
322
354
  }
323
- console.log(
324
- `[ToolCall(${event.call_id}) Args]`,
325
- JSON.stringify(event.args)
326
- );
327
355
  }
328
356
  if (event.type === "task") {
329
357
  console.log(`[Task:${event.status}]`);
330
358
  console.log("--------------------------------");
331
359
  console.log(event.text || "\u65E0");
332
360
  console.log("--------------------------------");
361
+ if (data2.type && data2.type !== "task") {
362
+ events.push(data2);
363
+ data2 = {};
364
+ } else {
365
+ data2.type = "task";
366
+ data2.status = event.status;
367
+ data2.text = event.text;
368
+ }
333
369
  }
334
370
  if (event.type === "request") {
335
371
  console.log(JSON.stringify(event, null, 2));
372
+ if (data2.type && data2.type !== "request") {
373
+ events.push(data2);
374
+ data2 = {};
375
+ } else {
376
+ data2 = event;
377
+ }
336
378
  }
337
379
  }
380
+ if (data2.type) {
381
+ events.push(data2);
382
+ data2 = {};
383
+ }
338
384
  await api.cliRequirements.updateTaskStatus({
339
385
  taskId: payload.taskId,
340
386
  requirementId: payload.requirementId,
@@ -344,6 +390,16 @@ function runConnect(opts) {
344
390
  requirementId: payload.requirementId,
345
391
  status: "IDLE"
346
392
  });
393
+ console.log("[Done]");
394
+ const sessionsDir = resolve2(
395
+ payload.cwd,
396
+ `.apm/workitems/${payload.requirementId}/sessions`
397
+ );
398
+ ensureDirExists(sessionsDir);
399
+ const sessionFile = resolve2(sessionsDir, `${run.agentId}.md`);
400
+ for (const event of events) {
401
+ appendFileSync(sessionFile, JSON.stringify(event, null, 2) + "\n=====================================================\n");
402
+ }
347
403
  } catch {
348
404
  console.error("[apm] \u65E0\u6CD5\u89E3\u6790 WebSocket \u6D88\u606F:", text);
349
405
  }
@@ -420,13 +476,13 @@ async function runLogin(opts) {
420
476
 
421
477
  // src/commands/branch.ts
422
478
  import { execFile } from "child_process";
423
- import { resolve as resolve2 } from "path";
479
+ import { resolve as resolve3 } from "path";
424
480
  import { promisify } from "util";
425
481
  var execFileAsync = promisify(execFile);
426
482
  async function fetchBaselineBranchFromApi(requirementId, cwd) {
427
483
  const cfg = await ensureLoggedConfig();
428
484
  const api = createApmApiClient(cfg);
429
- const workdirPath = resolve2(cwd);
485
+ const workdirPath = resolve3(cwd);
430
486
  const { baselineBranch } = await api.cliRequirements.branchBaseline({
431
487
  requirementId,
432
488
  workdirPath
@@ -811,11 +867,11 @@ import path5 from "node:path";
811
867
 
812
868
  // src/commands/deploy/lib/apm-config.ts
813
869
  import { existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
814
- import { resolve as resolve3 } from "node:path";
870
+ import { resolve as resolve4 } from "node:path";
815
871
  function loadApmConfig(options) {
816
- const p = resolve3(
872
+ const p = resolve4(
817
873
  process.cwd(),
818
- options?.configPath ?? resolve3(WORKSPACE_APM_DIR, "apm.config.json")
874
+ options?.configPath ?? resolve4(WORKSPACE_APM_DIR, "apm.config.json")
819
875
  );
820
876
  if (!existsSync3(p)) {
821
877
  console.error(`\u672A\u627E\u5230\u914D\u7F6E\u6587\u4EF6\uFF1A${p}`);
@@ -1059,17 +1115,17 @@ var DockerodeClient = class {
1059
1115
  await this.client.getImage(image).remove({ force: true });
1060
1116
  }
1061
1117
  async pullImage(image, auth) {
1062
- const stream = await new Promise((resolve4, reject) => {
1118
+ const stream = await new Promise((resolve5, reject) => {
1063
1119
  const pullOptions = auth ? { authconfig: auth } : void 0;
1064
1120
  this.client.pull(image, pullOptions, (err, output) => {
1065
1121
  if (err || !output) {
1066
1122
  reject(err ?? new Error("docker pull \u8FD4\u56DE\u7A7A\u8F93\u51FA"));
1067
1123
  return;
1068
1124
  }
1069
- resolve4(output);
1125
+ resolve5(output);
1070
1126
  });
1071
1127
  });
1072
- await new Promise((resolve4, reject) => {
1128
+ await new Promise((resolve5, reject) => {
1073
1129
  this.client.modem.followProgress(
1074
1130
  stream,
1075
1131
  (err) => {
@@ -1077,7 +1133,7 @@ var DockerodeClient = class {
1077
1133
  reject(err);
1078
1134
  return;
1079
1135
  }
1080
- resolve4();
1136
+ resolve5();
1081
1137
  },
1082
1138
  () => void 0
1083
1139
  );
@@ -1593,14 +1649,14 @@ var MinioClient = class {
1593
1649
  async deleteObjectsByPrefix(bucket, prefix) {
1594
1650
  const objectsStream = this.inner.listObjectsV2(bucket, prefix, true);
1595
1651
  const keys = [];
1596
- await new Promise((resolve4, reject) => {
1652
+ await new Promise((resolve5, reject) => {
1597
1653
  objectsStream.on("data", (obj) => {
1598
1654
  if (obj.name) {
1599
1655
  keys.push(obj.name);
1600
1656
  }
1601
1657
  });
1602
1658
  objectsStream.on("error", reject);
1603
- objectsStream.on("end", resolve4);
1659
+ objectsStream.on("end", resolve5);
1604
1660
  });
1605
1661
  const chunkSize = 500;
1606
1662
  for (let i = 0; i < keys.length; i += chunkSize) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-project-manage-cli",
3
- "version": "3.0.10",
3
+ "version": "3.0.11",
4
4
  "description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
5
5
  "type": "module",
6
6
  "private": false,