@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.
- package/defaults/config/thread-templates/agents/benchmark-coder.json +2 -2
- package/defaults/config/thread-templates/agents/benchmark-fixer.json +17 -0
- package/defaults/config/thread-templates/agents/benchmark-reviewer.json +5 -5
- package/defaults/config/thread-templates/templates/benchmark-coder-review-fix.json +21 -0
- package/defaults/plugins/cortex-system/skills/thread/SKILL.md +1 -0
- package/defaults/prompts/directives/benchmark-coder.md +1 -0
- package/defaults/prompts/directives/benchmark-fixer.md +1 -0
- package/defaults/prompts/directives/benchmark-reviewer.md +1 -0
- package/defaults/prompts/systemPrompts/benchmark-coder.md +1 -0
- package/defaults/prompts/systemPrompts/benchmark-fixer.md +1 -0
- package/defaults/prompts/systemPrompts/benchmark-reviewer.md +1 -0
- package/dist/agent-adapter/capabilities.d.ts +32 -1
- package/dist/agent-adapter/capabilities.js +39 -1
- package/dist/agent-adapter/claude/adapter.d.ts +15 -0
- package/dist/agent-adapter/claude/adapter.js +29 -7
- package/dist/agent-adapter/claude/spawn-args.d.ts +5 -2
- package/dist/agent-adapter/claude/spawn-args.js +29 -6
- package/dist/agent-adapter/index.js +11 -1
- package/dist/agent-adapter/normalize/tool-names.d.ts +4 -0
- package/dist/agent-adapter/normalize/tool-names.js +10 -0
- package/dist/agent-adapter/pi/adapter.d.ts +20 -8
- package/dist/agent-adapter/pi/adapter.js +130 -35
- package/dist/agent-adapter/pi/agent-dir.d.ts +20 -53
- package/dist/agent-adapter/pi/agent-dir.js +48 -89
- package/dist/agent-adapter/pi/custom-catalog.d.ts +10 -0
- package/dist/agent-adapter/pi/custom-catalog.js +42 -0
- package/dist/agent-adapter/pi/defaults.d.ts +9 -0
- package/dist/agent-adapter/pi/defaults.js +14 -4
- package/dist/agent-adapter/pi/discovery.d.ts +1 -3
- package/dist/agent-adapter/pi/discovery.js +3 -15
- package/dist/agent-adapter/pi/event-parser.js +8 -0
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +13 -0
- package/dist/agent-adapter/pi/mcp-bridge.js +31 -6
- package/dist/agent-adapter/pi/mcp-duration.d.ts +28 -0
- package/dist/agent-adapter/pi/mcp-duration.js +48 -0
- package/dist/agent-adapter/pi/policy-guard.d.ts +40 -0
- package/dist/agent-adapter/pi/policy-guard.js +111 -0
- package/dist/agent-adapter/pi/providers-config.d.ts +62 -0
- package/dist/agent-adapter/pi/providers-config.js +101 -0
- package/dist/agent-adapter/pi/quota-probe.d.ts +11 -0
- package/dist/agent-adapter/pi/quota-probe.js +36 -0
- package/dist/agent-adapter/pi/quota-sink.d.ts +25 -0
- package/dist/agent-adapter/pi/quota-sink.js +31 -0
- package/dist/agent-adapter/pi/session-files.d.ts +2 -0
- package/dist/agent-adapter/pi/session-files.js +19 -0
- package/dist/agent-adapter/pi/session-support.d.ts +14 -3
- package/dist/agent-adapter/pi/session-support.js +8 -0
- package/dist/agent-adapter/pi/spawn-args.d.ts +11 -1
- package/dist/agent-adapter/pi/spawn-args.js +13 -0
- package/dist/agent-adapter/pi/tool-shims.d.ts +2 -2
- package/dist/agent-adapter/pi/tool-shims.js +32 -21
- package/dist/agent-adapter/pi/web-search.js +36 -8
- package/dist/agent-adapter/types.d.ts +14 -0
- package/dist/core/locales/en.d.ts +54 -1
- package/dist/core/locales/en.js +2 -0
- package/dist/core/locales/slices/commands.d.ts +12 -1
- package/dist/core/locales/slices/commands.js +24 -2
- package/dist/core/locales/slices/providers.d.ts +45 -0
- package/dist/core/locales/slices/providers.js +95 -0
- package/dist/core/locales/zh.js +2 -0
- package/dist/core/resilient-watch.d.ts +28 -0
- package/dist/core/resilient-watch.js +110 -0
- package/dist/core/settings.js +15 -20
- package/dist/core/types/agent-types.d.ts +6 -0
- package/dist/core/types/thread-types.d.ts +21 -3
- package/dist/domain/agent-run/agent-run-cli.js +3 -1
- package/dist/domain/agent-run/benchmark-local-thread-orchestrator.d.ts +31 -0
- package/dist/domain/agent-run/benchmark-local-thread-orchestrator.js +231 -24
- package/dist/domain/agent-run/benchmark-thread-identity.d.ts +15 -2
- package/dist/domain/agent-run/benchmark-thread-identity.js +123 -34
- package/dist/domain/agent-run/identity.d.ts +5 -0
- package/dist/domain/agent-run/identity.js +4 -1
- package/dist/domain/agent-run/journal.d.ts +3 -2
- package/dist/domain/agent-run/manifest.js +11 -4
- package/dist/domain/agent-run/pinned-node-process.d.ts +4 -0
- package/dist/domain/agent-run/pinned-node-process.js +9 -0
- package/dist/domain/agent-run/role-surface.d.ts +2 -2
- package/dist/domain/agent-run/role-surface.js +7 -3
- package/dist/domain/agent-run/run-config.d.ts +10 -1
- package/dist/domain/agent-run/run-config.js +57 -6
- package/dist/domain/agent-run/runner.js +149 -31
- package/dist/domain/agents/facade.d.ts +37 -122
- package/dist/domain/agents/facade.js +47 -115
- package/dist/domain/agents/spawn-config.d.ts +135 -0
- package/dist/domain/agents/spawn-config.js +121 -0
- package/dist/domain/benchmark/accounting-reconciliation.d.ts +98 -0
- package/dist/domain/benchmark/accounting-reconciliation.js +218 -0
- package/dist/domain/benchmark/arm-schema.d.ts +43 -0
- package/dist/domain/benchmark/arm-schema.js +243 -0
- package/dist/domain/benchmark/capabilities.d.ts +4 -0
- package/dist/domain/benchmark/capabilities.js +54 -0
- package/dist/domain/benchmark/decimal-text.d.ts +27 -0
- package/dist/domain/benchmark/decimal-text.js +67 -0
- package/dist/domain/benchmark/lease-echo.d.ts +43 -0
- package/dist/domain/benchmark/lease-echo.js +56 -0
- package/dist/domain/benchmark/policy-backed-runtime-deps.d.ts +14 -0
- package/dist/domain/benchmark/policy-backed-runtime-deps.js +47 -0
- package/dist/domain/benchmark/policy-compiler.d.ts +68 -0
- package/dist/domain/benchmark/policy-compiler.js +680 -0
- package/dist/domain/benchmark/resolved-policy.d.ts +110 -0
- package/dist/domain/benchmark/resolved-policy.js +195 -0
- package/dist/domain/benchmark/trial-adapter-factory.d.ts +38 -0
- package/dist/domain/benchmark/trial-adapter-factory.js +165 -0
- package/dist/domain/benchmark/trial-thread-adapter.d.ts +25 -0
- package/dist/domain/benchmark/trial-thread-adapter.js +106 -0
- package/dist/domain/benchmark/variant-proposal.d.ts +45 -0
- package/dist/domain/benchmark/variant-proposal.js +42 -0
- package/dist/domain/benchmark/workspace-lease.d.ts +99 -0
- package/dist/domain/benchmark/workspace-lease.js +272 -0
- package/dist/domain/costs/codex-quota.d.ts +29 -0
- package/dist/domain/costs/codex-quota.js +102 -0
- package/dist/domain/costs/cost-tracker.d.ts +48 -9
- package/dist/domain/costs/cost-tracker.js +74 -18
- package/dist/domain/costs/rate-limit-throttle.d.ts +23 -1
- package/dist/domain/costs/rate-limit-throttle.js +61 -6
- package/dist/domain/costs/resume-registry.d.ts +3 -1
- package/dist/domain/costs/resume-registry.js +10 -1
- package/dist/domain/mcp/tools/benchmark-thread-run.d.ts +26 -2
- package/dist/domain/mcp/tools/benchmark-thread-run.js +63 -20
- package/dist/domain/mcp/tools/cost.js +15 -6
- package/dist/domain/pi-providers/custom-provider-model.d.ts +53 -0
- package/dist/domain/pi-providers/custom-provider-model.js +122 -0
- package/dist/domain/pi-providers/custom-provider-service.d.ts +59 -0
- package/dist/domain/pi-providers/custom-provider-service.js +143 -0
- package/dist/domain/pi-providers/gateway-route-store.d.ts +23 -0
- package/dist/domain/pi-providers/gateway-route-store.js +78 -0
- package/dist/domain/pi-providers/index.d.ts +4 -0
- package/dist/domain/pi-providers/index.js +8 -0
- package/dist/domain/pi-providers/models-json-store.d.ts +6 -0
- package/dist/domain/pi-providers/models-json-store.js +77 -0
- package/dist/domain/scheduling/jobs/_shared.d.ts +4 -1
- package/dist/domain/scheduling/jobs/_shared.js +11 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +1 -0
- package/dist/domain/scheduling/jobs/task-dispatch.js +49 -54
- package/dist/domain/sessions/session-lifecycle.d.ts +22 -0
- package/dist/domain/sessions/session-lifecycle.js +20 -1
- package/dist/domain/system/system-notice.d.ts +4 -1
- package/dist/domain/system/system-notice.js +6 -2
- package/dist/domain/tasks/dispatch-utils.d.ts +0 -4
- package/dist/domain/tasks/dispatch-utils.js +24 -37
- package/dist/domain/threads/runner.d.ts +16 -1
- package/dist/domain/threads/runner.js +62 -8
- package/dist/domain/threads/template-loader.d.ts +5 -0
- package/dist/domain/threads/template-loader.js +120 -36
- package/dist/domain/threads/template-validate.d.ts +244 -0
- package/dist/domain/threads/template-validate.js +574 -0
- package/dist/domain/threads/template-validate.parity.d.ts +1 -0
- package/dist/domain/threads/template-validate.parity.js +47 -0
- package/dist/domain/threads/template-writer.d.ts +55 -0
- package/dist/domain/threads/template-writer.js +131 -0
- package/dist/domain/ui-service/app-router.d.ts +143 -1
- package/dist/domain/ui-service/app-router.js +29 -3
- package/dist/domain/ui-service/input-schemas.d.ts +228 -4
- package/dist/domain/ui-service/input-schemas.js +132 -1
- package/dist/domain/ui-service/mutate/config.d.ts +10 -1
- package/dist/domain/ui-service/mutate/config.js +45 -5
- package/dist/domain/ui-service/mutate/custom-providers.d.ts +8 -0
- package/dist/domain/ui-service/mutate/custom-providers.js +37 -0
- package/dist/domain/ui-service/mutate/profiles.d.ts +21 -0
- package/dist/domain/ui-service/mutate/profiles.js +156 -0
- package/dist/domain/ui-service/mutate/schedules.d.ts +2 -1
- package/dist/domain/ui-service/mutate/schedules.js +53 -3
- package/dist/domain/ui-service/mutate/sessions.d.ts +2 -1
- package/dist/domain/ui-service/mutate/sessions.js +25 -1
- package/dist/domain/ui-service/mutate/system.d.ts +2 -1
- package/dist/domain/ui-service/mutate/system.js +17 -3
- package/dist/domain/ui-service/mutate/thread-templates.d.ts +4 -0
- package/dist/domain/ui-service/mutate/thread-templates.js +71 -0
- package/dist/domain/ui-service/query/config.js +30 -0
- package/dist/domain/ui-service/query/custom-providers.d.ts +8 -0
- package/dist/domain/ui-service/query/custom-providers.js +13 -0
- package/dist/domain/ui-service/query/machine-detail.d.ts +2 -0
- package/dist/domain/ui-service/query/machine-detail.js +56 -0
- package/dist/domain/ui-service/query/machine-probe.d.ts +18 -0
- package/dist/domain/ui-service/query/machine-probe.js +136 -0
- package/dist/domain/ui-service/query/schedules.js +5 -0
- package/dist/domain/ui-service/query/sessions.js +8 -2
- package/dist/domain/ui-service/query/thread-template-detail.d.ts +8 -0
- package/dist/domain/ui-service/query/thread-template-detail.js +94 -0
- package/dist/domain/ui-service/query/thread-templates.d.ts +5 -3
- package/dist/domain/ui-service/query/thread-templates.js +44 -7
- package/dist/domain/ui-service/types.d.ts +298 -7
- package/dist/domain/ui-service/ui-service.js +27 -3
- package/dist/entry/app.js +24 -3
- package/dist/entry/auth-cli.d.ts +4 -1
- package/dist/entry/auth-cli.js +10 -2
- package/dist/entry/cli-help.js +6 -2
- package/dist/entry/cli.js +2 -1
- package/dist/entry/daemon.d.ts +0 -11
- package/dist/entry/daemon.js +5 -49
- package/dist/entry/provider-cli.d.ts +16 -0
- package/dist/entry/provider-cli.js +203 -0
- package/dist/events/event-types.d.ts +2 -1
- package/dist/orchestration/agent-runner.js +3 -2
- package/dist/orchestration/routing/commands/cost.d.ts +8 -0
- package/dist/orchestration/routing/commands/cost.js +93 -21
- package/dist/orchestration/routing/commands/login-custom.d.ts +26 -0
- package/dist/orchestration/routing/commands/login-custom.js +89 -0
- package/dist/orchestration/routing/commands/login.d.ts +3 -0
- package/dist/orchestration/routing/commands/login.js +7 -0
- package/dist/orchestration/routing/message-router.js +48 -33
- package/dist/orchestration/routing/webhook.js +1 -1
- package/dist/orchestration/session-events.d.ts +2 -1
- package/dist/orchestration/session-events.js +1 -0
- package/dist/orchestration/thread-callback.js +1 -1
- package/dist/store/conversation-history-repo.d.ts +5 -1
- package/dist/store/conversation-history-repo.js +2 -1
- package/dist/store/cost-repo.d.ts +17 -0
- package/dist/store/cost-repo.js +47 -5
- package/dist/store/profile-repo.d.ts +0 -10
- package/dist/store/profile-repo.js +34 -56
- package/dist/store/session-registry-repo.d.ts +12 -0
- package/dist/store/session-registry-repo.js +16 -0
- package/package.json +1 -1
- package/web/dist/assets/index-DYMfaAi4.css +1 -0
- package/web/dist/assets/index-uOoZjGKa.js +141 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-XqBCYtkw.js +0 -139
- package/web/dist/assets/index-zpf3OSKC.css +0 -1
|
@@ -1,129 +1,42 @@
|
|
|
1
|
-
import type { AgentAdapter, AgentCompactResult,
|
|
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
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
|
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
|
-
// ---
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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;
|