ai-project-manage-cli 3.0.10 → 3.0.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.
Files changed (2) hide show
  1. package/dist/index.js +83 -31
  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,87 @@ 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 !== "assistant") {
314
+ events.push(data2);
315
+ data2 = {};
316
+ }
317
+ data2.type = "output";
318
+ if (!data2.content) {
319
+ data2.content = "";
320
+ }
321
+ data2.content += output;
312
322
  }
313
323
  if (event.type === "thinking") {
314
- console.log(`[Thinking]`, JSON.stringify(event.text));
324
+ const thinking = event.text;
325
+ console.log(`[Thinking]`, thinking);
326
+ if (data2.type && data2.type !== "thinking") {
327
+ events.push(data2);
328
+ data2 = {};
329
+ }
330
+ data2.type = "thinking";
331
+ if (!data2.content) {
332
+ data2.content = "";
333
+ }
334
+ data2.content += thinking;
315
335
  }
316
- if (event.type === "tool_call") {
317
- if (event.result) {
318
- console.log(
319
- `[ToolCall(${event.call_id}) Result]`,
320
- JSON.stringify(event.result)
321
- );
336
+ if (event.type === "tool_call" && (event.status === "completed" || event.status === "error")) {
337
+ console.log(`[ToolCall(${event.call_id}) Result]`);
338
+ console.log(JSON.stringify(event.args));
339
+ console.log(JSON.stringify(event.result, null, 2));
340
+ console.log("---------------\u8C03\u7528\u5B8C\u6210-----------------");
341
+ if (data2.type && data2.type !== "tool_call") {
342
+ events.push(data2);
343
+ data2 = {};
322
344
  }
323
- console.log(
324
- `[ToolCall(${event.call_id}) Args]`,
325
- JSON.stringify(event.args)
326
- );
345
+ data2.type = "tool_call";
346
+ data2.call_id = event.call_id;
347
+ data2.args = event.args;
348
+ data2.result = event.result;
349
+ data2.status = event.status;
327
350
  }
328
351
  if (event.type === "task") {
329
352
  console.log(`[Task:${event.status}]`);
330
353
  console.log("--------------------------------");
331
354
  console.log(event.text || "\u65E0");
332
355
  console.log("--------------------------------");
356
+ if (data2.type && data2.type !== "task") {
357
+ events.push(data2);
358
+ data2 = {};
359
+ }
360
+ data2.type = "task";
361
+ data2.status = event.status;
362
+ data2.text = event.text;
333
363
  }
334
364
  if (event.type === "request") {
335
365
  console.log(JSON.stringify(event, null, 2));
366
+ if (data2.type && data2.type !== "request") {
367
+ events.push(data2);
368
+ data2 = {};
369
+ }
370
+ data2 = event;
336
371
  }
337
372
  }
373
+ if (data2.type) {
374
+ events.push(data2);
375
+ data2 = {};
376
+ }
338
377
  await api.cliRequirements.updateTaskStatus({
339
378
  taskId: payload.taskId,
340
379
  requirementId: payload.requirementId,
@@ -344,6 +383,19 @@ function runConnect(opts) {
344
383
  requirementId: payload.requirementId,
345
384
  status: "IDLE"
346
385
  });
386
+ console.log("[Done]");
387
+ const sessionsDir = resolve2(
388
+ payload.cwd,
389
+ `.apm/workitems/${payload.requirementId}/sessions`
390
+ );
391
+ ensureDirExists(sessionsDir);
392
+ const sessionFile = resolve2(sessionsDir, `${run.agentId}.md`);
393
+ for (const event of events) {
394
+ appendFileSync(
395
+ sessionFile,
396
+ JSON.stringify(event, null, 2) + "\n=====================================================\n"
397
+ );
398
+ }
347
399
  } catch {
348
400
  console.error("[apm] \u65E0\u6CD5\u89E3\u6790 WebSocket \u6D88\u606F:", text);
349
401
  }
@@ -420,13 +472,13 @@ async function runLogin(opts) {
420
472
 
421
473
  // src/commands/branch.ts
422
474
  import { execFile } from "child_process";
423
- import { resolve as resolve2 } from "path";
475
+ import { resolve as resolve3 } from "path";
424
476
  import { promisify } from "util";
425
477
  var execFileAsync = promisify(execFile);
426
478
  async function fetchBaselineBranchFromApi(requirementId, cwd) {
427
479
  const cfg = await ensureLoggedConfig();
428
480
  const api = createApmApiClient(cfg);
429
- const workdirPath = resolve2(cwd);
481
+ const workdirPath = resolve3(cwd);
430
482
  const { baselineBranch } = await api.cliRequirements.branchBaseline({
431
483
  requirementId,
432
484
  workdirPath
@@ -811,11 +863,11 @@ import path5 from "node:path";
811
863
 
812
864
  // src/commands/deploy/lib/apm-config.ts
813
865
  import { existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
814
- import { resolve as resolve3 } from "node:path";
866
+ import { resolve as resolve4 } from "node:path";
815
867
  function loadApmConfig(options) {
816
- const p = resolve3(
868
+ const p = resolve4(
817
869
  process.cwd(),
818
- options?.configPath ?? resolve3(WORKSPACE_APM_DIR, "apm.config.json")
870
+ options?.configPath ?? resolve4(WORKSPACE_APM_DIR, "apm.config.json")
819
871
  );
820
872
  if (!existsSync3(p)) {
821
873
  console.error(`\u672A\u627E\u5230\u914D\u7F6E\u6587\u4EF6\uFF1A${p}`);
@@ -1059,17 +1111,17 @@ var DockerodeClient = class {
1059
1111
  await this.client.getImage(image).remove({ force: true });
1060
1112
  }
1061
1113
  async pullImage(image, auth) {
1062
- const stream = await new Promise((resolve4, reject) => {
1114
+ const stream = await new Promise((resolve5, reject) => {
1063
1115
  const pullOptions = auth ? { authconfig: auth } : void 0;
1064
1116
  this.client.pull(image, pullOptions, (err, output) => {
1065
1117
  if (err || !output) {
1066
1118
  reject(err ?? new Error("docker pull \u8FD4\u56DE\u7A7A\u8F93\u51FA"));
1067
1119
  return;
1068
1120
  }
1069
- resolve4(output);
1121
+ resolve5(output);
1070
1122
  });
1071
1123
  });
1072
- await new Promise((resolve4, reject) => {
1124
+ await new Promise((resolve5, reject) => {
1073
1125
  this.client.modem.followProgress(
1074
1126
  stream,
1075
1127
  (err) => {
@@ -1077,7 +1129,7 @@ var DockerodeClient = class {
1077
1129
  reject(err);
1078
1130
  return;
1079
1131
  }
1080
- resolve4();
1132
+ resolve5();
1081
1133
  },
1082
1134
  () => void 0
1083
1135
  );
@@ -1593,14 +1645,14 @@ var MinioClient = class {
1593
1645
  async deleteObjectsByPrefix(bucket, prefix) {
1594
1646
  const objectsStream = this.inner.listObjectsV2(bucket, prefix, true);
1595
1647
  const keys = [];
1596
- await new Promise((resolve4, reject) => {
1648
+ await new Promise((resolve5, reject) => {
1597
1649
  objectsStream.on("data", (obj) => {
1598
1650
  if (obj.name) {
1599
1651
  keys.push(obj.name);
1600
1652
  }
1601
1653
  });
1602
1654
  objectsStream.on("error", reject);
1603
- objectsStream.on("end", resolve4);
1655
+ objectsStream.on("end", resolve5);
1604
1656
  });
1605
1657
  const chunkSize = 500;
1606
1658
  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.12",
4
4
  "description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
5
5
  "type": "module",
6
6
  "private": false,