@vibedeckx/darwin-arm64 0.3.44 → 0.3.46
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/bin.js +804 -158
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -185779,6 +185779,10 @@ var createScheduledRepos = (kdb, h) => ({
|
|
|
185779
185779
|
const row = await kdb.selectFrom("scheduled_tasks").selectAll().where("project_id", "=", projectId).where("source_session_id", "=", sessionId).where("source_tool_use_id", "=", toolUseId).executeTakeFirst();
|
|
185780
185780
|
return row ? mapTask(row) : void 0;
|
|
185781
185781
|
},
|
|
185782
|
+
listIdsBySourceSession: async (sessionId) => {
|
|
185783
|
+
const rows = await kdb.selectFrom("scheduled_tasks").select("id").where("source_session_id", "=", sessionId).where("source_tool_use_id", "is not", null).orderBy("id", "asc").execute();
|
|
185784
|
+
return rows.map((row) => row.id);
|
|
185785
|
+
},
|
|
185782
185786
|
getByProjectId: async (projectId) => {
|
|
185783
185787
|
const rows = await kdb.selectFrom("scheduled_tasks").selectAll().where("project_id", "=", projectId).orderBy("created_at", "asc").orderBy("id", "asc").execute();
|
|
185784
185788
|
return rows.map(mapTask);
|
|
@@ -186105,6 +186109,7 @@ async function deleteSessionSideRows(trx, sessionIds) {
|
|
|
186105
186109
|
const ids = [...sessionIds];
|
|
186106
186110
|
await trx.deleteFrom("agent_session_remote_grants").where("session_id", "in", ids).execute();
|
|
186107
186111
|
await trx.deleteFrom("agent_session_remote_touches").where("session_id", "in", ids).execute();
|
|
186112
|
+
await trx.deleteFrom("agent_session_retention_holds").where("session_id", "in", ids).execute();
|
|
186108
186113
|
}
|
|
186109
186114
|
|
|
186110
186115
|
// src/storage/repositories/core.ts
|
|
@@ -187085,6 +187090,10 @@ var retentionPredicate = (cutoff) => sql`
|
|
|
187085
187090
|
AND favorited_at IS NULL
|
|
187086
187091
|
AND status <> 'running'
|
|
187087
187092
|
AND ${visibleLifecycle}
|
|
187093
|
+
AND NOT EXISTS (
|
|
187094
|
+
SELECT 1 FROM agent_session_retention_holds h
|
|
187095
|
+
WHERE h.session_id = agent_sessions.id
|
|
187096
|
+
)
|
|
187088
187097
|
AND NOT EXISTS (
|
|
187089
187098
|
SELECT 1 FROM workflow_runs wr
|
|
187090
187099
|
WHERE wr.status IN (${sql.join(WORKFLOW_ACTIVE_STATUSES.map((s3) => sql`${s3}`))})
|
|
@@ -187685,6 +187694,12 @@ var createAgentSessionRepos = (kdb, h) => ({
|
|
|
187685
187694
|
const rows = await kdb.selectFrom("remote_session_mappings").selectAll().execute();
|
|
187686
187695
|
return rows.map(mapRemoteSessionMapping);
|
|
187687
187696
|
},
|
|
187697
|
+
// Same link test as projectRemotes.getByProjectAndServer: the
|
|
187698
|
+
// project_remotes row AND its remote_servers row (that lookup inner-joins).
|
|
187699
|
+
getAllWithLinkState: async () => {
|
|
187700
|
+
const rows = await kdb.selectFrom("remote_session_mappings as mapping").leftJoin("project_remotes as link", (join2) => join2.onRef("link.project_id", "=", "mapping.project_id").onRef("link.remote_server_id", "=", "mapping.remote_server_id")).leftJoin("remote_servers as server", "server.id", "link.remote_server_id").selectAll("mapping").select("server.id as linked_server_id").execute();
|
|
187701
|
+
return rows.map((row) => ({ ...mapRemoteSessionMapping(row), linked: row.linked_server_id != null }));
|
|
187702
|
+
},
|
|
187688
187703
|
listByProject: async (projectId, limit, consumer) => {
|
|
187689
187704
|
const rows = await projectedRemoteMappingBase(kdb).where(sql`case when mapping.workspace_checkout_id is null then mapping.project_id else workspace.project_id end = ${projectId}`).orderBy("mapping.local_session_id", "asc").limit(limit).execute();
|
|
187690
187705
|
rows.forEach((row) => observeProjectedRemoteMapping(consumer, row));
|
|
@@ -187993,7 +188008,7 @@ var mapRule = (row) => ({
|
|
|
187993
188008
|
});
|
|
187994
188009
|
var createWorkspaceRepos = (kdb, h) => ({
|
|
187995
188010
|
tasks: {
|
|
187996
|
-
create: async ({ id, project_id, title, description, status, priority, assigned_branch }) => {
|
|
188011
|
+
create: async ({ id, project_id, title, description, status, priority, assigned_branch, source }) => {
|
|
187997
188012
|
await kdb.insertInto("tasks").values((eb) => ({
|
|
187998
188013
|
id,
|
|
187999
188014
|
project_id,
|
|
@@ -188002,10 +188017,25 @@ var createWorkspaceRepos = (kdb, h) => ({
|
|
|
188002
188017
|
status: status ?? "todo",
|
|
188003
188018
|
priority: priority ?? "medium",
|
|
188004
188019
|
assigned_branch: assigned_branch ?? null,
|
|
188005
|
-
position: eb.selectFrom("tasks").select(sql`coalesce(max(position), -1) + 1`.as("next_position")).where("project_id", "=", project_id)
|
|
188006
|
-
|
|
188007
|
-
|
|
188008
|
-
|
|
188020
|
+
position: eb.selectFrom("tasks").select(sql`coalesce(max(position), -1) + 1`.as("next_position")).where("project_id", "=", project_id),
|
|
188021
|
+
source_session_id: source?.session_id ?? null,
|
|
188022
|
+
source_tool_use_id: source?.tool_use_id ?? null,
|
|
188023
|
+
source_item_index: source?.item_index ?? null
|
|
188024
|
+
// DO NOTHING only for a proposal, so a concurrent replay races into
|
|
188025
|
+
// idx_tasks_source and is resolved below (same argument as
|
|
188026
|
+
// scheduledTasks.create); a plain insert keeps failing loudly.
|
|
188027
|
+
})).$if(!!source, (qb) => qb.onConflict((oc) => oc.doNothing())).execute();
|
|
188028
|
+
const row = await kdb.selectFrom("tasks").selectAll().where("id", "=", id).executeTakeFirst();
|
|
188029
|
+
if (row) return mapTask2(row);
|
|
188030
|
+
if (source) {
|
|
188031
|
+
const existing = await kdb.selectFrom("tasks").selectAll().where("project_id", "=", project_id).where("source_session_id", "=", source.session_id).where("source_tool_use_id", "=", source.tool_use_id).where("source_item_index", "=", source.item_index).executeTakeFirst();
|
|
188032
|
+
if (existing) return mapTask2(existing);
|
|
188033
|
+
}
|
|
188034
|
+
throw new Error(`Failed to create task ${id}`);
|
|
188035
|
+
},
|
|
188036
|
+
listOpenIdsBySourceSession: async (sessionId) => {
|
|
188037
|
+
const rows = await kdb.selectFrom("tasks").select("id").where("source_session_id", "=", sessionId).where("source_tool_use_id", "is not", null).where("archived_at", "is", null).where("status", "in", ["todo", "in_progress"]).orderBy("id", "asc").execute();
|
|
188038
|
+
return rows.map((row) => row.id);
|
|
188009
188039
|
},
|
|
188010
188040
|
getByProjectId: async (projectId, opts) => {
|
|
188011
188041
|
let query = kdb.selectFrom("tasks").selectAll().where("project_id", "=", projectId);
|
|
@@ -188248,6 +188278,36 @@ var createSessionRemoteTouchRepo = (kdb) => ({
|
|
|
188248
188278
|
}
|
|
188249
188279
|
});
|
|
188250
188280
|
|
|
188281
|
+
// src/storage/repositories/session-retention-holds.ts
|
|
188282
|
+
var createSessionRetentionHoldRepo = (kdb) => ({
|
|
188283
|
+
sessionRetentionHolds: {
|
|
188284
|
+
list: async (sessionId) => {
|
|
188285
|
+
const rows = await kdb.selectFrom("agent_session_retention_holds").select(["holder_kind", "holder_id"]).where("session_id", "=", sessionId).orderBy("holder_kind", "asc").orderBy("holder_id", "asc").execute();
|
|
188286
|
+
return rows.map((row) => ({ kind: row.holder_kind, id: row.holder_id }));
|
|
188287
|
+
},
|
|
188288
|
+
listSessionIds: async () => {
|
|
188289
|
+
const rows = await kdb.selectFrom("agent_session_retention_holds").select("session_id").distinct().orderBy("session_id", "asc").execute();
|
|
188290
|
+
return rows.map((row) => row.session_id);
|
|
188291
|
+
},
|
|
188292
|
+
replace: async (sessionId, holds) => {
|
|
188293
|
+
const unique = /* @__PURE__ */ new Map();
|
|
188294
|
+
for (const hold of holds) unique.set(`${hold.kind}\0${hold.id}`, hold);
|
|
188295
|
+
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
188296
|
+
await kdb.transaction().execute(async (trx) => {
|
|
188297
|
+
await trx.deleteFrom("agent_session_retention_holds").where("session_id", "=", sessionId).execute();
|
|
188298
|
+
if (unique.size > 0) {
|
|
188299
|
+
await trx.insertInto("agent_session_retention_holds").values([...unique.values()].map((hold) => ({
|
|
188300
|
+
session_id: sessionId,
|
|
188301
|
+
holder_kind: hold.kind,
|
|
188302
|
+
holder_id: hold.id,
|
|
188303
|
+
created_at: createdAt
|
|
188304
|
+
}))).execute();
|
|
188305
|
+
}
|
|
188306
|
+
});
|
|
188307
|
+
}
|
|
188308
|
+
}
|
|
188309
|
+
});
|
|
188310
|
+
|
|
188251
188311
|
// src/storage/repositories/merge-targets.ts
|
|
188252
188312
|
var createMergeTargetsRepo = (kdb) => ({
|
|
188253
188313
|
mergeTargets: {
|
|
@@ -188598,6 +188658,13 @@ var createSearchCacheRepos = (kdb, _h) => ({
|
|
|
188598
188658
|
if (projectIds.length === 0) return [];
|
|
188599
188659
|
return kdb.selectFrom("search_catalog_sync_state").select(["project_id", "target_id", "last_success_at", "last_attempt_at", "last_error"]).where("project_id", "in", projectIds).execute();
|
|
188600
188660
|
},
|
|
188661
|
+
getCachedSessionTitles: async (localSessionIds) => {
|
|
188662
|
+
const titles = /* @__PURE__ */ new Map();
|
|
188663
|
+
if (localSessionIds.length === 0) return titles;
|
|
188664
|
+
const rows = await kdb.selectFrom("session_search_cache").select(["local_session_id", "title"]).where("local_session_id", "in", [...localSessionIds]).where("deleted_at", "is", null).execute();
|
|
188665
|
+
for (const row of rows) titles.set(row.local_session_id, row.title);
|
|
188666
|
+
return titles;
|
|
188667
|
+
},
|
|
188601
188668
|
// Opportunistic freshness: called where a title transits the server
|
|
188602
188669
|
// anyway (remote title PATCH proxy + local AI title generation).
|
|
188603
188670
|
// UPDATE-only — a title alone must not fabricate a session's existence.
|
|
@@ -204924,6 +204991,20 @@ var initializeSchema = (db) => {
|
|
|
204924
204991
|
last_used_at TEXT NOT NULL,
|
|
204925
204992
|
PRIMARY KEY (session_id, remote_server_id)
|
|
204926
204993
|
);
|
|
204994
|
+
|
|
204995
|
+
-- What keeps a session out of the retention sweep besides a star: one row
|
|
204996
|
+
-- per (session, holder) \u2014 today a schedule proposed from that session.
|
|
204997
|
+
-- Owned by the machine the session lives on (the hub pushes the whole set
|
|
204998
|
+
-- to a worker), since retention runs there. Retention-only: a manual
|
|
204999
|
+
-- delete still goes through and removes the rows via deleteSessionSideRows.
|
|
205000
|
+
-- No FK on session_id, for the same reason as the grants table.
|
|
205001
|
+
CREATE TABLE IF NOT EXISTS agent_session_retention_holds (
|
|
205002
|
+
session_id TEXT NOT NULL,
|
|
205003
|
+
holder_kind TEXT NOT NULL,
|
|
205004
|
+
holder_id TEXT NOT NULL,
|
|
205005
|
+
created_at TEXT NOT NULL,
|
|
205006
|
+
PRIMARY KEY (session_id, holder_kind, holder_id)
|
|
205007
|
+
);
|
|
204927
205008
|
`);
|
|
204928
205009
|
const workspaceCheckoutsTable = db.prepare(
|
|
204929
205010
|
"SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'workspace_checkouts'"
|
|
@@ -205227,6 +205308,16 @@ var initializeSchema = (db) => {
|
|
|
205227
205308
|
if (!hasArchivedAtColumn) {
|
|
205228
205309
|
db.exec("ALTER TABLE tasks ADD COLUMN archived_at INTEGER DEFAULT NULL");
|
|
205229
205310
|
}
|
|
205311
|
+
const taskSourceInfo = db.prepare("PRAGMA table_info(tasks)").all();
|
|
205312
|
+
if (!taskSourceInfo.some((col) => col.name === "source_session_id")) {
|
|
205313
|
+
db.exec("ALTER TABLE tasks ADD COLUMN source_session_id TEXT");
|
|
205314
|
+
}
|
|
205315
|
+
if (!taskSourceInfo.some((col) => col.name === "source_tool_use_id")) {
|
|
205316
|
+
db.exec("ALTER TABLE tasks ADD COLUMN source_tool_use_id TEXT");
|
|
205317
|
+
}
|
|
205318
|
+
if (!taskSourceInfo.some((col) => col.name === "source_item_index")) {
|
|
205319
|
+
db.exec("ALTER TABLE tasks ADD COLUMN source_item_index INTEGER");
|
|
205320
|
+
}
|
|
205230
205321
|
const sessionTableInfo = db.prepare("PRAGMA table_info(agent_sessions)").all();
|
|
205231
205322
|
const hasWorktreePathColumn = sessionTableInfo.some((col) => col.name === "worktree_path");
|
|
205232
205323
|
if (hasWorktreePathColumn) {
|
|
@@ -206066,6 +206157,12 @@ var initializeSchema = (db) => {
|
|
|
206066
206157
|
);
|
|
206067
206158
|
`);
|
|
206068
206159
|
db.exec(`
|
|
206160
|
+
-- Idempotency for agent-proposed tasks, one row per proposed item; same
|
|
206161
|
+
-- reasoning as idx_scheduled_tasks_source. Also serves the retention-hold
|
|
206162
|
+
-- lookup by source session.
|
|
206163
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_tasks_source
|
|
206164
|
+
ON tasks(source_session_id, source_tool_use_id, source_item_index)
|
|
206165
|
+
WHERE source_tool_use_id IS NOT NULL;
|
|
206069
206166
|
CREATE INDEX IF NOT EXISTS idx_tasks_project_archived_position_id
|
|
206070
206167
|
ON tasks(project_id, archived_at, position ASC, id ASC);
|
|
206071
206168
|
CREATE INDEX IF NOT EXISTS idx_tasks_project_archived_status_position_id
|
|
@@ -206305,6 +206402,7 @@ var createSqliteStorage = async (dbPath) => {
|
|
|
206305
206402
|
...createCrossRemoteAuditRepo(kdb),
|
|
206306
206403
|
...createSessionRemoteGrantRepo(kdb),
|
|
206307
206404
|
...createSessionRemoteTouchRepo(kdb),
|
|
206405
|
+
...createSessionRetentionHoldRepo(kdb),
|
|
206308
206406
|
...createMergeTargetsRepo(kdb),
|
|
206309
206407
|
...createSearchCacheRepos(kdb, h),
|
|
206310
206408
|
...createWorkflowRunRepos(kdb),
|
|
@@ -206426,6 +206524,8 @@ var SESSION_TOOLS_MCP_PATH = "/api/session-mcp";
|
|
|
206426
206524
|
var SESSION_TOOLS_MCP_SERVER_NAME = "vibedeckx";
|
|
206427
206525
|
var PROPOSE_SCHEDULE_TOOL = "propose_schedule";
|
|
206428
206526
|
var CANONICAL_PROPOSE_SCHEDULE_TOOL = `mcp__${SESSION_TOOLS_MCP_SERVER_NAME}__${PROPOSE_SCHEDULE_TOOL}`;
|
|
206527
|
+
var PROPOSE_TASK_TOOL = "propose_task";
|
|
206528
|
+
var CANONICAL_PROPOSE_TASK_TOOL = `mcp__${SESSION_TOOLS_MCP_SERVER_NAME}__${PROPOSE_TASK_TOOL}`;
|
|
206429
206529
|
var PROPOSE_SCHEDULE_DESCRIPTION = [
|
|
206430
206530
|
"Propose a recurring scheduled check to the user. This is the only way to schedule work in this",
|
|
206431
206531
|
"environment. Call it in either situation:",
|
|
@@ -206459,12 +206559,15 @@ var PROPOSE_SCHEDULE_DESCRIPTION = [
|
|
|
206459
206559
|
"Project, execution target and branch are taken from this session \u2014 do not describe them here."
|
|
206460
206560
|
].join("\n");
|
|
206461
206561
|
var ARTIFACT_PATH_HINT = "Files for the user to look at: when you produce a screenshot, image, or report file for the user, write its absolute path on its own line in your reply so it can be previewed.";
|
|
206562
|
+
var TASK_ROUTING_HINT = `Tasks: when the user asks to record something as a task or to-do for later, call \`${CANONICAL_PROPOSE_TASK_TOOL}\` to propose it, and do not do the work itself now. Never call it, or suggest creating a task, unless the user asks.`;
|
|
206462
206563
|
var SESSION_TOOLS_MCP_INSTRUCTIONS = [
|
|
206463
206564
|
`\`${PROPOSE_SCHEDULE_TOOL}\` is the only way to schedule work in this environment.`,
|
|
206464
206565
|
'When the user asks for anything recurring \u2014 nightly, hourly, every morning, on a cron, "keep',
|
|
206465
206566
|
'watching" \u2014 call it instead of writing a crontab entry, systemd timer, or setInterval loop.',
|
|
206466
206567
|
"Scheduling inside the user's own product remains ordinary coding work.",
|
|
206467
206568
|
"",
|
|
206569
|
+
TASK_ROUTING_HINT,
|
|
206570
|
+
"",
|
|
206468
206571
|
ARTIFACT_PATH_HINT
|
|
206469
206572
|
].join("\n");
|
|
206470
206573
|
var SESSION_TOOLS_SYSTEM_PROMPT_HINT = [
|
|
@@ -206472,6 +206575,7 @@ var SESSION_TOOLS_SYSTEM_PROMPT_HINT = [
|
|
|
206472
206575
|
`morning, on a cron, "keep watching"), call the \`${CANONICAL_PROPOSE_SCHEDULE_TOOL}\` tool. That`,
|
|
206473
206576
|
"is the only way to schedule work here \u2014 do not hand-roll a crontab entry, systemd timer, or",
|
|
206474
206577
|
"setInterval loop for it. Writing scheduling into the user's own project is still normal coding.",
|
|
206578
|
+
TASK_ROUTING_HINT,
|
|
206475
206579
|
ARTIFACT_PATH_HINT
|
|
206476
206580
|
].join(" ");
|
|
206477
206581
|
var PROPOSE_SCHEDULE_INPUT_SCHEMA = {
|
|
@@ -206513,19 +206617,96 @@ function parseProposeScheduleArgs(args) {
|
|
|
206513
206617
|
}
|
|
206514
206618
|
return { ok: true, value: { name: name25, cron_expr: cronExpr, run_type, content, ...timezone ? { timezone } : {} } };
|
|
206515
206619
|
}
|
|
206516
|
-
var
|
|
206620
|
+
var PROPOSE_TASK_DESCRIPTION = [
|
|
206621
|
+
"Propose one or more tasks for the project's task list: work to be done LATER, recorded so it",
|
|
206622
|
+
`isn't lost. Call this only when the user asks to record work as a task ("make this a task",`,
|
|
206623
|
+
'"add a to-do for the skipped test"). Never call it on your own initiative.',
|
|
206624
|
+
"",
|
|
206625
|
+
'Do not do the work. Even when the task reads like an instruction ("add error handling to X"),',
|
|
206626
|
+
"the user is asking you to write it down, not to carry it out now.",
|
|
206627
|
+
"",
|
|
206628
|
+
"The proposal is shown to the user as a confirmation card; it does NOT create anything by itself",
|
|
206629
|
+
"and this call does not wait for the user. Say you have proposed the task (never that you created",
|
|
206630
|
+
"it) and continue.",
|
|
206631
|
+
"",
|
|
206632
|
+
"Each description must be self-contained: the task may be picked up later in a fresh session with",
|
|
206633
|
+
"none of this conversation's context. Cover the background, the relevant files, what remains to",
|
|
206634
|
+
"be done, and how to tell it is finished. Propose several tasks in one call when the user asks to",
|
|
206635
|
+
"split the work.",
|
|
206636
|
+
"",
|
|
206637
|
+
"Project and source session are taken from this session \u2014 do not describe them here."
|
|
206638
|
+
].join("\n");
|
|
206639
|
+
var PROPOSE_TASK_INPUT_SCHEMA = {
|
|
206640
|
+
type: "object",
|
|
206641
|
+
properties: {
|
|
206642
|
+
tasks: {
|
|
206643
|
+
type: "array",
|
|
206644
|
+
minItems: 1,
|
|
206645
|
+
maxItems: 5,
|
|
206646
|
+
description: "The tasks to propose, usually one.",
|
|
206647
|
+
items: {
|
|
206648
|
+
type: "object",
|
|
206649
|
+
properties: {
|
|
206650
|
+
title: { type: "string", description: 'Short, specific title, e.g. "Cover remote path in retention-hold tests"' },
|
|
206651
|
+
description: { type: "string", description: "Self-contained description: background, relevant files, remaining work, definition of done." },
|
|
206652
|
+
priority: { type: "string", enum: ["low", "medium", "high", "urgent"], description: "Optional; defaults to medium." }
|
|
206653
|
+
},
|
|
206654
|
+
required: ["title", "description"]
|
|
206655
|
+
}
|
|
206656
|
+
}
|
|
206657
|
+
},
|
|
206658
|
+
required: ["tasks"]
|
|
206659
|
+
};
|
|
206660
|
+
var PROPOSE_TASK_ACK = "Proposal shown to the user as a confirmation card. Nothing has been created yet \u2014 the user decides whether to accept it. Tell the user you PROPOSED the task and that they can confirm it on the card above. Do not start working on it.";
|
|
206661
|
+
var PROPOSE_TASK_MAX_ITEMS = 5;
|
|
206662
|
+
var TASK_TITLE_MAX = 200;
|
|
206663
|
+
var TASK_DESCRIPTION_MAX = 2e4;
|
|
206664
|
+
var TASK_PRIORITIES = ["low", "medium", "high", "urgent"];
|
|
206665
|
+
function parseProposeTaskArgs(args) {
|
|
206666
|
+
const raw = args.tasks;
|
|
206667
|
+
if (!Array.isArray(raw) || raw.length === 0) return { ok: false, error: "tasks must be a non-empty array" };
|
|
206668
|
+
if (raw.length > PROPOSE_TASK_MAX_ITEMS) {
|
|
206669
|
+
return { ok: false, error: `propose at most ${PROPOSE_TASK_MAX_ITEMS} tasks at a time` };
|
|
206670
|
+
}
|
|
206671
|
+
const tasks = [];
|
|
206672
|
+
for (const [i, item] of raw.entries()) {
|
|
206673
|
+
const obj = item && typeof item === "object" ? item : {};
|
|
206674
|
+
const title = str(obj.title);
|
|
206675
|
+
if (!title) return { ok: false, error: `tasks[${i}].title is required` };
|
|
206676
|
+
if (title.length > TASK_TITLE_MAX) {
|
|
206677
|
+
return { ok: false, error: `tasks[${i}].title must be at most ${TASK_TITLE_MAX} characters` };
|
|
206678
|
+
}
|
|
206679
|
+
const description = str(obj.description);
|
|
206680
|
+
if (!description) return { ok: false, error: `tasks[${i}].description is required` };
|
|
206681
|
+
if (description.length > TASK_DESCRIPTION_MAX) {
|
|
206682
|
+
return { ok: false, error: `tasks[${i}].description must be at most ${TASK_DESCRIPTION_MAX} characters` };
|
|
206683
|
+
}
|
|
206684
|
+
const priorityRaw = str(obj.priority)?.toLowerCase();
|
|
206685
|
+
if (priorityRaw && !TASK_PRIORITIES.includes(priorityRaw)) {
|
|
206686
|
+
return { ok: false, error: `tasks[${i}].priority must be one of: ${TASK_PRIORITIES.join(", ")}` };
|
|
206687
|
+
}
|
|
206688
|
+
tasks.push({ title, description, priority: priorityRaw || "medium" });
|
|
206689
|
+
}
|
|
206690
|
+
return { ok: true, value: tasks };
|
|
206691
|
+
}
|
|
206692
|
+
var aliasesOf = (tool2, canonical) => new Set(
|
|
206517
206693
|
[
|
|
206518
|
-
|
|
206519
|
-
|
|
206520
|
-
`${SESSION_TOOLS_MCP_SERVER_NAME}.${
|
|
206521
|
-
`${SESSION_TOOLS_MCP_SERVER_NAME}/${
|
|
206522
|
-
`${SESSION_TOOLS_MCP_SERVER_NAME}__${
|
|
206523
|
-
`${SESSION_TOOLS_MCP_SERVER_NAME}-${
|
|
206694
|
+
tool2,
|
|
206695
|
+
canonical,
|
|
206696
|
+
`${SESSION_TOOLS_MCP_SERVER_NAME}.${tool2}`,
|
|
206697
|
+
`${SESSION_TOOLS_MCP_SERVER_NAME}/${tool2}`,
|
|
206698
|
+
`${SESSION_TOOLS_MCP_SERVER_NAME}__${tool2}`,
|
|
206699
|
+
`${SESSION_TOOLS_MCP_SERVER_NAME}-${tool2}`
|
|
206524
206700
|
].map((n) => n.toLowerCase())
|
|
206525
206701
|
);
|
|
206702
|
+
var SESSION_TOOL_ALIASES = [
|
|
206703
|
+
[aliasesOf(PROPOSE_SCHEDULE_TOOL, CANONICAL_PROPOSE_SCHEDULE_TOOL), CANONICAL_PROPOSE_SCHEDULE_TOOL],
|
|
206704
|
+
[aliasesOf(PROPOSE_TASK_TOOL, CANONICAL_PROPOSE_TASK_TOOL), CANONICAL_PROPOSE_TASK_TOOL]
|
|
206705
|
+
];
|
|
206526
206706
|
function canonicalizeSessionToolName(tool2, server) {
|
|
206527
206707
|
if (server !== void 0 && server.trim().toLowerCase() !== SESSION_TOOLS_MCP_SERVER_NAME) return tool2;
|
|
206528
|
-
|
|
206708
|
+
const key2 = tool2.trim().toLowerCase();
|
|
206709
|
+
return SESSION_TOOL_ALIASES.find(([aliases]) => aliases.has(key2))?.[1] ?? tool2;
|
|
206529
206710
|
}
|
|
206530
206711
|
async function mintSessionToolsMcpConfig(deps, args) {
|
|
206531
206712
|
const origin = args.origin?.trim();
|
|
@@ -207978,6 +208159,256 @@ ${GREEN}Done${info}${RESET}
|
|
|
207978
208159
|
}
|
|
207979
208160
|
};
|
|
207980
208161
|
|
|
208162
|
+
// src/trace-context.ts
|
|
208163
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
208164
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
208165
|
+
var VERSION3 = "00";
|
|
208166
|
+
var INVALID_VERSION = "ff";
|
|
208167
|
+
var ZERO_TRACE_ID = "0".repeat(32);
|
|
208168
|
+
var ZERO_SPAN_ID = "0".repeat(16);
|
|
208169
|
+
var HEX_2 = /^[0-9a-f]{2}$/;
|
|
208170
|
+
var HEX_16 = /^[0-9a-f]{16}$/;
|
|
208171
|
+
var HEX_32 = /^[0-9a-f]{32}$/;
|
|
208172
|
+
function parseTraceparent(value) {
|
|
208173
|
+
const raw = Array.isArray(value) ? value[0] : value;
|
|
208174
|
+
if (typeof raw !== "string") return null;
|
|
208175
|
+
const parts = raw.split("-");
|
|
208176
|
+
if (parts.length < 4) return null;
|
|
208177
|
+
const [version2, traceId, spanId, flags] = parts;
|
|
208178
|
+
if (!HEX_2.test(version2) || version2 === INVALID_VERSION) return null;
|
|
208179
|
+
if (version2 === VERSION3 && parts.length !== 4) return null;
|
|
208180
|
+
if (!HEX_32.test(traceId) || traceId === ZERO_TRACE_ID) return null;
|
|
208181
|
+
if (!HEX_16.test(spanId) || spanId === ZERO_SPAN_ID) return null;
|
|
208182
|
+
if (!HEX_2.test(flags)) return null;
|
|
208183
|
+
return { traceId, spanId, flags };
|
|
208184
|
+
}
|
|
208185
|
+
function formatTraceparent(ctx) {
|
|
208186
|
+
return `${VERSION3}-${ctx.traceId}-${ctx.spanId}-${ctx.sampled ? "01" : "00"}`;
|
|
208187
|
+
}
|
|
208188
|
+
function newTraceId() {
|
|
208189
|
+
return randomBytes2(16).toString("hex");
|
|
208190
|
+
}
|
|
208191
|
+
function newSpanId() {
|
|
208192
|
+
return randomBytes2(8).toString("hex");
|
|
208193
|
+
}
|
|
208194
|
+
function newTraceContext(incoming) {
|
|
208195
|
+
const parsed = parseTraceparent(incoming);
|
|
208196
|
+
if (parsed) {
|
|
208197
|
+
return {
|
|
208198
|
+
traceId: parsed.traceId,
|
|
208199
|
+
spanId: newSpanId(),
|
|
208200
|
+
parentSpanId: parsed.spanId,
|
|
208201
|
+
sampled: (parseInt(parsed.flags, 16) & 1) === 1,
|
|
208202
|
+
continued: true
|
|
208203
|
+
};
|
|
208204
|
+
}
|
|
208205
|
+
return {
|
|
208206
|
+
traceId: newTraceId(),
|
|
208207
|
+
spanId: newSpanId(),
|
|
208208
|
+
sampled: true,
|
|
208209
|
+
continued: false
|
|
208210
|
+
};
|
|
208211
|
+
}
|
|
208212
|
+
var storage = new AsyncLocalStorage();
|
|
208213
|
+
function runWithTraceContext(ctx, fn) {
|
|
208214
|
+
return storage.run(ctx, fn);
|
|
208215
|
+
}
|
|
208216
|
+
function getTraceContext() {
|
|
208217
|
+
return storage.getStore();
|
|
208218
|
+
}
|
|
208219
|
+
function outboundTraceparent() {
|
|
208220
|
+
const ctx = storage.getStore();
|
|
208221
|
+
return ctx ? formatTraceparent(ctx) : void 0;
|
|
208222
|
+
}
|
|
208223
|
+
|
|
208224
|
+
// src/utils/remote-proxy.ts
|
|
208225
|
+
function proxyStatus(result, fallback = 502) {
|
|
208226
|
+
return result.status > 0 ? result.status : fallback;
|
|
208227
|
+
}
|
|
208228
|
+
async function proxyToRemoteAuto(remoteServerId, method, apiPath, body, options) {
|
|
208229
|
+
const rcm = options?.reverseConnectManager;
|
|
208230
|
+
if (rcm && rcm.isConnected(remoteServerId)) {
|
|
208231
|
+
const traceparent = outboundTraceparent();
|
|
208232
|
+
const headers = {
|
|
208233
|
+
...traceparent ? { traceparent } : {},
|
|
208234
|
+
...options?.headers
|
|
208235
|
+
};
|
|
208236
|
+
return rcm.sendHttpRequest(remoteServerId, method, apiPath, body, options?.timeoutMs, headers);
|
|
208237
|
+
}
|
|
208238
|
+
return {
|
|
208239
|
+
ok: false,
|
|
208240
|
+
status: 0,
|
|
208241
|
+
data: { error: "Remote server is not connected" },
|
|
208242
|
+
errorCode: "network_error",
|
|
208243
|
+
requestId: options?.requestId
|
|
208244
|
+
};
|
|
208245
|
+
}
|
|
208246
|
+
|
|
208247
|
+
// src/retention-holds.ts
|
|
208248
|
+
var TIMEOUT_MS = 1e4;
|
|
208249
|
+
var RELEASE_STALE_MAX_SESSIONS = 1e4;
|
|
208250
|
+
var RetentionHoldSync = class {
|
|
208251
|
+
constructor(deps) {
|
|
208252
|
+
this.deps = deps;
|
|
208253
|
+
}
|
|
208254
|
+
deps;
|
|
208255
|
+
tails = /* @__PURE__ */ new Map();
|
|
208256
|
+
releasing = /* @__PURE__ */ new Map();
|
|
208257
|
+
/**
|
|
208258
|
+
* Recompute `sessionId`'s holds and write them where the session lives.
|
|
208259
|
+
* Rejects when the write did not land (worker offline); the caller decides
|
|
208260
|
+
* whether that blocks.
|
|
208261
|
+
*/
|
|
208262
|
+
sync(sessionId) {
|
|
208263
|
+
return this.exclusive(sessionId, (syncNow) => syncNow());
|
|
208264
|
+
}
|
|
208265
|
+
/**
|
|
208266
|
+
* Run `fn` with this session's slot held: no other sync or exclusive block
|
|
208267
|
+
* for the session starts until it settles. `syncNow` syncs inside the slot
|
|
208268
|
+
* (calling `sync` from `fn` would wait on itself).
|
|
208269
|
+
*/
|
|
208270
|
+
exclusive(sessionId, fn) {
|
|
208271
|
+
const prev = this.tails.get(sessionId) ?? Promise.resolve();
|
|
208272
|
+
const run2 = prev.then(() => fn(() => this.syncNow(sessionId)));
|
|
208273
|
+
const tail = run2.catch(() => void 0);
|
|
208274
|
+
this.tails.set(sessionId, tail);
|
|
208275
|
+
void tail.then(() => {
|
|
208276
|
+
if (this.tails.get(sessionId) === tail) this.tails.delete(sessionId);
|
|
208277
|
+
});
|
|
208278
|
+
return run2;
|
|
208279
|
+
}
|
|
208280
|
+
/**
|
|
208281
|
+
* Recompute every session that holds on `remoteServerId` reports. A hold
|
|
208282
|
+
* only ever outlives its schedules when a release failed (worker away, or a
|
|
208283
|
+
* rolled-back create whose push landed after its timeout); this is what
|
|
208284
|
+
* eventually frees those sessions. It only re-derives sessions that already
|
|
208285
|
+
* have holds — schedules that predate holds are deliberately not backfilled.
|
|
208286
|
+
* Never throws; returns how many sessions could not be synced. A call while
|
|
208287
|
+
* one for the same worker is running joins it.
|
|
208288
|
+
*/
|
|
208289
|
+
releaseStale(remoteServerId) {
|
|
208290
|
+
const running = this.releasing.get(remoteServerId);
|
|
208291
|
+
if (running) return running;
|
|
208292
|
+
const run2 = this.releaseStaleNow(remoteServerId).finally(() => this.releasing.delete(remoteServerId));
|
|
208293
|
+
this.releasing.set(remoteServerId, run2);
|
|
208294
|
+
return run2;
|
|
208295
|
+
}
|
|
208296
|
+
async releaseStaleNow(remoteServerId) {
|
|
208297
|
+
const proxy = this.deps.proxy ?? proxyToRemoteAuto;
|
|
208298
|
+
const listed = await proxy(
|
|
208299
|
+
remoteServerId,
|
|
208300
|
+
"GET",
|
|
208301
|
+
"/api/path/retention-holds",
|
|
208302
|
+
void 0,
|
|
208303
|
+
{ reverseConnectManager: this.deps.reverseConnectManager, timeoutMs: TIMEOUT_MS }
|
|
208304
|
+
);
|
|
208305
|
+
const sessionIds = listed.data?.sessionIds;
|
|
208306
|
+
if (!listed.ok || !Array.isArray(sessionIds)) return 1;
|
|
208307
|
+
if (sessionIds.length > RELEASE_STALE_MAX_SESSIONS) {
|
|
208308
|
+
console.warn(`[RetentionHolds] ${remoteServerId} listed ${sessionIds.length} held sessions; checking the first ${RELEASE_STALE_MAX_SESSIONS}`);
|
|
208309
|
+
}
|
|
208310
|
+
let failed = 0;
|
|
208311
|
+
for (const remoteSessionId of sessionIds.slice(0, RELEASE_STALE_MAX_SESSIONS)) {
|
|
208312
|
+
if (typeof remoteSessionId !== "string") continue;
|
|
208313
|
+
try {
|
|
208314
|
+
const mapping = await this.deps.storage.remoteSessionMappings.getByRemote(remoteServerId, remoteSessionId);
|
|
208315
|
+
if (mapping) {
|
|
208316
|
+
await this.sync(mapping.local_session_id);
|
|
208317
|
+
} else {
|
|
208318
|
+
await this.push({ remoteServerId, remoteSessionId }, []);
|
|
208319
|
+
}
|
|
208320
|
+
} catch {
|
|
208321
|
+
failed++;
|
|
208322
|
+
}
|
|
208323
|
+
}
|
|
208324
|
+
return failed;
|
|
208325
|
+
}
|
|
208326
|
+
async syncNow(sessionId) {
|
|
208327
|
+
const holds = [];
|
|
208328
|
+
for (const source of this.deps.sources) {
|
|
208329
|
+
for (const id of await source.listHolders(sessionId)) holds.push({ kind: source.kind, id });
|
|
208330
|
+
}
|
|
208331
|
+
if (!sessionId.startsWith("remote-")) {
|
|
208332
|
+
if (!await this.deps.storage.agentSessions.getById(sessionId)) return;
|
|
208333
|
+
await this.deps.storage.sessionRetentionHolds.replace(sessionId, holds);
|
|
208334
|
+
return;
|
|
208335
|
+
}
|
|
208336
|
+
const remote = await this.resolveRemote(sessionId);
|
|
208337
|
+
if (!remote) return;
|
|
208338
|
+
await this.push(remote, holds);
|
|
208339
|
+
}
|
|
208340
|
+
async push(remote, holds) {
|
|
208341
|
+
const proxy = this.deps.proxy ?? proxyToRemoteAuto;
|
|
208342
|
+
const result = await proxy(
|
|
208343
|
+
remote.remoteServerId,
|
|
208344
|
+
"PUT",
|
|
208345
|
+
`/api/path/retention-holds/${remote.remoteSessionId}`,
|
|
208346
|
+
{ holds },
|
|
208347
|
+
{ reverseConnectManager: this.deps.reverseConnectManager, timeoutMs: TIMEOUT_MS }
|
|
208348
|
+
);
|
|
208349
|
+
if (result.status === 404) return;
|
|
208350
|
+
if (!result.ok) {
|
|
208351
|
+
throw new Error(
|
|
208352
|
+
result.status === 0 ? "The session's machine is not connected" : `Worker responded ${result.status}`
|
|
208353
|
+
);
|
|
208354
|
+
}
|
|
208355
|
+
}
|
|
208356
|
+
async resolveRemote(sessionId) {
|
|
208357
|
+
const live = this.deps.remoteSessionMap.get(sessionId);
|
|
208358
|
+
if (live) return live;
|
|
208359
|
+
const mapping = await this.deps.storage.remoteSessionMappings.getByLocal(sessionId);
|
|
208360
|
+
return mapping ? { remoteServerId: mapping.remote_server_id, remoteSessionId: mapping.remote_session_id } : null;
|
|
208361
|
+
}
|
|
208362
|
+
};
|
|
208363
|
+
function scheduleHoldSource(storage2) {
|
|
208364
|
+
return {
|
|
208365
|
+
kind: "schedule",
|
|
208366
|
+
listHolders: (sessionId) => storage2.scheduledTasks.listIdsBySourceSession(sessionId)
|
|
208367
|
+
};
|
|
208368
|
+
}
|
|
208369
|
+
function taskHoldSource(storage2) {
|
|
208370
|
+
return {
|
|
208371
|
+
kind: "task",
|
|
208372
|
+
listHolders: (sessionId) => storage2.tasks.listOpenIdsBySourceSession(sessionId)
|
|
208373
|
+
};
|
|
208374
|
+
}
|
|
208375
|
+
function subscribeTaskHoldSync(eventBus, holds) {
|
|
208376
|
+
return eventBus.subscribe((event) => {
|
|
208377
|
+
if (event.type !== "task:updated") return;
|
|
208378
|
+
const sourceSessionId = event.task.source_session_id;
|
|
208379
|
+
if (typeof sourceSessionId !== "string" || !sourceSessionId) return;
|
|
208380
|
+
void holds.sync(sourceSessionId).catch((error48) => {
|
|
208381
|
+
console.warn(`[RetentionHolds] task hold sync for ${sourceSessionId} deferred:`, error48);
|
|
208382
|
+
});
|
|
208383
|
+
});
|
|
208384
|
+
}
|
|
208385
|
+
function taskHoldsSource(task) {
|
|
208386
|
+
return !!task.source_session_id && !!task.source_tool_use_id && task.archived_at === null && (task.status === "todo" || task.status === "in_progress");
|
|
208387
|
+
}
|
|
208388
|
+
async function applyTaskChange(deps, taskId, apply, revert) {
|
|
208389
|
+
const existing = await deps.storage.tasks.getById(taskId);
|
|
208390
|
+
if (!existing?.source_session_id) return apply();
|
|
208391
|
+
return deps.retentionHolds.exclusive(existing.source_session_id, async (syncNow) => {
|
|
208392
|
+
const before = await deps.storage.tasks.getById(taskId);
|
|
208393
|
+
if (!before) return void 0;
|
|
208394
|
+
const task = await apply();
|
|
208395
|
+
if (!task || taskHoldsSource(before) || !taskHoldsSource(task)) return task;
|
|
208396
|
+
try {
|
|
208397
|
+
await syncNow();
|
|
208398
|
+
return task;
|
|
208399
|
+
} catch (error48) {
|
|
208400
|
+
await revert(before);
|
|
208401
|
+
await syncNow().catch(() => void 0);
|
|
208402
|
+
throw error48;
|
|
208403
|
+
}
|
|
208404
|
+
});
|
|
208405
|
+
}
|
|
208406
|
+
function revertTaskPatch(storage2, taskId, patch) {
|
|
208407
|
+
return (before) => storage2.tasks.update(taskId, Object.fromEntries(
|
|
208408
|
+
Object.keys(patch).filter((key2) => patch[key2] !== void 0).map((key2) => [key2, before[key2]])
|
|
208409
|
+
));
|
|
208410
|
+
}
|
|
208411
|
+
|
|
207981
208412
|
// src/agent-session-manager.ts
|
|
207982
208413
|
import { spawn as spawn3 } from "child_process";
|
|
207983
208414
|
import { randomUUID } from "crypto";
|
|
@@ -208072,7 +208503,7 @@ var ClaudeCodeProvider = class {
|
|
|
208072
208503
|
permissionMode,
|
|
208073
208504
|
Object.keys(mcpServers).length > 0 ? buildClaudeMcpConfigArg(mcpServers) : void 0,
|
|
208074
208505
|
model,
|
|
208075
|
-
sessionToolsMcp ? [CANONICAL_PROPOSE_SCHEDULE_TOOL] : void 0,
|
|
208506
|
+
sessionToolsMcp ? [CANONICAL_PROPOSE_SCHEDULE_TOOL, CANONICAL_PROPOSE_TASK_TOOL] : void 0,
|
|
208076
208507
|
sessionToolsMcp ? SESSION_TOOLS_SYSTEM_PROMPT_HINT : void 0
|
|
208077
208508
|
);
|
|
208078
208509
|
}
|
|
@@ -208701,7 +209132,7 @@ function getAllProviders() {
|
|
|
208701
209132
|
}
|
|
208702
209133
|
|
|
208703
209134
|
// src/utils/cross-remote-token.ts
|
|
208704
|
-
import { createHmac as createHmac2, randomBytes as
|
|
209135
|
+
import { createHmac as createHmac2, randomBytes as randomBytes3, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
208705
209136
|
var CROSS_REMOTE_SECRET_SETTING = "cross_remote_token_secret";
|
|
208706
209137
|
var CROSS_REMOTE_TOKEN_TTL_MS = 7 * 864e5;
|
|
208707
209138
|
var sign2 = (secret, body) => createHmac2("sha256", secret).update(body).digest("base64url");
|
|
@@ -208773,7 +209204,7 @@ function verifyCrossRemoteTokenDetailed(secret, token, nowMs) {
|
|
|
208773
209204
|
async function getCrossRemoteSecret(storage2) {
|
|
208774
209205
|
return storage2.settings.getOrCreate(
|
|
208775
209206
|
CROSS_REMOTE_SECRET_SETTING,
|
|
208776
|
-
() =>
|
|
209207
|
+
() => randomBytes3(32).toString("hex")
|
|
208777
209208
|
);
|
|
208778
209209
|
}
|
|
208779
209210
|
|
|
@@ -214166,7 +214597,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
214166
214597
|
);
|
|
214167
214598
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
214168
214599
|
}
|
|
214169
|
-
var
|
|
214600
|
+
var VERSION4 = true ? "4.0.15" : "0.0.0-test";
|
|
214170
214601
|
var getOriginalFetch = () => globalThis.fetch;
|
|
214171
214602
|
var getFromApi = async ({
|
|
214172
214603
|
url: url2,
|
|
@@ -214181,7 +214612,7 @@ var getFromApi = async ({
|
|
|
214181
214612
|
method: "GET",
|
|
214182
214613
|
headers: withUserAgentSuffix(
|
|
214183
214614
|
headers,
|
|
214184
|
-
`ai-sdk/provider-utils/${
|
|
214615
|
+
`ai-sdk/provider-utils/${VERSION4}`,
|
|
214185
214616
|
getRuntimeEnvironmentUserAgent()
|
|
214186
214617
|
),
|
|
214187
214618
|
signal: abortSignal
|
|
@@ -215729,7 +216160,7 @@ var postToApi = async ({
|
|
|
215729
216160
|
method: "POST",
|
|
215730
216161
|
headers: withUserAgentSuffix(
|
|
215731
216162
|
headers,
|
|
215732
|
-
`ai-sdk/provider-utils/${
|
|
216163
|
+
`ai-sdk/provider-utils/${VERSION4}`,
|
|
215733
216164
|
getRuntimeEnvironmentUserAgent()
|
|
215734
216165
|
),
|
|
215735
216166
|
body: body.content,
|
|
@@ -217165,7 +217596,7 @@ async function getVercelRequestId() {
|
|
|
217165
217596
|
var _a94;
|
|
217166
217597
|
return (_a94 = (0, import_oidc.getContext)().headers) == null ? void 0 : _a94["x-vercel-id"];
|
|
217167
217598
|
}
|
|
217168
|
-
var
|
|
217599
|
+
var VERSION5 = true ? "3.0.55" : "0.0.0-test";
|
|
217169
217600
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
217170
217601
|
function createGatewayProvider(options = {}) {
|
|
217171
217602
|
var _a94, _b93;
|
|
@@ -217184,7 +217615,7 @@ function createGatewayProvider(options = {}) {
|
|
|
217184
217615
|
[GATEWAY_AUTH_METHOD_HEADER]: auth2.authMethod,
|
|
217185
217616
|
...options.headers
|
|
217186
217617
|
},
|
|
217187
|
-
`ai-sdk/gateway/${
|
|
217618
|
+
`ai-sdk/gateway/${VERSION5}`
|
|
217188
217619
|
);
|
|
217189
217620
|
} catch (error48) {
|
|
217190
217621
|
throw GatewayAuthenticationError.createContextualError({
|
|
@@ -217931,7 +218362,7 @@ function detectMediaType({
|
|
|
217931
218362
|
}
|
|
217932
218363
|
return void 0;
|
|
217933
218364
|
}
|
|
217934
|
-
var
|
|
218365
|
+
var VERSION6 = true ? "6.0.99" : "0.0.0-test";
|
|
217935
218366
|
var download = async ({
|
|
217936
218367
|
url: url2,
|
|
217937
218368
|
maxBytes,
|
|
@@ -217943,7 +218374,7 @@ var download = async ({
|
|
|
217943
218374
|
const response = await fetch(urlText, {
|
|
217944
218375
|
headers: withUserAgentSuffix(
|
|
217945
218376
|
{},
|
|
217946
|
-
`ai-sdk/${
|
|
218377
|
+
`ai-sdk/${VERSION6}`,
|
|
217947
218378
|
getRuntimeEnvironmentUserAgent()
|
|
217948
218379
|
),
|
|
217949
218380
|
signal: abortSignal
|
|
@@ -220616,7 +221047,7 @@ async function generateText({
|
|
|
220616
221047
|
const callSettings = prepareCallSettings(settings);
|
|
220617
221048
|
const headersWithUserAgent = withUserAgentSuffix(
|
|
220618
221049
|
headers != null ? headers : {},
|
|
220619
|
-
`ai/${
|
|
221050
|
+
`ai/${VERSION6}`
|
|
220620
221051
|
);
|
|
220621
221052
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
|
220622
221053
|
model,
|
|
@@ -225459,7 +225890,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
225459
225890
|
};
|
|
225460
225891
|
}
|
|
225461
225892
|
};
|
|
225462
|
-
var
|
|
225893
|
+
var VERSION7 = true ? "2.0.20" : "0.0.0-test";
|
|
225463
225894
|
function createDeepSeek(options = {}) {
|
|
225464
225895
|
var _a26;
|
|
225465
225896
|
const baseURL = withoutTrailingSlash(
|
|
@@ -225474,7 +225905,7 @@ function createDeepSeek(options = {}) {
|
|
|
225474
225905
|
})}`,
|
|
225475
225906
|
...options.headers
|
|
225476
225907
|
},
|
|
225477
|
-
`ai-sdk/deepseek/${
|
|
225908
|
+
`ai-sdk/deepseek/${VERSION7}`
|
|
225478
225909
|
);
|
|
225479
225910
|
const createLanguageModel = (modelId) => {
|
|
225480
225911
|
return new DeepSeekChatLanguageModel(modelId, {
|
|
@@ -226117,7 +226548,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
|
226117
226548
|
);
|
|
226118
226549
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
226119
226550
|
}
|
|
226120
|
-
var
|
|
226551
|
+
var VERSION8 = true ? "4.0.1" : "0.0.0-test";
|
|
226121
226552
|
function loadApiKey2({
|
|
226122
226553
|
apiKey,
|
|
226123
226554
|
environmentVariableName,
|
|
@@ -227507,7 +227938,7 @@ var postToApi2 = async ({
|
|
|
227507
227938
|
method: "POST",
|
|
227508
227939
|
headers: withUserAgentSuffix2(
|
|
227509
227940
|
headers,
|
|
227510
|
-
`ai-sdk/provider-utils/${
|
|
227941
|
+
`ai-sdk/provider-utils/${VERSION8}`,
|
|
227511
227942
|
getRuntimeEnvironmentUserAgent2()
|
|
227512
227943
|
),
|
|
227513
227944
|
body: body.content,
|
|
@@ -230396,6 +230827,8 @@ async function appendRemoteGrantContext(storage2, sessionId, userId, content) {
|
|
|
230396
230827
|
|
|
230397
230828
|
// src/utils/conversation-title.ts
|
|
230398
230829
|
var TITLE_MAX_CHARS = 60;
|
|
230830
|
+
var VSCHEDULE_BLOCK_RE = /<vschedule(?:\s[^>]*)?>[\s\S]*?<\/vschedule>/g;
|
|
230831
|
+
var VTASK_BLOCK_RE = /<vtask(?:\s[^>]*)?>[\s\S]*?<\/vtask>/g;
|
|
230399
230832
|
var AI_TIMEOUT_MS = 15e3;
|
|
230400
230833
|
var MAX_INPUT_CHARS = 2e3;
|
|
230401
230834
|
var SYSTEM_PROMPT = "You write very short, descriptive titles for chat conversations. Reply with the title only \u2014 no quotes, no trailing punctuation, no markdown, no prefixes like 'Title:'. Use the same language as the user's message. Keep it under 8 words and 50 characters.";
|
|
@@ -230412,7 +230845,7 @@ async function isChatModelConfigured(storage2, userId) {
|
|
|
230412
230845
|
}
|
|
230413
230846
|
function extractUserText(content) {
|
|
230414
230847
|
const text2 = typeof content === "string" ? content : content.filter((p2) => p2.type === "text").map((p2) => p2.text).join(" ");
|
|
230415
|
-
return stripRemoteGrantContext(text2);
|
|
230848
|
+
return stripRemoteGrantContext(text2.replace(VSCHEDULE_BLOCK_RE, "").replace(VTASK_BLOCK_RE, ""));
|
|
230416
230849
|
}
|
|
230417
230850
|
function snippetTitle(text2) {
|
|
230418
230851
|
const trimmed = text2.trim();
|
|
@@ -234355,91 +234788,6 @@ var AgentSessionManager = class {
|
|
|
234355
234788
|
// src/chat-session-manager.ts
|
|
234356
234789
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
234357
234790
|
|
|
234358
|
-
// src/trace-context.ts
|
|
234359
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
234360
|
-
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
234361
|
-
var VERSION8 = "00";
|
|
234362
|
-
var INVALID_VERSION = "ff";
|
|
234363
|
-
var ZERO_TRACE_ID = "0".repeat(32);
|
|
234364
|
-
var ZERO_SPAN_ID = "0".repeat(16);
|
|
234365
|
-
var HEX_2 = /^[0-9a-f]{2}$/;
|
|
234366
|
-
var HEX_16 = /^[0-9a-f]{16}$/;
|
|
234367
|
-
var HEX_32 = /^[0-9a-f]{32}$/;
|
|
234368
|
-
function parseTraceparent(value) {
|
|
234369
|
-
const raw = Array.isArray(value) ? value[0] : value;
|
|
234370
|
-
if (typeof raw !== "string") return null;
|
|
234371
|
-
const parts = raw.split("-");
|
|
234372
|
-
if (parts.length < 4) return null;
|
|
234373
|
-
const [version2, traceId, spanId, flags] = parts;
|
|
234374
|
-
if (!HEX_2.test(version2) || version2 === INVALID_VERSION) return null;
|
|
234375
|
-
if (version2 === VERSION8 && parts.length !== 4) return null;
|
|
234376
|
-
if (!HEX_32.test(traceId) || traceId === ZERO_TRACE_ID) return null;
|
|
234377
|
-
if (!HEX_16.test(spanId) || spanId === ZERO_SPAN_ID) return null;
|
|
234378
|
-
if (!HEX_2.test(flags)) return null;
|
|
234379
|
-
return { traceId, spanId, flags };
|
|
234380
|
-
}
|
|
234381
|
-
function formatTraceparent(ctx) {
|
|
234382
|
-
return `${VERSION8}-${ctx.traceId}-${ctx.spanId}-${ctx.sampled ? "01" : "00"}`;
|
|
234383
|
-
}
|
|
234384
|
-
function newTraceId() {
|
|
234385
|
-
return randomBytes3(16).toString("hex");
|
|
234386
|
-
}
|
|
234387
|
-
function newSpanId() {
|
|
234388
|
-
return randomBytes3(8).toString("hex");
|
|
234389
|
-
}
|
|
234390
|
-
function newTraceContext(incoming) {
|
|
234391
|
-
const parsed = parseTraceparent(incoming);
|
|
234392
|
-
if (parsed) {
|
|
234393
|
-
return {
|
|
234394
|
-
traceId: parsed.traceId,
|
|
234395
|
-
spanId: newSpanId(),
|
|
234396
|
-
parentSpanId: parsed.spanId,
|
|
234397
|
-
sampled: (parseInt(parsed.flags, 16) & 1) === 1,
|
|
234398
|
-
continued: true
|
|
234399
|
-
};
|
|
234400
|
-
}
|
|
234401
|
-
return {
|
|
234402
|
-
traceId: newTraceId(),
|
|
234403
|
-
spanId: newSpanId(),
|
|
234404
|
-
sampled: true,
|
|
234405
|
-
continued: false
|
|
234406
|
-
};
|
|
234407
|
-
}
|
|
234408
|
-
var storage = new AsyncLocalStorage();
|
|
234409
|
-
function runWithTraceContext(ctx, fn) {
|
|
234410
|
-
return storage.run(ctx, fn);
|
|
234411
|
-
}
|
|
234412
|
-
function getTraceContext() {
|
|
234413
|
-
return storage.getStore();
|
|
234414
|
-
}
|
|
234415
|
-
function outboundTraceparent() {
|
|
234416
|
-
const ctx = storage.getStore();
|
|
234417
|
-
return ctx ? formatTraceparent(ctx) : void 0;
|
|
234418
|
-
}
|
|
234419
|
-
|
|
234420
|
-
// src/utils/remote-proxy.ts
|
|
234421
|
-
function proxyStatus(result, fallback = 502) {
|
|
234422
|
-
return result.status > 0 ? result.status : fallback;
|
|
234423
|
-
}
|
|
234424
|
-
async function proxyToRemoteAuto(remoteServerId, method, apiPath, body, options) {
|
|
234425
|
-
const rcm = options?.reverseConnectManager;
|
|
234426
|
-
if (rcm && rcm.isConnected(remoteServerId)) {
|
|
234427
|
-
const traceparent = outboundTraceparent();
|
|
234428
|
-
const headers = {
|
|
234429
|
-
...traceparent ? { traceparent } : {},
|
|
234430
|
-
...options?.headers
|
|
234431
|
-
};
|
|
234432
|
-
return rcm.sendHttpRequest(remoteServerId, method, apiPath, body, options?.timeoutMs, headers);
|
|
234433
|
-
}
|
|
234434
|
-
return {
|
|
234435
|
-
ok: false,
|
|
234436
|
-
status: 0,
|
|
234437
|
-
data: { error: "Remote server is not connected" },
|
|
234438
|
-
errorCode: "network_error",
|
|
234439
|
-
requestId: options?.requestId
|
|
234440
|
-
};
|
|
234441
|
-
}
|
|
234442
|
-
|
|
234443
234791
|
// ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/wrapper.mjs
|
|
234444
234792
|
var import_stream3 = __toESM(require_stream(), 1);
|
|
234445
234793
|
var import_receiver = __toESM(require_receiver(), 1);
|
|
@@ -238405,6 +238753,7 @@ function createRemoteProjectSessionReader(options) {
|
|
|
238405
238753
|
}
|
|
238406
238754
|
};
|
|
238407
238755
|
}
|
|
238756
|
+
var applyTaskChangeDirectly = (_taskId, apply) => apply();
|
|
238408
238757
|
var emptySchema = external_exports.object({}).strict();
|
|
238409
238758
|
var selectorSchema = external_exports.string().min(1).max(MAX_TOOL_SELECTOR_ID);
|
|
238410
238759
|
var taskStatusSchema = external_exports.enum(["todo", "in_progress", "done", "cancelled"]);
|
|
@@ -238912,10 +239261,15 @@ async function createProjectChatTools(options) {
|
|
|
238912
239261
|
const current = await storage2.tasks.getById(taskId);
|
|
238913
239262
|
if (!current || current.project_id !== projectId) throw new Error("Task is no longer authorized");
|
|
238914
239263
|
await validateAssignedBranch(assignedBranch);
|
|
238915
|
-
const
|
|
239264
|
+
const storagePatch = {
|
|
238916
239265
|
...patch,
|
|
238917
239266
|
...assignedBranch !== void 0 ? { assigned_branch: assignedBranch } : {}
|
|
238918
|
-
}
|
|
239267
|
+
};
|
|
239268
|
+
const updated = await (options.applyTaskChange ?? applyTaskChangeDirectly)(
|
|
239269
|
+
taskId,
|
|
239270
|
+
() => storage2.tasks.update(taskId, storagePatch),
|
|
239271
|
+
revertTaskPatch(storage2, taskId, storagePatch)
|
|
239272
|
+
);
|
|
238919
239273
|
if (!updated) throw new Error("Task update failed");
|
|
238920
239274
|
await touch("task", taskId);
|
|
238921
239275
|
await finishOperation(operation, "completed", { taskId, title: updated.title });
|
|
@@ -240611,10 +240965,15 @@ var ProjectChatManager = class {
|
|
|
240611
240965
|
}
|
|
240612
240966
|
try {
|
|
240613
240967
|
const { assignedBranch, ...patch } = payload.patch;
|
|
240614
|
-
const
|
|
240968
|
+
const storagePatch = {
|
|
240615
240969
|
...patch,
|
|
240616
240970
|
...assignedBranch !== void 0 ? { assigned_branch: assignedBranch } : {}
|
|
240617
|
-
}
|
|
240971
|
+
};
|
|
240972
|
+
const updated = await (this.toolDependencies?.applyTaskChange ?? applyTaskChangeDirectly)(
|
|
240973
|
+
payload.taskId,
|
|
240974
|
+
() => this.storage.tasks.update(payload.taskId, storagePatch),
|
|
240975
|
+
revertTaskPatch(this.storage, payload.taskId, storagePatch)
|
|
240976
|
+
);
|
|
240618
240977
|
if (!updated) throw new Error("Task update failed");
|
|
240619
240978
|
} catch (error48) {
|
|
240620
240979
|
console.warn(`[ProjectChat] task update ${operation.id} remains retryable:`, boundedStreamError(error48).message);
|
|
@@ -244611,6 +244970,10 @@ var ReverseConnectManager = class {
|
|
|
244611
244970
|
this.cleanupConnection(remoteServerId, conn);
|
|
244612
244971
|
this.connections.delete(remoteServerId);
|
|
244613
244972
|
}
|
|
244973
|
+
/** Ids of every worker currently connected. */
|
|
244974
|
+
connectedServerIds() {
|
|
244975
|
+
return [...this.connections.keys()];
|
|
244976
|
+
}
|
|
244614
244977
|
isConnected(remoteServerId) {
|
|
244615
244978
|
const conn = this.connections.get(this.resolveId(remoteServerId));
|
|
244616
244979
|
return conn !== void 0 && conn.ws.readyState === 1;
|
|
@@ -247624,6 +247987,12 @@ var RemoteSessionReconciler = class {
|
|
|
247624
247987
|
// src/remote-liveness-reconcile.ts
|
|
247625
247988
|
var RemoteLivenessTracker = class {
|
|
247626
247989
|
byProject = /* @__PURE__ */ new Map();
|
|
247990
|
+
/**
|
|
247991
|
+
* Newest read id whose answer was acted on, per project — baseline or not. A
|
|
247992
|
+
* reconcile of a project the hub never served must still be ordered against
|
|
247993
|
+
* an overlapping one, without inventing a death baseline for it.
|
|
247994
|
+
*/
|
|
247995
|
+
answeredSeq = /* @__PURE__ */ new Map();
|
|
247627
247996
|
seqCounter = 0;
|
|
247628
247997
|
eventBus;
|
|
247629
247998
|
constructor(eventBus = null) {
|
|
@@ -247645,6 +248014,7 @@ var RemoteLivenessTracker = class {
|
|
|
247645
248014
|
const previous = this.byProject.get(projectId);
|
|
247646
248015
|
if (previous && seq < previous.seq) return [];
|
|
247647
248016
|
this.byProject.set(projectId, { remoteServerId, remotePath, sessions, seq });
|
|
248017
|
+
this.markAnswered(projectId, seq);
|
|
247648
248018
|
if (!previous) return [];
|
|
247649
248019
|
const live = new Set(sessions.map((session) => session.remoteSessionId));
|
|
247650
248020
|
const retired = previous.sessions.filter((session) => !live.has(session.remoteSessionId));
|
|
@@ -247676,6 +248046,45 @@ var RemoteLivenessTracker = class {
|
|
|
247676
248046
|
}).filter((session) => session !== null);
|
|
247677
248047
|
return this.accept(projectId, remoteServerId, remotePath, sessions, seq);
|
|
247678
248048
|
}
|
|
248049
|
+
/**
|
|
248050
|
+
* True when an answer claimed with `seq` has been overtaken by a newer
|
|
248051
|
+
* accepted one for this project — it must decide nothing, deaths or status.
|
|
248052
|
+
*/
|
|
248053
|
+
isOvertaken(projectId, seq) {
|
|
248054
|
+
const current = Math.max(this.byProject.get(projectId)?.seq ?? 0, this.answeredSeq.get(projectId) ?? 0);
|
|
248055
|
+
return seq < current;
|
|
248056
|
+
}
|
|
248057
|
+
/** Record that the answer read with `seq` was acted on, without touching the baseline. */
|
|
248058
|
+
markAnswered(projectId, seq) {
|
|
248059
|
+
if (seq > (this.answeredSeq.get(projectId) ?? 0)) this.answeredSeq.set(projectId, seq);
|
|
248060
|
+
}
|
|
248061
|
+
/** Whether a browser read has given this project a death baseline. */
|
|
248062
|
+
hasBaseline(projectId) {
|
|
248063
|
+
return this.byProject.has(projectId);
|
|
248064
|
+
}
|
|
248065
|
+
/**
|
|
248066
|
+
* Announce each session's current status as the worker reports it.
|
|
248067
|
+
*
|
|
248068
|
+
* The worker sends status changes only on each session's own stream, so a
|
|
248069
|
+
* turn that ended while the hub held no stream for it (a hub restart, a
|
|
248070
|
+
* tunnel outage) leaves every browser showing "running" forever. An
|
|
248071
|
+
* authoritative alive answer carries the status, so re-announcing it repairs
|
|
248072
|
+
* those rows. Deliberately independent of stream restoration: once status
|
|
248073
|
+
* moves to a project-level channel this stays as the post-reconnect repair,
|
|
248074
|
+
* while per-session streams only carry conversation content.
|
|
248075
|
+
*/
|
|
248076
|
+
announceStatuses(projectId, sessions) {
|
|
248077
|
+
for (const session of sessions) {
|
|
248078
|
+
if (!session.status) continue;
|
|
248079
|
+
this.eventBus?.emit({
|
|
248080
|
+
type: "session:status",
|
|
248081
|
+
projectId,
|
|
248082
|
+
branch: session.branch,
|
|
248083
|
+
sessionId: session.localSessionId,
|
|
248084
|
+
status: session.status
|
|
248085
|
+
});
|
|
248086
|
+
}
|
|
248087
|
+
}
|
|
247679
248088
|
entriesFor(remoteServerId) {
|
|
247680
248089
|
const rows = [];
|
|
247681
248090
|
for (const [projectId, tracked] of this.byProject) {
|
|
@@ -247694,40 +248103,58 @@ function parseAliveAnswer(data) {
|
|
|
247694
248103
|
if (!entry || typeof entry !== "object") continue;
|
|
247695
248104
|
const row = entry;
|
|
247696
248105
|
if (typeof row.id !== "string") continue;
|
|
247697
|
-
|
|
248106
|
+
const status = row.status === "running" || row.status === "stopped" || row.status === "error" ? row.status : null;
|
|
248107
|
+
rows.push({ id: row.id, branch: typeof row.branch === "string" ? row.branch : null, status });
|
|
247698
248108
|
}
|
|
247699
248109
|
return rows;
|
|
247700
248110
|
}
|
|
247701
248111
|
async function reconcileRemoteLiveness(remoteServerId, deps) {
|
|
247702
248112
|
const dead = [];
|
|
247703
|
-
const
|
|
248113
|
+
const answers = [];
|
|
248114
|
+
const targets = /* @__PURE__ */ new Map();
|
|
248115
|
+
for (const entry of deps.tracker.entriesFor(remoteServerId)) targets.set(entry.projectId, entry.remotePath);
|
|
248116
|
+
if (deps.listProjects) {
|
|
248117
|
+
try {
|
|
248118
|
+
for (const project of await deps.listProjects(remoteServerId)) {
|
|
248119
|
+
if (!targets.has(project.projectId)) targets.set(project.projectId, project.remotePath);
|
|
248120
|
+
}
|
|
248121
|
+
} catch (error48) {
|
|
248122
|
+
console.warn(`[RemoteLiveness] project listing failed for ${remoteServerId}:`, error48);
|
|
248123
|
+
}
|
|
248124
|
+
}
|
|
247704
248125
|
let projects = 0;
|
|
247705
|
-
for (const
|
|
247706
|
-
if (entry.sessions.length === 0) continue;
|
|
248126
|
+
for (const [projectId, remotePath] of targets) {
|
|
247707
248127
|
const seq = deps.tracker.nextReadSeq();
|
|
247708
248128
|
let result;
|
|
247709
248129
|
try {
|
|
247710
|
-
result = await deps.proxy(remoteServerId,
|
|
248130
|
+
result = await deps.proxy(remoteServerId, remotePath);
|
|
247711
248131
|
} catch (error48) {
|
|
247712
|
-
console.warn(`[RemoteLiveness] alive query failed for ${
|
|
248132
|
+
console.warn(`[RemoteLiveness] alive query failed for ${projectId}:`, error48);
|
|
247713
248133
|
continue;
|
|
247714
248134
|
}
|
|
247715
248135
|
if (!result.ok) continue;
|
|
247716
248136
|
const rows = parseAliveAnswer(result.data);
|
|
247717
248137
|
if (!rows) continue;
|
|
248138
|
+
if (deps.tracker.isOvertaken(projectId, seq)) continue;
|
|
247718
248139
|
projects += 1;
|
|
247719
|
-
|
|
247720
|
-
|
|
247721
|
-
|
|
247722
|
-
|
|
247723
|
-
|
|
247724
|
-
|
|
247725
|
-
))
|
|
248140
|
+
const sessions = rows.map((row) => ({
|
|
248141
|
+
localSessionId: `remote-${remoteServerId}-${projectId}-${row.id}`,
|
|
248142
|
+
remoteSessionId: row.id,
|
|
248143
|
+
branch: row.branch,
|
|
248144
|
+
status: row.status
|
|
248145
|
+
}));
|
|
248146
|
+
if (deps.tracker.hasBaseline(projectId)) {
|
|
248147
|
+
dead.push(...deps.tracker.acceptRemoteIds(projectId, remoteServerId, remotePath, rows, seq));
|
|
248148
|
+
} else {
|
|
248149
|
+
deps.tracker.markAnswered(projectId, seq);
|
|
248150
|
+
}
|
|
248151
|
+
deps.tracker.announceStatuses(projectId, sessions);
|
|
248152
|
+
answers.push({ projectId, sessions });
|
|
247726
248153
|
}
|
|
247727
248154
|
if (dead.length > 0) {
|
|
247728
248155
|
console.log(`[RemoteLiveness] ${remoteServerId}: ${dead.length} session(s) lost their process while unobserved`);
|
|
247729
248156
|
}
|
|
247730
|
-
return { projects, dead };
|
|
248157
|
+
return { projects, dead, answers };
|
|
247731
248158
|
}
|
|
247732
248159
|
|
|
247733
248160
|
// src/logger.ts
|
|
@@ -248540,12 +248967,8 @@ var sharedServices = async (fastify2, opts) => {
|
|
|
248540
248967
|
await agentSessionManager.restoreSessionsFromDb();
|
|
248541
248968
|
const remoteExecutorMap = /* @__PURE__ */ new Map();
|
|
248542
248969
|
const remoteSessionMap = /* @__PURE__ */ new Map();
|
|
248543
|
-
for (const row of await opts.storage.remoteSessionMappings.
|
|
248544
|
-
|
|
248545
|
-
row.project_id,
|
|
248546
|
-
row.remote_server_id
|
|
248547
|
-
);
|
|
248548
|
-
if (!remote) {
|
|
248970
|
+
for (const row of await opts.storage.remoteSessionMappings.getAllWithLinkState()) {
|
|
248971
|
+
if (!row.linked) {
|
|
248549
248972
|
console.warn(`[SharedServices] Skipping remote_session_mappings row ${row.local_session_id}: project_remotes(${row.project_id}, ${row.remote_server_id}) not found`);
|
|
248550
248973
|
continue;
|
|
248551
248974
|
}
|
|
@@ -248577,6 +249000,12 @@ var sharedServices = async (fastify2, opts) => {
|
|
|
248577
249000
|
}
|
|
248578
249001
|
}
|
|
248579
249002
|
const reverseConnectManager = new ReverseConnectManager();
|
|
249003
|
+
const retentionHolds = new RetentionHoldSync({
|
|
249004
|
+
storage: opts.storage,
|
|
249005
|
+
reverseConnectManager,
|
|
249006
|
+
remoteSessionMap,
|
|
249007
|
+
sources: [scheduleHoldSource(opts.storage), taskHoldSource(opts.storage)]
|
|
249008
|
+
});
|
|
248580
249009
|
const browserManager = new BrowserManager();
|
|
248581
249010
|
const remoteExecutorMonitor = new RemoteExecutorMonitor(reverseConnectManager, eventBus, opts.storage, remoteExecutorMap);
|
|
248582
249011
|
const scheduler = new SchedulerService(opts.storage, processManager, {
|
|
@@ -248610,6 +249039,7 @@ var sharedServices = async (fastify2, opts) => {
|
|
|
248610
249039
|
toolDependencies: {
|
|
248611
249040
|
agentSessionManager,
|
|
248612
249041
|
remoteSessions: projectChatRemoteSessions,
|
|
249042
|
+
applyTaskChange: (taskId, apply, revert) => applyTaskChange({ storage: opts.storage, retentionHolds }, taskId, apply, revert),
|
|
248613
249043
|
mutationServices: {
|
|
248614
249044
|
// Prepared-session lifecycle §10.3: one `start` under the operation's
|
|
248615
249045
|
// own idempotency key. A replay of the same operation returns the
|
|
@@ -248830,6 +249260,20 @@ var sharedServices = async (fastify2, opts) => {
|
|
|
248830
249260
|
fastify2.decorate("reverseConnectManager", reverseConnectManager);
|
|
248831
249261
|
fastify2.decorate("browserManager", browserManager);
|
|
248832
249262
|
fastify2.decorate("scheduler", scheduler);
|
|
249263
|
+
fastify2.decorate("retentionHolds", retentionHolds);
|
|
249264
|
+
subscribeTaskHoldSync(eventBus, retentionHolds);
|
|
249265
|
+
const releaseStaleHolds = (remoteServerId) => {
|
|
249266
|
+
void retentionHolds.releaseStale(remoteServerId).then((failed) => {
|
|
249267
|
+
if (failed > 0) console.warn(`[RetentionHolds] ${failed} session(s) on ${remoteServerId} not re-synced`);
|
|
249268
|
+
});
|
|
249269
|
+
};
|
|
249270
|
+
reverseConnectManager.setStatusChangeHandler((remoteServerId, status) => {
|
|
249271
|
+
if (status === "online") releaseStaleHolds(remoteServerId);
|
|
249272
|
+
});
|
|
249273
|
+
const retentionHoldTimer = setInterval(() => {
|
|
249274
|
+
for (const remoteServerId of reverseConnectManager.connectedServerIds()) releaseStaleHolds(remoteServerId);
|
|
249275
|
+
}, 60 * 60 * 1e3);
|
|
249276
|
+
retentionHoldTimer.unref();
|
|
248833
249277
|
agentSessionManager.setEventBus(eventBus);
|
|
248834
249278
|
void recoverPendingRemoteAgentSessions({
|
|
248835
249279
|
remoteSessionMap,
|
|
@@ -248950,6 +249394,7 @@ var sharedServices = async (fastify2, opts) => {
|
|
|
248950
249394
|
memoryStatsReporter.start();
|
|
248951
249395
|
fastify2.addHook("onClose", async () => {
|
|
248952
249396
|
memoryStatsReporter.close();
|
|
249397
|
+
clearInterval(retentionHoldTimer);
|
|
248953
249398
|
await sessionRetention.close();
|
|
248954
249399
|
await remoteSessionReconciler.close();
|
|
248955
249400
|
scheduler.shutdown();
|
|
@@ -255761,6 +256206,21 @@ var sessionInventoryRoutes = async (fastify2) => {
|
|
|
255761
256206
|
return reply.code(200).send({ sessionIds, complete: true });
|
|
255762
256207
|
}
|
|
255763
256208
|
);
|
|
256209
|
+
fastify2.get("/api/path/retention-holds", async (_req, reply) => {
|
|
256210
|
+
return reply.code(200).send({ sessionIds: await fastify2.storage.sessionRetentionHolds.listSessionIds() });
|
|
256211
|
+
});
|
|
256212
|
+
fastify2.put("/api/path/retention-holds/:sessionId", async (req, reply) => {
|
|
256213
|
+
const raw = req.body?.holds;
|
|
256214
|
+
const validPart = (v2) => typeof v2 === "string" && v2.length > 0 && v2.length <= 200;
|
|
256215
|
+
if (!Array.isArray(raw) || raw.length > 1e3 || !raw.every((h) => h && typeof h === "object" && validPart(h.kind) && validPart(h.id))) {
|
|
256216
|
+
return reply.code(400).send({ error: "holds must be an array of { kind, id }" });
|
|
256217
|
+
}
|
|
256218
|
+
const session = await fastify2.storage.agentSessions.getById(req.params.sessionId);
|
|
256219
|
+
if (!session) return reply.code(404).send({ error: "Session not found" });
|
|
256220
|
+
const holds = raw.map((h) => ({ kind: h.kind, id: h.id }));
|
|
256221
|
+
await fastify2.storage.sessionRetentionHolds.replace(req.params.sessionId, holds);
|
|
256222
|
+
return reply.code(204).send();
|
|
256223
|
+
});
|
|
255764
256224
|
};
|
|
255765
256225
|
var session_inventory_routes_default = sessionInventoryRoutes;
|
|
255766
256226
|
|
|
@@ -256666,7 +257126,46 @@ var project_activity_routes_default = (0, import_fastify_plugin18.default)(route
|
|
|
256666
257126
|
// src/routes/task-routes.ts
|
|
256667
257127
|
var import_fastify_plugin19 = __toESM(require_plugin2(), 1);
|
|
256668
257128
|
import { randomUUID as randomUUID22 } from "crypto";
|
|
257129
|
+
|
|
257130
|
+
// src/routes/source-sessions.ts
|
|
257131
|
+
var SOURCE_ID_MAX = 200;
|
|
257132
|
+
var validSourceId = (value) => typeof value === "string" && value.length > 0 && value.length <= SOURCE_ID_MAX && value.trim() === value;
|
|
257133
|
+
async function isProjectSourceSession(storage2, sessionId, projectId) {
|
|
257134
|
+
const sourceSession = await storage2.agentSessions.getById(sessionId);
|
|
257135
|
+
return sourceSession ? sourceSession.project_id === projectId : !!await storage2.remoteSessionMappings.getAuthorizedByLocal(sessionId, projectId);
|
|
257136
|
+
}
|
|
257137
|
+
async function resolveSourceSessions(storage2, ids) {
|
|
257138
|
+
const unique = [...new Set(ids)];
|
|
257139
|
+
const remoteIds = unique.filter((id) => id.startsWith("remote-"));
|
|
257140
|
+
const remoteTitles = await storage2.searchCache.getCachedSessionTitles(remoteIds);
|
|
257141
|
+
const branchOf2 = async (row) => {
|
|
257142
|
+
if (!row) return null;
|
|
257143
|
+
const registered = row.workspace_checkout_id ? await storage2.workspaceRegistry.getCheckoutById(row.workspace_checkout_id) : void 0;
|
|
257144
|
+
return (registered ? registered.workspace.branch : row.branch) || null;
|
|
257145
|
+
};
|
|
257146
|
+
const out = /* @__PURE__ */ new Map();
|
|
257147
|
+
await Promise.all(unique.map(async (id) => {
|
|
257148
|
+
if (id.startsWith("remote-")) {
|
|
257149
|
+
const mapping = await storage2.remoteSessionMappings.getByLocal(id);
|
|
257150
|
+
out.set(id, {
|
|
257151
|
+
id,
|
|
257152
|
+
exists: !!mapping,
|
|
257153
|
+
branch: await branchOf2(mapping),
|
|
257154
|
+
title: remoteTitles.get(id) ?? null
|
|
257155
|
+
});
|
|
257156
|
+
return;
|
|
257157
|
+
}
|
|
257158
|
+
const session = await storage2.agentSessions.getById(id);
|
|
257159
|
+
out.set(id, { id, exists: !!session, branch: await branchOf2(session), title: session?.title ?? null });
|
|
257160
|
+
}));
|
|
257161
|
+
return out;
|
|
257162
|
+
}
|
|
257163
|
+
|
|
257164
|
+
// src/routes/task-routes.ts
|
|
257165
|
+
var SOURCE_ITEM_INDEX_MAX = 100;
|
|
256669
257166
|
var routes18 = async (fastify2) => {
|
|
257167
|
+
const applyHoldingChange = (taskId, apply, revert) => applyTaskChange(fastify2, taskId, apply, revert);
|
|
257168
|
+
const holdFailed = (error48) => `Could not protect the source session from retention: ${error48 instanceof Error ? error48.message : String(error48)}`;
|
|
256670
257169
|
fastify2.get(
|
|
256671
257170
|
"/api/projects/:projectId/tasks",
|
|
256672
257171
|
async (req, reply) => {
|
|
@@ -256678,7 +257177,16 @@ var routes18 = async (fastify2) => {
|
|
|
256678
257177
|
}
|
|
256679
257178
|
const includeArchived = req.query.includeArchived === "true";
|
|
256680
257179
|
const tasks = await fastify2.storage.tasks.getByProjectId(req.params.projectId, { includeArchived });
|
|
256681
|
-
|
|
257180
|
+
const sources = await resolveSourceSessions(
|
|
257181
|
+
fastify2.storage,
|
|
257182
|
+
tasks.flatMap((t) => t.source_session_id ? [t.source_session_id] : [])
|
|
257183
|
+
);
|
|
257184
|
+
return reply.code(200).send({
|
|
257185
|
+
tasks: tasks.map((t) => ({
|
|
257186
|
+
...t,
|
|
257187
|
+
source_session: t.source_session_id ? sources.get(t.source_session_id) ?? null : null
|
|
257188
|
+
}))
|
|
257189
|
+
});
|
|
256682
257190
|
}
|
|
256683
257191
|
);
|
|
256684
257192
|
fastify2.get(
|
|
@@ -256702,10 +257210,23 @@ var routes18 = async (fastify2) => {
|
|
|
256702
257210
|
if (!project) {
|
|
256703
257211
|
return reply.code(404).send({ error: "Project not found" });
|
|
256704
257212
|
}
|
|
256705
|
-
const { title: providedTitle, description, status, priority
|
|
257213
|
+
const { title: providedTitle, description, status, priority } = req.body;
|
|
257214
|
+
let { assigned_branch } = req.body;
|
|
256706
257215
|
if (!description) {
|
|
256707
257216
|
return reply.code(400).send({ error: "description is required" });
|
|
256708
257217
|
}
|
|
257218
|
+
let source = null;
|
|
257219
|
+
if (req.body.source) {
|
|
257220
|
+
const { session_id, tool_use_id, item_index } = req.body.source;
|
|
257221
|
+
if (!validSourceId(session_id) || !validSourceId(tool_use_id) || typeof item_index !== "number" || !Number.isInteger(item_index) || item_index < 0 || item_index > SOURCE_ITEM_INDEX_MAX) {
|
|
257222
|
+
return reply.code(400).send({ error: "Invalid source" });
|
|
257223
|
+
}
|
|
257224
|
+
if (!await isProjectSourceSession(fastify2.storage, session_id, req.params.projectId)) {
|
|
257225
|
+
return reply.code(400).send({ error: "Invalid source" });
|
|
257226
|
+
}
|
|
257227
|
+
source = { session_id, tool_use_id, item_index };
|
|
257228
|
+
assigned_branch = null;
|
|
257229
|
+
}
|
|
256709
257230
|
let title = providedTitle;
|
|
256710
257231
|
if (!title) {
|
|
256711
257232
|
try {
|
|
@@ -256730,16 +257251,44 @@ Description: ${description}`,
|
|
|
256730
257251
|
}
|
|
256731
257252
|
}
|
|
256732
257253
|
const id = randomUUID22();
|
|
256733
|
-
const
|
|
257254
|
+
const insert = () => fastify2.storage.tasks.create({
|
|
256734
257255
|
id,
|
|
256735
257256
|
project_id: req.params.projectId,
|
|
256736
257257
|
title,
|
|
256737
257258
|
description,
|
|
256738
257259
|
status,
|
|
256739
257260
|
priority,
|
|
256740
|
-
assigned_branch
|
|
257261
|
+
assigned_branch,
|
|
257262
|
+
source
|
|
256741
257263
|
});
|
|
256742
|
-
|
|
257264
|
+
let task;
|
|
257265
|
+
if (source) {
|
|
257266
|
+
const sourceSessionId = source.session_id;
|
|
257267
|
+
try {
|
|
257268
|
+
task = await fastify2.retentionHolds.exclusive(sourceSessionId, async (syncNow) => {
|
|
257269
|
+
const row = await insert();
|
|
257270
|
+
try {
|
|
257271
|
+
await syncNow();
|
|
257272
|
+
return row;
|
|
257273
|
+
} catch (error48) {
|
|
257274
|
+
if (row.id === id) {
|
|
257275
|
+
await fastify2.storage.tasks.delete(row.id);
|
|
257276
|
+
await syncNow().catch(() => void 0);
|
|
257277
|
+
}
|
|
257278
|
+
throw error48;
|
|
257279
|
+
}
|
|
257280
|
+
});
|
|
257281
|
+
} catch (error48) {
|
|
257282
|
+
return reply.code(502).send({ error: holdFailed(error48) });
|
|
257283
|
+
}
|
|
257284
|
+
} else {
|
|
257285
|
+
task = await insert();
|
|
257286
|
+
}
|
|
257287
|
+
const created = task.id === id;
|
|
257288
|
+
if (created) {
|
|
257289
|
+
fastify2.eventBus.emit({ type: "task:created", projectId: req.params.projectId, task: { ...task } });
|
|
257290
|
+
}
|
|
257291
|
+
return reply.code(created ? 201 : 200).send({ task });
|
|
256743
257292
|
});
|
|
256744
257293
|
fastify2.put("/api/tasks/:id", async (req, reply) => {
|
|
256745
257294
|
const userId = requireUserFacingUserId(req, reply);
|
|
@@ -256752,14 +257301,25 @@ Description: ${description}`,
|
|
|
256752
257301
|
if (!project) {
|
|
256753
257302
|
return reply.code(404).send({ error: "Task not found" });
|
|
256754
257303
|
}
|
|
256755
|
-
const
|
|
257304
|
+
const patch = {
|
|
256756
257305
|
title: req.body.title,
|
|
256757
257306
|
description: req.body.description,
|
|
256758
257307
|
status: req.body.status,
|
|
256759
257308
|
priority: req.body.priority,
|
|
256760
257309
|
assigned_branch: req.body.assigned_branch,
|
|
256761
257310
|
position: req.body.position
|
|
256762
|
-
}
|
|
257311
|
+
};
|
|
257312
|
+
let task;
|
|
257313
|
+
try {
|
|
257314
|
+
task = await applyHoldingChange(
|
|
257315
|
+
req.params.id,
|
|
257316
|
+
() => fastify2.storage.tasks.update(req.params.id, patch),
|
|
257317
|
+
revertTaskPatch(fastify2.storage, req.params.id, patch)
|
|
257318
|
+
);
|
|
257319
|
+
} catch (error48) {
|
|
257320
|
+
return reply.code(502).send({ error: holdFailed(error48) });
|
|
257321
|
+
}
|
|
257322
|
+
if (task) fastify2.eventBus.emit({ type: "task:updated", projectId: existing.project_id, task: { ...task } });
|
|
256763
257323
|
return reply.code(200).send({ task });
|
|
256764
257324
|
});
|
|
256765
257325
|
fastify2.delete("/api/tasks/:id", async (req, reply) => {
|
|
@@ -256774,6 +257334,12 @@ Description: ${description}`,
|
|
|
256774
257334
|
return reply.code(404).send({ error: "Task not found" });
|
|
256775
257335
|
}
|
|
256776
257336
|
await fastify2.storage.tasks.delete(req.params.id);
|
|
257337
|
+
fastify2.eventBus.emit({ type: "task:deleted", projectId: existing.project_id, taskId: req.params.id });
|
|
257338
|
+
if (existing.source_session_id) {
|
|
257339
|
+
await fastify2.retentionHolds.sync(existing.source_session_id).catch((error48) => {
|
|
257340
|
+
console.warn(`[RetentionHolds] release for ${existing.source_session_id} deferred:`, error48);
|
|
257341
|
+
});
|
|
257342
|
+
}
|
|
256777
257343
|
return reply.code(200).send({ success: true });
|
|
256778
257344
|
});
|
|
256779
257345
|
fastify2.post("/api/tasks/:id/archive", async (req, reply) => {
|
|
@@ -256788,6 +257354,7 @@ Description: ${description}`,
|
|
|
256788
257354
|
return reply.code(404).send({ error: "Task not found" });
|
|
256789
257355
|
}
|
|
256790
257356
|
const task = await fastify2.storage.tasks.archive(req.params.id);
|
|
257357
|
+
if (task) fastify2.eventBus.emit({ type: "task:updated", projectId: existing.project_id, task: { ...task } });
|
|
256791
257358
|
return reply.code(200).send({ task });
|
|
256792
257359
|
});
|
|
256793
257360
|
fastify2.post("/api/tasks/:id/unarchive", async (req, reply) => {
|
|
@@ -256801,7 +257368,17 @@ Description: ${description}`,
|
|
|
256801
257368
|
if (!project) {
|
|
256802
257369
|
return reply.code(404).send({ error: "Task not found" });
|
|
256803
257370
|
}
|
|
256804
|
-
|
|
257371
|
+
let task;
|
|
257372
|
+
try {
|
|
257373
|
+
task = await applyHoldingChange(
|
|
257374
|
+
req.params.id,
|
|
257375
|
+
() => fastify2.storage.tasks.unarchive(req.params.id),
|
|
257376
|
+
() => fastify2.storage.tasks.archive(req.params.id)
|
|
257377
|
+
);
|
|
257378
|
+
} catch (error48) {
|
|
257379
|
+
return reply.code(502).send({ error: holdFailed(error48) });
|
|
257380
|
+
}
|
|
257381
|
+
if (task) fastify2.eventBus.emit({ type: "task:updated", projectId: existing.project_id, task: { ...task } });
|
|
256805
257382
|
return reply.code(200).send({ task });
|
|
256806
257383
|
});
|
|
256807
257384
|
fastify2.put("/api/projects/:projectId/tasks/reorder", async (req, reply) => {
|
|
@@ -259145,6 +259722,13 @@ function resolveRemoteReplayCursor(clientEpoch, cachedEpoch, afterEntryIndex) {
|
|
|
259145
259722
|
replayAfter: epochMatches ? afterEntryIndex ?? -1 : -1
|
|
259146
259723
|
};
|
|
259147
259724
|
}
|
|
259725
|
+
function restoreRunningRemoteStreams(answers, ensure) {
|
|
259726
|
+
for (const { sessions } of answers) {
|
|
259727
|
+
for (const session of sessions) {
|
|
259728
|
+
if (session.status === "running") ensure(session.localSessionId);
|
|
259729
|
+
}
|
|
259730
|
+
}
|
|
259731
|
+
}
|
|
259148
259732
|
var routes25 = async (fastify2) => {
|
|
259149
259733
|
fastify2.reverseConnectManager.setStatusChangeHandler((remoteServerId, status) => {
|
|
259150
259734
|
if (status !== "online") return;
|
|
@@ -259174,8 +259758,29 @@ var routes25 = async (fastify2) => {
|
|
|
259174
259758
|
`/api/path/agent-sessions/alive?path=${encodeURIComponent(remotePath)}`,
|
|
259175
259759
|
void 0,
|
|
259176
259760
|
{ reverseConnectManager: fastify2.reverseConnectManager }
|
|
259177
|
-
)
|
|
259178
|
-
|
|
259761
|
+
),
|
|
259762
|
+
// Same scope as the project `/alive` route: projects whose agent runs on
|
|
259763
|
+
// this worker. No user filter — this is server maintenance.
|
|
259764
|
+
listProjects: async (serverId) => {
|
|
259765
|
+
const projects = (await fastify2.storage.projects.getAll()).filter((project) => project.agent_mode === serverId);
|
|
259766
|
+
const rows = [];
|
|
259767
|
+
for (const project of projects) {
|
|
259768
|
+
const remote = await fastify2.storage.projectRemotes.getByProjectAndServer(project.id, serverId);
|
|
259769
|
+
if (remote) rows.push({ projectId: project.id, remotePath: remote.remote_path });
|
|
259770
|
+
}
|
|
259771
|
+
return rows;
|
|
259772
|
+
}
|
|
259773
|
+
}).then(({ answers }) => restoreRunningRemoteStreams(
|
|
259774
|
+
answers,
|
|
259775
|
+
(localSessionId) => ensureRemoteAgentStream(localSessionId, {
|
|
259776
|
+
remoteSessionMap: fastify2.remoteSessionMap,
|
|
259777
|
+
remotePatchCache: fastify2.remotePatchCache,
|
|
259778
|
+
reverseConnectManager: fastify2.reverseConnectManager,
|
|
259779
|
+
eventBus: fastify2.eventBus,
|
|
259780
|
+
agentSessionManager: fastify2.agentSessionManager,
|
|
259781
|
+
storage: fastify2.storage
|
|
259782
|
+
})
|
|
259783
|
+
)).catch((error48) => console.warn("[RemoteLiveness] reconcile failed:", error48));
|
|
259179
259784
|
});
|
|
259180
259785
|
fastify2.after(() => {
|
|
259181
259786
|
fastify2.get(
|
|
@@ -266734,6 +267339,11 @@ var TOOLS2 = [
|
|
|
266734
267339
|
name: PROPOSE_SCHEDULE_TOOL,
|
|
266735
267340
|
description: PROPOSE_SCHEDULE_DESCRIPTION,
|
|
266736
267341
|
inputSchema: PROPOSE_SCHEDULE_INPUT_SCHEMA
|
|
267342
|
+
},
|
|
267343
|
+
{
|
|
267344
|
+
name: PROPOSE_TASK_TOOL,
|
|
267345
|
+
description: PROPOSE_TASK_DESCRIPTION,
|
|
267346
|
+
inputSchema: PROPOSE_TASK_INPUT_SCHEMA
|
|
266737
267347
|
}
|
|
266738
267348
|
];
|
|
266739
267349
|
var textResult2 = (text2, isError = false) => ({
|
|
@@ -266756,6 +267366,10 @@ var routes33 = async (fastify2) => {
|
|
|
266756
267366
|
return payload;
|
|
266757
267367
|
};
|
|
266758
267368
|
const callTool = (toolName, args) => {
|
|
267369
|
+
if (toolName === PROPOSE_TASK_TOOL) {
|
|
267370
|
+
const parsed2 = parseProposeTaskArgs(args);
|
|
267371
|
+
return parsed2.ok ? textResult2(PROPOSE_TASK_ACK) : textResult2(parsed2.error, true);
|
|
267372
|
+
}
|
|
266759
267373
|
if (toolName !== PROPOSE_SCHEDULE_TOOL) return textResult2(`Unknown tool: ${toolName}`, true);
|
|
266760
267374
|
const parsed = parseProposeScheduleArgs(args);
|
|
266761
267375
|
if (!parsed.ok) return textResult2(parsed.error, true);
|
|
@@ -266808,8 +267422,6 @@ import { randomUUID as randomUUID29 } from "crypto";
|
|
|
266808
267422
|
import path20 from "path";
|
|
266809
267423
|
var RUN_TYPES = ["command", "prompt"];
|
|
266810
267424
|
var CWD_MODES = ["branch", "directory"];
|
|
266811
|
-
var SOURCE_ID_MAX = 200;
|
|
266812
|
-
var validSourceId = (value) => typeof value === "string" && value.length > 0 && value.length <= SOURCE_ID_MAX && value.trim() === value;
|
|
266813
267425
|
function validRequestId(value) {
|
|
266814
267426
|
return typeof value === "string" && value.length > 0 && value.length <= 200 && value.trim() === value;
|
|
266815
267427
|
}
|
|
@@ -266858,9 +267470,14 @@ var routes34 = async (fastify2) => {
|
|
|
266858
267470
|
if (!project) return reply.code(404).send({ error: "Project not found" });
|
|
266859
267471
|
const schedules = await fastify2.storage.scheduledTasks.getByProjectId(req.params.projectId);
|
|
266860
267472
|
const lastRuns = await fastify2.storage.scheduledTaskRuns.getLastByScheduleIds(schedules.map((s3) => s3.id));
|
|
267473
|
+
const sources = await resolveSourceSessions(
|
|
267474
|
+
fastify2.storage,
|
|
267475
|
+
schedules.flatMap((s3) => s3.source_session_id ? [s3.source_session_id] : [])
|
|
267476
|
+
);
|
|
266861
267477
|
return reply.code(200).send({
|
|
266862
267478
|
schedules: schedules.map((s3) => ({
|
|
266863
267479
|
...s3,
|
|
267480
|
+
source_session: s3.source_session_id ? sources.get(s3.source_session_id) ?? null : null,
|
|
266864
267481
|
last_run: lastRuns[s3.id] ?? null,
|
|
266865
267482
|
next_run_at: fastify2.scheduler.nextRunAt(s3.id),
|
|
266866
267483
|
running: fastify2.scheduler.isRunning(s3.id)
|
|
@@ -266899,19 +267516,16 @@ var routes34 = async (fastify2) => {
|
|
|
266899
267516
|
if (!validSourceId(b2.source.session_id) || !validSourceId(b2.source.tool_use_id)) {
|
|
266900
267517
|
return reply.code(400).send({ error: "Invalid source" });
|
|
266901
267518
|
}
|
|
266902
|
-
const
|
|
266903
|
-
const owned = sourceSession ? sourceSession.project_id === req.params.projectId : !!await fastify2.storage.remoteSessionMappings.getAuthorizedByLocal(
|
|
266904
|
-
b2.source.session_id,
|
|
266905
|
-
req.params.projectId
|
|
266906
|
-
);
|
|
267519
|
+
const owned = await isProjectSourceSession(fastify2.storage, b2.source.session_id, req.params.projectId);
|
|
266907
267520
|
if (!owned) return reply.code(400).send({ error: "Invalid source" });
|
|
266908
267521
|
source = { session_id: b2.source.session_id, tool_use_id: b2.source.tool_use_id };
|
|
266909
267522
|
}
|
|
266910
267523
|
const newId = randomUUID29();
|
|
266911
|
-
const
|
|
267524
|
+
const name25 = b2.name.trim();
|
|
267525
|
+
const insert = () => fastify2.storage.scheduledTasks.create({
|
|
266912
267526
|
id: newId,
|
|
266913
267527
|
project_id: req.params.projectId,
|
|
266914
|
-
name:
|
|
267528
|
+
name: name25,
|
|
266915
267529
|
cron_expr: resolved.cron_expr,
|
|
266916
267530
|
timezone: resolved.timezone,
|
|
266917
267531
|
run_type: resolved.run_type,
|
|
@@ -266925,8 +267539,31 @@ var routes34 = async (fastify2) => {
|
|
|
266925
267539
|
target,
|
|
266926
267540
|
source
|
|
266927
267541
|
});
|
|
266928
|
-
|
|
267542
|
+
let schedule;
|
|
267543
|
+
if (source) {
|
|
267544
|
+
try {
|
|
267545
|
+
schedule = await fastify2.retentionHolds.exclusive(source.session_id, async (syncNow) => {
|
|
267546
|
+
const row = await insert();
|
|
267547
|
+
try {
|
|
267548
|
+
await syncNow();
|
|
267549
|
+
return row;
|
|
267550
|
+
} catch (error49) {
|
|
267551
|
+
if (row.id === newId) {
|
|
267552
|
+
await fastify2.storage.scheduledTasks.delete(row.id);
|
|
267553
|
+
await syncNow().catch(() => void 0);
|
|
267554
|
+
}
|
|
267555
|
+
throw error49;
|
|
267556
|
+
}
|
|
267557
|
+
});
|
|
267558
|
+
} catch (error49) {
|
|
267559
|
+
const message = error49 instanceof Error ? error49.message : String(error49);
|
|
267560
|
+
return reply.code(502).send({ error: `Could not protect the source session from retention: ${message}` });
|
|
267561
|
+
}
|
|
267562
|
+
} else {
|
|
267563
|
+
schedule = await insert();
|
|
267564
|
+
}
|
|
266929
267565
|
const created = schedule.id === newId;
|
|
267566
|
+
await fastify2.scheduler.reschedule(schedule.id);
|
|
266930
267567
|
if (created) {
|
|
266931
267568
|
fastify2.eventBus.emit({
|
|
266932
267569
|
type: "schedule:changed",
|
|
@@ -267004,6 +267641,11 @@ var routes34 = async (fastify2) => {
|
|
|
267004
267641
|
scheduleId: req.params.id,
|
|
267005
267642
|
change: "deleted"
|
|
267006
267643
|
});
|
|
267644
|
+
if (existing.source_session_id) {
|
|
267645
|
+
await fastify2.retentionHolds.sync(existing.source_session_id).catch((error48) => {
|
|
267646
|
+
console.warn(`[RetentionHolds] release for ${existing.source_session_id} deferred:`, error48);
|
|
267647
|
+
});
|
|
267648
|
+
}
|
|
267007
267649
|
return reply.code(204).send();
|
|
267008
267650
|
}
|
|
267009
267651
|
);
|
|
@@ -268248,6 +268890,10 @@ var WORKER_CAPABILITIES = {
|
|
|
268248
268890
|
// NOTHING, so an old worker can never look like it deleted its sessions.
|
|
268249
268891
|
"http:PUT /api/settings/session-retention/apply": { since: "0.3.14", summary: "\u4E0B\u53D1\u4F1A\u8BDD\u4FDD\u7559\u5929\u6570" },
|
|
268250
268892
|
"http:GET /api/path/session-ids": { since: "0.3.14", summary: "\u4F1A\u8BDD id \u5168\u91CF\u6E05\u5355(\u5BF9\u8D26\u7528)" },
|
|
268893
|
+
// Hub-computed hold set (schedules proposed from the session) that keeps a
|
|
268894
|
+
// session out of the worker's own retention sweep — retention-holds.ts.
|
|
268895
|
+
"http:PUT /api/path/retention-holds/:param": { since: "0.3.45", summary: "\u4E0B\u53D1\u4F1A\u8BDD\u4FDD\u7559\u9501(\u9632\u4FDD\u7559\u671F\u6E05\u7406)" },
|
|
268896
|
+
"http:GET /api/path/retention-holds": { since: "0.3.45", summary: "\u5217\u51FA\u6301\u6709\u4FDD\u7559\u9501\u7684\u4F1A\u8BDD(\u91CA\u653E\u8FC7\u671F\u9501)" },
|
|
268251
268897
|
// --- Search / notifications / cross-remote ---
|
|
268252
268898
|
"http:GET /api/path/search-catalog": { since: "0.2.0", summary: "\u641C\u7D22\u76EE\u5F55\u5FEB\u7167" },
|
|
268253
268899
|
// Empirically probed: 0.2.15 → 404, 0.2.16 → 400 (route exists).
|