@sema-agent/core 1.286.1 → 1.288.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 +18 -0
- package/dist/agents/subagent.d.ts.map +1 -1
- package/dist/agents/subagent.js +98 -7
- package/dist/agents/subagent.js.map +1 -1
- package/dist/core/auto-compaction.d.ts +5 -0
- package/dist/core/auto-compaction.d.ts.map +1 -1
- package/dist/core/auto-compaction.js +19 -2
- package/dist/core/auto-compaction.js.map +1 -1
- package/dist/core/file-snapshot-store.d.ts +1 -0
- package/dist/core/file-snapshot-store.d.ts.map +1 -1
- package/dist/core/file-snapshot-store.js +8 -2
- package/dist/core/file-snapshot-store.js.map +1 -1
- package/dist/core/runner/prepare-task.d.ts.map +1 -1
- package/dist/core/runner/prepare-task.js +4 -1
- package/dist/core/runner/prepare-task.js.map +1 -1
- package/dist/core/runner/runtask.d.ts.map +1 -1
- package/dist/core/runner/runtask.js +67 -8
- package/dist/core/runner/runtask.js.map +1 -1
- package/dist/core/runner/synthetic-tools.d.ts +11 -0
- package/dist/core/runner/synthetic-tools.d.ts.map +1 -1
- package/dist/core/runner/synthetic-tools.js +44 -0
- package/dist/core/runner/synthetic-tools.js.map +1 -1
- package/dist/core/trace.d.ts +17 -0
- package/dist/core/trace.d.ts.map +1 -1
- package/dist/core/trace.js.map +1 -1
- package/dist/core/types.d.ts +1 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/engine/compaction/compaction.d.ts +2 -2
- package/dist/engine/compaction/compaction.d.ts.map +1 -1
- package/dist/engine/compaction/compaction.js +13 -6
- package/dist/engine/compaction/compaction.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/orchestration/workflow.d.ts.map +1 -1
- package/dist/orchestration/workflow.js +3 -0
- package/dist/orchestration/workflow.js.map +1 -1
- package/dist/tools/fs/index.d.ts.map +1 -1
- package/dist/tools/fs/index.js +14 -4
- package/dist/tools/fs/index.js.map +1 -1
- package/dist/tools/fs/search.d.ts.map +1 -1
- package/dist/tools/fs/search.js +3 -2
- package/dist/tools/fs/search.js.map +1 -1
- package/package.json +1 -1
|
@@ -8,6 +8,9 @@ export type { SubagentStep, SubagentEditedFile } from "./subagent-steps.js";
|
|
|
8
8
|
export declare function inheritedManifestScopeFor(snapshot: readonly unknown[] | undefined): RunInternals["inheritedManifestScope"];
|
|
9
9
|
export declare const DEFAULT_SUBAGENT_TOOL_NAME = "Agent";
|
|
10
10
|
export declare const LEGACY_SUBAGENT_TOOL_NAME = "Task";
|
|
11
|
+
export declare const EXTRA_TOOLS_MAX_FACTORY_CALLS_PER_TREE = 64;
|
|
12
|
+
export declare const EXTRA_TOOLS_FAILED_NOTE = "note: extraTools evaluation failed \u2014 the injected tool set was skipped for this spawn.";
|
|
13
|
+
export declare const EXTRA_TOOLS_BUDGET_NOTE = "note: extraTools evaluation was skipped \u2014 this spawn tree exhausted its factory-call budget (64); no dynamic tools were injected for this spawn.";
|
|
11
14
|
export interface SubagentToolStats {
|
|
12
15
|
readCount: number;
|
|
13
16
|
searchCount: number;
|
|
@@ -18,6 +21,7 @@ export interface SubagentToolStats {
|
|
|
18
21
|
otherToolCount: number;
|
|
19
22
|
}
|
|
20
23
|
export declare const FORK_SUBAGENT_TYPE = "fork";
|
|
24
|
+
export declare const GENERAL_PURPOSE_SUBAGENT_TYPE = "general-purpose";
|
|
21
25
|
export declare const FORK_DEFAULT_MAX_TURNS = 200;
|
|
22
26
|
export declare function forkGovernanceDenial(enableFork: boolean | undefined, allowFork: boolean | undefined): "task" | "principal" | undefined;
|
|
23
27
|
export interface SubagentWorktreeIsolation {
|
|
@@ -127,6 +131,20 @@ export interface SubagentToolOptions {
|
|
|
127
131
|
observedAgent?: string;
|
|
128
132
|
observerAgent?: string;
|
|
129
133
|
}) => void;
|
|
134
|
+
extraTools?: (ctx: SubagentSpawnContext) => ToolSpec[] | Promise<ToolSpec[]>;
|
|
135
|
+
onExtraToolsError?: (err: unknown, info: {
|
|
136
|
+
toolCallId: string;
|
|
137
|
+
agentType?: string;
|
|
138
|
+
depth: number;
|
|
139
|
+
}) => void;
|
|
140
|
+
}
|
|
141
|
+
export interface SubagentSpawnContext {
|
|
142
|
+
toolCallId: string;
|
|
143
|
+
parentTaskId?: string;
|
|
144
|
+
parentSessionId?: string;
|
|
145
|
+
principal?: string;
|
|
146
|
+
agentType?: string;
|
|
147
|
+
depth: number;
|
|
130
148
|
}
|
|
131
149
|
export declare const SUBAGENT_SYSTEM_NOTE: string;
|
|
132
150
|
export declare const FORK_DIRECTIVE_FRAME = "<fork-boilerplate>\nYou are a worker fork. The transcript above is the parent's history \u2014 inherited reference, not your situation. You are NOT a continuation of that agent. Execute ONE directive, then stop.\n\nHard rules:\n- Do NOT spawn subagents with the Agent tool. The \"default to forking\" guidance is for the parent; you ARE the fork, execute directly.\n- One shot: report once and stop. No follow-up questions, no proposed next steps, no waiting for the user.\n\nGuidelines (your directive may override any of these):\n- Stay in scope. Other forks may be handling adjacent work; if you spot something outside your directive, note it in a sentence and move on.\n- Open with one line restating your task, so the parent can spot scope drift at a glance.\n- Be concise \u2014 as short as the answer allows, no shorter. Plain text, no preamble, no meta-commentary.\n- If you committed changes, list the paths and commit hashes in your report.\n</fork-boilerplate>\n\nYour directive: ";
|
|
@@ -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;AAC/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;
|
|
1
|
+
{"version":3,"file":"subagent.d.ts","sourceRoot":"","sources":["../../src/ag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IAEf,QAAQ,EAAE,OAAO,0BAA0B,EAAE,YAAY,CAAC;IAE1D,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;;;aAmEzE"}
|
package/dist/agents/subagent.js
CHANGED
|
@@ -5,6 +5,7 @@ import { defineTool } from "../core/tools.js";
|
|
|
5
5
|
import { TOOL_SEARCH_NAME } from "../core/runner/tool-disclosure.js";
|
|
6
6
|
import { OFFLOAD_TOOL_NAME } from "../core/tool-result-store.js";
|
|
7
7
|
import { resolveToolSubset, toolNameAllowed } from "./tool-filter.js";
|
|
8
|
+
import { canonicalToolName } from "../core/tool-name-aliases.js";
|
|
8
9
|
import { builtinAgentDefinitions } from "./builtin-agents.js";
|
|
9
10
|
import { SUBAGENT_PROMPT } from "../prompts/default.js";
|
|
10
11
|
import { hasSessionFork } from "../core/session.js";
|
|
@@ -40,6 +41,9 @@ export function inheritedManifestScopeFor(snapshot) {
|
|
|
40
41
|
}
|
|
41
42
|
export const DEFAULT_SUBAGENT_TOOL_NAME = "Agent";
|
|
42
43
|
export const LEGACY_SUBAGENT_TOOL_NAME = "Task";
|
|
44
|
+
export const EXTRA_TOOLS_MAX_FACTORY_CALLS_PER_TREE = 64;
|
|
45
|
+
export const EXTRA_TOOLS_FAILED_NOTE = "note: extraTools evaluation failed — the injected tool set was skipped for this spawn.";
|
|
46
|
+
export const EXTRA_TOOLS_BUDGET_NOTE = `note: extraTools evaluation was skipped — this spawn tree exhausted its factory-call budget (${EXTRA_TOOLS_MAX_FACTORY_CALLS_PER_TREE}); no dynamic tools were injected for this spawn.`;
|
|
43
47
|
function countArgLines(v) {
|
|
44
48
|
return typeof v === "string" && v.length > 0 ? v.split("\n").length : 0;
|
|
45
49
|
}
|
|
@@ -104,6 +108,7 @@ function makeToolStatsCounter(delegationToolName) {
|
|
|
104
108
|
};
|
|
105
109
|
}
|
|
106
110
|
export const FORK_SUBAGENT_TYPE = "fork";
|
|
111
|
+
export const GENERAL_PURPOSE_SUBAGENT_TYPE = "general-purpose";
|
|
107
112
|
export const FORK_DEFAULT_MAX_TURNS = 200;
|
|
108
113
|
export function forkGovernanceDenial(enableFork, allowFork) {
|
|
109
114
|
if (enableFork === false)
|
|
@@ -590,6 +595,16 @@ function adaptLegacyForkArgs(args) {
|
|
|
590
595
|
}
|
|
591
596
|
return args;
|
|
592
597
|
}
|
|
598
|
+
function foldGeneralPurposeAlias(args, shadowed) {
|
|
599
|
+
if (shadowed)
|
|
600
|
+
return args;
|
|
601
|
+
const raw = args;
|
|
602
|
+
if (raw !== null && typeof raw === "object" && raw.subagent_type === GENERAL_PURPOSE_SUBAGENT_TYPE) {
|
|
603
|
+
const { subagent_type: _dropped, ...rest } = raw;
|
|
604
|
+
return rest;
|
|
605
|
+
}
|
|
606
|
+
return args;
|
|
607
|
+
}
|
|
593
608
|
export const SUBAGENT_SYSTEM_NOTE = "You can delegate a self-contained subtask to an isolated sub-agent via the delegation tool. " +
|
|
594
609
|
"The sub-agent runs in a clean context and returns a single report. Delegate slow, parallelizable, " +
|
|
595
610
|
"or well-scoped work; do the rest yourself. If you delegate several at once, make each one FULLY " +
|
|
@@ -662,7 +677,7 @@ export function agentWhenToUseText(def, lean = true) {
|
|
|
662
677
|
const leanText = lean ? def.whenToUseLean : undefined;
|
|
663
678
|
return (leanText || def.whenToUse) || undefined;
|
|
664
679
|
}
|
|
665
|
-
function makeSubagentTool(opts, depth, excluded) {
|
|
680
|
+
function makeSubagentTool(opts, depth, excluded, extraToolsBudget) {
|
|
666
681
|
const maxDepth = opts.maxDepth ?? 5;
|
|
667
682
|
const toolName = opts.name ?? DEFAULT_SUBAGENT_TOOL_NAME;
|
|
668
683
|
const deploymentNames = new Set((opts.agents ?? []).map((a) => a.name));
|
|
@@ -678,6 +693,7 @@ function makeSubagentTool(opts, depth, excluded) {
|
|
|
678
693
|
.join("\n");
|
|
679
694
|
const forkShadowed = (opts.agents ?? []).some((agent) => agent.name === FORK_SUBAGENT_TYPE);
|
|
680
695
|
const forkOffered = !forkShadowed;
|
|
696
|
+
const generalPurposeShadowed = deploymentNames.has(GENERAL_PURPOSE_SUBAGENT_TYPE) || builtins.some((b) => b.name === GENERAL_PURPOSE_SUBAGENT_TYPE);
|
|
681
697
|
const rosterNames = opts.models ? Object.keys(opts.models) : undefined;
|
|
682
698
|
const agentListing = [
|
|
683
699
|
...available.map((a) => ({ name: a.name, description: agentWhenToUseText(a) ?? "", tools: agentToolsNote(a) })),
|
|
@@ -728,7 +744,9 @@ function makeSubagentTool(opts, depth, excluded) {
|
|
|
728
744
|
subagent_type: Type.Optional(Type.Union([...available.map((a) => Type.Literal(a.name)), ...(forkOffered ? [Type.Literal(FORK_SUBAGENT_TYPE)] : [])], {
|
|
729
745
|
description: (forkOffered
|
|
730
746
|
? `Which defined agent type to delegate to ("${FORK_SUBAGENT_TYPE}" = built-in context-inheriting fork).`
|
|
731
|
-
: "Which defined agent type to delegate to.") +
|
|
747
|
+
: "Which defined agent type to delegate to.") +
|
|
748
|
+
" If omitted, a general-purpose sub-agent is used." +
|
|
749
|
+
(generalPurposeShadowed ? "" : ` "${GENERAL_PURPOSE_SUBAGENT_TYPE}" is accepted as an alias for omitting it.`),
|
|
732
750
|
})),
|
|
733
751
|
}
|
|
734
752
|
: forkOffered
|
|
@@ -748,9 +766,9 @@ function makeSubagentTool(opts, depth, excluded) {
|
|
|
748
766
|
}
|
|
749
767
|
: {}),
|
|
750
768
|
}),
|
|
751
|
-
prepareArguments: adaptLegacyForkArgs,
|
|
769
|
+
prepareArguments: (args) => foldGeneralPurposeAlias(adaptLegacyForkArgs(args), generalPurposeShadowed),
|
|
752
770
|
execute: async (args, ctx) => {
|
|
753
|
-
const a = adaptLegacyForkArgs(args);
|
|
771
|
+
const a = foldGeneralPurposeAlias(adaptLegacyForkArgs(args), generalPurposeShadowed);
|
|
754
772
|
const wantsBackground = opts.background !== undefined && a.run_in_background !== false;
|
|
755
773
|
const prompt = String(a.prompt ?? "").trim();
|
|
756
774
|
if (!prompt) {
|
|
@@ -839,9 +857,78 @@ function makeSubagentTool(opts, depth, excluded) {
|
|
|
839
857
|
return `worktree: ${worktreeDir} (cleanup check failed: ${e instanceof Error ? e.message : String(e)})`;
|
|
840
858
|
}
|
|
841
859
|
};
|
|
860
|
+
let injectedTools = [];
|
|
861
|
+
let extraToolsNote;
|
|
862
|
+
const treeBudget = extraToolsBudget ?? { used: 0 };
|
|
863
|
+
const reportExtraToolsError = (err) => {
|
|
864
|
+
try {
|
|
865
|
+
opts.onExtraToolsError?.(err, {
|
|
866
|
+
toolCallId: ctx.toolCallId,
|
|
867
|
+
...(def !== undefined ? { agentType: def.name } : wantsFork ? { agentType: FORK_SUBAGENT_TYPE } : {}),
|
|
868
|
+
depth,
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
catch {
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
if (opts.extraTools !== undefined) {
|
|
875
|
+
if (treeBudget.used >= EXTRA_TOOLS_MAX_FACTORY_CALLS_PER_TREE) {
|
|
876
|
+
extraToolsNote = EXTRA_TOOLS_BUDGET_NOTE;
|
|
877
|
+
reportExtraToolsError(new Error(`extraTools factory-call budget exhausted for this spawn tree (${EXTRA_TOOLS_MAX_FACTORY_CALLS_PER_TREE})`));
|
|
878
|
+
}
|
|
879
|
+
else {
|
|
880
|
+
treeBudget.used++;
|
|
881
|
+
try {
|
|
882
|
+
injectedTools = (await opts.extraTools({
|
|
883
|
+
toolCallId: ctx.toolCallId,
|
|
884
|
+
...(ctx.taskId !== undefined ? { parentTaskId: ctx.taskId } : {}),
|
|
885
|
+
...(ctx.sessionId !== undefined ? { parentSessionId: ctx.sessionId } : {}),
|
|
886
|
+
...(ctx.principal !== undefined ? { principal: ctx.principal } : {}),
|
|
887
|
+
...(def !== undefined ? { agentType: def.name } : wantsFork ? { agentType: FORK_SUBAGENT_TYPE } : {}),
|
|
888
|
+
depth,
|
|
889
|
+
})) ?? [];
|
|
890
|
+
}
|
|
891
|
+
catch (e) {
|
|
892
|
+
injectedTools = [];
|
|
893
|
+
extraToolsNote = EXTRA_TOOLS_FAILED_NOTE;
|
|
894
|
+
reportExtraToolsError(e);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
if (ctx.signal?.aborted) {
|
|
898
|
+
const wt = await finishWorktree();
|
|
899
|
+
return {
|
|
900
|
+
content: `Sub-agent not started: the parent task was aborted while extraTools was being evaluated.${wt ? `\n${wt}` : ""}`,
|
|
901
|
+
details: { error: "aborted" },
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
let childPool = opts.tools ?? [];
|
|
906
|
+
if (injectedTools.length > 0) {
|
|
907
|
+
const taken = new Set();
|
|
908
|
+
const reserve = (t) => {
|
|
909
|
+
taken.add(canonicalToolName(t.name));
|
|
910
|
+
for (const alias of t.aliases ?? [])
|
|
911
|
+
taken.add(canonicalToolName(alias));
|
|
912
|
+
};
|
|
913
|
+
for (const t of opts.tools ?? [])
|
|
914
|
+
reserve(t);
|
|
915
|
+
taken.add(canonicalToolName(toolName));
|
|
916
|
+
if (!opts.name)
|
|
917
|
+
taken.add(canonicalToolName(LEGACY_SUBAGENT_TOOL_NAME));
|
|
918
|
+
const merged = [...(opts.tools ?? [])];
|
|
919
|
+
for (const t of injectedTools) {
|
|
920
|
+
const names = [canonicalToolName(t.name), ...(t.aliases ?? []).map((alias) => canonicalToolName(alias))];
|
|
921
|
+
if (names.some((n) => taken.has(n)))
|
|
922
|
+
continue;
|
|
923
|
+
for (const n of names)
|
|
924
|
+
taken.add(n);
|
|
925
|
+
merged.push(t);
|
|
926
|
+
}
|
|
927
|
+
childPool = merged;
|
|
928
|
+
}
|
|
842
929
|
const childTools = def
|
|
843
|
-
? resolveToolSubset(
|
|
844
|
-
: resolveToolSubset(
|
|
930
|
+
? resolveToolSubset(childPool, def.allowTools, def.denyTools)
|
|
931
|
+
: resolveToolSubset(childPool, opts.allowTools, opts.denyTools);
|
|
845
932
|
const childModel = wantsFork
|
|
846
933
|
? ctx.model ?? opts.model
|
|
847
934
|
: perCallModel ?? (def ? (def.model ?? ctx.model ?? opts.model) : opts.model);
|
|
@@ -855,7 +942,7 @@ function makeSubagentTool(opts, depth, excluded) {
|
|
|
855
942
|
const nextExcluded = def ? new Set([...excluded, def.name]) : excluded;
|
|
856
943
|
const defAllowsDelegation = def === undefined || toolNameAllowed(opts.name ?? DEFAULT_SUBAGENT_TOOL_NAME, def.allowTools, def.denyTools);
|
|
857
944
|
if (depth + 1 < maxDepth && defAllowsDelegation) {
|
|
858
|
-
childTools.push(makeSubagentTool(opts, depth + 1, nextExcluded));
|
|
945
|
+
childTools.push(makeSubagentTool(opts, depth + 1, nextExcluded, treeBudget));
|
|
859
946
|
}
|
|
860
947
|
const inheritedManifestScope = inheritedManifestScopeFor(ctx.activeSkillScope?.());
|
|
861
948
|
const childAgentName = (typeof a.description === "string" && a.description.trim() ? a.description.trim() : undefined) ?? def?.name;
|
|
@@ -1357,6 +1444,7 @@ task_id: ${taskId}
|
|
|
1357
1444
|
`The forked agent inherits your full current context and works on its prompt in the background. You will be notified automatically when it completes.
|
|
1358
1445
|
` +
|
|
1359
1446
|
(modelNote ? `${modelNote}\n` : "") +
|
|
1447
|
+
(extraToolsNote ? `${extraToolsNote}\n` : "") +
|
|
1360
1448
|
(worktreeDir !== undefined
|
|
1361
1449
|
? `worktree: ${worktreeDir} (the agent works in its own detached worktree; auto-removed when it settles unchanged, kept when it made changes)
|
|
1362
1450
|
`
|
|
@@ -1407,6 +1495,7 @@ task_id: ${taskId}
|
|
|
1407
1495
|
`[Sub-agent report · ${FORK_SUBAGENT_TYPE}${a.description ? ` · ${String(a.description)}` : ""}] (forked session …${forkedId.slice(-8)})`,
|
|
1408
1496
|
`status: ${forkChild.status}`,
|
|
1409
1497
|
modelNote ?? "",
|
|
1498
|
+
extraToolsNote ?? "",
|
|
1410
1499
|
bgIgnoredNote ?? "",
|
|
1411
1500
|
wtLine ?? "",
|
|
1412
1501
|
forkChild.blockedReason ? `blocked_reason: ${inlineUntrusted(forkChild.blockedReason, REPORT_FIELD_MAX)}` : "",
|
|
@@ -1670,6 +1759,7 @@ task_id: ${taskId}
|
|
|
1670
1759
|
`The agent is working in the background. You will be notified automatically when it completes.
|
|
1671
1760
|
` +
|
|
1672
1761
|
(modelNote ? `${modelNote}\n` : "") +
|
|
1762
|
+
(extraToolsNote ? `${extraToolsNote}\n` : "") +
|
|
1673
1763
|
(worktreeDir !== undefined
|
|
1674
1764
|
? `worktree: ${worktreeDir} (the agent works in its own detached worktree; auto-removed when it settles unchanged, kept when it made changes)
|
|
1675
1765
|
`
|
|
@@ -1766,6 +1856,7 @@ task_id: ${taskId}
|
|
|
1766
1856
|
`[Sub-agent report${def ? ` · ${def.name}` : ""}${a.description ? ` · ${String(a.description)}` : ""}]`,
|
|
1767
1857
|
`status: ${child.status}`,
|
|
1768
1858
|
modelNote ?? "",
|
|
1859
|
+
extraToolsNote ?? "",
|
|
1769
1860
|
worktreeLine ?? "",
|
|
1770
1861
|
child.blockedReason ? `blocked_reason: ${inlineUntrusted(child.blockedReason, REPORT_FIELD_MAX)}` : "",
|
|
1771
1862
|
child.errorMessage ? `error: ${inlineUntrusted(child.errorMessage, REPORT_FIELD_MAX)}` : "",
|