mixdog 0.9.95 → 0.9.96
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/LICENSES/Apache-2.0.txt +201 -0
- package/LICENSES/MIT.txt +56 -0
- package/LICENSES/codex-NOTICE.txt +6 -0
- package/NOTICE.md +46 -9
- package/package.json +12 -9
- package/scripts/.tmp-coverage-report.mjs +96 -0
- package/scripts/build-tui.mjs +17 -1
- package/scripts/fixtures/patch-replay-corpus.json +98 -0
- package/src/defaults/mixdog-config.template.json +5 -8
- package/src/rules/agent/30-explorer.md +7 -4
- package/src/rules/shared/01-tool.md +20 -29
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +18 -2
- package/src/runtime/agent/orchestrator/agent-runtime/agent-progress-watchdog.mjs +31 -1
- package/src/runtime/agent/orchestrator/agent-runtime/maintenance-route.mjs +6 -17
- package/src/runtime/agent/orchestrator/agent-trace-format.mjs +12 -1
- package/src/runtime/agent/orchestrator/config.mjs +246 -67
- package/src/runtime/agent/orchestrator/mcp/client.mjs +26 -11
- package/src/runtime/agent/orchestrator/mcp/reconnect-singleflight.mjs +23 -0
- package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +113 -14
- package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +5 -1
- package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +32 -11
- package/src/runtime/agent/orchestrator/providers/gemini.mjs +89 -2
- package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +12 -1
- package/src/runtime/agent/orchestrator/providers/openai-compat-xai.mjs +19 -1
- package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +144 -39
- package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +22 -8
- package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +15 -1
- package/src/runtime/agent/orchestrator/providers/openai-transport-policy.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +3 -4
- package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +67 -7
- package/src/runtime/agent/orchestrator/providers/stream-json-pool.mjs +291 -0
- package/src/runtime/agent/orchestrator/providers/stream-json-worker.mjs +21 -0
- package/src/runtime/agent/orchestrator/session/agent-loop.mjs +28 -4
- package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +4 -33
- package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +13 -0
- package/src/runtime/agent/orchestrator/session/loop/termination.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/loop/tool-classify.mjs +0 -24
- package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +1 -27
- package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +6 -10
- package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +5 -0
- package/src/runtime/agent/orchestrator/session/manager/pending-messages.mjs +142 -84
- package/src/runtime/agent/orchestrator/session/manager/runtime-loaders.mjs +4 -0
- package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +31 -1
- package/src/runtime/agent/orchestrator/session/manager/turn-interruption.mjs +29 -9
- package/src/runtime/agent/orchestrator/session/manager.mjs +2 -0
- package/src/runtime/agent/orchestrator/session/result-classification.mjs +65 -0
- package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +86 -8
- package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +12 -0
- package/src/runtime/agent/orchestrator/session/tool-batch.mjs +3 -33
- package/src/runtime/agent/orchestrator/session/tool-result-offload.mjs +4 -5
- package/src/runtime/agent/orchestrator/stall-policy.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/bash-session.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +35 -1
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +118 -18
- package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +8 -9
- package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/builtin/device-paths.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-context-expander.mjs +6 -15
- package/src/runtime/agent/orchestrator/tools/builtin/list-tool.mjs +10 -26
- package/src/runtime/agent/orchestrator/tools/builtin/read-image.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/read-single-tool.mjs +3 -3
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool.mjs +1 -23
- package/src/runtime/agent/orchestrator/tools/builtin/rg-runner.mjs +23 -9
- package/src/runtime/agent/orchestrator/tools/builtin/search-path-diagnostics.mjs +7 -0
- package/src/runtime/agent/orchestrator/tools/builtin/search-tool.mjs +17 -39
- package/src/runtime/agent/orchestrator/tools/builtin/shell-analysis.mjs +73 -0
- package/src/runtime/agent/orchestrator/tools/builtin/shell-job-paths.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/shell-job-spawn.mjs +0 -2
- package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +3 -8
- package/src/runtime/agent/orchestrator/tools/builtin/shell-runtime.mjs +30 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +5 -5
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +87 -15
- package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +6 -15
- package/src/runtime/agent/orchestrator/tools/code-graph-tool-defs.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/lib/pwsh-standby-pool.mjs +83 -13
- package/src/runtime/agent/orchestrator/tools/patch/matcher.mjs +39 -1
- package/src/runtime/agent/orchestrator/tools/patch/orchestrator.mjs +29 -1
- package/src/runtime/agent/orchestrator/tools/patch/parsing.mjs +16 -0
- package/src/runtime/agent/orchestrator/tools/patch/v4a-convert.mjs +108 -12
- package/src/runtime/agent/orchestrator/tools/patch-tool-defs.mjs +10 -10
- package/src/runtime/agent/orchestrator/tools/shell-command.mjs +56 -8
- package/src/runtime/agent/orchestrator/tools/shell-exec-output.mjs +2 -2
- package/src/runtime/channels/lib/config.mjs +2 -2
- package/src/runtime/channels/lib/inbound-handler.mjs +1 -1
- package/src/runtime/channels/lib/scheduler.mjs +2 -2
- package/src/runtime/memory/index.mjs +5 -38
- package/src/runtime/memory/lib/agent-ipc.mjs +145 -81
- package/src/runtime/memory/lib/compact-vector-cache.mjs +88 -0
- package/src/runtime/memory/lib/core-memory-store.mjs +18 -1
- package/src/runtime/memory/lib/cycle-llm-adapters.mjs +12 -33
- package/src/runtime/memory/lib/embedding-provider.mjs +47 -26
- package/src/runtime/memory/lib/embedding-worker.mjs +30 -34
- package/src/runtime/memory/lib/http-router.mjs +8 -0
- package/src/runtime/memory/lib/ko-morph.mjs +3 -20
- package/src/runtime/memory/lib/memory-action-handlers.mjs +2 -1
- package/src/runtime/memory/lib/memory-cycle1.mjs +1 -0
- package/src/runtime/memory/lib/memory-cycle2-gate.mjs +4 -2
- package/src/runtime/memory/lib/memory-cycle2-mutations.mjs +1 -0
- package/src/runtime/memory/lib/memory-cycle3.mjs +3 -1
- package/src/runtime/memory/lib/pg/process.mjs +32 -9
- package/src/runtime/memory/tool-defs.mjs +1 -5
- package/src/runtime/search/tool-defs.mjs +2 -2
- package/src/runtime/shared/agent-route-config.mjs +119 -0
- package/src/runtime/shared/atomic-file.mjs +80 -4
- package/src/runtime/shared/channel-notification-routing.mjs +2 -2
- package/src/runtime/shared/child-guardian.mjs +204 -108
- package/src/runtime/shared/child-spawn-gate.mjs +60 -31
- package/src/runtime/shared/config.mjs +130 -44
- package/src/runtime/shared/resource-admission.mjs +146 -97
- package/src/runtime/shared/stream-progress.mjs +6 -0
- package/src/runtime/shared/tool-surface.mjs +0 -5
- package/src/runtime/shared/turn-snapshot.mjs +31 -5
- package/src/runtime/shared/turn-worktree-snapshot.mjs +14 -2
- package/src/session-runtime/config-helpers.mjs +39 -37
- package/src/session-runtime/model-route-api.mjs +7 -5
- package/src/session-runtime/provider-auth-api.mjs +0 -7
- package/src/session-runtime/runtime-core.mjs +11 -11
- package/src/session-runtime/runtime-tunables.mjs +4 -4
- package/src/session-runtime/session-lifecycle.mjs +9 -2
- package/src/session-runtime/session-turn-api.mjs +41 -9
- package/src/session-runtime/settings-api.mjs +5 -17
- package/src/session-runtime/tool-defs.mjs +3 -3
- package/src/session-runtime/workflow-agents-api.mjs +55 -81
- package/src/session-runtime/workflow.mjs +14 -24
- package/src/standalone/agent-dispatch-broker.mjs +198 -0
- package/src/standalone/agent-tool/helpers.mjs +2 -2
- package/src/standalone/agent-tool/spawn-flow.mjs +2 -0
- package/src/standalone/agent-tool/spawn-preset.mjs +11 -21
- package/src/standalone/agent-tool/tool-def.mjs +0 -14
- package/src/standalone/backend-daemon.mjs +97 -36
- package/src/standalone/channel-admin.mjs +12 -12
- package/src/standalone/channel-daemon-client.mjs +17 -1
- package/src/standalone/channel-daemon-transport.mjs +90 -8
- package/src/standalone/engine-daemon-client.mjs +380 -205
- package/src/standalone/engine-daemon-protocol.mjs +3 -4
- package/src/standalone/engine-daemon-service.mjs +378 -134
- package/src/standalone/engine-daemon-transport.mjs +268 -77
- package/src/standalone/explore-tool.mjs +187 -70
- package/src/standalone/fair-call-scheduler.mjs +264 -0
- package/src/standalone/session-protocol.mjs +188 -0
- package/src/tui/App.jsx +30 -17
- package/src/tui/app/app-view.jsx +5 -2
- package/src/tui/app/core-memory-picker.mjs +19 -19
- package/src/tui/app/doctor.mjs +5 -11
- package/src/tui/app/message-selector.mjs +103 -0
- package/src/tui/app/onboarding-steps.mjs +1 -2
- package/src/tui/app/project-picker.mjs +80 -56
- package/src/tui/app/prompt-submit.mjs +46 -41
- package/src/tui/app/resume-picker.mjs +2 -2
- package/src/tui/app/route-pickers.mjs +3 -1
- package/src/tui/app/settings-picker.mjs +6 -8
- package/src/tui/app/transcript-window.mjs +38 -0
- package/src/tui/app/use-prompt-draft-flow.mjs +5 -7
- package/src/tui/app/use-prompt-handlers.mjs +86 -21
- package/src/tui/app/use-prompt-hint.mjs +3 -2
- package/src/tui/app/use-prompt-queue-history.mjs +10 -3
- package/src/tui/app/use-transcript-scroll.mjs +9 -2
- package/src/tui/app/use-transcript-window.mjs +50 -17
- package/src/tui/components/PromptInput.jsx +71 -38
- package/src/tui/components/Spinner.jsx +1 -1
- package/src/tui/components/prompt-input/edit-helpers.mjs +9 -11
- package/src/tui/components/prompt-input/escape-policy.mjs +42 -0
- package/src/tui/components/prompt-input/immediate-render.mjs +0 -10
- package/src/tui/components/prompt-input/interrupt-policy.mjs +10 -0
- package/src/tui/components/prompt-input/restore-policy.mjs +10 -0
- package/src/tui/dist/index.mjs +920 -1592
- package/src/tui/engine/live-share.mjs +34 -0
- package/src/tui/engine/session-api-ext.mjs +1 -4
- package/src/tui/engine/session-api.mjs +103 -33
- package/src/tui/engine/session-flow.mjs +7 -1
- package/src/tui/engine/tool-card-results.mjs +4 -2
- package/src/tui/engine/tool-result-text.mjs +10 -0
- package/src/tui/engine/turn.mjs +9 -69
- package/src/tui/engine-local-session.mjs +47 -31
- package/src/tui/index.jsx +1 -2
- package/src/tui/spinner-meta.mjs +4 -4
- package/src/tui/spinner-verbs.mjs +51 -3
- package/src/standalone/engine-daemon-local-bridge.mjs +0 -20
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
workflowPresetId,
|
|
11
11
|
WORKFLOW_ROUTE_SLOTS,
|
|
12
12
|
FIXED_AGENT_SLOTS,
|
|
13
|
-
agentPresetSlot,
|
|
14
13
|
normalizeAgentId,
|
|
15
14
|
normalizeWorkflowId,
|
|
16
15
|
workflowIdFromName,
|
|
@@ -24,6 +23,7 @@ import { ONBOARDING_VERSION } from './quick-search-models.mjs';
|
|
|
24
23
|
import { findOutputStyle } from './output-styles.mjs';
|
|
25
24
|
import { ensureProviderEnabled } from './config-helpers.mjs';
|
|
26
25
|
import { fastCapableFor } from './model-capabilities.mjs';
|
|
26
|
+
import { canonicalizeAgentRouteStorage } from '../runtime/shared/agent-route-config.mjs';
|
|
27
27
|
|
|
28
28
|
// Onboarding + agents/workflows/output-style selection surface. Extracted
|
|
29
29
|
// verbatim from the runtime API object; stateless helpers are imported directly
|
|
@@ -46,67 +46,54 @@ export function createWorkflowAgentsApi(deps) {
|
|
|
46
46
|
// Search/agent picks) omits defaultRoute entirely and must NOT persist the
|
|
47
47
|
// current route as Main or recreate the session.
|
|
48
48
|
const config = getConfig();
|
|
49
|
-
const defaultRoute = hasOwn(payload, 'defaultRoute')
|
|
50
|
-
? normalizeWorkflowRoute(payload.defaultRoute, getRoute())
|
|
51
|
-
: null;
|
|
52
49
|
const workflowInput = payload.workflowRoutes && typeof payload.workflowRoutes === 'object'
|
|
53
50
|
? payload.workflowRoutes
|
|
54
51
|
: {};
|
|
55
52
|
const nextConfig = { ...config };
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (!isKnownProvider(requested)) throw new Error(`unknown provider "${payload.defaultProvider}"`);
|
|
60
|
-
nextConfig.defaultProvider = requested;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
53
|
+
const defaultRoute = hasOwn(payload, 'defaultRoute')
|
|
54
|
+
? normalizeWorkflowRoute(payload.defaultRoute, getRoute())
|
|
55
|
+
: null;
|
|
63
56
|
let presets = Array.isArray(nextConfig.presets) ? nextConfig.presets.slice() : [];
|
|
64
|
-
const
|
|
65
|
-
const touchedWorkflowSlots = new Set();
|
|
57
|
+
const agentRoutes = { ...(nextConfig.agents || {}) };
|
|
66
58
|
|
|
67
59
|
if (defaultRoute) {
|
|
68
60
|
presets = upsertWorkflowPreset(presets, 'lead', defaultRoute);
|
|
69
|
-
workflowRoutes.lead = defaultRoute;
|
|
70
61
|
nextConfig.default = workflowPresetId('lead');
|
|
71
62
|
}
|
|
72
63
|
|
|
73
64
|
for (const slot of WORKFLOW_ROUTE_SLOTS) {
|
|
65
|
+
if (!hasOwn(workflowInput, slot)) continue;
|
|
74
66
|
const normalized = normalizeWorkflowRoute(workflowInput[slot]);
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
if (slot === 'lead') {
|
|
68
|
+
if (!normalized) continue;
|
|
69
|
+
presets = upsertWorkflowPreset(presets, 'lead', normalized);
|
|
70
|
+
nextConfig.default = workflowPresetId('lead');
|
|
71
|
+
} else if (slot === 'agent') {
|
|
72
|
+
if (normalized) agentRoutes.worker = normalized;
|
|
73
|
+
else delete agentRoutes.worker;
|
|
74
|
+
} else if (slot === 'explorer') {
|
|
75
|
+
if (normalized) agentRoutes.explore = normalized;
|
|
76
|
+
else delete agentRoutes.explore;
|
|
77
|
+
} else if (slot === 'memory') {
|
|
78
|
+
if (normalized) agentRoutes.maintainer = normalized;
|
|
79
|
+
else delete agentRoutes.maintainer;
|
|
80
|
+
}
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
nextConfig.presets = presets;
|
|
82
|
-
nextConfig.
|
|
83
|
-
nextConfig.maintenance = {
|
|
84
|
-
...(nextConfig.maintenance || {}),
|
|
85
|
-
...(touchedWorkflowSlots.has('explorer') ? { explore: normalizeWorkflowRoute(workflowRoutes.explorer) } : {}),
|
|
86
|
-
...(touchedWorkflowSlots.has('memory') ? { memory: normalizeWorkflowRoute(workflowRoutes.memory) } : {}),
|
|
87
|
-
};
|
|
84
|
+
nextConfig.agents = agentRoutes;
|
|
88
85
|
const agentInput = payload.agentRoutes && typeof payload.agentRoutes === 'object'
|
|
89
86
|
? payload.agentRoutes
|
|
90
87
|
: null;
|
|
91
88
|
if (agentInput) {
|
|
92
|
-
const nextAgents = { ...
|
|
93
|
-
const nextMaintenance = { ...(nextConfig.maintenance || {}) };
|
|
89
|
+
const nextAgents = { ...agentRoutes };
|
|
94
90
|
for (const agent of FIXED_AGENT_SLOTS) {
|
|
91
|
+
if (!hasOwn(agentInput, agent.id)) continue;
|
|
95
92
|
const routeToSave = normalizeWorkflowRoute(agentInput[agent.id]);
|
|
96
|
-
if (
|
|
97
|
-
nextAgents[agent.id]
|
|
98
|
-
presets = upsertWorkflowPreset(presets, agentPresetSlot(agent.id), routeToSave);
|
|
99
|
-
if (agent.workflowSlot) {
|
|
100
|
-
workflowRoutes[agent.workflowSlot] = routeToSave;
|
|
101
|
-
presets = upsertWorkflowPreset(presets, agent.workflowSlot, routeToSave);
|
|
102
|
-
if (agent.id === 'explore') nextMaintenance.explore = routeToSave;
|
|
103
|
-
if (agent.id === 'maintainer') nextMaintenance.memory = routeToSave;
|
|
104
|
-
}
|
|
93
|
+
if (routeToSave) nextAgents[agent.id] = routeToSave;
|
|
94
|
+
else delete nextAgents[agent.id];
|
|
105
95
|
}
|
|
106
96
|
nextConfig.agents = nextAgents;
|
|
107
|
-
nextConfig.presets = presets;
|
|
108
|
-
nextConfig.workflowRoutes = workflowRoutes;
|
|
109
|
-
nextConfig.maintenance = nextMaintenance;
|
|
110
97
|
}
|
|
111
98
|
nextConfig.onboarding = {
|
|
112
99
|
...(nextConfig.onboarding || {}),
|
|
@@ -116,11 +103,13 @@ export function createWorkflowAgentsApi(deps) {
|
|
|
116
103
|
};
|
|
117
104
|
|
|
118
105
|
if (payload.searchRoute) {
|
|
119
|
-
const searchToSave =
|
|
106
|
+
const searchToSave = clean(payload.searchRoute.provider)
|
|
107
|
+
? normalizeSearchRouteConfig(payload.searchRoute)
|
|
108
|
+
: normalizeSearchRouteConfig({ provider: 'default', model: 'default', toolType: payload.searchRoute.toolType });
|
|
120
109
|
if (searchToSave) nextConfig.searchRoute = searchToSave;
|
|
121
110
|
}
|
|
122
111
|
|
|
123
|
-
saveConfigAndAdopt(nextConfig);
|
|
112
|
+
saveConfigAndAdopt(canonicalizeAgentRouteStorage(nextConfig));
|
|
124
113
|
if (defaultRoute) {
|
|
125
114
|
setRouteState(resolveRoute(getConfig(), { provider: defaultRoute.provider, model: defaultRoute.model, effort: defaultRoute.effort }));
|
|
126
115
|
const session = getSession();
|
|
@@ -362,12 +351,6 @@ export function createWorkflowAgentsApi(deps) {
|
|
|
362
351
|
clearAgentDefinitionCache(id);
|
|
363
352
|
if (payload.route) {
|
|
364
353
|
await this.setAgentRoute(id, payload.route);
|
|
365
|
-
} else if (!FIXED_AGENT_SLOTS.some((agent) => agent.id === id)
|
|
366
|
-
&& !agentRouteFromConfig(getConfig(), id, dataDir)) {
|
|
367
|
-
// Custom roles have no built-in preset fallback, so a model-less save
|
|
368
|
-
// would spawn as `agent "<id>" has no model assignment`. Seed the
|
|
369
|
-
// current default route; an unconfigured install just stays routeless.
|
|
370
|
-
try { await this.setAgentRoute(id, {}); } catch { /* no default route yet */ }
|
|
371
354
|
}
|
|
372
355
|
return this.getAgentDefinition(id);
|
|
373
356
|
},
|
|
@@ -412,10 +395,7 @@ export function createWorkflowAgentsApi(deps) {
|
|
|
412
395
|
delete agents[id];
|
|
413
396
|
nextConfig.agents = agents;
|
|
414
397
|
}
|
|
415
|
-
|
|
416
|
-
nextConfig.presets = (Array.isArray(nextConfig.presets) ? nextConfig.presets : [])
|
|
417
|
-
.filter((preset) => clean(preset?.id) !== presetId);
|
|
418
|
-
saveConfigAndAdopt(nextConfig);
|
|
398
|
+
saveConfigAndAdopt(canonicalizeAgentRouteStorage(nextConfig));
|
|
419
399
|
}
|
|
420
400
|
return { id, deleted: true, revertedToBuiltIn };
|
|
421
401
|
},
|
|
@@ -435,23 +415,31 @@ export function createWorkflowAgentsApi(deps) {
|
|
|
435
415
|
const requested = { ...(next || {}) };
|
|
436
416
|
const routeDataDir = cfgMod.getPluginData?.() || STANDALONE_DATA_DIR;
|
|
437
417
|
const stored = agentRouteFromConfig(getConfig(), id, routeDataDir) || {};
|
|
438
|
-
//
|
|
439
|
-
//
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
: (sameModel ? (stored.effort || null) : null),
|
|
450
|
-
fast: requested.fast !== undefined
|
|
451
|
-
? selectedRoute.fast === true
|
|
452
|
-
: (sameModel && stored.fast === true),
|
|
453
|
-
};
|
|
418
|
+
// No provider means no explicit override. Remove the stored route so the
|
|
419
|
+
// agent follows Main dynamically; never synthesize a provider.
|
|
420
|
+
if (!clean(requested.provider)) {
|
|
421
|
+
const nextConfig = { ...getConfig() };
|
|
422
|
+
const agents = { ...(nextConfig.agents || {}) };
|
|
423
|
+
const hadOverride = Object.prototype.hasOwnProperty.call(agents, id);
|
|
424
|
+
delete agents[id];
|
|
425
|
+
nextConfig.agents = agents;
|
|
426
|
+
if (hadOverride) saveConfigAndAdopt(canonicalizeAgentRouteStorage(nextConfig));
|
|
427
|
+
const inherited = normalizeWorkflowRoute(resolveRoute(getConfig(), {}));
|
|
428
|
+
return { ...(inherited || {}), inherited: true };
|
|
454
429
|
}
|
|
430
|
+
if (!clean(requested.model)) throw new Error('agent route requires provider and model');
|
|
431
|
+
let selectedRoute = resolveRoute(getConfig(), requested);
|
|
432
|
+
const sameModel = clean(selectedRoute.provider) === clean(stored.provider)
|
|
433
|
+
&& clean(selectedRoute.model) === clean(stored.model);
|
|
434
|
+
selectedRoute = {
|
|
435
|
+
...selectedRoute,
|
|
436
|
+
effort: requested.effort !== undefined
|
|
437
|
+
? selectedRoute.effort
|
|
438
|
+
: (sameModel ? (stored.effort || null) : null),
|
|
439
|
+
fast: requested.fast !== undefined
|
|
440
|
+
? selectedRoute.fast === true
|
|
441
|
+
: (sameModel && stored.fast === true),
|
|
442
|
+
};
|
|
455
443
|
await ensureProvidersReady(ensureProviderEnabled(getConfig(), selectedRoute.provider));
|
|
456
444
|
const modelMeta = await lookupModelMeta(selectedRoute.provider, selectedRoute.model);
|
|
457
445
|
const fastCapable = fastCapableFor(selectedRoute.provider, modelMeta);
|
|
@@ -459,26 +447,12 @@ export function createWorkflowAgentsApi(deps) {
|
|
|
459
447
|
|
|
460
448
|
const routeToSave = normalizeWorkflowRoute(selectedRoute);
|
|
461
449
|
if (!routeToSave) throw new Error('agent route requires provider and model');
|
|
462
|
-
const agent = FIXED_AGENT_SLOTS.find((item) => item.id === id);
|
|
463
450
|
const nextConfig = { ...getConfig() };
|
|
464
451
|
nextConfig.agents = {
|
|
465
452
|
...(nextConfig.agents || {}),
|
|
466
453
|
[id]: routeToSave,
|
|
467
454
|
};
|
|
468
|
-
|
|
469
|
-
if (agent?.workflowSlot) {
|
|
470
|
-
nextConfig.workflowRoutes = {
|
|
471
|
-
...(nextConfig.workflowRoutes || {}),
|
|
472
|
-
[agent.workflowSlot]: routeToSave,
|
|
473
|
-
};
|
|
474
|
-
nextConfig.presets = upsertWorkflowPreset(nextConfig.presets, agent.workflowSlot, routeToSave);
|
|
475
|
-
nextConfig.maintenance = {
|
|
476
|
-
...(nextConfig.maintenance || {}),
|
|
477
|
-
...(id === 'explore' ? { explore: routeToSave } : {}),
|
|
478
|
-
...(id === 'maintainer' ? { memory: routeToSave } : {}),
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
saveConfigAndAdopt(nextConfig);
|
|
455
|
+
saveConfigAndAdopt(canonicalizeAgentRouteStorage(nextConfig));
|
|
482
456
|
return routeToSave;
|
|
483
457
|
},
|
|
484
458
|
};
|
|
@@ -9,6 +9,7 @@ import { normalizeEffortInput } from './effort.mjs';
|
|
|
9
9
|
import { isLikelyRawModelId } from './config-helpers.mjs';
|
|
10
10
|
import { readTextSafe, readJsonSafe } from './fs-utils.mjs';
|
|
11
11
|
import { isHiddenAgent } from '../runtime/agent/orchestrator/internal-agents.mjs';
|
|
12
|
+
import { configuredAgentRouteCandidates } from '../runtime/shared/agent-route-config.mjs';
|
|
12
13
|
|
|
13
14
|
export const WORKFLOW_ROUTE_SLOTS = ['lead', 'agent', 'explorer', 'memory'];
|
|
14
15
|
export const FIXED_AGENT_SLOTS = Object.freeze([
|
|
@@ -415,16 +416,16 @@ export function upsertWorkflowPreset(presets, slot, routeLike) {
|
|
|
415
416
|
// the runtime; created via this factory.
|
|
416
417
|
export function createWorkflowRouteHelpers({ resolveDefaultProvider, findPreset }) {
|
|
417
418
|
function summarizeWorkflowRoutes(config) {
|
|
418
|
-
const routes = config?.workflowRoutes && typeof config.workflowRoutes === 'object' ? config.workflowRoutes : {};
|
|
419
|
-
const fallbackProvider = resolveDefaultProvider(config);
|
|
420
419
|
const out = {};
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
420
|
+
const lead = routeFromPreset(config, config?.default);
|
|
421
|
+
if (lead) out.lead = lead;
|
|
422
|
+
for (const [slot, agentId] of [
|
|
423
|
+
['agent', 'worker'],
|
|
424
|
+
['explorer', 'explore'],
|
|
425
|
+
['memory', 'maintainer'],
|
|
426
|
+
]) {
|
|
427
|
+
const route = agentRouteFromConfig(config, agentId);
|
|
428
|
+
if (route) out[slot] = route;
|
|
428
429
|
}
|
|
429
430
|
return out;
|
|
430
431
|
}
|
|
@@ -446,22 +447,11 @@ export function createWorkflowRouteHelpers({ resolveDefaultProvider, findPreset
|
|
|
446
447
|
// their routes live in config.agents[<id>] like the fixed roles.
|
|
447
448
|
const id = normalizeAgentId(agentId) || normalizeWorkflowId(agentId);
|
|
448
449
|
if (!id) return null;
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|| (id === 'maintainer' ? normalizeWorkflowRoute(config?.agents?.maintenance, fallback) : null);
|
|
454
|
-
if (explicit) return explicit;
|
|
455
|
-
|
|
456
|
-
const agent = FIXED_AGENT_SLOTS.find((item) => item.id === id);
|
|
457
|
-
if (agent?.workflowSlot) {
|
|
458
|
-
const workflowRoute = normalizeWorkflowRoute(config?.workflowRoutes?.[agent.workflowSlot], fallback);
|
|
459
|
-
if (workflowRoute) return workflowRoute;
|
|
450
|
+
for (const candidate of configuredAgentRouteCandidates(config, id)) {
|
|
451
|
+
const route = normalizeWorkflowRoute(candidate)
|
|
452
|
+
|| routeFromPreset(config, candidate);
|
|
453
|
+
if (route) return route;
|
|
460
454
|
}
|
|
461
|
-
|
|
462
|
-
if (id === 'explore') return routeFromPreset(config, config?.maintenance?.explore);
|
|
463
|
-
if (id === 'maintainer') return routeFromPreset(config, config?.maintenance?.memory);
|
|
464
|
-
|
|
465
455
|
return null;
|
|
466
456
|
}
|
|
467
457
|
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { createFairCallScheduler } from './fair-call-scheduler.mjs';
|
|
2
|
+
|
|
3
|
+
const MEMORY_AGENTS = Object.freeze([
|
|
4
|
+
'cycle1-agent',
|
|
5
|
+
'cycle2-agent',
|
|
6
|
+
'cycle3-agent',
|
|
7
|
+
]);
|
|
8
|
+
const MEMORY_AGENT_SET = new Set(MEMORY_AGENTS);
|
|
9
|
+
|
|
10
|
+
function abortError(signal) {
|
|
11
|
+
return signal?.reason instanceof Error
|
|
12
|
+
? signal.reason
|
|
13
|
+
: new Error(String(signal?.reason || 'agent dispatch canceled'));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function awaitSharedPreparation(promise, signal) {
|
|
17
|
+
if (!signal) return promise;
|
|
18
|
+
if (signal.aborted) return Promise.reject(abortError(signal));
|
|
19
|
+
let listener = null;
|
|
20
|
+
const aborted = new Promise((_, reject) => {
|
|
21
|
+
listener = () => reject(abortError(signal));
|
|
22
|
+
signal.addEventListener('abort', listener, { once: true });
|
|
23
|
+
});
|
|
24
|
+
return Promise.race([promise, aborted]).finally(() => {
|
|
25
|
+
if (listener) {
|
|
26
|
+
try { signal.removeEventListener('abort', listener); } catch {}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Process-singleton memory LLM broker.
|
|
33
|
+
*
|
|
34
|
+
* The backend daemon owns one provider/session graph. The separate memory
|
|
35
|
+
* process keeps PG, embeddings, and recall, and forwards only cycle LLM calls
|
|
36
|
+
* here. A singleton is NOT a serial lane: every call gets its own dispatch
|
|
37
|
+
* session + AbortController and the fair scheduler starts calls in parallel
|
|
38
|
+
* unless an operator explicitly configures a finite active limit.
|
|
39
|
+
*/
|
|
40
|
+
export function createAgentDispatchBroker({
|
|
41
|
+
loadConfig,
|
|
42
|
+
initProviders,
|
|
43
|
+
makeAgentDispatch,
|
|
44
|
+
log = () => {},
|
|
45
|
+
activeMax = Infinity,
|
|
46
|
+
queueMax = 256,
|
|
47
|
+
onActivityChanged = null,
|
|
48
|
+
} = {}) {
|
|
49
|
+
if (typeof loadConfig !== 'function') throw new TypeError('loadConfig is required');
|
|
50
|
+
if (typeof initProviders !== 'function') throw new TypeError('initProviders is required');
|
|
51
|
+
if (typeof makeAgentDispatch !== 'function') throw new TypeError('makeAgentDispatch is required');
|
|
52
|
+
|
|
53
|
+
const scheduler = createFairCallScheduler({
|
|
54
|
+
name: 'memory agent dispatch',
|
|
55
|
+
activeMax,
|
|
56
|
+
queueMax,
|
|
57
|
+
minOwnerQueue: Math.max(8, Math.floor(queueMax / 16)),
|
|
58
|
+
});
|
|
59
|
+
const inFlight = new Map();
|
|
60
|
+
const dispatchers = new Map(MEMORY_AGENTS.map((agent) => [
|
|
61
|
+
agent,
|
|
62
|
+
makeAgentDispatch({
|
|
63
|
+
agent,
|
|
64
|
+
taskType: 'maintenance',
|
|
65
|
+
sourceType: 'memory-cycle',
|
|
66
|
+
brief: false,
|
|
67
|
+
}),
|
|
68
|
+
]));
|
|
69
|
+
let nextCallId = 0;
|
|
70
|
+
let closed = false;
|
|
71
|
+
let preparedProviderSignature = null;
|
|
72
|
+
let providerPreparePromise = null;
|
|
73
|
+
|
|
74
|
+
async function prepareProviders(signal = null) {
|
|
75
|
+
const config = loadConfig();
|
|
76
|
+
const providers = config?.providers || {};
|
|
77
|
+
let signature = null;
|
|
78
|
+
try { signature = JSON.stringify(providers); } catch {}
|
|
79
|
+
if (signature !== null && preparedProviderSignature === signature) return;
|
|
80
|
+
if (providerPreparePromise) {
|
|
81
|
+
await awaitSharedPreparation(providerPreparePromise, signal);
|
|
82
|
+
if (signature !== null && preparedProviderSignature === signature) return;
|
|
83
|
+
return prepareProviders(signal);
|
|
84
|
+
}
|
|
85
|
+
const pending = Promise.resolve()
|
|
86
|
+
// Process-global preparation is shared by every request. One caller's
|
|
87
|
+
// cancellation may stop waiting but must never abort initialization
|
|
88
|
+
// underneath independent calls.
|
|
89
|
+
.then(() => initProviders(providers))
|
|
90
|
+
.then(() => {
|
|
91
|
+
preparedProviderSignature = signature;
|
|
92
|
+
});
|
|
93
|
+
const tracked = pending.finally(() => {
|
|
94
|
+
if (providerPreparePromise === tracked) providerPreparePromise = null;
|
|
95
|
+
});
|
|
96
|
+
providerPreparePromise = tracked;
|
|
97
|
+
await awaitSharedPreparation(tracked, signal);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function warmup() {
|
|
101
|
+
if (closed) throw new Error('memory agent dispatch broker is closed');
|
|
102
|
+
await prepareProviders();
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function dispatch(params = {}, { callId = null, signal = null } = {}) {
|
|
107
|
+
if (closed) return Promise.reject(new Error('memory agent dispatch broker is closed'));
|
|
108
|
+
const agent = String(params.agent || '').trim();
|
|
109
|
+
if (!MEMORY_AGENT_SET.has(agent)) {
|
|
110
|
+
return Promise.reject(new Error(`memory agent dispatch denied for "${agent || 'unknown'}"`));
|
|
111
|
+
}
|
|
112
|
+
const prompt = String(params.prompt ?? '');
|
|
113
|
+
if (!prompt) return Promise.reject(new Error(`agent dispatch prompt required for "${agent}"`));
|
|
114
|
+
|
|
115
|
+
const id = String(callId || `broker-${process.pid}-${++nextCallId}`);
|
|
116
|
+
const existing = inFlight.get(id);
|
|
117
|
+
if (existing) return existing.promise;
|
|
118
|
+
|
|
119
|
+
const controller = new AbortController();
|
|
120
|
+
const abortFromCaller = () => {
|
|
121
|
+
if (controller.signal.aborted) return;
|
|
122
|
+
try { controller.abort(signal?.reason); } catch { try { controller.abort(); } catch {} }
|
|
123
|
+
};
|
|
124
|
+
if (signal?.aborted) abortFromCaller();
|
|
125
|
+
else signal?.addEventListener?.('abort', abortFromCaller, { once: true });
|
|
126
|
+
|
|
127
|
+
const run = async () => {
|
|
128
|
+
if (controller.signal.aborted) throw abortError(controller.signal);
|
|
129
|
+
await prepareProviders(controller.signal);
|
|
130
|
+
if (controller.signal.aborted) throw abortError(controller.signal);
|
|
131
|
+
const timeout = Number(params.timeout);
|
|
132
|
+
return dispatchers.get(agent)({
|
|
133
|
+
prompt,
|
|
134
|
+
preset: params.preset || undefined,
|
|
135
|
+
cwd: typeof params.cwd === 'string' && params.cwd ? params.cwd : undefined,
|
|
136
|
+
parentSignal: controller.signal,
|
|
137
|
+
...(Number.isFinite(timeout) && timeout > 0 ? { idleTimeoutMs: timeout } : {}),
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
const promise = scheduler.enqueue(`memory:${agent}`, run, {
|
|
141
|
+
signal: controller.signal,
|
|
142
|
+
});
|
|
143
|
+
let record = null;
|
|
144
|
+
const tracked = promise.finally(() => {
|
|
145
|
+
signal?.removeEventListener?.('abort', abortFromCaller);
|
|
146
|
+
if (inFlight.get(id) === record) inFlight.delete(id);
|
|
147
|
+
try { onActivityChanged?.(snapshot()); } catch {}
|
|
148
|
+
});
|
|
149
|
+
record = { controller, promise: tracked };
|
|
150
|
+
inFlight.set(id, record);
|
|
151
|
+
try { onActivityChanged?.(snapshot()); } catch {}
|
|
152
|
+
return tracked;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function cancel(callId, reason = 'memory agent dispatch canceled') {
|
|
156
|
+
const id = String(callId || '');
|
|
157
|
+
const record = inFlight.get(id);
|
|
158
|
+
if (!record) return false;
|
|
159
|
+
try { record.controller.abort(new Error(reason)); } catch { try { record.controller.abort(); } catch {} }
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function cancelAndWait(callId, reason = 'memory agent dispatch canceled') {
|
|
164
|
+
const id = String(callId || '');
|
|
165
|
+
const record = inFlight.get(id);
|
|
166
|
+
if (!record) return false;
|
|
167
|
+
cancel(id, reason);
|
|
168
|
+
try { await record.promise; } catch {}
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function snapshot() {
|
|
173
|
+
return {
|
|
174
|
+
...scheduler.snapshot(),
|
|
175
|
+
inFlight: inFlight.size,
|
|
176
|
+
dispatchers: dispatchers.size,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function close(reason = 'memory agent dispatch broker is closed') {
|
|
181
|
+
if (closed) return;
|
|
182
|
+
closed = true;
|
|
183
|
+
for (const record of inFlight.values()) {
|
|
184
|
+
try { record.controller.abort(new Error(reason)); } catch {}
|
|
185
|
+
}
|
|
186
|
+
scheduler.close(reason);
|
|
187
|
+
log(`agent dispatch broker closed (${reason})`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
warmup,
|
|
192
|
+
dispatch,
|
|
193
|
+
cancel,
|
|
194
|
+
cancelAndWait,
|
|
195
|
+
snapshot,
|
|
196
|
+
close,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
@@ -151,8 +151,8 @@ export function synthesizePreset(config, key) {
|
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
export function normalizeAgentRoute(routeLike
|
|
155
|
-
const provider = clean(routeLike?.provider)
|
|
154
|
+
export function normalizeAgentRoute(routeLike) {
|
|
155
|
+
const provider = clean(routeLike?.provider);
|
|
156
156
|
const model = clean(routeLike?.model);
|
|
157
157
|
if (!provider || !model) return null;
|
|
158
158
|
return {
|
|
@@ -76,6 +76,8 @@ export function createSpawnFlow({
|
|
|
76
76
|
const lease = await resourceAdmission.acquire('agent', {
|
|
77
77
|
signal: admissionController.signal,
|
|
78
78
|
label: jobMeta?.tag || type,
|
|
79
|
+
ownerKey: notifyContext?.callerSessionId || notifyContext?.sessionId
|
|
80
|
+
|| clientHostPid || null,
|
|
79
81
|
});
|
|
80
82
|
try {
|
|
81
83
|
// Yield one macrotask before doing agent work. startBackgroundTask uses
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
DEFAULT_AGENT_PRESETS,
|
|
4
|
-
DEFAULT_PROVIDER,
|
|
5
|
-
} from './tool-def.mjs';
|
|
1
|
+
import { configuredAgentRouteCandidates } from '../../runtime/shared/agent-route-config.mjs';
|
|
6
2
|
import {
|
|
7
3
|
agentPresetName,
|
|
8
4
|
clean,
|
|
@@ -30,19 +26,10 @@ export function resolveAgentSpawnPreset(config, args = {}) {
|
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
const agentName = normalizeAgentName(args.agent);
|
|
33
|
-
const configuredDefault = clean(config?.defaultProvider);
|
|
34
|
-
const fallbackProvider = configuredDefault && isKnownProvider(configuredDefault)
|
|
35
|
-
? configuredDefault
|
|
36
|
-
: DEFAULT_PROVIDER;
|
|
37
|
-
const workflowSlot = agentName === 'explore' ? 'explorer'
|
|
38
|
-
: (agentName === 'maintainer' ? 'memory' : '');
|
|
39
|
-
const maintenanceSlot = agentName === 'explore' ? 'explore'
|
|
40
|
-
: (agentName === 'maintainer' ? 'memory' : '');
|
|
41
29
|
const agentRoute = !clean(args.preset)
|
|
42
|
-
? (
|
|
43
|
-
|
|
44
|
-
||
|
|
45
|
-
|| normalizeAgentRoute(config?.maintenance?.[maintenanceSlot], fallbackProvider))
|
|
30
|
+
? configuredAgentRouteCandidates(config, agentName)
|
|
31
|
+
.map((candidate) => normalizeAgentRoute(candidate))
|
|
32
|
+
.find(Boolean) || null
|
|
46
33
|
: null;
|
|
47
34
|
if (agentRoute) {
|
|
48
35
|
return {
|
|
@@ -60,14 +47,17 @@ export function resolveAgentSpawnPreset(config, args = {}) {
|
|
|
60
47
|
};
|
|
61
48
|
}
|
|
62
49
|
|
|
63
|
-
const mainPreset = !clean(args.preset)
|
|
50
|
+
const mainPreset = !clean(args.preset)
|
|
64
51
|
? findPreset(config, config?.default)
|
|
65
52
|
: null;
|
|
66
|
-
if (mainPreset)
|
|
53
|
+
if (normalizeAgentRoute(mainPreset)) {
|
|
54
|
+
return { presetName: mainPreset.id || mainPreset.name, preset: mainPreset };
|
|
55
|
+
}
|
|
67
56
|
|
|
68
|
-
const presetName = clean(args.preset)
|
|
69
|
-
if (!presetName) throw new Error(`agent: agent "${agentName}" has no model assignment`);
|
|
57
|
+
const presetName = clean(args.preset);
|
|
58
|
+
if (!presetName) throw new Error(`agent: agent "${agentName}" has no Main model assignment`);
|
|
70
59
|
const preset = findPreset(config, presetName) || synthesizePreset(config, presetName);
|
|
71
60
|
if (!preset) throw new Error(`agent: preset "${presetName}" not found`);
|
|
61
|
+
if (!normalizeAgentRoute(preset)) throw new Error(`agent: preset "${presetName}" has no complete route`);
|
|
72
62
|
return { presetName, preset };
|
|
73
63
|
}
|
|
@@ -6,20 +6,6 @@ export const PRESET_ALIASES = new Map([
|
|
|
6
6
|
['opus-xhigh', { base: 'opus-high', effort: 'xhigh', id: 'opus-xhigh', name: 'OPUS XHIGH' }],
|
|
7
7
|
]);
|
|
8
8
|
|
|
9
|
-
export const DEFAULT_AGENT_PRESETS = Object.freeze({
|
|
10
|
-
explore: 'sonnet-high',
|
|
11
|
-
maintainer: 'haiku',
|
|
12
|
-
worker: 'sonnet-high',
|
|
13
|
-
'heavy-worker': 'sonnet-high',
|
|
14
|
-
reviewer: 'opus-xhigh',
|
|
15
|
-
debugger: 'opus-xhigh',
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// Mirrors DEFAULT_PROVIDER in mixdog-session-runtime.mjs. Used only as the
|
|
19
|
-
// last-resort fallback when a stored agent route omits its provider and the
|
|
20
|
-
// config carries no defaultProvider.
|
|
21
|
-
export const DEFAULT_PROVIDER = 'anthropic-oauth';
|
|
22
|
-
|
|
23
9
|
export const WORKER_INDEX_FILE = 'agent-workers.json';
|
|
24
10
|
|
|
25
11
|
export const ACTIVE_STAGES = new Set(['connecting', 'requesting', 'streaming', 'tool_running', 'running', 'cancelling']);
|