@agent-dock/cli 0.3.14 → 0.3.15
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/cli.js +248 -172
- package/dist/cli.js.map +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -979,11 +979,11 @@ var init_sdk = __esm({
|
|
|
979
979
|
|
|
980
980
|
// src/abortable.ts
|
|
981
981
|
function abortable(operation, signal) {
|
|
982
|
-
return new Promise((
|
|
982
|
+
return new Promise((resolve17, reject2) => {
|
|
983
983
|
const abort = () => reject2(signal.reason);
|
|
984
984
|
if (signal.aborted) abort();
|
|
985
985
|
else signal.addEventListener("abort", abort, { once: true });
|
|
986
|
-
operation.then(
|
|
986
|
+
operation.then(resolve17, reject2).finally(() => signal.removeEventListener("abort", abort));
|
|
987
987
|
});
|
|
988
988
|
}
|
|
989
989
|
var init_abortable = __esm({
|
|
@@ -994,7 +994,7 @@ var init_abortable = __esm({
|
|
|
994
994
|
|
|
995
995
|
// src/daemon/time.ts
|
|
996
996
|
function sleep(ms) {
|
|
997
|
-
return new Promise((
|
|
997
|
+
return new Promise((resolve17) => setTimeout(resolve17, ms));
|
|
998
998
|
}
|
|
999
999
|
var init_time = __esm({
|
|
1000
1000
|
"src/daemon/time.ts"() {
|
|
@@ -2333,7 +2333,7 @@ var init_message_content = __esm({
|
|
|
2333
2333
|
|
|
2334
2334
|
// src/lark/config.ts
|
|
2335
2335
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
2336
|
-
import { isAbsolute as
|
|
2336
|
+
import { isAbsolute as isAbsolute3 } from "node:path";
|
|
2337
2337
|
function normalizeStoredConfig(parsed) {
|
|
2338
2338
|
if (!parsed.appId || !parsed.appSecret) return void 0;
|
|
2339
2339
|
const pushIntervalMs = Number(parsed.pushIntervalMs ?? defaultLarkPushIntervalMs);
|
|
@@ -2466,7 +2466,7 @@ async function saveLarkConfigAttempt(repository, agents, input) {
|
|
|
2466
2466
|
if (!appSecret) throw new LarkServiceError("INVALID_LARK_CONFIG", "App Secret is required", 400);
|
|
2467
2467
|
if (input.stage === "agent" && !defaultAgentId) throw new LarkServiceError("INVALID_LARK_CONFIG", "Default Agent is required", 400);
|
|
2468
2468
|
if (current?.hardGateEnabled && defaultAgentId !== current.defaultAgentId) throw new LarkServiceError("HARD_GATE_AGENT_LOCKED", "Disable and save the hard gate before changing the default Agent", 409);
|
|
2469
|
-
if (workspace && !
|
|
2469
|
+
if (workspace && !isAbsolute3(workspace)) throw new LarkServiceError("INVALID_LARK_CONFIG", "Workspace must be an absolute path", 400);
|
|
2470
2470
|
if (!Number.isInteger(pushIntervalMs) || pushIntervalMs < 500 || pushIntervalMs > 2e4) throw new LarkServiceError("INVALID_LARK_CONFIG", "Push interval must be an integer between 500 and 20000 milliseconds", 400);
|
|
2471
2471
|
if (!Number.isInteger(traceLimit) || traceLimit < 1) throw new LarkServiceError("INVALID_LARK_CONFIG", "Trace limit must be a positive integer", 400);
|
|
2472
2472
|
const patternValidation = validateHighRiskPattern(highRiskPattern);
|
|
@@ -2719,7 +2719,7 @@ var init_access_config = __esm({
|
|
|
2719
2719
|
// src/lark/agent-tools.ts
|
|
2720
2720
|
import { createHmac as createHmac2, randomBytes as randomBytes2, randomUUID as randomUUID4 } from "node:crypto";
|
|
2721
2721
|
import { readFile as readFile3, stat as stat2 } from "node:fs/promises";
|
|
2722
|
-
import { isAbsolute as
|
|
2722
|
+
import { isAbsolute as isAbsolute4, resolve as resolve6 } from "node:path";
|
|
2723
2723
|
function larkAgentSessionBinding(session) {
|
|
2724
2724
|
if (session.source !== "lark" || !session.sourceId) return;
|
|
2725
2725
|
const parts = session.sourceId.split(":");
|
|
@@ -3203,7 +3203,7 @@ ${prompt}`;
|
|
|
3203
3203
|
if (result.messages.length) return result;
|
|
3204
3204
|
const remaining = deadline - Date.now();
|
|
3205
3205
|
if (remaining <= 0) return { ...result, timedOut: true };
|
|
3206
|
-
await new Promise((
|
|
3206
|
+
await new Promise((resolve17) => setTimeout(resolve17, Math.min(this.pollIntervalMs, remaining)));
|
|
3207
3207
|
}
|
|
3208
3208
|
}
|
|
3209
3209
|
/**
|
|
@@ -3248,7 +3248,7 @@ ${prompt}`;
|
|
|
3248
3248
|
const name = (trimmed.split("/").pop() || "").split("?")[0] || filenameHint;
|
|
3249
3249
|
return { bytes: buffer, filename: name };
|
|
3250
3250
|
}
|
|
3251
|
-
const filePath =
|
|
3251
|
+
const filePath = isAbsolute4(trimmed) ? trimmed : baseDir ? resolve6(baseDir, trimmed) : trimmed;
|
|
3252
3252
|
try {
|
|
3253
3253
|
const info = await stat2(filePath);
|
|
3254
3254
|
if (!info.isFile()) throw new Error("not a file");
|
|
@@ -3360,7 +3360,7 @@ ${prompt}`;
|
|
|
3360
3360
|
};
|
|
3361
3361
|
shellQuote2 = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
3362
3362
|
agentDockGroupToolsCommand = (entrypoint, execPath = process.execPath, tsxLoader) => {
|
|
3363
|
-
const absoluteEntrypoint =
|
|
3363
|
+
const absoluteEntrypoint = resolve6(entrypoint);
|
|
3364
3364
|
const loader = absoluteEntrypoint.endsWith(".ts") ? tsxLoader ?? import.meta.resolve("tsx") : void 0;
|
|
3365
3365
|
return `${shellQuote2(execPath)}${loader ? ` --import ${shellQuote2(loader)}` : ""} ${shellQuote2(absoluteEntrypoint)}`;
|
|
3366
3366
|
};
|
|
@@ -4174,8 +4174,8 @@ ${truncate(entry.data.message ?? "Agent \u6267\u884C\u672A\u5B8C\u5168\u6210\u52
|
|
|
4174
4174
|
try {
|
|
4175
4175
|
const names = await Promise.race([
|
|
4176
4176
|
pending,
|
|
4177
|
-
new Promise((
|
|
4178
|
-
timer = setTimeout(() =>
|
|
4177
|
+
new Promise((resolve17) => {
|
|
4178
|
+
timer = setTimeout(() => resolve17(void 0), chatNamesTimeoutMs);
|
|
4179
4179
|
})
|
|
4180
4180
|
]);
|
|
4181
4181
|
if (names) {
|
|
@@ -4347,7 +4347,7 @@ ${truncate(entry.data.message ?? "Agent \u6267\u884C\u672A\u5B8C\u5168\u6210\u52
|
|
|
4347
4347
|
}
|
|
4348
4348
|
if (attempt < 3) {
|
|
4349
4349
|
const delay = isLarkMessageRateLimit(error) ? larkRateLimitBackoffMs(attempt) : attempt * 300;
|
|
4350
|
-
await new Promise((
|
|
4350
|
+
await new Promise((resolve17) => setTimeout(resolve17, delay));
|
|
4351
4351
|
}
|
|
4352
4352
|
}
|
|
4353
4353
|
}
|
|
@@ -4906,7 +4906,7 @@ ${error instanceof Error ? error.message : String(error)}`;
|
|
|
4906
4906
|
this.log.warn({ error, messageId: pending.input.messageId, attempt, attempts }, "\u66F4\u65B0\u98DE\u4E66\u670D\u52A1\u5361\u7247\u5931\u8D25");
|
|
4907
4907
|
if (attempt < attempts) {
|
|
4908
4908
|
const retryDelay = isLarkMessageRateLimit(error) ? Math.max(0, cardRateLimitedUntil - Date.now()) : attempt * 300;
|
|
4909
|
-
await new Promise((
|
|
4909
|
+
await new Promise((resolve17) => setTimeout(resolve17, retryDelay));
|
|
4910
4910
|
}
|
|
4911
4911
|
}
|
|
4912
4912
|
}
|
|
@@ -5027,7 +5027,7 @@ ${error instanceof Error ? error.message : String(error)}`;
|
|
|
5027
5027
|
if (attempt < maxQuietReplyAttempts) {
|
|
5028
5028
|
const delay = isLarkMessageRateLimit(error) ? larkRateLimitBackoffMs(attempt) : attempt * 500;
|
|
5029
5029
|
this.log.warn({ error, attempt, chatId: event.chatId, messageId: event.messageId }, "\u53D1\u9001\u9759\u9ED8\u7EC8\u6001\u56DE\u590D\u5931\u8D25\uFF0C\u51C6\u5907\u91CD\u8BD5");
|
|
5030
|
-
await new Promise((
|
|
5030
|
+
await new Promise((resolve17) => setTimeout(resolve17, delay));
|
|
5031
5031
|
}
|
|
5032
5032
|
}
|
|
5033
5033
|
}
|
|
@@ -5708,13 +5708,13 @@ __export(session_cli_exports, {
|
|
|
5708
5708
|
streamSessionShow: () => streamSessionShow
|
|
5709
5709
|
});
|
|
5710
5710
|
import { existsSync as existsSync9 } from "node:fs";
|
|
5711
|
-
import { join as join20, resolve as
|
|
5711
|
+
import { join as join20, resolve as resolve12 } from "node:path";
|
|
5712
5712
|
function resolveDatabasePath(explicit, cwd = process.cwd()) {
|
|
5713
|
-
if (explicit) return
|
|
5714
|
-
if (process.env.AGENTDOCK_DATABASE_URL) return
|
|
5713
|
+
if (explicit) return resolve12(cwd, explicit);
|
|
5714
|
+
if (process.env.AGENTDOCK_DATABASE_URL) return resolve12(cwd, process.env.AGENTDOCK_DATABASE_URL);
|
|
5715
5715
|
const daemonDir = resolveDaemonDir(cwd);
|
|
5716
5716
|
const recorded = readDaemonStatus(daemonDir)?.database;
|
|
5717
|
-
return recorded ?
|
|
5717
|
+
return recorded ? resolve12(daemonDir, recorded) : join20(daemonDir, "..", "agentdock.db");
|
|
5718
5718
|
}
|
|
5719
5719
|
function sessionPeerIds(sessions2, sourceId2) {
|
|
5720
5720
|
const source2 = sessions2.find((session) => session.id === sourceId2);
|
|
@@ -5963,7 +5963,7 @@ var AutostartService = class {
|
|
|
5963
5963
|
|
|
5964
5964
|
// src/cli.ts
|
|
5965
5965
|
init_src();
|
|
5966
|
-
import { existsSync as existsSync12, readFileSync as
|
|
5966
|
+
import { existsSync as existsSync12, readFileSync as readFileSync16 } from "node:fs";
|
|
5967
5967
|
import { spawn as spawn13 } from "node:child_process";
|
|
5968
5968
|
import { loadEnvFile } from "node:process";
|
|
5969
5969
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
@@ -6359,8 +6359,8 @@ var KeepAwakeService = class {
|
|
|
6359
6359
|
const child = (this.options.spawn ?? spawn2)(this.caffeinatePath, this.args(), { stdio: "ignore" });
|
|
6360
6360
|
this.child = child;
|
|
6361
6361
|
try {
|
|
6362
|
-
await new Promise((
|
|
6363
|
-
child.once("spawn",
|
|
6362
|
+
await new Promise((resolve17, reject2) => {
|
|
6363
|
+
child.once("spawn", resolve17);
|
|
6364
6364
|
child.once("error", reject2);
|
|
6365
6365
|
});
|
|
6366
6366
|
} catch (error) {
|
|
@@ -6467,8 +6467,8 @@ async function resolveProjectPath(raw, options = {}) {
|
|
|
6467
6467
|
init_src2();
|
|
6468
6468
|
|
|
6469
6469
|
// ../../packages/acp-client/src/index.ts
|
|
6470
|
-
import { dirname as dirname6, join as join6 } from "node:path";
|
|
6471
|
-
import { existsSync as existsSync6 } from "node:fs";
|
|
6470
|
+
import { delimiter, dirname as dirname6, extname, isAbsolute as isAbsolute2, join as join6, resolve as resolve3 } from "node:path";
|
|
6471
|
+
import { accessSync, constants as constants2, existsSync as existsSync6, statSync as statSync3 } from "node:fs";
|
|
6472
6472
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
6473
6473
|
|
|
6474
6474
|
// ../../node_modules/.pnpm/acpx@0.20.0_patch_hash=34d804a05175c628ad9877f34a2db2f24bdce786dbb98bacb313e7559b2ca416/node_modules/acpx/dist/agent-registry-Gtwn7nMp.js
|
|
@@ -6480,7 +6480,7 @@ var PROCESS_HELPER_TIMEOUT_MS = 8e3;
|
|
|
6480
6480
|
var PROCESS_HELPER_MAX_BUFFER_BYTES = 33554432;
|
|
6481
6481
|
async function runTimedExecFile(command, args, options = {}) {
|
|
6482
6482
|
const timeoutMs = Math.max(1, Math.round(options.timeoutMs ?? 8e3));
|
|
6483
|
-
return await new Promise((
|
|
6483
|
+
return await new Promise((resolve17, reject2) => {
|
|
6484
6484
|
let settled = false;
|
|
6485
6485
|
let timer;
|
|
6486
6486
|
const child = execFile2(command, [...args], {
|
|
@@ -6497,7 +6497,7 @@ async function runTimedExecFile(command, args, options = {}) {
|
|
|
6497
6497
|
reject2(error);
|
|
6498
6498
|
return;
|
|
6499
6499
|
}
|
|
6500
|
-
|
|
6500
|
+
resolve17(stdout);
|
|
6501
6501
|
});
|
|
6502
6502
|
timer = setTimeout(() => {
|
|
6503
6503
|
if (settled) return;
|
|
@@ -6531,10 +6531,10 @@ function isoNow() {
|
|
|
6531
6531
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
6532
6532
|
}
|
|
6533
6533
|
function waitForSpawn(child) {
|
|
6534
|
-
return new Promise((
|
|
6534
|
+
return new Promise((resolve17, reject2) => {
|
|
6535
6535
|
const onSpawn = () => {
|
|
6536
6536
|
child.off("error", onError);
|
|
6537
|
-
|
|
6537
|
+
resolve17();
|
|
6538
6538
|
};
|
|
6539
6539
|
const onError = (error) => {
|
|
6540
6540
|
child.off("spawn", onSpawn);
|
|
@@ -6553,7 +6553,7 @@ function requireAgentStdio(child) {
|
|
|
6553
6553
|
}
|
|
6554
6554
|
function waitForChildExit(child, timeoutMs) {
|
|
6555
6555
|
if (!isChildProcessRunning(child)) return Promise.resolve(true);
|
|
6556
|
-
return new Promise((
|
|
6556
|
+
return new Promise((resolve17) => {
|
|
6557
6557
|
let settled = false;
|
|
6558
6558
|
const timer = setTimeout(() => {
|
|
6559
6559
|
finish(false);
|
|
@@ -6564,7 +6564,7 @@ function waitForChildExit(child, timeoutMs) {
|
|
|
6564
6564
|
child.off("close", onExitLike);
|
|
6565
6565
|
child.off("exit", onExitLike);
|
|
6566
6566
|
clearTimeout(timer);
|
|
6567
|
-
|
|
6567
|
+
resolve17(value);
|
|
6568
6568
|
};
|
|
6569
6569
|
const onExitLike = () => {
|
|
6570
6570
|
finish(true);
|
|
@@ -7069,8 +7069,8 @@ function inspectAgent(agentId, override, options = {}) {
|
|
|
7069
7069
|
};
|
|
7070
7070
|
}
|
|
7071
7071
|
function inspectPrerequisites(launch, requiredCommands, options) {
|
|
7072
|
-
const
|
|
7073
|
-
const missingCommands = requiredCommands.filter((command) => !
|
|
7072
|
+
const resolveExecutable2 = options.resolveExecutable ?? resolveInstalledExecutable;
|
|
7073
|
+
const missingCommands = requiredCommands.filter((command) => !resolveExecutable2(command)).map((name) => ({
|
|
7074
7074
|
kind: "command",
|
|
7075
7075
|
name
|
|
7076
7076
|
}));
|
|
@@ -7174,12 +7174,12 @@ function resolveInstalledBuiltInAgentLaunch(agentCommand, options = {}) {
|
|
|
7174
7174
|
return resolveInstalledBuiltInAgentLaunchForSpec(spec, options);
|
|
7175
7175
|
}
|
|
7176
7176
|
function resolveInstalledBuiltInAgentLaunchForSpec(spec, options) {
|
|
7177
|
-
const
|
|
7177
|
+
const readFileSync17 = options.readFileSync ?? fs.readFileSync;
|
|
7178
7178
|
const existsSync13 = options.existsSync ?? fs.existsSync;
|
|
7179
7179
|
const resolvePackageRoot = options.resolvePackageRoot ?? defaultResolvePackageRoot;
|
|
7180
7180
|
try {
|
|
7181
7181
|
const resolved = resolveInstalledBuiltInAgentPackage(spec, {
|
|
7182
|
-
readFileSync:
|
|
7182
|
+
readFileSync: readFileSync17,
|
|
7183
7183
|
existsSync: existsSync13,
|
|
7184
7184
|
resolvePackageRoot
|
|
7185
7185
|
});
|
|
@@ -9015,7 +9015,7 @@ async function withTimeout(promise, timeoutMs) {
|
|
|
9015
9015
|
}
|
|
9016
9016
|
}
|
|
9017
9017
|
async function withInterrupt(run2, onInterrupt) {
|
|
9018
|
-
return await new Promise((
|
|
9018
|
+
return await new Promise((resolve17, reject2) => {
|
|
9019
9019
|
let settled = false;
|
|
9020
9020
|
const finish = (cb) => {
|
|
9021
9021
|
if (settled) return;
|
|
@@ -9040,7 +9040,7 @@ async function withInterrupt(run2, onInterrupt) {
|
|
|
9040
9040
|
process.once("SIGINT", onSigint);
|
|
9041
9041
|
process.once("SIGTERM", onSigterm);
|
|
9042
9042
|
process.once("SIGHUP", onSighup);
|
|
9043
|
-
run2().then((result) => finish(() =>
|
|
9043
|
+
run2().then((result) => finish(() => resolve17(result)), (error) => finish(() => reject2(error)));
|
|
9044
9044
|
});
|
|
9045
9045
|
}
|
|
9046
9046
|
function preferCodexPermissionRefusal(request, agentName) {
|
|
@@ -9116,8 +9116,8 @@ async function askPermission(options) {
|
|
|
9116
9116
|
const signal = options.signal ? AbortSignal.any([options.signal, questionController.signal]) : questionController.signal;
|
|
9117
9117
|
let onClose = () => {
|
|
9118
9118
|
};
|
|
9119
|
-
const closed = new Promise((
|
|
9120
|
-
onClose = () =>
|
|
9119
|
+
const closed = new Promise((resolve17) => {
|
|
9120
|
+
onClose = () => resolve17(void 0);
|
|
9121
9121
|
rl.once("close", onClose);
|
|
9122
9122
|
});
|
|
9123
9123
|
try {
|
|
@@ -9945,8 +9945,8 @@ function captureCommandProbeOutput(child, timeoutMs, retire) {
|
|
|
9945
9945
|
let disposed = false;
|
|
9946
9946
|
let timer;
|
|
9947
9947
|
let resolveResult;
|
|
9948
|
-
const result = new Promise((
|
|
9949
|
-
resolveResult =
|
|
9948
|
+
const result = new Promise((resolve17) => {
|
|
9949
|
+
resolveResult = resolve17;
|
|
9950
9950
|
});
|
|
9951
9951
|
const finish = (value) => {
|
|
9952
9952
|
if (settled) return;
|
|
@@ -10365,8 +10365,8 @@ function canPromptForPermission() {
|
|
|
10365
10365
|
return process.stdin.isTTY && process.stderr.isTTY;
|
|
10366
10366
|
}
|
|
10367
10367
|
function waitMs2(ms) {
|
|
10368
|
-
return new Promise((
|
|
10369
|
-
setTimeout(
|
|
10368
|
+
return new Promise((resolve17) => {
|
|
10369
|
+
setTimeout(resolve17, Math.max(0, ms));
|
|
10370
10370
|
});
|
|
10371
10371
|
}
|
|
10372
10372
|
function onStreamError() {
|
|
@@ -10425,8 +10425,8 @@ var TerminalManager = class {
|
|
|
10425
10425
|
const { proc, spawnCommand } = await spawnTerminalProcess(params, this.cwd, authority);
|
|
10426
10426
|
let resolveExit = () => {
|
|
10427
10427
|
};
|
|
10428
|
-
const exitPromise = new Promise((
|
|
10429
|
-
resolveExit =
|
|
10428
|
+
const exitPromise = new Promise((resolve17) => {
|
|
10429
|
+
resolveExit = resolve17;
|
|
10430
10430
|
});
|
|
10431
10431
|
const terminal = {
|
|
10432
10432
|
process: proc,
|
|
@@ -10859,8 +10859,8 @@ function elicitationRequestScopeId(request) {
|
|
|
10859
10859
|
}
|
|
10860
10860
|
async function raceWithAbort(signal, pending) {
|
|
10861
10861
|
let onAbort;
|
|
10862
|
-
const aborted = new Promise((
|
|
10863
|
-
onAbort = () =>
|
|
10862
|
+
const aborted = new Promise((resolve17) => {
|
|
10863
|
+
onAbort = () => resolve17(void 0);
|
|
10864
10864
|
if (signal.aborted) onAbort();
|
|
10865
10865
|
else signal.addEventListener("abort", onAbort, { once: true });
|
|
10866
10866
|
});
|
|
@@ -11323,8 +11323,8 @@ var AcpClient = class {
|
|
|
11323
11323
|
async admitSpawnedProcess(child, observe, admit) {
|
|
11324
11324
|
let releaseExitNotification = () => {
|
|
11325
11325
|
};
|
|
11326
|
-
observe(new Promise((
|
|
11327
|
-
releaseExitNotification =
|
|
11326
|
+
observe(new Promise((resolve17) => {
|
|
11327
|
+
releaseExitNotification = resolve17;
|
|
11328
11328
|
}));
|
|
11329
11329
|
try {
|
|
11330
11330
|
await admit();
|
|
@@ -11704,8 +11704,8 @@ var AcpClient = class {
|
|
|
11704
11704
|
const activePromise = active.promise;
|
|
11705
11705
|
if (!activePromise) return;
|
|
11706
11706
|
let timer;
|
|
11707
|
-
const timeoutPromise = new Promise((
|
|
11708
|
-
timer = setTimeout(
|
|
11707
|
+
const timeoutPromise = new Promise((resolve17) => {
|
|
11708
|
+
timer = setTimeout(resolve17, waitMs3);
|
|
11709
11709
|
});
|
|
11710
11710
|
try {
|
|
11711
11711
|
return await Promise.race([activePromise.then((response) => response, () => void 0), timeoutPromise]);
|
|
@@ -12225,7 +12225,7 @@ var AcpClient = class {
|
|
|
12225
12225
|
return error;
|
|
12226
12226
|
}
|
|
12227
12227
|
async runConnectionRequest(run2, authority, mapRequestError) {
|
|
12228
|
-
return await new Promise((
|
|
12228
|
+
return await new Promise((resolve17, reject2) => {
|
|
12229
12229
|
const rejectRequestError = (error) => {
|
|
12230
12230
|
try {
|
|
12231
12231
|
reject2(mapRequestError ? mapRequestError(error) : error);
|
|
@@ -12257,7 +12257,7 @@ var AcpClient = class {
|
|
|
12257
12257
|
value: await run2()
|
|
12258
12258
|
};
|
|
12259
12259
|
}).then((outcome) => {
|
|
12260
|
-
if (outcome.started) finish(() =>
|
|
12260
|
+
if (outcome.started) finish(() => resolve17(outcome.value));
|
|
12261
12261
|
}, (error) => finish(() => rejectRequestError(error)));
|
|
12262
12262
|
});
|
|
12263
12263
|
}
|
|
@@ -12362,8 +12362,8 @@ var AcpClient = class {
|
|
|
12362
12362
|
await this.sessionUpdateChain;
|
|
12363
12363
|
if (this.processedSessionUpdates === this.observedSessionUpdates) return;
|
|
12364
12364
|
}
|
|
12365
|
-
await new Promise((
|
|
12366
|
-
setTimeout(
|
|
12365
|
+
await new Promise((resolve17) => {
|
|
12366
|
+
setTimeout(resolve17, DRAIN_POLL_INTERVAL_MS);
|
|
12367
12367
|
});
|
|
12368
12368
|
}
|
|
12369
12369
|
throw new Error(`Timed out waiting for session replay drain after ${normalizedTimeoutMs}ms`);
|
|
@@ -14613,14 +14613,14 @@ function commandRecord(value) {
|
|
|
14613
14613
|
return value;
|
|
14614
14614
|
}
|
|
14615
14615
|
function createDeferred() {
|
|
14616
|
-
let
|
|
14616
|
+
let resolve17;
|
|
14617
14617
|
let reject2;
|
|
14618
14618
|
return {
|
|
14619
14619
|
promise: new Promise((res, rej) => {
|
|
14620
|
-
|
|
14620
|
+
resolve17 = res;
|
|
14621
14621
|
reject2 = rej;
|
|
14622
14622
|
}),
|
|
14623
|
-
resolve:
|
|
14623
|
+
resolve: resolve17,
|
|
14624
14624
|
reject: reject2
|
|
14625
14625
|
};
|
|
14626
14626
|
}
|
|
@@ -15198,8 +15198,8 @@ var AcpRuntimeManager = class {
|
|
|
15198
15198
|
async serializeManagerOperation(locks, key, run2) {
|
|
15199
15199
|
const previous = locks.get(key) ?? Promise.resolve();
|
|
15200
15200
|
let release;
|
|
15201
|
-
const gate = new Promise((
|
|
15202
|
-
release =
|
|
15201
|
+
const gate = new Promise((resolve17) => {
|
|
15202
|
+
release = resolve17;
|
|
15203
15203
|
});
|
|
15204
15204
|
const tail2 = previous.then(() => gate);
|
|
15205
15205
|
locks.set(key, tail2);
|
|
@@ -16423,7 +16423,7 @@ try {
|
|
|
16423
16423
|
}
|
|
16424
16424
|
`;
|
|
16425
16425
|
function testRegexWithTimeout(pattern, input, timeoutMs = 1e3) {
|
|
16426
|
-
return new Promise((
|
|
16426
|
+
return new Promise((resolve17, reject2) => {
|
|
16427
16427
|
const worker = new Worker(workerSource, { eval: true, workerData: { pattern, input } });
|
|
16428
16428
|
let settled = false;
|
|
16429
16429
|
const finish = (callback) => {
|
|
@@ -16435,7 +16435,7 @@ function testRegexWithTimeout(pattern, input, timeoutMs = 1e3) {
|
|
|
16435
16435
|
callback();
|
|
16436
16436
|
};
|
|
16437
16437
|
const timer = setTimeout(() => finish(() => reject2(new RegexMatchTimeoutError(timeoutMs))), timeoutMs);
|
|
16438
|
-
worker.once("message", (result) => finish(() => result.error ? reject2(new Error(`\u6B63\u5219\u5339\u914D\u5931\u8D25\uFF1A${result.error}`)) :
|
|
16438
|
+
worker.once("message", (result) => finish(() => result.error ? reject2(new Error(`\u6B63\u5219\u5339\u914D\u5931\u8D25\uFF1A${result.error}`)) : resolve17(result.matched === true)));
|
|
16439
16439
|
worker.once("error", (error) => finish(() => reject2(error)));
|
|
16440
16440
|
worker.once("exit", (code) => {
|
|
16441
16441
|
if (code !== 0) finish(() => reject2(new Error(`\u6B63\u5219\u5339\u914D\u9694\u79BB\u4EFB\u52A1\u5F02\u5E38\u9000\u51FA\uFF1A${code}`)));
|
|
@@ -16683,10 +16683,10 @@ async function terminateExternalChild(child, graceMs = 5e3) {
|
|
|
16683
16683
|
} catch {
|
|
16684
16684
|
}
|
|
16685
16685
|
if (child.exitCode !== null || child.signalCode !== null) return;
|
|
16686
|
-
await new Promise((
|
|
16686
|
+
await new Promise((resolve17) => {
|
|
16687
16687
|
const done = () => {
|
|
16688
16688
|
clearTimeout(timer);
|
|
16689
|
-
|
|
16689
|
+
resolve17();
|
|
16690
16690
|
};
|
|
16691
16691
|
const timer = setTimeout(() => {
|
|
16692
16692
|
if (child.exitCode === null) child.kill("SIGKILL");
|
|
@@ -16762,6 +16762,45 @@ function wrapAgentForSsh(agent, host, remoteCwd, options = {}) {
|
|
|
16762
16762
|
}
|
|
16763
16763
|
|
|
16764
16764
|
// ../../packages/acp-client/src/index.ts
|
|
16765
|
+
function isExecutableFile(file, platform2) {
|
|
16766
|
+
try {
|
|
16767
|
+
if (!statSync3(file).isFile()) return false;
|
|
16768
|
+
if (platform2 !== "win32") accessSync(file, constants2.X_OK);
|
|
16769
|
+
return true;
|
|
16770
|
+
} catch {
|
|
16771
|
+
return false;
|
|
16772
|
+
}
|
|
16773
|
+
}
|
|
16774
|
+
function resolveExecutable(command, options = {}) {
|
|
16775
|
+
const env = options.env ?? process.env;
|
|
16776
|
+
const platform2 = options.platform ?? process.platform;
|
|
16777
|
+
const candidates = platform2 === "win32" && !extname(command) ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
|
|
16778
|
+
const hasPathSeparator = command.includes("/") || command.includes("\\");
|
|
16779
|
+
if (hasPathSeparator || isAbsolute2(command)) {
|
|
16780
|
+
const absolute = resolve3(command);
|
|
16781
|
+
for (const extension of candidates) {
|
|
16782
|
+
const candidate = `${absolute}${extension}`;
|
|
16783
|
+
if (isExecutableFile(candidate, platform2)) return candidate;
|
|
16784
|
+
}
|
|
16785
|
+
return void 0;
|
|
16786
|
+
}
|
|
16787
|
+
const pathValue = env.PATH ?? env.Path ?? "";
|
|
16788
|
+
for (const directory of pathValue.split(delimiter).filter(Boolean)) {
|
|
16789
|
+
for (const extension of candidates) {
|
|
16790
|
+
const candidate = resolve3(directory, `${command}${extension}`);
|
|
16791
|
+
if (isExecutableFile(candidate, platform2)) return candidate;
|
|
16792
|
+
}
|
|
16793
|
+
}
|
|
16794
|
+
return void 0;
|
|
16795
|
+
}
|
|
16796
|
+
function antigravityArgv(argv, options) {
|
|
16797
|
+
for (const command of ["agy", "antigravity"]) {
|
|
16798
|
+
const executable = resolveExecutable(command, options);
|
|
16799
|
+
if (executable) return [executable, "acp"];
|
|
16800
|
+
}
|
|
16801
|
+
const legacy = argv[0] ? resolveExecutable(argv[0], options) : void 0;
|
|
16802
|
+
return legacy ? [legacy, ...argv.slice(1)] : argv;
|
|
16803
|
+
}
|
|
16765
16804
|
function agentLauncherPath(name) {
|
|
16766
16805
|
const moduleDirectory = dirname6(fileURLToPath4(import.meta.url));
|
|
16767
16806
|
const adjacent = join6(moduleDirectory, "agents", `${name}-acp.mjs`);
|
|
@@ -16773,13 +16812,14 @@ var flattenRiskText = (value, output3 = []) => {
|
|
|
16773
16812
|
else if (value && typeof value === "object") for (const item of Object.values(value)) flattenRiskText(item, output3);
|
|
16774
16813
|
return output3;
|
|
16775
16814
|
};
|
|
16776
|
-
function listAcpxBuiltinAgents() {
|
|
16815
|
+
function listAcpxBuiltinAgents(options = {}) {
|
|
16777
16816
|
const registry = createAgentRegistry();
|
|
16778
16817
|
return registry.list().map((id) => {
|
|
16779
16818
|
const command = registry.resolve(id);
|
|
16780
16819
|
if (id === "claude") return { id, argv: [process.execPath, agentLauncherPath("claude")] };
|
|
16781
16820
|
const argv = typeof command === "string" ? [command] : [...command];
|
|
16782
16821
|
if (id === "codex") return { id, argv: [process.execPath, agentLauncherPath("codex")] };
|
|
16822
|
+
if (id === "antigravity") return { id, argv: antigravityArgv(argv, options) };
|
|
16783
16823
|
return { id, argv };
|
|
16784
16824
|
});
|
|
16785
16825
|
}
|
|
@@ -16891,7 +16931,7 @@ var AcpxAdapter = class {
|
|
|
16891
16931
|
if (this.permissionMode === "deny-all") return { outcome: "reject_once" };
|
|
16892
16932
|
if (this.permissionMode === "approve-reads" && /read|search|fetch/i.test(String(request.inferredKind ?? ""))) return { outcome: "allow_once" };
|
|
16893
16933
|
this.options.onEvent({ type: "permission_request", data: { id, toolCallId: raw.toolCall?.toolCallId, title: raw.toolCall?.title ?? "Permission required", options: raw.options ?? [], status: "pending" } });
|
|
16894
|
-
return new Promise((
|
|
16934
|
+
return new Promise((resolve17) => this.pendingPermissions.set(id, resolve17));
|
|
16895
16935
|
}
|
|
16896
16936
|
});
|
|
16897
16937
|
}
|
|
@@ -17102,7 +17142,7 @@ var AcpxAdapter = class {
|
|
|
17102
17142
|
await this.start();
|
|
17103
17143
|
}
|
|
17104
17144
|
async stop(options = {}) {
|
|
17105
|
-
for (const
|
|
17145
|
+
for (const resolve17 of this.pendingPermissions.values()) resolve17({ outcome: "reject_once" });
|
|
17106
17146
|
this.pendingPermissions.clear();
|
|
17107
17147
|
const turn = this.turn;
|
|
17108
17148
|
if (turn) {
|
|
@@ -17118,10 +17158,10 @@ var AcpxAdapter = class {
|
|
|
17118
17158
|
if (options.discardSession) await this.resetPersistentState();
|
|
17119
17159
|
}
|
|
17120
17160
|
async resolvePermission(id, approved) {
|
|
17121
|
-
const
|
|
17122
|
-
if (!
|
|
17161
|
+
const resolve17 = this.pendingPermissions.get(id);
|
|
17162
|
+
if (!resolve17) return false;
|
|
17123
17163
|
this.pendingPermissions.delete(id);
|
|
17124
|
-
|
|
17164
|
+
resolve17({ outcome: approved ? "allow_once" : "reject_once" });
|
|
17125
17165
|
return true;
|
|
17126
17166
|
}
|
|
17127
17167
|
async setModel(model) {
|
|
@@ -18040,7 +18080,7 @@ var AgentDockRuntime = class _AgentDockRuntime {
|
|
|
18040
18080
|
return await driver.start();
|
|
18041
18081
|
} catch (error) {
|
|
18042
18082
|
if (!this.resumeOptions(session) || attempt >= 4 || !mentionsActiveWriter(error)) throw error;
|
|
18043
|
-
await new Promise((
|
|
18083
|
+
await new Promise((resolve17) => setTimeout(resolve17, 1500));
|
|
18044
18084
|
}
|
|
18045
18085
|
}
|
|
18046
18086
|
}
|
|
@@ -18143,7 +18183,7 @@ var AgentDockRuntime = class _AgentDockRuntime {
|
|
|
18143
18183
|
this.activeTurns.delete(id);
|
|
18144
18184
|
this.activeTasks.delete(id);
|
|
18145
18185
|
this.touch(id);
|
|
18146
|
-
for (const
|
|
18186
|
+
for (const resolve17 of this.turnWaiters.get(id) ?? []) resolve17();
|
|
18147
18187
|
this.turnWaiters.delete(id);
|
|
18148
18188
|
if (!hardInterrupted) this.scheduleQueue(id);
|
|
18149
18189
|
}
|
|
@@ -18201,9 +18241,9 @@ var AgentDockRuntime = class _AgentDockRuntime {
|
|
|
18201
18241
|
}
|
|
18202
18242
|
let timer;
|
|
18203
18243
|
try {
|
|
18204
|
-
return await new Promise((
|
|
18205
|
-
timer = setTimeout(() =>
|
|
18206
|
-
void turn.then(() =>
|
|
18244
|
+
return await new Promise((resolve17) => {
|
|
18245
|
+
timer = setTimeout(() => resolve17(true), timeoutMs);
|
|
18246
|
+
void turn.then(() => resolve17(false));
|
|
18207
18247
|
});
|
|
18208
18248
|
} finally {
|
|
18209
18249
|
if (timer) clearTimeout(timer);
|
|
@@ -18424,9 +18464,9 @@ var AgentDockRuntime = class _AgentDockRuntime {
|
|
|
18424
18464
|
}
|
|
18425
18465
|
waitForTurn(id) {
|
|
18426
18466
|
if (!this.activeTurns.has(id)) return Promise.resolve();
|
|
18427
|
-
return new Promise((
|
|
18467
|
+
return new Promise((resolve17) => {
|
|
18428
18468
|
const waiters = this.turnWaiters.get(id) ?? /* @__PURE__ */ new Set();
|
|
18429
|
-
waiters.add(
|
|
18469
|
+
waiters.add(resolve17);
|
|
18430
18470
|
this.turnWaiters.set(id, waiters);
|
|
18431
18471
|
});
|
|
18432
18472
|
}
|
|
@@ -18544,7 +18584,7 @@ var AgentDockRuntime = class _AgentDockRuntime {
|
|
|
18544
18584
|
this.queuedAgentPrompts.delete(sessionId);
|
|
18545
18585
|
this.queuedRiskPolicies.delete(sessionId);
|
|
18546
18586
|
this.queueRuns.delete(sessionId);
|
|
18547
|
-
for (const
|
|
18587
|
+
for (const resolve17 of this.turnWaiters.get(sessionId) ?? []) resolve17();
|
|
18548
18588
|
this.turnWaiters.delete(sessionId);
|
|
18549
18589
|
for (const key of this.permissions.keys()) if (key.startsWith(`${sessionId}:`)) this.permissions.delete(key);
|
|
18550
18590
|
}
|
|
@@ -18593,7 +18633,7 @@ var AgentDockRuntime = class _AgentDockRuntime {
|
|
|
18593
18633
|
this.driverEventChains.clear();
|
|
18594
18634
|
this.driverEventErrors.clear();
|
|
18595
18635
|
this.openToolCalls.clear();
|
|
18596
|
-
for (const waiters of this.turnWaiters.values()) for (const
|
|
18636
|
+
for (const waiters of this.turnWaiters.values()) for (const resolve17 of waiters) resolve17();
|
|
18597
18637
|
this.turnWaiters.clear();
|
|
18598
18638
|
this.queues.clear();
|
|
18599
18639
|
this.queuedAgentPrompts.clear();
|
|
@@ -18607,7 +18647,7 @@ var AgentDockRuntime = class _AgentDockRuntime {
|
|
|
18607
18647
|
init_src2();
|
|
18608
18648
|
import { z as z3 } from "zod";
|
|
18609
18649
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
18610
|
-
import { resolve as
|
|
18650
|
+
import { resolve as resolve4 } from "node:path";
|
|
18611
18651
|
var appConfigSchema = z3.object({
|
|
18612
18652
|
host: z3.string().default("0.0.0.0"),
|
|
18613
18653
|
port: z3.number().int().positive().default(4310),
|
|
@@ -18641,7 +18681,8 @@ var agentDetails = {
|
|
|
18641
18681
|
qoder: { name: "Qoder", cli: "qodercli" },
|
|
18642
18682
|
qwen: { name: "Qwen Code", cli: "qwen" },
|
|
18643
18683
|
trae: { name: "Trae", cli: "traecli" },
|
|
18644
|
-
zeroclaw: { name: "ZeroClaw", cli: "zeroclaw" }
|
|
18684
|
+
zeroclaw: { name: "ZeroClaw", cli: "zeroclaw" },
|
|
18685
|
+
antigravity: { name: "Google Antigravity", cli: ["agy", "antigravity"], argvExecutable: true }
|
|
18645
18686
|
};
|
|
18646
18687
|
function cliVersion(command, prefixArgs = []) {
|
|
18647
18688
|
for (const args of [["--version"], ["-V"], ["version"]]) {
|
|
@@ -18653,15 +18694,35 @@ ${result.stderr ?? ""}`.split(/\r?\n/).map((value) => value.trim()).find(Boolean
|
|
|
18653
18694
|
return void 0;
|
|
18654
18695
|
}
|
|
18655
18696
|
var scannedBuiltinAgents;
|
|
18656
|
-
|
|
18657
|
-
const
|
|
18658
|
-
|
|
18659
|
-
return
|
|
18660
|
-
|
|
18697
|
+
function discoverBuiltinAgents(entries = listAcpxBuiltinAgents(), dependencies = {}) {
|
|
18698
|
+
const exists = dependencies.commandExists ?? commandExists;
|
|
18699
|
+
const version = dependencies.cliVersion ?? cliVersion;
|
|
18700
|
+
return entries.flatMap(({ id, argv }) => {
|
|
18701
|
+
const detail = agentDetails[id];
|
|
18702
|
+
if (!detail) return [];
|
|
18703
|
+
const commands = Array.isArray(detail.cli) ? detail.cli : [detail.cli];
|
|
18704
|
+
const installed = commands.some(exists) || Boolean(detail.argvExecutable && argv[0] && exists(argv[0]));
|
|
18705
|
+
if (!installed) return [];
|
|
18706
|
+
return [{
|
|
18707
|
+
id,
|
|
18708
|
+
name: detail.name,
|
|
18709
|
+
command: argv[0],
|
|
18710
|
+
args: argv.slice(1),
|
|
18711
|
+
protocol: "acp",
|
|
18712
|
+
env: {},
|
|
18713
|
+
permissionMode: "full-trust",
|
|
18714
|
+
timeout: 600,
|
|
18715
|
+
capabilities: { pause: false, resume: true },
|
|
18716
|
+
builtin: true,
|
|
18717
|
+
version: id === "antigravity" ? version(argv[0]) : id === "codex" ? version(argv[0], argv.slice(1)) : version(commands[0])
|
|
18718
|
+
}];
|
|
18719
|
+
});
|
|
18720
|
+
}
|
|
18721
|
+
var scanBuiltinAgents = () => scannedBuiltinAgents ??= discoverBuiltinAgents();
|
|
18661
18722
|
var builtinAgents = (cwd = process.cwd()) => scanBuiltinAgents().map((agent) => ({ ...agent, cwd }));
|
|
18662
18723
|
function loadConfig(env = process.env) {
|
|
18663
18724
|
const extra = env.AGENTDOCK_AGENTS_JSON ? JSON.parse(env.AGENTDOCK_AGENTS_JSON) : [];
|
|
18664
|
-
const defaultCwd =
|
|
18725
|
+
const defaultCwd = resolve4(env.AGENTDOCK_DEFAULT_CWD ?? process.cwd());
|
|
18665
18726
|
const agents = new Map(builtinAgents(defaultCwd).map((agent) => [agent.id, agent]));
|
|
18666
18727
|
for (const agent of extra) {
|
|
18667
18728
|
const configured = agentConfigSchema.parse(agent);
|
|
@@ -18670,7 +18731,7 @@ function loadConfig(env = process.env) {
|
|
|
18670
18731
|
return appConfigSchema.parse({
|
|
18671
18732
|
host: env.AGENTDOCK_LOCAL_ONLY === "true" ? "127.0.0.1" : env.AGENTDOCK_HOST,
|
|
18672
18733
|
port: env.AGENTDOCK_PORT ? Number(env.AGENTDOCK_PORT) : void 0,
|
|
18673
|
-
databaseUrl:
|
|
18734
|
+
databaseUrl: resolve4(defaultCwd, env.AGENTDOCK_DATABASE_URL ?? "./.agentdock/agentdock.db"),
|
|
18674
18735
|
acpxCommand: env.AGENTDOCK_ACPX_COMMAND,
|
|
18675
18736
|
driverIdleTimeoutMs: env.AGENTDOCK_DRIVER_IDLE_TIMEOUT_MS ? Number(env.AGENTDOCK_DRIVER_IDLE_TIMEOUT_MS) : void 0,
|
|
18676
18737
|
cleanupIntervalMs: env.AGENTDOCK_CLEANUP_INTERVAL_MS ? Number(env.AGENTDOCK_CLEANUP_INTERVAL_MS) : void 0,
|
|
@@ -18688,13 +18749,13 @@ import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
|
18688
18749
|
init_src2();
|
|
18689
18750
|
init_daemon();
|
|
18690
18751
|
import { spawn as spawn7 } from "node:child_process";
|
|
18691
|
-
import { closeSync, mkdirSync as mkdirSync4, openSync as openSync2, readFileSync as readFileSync5, rmSync as rmSync2, statSync as
|
|
18752
|
+
import { closeSync, mkdirSync as mkdirSync4, openSync as openSync2, readFileSync as readFileSync5, rmSync as rmSync2, statSync as statSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
18692
18753
|
import { homedir as homedir5 } from "node:os";
|
|
18693
18754
|
import { dirname as dirname7, join as join8 } from "node:path";
|
|
18694
18755
|
|
|
18695
18756
|
// src/update.ts
|
|
18696
18757
|
import { execFile as execFile3 } from "node:child_process";
|
|
18697
|
-
import { resolve as
|
|
18758
|
+
import { resolve as resolve5 } from "node:path";
|
|
18698
18759
|
import { promisify as promisify2 } from "node:util";
|
|
18699
18760
|
var execFileAsync2 = promisify2(execFile3);
|
|
18700
18761
|
var DEFAULT_PACKAGE_NAME = "@agent-dock/cli";
|
|
@@ -18738,7 +18799,7 @@ async function updateAgentDock(currentVersion, options, dependencies) {
|
|
|
18738
18799
|
}
|
|
18739
18800
|
const globalRoot = (await dependencies.runNpm(["root", "--global"])).trim();
|
|
18740
18801
|
if (!globalRoot) throw new Error("npm did not report its global package directory. The service was not restarted.");
|
|
18741
|
-
await dependencies.restart(
|
|
18802
|
+
await dependencies.restart(resolve5(globalRoot, packageName, "dist/cli.js"));
|
|
18742
18803
|
return {
|
|
18743
18804
|
action: "update",
|
|
18744
18805
|
packageName,
|
|
@@ -18889,7 +18950,7 @@ var SelfUpdateService = class {
|
|
|
18889
18950
|
*/
|
|
18890
18951
|
lockHeld() {
|
|
18891
18952
|
try {
|
|
18892
|
-
if (this.now() -
|
|
18953
|
+
if (this.now() - statSync4(this.lockFile).mtimeMs > UPDATE_LOCK_MAX_AGE_MS) return false;
|
|
18893
18954
|
return pidAlive(Number(readFileSync5(this.lockFile, "utf8").trim()));
|
|
18894
18955
|
} catch {
|
|
18895
18956
|
return false;
|
|
@@ -18977,7 +19038,7 @@ import Fastify from "fastify";
|
|
|
18977
19038
|
import cors from "@fastify/cors";
|
|
18978
19039
|
import { readFile as readFile12, mkdir as mkdir4, readdir as readdir4, rm as rm2, stat as stat5, writeFile as writeFile4 } from "node:fs/promises";
|
|
18979
19040
|
import { Readable as Readable3 } from "node:stream";
|
|
18980
|
-
import { extname, join as join19, resolve as
|
|
19041
|
+
import { extname as extname2, join as join19, resolve as resolve10, sep as sep2 } from "node:path";
|
|
18981
19042
|
import { homedir as homedir14 } from "node:os";
|
|
18982
19043
|
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
18983
19044
|
|
|
@@ -18993,7 +19054,7 @@ init_listener();
|
|
|
18993
19054
|
// src/lark/security-hooks.ts
|
|
18994
19055
|
init_service();
|
|
18995
19056
|
import { access as access2, mkdir as mkdir3, readFile as readFile4, writeFile as writeFile3 } from "node:fs/promises";
|
|
18996
|
-
import { constants as
|
|
19057
|
+
import { constants as constants3 } from "node:fs";
|
|
18997
19058
|
import { dirname as dirname8, join as join10 } from "node:path";
|
|
18998
19059
|
var guardVersion = "agentdock-high-risk-guard-v2";
|
|
18999
19060
|
var quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
@@ -19117,7 +19178,7 @@ async function larkHookStatus(agentId, workspace) {
|
|
|
19117
19178
|
const { hooksPath } = paths(adapter, workspace);
|
|
19118
19179
|
let writable = true;
|
|
19119
19180
|
try {
|
|
19120
|
-
await access2(workspace,
|
|
19181
|
+
await access2(workspace, constants3.W_OK);
|
|
19121
19182
|
} catch {
|
|
19122
19183
|
writable = false;
|
|
19123
19184
|
}
|
|
@@ -21016,7 +21077,7 @@ async function discoverAgentModels(agent, model, forceRefresh = false) {
|
|
|
21016
21077
|
import { spawn as spawn8 } from "node:child_process";
|
|
21017
21078
|
import { existsSync as existsSync7, readFileSync as readFileSync6, readdirSync } from "node:fs";
|
|
21018
21079
|
import { homedir as homedir6 } from "node:os";
|
|
21019
|
-
import { dirname as dirname9, isAbsolute as
|
|
21080
|
+
import { dirname as dirname9, isAbsolute as isAbsolute5, join as join12, resolve as resolve7 } from "node:path";
|
|
21020
21081
|
var MAX_INCLUDE_DEPTH = 4;
|
|
21021
21082
|
function isValidSshHost(host) {
|
|
21022
21083
|
return /^[A-Za-z0-9][A-Za-z0-9._@:+-]*$/.test(host);
|
|
@@ -21035,7 +21096,7 @@ function splitDirective(line) {
|
|
|
21035
21096
|
}
|
|
21036
21097
|
function expandInclude(pattern, baseDir) {
|
|
21037
21098
|
const expanded = pattern.replace(/^~(?=$|\/)/, homedir6());
|
|
21038
|
-
const absolute =
|
|
21099
|
+
const absolute = isAbsolute5(expanded) ? expanded : resolve7(baseDir, expanded);
|
|
21039
21100
|
if (!/[*?]/.test(absolute)) return [absolute];
|
|
21040
21101
|
const directory = dirname9(absolute);
|
|
21041
21102
|
const namePattern = absolute.slice(directory.length + 1);
|
|
@@ -21153,7 +21214,7 @@ printf 'codex=%s\\n' "$(command -v codex 2>/dev/null)"
|
|
|
21153
21214
|
printf 'home=%s\\n' "$HOME"
|
|
21154
21215
|
`;
|
|
21155
21216
|
function runSsh(host, script, timeoutMs) {
|
|
21156
|
-
return new Promise((
|
|
21217
|
+
return new Promise((resolve17) => {
|
|
21157
21218
|
let stdout = "";
|
|
21158
21219
|
let stderr = "";
|
|
21159
21220
|
let settled = false;
|
|
@@ -21163,12 +21224,12 @@ function runSsh(host, script, timeoutMs) {
|
|
|
21163
21224
|
if (settled) return;
|
|
21164
21225
|
settled = true;
|
|
21165
21226
|
clearTimeout(timer);
|
|
21166
|
-
|
|
21227
|
+
resolve17(result);
|
|
21167
21228
|
};
|
|
21168
21229
|
try {
|
|
21169
21230
|
child = spawn8("ssh", [...sshArgs(host), `sh -c ${shellQuote3(script)}`], { stdio: ["ignore", "pipe", "pipe"] });
|
|
21170
21231
|
} catch (error) {
|
|
21171
|
-
|
|
21232
|
+
resolve17({ code: null, stdout, stderr, timedOut: false, error: error instanceof Error ? error.message : String(error) });
|
|
21172
21233
|
return;
|
|
21173
21234
|
}
|
|
21174
21235
|
const timer = setTimeout(() => {
|
|
@@ -21265,7 +21326,7 @@ function normalizeCodexUsage(result, checkedAt = Date.now()) {
|
|
|
21265
21326
|
return { status: "available", plan: bucket.planType ?? void 0, windows, checkedAt };
|
|
21266
21327
|
}
|
|
21267
21328
|
function readFromCodex() {
|
|
21268
|
-
return new Promise((
|
|
21329
|
+
return new Promise((resolve17) => {
|
|
21269
21330
|
let settled = false;
|
|
21270
21331
|
let buffer = "";
|
|
21271
21332
|
let child;
|
|
@@ -21274,7 +21335,7 @@ function readFromCodex() {
|
|
|
21274
21335
|
settled = true;
|
|
21275
21336
|
clearTimeout(timer);
|
|
21276
21337
|
child?.kill();
|
|
21277
|
-
|
|
21338
|
+
resolve17(usage);
|
|
21278
21339
|
};
|
|
21279
21340
|
const unavailable = (reason) => ({ status: "unavailable", reason, windows: [], checkedAt: Date.now() });
|
|
21280
21341
|
const timer = setTimeout(() => done(unavailable("Codex \u989D\u5EA6\u67E5\u8BE2\u8D85\u65F6")), 8e3);
|
|
@@ -21532,7 +21593,7 @@ import { promisify as promisify5 } from "node:util";
|
|
|
21532
21593
|
// src/skill-catalog.ts
|
|
21533
21594
|
import { readFile as readFile9, readdir as readdir2 } from "node:fs/promises";
|
|
21534
21595
|
import { homedir as homedir10 } from "node:os";
|
|
21535
|
-
import { basename as basename4, dirname as dirname10, join as join16, resolve as
|
|
21596
|
+
import { basename as basename4, dirname as dirname10, join as join16, resolve as resolve8 } from "node:path";
|
|
21536
21597
|
var ignoredDirectories = /* @__PURE__ */ new Set([".git", "node_modules", "dist", "build"]);
|
|
21537
21598
|
async function findSkillFiles(root4, maxDepth = 5) {
|
|
21538
21599
|
const found = [];
|
|
@@ -21558,7 +21619,7 @@ function frontmatterValue(markdown, key) {
|
|
|
21558
21619
|
return value.replace(/^['"]|['"]$/g, "");
|
|
21559
21620
|
}
|
|
21560
21621
|
async function discoverSkills(workspace) {
|
|
21561
|
-
const workspaceRoot =
|
|
21622
|
+
const workspaceRoot = resolve8(workspace?.trim() || process.cwd());
|
|
21562
21623
|
const roots = [
|
|
21563
21624
|
{ path: join16(workspaceRoot, ".agents", "skills"), source: "workspace" },
|
|
21564
21625
|
{ path: join16(workspaceRoot, ".codex", "skills"), source: "workspace" },
|
|
@@ -22685,16 +22746,16 @@ function registerTerminalWebSockets(server, runtime, options = {}) {
|
|
|
22685
22746
|
init_src2();
|
|
22686
22747
|
import { realpathSync as realpathSync3 } from "node:fs";
|
|
22687
22748
|
import { readdir as readdir3, readFile as readFile10, stat as stat4 } from "node:fs/promises";
|
|
22688
|
-
import { isAbsolute as
|
|
22749
|
+
import { isAbsolute as isAbsolute7, relative } from "node:path";
|
|
22689
22750
|
|
|
22690
22751
|
// src/fs-paths.ts
|
|
22691
22752
|
import { realpathSync as realpathSync2 } from "node:fs";
|
|
22692
|
-
import { isAbsolute as
|
|
22753
|
+
import { isAbsolute as isAbsolute6, resolve as resolve9, sep } from "node:path";
|
|
22693
22754
|
function resolveInsideRoot(root4, userPath) {
|
|
22694
22755
|
const normalized2 = (userPath ?? "").trim();
|
|
22695
|
-
if (
|
|
22696
|
-
const absolute =
|
|
22697
|
-
const rootResolved =
|
|
22756
|
+
if (isAbsolute6(normalized2)) throw new WorkspacePathError("\u8DEF\u5F84\u5FC5\u987B\u662F\u76F8\u5BF9\u5DE5\u4F5C\u533A\u7684\u76F8\u5BF9\u8DEF\u5F84");
|
|
22757
|
+
const absolute = resolve9(root4, normalized2);
|
|
22758
|
+
const rootResolved = resolve9(root4);
|
|
22698
22759
|
if (absolute !== rootResolved && !absolute.startsWith(`${rootResolved}${sep}`)) {
|
|
22699
22760
|
throw new WorkspacePathError("\u8DEF\u5F84\u8D85\u51FA\u5DE5\u4F5C\u533A\u8303\u56F4");
|
|
22700
22761
|
}
|
|
@@ -22862,7 +22923,7 @@ async function registerFsRoutes(app, runtime) {
|
|
|
22862
22923
|
if (!userPath) throw new RuntimeError("INVALID_PATH", "\u7F3A\u5C11 path \u53C2\u6570", 400);
|
|
22863
22924
|
let resolved;
|
|
22864
22925
|
try {
|
|
22865
|
-
if (
|
|
22926
|
+
if (isAbsolute7(userPath)) {
|
|
22866
22927
|
try {
|
|
22867
22928
|
resolved = resolveExistingInside(session.cwd, relative(session.cwd, userPath));
|
|
22868
22929
|
} catch {
|
|
@@ -23646,7 +23707,7 @@ data: ${JSON.stringify(data)}
|
|
|
23646
23707
|
|
|
23647
23708
|
// src/json-compression.ts
|
|
23648
23709
|
import { promisify as promisify6 } from "node:util";
|
|
23649
|
-
import { brotliCompress, constants as
|
|
23710
|
+
import { brotliCompress, constants as constants4, gzip } from "node:zlib";
|
|
23650
23711
|
var brotli = promisify6(brotliCompress);
|
|
23651
23712
|
var gzipAsync = promisify6(gzip);
|
|
23652
23713
|
var JSON_COMPRESSION_THRESHOLD = 32 * 1024;
|
|
@@ -23672,7 +23733,7 @@ function registerJsonCompression(app, threshold = JSON_COMPRESSION_THRESHOLD) {
|
|
|
23672
23733
|
if (size < threshold) return payload;
|
|
23673
23734
|
const encoding = pickJsonEncoding(request.headers["accept-encoding"]);
|
|
23674
23735
|
if (!encoding) return payload;
|
|
23675
|
-
const body = encoding === "br" ? await brotli(payload, { params: { [
|
|
23736
|
+
const body = encoding === "br" ? await brotli(payload, { params: { [constants4.BROTLI_PARAM_MODE]: constants4.BROTLI_MODE_TEXT, [constants4.BROTLI_PARAM_QUALITY]: 4, [constants4.BROTLI_PARAM_SIZE_HINT]: size } }) : await gzipAsync(payload, { level: 6 });
|
|
23676
23737
|
reply.header("content-encoding", encoding);
|
|
23677
23738
|
const vary = String(reply.getHeader("vary") ?? "");
|
|
23678
23739
|
if (!/(^|,)\s*accept-encoding\s*(,|$)/i.test(vary)) reply.header("vary", vary ? `${vary}, Accept-Encoding` : "Accept-Encoding");
|
|
@@ -24068,7 +24129,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
24068
24129
|
} catch (error) {
|
|
24069
24130
|
const detail = describeAcpError(error);
|
|
24070
24131
|
if (attempt < 3 && /active writer/i.test(detail)) {
|
|
24071
|
-
await new Promise((
|
|
24132
|
+
await new Promise((resolve17) => setTimeout(resolve17, 1200));
|
|
24072
24133
|
continue;
|
|
24073
24134
|
}
|
|
24074
24135
|
throw error;
|
|
@@ -24153,7 +24214,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
24153
24214
|
return await loadExternalSessionTranscript(effective, session.sourceId, session.cwd, { timeoutMs: 6e4 });
|
|
24154
24215
|
} catch (error) {
|
|
24155
24216
|
if (attempt < 3 && /active writer/i.test(describeAcpError(error))) {
|
|
24156
|
-
await new Promise((
|
|
24217
|
+
await new Promise((resolve17) => setTimeout(resolve17, 1200));
|
|
24157
24218
|
continue;
|
|
24158
24219
|
}
|
|
24159
24220
|
throw error;
|
|
@@ -24273,7 +24334,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
24273
24334
|
const extFromContentType = (contentType, fallbackName) => {
|
|
24274
24335
|
const known = mimeToExt[contentType];
|
|
24275
24336
|
if (known !== void 0) return known;
|
|
24276
|
-
const suffix = fallbackName ?
|
|
24337
|
+
const suffix = fallbackName ? extname2(fallbackName).toLowerCase() : "";
|
|
24277
24338
|
return /^\.[a-z0-9]{1,8}$/.test(suffix) ? suffix : "";
|
|
24278
24339
|
};
|
|
24279
24340
|
app.post("/api/sessions/:id/uploads", async (request, reply) => {
|
|
@@ -24311,7 +24372,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
24311
24372
|
throw new RuntimeError("INVALID_UPLOAD", "Invalid filename", 400);
|
|
24312
24373
|
}
|
|
24313
24374
|
const filePath = join19(globalUploadRoot, session.id, filename);
|
|
24314
|
-
const ext =
|
|
24375
|
+
const ext = extname2(filename).toLowerCase();
|
|
24315
24376
|
const data = await readFile12(filePath);
|
|
24316
24377
|
reply.header("Content-Type", contentTypes[ext] ?? "application/octet-stream");
|
|
24317
24378
|
reply.header("Cache-Control", "public, max-age=31536000, immutable");
|
|
@@ -24333,11 +24394,11 @@ event: ${event.type}
|
|
|
24333
24394
|
data: ${JSON.stringify(event)}
|
|
24334
24395
|
|
|
24335
24396
|
`);
|
|
24336
|
-
const drain = () => new Promise((
|
|
24397
|
+
const drain = () => new Promise((resolve17) => {
|
|
24337
24398
|
const finish = () => {
|
|
24338
24399
|
reply.raw.off("drain", finish);
|
|
24339
24400
|
reply.raw.off("close", finish);
|
|
24340
|
-
|
|
24401
|
+
resolve17();
|
|
24341
24402
|
};
|
|
24342
24403
|
reply.raw.once("drain", finish);
|
|
24343
24404
|
reply.raw.once("close", finish);
|
|
@@ -24355,15 +24416,15 @@ data: ${JSON.stringify(event)}
|
|
|
24355
24416
|
});
|
|
24356
24417
|
});
|
|
24357
24418
|
if (options.webRoot) {
|
|
24358
|
-
const webRoot =
|
|
24359
|
-
const indexFile =
|
|
24419
|
+
const webRoot = resolve10(options.webRoot);
|
|
24420
|
+
const indexFile = resolve10(webRoot, "index.html");
|
|
24360
24421
|
app.setNotFoundHandler(async (request, reply) => {
|
|
24361
24422
|
if (request.method !== "GET" && request.method !== "HEAD") return reply.code(404).send({ error: { code: "NOT_FOUND", message: "Route not found" } });
|
|
24362
24423
|
const pathname = new URL(request.url, "http://agent-dock.local").pathname;
|
|
24363
24424
|
if (pathname.startsWith("/api/") || pathname === "/api") return reply.code(404).send({ error: { code: "NOT_FOUND", message: "API route not found" } });
|
|
24364
24425
|
let requestedFile;
|
|
24365
24426
|
try {
|
|
24366
|
-
requestedFile =
|
|
24427
|
+
requestedFile = resolve10(webRoot, decodeURIComponent(pathname).replace(/^\/+/, ""));
|
|
24367
24428
|
} catch {
|
|
24368
24429
|
return reply.code(400).send({ error: { code: "INVALID_PATH", message: "Invalid URL path" } });
|
|
24369
24430
|
}
|
|
@@ -24373,7 +24434,7 @@ data: ${JSON.stringify(event)}
|
|
|
24373
24434
|
try {
|
|
24374
24435
|
body = await readFile12(file);
|
|
24375
24436
|
} catch {
|
|
24376
|
-
if (
|
|
24437
|
+
if (extname2(pathname)) return reply.code(404).send();
|
|
24377
24438
|
file = indexFile;
|
|
24378
24439
|
try {
|
|
24379
24440
|
body = await readFile12(file);
|
|
@@ -24381,7 +24442,7 @@ data: ${JSON.stringify(event)}
|
|
|
24381
24442
|
return reply.code(404).send({ error: { code: "WEB_UI_NOT_FOUND", message: "Web UI is not installed" } });
|
|
24382
24443
|
}
|
|
24383
24444
|
}
|
|
24384
|
-
const type2 = contentTypes[
|
|
24445
|
+
const type2 = contentTypes[extname2(file).toLowerCase()] ?? "application/octet-stream";
|
|
24385
24446
|
if (pathname.startsWith("/assets/")) reply.header("Cache-Control", "public, max-age=31536000, immutable");
|
|
24386
24447
|
else if (file === indexFile) reply.header("Cache-Control", "no-cache, must-revalidate");
|
|
24387
24448
|
return reply.type(type2).send(request.method === "HEAD" ? void 0 : body);
|
|
@@ -25958,7 +26019,7 @@ var LarkProtocolClient = class {
|
|
|
25958
26019
|
}
|
|
25959
26020
|
async connectOnce() {
|
|
25960
26021
|
const url = await this.buildWsUrl();
|
|
25961
|
-
return new Promise((
|
|
26022
|
+
return new Promise((resolve17, reject2) => {
|
|
25962
26023
|
const ws = new WebSocket(url, {
|
|
25963
26024
|
headers: { "user-agent": USER_AGENT2 },
|
|
25964
26025
|
handshakeTimeout: 15e3
|
|
@@ -25986,7 +26047,7 @@ var LarkProtocolClient = class {
|
|
|
25986
26047
|
this.clearHeartbeat();
|
|
25987
26048
|
});
|
|
25988
26049
|
this.startHeartbeat(ws);
|
|
25989
|
-
|
|
26050
|
+
resolve17(ws);
|
|
25990
26051
|
});
|
|
25991
26052
|
ws.once("error", (error) => fail(error));
|
|
25992
26053
|
ws.once("close", () => fail(new Error("WebSocket closed before open")));
|
|
@@ -25994,14 +26055,14 @@ var LarkProtocolClient = class {
|
|
|
25994
26055
|
}
|
|
25995
26056
|
waitForClose(ws) {
|
|
25996
26057
|
if (ws.readyState === WebSocket.CLOSED) return Promise.resolve();
|
|
25997
|
-
return new Promise((
|
|
25998
|
-
ws.once("close", () =>
|
|
26058
|
+
return new Promise((resolve17) => {
|
|
26059
|
+
ws.once("close", () => resolve17());
|
|
25999
26060
|
});
|
|
26000
26061
|
}
|
|
26001
26062
|
async sleep(ms) {
|
|
26002
26063
|
const deadline = Date.now() + ms;
|
|
26003
26064
|
while (this.running && Date.now() < deadline) {
|
|
26004
|
-
await new Promise((
|
|
26065
|
+
await new Promise((resolve17) => setTimeout(resolve17, Math.min(250, deadline - Date.now())));
|
|
26005
26066
|
}
|
|
26006
26067
|
}
|
|
26007
26068
|
startHeartbeat(ws) {
|
|
@@ -27330,8 +27391,8 @@ var LarkAvatarService = class {
|
|
|
27330
27391
|
let sentAny = false;
|
|
27331
27392
|
const buffered = [];
|
|
27332
27393
|
let resolveDone;
|
|
27333
|
-
const done = new Promise((
|
|
27334
|
-
resolveDone =
|
|
27394
|
+
const done = new Promise((resolve17) => {
|
|
27395
|
+
resolveDone = resolve17;
|
|
27335
27396
|
});
|
|
27336
27397
|
const flush = () => {
|
|
27337
27398
|
if (flushTimer) {
|
|
@@ -27415,12 +27476,12 @@ var LarkAvatarService = class {
|
|
|
27415
27476
|
const pending = buffered.splice(0);
|
|
27416
27477
|
for (const event of pending) handle(event);
|
|
27417
27478
|
const timeoutMs = input.timeoutMs ?? 0;
|
|
27418
|
-
const timeoutPromise = timeoutMs > 0 ? new Promise((
|
|
27479
|
+
const timeoutPromise = timeoutMs > 0 ? new Promise((resolve17) => {
|
|
27419
27480
|
timeout = setTimeout(() => {
|
|
27420
27481
|
terminal = "timeout";
|
|
27421
27482
|
settled = true;
|
|
27422
27483
|
flush();
|
|
27423
|
-
|
|
27484
|
+
resolve17();
|
|
27424
27485
|
}, timeoutMs);
|
|
27425
27486
|
timeout.unref?.();
|
|
27426
27487
|
}) : void 0;
|
|
@@ -28119,7 +28180,7 @@ ${signature}` : body;
|
|
|
28119
28180
|
if (activeTurns.length) {
|
|
28120
28181
|
await Promise.race([
|
|
28121
28182
|
Promise.allSettled(activeTurns),
|
|
28122
|
-
new Promise((
|
|
28183
|
+
new Promise((resolve17) => setTimeout(resolve17, 5e3))
|
|
28123
28184
|
]);
|
|
28124
28185
|
}
|
|
28125
28186
|
if (this.ownsStore) this.store.close();
|
|
@@ -30912,29 +30973,29 @@ function withContext(percent2) {
|
|
|
30912
30973
|
|
|
30913
30974
|
// src/assistant/cwd.ts
|
|
30914
30975
|
init_src2();
|
|
30915
|
-
import { accessSync, constants as
|
|
30976
|
+
import { accessSync as accessSync2, constants as constants5, statSync as statSync5 } from "node:fs";
|
|
30916
30977
|
import { homedir as homedir15 } from "node:os";
|
|
30917
|
-
import { isAbsolute as
|
|
30978
|
+
import { isAbsolute as isAbsolute8, resolve as resolve11 } from "node:path";
|
|
30918
30979
|
function expandHomePath(value) {
|
|
30919
30980
|
const trimmed = value.trim();
|
|
30920
30981
|
if (trimmed === "~") return homedir15();
|
|
30921
|
-
if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) return
|
|
30982
|
+
if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) return resolve11(homedir15(), trimmed.slice(2));
|
|
30922
30983
|
return trimmed;
|
|
30923
30984
|
}
|
|
30924
30985
|
function resolveCwdArgument(value, base = process.cwd()) {
|
|
30925
|
-
return
|
|
30986
|
+
return resolve11(base, expandHomePath(value));
|
|
30926
30987
|
}
|
|
30927
30988
|
function validateCwd(value) {
|
|
30928
30989
|
const trimmed = value?.trim();
|
|
30929
30990
|
if (!trimmed) return void 0;
|
|
30930
30991
|
const expanded = expandHomePath(trimmed);
|
|
30931
|
-
if (!
|
|
30992
|
+
if (!isAbsolute8(expanded)) {
|
|
30932
30993
|
throw new RuntimeError("INVALID_TASK_CWD", `\u5DE5\u4F5C\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84\uFF1A${trimmed}`, 400);
|
|
30933
30994
|
}
|
|
30934
|
-
const absolute =
|
|
30995
|
+
const absolute = resolve11(expanded);
|
|
30935
30996
|
let stats;
|
|
30936
30997
|
try {
|
|
30937
|
-
stats =
|
|
30998
|
+
stats = statSync5(absolute);
|
|
30938
30999
|
} catch {
|
|
30939
31000
|
throw new RuntimeError("INVALID_TASK_CWD", `\u5DE5\u4F5C\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${absolute}`, 400);
|
|
30940
31001
|
}
|
|
@@ -30942,7 +31003,7 @@ function validateCwd(value) {
|
|
|
30942
31003
|
throw new RuntimeError("INVALID_TASK_CWD", `\u5DE5\u4F5C\u76EE\u5F55\u4E0D\u662F\u6587\u4EF6\u5939\uFF1A${absolute}`, 400);
|
|
30943
31004
|
}
|
|
30944
31005
|
try {
|
|
30945
|
-
|
|
31006
|
+
accessSync2(absolute, constants5.R_OK | constants5.X_OK);
|
|
30946
31007
|
} catch {
|
|
30947
31008
|
throw new RuntimeError("INVALID_TASK_CWD", `\u5DE5\u4F5C\u76EE\u5F55\u4E0D\u53EF\u8BBF\u95EE\uFF08\u9700\u8981\u8BFB\u548C\u6267\u884C\u6743\u9650\uFF09\uFF1A${absolute}`, 400);
|
|
30948
31009
|
}
|
|
@@ -32190,7 +32251,7 @@ function parseGithubTarget(value) {
|
|
|
32190
32251
|
}
|
|
32191
32252
|
async function runWatchCommand(watch) {
|
|
32192
32253
|
const shell = resolveLoginShell();
|
|
32193
|
-
return await new Promise((
|
|
32254
|
+
return await new Promise((resolve17) => {
|
|
32194
32255
|
const child = spawn11(shell.file, [...shell.args, "-c", watch.command], {
|
|
32195
32256
|
cwd: watch.cwd ?? process.cwd(),
|
|
32196
32257
|
env: { ...process.env, agentdock_watch_id: watch.id, agentdock_session_id: watch.ownerSessionId },
|
|
@@ -32223,7 +32284,7 @@ async function runWatchCommand(watch) {
|
|
|
32223
32284
|
if (settled) return;
|
|
32224
32285
|
settled = true;
|
|
32225
32286
|
clearTimeout(timer);
|
|
32226
|
-
|
|
32287
|
+
resolve17({ exitCode, output: output3.trim() });
|
|
32227
32288
|
};
|
|
32228
32289
|
child.on("error", (error) => {
|
|
32229
32290
|
append(Buffer.from(String(error)));
|
|
@@ -32789,8 +32850,8 @@ async function runLarkMessageListen(options, deps = {}) {
|
|
|
32789
32850
|
let writeChain = Promise.resolve();
|
|
32790
32851
|
let resolveDone;
|
|
32791
32852
|
let rejectDone;
|
|
32792
|
-
const done = new Promise((
|
|
32793
|
-
resolveDone =
|
|
32853
|
+
const done = new Promise((resolve17, reject2) => {
|
|
32854
|
+
resolveDone = resolve17;
|
|
32794
32855
|
rejectDone = reject2;
|
|
32795
32856
|
});
|
|
32796
32857
|
const cleanup = () => {
|
|
@@ -32988,15 +33049,30 @@ async function runLarkAvatarReactionRoute(options) {
|
|
|
32988
33049
|
|
|
32989
33050
|
// src/acpx.ts
|
|
32990
33051
|
import { spawn as spawn12 } from "node:child_process";
|
|
33052
|
+
import { readFileSync as readFileSync11 } from "node:fs";
|
|
33053
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
33054
|
+
import { dirname as dirname12, resolve as resolve13 } from "node:path";
|
|
32991
33055
|
function acpxPassThroughArgs(argv) {
|
|
32992
33056
|
return argv[2] === "acpx" ? argv.slice(3) : void 0;
|
|
32993
33057
|
}
|
|
32994
|
-
function
|
|
32995
|
-
|
|
33058
|
+
function resolveAcpxLauncher(moduleUrl = import.meta.url) {
|
|
33059
|
+
try {
|
|
33060
|
+
const require2 = createRequire3(moduleUrl);
|
|
33061
|
+
const manifestPath = require2.resolve("acpx/package.json");
|
|
33062
|
+
const manifest = JSON.parse(readFileSync11(manifestPath, "utf8"));
|
|
33063
|
+
const relative2 = typeof manifest.bin === "string" ? manifest.bin : manifest.bin?.acpx;
|
|
33064
|
+
if (relative2) return { command: process.execPath, args: [resolve13(dirname12(manifestPath), relative2)] };
|
|
33065
|
+
} catch {
|
|
33066
|
+
return { command: "acpx", args: [] };
|
|
33067
|
+
}
|
|
33068
|
+
return { command: "acpx", args: [] };
|
|
33069
|
+
}
|
|
33070
|
+
function runAcpx(args, spawnProcess = spawn12, launcher = resolveAcpxLauncher()) {
|
|
33071
|
+
return new Promise((resolve17, reject2) => {
|
|
32996
33072
|
const options = { stdio: "inherit", env: process.env };
|
|
32997
|
-
const child = spawnProcess(
|
|
33073
|
+
const child = spawnProcess(launcher.command, [...launcher.args, ...args], options);
|
|
32998
33074
|
child.once("error", reject2);
|
|
32999
|
-
child.once("exit", (code, signal) =>
|
|
33075
|
+
child.once("exit", (code, signal) => resolve17(code ?? (signal ? 1 : 0)));
|
|
33000
33076
|
});
|
|
33001
33077
|
}
|
|
33002
33078
|
|
|
@@ -33132,8 +33208,8 @@ init_agent_tools();
|
|
|
33132
33208
|
// src/daemon/command.ts
|
|
33133
33209
|
init_daemon();
|
|
33134
33210
|
init_time();
|
|
33135
|
-
import { readFileSync as
|
|
33136
|
-
import { resolve as
|
|
33211
|
+
import { readFileSync as readFileSync12 } from "node:fs";
|
|
33212
|
+
import { resolve as resolve14 } from "node:path";
|
|
33137
33213
|
var STARTUP_LOG_MAX_BYTES = 16 * 1024;
|
|
33138
33214
|
var READY_TIMEOUT_MS = 15e3;
|
|
33139
33215
|
var RESTART_HOST_ENV = "AGENTDOCK_DAEMON_RESTART_HOST";
|
|
@@ -33162,8 +33238,8 @@ function markDaemonReady(dir, patch = {}) {
|
|
|
33162
33238
|
async function daemonStart(options, handlers, env = process.env) {
|
|
33163
33239
|
const invocationCwd = process.cwd();
|
|
33164
33240
|
const dir = isDaemonChild(env) ? defaultDaemonDir(invocationCwd) : resolveDaemonDir(invocationCwd, env.HOME);
|
|
33165
|
-
const cwd = isDaemonChild(env) ? invocationCwd :
|
|
33166
|
-
const database =
|
|
33241
|
+
const cwd = isDaemonChild(env) ? invocationCwd : resolve14(dir, "../..");
|
|
33242
|
+
const database = resolve14(cwd, options.database ?? ".agentdock/agentdock.db");
|
|
33167
33243
|
if (isDaemonChild(env)) {
|
|
33168
33244
|
const meta = childMeta(env);
|
|
33169
33245
|
writePidFile(dir, process.pid);
|
|
@@ -33197,12 +33273,12 @@ async function daemonStart(options, handlers, env = process.env) {
|
|
|
33197
33273
|
function readStartupLog(logFile, startOffset, maxBytes = STARTUP_LOG_MAX_BYTES) {
|
|
33198
33274
|
let size = 0;
|
|
33199
33275
|
try {
|
|
33200
|
-
size =
|
|
33276
|
+
size = readFileSync12(logFile).length;
|
|
33201
33277
|
} catch {
|
|
33202
33278
|
return "";
|
|
33203
33279
|
}
|
|
33204
33280
|
const begin = Math.max(0, startOffset, size - maxBytes);
|
|
33205
|
-
const buf =
|
|
33281
|
+
const buf = readFileSync12(logFile, { encoding: "utf8" });
|
|
33206
33282
|
return buf.slice(begin).trim();
|
|
33207
33283
|
}
|
|
33208
33284
|
async function waitUntilReady(dir, logFile, startOffset) {
|
|
@@ -33401,16 +33477,16 @@ init_session_cli();
|
|
|
33401
33477
|
|
|
33402
33478
|
// src/dev-sandbox.ts
|
|
33403
33479
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
33404
|
-
import { chmodSync as chmodSync3, existsSync as existsSync11, mkdirSync as mkdirSync6, readFileSync as
|
|
33480
|
+
import { chmodSync as chmodSync3, existsSync as existsSync11, mkdirSync as mkdirSync6, readFileSync as readFileSync13, rmSync as rmSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
33405
33481
|
import { createServer } from "node:net";
|
|
33406
|
-
import { delimiter, dirname as
|
|
33482
|
+
import { delimiter as delimiter2, dirname as dirname13, join as join21, resolve as resolve15 } from "node:path";
|
|
33407
33483
|
init_daemon();
|
|
33408
33484
|
var SANDBOX_FILE = "sandbox.json";
|
|
33409
33485
|
function findRepoRoot(start = process.cwd()) {
|
|
33410
|
-
let dir =
|
|
33486
|
+
let dir = resolve15(start);
|
|
33411
33487
|
for (; ; ) {
|
|
33412
33488
|
if (existsSync11(join21(dir, "apps", "server", "package.json")) && existsSync11(join21(dir, "pnpm-workspace.yaml"))) return dir;
|
|
33413
|
-
const parent =
|
|
33489
|
+
const parent = dirname13(dir);
|
|
33414
33490
|
if (parent === dir) throw new Error("\u627E\u4E0D\u5230 agent-dock \u6E90\u7801\u4ED3\u5E93\u3002\u8BF7\u5728\u4ED3\u5E93\u76EE\u5F55\u4E0B\u8FD0\u884C agent-dock dev\uFF0C\u6216\u7528 --repo \u6307\u5B9A\u3002");
|
|
33415
33491
|
dir = parent;
|
|
33416
33492
|
}
|
|
@@ -33432,7 +33508,7 @@ function sandboxEnv(sandbox, base = process.env) {
|
|
|
33432
33508
|
AGENTDOCK_ALLOW_REACTION_TEST: "true",
|
|
33433
33509
|
agentdock_database: sandbox.database
|
|
33434
33510
|
};
|
|
33435
|
-
env.PATH = [shimDir(sandbox), base.PATH].filter(Boolean).join(
|
|
33511
|
+
env.PATH = [shimDir(sandbox), base.PATH].filter(Boolean).join(delimiter2);
|
|
33436
33512
|
for (const key of ["agentdock_session_id", "agentdock_group_tools_url", "agentdock_group_tools_token"]) delete env[key];
|
|
33437
33513
|
for (const key of [DAEMON_ENV_FLAG, DAEMON_CWD_ENV, DAEMON_STARTED_AT_ENV, DAEMON_DIR_ENV]) delete env[key];
|
|
33438
33514
|
return env;
|
|
@@ -33450,7 +33526,7 @@ exec ${shellQuote5(node)} ${shellQuote5(sandbox.entrypoint)} "$@"
|
|
|
33450
33526
|
}
|
|
33451
33527
|
function readSandbox(repo) {
|
|
33452
33528
|
try {
|
|
33453
|
-
return JSON.parse(
|
|
33529
|
+
return JSON.parse(readFileSync13(join21(repo, ".agentdock", "dev", SANDBOX_FILE), "utf8"));
|
|
33454
33530
|
} catch {
|
|
33455
33531
|
return void 0;
|
|
33456
33532
|
}
|
|
@@ -33526,7 +33602,7 @@ async function readLineFromStdin() {
|
|
|
33526
33602
|
return Buffer.concat(chunks).toString("utf8").split(/\r?\n/)[0] ?? "";
|
|
33527
33603
|
}
|
|
33528
33604
|
function promptHidden(question) {
|
|
33529
|
-
return new Promise((
|
|
33605
|
+
return new Promise((resolve17, reject2) => {
|
|
33530
33606
|
const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
|
|
33531
33607
|
const output3 = rl;
|
|
33532
33608
|
let prompted = false;
|
|
@@ -33544,7 +33620,7 @@ function promptHidden(question) {
|
|
|
33544
33620
|
rl.question(question, (answer) => {
|
|
33545
33621
|
rl.close();
|
|
33546
33622
|
process.stdout.write("\n");
|
|
33547
|
-
|
|
33623
|
+
resolve17(answer);
|
|
33548
33624
|
});
|
|
33549
33625
|
});
|
|
33550
33626
|
}
|
|
@@ -33691,7 +33767,7 @@ var runScheduleRemove = (id, options = {}) => control(id, "remove", options);
|
|
|
33691
33767
|
|
|
33692
33768
|
// src/assistant/cli.ts
|
|
33693
33769
|
init_session_cli();
|
|
33694
|
-
import { readFileSync as
|
|
33770
|
+
import { readFileSync as readFileSync14 } from "node:fs";
|
|
33695
33771
|
var daemon = () => requireDaemon();
|
|
33696
33772
|
var currentSessionId = () => process.env.agentdock_session_id?.trim() || void 0;
|
|
33697
33773
|
var fromFields = (from) => {
|
|
@@ -33766,8 +33842,8 @@ function formatDrafts(drafts) {
|
|
|
33766
33842
|
return drafts.map((draft) => `${draft.id} [${draft.state}] ${draft.channel} ${draft.target}`).join("\n");
|
|
33767
33843
|
}
|
|
33768
33844
|
function readBody(options) {
|
|
33769
|
-
if (options.bodyFile === "-") return
|
|
33770
|
-
if (options.bodyFile) return
|
|
33845
|
+
if (options.bodyFile === "-") return readFileSync14(0, "utf8");
|
|
33846
|
+
if (options.bodyFile) return readFileSync14(options.bodyFile, "utf8");
|
|
33771
33847
|
throw new Error("\u8BF7\u7528 --body-file - \u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u53D6\uFF0C\u6216 --body-file <file>");
|
|
33772
33848
|
}
|
|
33773
33849
|
function parseCheck(value) {
|
|
@@ -33798,7 +33874,7 @@ async function runTaskStart(taskId, options) {
|
|
|
33798
33874
|
if (!title) throw new Error("--title \u5FC5\u586B");
|
|
33799
33875
|
const doneWhen = (options.doneWhen ?? []).map((item) => item.trim()).filter(Boolean);
|
|
33800
33876
|
if (!doneWhen.length) throw new Error("\u81F3\u5C11\u7528 --done-when \u5199\u4E00\u6761\u9A8C\u6536\u6807\u51C6");
|
|
33801
|
-
const notes = options.notesFile === "-" ?
|
|
33877
|
+
const notes = options.notesFile === "-" ? readFileSync14(0, "utf8") : options.notes;
|
|
33802
33878
|
const result = await callDaemon(daemon(), "/api/assistant/tasks", "POST", {
|
|
33803
33879
|
title,
|
|
33804
33880
|
...notes ? { notes } : {},
|
|
@@ -34130,7 +34206,7 @@ async function waitForHandoff(id, options) {
|
|
|
34130
34206
|
if (Date.now() - started > limit) {
|
|
34131
34207
|
throw new Error(`\u4EA4\u63A5 ${id} \u8FD8\u5728\u8FDB\u884C\uFF08${handoffStateLabel[handoff.state] ?? text2(handoff.state)}\uFF09\u3002\u7A0D\u540E\u7528 agent-dock main handoff show ${id} \u67E5\u770B\uFF1B\u5931\u8D25\u4F1A\u81EA\u52A8\u56DE\u6EDA\u3002`);
|
|
34132
34208
|
}
|
|
34133
|
-
await new Promise((
|
|
34209
|
+
await new Promise((resolve17) => setTimeout(resolve17, 1e3));
|
|
34134
34210
|
}
|
|
34135
34211
|
}
|
|
34136
34212
|
async function runMainHandoff(options) {
|
|
@@ -34273,8 +34349,8 @@ async function runNotesUnarchive(options) {
|
|
|
34273
34349
|
init_src();
|
|
34274
34350
|
init_daemon();
|
|
34275
34351
|
init_session_cli();
|
|
34276
|
-
import { readFileSync as
|
|
34277
|
-
import { resolve as
|
|
34352
|
+
import { readFileSync as readFileSync15 } from "node:fs";
|
|
34353
|
+
import { resolve as resolve16 } from "node:path";
|
|
34278
34354
|
|
|
34279
34355
|
// src/sources-router/daemon-call.ts
|
|
34280
34356
|
init_session_cli();
|
|
@@ -35024,7 +35100,7 @@ function runRouterDryRun(fixture, options) {
|
|
|
35024
35100
|
return output2({ sourceId: sourceId2, ...result, persisted: false, createdCase: false, createdSession: false, sentAction: false }, options.json);
|
|
35025
35101
|
}
|
|
35026
35102
|
function readFixture(fixture) {
|
|
35027
|
-
return fixture ?
|
|
35103
|
+
return fixture ? readFileSync15(resolve16(fixture), "utf8") : readFileSync15(0, "utf8");
|
|
35028
35104
|
}
|
|
35029
35105
|
function parseFixture(raw) {
|
|
35030
35106
|
try {
|
|
@@ -35038,7 +35114,7 @@ function dryRunViaDaemon(sourceId2, event) {
|
|
|
35038
35114
|
}
|
|
35039
35115
|
|
|
35040
35116
|
// src/cli.ts
|
|
35041
|
-
var packageJson = JSON.parse(
|
|
35117
|
+
var packageJson = JSON.parse(readFileSync16(new URL("../package.json", import.meta.url), "utf8"));
|
|
35042
35118
|
var interactiveOutput = () => Boolean(process.stdout.isTTY && process.env.NO_COLOR === void 0 && process.env.TERM !== "dumb");
|
|
35043
35119
|
try {
|
|
35044
35120
|
loadEnvFile();
|
|
@@ -35093,9 +35169,9 @@ async function restartWithInstalledCli(entrypoint) {
|
|
|
35093
35169
|
if (!existsSync12(entrypoint)) throw new Error(`Updated AgentDock entrypoint was not found: ${entrypoint}. The service was not restarted.`);
|
|
35094
35170
|
const previousPid = daemonStatus().pid;
|
|
35095
35171
|
const child = spawn13(process.execPath, [entrypoint, "daemon", "restart"], { stdio: "inherit", env: process.env });
|
|
35096
|
-
await new Promise((
|
|
35172
|
+
await new Promise((resolve17, reject2) => {
|
|
35097
35173
|
child.once("error", reject2);
|
|
35098
|
-
child.once("exit", (code) => code === 0 ?
|
|
35174
|
+
child.once("exit", (code) => code === 0 ? resolve17() : reject2(new Error(`AgentDock restart exited with code ${code ?? "unknown"}.`)));
|
|
35099
35175
|
});
|
|
35100
35176
|
const deadline = Date.now() + 15e3;
|
|
35101
35177
|
while (Date.now() < deadline) {
|