chatccc 0.2.281 → 0.2.282
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/README.md +2 -0
- package/dist/src/cardkit.js +25 -1
- package/dist/src/feishu-connection.js +144 -0
- package/dist/src/index.js +26 -9
- package/dist/src/session.js +4 -1
- package/dist/src/terminal-error.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -448,6 +448,8 @@ Codex 的默认模型和推理强度可继续由 `~/.codex/config.toml` 管理
|
|
|
448
448
|
`/restart safe`(短别名 `/restartsf`)与 `/update safe`(短别名 `/updatesf`)会先建立全局准入门禁:指令到达前已经运行或进入单会话缓存队列的工作会继续完成,之后到达的新普通任务会被提示在维护完成后重发。维护任务持久化到 `~/.chatccc/state/safe-maintenance.json`,进程意外退出后可继续排空;依赖安装、会话收尾、自动恢复和 Agent Teams 执行也计入等待条件。内存缓存随重启自然重建,磁盘会话、看板、图片等持久数据不会被清理。
|
|
449
449
|
|
|
450
450
|
ChatCCC 的内部重启和更新使用跨平台父子进程握手:替代进程完成启动预检后通知父进程退出,再等待旧监听端口实际释放并接管 PID;替代进程未就绪或握手超时时,父进程会保留并继续服务。
|
|
451
|
+
|
|
452
|
+
飞书接收长连接启用 15 秒握手超时和 30 秒心跳应答超时;首次启动最多等待 45 秒真实连接确认后才提示就绪。运行期间连接持续异常 90 秒时,会关闭并重新建立接收连接,保留会话、消息去重和正在执行的任务。没有用户消息不会触发重连。连接状态与恢复记录写入运行日志和 `startup-trace.log`(`FEISHU-CONNECTION` / `feishu-connection`)。卡片更新遇到网络失败或序号冲突时不会当成送达成功,错误通知保留文本兜底;TLS 断线会明确显示为网络连接失败,已中断的 Agent 任务不会因此自动重放。
|
|
451
453
|
|
|
452
454
|
> **模型切换**:`/model` 查看当前会话 Agent 的可选模型清单,`/model <名称>` 模糊匹配切换,`/model clear` 恢复默认。可选模型来自当前 Agent 的配置:Claude 使用 `claude.model` / `claude.subagentModel`;Cursor、Codex、CCC Agent 和 DSH 使用各自的 `model` / `alternativeModel`。
|
|
453
455
|
|
package/dist/src/cardkit.js
CHANGED
|
@@ -103,7 +103,31 @@ export async function streamCardKitElement(token, cardId, elementId, content, se
|
|
|
103
103
|
// success log is intentionally sparse — uncomment to debug streaming throughput
|
|
104
104
|
// console.log(`[${ts()}] [CARDIKT] streamElement OK cardId=${cardId} seq=${sequence}`);
|
|
105
105
|
}
|
|
106
|
-
|
|
106
|
+
// Keep bounded per-card sequence history; never reuse an attempted sequence
|
|
107
|
+
// because a failed fetch can mean the response (not the update) was lost.
|
|
108
|
+
const cardUpdateQueues = new Map();
|
|
109
|
+
export function updateCardKitCard(token, cardId, cardJson, sequence) {
|
|
110
|
+
let state = cardUpdateQueues.get(cardId);
|
|
111
|
+
if (!state) {
|
|
112
|
+
for (const [key, candidate] of cardUpdateQueues) {
|
|
113
|
+
if (cardUpdateQueues.size < 512)
|
|
114
|
+
break;
|
|
115
|
+
if (candidate.pending === 0)
|
|
116
|
+
cardUpdateQueues.delete(key);
|
|
117
|
+
}
|
|
118
|
+
state = { sequence: 0, tail: Promise.resolve(), pending: 0 };
|
|
119
|
+
cardUpdateQueues.set(cardId, state);
|
|
120
|
+
}
|
|
121
|
+
const queue = state;
|
|
122
|
+
queue.pending++;
|
|
123
|
+
const result = queue.tail.then(async () => {
|
|
124
|
+
queue.sequence = Math.max(sequence, queue.sequence + 1);
|
|
125
|
+
await performCardKitUpdate(token, cardId, cardJson, queue.sequence);
|
|
126
|
+
});
|
|
127
|
+
queue.tail = result.catch(() => { }).finally(() => { queue.pending--; });
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
async function performCardKitUpdate(token, cardId, cardJson, sequence) {
|
|
107
131
|
const { resp, respText } = await fetchCardKit(`${BASE_URL}/cardkit/v1/cards/${cardId}`, {
|
|
108
132
|
method: "PUT",
|
|
109
133
|
headers: {
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { sanitizeTerminalErrorDetail } from "./terminal-error.js";
|
|
2
|
+
/** Owns only the receiving transport. It never resets sessions or replays tasks. */
|
|
3
|
+
export function createFeishuConnectionSupervisor(options) {
|
|
4
|
+
const stalledAfterMs = options.stalledAfterMs ?? 90_000;
|
|
5
|
+
let stopped = false;
|
|
6
|
+
let client;
|
|
7
|
+
let timer;
|
|
8
|
+
let startupTimer;
|
|
9
|
+
let startup;
|
|
10
|
+
let resolveStartup;
|
|
11
|
+
let rejectStartup;
|
|
12
|
+
let unhealthySince;
|
|
13
|
+
let lastState = "idle";
|
|
14
|
+
let connected = false;
|
|
15
|
+
let launching = false;
|
|
16
|
+
let lastAttempt = 0;
|
|
17
|
+
const log = (event, detail) => {
|
|
18
|
+
try {
|
|
19
|
+
options.log(event, detail);
|
|
20
|
+
}
|
|
21
|
+
catch { /* diagnostics cannot break recovery */ }
|
|
22
|
+
};
|
|
23
|
+
const reportError = (error) => {
|
|
24
|
+
if (stopped)
|
|
25
|
+
return;
|
|
26
|
+
connected = false;
|
|
27
|
+
unhealthySince ??= Date.now();
|
|
28
|
+
log("connection error", { reason: sanitizeTerminalErrorDetail(error instanceof Error ? error.message : String(error)) });
|
|
29
|
+
};
|
|
30
|
+
const becameConnected = () => {
|
|
31
|
+
if (stopped) {
|
|
32
|
+
// A handshake already in flight can finish after close(); never resurrect
|
|
33
|
+
// a transport belonging to a stopped setup attempt or shutting-down app.
|
|
34
|
+
try {
|
|
35
|
+
client?.close({ force: true });
|
|
36
|
+
}
|
|
37
|
+
catch { /* best effort */ }
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (connected)
|
|
41
|
+
return;
|
|
42
|
+
connected = true;
|
|
43
|
+
unhealthySince = undefined;
|
|
44
|
+
lastState = "connected";
|
|
45
|
+
log("connected");
|
|
46
|
+
if (startupTimer)
|
|
47
|
+
clearTimeout(startupTimer);
|
|
48
|
+
resolveStartup?.();
|
|
49
|
+
resolveStartup = undefined;
|
|
50
|
+
rejectStartup = undefined;
|
|
51
|
+
void Promise.resolve().then(() => stopped ? undefined : options.onConnected()).catch((error) => {
|
|
52
|
+
log("binding recovery failed", { reason: sanitizeTerminalErrorDetail(String(error)) });
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const stop = () => {
|
|
56
|
+
if (stopped)
|
|
57
|
+
return;
|
|
58
|
+
stopped = true;
|
|
59
|
+
if (timer)
|
|
60
|
+
clearInterval(timer);
|
|
61
|
+
if (startupTimer)
|
|
62
|
+
clearTimeout(startupTimer);
|
|
63
|
+
try {
|
|
64
|
+
client?.close({ force: true });
|
|
65
|
+
}
|
|
66
|
+
catch { /* best effort shutdown */ }
|
|
67
|
+
rejectStartup?.(new Error("飞书长连接在就绪前已停止"));
|
|
68
|
+
resolveStartup = undefined;
|
|
69
|
+
rejectStartup = undefined;
|
|
70
|
+
log("stopped");
|
|
71
|
+
};
|
|
72
|
+
const launch = () => {
|
|
73
|
+
if (stopped || launching || !client)
|
|
74
|
+
return;
|
|
75
|
+
launching = true;
|
|
76
|
+
lastAttempt = Date.now();
|
|
77
|
+
unhealthySince = lastAttempt;
|
|
78
|
+
void Promise.resolve().then(() => stopped ? undefined : client.start())
|
|
79
|
+
.catch(reportError).finally(() => { launching = false; });
|
|
80
|
+
};
|
|
81
|
+
const check = () => {
|
|
82
|
+
if (stopped || !client)
|
|
83
|
+
return;
|
|
84
|
+
try {
|
|
85
|
+
const status = client.getConnectionStatus();
|
|
86
|
+
if (status.state !== lastState) {
|
|
87
|
+
lastState = status.state;
|
|
88
|
+
log("state", { ...status });
|
|
89
|
+
}
|
|
90
|
+
if (status.state === "connected") {
|
|
91
|
+
becameConnected();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
connected = false;
|
|
95
|
+
unhealthySince ??= Date.now();
|
|
96
|
+
// SDK gets a bounded chance to recover. Silence from users is irrelevant.
|
|
97
|
+
if (launching || Date.now() - unhealthySince < stalledAfterMs
|
|
98
|
+
|| Date.now() - lastAttempt < stalledAfterMs)
|
|
99
|
+
return;
|
|
100
|
+
log("restarting receiving connection", { ...status, disconnectedForMs: Date.now() - unhealthySince });
|
|
101
|
+
client.close({ force: true });
|
|
102
|
+
launch();
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
reportError(error);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const start = () => {
|
|
109
|
+
if (startup)
|
|
110
|
+
return startup;
|
|
111
|
+
if (stopped)
|
|
112
|
+
return Promise.reject(new Error("飞书长连接已停止"));
|
|
113
|
+
startup = new Promise((resolve, reject) => { resolveStartup = resolve; rejectStartup = reject; });
|
|
114
|
+
startupTimer = setTimeout(() => {
|
|
115
|
+
rejectStartup?.(new Error("飞书长连接握手超时,尚未收到连接成功确认"));
|
|
116
|
+
rejectStartup = undefined;
|
|
117
|
+
stop();
|
|
118
|
+
}, options.startupTimeoutMs ?? 45_000);
|
|
119
|
+
try {
|
|
120
|
+
client = options.createClient({
|
|
121
|
+
onReady: becameConnected,
|
|
122
|
+
onReconnected: becameConnected,
|
|
123
|
+
onReconnecting() {
|
|
124
|
+
if (stopped)
|
|
125
|
+
return;
|
|
126
|
+
connected = false;
|
|
127
|
+
unhealthySince ??= Date.now();
|
|
128
|
+
log("reconnecting");
|
|
129
|
+
},
|
|
130
|
+
onError: reportError,
|
|
131
|
+
});
|
|
132
|
+
timer = setInterval(check, options.checkIntervalMs ?? 10_000);
|
|
133
|
+
timer.unref();
|
|
134
|
+
launch();
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
rejectStartup?.(error instanceof Error ? error : new Error(String(error)));
|
|
138
|
+
rejectStartup = undefined;
|
|
139
|
+
stop();
|
|
140
|
+
}
|
|
141
|
+
return startup;
|
|
142
|
+
};
|
|
143
|
+
return { start, stop };
|
|
144
|
+
}
|
package/dist/src/index.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import { createServer } from "node:http";
|
|
25
25
|
import { WSClient, EventDispatcher, Domain } from "@larksuiteoapi/node-sdk";
|
|
26
|
+
import { createFeishuConnectionSupervisor } from "./feishu-connection.js";
|
|
26
27
|
import WebSocket from "ws";
|
|
27
28
|
import { appendStartupTrace, attachRelayWebSocket, ensureSingleInstance, freeRelayListenPort, installCrashLogging, installEpipeGuard, waitForPortFree } from "./shared.js";
|
|
28
29
|
import { createUiRouter, setExtraApiHandler, setReloadConfigHook, startSetupMode } from "./web-ui.js";
|
|
@@ -256,6 +257,7 @@ async function startBotService(opts) {
|
|
|
256
257
|
throw err;
|
|
257
258
|
}
|
|
258
259
|
}
|
|
260
|
+
let feishuConnection;
|
|
259
261
|
async function startBotServiceCore() {
|
|
260
262
|
const modeTag = USE_LOCAL ? " (local relay mode)" : "";
|
|
261
263
|
console.log(`${"=".repeat(60)}`);
|
|
@@ -420,20 +422,33 @@ async function startBotServiceCore() {
|
|
|
420
422
|
// - 已处理消息的去重 set 必须保留,避免 SDK 重推老消息时 prompt 跑两遍
|
|
421
423
|
// 历史 bug:此处曾误调 resetState() 导致重连即让所有后台任务变孤儿,
|
|
422
424
|
// 同一 session 还可能双开 prompt(详见 session.ts::resetState 注释)。
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
425
|
+
feishuConnection?.stop();
|
|
426
|
+
feishuConnection = createFeishuConnectionSupervisor({
|
|
427
|
+
createClient(callbacks) {
|
|
428
|
+
const client = new WSClient({
|
|
429
|
+
appId: APP_ID,
|
|
430
|
+
appSecret: APP_SECRET,
|
|
431
|
+
domain: FEISHU_PLATFORM_TYPE === "lark" ? Domain.Lark : Domain.Feishu,
|
|
432
|
+
autoReconnect: true,
|
|
433
|
+
handshakeTimeoutMs: 15_000,
|
|
434
|
+
wsConfig: { pingTimeout: 30 },
|
|
435
|
+
...callbacks,
|
|
436
|
+
});
|
|
437
|
+
return {
|
|
438
|
+
start: () => client.start({ eventDispatcher }),
|
|
439
|
+
close: (options) => client.close(options),
|
|
440
|
+
getConnectionStatus: () => client.getConnectionStatus(),
|
|
441
|
+
};
|
|
429
442
|
},
|
|
430
|
-
|
|
431
|
-
|
|
443
|
+
onConnected: rebuildBindingsFromRegistry,
|
|
444
|
+
log(event, detail) {
|
|
445
|
+
appendStartupTrace(`feishu-connection: ${event}`, detail);
|
|
446
|
+
console.log(`[${ts()}] [FEISHU-CONNECTION] ${event}${detail ? ` ${JSON.stringify(detail)}` : ""}`);
|
|
432
447
|
},
|
|
433
448
|
});
|
|
434
449
|
console.log(`\n[启动 6/7] 飞书长连接:正在通过 SDK 建立 WebSocket …`);
|
|
435
450
|
try {
|
|
436
|
-
await
|
|
451
|
+
await feishuConnection.start();
|
|
437
452
|
}
|
|
438
453
|
catch (err) {
|
|
439
454
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -790,6 +805,7 @@ function installShutdownHandlers(httpServer, serviceLifecycle) {
|
|
|
790
805
|
process.on("SIGINT", () => {
|
|
791
806
|
console.log("\nShutting down...");
|
|
792
807
|
serviceLifecycle.beginShutdown("SIGINT");
|
|
808
|
+
feishuConnection?.stop();
|
|
793
809
|
wechatSignal.stopped = true;
|
|
794
810
|
stopChromeDevtoolsGuard();
|
|
795
811
|
httpServer.close();
|
|
@@ -797,6 +813,7 @@ function installShutdownHandlers(httpServer, serviceLifecycle) {
|
|
|
797
813
|
});
|
|
798
814
|
process.on("SIGTERM", () => {
|
|
799
815
|
serviceLifecycle.beginShutdown("SIGTERM");
|
|
816
|
+
feishuConnection?.stop();
|
|
800
817
|
wechatSignal.stopped = true;
|
|
801
818
|
stopChromeDevtoolsGuard();
|
|
802
819
|
httpServer.close();
|
package/dist/src/session.js
CHANGED
|
@@ -1785,7 +1785,6 @@ export function startUnifiedDisplayLoop() {
|
|
|
1785
1785
|
console.error(`[${ts()}] [DISPLAY] terminal cardUpdate failed: ${err.message}`);
|
|
1786
1786
|
if (isCardKitSequenceConflict(err)) {
|
|
1787
1787
|
display.sequence = nextSeq;
|
|
1788
|
-
terminalCardUpdateAccepted = true;
|
|
1789
1788
|
}
|
|
1790
1789
|
});
|
|
1791
1790
|
if (terminalCardUpdateAccepted) {
|
|
@@ -1943,6 +1942,8 @@ export function startUnifiedDisplayLoop() {
|
|
|
1943
1942
|
catch (err) {
|
|
1944
1943
|
const errMsg = err.message;
|
|
1945
1944
|
console.error(`[${ts()}] CardKit update error: chatId=${chatId} ${errMsg}`);
|
|
1945
|
+
display.lastSentContent = "";
|
|
1946
|
+
display.lastSentHeaderTitle = "";
|
|
1946
1947
|
if (errMsg.includes("300317")) {
|
|
1947
1948
|
display.sequence = mySeq;
|
|
1948
1949
|
}
|
|
@@ -1977,6 +1978,8 @@ export function startUnifiedDisplayLoop() {
|
|
|
1977
1978
|
catch (err) {
|
|
1978
1979
|
const errMsg = err.message;
|
|
1979
1980
|
console.error(`[${ts()}] CardKit update error: chatId=${chatId} ${errMsg}`);
|
|
1981
|
+
display.lastSentContent = "";
|
|
1982
|
+
display.lastSentHeaderTitle = "";
|
|
1980
1983
|
if (errMsg.includes("300317")) {
|
|
1981
1984
|
display.sequence = mySeq;
|
|
1982
1985
|
}
|
|
@@ -64,7 +64,7 @@ export function classifyTerminalError(error, occurredAt = Date.now()) {
|
|
|
64
64
|
occurredAt,
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
if (/econnrefused|econnreset|enotfound|eai_again|socket hang up|network error|cannot connect/.test(lower)) {
|
|
67
|
+
if (/econnrefused|econnreset|enotfound|eai_again|socket hang up|network error|cannot connect|tls handshake|before secure tls connection|stream disconnected before completion|websocket closed/.test(lower)) {
|
|
68
68
|
return {
|
|
69
69
|
kind: "network",
|
|
70
70
|
title: "无法连接模型服务",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chatccc",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.282",
|
|
4
4
|
"description": "Feishu bot bridge for Claude Code",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@ai-sdk/anthropic": "^3.0.105",
|
|
55
55
|
"@ai-sdk/openai-compatible": "^2.0.47",
|
|
56
|
-
"@larksuiteoapi/node-sdk": "^1.
|
|
56
|
+
"@larksuiteoapi/node-sdk": "^1.66.1",
|
|
57
57
|
"@openilink/openilink-sdk-node": "^0.6.0",
|
|
58
58
|
"@vscode/ripgrep": "^1.18.0",
|
|
59
59
|
"ai": "^6.0.184",
|