@ponythewhite/base-context 1.0.0 → 1.0.2

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 (285) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/NOTICE +0 -5
  3. package/README.md +44 -27
  4. package/dist/NOTICE +0 -5
  5. package/dist/base-context-runtime/pyproject.toml +1 -1
  6. package/dist/base-context-runtime/src/rlm/__init__.py +7 -5
  7. package/dist/base-context-runtime/test/test_subagent_registry.py +28 -1
  8. package/dist/base-context-runtime/uv.lock +1 -1
  9. package/dist/build-info.json +1 -1
  10. package/dist/bundle/amazon-bedrock.js +21 -0
  11. package/dist/bundle/{anthropic-YY4S534V.js → anthropic-UV5GZDGU.js} +5 -5
  12. package/dist/bundle/{azure-openai-responses-JRP6MIM3.js → azure-openai-responses-WSNPXLYC.js} +6 -6
  13. package/dist/bundle/{bundled-modules-P5HARVZA.js → bundled-modules-PWOGKUQQ.js} +71 -16
  14. package/dist/bundle/chunk-27QCJ2AZ.js +2578 -0
  15. package/dist/bundle/{chunk-BYVP7LWV.js → chunk-44PEHPOG.js} +1916 -4689
  16. package/dist/bundle/{chunk-MZHTNNVA.js → chunk-4GXPNXOJ.js} +8 -0
  17. package/dist/bundle/{chunk-SC5KG5R4.js → chunk-DGNX7HQ3.js} +1 -7
  18. package/dist/bundle/{chunk-A53O363M.js → chunk-GRJFXLBM.js} +0 -1
  19. package/dist/bundle/chunk-HKINIBP4.js +29 -0
  20. package/dist/bundle/{chunk-73DCPU3D.js → chunk-IADCPVEI.js} +1019 -3427
  21. package/dist/bundle/{chunk-UDSW6FNG.js → chunk-KTNETTHI.js} +1 -1
  22. package/dist/bundle/{chunk-U7AUVG3B.js → chunk-VSIYFWYI.js} +24 -6
  23. package/dist/bundle/{chunk-IW77OXFS.js → chunk-W46VZFI6.js} +0 -2099
  24. package/dist/bundle/{cli-main-O4X7GFGY.js → cli-main-4DS7Y3PI.js} +8 -6
  25. package/dist/bundle/cli.js +2 -2
  26. package/dist/bundle/{google-AUTVGDGZ.js → google-T32FMD4G.js} +6 -6
  27. package/dist/bundle/{google-vertex-Q75D7RKS.js → google-vertex-56KP6I3B.js} +3 -3
  28. package/dist/bundle/{main-XKOW2BV6.js → main-SV7JLVEB.js} +7 -5
  29. package/dist/bundle/{mistral-7ESB7QUD.js → mistral-WGBMYIVU.js} +5 -5
  30. package/dist/bundle/{openai-codex-responses-LV3QRPN4.js → openai-codex-responses-PIV2RQ3G.js} +6 -6
  31. package/dist/bundle/{openai-completions-OJECLPXJ.js → openai-completions-64C3JPR4.js} +11 -22
  32. package/dist/bundle/{openai-responses-FN6HZMBC.js → openai-responses-UI7RSTDV.js} +6 -6
  33. package/dist/cli/args.d.ts.map +1 -1
  34. package/dist/cli/args.js +108 -59
  35. package/dist/cli/args.js.map +1 -1
  36. package/dist/cli/daemon-ps.d.ts +4 -3
  37. package/dist/cli/daemon-ps.d.ts.map +1 -1
  38. package/dist/cli/daemon-ps.js +6 -1
  39. package/dist/cli/daemon-ps.js.map +1 -1
  40. package/dist/cli/product-doctor.d.ts +0 -1
  41. package/dist/cli/product-doctor.d.ts.map +1 -1
  42. package/dist/cli/product-doctor.js +6 -3
  43. package/dist/cli/product-doctor.js.map +1 -1
  44. package/dist/config.d.ts +0 -3
  45. package/dist/config.d.ts.map +1 -1
  46. package/dist/config.js +0 -8
  47. package/dist/config.js.map +1 -1
  48. package/dist/core/agent-session-config.d.ts +1 -2
  49. package/dist/core/agent-session-config.d.ts.map +1 -1
  50. package/dist/core/agent-session-config.js +0 -3
  51. package/dist/core/agent-session-config.js.map +1 -1
  52. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  53. package/dist/core/agent-session-runtime.js +5 -4
  54. package/dist/core/agent-session-runtime.js.map +1 -1
  55. package/dist/core/agent-session-services.d.ts +5 -3
  56. package/dist/core/agent-session-services.d.ts.map +1 -1
  57. package/dist/core/agent-session-services.js +2 -27
  58. package/dist/core/agent-session-services.js.map +1 -1
  59. package/dist/core/agent-session.d.ts +10 -6
  60. package/dist/core/agent-session.d.ts.map +1 -1
  61. package/dist/core/agent-session.js +107 -107
  62. package/dist/core/agent-session.js.map +1 -1
  63. package/dist/core/auth-storage.d.ts +8 -35
  64. package/dist/core/auth-storage.d.ts.map +1 -1
  65. package/dist/core/auth-storage.js +33 -243
  66. package/dist/core/auth-storage.js.map +1 -1
  67. package/dist/core/cron-jobs.d.ts.map +1 -1
  68. package/dist/core/cron-jobs.js +7 -1
  69. package/dist/core/cron-jobs.js.map +1 -1
  70. package/dist/core/inference-coordinator.d.ts +6 -1
  71. package/dist/core/inference-coordinator.d.ts.map +1 -1
  72. package/dist/core/inference-coordinator.js +18 -2
  73. package/dist/core/inference-coordinator.js.map +1 -1
  74. package/dist/core/kernel/bootstrap.d.ts.map +1 -1
  75. package/dist/core/kernel/bootstrap.js +2 -2
  76. package/dist/core/kernel/bootstrap.js.map +1 -1
  77. package/dist/core/kernel/repl-manager.d.ts +2 -0
  78. package/dist/core/kernel/repl-manager.d.ts.map +1 -1
  79. package/dist/core/kernel/repl-manager.js +44 -1
  80. package/dist/core/kernel/repl-manager.js.map +1 -1
  81. package/dist/core/logging.d.ts +4 -3
  82. package/dist/core/logging.d.ts.map +1 -1
  83. package/dist/core/logging.js +6 -6
  84. package/dist/core/logging.js.map +1 -1
  85. package/dist/core/mcp/mcp-manager.d.ts.map +1 -1
  86. package/dist/core/mcp/mcp-manager.js +3 -3
  87. package/dist/core/mcp/mcp-manager.js.map +1 -1
  88. package/dist/core/model-registry.d.ts +1 -16
  89. package/dist/core/model-registry.d.ts.map +1 -1
  90. package/dist/core/model-registry.js +88 -196
  91. package/dist/core/model-registry.js.map +1 -1
  92. package/dist/core/model-resolver.d.ts +2 -19
  93. package/dist/core/model-resolver.d.ts.map +1 -1
  94. package/dist/core/model-resolver.js +36 -266
  95. package/dist/core/model-resolver.js.map +1 -1
  96. package/dist/core/provider-contracts.d.ts +5 -6
  97. package/dist/core/provider-contracts.d.ts.map +1 -1
  98. package/dist/core/provider-contracts.js +25 -36
  99. package/dist/core/provider-contracts.js.map +1 -1
  100. package/dist/core/provider-display-names.d.ts.map +1 -1
  101. package/dist/core/provider-display-names.js +0 -2
  102. package/dist/core/provider-display-names.js.map +1 -1
  103. package/dist/core/rlm-max-subagents.d.ts +32 -0
  104. package/dist/core/rlm-max-subagents.d.ts.map +1 -0
  105. package/dist/core/rlm-max-subagents.js +50 -0
  106. package/dist/core/rlm-max-subagents.js.map +1 -0
  107. package/dist/core/rlm-runtime.d.ts +3 -3
  108. package/dist/core/rlm-runtime.d.ts.map +1 -1
  109. package/dist/core/rlm-runtime.js.map +1 -1
  110. package/dist/core/sdk.d.ts +4 -3
  111. package/dist/core/sdk.d.ts.map +1 -1
  112. package/dist/core/sdk.js +27 -14
  113. package/dist/core/sdk.js.map +1 -1
  114. package/dist/core/settings-manager.d.ts +3 -16
  115. package/dist/core/settings-manager.d.ts.map +1 -1
  116. package/dist/core/settings-manager.js +12 -44
  117. package/dist/core/settings-manager.js.map +1 -1
  118. package/dist/core/slash-commands.d.ts.map +1 -1
  119. package/dist/core/slash-commands.js +6 -6
  120. package/dist/core/slash-commands.js.map +1 -1
  121. package/dist/index.d.ts +1 -1
  122. package/dist/index.d.ts.map +1 -1
  123. package/dist/index.js.map +1 -1
  124. package/dist/installer.mjs +2 -3
  125. package/dist/main.d.ts.map +1 -1
  126. package/dist/main.js +39 -34
  127. package/dist/main.js.map +1 -1
  128. package/dist/modes/acp/acp-mode.d.ts.map +1 -1
  129. package/dist/modes/acp/acp-mode.js +1 -1
  130. package/dist/modes/acp/acp-mode.js.map +1 -1
  131. package/dist/modes/agent-connection/daemon-agent-connection.d.ts +6 -2
  132. package/dist/modes/agent-connection/daemon-agent-connection.d.ts.map +1 -1
  133. package/dist/modes/agent-connection/daemon-agent-connection.js +13 -2
  134. package/dist/modes/agent-connection/daemon-agent-connection.js.map +1 -1
  135. package/dist/modes/agent-connection/in-process-agent-connection.d.ts +2 -0
  136. package/dist/modes/agent-connection/in-process-agent-connection.d.ts.map +1 -1
  137. package/dist/modes/agent-connection/in-process-agent-connection.js +6 -0
  138. package/dist/modes/agent-connection/in-process-agent-connection.js.map +1 -1
  139. package/dist/modes/agent-connection/types.d.ts +3 -0
  140. package/dist/modes/agent-connection/types.d.ts.map +1 -1
  141. package/dist/modes/agent-connection/types.js.map +1 -1
  142. package/dist/modes/agents-view/agents-view-mode.d.ts.map +1 -1
  143. package/dist/modes/agents-view/agents-view-mode.js +2 -19
  144. package/dist/modes/agents-view/agents-view-mode.js.map +1 -1
  145. package/dist/modes/daemon/daemon-mode.d.ts +5 -0
  146. package/dist/modes/daemon/daemon-mode.d.ts.map +1 -1
  147. package/dist/modes/daemon/daemon-mode.js +107 -12
  148. package/dist/modes/daemon/daemon-mode.js.map +1 -1
  149. package/dist/modes/daemon/daemon-protocol.d.ts +194 -165
  150. package/dist/modes/daemon/daemon-protocol.d.ts.map +1 -1
  151. package/dist/modes/daemon/daemon-protocol.js +16 -11
  152. package/dist/modes/daemon/daemon-protocol.js.map +1 -1
  153. package/dist/modes/daemon/daemon-rlm-capacity-coordinator.d.ts +19 -0
  154. package/dist/modes/daemon/daemon-rlm-capacity-coordinator.d.ts.map +1 -0
  155. package/dist/modes/daemon/daemon-rlm-capacity-coordinator.js +74 -0
  156. package/dist/modes/daemon/daemon-rlm-capacity-coordinator.js.map +1 -0
  157. package/dist/modes/daemon/daemon-rlm-capacity.d.ts +19 -0
  158. package/dist/modes/daemon/daemon-rlm-capacity.d.ts.map +1 -0
  159. package/dist/modes/daemon/daemon-rlm-capacity.js +85 -0
  160. package/dist/modes/daemon/daemon-rlm-capacity.js.map +1 -0
  161. package/dist/modes/daemon/daemon-session-summarizer.d.ts +2 -3
  162. package/dist/modes/daemon/daemon-session-summarizer.d.ts.map +1 -1
  163. package/dist/modes/daemon/daemon-session-summarizer.js +32 -23
  164. package/dist/modes/daemon/daemon-session-summarizer.js.map +1 -1
  165. package/dist/modes/daemon/daemon-state-root.d.ts +15 -0
  166. package/dist/modes/daemon/daemon-state-root.d.ts.map +1 -0
  167. package/dist/modes/daemon/daemon-state-root.js +40 -0
  168. package/dist/modes/daemon/daemon-state-root.js.map +1 -0
  169. package/dist/modes/daemon/daemon-supervisor-ownership.d.ts +2 -0
  170. package/dist/modes/daemon/daemon-supervisor-ownership.d.ts.map +1 -1
  171. package/dist/modes/daemon/daemon-supervisor-ownership.js +27 -0
  172. package/dist/modes/daemon/daemon-supervisor-ownership.js.map +1 -1
  173. package/dist/modes/daemon/daemon-supervisor.d.ts +10 -1
  174. package/dist/modes/daemon/daemon-supervisor.d.ts.map +1 -1
  175. package/dist/modes/daemon/daemon-supervisor.js +213 -20
  176. package/dist/modes/daemon/daemon-supervisor.js.map +1 -1
  177. package/dist/modes/daemon/daemon-worker-protocol.d.ts +28 -1
  178. package/dist/modes/daemon/daemon-worker-protocol.d.ts.map +1 -1
  179. package/dist/modes/daemon/daemon-worker-protocol.js +16 -2
  180. package/dist/modes/daemon/daemon-worker-protocol.js.map +1 -1
  181. package/dist/modes/daemon/saved-session-catalog.d.ts.map +1 -1
  182. package/dist/modes/daemon/saved-session-catalog.js +2 -0
  183. package/dist/modes/daemon/saved-session-catalog.js.map +1 -1
  184. package/dist/modes/interactive/auth-flows.d.ts +0 -6
  185. package/dist/modes/interactive/auth-flows.d.ts.map +1 -1
  186. package/dist/modes/interactive/auth-flows.js +6 -126
  187. package/dist/modes/interactive/auth-flows.js.map +1 -1
  188. package/dist/modes/interactive/components/configuration-menu.d.ts +3 -0
  189. package/dist/modes/interactive/components/configuration-menu.d.ts.map +1 -1
  190. package/dist/modes/interactive/components/configuration-menu.js +13 -2
  191. package/dist/modes/interactive/components/configuration-menu.js.map +1 -1
  192. package/dist/modes/interactive/components/footer.d.ts +1 -1
  193. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  194. package/dist/modes/interactive/components/footer.js +2 -2
  195. package/dist/modes/interactive/components/footer.js.map +1 -1
  196. package/dist/modes/interactive/components/index.d.ts +0 -1
  197. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  198. package/dist/modes/interactive/components/index.js +0 -1
  199. package/dist/modes/interactive/components/index.js.map +1 -1
  200. package/dist/modes/interactive/components/login-dialog.d.ts +0 -1
  201. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  202. package/dist/modes/interactive/components/login-dialog.js +3 -40
  203. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  204. package/dist/modes/interactive/components/model-selector.d.ts +2 -0
  205. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  206. package/dist/modes/interactive/components/model-selector.js +13 -2
  207. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  208. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  209. package/dist/modes/interactive/components/oauth-selector.js +2 -11
  210. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  211. package/dist/modes/interactive/feature-hints.d.ts.map +1 -1
  212. package/dist/modes/interactive/feature-hints.js +0 -4
  213. package/dist/modes/interactive/feature-hints.js.map +1 -1
  214. package/dist/modes/interactive/interactive-mode.d.ts +3 -12
  215. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  216. package/dist/modes/interactive/interactive-mode.js +81 -507
  217. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  218. package/dist/modes/interactive/onboarding.d.ts +0 -3
  219. package/dist/modes/interactive/onboarding.d.ts.map +1 -1
  220. package/dist/modes/interactive/onboarding.js +0 -17
  221. package/dist/modes/interactive/onboarding.js.map +1 -1
  222. package/dist/modes/rpc/rpc-client.d.ts +4 -1
  223. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  224. package/dist/modes/rpc/rpc-client.js +82 -42
  225. package/dist/modes/rpc/rpc-client.js.map +1 -1
  226. package/dist/node/amazon-bedrock.d.ts +2 -0
  227. package/dist/node/amazon-bedrock.d.ts.map +1 -0
  228. package/dist/node/amazon-bedrock.js +6 -0
  229. package/dist/node/amazon-bedrock.js.map +1 -0
  230. package/dist/product-identity.d.ts +0 -1
  231. package/dist/product-identity.d.ts.map +1 -1
  232. package/dist/product-identity.js +0 -1
  233. package/dist/product-identity.js.map +1 -1
  234. package/docs/development.md +1 -1
  235. package/docs/fork-philosophy.md +4 -8
  236. package/docs/installation.md +83 -62
  237. package/docs/providers.md +23 -25
  238. package/docs/quickstart.md +19 -10
  239. package/docs/rlm-runtime.md +13 -5
  240. package/docs/rpc.md +4 -4
  241. package/docs/sdk.md +20 -11
  242. package/docs/sessions.md +0 -1
  243. package/docs/settings.md +9 -42
  244. package/docs/skills.md +0 -1
  245. package/docs/upstream-0.9.5.md +171 -0
  246. package/docs/usage.md +14 -10
  247. package/package.json +4 -4
  248. package/dist/core/agent-traces.d.ts +0 -149
  249. package/dist/core/agent-traces.d.ts.map +0 -1
  250. package/dist/core/agent-traces.js +0 -904
  251. package/dist/core/agent-traces.js.map +0 -1
  252. package/dist/core/prime-inference-auth.d.ts +0 -70
  253. package/dist/core/prime-inference-auth.d.ts.map +0 -1
  254. package/dist/core/prime-inference-auth.js +0 -352
  255. package/dist/core/prime-inference-auth.js.map +0 -1
  256. package/dist/core/prime-inference-model-selection.d.ts +0 -16
  257. package/dist/core/prime-inference-model-selection.d.ts.map +0 -1
  258. package/dist/core/prime-inference-model-selection.js +0 -16
  259. package/dist/core/prime-inference-model-selection.js.map +0 -1
  260. package/dist/core/prime-inference-models.d.ts +0 -6
  261. package/dist/core/prime-inference-models.d.ts.map +0 -1
  262. package/dist/core/prime-inference-models.js +0 -62
  263. package/dist/core/prime-inference-models.js.map +0 -1
  264. package/dist/core/telemetry.d.ts +0 -95
  265. package/dist/core/telemetry.d.ts.map +0 -1
  266. package/dist/core/telemetry.js +0 -637
  267. package/dist/core/telemetry.js.map +0 -1
  268. package/dist/modes/interactive/components/prime-onboarding-splash.d.ts +0 -39
  269. package/dist/modes/interactive/components/prime-onboarding-splash.d.ts.map +0 -1
  270. package/dist/modes/interactive/components/prime-onboarding-splash.js +0 -286
  271. package/dist/modes/interactive/components/prime-onboarding-splash.js.map +0 -1
  272. package/dist/modes/interactive/components/prime-team-selector.d.ts +0 -30
  273. package/dist/modes/interactive/components/prime-team-selector.d.ts.map +0 -1
  274. package/dist/modes/interactive/components/prime-team-selector.js +0 -166
  275. package/dist/modes/interactive/components/prime-team-selector.js.map +0 -1
  276. package/dist/skills/prime-intellect/SKILL.md +0 -87
  277. package/dist/skills/prime-intellect/references/compute.md +0 -45
  278. package/dist/skills/prime-intellect/references/environments.md +0 -73
  279. package/dist/skills/prime-intellect/references/inference.md +0 -47
  280. package/dist/skills/prime-intellect/references/sandboxes.md +0 -75
  281. package/skills/prime-intellect/SKILL.md +0 -87
  282. package/skills/prime-intellect/references/compute.md +0 -45
  283. package/skills/prime-intellect/references/environments.md +0 -73
  284. package/skills/prime-intellect/references/inference.md +0 -47
  285. package/skills/prime-intellect/references/sandboxes.md +0 -75
@@ -26,7 +26,7 @@ import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
26
26
  import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
27
27
  import { emitSessionShutdownEvent } from "./extensions/runner.js";
28
28
  import { createGoalContextMessage, emptyGoalState, GOAL_CONTEXT_CUSTOM_TYPE, GOAL_CONTEXT_PREVIEW_LABEL, GOAL_SKILL_NAME, GOAL_STATE_CUSTOM_TYPE, goalHostResponse, goalTokenDeltaForUsage, isPersistedGoalState, normalizeGoalState, validateGoalBudget, validateGoalObjective, } from "./goals.js";
29
- import { captureNativeBranchRequests, captureNativeCompactionRequests, captureNativePlannerRequests, captureNativeReviewerRequests, InferenceCoordinator, } from "./inference-coordinator.js";
29
+ import { captureNativeBranchRequests, captureNativeCompactionRequests, captureNativePlannerRequests, captureNativeReviewerRequests, InferenceCoordinator, takeNativeInferenceAuthSource, } from "./inference-coordinator.js";
30
30
  import { snapshotPathIn } from "./kernel/state-snapshot.js";
31
31
  import { convertToLlm, createCompactionOutcomeMessage, createHeartbeatPromptMessage, createRefinementOutcomeMessage, createRlmChildFailureMessage, createRlmChildTerminalNoticeMessage, createSessionSlashCommandMessage, createSessionSlashCommandResultMessage, HEARTBEAT_PROMPT_CUSTOM_TYPE, HEARTBEAT_PROMPT_PREVIEW_LABEL, IPYTHON_STATE_RESTORED_CUSTOM_TYPE, isSessionSlashCommandMessage, RLM_CHILD_FAILURE_CUSTOM_TYPE, RLM_CHILD_TERMINAL_NOTICE_CUSTOM_TYPE, } from "./messages.js";
32
32
  import { throwIfPromptAdmissionCancelled } from "./prompt-admission.js";
@@ -190,6 +190,7 @@ class StaleCompactionOwnerError extends Error {
190
190
  function createPostCompactionContinuationSettlement(resume) {
191
191
  return { ...createAgentMessageDeferred(), resume, settled: false };
192
192
  }
193
+ import { LocalRlmSubagentCapacity, } from "./rlm-max-subagents.js";
193
194
  const KERNEL_STATE_LISTING_TIMEOUT_MS = 5000;
194
195
  const RLM_MAX_DEPTH_STATE_CUSTOM_TYPE = "rlm_max_depth_state";
195
196
  function noopRlmChildAbort() { }
@@ -349,7 +350,6 @@ export class AgentSession {
349
350
  _retryAttempt = 0;
350
351
  _retryPromise = undefined;
351
352
  _retryResolve = undefined;
352
- _retryAuthFailureSources = [];
353
353
  _agentMessageClearEpoch = 0;
354
354
  _agentMessageOutcomes = new Map();
355
355
  _lateIpythonSentAgentMessages = new Map();
@@ -411,8 +411,10 @@ export class AgentSession {
411
411
  _repliedToParentSinceTask;
412
412
  _parentReplyCount = 0;
413
413
  _subagentRuntimeHost;
414
- _rlmChildAdmission;
414
+ _rlmChildAdmissions = new Set();
415
+ _rlmSubagentCapacity;
415
416
  _rlmParentAdmission;
417
+ _rlmRootAdmission;
416
418
  _rlmResidentDisposalComplete = false;
417
419
  _releaseRlmResidentCapacity;
418
420
  _activeRlmChildRuns = new Map();
@@ -474,6 +476,12 @@ export class AgentSession {
474
476
  _serializedPlanClaim;
475
477
  _serializedExplicitRefineOptions;
476
478
  constructor(config) {
479
+ this._rlmRootAdmission = config.rlmRootAdmission;
480
+ this._rlmRootAdmission?.bind(this);
481
+ this._rlmSubagentCapacity =
482
+ config.rlmChildAdmission?.parent._rlmSubagentCapacity ??
483
+ config.rlmSubagentCapacity ??
484
+ new LocalRlmSubagentCapacity(config.settingsManager);
477
485
  this._rlmParentAdmission = config.rlmChildAdmission;
478
486
  this._rlmParentAdmission?.bind(this);
479
487
  this.agent = config.agent;
@@ -568,7 +576,19 @@ export class AgentSession {
568
576
  maxEntries: limits.maxMessages,
569
577
  maxSourceBytes: limits.maxSourceBytes,
570
578
  });
571
- const captured = this.requests.capture(compaction);
579
+ let captured;
580
+ try {
581
+ captured = this.requests.capture(compaction);
582
+ }
583
+ catch (error) {
584
+ try {
585
+ await compaction.release();
586
+ }
587
+ catch (cleanupError) {
588
+ throw new AggregateError([error, cleanupError], "Canonical context capture and release failed");
589
+ }
590
+ throw error;
591
+ }
572
592
  try {
573
593
  const messages = await captured.readHistory(async (view) => {
574
594
  const sameSource = controls?.sessionId === view.source.sessionId && controls?.sessionFile === view.source.sessionFile;
@@ -836,7 +856,6 @@ export class AgentSession {
836
856
  });
837
857
  }
838
858
  this._retryAttempt = 0;
839
- this._retryAuthFailureSources = [];
840
859
  this._resolveRetry();
841
860
  },
842
861
  });
@@ -3673,6 +3692,13 @@ export class AgentSession {
3673
3692
  record.started = true;
3674
3693
  }
3675
3694
  }
3695
+ if (event.type === "message_end" && event.message.role === "assistant") {
3696
+ // Native result settlement precedes message publication. Keep auth failure
3697
+ // ownership independent of later message replacement, cancellation, or retry cleanup.
3698
+ const source = takeNativeInferenceAuthSource(event.message);
3699
+ if (source && this._isConcreteProviderAuthFailure(event.message))
3700
+ this._markProviderAuthStale(source);
3701
+ }
3676
3702
  const compactionOwner = event.type === "agent_end" ? this._invocationCompactionOwner : undefined;
3677
3703
  const job = this._agentEventQueue.then(() => this._processAgentEvent(event, nativeMessageWrite, compactionOwner), () => this._processAgentEvent(event, nativeMessageWrite, compactionOwner));
3678
3704
  this._agentEventQueue = job;
@@ -3754,7 +3780,6 @@ export class AgentSession {
3754
3780
  });
3755
3781
  this._retryAttempt = 0;
3756
3782
  }
3757
- this._retryAuthFailureSources = [];
3758
3783
  this._resolveRetry();
3759
3784
  await this._emitExtensionEvent(event);
3760
3785
  this._emit(event);
@@ -3849,9 +3874,6 @@ export class AgentSession {
3849
3874
  if (assistantMsg.stopReason !== "error") {
3850
3875
  this._overflowRecovery = "idle";
3851
3876
  }
3852
- if (this._isConcreteProviderAuthFailure(assistantMsg)) {
3853
- this._captureRetryAuthFailureSource(assistantMsg);
3854
- }
3855
3877
  // Reset retry counter immediately on successful assistant response
3856
3878
  // This prevents accumulation across multiple LLM calls within a turn
3857
3879
  if (assistantMsg.stopReason !== "error" &&
@@ -3863,7 +3885,6 @@ export class AgentSession {
3863
3885
  attempt: this._retryAttempt,
3864
3886
  });
3865
3887
  this._retryAttempt = 0;
3866
- this._retryAuthFailureSources = [];
3867
3888
  }
3868
3889
  if ((await this._accountGoalUsageForAssistantMessage(assistantMsg)) && !this._invocationOutputRefused) {
3869
3890
  const message = createGoalContextMessage(this._goalState, "budget_limit");
@@ -3886,12 +3907,6 @@ export class AgentSession {
3886
3907
  this._resolveRetry();
3887
3908
  return;
3888
3909
  }
3889
- if (this._isConcreteProviderAuthFailure(msg)) {
3890
- this._markProviderAuthStaleForRetryFailure(msg, {
3891
- markAuthStaleOnFailure: true,
3892
- authSourceTokens: this._retryAuthFailureSources,
3893
- });
3894
- }
3895
3910
  const compactionWillRetry = await this._checkCompaction(msg, true, true, compactionOwner);
3896
3911
  if (compactionWillRetry && this._retryAttempt > 0) {
3897
3912
  return;
@@ -4087,7 +4102,8 @@ export class AgentSession {
4087
4102
  * the latest state reaches disk instead of racing process exit.
4088
4103
  */
4089
4104
  async disposeAsync(options) {
4090
- this._rlmChildAdmission?.cancel("Parent session disposed");
4105
+ for (const admission of this._rlmChildAdmissions)
4106
+ admission.cancel("Parent session disposed");
4091
4107
  if (this._disposeAsyncPromise)
4092
4108
  return this._disposeAsyncPromise;
4093
4109
  this.closeAutoRefineAdmission();
@@ -4114,7 +4130,8 @@ export class AgentSession {
4114
4130
  if (errors.length > 1)
4115
4131
  throw new AggregateError(errors, "Session disposal failed");
4116
4132
  this._rlmResidentDisposalComplete = true;
4117
- this._releaseRlmResidentCapacity?.();
4133
+ await this._releaseRlmResidentCapacity?.();
4134
+ await this._rlmRootAdmission?.release();
4118
4135
  })();
4119
4136
  return this._disposeAsyncPromise;
4120
4137
  }
@@ -4211,7 +4228,7 @@ export class AgentSession {
4211
4228
  throw new AggregateError(distinct, "Session refinement drain failed");
4212
4229
  }
4213
4230
  async _disposeAsyncOnce(kernelSnapshot) {
4214
- const admission = this._rlmChildAdmission;
4231
+ const admissions = [...this._rlmChildAdmissions];
4215
4232
  const errors = [];
4216
4233
  const drain = async (operation) => {
4217
4234
  try {
@@ -4232,10 +4249,11 @@ export class AgentSession {
4232
4249
  // Join it before disposing any runtime resources it may still be constructing.
4233
4250
  if (this._initialization)
4234
4251
  await Promise.allSettled([this._initialization]);
4235
- const admittedChild = admission?.session;
4236
- // Includes a native child constructed but not yet published by its factory.
4237
- if (admittedChild)
4238
- await drain(() => admittedChild.disposeAsync());
4252
+ // Includes native children constructed but not yet published by their factories.
4253
+ for (const admission of admissions) {
4254
+ if (admission.session)
4255
+ await drain(() => admission.session?.disposeAsync());
4256
+ }
4239
4257
  for (const run of [...this._activeRlmChildRuns.values()]) {
4240
4258
  const childSession = run.session;
4241
4259
  if (!childSession)
@@ -4267,9 +4285,10 @@ export class AgentSession {
4267
4285
  for (const task of [...this._rlmRunTasks])
4268
4286
  await drain(() => task);
4269
4287
  }
4270
- await drain(() => admission?.settlement);
4271
- if (admission?.session && admission.session !== admittedChild) {
4272
- await drain(() => admission.session?.disposeAsync());
4288
+ for (const admission of admissions) {
4289
+ await drain(() => admission.settlement);
4290
+ if (admission.session)
4291
+ await drain(() => admission.session?.disposeAsync());
4273
4292
  }
4274
4293
  await drain(() => this.agent.waitForIdle());
4275
4294
  await drain(() => this._compactionOperation);
@@ -6938,9 +6957,9 @@ export class AgentSession {
6938
6957
  const current = () => !owner || this._isCompactionOwnerCurrent(owner);
6939
6958
  while (current() && (settlement === undefined || this._postCompactionContinuationSettlement === settlement)) {
6940
6959
  if (this._actionStore.queuedActions().length > 0) {
6941
- if (this._sessionInputPumpSuspended ||
6942
- this._queuedWorkPauses.size > 0 ||
6943
- (settlement && this._sessionInputAdmissionPauses.size > 0)) {
6960
+ // A blocked pump must wait for a checkpoint change, not spin in
6961
+ // microtasks and starve the IO that clears its busy state.
6962
+ if (this._isBusyForSessionInput("pump") || (settlement && this._sessionInputAdmissionPauses.size > 0)) {
6944
6963
  let wake = () => { };
6945
6964
  const changed = new Promise((resolve) => {
6946
6965
  wake = resolve;
@@ -7135,7 +7154,7 @@ export class AgentSession {
7135
7154
  throw new Error(`No API key for ${model.provider}/${model.id}`);
7136
7155
  }
7137
7156
  if (!(await this._modelRegistry.canUseModel(model))) {
7138
- throw new Error(`Model "${model.provider}/${model.id}" is not available for the current Prime team.`);
7157
+ throw new Error(`Model "${model.provider}/${model.id}" is not available with the configured authentication.`);
7139
7158
  }
7140
7159
  if (this.sessionManager.getSessionId() !== sourceId || this.sessionManager.getSessionFile() !== sourceFile) {
7141
7160
  throw new Error("Session source changed during model selection");
@@ -9850,25 +9869,27 @@ export class AgentSession {
9850
9869
  get hasRlmParentAdmission() {
9851
9870
  return this._releaseRlmResidentCapacity !== undefined;
9852
9871
  }
9853
- /** Reserve before setup awaits. The concrete parent lifetime owns this one slot. */
9854
- reserveRlmChildAdmission() {
9872
+ /** Reserve before setup awaits. Capacity remains owned until real cleanup completes. */
9873
+ async reserveRlmChildAdmission() {
9855
9874
  if (this._disposed || this._disposing || this._disposeAsyncPromise) {
9856
9875
  throw new Error("Cannot spawn a subagent after its parent was disposed");
9857
9876
  }
9858
- if (this._rlmChildAdmission) {
9859
- throw new Error("RLM resident child limit reached (one child per parent); dispose or passivate the existing child first");
9860
- }
9861
9877
  const controller = new AbortController();
9862
9878
  const settlement = createAgentMessageDeferred();
9863
9879
  let child;
9864
9880
  let settled = false;
9865
9881
  let factoryClaimed = false;
9866
9882
  let unboundCleanupComplete = true;
9867
- const release = () => {
9883
+ let capacity;
9884
+ let capacityRelease;
9885
+ const release = async () => {
9868
9886
  if (!settled || (child ? !child._rlmResidentDisposalComplete : !unboundCleanupComplete))
9869
9887
  return;
9870
- if (this._rlmChildAdmission === admission)
9871
- this._rlmChildAdmission = undefined;
9888
+ if (capacity) {
9889
+ capacityRelease ??= capacity.release();
9890
+ await capacityRelease;
9891
+ }
9892
+ this._rlmChildAdmissions.delete(admission);
9872
9893
  if (child?._releaseRlmResidentCapacity === release)
9873
9894
  child._releaseRlmResidentCapacity = undefined;
9874
9895
  if (child?._rlmParentAdmission === admission)
@@ -9888,20 +9909,21 @@ export class AgentSession {
9888
9909
  if (this._disposed ||
9889
9910
  this._disposing ||
9890
9911
  this._disposeAsyncPromise ||
9891
- this._rlmChildAdmission !== admission) {
9912
+ !this._rlmChildAdmissions.has(admission)) {
9892
9913
  throw new Error("RLM child admission is no longer current");
9893
9914
  }
9894
9915
  },
9895
9916
  bind: (session) => {
9896
- if (this._rlmChildAdmission !== admission)
9917
+ if (!this._rlmChildAdmissions.has(admission))
9897
9918
  throw new Error("RLM child admission is no longer current");
9898
9919
  if ((child && child !== session) ||
9899
9920
  (session._releaseRlmResidentCapacity && session._releaseRlmResidentCapacity !== release)) {
9900
9921
  throw new Error("RLM child already belongs to another resident admission");
9901
9922
  }
9902
9923
  child = session;
9924
+ session._rlmParentAdmission = admission;
9925
+ session._rlmSubagentCapacity = this._rlmSubagentCapacity;
9903
9926
  session._releaseRlmResidentCapacity = release;
9904
- release();
9905
9927
  },
9906
9928
  beginSetup: () => {
9907
9929
  if (settled || child)
@@ -9914,14 +9936,18 @@ export class AgentSession {
9914
9936
  admission.beginSetup();
9915
9937
  factoryClaimed = true;
9916
9938
  },
9917
- confirmUnboundCleanup: () => {
9939
+ confirmUnboundCleanup: async () => {
9918
9940
  unboundCleanupComplete = true;
9919
- release();
9941
+ await release();
9920
9942
  },
9921
- settle: () => {
9943
+ settle: async () => {
9922
9944
  settled = true;
9923
- settlement.resolve();
9924
- release();
9945
+ try {
9946
+ await release();
9947
+ }
9948
+ finally {
9949
+ settlement.resolve();
9950
+ }
9925
9951
  },
9926
9952
  cancel: (reason) => {
9927
9953
  if (settled || controller.signal.aborted)
@@ -9931,8 +9957,16 @@ export class AgentSession {
9931
9957
  return true;
9932
9958
  },
9933
9959
  };
9934
- this._rlmChildAdmission = admission;
9935
- return admission;
9960
+ this._rlmChildAdmissions.add(admission);
9961
+ try {
9962
+ capacity = await this._rlmSubagentCapacity.reserve();
9963
+ admission.assertCurrent();
9964
+ return admission;
9965
+ }
9966
+ catch (error) {
9967
+ await admission.settle();
9968
+ throw error;
9969
+ }
9936
9970
  }
9937
9971
  _createRlmSubagentRuntimeOptions(options) {
9938
9972
  const requestTokenBudget = this.requests.getRequestTokenBudgetOptions();
@@ -10046,7 +10080,7 @@ export class AgentSession {
10046
10080
  await failedChild.disposeAsync();
10047
10081
  else {
10048
10082
  await childSessionManager.close();
10049
- options.admission.confirmUnboundCleanup();
10083
+ await options.admission.confirmUnboundCleanup();
10050
10084
  }
10051
10085
  }
10052
10086
  catch (cleanupError) {
@@ -10066,7 +10100,8 @@ export class AgentSession {
10066
10100
  this._scheduleGoalContinuationAfterRlmWork();
10067
10101
  }
10068
10102
  _cancelActiveRlmChildRuns(reason) {
10069
- this._rlmChildAdmission?.cancel(reason);
10103
+ for (const admission of this._rlmChildAdmissions)
10104
+ admission.cancel(reason);
10070
10105
  for (const run of this._activeRlmChildRuns.values()) {
10071
10106
  this._cancelRlmChildRun(run, reason);
10072
10107
  }
@@ -10488,15 +10523,15 @@ export class AgentSession {
10488
10523
  return false;
10489
10524
  }
10490
10525
  if (!session._rlmResidentDisposalComplete) {
10491
- if (this._rlmChildAdmission)
10492
- this._rlmChildAdmission.bind(session);
10526
+ if (session._rlmParentAdmission?.parent === this)
10527
+ session._rlmParentAdmission.bind(session);
10493
10528
  else {
10494
- const admission = this.reserveRlmChildAdmission();
10529
+ const admission = await this.reserveRlmChildAdmission();
10495
10530
  try {
10496
10531
  admission.bind(session);
10497
10532
  }
10498
10533
  finally {
10499
- admission.settle();
10534
+ await admission.settle();
10500
10535
  }
10501
10536
  }
10502
10537
  }
@@ -10624,8 +10659,9 @@ export class AgentSession {
10624
10659
  /** True when any direct or nested subagent is still running or queued. */
10625
10660
  hasRunningRlmChildren() {
10626
10661
  for (const session of this._rlmSubtreeSessions()) {
10627
- if (session._rlmChildAdmission?.pending)
10628
- return true;
10662
+ for (const admission of session._rlmChildAdmissions)
10663
+ if (admission.pending)
10664
+ return true;
10629
10665
  for (const run of session._activeRlmChildRuns.values()) {
10630
10666
  if (run.status === "running" || run.status === "queued") {
10631
10667
  return true;
@@ -10773,8 +10809,9 @@ export class AgentSession {
10773
10809
  cancelRunningRlmDescendants(reason = "Cancelled by user") {
10774
10810
  let cancelled = false;
10775
10811
  for (const session of this._rlmSubtreeSessions()) {
10776
- if (session._rlmChildAdmission?.cancel(reason))
10777
- cancelled = true;
10812
+ for (const admission of session._rlmChildAdmissions)
10813
+ if (admission.cancel(reason))
10814
+ cancelled = true;
10778
10815
  for (const run of session._activeRlmChildRuns.values()) {
10779
10816
  if (session._cancelRlmChildRun(run, reason))
10780
10817
  cancelled = true;
@@ -11002,7 +11039,7 @@ export class AgentSession {
11002
11039
  admission.bind(childRuntime.session);
11003
11040
  }
11004
11041
  finally {
11005
- admission.settle();
11042
+ await admission.settle();
11006
11043
  }
11007
11044
  admission.assertCurrent();
11008
11045
  const child = childRuntime.session;
@@ -11289,7 +11326,7 @@ export class AgentSession {
11289
11326
  };
11290
11327
  }
11291
11328
  async runRlmChild(prompt, kwargs = {}, spawnCode) {
11292
- const admission = this.reserveRlmChildAdmission();
11329
+ const admission = await this.reserveRlmChildAdmission();
11293
11330
  const start = this._startRlmChildRun(prompt, admission, kwargs, spawnCode);
11294
11331
  // Join pre-runtime name/model work during disposal as well as the detached task.
11295
11332
  const pending = start.then(() => undefined, () => undefined);
@@ -11298,7 +11335,7 @@ export class AgentSession {
11298
11335
  return await start;
11299
11336
  }
11300
11337
  catch (error) {
11301
- admission.settle();
11338
+ await admission.settle();
11302
11339
  throw error;
11303
11340
  }
11304
11341
  finally {
@@ -11348,56 +11385,15 @@ export class AgentSession {
11348
11385
  return (/\b(?:401|403)\b/.test(message.errorMessage) &&
11349
11386
  /auth|unauthori[sz]ed|forbidden|api.?key|token|credential/i.test(message.errorMessage));
11350
11387
  }
11351
- _captureRetryAuthFailureSource(message) {
11352
- const token = this._modelRegistry.getCurrentProviderAuthSourceToken(message.provider);
11353
- if (!token) {
11354
- return undefined;
11355
- }
11356
- if (!this._retryAuthFailureSources.some((existing) => existing.provider === token.provider &&
11357
- existing.source === token.source &&
11358
- existing.identityFingerprint === token.identityFingerprint &&
11359
- existing.valueFingerprint === token.valueFingerprint)) {
11360
- this._retryAuthFailureSources.push(token);
11361
- }
11362
- return token;
11363
- }
11364
- _markProviderAuthStale(message, authSourceTokens) {
11365
- if (authSourceTokens && authSourceTokens.length > 0) {
11366
- let marked = false;
11367
- for (const token of authSourceTokens) {
11368
- marked = this._modelRegistry.markProviderAuthSourceStale(token) || marked;
11369
- }
11370
- if (marked) {
11371
- this._emit({
11372
- type: "auth_stale",
11373
- provider: message.provider,
11374
- sourceTokens: authSourceTokens,
11375
- });
11376
- }
11377
- return marked;
11378
- }
11379
- const marked = this._modelRegistry.markProviderAuthStale(message.provider);
11380
- if (marked) {
11381
- this._emit({ type: "auth_stale", provider: message.provider });
11388
+ _markProviderAuthStale(source) {
11389
+ if (this._modelRegistry.markProviderAuthSourceStale(source)) {
11390
+ this._emit({ type: "auth_stale", provider: source.provider, sourceTokens: [source] });
11382
11391
  }
11383
- return marked;
11384
- }
11385
- _markProviderAuthStaleForRetryFailure(message, options) {
11386
- const authSourceTokens = this._retryAuthFailureSources.length > 0 ? this._retryAuthFailureSources : options?.authSourceTokens;
11387
- if ((authSourceTokens?.length ?? 0) > 0 || options?.markAuthStaleOnFailure) {
11388
- const marked = this._markProviderAuthStale(message, authSourceTokens);
11389
- if (marked && message.errorMessage) {
11390
- message.errorMessage = addLoginGuidanceToAuthError(message.errorMessage);
11391
- }
11392
- return marked;
11393
- }
11394
- return false;
11395
11392
  }
11396
11393
  _finishActiveRetryWithFailure(message) {
11397
11394
  if (this._retryAttempt === 0) {
11398
11395
  return;
11399
11396
  }
11400
- this._markProviderAuthStaleForRetryFailure(message);
11401
11397
  this._emit({
11402
11398
  type: "auto_retry_end",
11403
11399
  success: false,
@@ -11405,7 +11401,6 @@ export class AgentSession {
11405
11401
  finalError: message.errorMessage,
11406
11402
  });
11407
11403
  this._retryAttempt = 0;
11408
- this._retryAuthFailureSources = [];
11409
11404
  }
11410
11405
  async _handleRetryableError(message, signal) {
11411
11406
  const settings = this.settingsManager.getRetrySettings();
@@ -11468,7 +11463,6 @@ export class AgentSession {
11468
11463
  });
11469
11464
  this._retryAttempt = 0;
11470
11465
  }
11471
- this._retryAuthFailureSources = [];
11472
11466
  this._resolveRetry();
11473
11467
  }
11474
11468
  async waitForRetry() {
@@ -11695,6 +11689,12 @@ export class AgentSession {
11695
11689
  this.agent.state.messages.push(bashMessage);
11696
11690
  }
11697
11691
  }
11692
+ getRlmMaxSubagentsStatus() {
11693
+ return this._rlmSubagentCapacity.getStatus();
11694
+ }
11695
+ setRlmMaxSubagents(maxSubagents) {
11696
+ return this._rlmSubagentCapacity.setMaxSubagents(maxSubagents);
11697
+ }
11698
11698
  getRlmMaxDepthStatus() {
11699
11699
  return { maxDepth: this._rlmMaxDepth, source: this._rlmMaxDepthSource };
11700
11700
  }