@csdwd/ai-teams-agent 0.3.4 → 0.3.6
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 +53 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -247,6 +247,28 @@ var CLAUDE_HOOKS_ENABLED = process.env.CLAUDE_HOOKS_ENABLED !== "false";
|
|
|
247
247
|
var WORKSPACE_CLAUDE_MD = path3.join(DEFAULT_WORKSPACE, "CLAUDE.md");
|
|
248
248
|
var CLAUDE_MD_SECTION_START = "<!-- AI_TEAMS_AGENT_RULES_START -->";
|
|
249
249
|
var CLAUDE_MD_SECTION_END = "<!-- AI_TEAMS_AGENT_RULES_END -->";
|
|
250
|
+
function reinitializeConfig() {
|
|
251
|
+
fileConfig = loadConfigFile();
|
|
252
|
+
SERVER_PORT = process.env.AI_TEAMS_SERVER_PORT || "3789";
|
|
253
|
+
SERVER_URL = process.env.SERVER_URL || fileConfig?.serverUrl || `ws://localhost:${SERVER_PORT}`;
|
|
254
|
+
AUTH_TOKEN = process.env.AI_TEAMS_AUTH_TOKEN || fileConfig?.authToken || "";
|
|
255
|
+
EMPLOYEE_ID = process.env.EMPLOYEE_ID || fileConfig?.employeeId || "emp_local";
|
|
256
|
+
EMPLOYEE_NAME = process.env.EMPLOYEE_NAME || fileConfig?.employeeName || "Local Agent";
|
|
257
|
+
EMPLOYEE_LABELS = process.env.EMPLOYEE_LABELS?.split(",").map((item) => item.trim()).filter(Boolean) ?? [];
|
|
258
|
+
RECONNECT_MS = Number(process.env.RECONNECT_MS) || 5e3;
|
|
259
|
+
RUNNER_MODE = process.env.RUNNER_MODE || fileConfig?.runnerMode || "claude";
|
|
260
|
+
DEFAULT_WORKSPACE = process.env.DEFAULT_WORKSPACE || fileConfig?.workspace || process.cwd();
|
|
261
|
+
MAX_BUFFERED_MESSAGES = Number(process.env.AGENT_BUFFER_LIMIT) || 400;
|
|
262
|
+
AGENT_RECORDS_DIR = process.env.AGENT_RECORDS_DIR || path3.join(DEFAULT_WORKSPACE, ".ai-teams", "agents", EMPLOYEE_ID);
|
|
263
|
+
STATE_FILE = process.env.AGENT_STATE_FILE || path3.join(AGENT_RECORDS_DIR, "session-state.json");
|
|
264
|
+
LEGACY_STATE_FILE = path3.join(process.cwd(), `.agent-state.${EMPLOYEE_ID}.json`);
|
|
265
|
+
DAILY_RECORDS_DIR = path3.join(AGENT_RECORDS_DIR, "daily");
|
|
266
|
+
HOOKS_DIR = path3.join(AGENT_RECORDS_DIR, "hooks");
|
|
267
|
+
CLAUDE_HOOK_SCRIPT = path3.join(HOOKS_DIR, "claude-session-recorder.cjs");
|
|
268
|
+
CLAUDE_HOOK_SETTINGS = path3.join(HOOKS_DIR, "claude-hooks.settings.json");
|
|
269
|
+
CLAUDE_HOOKS_ENABLED = process.env.CLAUDE_HOOKS_ENABLED !== "false";
|
|
270
|
+
WORKSPACE_CLAUDE_MD = path3.join(DEFAULT_WORKSPACE, "CLAUDE.md");
|
|
271
|
+
}
|
|
250
272
|
|
|
251
273
|
// src/state.ts
|
|
252
274
|
import fs3 from "node:fs";
|
|
@@ -1035,7 +1057,12 @@ function connect(state, getMainTask, getQueueTask, onMessage) {
|
|
|
1035
1057
|
console.error(`[agent:${EMPLOYEE_ID}] invalid server message`, error);
|
|
1036
1058
|
}
|
|
1037
1059
|
});
|
|
1038
|
-
state.socket.on("close", () => {
|
|
1060
|
+
state.socket.on("close", (code, reason) => {
|
|
1061
|
+
if (code === 1008) {
|
|
1062
|
+
console.error(`[agent:${EMPLOYEE_ID}] \u8BA4\u8BC1\u5931\u8D25\uFF1AToken \u65E0\u6548\u6216\u670D\u52A1\u5668\u62D2\u7EDD\u8FDE\u63A5\u3002${reason ? ` (${reason})` : ""}`);
|
|
1063
|
+
console.error(`[agent:${EMPLOYEE_ID}] \u8BF7\u68C0\u67E5 AI_TEAMS_AUTH_TOKEN \u914D\u7F6E\u540E\u91CD\u65B0\u542F\u52A8\u3002`);
|
|
1064
|
+
process.exit(1);
|
|
1065
|
+
}
|
|
1039
1066
|
console.log(`[agent:${EMPLOYEE_ID}] disconnected, reconnecting in ${RECONNECT_MS}ms...`);
|
|
1040
1067
|
scheduleReconnect(state, () => connect(state, getMainTask, getQueueTask, onMessage));
|
|
1041
1068
|
});
|
|
@@ -1201,15 +1228,19 @@ function gracefulShutdown(signal) {
|
|
|
1201
1228
|
if (shuttingDown) return;
|
|
1202
1229
|
shuttingDown = true;
|
|
1203
1230
|
console.log(`[agent:${EMPLOYEE_ID}] received ${signal}, shutting down...`);
|
|
1231
|
+
const children = [];
|
|
1204
1232
|
for (const task of [mainTask, queueTask]) {
|
|
1205
1233
|
if (!task) continue;
|
|
1206
1234
|
task.cancelRequested = true;
|
|
1235
|
+
if (task.child) children.push(task.child);
|
|
1207
1236
|
task.child?.kill("SIGTERM");
|
|
1208
1237
|
send2({ type: "task.cancelled", taskId: task.taskId });
|
|
1209
1238
|
}
|
|
1239
|
+
mainTask = null;
|
|
1240
|
+
queueTask = null;
|
|
1210
1241
|
setTimeout(() => {
|
|
1211
|
-
for (const
|
|
1212
|
-
|
|
1242
|
+
for (const child of children) {
|
|
1243
|
+
child.kill("SIGKILL");
|
|
1213
1244
|
}
|
|
1214
1245
|
}, 2e3);
|
|
1215
1246
|
if (connState.reconnectTimer) clearTimeout(connState.reconnectTimer);
|
|
@@ -1217,7 +1248,7 @@ function gracefulShutdown(signal) {
|
|
|
1217
1248
|
if (connState.socket && connState.socket.readyState === WebSocket2.OPEN) {
|
|
1218
1249
|
connState.socket.close(1e3, "agent shutting down");
|
|
1219
1250
|
}
|
|
1220
|
-
setTimeout(() => process.exit(0),
|
|
1251
|
+
setTimeout(() => process.exit(0), 3e3);
|
|
1221
1252
|
}
|
|
1222
1253
|
process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
|
|
1223
1254
|
process.on("SIGINT", () => gracefulShutdown("SIGINT"));
|
|
@@ -1254,7 +1285,7 @@ if (isCli) {
|
|
|
1254
1285
|
getArgValue2 = getArgValue, resolveWorkspace3 = resolveWorkspace2, resolveAgentDir2 = resolveAgentDir, resolvePidFile2 = resolvePidFile, resolveLogDir2 = resolveLogDir, applyCliArgsToEnv2 = applyCliArgsToEnv;
|
|
1255
1286
|
const args = process.argv.slice(2);
|
|
1256
1287
|
if (args.includes("--version") || args.includes("-v")) {
|
|
1257
|
-
console.log("0.3.
|
|
1288
|
+
console.log("0.3.6");
|
|
1258
1289
|
process.exit(0);
|
|
1259
1290
|
}
|
|
1260
1291
|
if (args.includes("--help") || args.includes("-h")) {
|
|
@@ -1291,20 +1322,22 @@ if (isCli) {
|
|
|
1291
1322
|
} else {
|
|
1292
1323
|
const subcommand = args[0];
|
|
1293
1324
|
if (subcommand === "start" || subcommand === "restart") {
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1325
|
+
applyCliArgsToEnv();
|
|
1326
|
+
if (!process.env.__AI_TEAMS_DAEMON_WATCHDOG && !process.env.__AI_TEAMS_DAEMON_WORKER) {
|
|
1327
|
+
if (subcommand === "restart") {
|
|
1328
|
+
const pidFile = resolvePidFile();
|
|
1329
|
+
const status = getDaemonStatus(pidFile);
|
|
1330
|
+
if (status.running) {
|
|
1331
|
+
void stopDaemon(pidFile);
|
|
1332
|
+
}
|
|
1333
|
+
} else {
|
|
1334
|
+
const status = getDaemonStatus(resolvePidFile());
|
|
1335
|
+
if (status.running) {
|
|
1336
|
+
console.log(`Already running (PID ${status.pid}).`);
|
|
1337
|
+
process.exit(0);
|
|
1338
|
+
}
|
|
1305
1339
|
}
|
|
1306
1340
|
}
|
|
1307
|
-
applyCliArgsToEnv();
|
|
1308
1341
|
const fileConfig2 = loadConfigFile();
|
|
1309
1342
|
const hasEnvConfig = process.env.AI_TEAMS_AUTH_TOKEN || process.env.SERVER_URL;
|
|
1310
1343
|
if (!fileConfig2 && !hasEnvConfig) {
|
|
@@ -1319,6 +1352,8 @@ if (isCli) {
|
|
|
1319
1352
|
run: async () => {
|
|
1320
1353
|
console.log(" \u2713 \u6B63\u5728\u8FDE\u63A5\u670D\u52A1\u5668...");
|
|
1321
1354
|
connect2();
|
|
1355
|
+
return new Promise(() => {
|
|
1356
|
+
});
|
|
1322
1357
|
}
|
|
1323
1358
|
});
|
|
1324
1359
|
})();
|
|
@@ -1355,6 +1390,7 @@ if (isCli) {
|
|
|
1355
1390
|
await runSetup(null);
|
|
1356
1391
|
}
|
|
1357
1392
|
applyCliArgsToEnv();
|
|
1393
|
+
reinitializeConfig();
|
|
1358
1394
|
console.log(" \u2713 \u6B63\u5728\u8FDE\u63A5\u670D\u52A1\u5668...");
|
|
1359
1395
|
connect2();
|
|
1360
1396
|
})();
|