@agent-dock/cli 0.3.19 → 0.3.21
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 +370 -96
- package/dist/cli.js.map +3 -3
- package/package.json +1 -1
- package/public/assets/{ImageLightbox-uTy7xK9b.js → ImageLightbox-CAtzWriv.js} +1 -1
- package/public/assets/{PromptEditor-CDvFjBZX.js → PromptEditor-DIIxWw25.js} +1 -1
- package/public/assets/index-DGQnK45p.css +1 -0
- package/public/assets/{main-tvLYP_4f.js → main-DvU2hFvR.js} +283 -283
- package/public/assets/{sourcesRouter-0alkUGCE.js → sourcesRouter-DMITEG81.js} +1 -1
- package/public/index.html +3 -3
- package/public/sources-router.html +3 -3
- package/public/assets/index-CjxH5qGO.css +0 -1
- /package/public/assets/{index-DmdDXpGt.js → index-ua9DFgh1.js} +0 -0
package/dist/cli.js
CHANGED
|
@@ -1189,7 +1189,13 @@ function pickFinalAssistantText(entries) {
|
|
|
1189
1189
|
const text3 = index >= 0 ? folded[index]?.data?.text : void 0;
|
|
1190
1190
|
return typeof text3 === "string" ? text3 : "";
|
|
1191
1191
|
}
|
|
1192
|
-
|
|
1192
|
+
function isDeferredAsyncWaitText(text3) {
|
|
1193
|
+
const trimmed = text3?.trim();
|
|
1194
|
+
if (!trimmed || trimmed.length > DEFERRED_WAIT_MAX_CHARS) return false;
|
|
1195
|
+
if (DEFERRED_WAIT_DISPATCH_RE.test(trimmed)) return false;
|
|
1196
|
+
return DEFERRED_WAIT_PATTERNS.some((pattern) => pattern.test(trimmed));
|
|
1197
|
+
}
|
|
1198
|
+
var isTerminalToolStatus, isPendingToolStatus, isAssistantText, isToolEntry, toolCallIdOf, toolStatusOf, isCarriedOverToolCall, agentWarningPrefix, isAgentWarningText, agentStreamErrorPrefix, agentStreamErrorSuffix, isAgentStreamErrorText, antigravityAuthErrorPattern, DEFERRED_WAIT_MAX_CHARS, DEFERRED_WAIT_DISPATCH_RE, DEFERRED_WAIT_PATTERNS, ACPX_DEFERRED_WAIT_CORRECTION_PROMPT;
|
|
1193
1199
|
var init_turn_outcome = __esm({
|
|
1194
1200
|
"../../packages/shared/src/turn-outcome.ts"() {
|
|
1195
1201
|
"use strict";
|
|
@@ -1206,6 +1212,15 @@ var init_turn_outcome = __esm({
|
|
|
1206
1212
|
agentStreamErrorSuffix = /(?:\r?\n){1,2}Error:\s*(?:RetriableError|T):[^\n]*\s*$/i;
|
|
1207
1213
|
isAgentStreamErrorText = (text3) => agentStreamErrorPrefix.test(text3);
|
|
1208
1214
|
antigravityAuthErrorPattern = "^\\s*(?:\u26A0\\s*)?UNAUTHENTICATED\\s*\\(code\\s+401\\)";
|
|
1215
|
+
DEFERRED_WAIT_MAX_CHARS = 600;
|
|
1216
|
+
DEFERRED_WAIT_DISPATCH_RE = /(?:已派活|atask_[a-z0-9-]+)/i;
|
|
1217
|
+
DEFERRED_WAIT_PATTERNS = [
|
|
1218
|
+
/(?:正在|仍在|已在|目前在|后台正在|当前正在).{0,35}(?:后台|运行|执行|构建|编译|测试|跑|等待|进行中|发布|触发).{0,45}(?:完成后|结束后|跑完后|一完成|稍后|随后|会自动|我会立刻|我会再|再继续|再汇报|再通知|再进入|再验收)/,
|
|
1219
|
+
/(?:等|等待).{0,25}(?:完成|结束|跑完|返回|结果|构建|测试|发布|流水线|通知).{0,25}(?:后|之后|再|我会|立刻|自动|继续|汇报|推进|唤醒)/,
|
|
1220
|
+
/\b(?:running|executing|building|testing|waiting)\b.{0,45}\b(?:in the background|for (?:it|the build|the test|the tests|the task|the command|ci|workflow|run|completion) to (?:finish|complete))\b/i,
|
|
1221
|
+
/\b(?:i['’]?ll|will)\s+(?:wake up|resume|continue|report|follow up|let you know|proceed)\b.{0,35}\b(?:when|once|as soon as)\b.{0,30}\b(?:finish|finishes|complete|completes|done|ready)\b/i
|
|
1222
|
+
];
|
|
1223
|
+
ACPX_DEFERRED_WAIT_CORRECTION_PROMPT = "[AgentDock \u5F3A\u7EA6\u675F] ACPX \u6309\u8F6E\u6B21\u6536\u53E3\uFF0C\u672C\u8F6E\u7ED3\u675F\u540E\u4E0D\u4F1A\u628A\u5185\u7F6E\u540E\u53F0\u4EFB\u52A1\uFF08background task\uFF09\u3001\u5185\u7F6E subAgent \u6216\u5B9A\u65F6\u5668\u7684\u5B8C\u6210\u4E8B\u4EF6\u5F02\u6B65\u63A8\u56DE\u5524\u9192\u4F60\u2014\u2014\u4F60\u521A\u624D\u7ED3\u675F\u672C\u8F6E\u4F1A\u8BA9\u7528\u6237\u4E00\u76F4\u5E72\u7B49\u3002\u8BF7\u7ACB\u523B\u68C0\u67E5\u672A\u5B8C\u6210\u7684\u540E\u53F0\u4EFB\u52A1\u72B6\u6001\uFF0C\u5E76\u5728\u672C\u8F6E\u5DE5\u5177\u8C03\u7528\u5185\u540C\u6B65\u7B49\u5230\u6700\u7EC8\u7ED3\u679C\u518D\u7ED9\u51FA\u5B8C\u6574\u7B54\u590D\uFF1B\u4E25\u7981\u518D\u6B21\u63D0\u524D\u7ED3\u675F\u672C\u8F6E\u7B49\u5F85\u901A\u77E5\u3002";
|
|
1209
1224
|
}
|
|
1210
1225
|
});
|
|
1211
1226
|
|
|
@@ -1316,7 +1331,10 @@ function validateHighRiskPattern(pattern) {
|
|
|
1316
1331
|
if (!safeRegex(pattern)) return { valid: false, error: "\u6B63\u5219\u8868\u8FBE\u5F0F\u53EF\u80FD\u9020\u6210\u707E\u96BE\u6027\u56DE\u6EAF\uFF0C\u8BF7\u79FB\u9664\u5D4C\u5957\u91CF\u8BCD\u6216\u62C6\u5206\u590D\u6742\u8868\u8FBE\u5F0F" };
|
|
1317
1332
|
return { valid: true };
|
|
1318
1333
|
}
|
|
1319
|
-
|
|
1334
|
+
function isMainSessionScheduleTarget(sessionId) {
|
|
1335
|
+
return sessionId === SCHEDULE_MAIN_SESSION_ID;
|
|
1336
|
+
}
|
|
1337
|
+
var highRiskPatternMaxLength, protocols, permissionModes, agentConfigSchema, RuntimeError, SCHEDULE_MAIN_SESSION_ID, now, makeId, defaultLarkTraceLimit;
|
|
1320
1338
|
var init_src2 = __esm({
|
|
1321
1339
|
"../../packages/shared/src/index.ts"() {
|
|
1322
1340
|
init_turn_outcome();
|
|
@@ -1359,6 +1377,7 @@ var init_src2 = __esm({
|
|
|
1359
1377
|
code;
|
|
1360
1378
|
statusCode;
|
|
1361
1379
|
};
|
|
1380
|
+
SCHEDULE_MAIN_SESSION_ID = "main";
|
|
1362
1381
|
now = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
1363
1382
|
makeId = (prefix) => `${prefix}_${crypto.randomUUID()}`;
|
|
1364
1383
|
defaultLarkTraceLimit = 50;
|
|
@@ -6436,13 +6455,13 @@ __export(session_cli_exports, {
|
|
|
6436
6455
|
streamSessionShow: () => streamSessionShow
|
|
6437
6456
|
});
|
|
6438
6457
|
import { existsSync as existsSync10 } from "node:fs";
|
|
6439
|
-
import { join as
|
|
6458
|
+
import { join as join23, resolve as resolve12 } from "node:path";
|
|
6440
6459
|
function resolveDatabasePath(explicit, cwd = process.cwd()) {
|
|
6441
6460
|
if (explicit) return resolve12(cwd, explicit);
|
|
6442
6461
|
if (process.env.AGENTDOCK_DATABASE_URL) return resolve12(cwd, process.env.AGENTDOCK_DATABASE_URL);
|
|
6443
6462
|
const daemonDir = resolveDaemonDir(cwd);
|
|
6444
6463
|
const recorded = readDaemonStatus(daemonDir)?.database;
|
|
6445
|
-
return recorded ? resolve12(daemonDir, recorded) :
|
|
6464
|
+
return recorded ? resolve12(daemonDir, recorded) : join23(daemonDir, "..", "agentdock.db");
|
|
6446
6465
|
}
|
|
6447
6466
|
function sessionPeerIds(sessions2, sourceId2) {
|
|
6448
6467
|
const source2 = sessions2.find((session) => session.id === sourceId2);
|
|
@@ -6845,8 +6864,9 @@ Notes:
|
|
|
6845
6864
|
dev.command("env").description("Print sandbox URL, database and paths as JSON (for scripts and browser checks)").option("--repo <dir>", "agent-dock source repo").action((options) => handlers.devEnv?.(options));
|
|
6846
6865
|
dev.command("down").description("Stop the sandbox and delete its data").option("--keep-data", "Stop but keep the sandbox database for inspection").option("--repo <dir>", "agent-dock source repo").action((options) => handlers.devDown?.(options));
|
|
6847
6866
|
const schedule = program.command("schedule").description("Register and manage AgentDock scheduled prompts (persisted by the daemon, survive restarts)");
|
|
6848
|
-
schedule.command("add").description("Register a scheduled prompt; defaults to the current session (agentdock_session_id)").argument("<prompt>", "Prompt delivered to the session when the schedule fires").option("--cron <expr>", 'Recurring 5-field cron expression, e.g. "0 9 * * 1-5"').option("--every <interval>", "Fixed interval from now, e.g. 45m, 2h, 1h30m, 1d (not limited to divisors of 60 like cron)").option("--at <time>", 'One-shot trigger time, e.g. "2026-10-14 18:00" (local) or ISO 8601').option("--tz <timezone>", "IANA timezone for --cron, defaults to the machine timezone").option("--name <name>", "Short label shown in lists").option("--delivery <mode>", "new_session (default: fresh session each run) or append (continue in the bound session)").option("--session <session-id>",
|
|
6849
|
-
schedule.command("
|
|
6867
|
+
schedule.command("add").alias("create").description("Register a scheduled prompt; defaults to the current session (agentdock_session_id)").argument("<prompt>", "Prompt delivered to the session when the schedule fires").option("--cron <expr>", 'Recurring 5-field cron expression, e.g. "0 9 * * 1-5"').option("--every <interval>", "Fixed interval from now, e.g. 45m, 2h, 1h30m, 1d (not limited to divisors of 60 like cron)").option("--at <time>", 'One-shot trigger time, e.g. "2026-10-14 18:00" (local) or ISO 8601').option("--tz <timezone>", "IANA timezone for --cron, defaults to the machine timezone").option("--name <name>", "Short label shown in lists").option("--delivery <mode>", "new_session (default: fresh session each run) or append (continue in the bound session)").option("--session <session-id>", 'Bind to this session (use "main" to dynamically follow the active main session)').option("--main", "Dynamically follow the active main session (shorthand for --session main; survives handoff)").option("--from <session-id>", "Source session ID (defaults to agentdock_session_id)").option("--json", "Output the created schedule as JSON").action((prompt, options) => handlers.scheduleAdd?.(prompt, options));
|
|
6868
|
+
schedule.command("update").description("Update an existing schedule (prompt, timing, delivery, or target session)").argument("<schedule-id>", "Schedule ID (sch_*)").option("--prompt <prompt>", "Updated prompt text").option("--name <name>", "Updated short label").option("--cron <expr>", "Switch to a 5-field cron expression").option("--every <interval>", "Switch to a fixed interval, e.g. 45m, 2h, 1d").option("--at <time>", "Switch to a one-shot trigger time").option("--tz <timezone>", "IANA timezone for --cron").option("--delivery <mode>", "new_session or append").option("--session <session-id>", 'Rebind to this session (use "main" to dynamically follow the active main session)').option("--main", "Dynamically follow the active main session (shorthand for --session main)").option("--from <session-id>", "Source session ID (defaults to agentdock_session_id)").option("--json", "Output the updated schedule as JSON").action((id, options) => handlers.scheduleUpdate?.(id, options));
|
|
6869
|
+
schedule.command("list").description("List schedules of the current session (all schedules outside a session)").option("--all", "List schedules of every session").option("--session <session-id>", 'List schedules bound to this session (use "main" for main-following schedules)').option("--main", "List schedules dynamically following the active main session").option("--json", "Output raw schedule rows as JSON").action((options) => handlers.scheduleList?.(options));
|
|
6850
6870
|
schedule.command("show").description("Show one schedule with its recent runs").argument("<schedule-id>", "Schedule ID (sch_*)").option("--json", "Output raw schedule and runs as JSON").action((id, options) => handlers.scheduleShow?.(id, options));
|
|
6851
6871
|
for (const [name, description, handler] of [
|
|
6852
6872
|
["pause", "Pause a schedule", "schedulePause"],
|
|
@@ -6866,6 +6886,8 @@ Examples:
|
|
|
6866
6886
|
$ agent-dock schedule add "\u68C0\u67E5\u53D1\u5E03\u72B6\u6001" --every 45m # also 2h, 1h30m, 1d
|
|
6867
6887
|
$ agent-dock schedule add "\u63D0\u9192\u6211\u5F00\u4F1A" --at "2026-10-14 18:00" # local time; --tz for another zone
|
|
6868
6888
|
$ agent-dock schedule add "\u7EE7\u7EED\u8DDF\u8FDB" --every 1h --delivery append
|
|
6889
|
+
$ agent-dock schedule add "\u6BCF\u65E5\u5DE1\u68C0" --cron "0 9 * * *" --delivery append --main # follow active main session across handoffs
|
|
6890
|
+
$ agent-dock schedule update sch_xxx --main --delivery append
|
|
6869
6891
|
$ agent-dock schedule list
|
|
6870
6892
|
$ agent-dock schedule show|pause|resume|run|remove SCHEDULE_ID
|
|
6871
6893
|
|
|
@@ -19056,6 +19078,11 @@ var AgentDockRuntime = class _AgentDockRuntime {
|
|
|
19056
19078
|
if (riskPolicy) await this.applyRiskPolicy(session, driver, riskPolicy);
|
|
19057
19079
|
outcome = await this.executeTurnAndResolve(id, session, task, driver, resolvedAgentPrompt, retryAfterSequence);
|
|
19058
19080
|
}
|
|
19081
|
+
if (outcome.status === "completed" && session.source !== "assistant-main" && !this.interruptedTurns.has(id) && isDeferredAsyncWaitText(outcome.finalText)) {
|
|
19082
|
+
const retryAfterSequence = this.sequences.get(id);
|
|
19083
|
+
await this.emit(id, "status", { state: "acpx_sync_guard", reason: "deferred_async_wait" });
|
|
19084
|
+
outcome = await this.executeTurnAndResolve(id, session, task, driver, ACPX_DEFERRED_WAIT_CORRECTION_PROMPT, retryAfterSequence);
|
|
19085
|
+
}
|
|
19059
19086
|
task.finalText = outcome.finalText;
|
|
19060
19087
|
session.lastMessageAt = now();
|
|
19061
19088
|
if (outcome.status === "interrupted") {
|
|
@@ -19955,8 +19982,8 @@ import Fastify from "fastify";
|
|
|
19955
19982
|
import cors from "@fastify/cors";
|
|
19956
19983
|
import { readFile as readFile13, mkdir as mkdir4, readdir as readdir4, rm as rm2, stat as stat6, writeFile as writeFile4 } from "node:fs/promises";
|
|
19957
19984
|
import { Readable as Readable3 } from "node:stream";
|
|
19958
|
-
import { extname as extname2, join as
|
|
19959
|
-
import { homedir as
|
|
19985
|
+
import { extname as extname2, join as join22, resolve as resolve10, sep as sep3 } from "node:path";
|
|
19986
|
+
import { homedir as homedir16 } from "node:os";
|
|
19960
19987
|
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
19961
19988
|
|
|
19962
19989
|
// src/lark/routes.ts
|
|
@@ -23110,15 +23137,14 @@ function registerShareLinkRoutes(app, service, runtime) {
|
|
|
23110
23137
|
// src/schedules/routes.ts
|
|
23111
23138
|
function registerScheduleRoutes(app, schedules2) {
|
|
23112
23139
|
app.get("/api/schedules", async (request) => {
|
|
23113
|
-
|
|
23114
|
-
const sessionId = request.query?.sessionId?.trim();
|
|
23115
|
-
return sessionId ? all.filter((item) => item.sessionId === sessionId) : all;
|
|
23140
|
+
return schedules2.list(request.query?.sessionId?.trim() || void 0);
|
|
23116
23141
|
});
|
|
23117
23142
|
app.post("/api/schedules", async (request, reply) => {
|
|
23118
23143
|
const body = request.body ?? {};
|
|
23119
23144
|
const created = await schedules2.create({
|
|
23120
23145
|
prompt: body.prompt ?? "",
|
|
23121
23146
|
...body.sessionId !== void 0 ? { sessionId: body.sessionId } : {},
|
|
23147
|
+
...body.followMain !== void 0 ? { followMain: Boolean(body.followMain) } : {},
|
|
23122
23148
|
...body.template !== void 0 ? { template: body.template } : {},
|
|
23123
23149
|
...body.name !== void 0 ? { name: body.name } : {},
|
|
23124
23150
|
...body.delivery !== void 0 ? { delivery: body.delivery } : {},
|
|
@@ -23137,6 +23163,7 @@ function registerScheduleRoutes(app, schedules2) {
|
|
|
23137
23163
|
...body.prompt !== void 0 ? { prompt: body.prompt } : {},
|
|
23138
23164
|
...body.delivery !== void 0 ? { delivery: body.delivery } : {},
|
|
23139
23165
|
...body.sessionId !== void 0 ? { sessionId: body.sessionId } : {},
|
|
23166
|
+
...body.followMain !== void 0 ? { followMain: Boolean(body.followMain) } : {},
|
|
23140
23167
|
...body.template !== void 0 ? { template: body.template } : {},
|
|
23141
23168
|
...body.cron !== void 0 ? { cron: body.cron } : {},
|
|
23142
23169
|
...body.runAt !== void 0 ? { runAt: body.runAt } : {},
|
|
@@ -23963,9 +23990,10 @@ function registerTerminalWebSockets(server, runtime, options = {}) {
|
|
|
23963
23990
|
|
|
23964
23991
|
// src/fs-routes.ts
|
|
23965
23992
|
init_src2();
|
|
23966
|
-
import { realpathSync as realpathSync3 } from "node:fs";
|
|
23993
|
+
import { createReadStream, realpathSync as realpathSync3 } from "node:fs";
|
|
23967
23994
|
import { readdir as readdir3, readFile as readFile11, stat as stat5 } from "node:fs/promises";
|
|
23968
|
-
import {
|
|
23995
|
+
import { homedir as homedir13 } from "node:os";
|
|
23996
|
+
import { basename as basename7, isAbsolute as isAbsolute7, join as join19, relative, sep as sep2 } from "node:path";
|
|
23969
23997
|
|
|
23970
23998
|
// src/fs-paths.ts
|
|
23971
23999
|
import { existsSync as existsSync8, realpathSync as realpathSync2 } from "node:fs";
|
|
@@ -24158,13 +24186,18 @@ var textExtensions = /* @__PURE__ */ new Set([
|
|
|
24158
24186
|
".bib"
|
|
24159
24187
|
]);
|
|
24160
24188
|
var imageExtensions = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg", ".avif"]);
|
|
24189
|
+
var videoExtensions = /* @__PURE__ */ new Set([".mp4", ".webm", ".mov", ".m4v", ".ogv"]);
|
|
24190
|
+
var audioExtensions = /* @__PURE__ */ new Set([".mp3", ".wav", ".m4a", ".aac", ".ogg", ".flac", ".opus"]);
|
|
24161
24191
|
var maxTextPreviewBytes = 1024 * 1024;
|
|
24162
24192
|
var maxDocumentPreviewBytes = 20 * 1024 * 1024;
|
|
24193
|
+
var maxMediaPreviewBytes = 500 * 1024 * 1024;
|
|
24163
24194
|
function previewKindForName(name) {
|
|
24164
24195
|
const lower = name.toLowerCase();
|
|
24165
24196
|
const dot = lower.lastIndexOf(".");
|
|
24166
24197
|
const ext = dot >= 0 ? lower.slice(dot) : lower;
|
|
24167
24198
|
if (imageExtensions.has(ext)) return "image";
|
|
24199
|
+
if (videoExtensions.has(ext)) return "video";
|
|
24200
|
+
if (audioExtensions.has(ext)) return "audio";
|
|
24168
24201
|
if (textExtensions.has(ext)) return "text";
|
|
24169
24202
|
if (ext === ".pdf") return "pdf";
|
|
24170
24203
|
return "unsupported";
|
|
@@ -24179,10 +24212,28 @@ var imageMime = {
|
|
|
24179
24212
|
".svg": "image/svg+xml",
|
|
24180
24213
|
".avif": "image/avif"
|
|
24181
24214
|
};
|
|
24215
|
+
var mediaMime = {
|
|
24216
|
+
".mp4": "video/mp4",
|
|
24217
|
+
".webm": "video/webm",
|
|
24218
|
+
".mov": "video/quicktime",
|
|
24219
|
+
".m4v": "video/x-m4v",
|
|
24220
|
+
".ogv": "video/ogg",
|
|
24221
|
+
".mp3": "audio/mpeg",
|
|
24222
|
+
".wav": "audio/wav",
|
|
24223
|
+
".m4a": "audio/mp4",
|
|
24224
|
+
".aac": "audio/aac",
|
|
24225
|
+
".ogg": "audio/ogg",
|
|
24226
|
+
".flac": "audio/flac",
|
|
24227
|
+
".opus": "audio/opus"
|
|
24228
|
+
};
|
|
24182
24229
|
function imageMimeForName(name) {
|
|
24183
24230
|
const dot = name.toLowerCase().lastIndexOf(".");
|
|
24184
24231
|
return dot >= 0 ? imageMime[name.toLowerCase().slice(dot)] : void 0;
|
|
24185
24232
|
}
|
|
24233
|
+
function mediaMimeForName(name) {
|
|
24234
|
+
const dot = name.toLowerCase().lastIndexOf(".");
|
|
24235
|
+
return dot >= 0 ? mediaMime[name.toLowerCase().slice(dot)] : void 0;
|
|
24236
|
+
}
|
|
24186
24237
|
|
|
24187
24238
|
// src/fs-routes.ts
|
|
24188
24239
|
function badPath(error) {
|
|
@@ -24196,6 +24247,28 @@ function contentDispositionAttachment(filename) {
|
|
|
24196
24247
|
const safeAscii = filename.replace(/[^\x20-\x7e]/g, "_").replace(/["\\]/g, "_");
|
|
24197
24248
|
return `attachment; filename="${safeAscii}"; filename*=UTF-8''${encodeURIComponent(filename)}`;
|
|
24198
24249
|
}
|
|
24250
|
+
function parseSingleByteRange(rangeHeader, totalSize) {
|
|
24251
|
+
if (!rangeHeader.startsWith("bytes=")) return void 0;
|
|
24252
|
+
const spec = rangeHeader.slice("bytes=".length).split(",")[0]?.trim();
|
|
24253
|
+
if (!spec) return "invalid";
|
|
24254
|
+
const match = /^(\d*)-(\d*)$/.exec(spec);
|
|
24255
|
+
if (!match) return "invalid";
|
|
24256
|
+
const [, startText, endText] = match;
|
|
24257
|
+
if (!startText && !endText) return "invalid";
|
|
24258
|
+
if (totalSize === 0) return "invalid";
|
|
24259
|
+
if (!startText) {
|
|
24260
|
+
const suffixLength = Number(endText);
|
|
24261
|
+
if (!Number.isFinite(suffixLength) || suffixLength <= 0) return "invalid";
|
|
24262
|
+
const start2 = Math.max(0, totalSize - suffixLength);
|
|
24263
|
+
return { start: start2, end: totalSize - 1 };
|
|
24264
|
+
}
|
|
24265
|
+
const start = Number(startText);
|
|
24266
|
+
const end = endText ? Math.min(Number(endText), totalSize - 1) : totalSize - 1;
|
|
24267
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || start < 0 || start >= totalSize || end < start) {
|
|
24268
|
+
return "invalid";
|
|
24269
|
+
}
|
|
24270
|
+
return { start, end };
|
|
24271
|
+
}
|
|
24199
24272
|
async function registerFsRoutes(app, runtime, options = {}) {
|
|
24200
24273
|
app.get("/api/sessions/:id/fs/list", async (request) => {
|
|
24201
24274
|
const session = await runtime.getSession(request.params.id);
|
|
@@ -24236,31 +24309,30 @@ async function registerFsRoutes(app, runtime, options = {}) {
|
|
|
24236
24309
|
}
|
|
24237
24310
|
const userPath = request.query.path;
|
|
24238
24311
|
if (!userPath) throw new RuntimeError("INVALID_PATH", "\u7F3A\u5C11 path \u53C2\u6570", 400);
|
|
24239
|
-
|
|
24312
|
+
const expandedPath = userPath.startsWith("~/") ? join19(options.homeDir ?? homedir13(), userPath.slice(2)) : userPath;
|
|
24313
|
+
if (isSensitivePath(userPath) || isSensitivePath(expandedPath)) {
|
|
24240
24314
|
throw new RuntimeError("SENSITIVE_FILE_BLOCKED", "\u7981\u6B62\u9884\u89C8\u6216\u4E0B\u8F7D\u654F\u611F\u6587\u4EF6", 403);
|
|
24241
24315
|
}
|
|
24242
24316
|
const claim = request.webClaim;
|
|
24243
24317
|
const role = claim?.kind === "session" ? "session" : "master";
|
|
24244
24318
|
let resolved;
|
|
24245
24319
|
try {
|
|
24246
|
-
if (isAbsolute7(
|
|
24247
|
-
const realTarget = realpathSync3(
|
|
24248
|
-
|
|
24249
|
-
|
|
24250
|
-
|
|
24251
|
-
|
|
24252
|
-
|
|
24253
|
-
|
|
24254
|
-
|
|
24255
|
-
|
|
24256
|
-
|
|
24257
|
-
|
|
24258
|
-
"FORBIDDEN",
|
|
24259
|
-
|
|
24260
|
-
403
|
|
24261
|
-
);
|
|
24320
|
+
if (isAbsolute7(expandedPath)) {
|
|
24321
|
+
const realTarget = realpathSync3(expandedPath);
|
|
24322
|
+
if (role === "session") {
|
|
24323
|
+
const roots = allowedReadRoots({
|
|
24324
|
+
role,
|
|
24325
|
+
cwd: session.cwd,
|
|
24326
|
+
sessionId: request.params.id,
|
|
24327
|
+
...options.homeDir ? { homeDir: options.homeDir } : {},
|
|
24328
|
+
...options.tempDir ? { tempDir: options.tempDir } : {},
|
|
24329
|
+
...options.extraMasterRoots ? { extraMasterRoots: options.extraMasterRoots } : {}
|
|
24330
|
+
});
|
|
24331
|
+
if (!isRealPathWithinRoots(realTarget, roots)) {
|
|
24332
|
+
throw new RuntimeError("FORBIDDEN", "\u4F1A\u8BDD\u5206\u4EAB\u94FE\u63A5\u53EA\u80FD\u9884\u89C8\u8BE5\u4F1A\u8BDD\u5DE5\u4F5C\u533A\u53CA\u4E0A\u4F20\u76EE\u5F55\u5185\u7684\u6587\u4EF6", 403);
|
|
24333
|
+
}
|
|
24262
24334
|
}
|
|
24263
|
-
let rel =
|
|
24335
|
+
let rel = expandedPath;
|
|
24264
24336
|
try {
|
|
24265
24337
|
const realCwd = realpathSync3(session.cwd);
|
|
24266
24338
|
if (realTarget === realCwd || realTarget.startsWith(`${realCwd}${sep2}`)) {
|
|
@@ -24270,7 +24342,7 @@ async function registerFsRoutes(app, runtime, options = {}) {
|
|
|
24270
24342
|
}
|
|
24271
24343
|
resolved = { absolute: realTarget, relative: rel };
|
|
24272
24344
|
} else {
|
|
24273
|
-
resolved = resolveExistingInside(session.cwd,
|
|
24345
|
+
resolved = resolveExistingInside(session.cwd, expandedPath);
|
|
24274
24346
|
}
|
|
24275
24347
|
} catch (error) {
|
|
24276
24348
|
badPath(error);
|
|
@@ -24290,22 +24362,47 @@ async function registerFsRoutes(app, runtime, options = {}) {
|
|
|
24290
24362
|
const wantDownload = request.query.download === "1" || request.query.download === "true";
|
|
24291
24363
|
const wantText = request.query.format === "text";
|
|
24292
24364
|
if (wantDownload) {
|
|
24293
|
-
|
|
24294
|
-
|
|
24295
|
-
|
|
24296
|
-
const buffer2 = await readFile11(resolved.absolute);
|
|
24297
|
-
reply.header("Content-Type", imageMimeForName(filename) ?? (filename.toLowerCase().endsWith(".pdf") ? "application/pdf" : "application/octet-stream"));
|
|
24365
|
+
const contentType = imageMimeForName(filename) ?? mediaMimeForName(filename) ?? (filename.toLowerCase().endsWith(".pdf") ? "application/pdf" : "application/octet-stream");
|
|
24366
|
+
reply.header("Content-Type", contentType);
|
|
24367
|
+
reply.header("Content-Length", String(info.size));
|
|
24298
24368
|
reply.header("Content-Disposition", contentDispositionAttachment(filename));
|
|
24299
24369
|
reply.header("X-Content-Type-Options", "nosniff");
|
|
24300
24370
|
if (isSvg) reply.header("Content-Security-Policy", "sandbox");
|
|
24301
24371
|
reply.header("Cache-Control", "private, no-store");
|
|
24302
|
-
return reply.send(
|
|
24372
|
+
return reply.send(createReadStream(resolved.absolute));
|
|
24303
24373
|
}
|
|
24304
24374
|
const baseKind = previewKindForName(filename);
|
|
24305
24375
|
const effectiveKind = wantText && (baseKind === "text" || isSvg) ? "text" : baseKind;
|
|
24306
24376
|
if (effectiveKind === "unsupported") {
|
|
24307
24377
|
throw new RuntimeError("UNSUPPORTED_PREVIEW", "\u4E0D\u652F\u6301\u9884\u89C8\u7684\u6587\u4EF6\u7C7B\u578B\uFF0C\u8BF7\u5728\u7EC8\u7AEF\u4E2D\u67E5\u770B\u6216\u4E0B\u8F7D", 415);
|
|
24308
24378
|
}
|
|
24379
|
+
if (effectiveKind === "video" || effectiveKind === "audio") {
|
|
24380
|
+
if (info.size > maxMediaPreviewBytes) {
|
|
24381
|
+
throw new RuntimeError("FILE_TOO_LARGE", `\u97F3\u89C6\u9891\u6587\u4EF6\u8D85\u8FC7 500MB \u9884\u89C8\u4E0A\u9650\uFF08\u5B9E\u9645 ${info.size} \u5B57\u8282\uFF09\uFF0C\u8BF7\u4E0B\u8F7D\u6216\u7528\u672C\u673A\u64AD\u653E\u5668\u67E5\u770B`, 415);
|
|
24382
|
+
}
|
|
24383
|
+
const contentType = mediaMimeForName(filename) ?? "application/octet-stream";
|
|
24384
|
+
reply.header("Content-Type", contentType);
|
|
24385
|
+
reply.header("Accept-Ranges", "bytes");
|
|
24386
|
+
reply.header("X-Content-Type-Options", "nosniff");
|
|
24387
|
+
reply.header("Cache-Control", "private, max-age=60");
|
|
24388
|
+
const rangeHeader = typeof request.headers.range === "string" ? request.headers.range : void 0;
|
|
24389
|
+
if (rangeHeader) {
|
|
24390
|
+
const parsed = parseSingleByteRange(rangeHeader, info.size);
|
|
24391
|
+
if (parsed === "invalid") {
|
|
24392
|
+
reply.code(416);
|
|
24393
|
+
reply.header("Content-Range", `bytes */${info.size}`);
|
|
24394
|
+
return reply.send();
|
|
24395
|
+
}
|
|
24396
|
+
if (parsed) {
|
|
24397
|
+
reply.code(206);
|
|
24398
|
+
reply.header("Content-Range", `bytes ${parsed.start}-${parsed.end}/${info.size}`);
|
|
24399
|
+
reply.header("Content-Length", String(parsed.end - parsed.start + 1));
|
|
24400
|
+
return reply.send(createReadStream(resolved.absolute, { start: parsed.start, end: parsed.end }));
|
|
24401
|
+
}
|
|
24402
|
+
}
|
|
24403
|
+
reply.header("Content-Length", String(info.size));
|
|
24404
|
+
return reply.send(createReadStream(resolved.absolute));
|
|
24405
|
+
}
|
|
24309
24406
|
const maxBytes = effectiveKind === "text" ? maxTextPreviewBytes : maxDocumentPreviewBytes;
|
|
24310
24407
|
if (info.size > maxBytes) {
|
|
24311
24408
|
throw new RuntimeError("FILE_TOO_LARGE", `\u6587\u4EF6\u8D85\u8FC7 ${effectiveKind === "text" ? "1MB" : "20MB"} \u9884\u89C8\u4E0A\u9650\uFF08\u5B9E\u9645 ${info.size} \u5B57\u8282\uFF09\uFF0C\u8BF7\u5728\u7EC8\u7AEF\u4E2D\u67E5\u770B\u6216\u4E0B\u8F7D`, 415);
|
|
@@ -24742,8 +24839,8 @@ var LlmClient = class {
|
|
|
24742
24839
|
|
|
24743
24840
|
// src/llm/detect.ts
|
|
24744
24841
|
import { readFile as readFile12 } from "node:fs/promises";
|
|
24745
|
-
import { homedir as
|
|
24746
|
-
import { join as
|
|
24842
|
+
import { homedir as homedir14 } from "node:os";
|
|
24843
|
+
import { join as join20 } from "node:path";
|
|
24747
24844
|
var stringValue = (value) => typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
24748
24845
|
async function readJson(path5) {
|
|
24749
24846
|
try {
|
|
@@ -24873,9 +24970,9 @@ function codexCandidate(configText, env) {
|
|
|
24873
24970
|
}
|
|
24874
24971
|
async function detectLlmEndpoints(options = {}) {
|
|
24875
24972
|
const env = options.env ?? process.env;
|
|
24876
|
-
const home = options.home ??
|
|
24973
|
+
const home = options.home ?? homedir14();
|
|
24877
24974
|
const candidates = [];
|
|
24878
|
-
const settings = await readJson(
|
|
24975
|
+
const settings = await readJson(join20(home, ".claude", "settings.json"));
|
|
24879
24976
|
const settingsEnv = settings?.env && typeof settings.env === "object" && !Array.isArray(settings.env) ? settings.env : {};
|
|
24880
24977
|
const fromSettings = anthropicCandidate(settingsEnv, settings?.model, "claude-code:settings", "Claude Code\uFF08settings.json\uFF09");
|
|
24881
24978
|
if (fromSettings) candidates.push(fromSettings);
|
|
@@ -24883,7 +24980,7 @@ async function detectLlmEndpoints(options = {}) {
|
|
|
24883
24980
|
if (fromEnv) candidates.push(fromEnv);
|
|
24884
24981
|
const openai = openAiCandidate(env);
|
|
24885
24982
|
if (openai) candidates.push(openai);
|
|
24886
|
-
const codexConfig = await readText(
|
|
24983
|
+
const codexConfig = await readText(join20(home, ".codex", "config.toml"));
|
|
24887
24984
|
if (codexConfig) {
|
|
24888
24985
|
const codex = codexCandidate(codexConfig, env);
|
|
24889
24986
|
if (codex) candidates.push(codex);
|
|
@@ -25113,16 +25210,16 @@ function registerJsonCompression(app, threshold = JSON_COMPRESSION_THRESHOLD) {
|
|
|
25113
25210
|
// src/web-password.ts
|
|
25114
25211
|
import { randomBytes as randomBytes3, scryptSync, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
25115
25212
|
import { chmodSync as chmodSync2, existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as readFileSync7, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
25116
|
-
import { homedir as
|
|
25117
|
-
import { dirname as dirname11, join as
|
|
25213
|
+
import { homedir as homedir15 } from "node:os";
|
|
25214
|
+
import { dirname as dirname11, join as join21 } from "node:path";
|
|
25118
25215
|
var webPasswordFileName = "web-password";
|
|
25119
25216
|
var SCRYPT_N = 16384;
|
|
25120
25217
|
var SCRYPT_R = 8;
|
|
25121
25218
|
var SCRYPT_P = 1;
|
|
25122
25219
|
var KEY_LENGTH = 32;
|
|
25123
25220
|
var minWebPasswordLength = 6;
|
|
25124
|
-
function webPasswordPath(home =
|
|
25125
|
-
return
|
|
25221
|
+
function webPasswordPath(home = homedir15()) {
|
|
25222
|
+
return join21(home, ".agentdock", webPasswordFileName);
|
|
25126
25223
|
}
|
|
25127
25224
|
function hashWebPassword(password) {
|
|
25128
25225
|
const salt = randomBytes3(16);
|
|
@@ -25689,7 +25786,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
25689
25786
|
"audio/flac": ".flac",
|
|
25690
25787
|
"application/octet-stream": ""
|
|
25691
25788
|
};
|
|
25692
|
-
const globalUploadRoot =
|
|
25789
|
+
const globalUploadRoot = join22(homedir16(), ".agentdock", "uploads");
|
|
25693
25790
|
const uploadTtlMs = 7 * 24 * 60 * 6e4;
|
|
25694
25791
|
const collectExpiredUploads = async (now2 = Date.now()) => {
|
|
25695
25792
|
let removedFiles = 0;
|
|
@@ -25700,7 +25797,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
25700
25797
|
return { removedFiles };
|
|
25701
25798
|
}
|
|
25702
25799
|
for (const sessionDir of sessionDirs) {
|
|
25703
|
-
const directory =
|
|
25800
|
+
const directory = join22(globalUploadRoot, sessionDir);
|
|
25704
25801
|
let names;
|
|
25705
25802
|
try {
|
|
25706
25803
|
names = await readdir4(directory);
|
|
@@ -25708,7 +25805,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
25708
25805
|
continue;
|
|
25709
25806
|
}
|
|
25710
25807
|
for (const name of names) {
|
|
25711
|
-
const filePath =
|
|
25808
|
+
const filePath = join22(directory, name);
|
|
25712
25809
|
try {
|
|
25713
25810
|
const info = await stat6(filePath);
|
|
25714
25811
|
if (!info.isFile() || now2 - info.mtimeMs <= uploadTtlMs) continue;
|
|
@@ -25754,10 +25851,10 @@ async function buildApp(runtime, options = {}) {
|
|
|
25754
25851
|
originalName = rawName;
|
|
25755
25852
|
}
|
|
25756
25853
|
const ext = extFromContentType(contentType, originalName);
|
|
25757
|
-
const uploadDir =
|
|
25854
|
+
const uploadDir = join22(globalUploadRoot, session.id);
|
|
25758
25855
|
await mkdir4(uploadDir, { recursive: true });
|
|
25759
25856
|
const filename = `${Date.now()}-${randomBytes4(6).toString("hex")}${ext}`;
|
|
25760
|
-
const filePath =
|
|
25857
|
+
const filePath = join22(uploadDir, filename);
|
|
25761
25858
|
await writeFile4(filePath, buffer);
|
|
25762
25859
|
return reply.code(201).send({ path: filePath, url: `/api/sessions/${session.id}/uploads/${filename}`, filename });
|
|
25763
25860
|
});
|
|
@@ -25768,7 +25865,7 @@ async function buildApp(runtime, options = {}) {
|
|
|
25768
25865
|
if (filename.includes("..") || filename.includes("/") || filename.includes("\\")) {
|
|
25769
25866
|
throw new RuntimeError("INVALID_UPLOAD", "Invalid filename", 400);
|
|
25770
25867
|
}
|
|
25771
|
-
const filePath =
|
|
25868
|
+
const filePath = join22(globalUploadRoot, session.id, filename);
|
|
25772
25869
|
const ext = extname2(filename).toLowerCase();
|
|
25773
25870
|
const data = await readFile13(filePath);
|
|
25774
25871
|
reply.header("Content-Type", contentTypes[ext] ?? "application/octet-stream");
|
|
@@ -29589,8 +29686,8 @@ ${signature}` : body;
|
|
|
29589
29686
|
// src/initial-system-prompt.ts
|
|
29590
29687
|
function buildRuntimeGuidance(sessionId) {
|
|
29591
29688
|
return `[AgentDock]
|
|
29592
|
-
\u4F60\u8FD0\u884C\u5728 AgentDock
|
|
29593
|
-
- \u672C\u8F6E\u7ED3\u675F\
|
|
29689
|
+
\u4F60\u8FD0\u884C\u5728 AgentDock\uFF08ACPX\uFF09\u6258\u7BA1\u7684\u4F1A\u8BDD\u4E2D\uFF0C\u5F53\u524D\u4F1A\u8BDD ID\uFF1A${sessionId}\u3002
|
|
29690
|
+
- \u3010\u786C\u7EA6\u675F \xB7 \u9AD8\u4E8E\u5185\u7F6E\u5F02\u6B65\u63D0\u793A\u3011ACPX \u6309\u8F6E\u6B21\u6536\u53E3\uFF1A\u672C\u8F6E\u4E00\u65E6\u7ED3\u675F\uFF08end_turn\uFF09\uFF0C\u4EFB\u4F55\u5185\u7F6E\u540E\u53F0\u4EFB\u52A1\uFF08background task\uFF09\u3001\u5185\u7F6E subAgent\u3001\u5185\u7F6E timer/schedule\u3001swarm \u6216\u540E\u53F0\u8FDB\u7A0B\uFF08&\u3001nohup\u3001tmux \u7B49\uFF09\u7684\u5B8C\u6210\u4E8B\u4EF6\u90FD\u4E0D\u4F1A\u5F02\u6B65\u63A8\u56DE\u5524\u9192\u4F60\uFF0C\u4E14\u540E\u53F0\u8FDB\u7A0B\u53EF\u80FD\u88AB\u7EC8\u6B62\u3002\u51E1\u662F\u9700\u8981\u62FF\u5230\u7ED3\u679C\u7684\u547D\u4EE4/\u6784\u5EFA/\u6D4B\u8BD5/CI\uFF0C\u5FC5\u987B\u5728\u672C\u8F6E\u5DE5\u5177\u8C03\u7528\u5185\u540C\u6B65\u7B49\u5230\u7ED3\u679C\uFF0C\u4E25\u7981\u7ED3\u675F\u672C\u8F6E\u5E76\u627F\u8BFA\u300C\u540E\u53F0\u8DD1\u5B8C\u540E\u518D\u6C47\u62A5\u300D\uFF1B\u4E0D\u8981\u6D3E\u7ED9\u5185\u7F6E subAgent\uFF08\u8DE8\u4F1A\u8BDD\u6D3E\u6D3B\u7EDF\u4E00\u7528 \`agent-dock task start\`\uFF09\u3002
|
|
29594
29691
|
- \u5B9A\u65F6 / \u5468\u671F\u6267\u884C / \u300CX \u70B9\u63D0\u9192\u6211\u300D\u7528 \`agent-dock schedule\`\uFF0C\u4E0D\u8981\u7528 CronCreate\u3001ScheduleWakeup\u3001/loop\u3001crontab \u6216 sleep \u8F6E\u8BE2\u3002
|
|
29595
29692
|
- \u4E0E\u4E3B\u4F1A\u8BDD / \u4FA7\u8FB9\u4F1A\u8BDD\u901A\u4FE1\u7528 \`agent-dock session\`\uFF0C\u4E0D\u8981\u7528 Claude \u7684 ListAgents / SendMessage\u3002
|
|
29596
29693
|
- \u7528\u5230\u4EE5\u4E0A\u80FD\u529B\u524D\uFF0C\u5148\u8FD0\u884C \`agent-dock schedule -h\` \u6216 \`agent-dock session -h\` \u8BFB\u7528\u6CD5\u3002`;
|
|
@@ -29717,8 +29814,23 @@ var ScheduleService = class {
|
|
|
29717
29814
|
this.timer = void 0;
|
|
29718
29815
|
await this.ticking;
|
|
29719
29816
|
}
|
|
29720
|
-
|
|
29721
|
-
|
|
29817
|
+
async resolveMainSessionId() {
|
|
29818
|
+
const id = (await this.options.resolveMainSessionId?.())?.trim();
|
|
29819
|
+
return id || void 0;
|
|
29820
|
+
}
|
|
29821
|
+
/**
|
|
29822
|
+
* 列出定时任务;指定 sessionId 时只看该会话的任务:
|
|
29823
|
+
* - sessionId='main':只看跟随当前主会话的任务;
|
|
29824
|
+
* - sessionId 恰好是当前活跃主会话 ID:同时包含直接绑在该会话上的和跟随主会话的任务。
|
|
29825
|
+
*/
|
|
29826
|
+
async list(sessionId) {
|
|
29827
|
+
const all = await this.schedules.list();
|
|
29828
|
+
const target = sessionId?.trim();
|
|
29829
|
+
if (!target) return all;
|
|
29830
|
+
if (isMainSessionScheduleTarget(target)) return all.filter((item) => isMainSessionScheduleTarget(item.sessionId));
|
|
29831
|
+
const mainId = await this.resolveMainSessionId();
|
|
29832
|
+
const includeMain = Boolean(mainId && mainId === target);
|
|
29833
|
+
return all.filter((item) => item.sessionId === target || includeMain && isMainSessionScheduleTarget(item.sessionId));
|
|
29722
29834
|
}
|
|
29723
29835
|
async get(id) {
|
|
29724
29836
|
const schedule = await this.schedules.get(id);
|
|
@@ -29729,22 +29841,45 @@ var ScheduleService = class {
|
|
|
29729
29841
|
await this.get(id);
|
|
29730
29842
|
return this.schedules.listRuns(id, limit);
|
|
29731
29843
|
}
|
|
29732
|
-
/** 最近执行(跨任务);给 sessionId
|
|
29844
|
+
/** 最近执行(跨任务);给 sessionId 时只看绑在这个会话上的任务(主会话同时含跟随主会话的任务)。 */
|
|
29733
29845
|
async recentRuns(limit = 50, sessionId) {
|
|
29734
29846
|
if (!sessionId) return this.schedules.listRecentRuns(limit);
|
|
29735
|
-
const ids = (await this.
|
|
29847
|
+
const ids = (await this.list(sessionId)).map((item) => item.id);
|
|
29736
29848
|
return this.schedules.listRecentRuns(limit, ids);
|
|
29737
29849
|
}
|
|
29850
|
+
/**
|
|
29851
|
+
* 主会话交接换代时,把旧主会话上存量写死 sessionId 的 append 定时任务平滑迁移为跟随当前主会话,
|
|
29852
|
+
* 避免旧主会话归档后存量任务在下次触发时被误停用。
|
|
29853
|
+
*/
|
|
29854
|
+
async migrateSessionAppendSchedulesToMain(fromSessionId) {
|
|
29855
|
+
const all = await this.schedules.list();
|
|
29856
|
+
const targets = all.filter((item) => item.delivery === "append" && item.sessionId === fromSessionId);
|
|
29857
|
+
if (!targets.length) return 0;
|
|
29858
|
+
const stamp2 = this.clock().toISOString();
|
|
29859
|
+
for (const item of targets) {
|
|
29860
|
+
await this.schedules.save({ ...item, sessionId: SCHEDULE_MAIN_SESSION_ID, updatedAt: stamp2 });
|
|
29861
|
+
}
|
|
29862
|
+
this.options.log?.info(`\u4E3B\u4F1A\u8BDD\u4EA4\u63A5\uFF1A\u5DF2\u5C06 ${targets.length} \u6761\u7ED1\u5B9A\u65E7\u4E3B\u4F1A\u8BDD ${fromSessionId} \u7684\u8FFD\u52A0\u578B\u5B9A\u65F6\u4EFB\u52A1\u8FC1\u79FB\u4E3A\u8DDF\u968F\u5F53\u524D\u4E3B\u4F1A\u8BDD`);
|
|
29863
|
+
return targets.length;
|
|
29864
|
+
}
|
|
29738
29865
|
async create(input) {
|
|
29739
29866
|
const prompt = input.prompt?.trim();
|
|
29740
29867
|
if (!prompt) throw new RuntimeError("INVALID_SCHEDULE", "\u5B9A\u65F6\u4EFB\u52A1\u5185\u5BB9\u4E0D\u80FD\u4E3A\u7A7A", 400);
|
|
29741
29868
|
const delivery = input.delivery ?? "new_session";
|
|
29742
29869
|
if (delivery !== "append" && delivery !== "new_session") throw new RuntimeError("INVALID_SCHEDULE", `\u672A\u77E5\u7684\u6295\u9012\u65B9\u5F0F\uFF1A${String(delivery)}`, 400);
|
|
29743
|
-
const
|
|
29870
|
+
const followMain = input.followMain === true || isMainSessionScheduleTarget(input.sessionId?.trim());
|
|
29871
|
+
const sessionId = followMain ? SCHEDULE_MAIN_SESSION_ID : input.sessionId?.trim();
|
|
29744
29872
|
if (!sessionId && delivery === "append") throw new RuntimeError("INVALID_SCHEDULE", "\u8FFD\u52A0\u5230\u4F1A\u8BDD\u5FC5\u987B\u6307\u5B9A\u4F1A\u8BDD", 400);
|
|
29745
|
-
|
|
29746
|
-
if (
|
|
29747
|
-
|
|
29873
|
+
let session;
|
|
29874
|
+
if (followMain) {
|
|
29875
|
+
const mainId = await this.resolveMainSessionId();
|
|
29876
|
+
const main2 = mainId ? await this.sessions.get(mainId) : void 0;
|
|
29877
|
+
if (main2 && !main2.archivedAt) session = main2;
|
|
29878
|
+
} else if (sessionId) {
|
|
29879
|
+
session = await this.sessions.get(sessionId);
|
|
29880
|
+
if (!session) throw new RuntimeError("SESSION_NOT_FOUND", `\u4F1A\u8BDD\u4E0D\u5B58\u5728\uFF1A${sessionId}`, 404);
|
|
29881
|
+
if (session.archivedAt) throw new RuntimeError("SESSION_ARCHIVED", `\u4F1A\u8BDD\u5DF2\u5F52\u6863\uFF1A${sessionId}`, 409);
|
|
29882
|
+
}
|
|
29748
29883
|
const template = delivery === "new_session" ? normalizeTemplate(input.template) ?? (session ? templateFrom(session) : void 0) : void 0;
|
|
29749
29884
|
if (delivery === "new_session" && !template) throw new RuntimeError("INVALID_SCHEDULE", "\u6BCF\u6B21\u65B0\u5F00\u4F1A\u8BDD\u9700\u8981\u6307\u5B9A Agent \u548C\u5DE5\u4F5C\u76EE\u5F55\uFF0C\u6216\u7ED1\u5B9A\u4E00\u4E2A\u4F1A\u8BDD", 400);
|
|
29750
29885
|
const timezone = input.timezone?.trim() || localTimezone();
|
|
@@ -29758,7 +29893,7 @@ var ScheduleService = class {
|
|
|
29758
29893
|
const schedule = {
|
|
29759
29894
|
id: scheduleId(),
|
|
29760
29895
|
name: input.name?.trim() || prompt.replace(/\s+/g, " ").slice(0, 40),
|
|
29761
|
-
sessionId: session?.id ?? null,
|
|
29896
|
+
sessionId: followMain ? SCHEDULE_MAIN_SESSION_ID : session?.id ?? null,
|
|
29762
29897
|
delivery,
|
|
29763
29898
|
sessionTemplate: template ? JSON.stringify(template) : null,
|
|
29764
29899
|
cron,
|
|
@@ -29785,12 +29920,30 @@ var ScheduleService = class {
|
|
|
29785
29920
|
if (!prompt) throw new RuntimeError("INVALID_SCHEDULE", "\u5B9A\u65F6\u4EFB\u52A1\u5185\u5BB9\u4E0D\u80FD\u4E3A\u7A7A", 400);
|
|
29786
29921
|
const delivery = input.delivery ?? current.delivery;
|
|
29787
29922
|
if (delivery !== "append" && delivery !== "new_session") throw new RuntimeError("INVALID_SCHEDULE", `\u672A\u77E5\u7684\u6295\u9012\u65B9\u5F0F\uFF1A${String(delivery)}`, 400);
|
|
29788
|
-
|
|
29923
|
+
let sessionId;
|
|
29924
|
+
if (input.followMain === true) {
|
|
29925
|
+
sessionId = SCHEDULE_MAIN_SESSION_ID;
|
|
29926
|
+
} else if (input.sessionId !== void 0) {
|
|
29927
|
+
const trimmed = input.sessionId?.trim() || null;
|
|
29928
|
+
sessionId = isMainSessionScheduleTarget(trimmed) ? SCHEDULE_MAIN_SESSION_ID : trimmed;
|
|
29929
|
+
} else if (input.followMain === false && isMainSessionScheduleTarget(current.sessionId)) {
|
|
29930
|
+
sessionId = null;
|
|
29931
|
+
} else {
|
|
29932
|
+
sessionId = current.sessionId ?? null;
|
|
29933
|
+
}
|
|
29789
29934
|
if (delivery === "append" && !sessionId) throw new RuntimeError("INVALID_SCHEDULE", "\u8FFD\u52A0\u5230\u4F1A\u8BDD\u5FC5\u987B\u6307\u5B9A\u4F1A\u8BDD", 400);
|
|
29790
|
-
const
|
|
29791
|
-
|
|
29792
|
-
|
|
29793
|
-
|
|
29935
|
+
const followMain = isMainSessionScheduleTarget(sessionId);
|
|
29936
|
+
let session;
|
|
29937
|
+
if (followMain) {
|
|
29938
|
+
const mainId = await this.resolveMainSessionId();
|
|
29939
|
+
const main2 = mainId ? await this.sessions.get(mainId) : void 0;
|
|
29940
|
+
if (main2 && !main2.archivedAt) session = main2;
|
|
29941
|
+
} else if (sessionId) {
|
|
29942
|
+
session = await this.sessions.get(sessionId);
|
|
29943
|
+
if (sessionId !== current.sessionId) {
|
|
29944
|
+
if (!session) throw new RuntimeError("SESSION_NOT_FOUND", `\u4F1A\u8BDD\u4E0D\u5B58\u5728\uFF1A${sessionId}`, 404);
|
|
29945
|
+
if (session.archivedAt) throw new RuntimeError("SESSION_ARCHIVED", `\u4F1A\u8BDD\u5DF2\u5F52\u6863\uFF1A${sessionId}`, 409);
|
|
29946
|
+
}
|
|
29794
29947
|
}
|
|
29795
29948
|
let template;
|
|
29796
29949
|
if (delivery === "new_session") {
|
|
@@ -29912,10 +30065,20 @@ var ScheduleService = class {
|
|
|
29912
30065
|
return finished;
|
|
29913
30066
|
}
|
|
29914
30067
|
async attempt(schedule) {
|
|
29915
|
-
const
|
|
29916
|
-
|
|
29917
|
-
|
|
29918
|
-
|
|
30068
|
+
const followMain = isMainSessionScheduleTarget(schedule.sessionId);
|
|
30069
|
+
let source2;
|
|
30070
|
+
if (followMain) {
|
|
30071
|
+
const mainId = await this.resolveMainSessionId();
|
|
30072
|
+
source2 = mainId ? await this.runtime.getSession(mainId) : void 0;
|
|
30073
|
+
if (!source2 || source2.archivedAt) {
|
|
30074
|
+
return { status: "skipped", reason: "\u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u7684\u4E3B\u4F1A\u8BDD\uFF0C\u672C\u6B21\u8DF3\u8FC7", sessionId: null, taskId: null };
|
|
30075
|
+
}
|
|
30076
|
+
} else if (schedule.sessionId) {
|
|
30077
|
+
source2 = await this.runtime.getSession(schedule.sessionId);
|
|
30078
|
+
if (!source2 || source2.archivedAt) {
|
|
30079
|
+
await this.disable(schedule.id, "\u6765\u6E90\u4F1A\u8BDD\u4E0D\u5B58\u5728\u6216\u5DF2\u5F52\u6863");
|
|
30080
|
+
return { status: "failed", reason: "\u6765\u6E90\u4F1A\u8BDD\u4E0D\u5B58\u5728\u6216\u5DF2\u5F52\u6863\uFF0C\u5B9A\u65F6\u4EFB\u52A1\u5DF2\u505C\u7528", sessionId: schedule.sessionId, taskId: null };
|
|
30081
|
+
}
|
|
29919
30082
|
}
|
|
29920
30083
|
const previous = await this.unfinishedPrevious(schedule);
|
|
29921
30084
|
if (previous) return { status: "skipped", reason: `\u4E0A\u4E00\u6B21\u89E6\u53D1\u7684\u4EFB\u52A1\u8FD8\u672A\u7ED3\u675F\uFF08${previous}\uFF09`, sessionId: null, taskId: null };
|
|
@@ -29926,22 +30089,25 @@ var ScheduleService = class {
|
|
|
29926
30089
|
const task2 = await this.runtime.dispatch(source2.id, prompt);
|
|
29927
30090
|
return { status: "delivered", reason: null, sessionId: source2.id, taskId: task2.id };
|
|
29928
30091
|
}
|
|
30092
|
+
const parentSessionId = source2?.id ?? null;
|
|
29929
30093
|
const template = parseTemplate(schedule);
|
|
29930
30094
|
const created = await this.runtime.start({
|
|
29931
30095
|
agentId: template.agentId,
|
|
29932
30096
|
cwd: template.cwd,
|
|
29933
30097
|
...template.model ? { model: template.model } : {},
|
|
29934
30098
|
...template.reasoningEffort ? { reasoningEffort: template.reasoningEffort } : {},
|
|
29935
|
-
systemPrompt: buildScheduleSessionSeed(schedule),
|
|
29936
|
-
...
|
|
30099
|
+
systemPrompt: buildScheduleSessionSeed({ ...schedule, sessionId: parentSessionId }),
|
|
30100
|
+
...parentSessionId ? { source: scheduleSessionSource, sourceId: parentSessionId } : {}
|
|
29937
30101
|
});
|
|
29938
30102
|
const task = await this.runtime.dispatch(created.id, prompt);
|
|
29939
30103
|
return { status: "delivered", reason: null, sessionId: created.id, taskId: task.id };
|
|
29940
30104
|
}
|
|
29941
|
-
/**
|
|
30105
|
+
/** 上一条已投递的任务若仍在排队/执行,返回它的状态。已归档会话(如换代后的前任主会话)上的旧任务不再阻塞新触发。 */
|
|
29942
30106
|
async unfinishedPrevious(schedule) {
|
|
29943
30107
|
const last = (await this.schedules.listRuns(schedule.id, 10)).find((run2) => run2.status === "delivered" && run2.sessionId && run2.taskId);
|
|
29944
30108
|
if (!last) return void 0;
|
|
30109
|
+
const lastSession = await this.runtime.getSession(last.sessionId);
|
|
30110
|
+
if (lastSession?.archivedAt) return void 0;
|
|
29945
30111
|
const task = (await this.runtime.getTasks(last.sessionId)).find((item) => item.id === last.taskId);
|
|
29946
30112
|
return task && unfinishedTaskStatuses.has(task.status) ? task.status : void 0;
|
|
29947
30113
|
}
|
|
@@ -32188,6 +32354,11 @@ var AssistantLifecycle = class {
|
|
|
32188
32354
|
retired.peakAgeScore = collected.cat.peakAgeScore;
|
|
32189
32355
|
}
|
|
32190
32356
|
this.store.saveCat(retired);
|
|
32357
|
+
try {
|
|
32358
|
+
await this.host.onMainSessionHandoff?.(fromSession.id, session.id);
|
|
32359
|
+
} catch (error) {
|
|
32360
|
+
this.log.warn(`\u4E3B\u4F1A\u8BDD\u4EA4\u63A5\u8FC1\u79FB\u5B9A\u65F6\u4EFB\u52A1\u5931\u8D25\uFF1A${errorMessage2(error)}`);
|
|
32361
|
+
}
|
|
32191
32362
|
await this.runtime.archive(fromSession.id);
|
|
32192
32363
|
committed = true;
|
|
32193
32364
|
this.markStep(id, "retiring", `\u65E7\u4E3B\u4F1A\u8BDD ${fromSession.id} \u5DF2\u5F52\u6863\uFF08\u53EA\u8BFB\uFF0C\u8BB0\u5F55\u5168\u90E8\u4FDD\u7559\uFF09`);
|
|
@@ -32373,12 +32544,12 @@ function withContext(percent2) {
|
|
|
32373
32544
|
// src/assistant/cwd.ts
|
|
32374
32545
|
init_src2();
|
|
32375
32546
|
import { accessSync as accessSync3, constants as constants6, statSync as statSync6 } from "node:fs";
|
|
32376
|
-
import { homedir as
|
|
32547
|
+
import { homedir as homedir17 } from "node:os";
|
|
32377
32548
|
import { isAbsolute as isAbsolute8, resolve as resolve11 } from "node:path";
|
|
32378
32549
|
function expandHomePath(value) {
|
|
32379
32550
|
const trimmed = value.trim();
|
|
32380
|
-
if (trimmed === "~") return
|
|
32381
|
-
if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) return resolve11(
|
|
32551
|
+
if (trimmed === "~") return homedir17();
|
|
32552
|
+
if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) return resolve11(homedir17(), trimmed.slice(2));
|
|
32382
32553
|
return trimmed;
|
|
32383
32554
|
}
|
|
32384
32555
|
function resolveCwdArgument(value, base = process.cwd()) {
|
|
@@ -32516,7 +32687,8 @@ var AssistantService = class {
|
|
|
32516
32687
|
nameSession: (sessionId, title) => this.nameSession(sessionId, title),
|
|
32517
32688
|
mainSystemPrompt: () => buildMainSystemPrompt(),
|
|
32518
32689
|
normalizeName: normalizeCompanionName,
|
|
32519
|
-
agentCatalog: (agentId) => this.handoffAgentCatalog(agentId)
|
|
32690
|
+
agentCatalog: (agentId) => this.handoffAgentCatalog(agentId),
|
|
32691
|
+
...options.onMainSessionHandoff ? { onMainSessionHandoff: options.onMainSessionHandoff } : {}
|
|
32520
32692
|
}
|
|
32521
32693
|
});
|
|
32522
32694
|
}
|
|
@@ -33775,7 +33947,9 @@ async function startLocalServer(options = {}) {
|
|
|
33775
33947
|
const sideChatConfig = new SideChatConfigService({ config: repos.config, listAgents: () => runtime.listAgents() });
|
|
33776
33948
|
const packageJson2 = JSON.parse(readFileSync9(new URL("../package.json", import.meta.url), "utf8"));
|
|
33777
33949
|
const selfUpdate = options.cliEntrypoint ? new SelfUpdateService({ currentVersion: packageJson2.version, packageName: packageJson2.name, cliEntrypoint: options.cliEntrypoint, env }) : void 0;
|
|
33778
|
-
schedules2 = new ScheduleService(repos.schedules, repos.sessions, runtime
|
|
33950
|
+
schedules2 = new ScheduleService(repos.schedules, repos.sessions, runtime, {
|
|
33951
|
+
resolveMainSessionId: () => assistant?.mainSessionId
|
|
33952
|
+
});
|
|
33779
33953
|
assistant = new AssistantService({
|
|
33780
33954
|
databaseUrl: config.databaseUrl,
|
|
33781
33955
|
runtime,
|
|
@@ -33786,6 +33960,9 @@ async function startLocalServer(options = {}) {
|
|
|
33786
33960
|
sendLarkReply: (input) => {
|
|
33787
33961
|
if (!larkAvatar) throw new Error("\u98DE\u4E66\u66FF\u8EAB\u5C1A\u672A\u521D\u59CB\u5316");
|
|
33788
33962
|
return larkAvatar.sendMessage(input);
|
|
33963
|
+
},
|
|
33964
|
+
onMainSessionHandoff: async (fromSessionId) => {
|
|
33965
|
+
await schedules2?.migrateSessionAppendSchedulesToMain(fromSessionId);
|
|
33789
33966
|
}
|
|
33790
33967
|
});
|
|
33791
33968
|
await assistant.initialize();
|
|
@@ -34879,23 +35056,23 @@ init_session_cli();
|
|
|
34879
35056
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
34880
35057
|
import { chmodSync as chmodSync3, existsSync as existsSync12, mkdirSync as mkdirSync6, readFileSync as readFileSync13, rmSync as rmSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
34881
35058
|
import { createServer } from "node:net";
|
|
34882
|
-
import { delimiter as delimiter2, dirname as dirname13, join as
|
|
35059
|
+
import { delimiter as delimiter2, dirname as dirname13, join as join24, resolve as resolve15 } from "node:path";
|
|
34883
35060
|
init_daemon();
|
|
34884
35061
|
var SANDBOX_FILE = "sandbox.json";
|
|
34885
35062
|
function findRepoRoot(start = process.cwd()) {
|
|
34886
35063
|
let dir = resolve15(start);
|
|
34887
35064
|
for (; ; ) {
|
|
34888
|
-
if (existsSync12(
|
|
35065
|
+
if (existsSync12(join24(dir, "apps", "server", "package.json")) && existsSync12(join24(dir, "pnpm-workspace.yaml"))) return dir;
|
|
34889
35066
|
const parent = dirname13(dir);
|
|
34890
35067
|
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");
|
|
34891
35068
|
dir = parent;
|
|
34892
35069
|
}
|
|
34893
35070
|
}
|
|
34894
35071
|
function sandboxPaths(repo, port) {
|
|
34895
|
-
const root4 =
|
|
34896
|
-
return { root: root4, home:
|
|
35072
|
+
const root4 = join24(repo, ".agentdock", "dev");
|
|
35073
|
+
return { root: root4, home: join24(root4, "home"), work: join24(root4, "work"), database: join24(root4, "agentdock.db"), entrypoint: join24(repo, "apps", "server", "dist", "cli.js"), port };
|
|
34897
35074
|
}
|
|
34898
|
-
var shimDir = (sandbox) =>
|
|
35075
|
+
var shimDir = (sandbox) => join24(sandbox.root, "bin");
|
|
34899
35076
|
function sandboxEnv(sandbox, base = process.env) {
|
|
34900
35077
|
const env = {
|
|
34901
35078
|
...base,
|
|
@@ -34921,7 +35098,7 @@ function writeCliShim(sandbox, node = process.execPath) {
|
|
|
34921
35098
|
if (process.platform === "win32") {
|
|
34922
35099
|
const quote2 = (path5) => `"${path5.replace(/%/g, "%%")}"`;
|
|
34923
35100
|
writeFileSync5(
|
|
34924
|
-
|
|
35101
|
+
join24(dir, "agent-dock.cmd"),
|
|
34925
35102
|
`@echo off\r
|
|
34926
35103
|
setlocal DisableDelayedExpansion\r
|
|
34927
35104
|
${quote2(node)} ${quote2(sandbox.entrypoint)} %*\r
|
|
@@ -34929,7 +35106,7 @@ ${quote2(node)} ${quote2(sandbox.entrypoint)} %*\r
|
|
|
34929
35106
|
);
|
|
34930
35107
|
return;
|
|
34931
35108
|
}
|
|
34932
|
-
const file =
|
|
35109
|
+
const file = join24(dir, "agent-dock");
|
|
34933
35110
|
writeFileSync5(file, `#!/bin/sh
|
|
34934
35111
|
exec ${shellQuote5(node)} ${shellQuote5(sandbox.entrypoint)} "$@"
|
|
34935
35112
|
`);
|
|
@@ -34937,7 +35114,7 @@ exec ${shellQuote5(node)} ${shellQuote5(sandbox.entrypoint)} "$@"
|
|
|
34937
35114
|
}
|
|
34938
35115
|
function readSandbox(repo) {
|
|
34939
35116
|
try {
|
|
34940
|
-
return JSON.parse(readFileSync13(
|
|
35117
|
+
return JSON.parse(readFileSync13(join24(repo, ".agentdock", "dev", SANDBOX_FILE), "utf8"));
|
|
34941
35118
|
} catch {
|
|
34942
35119
|
return void 0;
|
|
34943
35120
|
}
|
|
@@ -34964,7 +35141,7 @@ async function devUp(options = {}) {
|
|
|
34964
35141
|
const sandbox = sandboxPaths(repo, port);
|
|
34965
35142
|
if (!existsSync12(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`);
|
|
34966
35143
|
for (const dir of [sandbox.home, sandbox.work]) mkdirSync6(dir, { recursive: true });
|
|
34967
|
-
writeFileSync5(
|
|
35144
|
+
writeFileSync5(join24(sandbox.root, SANDBOX_FILE), `${JSON.stringify(sandbox, null, 2)}
|
|
34968
35145
|
`);
|
|
34969
35146
|
writeCliShim(sandbox);
|
|
34970
35147
|
const run2 = options.run ?? defaultRun;
|
|
@@ -35057,6 +35234,8 @@ function runPasswordStatus(path5 = webPasswordPath()) {
|
|
|
35057
35234
|
}
|
|
35058
35235
|
|
|
35059
35236
|
// src/schedule-cli.ts
|
|
35237
|
+
init_src2();
|
|
35238
|
+
init_src();
|
|
35060
35239
|
init_session_cli();
|
|
35061
35240
|
var deliveryLabel = { new_session: "\u6BCF\u6B21\u65B0\u5F00\u4F1A\u8BDD", append: "\u8FFD\u52A0\u5230\u4F1A\u8BDD" };
|
|
35062
35241
|
function localTime(iso, timezone) {
|
|
@@ -35064,6 +35243,7 @@ function localTime(iso, timezone) {
|
|
|
35064
35243
|
return new Date(iso).toLocaleString("zh-CN", { hour12: false, ...timezone ? { timeZone: timezone } : {} });
|
|
35065
35244
|
}
|
|
35066
35245
|
function scheduleWhere(item) {
|
|
35246
|
+
if (isMainSessionScheduleTarget(item.sessionId)) return "\u8DDF\u968F\u5F53\u524D\u4E3B\u4F1A\u8BDD\uFF08\u6362\u4EE3\u81EA\u52A8\u8DDF\u968F\uFF09";
|
|
35067
35247
|
if (item.sessionId) return `\u4F1A\u8BDD ${item.sessionId}`;
|
|
35068
35248
|
try {
|
|
35069
35249
|
const template = JSON.parse(item.sessionTemplate ?? "");
|
|
@@ -35082,19 +35262,53 @@ function scheduleLine(item) {
|
|
|
35082
35262
|
function runLine(run2) {
|
|
35083
35263
|
return `${localTime(run2.fireAt)} ${run2.status}${run2.reason ? `\uFF08${run2.reason}\uFF09` : ""}${run2.sessionId ? ` session=${run2.sessionId}` : ""}${run2.taskId ? ` task=${run2.taskId}` : ""}`;
|
|
35084
35264
|
}
|
|
35265
|
+
function resolveMainOption(options) {
|
|
35266
|
+
const raw = options.session?.trim();
|
|
35267
|
+
if (options.main && raw && !isMainSessionScheduleTarget(raw)) {
|
|
35268
|
+
throw new Error("--main \u4E0D\u80FD\u4E0E --session \u540C\u65F6\u6307\u5B9A\u4E0D\u540C\u7684\u4F1A\u8BDD\u3002");
|
|
35269
|
+
}
|
|
35270
|
+
if (options.main || isMainSessionScheduleTarget(raw)) {
|
|
35271
|
+
return { session: SCHEDULE_MAIN_SESSION_ID, followMain: true };
|
|
35272
|
+
}
|
|
35273
|
+
return { ...raw ? { session: raw } : {}, followMain: false };
|
|
35274
|
+
}
|
|
35275
|
+
async function assertMainPeerIfApplicable(database, fromId) {
|
|
35276
|
+
const repos = createRepositories(database);
|
|
35277
|
+
let mainId;
|
|
35278
|
+
try {
|
|
35279
|
+
mainId = (await repos.config.get("assistant.main"))?.trim() || void 0;
|
|
35280
|
+
} finally {
|
|
35281
|
+
repos.close();
|
|
35282
|
+
}
|
|
35283
|
+
if (mainId && mainId !== fromId) {
|
|
35284
|
+
await assertPeerTarget(database, mainId, fromId, true);
|
|
35285
|
+
}
|
|
35286
|
+
}
|
|
35085
35287
|
async function runScheduleAdd(prompt, options = {}) {
|
|
35086
35288
|
const text3 = prompt.trim();
|
|
35087
35289
|
if (!text3) throw new Error("\u5B9A\u65F6\u4EFB\u52A1\u5185\u5BB9\u4E0D\u80FD\u4E3A\u7A7A\u3002");
|
|
35088
35290
|
if ([options.cron, options.at, options.every].filter(Boolean).length !== 1) throw new Error("\u5FC5\u987B\u4E14\u53EA\u80FD\u6307\u5B9A --cron\u3001--every\u3001--at \u4E2D\u7684\u4E00\u4E2A\u3002");
|
|
35089
35291
|
if (options.delivery && options.delivery !== "new_session" && options.delivery !== "append") throw new Error("--delivery \u53EA\u80FD\u662F new_session \u6216 append\u3002");
|
|
35292
|
+
const { session: explicitSession, followMain } = resolveMainOption(options);
|
|
35090
35293
|
const state = requireDaemon(options.daemonDir);
|
|
35091
|
-
|
|
35092
|
-
|
|
35093
|
-
if (
|
|
35294
|
+
let fromId;
|
|
35295
|
+
let sessionId;
|
|
35296
|
+
if (followMain) {
|
|
35297
|
+
try {
|
|
35298
|
+
fromId = sourceSessionId(options.from);
|
|
35299
|
+
} catch {
|
|
35300
|
+
}
|
|
35301
|
+
if (fromId) await assertMainPeerIfApplicable(state.database, fromId);
|
|
35302
|
+
sessionId = SCHEDULE_MAIN_SESSION_ID;
|
|
35303
|
+
} else {
|
|
35304
|
+
fromId = sourceSessionId(options.from);
|
|
35305
|
+
sessionId = explicitSession || fromId;
|
|
35306
|
+
if (sessionId !== fromId) await assertPeerTarget(state.database, sessionId, fromId, true);
|
|
35307
|
+
}
|
|
35094
35308
|
const created = await callDaemon(state, "/api/schedules", "POST", {
|
|
35095
35309
|
sessionId,
|
|
35096
35310
|
prompt: text3,
|
|
35097
|
-
createdBySessionId: fromId,
|
|
35311
|
+
...fromId ? { createdBySessionId: fromId } : {},
|
|
35098
35312
|
...options.cron ? { cron: options.cron } : {},
|
|
35099
35313
|
...options.every ? { intervalMinutes: parseEvery(options.every) } : {},
|
|
35100
35314
|
...options.at ? { runAt: parseAt(options.at) } : {},
|
|
@@ -35107,6 +35321,59 @@ async function runScheduleAdd(prompt, options = {}) {
|
|
|
35107
35321
|
${scheduleLine(created)}
|
|
35108
35322
|
`;
|
|
35109
35323
|
}
|
|
35324
|
+
async function runScheduleUpdate(id, options = {}) {
|
|
35325
|
+
const timingCount = [options.cron, options.at, options.every].filter(Boolean).length;
|
|
35326
|
+
if (timingCount > 1) throw new Error("--cron\u3001--every\u3001--at \u6700\u591A\u53EA\u80FD\u6307\u5B9A\u4E00\u4E2A\u3002");
|
|
35327
|
+
if (options.delivery && options.delivery !== "new_session" && options.delivery !== "append") throw new Error("--delivery \u53EA\u80FD\u662F new_session \u6216 append\u3002");
|
|
35328
|
+
const { session: explicitSession, followMain } = resolveMainOption(options);
|
|
35329
|
+
const state = requireDaemon(options.daemonDir);
|
|
35330
|
+
if (followMain) {
|
|
35331
|
+
let fromId;
|
|
35332
|
+
try {
|
|
35333
|
+
fromId = sourceSessionId(options.from);
|
|
35334
|
+
} catch {
|
|
35335
|
+
}
|
|
35336
|
+
if (fromId) await assertMainPeerIfApplicable(state.database, fromId);
|
|
35337
|
+
} else if (explicitSession) {
|
|
35338
|
+
let fromId;
|
|
35339
|
+
try {
|
|
35340
|
+
fromId = sourceSessionId(options.from);
|
|
35341
|
+
} catch {
|
|
35342
|
+
}
|
|
35343
|
+
if (fromId && explicitSession !== fromId) await assertPeerTarget(state.database, explicitSession, fromId, true);
|
|
35344
|
+
}
|
|
35345
|
+
const body = {};
|
|
35346
|
+
if (options.prompt !== void 0) {
|
|
35347
|
+
const text3 = options.prompt.trim();
|
|
35348
|
+
if (!text3) throw new Error("\u5B9A\u65F6\u4EFB\u52A1\u5185\u5BB9\u4E0D\u80FD\u4E3A\u7A7A\u3002");
|
|
35349
|
+
body.prompt = text3;
|
|
35350
|
+
}
|
|
35351
|
+
if (options.name !== void 0) body.name = options.name;
|
|
35352
|
+
if (options.delivery !== void 0) body.delivery = options.delivery;
|
|
35353
|
+
if (explicitSession !== void 0) body.sessionId = explicitSession;
|
|
35354
|
+
if (options.tz !== void 0) body.timezone = options.tz;
|
|
35355
|
+
if (options.cron !== void 0) {
|
|
35356
|
+
body.cron = options.cron;
|
|
35357
|
+
body.intervalMinutes = null;
|
|
35358
|
+
body.runAt = null;
|
|
35359
|
+
}
|
|
35360
|
+
if (options.every !== void 0) {
|
|
35361
|
+
body.intervalMinutes = parseEvery(options.every);
|
|
35362
|
+
body.cron = null;
|
|
35363
|
+
body.runAt = null;
|
|
35364
|
+
}
|
|
35365
|
+
if (options.at !== void 0) {
|
|
35366
|
+
body.runAt = parseAt(options.at);
|
|
35367
|
+
body.cron = null;
|
|
35368
|
+
body.intervalMinutes = null;
|
|
35369
|
+
}
|
|
35370
|
+
if (!Object.keys(body).length) throw new Error("\u8BF7\u81F3\u5C11\u6307\u5B9A\u4E00\u4E2A\u8981\u66F4\u65B0\u7684\u5B57\u6BB5\uFF08\u5982 --prompt\u3001--name\u3001--cron\u3001--every\u3001--at\u3001--delivery\u3001--session\u3001--main\uFF09\u3002");
|
|
35371
|
+
const updated = await callDaemon(state, `/api/schedules/${encodeURIComponent(id)}`, "PATCH", body);
|
|
35372
|
+
if (options.json) return JSON.stringify(updated, null, 2) + "\n";
|
|
35373
|
+
return `\u5DF2\u66F4\u65B0\u5B9A\u65F6\u4EFB\u52A1\uFF1A
|
|
35374
|
+
${scheduleLine(updated)}
|
|
35375
|
+
`;
|
|
35376
|
+
}
|
|
35110
35377
|
function parseEvery(value) {
|
|
35111
35378
|
const text3 = value.trim().toLowerCase();
|
|
35112
35379
|
if (/^\d+$/.test(text3)) return Number(text3);
|
|
@@ -35132,7 +35399,8 @@ function parseAt(value) {
|
|
|
35132
35399
|
}
|
|
35133
35400
|
async function runScheduleList(options = {}) {
|
|
35134
35401
|
const state = requireDaemon(options.daemonDir);
|
|
35135
|
-
|
|
35402
|
+
const { session: explicitSession } = resolveMainOption(options);
|
|
35403
|
+
let sessionId = explicitSession;
|
|
35136
35404
|
if (!options.all && !sessionId) {
|
|
35137
35405
|
try {
|
|
35138
35406
|
sessionId = sourceSessionId();
|
|
@@ -35141,8 +35409,11 @@ async function runScheduleList(options = {}) {
|
|
|
35141
35409
|
}
|
|
35142
35410
|
const items = await callDaemon(state, `/api/schedules${sessionId ? `?sessionId=${encodeURIComponent(sessionId)}` : ""}`, "GET");
|
|
35143
35411
|
if (options.json) return JSON.stringify(items, null, 2) + "\n";
|
|
35144
|
-
if (!items.length)
|
|
35412
|
+
if (!items.length) {
|
|
35413
|
+
if (isMainSessionScheduleTarget(sessionId)) return "\u6CA1\u6709\u8DDF\u968F\u5F53\u524D\u4E3B\u4F1A\u8BDD\u7684\u5B9A\u65F6\u4EFB\u52A1\u3002\u7528 --all \u67E5\u770B\u5168\u90E8\u3002\n";
|
|
35414
|
+
return sessionId ? `\u4F1A\u8BDD ${sessionId} \u6CA1\u6709\u5B9A\u65F6\u4EFB\u52A1\u3002\u7528 --all \u67E5\u770B\u5168\u90E8\u3002
|
|
35145
35415
|
` : "\u6CA1\u6709\u5B9A\u65F6\u4EFB\u52A1\u3002\n";
|
|
35416
|
+
}
|
|
35146
35417
|
return items.map(scheduleLine).join("\n\n") + "\n";
|
|
35147
35418
|
}
|
|
35148
35419
|
async function runScheduleShow(id, options = {}) {
|
|
@@ -36859,6 +37130,9 @@ ${status.plistPath}` : "\u5F00\u673A\u81EA\u542F\uFF1A\u672A\u5F00\u542F"}
|
|
|
36859
37130
|
scheduleAdd: async (prompt, options) => {
|
|
36860
37131
|
process.stdout.write(await runScheduleAdd(prompt, options));
|
|
36861
37132
|
},
|
|
37133
|
+
scheduleUpdate: async (id, options) => {
|
|
37134
|
+
process.stdout.write(await runScheduleUpdate(id, options));
|
|
37135
|
+
},
|
|
36862
37136
|
scheduleList: async (options) => {
|
|
36863
37137
|
process.stdout.write(await runScheduleList(options));
|
|
36864
37138
|
},
|