chatccc 0.2.85 → 0.2.87
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/package.json +1 -1
- package/src/adapters/cursor-adapter.ts +12 -3
- package/src/session.ts +11 -1
package/package.json
CHANGED
|
@@ -268,11 +268,13 @@ function spawnAgent(
|
|
|
268
268
|
shell: true,
|
|
269
269
|
});
|
|
270
270
|
|
|
271
|
+
console.log(`[Cursor debug] spawn: cmd=${CURSOR_AGENT_COMMAND}, args=[${allArgs.join(", ")}], cwd=${cwd ?? "(none)"}, stdinLen=${stdinText?.length ?? 0}, pid=${proc.pid}`);
|
|
272
|
+
|
|
271
273
|
// 收集 stderr,子进程异常退出时输出到日志,方便排查静默失败
|
|
272
274
|
let stderr = "";
|
|
273
275
|
proc.stderr!.on("data", (chunk: Buffer) => { stderr += chunk.toString(); });
|
|
274
276
|
proc.on("close", (code) => {
|
|
275
|
-
if (
|
|
277
|
+
if (stderr.trim()) {
|
|
276
278
|
console.error(`[Cursor stderr] exit=${code}: ${stderr.trim().slice(0, 2000)}`);
|
|
277
279
|
}
|
|
278
280
|
});
|
|
@@ -287,14 +289,18 @@ function spawnAgent(
|
|
|
287
289
|
async function* readJsonLines(
|
|
288
290
|
proc: ChildProcess,
|
|
289
291
|
signal?: AbortSignal,
|
|
292
|
+
debugTag?: string,
|
|
290
293
|
): AsyncGenerator<CursorMessageLine> {
|
|
294
|
+
const tag = debugTag ?? "cursor";
|
|
291
295
|
const rl = createInterface({ input: proc.stdout!, crlfDelay: Infinity });
|
|
292
296
|
// abort 时主动 close readline,避免等待 Windows 管道自然关闭(可能延迟数分钟)
|
|
293
297
|
const onAbort = () => { rl.close(); };
|
|
294
298
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
299
|
+
let lineCount = 0;
|
|
295
300
|
try {
|
|
296
301
|
for await (const line of rl) {
|
|
297
302
|
if (signal?.aborted) break;
|
|
303
|
+
lineCount++;
|
|
298
304
|
const trimmed = line.trim();
|
|
299
305
|
if (!trimmed) continue;
|
|
300
306
|
try {
|
|
@@ -304,6 +310,7 @@ async function* readJsonLines(
|
|
|
304
310
|
} finally {
|
|
305
311
|
signal?.removeEventListener("abort", onAbort);
|
|
306
312
|
rl.close();
|
|
313
|
+
console.log(`[Cursor debug] ${tag} readJsonLines done: ${lineCount} raw lines, signalAborted=${signal?.aborted ?? false}`);
|
|
307
314
|
}
|
|
308
315
|
}
|
|
309
316
|
|
|
@@ -325,7 +332,7 @@ class CursorAdapter implements ToolAdapter {
|
|
|
325
332
|
const proc = spawnAgent(["ok"], cwd);
|
|
326
333
|
this.activeProcs.add(proc);
|
|
327
334
|
|
|
328
|
-
for await (const msg of readJsonLines(proc)) {
|
|
335
|
+
for await (const msg of readJsonLines(proc, undefined, "createSession")) {
|
|
329
336
|
if (msg.type === "system" && msg.subtype === "init" && msg.session_id) {
|
|
330
337
|
const sessionId = msg.session_id;
|
|
331
338
|
await this.metaStore
|
|
@@ -348,6 +355,7 @@ class CursorAdapter implements ToolAdapter {
|
|
|
348
355
|
cwd: string,
|
|
349
356
|
signal?: AbortSignal,
|
|
350
357
|
): AsyncIterable<UnifiedStreamMessage> {
|
|
358
|
+
console.log(`[Cursor debug] prompt start: sessionId=${sessionId}, cwd=${cwd}, userTextLen=${userText.length}`);
|
|
351
359
|
const proc = spawnAgent(["--resume", sessionId], cwd, userText);
|
|
352
360
|
this.activeProcs.add(proc);
|
|
353
361
|
|
|
@@ -357,7 +365,7 @@ class CursorAdapter implements ToolAdapter {
|
|
|
357
365
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
358
366
|
|
|
359
367
|
try {
|
|
360
|
-
for await (const raw of readJsonLines(proc, signal)) {
|
|
368
|
+
for await (const raw of readJsonLines(proc, signal, sessionId)) {
|
|
361
369
|
if (signal?.aborted) break;
|
|
362
370
|
if (
|
|
363
371
|
raw.type === "system" &&
|
|
@@ -376,6 +384,7 @@ class CursorAdapter implements ToolAdapter {
|
|
|
376
384
|
signal?.removeEventListener("abort", onAbort);
|
|
377
385
|
await killProcessTree(proc.pid);
|
|
378
386
|
this.activeProcs.delete(proc);
|
|
387
|
+
console.log(`[Cursor debug] prompt end: sessionId=${sessionId}, signalAborted=${signal?.aborted ?? false}`);
|
|
379
388
|
}
|
|
380
389
|
}
|
|
381
390
|
|
package/src/session.ts
CHANGED
|
@@ -955,7 +955,16 @@ export async function runAgentSession(
|
|
|
955
955
|
const CARD_ROTATE_MS = 9 * 60 * 1000;
|
|
956
956
|
|
|
957
957
|
export function ensureDisplayLoop(sessionId: string): void {
|
|
958
|
-
|
|
958
|
+
// 杀掉旧 loop(如果存在),避免竞态:旧 loop 正在处理 terminal 分支
|
|
959
|
+
// (发送完成卡片、清理 display)尚未 delete 自己,新 turn 的
|
|
960
|
+
// runAgentSession 调用 ensureDisplayLoop 时因 guard 直接返回,
|
|
961
|
+
// 导致新 turn 没有 display loop → 卡片永久不更新。
|
|
962
|
+
const oldStop = displayLoops.get(sessionId);
|
|
963
|
+
if (oldStop) {
|
|
964
|
+
console.log(`[${ts()}] [DISPLAY] ensureDisplayLoop restarting loop for ${sessionId} (old loop existed)`);
|
|
965
|
+
oldStop();
|
|
966
|
+
displayLoops.delete(sessionId);
|
|
967
|
+
}
|
|
959
968
|
|
|
960
969
|
let dotCount = 0;
|
|
961
970
|
|
|
@@ -1243,6 +1252,7 @@ export function ensureDisplayLoop(sessionId: string): void {
|
|
|
1243
1252
|
}
|
|
1244
1253
|
|
|
1245
1254
|
if (isTerminal) {
|
|
1255
|
+
console.log(`[${ts()}] [DISPLAY] loop stopping for ${sessionId} (terminal state: ${state.status})`);
|
|
1246
1256
|
clearInterval(interval);
|
|
1247
1257
|
displayLoops.delete(sessionId);
|
|
1248
1258
|
}
|