pilotswarm-sdk 0.5.63 → 0.5.65

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 (289) hide show
  1. package/api/src/admin-diagnostics.d.ts +12 -0
  2. package/api/src/admin-diagnostics.js +38 -1
  3. package/api/src/http-api-transport.js +26 -0
  4. package/api/src/protocol.js +15 -0
  5. package/dist/activity-routing.d.ts +21 -0
  6. package/dist/activity-routing.d.ts.map +1 -0
  7. package/dist/activity-routing.js +32 -0
  8. package/dist/activity-routing.js.map +1 -0
  9. package/dist/agent-discovery.d.ts +35 -0
  10. package/dist/agent-discovery.d.ts.map +1 -0
  11. package/dist/agent-discovery.js +107 -0
  12. package/dist/agent-discovery.js.map +1 -0
  13. package/dist/client.d.ts +9 -1
  14. package/dist/client.d.ts.map +1 -1
  15. package/dist/client.js +94 -12
  16. package/dist/client.js.map +1 -1
  17. package/dist/cms-migrations.d.ts.map +1 -1
  18. package/dist/cms-migrations.js +4 -0
  19. package/dist/cms-migrations.js.map +1 -1
  20. package/dist/cms.d.ts +3 -0
  21. package/dist/cms.d.ts.map +1 -1
  22. package/dist/cms.js +7 -0
  23. package/dist/cms.js.map +1 -1
  24. package/dist/feature-flag-cache.d.ts +40 -0
  25. package/dist/feature-flag-cache.d.ts.map +1 -0
  26. package/dist/feature-flag-cache.js +125 -0
  27. package/dist/feature-flag-cache.js.map +1 -0
  28. package/dist/feature-flags.d.ts +68 -0
  29. package/dist/feature-flags.d.ts.map +1 -0
  30. package/dist/feature-flags.js +45 -0
  31. package/dist/feature-flags.js.map +1 -0
  32. package/dist/feature-store.d.ts +55 -0
  33. package/dist/feature-store.d.ts.map +1 -0
  34. package/dist/feature-store.js +106 -0
  35. package/dist/feature-store.js.map +1 -0
  36. package/dist/feature-tools.d.ts +94 -0
  37. package/dist/feature-tools.d.ts.map +1 -0
  38. package/dist/feature-tools.js +60 -0
  39. package/dist/feature-tools.js.map +1 -0
  40. package/dist/index.d.ts +6 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +4 -0
  43. package/dist/index.js.map +1 -1
  44. package/dist/managed-session.d.ts +4 -0
  45. package/dist/managed-session.d.ts.map +1 -1
  46. package/dist/managed-session.js +120 -23
  47. package/dist/managed-session.js.map +1 -1
  48. package/dist/management-client.d.ts +18 -0
  49. package/dist/management-client.d.ts.map +1 -1
  50. package/dist/management-client.js +19 -0
  51. package/dist/management-client.js.map +1 -1
  52. package/dist/migrations/feature-flags-0077.d.ts +3 -0
  53. package/dist/migrations/feature-flags-0077.d.ts.map +1 -0
  54. package/dist/migrations/feature-flags-0077.js +271 -0
  55. package/dist/migrations/feature-flags-0077.js.map +1 -0
  56. package/dist/migrations/native-tasks-default-policy-0078.d.ts +3 -0
  57. package/dist/migrations/native-tasks-default-policy-0078.d.ts.map +1 -0
  58. package/dist/migrations/native-tasks-default-policy-0078.js +21 -0
  59. package/dist/migrations/native-tasks-default-policy-0078.js.map +1 -0
  60. package/dist/native-subagents.d.ts +25 -0
  61. package/dist/native-subagents.d.ts.map +1 -0
  62. package/dist/native-subagents.js +191 -0
  63. package/dist/native-subagents.js.map +1 -0
  64. package/dist/native-task-observer.d.ts +87 -0
  65. package/dist/native-task-observer.d.ts.map +1 -0
  66. package/dist/native-task-observer.js +268 -0
  67. package/dist/native-task-observer.js.map +1 -0
  68. package/dist/orchestration/agents.d.ts +8 -3
  69. package/dist/orchestration/agents.d.ts.map +1 -1
  70. package/dist/orchestration/agents.js +87 -36
  71. package/dist/orchestration/agents.js.map +1 -1
  72. package/dist/orchestration/index.d.ts +2 -2
  73. package/dist/orchestration/index.js +1 -1
  74. package/dist/orchestration/lifecycle.js +1 -1
  75. package/dist/orchestration/lifecycle.js.map +1 -1
  76. package/dist/orchestration/runtime.d.ts +1 -1
  77. package/dist/orchestration/runtime.d.ts.map +1 -1
  78. package/dist/orchestration/runtime.js +18 -4
  79. package/dist/orchestration/runtime.js.map +1 -1
  80. package/dist/orchestration/turn.d.ts.map +1 -1
  81. package/dist/orchestration/turn.js +3 -5
  82. package/dist/orchestration/turn.js.map +1 -1
  83. package/dist/orchestration-registry.d.ts.map +1 -1
  84. package/dist/orchestration-registry.js +12 -2
  85. package/dist/orchestration-registry.js.map +1 -1
  86. package/dist/orchestration-version.d.ts +1 -1
  87. package/dist/orchestration-version.js +1 -1
  88. package/dist/orchestration.d.ts +2 -2
  89. package/dist/orchestration.js +1 -1
  90. package/dist/orchestration_1_0_46.d.ts +1 -1
  91. package/dist/orchestration_1_0_47.d.ts +1 -1
  92. package/dist/orchestration_1_0_48.d.ts +1 -1
  93. package/dist/orchestration_1_0_49.d.ts +1 -1
  94. package/dist/orchestration_1_0_50.d.ts +1 -1
  95. package/dist/orchestration_1_0_73/agents.d.ts +61 -0
  96. package/dist/orchestration_1_0_73/agents.d.ts.map +1 -0
  97. package/dist/orchestration_1_0_73/agents.js +843 -0
  98. package/dist/orchestration_1_0_73/agents.js.map +1 -0
  99. package/dist/orchestration_1_0_73/index.d.ts +24 -0
  100. package/dist/orchestration_1_0_73/index.d.ts.map +1 -0
  101. package/dist/orchestration_1_0_73/index.js +13 -0
  102. package/dist/orchestration_1_0_73/index.js.map +1 -0
  103. package/dist/orchestration_1_0_73/lifecycle.d.ts +51 -0
  104. package/dist/orchestration_1_0_73/lifecycle.d.ts.map +1 -0
  105. package/dist/orchestration_1_0_73/lifecycle.js +981 -0
  106. package/dist/orchestration_1_0_73/lifecycle.js.map +1 -0
  107. package/dist/orchestration_1_0_73/queue.d.ts +20 -0
  108. package/dist/orchestration_1_0_73/queue.d.ts.map +1 -0
  109. package/dist/orchestration_1_0_73/queue.js +894 -0
  110. package/dist/orchestration_1_0_73/queue.js.map +1 -0
  111. package/dist/orchestration_1_0_73/runtime.d.ts +31 -0
  112. package/dist/orchestration_1_0_73/runtime.d.ts.map +1 -0
  113. package/dist/orchestration_1_0_73/runtime.js +230 -0
  114. package/dist/orchestration_1_0_73/runtime.js.map +1 -0
  115. package/dist/orchestration_1_0_73/state.d.ts +214 -0
  116. package/dist/orchestration_1_0_73/state.d.ts.map +1 -0
  117. package/dist/orchestration_1_0_73/state.js +178 -0
  118. package/dist/orchestration_1_0_73/state.js.map +1 -0
  119. package/dist/orchestration_1_0_73/turn.d.ts +34 -0
  120. package/dist/orchestration_1_0_73/turn.d.ts.map +1 -0
  121. package/dist/orchestration_1_0_73/turn.js +1435 -0
  122. package/dist/orchestration_1_0_73/turn.js.map +1 -0
  123. package/dist/orchestration_1_0_73/utils.d.ts +39 -0
  124. package/dist/orchestration_1_0_73/utils.d.ts.map +1 -0
  125. package/dist/orchestration_1_0_73/utils.js +322 -0
  126. package/dist/orchestration_1_0_73/utils.js.map +1 -0
  127. package/dist/orchestration_1_0_74/agents.d.ts +61 -0
  128. package/dist/orchestration_1_0_74/agents.d.ts.map +1 -0
  129. package/dist/orchestration_1_0_74/agents.js +889 -0
  130. package/dist/orchestration_1_0_74/agents.js.map +1 -0
  131. package/dist/orchestration_1_0_74/index.d.ts +24 -0
  132. package/dist/orchestration_1_0_74/index.d.ts.map +1 -0
  133. package/dist/orchestration_1_0_74/index.js +13 -0
  134. package/dist/orchestration_1_0_74/index.js.map +1 -0
  135. package/dist/orchestration_1_0_74/lifecycle.d.ts +51 -0
  136. package/dist/orchestration_1_0_74/lifecycle.d.ts.map +1 -0
  137. package/dist/orchestration_1_0_74/lifecycle.js +981 -0
  138. package/dist/orchestration_1_0_74/lifecycle.js.map +1 -0
  139. package/dist/orchestration_1_0_74/queue.d.ts +20 -0
  140. package/dist/orchestration_1_0_74/queue.d.ts.map +1 -0
  141. package/dist/orchestration_1_0_74/queue.js +894 -0
  142. package/dist/orchestration_1_0_74/queue.js.map +1 -0
  143. package/dist/orchestration_1_0_74/runtime.d.ts +31 -0
  144. package/dist/orchestration_1_0_74/runtime.d.ts.map +1 -0
  145. package/dist/orchestration_1_0_74/runtime.js +232 -0
  146. package/dist/orchestration_1_0_74/runtime.js.map +1 -0
  147. package/dist/orchestration_1_0_74/state.d.ts +214 -0
  148. package/dist/orchestration_1_0_74/state.d.ts.map +1 -0
  149. package/dist/orchestration_1_0_74/state.js +178 -0
  150. package/dist/orchestration_1_0_74/state.js.map +1 -0
  151. package/dist/orchestration_1_0_74/turn.d.ts +34 -0
  152. package/dist/orchestration_1_0_74/turn.d.ts.map +1 -0
  153. package/dist/orchestration_1_0_74/turn.js +1435 -0
  154. package/dist/orchestration_1_0_74/turn.js.map +1 -0
  155. package/dist/orchestration_1_0_74/utils.d.ts +39 -0
  156. package/dist/orchestration_1_0_74/utils.d.ts.map +1 -0
  157. package/dist/orchestration_1_0_74/utils.js +322 -0
  158. package/dist/orchestration_1_0_74/utils.js.map +1 -0
  159. package/dist/orchestration_1_0_75/agents.d.ts +61 -0
  160. package/dist/orchestration_1_0_75/agents.d.ts.map +1 -0
  161. package/dist/orchestration_1_0_75/agents.js +887 -0
  162. package/dist/orchestration_1_0_75/agents.js.map +1 -0
  163. package/dist/orchestration_1_0_75/index.d.ts +24 -0
  164. package/dist/orchestration_1_0_75/index.d.ts.map +1 -0
  165. package/dist/orchestration_1_0_75/index.js +13 -0
  166. package/dist/orchestration_1_0_75/index.js.map +1 -0
  167. package/dist/orchestration_1_0_75/lifecycle.d.ts +51 -0
  168. package/dist/orchestration_1_0_75/lifecycle.d.ts.map +1 -0
  169. package/dist/orchestration_1_0_75/lifecycle.js +981 -0
  170. package/dist/orchestration_1_0_75/lifecycle.js.map +1 -0
  171. package/dist/orchestration_1_0_75/queue.d.ts +20 -0
  172. package/dist/orchestration_1_0_75/queue.d.ts.map +1 -0
  173. package/dist/orchestration_1_0_75/queue.js +894 -0
  174. package/dist/orchestration_1_0_75/queue.js.map +1 -0
  175. package/dist/orchestration_1_0_75/runtime.d.ts +31 -0
  176. package/dist/orchestration_1_0_75/runtime.d.ts.map +1 -0
  177. package/dist/orchestration_1_0_75/runtime.js +239 -0
  178. package/dist/orchestration_1_0_75/runtime.js.map +1 -0
  179. package/dist/orchestration_1_0_75/state.d.ts +214 -0
  180. package/dist/orchestration_1_0_75/state.d.ts.map +1 -0
  181. package/dist/orchestration_1_0_75/state.js +178 -0
  182. package/dist/orchestration_1_0_75/state.js.map +1 -0
  183. package/dist/orchestration_1_0_75/turn.d.ts +34 -0
  184. package/dist/orchestration_1_0_75/turn.d.ts.map +1 -0
  185. package/dist/orchestration_1_0_75/turn.js +1435 -0
  186. package/dist/orchestration_1_0_75/turn.js.map +1 -0
  187. package/dist/orchestration_1_0_75/utils.d.ts +39 -0
  188. package/dist/orchestration_1_0_75/utils.d.ts.map +1 -0
  189. package/dist/orchestration_1_0_75/utils.js +322 -0
  190. package/dist/orchestration_1_0_75/utils.js.map +1 -0
  191. package/dist/orchestration_1_0_76/agents.d.ts +61 -0
  192. package/dist/orchestration_1_0_76/agents.d.ts.map +1 -0
  193. package/dist/orchestration_1_0_76/agents.js +865 -0
  194. package/dist/orchestration_1_0_76/agents.js.map +1 -0
  195. package/dist/orchestration_1_0_76/index.d.ts +24 -0
  196. package/dist/orchestration_1_0_76/index.d.ts.map +1 -0
  197. package/dist/orchestration_1_0_76/index.js +13 -0
  198. package/dist/orchestration_1_0_76/index.js.map +1 -0
  199. package/dist/orchestration_1_0_76/lifecycle.d.ts +51 -0
  200. package/dist/orchestration_1_0_76/lifecycle.d.ts.map +1 -0
  201. package/dist/orchestration_1_0_76/lifecycle.js +981 -0
  202. package/dist/orchestration_1_0_76/lifecycle.js.map +1 -0
  203. package/dist/orchestration_1_0_76/queue.d.ts +20 -0
  204. package/dist/orchestration_1_0_76/queue.d.ts.map +1 -0
  205. package/dist/orchestration_1_0_76/queue.js +894 -0
  206. package/dist/orchestration_1_0_76/queue.js.map +1 -0
  207. package/dist/orchestration_1_0_76/runtime.d.ts +31 -0
  208. package/dist/orchestration_1_0_76/runtime.d.ts.map +1 -0
  209. package/dist/orchestration_1_0_76/runtime.js +239 -0
  210. package/dist/orchestration_1_0_76/runtime.js.map +1 -0
  211. package/dist/orchestration_1_0_76/state.d.ts +214 -0
  212. package/dist/orchestration_1_0_76/state.d.ts.map +1 -0
  213. package/dist/orchestration_1_0_76/state.js +178 -0
  214. package/dist/orchestration_1_0_76/state.js.map +1 -0
  215. package/dist/orchestration_1_0_76/turn.d.ts +34 -0
  216. package/dist/orchestration_1_0_76/turn.d.ts.map +1 -0
  217. package/dist/orchestration_1_0_76/turn.js +1435 -0
  218. package/dist/orchestration_1_0_76/turn.js.map +1 -0
  219. package/dist/orchestration_1_0_76/utils.d.ts +39 -0
  220. package/dist/orchestration_1_0_76/utils.d.ts.map +1 -0
  221. package/dist/orchestration_1_0_76/utils.js +322 -0
  222. package/dist/orchestration_1_0_76/utils.js.map +1 -0
  223. package/dist/orchestration_1_0_77/agents.d.ts +66 -0
  224. package/dist/orchestration_1_0_77/agents.d.ts.map +1 -0
  225. package/dist/orchestration_1_0_77/agents.js +895 -0
  226. package/dist/orchestration_1_0_77/agents.js.map +1 -0
  227. package/dist/orchestration_1_0_77/index.d.ts +24 -0
  228. package/dist/orchestration_1_0_77/index.d.ts.map +1 -0
  229. package/dist/orchestration_1_0_77/index.js +13 -0
  230. package/dist/orchestration_1_0_77/index.js.map +1 -0
  231. package/dist/orchestration_1_0_77/lifecycle.d.ts +51 -0
  232. package/dist/orchestration_1_0_77/lifecycle.d.ts.map +1 -0
  233. package/dist/orchestration_1_0_77/lifecycle.js +981 -0
  234. package/dist/orchestration_1_0_77/lifecycle.js.map +1 -0
  235. package/dist/orchestration_1_0_77/queue.d.ts +20 -0
  236. package/dist/orchestration_1_0_77/queue.d.ts.map +1 -0
  237. package/dist/orchestration_1_0_77/queue.js +894 -0
  238. package/dist/orchestration_1_0_77/queue.js.map +1 -0
  239. package/dist/orchestration_1_0_77/runtime.d.ts +31 -0
  240. package/dist/orchestration_1_0_77/runtime.d.ts.map +1 -0
  241. package/dist/orchestration_1_0_77/runtime.js +239 -0
  242. package/dist/orchestration_1_0_77/runtime.js.map +1 -0
  243. package/dist/orchestration_1_0_77/state.d.ts +214 -0
  244. package/dist/orchestration_1_0_77/state.d.ts.map +1 -0
  245. package/dist/orchestration_1_0_77/state.js +178 -0
  246. package/dist/orchestration_1_0_77/state.js.map +1 -0
  247. package/dist/orchestration_1_0_77/turn.d.ts +34 -0
  248. package/dist/orchestration_1_0_77/turn.d.ts.map +1 -0
  249. package/dist/orchestration_1_0_77/turn.js +1433 -0
  250. package/dist/orchestration_1_0_77/turn.js.map +1 -0
  251. package/dist/orchestration_1_0_77/utils.d.ts +39 -0
  252. package/dist/orchestration_1_0_77/utils.d.ts.map +1 -0
  253. package/dist/orchestration_1_0_77/utils.js +322 -0
  254. package/dist/orchestration_1_0_77/utils.js.map +1 -0
  255. package/dist/reserved-tool-names.d.ts +5 -0
  256. package/dist/reserved-tool-names.d.ts.map +1 -0
  257. package/dist/reserved-tool-names.js +102 -0
  258. package/dist/reserved-tool-names.js.map +1 -0
  259. package/dist/session-manager.d.ts +31 -1
  260. package/dist/session-manager.d.ts.map +1 -1
  261. package/dist/session-manager.js +343 -102
  262. package/dist/session-manager.js.map +1 -1
  263. package/dist/session-proxy.d.ts +28 -3
  264. package/dist/session-proxy.d.ts.map +1 -1
  265. package/dist/session-proxy.js +192 -71
  266. package/dist/session-proxy.js.map +1 -1
  267. package/dist/session-store.d.ts +2 -0
  268. package/dist/session-store.d.ts.map +1 -1
  269. package/dist/session-store.js +18 -2
  270. package/dist/session-store.js.map +1 -1
  271. package/dist/types.d.ts +25 -3
  272. package/dist/types.d.ts.map +1 -1
  273. package/dist/types.js.map +1 -1
  274. package/dist/web/generated-op-methods.d.ts +96 -0
  275. package/dist/web/generated-op-methods.d.ts.map +1 -1
  276. package/dist/web/generated-op-methods.js +24 -0
  277. package/dist/web/generated-op-methods.js.map +1 -1
  278. package/dist/web/web-management-client.d.ts +13 -0
  279. package/dist/web/web-management-client.d.ts.map +1 -1
  280. package/dist/web/web-management-client.js +12 -0
  281. package/dist/web/web-management-client.js.map +1 -1
  282. package/dist/worker.d.ts +13 -3
  283. package/dist/worker.d.ts.map +1 -1
  284. package/dist/worker.js +150 -110
  285. package/dist/worker.js.map +1 -1
  286. package/package.json +4 -3
  287. package/plugins/mgmt/agents/pilotswarm.agent.md +18 -1
  288. package/plugins/mgmt/agents/resourcemgr.agent.md +18 -1
  289. package/plugins/system/agents/default.agent.md +16 -7
@@ -1,3 +1,4 @@
1
+ import { isNativeChildEvent, settleNativeSubagents, guardNativeExternalTools } from "./native-subagents.js";
1
2
  import { defineTool } from "@github/copilot-sdk";
2
3
  import { normalizeCanvasResponseContract as normalizeCanvasContractShared } from "./canvas-app-manifest.js";
3
4
  // One list gates BOTH halves of every manager tool: the declaration in the
@@ -7,6 +8,7 @@ import { holdsManagerBundle } from "./agent-manager-tools.js";
7
8
  // the declarations in systemToolDefs() and the handlers in runTurn().
8
9
  import { holdsProviderTools, providerToolDefs, providerToolsUnavailable } from "./provider-tools.js";
9
10
  import { LiveTurnCoalescer } from "./live-turn.js";
11
+ import { NativeTaskObserver } from "./native-task-observer.js";
10
12
  const DEFAULT_WAIT_TOOL_DESCRIPTION = "The ONLY way to wait, pause, delay, or pause-before-retry inside a turn: a durable timer that survives " +
11
13
  "restarts and may resume on a different worker (set preserveWorkerAffinity=true for node-local work). " +
12
14
  "NEVER use bash sleep, setTimeout, setInterval, or any other external timing mechanism. " +
@@ -615,6 +617,16 @@ export class ManagedSession {
615
617
  }
616
618
  /** Set for the duration of runTurn(); read by the lock-bypassing stop path. */
617
619
  activeTurn = null;
620
+ nativeFeatureRevoked = false;
621
+ canAdmitNativeTask() {
622
+ return this.config.nativeSubagents === "sync" && !this.nativeFeatureRevoked
623
+ && (this.config.nativeFeatureAllowed?.() ?? false);
624
+ }
625
+ /** A cached OFF is sticky for this turn, even if the next poll is ON. */
626
+ refreshNativeFeaturePolicy() {
627
+ if (this.activeTurn && !this.canAdmitNativeTask())
628
+ this.nativeFeatureRevoked = true;
629
+ }
618
630
  /** Set only by requestStop(); classifies the turn unwind as "stopped". */
619
631
  stopRequest = null;
620
632
  /** Resolver for the current turn's completion promise — hang escalation hook. */
@@ -910,11 +922,12 @@ export class ManagedSession {
910
922
  "If the user explicitly asks you to use sub-agents, delegation, fan-out, or parallel processing, you should comply within runtime limits instead of collapsing the work into a direct answer. " +
911
923
  "If the user did not explicitly ask for delegation, use your judgment about whether parallel work is actually helpful. " +
912
924
  "Each agent adds cost, so avoid unnecessary fan-out when delegation was not requested. " +
913
- "For KNOWN user-creatable agents, pass agent_name. The agent's prompt, tools, and task load automatically. " +
925
+ "For KNOWN user-creatable agents, pass agent_name. The agent's instructions, tools, and startup requirement load automatically; task supplies your assignment. " +
926
+ "Before choosing a custom child, check the available static and published agent definitions with ps_list_agents unless the current catalog already identifies a suitable specialist. Select by role, source access, and capabilities, then pass the exact agent_name from the list and task for the assignment. Prefer a suitable named specialist over recreating it as a generic child. " +
914
927
  "You MAY spawn multiple concurrent instances of the same agent_name (e.g. one per bug or per shard); they each get their own conversation. The only caps are the global maximum concurrent sub-agents and the maximum nesting depth. " +
915
928
  "Sub-agents do NOT auto-terminate when they finish their task \u2014 they stay alive idle, ready for follow-up via message_agent. YOU are responsible for closing each child with complete_agent (graceful), cancel_agent (interrupt), or delete_agent (forceful) when you no longer need it. " +
916
929
  "Worker-managed system agents are NOT valid spawn_agent targets; if one is missing, the workers likely need to be restarted. " +
917
- "For CUSTOM agents (ad-hoc tasks), pass task instead. " +
930
+ "For CUSTOM agents (ad-hoc tasks), pass task instead. Do not attach package-owned names through tool_names; select their named agent through ps_list_agents so its instructions, tools, and startup requirement stay together. " +
918
931
  "Call ps_list_agents to see all available named agents you CAN spawn. " +
919
932
  "By default, sub-agents inherit the parent's model. " +
920
933
  "If you want to override the model, call list_available_models first and use only an exact provider:model value returned there. " +
@@ -925,11 +938,11 @@ export class ManagedSession {
925
938
  properties: {
926
939
  agent_name: {
927
940
  type: "string",
928
- description: "Name of a known user-creatable agent to spawn (from ps_list_agents). The agent's system message, tools, and initial prompt are loaded automatically. Do NOT also pass task or system_message. Worker-managed system agents are not valid here.",
941
+ description: "Name of a known user-creatable agent to spawn (from ps_list_agents). The agent's instructions, tools, and startup requirement are loaded automatically. Optionally pass task for a specific assignment; otherwise its initial prompt is used. Do not override system_message or tool_names. Worker-managed system agents are not valid here.",
929
942
  },
930
943
  task: {
931
944
  type: "string",
932
- description: "For custom agents only: a clear description of what the sub-agent should do. This becomes the agent's first prompt. Do NOT use this for known agents — use agent_name instead.",
945
+ description: "The assignment for the child, whether named or custom. This becomes its first prompt while a named agent retains its instructions, tools, and startup requirement. Required for custom agents; optional for named agents, whose initial prompt is the default.",
933
946
  },
934
947
  model: {
935
948
  type: "string",
@@ -1124,9 +1137,29 @@ export class ManagedSession {
1124
1137
  * misclassified as a retryable error.
1125
1138
  */
1126
1139
  async runTurn(prompt, opts) {
1140
+ this.nativeFeatureRevoked = false;
1127
1141
  this.activeTurn = { turnIndex: opts?.turnIndex ?? -1, startedAt: Date.now() };
1142
+ let result;
1143
+ let turnError;
1144
+ let failed = false;
1128
1145
  try {
1129
- const result = await this._runTurnInner(prompt, opts);
1146
+ try {
1147
+ // Also retire native tasks restored from an interrupted worker.
1148
+ if (this.config.nativeSubagents === "sync")
1149
+ await settleNativeSubagents(this.copilotSession);
1150
+ result = await this._runTurnInner(prompt, opts);
1151
+ }
1152
+ catch (err) {
1153
+ failed = true;
1154
+ turnError = err;
1155
+ }
1156
+ // Cleanup failures must escape stop/error classification: the
1157
+ // activity cannot commit a snapshot with native work still live.
1158
+ if (this.config.nativeSubagents === "sync")
1159
+ await settleNativeSubagents(this.copilotSession, {
1160
+ rejectRunning: result?.type === "completed" && !this.stopRequest,
1161
+ });
1162
+ // A stop can arrive DURING cleanup. Classify only after it settles.
1130
1163
  if (this.stopRequest) {
1131
1164
  return {
1132
1165
  type: "stopped",
@@ -1134,14 +1167,10 @@ export class ManagedSession {
1134
1167
  ...(result?.events ? { events: result.events } : {}),
1135
1168
  };
1136
1169
  }
1170
+ if (failed)
1171
+ throw turnError;
1137
1172
  return result;
1138
1173
  }
1139
- catch (err) {
1140
- if (this.stopRequest) {
1141
- return { type: "stopped", reason: this.stopRequest.reason };
1142
- }
1143
- throw err;
1144
- }
1145
1174
  finally {
1146
1175
  this.activeTurn = null;
1147
1176
  this.stopRequest = null;
@@ -1989,14 +2018,15 @@ export class ManagedSession {
1989
2018
  });
1990
2019
  // Build sub-agent tools
1991
2020
  const spawnAgentTool = defineTool("spawn_agent", {
1992
- description: "Spawn a sub-agent. For KNOWN user-creatable agents, pass agent_name ONLY. " +
1993
- "The agent's system message, tools, and initial prompt are loaded automatically from agent_name. " +
1994
- "Do NOT pass task or system_message when using agent_name. " +
2021
+ description: "Spawn a sub-agent. For KNOWN user-creatable agents, pass agent_name. " +
2022
+ "The agent's instructions, tools, and startup requirement load automatically; task supplies your assignment. " +
2023
+ "Do not override system_message or tool_names when using agent_name. " +
2024
+ "Before choosing a custom child, check the available static and published agent definitions with ps_list_agents unless the current catalog already identifies a suitable specialist. Select by role, source access, and capabilities, then pass the exact agent_name from the list and task for the assignment. Prefer a suitable named specialist over recreating it as a generic child. " +
1995
2025
  "Calling spawn_agent does NOT finish your turn. After it succeeds, continue executing the rest of your workflow in the SAME turn unless you intentionally call wait, wait_for_agents, ask_user, or give your final answer. " +
1996
2026
  "Call ps_list_agents to see all available named agents you CAN spawn. " +
1997
2027
  "Worker-managed system agents are not valid spawn_agent targets; if one is missing, the workers likely need to be restarted. " +
1998
- "For CUSTOM agents (ad-hoc tasks), pass task instead — no agent_name is needed. " +
1999
- "Any task you can describe can be spawned as a custom agent; you do not need a skill or pre-configured definition. " +
2028
+ "For CUSTOM agents (ad-hoc tasks), pass task instead — no agent_name is needed. Do not attach package-owned names through tool_names; select their named agent through ps_list_agents so its instructions, tools, and startup requirement stay together. " +
2029
+ "Use a custom agent when no available named definition fits the task. " +
2000
2030
  "If you want a different model, call list_available_models first and use only an exact provider:model value from that list. " +
2001
2031
  "If you want different reasoning power, also use only a reasoning_effort value listed for that model. " +
2002
2032
  "Never invent, guess, or shorten model names.",
@@ -2005,11 +2035,11 @@ export class ManagedSession {
2005
2035
  properties: {
2006
2036
  agent_name: {
2007
2037
  type: "string",
2008
- description: "Name of a known user-creatable agent to spawn (from ps_list_agents). The agent's prompt, tools, and task load automatically. Do NOT also pass task or system_message. Worker-managed system agents are not valid here.",
2038
+ description: "Name of a known user-creatable agent to spawn (from ps_list_agents). Its instructions, tools, and startup requirement load automatically. Optionally pass task for an assignment; otherwise its initial prompt is used. Do not override system_message or tool_names. Worker-managed system agents are not valid here.",
2009
2039
  },
2010
2040
  task: {
2011
2041
  type: "string",
2012
- description: "For custom agents only: a clear description of what the sub-agent should do. Any task can be spawned — no pre-configured agent or skill is required.",
2042
+ description: "The assignment for the child, whether named or custom. A named agent retains its instructions, tools, and startup requirement. Required for custom agents; optional for named agents, whose initial prompt is the default.",
2013
2043
  },
2014
2044
  model: {
2015
2045
  type: "string",
@@ -2047,8 +2077,11 @@ export class ManagedSession {
2047
2077
  handler: async (args) => {
2048
2078
  if (hasTerminalTurnBoundary(turnState))
2049
2079
  return blockedAfterTurnBoundary("spawn_agent");
2080
+ if (Object.hasOwn(args, "required_tool") || Object.hasOwn(args, "requiredTool")) {
2081
+ return "Error: required_tool is no longer supported by spawn_agent. Use ps_list_agents to find a suitable named agent, then pass its exact agent_name and your assignment in task.";
2082
+ }
2050
2083
  if (!args.agent_name && !args.task) {
2051
- return "Error: either agent_name or task is required.";
2084
+ return "Error: agent_name or task is required.";
2052
2085
  }
2053
2086
  const reasoningEffort = args.reasoning_effort ? normalizeReasoningEffort(args.reasoning_effort) : undefined;
2054
2087
  if (args.reasoning_effort && !reasoningEffort) {
@@ -2058,7 +2091,10 @@ export class ManagedSession {
2058
2091
  return "Error: context_tier must be one of default, long_context.";
2059
2092
  }
2060
2093
  if (controlBridge) {
2061
- return await controlBridge.spawnAgent({ ...args, ...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}) });
2094
+ return await controlBridge.spawnAgent({
2095
+ ...args,
2096
+ ...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),
2097
+ });
2062
2098
  }
2063
2099
  turnState.pendingActions.push({
2064
2100
  type: "spawn_agent",
@@ -2500,7 +2536,8 @@ export class ManagedSession {
2500
2536
  // registerTools from the public types (it was always @internal) but
2501
2537
  // ships it unchanged in dist/session.js — cast until a public
2502
2538
  // handler-refresh API exists.
2503
- this.copilotSession.registerTools(allTools);
2539
+ this.copilotSession.registerTools(this.config.nativeSubagents === "sync"
2540
+ ? guardNativeExternalTools(allTools, this.copilotSession.sessionId) : allTools);
2504
2541
  // Collect the final assistant content and all events via on()
2505
2542
  let finalContent;
2506
2543
  const collectedEvents = [];
@@ -2531,6 +2568,19 @@ export class ManagedSession {
2531
2568
  catch { }
2532
2569
  })
2533
2570
  : null;
2571
+ const nativeTasks = this.config.nativeSubagents === "sync"
2572
+ ? new NativeTaskObserver(this.copilotSession, {
2573
+ turnIndex: opts?.turnIndex,
2574
+ emit: (event) => {
2575
+ if (event.eventType !== "session.native_tasks_tick")
2576
+ collectedEvents.push(event);
2577
+ try {
2578
+ opts?.onEvent?.(event);
2579
+ }
2580
+ catch { }
2581
+ },
2582
+ })
2583
+ : null;
2534
2584
  // Note: we used to emit a synthetic `assistant.streaming_progress`
2535
2585
  // heartbeat into CMS for the activity pane. The user found those
2536
2586
  // rows noisy compared to the actual reasoning snapshots, so the
@@ -2657,6 +2707,30 @@ export class ManagedSession {
2657
2707
  eventData.durableSessionId = durableSessionId;
2658
2708
  }
2659
2709
  }
2710
+ nativeTasks?.observe({ ...event, data: eventData });
2711
+ // This empty ephemeral event only invalidates the CLI task
2712
+ // registry. It is neither activity nor durable history.
2713
+ if (eventType === "session.background_tasks_changed")
2714
+ return;
2715
+ if (isNativeChildEvent(event)) {
2716
+ // Child events share the parent subscription. Keep usage
2717
+ // in the existing accounting stream, but namespace child
2718
+ // transcript/tools so they cannot settle parent state or
2719
+ // satisfy a required parent tool invocation.
2720
+ if (/delta|streaming/.test(eventType))
2721
+ return;
2722
+ const nativeEvent = {
2723
+ eventType: eventType === "assistant.usage" || eventType.startsWith("subagent.")
2724
+ ? eventType : `native.${eventType}`,
2725
+ data: { ...eventData, nativeAgentId: event.agentId ?? eventData.nativeAgentId ?? eventData.parentToolCallId },
2726
+ };
2727
+ collectedEvents.push(nativeEvent);
2728
+ try {
2729
+ opts?.onEvent?.(nativeEvent);
2730
+ }
2731
+ catch { }
2732
+ return;
2733
+ }
2660
2734
  const captured = { eventType, data: eventData };
2661
2735
  if (eventType === "session.error" && isBenignPostCompletionQueryError(eventData)) {
2662
2736
  deferredSessionError = captured;
@@ -2782,6 +2856,8 @@ export class ManagedSession {
2782
2856
  }
2783
2857
  }));
2784
2858
  unsubscribers.push(this.copilotSession.on("assistant.reasoning", (event) => {
2859
+ if (isNativeChildEvent(event))
2860
+ return;
2785
2861
  currentReasoning = String(extractReasoningText(event?.data ?? event) || "").trim();
2786
2862
  if (currentReasoning) {
2787
2863
  lastPublishedReasoning = currentReasoning;
@@ -2790,6 +2866,8 @@ export class ManagedSession {
2790
2866
  }));
2791
2867
  for (const eventType of ["assistant.reasoning_delta", "reasoning_delta"]) {
2792
2868
  unsubscribers.push(this.copilotSession.on(eventType, (event) => {
2869
+ if (isNativeChildEvent(event))
2870
+ return;
2793
2871
  currentReasoning = mergeReasoningText(currentReasoning, extractReasoningText(event?.data ?? event));
2794
2872
  publishReasoningSnapshot(eventType);
2795
2873
  }));
@@ -2797,6 +2875,8 @@ export class ManagedSession {
2797
2875
  // Stream deltas to the caller if requested
2798
2876
  if (opts?.onDelta) {
2799
2877
  unsubscribers.push(this.copilotSession.on("assistant.message_delta", (event) => {
2878
+ if (isNativeChildEvent(event))
2879
+ return;
2800
2880
  if (opts.requiredTool && !hasInvokedTool(collectedEvents, opts.requiredTool))
2801
2881
  return;
2802
2882
  if (event.data?.deltaContent) {
@@ -2807,11 +2887,15 @@ export class ManagedSession {
2807
2887
  // Notify caller of tool execution starts
2808
2888
  if (opts?.onToolStart) {
2809
2889
  unsubscribers.push(this.copilotSession.on("tool.execution_start", (event) => {
2890
+ if (isNativeChildEvent(event))
2891
+ return;
2810
2892
  opts.onToolStart(event.data?.toolName ?? "unknown", event.data?.toolArgs);
2811
2893
  }));
2812
2894
  }
2813
2895
  // session.idle = turn finished (normal completion or post-abort)
2814
- unsubscribers.push(this.copilotSession.on("session.idle", () => {
2896
+ unsubscribers.push(this.copilotSession.on("session.idle", (event) => {
2897
+ if (isNativeChildEvent(event))
2898
+ return;
2815
2899
  flushStreamingProgress(true);
2816
2900
  publishReasoningSnapshot("session.idle", true);
2817
2901
  liveTurn?.finishTurn();
@@ -2862,7 +2946,9 @@ export class ManagedSession {
2862
2946
  // the model's response to a mid-turn correction without tearing down the
2863
2947
  // event subscriptions set up above.
2864
2948
  const waitForNextIdle = () => new Promise((resolve) => {
2865
- const unsub = this.copilotSession.on("session.idle", () => {
2949
+ const unsub = this.copilotSession.on("session.idle", (event) => {
2950
+ if (isNativeChildEvent(event))
2951
+ return;
2866
2952
  flushStreamingProgress(true);
2867
2953
  publishReasoningSnapshot("session.idle", true);
2868
2954
  liveTurn?.finishTurn();
@@ -3062,6 +3148,7 @@ export class ManagedSession {
3062
3148
  // live row anyway so reconnecting viewers cannot see stale text.
3063
3149
  liveTurn?.finishTurn();
3064
3150
  liveTurn?.dispose();
3151
+ nativeTasks?.finish(this.stopRequest ? "cancelled" : "interrupted");
3065
3152
  // Always clean up subscriptions
3066
3153
  for (const unsub of unsubscribers)
3067
3154
  unsub();
@@ -3149,6 +3236,10 @@ export class ManagedSession {
3149
3236
  * Update configuration for the next turn.
3150
3237
  */
3151
3238
  updateConfig(config) {
3239
+ if (config.nativeFeatureAllowed !== undefined)
3240
+ this.config.nativeFeatureAllowed = config.nativeFeatureAllowed;
3241
+ if (config.featureToolFingerprint !== undefined)
3242
+ this.config.featureToolFingerprint = config.featureToolFingerprint;
3152
3243
  if (config.model !== undefined)
3153
3244
  this.config.model = config.model;
3154
3245
  if (Object.prototype.hasOwnProperty.call(config, "reasoningEffort"))
@@ -3183,6 +3274,12 @@ export class ManagedSession {
3183
3274
  const nextProviderFingerprint = config.providerFingerprint !== undefined
3184
3275
  ? config.providerFingerprint ?? null
3185
3276
  : currentProviderFingerprint;
3277
+ if (config.nativeSubagents !== undefined
3278
+ && config.nativeSubagents !== (this.config.nativeSubagents ?? "off"))
3279
+ return true;
3280
+ if (config.featureToolFingerprint !== undefined
3281
+ && config.featureToolFingerprint !== this.config.featureToolFingerprint)
3282
+ return true;
3186
3283
  return Boolean((currentModel || nextModel)
3187
3284
  && (currentModel !== nextModel
3188
3285
  || currentReasoningEffort !== nextReasoningEffort