chatccc 0.2.97 → 0.2.99
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/orchestrator.ts +73 -30
package/package.json
CHANGED
package/src/orchestrator.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { readdir, stat } from "node:fs/promises";
|
|
|
10
10
|
import { resolve, dirname } from "node:path";
|
|
11
11
|
|
|
12
12
|
import { makeTraceId, logTrace } from "./trace.ts";
|
|
13
|
+
import { appendStartupTrace } from "./shared.ts";
|
|
13
14
|
import {
|
|
14
15
|
CLAUDE_EFFORT,
|
|
15
16
|
CLAUDE_MODEL,
|
|
@@ -138,15 +139,34 @@ export async function handleCommand(
|
|
|
138
139
|
logTrace(tid, "BRANCH", { cmd: "/restart" });
|
|
139
140
|
await platform.sendText(chatId, "重启中...请几秒后发消息唤醒我").catch(() => {});
|
|
140
141
|
logTrace(tid, "DONE", { outcome: "restart" });
|
|
141
|
-
|
|
142
|
+
|
|
143
|
+
appendStartupTrace("restart: spawn begin", { fromPid: process.pid });
|
|
142
144
|
const child = spawn("npx", ["tsx", "src/index.ts"], {
|
|
143
145
|
cwd: PROJECT_ROOT,
|
|
144
146
|
detached: true,
|
|
145
147
|
stdio: "ignore",
|
|
146
148
|
shell: true,
|
|
147
149
|
});
|
|
150
|
+
|
|
151
|
+
child.on("error", (err) => {
|
|
152
|
+
appendStartupTrace("restart: spawn error", { error: err.message });
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
child.on("exit", (code, signal) => {
|
|
156
|
+
appendStartupTrace("restart: child exit", {
|
|
157
|
+
childPid: child.pid,
|
|
158
|
+
code,
|
|
159
|
+
signal,
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
148
163
|
child.unref();
|
|
149
|
-
|
|
164
|
+
|
|
165
|
+
// 给子进程 2 秒启动窗口,期间若立即 crash 则 exit handler 已写入 trace
|
|
166
|
+
setTimeout(() => {
|
|
167
|
+
appendStartupTrace("restart: parent exit", { childPid: child.pid });
|
|
168
|
+
process.exit(0);
|
|
169
|
+
}, 2000);
|
|
150
170
|
return;
|
|
151
171
|
}
|
|
152
172
|
|
|
@@ -267,34 +287,6 @@ export async function handleCommand(
|
|
|
267
287
|
return;
|
|
268
288
|
}
|
|
269
289
|
|
|
270
|
-
if (textLower === "/model") {
|
|
271
|
-
logTrace(tid, "BRANCH", { cmd: "/model" });
|
|
272
|
-
|
|
273
|
-
const defaultTool = resolveDefaultAgentTool();
|
|
274
|
-
const models = getAllModelsForTool(defaultTool);
|
|
275
|
-
let currentModel = "";
|
|
276
|
-
if (defaultTool === "cursor") currentModel = config.cursor.model;
|
|
277
|
-
else if (defaultTool === "codex") currentModel = config.codex.model;
|
|
278
|
-
else currentModel = CLAUDE_MODEL;
|
|
279
|
-
|
|
280
|
-
if (platform.kind === "wechat") {
|
|
281
|
-
const lines = [currentModel ? `当前模型 (${defaultTool}): ${currentModel}` : `当前模型 (${defaultTool}): 未指定`];
|
|
282
|
-
if (models.length > 0) {
|
|
283
|
-
lines.push("", "可切换模型:");
|
|
284
|
-
for (const m of models) lines.push(` ${m}`);
|
|
285
|
-
lines.push("", "在会话中输入 /model <模型名> 切换模型");
|
|
286
|
-
} else {
|
|
287
|
-
lines.push("", "没有可切换的模型。请在 config.json 中配置模型字段。");
|
|
288
|
-
}
|
|
289
|
-
await platform.sendText(chatId, lines.join("\n")).catch(() => {});
|
|
290
|
-
} else {
|
|
291
|
-
const card = buildModelCard(currentModel, models, defaultTool);
|
|
292
|
-
await platform.sendRawCard(chatId, card);
|
|
293
|
-
}
|
|
294
|
-
logTrace(tid, "DONE", { outcome: "model_query", defaultTool });
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
290
|
if (textLower === "/new" || textLower.startsWith("/new ")) {
|
|
299
291
|
const toolArg = text.slice(5).trim().toLowerCase();
|
|
300
292
|
const tool = toolArg || resolveDefaultAgentTool();
|
|
@@ -1062,6 +1054,30 @@ export async function handleCommand(
|
|
|
1062
1054
|
return;
|
|
1063
1055
|
}
|
|
1064
1056
|
|
|
1057
|
+
// /model — 查看当前会话的可用模型(根据会话 Agent 类型)
|
|
1058
|
+
if (textLower === "/model") {
|
|
1059
|
+
logTrace(tid, "BRANCH", { cmd: "/model", sessionId, tool: descriptionTool });
|
|
1060
|
+
const models = getAllModelsForTool(descriptionTool as AgentTool);
|
|
1061
|
+
const currentModel = getEffectiveModelForTool(descriptionTool, sessionId);
|
|
1062
|
+
|
|
1063
|
+
if (platform.kind === "wechat") {
|
|
1064
|
+
const lines = [currentModel ? `当前模型 (${toolLabel}): ${currentModel}` : `当前模型 (${toolLabel}): 未指定`];
|
|
1065
|
+
if (models.length > 0) {
|
|
1066
|
+
lines.push("", "可切换模型:");
|
|
1067
|
+
for (const m of models) lines.push(` ${m}`);
|
|
1068
|
+
lines.push("", "输入 /model <模型名> 切换模型");
|
|
1069
|
+
} else {
|
|
1070
|
+
lines.push("", "没有可切换的模型。请在 config.json 中配置模型字段。");
|
|
1071
|
+
}
|
|
1072
|
+
await platform.sendText(chatId, lines.join("\n")).catch(() => {});
|
|
1073
|
+
} else {
|
|
1074
|
+
const card = buildModelCard(currentModel, models, descriptionTool);
|
|
1075
|
+
await platform.sendRawCard(chatId, card);
|
|
1076
|
+
}
|
|
1077
|
+
logTrace(tid, "DONE", { outcome: "model_query", tool: descriptionTool });
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1065
1081
|
// /git <args>:在「当前会话工作目录」执行 git 命令
|
|
1066
1082
|
if (textLower.startsWith("/git ") || textLower === "/git") {
|
|
1067
1083
|
const args = text === "/git" ? "" : text.slice(5).trim();
|
|
@@ -1193,6 +1209,33 @@ export async function handleCommand(
|
|
|
1193
1209
|
return;
|
|
1194
1210
|
}
|
|
1195
1211
|
|
|
1212
|
+
// 无会话上下文 → 检查是否是 /model 查询
|
|
1213
|
+
if (textLower === "/model") {
|
|
1214
|
+
const defaultTool = resolveDefaultAgentTool();
|
|
1215
|
+
const models = getAllModelsForTool(defaultTool);
|
|
1216
|
+
let currentModel = "";
|
|
1217
|
+
if (defaultTool === "cursor") currentModel = config.cursor.model;
|
|
1218
|
+
else if (defaultTool === "codex") currentModel = config.codex.model;
|
|
1219
|
+
else currentModel = CLAUDE_MODEL;
|
|
1220
|
+
|
|
1221
|
+
if (platform.kind === "wechat") {
|
|
1222
|
+
const lines = [currentModel ? `当前模型 (${defaultTool}): ${currentModel}` : `当前模型 (${defaultTool}): 未指定`];
|
|
1223
|
+
if (models.length > 0) {
|
|
1224
|
+
lines.push("", "可切换模型:");
|
|
1225
|
+
for (const m of models) lines.push(` ${m}`);
|
|
1226
|
+
lines.push("", "在会话中输入 /model <模型名> 切换模型");
|
|
1227
|
+
} else {
|
|
1228
|
+
lines.push("", "没有可切换的模型。请在 config.json 中配置模型字段。");
|
|
1229
|
+
}
|
|
1230
|
+
await platform.sendText(chatId, lines.join("\n")).catch(() => {});
|
|
1231
|
+
} else {
|
|
1232
|
+
const card = buildModelCard(currentModel, models, defaultTool);
|
|
1233
|
+
await platform.sendRawCard(chatId, card);
|
|
1234
|
+
}
|
|
1235
|
+
logTrace(tid, "DONE", { outcome: "model_query", defaultTool });
|
|
1236
|
+
return;
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1196
1239
|
// 无会话上下文 → help card
|
|
1197
1240
|
logTrace(tid, "SEND", { method: "help_card", chatId });
|
|
1198
1241
|
const card = buildHelpCard(text, { defaultToolLabel: toolDisplayName(resolveDefaultAgentTool()) });
|