@cortex-agent/server 2026.8.3-2 → 2026.8.6

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 (219) hide show
  1. package/defaults/config/thread-templates/agents/benchmark-coder.json +2 -2
  2. package/defaults/config/thread-templates/agents/benchmark-fixer.json +17 -0
  3. package/defaults/config/thread-templates/agents/benchmark-reviewer.json +5 -5
  4. package/defaults/config/thread-templates/templates/benchmark-coder-review-fix.json +21 -0
  5. package/defaults/plugins/cortex-system/skills/thread/SKILL.md +1 -0
  6. package/defaults/prompts/directives/benchmark-coder.md +1 -0
  7. package/defaults/prompts/directives/benchmark-fixer.md +1 -0
  8. package/defaults/prompts/directives/benchmark-reviewer.md +1 -0
  9. package/defaults/prompts/systemPrompts/benchmark-coder.md +1 -0
  10. package/defaults/prompts/systemPrompts/benchmark-fixer.md +1 -0
  11. package/defaults/prompts/systemPrompts/benchmark-reviewer.md +1 -0
  12. package/dist/agent-adapter/capabilities.d.ts +32 -1
  13. package/dist/agent-adapter/capabilities.js +39 -1
  14. package/dist/agent-adapter/claude/adapter.d.ts +15 -0
  15. package/dist/agent-adapter/claude/adapter.js +29 -7
  16. package/dist/agent-adapter/claude/spawn-args.d.ts +5 -2
  17. package/dist/agent-adapter/claude/spawn-args.js +29 -6
  18. package/dist/agent-adapter/index.js +11 -1
  19. package/dist/agent-adapter/normalize/tool-names.d.ts +4 -0
  20. package/dist/agent-adapter/normalize/tool-names.js +10 -0
  21. package/dist/agent-adapter/pi/adapter.d.ts +20 -8
  22. package/dist/agent-adapter/pi/adapter.js +130 -35
  23. package/dist/agent-adapter/pi/agent-dir.d.ts +20 -53
  24. package/dist/agent-adapter/pi/agent-dir.js +48 -89
  25. package/dist/agent-adapter/pi/custom-catalog.d.ts +10 -0
  26. package/dist/agent-adapter/pi/custom-catalog.js +42 -0
  27. package/dist/agent-adapter/pi/defaults.d.ts +9 -0
  28. package/dist/agent-adapter/pi/defaults.js +14 -4
  29. package/dist/agent-adapter/pi/discovery.d.ts +1 -3
  30. package/dist/agent-adapter/pi/discovery.js +3 -15
  31. package/dist/agent-adapter/pi/event-parser.js +8 -0
  32. package/dist/agent-adapter/pi/mcp-bridge.d.ts +13 -0
  33. package/dist/agent-adapter/pi/mcp-bridge.js +31 -6
  34. package/dist/agent-adapter/pi/mcp-duration.d.ts +28 -0
  35. package/dist/agent-adapter/pi/mcp-duration.js +48 -0
  36. package/dist/agent-adapter/pi/policy-guard.d.ts +40 -0
  37. package/dist/agent-adapter/pi/policy-guard.js +111 -0
  38. package/dist/agent-adapter/pi/providers-config.d.ts +62 -0
  39. package/dist/agent-adapter/pi/providers-config.js +101 -0
  40. package/dist/agent-adapter/pi/quota-probe.d.ts +11 -0
  41. package/dist/agent-adapter/pi/quota-probe.js +36 -0
  42. package/dist/agent-adapter/pi/quota-sink.d.ts +25 -0
  43. package/dist/agent-adapter/pi/quota-sink.js +31 -0
  44. package/dist/agent-adapter/pi/session-files.d.ts +2 -0
  45. package/dist/agent-adapter/pi/session-files.js +19 -0
  46. package/dist/agent-adapter/pi/session-support.d.ts +14 -3
  47. package/dist/agent-adapter/pi/session-support.js +8 -0
  48. package/dist/agent-adapter/pi/spawn-args.d.ts +11 -1
  49. package/dist/agent-adapter/pi/spawn-args.js +13 -0
  50. package/dist/agent-adapter/pi/tool-shims.d.ts +2 -2
  51. package/dist/agent-adapter/pi/tool-shims.js +32 -21
  52. package/dist/agent-adapter/pi/web-search.js +36 -8
  53. package/dist/agent-adapter/types.d.ts +14 -0
  54. package/dist/core/locales/en.d.ts +54 -1
  55. package/dist/core/locales/en.js +2 -0
  56. package/dist/core/locales/slices/commands.d.ts +12 -1
  57. package/dist/core/locales/slices/commands.js +24 -2
  58. package/dist/core/locales/slices/providers.d.ts +45 -0
  59. package/dist/core/locales/slices/providers.js +95 -0
  60. package/dist/core/locales/zh.js +2 -0
  61. package/dist/core/resilient-watch.d.ts +28 -0
  62. package/dist/core/resilient-watch.js +110 -0
  63. package/dist/core/settings.js +15 -20
  64. package/dist/core/types/agent-types.d.ts +6 -0
  65. package/dist/core/types/thread-types.d.ts +21 -3
  66. package/dist/domain/agent-run/agent-run-cli.js +3 -1
  67. package/dist/domain/agent-run/benchmark-local-thread-orchestrator.d.ts +31 -0
  68. package/dist/domain/agent-run/benchmark-local-thread-orchestrator.js +231 -24
  69. package/dist/domain/agent-run/benchmark-thread-identity.d.ts +15 -2
  70. package/dist/domain/agent-run/benchmark-thread-identity.js +123 -34
  71. package/dist/domain/agent-run/identity.d.ts +5 -0
  72. package/dist/domain/agent-run/identity.js +4 -1
  73. package/dist/domain/agent-run/journal.d.ts +3 -2
  74. package/dist/domain/agent-run/manifest.js +11 -4
  75. package/dist/domain/agent-run/pinned-node-process.d.ts +4 -0
  76. package/dist/domain/agent-run/pinned-node-process.js +9 -0
  77. package/dist/domain/agent-run/role-surface.d.ts +2 -2
  78. package/dist/domain/agent-run/role-surface.js +7 -3
  79. package/dist/domain/agent-run/run-config.d.ts +10 -1
  80. package/dist/domain/agent-run/run-config.js +57 -6
  81. package/dist/domain/agent-run/runner.js +149 -31
  82. package/dist/domain/agents/facade.d.ts +37 -122
  83. package/dist/domain/agents/facade.js +47 -115
  84. package/dist/domain/agents/spawn-config.d.ts +135 -0
  85. package/dist/domain/agents/spawn-config.js +121 -0
  86. package/dist/domain/benchmark/accounting-reconciliation.d.ts +98 -0
  87. package/dist/domain/benchmark/accounting-reconciliation.js +218 -0
  88. package/dist/domain/benchmark/arm-schema.d.ts +43 -0
  89. package/dist/domain/benchmark/arm-schema.js +243 -0
  90. package/dist/domain/benchmark/capabilities.d.ts +4 -0
  91. package/dist/domain/benchmark/capabilities.js +54 -0
  92. package/dist/domain/benchmark/decimal-text.d.ts +27 -0
  93. package/dist/domain/benchmark/decimal-text.js +67 -0
  94. package/dist/domain/benchmark/lease-echo.d.ts +43 -0
  95. package/dist/domain/benchmark/lease-echo.js +56 -0
  96. package/dist/domain/benchmark/policy-backed-runtime-deps.d.ts +14 -0
  97. package/dist/domain/benchmark/policy-backed-runtime-deps.js +47 -0
  98. package/dist/domain/benchmark/policy-compiler.d.ts +68 -0
  99. package/dist/domain/benchmark/policy-compiler.js +680 -0
  100. package/dist/domain/benchmark/resolved-policy.d.ts +110 -0
  101. package/dist/domain/benchmark/resolved-policy.js +195 -0
  102. package/dist/domain/benchmark/trial-adapter-factory.d.ts +38 -0
  103. package/dist/domain/benchmark/trial-adapter-factory.js +165 -0
  104. package/dist/domain/benchmark/trial-thread-adapter.d.ts +25 -0
  105. package/dist/domain/benchmark/trial-thread-adapter.js +106 -0
  106. package/dist/domain/benchmark/variant-proposal.d.ts +45 -0
  107. package/dist/domain/benchmark/variant-proposal.js +42 -0
  108. package/dist/domain/benchmark/workspace-lease.d.ts +99 -0
  109. package/dist/domain/benchmark/workspace-lease.js +272 -0
  110. package/dist/domain/costs/codex-quota.d.ts +29 -0
  111. package/dist/domain/costs/codex-quota.js +102 -0
  112. package/dist/domain/costs/cost-tracker.d.ts +48 -9
  113. package/dist/domain/costs/cost-tracker.js +74 -18
  114. package/dist/domain/costs/rate-limit-throttle.d.ts +23 -1
  115. package/dist/domain/costs/rate-limit-throttle.js +61 -6
  116. package/dist/domain/costs/resume-registry.d.ts +3 -1
  117. package/dist/domain/costs/resume-registry.js +10 -1
  118. package/dist/domain/mcp/tools/benchmark-thread-run.d.ts +26 -2
  119. package/dist/domain/mcp/tools/benchmark-thread-run.js +63 -20
  120. package/dist/domain/mcp/tools/cost.js +15 -6
  121. package/dist/domain/pi-providers/custom-provider-model.d.ts +53 -0
  122. package/dist/domain/pi-providers/custom-provider-model.js +122 -0
  123. package/dist/domain/pi-providers/custom-provider-service.d.ts +59 -0
  124. package/dist/domain/pi-providers/custom-provider-service.js +143 -0
  125. package/dist/domain/pi-providers/gateway-route-store.d.ts +23 -0
  126. package/dist/domain/pi-providers/gateway-route-store.js +78 -0
  127. package/dist/domain/pi-providers/index.d.ts +4 -0
  128. package/dist/domain/pi-providers/index.js +8 -0
  129. package/dist/domain/pi-providers/models-json-store.d.ts +6 -0
  130. package/dist/domain/pi-providers/models-json-store.js +77 -0
  131. package/dist/domain/scheduling/jobs/_shared.d.ts +4 -1
  132. package/dist/domain/scheduling/jobs/_shared.js +11 -2
  133. package/dist/domain/scheduling/jobs/scheduled-task.js +1 -0
  134. package/dist/domain/scheduling/jobs/task-dispatch.js +49 -54
  135. package/dist/domain/sessions/session-lifecycle.d.ts +22 -0
  136. package/dist/domain/sessions/session-lifecycle.js +20 -1
  137. package/dist/domain/system/system-notice.d.ts +4 -1
  138. package/dist/domain/system/system-notice.js +6 -2
  139. package/dist/domain/tasks/dispatch-utils.d.ts +0 -4
  140. package/dist/domain/tasks/dispatch-utils.js +24 -37
  141. package/dist/domain/threads/runner.d.ts +16 -1
  142. package/dist/domain/threads/runner.js +62 -8
  143. package/dist/domain/threads/template-loader.d.ts +5 -0
  144. package/dist/domain/threads/template-loader.js +120 -36
  145. package/dist/domain/threads/template-validate.d.ts +244 -0
  146. package/dist/domain/threads/template-validate.js +574 -0
  147. package/dist/domain/threads/template-validate.parity.d.ts +1 -0
  148. package/dist/domain/threads/template-validate.parity.js +47 -0
  149. package/dist/domain/threads/template-writer.d.ts +55 -0
  150. package/dist/domain/threads/template-writer.js +131 -0
  151. package/dist/domain/ui-service/app-router.d.ts +143 -1
  152. package/dist/domain/ui-service/app-router.js +29 -3
  153. package/dist/domain/ui-service/input-schemas.d.ts +228 -4
  154. package/dist/domain/ui-service/input-schemas.js +132 -1
  155. package/dist/domain/ui-service/mutate/config.d.ts +10 -1
  156. package/dist/domain/ui-service/mutate/config.js +45 -5
  157. package/dist/domain/ui-service/mutate/custom-providers.d.ts +8 -0
  158. package/dist/domain/ui-service/mutate/custom-providers.js +37 -0
  159. package/dist/domain/ui-service/mutate/profiles.d.ts +21 -0
  160. package/dist/domain/ui-service/mutate/profiles.js +156 -0
  161. package/dist/domain/ui-service/mutate/schedules.d.ts +2 -1
  162. package/dist/domain/ui-service/mutate/schedules.js +53 -3
  163. package/dist/domain/ui-service/mutate/sessions.d.ts +2 -1
  164. package/dist/domain/ui-service/mutate/sessions.js +25 -1
  165. package/dist/domain/ui-service/mutate/system.d.ts +2 -1
  166. package/dist/domain/ui-service/mutate/system.js +17 -3
  167. package/dist/domain/ui-service/mutate/thread-templates.d.ts +4 -0
  168. package/dist/domain/ui-service/mutate/thread-templates.js +71 -0
  169. package/dist/domain/ui-service/query/config.js +30 -0
  170. package/dist/domain/ui-service/query/custom-providers.d.ts +8 -0
  171. package/dist/domain/ui-service/query/custom-providers.js +13 -0
  172. package/dist/domain/ui-service/query/machine-detail.d.ts +2 -0
  173. package/dist/domain/ui-service/query/machine-detail.js +56 -0
  174. package/dist/domain/ui-service/query/machine-probe.d.ts +18 -0
  175. package/dist/domain/ui-service/query/machine-probe.js +136 -0
  176. package/dist/domain/ui-service/query/schedules.js +5 -0
  177. package/dist/domain/ui-service/query/sessions.js +8 -2
  178. package/dist/domain/ui-service/query/thread-template-detail.d.ts +8 -0
  179. package/dist/domain/ui-service/query/thread-template-detail.js +94 -0
  180. package/dist/domain/ui-service/query/thread-templates.d.ts +5 -3
  181. package/dist/domain/ui-service/query/thread-templates.js +44 -7
  182. package/dist/domain/ui-service/types.d.ts +298 -7
  183. package/dist/domain/ui-service/ui-service.js +27 -3
  184. package/dist/entry/app.js +24 -3
  185. package/dist/entry/auth-cli.d.ts +4 -1
  186. package/dist/entry/auth-cli.js +10 -2
  187. package/dist/entry/cli-help.js +6 -2
  188. package/dist/entry/cli.js +2 -1
  189. package/dist/entry/daemon.d.ts +0 -11
  190. package/dist/entry/daemon.js +5 -49
  191. package/dist/entry/provider-cli.d.ts +16 -0
  192. package/dist/entry/provider-cli.js +203 -0
  193. package/dist/events/event-types.d.ts +2 -1
  194. package/dist/orchestration/agent-runner.js +3 -2
  195. package/dist/orchestration/routing/commands/cost.d.ts +8 -0
  196. package/dist/orchestration/routing/commands/cost.js +93 -21
  197. package/dist/orchestration/routing/commands/login-custom.d.ts +26 -0
  198. package/dist/orchestration/routing/commands/login-custom.js +89 -0
  199. package/dist/orchestration/routing/commands/login.d.ts +3 -0
  200. package/dist/orchestration/routing/commands/login.js +7 -0
  201. package/dist/orchestration/routing/message-router.js +48 -33
  202. package/dist/orchestration/routing/webhook.js +1 -1
  203. package/dist/orchestration/session-events.d.ts +2 -1
  204. package/dist/orchestration/session-events.js +1 -0
  205. package/dist/orchestration/thread-callback.js +1 -1
  206. package/dist/store/conversation-history-repo.d.ts +5 -1
  207. package/dist/store/conversation-history-repo.js +2 -1
  208. package/dist/store/cost-repo.d.ts +17 -0
  209. package/dist/store/cost-repo.js +47 -5
  210. package/dist/store/profile-repo.d.ts +0 -10
  211. package/dist/store/profile-repo.js +34 -56
  212. package/dist/store/session-registry-repo.d.ts +12 -0
  213. package/dist/store/session-registry-repo.js +16 -0
  214. package/package.json +1 -1
  215. package/web/dist/assets/index-DYMfaAi4.css +1 -0
  216. package/web/dist/assets/index-uOoZjGKa.js +141 -0
  217. package/web/dist/index.html +2 -2
  218. package/web/dist/assets/index-XqBCYtkw.js +0 -139
  219. package/web/dist/assets/index-zpf3OSKC.css +0 -1
@@ -1,129 +1,42 @@
1
- import type { AgentAdapter, AgentCompactResult, AgentProcessSpawner, AgentSpawnConfig, Backend, McpComposition, NormalizedEvent } from '../../agent-adapter/index.js';
1
+ import type { AgentAdapter, AgentCompactResult, Backend } from '../../agent-adapter/index.js';
2
+ import { buildAgentSpawnConfig, filterChannelScopedPlugins } from './spawn-config.js';
3
+ import type { AgentConfig, RunAgentOptions } from './spawn-config.js';
2
4
  import type { ResolvedProfileConfig } from './profile-manager.js';
3
- import type { AgentHandle, AgentResult, ChatNoticeLevel, ContextUsage } from '../../core/types/agent-types.js';
5
+ import type { AgentHandle, AgentResult } from '../../core/types/agent-types.js';
4
6
  import { resolveRateLimitProvider, withRateLimitProvider } from './provider-run-lifecycle.js';
5
7
  export { resolveRateLimitProvider };
6
- export interface AgentConfig {
7
- model: string;
8
- backend: Backend;
9
- mode: string | null;
10
- /** Opaque rate-limit provider identity; for PI it also selects the request protocol. */
11
- provider?: string | null;
12
- extraEnv?: Record<string, string>;
13
- extraOption?: Record<string, string>;
14
- /** DR-0012: Claude adapter mode (print/tui). Only meaningful for backend='claude'. */
15
- claudeBackend?: 'print' | 'tui';
16
- /** Thinking level from the profile (backend-native value: claude → --effort, pi → --thinking).
17
- * null/undefined → nothing is passed. */
18
- thinking?: string | null;
19
- }
20
- export interface RunObserver {
21
- onEvent(event: NormalizedEvent): void;
22
- onClose?(): void | Promise<void>;
23
- }
24
- export interface RunAgentOptions {
25
- profileName?: string | null;
26
- /** Backend resume target (Claude `--resume` / PI `--session`). null → fresh (backend self-assigns
27
- * its own id). Decoupled from {@link trackSessionId}. */
28
- sessionId?: string | null;
29
- /** Stable Cortex tracking id (UI-facing identity) — surfaced as CORTEX_SESSION_ID only; does NOT
30
- * drive backend resume. Defaults to `sessionId` when unset (threads / legacy callers). */
31
- trackSessionId?: string | null;
32
- sessionKey?: string | null;
33
- channel?: string;
34
- files?: unknown[];
35
- /** Best-effort synchronous event observers; failures are logged and ignored. */
36
- observers?: RunObserver[];
37
- /** Synchronous event sinks whose write or close failure aborts the run. */
38
- requiredSinks?: RunObserver[];
39
- /** Explicit background policy. Undefined preserves the legacy thread-keyed decision. */
40
- awaitBackground?: boolean;
41
- /** Completion-only disables ambient caps and waits until continuation or process termination. */
42
- backgroundWaitPolicy?: 'bounded' | 'completion-only';
43
- /** Absolute working directory resolved by the caller for the backend process. */
44
- cwd?: string;
45
- /** Optional containment-aware process boundary for daemon-free runs. */
46
- processSpawner?: AgentProcessSpawner;
47
- /** Pre-resolved spawn input used when identity must hash the exact object before launch. */
48
- preparedSpawnConfig?: AgentSpawnConfig;
49
- /** Concrete MCP config paths frozen by a one-shot run config. */
50
- mcpConfigPaths?: string[];
51
- /** Suppress hooks for an isolated one-shot role. */
52
- disableHooks?: boolean;
53
- /** Explicit streaming policy for runs that must not load watched daemon settings. */
54
- streamDeltas?: boolean;
55
- /** Suppress legacy transcript logs when a required journal is configured. */
56
- captureTranscriptLogs?: boolean;
57
- /** Keep unavailable backend accounting null for provenance-sensitive runs. */
58
- preserveUnreportedAccounting?: boolean;
59
- /** Disable ambient global rules for a frozen role prompt. */
60
- loadCortexRules?: boolean;
61
- /** Disable daemon cost-store writes while preserving streamed cost records. */
62
- recordCost?: boolean;
63
- callbackSource?: string | null;
64
- scheduleTaskId?: string | null;
65
- isUserInitiated?: boolean;
66
- project?: string;
67
- trigger?: string;
68
- /** Cortex execution context surfaced to the MCP server child as CORTEX_THREAD_ID/PROFILE/PROJECT/SESSION_NAME env vars.
69
- * Read by the cortex_context / cortex_schedule_* MCP tools so LLMs can self-discover their thread and target schedules
70
- * at the current thread / session without guessing IDs. */
71
- threadId?: string | null;
72
- sessionName?: string | null;
73
- /** Cortex execution record id, surfaced as CORTEX_EXECUTION_ID to subprocess env. */
74
- executionId?: string | null;
75
- /** Explicit MCP privilege surface for the spawned backend. */
76
- mcpComposition?: McpComposition;
77
- /** Legacy thread-surface selector. Accepted for existing callers and resolved when the explicit
78
- * composition is absent. */
79
- useCoreMcp?: boolean;
80
- /** Recursion depth of the owning thread, surfaced to the spawned agent as CORTEX_THREAD_DEPTH
81
- * so the thread_start MCP tool can forward it for the depth guard. */
82
- threadDepth?: number | null;
83
- /** Owning dispatch task id/project, surfaced as CORTEX_TASK_ID / CORTEX_TASK_PROJECT so
84
- * `cortex-task spawn` can infer the current task as the parent of a child task. */
85
- taskId?: string | null;
86
- taskProject?: string | null;
87
- taskGeneration?: string | null;
88
- onProgress?: ((progress: any) => void) | null;
89
- onContextUsage?: ((usage: ContextUsage) => void | Promise<void>) | null;
90
- /** A complete assistant text block. `blockId` ties it to prior deltas; `noticeLevel` turns
91
- * system-authored text into semantic chat chrome without changing plain platform output. */
92
- onAssistantMessage?: ((msg: string, blockId?: string, noticeLevel?: ChatNoticeLevel) => void) | null;
93
- /** An incremental text chunk of a block still being generated (never the accumulated total).
94
- * Opt-in: callers that leave it unset receive complete messages only, exactly as before. */
95
- onAssistantDelta?: ((text: string, blockId: string) => void) | null;
96
- onToolUse?: ((name: string, input: any, toolUseId: string) => void) | null;
97
- onToolResult?: ((toolUseId: string, content: string, isError: boolean) => void) | null;
98
- onFallback?: (current: AgentConfig, next: AgentConfig, result: AgentResult | null, error?: Error) => Promise<void>;
99
- [key: string]: any;
100
- }
101
- /**
102
- * Build the gateway sub-path for a PI provider's models.json override, following the gateway's URL
103
- * convention `/m/<mode>/<endpoint>`. The `mode` selects the gateway route (gateway.yaml owns the
104
- * upstream + keys); the `provider` is both the PI `--provider` and the gateway endpoint segment.
105
- *
106
- * `provider` is required for pi profiles (validated at load time — no default, no fallback). Returns
107
- * undefined when `mode` is absent — the PI adapter then falls back to the default `/<provider>` path
108
- * (direct per-provider routing, no `/m/` mode indirection).
8
+ /** Track error notices within one provider attempt so terminal handling is durable but not noisy.
9
+ * runWithAdapter drains its event loop before rejecting, so any API Error from that attempt has
10
+ * already reached this tracker. A fallback starts a new dedupe window because its terminal
11
+ * failure must not be hidden by the previous provider's notice.
109
12
  *
110
- * Keeping this derivation in code (not in the profile) means profiles only carry the logical
111
- * `mode` name; no gateway path string leaks into profiles.json.
112
- */
113
- export declare function buildPiGatewaySubPath(mode: string | null, provider: string): string | undefined;
114
- /** Plugins that load only for sessions originating from a specific platform channel.
115
- * Mirrors the channel-gated MCP loading (loadFeishuMcp = channel.startsWith('feishu:')):
116
- * the cortex-feishu skill bundle is only relevant when the user is working inside Feishu,
117
- * so it is stripped from non-Feishu sessions even when listed in an agent's pluginDirs. */
118
- export declare const CHANNEL_SCOPED_PLUGINS: ReadonlyArray<{
119
- plugin: string;
120
- channelPrefix: string;
121
- }>;
122
- /** Drop channel-scoped plugin dirs whose channel prefix the current session does not match.
123
- * Non-scoped plugins always pass through. Matched by the plugin dir's final path segment
124
- * (basename) so substrings like `cortex-feishu-x` are not affected. */
125
- export declare function filterChannelScopedPlugins(dirs: string[] | undefined, channel: string | undefined): string[] | undefined;
126
- export declare function buildAgentSpawnConfig(options: RunAgentOptions, config: AgentConfig, anthropicBaseUrl: string | undefined): AgentSpawnConfig;
13
+ * Rate-limit API errors are HELD rather than forwarded on arrival: the backend surfaces a 429 as
14
+ * an assistant message before the turn settles, and only the settle tells us whether it was a
15
+ * failure (card) or a pause the resume registry already owns (auto-resume warning instead). */
16
+ declare class AttemptNoticeTracker {
17
+ private readonly original;
18
+ readonly options: RunAgentOptions;
19
+ private readonly forward;
20
+ private readonly generateNotices;
21
+ private attemptHasErrorNotice;
22
+ private heldError;
23
+ constructor(original: RunAgentOptions);
24
+ private observe;
25
+ /** Release a held rate-limit card. Every settle path calls this except the resumable one,
26
+ * which drops the card in favour of the auto-resume warning. */
27
+ private flushHeldError;
28
+ /** The attempt produced a result: a turn that recovered from a mid-flight API error still
29
+ * reports it, just once the outcome is known. */
30
+ settleSuccess(): void;
31
+ private emitTerminal;
32
+ private emitAutoResume;
33
+ transitionToFallback(current: AgentConfig, next: AgentConfig, result: AgentResult | null, error?: Error): Promise<void>;
34
+ emitTerminalError(error: unknown): void;
35
+ emitTerminalRateLimit(result: AgentResult): void;
36
+ }
37
+ declare function withTerminalNotices(handle: AgentHandle, notices: AttemptNoticeTracker): AgentHandle;
38
+ export { buildAgentSpawnConfig, buildPiGatewaySubPath, CHANNEL_SCOPED_PLUGINS, filterChannelScopedPlugins, } from './spawn-config.js';
39
+ export type { AgentConfig, RunAgentOptions, RunObserver } from './spawn-config.js';
127
40
  export declare function runWithAdapter(adapter: AgentAdapter, message: string, options: RunAgentOptions, config: AgentConfig, anthropicBaseUrl: string | undefined): AgentHandle;
128
41
  export interface CompactAgentRequest {
129
42
  sessionId: string;
@@ -164,6 +77,8 @@ export declare function runAgent(message: string, options?: RunAgentOptions): Ag
164
77
  export declare function allConfigsRateLimited(profileName: string | null): boolean;
165
78
  export declare const _test: {
166
79
  runWithAdapter: typeof runWithAdapter;
80
+ AttemptNoticeTracker: typeof AttemptNoticeTracker;
81
+ withTerminalNotices: typeof withTerminalNotices;
167
82
  resolveRateLimitProvider: typeof resolveRateLimitProvider;
168
83
  withRateLimitProvider: typeof withRateLimitProvider;
169
84
  buildSpawnConfig: typeof buildAgentSpawnConfig;
@@ -2,17 +2,16 @@
2
2
  // output: attributed runs with exact continuation accounting
3
3
  // pos: Backend-neutral agent run facade
4
4
  // >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
5
- import { getAdapter, resolveMcpComposition } from '../../agent-adapter/index.js';
5
+ import { getAdapter } from '../../agent-adapter/index.js';
6
6
  import { canAwaitBgContinuation, shouldAwaitBgInline, waitForBgContinuation, } from '../../agent-adapter/bg-wait.js';
7
7
  import { consumeEventStream, createProcessCloser, createRunEventTee, settleEventfulRun, } from '../../agent-adapter/event-tee.js';
8
+ import { buildAgentSpawnConfig, filterChannelScopedPlugins } from './spawn-config.js';
8
9
  import { resolveProfileConfig } from './profile-manager.js';
9
10
  import { recordCost } from '../costs/cost-tracker.js';
10
11
  import { configureEnvForMode, isApiRateLimitError, isRetryableResult, isRetryableError } from './config.js';
11
12
  import { isProviderRateLimited, isThrottled } from '../costs/rate-limit-throttle.js';
12
- import { GATEWAY_URL } from '../costs/gateway-manager.js';
13
13
  import { createLogger } from '../../core/log.js';
14
14
  import { getSettings } from '../../core/settings.js';
15
- import { loadCortexRules } from '../memory/rules-loader.js';
16
15
  import { configIsRateLimited, rateLimitedResult, resolveRateLimitProvider, withAuthLifecycle, withRateLimitProvider, } from './provider-run-lifecycle.js';
17
16
  import { t } from '../../core/i18n.js';
18
17
  export { resolveRateLimitProvider };
@@ -29,27 +28,52 @@ function terminalErrorText(message) {
29
28
  /** Track error notices within one provider attempt so terminal handling is durable but not noisy.
30
29
  * runWithAdapter drains its event loop before rejecting, so any API Error from that attempt has
31
30
  * already reached this tracker. A fallback starts a new dedupe window because its terminal
32
- * failure must not be hidden by the previous provider's notice. */
31
+ * failure must not be hidden by the previous provider's notice.
32
+ *
33
+ * Rate-limit API errors are HELD rather than forwarded on arrival: the backend surfaces a 429 as
34
+ * an assistant message before the turn settles, and only the settle tells us whether it was a
35
+ * failure (card) or a pause the resume registry already owns (auto-resume warning instead). */
33
36
  class AttemptNoticeTracker {
34
37
  original;
35
38
  options;
36
39
  forward;
37
40
  generateNotices;
38
41
  attemptHasErrorNotice = false;
42
+ heldError = null;
39
43
  constructor(original) {
40
44
  this.original = original;
41
45
  this.forward = original.onAssistantMessage ?? null;
42
46
  this.generateNotices = original.channel?.startsWith('web:') === true;
43
47
  this.options = this.forward
44
- ? { ...original, onAssistantMessage: (text, blockId, level) => this.observe(text, blockId, level) }
48
+ ? { ...original, onAssistantMessage: (text, blockId, level, action) => this.observe(text, blockId, level, action) }
45
49
  : original;
46
50
  }
47
- observe(text, blockId, level) {
51
+ observe(text, blockId, level, action) {
52
+ if (level === 'error' && this.generateNotices && isApiRateLimitError(text)) {
53
+ this.heldError = { text, ...(blockId ? { blockId } : {}) };
54
+ return;
55
+ }
48
56
  if (level === 'error')
49
57
  this.attemptHasErrorNotice = true;
50
- this.forward?.(text, blockId, level);
58
+ this.forward?.(text, blockId, level, action);
59
+ }
60
+ /** Release a held rate-limit card. Every settle path calls this except the resumable one,
61
+ * which drops the card in favour of the auto-resume warning. */
62
+ flushHeldError() {
63
+ const held = this.heldError;
64
+ this.heldError = null;
65
+ if (!held || !this.forward)
66
+ return;
67
+ this.attemptHasErrorNotice = true;
68
+ this.forward(held.text, held.blockId, 'error');
69
+ }
70
+ /** The attempt produced a result: a turn that recovered from a mid-flight API error still
71
+ * reports it, just once the outcome is known. */
72
+ settleSuccess() {
73
+ this.flushHeldError();
51
74
  }
52
75
  emitTerminal(message, displayText = terminalErrorText(message)) {
76
+ this.flushHeldError();
53
77
  if (!this.generateNotices || !this.forward || this.attemptHasErrorNotice)
54
78
  return;
55
79
  this.attemptHasErrorNotice = true;
@@ -58,14 +82,18 @@ class AttemptNoticeTracker {
58
82
  emitAutoResume(provider) {
59
83
  if (!this.original.isUserInitiated || !isProviderRateLimited(provider))
60
84
  return false;
85
+ // Paused, not failed — the held card would misreport the outcome.
86
+ this.heldError = null;
61
87
  if (this.generateNotices && this.forward && !this.attemptHasErrorNotice) {
62
88
  this.attemptHasErrorNotice = true;
63
- this.forward(t('notify.rateLimitAutoResume'), undefined, 'warning');
89
+ this.forward(t('notify.rateLimitAutoResume'), undefined, 'warning', { kind: 'cancel-resume' });
64
90
  }
65
91
  return true;
66
92
  }
67
93
  async transitionToFallback(current, next, result, error) {
68
94
  await this.original.onFallback?.(current, next, result, error);
95
+ // This attempt is over: its held card is now terminal for that provider.
96
+ this.flushHeldError();
69
97
  if (this.generateNotices) {
70
98
  this.observe(t('notify.agentFallback', {
71
99
  from: configLabel(current), to: configLabel(next),
@@ -102,6 +130,8 @@ function withTerminalNotices(handle, notices) {
102
130
  promise: handle.promise.then((result) => {
103
131
  if (result.rateLimited)
104
132
  notices.emitTerminalRateLimit(result);
133
+ else
134
+ notices.settleSuccess();
105
135
  return result;
106
136
  }, (error) => {
107
137
  if (!killed)
@@ -116,113 +146,11 @@ function withTerminalNotices(handle, notices) {
116
146
  get agentProcess() { return handle.agentProcess; },
117
147
  };
118
148
  }
119
- // --- PI gateway routing ---
120
- /**
121
- * Build the gateway sub-path for a PI provider's models.json override, following the gateway's URL
122
- * convention `/m/<mode>/<endpoint>`. The `mode` selects the gateway route (gateway.yaml owns the
123
- * upstream + keys); the `provider` is both the PI `--provider` and the gateway endpoint segment.
124
- *
125
- * `provider` is required for pi profiles (validated at load time — no default, no fallback). Returns
126
- * undefined when `mode` is absent — the PI adapter then falls back to the default `/<provider>` path
127
- * (direct per-provider routing, no `/m/` mode indirection).
128
- *
129
- * Keeping this derivation in code (not in the profile) means profiles only carry the logical
130
- * `mode` name; no gateway path string leaks into profiles.json.
131
- */
132
- export function buildPiGatewaySubPath(mode, provider) {
133
- if (!mode)
134
- return undefined;
135
- return `/m/${mode}/${provider}`;
136
- }
137
- // --- Channel-scoped plugin gating ---
138
- /** Plugins that load only for sessions originating from a specific platform channel.
139
- * Mirrors the channel-gated MCP loading (loadFeishuMcp = channel.startsWith('feishu:')):
140
- * the cortex-feishu skill bundle is only relevant when the user is working inside Feishu,
141
- * so it is stripped from non-Feishu sessions even when listed in an agent's pluginDirs. */
142
- export const CHANNEL_SCOPED_PLUGINS = [
143
- { plugin: 'cortex-feishu', channelPrefix: 'feishu:' },
144
- ];
145
- /** Drop channel-scoped plugin dirs whose channel prefix the current session does not match.
146
- * Non-scoped plugins always pass through. Matched by the plugin dir's final path segment
147
- * (basename) so substrings like `cortex-feishu-x` are not affected. */
148
- export function filterChannelScopedPlugins(dirs, channel) {
149
- if (!dirs)
150
- return dirs;
151
- return dirs.filter((dir) => {
152
- const base = dir.split('/').filter(Boolean).pop();
153
- const rule = CHANNEL_SCOPED_PLUGINS.find((r) => r.plugin === base);
154
- if (!rule)
155
- return true;
156
- return !!channel && channel.startsWith(rule.channelPrefix);
157
- });
158
- }
159
- // --- Adapter execution ---
160
- export function buildAgentSpawnConfig(options, config, anthropicBaseUrl) {
161
- // Pack the Cortex execution context only if at least one field is set, so adapters can
162
- // skip writing CORTEX_* env vars / route-context fields when there's nothing to report.
163
- const ctx = {
164
- threadId: options.threadId ?? null,
165
- profile: options.profileName ?? null,
166
- project: options.project ?? null,
167
- sessionName: options.sessionName ?? null,
168
- // Stable Cortex tracking id for CORTEX_SESSION_ID; falls back to the backend id (threads/legacy).
169
- trackSessionId: options.trackSessionId ?? options.sessionId ?? null,
170
- executionId: options.executionId ?? null,
171
- useCoreMcp: options.useCoreMcp ?? undefined,
172
- threadDepth: options.threadDepth ?? null,
173
- taskId: options.taskId ?? null,
174
- taskProject: options.taskProject ?? null,
175
- taskGeneration: options.taskGeneration ?? null,
176
- };
177
- const hasContext = !!(ctx.threadId || ctx.profile || ctx.project || ctx.sessionName || ctx.trackSessionId ||
178
- ctx.executionId || ctx.useCoreMcp || ctx.threadDepth != null || ctx.taskId ||
179
- ctx.taskProject || ctx.taskGeneration);
180
- // Load global rules (no paths frontmatter) and inject as appendSystemPrompt.
181
- // Scoped rules (with paths) are handled by the Read/Grep PostToolUse hook.
182
- const rules = options.loadCortexRules === false ? [] : loadCortexRules().global;
183
- const appendSystemPrompt = rules.length > 0
184
- ? rules.map(rule => rule.body).join('\n\n---\n\n')
185
- : undefined;
186
- return {
187
- sessionId: options.sessionId ?? null,
188
- sessionKey: options.sessionKey || options.channel || 'default',
189
- resume: !!options.sessionId,
190
- model: config.model,
191
- systemPrompt: typeof options.systemPrompt === 'string' ? options.systemPrompt : undefined,
192
- outputStyle: typeof options.outputStyle === 'string' ? options.outputStyle : undefined,
193
- cwd: options.cwd,
194
- mcpComposition: resolveMcpComposition(options.mcpComposition, options.useCoreMcp),
195
- mcpConfigPaths: options.mcpConfigPaths,
196
- disableHooks: options.disableHooks,
197
- streamDeltas: options.streamDeltas,
198
- captureTranscriptLogs: options.captureTranscriptLogs,
199
- preserveUnreportedAccounting: options.preserveUnreportedAccounting,
200
- processSpawner: options.processSpawner,
201
- pluginDirs: filterChannelScopedPlugins(Array.isArray(options.pluginDirs) ? options.pluginDirs : undefined, options.channel),
202
- env: config.extraEnv && Object.keys(config.extraEnv).length > 0 ? config.extraEnv : undefined,
203
- extraOption: config.extraOption && Object.keys(config.extraOption).length > 0 ? config.extraOption : undefined,
204
- claudeBackend: config.claudeBackend,
205
- thinking: config.thinking || undefined,
206
- channel: options.channel,
207
- claudeAgent: options.claudeAgent ?? undefined,
208
- callbackSource: options.callbackSource ?? undefined,
209
- scheduleTaskId: options.scheduleTaskId ?? undefined,
210
- isUserInitiated: !!options.isUserInitiated,
211
- rawTools: typeof options.tools === 'string' ? options.tools : undefined,
212
- anthropicBaseUrl,
213
- // PI-specific routing: provider name (= profile mode) + gateway base URL. PI adapter writes
214
- // a multi-provider models.json (writeProvidersConfig) so every PI provider lands on the
215
- // gateway. Claude ignores these fields.
216
- // PI routing: `provider` is the --provider (protocol; required for pi, validated at load — no
217
- // default). The gateway sub-path `/m/<mode>/<provider>` is derived from the profile's logical
218
- // `mode` (gateway.yaml owns the route).
219
- piProvider: config.backend === 'pi' && config.provider ? config.provider : undefined,
220
- piGatewayPath: config.backend === 'pi' && config.provider ? buildPiGatewaySubPath(config.mode, config.provider) : undefined,
221
- piGatewayBaseUrl: config.backend === 'pi' ? GATEWAY_URL : undefined,
222
- cortexContext: hasContext ? ctx : undefined,
223
- appendSystemPrompt,
224
- };
225
- }
149
+ // --- Types ---
150
+ // The spawn-config builder and its option types live in spawn-config.ts so a construction path
151
+ // can reach them without importing the ambient adapter registry (design §13 S6.1). Re-exported
152
+ // here so every existing importer of the facade keeps working against the single definition.
153
+ export { buildAgentSpawnConfig, buildPiGatewaySubPath, CHANNEL_SCOPED_PLUGINS, filterChannelScopedPlugins, } from './spawn-config.js';
226
154
  class LegacyEventDispatcher {
227
155
  adapter;
228
156
  options;
@@ -523,6 +451,8 @@ export function runAgent(message, options = {}) {
523
451
  if (!isRetryableResult(result) || isLast) {
524
452
  if (result.rateLimited)
525
453
  notices.emitTerminalRateLimit(result);
454
+ else
455
+ notices.settleSuccess();
526
456
  return result;
527
457
  }
528
458
  const modeLabel = config.mode || 'api';
@@ -572,6 +502,8 @@ export function allConfigsRateLimited(profileName) {
572
502
  // Exposed for tests/run-with-adapter.test.ts; not intended as a public API.
573
503
  export const _test = {
574
504
  runWithAdapter,
505
+ AttemptNoticeTracker,
506
+ withTerminalNotices,
575
507
  resolveRateLimitProvider,
576
508
  withRateLimitProvider,
577
509
  buildSpawnConfig: buildAgentSpawnConfig,
@@ -0,0 +1,135 @@
1
+ import type { AgentProcessSpawner, AgentSpawnConfig, Backend, McpComposition } from '../../agent-adapter/types.js';
2
+ import type { NormalizedEvent } from '../../agent-adapter/normalize/event-types.js';
3
+ import type { AgentResult, ChatNoticeLevel, ContextUsage, NoticeAction } from '../../core/types/agent-types.js';
4
+ export interface AgentConfig {
5
+ model: string;
6
+ backend: Backend;
7
+ mode: string | null;
8
+ /** Opaque rate-limit provider identity; for PI it also selects the request protocol. */
9
+ provider?: string | null;
10
+ extraEnv?: Record<string, string>;
11
+ extraOption?: Record<string, string>;
12
+ /** DR-0012: Claude adapter mode (print/tui). Only meaningful for backend='claude'. */
13
+ claudeBackend?: 'print' | 'tui';
14
+ /** Thinking level from the profile (backend-native value: claude → --effort, pi → --thinking).
15
+ * null/undefined → nothing is passed. */
16
+ thinking?: string | null;
17
+ }
18
+ export interface RunObserver {
19
+ onEvent(event: NormalizedEvent): void;
20
+ onClose?(): void | Promise<void>;
21
+ }
22
+ export interface RunAgentOptions {
23
+ profileName?: string | null;
24
+ /** Backend resume target (Claude `--resume` / PI `--session`). null → fresh (backend self-assigns
25
+ * its own id). Decoupled from {@link trackSessionId}. */
26
+ sessionId?: string | null;
27
+ /** Stable Cortex tracking id (UI-facing identity) — surfaced as CORTEX_SESSION_ID only; does NOT
28
+ * drive backend resume. Defaults to `sessionId` when unset (threads / legacy callers). */
29
+ trackSessionId?: string | null;
30
+ sessionKey?: string | null;
31
+ channel?: string;
32
+ files?: unknown[];
33
+ /** Best-effort synchronous event observers; failures are logged and ignored. */
34
+ observers?: RunObserver[];
35
+ /** Synchronous event sinks whose write or close failure aborts the run. */
36
+ requiredSinks?: RunObserver[];
37
+ /** Explicit background policy. Undefined preserves the legacy thread-keyed decision. */
38
+ awaitBackground?: boolean;
39
+ /** Completion-only disables ambient caps and waits until continuation or process termination. */
40
+ backgroundWaitPolicy?: 'bounded' | 'completion-only';
41
+ /** Absolute working directory resolved by the caller for the backend process. */
42
+ cwd?: string;
43
+ /** Optional containment-aware process boundary for daemon-free runs. */
44
+ processSpawner?: AgentProcessSpawner;
45
+ /** Pre-resolved spawn input used when identity must hash the exact object before launch. */
46
+ preparedSpawnConfig?: AgentSpawnConfig;
47
+ /** Absolute backend CLI path frozen by a trial policy. Absent resolves the CLI from PATH. */
48
+ cliPath?: string;
49
+ /** Compiled benchmark policy guard for this role; present replaces the ambient hook surface. */
50
+ benchmarkPolicyGuard?: AgentSpawnConfig['benchmarkPolicyGuard'];
51
+ /** Benchmark thread slot this step runs as. Selects the trial's compiled role before the spawn
52
+ * config is built, and is never written into it. */
53
+ benchmarkAgentSlot?: string;
54
+ /** Exact allowlisted child environment for an isolated trial; replaces host inheritance. */
55
+ pinnedEnv?: NodeJS.ProcessEnv;
56
+ /** Absolute trial deadline a backend derives its in-process call budget from (§5.6 P5). */
57
+ benchmarkDeadlineEpochMs?: number;
58
+ /** Concrete MCP config paths frozen by a one-shot run config. */
59
+ mcpConfigPaths?: string[];
60
+ /** Suppress hooks for an isolated one-shot role. */
61
+ disableHooks?: boolean;
62
+ /** Explicit streaming policy for runs that must not load watched daemon settings. */
63
+ streamDeltas?: boolean;
64
+ /** Suppress legacy transcript logs when a required journal is configured. */
65
+ captureTranscriptLogs?: boolean;
66
+ /** Keep unavailable backend accounting null for provenance-sensitive runs. */
67
+ preserveUnreportedAccounting?: boolean;
68
+ /** Disable ambient global rules for a frozen role prompt. */
69
+ loadCortexRules?: boolean;
70
+ /** Disable daemon cost-store writes while preserving streamed cost records. */
71
+ recordCost?: boolean;
72
+ callbackSource?: string | null;
73
+ scheduleTaskId?: string | null;
74
+ isUserInitiated?: boolean;
75
+ project?: string;
76
+ trigger?: string;
77
+ /** Cortex execution context surfaced to the MCP server child as CORTEX_THREAD_ID/PROFILE/PROJECT/SESSION_NAME env vars.
78
+ * Read by the cortex_context / cortex_schedule_* MCP tools so LLMs can self-discover their thread and target schedules
79
+ * at the current thread / session without guessing IDs. */
80
+ threadId?: string | null;
81
+ sessionName?: string | null;
82
+ /** Cortex execution record id, surfaced as CORTEX_EXECUTION_ID to subprocess env. */
83
+ executionId?: string | null;
84
+ /** Explicit MCP privilege surface for the spawned backend. */
85
+ mcpComposition?: McpComposition;
86
+ /** Legacy thread-surface selector. Accepted for existing callers and resolved when the explicit
87
+ * composition is absent. */
88
+ useCoreMcp?: boolean;
89
+ /** Recursion depth of the owning thread, surfaced to the spawned agent as CORTEX_THREAD_DEPTH
90
+ * so the thread_start MCP tool can forward it for the depth guard. */
91
+ threadDepth?: number | null;
92
+ /** Owning dispatch task id/project, surfaced as CORTEX_TASK_ID / CORTEX_TASK_PROJECT so
93
+ * `cortex-task spawn` can infer the current task as the parent of a child task. */
94
+ taskId?: string | null;
95
+ taskProject?: string | null;
96
+ taskGeneration?: string | null;
97
+ onProgress?: ((progress: any) => void) | null;
98
+ onContextUsage?: ((usage: ContextUsage) => void | Promise<void>) | null;
99
+ /** A complete assistant text block. `blockId` ties it to prior deltas; `noticeLevel` turns
100
+ * system-authored text into semantic chat chrome without changing plain platform output. */
101
+ onAssistantMessage?: ((msg: string, blockId?: string, noticeLevel?: ChatNoticeLevel, noticeAction?: NoticeAction) => void) | null;
102
+ /** An incremental text chunk of a block still being generated (never the accumulated total).
103
+ * Opt-in: callers that leave it unset receive complete messages only, exactly as before. */
104
+ onAssistantDelta?: ((text: string, blockId: string) => void) | null;
105
+ onToolUse?: ((name: string, input: any, toolUseId: string) => void) | null;
106
+ onToolResult?: ((toolUseId: string, content: string, isError: boolean) => void) | null;
107
+ onFallback?: (current: AgentConfig, next: AgentConfig, result: AgentResult | null, error?: Error) => Promise<void>;
108
+ [key: string]: any;
109
+ }
110
+ /**
111
+ * Build the gateway sub-path for a PI provider's models.json override, following the gateway's URL
112
+ * convention `/m/<mode>/<endpoint>`. The `mode` selects the gateway route (gateway.yaml owns the
113
+ * upstream + keys); the `provider` is both the PI `--provider` and the gateway endpoint segment.
114
+ *
115
+ * `provider` is required for pi profiles (validated at load time — no default, no fallback). Returns
116
+ * undefined when `mode` is absent — the PI adapter then falls back to the default `/<provider>` path
117
+ * (direct per-provider routing, no `/m/` mode indirection).
118
+ *
119
+ * Keeping this derivation in code (not in the profile) means profiles only carry the logical
120
+ * `mode` name; no gateway path string leaks into profiles.json.
121
+ */
122
+ export declare function buildPiGatewaySubPath(mode: string | null, provider: string): string | undefined;
123
+ /** Plugins that load only for sessions originating from a specific platform channel.
124
+ * Mirrors the channel-gated MCP loading (loadFeishuMcp = channel.startsWith('feishu:')):
125
+ * the cortex-feishu skill bundle is only relevant when the user is working inside Feishu,
126
+ * so it is stripped from non-Feishu sessions even when listed in an agent's pluginDirs. */
127
+ export declare const CHANNEL_SCOPED_PLUGINS: ReadonlyArray<{
128
+ plugin: string;
129
+ channelPrefix: string;
130
+ }>;
131
+ /** Drop channel-scoped plugin dirs whose channel prefix the current session does not match.
132
+ * Non-scoped plugins always pass through. Matched by the plugin dir's final path segment
133
+ * (basename) so substrings like `cortex-feishu-x` are not affected. */
134
+ export declare function filterChannelScopedPlugins(dirs: string[] | undefined, channel: string | undefined): string[] | undefined;
135
+ export declare function buildAgentSpawnConfig(options: RunAgentOptions, config: AgentConfig, anthropicBaseUrl: string | undefined): AgentSpawnConfig;