@agent-dock/cli 0.1.1 → 0.1.2
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/agents/codex-acp.mjs +35 -1
- package/dist/cli.js +421 -286
- package/dist/cli.js.map +4 -4
- package/package.json +1 -1
- package/public/assets/{ImageLightbox-DDAwu-Ky.js → ImageLightbox-D0mGZhIC.js} +1 -1
- package/public/assets/{PromptEditor-CkEM_6zj.js → PromptEditor-Cfvua_lI.js} +1 -1
- package/public/assets/{index-DCRx7Io2.js → index-CVjQTj1y.js} +92 -92
- package/public/index.html +1 -1
package/dist/cli.js
CHANGED
|
@@ -9,19 +9,160 @@ var __export = (target, all) => {
|
|
|
9
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
// src/daemon/daemon.ts
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { chmodSync, existsSync, mkdirSync, openSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { spawn } from "node:child_process";
|
|
17
|
+
function defaultDaemonDir(cwd = process.cwd()) {
|
|
18
|
+
return join(cwd, ".agentdock", "daemon");
|
|
19
|
+
}
|
|
20
|
+
function lastDaemonDirPointerFile(home = process.env.HOME ?? homedir()) {
|
|
21
|
+
return join(home, ".agentdock", "last-daemon-dir");
|
|
22
|
+
}
|
|
23
|
+
function readLastDaemonDir(home = process.env.HOME ?? homedir()) {
|
|
24
|
+
try {
|
|
25
|
+
const raw = readFileSync(lastDaemonDirPointerFile(home), "utf8").trim();
|
|
26
|
+
return raw || void 0;
|
|
27
|
+
} catch {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function writeLastDaemonDir(dir, home = process.env.HOME ?? homedir()) {
|
|
32
|
+
const pointerFile = lastDaemonDirPointerFile(home);
|
|
33
|
+
mkdirSync(dirname(pointerFile), { recursive: true });
|
|
34
|
+
writeFileSync(pointerFile, `${dir}
|
|
35
|
+
`, "utf8");
|
|
36
|
+
}
|
|
37
|
+
function resolveDaemonDir(cwd = process.cwd(), home = process.env.HOME ?? homedir()) {
|
|
38
|
+
const localDir = defaultDaemonDir(cwd);
|
|
39
|
+
if (isDaemonRunning(localDir)) return localDir;
|
|
40
|
+
const lastDir = readLastDaemonDir(home);
|
|
41
|
+
if (lastDir && existsSync(lastDir)) return lastDir;
|
|
42
|
+
return localDir;
|
|
43
|
+
}
|
|
44
|
+
function daemonPaths(dir = defaultDaemonDir()) {
|
|
45
|
+
return { dir, pidFile: join(dir, PID_FILE), stateFile: join(dir, STATE_FILE), logFile: join(dir, LOG_FILE) };
|
|
46
|
+
}
|
|
47
|
+
function pidAlive(pid) {
|
|
48
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
49
|
+
try {
|
|
50
|
+
process.kill(pid, 0);
|
|
51
|
+
return true;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return error.code === "EPERM";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function readDaemonStatus(dir = defaultDaemonDir()) {
|
|
57
|
+
let raw;
|
|
58
|
+
try {
|
|
59
|
+
raw = readFileSync(join(dir, STATE_FILE), "utf8");
|
|
60
|
+
} catch {
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(raw);
|
|
65
|
+
} catch {
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function pidFromState(state) {
|
|
70
|
+
return state && Number.isInteger(state.pid) && state.pid > 0 ? state.pid : 0;
|
|
71
|
+
}
|
|
72
|
+
function isDaemonRunning(dir = defaultDaemonDir()) {
|
|
73
|
+
const pid = pidFromState(readDaemonStatus(dir));
|
|
74
|
+
return pid > 0 && pidAlive(pid);
|
|
75
|
+
}
|
|
76
|
+
function ensureDir(dir) {
|
|
77
|
+
mkdirSync(dir, { recursive: true });
|
|
78
|
+
}
|
|
79
|
+
function writeState(dir, state) {
|
|
80
|
+
ensureDir(dir);
|
|
81
|
+
const stateFile = join(dir, STATE_FILE);
|
|
82
|
+
writeFileSync(stateFile, `${JSON.stringify(state, null, 2)}
|
|
83
|
+
`, "utf8");
|
|
84
|
+
try {
|
|
85
|
+
chmodSync(stateFile, 384);
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function writePidFile(dir, pid) {
|
|
90
|
+
ensureDir(dir);
|
|
91
|
+
writeFileSync(join(dir, PID_FILE), `${pid}
|
|
92
|
+
`, "utf8");
|
|
93
|
+
}
|
|
94
|
+
function clearState(dir) {
|
|
95
|
+
ensureDir(dir);
|
|
96
|
+
writeFileSync(join(dir, STATE_FILE), "", "utf8");
|
|
97
|
+
writeFileSync(join(dir, PID_FILE), "", "utf8");
|
|
98
|
+
}
|
|
99
|
+
function isDaemonChild(env = process.env) {
|
|
100
|
+
return env[DAEMON_ENV_FLAG] === "1";
|
|
101
|
+
}
|
|
102
|
+
function childMeta(env = process.env) {
|
|
103
|
+
return {
|
|
104
|
+
cwd: env[DAEMON_CWD_ENV] ?? process.cwd(),
|
|
105
|
+
startedAt: env[DAEMON_STARTED_AT_ENV] ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function daemonize(options = {}) {
|
|
109
|
+
const cwd = options.cwd ?? process.cwd();
|
|
110
|
+
const logFile = daemonPaths(cwd ? join(cwd, ".agentdock", "daemon") : defaultDaemonDir()).logFile;
|
|
111
|
+
const startOffset = fileSizeOrZero(logFile);
|
|
112
|
+
const fd = openLogFd(logFile);
|
|
113
|
+
const entrypoint = process.argv[1];
|
|
114
|
+
if (!entrypoint) throw new Error("Cannot daemonize: process.argv[1] is missing.");
|
|
115
|
+
const child = spawn(process.execPath, [entrypoint, ...process.argv.slice(2)], {
|
|
116
|
+
cwd,
|
|
117
|
+
stdio: ["ignore", fd, fd],
|
|
118
|
+
detached: true,
|
|
119
|
+
env: {
|
|
120
|
+
...options.env ?? process.env,
|
|
121
|
+
[DAEMON_ENV_FLAG]: "1",
|
|
122
|
+
[DAEMON_CWD_ENV]: cwd,
|
|
123
|
+
[DAEMON_STARTED_AT_ENV]: options.startedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
child.unref();
|
|
127
|
+
return { child, logFile, startOffset };
|
|
128
|
+
}
|
|
129
|
+
function fileSizeOrZero(file) {
|
|
130
|
+
try {
|
|
131
|
+
return statSync(file).size;
|
|
132
|
+
} catch {
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function openLogFd(file) {
|
|
137
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
138
|
+
return openSync(file, "a");
|
|
139
|
+
}
|
|
140
|
+
var DAEMON_ENV_FLAG, DAEMON_CWD_ENV, DAEMON_STARTED_AT_ENV, PID_FILE, STATE_FILE, LOG_FILE;
|
|
141
|
+
var init_daemon = __esm({
|
|
142
|
+
"src/daemon/daemon.ts"() {
|
|
143
|
+
"use strict";
|
|
144
|
+
DAEMON_ENV_FLAG = "AGENTDOCK_DAEMONIZED";
|
|
145
|
+
DAEMON_CWD_ENV = "AGENTDOCK_DAEMON_CWD";
|
|
146
|
+
DAEMON_STARTED_AT_ENV = "AGENTDOCK_DAEMON_STARTED_AT";
|
|
147
|
+
PID_FILE = "agentdock.pid";
|
|
148
|
+
STATE_FILE = "agentdock.state.json";
|
|
149
|
+
LOG_FILE = "agentdock.log";
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
12
153
|
// ../../packages/storage/src/native.ts
|
|
13
154
|
import Database from "better-sqlite3";
|
|
14
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
155
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "node:fs";
|
|
15
156
|
import { createRequire } from "node:module";
|
|
16
|
-
import { dirname, join } from "node:path";
|
|
157
|
+
import { dirname as dirname3, join as join3 } from "node:path";
|
|
17
158
|
function configureNativeFallback(fallback) {
|
|
18
159
|
configuredFallback = fallback;
|
|
19
160
|
}
|
|
20
161
|
function installedBetterSqlite() {
|
|
21
162
|
try {
|
|
22
163
|
const entry = localRequire.resolve("better-sqlite3/package.json");
|
|
23
|
-
const version = JSON.parse(
|
|
24
|
-
return version ? { dir:
|
|
164
|
+
const version = JSON.parse(readFileSync2(entry, "utf8")).version;
|
|
165
|
+
return version ? { dir: dirname3(entry), version } : void 0;
|
|
25
166
|
} catch {
|
|
26
167
|
return void 0;
|
|
27
168
|
}
|
|
@@ -46,13 +187,13 @@ function errorCode(error) {
|
|
|
46
187
|
return error?.code ?? void 0;
|
|
47
188
|
}
|
|
48
189
|
function usableFallback(fallback) {
|
|
49
|
-
if (!fallback || !
|
|
190
|
+
if (!fallback || !existsSync3(fallback.path)) return void 0;
|
|
50
191
|
return installedBetterSqlite()?.version === fallback.version ? fallback : void 0;
|
|
51
192
|
}
|
|
52
193
|
function prebuildRelativePath() {
|
|
53
194
|
const arch = process.arch;
|
|
54
|
-
if (process.platform === "linux") return
|
|
55
|
-
return
|
|
195
|
+
if (process.platform === "linux") return join3("prebuilds", `${hasGlibc() ? "linux" : "linuxmusl"}-${arch}.node`);
|
|
196
|
+
return join3("prebuilds", `${process.platform}-${arch}.node`);
|
|
56
197
|
}
|
|
57
198
|
function hasGlibc() {
|
|
58
199
|
try {
|
|
@@ -119,8 +260,8 @@ var init_schema = __esm({
|
|
|
119
260
|
// ../../packages/storage/src/index.ts
|
|
120
261
|
import { and, asc, desc, eq, gt, inArray, isNotNull, lt, lte } from "drizzle-orm";
|
|
121
262
|
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
122
|
-
import { mkdirSync } from "node:fs";
|
|
123
|
-
import { dirname as
|
|
263
|
+
import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
264
|
+
import { dirname as dirname4 } from "node:path";
|
|
124
265
|
function* parseEvents(rows) {
|
|
125
266
|
for (const row of rows) {
|
|
126
267
|
yield { id: row.id, sessionId: row.session_id, sequence: row.sequence, type: row.type, timestamp: row.timestamp, data: JSON.parse(row.data), raw: row.raw ?? void 0 };
|
|
@@ -163,7 +304,7 @@ function mergeStreamingSegments(rows, mergeText, maxBytes) {
|
|
|
163
304
|
return result;
|
|
164
305
|
}
|
|
165
306
|
function createRepositories(filename, options = {}) {
|
|
166
|
-
if (filename !== ":memory:")
|
|
307
|
+
if (filename !== ":memory:") mkdirSync3(dirname4(filename), { recursive: true });
|
|
167
308
|
const sqlite = openDatabase(filename, options.nativeFallback ? { fallback: options.nativeFallback } : {});
|
|
168
309
|
sqlite.pragma("journal_mode = WAL");
|
|
169
310
|
sqlite.exec(`
|
|
@@ -454,147 +595,6 @@ var init_src = __esm({
|
|
|
454
595
|
}
|
|
455
596
|
});
|
|
456
597
|
|
|
457
|
-
// src/daemon/daemon.ts
|
|
458
|
-
import { dirname as dirname5, join as join5 } from "node:path";
|
|
459
|
-
import { homedir } from "node:os";
|
|
460
|
-
import { chmodSync, existsSync as existsSync4, mkdirSync as mkdirSync2, openSync, readFileSync as readFileSync4, statSync as statSync2, writeFileSync } from "node:fs";
|
|
461
|
-
import { spawn as spawn5 } from "node:child_process";
|
|
462
|
-
function defaultDaemonDir(cwd = process.cwd()) {
|
|
463
|
-
return join5(cwd, ".agentdock", "daemon");
|
|
464
|
-
}
|
|
465
|
-
function lastDaemonDirPointerFile(home = process.env.HOME ?? homedir()) {
|
|
466
|
-
return join5(home, ".agentdock", "last-daemon-dir");
|
|
467
|
-
}
|
|
468
|
-
function readLastDaemonDir(home = process.env.HOME ?? homedir()) {
|
|
469
|
-
try {
|
|
470
|
-
const raw = readFileSync4(lastDaemonDirPointerFile(home), "utf8").trim();
|
|
471
|
-
return raw || void 0;
|
|
472
|
-
} catch {
|
|
473
|
-
return void 0;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
function writeLastDaemonDir(dir, home = process.env.HOME ?? homedir()) {
|
|
477
|
-
const pointerFile = lastDaemonDirPointerFile(home);
|
|
478
|
-
mkdirSync2(dirname5(pointerFile), { recursive: true });
|
|
479
|
-
writeFileSync(pointerFile, `${dir}
|
|
480
|
-
`, "utf8");
|
|
481
|
-
}
|
|
482
|
-
function resolveDaemonDir(cwd = process.cwd(), home = process.env.HOME ?? homedir()) {
|
|
483
|
-
const localDir = defaultDaemonDir(cwd);
|
|
484
|
-
if (isDaemonRunning(localDir)) return localDir;
|
|
485
|
-
const lastDir = readLastDaemonDir(home);
|
|
486
|
-
if (lastDir && existsSync4(lastDir)) return lastDir;
|
|
487
|
-
return localDir;
|
|
488
|
-
}
|
|
489
|
-
function daemonPaths(dir = defaultDaemonDir()) {
|
|
490
|
-
return { dir, pidFile: join5(dir, PID_FILE), stateFile: join5(dir, STATE_FILE), logFile: join5(dir, LOG_FILE) };
|
|
491
|
-
}
|
|
492
|
-
function pidAlive(pid) {
|
|
493
|
-
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
494
|
-
try {
|
|
495
|
-
process.kill(pid, 0);
|
|
496
|
-
return true;
|
|
497
|
-
} catch (error) {
|
|
498
|
-
return error.code === "EPERM";
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
function readDaemonStatus(dir = defaultDaemonDir()) {
|
|
502
|
-
let raw;
|
|
503
|
-
try {
|
|
504
|
-
raw = readFileSync4(join5(dir, STATE_FILE), "utf8");
|
|
505
|
-
} catch {
|
|
506
|
-
return void 0;
|
|
507
|
-
}
|
|
508
|
-
try {
|
|
509
|
-
return JSON.parse(raw);
|
|
510
|
-
} catch {
|
|
511
|
-
return void 0;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
function pidFromState(state) {
|
|
515
|
-
return state && Number.isInteger(state.pid) && state.pid > 0 ? state.pid : 0;
|
|
516
|
-
}
|
|
517
|
-
function isDaemonRunning(dir = defaultDaemonDir()) {
|
|
518
|
-
const pid = pidFromState(readDaemonStatus(dir));
|
|
519
|
-
return pid > 0 && pidAlive(pid);
|
|
520
|
-
}
|
|
521
|
-
function ensureDir(dir) {
|
|
522
|
-
mkdirSync2(dir, { recursive: true });
|
|
523
|
-
}
|
|
524
|
-
function writeState(dir, state) {
|
|
525
|
-
ensureDir(dir);
|
|
526
|
-
const stateFile = join5(dir, STATE_FILE);
|
|
527
|
-
writeFileSync(stateFile, `${JSON.stringify(state, null, 2)}
|
|
528
|
-
`, "utf8");
|
|
529
|
-
try {
|
|
530
|
-
chmodSync(stateFile, 384);
|
|
531
|
-
} catch {
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
function writePidFile(dir, pid) {
|
|
535
|
-
ensureDir(dir);
|
|
536
|
-
writeFileSync(join5(dir, PID_FILE), `${pid}
|
|
537
|
-
`, "utf8");
|
|
538
|
-
}
|
|
539
|
-
function clearState(dir) {
|
|
540
|
-
ensureDir(dir);
|
|
541
|
-
writeFileSync(join5(dir, STATE_FILE), "", "utf8");
|
|
542
|
-
writeFileSync(join5(dir, PID_FILE), "", "utf8");
|
|
543
|
-
}
|
|
544
|
-
function isDaemonChild(env = process.env) {
|
|
545
|
-
return env[DAEMON_ENV_FLAG] === "1";
|
|
546
|
-
}
|
|
547
|
-
function childMeta(env = process.env) {
|
|
548
|
-
return {
|
|
549
|
-
cwd: env[DAEMON_CWD_ENV] ?? process.cwd(),
|
|
550
|
-
startedAt: env[DAEMON_STARTED_AT_ENV] ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
function daemonize(options = {}) {
|
|
554
|
-
const cwd = options.cwd ?? process.cwd();
|
|
555
|
-
const logFile = daemonPaths(cwd ? join5(cwd, ".agentdock", "daemon") : defaultDaemonDir()).logFile;
|
|
556
|
-
const startOffset = fileSizeOrZero(logFile);
|
|
557
|
-
const fd = openLogFd(logFile);
|
|
558
|
-
const entrypoint = process.argv[1];
|
|
559
|
-
if (!entrypoint) throw new Error("Cannot daemonize: process.argv[1] is missing.");
|
|
560
|
-
const child = spawn5(process.execPath, [entrypoint, ...process.argv.slice(2)], {
|
|
561
|
-
cwd,
|
|
562
|
-
stdio: ["ignore", fd, fd],
|
|
563
|
-
detached: true,
|
|
564
|
-
env: {
|
|
565
|
-
...options.env ?? process.env,
|
|
566
|
-
[DAEMON_ENV_FLAG]: "1",
|
|
567
|
-
[DAEMON_CWD_ENV]: cwd,
|
|
568
|
-
[DAEMON_STARTED_AT_ENV]: options.startedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
569
|
-
}
|
|
570
|
-
});
|
|
571
|
-
child.unref();
|
|
572
|
-
return { child, logFile, startOffset };
|
|
573
|
-
}
|
|
574
|
-
function fileSizeOrZero(file) {
|
|
575
|
-
try {
|
|
576
|
-
return statSync2(file).size;
|
|
577
|
-
} catch {
|
|
578
|
-
return 0;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
function openLogFd(file) {
|
|
582
|
-
mkdirSync2(dirname5(file), { recursive: true });
|
|
583
|
-
return openSync(file, "a");
|
|
584
|
-
}
|
|
585
|
-
var DAEMON_ENV_FLAG, DAEMON_CWD_ENV, DAEMON_STARTED_AT_ENV, PID_FILE, STATE_FILE, LOG_FILE;
|
|
586
|
-
var init_daemon = __esm({
|
|
587
|
-
"src/daemon/daemon.ts"() {
|
|
588
|
-
"use strict";
|
|
589
|
-
DAEMON_ENV_FLAG = "AGENTDOCK_DAEMONIZED";
|
|
590
|
-
DAEMON_CWD_ENV = "AGENTDOCK_DAEMON_CWD";
|
|
591
|
-
DAEMON_STARTED_AT_ENV = "AGENTDOCK_DAEMON_STARTED_AT";
|
|
592
|
-
PID_FILE = "agentdock.pid";
|
|
593
|
-
STATE_FILE = "agentdock.state.json";
|
|
594
|
-
LOG_FILE = "agentdock.log";
|
|
595
|
-
}
|
|
596
|
-
});
|
|
597
|
-
|
|
598
598
|
// src/session-cli-format.ts
|
|
599
599
|
function writeTranscript(events2, write) {
|
|
600
600
|
let tail2 = "";
|
|
@@ -698,13 +698,13 @@ __export(session_cli_exports, {
|
|
|
698
698
|
sourceSessionId: () => sourceSessionId,
|
|
699
699
|
streamSessionShow: () => streamSessionShow
|
|
700
700
|
});
|
|
701
|
-
import { existsSync as
|
|
702
|
-
import { join as
|
|
701
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
702
|
+
import { join as join17, resolve as resolve8 } from "node:path";
|
|
703
703
|
function resolveDatabasePath(explicit, cwd = process.cwd()) {
|
|
704
704
|
if (explicit) return resolve8(cwd, explicit);
|
|
705
705
|
if (process.env.AGENTDOCK_DATABASE_URL) return resolve8(cwd, process.env.AGENTDOCK_DATABASE_URL);
|
|
706
706
|
const daemonDir = resolveDaemonDir(cwd);
|
|
707
|
-
return
|
|
707
|
+
return join17(daemonDir, "..", "agentdock.db");
|
|
708
708
|
}
|
|
709
709
|
function sessionPeerIds(sessions2, sourceId) {
|
|
710
710
|
const source = sessions2.find((session) => session.id === sourceId);
|
|
@@ -723,7 +723,7 @@ function sourceSessionId(explicit) {
|
|
|
723
723
|
}
|
|
724
724
|
async function runSessionPeers(sessionId, options = {}) {
|
|
725
725
|
const filename = resolveDatabasePath(options.database);
|
|
726
|
-
if (!
|
|
726
|
+
if (!existsSync7(filename)) throw new Error(`\u672A\u627E\u5230 AgentDock \u6570\u636E\u5E93\uFF1A${filename}\u3002daemon \u662F\u5426\u542F\u52A8\u8FC7\uFF1F`);
|
|
727
727
|
const repos = createRepositories(filename);
|
|
728
728
|
try {
|
|
729
729
|
const sourceId = sourceSessionId(sessionId);
|
|
@@ -795,7 +795,7 @@ async function runSessionCancel(targetId, taskId, options = {}) {
|
|
|
795
795
|
}
|
|
796
796
|
async function runSessionList(options = {}) {
|
|
797
797
|
const filename = resolveDatabasePath(options.database);
|
|
798
|
-
if (!
|
|
798
|
+
if (!existsSync7(filename)) throw new Error(`\u672A\u627E\u5230 AgentDock \u6570\u636E\u5E93\uFF1A${filename}\u3002daemon \u662F\u5426\u542F\u52A8\u8FC7\uFF1F`);
|
|
799
799
|
const repos = createRepositories(filename);
|
|
800
800
|
try {
|
|
801
801
|
const sessions2 = await repos.sessions.list();
|
|
@@ -807,7 +807,7 @@ async function runSessionList(options = {}) {
|
|
|
807
807
|
}
|
|
808
808
|
async function withSessionView(sessionId, options, view) {
|
|
809
809
|
const filename = resolveDatabasePath(options.database);
|
|
810
|
-
if (!
|
|
810
|
+
if (!existsSync7(filename)) throw new Error(`\u672A\u627E\u5230 AgentDock \u6570\u636E\u5E93\uFF1A${filename}\u3002daemon \u662F\u5426\u542F\u52A8\u8FC7\uFF1F`);
|
|
811
811
|
const repos = createRepositories(filename);
|
|
812
812
|
try {
|
|
813
813
|
const session = await repos.sessions.get(sessionId);
|
|
@@ -838,9 +838,116 @@ var init_session_cli = __esm({
|
|
|
838
838
|
}
|
|
839
839
|
});
|
|
840
840
|
|
|
841
|
+
// src/daemon/autostart.ts
|
|
842
|
+
init_daemon();
|
|
843
|
+
import { execFile } from "node:child_process";
|
|
844
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
845
|
+
import { homedir as homedir2, userInfo } from "node:os";
|
|
846
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
847
|
+
import { promisify } from "node:util";
|
|
848
|
+
var execFileAsync = promisify(execFile);
|
|
849
|
+
var AUTOSTART_LABEL = "com.agent-dock.daemon";
|
|
850
|
+
var xmlEscape = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
851
|
+
function renderLaunchAgentPlist(input) {
|
|
852
|
+
const item = (value) => ` <string>${xmlEscape(value)}</string>`;
|
|
853
|
+
const envEntries = Object.entries(input.env).map(([key, value]) => ` <key>${xmlEscape(key)}</key>
|
|
854
|
+
<string>${xmlEscape(value)}</string>`).join("\n");
|
|
855
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
856
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
857
|
+
<plist version="1.0">
|
|
858
|
+
<dict>
|
|
859
|
+
<key>Label</key>
|
|
860
|
+
<string>${xmlEscape(input.label)}</string>
|
|
861
|
+
<key>ProgramArguments</key>
|
|
862
|
+
<array>
|
|
863
|
+
${input.programArguments.map(item).join("\n")}
|
|
864
|
+
</array>
|
|
865
|
+
<key>WorkingDirectory</key>
|
|
866
|
+
<string>${xmlEscape(input.workingDirectory)}</string>
|
|
867
|
+
<key>EnvironmentVariables</key>
|
|
868
|
+
<dict>
|
|
869
|
+
${envEntries}
|
|
870
|
+
</dict>
|
|
871
|
+
<key>RunAtLoad</key>
|
|
872
|
+
<true/>
|
|
873
|
+
<key>ProcessType</key>
|
|
874
|
+
<string>Background</string>
|
|
875
|
+
<key>StandardOutPath</key>
|
|
876
|
+
<string>${xmlEscape(input.logFile)}</string>
|
|
877
|
+
<key>StandardErrorPath</key>
|
|
878
|
+
<string>${xmlEscape(input.logFile)}</string>
|
|
879
|
+
</dict>
|
|
880
|
+
</plist>
|
|
881
|
+
`;
|
|
882
|
+
}
|
|
883
|
+
var defaultLaunchctl = async (args) => {
|
|
884
|
+
await execFileAsync("/bin/launchctl", args, { timeout: 15e3 });
|
|
885
|
+
};
|
|
886
|
+
var AutostartService = class {
|
|
887
|
+
constructor(options) {
|
|
888
|
+
this.options = options;
|
|
889
|
+
this.platform = options.platform ?? process.platform;
|
|
890
|
+
this.env = options.env ?? process.env;
|
|
891
|
+
this.home = this.env.HOME ?? homedir2();
|
|
892
|
+
this.realHome = options.realHome ?? userInfo().homedir;
|
|
893
|
+
}
|
|
894
|
+
platform;
|
|
895
|
+
env;
|
|
896
|
+
home;
|
|
897
|
+
realHome;
|
|
898
|
+
unsupportedReason() {
|
|
899
|
+
if (this.platform !== "darwin") return "\u76EE\u524D\u53EA\u652F\u6301 macOS\uFF08launchd\uFF09";
|
|
900
|
+
if (this.home !== this.realHome) return "\u5F53\u524D\u662F\u9694\u79BB\u6C99\u7BB1\uFF0C\u4E0D\u80FD\u4FEE\u6539\u7CFB\u7EDF\u7684\u5F00\u673A\u542F\u52A8\u9879";
|
|
901
|
+
return void 0;
|
|
902
|
+
}
|
|
903
|
+
get plistPath() {
|
|
904
|
+
return join2(this.home, "Library", "LaunchAgents", `${AUTOSTART_LABEL}.plist`);
|
|
905
|
+
}
|
|
906
|
+
status() {
|
|
907
|
+
const reason = this.unsupportedReason();
|
|
908
|
+
if (reason) return { supported: false, enabled: false, reason };
|
|
909
|
+
return { supported: true, enabled: existsSync2(this.plistPath), plistPath: this.plistPath, entrypoint: this.options.entrypoint };
|
|
910
|
+
}
|
|
911
|
+
async enable() {
|
|
912
|
+
const reason = this.unsupportedReason();
|
|
913
|
+
if (reason) throw new Error(reason);
|
|
914
|
+
if (!existsSync2(this.options.entrypoint)) throw new Error(`\u627E\u4E0D\u5230 CLI \u5165\u53E3\uFF1A${this.options.entrypoint}`);
|
|
915
|
+
const root3 = this.options.workingDirectory?.() ?? dirname2(dirname2(resolveDaemonDir(void 0, this.home)));
|
|
916
|
+
const logFile = join2(root3, ".agentdock", "daemon", "autostart.log");
|
|
917
|
+
mkdirSync2(dirname2(logFile), { recursive: true });
|
|
918
|
+
mkdirSync2(dirname2(this.plistPath), { recursive: true });
|
|
919
|
+
const env = { HOME: this.home, ...this.env.PATH ? { PATH: this.env.PATH } : {} };
|
|
920
|
+
writeFileSync2(this.plistPath, renderLaunchAgentPlist({
|
|
921
|
+
label: AUTOSTART_LABEL,
|
|
922
|
+
programArguments: [this.options.nodePath ?? process.execPath, this.options.entrypoint, "start"],
|
|
923
|
+
workingDirectory: root3,
|
|
924
|
+
logFile,
|
|
925
|
+
env
|
|
926
|
+
}), { mode: 420 });
|
|
927
|
+
const launchctl = this.options.launchctl ?? defaultLaunchctl;
|
|
928
|
+
const domain = `gui/${this.options.uid ?? process.getuid?.() ?? userInfo().uid}`;
|
|
929
|
+
await launchctl(["bootout", `${domain}/${AUTOSTART_LABEL}`]).catch(() => void 0);
|
|
930
|
+
try {
|
|
931
|
+
await launchctl(["bootstrap", domain, this.plistPath]);
|
|
932
|
+
} catch (error) {
|
|
933
|
+
throw new Error(`\u5DF2\u5199\u5165 ${this.plistPath}\uFF0C\u4F46 launchctl \u52A0\u8F7D\u5931\u8D25\uFF08\u4E0B\u6B21\u767B\u5F55\u65F6\u4ECD\u4F1A\u751F\u6548\uFF09\uFF1A${error instanceof Error ? error.message : String(error)}`);
|
|
934
|
+
}
|
|
935
|
+
return this.status();
|
|
936
|
+
}
|
|
937
|
+
async disable() {
|
|
938
|
+
const reason = this.unsupportedReason();
|
|
939
|
+
if (reason) throw new Error(reason);
|
|
940
|
+
const launchctl = this.options.launchctl ?? defaultLaunchctl;
|
|
941
|
+
const domain = `gui/${this.options.uid ?? process.getuid?.() ?? userInfo().uid}`;
|
|
942
|
+
await launchctl(["bootout", `${domain}/${AUTOSTART_LABEL}`]).catch(() => void 0);
|
|
943
|
+
rmSync(this.plistPath, { force: true });
|
|
944
|
+
return this.status();
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
|
|
841
948
|
// src/cli.ts
|
|
842
949
|
init_src();
|
|
843
|
-
import { existsSync as
|
|
950
|
+
import { existsSync as existsSync9, readFileSync as readFileSync10 } from "node:fs";
|
|
844
951
|
import { spawn as spawn10 } from "node:child_process";
|
|
845
952
|
import { loadEnvFile } from "node:process";
|
|
846
953
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
@@ -954,6 +1061,10 @@ Without a password, the console is reachable only through the credential link pr
|
|
|
954
1061
|
links, or direct local access. With a password, entering it on the login page also grants full access.
|
|
955
1062
|
Changes take effect immediately; no restart needed.`);
|
|
956
1063
|
program.command("update").description("Update the global AgentDock package and restart the background service").option("--dist-tag <tag>", "npm dist-tag to install (default: latest)", "latest").action((options) => handlers.update?.(options));
|
|
1064
|
+
const autostart = program.command("autostart").description("Start AgentDock automatically at login (macOS launchd)");
|
|
1065
|
+
for (const [action, description] of [["enable", "Install the login item (runs `agent-dock start` at login)"], ["disable", "Remove the login item"], ["status", "Show whether the login item is installed"]]) {
|
|
1066
|
+
autostart.command(action).description(description).option("--json", "Output raw JSON").action((options) => handlers.autostart?.(action, options));
|
|
1067
|
+
}
|
|
957
1068
|
const addProcessCommands = (parent) => {
|
|
958
1069
|
parent.command("start").description("Start the AgentDock server in the background").action((options, command) => handlers.daemonStart?.(serverOptionsFrom(options, command)));
|
|
959
1070
|
parent.command("stop").description("Stop the background AgentDock server").action(() => handlers.daemonStop?.());
|
|
@@ -972,6 +1083,7 @@ Examples:
|
|
|
972
1083
|
$ agent-dock status
|
|
973
1084
|
$ agent-dock restart --port 4410
|
|
974
1085
|
$ agent-dock update --dist-tag fix
|
|
1086
|
+
$ agent-dock autostart enable
|
|
975
1087
|
$ agent-dock stop
|
|
976
1088
|
$ agent-dock daemon start --port 4310
|
|
977
1089
|
$ agent-dock daemon status
|
|
@@ -1004,8 +1116,8 @@ function environmentFromCli(options, base = process.env) {
|
|
|
1004
1116
|
}
|
|
1005
1117
|
|
|
1006
1118
|
// src/native-compat.ts
|
|
1007
|
-
import { existsSync as
|
|
1008
|
-
import { dirname as
|
|
1119
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3 } from "node:fs";
|
|
1120
|
+
import { dirname as dirname5, join as join4, resolve } from "node:path";
|
|
1009
1121
|
import { fileURLToPath } from "node:url";
|
|
1010
1122
|
var manifestCandidates = ["./vendor/native/better-sqlite3.json", "../vendor/native/better-sqlite3.json"];
|
|
1011
1123
|
function nativeTarget(platform2 = process.platform, arch = process.arch, musl = isMusl()) {
|
|
@@ -1023,9 +1135,9 @@ function readNativeManifest(urls = manifestCandidates) {
|
|
|
1023
1135
|
for (const candidate of urls) {
|
|
1024
1136
|
const file = fileURLToPath(new URL(candidate, import.meta.url));
|
|
1025
1137
|
try {
|
|
1026
|
-
if (!
|
|
1027
|
-
const manifest = JSON.parse(
|
|
1028
|
-
return { manifest, dir:
|
|
1138
|
+
if (!existsSync4(file)) continue;
|
|
1139
|
+
const manifest = JSON.parse(readFileSync3(file, "utf8"));
|
|
1140
|
+
return { manifest, dir: dirname5(file) };
|
|
1029
1141
|
} catch {
|
|
1030
1142
|
continue;
|
|
1031
1143
|
}
|
|
@@ -1036,8 +1148,8 @@ function packagedNativeFallback(target = nativeTarget()) {
|
|
|
1036
1148
|
const found = readNativeManifest();
|
|
1037
1149
|
const entry = found?.manifest.targets[target];
|
|
1038
1150
|
if (!found || !entry) return void 0;
|
|
1039
|
-
const path5 = resolve(
|
|
1040
|
-
if (!
|
|
1151
|
+
const path5 = resolve(join4(found.dir, entry.file));
|
|
1152
|
+
if (!existsSync4(path5)) return void 0;
|
|
1041
1153
|
return { path: path5, version: entry.version, ...entry.requires ? { requires: entry.requires } : {}, ...entry.builtFrom ? { builtFrom: entry.builtFrom } : {} };
|
|
1042
1154
|
}
|
|
1043
1155
|
|
|
@@ -1199,15 +1311,15 @@ var makeId = (prefix) => `${prefix}_${crypto.randomUUID()}`;
|
|
|
1199
1311
|
var defaultLarkTraceLimit = 50;
|
|
1200
1312
|
|
|
1201
1313
|
// ../../packages/acp-client/src/index.ts
|
|
1202
|
-
import { dirname as
|
|
1203
|
-
import { existsSync as
|
|
1314
|
+
import { dirname as dirname6, join as join5 } from "node:path";
|
|
1315
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
1204
1316
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
1205
1317
|
|
|
1206
1318
|
// ../../node_modules/.pnpm/acpx@0.20.0_patch_hash=34d804a05175c628ad9877f34a2db2f24bdce786dbb98bacb313e7559b2ca416/node_modules/acpx/dist/agent-registry-Gtwn7nMp.js
|
|
1207
1319
|
import fs from "node:fs";
|
|
1208
1320
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
1209
1321
|
import path from "node:path";
|
|
1210
|
-
import { execFile } from "node:child_process";
|
|
1322
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
1211
1323
|
var PROCESS_HELPER_TIMEOUT_MS = 8e3;
|
|
1212
1324
|
var PROCESS_HELPER_MAX_BUFFER_BYTES = 33554432;
|
|
1213
1325
|
async function runTimedExecFile(command, args, options = {}) {
|
|
@@ -1215,7 +1327,7 @@ async function runTimedExecFile(command, args, options = {}) {
|
|
|
1215
1327
|
return await new Promise((resolve11, reject2) => {
|
|
1216
1328
|
let settled = false;
|
|
1217
1329
|
let timer;
|
|
1218
|
-
const child =
|
|
1330
|
+
const child = execFile2(command, [...args], {
|
|
1219
1331
|
encoding: "utf8",
|
|
1220
1332
|
maxBuffer: options.maxBufferBytes ?? 33554432,
|
|
1221
1333
|
killSignal: "SIGKILL",
|
|
@@ -1907,12 +2019,12 @@ function resolveInstalledBuiltInAgentLaunch(agentCommand, options = {}) {
|
|
|
1907
2019
|
}
|
|
1908
2020
|
function resolveInstalledBuiltInAgentLaunchForSpec(spec, options) {
|
|
1909
2021
|
const readFileSync11 = options.readFileSync ?? fs.readFileSync;
|
|
1910
|
-
const
|
|
2022
|
+
const existsSync10 = options.existsSync ?? fs.existsSync;
|
|
1911
2023
|
const resolvePackageRoot = options.resolvePackageRoot ?? defaultResolvePackageRoot;
|
|
1912
2024
|
try {
|
|
1913
2025
|
const resolved = resolveInstalledBuiltInAgentPackage(spec, {
|
|
1914
2026
|
readFileSync: readFileSync11,
|
|
1915
|
-
existsSync:
|
|
2027
|
+
existsSync: existsSync10,
|
|
1916
2028
|
resolvePackageRoot
|
|
1917
2029
|
});
|
|
1918
2030
|
if (!resolved) return;
|
|
@@ -1945,12 +2057,12 @@ function resolveInstalledBuiltInAgentPackage(spec, options) {
|
|
|
1945
2057
|
function resolvePackageExecBuiltInAgentLaunch(agentCommand, options = {}) {
|
|
1946
2058
|
const spec = findBuiltInAgentPackage(agentCommand);
|
|
1947
2059
|
if (!spec) return;
|
|
1948
|
-
const
|
|
2060
|
+
const existsSync10 = options.existsSync ?? fs.existsSync;
|
|
1949
2061
|
const execPath = options.execPath ?? process.execPath;
|
|
1950
2062
|
const resolveNpmCliPath = options.resolveNpmCliPath ?? defaultResolveNpmCliPath;
|
|
1951
2063
|
try {
|
|
1952
2064
|
const npmCliPath = resolveNpmCliPath(execPath);
|
|
1953
|
-
if (!
|
|
2065
|
+
if (!existsSync10(npmCliPath)) return;
|
|
1954
2066
|
return {
|
|
1955
2067
|
source: "package-exec",
|
|
1956
2068
|
command: execPath,
|
|
@@ -2006,7 +2118,7 @@ function normalizeRegistryOverride(value) {
|
|
|
2006
2118
|
}
|
|
2007
2119
|
|
|
2008
2120
|
// ../../node_modules/.pnpm/acpx@0.20.0_patch_hash=34d804a05175c628ad9877f34a2db2f24bdce786dbb98bacb313e7559b2ca416/node_modules/acpx/dist/ipc-D2BC99hf.js
|
|
2009
|
-
import fs2, { statSync } from "node:fs";
|
|
2121
|
+
import fs2, { statSync as statSync2 } from "node:fs";
|
|
2010
2122
|
import path2 from "node:path";
|
|
2011
2123
|
import fs$1 from "node:fs/promises";
|
|
2012
2124
|
import os from "node:os";
|
|
@@ -3702,10 +3814,10 @@ var DEFAULT_LIMITS = Object.freeze({
|
|
|
3702
3814
|
});
|
|
3703
3815
|
|
|
3704
3816
|
// ../../node_modules/.pnpm/acpx@0.20.0_patch_hash=34d804a05175c628ad9877f34a2db2f24bdce786dbb98bacb313e7559b2ca416/node_modules/acpx/dist/queue-owner-runtime-Be8sr9L5.js
|
|
3705
|
-
import fs3, { readFileSync as
|
|
3817
|
+
import fs3, { readFileSync as readFileSync4, realpathSync } from "node:fs";
|
|
3706
3818
|
import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
|
|
3707
3819
|
import path3 from "node:path";
|
|
3708
|
-
import { spawn } from "node:child_process";
|
|
3820
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
3709
3821
|
import { appendRegularFile, appendRegularFileSync, withTempFile as withTempFile2 } from "@openclaw/fs-safe/advanced";
|
|
3710
3822
|
import { createHash, randomUUID } from "node:crypto";
|
|
3711
3823
|
import { isHardlinkFallbackError as isHardlinkFallbackError2 } from "@openclaw/fs-safe/durability";
|
|
@@ -4593,7 +4705,7 @@ function parseVersion(value) {
|
|
|
4593
4705
|
}
|
|
4594
4706
|
function readPackageVersion(packageJsonPath) {
|
|
4595
4707
|
try {
|
|
4596
|
-
return parseVersion(JSON.parse(
|
|
4708
|
+
return parseVersion(JSON.parse(readFileSync4(packageJsonPath, "utf8")).version);
|
|
4597
4709
|
} catch {
|
|
4598
4710
|
return null;
|
|
4599
4711
|
}
|
|
@@ -5446,7 +5558,7 @@ async function spawnAndWait(spawnCommand, params, defaultCwd, authority) {
|
|
|
5446
5558
|
const spawnOptions = buildTerminalSpawnOptions(spawnCommand.command, params.cwd ?? defaultCwd, params.env);
|
|
5447
5559
|
if (process.platform !== "win32") spawnOptions.detached = true;
|
|
5448
5560
|
assertControlAuthority(authority);
|
|
5449
|
-
const proc =
|
|
5561
|
+
const proc = spawn2(spawnCommand.command, spawnCommand.args, spawnOptions);
|
|
5450
5562
|
await waitForSpawn(proc);
|
|
5451
5563
|
return proc;
|
|
5452
5564
|
}
|
|
@@ -5958,7 +6070,7 @@ var AcpClient = class {
|
|
|
5958
6070
|
assertControlAuthority(authority);
|
|
5959
6071
|
let spawnedChild;
|
|
5960
6072
|
try {
|
|
5961
|
-
spawnedChild =
|
|
6073
|
+
spawnedChild = spawn2(launch.command, [...launch.args], {
|
|
5962
6074
|
...plan.spawnOptions,
|
|
5963
6075
|
windowsVerbatimArguments: prepared.windowsVerbatimArguments
|
|
5964
6076
|
});
|
|
@@ -6000,7 +6112,7 @@ var AcpClient = class {
|
|
|
6000
6112
|
}
|
|
6001
6113
|
let child;
|
|
6002
6114
|
try {
|
|
6003
|
-
child =
|
|
6115
|
+
child = spawn2(launch.command, [...launch.args], {
|
|
6004
6116
|
cwd: options.cwd,
|
|
6005
6117
|
env: options.env,
|
|
6006
6118
|
stdio: [
|
|
@@ -11172,13 +11284,13 @@ function testRegexWithTimeout(pattern, input, timeoutMs = 1e3) {
|
|
|
11172
11284
|
}
|
|
11173
11285
|
|
|
11174
11286
|
// ../../packages/acp-client/src/external-sessions.ts
|
|
11175
|
-
import { spawn as
|
|
11287
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
11176
11288
|
import { ClientSideConnection, ndJsonStream, PROTOCOL_VERSION as PROTOCOL_VERSION2 } from "@agentclientprotocol/sdk";
|
|
11177
11289
|
var DEFAULT_TIMEOUT_MS = 2e4;
|
|
11178
11290
|
async function listExternalSessions(agent, options = {}) {
|
|
11179
11291
|
if (agent.protocol !== "auto" && agent.protocol !== "acp") return { supported: false, sessions: [] };
|
|
11180
11292
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
11181
|
-
const child =
|
|
11293
|
+
const child = spawn3(agent.command, agent.args, {
|
|
11182
11294
|
cwd: agent.cwd ?? process.cwd(),
|
|
11183
11295
|
env: { ...process.env, ...agent.env },
|
|
11184
11296
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -11259,7 +11371,7 @@ async function loadExternalSessionTranscript(agent, sessionId, cwd, options = {}
|
|
|
11259
11371
|
if (agent.protocol !== "auto" && agent.protocol !== "acp") return { replayed: false, turns: [] };
|
|
11260
11372
|
const timeoutMs = options.timeoutMs ?? 6e4;
|
|
11261
11373
|
const updates = [];
|
|
11262
|
-
const child =
|
|
11374
|
+
const child = spawn3(agent.command, agent.args, {
|
|
11263
11375
|
cwd: agent.cwd ?? process.cwd(),
|
|
11264
11376
|
env: { ...process.env, ...agent.env },
|
|
11265
11377
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -11399,9 +11511,9 @@ async function terminateExternalChild(child, graceMs = 5e3) {
|
|
|
11399
11511
|
|
|
11400
11512
|
// ../../packages/acp-client/src/index.ts
|
|
11401
11513
|
function agentLauncherPath(name) {
|
|
11402
|
-
const moduleDirectory =
|
|
11403
|
-
const adjacent =
|
|
11404
|
-
return
|
|
11514
|
+
const moduleDirectory = dirname6(fileURLToPath4(import.meta.url));
|
|
11515
|
+
const adjacent = join5(moduleDirectory, "agents", `${name}-acp.mjs`);
|
|
11516
|
+
return existsSync5(adjacent) ? adjacent : join5(moduleDirectory, "..", "agents", `${name}-acp.mjs`);
|
|
11405
11517
|
}
|
|
11406
11518
|
var flattenRiskText = (value, output = []) => {
|
|
11407
11519
|
if (typeof value === "string") output.push(value);
|
|
@@ -11493,7 +11605,7 @@ var AcpxAdapter = class {
|
|
|
11493
11605
|
const cwd = agent.cwd ?? process.cwd();
|
|
11494
11606
|
this.sessionKey = options.sessionKey ?? `agentdock-${agent.id}`;
|
|
11495
11607
|
this.permissionMode = agent.permissionMode;
|
|
11496
|
-
this.sessionStore = createRuntimeStore({ stateDir:
|
|
11608
|
+
this.sessionStore = createRuntimeStore({ stateDir: join5(cwd, ".agentdock", "acpx") });
|
|
11497
11609
|
this.runtime = createAcpRuntime({
|
|
11498
11610
|
cwd,
|
|
11499
11611
|
sessionStore: this.sessionStore,
|
|
@@ -11779,7 +11891,7 @@ var AcpxAdapter = class {
|
|
|
11779
11891
|
};
|
|
11780
11892
|
|
|
11781
11893
|
// ../../packages/transports/src/index.ts
|
|
11782
|
-
import { spawn as
|
|
11894
|
+
import { spawn as spawn4, spawnSync } from "node:child_process";
|
|
11783
11895
|
import readline2 from "node:readline";
|
|
11784
11896
|
import * as pty from "node-pty";
|
|
11785
11897
|
function commandExists(command) {
|
|
@@ -11801,7 +11913,7 @@ var JsonlTransport = class {
|
|
|
11801
11913
|
child;
|
|
11802
11914
|
async start() {
|
|
11803
11915
|
if (this.child) return;
|
|
11804
|
-
this.child =
|
|
11916
|
+
this.child = spawn4(this.agent.command, this.agent.args, { cwd: this.agent.cwd, env: { ...process.env, ...this.agent.env }, detached: process.platform !== "win32" });
|
|
11805
11917
|
readline2.createInterface({ input: this.child.stdout }).on("line", (line) => {
|
|
11806
11918
|
const event = normalizeAcpxEvent(line);
|
|
11807
11919
|
if (event) this.options.onEvent(event);
|
|
@@ -11870,7 +11982,7 @@ var PtyTransport = class {
|
|
|
11870
11982
|
|
|
11871
11983
|
// ../../packages/agent-runtime/src/index.ts
|
|
11872
11984
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
11873
|
-
import { join as
|
|
11985
|
+
import { join as join6 } from "node:path";
|
|
11874
11986
|
|
|
11875
11987
|
// ../../packages/agent-runtime/src/session-title.ts
|
|
11876
11988
|
var SESSION_TITLE_MAX_CHARS = 120;
|
|
@@ -12461,9 +12573,9 @@ var AgentDockRuntime = class _AgentDockRuntime {
|
|
|
12461
12573
|
}
|
|
12462
12574
|
async applyRiskPolicy(session, driver, policy) {
|
|
12463
12575
|
driver?.setRiskPolicy?.(policy);
|
|
12464
|
-
const directory =
|
|
12576
|
+
const directory = join6(session.cwd, ".agentdock", "security", "sessions");
|
|
12465
12577
|
await mkdir(directory, { recursive: true });
|
|
12466
|
-
await writeFile(
|
|
12578
|
+
await writeFile(join6(directory, `${session.id}.json`), JSON.stringify(policy ?? { enabled: false }), { mode: 384 });
|
|
12467
12579
|
}
|
|
12468
12580
|
async runTask(id, task, agentPrompt = task.prompt, riskPolicy) {
|
|
12469
12581
|
const { session } = await this.active(id);
|
|
@@ -13039,20 +13151,20 @@ import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
|
13039
13151
|
|
|
13040
13152
|
// src/self-update.ts
|
|
13041
13153
|
import { spawn as spawn6 } from "node:child_process";
|
|
13042
|
-
import { closeSync, mkdirSync as
|
|
13043
|
-
import { homedir as
|
|
13044
|
-
import { dirname as
|
|
13154
|
+
import { closeSync, mkdirSync as mkdirSync4, openSync as openSync2, readFileSync as readFileSync5, rmSync as rmSync2, statSync as statSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
13155
|
+
import { homedir as homedir3 } from "node:os";
|
|
13156
|
+
import { dirname as dirname7, join as join7 } from "node:path";
|
|
13045
13157
|
init_daemon();
|
|
13046
13158
|
|
|
13047
13159
|
// src/update.ts
|
|
13048
|
-
import { execFile as
|
|
13160
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
13049
13161
|
import { resolve as resolve3 } from "node:path";
|
|
13050
|
-
import { promisify } from "node:util";
|
|
13051
|
-
var
|
|
13162
|
+
import { promisify as promisify2 } from "node:util";
|
|
13163
|
+
var execFileAsync2 = promisify2(execFile3);
|
|
13052
13164
|
var DEFAULT_PACKAGE_NAME = "@agent-dock/cli";
|
|
13053
13165
|
var npmCommand = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
13054
13166
|
var defaultRunNpm = async (args) => {
|
|
13055
|
-
const { stdout } = await
|
|
13167
|
+
const { stdout } = await execFileAsync2(npmCommand, args, { encoding: "utf8", maxBuffer: 10 * 1024 * 1024 });
|
|
13056
13168
|
return stdout;
|
|
13057
13169
|
};
|
|
13058
13170
|
function normalizeDistTag(value) {
|
|
@@ -13140,7 +13252,7 @@ function distTagForVersion(version) {
|
|
|
13140
13252
|
var CHECK_TTL_MS = 30 * 6e4;
|
|
13141
13253
|
var CHECK_ERROR_TTL_MS = 2 * 6e4;
|
|
13142
13254
|
var defaultSpawnUpdate = (args, options) => {
|
|
13143
|
-
|
|
13255
|
+
mkdirSync4(dirname7(options.logFile), { recursive: true });
|
|
13144
13256
|
const fd = openSync2(options.logFile, "w", 384);
|
|
13145
13257
|
const child = spawn6(process.execPath, args, { cwd: options.cwd, env: options.env, stdio: ["ignore", fd, fd], detached: true });
|
|
13146
13258
|
closeSync(fd);
|
|
@@ -13162,7 +13274,7 @@ var SelfUpdateService = class {
|
|
|
13162
13274
|
constructor(options) {
|
|
13163
13275
|
this.options = options;
|
|
13164
13276
|
this.env = options.env ?? process.env;
|
|
13165
|
-
this.lockFile = options.lockFile ??
|
|
13277
|
+
this.lockFile = options.lockFile ?? join7(this.env.HOME ?? homedir3(), ".agentdock", "update.lock");
|
|
13166
13278
|
this.now = options.now ?? Date.now;
|
|
13167
13279
|
}
|
|
13168
13280
|
cached;
|
|
@@ -13220,15 +13332,15 @@ var SelfUpdateService = class {
|
|
|
13220
13332
|
}
|
|
13221
13333
|
}
|
|
13222
13334
|
acquireLock(pid) {
|
|
13223
|
-
|
|
13335
|
+
mkdirSync4(dirname7(this.lockFile), { recursive: true });
|
|
13224
13336
|
try {
|
|
13225
|
-
|
|
13337
|
+
writeFileSync3(this.lockFile, String(pid), { flag: "wx", mode: 384 });
|
|
13226
13338
|
return true;
|
|
13227
13339
|
} catch {
|
|
13228
13340
|
if (this.lockHeld()) return false;
|
|
13229
|
-
|
|
13341
|
+
rmSync2(this.lockFile, { force: true });
|
|
13230
13342
|
try {
|
|
13231
|
-
|
|
13343
|
+
writeFileSync3(this.lockFile, String(pid), { flag: "wx", mode: 384 });
|
|
13232
13344
|
return true;
|
|
13233
13345
|
} catch {
|
|
13234
13346
|
return false;
|
|
@@ -13243,7 +13355,7 @@ var SelfUpdateService = class {
|
|
|
13243
13355
|
this.updating = true;
|
|
13244
13356
|
this.lastError = void 0;
|
|
13245
13357
|
const cwd = this.env[DAEMON_CWD_ENV] ?? process.cwd();
|
|
13246
|
-
const logFile =
|
|
13358
|
+
const logFile = join7(cwd, ".agentdock", "daemon", "update.log");
|
|
13247
13359
|
const env = { ...this.env };
|
|
13248
13360
|
delete env[DAEMON_ENV_FLAG];
|
|
13249
13361
|
delete env[DAEMON_CWD_ENV];
|
|
@@ -13255,7 +13367,7 @@ var SelfUpdateService = class {
|
|
|
13255
13367
|
child.onExit((code) => {
|
|
13256
13368
|
this.updating = false;
|
|
13257
13369
|
try {
|
|
13258
|
-
if (readFileSync5(this.lockFile, "utf8").trim() === String(lockedPid))
|
|
13370
|
+
if (readFileSync5(this.lockFile, "utf8").trim() === String(lockedPid)) rmSync2(this.lockFile, { force: true });
|
|
13259
13371
|
} catch {
|
|
13260
13372
|
}
|
|
13261
13373
|
if (code !== 0) this.lastError = describeUpdateFailure(tail(logFile), this.options.packageName, this.distTag);
|
|
@@ -13283,8 +13395,8 @@ import Fastify from "fastify";
|
|
|
13283
13395
|
import cors from "@fastify/cors";
|
|
13284
13396
|
import { readFile as readFile9, mkdir as mkdir4, readdir as readdir4, rm as rm2, stat as stat4, writeFile as writeFile4 } from "node:fs/promises";
|
|
13285
13397
|
import { Readable as Readable2 } from "node:stream";
|
|
13286
|
-
import { extname, join as
|
|
13287
|
-
import { homedir as
|
|
13398
|
+
import { extname, join as join16, resolve as resolve7, sep as sep2 } from "node:path";
|
|
13399
|
+
import { homedir as homedir9 } from "node:os";
|
|
13288
13400
|
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
13289
13401
|
|
|
13290
13402
|
// src/lark/sdk.ts
|
|
@@ -14740,7 +14852,7 @@ async function resolveLarkAccessConfig(config, service, actor, repository) {
|
|
|
14740
14852
|
import { createHash as createHash2 } from "node:crypto";
|
|
14741
14853
|
import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
|
|
14742
14854
|
import { tmpdir } from "node:os";
|
|
14743
|
-
import { basename, join as
|
|
14855
|
+
import { basename, join as join8 } from "node:path";
|
|
14744
14856
|
|
|
14745
14857
|
// src/lark/message-content.ts
|
|
14746
14858
|
var asRecord2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
@@ -15702,13 +15814,13 @@ function patchRejectedCardDelta(previous = [], current = []) {
|
|
|
15702
15814
|
}
|
|
15703
15815
|
async function materializeLarkResources(messageId, prompt, resources, service) {
|
|
15704
15816
|
if (!resources.length) return prompt;
|
|
15705
|
-
const directory =
|
|
15817
|
+
const directory = join8(tmpdir(), "agent-dock", "lark-resources", messageId.replace(/[^a-zA-Z0-9_-]/g, "_"));
|
|
15706
15818
|
const notes = [];
|
|
15707
15819
|
for (const resource of resources) {
|
|
15708
15820
|
try {
|
|
15709
15821
|
const downloaded = await service.downloadMessageResource(resource.messageId ?? messageId, resource.key, resource.type);
|
|
15710
15822
|
await mkdir2(directory, { recursive: true, mode: 448 });
|
|
15711
|
-
const path5 =
|
|
15823
|
+
const path5 = join8(directory, safeResourceName(resource, downloaded.contentType));
|
|
15712
15824
|
await writeFile2(path5, downloaded.data, { mode: 384 });
|
|
15713
15825
|
notes.push(`- ${resource.label}\u5DF2\u4E0B\u8F7D\u5230\u672C\u5730\uFF1A${path5}\u3002\u8BF7\u4F7F\u7528\u672C\u5730\u6587\u4EF6\u8BFB\u53D6\u5DE5\u5177\u67E5\u770B\u3002`);
|
|
15714
15826
|
} catch (error) {
|
|
@@ -17561,7 +17673,7 @@ var LarkLongConnectionListenerPool = class {
|
|
|
17561
17673
|
// src/lark/security-hooks.ts
|
|
17562
17674
|
import { access, mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "node:fs/promises";
|
|
17563
17675
|
import { constants } from "node:fs";
|
|
17564
|
-
import { dirname as
|
|
17676
|
+
import { dirname as dirname8, join as join9 } from "node:path";
|
|
17565
17677
|
var guardVersion = "agentdock-high-risk-guard-v2";
|
|
17566
17678
|
var quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
17567
17679
|
var adapters = {
|
|
@@ -17588,8 +17700,8 @@ var adapterFor = (agentId) => {
|
|
|
17588
17700
|
};
|
|
17589
17701
|
var markerFor = (adapter) => `agentdock-lark-high-risk-guard-${adapter.id}.mjs`;
|
|
17590
17702
|
var paths = (adapter, workspace) => ({
|
|
17591
|
-
hooksPath:
|
|
17592
|
-
scriptPath: adapter.kind === "pi-extension" ?
|
|
17703
|
+
hooksPath: join9(workspace, adapter.configDirectory, adapter.configFile),
|
|
17704
|
+
scriptPath: adapter.kind === "pi-extension" ? join9(workspace, adapter.configDirectory, adapter.configFile) : join9(workspace, ".agentdock", "security", markerFor(adapter))
|
|
17593
17705
|
});
|
|
17594
17706
|
async function readableJson(path5, fallback) {
|
|
17595
17707
|
try {
|
|
@@ -17708,8 +17820,8 @@ async function larkHookStatus(agentId, workspace) {
|
|
|
17708
17820
|
}
|
|
17709
17821
|
async function installJsonHook(adapter, workspace) {
|
|
17710
17822
|
const { hooksPath, scriptPath } = paths(adapter, workspace);
|
|
17711
|
-
await mkdir3(
|
|
17712
|
-
await mkdir3(
|
|
17823
|
+
await mkdir3(dirname8(scriptPath), { recursive: true });
|
|
17824
|
+
await mkdir3(dirname8(hooksPath), { recursive: true });
|
|
17713
17825
|
await writeFile3(scriptPath, commandGuardScript(adapter.kind === "cursor-json" ? "cursor" : "standard"), { mode: 448 });
|
|
17714
17826
|
const fallback = adapter.kind === "cursor-json" ? { version: 1, hooks: {} } : { description: "AgentDock project hooks", hooks: {} };
|
|
17715
17827
|
const config = await readableJson(hooksPath, fallback);
|
|
@@ -17730,7 +17842,7 @@ async function installLarkHook(agentId, workspace) {
|
|
|
17730
17842
|
const adapter = adapterFor(agentId);
|
|
17731
17843
|
if (adapter.kind === "pi-extension") {
|
|
17732
17844
|
const { scriptPath } = paths(adapter, workspace);
|
|
17733
|
-
await mkdir3(
|
|
17845
|
+
await mkdir3(dirname8(scriptPath), { recursive: true });
|
|
17734
17846
|
await writeFile3(scriptPath, piGuardExtension, { mode: 384 });
|
|
17735
17847
|
} else await installJsonHook(adapter, workspace);
|
|
17736
17848
|
return larkHookStatus(adapter.id, workspace);
|
|
@@ -18248,12 +18360,12 @@ data: ${JSON.stringify(data)}
|
|
|
18248
18360
|
|
|
18249
18361
|
// src/agent-models.ts
|
|
18250
18362
|
import { createHash as createHash3 } from "node:crypto";
|
|
18251
|
-
import { execFile as
|
|
18363
|
+
import { execFile as execFile4 } from "node:child_process";
|
|
18252
18364
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
18253
18365
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
18254
|
-
import { join as
|
|
18255
|
-
import { promisify as
|
|
18256
|
-
var run =
|
|
18366
|
+
import { join as join10 } from "node:path";
|
|
18367
|
+
import { promisify as promisify3 } from "node:util";
|
|
18368
|
+
var run = promisify3(execFile4);
|
|
18257
18369
|
var ACP_MODEL_PROBE_TIMEOUT_MS = 3e4;
|
|
18258
18370
|
var AgentModelProbeTimeoutError = class extends Error {
|
|
18259
18371
|
constructor(phase, timeoutMs) {
|
|
@@ -18349,7 +18461,7 @@ async function probeModelsThroughAcpRuntime(runtime, input, timeoutMs = ACP_MODE
|
|
|
18349
18461
|
}
|
|
18350
18462
|
}
|
|
18351
18463
|
async function discoverThroughAcp(agent, model) {
|
|
18352
|
-
const stateDir = await mkdtemp(
|
|
18464
|
+
const stateDir = await mkdtemp(join10(tmpdir2(), "agentdock-models-"));
|
|
18353
18465
|
const runtime = createAcpRuntime({
|
|
18354
18466
|
cwd: agent.cwd ?? process.cwd(),
|
|
18355
18467
|
sessionStore: createRuntimeStore({ stateDir }),
|
|
@@ -18417,16 +18529,16 @@ async function discoverAgentModels(agent, model, forceRefresh = false) {
|
|
|
18417
18529
|
|
|
18418
18530
|
// src/agent-owned-sessions.ts
|
|
18419
18531
|
import { readFile as readFile4, readdir } from "node:fs/promises";
|
|
18420
|
-
import { homedir as
|
|
18421
|
-
import { join as
|
|
18532
|
+
import { homedir as homedir4 } from "node:os";
|
|
18533
|
+
import { join as join11 } from "node:path";
|
|
18422
18534
|
async function collectAgentDockOwnedSessionIds(runtime) {
|
|
18423
|
-
const dirs = /* @__PURE__ */ new Set([
|
|
18535
|
+
const dirs = /* @__PURE__ */ new Set([join11(homedir4(), ".agentdock", "acpx", "sessions")]);
|
|
18424
18536
|
try {
|
|
18425
|
-
for (const session of await runtime.listSessions()) if (session.cwd) dirs.add(
|
|
18537
|
+
for (const session of await runtime.listSessions()) if (session.cwd) dirs.add(join11(session.cwd, ".agentdock", "acpx", "sessions"));
|
|
18426
18538
|
} catch {
|
|
18427
18539
|
}
|
|
18428
18540
|
try {
|
|
18429
|
-
for (const agent of await runtime.listAgents()) if (agent.cwd) dirs.add(
|
|
18541
|
+
for (const agent of await runtime.listAgents()) if (agent.cwd) dirs.add(join11(agent.cwd, ".agentdock", "acpx", "sessions"));
|
|
18430
18542
|
} catch {
|
|
18431
18543
|
}
|
|
18432
18544
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -18440,7 +18552,7 @@ async function collectAgentDockOwnedSessionIds(runtime) {
|
|
|
18440
18552
|
for (const entry of entries) {
|
|
18441
18553
|
if (!entry.endsWith(".json")) continue;
|
|
18442
18554
|
try {
|
|
18443
|
-
const record = JSON.parse(await readFile4(
|
|
18555
|
+
const record = JSON.parse(await readFile4(join11(dir, entry), "utf8"));
|
|
18444
18556
|
const id = record.acp_session_id ?? record.acpx?.backendSessionId ?? record.backendSessionId ?? record.agentSessionId;
|
|
18445
18557
|
if (typeof id === "string" && id.trim()) ids.add(id.trim());
|
|
18446
18558
|
} catch {
|
|
@@ -18556,8 +18668,8 @@ async function getCodexUsage(refresh = false) {
|
|
|
18556
18668
|
|
|
18557
18669
|
// src/claude-usage.ts
|
|
18558
18670
|
import { readFile as readFile5, stat as stat2 } from "node:fs/promises";
|
|
18559
|
-
import { homedir as
|
|
18560
|
-
import { join as
|
|
18671
|
+
import { homedir as homedir5 } from "node:os";
|
|
18672
|
+
import { join as join12 } from "node:path";
|
|
18561
18673
|
|
|
18562
18674
|
// src/agent-usage.ts
|
|
18563
18675
|
var unavailableUsage = (reason, source) => ({
|
|
@@ -18597,13 +18709,13 @@ function normalizeClaudeUsage(raw, checkedAt = Date.now(), stale = false) {
|
|
|
18597
18709
|
return { status: "available", plan: raw.plan, windows, source: "statusline", stale, checkedAt };
|
|
18598
18710
|
}
|
|
18599
18711
|
async function readClaudeUsage() {
|
|
18600
|
-
const home =
|
|
18712
|
+
const home = homedir5();
|
|
18601
18713
|
const candidates = [
|
|
18602
|
-
|
|
18603
|
-
|
|
18604
|
-
|
|
18605
|
-
|
|
18606
|
-
|
|
18714
|
+
join12(home, ".claude/statusline-snapshot.json"),
|
|
18715
|
+
join12(home, ".claude/kaboo-statusline.json"),
|
|
18716
|
+
join12(home, ".claude/anthropic-statusline.json"),
|
|
18717
|
+
join12(home, ".onwatch/data/anthropic-statusline.json"),
|
|
18718
|
+
join12(home, ".local/share/onwatch/claude_statusline.json")
|
|
18607
18719
|
];
|
|
18608
18720
|
for (const path5 of candidates) {
|
|
18609
18721
|
try {
|
|
@@ -18632,12 +18744,12 @@ async function getClaudeUsage(refresh = false) {
|
|
|
18632
18744
|
}
|
|
18633
18745
|
|
|
18634
18746
|
// src/cursor-usage.ts
|
|
18635
|
-
import { execFile as
|
|
18747
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
18636
18748
|
import { readFile as readFile6 } from "node:fs/promises";
|
|
18637
|
-
import { homedir as
|
|
18638
|
-
import { join as
|
|
18639
|
-
import { promisify as
|
|
18640
|
-
var
|
|
18749
|
+
import { homedir as homedir6, platform } from "node:os";
|
|
18750
|
+
import { join as join13 } from "node:path";
|
|
18751
|
+
import { promisify as promisify4 } from "node:util";
|
|
18752
|
+
var execFileAsync3 = promisify4(execFile5);
|
|
18641
18753
|
function normalizeCursorUsage(summary, checkedAt = Date.now()) {
|
|
18642
18754
|
if (!summary.billingCycleStart) return { ...unavailableUsage("Cursor \u672A\u8FD4\u56DE\u6709\u6548\u7684\u8BA2\u9605\u6570\u636E", "cursor.com"), checkedAt };
|
|
18643
18755
|
const resetsAt = resetSeconds(summary.billingCycleEnd);
|
|
@@ -18676,7 +18788,7 @@ function normalizeSessionToken(raw) {
|
|
|
18676
18788
|
async function cursorToken() {
|
|
18677
18789
|
if (platform() === "darwin") {
|
|
18678
18790
|
try {
|
|
18679
|
-
const { stdout } = await
|
|
18791
|
+
const { stdout } = await execFileAsync3("security", ["find-generic-password", "-s", "cursor-access-token", "-a", "cursor-user", "-w"], { timeout: 3e3, maxBuffer: 16384 });
|
|
18680
18792
|
if (stdout.trim()) return { token: normalizeSessionToken(stdout), source: "Cursor CLI" };
|
|
18681
18793
|
} catch (error) {
|
|
18682
18794
|
const code = error.code;
|
|
@@ -18684,7 +18796,7 @@ async function cursorToken() {
|
|
|
18684
18796
|
}
|
|
18685
18797
|
}
|
|
18686
18798
|
try {
|
|
18687
|
-
const auth = JSON.parse(await readFile6(
|
|
18799
|
+
const auth = JSON.parse(await readFile6(join13(homedir6(), ".config/cursor/auth.json"), "utf8"));
|
|
18688
18800
|
if (typeof auth.accessToken === "string" && auth.accessToken.trim()) return { token: normalizeSessionToken(auth.accessToken), source: "Cursor Agent" };
|
|
18689
18801
|
} catch {
|
|
18690
18802
|
}
|
|
@@ -18721,13 +18833,13 @@ async function getCursorUsage(refresh = false) {
|
|
|
18721
18833
|
}
|
|
18722
18834
|
|
|
18723
18835
|
// src/system-routes.ts
|
|
18724
|
-
import { execFile as
|
|
18725
|
-
import { promisify as
|
|
18836
|
+
import { execFile as execFile6 } from "node:child_process";
|
|
18837
|
+
import { promisify as promisify5 } from "node:util";
|
|
18726
18838
|
|
|
18727
18839
|
// src/skill-catalog.ts
|
|
18728
18840
|
import { readFile as readFile7, readdir as readdir2 } from "node:fs/promises";
|
|
18729
|
-
import { homedir as
|
|
18730
|
-
import { basename as basename2, dirname as
|
|
18841
|
+
import { homedir as homedir7 } from "node:os";
|
|
18842
|
+
import { basename as basename2, dirname as dirname9, join as join14, resolve as resolve5 } from "node:path";
|
|
18731
18843
|
var ignoredDirectories = /* @__PURE__ */ new Set([".git", "node_modules", "dist", "build"]);
|
|
18732
18844
|
async function findSkillFiles(root3, maxDepth = 5) {
|
|
18733
18845
|
const found = [];
|
|
@@ -18740,8 +18852,8 @@ async function findSkillFiles(root3, maxDepth = 5) {
|
|
|
18740
18852
|
return;
|
|
18741
18853
|
}
|
|
18742
18854
|
for (const entry of entries) {
|
|
18743
|
-
if (entry.isFile() && entry.name === "SKILL.md") found.push(
|
|
18744
|
-
else if (entry.isDirectory() && !ignoredDirectories.has(entry.name)) await visit(
|
|
18855
|
+
if (entry.isFile() && entry.name === "SKILL.md") found.push(join14(directory, entry.name));
|
|
18856
|
+
else if (entry.isDirectory() && !ignoredDirectories.has(entry.name)) await visit(join14(directory, entry.name), depth + 1);
|
|
18745
18857
|
}
|
|
18746
18858
|
};
|
|
18747
18859
|
await visit(root3, 0);
|
|
@@ -18755,15 +18867,15 @@ function frontmatterValue(markdown, key) {
|
|
|
18755
18867
|
async function discoverSkills(workspace) {
|
|
18756
18868
|
const workspaceRoot = resolve5(workspace?.trim() || process.cwd());
|
|
18757
18869
|
const roots = [
|
|
18758
|
-
{ path:
|
|
18759
|
-
{ path:
|
|
18760
|
-
{ path:
|
|
18761
|
-
{ path:
|
|
18870
|
+
{ path: join14(workspaceRoot, ".agents", "skills"), source: "workspace" },
|
|
18871
|
+
{ path: join14(workspaceRoot, ".codex", "skills"), source: "workspace" },
|
|
18872
|
+
{ path: join14(homedir7(), ".agents", "skills"), source: "user" },
|
|
18873
|
+
{ path: join14(homedir7(), ".codex", "skills"), source: "user" }
|
|
18762
18874
|
];
|
|
18763
18875
|
const references = await Promise.all(roots.map(async (root3) => Promise.all((await findSkillFiles(root3.path)).map(async (path5) => {
|
|
18764
18876
|
const markdown = await readFile7(path5, "utf8").catch(() => "");
|
|
18765
18877
|
return {
|
|
18766
|
-
name: frontmatterValue(markdown, "name") || basename2(
|
|
18878
|
+
name: frontmatterValue(markdown, "name") || basename2(dirname9(path5)),
|
|
18767
18879
|
description: frontmatterValue(markdown, "description"),
|
|
18768
18880
|
path: path5,
|
|
18769
18881
|
source: root3.source
|
|
@@ -18779,16 +18891,16 @@ async function discoverSkills(workspace) {
|
|
|
18779
18891
|
}
|
|
18780
18892
|
|
|
18781
18893
|
// src/system-routes.ts
|
|
18782
|
-
var
|
|
18894
|
+
var execFileAsync4 = promisify5(execFile6);
|
|
18783
18895
|
async function selectMacDirectory() {
|
|
18784
|
-
const { stdout } = await
|
|
18896
|
+
const { stdout } = await execFileAsync4("/usr/bin/osascript", [
|
|
18785
18897
|
"-e",
|
|
18786
18898
|
'POSIX path of (choose folder with prompt "\u9009\u62E9 Agent \u5DE5\u4F5C\u533A")'
|
|
18787
18899
|
], { timeout: 12e4 });
|
|
18788
18900
|
return stdout.trim().replace(/\/$/, "") || "/";
|
|
18789
18901
|
}
|
|
18790
18902
|
async function selectMacFile() {
|
|
18791
|
-
const { stdout } = await
|
|
18903
|
+
const { stdout } = await execFileAsync4("/usr/bin/osascript", [
|
|
18792
18904
|
"-e",
|
|
18793
18905
|
'POSIX path of (choose file with prompt "\u9009\u62E9\u8981\u5F15\u7528\u7684\u672C\u5730\u6587\u4EF6")'
|
|
18794
18906
|
], { timeout: 12e4 });
|
|
@@ -18798,6 +18910,17 @@ async function registerSystemRoutes(app, options = {}) {
|
|
|
18798
18910
|
const platform2 = options.platform ?? process.platform;
|
|
18799
18911
|
const supported = platform2 === "darwin";
|
|
18800
18912
|
app.get("/api/system/capabilities", async () => ({ platform: platform2, directoryPicker: supported, filePicker: supported, workingDirectory: process.cwd() }));
|
|
18913
|
+
app.get("/api/system/autostart", async () => options.autostart?.status() ?? { supported: false, enabled: false, reason: "\u5F53\u524D\u8FD0\u884C\u65B9\u5F0F\u4E0D\u652F\u6301" });
|
|
18914
|
+
app.put("/api/system/autostart", async (request, reply) => {
|
|
18915
|
+
const enabled = request.body?.enabled;
|
|
18916
|
+
if (typeof enabled !== "boolean") return reply.code(400).send({ error: { code: "INVALID_AUTOSTART_REQUEST", message: "enabled must be a boolean" } });
|
|
18917
|
+
if (!options.autostart) return reply.code(501).send({ error: { code: "AUTOSTART_UNSUPPORTED", message: "\u5F53\u524D\u8FD0\u884C\u65B9\u5F0F\u4E0D\u652F\u6301\u5F00\u673A\u81EA\u542F" } });
|
|
18918
|
+
try {
|
|
18919
|
+
return enabled ? await options.autostart.enable() : await options.autostart.disable();
|
|
18920
|
+
} catch (error) {
|
|
18921
|
+
return reply.code(409).send({ error: { code: "AUTOSTART_FAILED", message: error instanceof Error ? error.message : String(error) } });
|
|
18922
|
+
}
|
|
18923
|
+
});
|
|
18801
18924
|
app.get("/api/system/skills", async (request) => (options.discoverSkills ?? discoverSkills)(request.query.cwd));
|
|
18802
18925
|
app.post("/api/system/select-directory", async (_request, reply) => {
|
|
18803
18926
|
if (!supported) return reply.code(501).send({ error: { code: "DIRECTORY_PICKER_UNSUPPORTED", message: "The native directory picker is currently available on macOS only" } });
|
|
@@ -19843,17 +19966,17 @@ data: ${JSON.stringify(data)}
|
|
|
19843
19966
|
|
|
19844
19967
|
// src/web-password.ts
|
|
19845
19968
|
import { randomBytes as randomBytes3, scryptSync, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
19846
|
-
import { chmodSync as chmodSync2, existsSync as
|
|
19847
|
-
import { homedir as
|
|
19848
|
-
import { dirname as
|
|
19969
|
+
import { chmodSync as chmodSync2, existsSync as existsSync6, mkdirSync as mkdirSync5, readFileSync as readFileSync6, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
19970
|
+
import { homedir as homedir8 } from "node:os";
|
|
19971
|
+
import { dirname as dirname10, join as join15 } from "node:path";
|
|
19849
19972
|
var webPasswordFileName = "web-password";
|
|
19850
19973
|
var SCRYPT_N = 16384;
|
|
19851
19974
|
var SCRYPT_R = 8;
|
|
19852
19975
|
var SCRYPT_P = 1;
|
|
19853
19976
|
var KEY_LENGTH = 32;
|
|
19854
19977
|
var minWebPasswordLength = 6;
|
|
19855
|
-
function webPasswordPath(home =
|
|
19856
|
-
return
|
|
19978
|
+
function webPasswordPath(home = homedir8()) {
|
|
19979
|
+
return join15(home, ".agentdock", webPasswordFileName);
|
|
19857
19980
|
}
|
|
19858
19981
|
function hashWebPassword(password) {
|
|
19859
19982
|
const salt = randomBytes3(16);
|
|
@@ -19887,14 +20010,14 @@ function webPasswordEnabled(path5 = webPasswordPath()) {
|
|
|
19887
20010
|
}
|
|
19888
20011
|
function setWebPassword(password, path5 = webPasswordPath()) {
|
|
19889
20012
|
if (password.length < minWebPasswordLength) throw new Error(`\u5BC6\u7801\u81F3\u5C11 ${minWebPasswordLength} \u4F4D\u3002`);
|
|
19890
|
-
|
|
19891
|
-
|
|
20013
|
+
mkdirSync5(dirname10(path5), { recursive: true, mode: 448 });
|
|
20014
|
+
writeFileSync4(path5, `${hashWebPassword(password)}
|
|
19892
20015
|
`, { mode: 384 });
|
|
19893
20016
|
chmodSync2(path5, 384);
|
|
19894
20017
|
}
|
|
19895
20018
|
function clearWebPassword(path5 = webPasswordPath()) {
|
|
19896
|
-
if (!
|
|
19897
|
-
|
|
20019
|
+
if (!existsSync6(path5)) return false;
|
|
20020
|
+
rmSync3(path5, { force: true });
|
|
19898
20021
|
return true;
|
|
19899
20022
|
}
|
|
19900
20023
|
var LoginRateLimiter = class {
|
|
@@ -20315,7 +20438,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
20315
20438
|
"audio/flac": ".flac",
|
|
20316
20439
|
"application/octet-stream": ""
|
|
20317
20440
|
};
|
|
20318
|
-
const globalUploadRoot =
|
|
20441
|
+
const globalUploadRoot = join16(homedir9(), ".agentdock", "uploads");
|
|
20319
20442
|
const uploadTtlMs = 7 * 24 * 60 * 6e4;
|
|
20320
20443
|
const collectExpiredUploads = async (now2 = Date.now()) => {
|
|
20321
20444
|
let removedFiles = 0;
|
|
@@ -20326,7 +20449,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
20326
20449
|
return { removedFiles };
|
|
20327
20450
|
}
|
|
20328
20451
|
for (const sessionDir of sessionDirs) {
|
|
20329
|
-
const directory =
|
|
20452
|
+
const directory = join16(globalUploadRoot, sessionDir);
|
|
20330
20453
|
let names;
|
|
20331
20454
|
try {
|
|
20332
20455
|
names = await readdir4(directory);
|
|
@@ -20334,7 +20457,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
20334
20457
|
continue;
|
|
20335
20458
|
}
|
|
20336
20459
|
for (const name of names) {
|
|
20337
|
-
const filePath =
|
|
20460
|
+
const filePath = join16(directory, name);
|
|
20338
20461
|
try {
|
|
20339
20462
|
const info = await stat4(filePath);
|
|
20340
20463
|
if (!info.isFile() || now2 - info.mtimeMs <= uploadTtlMs) continue;
|
|
@@ -20380,10 +20503,10 @@ async function buildApp(runtime, options = {}) {
|
|
|
20380
20503
|
originalName = rawName;
|
|
20381
20504
|
}
|
|
20382
20505
|
const ext = extFromContentType(contentType, originalName);
|
|
20383
|
-
const uploadDir =
|
|
20506
|
+
const uploadDir = join16(globalUploadRoot, session.id);
|
|
20384
20507
|
await mkdir4(uploadDir, { recursive: true });
|
|
20385
20508
|
const filename = `${Date.now()}-${randomBytes4(6).toString("hex")}${ext}`;
|
|
20386
|
-
const filePath =
|
|
20509
|
+
const filePath = join16(uploadDir, filename);
|
|
20387
20510
|
await writeFile4(filePath, buffer);
|
|
20388
20511
|
return reply.code(201).send({ path: filePath, url: `/api/sessions/${session.id}/uploads/${filename}`, filename });
|
|
20389
20512
|
});
|
|
@@ -20394,7 +20517,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
20394
20517
|
if (filename.includes("..") || filename.includes("/") || filename.includes("\\")) {
|
|
20395
20518
|
throw new RuntimeError("INVALID_UPLOAD", "Invalid filename", 400);
|
|
20396
20519
|
}
|
|
20397
|
-
const filePath =
|
|
20520
|
+
const filePath = join16(globalUploadRoot, session.id, filename);
|
|
20398
20521
|
const ext = extname(filename).toLowerCase();
|
|
20399
20522
|
const data = await readFile9(filePath);
|
|
20400
20523
|
reply.header("Content-Type", contentTypes[ext] ?? "application/octet-stream");
|
|
@@ -20887,7 +21010,8 @@ async function startLocalServer(options = {}) {
|
|
|
20887
21010
|
const packageJson2 = JSON.parse(readFileSync7(new URL("../package.json", import.meta.url), "utf8"));
|
|
20888
21011
|
const selfUpdate = options.cliEntrypoint ? new SelfUpdateService({ currentVersion: packageJson2.version, packageName: packageJson2.name, cliEntrypoint: options.cliEntrypoint, env }) : void 0;
|
|
20889
21012
|
schedules2 = new ScheduleService(repos.schedules, repos.sessions, runtime);
|
|
20890
|
-
|
|
21013
|
+
const autostart = options.cliEntrypoint ? new AutostartService({ entrypoint: options.cliEntrypoint, env }) : void 0;
|
|
21014
|
+
app = await buildApp(runtime, { webRoot, webAuth, schedules: schedules2, ...selfUpdate ? { selfUpdate } : {}, ...autostart ? { system: { autostart } } : {}, llm: { service: llm }, lark: { env, config: repos.config, agents: repos.agents, cardMappings: repos.channelMappings, runtime, agentTools, listeningDisabled: env.AGENTDOCK_DISABLE_LARK_LISTENER === "true" } });
|
|
20891
21015
|
await app.listen(listenOptions(config));
|
|
20892
21016
|
schedules2.start();
|
|
20893
21017
|
} catch (error) {
|
|
@@ -21419,22 +21543,22 @@ init_session_cli();
|
|
|
21419
21543
|
|
|
21420
21544
|
// src/dev-sandbox.ts
|
|
21421
21545
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
21422
|
-
import { existsSync as
|
|
21546
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync9, rmSync as rmSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
21423
21547
|
import { createServer } from "node:net";
|
|
21424
|
-
import { dirname as
|
|
21548
|
+
import { dirname as dirname11, join as join18, resolve as resolve10 } from "node:path";
|
|
21425
21549
|
var SANDBOX_FILE = "sandbox.json";
|
|
21426
21550
|
function findRepoRoot(start = process.cwd()) {
|
|
21427
21551
|
let dir = resolve10(start);
|
|
21428
21552
|
for (; ; ) {
|
|
21429
|
-
if (
|
|
21430
|
-
const parent =
|
|
21553
|
+
if (existsSync8(join18(dir, "apps", "server", "package.json")) && existsSync8(join18(dir, "pnpm-workspace.yaml"))) return dir;
|
|
21554
|
+
const parent = dirname11(dir);
|
|
21431
21555
|
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");
|
|
21432
21556
|
dir = parent;
|
|
21433
21557
|
}
|
|
21434
21558
|
}
|
|
21435
21559
|
function sandboxPaths(repo, port) {
|
|
21436
|
-
const root3 =
|
|
21437
|
-
return { root: root3, home:
|
|
21560
|
+
const root3 = join18(repo, ".agentdock", "dev");
|
|
21561
|
+
return { root: root3, home: join18(root3, "home"), work: join18(root3, "work"), database: join18(root3, "agentdock.db"), entrypoint: join18(repo, "apps", "server", "dist", "cli.js"), port };
|
|
21438
21562
|
}
|
|
21439
21563
|
function sandboxEnv(sandbox, base = process.env) {
|
|
21440
21564
|
const env = { ...base, HOME: sandbox.home, AGENTDOCK_DISABLE_LARK_LISTENER: "true", AGENTDOCK_WEB_AUTH: "off", agentdock_database: sandbox.database };
|
|
@@ -21443,7 +21567,7 @@ function sandboxEnv(sandbox, base = process.env) {
|
|
|
21443
21567
|
}
|
|
21444
21568
|
function readSandbox(repo) {
|
|
21445
21569
|
try {
|
|
21446
|
-
return JSON.parse(readFileSync9(
|
|
21570
|
+
return JSON.parse(readFileSync9(join18(repo, ".agentdock", "dev", SANDBOX_FILE), "utf8"));
|
|
21447
21571
|
} catch {
|
|
21448
21572
|
return void 0;
|
|
21449
21573
|
}
|
|
@@ -21468,9 +21592,9 @@ async function devUp(options = {}) {
|
|
|
21468
21592
|
const existing = readSandbox(repo);
|
|
21469
21593
|
const port = existing?.port ?? options.port ?? await freePort(4399);
|
|
21470
21594
|
const sandbox = sandboxPaths(repo, port);
|
|
21471
|
-
if (!
|
|
21472
|
-
for (const dir of [sandbox.home, sandbox.work])
|
|
21473
|
-
|
|
21595
|
+
if (!existsSync8(sandbox.entrypoint)) throw new Error(`\u6CA1\u6709\u6784\u5EFA\u4EA7\u7269\uFF1A${sandbox.entrypoint}\u3002\u5148\u5728\u4ED3\u5E93\u6839\u76EE\u5F55\u8FD0\u884C pnpm build\u3002`);
|
|
21596
|
+
for (const dir of [sandbox.home, sandbox.work]) mkdirSync6(dir, { recursive: true });
|
|
21597
|
+
writeFileSync5(join18(sandbox.root, SANDBOX_FILE), `${JSON.stringify(sandbox, null, 2)}
|
|
21474
21598
|
`);
|
|
21475
21599
|
const run2 = options.run ?? defaultRun;
|
|
21476
21600
|
const env = sandboxEnv(sandbox);
|
|
@@ -21505,7 +21629,7 @@ function devDown(options = {}) {
|
|
|
21505
21629
|
const sandbox = readSandbox(repo);
|
|
21506
21630
|
if (!sandbox) return "\u6C99\u7BB1\u6CA1\u6709\u5728\u8FD0\u884C\u3002\n";
|
|
21507
21631
|
(options.run ?? defaultRun)([sandbox.entrypoint, "daemon", "stop"], sandboxEnv(sandbox), sandbox.work, false);
|
|
21508
|
-
if (!options.keepData)
|
|
21632
|
+
if (!options.keepData) rmSync4(sandbox.root, { recursive: true, force: true });
|
|
21509
21633
|
return options.keepData ? `\u6C99\u7BB1\u5DF2\u505C\u6B62\uFF0C\u6570\u636E\u4FDD\u7559\u5728 ${sandbox.root}\u3002
|
|
21510
21634
|
` : "\u6C99\u7BB1\u5DF2\u505C\u6B62\u5E76\u6E05\u7406\u3002\n";
|
|
21511
21635
|
}
|
|
@@ -21734,7 +21858,7 @@ async function serve(options, onReady) {
|
|
|
21734
21858
|
});
|
|
21735
21859
|
}
|
|
21736
21860
|
async function restartWithInstalledCli(entrypoint) {
|
|
21737
|
-
if (!
|
|
21861
|
+
if (!existsSync9(entrypoint)) throw new Error(`Updated AgentDock entrypoint was not found: ${entrypoint}. The service was not restarted.`);
|
|
21738
21862
|
const previousPid = daemonStatus().pid;
|
|
21739
21863
|
const child = spawn10(process.execPath, [entrypoint, "daemon", "restart"], { stdio: "inherit", env: process.env });
|
|
21740
21864
|
await new Promise((resolve11, reject2) => {
|
|
@@ -21787,6 +21911,17 @@ async function main() {
|
|
|
21787
21911
|
daemonStatus: (options) => {
|
|
21788
21912
|
const status = daemonStatus();
|
|
21789
21913
|
process.stdout.write(`${options.json ? JSON.stringify({ ok: true, action: "status", ...status }) : formatDaemonStatus(status, { interactive: interactiveOutput() })}
|
|
21914
|
+
`);
|
|
21915
|
+
},
|
|
21916
|
+
autostart: async (action, options) => {
|
|
21917
|
+
const service = new AutostartService({ entrypoint: fileURLToPath6(import.meta.url) });
|
|
21918
|
+
const status = action === "enable" ? await service.enable() : action === "disable" ? await service.disable() : service.status();
|
|
21919
|
+
if (options.json) {
|
|
21920
|
+
output({ action, ...status });
|
|
21921
|
+
return;
|
|
21922
|
+
}
|
|
21923
|
+
process.stdout.write(`${!status.supported ? `\u4E0D\u652F\u6301\uFF1A${status.reason}` : status.enabled ? `\u5F00\u673A\u81EA\u542F\uFF1A\u5DF2\u5F00\u542F
|
|
21924
|
+
${status.plistPath}` : "\u5F00\u673A\u81EA\u542F\uFF1A\u672A\u5F00\u542F"}
|
|
21790
21925
|
`);
|
|
21791
21926
|
},
|
|
21792
21927
|
update: async (options) => {
|