@sema-agent/core 1.362.0 → 1.364.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/subagent.d.ts +2 -0
- package/dist/agents/subagent.d.ts.map +1 -1
- package/dist/agents/subagent.js +77 -22
- package/dist/agents/subagent.js.map +1 -1
- package/dist/core/background-agent-store.d.ts +110 -0
- package/dist/core/background-agent-store.d.ts.map +1 -0
- package/dist/core/background-agent-store.js +0 -0
- package/dist/core/background-agent-store.js.map +1 -0
- package/dist/core/runner/prepare-task.d.ts.map +1 -1
- package/dist/core/runner/prepare-task.js +2 -1
- package/dist/core/runner/prepare-task.js.map +1 -1
- package/dist/core/task-registry.d.ts +44 -0
- package/dist/core/task-registry.d.ts.map +1 -1
- package/dist/core/task-registry.js +355 -4
- package/dist/core/task-registry.js.map +1 -1
- package/dist/core/types.d.ts +1 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/prompts/coordinator.d.ts +3 -2
- package/dist/prompts/coordinator.d.ts.map +1 -1
- package/dist/prompts/coordinator.js +6 -0
- package/dist/prompts/coordinator.js.map +1 -1
- package/dist/scenarios/full-body.d.ts +2 -0
- package/dist/scenarios/full-body.d.ts.map +1 -1
- package/dist/scenarios/full-body.js +1 -1
- package/dist/scenarios/full-body.js.map +1 -1
- package/dist/stores/file/background-agent-store.d.ts +49 -0
- package/dist/stores/file/background-agent-store.d.ts.map +1 -0
- package/dist/stores/file/background-agent-store.js +227 -0
- package/dist/stores/file/background-agent-store.js.map +1 -0
- package/dist/stores/file/fs-atomic.d.ts.map +1 -1
- package/dist/stores/file/fs-atomic.js +17 -1
- package/dist/stores/file/fs-atomic.js.map +1 -1
- package/dist/tools/task-list.d.ts +11 -1
- package/dist/tools/task-list.d.ts.map +1 -1
- package/dist/tools/task-list.js +108 -32
- package/dist/tools/task-list.js.map +1 -1
- package/package.json +1 -1
|
@@ -112,6 +112,7 @@ export interface SubagentToolOptions {
|
|
|
112
112
|
notify?: (n: import("../core/task-notification.js").TaskNotificationPayload, opts?: {
|
|
113
113
|
priority?: "now" | "next" | "later";
|
|
114
114
|
}) => void;
|
|
115
|
+
agentStore?: import("../core/background-agent-store.js").BackgroundAgentStore;
|
|
115
116
|
};
|
|
116
117
|
model?: ModelRef;
|
|
117
118
|
agents?: AgentDefinition[];
|
|
@@ -189,6 +190,7 @@ export declare const AGENT_TRANSCRIPT_TOOL_NAME = "AgentTranscript";
|
|
|
189
190
|
export interface AgentTranscriptToolOptions {
|
|
190
191
|
runner: Runner;
|
|
191
192
|
registry: import("../core/task-registry.js").TaskRegistry;
|
|
193
|
+
agentStore?: import("../core/background-agent-store.js").BackgroundAgentStore;
|
|
192
194
|
owner?: string;
|
|
193
195
|
scope?: string;
|
|
194
196
|
sessionId?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagent.d.ts","sourceRoot":"","sources":["../../src/agents/subagent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAa7F,OAAO,EAAU,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"subagent.d.ts","sourceRoot":"","sources":["../../src/agents/subagent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,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W,CAAC;IAGjD,aAAa,CAAC,EAAE,oBAAoB,CAAC;IAIrC,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,kBAAkB,EAAE,oBAAoB,KAAK,IAAI,CAAC;CAC3F;AAkBD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,mBAAmB,EAAE,WAAW,GAAG,SAAS,EAAE,KAAK,EAAE,OAAO,mBAAmB,EAAE,WAAW,GAAG,IAAI,CAOnJ;AAcD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,sBAAsB;;;;aAyVjE;AAGD,eAAO,MAAM,0BAA0B,oBAAoB,CAAC;AAK5D,MAAM,WAAW,0BAA0B;IAEzC,MAAM,EAAE,MAAM,CAAC;IAEf,QAAQ,EAAE,OAAO,0BAA0B,EAAE,YAAY,CAAC;IAK1D,UAAU,CAAC,EAAE,OAAO,mCAAmC,EAAE,oBAAoB,CAAC;IAE9E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAaD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,0BAA0B;;;aAwHzE"}
|
package/dist/agents/subagent.js
CHANGED
|
@@ -15,6 +15,7 @@ import { delimitUntrusted, inlineUntrusted } from "../core/untrusted-text.js";
|
|
|
15
15
|
import { uuidv7 } from "../internal/harness.js";
|
|
16
16
|
import { addWorktree } from "../core/git-worktree-env.js";
|
|
17
17
|
import { BG_AGENT_REAP_STOP_ERROR, normalizeAgentName } from "../core/task-registry.js";
|
|
18
|
+
import { canAccessAgentRecord } from "../core/background-agent-store.js";
|
|
18
19
|
import { extractErrorCode } from "../brain/errors.js";
|
|
19
20
|
import { ObserverDigestTap, ObserverPairing, createObserverReportToolSpec, markObserverTaskId, unmarkObserverTaskId, isObserverTaskId, observerFramingPrompt, observerSlug, resolveObserverDeclaration, OBSERVER_SENDMESSAGE_SENDER_REFUSAL, OBSERVER_SENDMESSAGE_TARGET_REFUSAL, } from "./observer.js";
|
|
20
21
|
import { SubagentStepRecorder, stepsFromMessages } from "./subagent-steps.js";
|
|
@@ -1392,7 +1393,7 @@ function makeSubagentTool(opts, depth, excluded, extraToolsBudget) {
|
|
|
1392
1393
|
limits: childLimits,
|
|
1393
1394
|
signal,
|
|
1394
1395
|
});
|
|
1395
|
-
const tryRetainChild = async (ledger, entryTtlMs, preMintedSessionId) => {
|
|
1396
|
+
const tryRetainChild = async (ledger, entryTtlMs, preMintedSessionId, durableProbe, releaseAnchor) => {
|
|
1396
1397
|
if (!ledger)
|
|
1397
1398
|
return undefined;
|
|
1398
1399
|
const childSessionId = preMintedSessionId ?? uuidv7();
|
|
@@ -1419,8 +1420,11 @@ function makeSubagentTool(opts, depth, excluded, extraToolsBudget) {
|
|
|
1419
1420
|
}
|
|
1420
1421
|
catch {
|
|
1421
1422
|
}
|
|
1423
|
+
if (durableProbe && (await durableProbe().catch(() => false)))
|
|
1424
|
+
return;
|
|
1422
1425
|
try {
|
|
1423
1426
|
await opts.runner.sessions.release(childSessionId);
|
|
1427
|
+
releaseAnchor?.();
|
|
1424
1428
|
}
|
|
1425
1429
|
catch {
|
|
1426
1430
|
}
|
|
@@ -1440,10 +1444,13 @@ function makeSubagentTool(opts, depth, excluded, extraToolsBudget) {
|
|
|
1440
1444
|
}
|
|
1441
1445
|
catch {
|
|
1442
1446
|
}
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
+
if (!(durableProbe && (await durableProbe().catch(() => false)))) {
|
|
1448
|
+
try {
|
|
1449
|
+
await opts.runner.sessions.release(childSessionId);
|
|
1450
|
+
releaseAnchor?.();
|
|
1451
|
+
}
|
|
1452
|
+
catch {
|
|
1453
|
+
}
|
|
1447
1454
|
}
|
|
1448
1455
|
entry = undefined;
|
|
1449
1456
|
}
|
|
@@ -1571,6 +1578,7 @@ function makeSubagentTool(opts, depth, excluded, extraToolsBudget) {
|
|
|
1571
1578
|
...(ctx.sessionId !== undefined ? { parentSessionId: ctx.sessionId } : {}),
|
|
1572
1579
|
deliveryChannel: "attaching",
|
|
1573
1580
|
toolUseId: ctx.toolCallId,
|
|
1581
|
+
...(bg.agentStore !== undefined ? { store: bg.agentStore } : {}),
|
|
1574
1582
|
abort,
|
|
1575
1583
|
});
|
|
1576
1584
|
}
|
|
@@ -1584,6 +1592,7 @@ function makeSubagentTool(opts, depth, excluded, extraToolsBudget) {
|
|
|
1584
1592
|
const wt = await finishWorktree();
|
|
1585
1593
|
return { isError: true, content: `Sub-agent not started in background: ${e instanceof Error ? e.message : String(e)}${wt ? `\n${wt}` : ""}`, details: { error: "register_failed" } };
|
|
1586
1594
|
}
|
|
1595
|
+
bg.registry.bindBackgroundAgentSession(taskId, forkedId);
|
|
1587
1596
|
if (agentName !== undefined) {
|
|
1588
1597
|
recordRosterSpawn(ctx.roster, { name: agentName, agentId: taskId, sessionId: forkedId, toolUseId: ctx.toolCallId, ...(bgOwner !== undefined ? { owner: bgOwner } : {}), ...(bgScope !== undefined ? { scope: bgScope } : {}), ...(sessionScopedBg ? { sessionScoped: true } : {}), createdAt: Date.now() });
|
|
1589
1598
|
}
|
|
@@ -1867,6 +1876,7 @@ task_id: ${taskId}
|
|
|
1867
1876
|
...(ctx.sessionId !== undefined ? { parentSessionId: ctx.sessionId } : {}),
|
|
1868
1877
|
deliveryChannel: "attaching",
|
|
1869
1878
|
toolUseId: ctx.toolCallId,
|
|
1879
|
+
...(bg.agentStore !== undefined ? { store: bg.agentStore } : {}),
|
|
1870
1880
|
abort,
|
|
1871
1881
|
});
|
|
1872
1882
|
}
|
|
@@ -1890,6 +1900,9 @@ task_id: ${taskId}
|
|
|
1890
1900
|
const bgChildSessionId = uuidv7();
|
|
1891
1901
|
const bgStartedAt = Date.now();
|
|
1892
1902
|
stepRecorder.lockTo(bgChildSessionId);
|
|
1903
|
+
bg.registry.bindBackgroundAgentSession(taskId, bgChildSessionId);
|
|
1904
|
+
const bgDurableProbe = bg.registry.durableAgentRowProbe(taskId);
|
|
1905
|
+
const bgRowConfirmed = async () => (bgDurableProbe ? await bgDurableProbe().catch(() => false) : false);
|
|
1893
1906
|
sinkEmit({
|
|
1894
1907
|
kind: "spawn",
|
|
1895
1908
|
taskId,
|
|
@@ -1910,7 +1923,7 @@ task_id: ${taskId}
|
|
|
1910
1923
|
: ctx.subagentRetain;
|
|
1911
1924
|
if (sessionScopedBg && bgRetainLedger)
|
|
1912
1925
|
ensureSessionReapHook(bg.registry);
|
|
1913
|
-
const bgRetain = await tryRetainChild(bgRetainLedger, sessionScopedBg && ctx.subagentRetain ? ctx.subagentRetain.ttlMs : undefined, bgChildSessionId);
|
|
1926
|
+
const bgRetain = await tryRetainChild(bgRetainLedger, sessionScopedBg && ctx.subagentRetain ? ctx.subagentRetain.ttlMs : undefined, bgChildSessionId, bgDurableProbe, () => bg.registry.releaseDurableTranscriptAnchor(taskId));
|
|
1914
1927
|
if (bgRetain) {
|
|
1915
1928
|
bg.registry.markRetainedContinuation(taskId);
|
|
1916
1929
|
const origRelease = bgRetain.release;
|
|
@@ -1990,13 +2003,6 @@ task_id: ${taskId}
|
|
|
1990
2003
|
else
|
|
1991
2004
|
bgRetainLedger?.markSettled(ctx.toolCallId);
|
|
1992
2005
|
}
|
|
1993
|
-
else {
|
|
1994
|
-
try {
|
|
1995
|
-
await opts.runner.sessions.release(child.sessionId);
|
|
1996
|
-
}
|
|
1997
|
-
catch {
|
|
1998
|
-
}
|
|
1999
|
-
}
|
|
2000
2006
|
const ok = child.status === "completed";
|
|
2001
2007
|
const reaped = !ok && abort.signal.aborted;
|
|
2002
2008
|
const settled = bg.registry.settleBackgroundAgent(taskId, {
|
|
@@ -2005,6 +2011,14 @@ task_id: ${taskId}
|
|
|
2005
2011
|
...(!ok ? { error: reaped ? BG_AGENT_REAP_STOP_ERROR : child.errorMessage ?? String(child.status) } : {}),
|
|
2006
2012
|
}) ??
|
|
2007
2013
|
(abort.signal.aborted ? "killed" : ok ? "completed" : "failed");
|
|
2014
|
+
if (!bgRetain && !(await bgRowConfirmed())) {
|
|
2015
|
+
try {
|
|
2016
|
+
await opts.runner.sessions.release(child.sessionId);
|
|
2017
|
+
bg.registry.releaseDurableTranscriptAnchor(taskId);
|
|
2018
|
+
}
|
|
2019
|
+
catch {
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2008
2022
|
const stoppedBy = settled === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
|
|
2009
2023
|
const observerNote = observerNoteFor(await startBoundedObserverDrain());
|
|
2010
2024
|
const residual = residualFields();
|
|
@@ -2069,15 +2083,16 @@ task_id: ${taskId}
|
|
|
2069
2083
|
else
|
|
2070
2084
|
bgRetainLedger?.markSettled(ctx.toolCallId);
|
|
2071
2085
|
}
|
|
2072
|
-
|
|
2086
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
2087
|
+
const settled = bg.registry.settleBackgroundAgent(taskId, { status: killed ? "killed" : "failed", error: msg }) ?? (killed ? "killed" : "failed");
|
|
2088
|
+
if (!bgRetain && !(await bgRowConfirmed())) {
|
|
2073
2089
|
try {
|
|
2074
2090
|
await opts.runner.sessions.release(bgChildSessionId);
|
|
2091
|
+
bg.registry.releaseDurableTranscriptAnchor(taskId);
|
|
2075
2092
|
}
|
|
2076
2093
|
catch {
|
|
2077
2094
|
}
|
|
2078
2095
|
}
|
|
2079
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
2080
|
-
const settled = bg.registry.settleBackgroundAgent(taskId, { status: killed ? "killed" : "failed", error: msg }) ?? (killed ? "killed" : "failed");
|
|
2081
2096
|
const stoppedBy = settled === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
|
|
2082
2097
|
const observerNote = observerNoteFor(await startBoundedObserverDrain());
|
|
2083
2098
|
sinkEmit({
|
|
@@ -2342,7 +2357,7 @@ export function createSendMessageTool(opts) {
|
|
|
2342
2357
|
const access = {
|
|
2343
2358
|
owner: ctx.taskId ?? opts.owner,
|
|
2344
2359
|
scope: ctx.principal ?? opts.scope,
|
|
2345
|
-
...(opts.sessionId !== undefined ? { sessionId: opts.sessionId } : {}),
|
|
2360
|
+
...((ctx.sessionId ?? opts.sessionId) !== undefined ? { sessionId: ctx.sessionId ?? opts.sessionId } : {}),
|
|
2346
2361
|
};
|
|
2347
2362
|
let idRow = opts.registry.getAccessibleTask(to, access);
|
|
2348
2363
|
let resolvedAccess = access;
|
|
@@ -2385,7 +2400,7 @@ export function createSendMessageTool(opts) {
|
|
|
2385
2400
|
return {
|
|
2386
2401
|
content: `Message not sent: "${to}" is on the durable roster (agent ${rosterHit.agentId}) but not reachable in this run — its session belongs to an earlier process. ` +
|
|
2387
2402
|
`Launch a new agent with the needed context instead.`,
|
|
2388
|
-
details: { error: "roster_only", to, agentId: rosterHit.agentId
|
|
2403
|
+
details: { error: "roster_only", to, agentId: rosterHit.agentId },
|
|
2389
2404
|
};
|
|
2390
2405
|
}
|
|
2391
2406
|
const labels = opts.registry.runningBackgroundAgentLabels(access);
|
|
@@ -2446,7 +2461,8 @@ export function createSendMessageTool(opts) {
|
|
|
2446
2461
|
};
|
|
2447
2462
|
}
|
|
2448
2463
|
const runLedger = ctx.subagentRetain ?? opts.retain;
|
|
2449
|
-
const
|
|
2464
|
+
const smLedgerSessionId = ctx.sessionId ?? opts.sessionId;
|
|
2465
|
+
const sessionLedger = smLedgerSessionId !== undefined ? getSessionRetainLedger(smLedgerSessionId) : undefined;
|
|
2450
2466
|
const knows = (l) => l !== undefined && row.toolUseId !== undefined && (l.get(row.toolUseId) !== undefined || l.wasEvicted(row.toolUseId));
|
|
2451
2467
|
const siblingLedger = opts.siblingRetain;
|
|
2452
2468
|
const ledger = (knows(sessionLedger) ? sessionLedger : undefined) ?? (knows(runLedger) ? runLedger : undefined) ?? (knows(siblingLedger) ? siblingLedger : undefined) ?? runLedger ?? sessionLedger ?? siblingLedger;
|
|
@@ -2531,9 +2547,41 @@ export function createAgentTranscriptTool(opts) {
|
|
|
2531
2547
|
const access = {
|
|
2532
2548
|
owner: ctx.taskId ?? opts.owner,
|
|
2533
2549
|
scope: ctx.principal ?? opts.scope,
|
|
2534
|
-
...(opts.sessionId !== undefined ? { sessionId: opts.sessionId } : {}),
|
|
2550
|
+
...((ctx.sessionId ?? opts.sessionId) !== undefined ? { sessionId: ctx.sessionId ?? opts.sessionId } : {}),
|
|
2551
|
+
};
|
|
2552
|
+
const readDurableSteps = async () => {
|
|
2553
|
+
if (!opts.agentStore || access.scope === undefined)
|
|
2554
|
+
return undefined;
|
|
2555
|
+
let durableRow;
|
|
2556
|
+
try {
|
|
2557
|
+
durableRow = await opts.agentStore.get(id, access.scope);
|
|
2558
|
+
}
|
|
2559
|
+
catch {
|
|
2560
|
+
return undefined;
|
|
2561
|
+
}
|
|
2562
|
+
if (!durableRow || !canAccessAgentRecord(durableRow, access) || durableRow.sessionId === undefined)
|
|
2563
|
+
return undefined;
|
|
2564
|
+
try {
|
|
2565
|
+
const acquired = await opts.runner.sessions.acquire(durableRow.sessionId, { requireExisting: true });
|
|
2566
|
+
const branch = await acquired.session.getBranch();
|
|
2567
|
+
const messages = branch.filter((e) => e.type === "message").map((e) => e.message);
|
|
2568
|
+
const steps = stepsFromMessages(messages, lastN);
|
|
2569
|
+
if (steps.length === 0) {
|
|
2570
|
+
return { content: `Agent ${id} recorded no tool steps.`, details: { type: "agent-transcript", id, steps: [] } };
|
|
2571
|
+
}
|
|
2572
|
+
const body = steps
|
|
2573
|
+
.map((s) => `- ${inlineUntrusted(`${s.tool}${s.target ? ` ${s.target}` : ""}${s.outcome ? ` → ${s.outcome}` : ""}`, REPORT_FIELD_MAX)}`)
|
|
2574
|
+
.join("\n");
|
|
2575
|
+
return {
|
|
2576
|
+
content: `Agent ${id} — last ${steps.length} tool step(s) (from its preserved transcript):\n${body}`,
|
|
2577
|
+
details: { type: "agent-transcript", id, steps },
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
catch {
|
|
2581
|
+
return undefined;
|
|
2582
|
+
}
|
|
2535
2583
|
};
|
|
2536
|
-
const row = opts.registry.
|
|
2584
|
+
const row = opts.registry.getAccessibleTask(id, access);
|
|
2537
2585
|
if (!row || row.type !== "background_agent") {
|
|
2538
2586
|
if (/^w[0-9a-f]{16}$/.test(id) || (row !== undefined && row.type === "workflow")) {
|
|
2539
2587
|
return {
|
|
@@ -2541,12 +2589,19 @@ export function createAgentTranscriptTool(opts) {
|
|
|
2541
2589
|
details: { error: "workflow_id", id },
|
|
2542
2590
|
};
|
|
2543
2591
|
}
|
|
2592
|
+
const durable = await readDurableSteps();
|
|
2593
|
+
if (durable)
|
|
2594
|
+
return durable;
|
|
2544
2595
|
return { content: `No transcript: no background agent task "${id}" (unknown id, not yours, or expired).`, details: { error: "not_found", id } };
|
|
2545
2596
|
}
|
|
2546
2597
|
const runLedger = ctx.subagentRetain ?? undefined;
|
|
2547
|
-
const
|
|
2598
|
+
const atLedgerSessionId = ctx.sessionId ?? opts.sessionId;
|
|
2599
|
+
const sessionLedger = atLedgerSessionId !== undefined ? getSessionRetainLedger(atLedgerSessionId) : undefined;
|
|
2548
2600
|
const entry = row.toolUseId !== undefined ? (sessionLedger?.get(row.toolUseId) ?? runLedger?.get(row.toolUseId)) : undefined;
|
|
2549
2601
|
if (!entry) {
|
|
2602
|
+
const durable = await readDurableSteps();
|
|
2603
|
+
if (durable)
|
|
2604
|
+
return durable;
|
|
2550
2605
|
return {
|
|
2551
2606
|
content: `No transcript: agent ${id}'s session was not retained (this run did not enable retainSubagentSessions), so its history is unavailable. Its completion notification carried the recent steps.`,
|
|
2552
2607
|
details: { error: "not_retained", id },
|