ai-project-manage-cli 5.0.20 → 5.0.21
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 +45 -46
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1049,13 +1049,19 @@ import { Agent, CursorAgentError } from "@cursor/sdk";
|
|
|
1049
1049
|
import { resolve as resolve3 } from "path";
|
|
1050
1050
|
|
|
1051
1051
|
// src/session-utils.ts
|
|
1052
|
+
import { formatCursorMessageLogEvent } from "@opc/shared";
|
|
1052
1053
|
var EventSession = class {
|
|
1053
1054
|
events = [];
|
|
1055
|
+
dirtyIndices = /* @__PURE__ */ new Set();
|
|
1054
1056
|
constructor(prompt) {
|
|
1055
1057
|
this.events.push({
|
|
1056
1058
|
type: "input",
|
|
1057
1059
|
content: prompt
|
|
1058
1060
|
});
|
|
1061
|
+
this.markDirty(0);
|
|
1062
|
+
}
|
|
1063
|
+
markDirty(index) {
|
|
1064
|
+
this.dirtyIndices.add(index);
|
|
1059
1065
|
}
|
|
1060
1066
|
addEvent(event) {
|
|
1061
1067
|
const latestEvent = this.events[this.events.length - 1];
|
|
@@ -1064,16 +1070,19 @@ var EventSession = class {
|
|
|
1064
1070
|
return;
|
|
1065
1071
|
}
|
|
1066
1072
|
if (formatedEvent.type === "tool_call") {
|
|
1067
|
-
const
|
|
1073
|
+
const existingIndex = this.events.findIndex(
|
|
1068
1074
|
(e) => e.type === "tool_call" && e.call_id === formatedEvent.call_id
|
|
1069
1075
|
);
|
|
1070
|
-
if (
|
|
1076
|
+
if (existingIndex >= 0) {
|
|
1077
|
+
const existingToolCall = this.events[existingIndex];
|
|
1071
1078
|
existingToolCall.args = formatedEvent.args;
|
|
1072
1079
|
existingToolCall.result = formatedEvent.result;
|
|
1073
1080
|
existingToolCall.status = formatedEvent.status;
|
|
1081
|
+
this.markDirty(existingIndex);
|
|
1074
1082
|
return;
|
|
1075
1083
|
}
|
|
1076
1084
|
this.events.push(formatedEvent);
|
|
1085
|
+
this.markDirty(this.events.length - 1);
|
|
1077
1086
|
return;
|
|
1078
1087
|
}
|
|
1079
1088
|
if (formatedEvent.type === "status") {
|
|
@@ -1081,6 +1090,7 @@ var EventSession = class {
|
|
|
1081
1090
|
}
|
|
1082
1091
|
if (formatedEvent.type === "request") {
|
|
1083
1092
|
this.events.push(formatedEvent);
|
|
1093
|
+
this.markDirty(this.events.length - 1);
|
|
1084
1094
|
return;
|
|
1085
1095
|
}
|
|
1086
1096
|
if (latestEvent?.type === formatedEvent.type) {
|
|
@@ -1096,9 +1106,11 @@ var EventSession = class {
|
|
|
1096
1106
|
latestEvent.text = formatedEvent.text;
|
|
1097
1107
|
break;
|
|
1098
1108
|
}
|
|
1109
|
+
this.markDirty(this.events.length - 1);
|
|
1099
1110
|
return;
|
|
1100
1111
|
}
|
|
1101
1112
|
this.events.push(formatedEvent);
|
|
1113
|
+
this.markDirty(this.events.length - 1);
|
|
1102
1114
|
}
|
|
1103
1115
|
formatEvent(event) {
|
|
1104
1116
|
switch (event.type) {
|
|
@@ -1143,43 +1155,29 @@ var EventSession = class {
|
|
|
1143
1155
|
return { type: "status", status: event.status, message: event.message };
|
|
1144
1156
|
}
|
|
1145
1157
|
}
|
|
1158
|
+
getDirtyEvents() {
|
|
1159
|
+
return [...this.dirtyIndices].sort((a, b) => a - b).map((index) => {
|
|
1160
|
+
const event = this.events[index];
|
|
1161
|
+
return {
|
|
1162
|
+
index,
|
|
1163
|
+
type: event.type,
|
|
1164
|
+
data: JSON.stringify(event)
|
|
1165
|
+
};
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
clearDirty(indices) {
|
|
1169
|
+
for (const index of indices) {
|
|
1170
|
+
this.dirtyIndices.delete(index);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1146
1173
|
/** 合并所有 assistant 片段,供剧场成员回传等场景使用 */
|
|
1147
1174
|
getAssistantText() {
|
|
1148
1175
|
return this.events.filter((e) => e.type === "assistant").map((e) => String(e.content ?? "")).join("\n").trim();
|
|
1149
1176
|
}
|
|
1150
1177
|
resolveLogContent() {
|
|
1151
|
-
return this.events.map(
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
if (type2 === "input") {
|
|
1155
|
-
return `## \u7528\u6237\u8F93\u5165
|
|
1156
|
-
|
|
1157
|
-
${event.content}
|
|
1158
|
-
`;
|
|
1159
|
-
}
|
|
1160
|
-
if (type2 === "assistant") {
|
|
1161
|
-
return `## \u6A21\u578B\u8F93\u51FA
|
|
1162
|
-
|
|
1163
|
-
${event.content}
|
|
1164
|
-
`;
|
|
1165
|
-
}
|
|
1166
|
-
if (type2 === "thinking") {
|
|
1167
|
-
return `## \u6A21\u578B\u601D\u8003
|
|
1168
|
-
|
|
1169
|
-
${event.content}
|
|
1170
|
-
`;
|
|
1171
|
-
}
|
|
1172
|
-
if (type2 === "tool_call") {
|
|
1173
|
-
return "````toolcall\n" + JSON.stringify(event, null, 2) + "\n````\n";
|
|
1174
|
-
}
|
|
1175
|
-
return `## \u672A\u77E5\u4E8B\u4EF6\uFF1A${type2}
|
|
1176
|
-
|
|
1177
|
-
\`\`\`json
|
|
1178
|
-
${JSON.stringify(event, null, 2)}
|
|
1179
|
-
\`\`\``;
|
|
1180
|
-
})(type);
|
|
1181
|
-
return content;
|
|
1182
|
-
}).join("\n");
|
|
1178
|
+
return this.events.map(
|
|
1179
|
+
(event) => formatCursorMessageLogEvent(event.type, JSON.stringify(event))
|
|
1180
|
+
).join("\n");
|
|
1183
1181
|
}
|
|
1184
1182
|
};
|
|
1185
1183
|
|
|
@@ -1201,14 +1199,15 @@ function createThrottledCursorMessageLogSync(cfg, ctx, onError) {
|
|
|
1201
1199
|
let lastRunAt = 0;
|
|
1202
1200
|
let timer;
|
|
1203
1201
|
let latestSession;
|
|
1204
|
-
const
|
|
1205
|
-
const
|
|
1206
|
-
if (
|
|
1202
|
+
const syncDirtyEvents = async (session) => {
|
|
1203
|
+
const events = session.getDirtyEvents();
|
|
1204
|
+
if (events.length === 0) {
|
|
1207
1205
|
return;
|
|
1208
1206
|
}
|
|
1209
1207
|
lastRunAt = Date.now();
|
|
1210
1208
|
try {
|
|
1211
|
-
await syncCursorMessageLog(cfg, ctx,
|
|
1209
|
+
await syncCursorMessageLog(cfg, ctx, events);
|
|
1210
|
+
session.clearDirty(events.map((event) => event.index));
|
|
1212
1211
|
} catch (err) {
|
|
1213
1212
|
onError(err);
|
|
1214
1213
|
}
|
|
@@ -1223,7 +1222,7 @@ function createThrottledCursorMessageLogSync(cfg, ctx, onError) {
|
|
|
1223
1222
|
clearTimeout(timer);
|
|
1224
1223
|
timer = void 0;
|
|
1225
1224
|
}
|
|
1226
|
-
void
|
|
1225
|
+
void syncDirtyEvents(session);
|
|
1227
1226
|
return;
|
|
1228
1227
|
}
|
|
1229
1228
|
if (timer) {
|
|
@@ -1231,7 +1230,7 @@ function createThrottledCursorMessageLogSync(cfg, ctx, onError) {
|
|
|
1231
1230
|
}
|
|
1232
1231
|
timer = setTimeout(() => {
|
|
1233
1232
|
timer = void 0;
|
|
1234
|
-
void
|
|
1233
|
+
void syncDirtyEvents(latestSession);
|
|
1235
1234
|
}, CURSOR_MESSAGE_LOG_SYNC_INTERVAL_MS - elapsed);
|
|
1236
1235
|
},
|
|
1237
1236
|
async flush(session) {
|
|
@@ -1240,14 +1239,13 @@ function createThrottledCursorMessageLogSync(cfg, ctx, onError) {
|
|
|
1240
1239
|
clearTimeout(timer);
|
|
1241
1240
|
timer = void 0;
|
|
1242
1241
|
}
|
|
1243
|
-
await
|
|
1242
|
+
await syncDirtyEvents(session);
|
|
1244
1243
|
}
|
|
1245
1244
|
};
|
|
1246
1245
|
}
|
|
1247
|
-
async function syncCursorMessageLog(cfg, ctx,
|
|
1246
|
+
async function syncCursorMessageLog(cfg, ctx, events) {
|
|
1248
1247
|
const agentId = ctx.agentId.trim();
|
|
1249
|
-
|
|
1250
|
-
if (!agentId || !data) {
|
|
1248
|
+
if (!agentId || events.length === 0) {
|
|
1251
1249
|
return;
|
|
1252
1250
|
}
|
|
1253
1251
|
const api = createApmApiClient(cfg);
|
|
@@ -1255,7 +1253,7 @@ async function syncCursorMessageLog(cfg, ctx, session) {
|
|
|
1255
1253
|
sessionId: ctx.sessionId,
|
|
1256
1254
|
messageId: ctx.messageId,
|
|
1257
1255
|
agentId,
|
|
1258
|
-
|
|
1256
|
+
events
|
|
1259
1257
|
});
|
|
1260
1258
|
}
|
|
1261
1259
|
|
|
@@ -1421,6 +1419,7 @@ async function runConnect(options) {
|
|
|
1421
1419
|
const ws = new WebSocket(url);
|
|
1422
1420
|
let stopHeartbeat;
|
|
1423
1421
|
let shuttingDown = false;
|
|
1422
|
+
let inboundQueue = Promise.resolve();
|
|
1424
1423
|
const shutdown = (code = 0) => {
|
|
1425
1424
|
if (shuttingDown) return;
|
|
1426
1425
|
shuttingDown = true;
|
|
@@ -1439,7 +1438,7 @@ async function runConnect(options) {
|
|
|
1439
1438
|
});
|
|
1440
1439
|
ws.on("message", (data) => {
|
|
1441
1440
|
const text = Buffer.isBuffer(data) ? data.toString("utf8") : String(data);
|
|
1442
|
-
|
|
1441
|
+
inboundQueue = inboundQueue.then(() => handleInboundMessage(cfg, text));
|
|
1443
1442
|
});
|
|
1444
1443
|
ws.on("close", (code, reason) => {
|
|
1445
1444
|
console.log(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-project-manage-cli",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.21",
|
|
4
4
|
"description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"node": ">=18"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@cursor/sdk": "~1.0.
|
|
32
|
+
"@cursor/sdk": "~1.0.18",
|
|
33
|
+
"@opc/shared": "workspace:*",
|
|
33
34
|
"ws": "~8.18.0",
|
|
34
35
|
"listpage-http": "~0.0.318",
|
|
35
36
|
"commander": "~14.0.3",
|
|
@@ -37,4 +38,4 @@
|
|
|
37
38
|
"minio": "~8.0.7",
|
|
38
39
|
"dockerode": "~5.0.0"
|
|
39
40
|
}
|
|
40
|
-
}
|
|
41
|
+
}
|