@sema-agent/core 1.299.1 → 1.301.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.
Files changed (102) hide show
  1. package/dist/agents/subagent.d.ts.map +1 -1
  2. package/dist/agents/subagent.js +124 -50
  3. package/dist/agents/subagent.js.map +1 -1
  4. package/dist/core/auto-mode-prompt.d.ts.map +1 -1
  5. package/dist/core/auto-mode-prompt.js +25 -2
  6. package/dist/core/auto-mode-prompt.js.map +1 -1
  7. package/dist/core/checkpoint-store.d.ts +5 -0
  8. package/dist/core/checkpoint-store.d.ts.map +1 -1
  9. package/dist/core/checkpoint-store.js.map +1 -1
  10. package/dist/core/memory-engine/engine.d.ts +2 -2
  11. package/dist/core/memory-engine/engine.d.ts.map +1 -1
  12. package/dist/core/memory-engine/engine.js +3 -3
  13. package/dist/core/memory-engine/engine.js.map +1 -1
  14. package/dist/core/memory-engine/file-backend.d.ts.map +1 -1
  15. package/dist/core/memory-engine/file-backend.js +17 -0
  16. package/dist/core/memory-engine/file-backend.js.map +1 -1
  17. package/dist/core/memory-engine/frontmatter.d.ts.map +1 -1
  18. package/dist/core/memory-engine/frontmatter.js +62 -1
  19. package/dist/core/memory-engine/frontmatter.js.map +1 -1
  20. package/dist/core/memory-engine/memory-backend-contract.d.ts.map +1 -1
  21. package/dist/core/memory-engine/memory-backend-contract.js +45 -0
  22. package/dist/core/memory-engine/memory-backend-contract.js.map +1 -1
  23. package/dist/core/memory-engine/sync-client.d.ts.map +1 -1
  24. package/dist/core/memory-engine/sync-client.js +23 -0
  25. package/dist/core/memory-engine/sync-client.js.map +1 -1
  26. package/dist/core/memory-engine/types.d.ts +7 -0
  27. package/dist/core/memory-engine/types.d.ts.map +1 -1
  28. package/dist/core/runner/prepare-task.d.ts +12 -1
  29. package/dist/core/runner/prepare-task.d.ts.map +1 -1
  30. package/dist/core/runner/prepare-task.js +120 -10
  31. package/dist/core/runner/prepare-task.js.map +1 -1
  32. package/dist/core/runner/prompt-suggestions.d.ts.map +1 -1
  33. package/dist/core/runner/prompt-suggestions.js +14 -2
  34. package/dist/core/runner/prompt-suggestions.js.map +1 -1
  35. package/dist/core/runner/runtask.d.ts.map +1 -1
  36. package/dist/core/runner/runtask.js +177 -59
  37. package/dist/core/runner/runtask.js.map +1 -1
  38. package/dist/core/runner/synthetic-tools.d.ts +11 -1
  39. package/dist/core/runner/synthetic-tools.d.ts.map +1 -1
  40. package/dist/core/runner/synthetic-tools.js +47 -28
  41. package/dist/core/runner/synthetic-tools.js.map +1 -1
  42. package/dist/core/runner/turn-attachments.d.ts +14 -3
  43. package/dist/core/runner/turn-attachments.d.ts.map +1 -1
  44. package/dist/core/runner/turn-attachments.js +59 -7
  45. package/dist/core/runner/turn-attachments.js.map +1 -1
  46. package/dist/core/scheduler.d.ts +5 -0
  47. package/dist/core/scheduler.d.ts.map +1 -1
  48. package/dist/core/scheduler.js.map +1 -1
  49. package/dist/core/task-registry.d.ts +31 -2
  50. package/dist/core/task-registry.d.ts.map +1 -1
  51. package/dist/core/task-registry.js +35 -6
  52. package/dist/core/task-registry.js.map +1 -1
  53. package/dist/core/tool-policy.d.ts +11 -2
  54. package/dist/core/tool-policy.d.ts.map +1 -1
  55. package/dist/core/tool-policy.js +14 -0
  56. package/dist/core/tool-policy.js.map +1 -1
  57. package/dist/core/trace.d.ts.map +1 -1
  58. package/dist/core/trace.js.map +1 -1
  59. package/dist/core/types.d.ts +8 -2
  60. package/dist/core/types.d.ts.map +1 -1
  61. package/dist/core/untrusted-text.d.ts +23 -0
  62. package/dist/core/untrusted-text.d.ts.map +1 -1
  63. package/dist/core/untrusted-text.js +69 -0
  64. package/dist/core/untrusted-text.js.map +1 -1
  65. package/dist/engine/compaction/utils.d.ts.map +1 -1
  66. package/dist/engine/compaction/utils.js +20 -1
  67. package/dist/engine/compaction/utils.js.map +1 -1
  68. package/dist/engine/harness/agent-harness.d.ts +11 -4
  69. package/dist/engine/harness/agent-harness.d.ts.map +1 -1
  70. package/dist/engine/harness/agent-harness.js +23 -6
  71. package/dist/engine/harness/agent-harness.js.map +1 -1
  72. package/dist/engine/harness/messages.d.ts.map +1 -1
  73. package/dist/engine/harness/messages.js +1 -0
  74. package/dist/engine/harness/messages.js.map +1 -1
  75. package/dist/engine/harness/types.d.ts.map +1 -1
  76. package/dist/engine/harness/types.js.map +1 -1
  77. package/dist/engine/llm/types.d.ts +7 -0
  78. package/dist/engine/llm/types.d.ts.map +1 -1
  79. package/dist/engine/loop/agent-loop.js +7 -0
  80. package/dist/engine/loop/agent-loop.js.map +1 -1
  81. package/dist/engine/loop/types.d.ts +1 -0
  82. package/dist/engine/loop/types.d.ts.map +1 -1
  83. package/dist/engine/session/import-validate.d.ts.map +1 -1
  84. package/dist/engine/session/import-validate.js +31 -0
  85. package/dist/engine/session/import-validate.js.map +1 -1
  86. package/dist/index.d.ts +1 -1
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +1 -1
  89. package/dist/index.js.map +1 -1
  90. package/dist/prompts/default.d.ts.map +1 -1
  91. package/dist/prompts/default.js.map +1 -1
  92. package/dist/tools/fs/index.d.ts +0 -1
  93. package/dist/tools/fs/index.d.ts.map +1 -1
  94. package/dist/tools/fs/index.js +2 -3
  95. package/dist/tools/fs/index.js.map +1 -1
  96. package/dist/tools/scheduler-tools.d.ts.map +1 -1
  97. package/dist/tools/scheduler-tools.js +71 -16
  98. package/dist/tools/scheduler-tools.js.map +1 -1
  99. package/dist/tools/worktree.d.ts.map +1 -1
  100. package/dist/tools/worktree.js +6 -5
  101. package/dist/tools/worktree.js.map +1 -1
  102. package/package.json +1 -1
@@ -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,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;;;aA2KjE;AAGD,eAAO,MAAM,0BAA0B,oBAAoB,CAAC;AAK5D,MAAM,WAAW,0BAA0B;IAEzC,MAAM,EAAE,MAAM,CAAC;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"}
@@ -1,4 +1,5 @@
1
1
  import { Type } from "typebox";
2
+ import { isAbsolute } from "node:path";
2
3
  import { resolveModel } from "../core/roles.js";
3
4
  import { OUTPUT_TOOL_NAME, REPORT_BLOCKED_TOOL_NAME } from "../core/runner/synthetic-tools.js";
4
5
  import { defineTool } from "../core/tools.js";
@@ -13,7 +14,7 @@ import { isDurablePause } from "./suspend-guard.js";
13
14
  import { delimitUntrusted, inlineUntrusted } from "../core/untrusted-text.js";
14
15
  import { uuidv7 } from "../internal/harness.js";
15
16
  import { addWorktree } from "../core/git-worktree-env.js";
16
- import { BG_AGENT_REAP_STOP_ERROR } from "../core/task-registry.js";
17
+ import { BG_AGENT_REAP_STOP_ERROR, normalizeAgentName } from "../core/task-registry.js";
17
18
  import { extractErrorCode } from "../brain/errors.js";
18
19
  import { ObserverDigestTap, ObserverPairing, createObserverReportToolSpec, markObserverTaskId, unmarkObserverTaskId, isObserverTaskId, observerFramingPrompt, observerSlug, resolveObserverDeclaration, OBSERVER_SENDMESSAGE_SENDER_REFUSAL, OBSERVER_SENDMESSAGE_TARGET_REFUSAL, } from "./observer.js";
19
20
  import { SubagentStepRecorder, stepsFromMessages } from "./subagent-steps.js";
@@ -705,15 +706,14 @@ function makeSubagentTool(opts, depth, excluded, extraToolsBudget) {
705
706
  const available = [...(opts.agents ?? []), ...builtins].filter((a) => !excluded.has(a.name));
706
707
  const agentMap = new Map(available.map((a) => [a.name, a]));
707
708
  const hasAgents = available.length > 0;
708
- const agentList = available
709
- .map((a) => {
710
- const w = agentWhenToUseText(a);
711
- return `- ${a.name}${w ? `: ${w}` : ""}`;
712
- })
713
- .join("\n");
714
709
  const forkShadowed = (opts.agents ?? []).some((agent) => agent.name === FORK_SUBAGENT_TYPE);
715
710
  const forkOffered = !forkShadowed;
716
711
  const generalPurposeShadowed = deploymentNames.has(GENERAL_PURPOSE_SUBAGENT_TYPE) || builtins.some((b) => b.name === GENERAL_PURPOSE_SUBAGENT_TYPE);
712
+ const acceptedSubagentTypes = () => [
713
+ ...agentMap.keys(),
714
+ ...(forkOffered ? [FORK_SUBAGENT_TYPE] : []),
715
+ ...(generalPurposeShadowed ? [] : [GENERAL_PURPOSE_SUBAGENT_TYPE]),
716
+ ];
717
717
  const rosterNames = opts.models ? Object.keys(opts.models) : undefined;
718
718
  const agentListing = [
719
719
  ...available.map((a) => ({ name: a.name, description: agentWhenToUseText(a) ?? "", tools: agentToolsNote(a) })),
@@ -728,11 +728,12 @@ function makeSubagentTool(opts, depth, excluded, extraToolsBudget) {
728
728
  return {
729
729
  name: opts.name ?? DEFAULT_SUBAGENT_TOOL_NAME,
730
730
  agentListing,
731
+ ...(rosterNames !== undefined ? { agentModels: rosterNames } : {}),
731
732
  executionMode: "parallel",
732
733
  ...(!opts.name ? { aliases: [LEGACY_SUBAGENT_TOOL_NAME] } : {}),
733
734
  description: `Launch a new agent. Delegate a self-contained subtask to an isolated sub-agent and get back a single report. ` +
734
735
  (opts.purpose ? `This sub-agent is for: ${opts.purpose}. ` : "") +
735
- (hasAgents ? `Pick the \`subagent_type\` whose role best fits the subtask (if omitted, a general-purpose sub-agent is used):\n${agentList}\n` : "") +
736
+ (hasAgents ? `Available agent types are listed in <system-reminder> messages in the conversation. If \`subagent_type\` is omitted, a general-purpose sub-agent is used.\n` : "") +
736
737
  `The sub-agent starts with a clean context (it does NOT see this conversation), so put everything it needs in 'prompt'. ` +
737
738
  `It returns status (completed/blocked/failed) and a result you must verify before deciding the overall task is done.\n\n` +
738
739
  `When NOT to delegate (do it yourself — it's faster and you keep the understanding):\n` +
@@ -751,7 +752,7 @@ function makeSubagentTool(opts, depth, excluded, extraToolsBudget) {
751
752
  (forkOffered
752
753
  ? `\n\nsubagent_type "${FORK_SUBAGENT_TYPE}" is built in: it spawns a child that INHERITS your full current context (this entire conversation — no re-explaining, shared prompt cache) and works on 'prompt' as its directive. The fork always runs on YOUR model (the 'model' parameter is ignored for forks) and is not available inside a forked agent.`
753
754
  : `\n\nNote: this deployment defines its own "${FORK_SUBAGENT_TYPE}" agent type, which OVERRIDES the built-in context-inheriting fork routing — subagent_type "${FORK_SUBAGENT_TYPE}" delegates to that definition instead.`) +
754
- `\n\nThe 'model' parameter optionally overrides the sub-agent's model${rosterNames?.length ? ` (available: ${rosterNames.join(", ")})` : ""}. If omitted, the agent definition's model (or the inherited default) applies.` +
755
+ `\n\nThe 'model' parameter optionally overrides the sub-agent's model. If omitted, the agent definition's model (or the inherited default) applies.` +
755
756
  `\nSet isolation: "worktree" to give the agent its own detached git worktree (auto-removed if it made no changes; kept for you to inspect/merge when it did).` +
756
757
  (opts.background
757
758
  ?
@@ -760,23 +761,19 @@ function makeSubagentTool(opts, depth, excluded, extraToolsBudget) {
760
761
  `\n\n**Don't race.** After launching, you know nothing about what the agent found. Never fabricate or predict agent results in any format — not as prose, summary, or structured output. The notification arrives as a user-role message in a later turn; it is never something you write yourself.`
761
762
  : `\n\nThe run_in_background parameter is not available in this context. Only synchronous subagents are supported.`),
762
763
  parameters: Type.Object({
763
- ...(hasAgents
764
- ? {
765
- subagent_type: Type.Optional(Type.Union([...available.map((a) => Type.Literal(a.name)), ...(forkOffered ? [Type.Literal(FORK_SUBAGENT_TYPE)] : [])], {
766
- description: (forkOffered
767
- ? `Which defined agent type to delegate to ("${FORK_SUBAGENT_TYPE}" = built-in context-inheriting fork).`
768
- : "Which defined agent type to delegate to.") +
769
- " If omitted, a general-purpose sub-agent is used." +
770
- (generalPurposeShadowed ? "" : ` "${GENERAL_PURPOSE_SUBAGENT_TYPE}" is accepted as an alias for omitting it.`),
771
- })),
772
- }
773
- : forkOffered
774
- ? { subagent_type: Type.Optional(Type.Literal(FORK_SUBAGENT_TYPE, { description: `Set to "${FORK_SUBAGENT_TYPE}" to spawn a child that inherits your full current context. Omit for a clean-context sub-agent.` })) }
775
- : {}),
764
+ subagent_type: Type.Optional(Type.String({ description: "The type of specialized agent to use for this task" })),
776
765
  description: Type.String({ description: "A short (3-5 word) description of the task." }),
777
766
  prompt: Type.String({ description: "Full, self-contained instructions for the sub-agent." }),
767
+ name: Type.Optional(Type.String({
768
+ maxLength: 64,
769
+ pattern: "^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$",
770
+ description: 'Name for the spawned agent. Makes a background agent addressable via SendMessage({to: name}). "main" is reserved.',
771
+ })),
772
+ cwd: Type.Optional(Type.String({
773
+ description: 'Absolute path to run the agent in. Overrides the working directory for all filesystem and shell operations within this agent. Mutually exclusive with isolation: "worktree".',
774
+ })),
778
775
  model: Type.Optional(Type.String({
779
- description: `Optional model override for this agent${rosterNames?.length ? ` (one of: ${rosterNames.join(", ")})` : ""}. Takes precedence over the agent definition's model. Ignored for subagent_type "${FORK_SUBAGENT_TYPE}" — forks always run on the caller's model.`,
776
+ description: `Optional model override for this agent. Takes precedence over the agent definition's model. If omitted, uses the agent definition's model, or inherits from the parent. Ignored for subagent_type: "${FORK_SUBAGENT_TYPE}" — forks always inherit the parent model.`,
780
777
  })),
781
778
  isolation: Type.Optional(Type.Literal("worktree", {
782
779
  description: 'Isolation mode. "worktree" runs the agent in its own detached git worktree (auto-removed if unchanged, kept when the agent made changes).',
@@ -795,12 +792,54 @@ function makeSubagentTool(opts, depth, excluded, extraToolsBudget) {
795
792
  if (!prompt) {
796
793
  return { content: "Sub-agent not started: 'prompt' was empty.", details: { error: "empty prompt" } };
797
794
  }
798
- const rawType = String(a.subagent_type ?? "");
795
+ if (a.subagent_type !== undefined && typeof a.subagent_type !== "string") {
796
+ return {
797
+ content: `Sub-agent not started: subagent_type must be a string. Available subagent_type values: ${acceptedSubagentTypes().join(", ")}.`,
798
+ details: { error: "unknown subagent_type" },
799
+ };
800
+ }
801
+ const rawType = a.subagent_type ?? "";
799
802
  const wantsFork = forkOffered && rawType === FORK_SUBAGENT_TYPE;
800
803
  const omitted = rawType === "";
801
804
  const def = hasAgents && !wantsFork && !omitted ? agentMap.get(rawType) : undefined;
802
- if (hasAgents && !def && !wantsFork && !omitted) {
803
- return { content: `Sub-agent not started: unknown subagent_type "${rawType}".`, details: { error: "unknown subagent_type" } };
805
+ if (!def && !wantsFork && !omitted) {
806
+ return {
807
+ content: `Sub-agent not started: unknown subagent_type "${rawType}". Available subagent_type values: ${acceptedSubagentTypes().join(", ")}.`,
808
+ details: { error: "unknown subagent_type" },
809
+ };
810
+ }
811
+ if (a.name !== undefined && typeof a.name !== "string") {
812
+ return { content: "Sub-agent not started: name must be a string.", details: { error: "name.invalid" } };
813
+ }
814
+ const agentName = a.name;
815
+ if (agentName !== undefined) {
816
+ if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(agentName)) {
817
+ return {
818
+ content: "Sub-agent not started: name must start with a letter or digit and contain only letters, digits, underscores, or hyphens (max 64 chars).",
819
+ details: { error: "name.invalid" },
820
+ };
821
+ }
822
+ if (agentName.toLowerCase() === "main") {
823
+ return {
824
+ content: 'Sub-agent not started: "main" is reserved — SendMessage routes it to the main conversation.',
825
+ details: { error: "name.reserved" },
826
+ };
827
+ }
828
+ }
829
+ if (a.cwd !== undefined && typeof a.cwd !== "string") {
830
+ return { content: "Sub-agent not started: cwd must be an absolute path string.", details: { error: "cwd.relative" } };
831
+ }
832
+ const childCwd = a.cwd;
833
+ if (childCwd !== undefined) {
834
+ if (!isAbsolute(childCwd)) {
835
+ return { content: "Sub-agent not started: cwd must be an absolute path.", details: { error: "cwd.relative" } };
836
+ }
837
+ if ((a.isolation ?? def?.isolation) === "worktree") {
838
+ return {
839
+ content: 'Sub-agent not started: cwd and isolation "worktree" are mutually exclusive — the worktree defines its own working directory.',
840
+ details: { error: "cwd.isolation_conflict" },
841
+ };
842
+ }
804
843
  }
805
844
  if (wantsFork) {
806
845
  if (ctx.forkAccess?.denied !== undefined) {
@@ -1131,7 +1170,14 @@ function makeSubagentTool(opts, depth, excluded, extraToolsBudget) {
1131
1170
  ...(childAgentName ? { agentName: childAgentName } : {}),
1132
1171
  ...(ctx.taskId !== undefined ? { parentTaskId: ctx.taskId } : {}),
1133
1172
  onForwardEvent: recordingForward,
1134
- ...(worktreeDir !== undefined ? { parentCwd: worktreeDir } : ctx.parentCwd !== undefined ? { parentCwd: ctx.parentCwd } : {}),
1173
+ ...(worktreeDir !== undefined
1174
+ ? { parentCwd: worktreeDir }
1175
+ : childCwd !== undefined
1176
+ ?
1177
+ { parentCwd: childCwd, requestedCwd: childCwd }
1178
+ : ctx.parentCwd !== undefined
1179
+ ? { parentCwd: ctx.parentCwd }
1180
+ : {}),
1135
1181
  ...(ctx.onSubagentSpawn ? { onSubagentSpawn: ctx.onSubagentSpawn } : {}),
1136
1182
  };
1137
1183
  const childThinking = def?.thinking ?? ctx.thinkingLevel;
@@ -1308,6 +1354,7 @@ function makeSubagentTool(opts, depth, excluded, extraToolsBudget) {
1308
1354
  ...(bgScope !== undefined ? { scope: bgScope } : {}),
1309
1355
  ...(sessionScopedBg ? { sessionScoped: true } : {}),
1310
1356
  description: shortDesc,
1357
+ ...(agentName !== undefined ? { name: agentName } : {}),
1311
1358
  toolUseId: ctx.toolCallId,
1312
1359
  abort,
1313
1360
  });
@@ -1569,6 +1616,7 @@ task_id: ${taskId}
1569
1616
  ...(bgScope !== undefined ? { scope: bgScope } : {}),
1570
1617
  ...(sessionScopedBg ? { sessionScoped: true } : {}),
1571
1618
  description: shortDesc,
1619
+ ...(agentName !== undefined ? { name: agentName } : {}),
1572
1620
  toolUseId: ctx.toolCallId,
1573
1621
  abort,
1574
1622
  });
@@ -1941,13 +1989,14 @@ export function createSendMessageTool(opts) {
1941
1989
  name: SEND_MESSAGE_TOOL_NAME,
1942
1990
  executionMode: "parallel",
1943
1991
  description: `Send a follow-up message to a previously spawned background agent, continuing it with its context intact. ` +
1944
- `'to' is the task_id (a…) returned when the agent was launched with run_in_background — the agent must have ` +
1992
+ `'to' is the agent's name (set at spawn via Agent({name})) or its task_id (a…) — the agent must have ` +
1945
1993
  `finished; it resumes as a new background run with its full prior conversation preserved, so don't re-explain ` +
1946
- `what it already knows. You will be notified automatically when it completes prefer ending your turn; do not poll. ` +
1947
- `This requires the run to retain sub-agent sessions; when the session was not retained (or has expired) you get ` +
1948
- `an honest error and should launch a new agent with the needed context instead.`,
1994
+ `what it already knows. Names keep working after an agent completes; when a newer agent took the name, the ` +
1995
+ `newest wins — use the task_id to address an older one. You will be notified automatically when it completes ` +
1996
+ `prefer ending your turn; do not poll. This requires the run to retain sub-agent sessions; when the session was ` +
1997
+ `not retained (or has expired) you get an honest error and should launch a new agent with the needed context instead.`,
1949
1998
  parameters: Type.Object({
1950
- to: Type.String({ description: "The background agent's task_id (a…) returned by the Agent tool with run_in_background." }),
1999
+ to: Type.String({ description: 'Recipient: the agent\'s name, or its task_id (a…) returned by the Agent tool with run_in_background. "main" is reserved for the spawning conversation.' }),
1951
2000
  message: Type.String({ description: "The follow-up request. The agent continues from its full prior context." }),
1952
2001
  summary: Type.Optional(Type.String({ maxLength: 200, description: "A short (3-5 word) description of the follow-up." })),
1953
2002
  }),
@@ -1966,31 +2015,56 @@ export function createSendMessageTool(opts) {
1966
2015
  if (isObserverTaskId(to)) {
1967
2016
  return { content: OBSERVER_SENDMESSAGE_TARGET_REFUSAL, details: { error: "observer_target", to } };
1968
2017
  }
2018
+ if (normalizeAgentName(to) === "main") {
2019
+ return {
2020
+ content: `Message not sent: "main" (the spawning conversation) is not yet a deliverable target here. ` +
2021
+ `Your completion is reported to it automatically — finish your task and your final report will be relayed.`,
2022
+ details: { error: "main_not_deliverable", to },
2023
+ };
2024
+ }
1969
2025
  const access = {
1970
2026
  owner: ctx.taskId ?? opts.owner,
1971
2027
  scope: ctx.principal ?? opts.scope,
1972
2028
  ...(opts.sessionId !== undefined ? { sessionId: opts.sessionId } : {}),
1973
2029
  };
1974
- const row = opts.registry.list(access, { limit: 500 }).find((r) => r.task_id === to);
1975
- if (!row) {
1976
- return {
1977
- content: `Message not sent: no background agent task "${to}" (unknown id, not yours, or expired). Launch a new agent instead.`,
1978
- details: { error: "not_found", to },
1979
- };
2030
+ const idRow = opts.registry.getAccessibleTask(to, access);
2031
+ let target = idRow;
2032
+ if (!target) {
2033
+ const byName = opts.registry.resolveBackgroundAgentByName(to, access);
2034
+ if (byName.status === "ambiguous") {
2035
+ return { content: `Message not sent: ${byName.message}`, details: { error: "ambiguous", to } };
2036
+ }
2037
+ if (byName.status === "found") {
2038
+ const h = byName.handle;
2039
+ target = { task_id: h.id, type: h.type, status: h.status, ...(h.toolUseId !== undefined ? { toolUseId: h.toolUseId } : {}) };
2040
+ }
2041
+ else {
2042
+ const labels = opts.registry.runningBackgroundAgentLabels(access);
2043
+ return {
2044
+ content: `Message not sent: no agent matches "${to}" (unknown id or name, not yours, or expired).` +
2045
+ (byName.suggestion !== undefined ? ` Did you mean: ${byName.suggestion}?` : "") +
2046
+ (labels.length > 0 ? ` Running background agents: ${labels.join(", ")}.` : "") +
2047
+ ` Launch a new agent instead.`,
2048
+ details: { error: "not_found", to, ...(byName.suggestion !== undefined ? { suggestion: byName.suggestion } : {}) },
2049
+ };
2050
+ }
1980
2051
  }
2052
+ const row = target;
2053
+ const targetId = row.task_id;
2054
+ const who = targetId === to ? `agent ${targetId}` : `agent "${to}" (${targetId})`;
1981
2055
  if (row.type !== "background_agent") {
1982
- return { content: `Message not sent: ${to} is a ${row.type} task, not a background agent.`, details: { error: "wrong_type", to } };
2056
+ return { content: `Message not sent: ${targetId} is a ${row.type} task, not a background agent.`, details: { error: "wrong_type", to } };
1983
2057
  }
1984
2058
  if (row.status === "running" || row.status === "pending") {
1985
2059
  return {
1986
- content: `Message not sent: agent ${to} is still running — it cannot take a follow-up yet. Wait for its completion notification, then SendMessage.`,
2060
+ content: `Message not sent: ${who} is still running — mid-run delivery is not yet supported here. Wait for its completion notification, then SendMessage to continue it.`,
1987
2061
  details: { error: "still_running", to },
1988
2062
  };
1989
2063
  }
1990
2064
  if (row.status === "killed") {
1991
- const by = opts.registry.getStopAttribution(to);
2065
+ const by = opts.registry.getStopAttribution(targetId);
1992
2066
  return {
1993
- content: `Message not sent: agent ${to} was stopped${by ? ` (by ${by})` : ""} — a stopped agent is not resumable. Launch a new agent with the needed context instead.`,
2067
+ content: `Message not sent: ${who} was stopped${by ? ` (by ${by})` : ""} — a stopped agent is not resumable. Launch a new agent with the needed context instead.`,
1994
2068
  details: { error: "killed", to, ...(by !== undefined ? { stoppedBy: by } : {}) },
1995
2069
  };
1996
2070
  }
@@ -2000,7 +2074,7 @@ export function createSendMessageTool(opts) {
2000
2074
  const ledger = (knows(sessionLedger) ? sessionLedger : undefined) ?? (knows(runLedger) ? runLedger : undefined) ?? runLedger ?? sessionLedger;
2001
2075
  if (!ledger || row.toolUseId === undefined) {
2002
2076
  return {
2003
- content: `Message not sent: agent ${to}'s session was not retained (this run did not enable retainSubagentSessions), so it cannot be continued — relaunch a new agent with the needed context instead.`,
2077
+ content: `Message not sent: ${who}'s session was not retained (this run did not enable retainSubagentSessions), so it cannot be continued — relaunch a new agent with the needed context instead.`,
2004
2078
  details: { error: "not_retained", to },
2005
2079
  };
2006
2080
  }
@@ -2016,23 +2090,23 @@ export function createSendMessageTool(opts) {
2016
2090
  try {
2017
2091
  const marker = await resume(summary ? `[${summary}] ${message}` : message);
2018
2092
  return {
2019
- content: `Message sent — agent ${to} resumed in the background with its prior context intact (correlation marker [${marker}]).\n` +
2093
+ content: `Message sent — ${who} resumed in the background with its prior context intact (correlation marker [${marker}]).\n` +
2020
2094
  `You will be notified automatically when it completes; its reply will carry [${marker}]. Continue with other work — do not poll.`,
2021
- details: { type: "send-message", status: "resumed", to, marker, ...(summary !== undefined ? { summary } : {}) },
2095
+ details: { type: "send-message", status: "resumed", to, task_id: targetId, marker, ...(summary !== undefined ? { summary } : {}) },
2022
2096
  };
2023
2097
  }
2024
2098
  catch (e) {
2025
2099
  const code = e?.code;
2026
2100
  const text = code === "resume.retain_off"
2027
- ? `agent ${to}'s session was not retained (retainSubagentSessions is off) — relaunch a new agent instead.`
2101
+ ? `${who}'s session was not retained (retainSubagentSessions is off) — relaunch a new agent instead.`
2028
2102
  : code === "resume.evicted"
2029
- ? `agent ${to}'s retained session was evicted (retain TTL / capacity / parent run ended) — relaunch a new agent instead.`
2103
+ ? `${who}'s retained session was evicted (retain TTL / capacity / parent run ended) — relaunch a new agent instead.`
2030
2104
  : code === "resume.session_not_found"
2031
- ? `agent ${to}'s session no longer exists — relaunch a new agent instead.`
2105
+ ? `${who}'s session no longer exists — relaunch a new agent instead.`
2032
2106
  : code === "resume.cap"
2033
- ? `agent ${to} reached its resume cap (${SUBAGENT_RESUME_CAP} follow-ups per agent) — relaunch a new agent instead.`
2107
+ ? `${who} reached its resume cap (${SUBAGENT_RESUME_CAP} follow-ups per agent) — relaunch a new agent instead.`
2034
2108
  : code === "steering.still_running"
2035
- ? `agent ${to} (or a prior follow-up to it) is still running — wait for its completion notification.`
2109
+ ? `${who} (or a prior follow-up to it) is still running — wait for its completion notification.`
2036
2110
  : `${e instanceof Error ? e.message : String(e)}`;
2037
2111
  return { content: `Message not sent: ${text}`, details: { error: code ?? "resume_failed", to } };
2038
2112
  }