apex-code 0.0.6 → 0.1.1

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 (234) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +8 -9
  3. package/dist/cli/args.d.ts +0 -12
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +2 -32
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +4 -130
  9. package/dist/cli.js.map +1 -1
  10. package/dist/config.d.ts +1 -1
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +1 -1
  13. package/dist/config.js.map +1 -1
  14. package/dist/core/agent-session-services.d.ts.map +1 -1
  15. package/dist/core/agent-session-services.js +0 -8
  16. package/dist/core/agent-session-services.js.map +1 -1
  17. package/dist/core/delegation/agents.d.ts.map +1 -1
  18. package/dist/core/delegation/agents.js +2 -1
  19. package/dist/core/delegation/agents.js.map +1 -1
  20. package/dist/core/delegation/runtime.d.ts +6 -14
  21. package/dist/core/delegation/runtime.d.ts.map +1 -1
  22. package/dist/core/delegation/runtime.js +1 -2
  23. package/dist/core/delegation/runtime.js.map +1 -1
  24. package/dist/core/extensions/loader.d.ts.map +1 -1
  25. package/dist/core/extensions/loader.js +3 -4
  26. package/dist/core/extensions/loader.js.map +1 -1
  27. package/dist/core/extensions/source-runtime.d.ts +4 -5
  28. package/dist/core/extensions/source-runtime.d.ts.map +1 -1
  29. package/dist/core/extensions/source-runtime.js +4 -5
  30. package/dist/core/extensions/source-runtime.js.map +1 -1
  31. package/dist/core/formatter-lifecycle.d.ts +2 -1
  32. package/dist/core/formatter-lifecycle.d.ts.map +1 -1
  33. package/dist/core/formatter-lifecycle.js +2 -1
  34. package/dist/core/formatter-lifecycle.js.map +1 -1
  35. package/dist/core/hooks/types.d.ts +2 -3
  36. package/dist/core/hooks/types.d.ts.map +1 -1
  37. package/dist/core/hooks/types.js +2 -3
  38. package/dist/core/hooks/types.js.map +1 -1
  39. package/dist/core/http-idle-timeout.d.ts +3 -5
  40. package/dist/core/http-idle-timeout.d.ts.map +1 -1
  41. package/dist/core/http-idle-timeout.js +3 -5
  42. package/dist/core/http-idle-timeout.js.map +1 -1
  43. package/dist/core/mcp/config.d.ts +18 -1
  44. package/dist/core/mcp/config.d.ts.map +1 -1
  45. package/dist/core/mcp/config.js +24 -7
  46. package/dist/core/mcp/config.js.map +1 -1
  47. package/dist/core/mcp/connector.d.ts +2 -3
  48. package/dist/core/mcp/connector.d.ts.map +1 -1
  49. package/dist/core/mcp/connector.js.map +1 -1
  50. package/dist/core/mcp/oauth/authorize.d.ts +2 -0
  51. package/dist/core/mcp/oauth/authorize.d.ts.map +1 -1
  52. package/dist/core/mcp/oauth/authorize.js +5 -2
  53. package/dist/core/mcp/oauth/authorize.js.map +1 -1
  54. package/dist/core/mcp/oauth/mcp-token.d.ts +4 -6
  55. package/dist/core/mcp/oauth/mcp-token.d.ts.map +1 -1
  56. package/dist/core/mcp/oauth/mcp-token.js +5 -7
  57. package/dist/core/mcp/oauth/mcp-token.js.map +1 -1
  58. package/dist/core/mcp/runtime.d.ts +1 -0
  59. package/dist/core/mcp/runtime.d.ts.map +1 -1
  60. package/dist/core/mcp/runtime.js +2 -1
  61. package/dist/core/mcp/runtime.js.map +1 -1
  62. package/dist/core/package-manager.d.ts.map +1 -1
  63. package/dist/core/package-manager.js +0 -15
  64. package/dist/core/package-manager.js.map +1 -1
  65. package/dist/core/permissions/store.d.ts +6 -11
  66. package/dist/core/permissions/store.d.ts.map +1 -1
  67. package/dist/core/permissions/store.js +23 -51
  68. package/dist/core/permissions/store.js.map +1 -1
  69. package/dist/core/project-resources.d.ts +62 -0
  70. package/dist/core/project-resources.d.ts.map +1 -0
  71. package/dist/core/project-resources.js +42 -0
  72. package/dist/core/project-resources.js.map +1 -0
  73. package/dist/core/sdk.d.ts +1 -9
  74. package/dist/core/sdk.d.ts.map +1 -1
  75. package/dist/core/sdk.js +10 -35
  76. package/dist/core/sdk.js.map +1 -1
  77. package/dist/core/session-share.d.ts +6 -8
  78. package/dist/core/session-share.d.ts.map +1 -1
  79. package/dist/core/session-share.js +9 -12
  80. package/dist/core/session-share.js.map +1 -1
  81. package/dist/core/settings-manager.d.ts +0 -21
  82. package/dist/core/settings-manager.d.ts.map +1 -1
  83. package/dist/core/settings-manager.js +4 -12
  84. package/dist/core/settings-manager.js.map +1 -1
  85. package/dist/core/tools/bash.d.ts.map +1 -1
  86. package/dist/core/tools/bash.js +0 -47
  87. package/dist/core/tools/bash.js.map +1 -1
  88. package/dist/core/tools/web-fetch.d.ts.map +1 -1
  89. package/dist/core/tools/web-fetch.js +4 -8
  90. package/dist/core/tools/web-fetch.js.map +1 -1
  91. package/dist/core/tools/web-search-exa.d.ts +3 -6
  92. package/dist/core/tools/web-search-exa.d.ts.map +1 -1
  93. package/dist/core/tools/web-search-exa.js +5 -8
  94. package/dist/core/tools/web-search-exa.js.map +1 -1
  95. package/dist/core/trust-manager.d.ts +6 -5
  96. package/dist/core/trust-manager.d.ts.map +1 -1
  97. package/dist/core/trust-manager.js +42 -19
  98. package/dist/core/trust-manager.js.map +1 -1
  99. package/dist/core/web-search-provider.d.ts +0 -10
  100. package/dist/core/web-search-provider.d.ts.map +1 -1
  101. package/dist/core/web-search-provider.js +2 -16
  102. package/dist/core/web-search-provider.js.map +1 -1
  103. package/dist/main.d.ts +0 -1
  104. package/dist/main.d.ts.map +1 -1
  105. package/dist/main.js +2 -3
  106. package/dist/main.js.map +1 -1
  107. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  108. package/dist/modes/interactive/components/settings-selector.js +1 -1
  109. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  110. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  111. package/dist/modes/interactive/interactive-mode.js +0 -29
  112. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  113. package/dist/modes/rpc/rpc-types.d.ts +1 -1
  114. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  115. package/dist/modes/rpc/rpc-types.js.map +1 -1
  116. package/dist/utils/tools-manager.d.ts +0 -25
  117. package/dist/utils/tools-manager.d.ts.map +1 -1
  118. package/dist/utils/tools-manager.js +3 -52
  119. package/dist/utils/tools-manager.js.map +1 -1
  120. package/dist/utils/version-check.d.ts +0 -2
  121. package/dist/utils/version-check.d.ts.map +1 -1
  122. package/dist/utils/version-check.js +0 -2
  123. package/dist/utils/version-check.js.map +1 -1
  124. package/docs/containerization.md +8 -4
  125. package/docs/sdk.md +17 -24
  126. package/docs/security.md +7 -5
  127. package/docs/settings.md +2 -7
  128. package/docs/skills.md +4 -7
  129. package/npm-shrinkwrap.json +5 -5
  130. package/package.json +2 -2
  131. package/dist/core/sandbox/bwrap-arguments.d.ts +0 -41
  132. package/dist/core/sandbox/bwrap-arguments.d.ts.map +0 -1
  133. package/dist/core/sandbox/bwrap-arguments.js +0 -136
  134. package/dist/core/sandbox/bwrap-arguments.js.map +0 -1
  135. package/dist/core/sandbox/child-entry.d.ts +0 -2
  136. package/dist/core/sandbox/child-entry.d.ts.map +0 -1
  137. package/dist/core/sandbox/child-entry.js +0 -24
  138. package/dist/core/sandbox/child-entry.js.map +0 -1
  139. package/dist/core/sandbox/cli-launch.d.ts +0 -162
  140. package/dist/core/sandbox/cli-launch.d.ts.map +0 -1
  141. package/dist/core/sandbox/cli-launch.js +0 -366
  142. package/dist/core/sandbox/cli-launch.js.map +0 -1
  143. package/dist/core/sandbox/cli-supervisor.d.ts +0 -31
  144. package/dist/core/sandbox/cli-supervisor.d.ts.map +0 -1
  145. package/dist/core/sandbox/cli-supervisor.js +0 -147
  146. package/dist/core/sandbox/cli-supervisor.js.map +0 -1
  147. package/dist/core/sandbox/default-hosts.d.ts +0 -28
  148. package/dist/core/sandbox/default-hosts.d.ts.map +0 -1
  149. package/dist/core/sandbox/default-hosts.js +0 -69
  150. package/dist/core/sandbox/default-hosts.js.map +0 -1
  151. package/dist/core/sandbox/full-access.d.ts +0 -28
  152. package/dist/core/sandbox/full-access.d.ts.map +0 -1
  153. package/dist/core/sandbox/full-access.js +0 -63
  154. package/dist/core/sandbox/full-access.js.map +0 -1
  155. package/dist/core/sandbox/git-identity.d.ts +0 -57
  156. package/dist/core/sandbox/git-identity.d.ts.map +0 -1
  157. package/dist/core/sandbox/git-identity.js +0 -78
  158. package/dist/core/sandbox/git-identity.js.map +0 -1
  159. package/dist/core/sandbox/host-approval.d.ts +0 -42
  160. package/dist/core/sandbox/host-approval.d.ts.map +0 -1
  161. package/dist/core/sandbox/host-approval.js +0 -99
  162. package/dist/core/sandbox/host-approval.js.map +0 -1
  163. package/dist/core/sandbox/linux-backend.d.ts +0 -48
  164. package/dist/core/sandbox/linux-backend.d.ts.map +0 -1
  165. package/dist/core/sandbox/linux-backend.js +0 -328
  166. package/dist/core/sandbox/linux-backend.js.map +0 -1
  167. package/dist/core/sandbox/macos-backend.d.ts +0 -30
  168. package/dist/core/sandbox/macos-backend.d.ts.map +0 -1
  169. package/dist/core/sandbox/macos-backend.js +0 -385
  170. package/dist/core/sandbox/macos-backend.js.map +0 -1
  171. package/dist/core/sandbox/network-proxy.d.ts +0 -38
  172. package/dist/core/sandbox/network-proxy.d.ts.map +0 -1
  173. package/dist/core/sandbox/network-proxy.js +0 -153
  174. package/dist/core/sandbox/network-proxy.js.map +0 -1
  175. package/dist/core/sandbox/network-refusal.d.ts +0 -24
  176. package/dist/core/sandbox/network-refusal.d.ts.map +0 -1
  177. package/dist/core/sandbox/network-refusal.js +0 -72
  178. package/dist/core/sandbox/network-refusal.js.map +0 -1
  179. package/dist/core/sandbox/policy.d.ts +0 -40
  180. package/dist/core/sandbox/policy.d.ts.map +0 -1
  181. package/dist/core/sandbox/policy.js +0 -55
  182. package/dist/core/sandbox/policy.js.map +0 -1
  183. package/dist/core/sandbox/profiles.d.ts +0 -25
  184. package/dist/core/sandbox/profiles.d.ts.map +0 -1
  185. package/dist/core/sandbox/profiles.js +0 -23
  186. package/dist/core/sandbox/profiles.js.map +0 -1
  187. package/dist/core/sandbox/rpc/command-client.d.ts +0 -28
  188. package/dist/core/sandbox/rpc/command-client.d.ts.map +0 -1
  189. package/dist/core/sandbox/rpc/command-client.js +0 -86
  190. package/dist/core/sandbox/rpc/command-client.js.map +0 -1
  191. package/dist/core/sandbox/rpc/command-proxy.d.ts +0 -48
  192. package/dist/core/sandbox/rpc/command-proxy.d.ts.map +0 -1
  193. package/dist/core/sandbox/rpc/command-proxy.js +0 -120
  194. package/dist/core/sandbox/rpc/command-proxy.js.map +0 -1
  195. package/dist/core/sandbox/rpc/credential-client.d.ts +0 -20
  196. package/dist/core/sandbox/rpc/credential-client.d.ts.map +0 -1
  197. package/dist/core/sandbox/rpc/credential-client.js +0 -170
  198. package/dist/core/sandbox/rpc/credential-client.js.map +0 -1
  199. package/dist/core/sandbox/rpc/credential-proxy.d.ts +0 -44
  200. package/dist/core/sandbox/rpc/credential-proxy.d.ts.map +0 -1
  201. package/dist/core/sandbox/rpc/credential-proxy.js +0 -287
  202. package/dist/core/sandbox/rpc/credential-proxy.js.map +0 -1
  203. package/dist/core/sandbox/rpc/framing.d.ts +0 -35
  204. package/dist/core/sandbox/rpc/framing.d.ts.map +0 -1
  205. package/dist/core/sandbox/rpc/framing.js +0 -114
  206. package/dist/core/sandbox/rpc/framing.js.map +0 -1
  207. package/dist/core/sandbox/rpc/git-credential-helper.d.ts +0 -47
  208. package/dist/core/sandbox/rpc/git-credential-helper.d.ts.map +0 -1
  209. package/dist/core/sandbox/rpc/git-credential-helper.js +0 -222
  210. package/dist/core/sandbox/rpc/git-credential-helper.js.map +0 -1
  211. package/dist/core/sandbox/rpc/git-credential-proxy.d.ts +0 -66
  212. package/dist/core/sandbox/rpc/git-credential-proxy.d.ts.map +0 -1
  213. package/dist/core/sandbox/rpc/git-credential-proxy.js +0 -209
  214. package/dist/core/sandbox/rpc/git-credential-proxy.js.map +0 -1
  215. package/dist/core/sandbox/supervisor-temp.d.ts +0 -18
  216. package/dist/core/sandbox/supervisor-temp.d.ts.map +0 -1
  217. package/dist/core/sandbox/supervisor-temp.js +0 -21
  218. package/dist/core/sandbox/supervisor-temp.js.map +0 -1
  219. package/dist/core/sandbox/supervisor.d.ts +0 -62
  220. package/dist/core/sandbox/supervisor.d.ts.map +0 -1
  221. package/dist/core/sandbox/supervisor.js +0 -32
  222. package/dist/core/sandbox/supervisor.js.map +0 -1
  223. package/dist/core/sandbox/terminal-handoff.d.ts +0 -68
  224. package/dist/core/sandbox/terminal-handoff.d.ts.map +0 -1
  225. package/dist/core/sandbox/terminal-handoff.js +0 -221
  226. package/dist/core/sandbox/terminal-handoff.js.map +0 -1
  227. package/dist/core/sandbox/terminal-size.d.ts +0 -53
  228. package/dist/core/sandbox/terminal-size.d.ts.map +0 -1
  229. package/dist/core/sandbox/terminal-size.js +0 -126
  230. package/dist/core/sandbox/terminal-size.js.map +0 -1
  231. package/dist/core/sandbox/violations.d.ts +0 -23
  232. package/dist/core/sandbox/violations.d.ts.map +0 -1
  233. package/dist/core/sandbox/violations.js +0 -30
  234. package/dist/core/sandbox/violations.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"agent-session-services.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-services.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CA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Y,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QAAC,aAAa,CAAC,EAAE,aAAa,CAAA;KAAE,CAAC,CAAC;IAC3E,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,CAAC,EAAE,yBAAyB,CAAC,cAAc,CAAC,CAAC;IACzD,OAAO,CAAC,EAAE,yBAAyB,CAAC,SAAS,CAAC,CAAC;IAC/C,WAAW,CAAC,EAAE,cAAc,EAAE,CAAC;IAC/B,cAAc,CAAC,EAAE,IAAI,CAAC,qBAAqB,EAAE,aAAa,CAAC,CAAC;IAC5D,iFAAiF;IACjF,0BAA0B,CAAC,EAAE,MAAM,mBAAmB,GAAG,SAAS,CAAC;CACnE;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,eAAe,CAAC;IACjC,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,cAAc,EAAE,cAAc,CAAC;IAC/B,8FAA8F;IAC9F,aAAa,EAAE,OAAO,CAAC;IACvB;;;;;OAKG;IACH,SAAS,EAAE,cAAc,CAAC;IAC1B,WAAW,EAAE,6BAA6B,EAAE,CAAC;IAC7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAkDD;;;;GAIG;AACH,wBAAsB,0BAA0B,CAC/C,OAAO,EAAE,iCAAiC,GACxC,OAAO,CAAC,oBAAoB,CAAC,CA8J/B;AAED;;;;;;GAMG;AACH,wBAAsB,8BAA8B,CACnD,OAAO,EAAE,qCAAqC,GAC5C,OAAO,CAAC,wBAAwB,CAAC,CAsDnC","sourcesContent":["import { join } from \"node:path\";\nimport type { Model } from \"@earendil-works/pi-ai\";\nimport type { ThinkingLevel } from \"apex-code-agent-core\";\nimport { getAgentDir, getAuthPath } from \"../config.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport type { SessionStartEvent, ToolDefinition } from \"./extensions/index.ts\";\nimport { LspDiagnostics } from \"./lsp/diagnostics.ts\";\nimport { LspPool } from \"./lsp/pool.ts\";\nimport { resolveLspRegistry } from \"./lsp/registry.ts\";\nimport { LspStatusStore } from \"./lsp/status.ts\";\nimport { ModelRuntime } from \"./model-runtime.ts\";\nimport type { PermissionGateOptions } from \"./permissions/gate.ts\";\nimport type { PermissionResponder } from \"./permissions/responder.ts\";\nimport {\n\tDefaultResourceLoader,\n\ttype DefaultResourceLoaderOptions,\n\ttype ResourceLoader,\n\ttype ResourceLoaderReloadOptions,\n} from \"./resource-loader.ts\";\nimport { createSandboxCredentialStore } from \"./sandbox/rpc/credential-client.ts\";\nimport { type CreateAgentSessionOptions, type CreateAgentSessionResult, createAgentSession } from \"./sdk.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport { SettingsManager } from \"./settings-manager.ts\";\nimport type { LspOperations } from \"./tools/lsp.ts\";\nimport { SqliteUsagePerformanceStore } from \"./usage-performance-store.ts\";\nimport { createDeferredWebSearchOperations, resolveWebSearchOperations } from \"./web-search-provider.ts\";\n\n/** Filename of the shared durable-state database within an agent directory (roadmap Phase 8). */\nconst DURABLE_STATE_DATABASE_FILENAME = \"state.sqlite\";\n\n/**\n * Non-fatal issues collected while creating services or sessions.\n *\n * Runtime creation returns diagnostics to the caller instead of printing or\n * exiting. The app layer decides whether warnings should be shown and whether\n * errors should abort startup.\n */\nexport interface AgentSessionRuntimeDiagnostic {\n\ttype: \"info\" | \"warning\" | \"error\";\n\tmessage: string;\n}\n\n/**\n * Inputs for creating cwd-bound runtime services.\n *\n * These services are recreated whenever the effective session cwd changes.\n * CLI-provided resource paths should be resolved to absolute paths before they\n * reach this function, so later cwd switches do not reinterpret them.\n */\nexport interface CreateAgentSessionServicesOptions {\n\tcwd: string;\n\tagentDir?: string;\n\t/**\n\t * Session id to stamp on every usage-performance sample this runtime records.\n\t * Only observed when `modelRuntime` is not already provided — a caller-supplied\n\t * runtime owns its own store, if any.\n\t */\n\tsessionId?: string;\n\tsettingsManager?: SettingsManager;\n\tmodelRuntime?: ModelRuntime;\n\tmodelRuntimeSignal?: AbortSignal;\n\textensionFlagValues?: Map<string, boolean | string>;\n\tresourceLoaderOptions?: Omit<DefaultResourceLoaderOptions, \"cwd\" | \"agentDir\" | \"settingsManager\">;\n\tresourceLoaderReloadOptions?: ResourceLoaderReloadOptions;\n}\n\n/**\n * Inputs for creating an AgentSession from already-created services.\n *\n * Use this after services exist and any cwd-bound model/tool/session options\n * have been resolved against those services.\n */\nexport interface CreateAgentSessionFromServicesOptions {\n\tservices: AgentSessionServices;\n\tsessionManager: SessionManager;\n\tsessionStartEvent?: SessionStartEvent;\n\tmodel?: Model<any>;\n\tthinkingLevel?: ThinkingLevel;\n\tscopedModels?: Array<{ model: Model<any>; thinkingLevel?: ThinkingLevel }>;\n\ttools?: string[];\n\texcludeTools?: CreateAgentSessionOptions[\"excludeTools\"];\n\tnoTools?: CreateAgentSessionOptions[\"noTools\"];\n\tcustomTools?: ToolDefinition[];\n\tpermissionGate?: Omit<PermissionGateOptions, \"getContract\">;\n\t/** Optional headless permission bridge (ACP, spec 2026-08-31-acp-adapter.md). */\n\tpermissionResponderFactory?: () => PermissionResponder | undefined;\n}\n\n/**\n * Coherent cwd-bound runtime services for one effective session cwd.\n *\n * This is infrastructure only. The AgentSession itself is created separately so\n * session options can be resolved against these services first.\n */\nexport interface AgentSessionServices {\n\tcwd: string;\n\tagentDir: string;\n\tmodelRuntime: ModelRuntime;\n\tsettingsManager: SettingsManager;\n\tresourceLoader: ResourceLoader;\n\tlspPool: LspPool;\n\t/**\n\t * Wraps `lspPool` for `DiagnosticsOperations.afterMutation` (LSP.4). Structurally\n\t * compatible with `core/tools/diagnostics.ts`'s `DiagnosticsOperations` -- callers\n\t * pass this value directly, never importing `core/lsp/*` themselves.\n\t */\n\tlspDiagnostics: LspDiagnostics;\n\t/** True when at least one LSP server resolved -- gates registering the `lsp` tool (LSP.5). */\n\tlspConfigured: boolean;\n\t/**\n\t * Chronological, bounded record of every server-root state transition observed by\n\t * `lspPool` for this services lifetime (LSP.2). Inspectable structured state -- not\n\t * wired to any user-facing surface by this plan (see `docs/plans/2026-08-18-lsp.md`,\n\t * Task LSP.2: this is not a `/doctor` task).\n\t */\n\tlspStatus: LspStatusStore;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n\tclose(): Promise<void>;\n}\n\nfunction applyExtensionFlagValues(\n\tresourceLoader: ResourceLoader,\n\textensionFlagValues: Map<string, boolean | string> | undefined,\n): AgentSessionRuntimeDiagnostic[] {\n\tif (!extensionFlagValues) {\n\t\treturn [];\n\t}\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tconst registeredFlags = new Map<string, { type: \"boolean\" | \"string\" }>();\n\tfor (const extension of extensionsResult.extensions) {\n\t\tfor (const [name, flag] of extension.flags) {\n\t\t\tregisteredFlags.set(name, { type: flag.type });\n\t\t}\n\t}\n\n\tconst unknownFlags: string[] = [];\n\tfor (const [name, value] of extensionFlagValues) {\n\t\tconst flag = registeredFlags.get(name);\n\t\tif (!flag) {\n\t\t\tunknownFlags.push(name);\n\t\t\tcontinue;\n\t\t}\n\t\tif (flag.type === \"boolean\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, true);\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === \"string\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t\tcontinue;\n\t\t}\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Extension flag \"--${name}\" requires a value`,\n\t\t});\n\t}\n\n\tif (unknownFlags.length > 0) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Unknown option${unknownFlags.length === 1 ? \"\" : \"s\"}: ${unknownFlags.map((name) => `--${name}`).join(\", \")}`,\n\t\t});\n\t}\n\n\treturn diagnostics;\n}\n\n/**\n * Create cwd-bound runtime services.\n *\n * Returns services plus diagnostics. It does not create an AgentSession.\n */\nexport async function createAgentSessionServices(\n\toptions: CreateAgentSessionServicesOptions,\n): Promise<AgentSessionServices> {\n\tconst cwd = resolvePath(options.cwd);\n\tconst agentDir = options.agentDir ? resolvePath(options.agentDir) : getAgentDir();\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\n\t// A ledger failure must never block session creation or a turn — open it\n\t// best-effort and degrade to a diagnostic, never a thrown error.\n\tlet usagePerformanceStore: SqliteUsagePerformanceStore | undefined;\n\tif (!options.modelRuntime) {\n\t\ttry {\n\t\t\tusagePerformanceStore = new SqliteUsagePerformanceStore(\n\t\t\t\tjoin(agentDir, DURABLE_STATE_DATABASE_FILENAME),\n\t\t\t\toptions.sessionId,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({ type: \"warning\", message: `Usage/cost recording unavailable: ${message}` });\n\t\t}\n\t}\n\n\tconst settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n\tconst otlpEndpoint = settingsManager.getObservabilitySettings().otlpEndpoint;\n\tconst otlpExportConfig = otlpEndpoint\n\t\t? { endpoint: otlpEndpoint, headers: settingsManager.getObservabilitySettings().otlpHeaders }\n\t\t: undefined;\n\n\t// Inside a sandboxed session the supervisor advertises a credential write channel\n\t// (spec: 2026-08-22-supervisor-mediated-credential-writes). Reads are unchanged --\n\t// still the read-only projection of the host credential file -- while writes and\n\t// deletes travel the supervisor-owned socket instead of failing on the read-only\n\t// mount. Outside a sandbox this resolves to undefined and the default store applies.\n\tconst sandboxCredentialStore = createSandboxCredentialStore();\n\tconst modelRuntime =\n\t\toptions.modelRuntime ??\n\t\t(await ModelRuntime.create({\n\t\t\tauthPath: process.env.APEX_CODE_AUTH_PATH ?? (options.agentDir ? join(agentDir, \"auth.json\") : getAuthPath()),\n\t\t\tcredentials: sandboxCredentialStore,\n\t\t\tmodelsPath: join(agentDir, \"models.json\"),\n\t\t\tsignal: options.modelRuntimeSignal,\n\t\t\tusagePerformanceStore,\n\t\t\totlpExportConfig,\n\t\t}));\n\tconst resourceLoader = new DefaultResourceLoader({\n\t\t...(options.resourceLoaderOptions ?? {}),\n\t\tcwd,\n\t\tagentDir,\n\t\tsettingsManager,\n\t});\n\tawait resourceLoader.reload(options.resourceLoaderReloadOptions);\n\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tfor (const { name, config, extensionPath } of extensionsResult.runtime.pendingProviderRegistrations) {\n\t\ttry {\n\t\t\tmodelRuntime.registerProvider(name, config);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"error\",\n\t\t\t\tmessage: `Extension \"${extensionPath}\" error: ${message}`,\n\t\t\t});\n\t\t}\n\t}\n\textensionsResult.runtime.pendingProviderRegistrations = [];\n\tfor (const { provider, extensionPath } of extensionsResult.runtime.pendingNativeProviderRegistrations) {\n\t\ttry {\n\t\t\tmodelRuntime.registerNativeProvider(provider);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"error\",\n\t\t\t\tmessage: `Extension \"${extensionPath}\" error: ${message}`,\n\t\t\t});\n\t\t}\n\t}\n\textensionsResult.runtime.pendingNativeProviderRegistrations = [];\n\tawait modelRuntime.refresh({ allowNetwork: false });\n\tdiagnostics.push(...applyExtensionFlagValues(resourceLoader, options.extensionFlagValues));\n\n\t// `lspStatus` is constructed unconditionally (and outside the try) so it always\n\t// records real state transitions the pool experiences below, including the\n\t// eager-start failure the catch block handles -- not just a snapshot taken at one\n\t// fixed point in time.\n\tconst lspStatus = new LspStatusStore();\n\tlet lspPool: LspPool | undefined;\n\tlet registry: ReturnType<typeof resolveLspRegistry> | undefined;\n\tlet lspConfigured = false;\n\ttry {\n\t\tregistry = resolveLspRegistry(settingsManager.getLspSettings(), { workspace: cwd });\n\t\tlspPool = new LspPool(registry, {\n\t\t\tonStatusChange: (status) =>\n\t\t\t\tlspStatus.record({\n\t\t\t\t\tserverId: status.serverId,\n\t\t\t\t\troot: status.root,\n\t\t\t\t\tstate: status.state,\n\t\t\t\t\tattempt: status.attempts,\n\t\t\t\t\t...(status.reason === undefined ? {} : { reason: status.reason }),\n\t\t\t\t}),\n\t\t});\n\t\tlspConfigured = registry.servers.length > 0;\n\t\t// Per the spec's \"Resolved configuration, ownership, and lifecycle\": any\n\t\t// configured entry that cannot resolve, spawn, or initialize its cwd-root\n\t\t// process within its timeout is a startup misconfiguration -- fail fast here,\n\t\t// following core/permissions/startup.ts's precedent, rather than let a broken\n\t\t// server surface only when a tool call needs it mid-run.\n\t\tif (lspConfigured) await lspPool.start();\n\t} catch (error) {\n\t\t// Name the failing binary(ies), not just the raw client/registry error: the\n\t\t// registry itself already does this for a resolution failure (missing/\n\t\t// un-spawnable binary names the command and lookup path), but a `pool.start()`\n\t\t// rejection surfaces only the first client's bare error (e.g. \"initialize timed\n\t\t// out\"), with no server id attached. `registry.servers` (resolved commands) and\n\t\t// `lspPool.status()` (which entries actually failed) are both in scope here, so\n\t\t// build the richer message without changing `LspPoolStatus`'s shape or the\n\t\t// pool's own error-propagation wire format.\n\t\tconst commandById = new Map(registry?.servers.map((server) => [server.id, server.command]) ?? []);\n\t\tconst failedEntries = (lspPool?.status() ?? []).filter(\n\t\t\t(status) => status.state === \"degraded\" || status.state === \"disabled\",\n\t\t);\n\t\tconst message =\n\t\t\tfailedEntries.length > 0\n\t\t\t\t? failedEntries\n\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t(status) =>\n\t\t\t\t\t\t\t\t`${status.serverId} (${commandById.get(status.serverId) ?? \"?\"}) at ${status.root}: ${status.reason ?? \"unknown error\"}`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"; \")\n\t\t\t\t: error instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: String(error);\n\t\tdiagnostics.push({ type: \"error\", message: `LSP startup failed: ${message}` });\n\t\t// A pool that got partway through eager start may already have spawned and\n\t\t// initialized sibling servers successfully; discarding it without disposing\n\t\t// would orphan those child processes rather than tearing them down cleanly.\n\t\tawait lspPool?.dispose().catch(() => {});\n\t\tlspConfigured = false;\n\t\tlspPool = new LspPool({ workspace: cwd, servers: [], platform: process.platform });\n\t}\n\tconst lspDiagnostics = new LspDiagnostics(lspPool);\n\n\treturn {\n\t\tcwd,\n\t\tagentDir,\n\t\tmodelRuntime,\n\t\tsettingsManager,\n\t\tresourceLoader,\n\t\tlspPool,\n\t\tlspDiagnostics,\n\t\tlspConfigured,\n\t\tlspStatus,\n\t\tdiagnostics,\n\t\tclose: async () => {\n\t\t\t// Diagnostics first: it still needs live LSP clients to send didClose\n\t\t\t// during its own teardown, so it must not outlive the pool it wraps.\n\t\t\tawait lspDiagnostics.dispose();\n\t\t\tawait lspPool.dispose();\n\t\t\tif (!options.modelRuntime) modelRuntime.close();\n\t\t},\n\t};\n}\n\n/**\n * Create an AgentSession from previously created services.\n *\n * This keeps session creation separate from service creation so callers can\n * resolve model, thinking, tools, and other session inputs against the target\n * cwd before constructing the session.\n */\nexport async function createAgentSessionFromServices(\n\toptions: CreateAgentSessionFromServicesOptions,\n): Promise<CreateAgentSessionResult> {\n\tconst { lspPool, lspDiagnostics, lspConfigured } = options.services;\n\t// Both gated on `lspConfigured` (at least one server resolved), not per-path:\n\t// the spec's \"no diagnostics injection or result change whatsoever when `lsp` is\n\t// unconfigured\" is a session-level guarantee. A session with servers configured\n\t// for *some* languages still injects diagnosticsOperations -- a mutated path with\n\t// no matching server correctly resolves to the explicit `unavailable` outcome via\n\t// `LspDiagnostics.afterMutation`'s own per-path `pool.acquire`, it is simply never\n\t// asked at all when the session has no servers whatsoever. `lspDiagnostics`\n\t// already matches `DiagnosticsOperations` structurally, so it is passed directly\n\t// rather than wrapped.\n\tconst diagnosticsOperations = lspConfigured ? lspDiagnostics : undefined;\n\tconst lspOperations: LspOperations | undefined = lspConfigured\n\t\t? {\n\t\t\t\trequest: async (absolutePath, method, params, signal) => {\n\t\t\t\t\tconst connection = await lspPool.acquire(absolutePath);\n\t\t\t\t\tif (!connection) return undefined;\n\t\t\t\t\treturn connection.client.request(method, params, signal);\n\t\t\t\t},\n\t\t\t}\n\t\t: undefined;\n\n\t// Read per call rather than captured here. The tool registry is built once at\n\t// session construction, so a key saved from the settings panel mid-session would\n\t// otherwise not take effect until restart.\n\t// Two different questions. Whether a credential resolves *now* decides whether the\n\t// tool is active, because activation happens once at construction. Resolution then\n\t// stays deferred so a key changed mid-session is picked up without a restart.\n\tconst settingsManager = options.services.settingsManager;\n\tconst webSearchOperations = resolveWebSearchOperations(settingsManager.getWebSearchSettings())\n\t\t? createDeferredWebSearchOperations(() => settingsManager.getWebSearchSettings())\n\t\t: undefined;\n\n\treturn createAgentSession({\n\t\tcwd: options.services.cwd,\n\t\tagentDir: options.services.agentDir,\n\t\tmodelRuntime: options.services.modelRuntime,\n\t\tsettingsManager: options.services.settingsManager,\n\t\tresourceLoader: options.services.resourceLoader,\n\t\tsessionManager: options.sessionManager,\n\t\tmodel: options.model,\n\t\tthinkingLevel: options.thinkingLevel,\n\t\tscopedModels: options.scopedModels,\n\t\ttools: options.tools,\n\t\texcludeTools: options.excludeTools,\n\t\tnoTools: options.noTools,\n\t\tcustomTools: options.customTools,\n\t\tsessionStartEvent: options.sessionStartEvent,\n\t\tpermissionGate: options.permissionGate,\n\t\tpermissionResponderFactory: options.permissionResponderFactory,\n\t\tdiagnosticsOperations,\n\t\tlspOperations,\n\t\twebSearchOperations,\n\t});\n}\n"]}
1
+ {"version":3,"file":"agent-session-services.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-services.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC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AAW,EAAE,6BAA6B,EAAE,CAAC;IAC7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAkDD;;;;GAIG;AACH,wBAAsB,0BAA0B,CAC/C,OAAO,EAAE,iCAAiC,GACxC,OAAO,CAAC,oBAAoB,CAAC,CAuJ/B;AAED;;;;;;GAMG;AACH,wBAAsB,8BAA8B,CACnD,OAAO,EAAE,qCAAqC,GAC5C,OAAO,CAAC,wBAAwB,CAAC,CAsDnC","sourcesContent":["import { join } from \"node:path\";\nimport type { Model } from \"@earendil-works/pi-ai\";\nimport type { ThinkingLevel } from \"apex-code-agent-core\";\nimport { getAgentDir, getAuthPath } from \"../config.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport type { SessionStartEvent, ToolDefinition } from \"./extensions/index.ts\";\nimport { LspDiagnostics } from \"./lsp/diagnostics.ts\";\nimport { LspPool } from \"./lsp/pool.ts\";\nimport { resolveLspRegistry } from \"./lsp/registry.ts\";\nimport { LspStatusStore } from \"./lsp/status.ts\";\nimport { ModelRuntime } from \"./model-runtime.ts\";\nimport type { PermissionGateOptions } from \"./permissions/gate.ts\";\nimport type { PermissionResponder } from \"./permissions/responder.ts\";\nimport {\n\tDefaultResourceLoader,\n\ttype DefaultResourceLoaderOptions,\n\ttype ResourceLoader,\n\ttype ResourceLoaderReloadOptions,\n} from \"./resource-loader.ts\";\nimport { type CreateAgentSessionOptions, type CreateAgentSessionResult, createAgentSession } from \"./sdk.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport { SettingsManager } from \"./settings-manager.ts\";\nimport type { LspOperations } from \"./tools/lsp.ts\";\nimport { SqliteUsagePerformanceStore } from \"./usage-performance-store.ts\";\nimport { createDeferredWebSearchOperations, resolveWebSearchOperations } from \"./web-search-provider.ts\";\n\n/** Filename of the shared durable-state database within an agent directory (roadmap Phase 8). */\nconst DURABLE_STATE_DATABASE_FILENAME = \"state.sqlite\";\n\n/**\n * Non-fatal issues collected while creating services or sessions.\n *\n * Runtime creation returns diagnostics to the caller instead of printing or\n * exiting. The app layer decides whether warnings should be shown and whether\n * errors should abort startup.\n */\nexport interface AgentSessionRuntimeDiagnostic {\n\ttype: \"info\" | \"warning\" | \"error\";\n\tmessage: string;\n}\n\n/**\n * Inputs for creating cwd-bound runtime services.\n *\n * These services are recreated whenever the effective session cwd changes.\n * CLI-provided resource paths should be resolved to absolute paths before they\n * reach this function, so later cwd switches do not reinterpret them.\n */\nexport interface CreateAgentSessionServicesOptions {\n\tcwd: string;\n\tagentDir?: string;\n\t/**\n\t * Session id to stamp on every usage-performance sample this runtime records.\n\t * Only observed when `modelRuntime` is not already provided — a caller-supplied\n\t * runtime owns its own store, if any.\n\t */\n\tsessionId?: string;\n\tsettingsManager?: SettingsManager;\n\tmodelRuntime?: ModelRuntime;\n\tmodelRuntimeSignal?: AbortSignal;\n\textensionFlagValues?: Map<string, boolean | string>;\n\tresourceLoaderOptions?: Omit<DefaultResourceLoaderOptions, \"cwd\" | \"agentDir\" | \"settingsManager\">;\n\tresourceLoaderReloadOptions?: ResourceLoaderReloadOptions;\n}\n\n/**\n * Inputs for creating an AgentSession from already-created services.\n *\n * Use this after services exist and any cwd-bound model/tool/session options\n * have been resolved against those services.\n */\nexport interface CreateAgentSessionFromServicesOptions {\n\tservices: AgentSessionServices;\n\tsessionManager: SessionManager;\n\tsessionStartEvent?: SessionStartEvent;\n\tmodel?: Model<any>;\n\tthinkingLevel?: ThinkingLevel;\n\tscopedModels?: Array<{ model: Model<any>; thinkingLevel?: ThinkingLevel }>;\n\ttools?: string[];\n\texcludeTools?: CreateAgentSessionOptions[\"excludeTools\"];\n\tnoTools?: CreateAgentSessionOptions[\"noTools\"];\n\tcustomTools?: ToolDefinition[];\n\tpermissionGate?: Omit<PermissionGateOptions, \"getContract\">;\n\t/** Optional headless permission bridge (ACP, spec 2026-08-31-acp-adapter.md). */\n\tpermissionResponderFactory?: () => PermissionResponder | undefined;\n}\n\n/**\n * Coherent cwd-bound runtime services for one effective session cwd.\n *\n * This is infrastructure only. The AgentSession itself is created separately so\n * session options can be resolved against these services first.\n */\nexport interface AgentSessionServices {\n\tcwd: string;\n\tagentDir: string;\n\tmodelRuntime: ModelRuntime;\n\tsettingsManager: SettingsManager;\n\tresourceLoader: ResourceLoader;\n\tlspPool: LspPool;\n\t/**\n\t * Wraps `lspPool` for `DiagnosticsOperations.afterMutation` (LSP.4). Structurally\n\t * compatible with `core/tools/diagnostics.ts`'s `DiagnosticsOperations` -- callers\n\t * pass this value directly, never importing `core/lsp/*` themselves.\n\t */\n\tlspDiagnostics: LspDiagnostics;\n\t/** True when at least one LSP server resolved -- gates registering the `lsp` tool (LSP.5). */\n\tlspConfigured: boolean;\n\t/**\n\t * Chronological, bounded record of every server-root state transition observed by\n\t * `lspPool` for this services lifetime (LSP.2). Inspectable structured state -- not\n\t * wired to any user-facing surface by this plan (see `docs/plans/2026-08-18-lsp.md`,\n\t * Task LSP.2: this is not a `/doctor` task).\n\t */\n\tlspStatus: LspStatusStore;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n\tclose(): Promise<void>;\n}\n\nfunction applyExtensionFlagValues(\n\tresourceLoader: ResourceLoader,\n\textensionFlagValues: Map<string, boolean | string> | undefined,\n): AgentSessionRuntimeDiagnostic[] {\n\tif (!extensionFlagValues) {\n\t\treturn [];\n\t}\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tconst registeredFlags = new Map<string, { type: \"boolean\" | \"string\" }>();\n\tfor (const extension of extensionsResult.extensions) {\n\t\tfor (const [name, flag] of extension.flags) {\n\t\t\tregisteredFlags.set(name, { type: flag.type });\n\t\t}\n\t}\n\n\tconst unknownFlags: string[] = [];\n\tfor (const [name, value] of extensionFlagValues) {\n\t\tconst flag = registeredFlags.get(name);\n\t\tif (!flag) {\n\t\t\tunknownFlags.push(name);\n\t\t\tcontinue;\n\t\t}\n\t\tif (flag.type === \"boolean\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, true);\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === \"string\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t\tcontinue;\n\t\t}\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Extension flag \"--${name}\" requires a value`,\n\t\t});\n\t}\n\n\tif (unknownFlags.length > 0) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Unknown option${unknownFlags.length === 1 ? \"\" : \"s\"}: ${unknownFlags.map((name) => `--${name}`).join(\", \")}`,\n\t\t});\n\t}\n\n\treturn diagnostics;\n}\n\n/**\n * Create cwd-bound runtime services.\n *\n * Returns services plus diagnostics. It does not create an AgentSession.\n */\nexport async function createAgentSessionServices(\n\toptions: CreateAgentSessionServicesOptions,\n): Promise<AgentSessionServices> {\n\tconst cwd = resolvePath(options.cwd);\n\tconst agentDir = options.agentDir ? resolvePath(options.agentDir) : getAgentDir();\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\n\t// A ledger failure must never block session creation or a turn — open it\n\t// best-effort and degrade to a diagnostic, never a thrown error.\n\tlet usagePerformanceStore: SqliteUsagePerformanceStore | undefined;\n\tif (!options.modelRuntime) {\n\t\ttry {\n\t\t\tusagePerformanceStore = new SqliteUsagePerformanceStore(\n\t\t\t\tjoin(agentDir, DURABLE_STATE_DATABASE_FILENAME),\n\t\t\t\toptions.sessionId,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({ type: \"warning\", message: `Usage/cost recording unavailable: ${message}` });\n\t\t}\n\t}\n\n\tconst settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n\tconst otlpEndpoint = settingsManager.getObservabilitySettings().otlpEndpoint;\n\tconst otlpExportConfig = otlpEndpoint\n\t\t? { endpoint: otlpEndpoint, headers: settingsManager.getObservabilitySettings().otlpHeaders }\n\t\t: undefined;\n\n\tconst modelRuntime =\n\t\toptions.modelRuntime ??\n\t\t(await ModelRuntime.create({\n\t\t\tauthPath: process.env.APEX_CODE_AUTH_PATH ?? (options.agentDir ? join(agentDir, \"auth.json\") : getAuthPath()),\n\t\t\tmodelsPath: join(agentDir, \"models.json\"),\n\t\t\tsignal: options.modelRuntimeSignal,\n\t\t\tusagePerformanceStore,\n\t\t\totlpExportConfig,\n\t\t}));\n\tconst resourceLoader = new DefaultResourceLoader({\n\t\t...(options.resourceLoaderOptions ?? {}),\n\t\tcwd,\n\t\tagentDir,\n\t\tsettingsManager,\n\t});\n\tawait resourceLoader.reload(options.resourceLoaderReloadOptions);\n\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tfor (const { name, config, extensionPath } of extensionsResult.runtime.pendingProviderRegistrations) {\n\t\ttry {\n\t\t\tmodelRuntime.registerProvider(name, config);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"error\",\n\t\t\t\tmessage: `Extension \"${extensionPath}\" error: ${message}`,\n\t\t\t});\n\t\t}\n\t}\n\textensionsResult.runtime.pendingProviderRegistrations = [];\n\tfor (const { provider, extensionPath } of extensionsResult.runtime.pendingNativeProviderRegistrations) {\n\t\ttry {\n\t\t\tmodelRuntime.registerNativeProvider(provider);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"error\",\n\t\t\t\tmessage: `Extension \"${extensionPath}\" error: ${message}`,\n\t\t\t});\n\t\t}\n\t}\n\textensionsResult.runtime.pendingNativeProviderRegistrations = [];\n\tawait modelRuntime.refresh({ allowNetwork: false });\n\tdiagnostics.push(...applyExtensionFlagValues(resourceLoader, options.extensionFlagValues));\n\n\t// `lspStatus` is constructed unconditionally (and outside the try) so it always\n\t// records real state transitions the pool experiences below, including the\n\t// eager-start failure the catch block handles -- not just a snapshot taken at one\n\t// fixed point in time.\n\tconst lspStatus = new LspStatusStore();\n\tlet lspPool: LspPool | undefined;\n\tlet registry: ReturnType<typeof resolveLspRegistry> | undefined;\n\tlet lspConfigured = false;\n\ttry {\n\t\tregistry = resolveLspRegistry(settingsManager.getLspSettings(), { workspace: cwd });\n\t\tlspPool = new LspPool(registry, {\n\t\t\tonStatusChange: (status) =>\n\t\t\t\tlspStatus.record({\n\t\t\t\t\tserverId: status.serverId,\n\t\t\t\t\troot: status.root,\n\t\t\t\t\tstate: status.state,\n\t\t\t\t\tattempt: status.attempts,\n\t\t\t\t\t...(status.reason === undefined ? {} : { reason: status.reason }),\n\t\t\t\t}),\n\t\t});\n\t\tlspConfigured = registry.servers.length > 0;\n\t\t// Per the spec's \"Resolved configuration, ownership, and lifecycle\": any\n\t\t// configured entry that cannot resolve, spawn, or initialize its cwd-root\n\t\t// process within its timeout is a startup misconfiguration -- fail fast here,\n\t\t// following core/permissions/startup.ts's precedent, rather than let a broken\n\t\t// server surface only when a tool call needs it mid-run.\n\t\tif (lspConfigured) await lspPool.start();\n\t} catch (error) {\n\t\t// Name the failing binary(ies), not just the raw client/registry error: the\n\t\t// registry itself already does this for a resolution failure (missing/\n\t\t// un-spawnable binary names the command and lookup path), but a `pool.start()`\n\t\t// rejection surfaces only the first client's bare error (e.g. \"initialize timed\n\t\t// out\"), with no server id attached. `registry.servers` (resolved commands) and\n\t\t// `lspPool.status()` (which entries actually failed) are both in scope here, so\n\t\t// build the richer message without changing `LspPoolStatus`'s shape or the\n\t\t// pool's own error-propagation wire format.\n\t\tconst commandById = new Map(registry?.servers.map((server) => [server.id, server.command]) ?? []);\n\t\tconst failedEntries = (lspPool?.status() ?? []).filter(\n\t\t\t(status) => status.state === \"degraded\" || status.state === \"disabled\",\n\t\t);\n\t\tconst message =\n\t\t\tfailedEntries.length > 0\n\t\t\t\t? failedEntries\n\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t(status) =>\n\t\t\t\t\t\t\t\t`${status.serverId} (${commandById.get(status.serverId) ?? \"?\"}) at ${status.root}: ${status.reason ?? \"unknown error\"}`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"; \")\n\t\t\t\t: error instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: String(error);\n\t\tdiagnostics.push({ type: \"error\", message: `LSP startup failed: ${message}` });\n\t\t// A pool that got partway through eager start may already have spawned and\n\t\t// initialized sibling servers successfully; discarding it without disposing\n\t\t// would orphan those child processes rather than tearing them down cleanly.\n\t\tawait lspPool?.dispose().catch(() => {});\n\t\tlspConfigured = false;\n\t\tlspPool = new LspPool({ workspace: cwd, servers: [], platform: process.platform });\n\t}\n\tconst lspDiagnostics = new LspDiagnostics(lspPool);\n\n\treturn {\n\t\tcwd,\n\t\tagentDir,\n\t\tmodelRuntime,\n\t\tsettingsManager,\n\t\tresourceLoader,\n\t\tlspPool,\n\t\tlspDiagnostics,\n\t\tlspConfigured,\n\t\tlspStatus,\n\t\tdiagnostics,\n\t\tclose: async () => {\n\t\t\t// Diagnostics first: it still needs live LSP clients to send didClose\n\t\t\t// during its own teardown, so it must not outlive the pool it wraps.\n\t\t\tawait lspDiagnostics.dispose();\n\t\t\tawait lspPool.dispose();\n\t\t\tif (!options.modelRuntime) modelRuntime.close();\n\t\t},\n\t};\n}\n\n/**\n * Create an AgentSession from previously created services.\n *\n * This keeps session creation separate from service creation so callers can\n * resolve model, thinking, tools, and other session inputs against the target\n * cwd before constructing the session.\n */\nexport async function createAgentSessionFromServices(\n\toptions: CreateAgentSessionFromServicesOptions,\n): Promise<CreateAgentSessionResult> {\n\tconst { lspPool, lspDiagnostics, lspConfigured } = options.services;\n\t// Both gated on `lspConfigured` (at least one server resolved), not per-path:\n\t// the spec's \"no diagnostics injection or result change whatsoever when `lsp` is\n\t// unconfigured\" is a session-level guarantee. A session with servers configured\n\t// for *some* languages still injects diagnosticsOperations -- a mutated path with\n\t// no matching server correctly resolves to the explicit `unavailable` outcome via\n\t// `LspDiagnostics.afterMutation`'s own per-path `pool.acquire`, it is simply never\n\t// asked at all when the session has no servers whatsoever. `lspDiagnostics`\n\t// already matches `DiagnosticsOperations` structurally, so it is passed directly\n\t// rather than wrapped.\n\tconst diagnosticsOperations = lspConfigured ? lspDiagnostics : undefined;\n\tconst lspOperations: LspOperations | undefined = lspConfigured\n\t\t? {\n\t\t\t\trequest: async (absolutePath, method, params, signal) => {\n\t\t\t\t\tconst connection = await lspPool.acquire(absolutePath);\n\t\t\t\t\tif (!connection) return undefined;\n\t\t\t\t\treturn connection.client.request(method, params, signal);\n\t\t\t\t},\n\t\t\t}\n\t\t: undefined;\n\n\t// Read per call rather than captured here. The tool registry is built once at\n\t// session construction, so a key saved from the settings panel mid-session would\n\t// otherwise not take effect until restart.\n\t// Two different questions. Whether a credential resolves *now* decides whether the\n\t// tool is active, because activation happens once at construction. Resolution then\n\t// stays deferred so a key changed mid-session is picked up without a restart.\n\tconst settingsManager = options.services.settingsManager;\n\tconst webSearchOperations = resolveWebSearchOperations(settingsManager.getWebSearchSettings())\n\t\t? createDeferredWebSearchOperations(() => settingsManager.getWebSearchSettings())\n\t\t: undefined;\n\n\treturn createAgentSession({\n\t\tcwd: options.services.cwd,\n\t\tagentDir: options.services.agentDir,\n\t\tmodelRuntime: options.services.modelRuntime,\n\t\tsettingsManager: options.services.settingsManager,\n\t\tresourceLoader: options.services.resourceLoader,\n\t\tsessionManager: options.sessionManager,\n\t\tmodel: options.model,\n\t\tthinkingLevel: options.thinkingLevel,\n\t\tscopedModels: options.scopedModels,\n\t\ttools: options.tools,\n\t\texcludeTools: options.excludeTools,\n\t\tnoTools: options.noTools,\n\t\tcustomTools: options.customTools,\n\t\tsessionStartEvent: options.sessionStartEvent,\n\t\tpermissionGate: options.permissionGate,\n\t\tpermissionResponderFactory: options.permissionResponderFactory,\n\t\tdiagnosticsOperations,\n\t\tlspOperations,\n\t\twebSearchOperations,\n\t});\n}\n"]}
@@ -7,7 +7,6 @@ import { resolveLspRegistry } from "./lsp/registry.js";
7
7
  import { LspStatusStore } from "./lsp/status.js";
8
8
  import { ModelRuntime } from "./model-runtime.js";
9
9
  import { DefaultResourceLoader, } from "./resource-loader.js";
10
- import { createSandboxCredentialStore } from "./sandbox/rpc/credential-client.js";
11
10
  import { createAgentSession } from "./sdk.js";
12
11
  import { SettingsManager } from "./settings-manager.js";
13
12
  import { SqliteUsagePerformanceStore } from "./usage-performance-store.js";
@@ -80,16 +79,9 @@ export async function createAgentSessionServices(options) {
80
79
  const otlpExportConfig = otlpEndpoint
81
80
  ? { endpoint: otlpEndpoint, headers: settingsManager.getObservabilitySettings().otlpHeaders }
82
81
  : undefined;
83
- // Inside a sandboxed session the supervisor advertises a credential write channel
84
- // (spec: 2026-08-22-supervisor-mediated-credential-writes). Reads are unchanged --
85
- // still the read-only projection of the host credential file -- while writes and
86
- // deletes travel the supervisor-owned socket instead of failing on the read-only
87
- // mount. Outside a sandbox this resolves to undefined and the default store applies.
88
- const sandboxCredentialStore = createSandboxCredentialStore();
89
82
  const modelRuntime = options.modelRuntime ??
90
83
  (await ModelRuntime.create({
91
84
  authPath: process.env.APEX_CODE_AUTH_PATH ?? (options.agentDir ? join(agentDir, "auth.json") : getAuthPath()),
92
- credentials: sandboxCredentialStore,
93
85
  modelsPath: join(agentDir, "models.json"),
94
86
  signal: options.modelRuntimeSignal,
95
87
  usagePerformanceStore,
@@ -1 +1 @@
1
- {"version":3,"file":"agent-session-services.js","sourceRoot":"","sources":["../../src/core/agent-session-services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB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C,YAAY;QAClC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;QAC5C,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,0BAA0B,EAAE,OAAO,CAAC,0BAA0B;QAC9D,qBAAqB;QACrB,aAAa;QACb,mBAAmB;KACnB,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { join } from \"node:path\";\nimport type { Model } from \"@earendil-works/pi-ai\";\nimport type { ThinkingLevel } from \"apex-code-agent-core\";\nimport { getAgentDir, getAuthPath } from \"../config.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport type { SessionStartEvent, ToolDefinition } from \"./extensions/index.ts\";\nimport { LspDiagnostics } from \"./lsp/diagnostics.ts\";\nimport { LspPool } from \"./lsp/pool.ts\";\nimport { resolveLspRegistry } from \"./lsp/registry.ts\";\nimport { LspStatusStore } from \"./lsp/status.ts\";\nimport { ModelRuntime } from \"./model-runtime.ts\";\nimport type { PermissionGateOptions } from \"./permissions/gate.ts\";\nimport type { PermissionResponder } from \"./permissions/responder.ts\";\nimport {\n\tDefaultResourceLoader,\n\ttype DefaultResourceLoaderOptions,\n\ttype ResourceLoader,\n\ttype ResourceLoaderReloadOptions,\n} from \"./resource-loader.ts\";\nimport { createSandboxCredentialStore } from \"./sandbox/rpc/credential-client.ts\";\nimport { type CreateAgentSessionOptions, type CreateAgentSessionResult, createAgentSession } from \"./sdk.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport { SettingsManager } from \"./settings-manager.ts\";\nimport type { LspOperations } from \"./tools/lsp.ts\";\nimport { SqliteUsagePerformanceStore } from \"./usage-performance-store.ts\";\nimport { createDeferredWebSearchOperations, resolveWebSearchOperations } from \"./web-search-provider.ts\";\n\n/** Filename of the shared durable-state database within an agent directory (roadmap Phase 8). */\nconst DURABLE_STATE_DATABASE_FILENAME = \"state.sqlite\";\n\n/**\n * Non-fatal issues collected while creating services or sessions.\n *\n * Runtime creation returns diagnostics to the caller instead of printing or\n * exiting. The app layer decides whether warnings should be shown and whether\n * errors should abort startup.\n */\nexport interface AgentSessionRuntimeDiagnostic {\n\ttype: \"info\" | \"warning\" | \"error\";\n\tmessage: string;\n}\n\n/**\n * Inputs for creating cwd-bound runtime services.\n *\n * These services are recreated whenever the effective session cwd changes.\n * CLI-provided resource paths should be resolved to absolute paths before they\n * reach this function, so later cwd switches do not reinterpret them.\n */\nexport interface CreateAgentSessionServicesOptions {\n\tcwd: string;\n\tagentDir?: string;\n\t/**\n\t * Session id to stamp on every usage-performance sample this runtime records.\n\t * Only observed when `modelRuntime` is not already provided — a caller-supplied\n\t * runtime owns its own store, if any.\n\t */\n\tsessionId?: string;\n\tsettingsManager?: SettingsManager;\n\tmodelRuntime?: ModelRuntime;\n\tmodelRuntimeSignal?: AbortSignal;\n\textensionFlagValues?: Map<string, boolean | string>;\n\tresourceLoaderOptions?: Omit<DefaultResourceLoaderOptions, \"cwd\" | \"agentDir\" | \"settingsManager\">;\n\tresourceLoaderReloadOptions?: ResourceLoaderReloadOptions;\n}\n\n/**\n * Inputs for creating an AgentSession from already-created services.\n *\n * Use this after services exist and any cwd-bound model/tool/session options\n * have been resolved against those services.\n */\nexport interface CreateAgentSessionFromServicesOptions {\n\tservices: AgentSessionServices;\n\tsessionManager: SessionManager;\n\tsessionStartEvent?: SessionStartEvent;\n\tmodel?: Model<any>;\n\tthinkingLevel?: ThinkingLevel;\n\tscopedModels?: Array<{ model: Model<any>; thinkingLevel?: ThinkingLevel }>;\n\ttools?: string[];\n\texcludeTools?: CreateAgentSessionOptions[\"excludeTools\"];\n\tnoTools?: CreateAgentSessionOptions[\"noTools\"];\n\tcustomTools?: ToolDefinition[];\n\tpermissionGate?: Omit<PermissionGateOptions, \"getContract\">;\n\t/** Optional headless permission bridge (ACP, spec 2026-08-31-acp-adapter.md). */\n\tpermissionResponderFactory?: () => PermissionResponder | undefined;\n}\n\n/**\n * Coherent cwd-bound runtime services for one effective session cwd.\n *\n * This is infrastructure only. The AgentSession itself is created separately so\n * session options can be resolved against these services first.\n */\nexport interface AgentSessionServices {\n\tcwd: string;\n\tagentDir: string;\n\tmodelRuntime: ModelRuntime;\n\tsettingsManager: SettingsManager;\n\tresourceLoader: ResourceLoader;\n\tlspPool: LspPool;\n\t/**\n\t * Wraps `lspPool` for `DiagnosticsOperations.afterMutation` (LSP.4). Structurally\n\t * compatible with `core/tools/diagnostics.ts`'s `DiagnosticsOperations` -- callers\n\t * pass this value directly, never importing `core/lsp/*` themselves.\n\t */\n\tlspDiagnostics: LspDiagnostics;\n\t/** True when at least one LSP server resolved -- gates registering the `lsp` tool (LSP.5). */\n\tlspConfigured: boolean;\n\t/**\n\t * Chronological, bounded record of every server-root state transition observed by\n\t * `lspPool` for this services lifetime (LSP.2). Inspectable structured state -- not\n\t * wired to any user-facing surface by this plan (see `docs/plans/2026-08-18-lsp.md`,\n\t * Task LSP.2: this is not a `/doctor` task).\n\t */\n\tlspStatus: LspStatusStore;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n\tclose(): Promise<void>;\n}\n\nfunction applyExtensionFlagValues(\n\tresourceLoader: ResourceLoader,\n\textensionFlagValues: Map<string, boolean | string> | undefined,\n): AgentSessionRuntimeDiagnostic[] {\n\tif (!extensionFlagValues) {\n\t\treturn [];\n\t}\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tconst registeredFlags = new Map<string, { type: \"boolean\" | \"string\" }>();\n\tfor (const extension of extensionsResult.extensions) {\n\t\tfor (const [name, flag] of extension.flags) {\n\t\t\tregisteredFlags.set(name, { type: flag.type });\n\t\t}\n\t}\n\n\tconst unknownFlags: string[] = [];\n\tfor (const [name, value] of extensionFlagValues) {\n\t\tconst flag = registeredFlags.get(name);\n\t\tif (!flag) {\n\t\t\tunknownFlags.push(name);\n\t\t\tcontinue;\n\t\t}\n\t\tif (flag.type === \"boolean\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, true);\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === \"string\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t\tcontinue;\n\t\t}\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Extension flag \"--${name}\" requires a value`,\n\t\t});\n\t}\n\n\tif (unknownFlags.length > 0) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Unknown option${unknownFlags.length === 1 ? \"\" : \"s\"}: ${unknownFlags.map((name) => `--${name}`).join(\", \")}`,\n\t\t});\n\t}\n\n\treturn diagnostics;\n}\n\n/**\n * Create cwd-bound runtime services.\n *\n * Returns services plus diagnostics. It does not create an AgentSession.\n */\nexport async function createAgentSessionServices(\n\toptions: CreateAgentSessionServicesOptions,\n): Promise<AgentSessionServices> {\n\tconst cwd = resolvePath(options.cwd);\n\tconst agentDir = options.agentDir ? resolvePath(options.agentDir) : getAgentDir();\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\n\t// A ledger failure must never block session creation or a turn — open it\n\t// best-effort and degrade to a diagnostic, never a thrown error.\n\tlet usagePerformanceStore: SqliteUsagePerformanceStore | undefined;\n\tif (!options.modelRuntime) {\n\t\ttry {\n\t\t\tusagePerformanceStore = new SqliteUsagePerformanceStore(\n\t\t\t\tjoin(agentDir, DURABLE_STATE_DATABASE_FILENAME),\n\t\t\t\toptions.sessionId,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({ type: \"warning\", message: `Usage/cost recording unavailable: ${message}` });\n\t\t}\n\t}\n\n\tconst settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n\tconst otlpEndpoint = settingsManager.getObservabilitySettings().otlpEndpoint;\n\tconst otlpExportConfig = otlpEndpoint\n\t\t? { endpoint: otlpEndpoint, headers: settingsManager.getObservabilitySettings().otlpHeaders }\n\t\t: undefined;\n\n\t// Inside a sandboxed session the supervisor advertises a credential write channel\n\t// (spec: 2026-08-22-supervisor-mediated-credential-writes). Reads are unchanged --\n\t// still the read-only projection of the host credential file -- while writes and\n\t// deletes travel the supervisor-owned socket instead of failing on the read-only\n\t// mount. Outside a sandbox this resolves to undefined and the default store applies.\n\tconst sandboxCredentialStore = createSandboxCredentialStore();\n\tconst modelRuntime =\n\t\toptions.modelRuntime ??\n\t\t(await ModelRuntime.create({\n\t\t\tauthPath: process.env.APEX_CODE_AUTH_PATH ?? (options.agentDir ? join(agentDir, \"auth.json\") : getAuthPath()),\n\t\t\tcredentials: sandboxCredentialStore,\n\t\t\tmodelsPath: join(agentDir, \"models.json\"),\n\t\t\tsignal: options.modelRuntimeSignal,\n\t\t\tusagePerformanceStore,\n\t\t\totlpExportConfig,\n\t\t}));\n\tconst resourceLoader = new DefaultResourceLoader({\n\t\t...(options.resourceLoaderOptions ?? {}),\n\t\tcwd,\n\t\tagentDir,\n\t\tsettingsManager,\n\t});\n\tawait resourceLoader.reload(options.resourceLoaderReloadOptions);\n\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tfor (const { name, config, extensionPath } of extensionsResult.runtime.pendingProviderRegistrations) {\n\t\ttry {\n\t\t\tmodelRuntime.registerProvider(name, config);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"error\",\n\t\t\t\tmessage: `Extension \"${extensionPath}\" error: ${message}`,\n\t\t\t});\n\t\t}\n\t}\n\textensionsResult.runtime.pendingProviderRegistrations = [];\n\tfor (const { provider, extensionPath } of extensionsResult.runtime.pendingNativeProviderRegistrations) {\n\t\ttry {\n\t\t\tmodelRuntime.registerNativeProvider(provider);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"error\",\n\t\t\t\tmessage: `Extension \"${extensionPath}\" error: ${message}`,\n\t\t\t});\n\t\t}\n\t}\n\textensionsResult.runtime.pendingNativeProviderRegistrations = [];\n\tawait modelRuntime.refresh({ allowNetwork: false });\n\tdiagnostics.push(...applyExtensionFlagValues(resourceLoader, options.extensionFlagValues));\n\n\t// `lspStatus` is constructed unconditionally (and outside the try) so it always\n\t// records real state transitions the pool experiences below, including the\n\t// eager-start failure the catch block handles -- not just a snapshot taken at one\n\t// fixed point in time.\n\tconst lspStatus = new LspStatusStore();\n\tlet lspPool: LspPool | undefined;\n\tlet registry: ReturnType<typeof resolveLspRegistry> | undefined;\n\tlet lspConfigured = false;\n\ttry {\n\t\tregistry = resolveLspRegistry(settingsManager.getLspSettings(), { workspace: cwd });\n\t\tlspPool = new LspPool(registry, {\n\t\t\tonStatusChange: (status) =>\n\t\t\t\tlspStatus.record({\n\t\t\t\t\tserverId: status.serverId,\n\t\t\t\t\troot: status.root,\n\t\t\t\t\tstate: status.state,\n\t\t\t\t\tattempt: status.attempts,\n\t\t\t\t\t...(status.reason === undefined ? {} : { reason: status.reason }),\n\t\t\t\t}),\n\t\t});\n\t\tlspConfigured = registry.servers.length > 0;\n\t\t// Per the spec's \"Resolved configuration, ownership, and lifecycle\": any\n\t\t// configured entry that cannot resolve, spawn, or initialize its cwd-root\n\t\t// process within its timeout is a startup misconfiguration -- fail fast here,\n\t\t// following core/permissions/startup.ts's precedent, rather than let a broken\n\t\t// server surface only when a tool call needs it mid-run.\n\t\tif (lspConfigured) await lspPool.start();\n\t} catch (error) {\n\t\t// Name the failing binary(ies), not just the raw client/registry error: the\n\t\t// registry itself already does this for a resolution failure (missing/\n\t\t// un-spawnable binary names the command and lookup path), but a `pool.start()`\n\t\t// rejection surfaces only the first client's bare error (e.g. \"initialize timed\n\t\t// out\"), with no server id attached. `registry.servers` (resolved commands) and\n\t\t// `lspPool.status()` (which entries actually failed) are both in scope here, so\n\t\t// build the richer message without changing `LspPoolStatus`'s shape or the\n\t\t// pool's own error-propagation wire format.\n\t\tconst commandById = new Map(registry?.servers.map((server) => [server.id, server.command]) ?? []);\n\t\tconst failedEntries = (lspPool?.status() ?? []).filter(\n\t\t\t(status) => status.state === \"degraded\" || status.state === \"disabled\",\n\t\t);\n\t\tconst message =\n\t\t\tfailedEntries.length > 0\n\t\t\t\t? failedEntries\n\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t(status) =>\n\t\t\t\t\t\t\t\t`${status.serverId} (${commandById.get(status.serverId) ?? \"?\"}) at ${status.root}: ${status.reason ?? \"unknown error\"}`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"; \")\n\t\t\t\t: error instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: String(error);\n\t\tdiagnostics.push({ type: \"error\", message: `LSP startup failed: ${message}` });\n\t\t// A pool that got partway through eager start may already have spawned and\n\t\t// initialized sibling servers successfully; discarding it without disposing\n\t\t// would orphan those child processes rather than tearing them down cleanly.\n\t\tawait lspPool?.dispose().catch(() => {});\n\t\tlspConfigured = false;\n\t\tlspPool = new LspPool({ workspace: cwd, servers: [], platform: process.platform });\n\t}\n\tconst lspDiagnostics = new LspDiagnostics(lspPool);\n\n\treturn {\n\t\tcwd,\n\t\tagentDir,\n\t\tmodelRuntime,\n\t\tsettingsManager,\n\t\tresourceLoader,\n\t\tlspPool,\n\t\tlspDiagnostics,\n\t\tlspConfigured,\n\t\tlspStatus,\n\t\tdiagnostics,\n\t\tclose: async () => {\n\t\t\t// Diagnostics first: it still needs live LSP clients to send didClose\n\t\t\t// during its own teardown, so it must not outlive the pool it wraps.\n\t\t\tawait lspDiagnostics.dispose();\n\t\t\tawait lspPool.dispose();\n\t\t\tif (!options.modelRuntime) modelRuntime.close();\n\t\t},\n\t};\n}\n\n/**\n * Create an AgentSession from previously created services.\n *\n * This keeps session creation separate from service creation so callers can\n * resolve model, thinking, tools, and other session inputs against the target\n * cwd before constructing the session.\n */\nexport async function createAgentSessionFromServices(\n\toptions: CreateAgentSessionFromServicesOptions,\n): Promise<CreateAgentSessionResult> {\n\tconst { lspPool, lspDiagnostics, lspConfigured } = options.services;\n\t// Both gated on `lspConfigured` (at least one server resolved), not per-path:\n\t// the spec's \"no diagnostics injection or result change whatsoever when `lsp` is\n\t// unconfigured\" is a session-level guarantee. A session with servers configured\n\t// for *some* languages still injects diagnosticsOperations -- a mutated path with\n\t// no matching server correctly resolves to the explicit `unavailable` outcome via\n\t// `LspDiagnostics.afterMutation`'s own per-path `pool.acquire`, it is simply never\n\t// asked at all when the session has no servers whatsoever. `lspDiagnostics`\n\t// already matches `DiagnosticsOperations` structurally, so it is passed directly\n\t// rather than wrapped.\n\tconst diagnosticsOperations = lspConfigured ? lspDiagnostics : undefined;\n\tconst lspOperations: LspOperations | undefined = lspConfigured\n\t\t? {\n\t\t\t\trequest: async (absolutePath, method, params, signal) => {\n\t\t\t\t\tconst connection = await lspPool.acquire(absolutePath);\n\t\t\t\t\tif (!connection) return undefined;\n\t\t\t\t\treturn connection.client.request(method, params, signal);\n\t\t\t\t},\n\t\t\t}\n\t\t: undefined;\n\n\t// Read per call rather than captured here. The tool registry is built once at\n\t// session construction, so a key saved from the settings panel mid-session would\n\t// otherwise not take effect until restart.\n\t// Two different questions. Whether a credential resolves *now* decides whether the\n\t// tool is active, because activation happens once at construction. Resolution then\n\t// stays deferred so a key changed mid-session is picked up without a restart.\n\tconst settingsManager = options.services.settingsManager;\n\tconst webSearchOperations = resolveWebSearchOperations(settingsManager.getWebSearchSettings())\n\t\t? createDeferredWebSearchOperations(() => settingsManager.getWebSearchSettings())\n\t\t: undefined;\n\n\treturn createAgentSession({\n\t\tcwd: options.services.cwd,\n\t\tagentDir: options.services.agentDir,\n\t\tmodelRuntime: options.services.modelRuntime,\n\t\tsettingsManager: options.services.settingsManager,\n\t\tresourceLoader: options.services.resourceLoader,\n\t\tsessionManager: options.sessionManager,\n\t\tmodel: options.model,\n\t\tthinkingLevel: options.thinkingLevel,\n\t\tscopedModels: options.scopedModels,\n\t\ttools: options.tools,\n\t\texcludeTools: options.excludeTools,\n\t\tnoTools: options.noTools,\n\t\tcustomTools: options.customTools,\n\t\tsessionStartEvent: options.sessionStartEvent,\n\t\tpermissionGate: options.permissionGate,\n\t\tpermissionResponderFactory: options.permissionResponderFactory,\n\t\tdiagnosticsOperations,\n\t\tlspOperations,\n\t\twebSearchOperations,\n\t});\n}\n"]}
1
+ {"version":3,"file":"agent-session-services.js","sourceRoot":"","sources":["../../src/core/agent-session-services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,EACN,qBAAqB,GAIrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAiE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE7G,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,iCAAiC,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAEzG,iGAAiG;AACjG,MAAM,+BAA+B,GAAG,cAAc,CAAC;AA4FvD,SAAS,wBAAwB,CAChC,cAA8B,EAC9B,mBAA8D,EAC5B;IAClC,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAC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AC,oBAAoB,EAAE,CAAC;QACjF,CAAC,CAAC,SAAS,CAAC;IAEb,OAAO,kBAAkB,CAAC;QACzB,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG;QACzB,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,QAAQ;QACnC,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,YAAY;QAC3C,eAAe,EAAE,OAAO,CAAC,QAAQ,CAAC,eAAe;QACjD,cAAc,EAAE,OAAO,CAAC,QAAQ,CAAC,cAAc;QAC/C,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;QAC5C,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,0BAA0B,EAAE,OAAO,CAAC,0BAA0B;QAC9D,qBAAqB;QACrB,aAAa;QACb,mBAAmB;KACnB,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { join } from \"node:path\";\nimport type { Model } from \"@earendil-works/pi-ai\";\nimport type { ThinkingLevel } from \"apex-code-agent-core\";\nimport { getAgentDir, getAuthPath } from \"../config.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport type { SessionStartEvent, ToolDefinition } from \"./extensions/index.ts\";\nimport { LspDiagnostics } from \"./lsp/diagnostics.ts\";\nimport { LspPool } from \"./lsp/pool.ts\";\nimport { resolveLspRegistry } from \"./lsp/registry.ts\";\nimport { LspStatusStore } from \"./lsp/status.ts\";\nimport { ModelRuntime } from \"./model-runtime.ts\";\nimport type { PermissionGateOptions } from \"./permissions/gate.ts\";\nimport type { PermissionResponder } from \"./permissions/responder.ts\";\nimport {\n\tDefaultResourceLoader,\n\ttype DefaultResourceLoaderOptions,\n\ttype ResourceLoader,\n\ttype ResourceLoaderReloadOptions,\n} from \"./resource-loader.ts\";\nimport { type CreateAgentSessionOptions, type CreateAgentSessionResult, createAgentSession } from \"./sdk.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport { SettingsManager } from \"./settings-manager.ts\";\nimport type { LspOperations } from \"./tools/lsp.ts\";\nimport { SqliteUsagePerformanceStore } from \"./usage-performance-store.ts\";\nimport { createDeferredWebSearchOperations, resolveWebSearchOperations } from \"./web-search-provider.ts\";\n\n/** Filename of the shared durable-state database within an agent directory (roadmap Phase 8). */\nconst DURABLE_STATE_DATABASE_FILENAME = \"state.sqlite\";\n\n/**\n * Non-fatal issues collected while creating services or sessions.\n *\n * Runtime creation returns diagnostics to the caller instead of printing or\n * exiting. The app layer decides whether warnings should be shown and whether\n * errors should abort startup.\n */\nexport interface AgentSessionRuntimeDiagnostic {\n\ttype: \"info\" | \"warning\" | \"error\";\n\tmessage: string;\n}\n\n/**\n * Inputs for creating cwd-bound runtime services.\n *\n * These services are recreated whenever the effective session cwd changes.\n * CLI-provided resource paths should be resolved to absolute paths before they\n * reach this function, so later cwd switches do not reinterpret them.\n */\nexport interface CreateAgentSessionServicesOptions {\n\tcwd: string;\n\tagentDir?: string;\n\t/**\n\t * Session id to stamp on every usage-performance sample this runtime records.\n\t * Only observed when `modelRuntime` is not already provided — a caller-supplied\n\t * runtime owns its own store, if any.\n\t */\n\tsessionId?: string;\n\tsettingsManager?: SettingsManager;\n\tmodelRuntime?: ModelRuntime;\n\tmodelRuntimeSignal?: AbortSignal;\n\textensionFlagValues?: Map<string, boolean | string>;\n\tresourceLoaderOptions?: Omit<DefaultResourceLoaderOptions, \"cwd\" | \"agentDir\" | \"settingsManager\">;\n\tresourceLoaderReloadOptions?: ResourceLoaderReloadOptions;\n}\n\n/**\n * Inputs for creating an AgentSession from already-created services.\n *\n * Use this after services exist and any cwd-bound model/tool/session options\n * have been resolved against those services.\n */\nexport interface CreateAgentSessionFromServicesOptions {\n\tservices: AgentSessionServices;\n\tsessionManager: SessionManager;\n\tsessionStartEvent?: SessionStartEvent;\n\tmodel?: Model<any>;\n\tthinkingLevel?: ThinkingLevel;\n\tscopedModels?: Array<{ model: Model<any>; thinkingLevel?: ThinkingLevel }>;\n\ttools?: string[];\n\texcludeTools?: CreateAgentSessionOptions[\"excludeTools\"];\n\tnoTools?: CreateAgentSessionOptions[\"noTools\"];\n\tcustomTools?: ToolDefinition[];\n\tpermissionGate?: Omit<PermissionGateOptions, \"getContract\">;\n\t/** Optional headless permission bridge (ACP, spec 2026-08-31-acp-adapter.md). */\n\tpermissionResponderFactory?: () => PermissionResponder | undefined;\n}\n\n/**\n * Coherent cwd-bound runtime services for one effective session cwd.\n *\n * This is infrastructure only. The AgentSession itself is created separately so\n * session options can be resolved against these services first.\n */\nexport interface AgentSessionServices {\n\tcwd: string;\n\tagentDir: string;\n\tmodelRuntime: ModelRuntime;\n\tsettingsManager: SettingsManager;\n\tresourceLoader: ResourceLoader;\n\tlspPool: LspPool;\n\t/**\n\t * Wraps `lspPool` for `DiagnosticsOperations.afterMutation` (LSP.4). Structurally\n\t * compatible with `core/tools/diagnostics.ts`'s `DiagnosticsOperations` -- callers\n\t * pass this value directly, never importing `core/lsp/*` themselves.\n\t */\n\tlspDiagnostics: LspDiagnostics;\n\t/** True when at least one LSP server resolved -- gates registering the `lsp` tool (LSP.5). */\n\tlspConfigured: boolean;\n\t/**\n\t * Chronological, bounded record of every server-root state transition observed by\n\t * `lspPool` for this services lifetime (LSP.2). Inspectable structured state -- not\n\t * wired to any user-facing surface by this plan (see `docs/plans/2026-08-18-lsp.md`,\n\t * Task LSP.2: this is not a `/doctor` task).\n\t */\n\tlspStatus: LspStatusStore;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n\tclose(): Promise<void>;\n}\n\nfunction applyExtensionFlagValues(\n\tresourceLoader: ResourceLoader,\n\textensionFlagValues: Map<string, boolean | string> | undefined,\n): AgentSessionRuntimeDiagnostic[] {\n\tif (!extensionFlagValues) {\n\t\treturn [];\n\t}\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tconst registeredFlags = new Map<string, { type: \"boolean\" | \"string\" }>();\n\tfor (const extension of extensionsResult.extensions) {\n\t\tfor (const [name, flag] of extension.flags) {\n\t\t\tregisteredFlags.set(name, { type: flag.type });\n\t\t}\n\t}\n\n\tconst unknownFlags: string[] = [];\n\tfor (const [name, value] of extensionFlagValues) {\n\t\tconst flag = registeredFlags.get(name);\n\t\tif (!flag) {\n\t\t\tunknownFlags.push(name);\n\t\t\tcontinue;\n\t\t}\n\t\tif (flag.type === \"boolean\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, true);\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === \"string\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t\tcontinue;\n\t\t}\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Extension flag \"--${name}\" requires a value`,\n\t\t});\n\t}\n\n\tif (unknownFlags.length > 0) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Unknown option${unknownFlags.length === 1 ? \"\" : \"s\"}: ${unknownFlags.map((name) => `--${name}`).join(\", \")}`,\n\t\t});\n\t}\n\n\treturn diagnostics;\n}\n\n/**\n * Create cwd-bound runtime services.\n *\n * Returns services plus diagnostics. It does not create an AgentSession.\n */\nexport async function createAgentSessionServices(\n\toptions: CreateAgentSessionServicesOptions,\n): Promise<AgentSessionServices> {\n\tconst cwd = resolvePath(options.cwd);\n\tconst agentDir = options.agentDir ? resolvePath(options.agentDir) : getAgentDir();\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\n\t// A ledger failure must never block session creation or a turn — open it\n\t// best-effort and degrade to a diagnostic, never a thrown error.\n\tlet usagePerformanceStore: SqliteUsagePerformanceStore | undefined;\n\tif (!options.modelRuntime) {\n\t\ttry {\n\t\t\tusagePerformanceStore = new SqliteUsagePerformanceStore(\n\t\t\t\tjoin(agentDir, DURABLE_STATE_DATABASE_FILENAME),\n\t\t\t\toptions.sessionId,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({ type: \"warning\", message: `Usage/cost recording unavailable: ${message}` });\n\t\t}\n\t}\n\n\tconst settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n\tconst otlpEndpoint = settingsManager.getObservabilitySettings().otlpEndpoint;\n\tconst otlpExportConfig = otlpEndpoint\n\t\t? { endpoint: otlpEndpoint, headers: settingsManager.getObservabilitySettings().otlpHeaders }\n\t\t: undefined;\n\n\tconst modelRuntime =\n\t\toptions.modelRuntime ??\n\t\t(await ModelRuntime.create({\n\t\t\tauthPath: process.env.APEX_CODE_AUTH_PATH ?? (options.agentDir ? join(agentDir, \"auth.json\") : getAuthPath()),\n\t\t\tmodelsPath: join(agentDir, \"models.json\"),\n\t\t\tsignal: options.modelRuntimeSignal,\n\t\t\tusagePerformanceStore,\n\t\t\totlpExportConfig,\n\t\t}));\n\tconst resourceLoader = new DefaultResourceLoader({\n\t\t...(options.resourceLoaderOptions ?? {}),\n\t\tcwd,\n\t\tagentDir,\n\t\tsettingsManager,\n\t});\n\tawait resourceLoader.reload(options.resourceLoaderReloadOptions);\n\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tfor (const { name, config, extensionPath } of extensionsResult.runtime.pendingProviderRegistrations) {\n\t\ttry {\n\t\t\tmodelRuntime.registerProvider(name, config);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"error\",\n\t\t\t\tmessage: `Extension \"${extensionPath}\" error: ${message}`,\n\t\t\t});\n\t\t}\n\t}\n\textensionsResult.runtime.pendingProviderRegistrations = [];\n\tfor (const { provider, extensionPath } of extensionsResult.runtime.pendingNativeProviderRegistrations) {\n\t\ttry {\n\t\t\tmodelRuntime.registerNativeProvider(provider);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"error\",\n\t\t\t\tmessage: `Extension \"${extensionPath}\" error: ${message}`,\n\t\t\t});\n\t\t}\n\t}\n\textensionsResult.runtime.pendingNativeProviderRegistrations = [];\n\tawait modelRuntime.refresh({ allowNetwork: false });\n\tdiagnostics.push(...applyExtensionFlagValues(resourceLoader, options.extensionFlagValues));\n\n\t// `lspStatus` is constructed unconditionally (and outside the try) so it always\n\t// records real state transitions the pool experiences below, including the\n\t// eager-start failure the catch block handles -- not just a snapshot taken at one\n\t// fixed point in time.\n\tconst lspStatus = new LspStatusStore();\n\tlet lspPool: LspPool | undefined;\n\tlet registry: ReturnType<typeof resolveLspRegistry> | undefined;\n\tlet lspConfigured = false;\n\ttry {\n\t\tregistry = resolveLspRegistry(settingsManager.getLspSettings(), { workspace: cwd });\n\t\tlspPool = new LspPool(registry, {\n\t\t\tonStatusChange: (status) =>\n\t\t\t\tlspStatus.record({\n\t\t\t\t\tserverId: status.serverId,\n\t\t\t\t\troot: status.root,\n\t\t\t\t\tstate: status.state,\n\t\t\t\t\tattempt: status.attempts,\n\t\t\t\t\t...(status.reason === undefined ? {} : { reason: status.reason }),\n\t\t\t\t}),\n\t\t});\n\t\tlspConfigured = registry.servers.length > 0;\n\t\t// Per the spec's \"Resolved configuration, ownership, and lifecycle\": any\n\t\t// configured entry that cannot resolve, spawn, or initialize its cwd-root\n\t\t// process within its timeout is a startup misconfiguration -- fail fast here,\n\t\t// following core/permissions/startup.ts's precedent, rather than let a broken\n\t\t// server surface only when a tool call needs it mid-run.\n\t\tif (lspConfigured) await lspPool.start();\n\t} catch (error) {\n\t\t// Name the failing binary(ies), not just the raw client/registry error: the\n\t\t// registry itself already does this for a resolution failure (missing/\n\t\t// un-spawnable binary names the command and lookup path), but a `pool.start()`\n\t\t// rejection surfaces only the first client's bare error (e.g. \"initialize timed\n\t\t// out\"), with no server id attached. `registry.servers` (resolved commands) and\n\t\t// `lspPool.status()` (which entries actually failed) are both in scope here, so\n\t\t// build the richer message without changing `LspPoolStatus`'s shape or the\n\t\t// pool's own error-propagation wire format.\n\t\tconst commandById = new Map(registry?.servers.map((server) => [server.id, server.command]) ?? []);\n\t\tconst failedEntries = (lspPool?.status() ?? []).filter(\n\t\t\t(status) => status.state === \"degraded\" || status.state === \"disabled\",\n\t\t);\n\t\tconst message =\n\t\t\tfailedEntries.length > 0\n\t\t\t\t? failedEntries\n\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t(status) =>\n\t\t\t\t\t\t\t\t`${status.serverId} (${commandById.get(status.serverId) ?? \"?\"}) at ${status.root}: ${status.reason ?? \"unknown error\"}`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"; \")\n\t\t\t\t: error instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: String(error);\n\t\tdiagnostics.push({ type: \"error\", message: `LSP startup failed: ${message}` });\n\t\t// A pool that got partway through eager start may already have spawned and\n\t\t// initialized sibling servers successfully; discarding it without disposing\n\t\t// would orphan those child processes rather than tearing them down cleanly.\n\t\tawait lspPool?.dispose().catch(() => {});\n\t\tlspConfigured = false;\n\t\tlspPool = new LspPool({ workspace: cwd, servers: [], platform: process.platform });\n\t}\n\tconst lspDiagnostics = new LspDiagnostics(lspPool);\n\n\treturn {\n\t\tcwd,\n\t\tagentDir,\n\t\tmodelRuntime,\n\t\tsettingsManager,\n\t\tresourceLoader,\n\t\tlspPool,\n\t\tlspDiagnostics,\n\t\tlspConfigured,\n\t\tlspStatus,\n\t\tdiagnostics,\n\t\tclose: async () => {\n\t\t\t// Diagnostics first: it still needs live LSP clients to send didClose\n\t\t\t// during its own teardown, so it must not outlive the pool it wraps.\n\t\t\tawait lspDiagnostics.dispose();\n\t\t\tawait lspPool.dispose();\n\t\t\tif (!options.modelRuntime) modelRuntime.close();\n\t\t},\n\t};\n}\n\n/**\n * Create an AgentSession from previously created services.\n *\n * This keeps session creation separate from service creation so callers can\n * resolve model, thinking, tools, and other session inputs against the target\n * cwd before constructing the session.\n */\nexport async function createAgentSessionFromServices(\n\toptions: CreateAgentSessionFromServicesOptions,\n): Promise<CreateAgentSessionResult> {\n\tconst { lspPool, lspDiagnostics, lspConfigured } = options.services;\n\t// Both gated on `lspConfigured` (at least one server resolved), not per-path:\n\t// the spec's \"no diagnostics injection or result change whatsoever when `lsp` is\n\t// unconfigured\" is a session-level guarantee. A session with servers configured\n\t// for *some* languages still injects diagnosticsOperations -- a mutated path with\n\t// no matching server correctly resolves to the explicit `unavailable` outcome via\n\t// `LspDiagnostics.afterMutation`'s own per-path `pool.acquire`, it is simply never\n\t// asked at all when the session has no servers whatsoever. `lspDiagnostics`\n\t// already matches `DiagnosticsOperations` structurally, so it is passed directly\n\t// rather than wrapped.\n\tconst diagnosticsOperations = lspConfigured ? lspDiagnostics : undefined;\n\tconst lspOperations: LspOperations | undefined = lspConfigured\n\t\t? {\n\t\t\t\trequest: async (absolutePath, method, params, signal) => {\n\t\t\t\t\tconst connection = await lspPool.acquire(absolutePath);\n\t\t\t\t\tif (!connection) return undefined;\n\t\t\t\t\treturn connection.client.request(method, params, signal);\n\t\t\t\t},\n\t\t\t}\n\t\t: undefined;\n\n\t// Read per call rather than captured here. The tool registry is built once at\n\t// session construction, so a key saved from the settings panel mid-session would\n\t// otherwise not take effect until restart.\n\t// Two different questions. Whether a credential resolves *now* decides whether the\n\t// tool is active, because activation happens once at construction. Resolution then\n\t// stays deferred so a key changed mid-session is picked up without a restart.\n\tconst settingsManager = options.services.settingsManager;\n\tconst webSearchOperations = resolveWebSearchOperations(settingsManager.getWebSearchSettings())\n\t\t? createDeferredWebSearchOperations(() => settingsManager.getWebSearchSettings())\n\t\t: undefined;\n\n\treturn createAgentSession({\n\t\tcwd: options.services.cwd,\n\t\tagentDir: options.services.agentDir,\n\t\tmodelRuntime: options.services.modelRuntime,\n\t\tsettingsManager: options.services.settingsManager,\n\t\tresourceLoader: options.services.resourceLoader,\n\t\tsessionManager: options.sessionManager,\n\t\tmodel: options.model,\n\t\tthinkingLevel: options.thinkingLevel,\n\t\tscopedModels: options.scopedModels,\n\t\ttools: options.tools,\n\t\texcludeTools: options.excludeTools,\n\t\tnoTools: options.noTools,\n\t\tcustomTools: options.customTools,\n\t\tsessionStartEvent: options.sessionStartEvent,\n\t\tpermissionGate: options.permissionGate,\n\t\tpermissionResponderFactory: options.permissionResponderFactory,\n\t\tdiagnosticsOperations,\n\t\tlspOperations,\n\t\twebSearchOperations,\n\t});\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/agents.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAmB,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAS7E,MAAM,WAAW,oCAAoC;IACpD,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,gBAAgB,EAAE,MAAM,OAAO,CAAC;CAChC;AAyCD,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,oCAAoC,GAAG,uBAAuB,CAKpH","sourcesContent":["/** Markdown agent-definition discovery (roadmap Phase 5, task 5.5).\n * User definitions are always eligible. Project definitions are eligible only\n * through the existing project-trust decision; discovery never prompts or creates\n * a second trust mechanism. Files are parsed on lookup so edits take effect on the\n * next delegation and malformed definitions simply remain unavailable.\n */\n\nimport { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { parseFrontmatter } from \"../../utils/frontmatter.ts\";\nimport type { AgentDefinition, AgentDefinitionResolver } from \"./runtime.ts\";\n\ninterface AgentFrontmatter extends Record<string, unknown> {\n\tname?: unknown;\n\tdescription?: unknown;\n\ttools?: unknown;\n\tmodel?: unknown;\n}\n\nexport interface CreateAgentDefinitionResolverOptions {\n\tcwd: string;\n\tagentDir: string;\n\t/** Delegated to SettingsManager.isProjectTrusted() in production. */\n\tisProjectTrusted: () => boolean;\n}\n\nfunction parseDefinition(content: string): AgentDefinition | undefined {\n\ttry {\n\t\tconst { frontmatter, body } = parseFrontmatter<AgentFrontmatter>(content);\n\t\tif (\n\t\t\ttypeof frontmatter.name !== \"string\" ||\n\t\t\t!frontmatter.name ||\n\t\t\ttypeof frontmatter.description !== \"string\" ||\n\t\t\t!frontmatter.description ||\n\t\t\t!Array.isArray(frontmatter.tools) ||\n\t\t\t!frontmatter.tools.every((tool): tool is string => typeof tool === \"string\" && tool.length > 0) ||\n\t\t\t(frontmatter.model !== undefined && (typeof frontmatter.model !== \"string\" || !frontmatter.model))\n\t\t)\n\t\t\treturn undefined;\n\t\treturn {\n\t\t\tname: frontmatter.name,\n\t\t\tdescription: frontmatter.description,\n\t\t\ttools: [...frontmatter.tools],\n\t\t\tmodel: frontmatter.model,\n\t\t\tsystemPrompt: body,\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction discover(dir: string, agentType: string): AgentDefinition | undefined {\n\tif (!existsSync(dir)) return undefined;\n\ttry {\n\t\tfor (const filename of readdirSync(dir).sort()) {\n\t\t\tif (!filename.endsWith(\".md\")) continue;\n\t\t\tconst definition = parseDefinition(readFileSync(join(dir, filename), \"utf8\"));\n\t\t\tif (definition?.name === agentType) return definition;\n\t\t}\n\t} catch {\n\t\t// A directory that cannot be read behaves as having no usable definitions.\n\t}\n\treturn undefined;\n}\n\nexport function createAgentDefinitionResolver(options: CreateAgentDefinitionResolverOptions): AgentDefinitionResolver {\n\tconst userDir = join(options.agentDir, \"agents\");\n\tconst projectDir = join(options.cwd, \".apex-code\", \"agents\");\n\treturn (agentType) =>\n\t\tdiscover(userDir, agentType) ?? (options.isProjectTrusted() ? discover(projectDir, agentType) : undefined);\n}\n"]}
1
+ {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/agents.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAmB,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAS7E,MAAM,WAAW,oCAAoC;IACpD,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,gBAAgB,EAAE,MAAM,OAAO,CAAC;CAChC;AAyCD,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,oCAAoC,GAAG,uBAAuB,CAKpH","sourcesContent":["/** Markdown agent-definition discovery (roadmap Phase 5, task 5.5).\n * User definitions are always eligible. Project definitions are eligible only\n * through the existing project-trust decision; discovery never prompts or creates\n * a second trust mechanism. Files are parsed on lookup so edits take effect on the\n * next delegation and malformed definitions simply remain unavailable.\n */\n\nimport { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { parseFrontmatter } from \"../../utils/frontmatter.ts\";\nimport { PROJECT_AGENTS_DIR, projectResourcePathByName } from \"../project-resources.ts\";\nimport type { AgentDefinition, AgentDefinitionResolver } from \"./runtime.ts\";\n\ninterface AgentFrontmatter extends Record<string, unknown> {\n\tname?: unknown;\n\tdescription?: unknown;\n\ttools?: unknown;\n\tmodel?: unknown;\n}\n\nexport interface CreateAgentDefinitionResolverOptions {\n\tcwd: string;\n\tagentDir: string;\n\t/** Delegated to SettingsManager.isProjectTrusted() in production. */\n\tisProjectTrusted: () => boolean;\n}\n\nfunction parseDefinition(content: string): AgentDefinition | undefined {\n\ttry {\n\t\tconst { frontmatter, body } = parseFrontmatter<AgentFrontmatter>(content);\n\t\tif (\n\t\t\ttypeof frontmatter.name !== \"string\" ||\n\t\t\t!frontmatter.name ||\n\t\t\ttypeof frontmatter.description !== \"string\" ||\n\t\t\t!frontmatter.description ||\n\t\t\t!Array.isArray(frontmatter.tools) ||\n\t\t\t!frontmatter.tools.every((tool): tool is string => typeof tool === \"string\" && tool.length > 0) ||\n\t\t\t(frontmatter.model !== undefined && (typeof frontmatter.model !== \"string\" || !frontmatter.model))\n\t\t)\n\t\t\treturn undefined;\n\t\treturn {\n\t\t\tname: frontmatter.name,\n\t\t\tdescription: frontmatter.description,\n\t\t\ttools: [...frontmatter.tools],\n\t\t\tmodel: frontmatter.model,\n\t\t\tsystemPrompt: body,\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction discover(dir: string, agentType: string): AgentDefinition | undefined {\n\tif (!existsSync(dir)) return undefined;\n\ttry {\n\t\tfor (const filename of readdirSync(dir).sort()) {\n\t\t\tif (!filename.endsWith(\".md\")) continue;\n\t\t\tconst definition = parseDefinition(readFileSync(join(dir, filename), \"utf8\"));\n\t\t\tif (definition?.name === agentType) return definition;\n\t\t}\n\t} catch {\n\t\t// A directory that cannot be read behaves as having no usable definitions.\n\t}\n\treturn undefined;\n}\n\nexport function createAgentDefinitionResolver(options: CreateAgentDefinitionResolverOptions): AgentDefinitionResolver {\n\tconst userDir = join(options.agentDir, \"agents\");\n\tconst projectDir = projectResourcePathByName(options.cwd, PROJECT_AGENTS_DIR);\n\treturn (agentType) =>\n\t\tdiscover(userDir, agentType) ?? (options.isProjectTrusted() ? discover(projectDir, agentType) : undefined);\n}\n"]}
@@ -7,6 +7,7 @@
7
7
  import { existsSync, readdirSync, readFileSync } from "node:fs";
8
8
  import { join } from "node:path";
9
9
  import { parseFrontmatter } from "../../utils/frontmatter.js";
10
+ import { PROJECT_AGENTS_DIR, projectResourcePathByName } from "../project-resources.js";
10
11
  function parseDefinition(content) {
11
12
  try {
12
13
  const { frontmatter, body } = parseFrontmatter(content);
@@ -49,7 +50,7 @@ function discover(dir, agentType) {
49
50
  }
50
51
  export function createAgentDefinitionResolver(options) {
51
52
  const userDir = join(options.agentDir, "agents");
52
- const projectDir = join(options.cwd, ".apex-code", "agents");
53
+ const projectDir = projectResourcePathByName(options.cwd, PROJECT_AGENTS_DIR);
53
54
  return (agentType) => discover(userDir, agentType) ?? (options.isProjectTrusted() ? discover(projectDir, agentType) : undefined);
54
55
  }
55
56
  //# sourceMappingURL=agents.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agents.js","sourceRoot":"","sources":["../../../src/core/delegation/agents.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAiB9D,SAAS,eAAe,CAAC,OAAe,EAA+B;IACtE,IAAI,CAAC;QACJ,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,gBAAgB,CAAmB,OAAO,CAAC,CAAC;QAC1E,IACC,OAAO,WAAW,CAAC,IAAI,KAAK,QAAQ;YACpC,CAAC,WAAW,CAAC,IAAI;YACjB,OAAO,WAAW,CAAC,WAAW,KAAK,QAAQ;YAC3C,CAAC,WAAW,CAAC,WAAW;YACxB,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC;YACjC,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;YAC/F,CAAC,WAAW,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,OAAO,WAAW,CAAC,KAAK,KAAK,QAAQ,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAElG,OAAO,SAAS,CAAC;QAClB,OAAO;YACN,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,WAAW,EAAE,WAAW,CAAC,WAAW;YACpC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC;YAC7B,KAAK,EAAE,WAAW,CAAC,KAAK;YACxB,YAAY,EAAE,IAAI;SAClB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AAAA,CACD;AAED,SAAS,QAAQ,CAAC,GAAW,EAAE,SAAiB,EAA+B;IAC9E,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IACvC,IAAI,CAAC;QACJ,KAAK,MAAM,QAAQ,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YAChD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAAE,SAAS;YACxC,MAAM,UAAU,GAAG,eAAe,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YAC9E,IAAI,UAAU,EAAE,IAAI,KAAK,SAAS;gBAAE,OAAO,UAAU,CAAC;QACvD,CAAC;IACF,CAAC;IAAC,MAAM,CAAC;QACR,2EAA2E;IAC5E,CAAC;IACD,OAAO,SAAS,CAAC;AAAA,CACjB;AAED,MAAM,UAAU,6BAA6B,CAAC,OAA6C,EAA2B;IACrH,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACjD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;IAC7D,OAAO,CAAC,SAAS,EAAE,EAAE,CACpB,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAAA,CAC5G","sourcesContent":["/** Markdown agent-definition discovery (roadmap Phase 5, task 5.5).\n * User definitions are always eligible. Project definitions are eligible only\n * through the existing project-trust decision; discovery never prompts or creates\n * a second trust mechanism. Files are parsed on lookup so edits take effect on the\n * next delegation and malformed definitions simply remain unavailable.\n */\n\nimport { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { parseFrontmatter } from \"../../utils/frontmatter.ts\";\nimport type { AgentDefinition, AgentDefinitionResolver } from \"./runtime.ts\";\n\ninterface AgentFrontmatter extends Record<string, unknown> {\n\tname?: unknown;\n\tdescription?: unknown;\n\ttools?: unknown;\n\tmodel?: unknown;\n}\n\nexport interface CreateAgentDefinitionResolverOptions {\n\tcwd: string;\n\tagentDir: string;\n\t/** Delegated to SettingsManager.isProjectTrusted() in production. */\n\tisProjectTrusted: () => boolean;\n}\n\nfunction parseDefinition(content: string): AgentDefinition | undefined {\n\ttry {\n\t\tconst { frontmatter, body } = parseFrontmatter<AgentFrontmatter>(content);\n\t\tif (\n\t\t\ttypeof frontmatter.name !== \"string\" ||\n\t\t\t!frontmatter.name ||\n\t\t\ttypeof frontmatter.description !== \"string\" ||\n\t\t\t!frontmatter.description ||\n\t\t\t!Array.isArray(frontmatter.tools) ||\n\t\t\t!frontmatter.tools.every((tool): tool is string => typeof tool === \"string\" && tool.length > 0) ||\n\t\t\t(frontmatter.model !== undefined && (typeof frontmatter.model !== \"string\" || !frontmatter.model))\n\t\t)\n\t\t\treturn undefined;\n\t\treturn {\n\t\t\tname: frontmatter.name,\n\t\t\tdescription: frontmatter.description,\n\t\t\ttools: [...frontmatter.tools],\n\t\t\tmodel: frontmatter.model,\n\t\t\tsystemPrompt: body,\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction discover(dir: string, agentType: string): AgentDefinition | undefined {\n\tif (!existsSync(dir)) return undefined;\n\ttry {\n\t\tfor (const filename of readdirSync(dir).sort()) {\n\t\t\tif (!filename.endsWith(\".md\")) continue;\n\t\t\tconst definition = parseDefinition(readFileSync(join(dir, filename), \"utf8\"));\n\t\t\tif (definition?.name === agentType) return definition;\n\t\t}\n\t} catch {\n\t\t// A directory that cannot be read behaves as having no usable definitions.\n\t}\n\treturn undefined;\n}\n\nexport function createAgentDefinitionResolver(options: CreateAgentDefinitionResolverOptions): AgentDefinitionResolver {\n\tconst userDir = join(options.agentDir, \"agents\");\n\tconst projectDir = join(options.cwd, \".apex-code\", \"agents\");\n\treturn (agentType) =>\n\t\tdiscover(userDir, agentType) ?? (options.isProjectTrusted() ? discover(projectDir, agentType) : undefined);\n}\n"]}
1
+ {"version":3,"file":"agents.js","sourceRoot":"","sources":["../../../src/core/delegation/agents.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAiBxF,SAAS,eAAe,CAAC,OAAe,EAA+B;IACtE,IAAI,CAAC;QACJ,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,gBAAgB,CAAmB,OAAO,CAAC,CAAC;QAC1E,IACC,OAAO,WAAW,CAAC,IAAI,KAAK,QAAQ;YACpC,CAAC,WAAW,CAAC,IAAI;YACjB,OAAO,WAAW,CAAC,WAAW,KAAK,QAAQ;YAC3C,CAAC,WAAW,CAAC,WAAW;YACxB,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC;YACjC,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;YAC/F,CAAC,WAAW,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,OAAO,WAAW,CAAC,KAAK,KAAK,QAAQ,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAElG,OAAO,SAAS,CAAC;QACl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AAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAAA,CAC5G","sourcesContent":["/** Markdown agent-definition discovery (roadmap Phase 5, task 5.5).\n * User definitions are always eligible. Project definitions are eligible only\n * through the existing project-trust decision; discovery never prompts or creates\n * a second trust mechanism. Files are parsed on lookup so edits take effect on the\n * next delegation and malformed definitions simply remain unavailable.\n */\n\nimport { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { parseFrontmatter } from \"../../utils/frontmatter.ts\";\nimport { PROJECT_AGENTS_DIR, projectResourcePathByName } from \"../project-resources.ts\";\nimport type { AgentDefinition, AgentDefinitionResolver } from \"./runtime.ts\";\n\ninterface AgentFrontmatter extends Record<string, unknown> {\n\tname?: unknown;\n\tdescription?: unknown;\n\ttools?: unknown;\n\tmodel?: unknown;\n}\n\nexport interface CreateAgentDefinitionResolverOptions {\n\tcwd: string;\n\tagentDir: string;\n\t/** Delegated to SettingsManager.isProjectTrusted() in production. */\n\tisProjectTrusted: () => boolean;\n}\n\nfunction parseDefinition(content: string): AgentDefinition | undefined {\n\ttry {\n\t\tconst { frontmatter, body } = parseFrontmatter<AgentFrontmatter>(content);\n\t\tif (\n\t\t\ttypeof frontmatter.name !== \"string\" ||\n\t\t\t!frontmatter.name ||\n\t\t\ttypeof frontmatter.description !== \"string\" ||\n\t\t\t!frontmatter.description ||\n\t\t\t!Array.isArray(frontmatter.tools) ||\n\t\t\t!frontmatter.tools.every((tool): tool is string => typeof tool === \"string\" && tool.length > 0) ||\n\t\t\t(frontmatter.model !== undefined && (typeof frontmatter.model !== \"string\" || !frontmatter.model))\n\t\t)\n\t\t\treturn undefined;\n\t\treturn {\n\t\t\tname: frontmatter.name,\n\t\t\tdescription: frontmatter.description,\n\t\t\ttools: [...frontmatter.tools],\n\t\t\tmodel: frontmatter.model,\n\t\t\tsystemPrompt: body,\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction discover(dir: string, agentType: string): AgentDefinition | undefined {\n\tif (!existsSync(dir)) return undefined;\n\ttry {\n\t\tfor (const filename of readdirSync(dir).sort()) {\n\t\t\tif (!filename.endsWith(\".md\")) continue;\n\t\t\tconst definition = parseDefinition(readFileSync(join(dir, filename), \"utf8\"));\n\t\t\tif (definition?.name === agentType) return definition;\n\t\t}\n\t} catch {\n\t\t// A directory that cannot be read behaves as having no usable definitions.\n\t}\n\treturn undefined;\n}\n\nexport function createAgentDefinitionResolver(options: CreateAgentDefinitionResolverOptions): AgentDefinitionResolver {\n\tconst userDir = join(options.agentDir, \"agents\");\n\tconst projectDir = projectResourcePathByName(options.cwd, PROJECT_AGENTS_DIR);\n\treturn (agentType) =>\n\t\tdiscover(userDir, agentType) ?? (options.isProjectTrusted() ? discover(projectDir, agentType) : undefined);\n}\n"]}
@@ -126,11 +126,6 @@ export interface ChildSessionHandle {
126
126
  * runtime relays it onto the child-run record when present.
127
127
  */
128
128
  policy?: ChildRunPolicySnapshot;
129
- /**
130
- * True when the OS-containment supervisor marker check passed at this
131
- * handle's construction. Optional for the same reason as `policy`.
132
- */
133
- sandboxEnforced?: boolean;
134
129
  /** Release the child's resources. Called when the child or owning parent is closed. */
135
130
  dispose(): void;
136
131
  }
@@ -169,7 +164,7 @@ export interface BuildChildSessionRequest {
169
164
  timeoutMs?: number;
170
165
  }
171
166
  /** The workspace authority requested by a child. Paths are advisory claims,
172
- * never a replacement for the path-permission or sandbox enforcement. */
167
+ * never a replacement for the path-permission gate. */
173
168
  export interface ChildWorkspaceRequest {
174
169
  isolation: "shared-read" | "worktree";
175
170
  ownedPaths: readonly string[];
@@ -292,8 +287,6 @@ export interface ChildRunPolicySnapshot {
292
287
  tools: string[];
293
288
  /** The admitted capability set from the same admission projection that gated the launch. */
294
289
  capabilities: string[];
295
- /** The sandbox contract string the child was constructed under ("required" | "external" | "none"). */
296
- sandbox: string;
297
290
  /** The delegation depth bound in force for this child's own delegations. */
298
291
  maxDelegationDepth: number;
299
292
  /** The child's resolved model id (its definition's model, or the parent's current model). */
@@ -313,11 +306,10 @@ export interface ChildRunRecord {
313
306
  /** The derived policy this child was built with, persisted so session readers describe the child without re-deriving it. Optional: legacy records predate the field. */
314
307
  policy?: ChildRunPolicySnapshot;
315
308
  /**
316
- * True when the SDK's OS-containment supervisor marker check passed for the
317
- * parent session (always the case under the "required" contract, which
318
- * refuses construction without it). Absent on legacy records; false means
319
- * the contract is "external"/"none" (or no supervisor marker was present)
320
- * and the SDK already allowed the run.
309
+ * Legacy only. Records what a session written before ADR 0032 was told about OS
310
+ * containment. Absent on records written since, because nothing sets it: the
311
+ * harness ships no boundary and makes no containment claim. Retained so an older
312
+ * session still parses and still reports what it reported (ADR 0006).
321
313
  */
322
314
  sandboxEnforced?: boolean;
323
315
  workspace?: ChildWorkspaceRequest;
@@ -442,7 +434,7 @@ export interface ChildRunStatus {
442
434
  parentSessionId?: string;
443
435
  /** The derived policy the child was built with; absent on legacy records and fixture handles that never carried one. */
444
436
  policy?: ChildRunPolicySnapshot;
445
- /** True when the OS-containment supervisor marker check passed for the parent session; absent on legacy records. */
437
+ /** Legacy only, surfaced from the record; nothing sets it since ADR 0032. */
446
438
  sandboxEnforced?: boolean;
447
439
  }
448
440
  /** The registry's record of a handle's latest settled turn. */