@ran-sh/dsh-crew 1.9.0 → 1.10.0
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/.claude-plugin/marketplace.json +16 -16
- package/.claude-plugin/plugin.json +14 -14
- package/LICENSE +21 -21
- package/README.de.md +359 -359
- package/README.es.md +359 -359
- package/README.fr.md +359 -359
- package/README.hi.md +359 -359
- package/README.id.md +359 -359
- package/README.ja.md +359 -359
- package/README.ko.md +359 -359
- package/README.md +126 -126
- package/README.pt.md +359 -359
- package/README.ru.md +359 -359
- package/README.th.md +359 -359
- package/README.tr.md +359 -359
- package/README.vi.md +359 -359
- package/README.zh-TW.md +359 -359
- package/README.zh.md +116 -116
- package/agents/ds-flash.md +24 -24
- package/agents/ds-pro.md +24 -24
- package/agents/ds-reviewer.md +23 -23
- package/agents/ds-worker.md +23 -23
- package/bin/dsh-crew.mjs +16 -16
- package/codex/agents/ds-flash.toml +34 -34
- package/codex/agents/ds-pro.toml +34 -34
- package/codex/agents/ds-reviewer.toml +32 -32
- package/codex/agents/ds-worker.toml +32 -32
- package/codex/prompts/dsh-config.md +19 -19
- package/codex/prompts/dsh-status.md +5 -5
- package/commands/config.md +23 -23
- package/commands/off.md +5 -5
- package/commands/on.md +5 -5
- package/commands/status.md +9 -9
- package/cordis.patch.yml +4 -4
- package/docs/gpt-relay-extension.md +103 -103
- package/docs/installation.md +138 -138
- package/docs/job-contracts.md +103 -103
- package/docs/readiness-matrix.md +85 -85
- package/docs/ui-surfaces.md +107 -107
- package/official-web-bridge/cordis.patch.yml +4 -4
- package/official-web-bridge/entry.mjs +1 -1
- package/official-web-bridge/overlay-entry.mjs +59 -59
- package/official-web-bridge/package.json +25 -25
- package/package.json +3 -2
- package/scripts/build-client.mjs +49 -49
- package/scripts/live-crew-smoke.mjs +39 -39
- package/scripts/live-policy-matrix.mjs +177 -177
- package/scripts/policy-probe.mjs +101 -101
- package/scripts/remove-legacy-official-bridge.ps1 +89 -89
- package/scripts/setup.mjs +393 -393
- package/scripts/smoke-real.mjs +110 -110
- package/scripts/smoke.mjs +78 -78
- package/scripts/verify-crew-ui-polish.mjs +145 -145
- package/scripts/verify-history-ui.mjs +97 -97
- package/scripts/verify-installer-fix.mjs +26 -26
- package/scripts/verify-npm-install.mjs +311 -311
- package/scripts/verify-official-bridge-e2e.mjs +192 -192
- package/src/adaptive-routing.mjs +260 -260
- package/src/client/activation-summary.tsx +64 -64
- package/src/client/collapsible-sections.mjs +55 -55
- package/src/client/history-panel.tsx +108 -108
- package/src/client/host-readiness.mjs +71 -71
- package/src/client/index.tsx +1711 -1711
- package/src/client/model-callability-view.mjs +17 -17
- package/src/client/panel-chrome.tsx +40 -40
- package/src/client/quick-entry.tsx +10 -10
- package/src/client/quick-panel.tsx +275 -275
- package/src/client/readiness-envelope.mjs +34 -34
- package/src/client/surface-detection.mjs +43 -43
- package/src/config-readiness.mjs +226 -226
- package/src/credential-reference.mjs +38 -38
- package/src/delivery.mjs +205 -205
- package/src/dsh-cli-runtime.mjs +1021 -1021
- package/src/dsh-cohort.mjs +20 -20
- package/src/extension-contract.mjs +104 -104
- package/src/failure-classification.mjs +201 -201
- package/src/history/admission-gate.mjs +67 -67
- package/src/history/archive-store.mjs +272 -272
- package/src/history/cleanup-plan.mjs +89 -89
- package/src/history/http.mjs +32 -32
- package/src/history/operation.mjs +86 -86
- package/src/history/runner-detach.mjs +34 -34
- package/src/history/runner.mjs +52 -52
- package/src/history/runtime.mjs +36 -36
- package/src/history/service.mjs +177 -177
- package/src/history/state.mjs +27 -27
- package/src/hub/entry.mjs +104 -104
- package/src/hub/index.mjs +2694 -2694
- package/src/hub-client.mjs +154 -154
- package/src/hub-compatibility.mjs +42 -42
- package/src/i18n.mjs +19 -19
- package/src/information-flow.mjs +67 -67
- package/src/install/cli.mjs +28 -28
- package/src/install/install-legacy.mjs +711 -711
- package/src/install/install.mjs +483 -483
- package/src/install/npx-lifecycle.mjs +3456 -3456
- package/src/install/official-frontend-assets.mjs +78 -78
- package/src/install/official-web.mjs +95 -95
- package/src/install/payload-content.mjs +88 -88
- package/src/install/windows-startup.mjs +236 -236
- package/src/install/windows-supervisor-adapter.mjs +443 -443
- package/src/install/windows-supervisor-lifecycle.mjs +782 -782
- package/src/install/zcode.mjs +397 -397
- package/src/job-contracts.mjs +255 -255
- package/src/local-request-guard.mjs +60 -60
- package/src/mcp-runtime.mjs +340 -340
- package/src/model-callability-contract.mjs +79 -79
- package/src/model-catalog.mjs +180 -180
- package/src/model-routing.mjs +586 -586
- package/src/model-schedule.mjs +207 -207
- package/src/official-web-bridge.mjs +447 -447
- package/src/policy.mjs +235 -235
- package/src/provider-delete-adapters.mjs +1934 -1934
- package/src/provider-health.mjs +130 -130
- package/src/provider-inventory.mjs +182 -182
- package/src/provider-layer-migration-adapters.mjs +759 -759
- package/src/provider-layer-migration.mjs +198 -198
- package/src/provider-lifecycle-state.mjs +103 -103
- package/src/provider-lifecycle.mjs +252 -252
- package/src/provider-profile-store.mjs +390 -390
- package/src/provider-settings-store.mjs +633 -633
- package/src/provider-store-lock.mjs +67 -67
- package/src/readiness-matrix.mjs +181 -181
- package/src/removable-waiter.mjs +29 -29
- package/src/role-profiles.mjs +107 -107
- package/src/runtime-controls.mjs +84 -84
- package/src/runtime-identity-contract.mjs +34 -34
- package/src/runtime-identity.mjs +235 -235
- package/src/runtime-readiness-snapshot.mjs +285 -285
- package/src/server.mjs +581 -581
- package/src/session-origins.mjs +60 -60
- package/src/standalone-sdk.mjs +23 -23
- package/src/status-shard.mjs +63 -63
- package/src/structured-error-code.mjs +38 -38
- package/src/supervisor/restart-request.mjs +256 -256
- package/src/workflow-runtime.mjs +739 -739
- package/src/workflow.mjs +155 -155
- package/src/workspace-audit.mjs +231 -231
- package/src/workspace-context.mjs +146 -146
- package/src/workspace-isolation.mjs +463 -455
- package/src/workspace-readiness.mjs +32 -32
- package/statusline/statusline.sh +14 -14
- package/statusline/worker-segment.sh +35 -35
- package/windows/start-dsh-crew.cmd +57 -57
- package/windows/start-dsh-crew.ps1 +1302 -1302
- package/windows/supervisor-control.ps1 +467 -467
- package/worker.cordis.yml +67 -67
- package/zcode/agents/ds-reviewer.md +31 -31
- package/zcode/agents/ds-worker.md +31 -31
- package/zcode/commands/dsh-config.md +17 -17
- package/zcode/commands/dsh-status.md +5 -5
package/src/policy.mjs
CHANGED
|
@@ -1,235 +1,235 @@
|
|
|
1
|
-
// v0.3 config-authority facade over the frozen v0.2 policy implementation.
|
|
2
|
-
//
|
|
3
|
-
// The v0.2 module remains byte-for-byte available as policy-legacy.mjs. New
|
|
4
|
-
// callers import this facade. For schema-v3 persisted configs, the nested
|
|
5
|
-
// worker/review/execution/legacy snapshot is authoritative; flat Flash/Pro
|
|
6
|
-
// fields are compatibility mirrors only. Legacy files still flow through the
|
|
7
|
-
// old migration exactly as before.
|
|
8
|
-
|
|
9
|
-
export * from './policy-legacy.mjs';
|
|
10
|
-
import * as legacy from './policy-legacy.mjs';
|
|
11
|
-
import { normalizeAdaptiveRouting } from './adaptive-routing.mjs';
|
|
12
|
-
import { normalizeModelSchedule } from './model-schedule.mjs';
|
|
13
|
-
|
|
14
|
-
export { normalizeAdaptiveRouting };
|
|
15
|
-
export const CONFIG_SCHEMA_VERSION = 4;
|
|
16
|
-
const MIN_CANONICAL_SCHEMA_VERSION = 3;
|
|
17
|
-
|
|
18
|
-
function validObject(value) {
|
|
19
|
-
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const EXECUTION_TRANSPORTS = new Set(['hub-3210', 'standalone-legacy']);
|
|
23
|
-
|
|
24
|
-
function normalizeExecutionTransport(value) {
|
|
25
|
-
return EXECUTION_TRANSPORTS.has(value) ? value : 'hub-3210';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function hasCanonicalAuthority(raw) {
|
|
29
|
-
return Number(raw?.config_schema_version) >= MIN_CANONICAL_SCHEMA_VERSION
|
|
30
|
-
&& validObject(raw?.worker)
|
|
31
|
-
&& validObject(raw?.review)
|
|
32
|
-
&& validObject(raw?.execution);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function semanticLegacyMode(canonical) {
|
|
36
|
-
if (canonical.review.auto_review === true && canonical.review.state === 'auto') return 'review-pipeline';
|
|
37
|
-
if (canonical.worker.state === 'auto' && canonical.review.state === 'disabled'
|
|
38
|
-
&& canonical.worker.model_policy.strategy === 'economy') return 'flash-only';
|
|
39
|
-
if (canonical.worker.state === 'auto' && canonical.review.state === 'disabled'
|
|
40
|
-
&& canonical.worker.model_policy.strategy === 'quality') return 'pro-only';
|
|
41
|
-
if (canonical.worker.state === 'auto' && canonical.review.state === 'manual') return 'balanced';
|
|
42
|
-
return 'custom';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function normalizeLegacySnapshot(raw, canonical) {
|
|
46
|
-
// A nested v3 legacy snapshot is canonical compatibility metadata. Flat
|
|
47
|
-
// fields are only a fallback for transitional/pre-v3 inputs.
|
|
48
|
-
const nested = validObject(raw?.legacy) ? raw.legacy : {};
|
|
49
|
-
const source = { ...raw, ...nested };
|
|
50
|
-
const mode = legacy.COLLABORATION_MODES.includes(source.collaboration_mode)
|
|
51
|
-
? source.collaboration_mode
|
|
52
|
-
: semanticLegacyMode(canonical);
|
|
53
|
-
|
|
54
|
-
let flash = legacy.TIER_STATES.includes(source.flash_state) ? source.flash_state : undefined;
|
|
55
|
-
let pro = legacy.TIER_STATES.includes(source.pro_state) ? source.pro_state : undefined;
|
|
56
|
-
if (mode === 'flash-only') { flash = 'auto'; pro = 'disabled'; }
|
|
57
|
-
else if (mode === 'pro-only') { flash = 'disabled'; pro = 'auto'; }
|
|
58
|
-
else if (mode === 'balanced' || mode === 'review-pipeline') { flash = 'auto'; pro = 'auto'; }
|
|
59
|
-
else {
|
|
60
|
-
flash ??= canonical.worker.state;
|
|
61
|
-
// reviewer=manual historically means the Pro tier is available/Auto but
|
|
62
|
-
// review itself is on-demand. Preserve an explicit nested pro state when
|
|
63
|
-
// present; otherwise use a conservative compatibility reconstruction.
|
|
64
|
-
pro ??= canonical.review.state === 'disabled' ? 'disabled' : 'auto';
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
collaboration_mode: mode,
|
|
69
|
-
tier_policy: mode === 'flash-only' ? 'flash-only' : mode === 'pro-only' ? 'pro-only' : 'auto',
|
|
70
|
-
flash_state: flash,
|
|
71
|
-
pro_state: pro,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function modelPolicyWithAdaptive(basePolicy, rawPolicy) {
|
|
76
|
-
const adaptive = normalizeAdaptiveRouting(rawPolicy?.adaptive);
|
|
77
|
-
const ordering = rawPolicy?.ordering === 'health-aware' || rawPolicy?.ordering === 'manual'
|
|
78
|
-
? rawPolicy.ordering
|
|
79
|
-
: adaptive.enabled ? 'health-aware' : 'manual';
|
|
80
|
-
return {
|
|
81
|
-
...basePolicy,
|
|
82
|
-
adaptive: { ...adaptive, enabled: ordering === 'health-aware' },
|
|
83
|
-
ordering,
|
|
84
|
-
health_gate: rawPolicy?.health_gate === 'off' ? 'off' : 'hard-failures',
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function normalizeCanonical(raw) {
|
|
89
|
-
const base = legacy.getCanonical(raw);
|
|
90
|
-
const providerMode = legacy.normalizeWorkerProviderMode(base.worker?.provider_mode);
|
|
91
|
-
const canonical = {
|
|
92
|
-
...base,
|
|
93
|
-
execution: {
|
|
94
|
-
...base.execution,
|
|
95
|
-
// There is one global dispatch permission. `execution.enabled` is a
|
|
96
|
-
// canonical mirror of the top-level switch, never a second authority.
|
|
97
|
-
enabled: base.subagents_enabled,
|
|
98
|
-
transport: normalizeExecutionTransport(raw?.execution?.transport ?? base.execution?.transport),
|
|
99
|
-
},
|
|
100
|
-
worker: {
|
|
101
|
-
...base.worker,
|
|
102
|
-
provider_mode: providerMode,
|
|
103
|
-
model_policy: modelPolicyWithAdaptive(base.worker.model_policy, raw?.worker?.model_policy),
|
|
104
|
-
},
|
|
105
|
-
review: {
|
|
106
|
-
...base.review,
|
|
107
|
-
gate: ['required', 'optional', 'off'].includes(raw?.review?.gate) ? raw.review.gate : 'required',
|
|
108
|
-
// v0.3 still exposes one Worker Provider selector. Until per-role
|
|
109
|
-
// provider modes become first-class, keep both roles aligned.
|
|
110
|
-
provider_mode: providerMode,
|
|
111
|
-
model_policy: modelPolicyWithAdaptive(base.review.model_policy, raw?.review?.model_policy),
|
|
112
|
-
},
|
|
113
|
-
// One schedule regulates every restricted model; the per-model list decides
|
|
114
|
-
// who it applies to. Top-level rather than per-role because the same model
|
|
115
|
-
// can sit in either role's priority list, so the restriction is a property
|
|
116
|
-
// of the model, not of the role that happens to route to it.
|
|
117
|
-
model_schedule: normalizeModelSchedule(raw?.model_schedule),
|
|
118
|
-
};
|
|
119
|
-
canonical.legacy = normalizeLegacySnapshot(raw, canonical);
|
|
120
|
-
return canonical;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function proMirror(canonical) {
|
|
124
|
-
const escalation = canonical.worker.model_policy;
|
|
125
|
-
const reviewer = canonical.review.model_policy;
|
|
126
|
-
if (escalation.escalation_priority_configured || escalation.escalation_priority.length > 0) {
|
|
127
|
-
return {
|
|
128
|
-
priority: escalation.escalation_priority,
|
|
129
|
-
configured: escalation.escalation_priority_configured,
|
|
130
|
-
fallback: escalation.fallback,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
priority: reviewer.priority,
|
|
135
|
-
configured: reviewer.priorityConfigured,
|
|
136
|
-
fallback: reviewer.fallback,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function legacyRoutingMirror(canonical) {
|
|
141
|
-
// Legacy tier/UI behavior has its own canonical compatibility sub-domain.
|
|
142
|
-
// Never infer this back from flat mirrors: schema-v3 `legacy` owns it.
|
|
143
|
-
return normalizeLegacySnapshot({ legacy: canonical.legacy }, canonical);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Re-exported normalizer with schema-v3 precedence.
|
|
148
|
-
*
|
|
149
|
-
* `legacy.normalizeGlobalConfig` remains the import path for legacy-file
|
|
150
|
-
* migration. Once schema v3 is present, flat compatibility fields are rebuilt
|
|
151
|
-
* from the canonical snapshot so a stale/manual mirror cannot override runtime
|
|
152
|
-
* behavior.
|
|
153
|
-
*/
|
|
154
|
-
export function normalizeGlobalConfig(raw = {}) {
|
|
155
|
-
const normalized = legacy.normalizeGlobalConfig(raw);
|
|
156
|
-
if (!hasCanonicalAuthority(raw)) return normalized;
|
|
157
|
-
|
|
158
|
-
const canonical = normalizeCanonical(raw);
|
|
159
|
-
const pro = proMirror(canonical);
|
|
160
|
-
const routing = legacyRoutingMirror(canonical);
|
|
161
|
-
return {
|
|
162
|
-
...normalized,
|
|
163
|
-
config_schema_version: CONFIG_SCHEMA_VERSION,
|
|
164
|
-
subagents_enabled: canonical.subagents_enabled,
|
|
165
|
-
main_agent_mode: canonical.main_agent_mode,
|
|
166
|
-
default_effort: canonical.execution.default_effort,
|
|
167
|
-
default_timeout_seconds: canonical.execution.default_timeout_seconds,
|
|
168
|
-
mode: canonical.execution.mode,
|
|
169
|
-
max_parallel: canonical.execution.max_parallel,
|
|
170
|
-
isolation: canonical.execution.isolation,
|
|
171
|
-
collaboration_mode: routing.collaboration_mode,
|
|
172
|
-
tier_policy: routing.tier_policy,
|
|
173
|
-
flash_state: routing.flash_state,
|
|
174
|
-
pro_state: routing.pro_state,
|
|
175
|
-
worker_state: canonical.worker.state,
|
|
176
|
-
review_state: canonical.review.state,
|
|
177
|
-
auto_review: canonical.review.auto_review === true,
|
|
178
|
-
worker_provider_mode: canonical.worker.provider_mode,
|
|
179
|
-
model_schedule: canonical.model_schedule,
|
|
180
|
-
flash_model_priority: [...canonical.worker.model_policy.priority],
|
|
181
|
-
flash_model_priority_configured: canonical.worker.model_policy.priorityConfigured,
|
|
182
|
-
flash_model_fallback: canonical.worker.model_policy.fallback,
|
|
183
|
-
pro_model_priority: [...pro.priority],
|
|
184
|
-
pro_model_priority_configured: pro.configured,
|
|
185
|
-
pro_model_fallback: pro.fallback,
|
|
186
|
-
escalate_on_failure: canonical.worker.model_policy.escalation.enabled,
|
|
187
|
-
pro_reviews_flash: canonical.review.auto_review === true,
|
|
188
|
-
execution: canonical.execution,
|
|
189
|
-
worker: canonical.worker,
|
|
190
|
-
review: canonical.review,
|
|
191
|
-
legacy: canonical.legacy,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* v0.3 model-policy view. The frozen v0.2 resolver remains authoritative for
|
|
197
|
-
* every existing dimension. This facade only adds the normalized opt-in
|
|
198
|
-
* adaptive sub-domain, so direct canonical-ish v0.2 callers retain the exact
|
|
199
|
-
* priority/escalation semantics they had before schema-v3 existed.
|
|
200
|
-
*/
|
|
201
|
-
export function resolveModelPolicy(config = {}, role = 'worker', context = {}) {
|
|
202
|
-
const base = legacy.resolveModelPolicy(config, role, context);
|
|
203
|
-
const rawPolicy = role === 'reviewer'
|
|
204
|
-
? config?.review?.model_policy
|
|
205
|
-
: config?.worker?.model_policy;
|
|
206
|
-
const adaptive = normalizeAdaptiveRouting(rawPolicy?.adaptive ?? base.adaptive);
|
|
207
|
-
const ordering = rawPolicy?.ordering === 'health-aware' || rawPolicy?.ordering === 'manual'
|
|
208
|
-
? rawPolicy.ordering
|
|
209
|
-
: adaptive.enabled ? 'health-aware' : 'manual';
|
|
210
|
-
return {
|
|
211
|
-
...base,
|
|
212
|
-
adaptive: { ...adaptive, enabled: ordering === 'health-aware' },
|
|
213
|
-
ordering,
|
|
214
|
-
health_gate: rawPolicy?.health_gate === 'off' ? 'off' : 'hard-failures',
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/** Automatic review respects the v4 reviewer gate; session opt-out remains authoritative. */
|
|
219
|
-
export function shouldAutoReview(config = {}, session = {}) {
|
|
220
|
-
const normalized = normalizeGlobalConfig(config);
|
|
221
|
-
const gate = ['required', 'optional', 'off'].includes(config?.review?.gate)
|
|
222
|
-
? config.review.gate
|
|
223
|
-
: normalized.review?.gate;
|
|
224
|
-
if (gate === 'off') return false;
|
|
225
|
-
return legacy.shouldAutoReview(normalized, session);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/** Explicit legacy-import normalizer for the persistence layer. */
|
|
229
|
-
export function normalizeLegacyGlobalConfig(raw = {}) {
|
|
230
|
-
return legacy.normalizeGlobalConfig(raw);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export function configHasCanonicalAuthority(raw = {}) {
|
|
234
|
-
return hasCanonicalAuthority(raw);
|
|
235
|
-
}
|
|
1
|
+
// v0.3 config-authority facade over the frozen v0.2 policy implementation.
|
|
2
|
+
//
|
|
3
|
+
// The v0.2 module remains byte-for-byte available as policy-legacy.mjs. New
|
|
4
|
+
// callers import this facade. For schema-v3 persisted configs, the nested
|
|
5
|
+
// worker/review/execution/legacy snapshot is authoritative; flat Flash/Pro
|
|
6
|
+
// fields are compatibility mirrors only. Legacy files still flow through the
|
|
7
|
+
// old migration exactly as before.
|
|
8
|
+
|
|
9
|
+
export * from './policy-legacy.mjs';
|
|
10
|
+
import * as legacy from './policy-legacy.mjs';
|
|
11
|
+
import { normalizeAdaptiveRouting } from './adaptive-routing.mjs';
|
|
12
|
+
import { normalizeModelSchedule } from './model-schedule.mjs';
|
|
13
|
+
|
|
14
|
+
export { normalizeAdaptiveRouting };
|
|
15
|
+
export const CONFIG_SCHEMA_VERSION = 4;
|
|
16
|
+
const MIN_CANONICAL_SCHEMA_VERSION = 3;
|
|
17
|
+
|
|
18
|
+
function validObject(value) {
|
|
19
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const EXECUTION_TRANSPORTS = new Set(['hub-3210', 'standalone-legacy']);
|
|
23
|
+
|
|
24
|
+
function normalizeExecutionTransport(value) {
|
|
25
|
+
return EXECUTION_TRANSPORTS.has(value) ? value : 'hub-3210';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function hasCanonicalAuthority(raw) {
|
|
29
|
+
return Number(raw?.config_schema_version) >= MIN_CANONICAL_SCHEMA_VERSION
|
|
30
|
+
&& validObject(raw?.worker)
|
|
31
|
+
&& validObject(raw?.review)
|
|
32
|
+
&& validObject(raw?.execution);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function semanticLegacyMode(canonical) {
|
|
36
|
+
if (canonical.review.auto_review === true && canonical.review.state === 'auto') return 'review-pipeline';
|
|
37
|
+
if (canonical.worker.state === 'auto' && canonical.review.state === 'disabled'
|
|
38
|
+
&& canonical.worker.model_policy.strategy === 'economy') return 'flash-only';
|
|
39
|
+
if (canonical.worker.state === 'auto' && canonical.review.state === 'disabled'
|
|
40
|
+
&& canonical.worker.model_policy.strategy === 'quality') return 'pro-only';
|
|
41
|
+
if (canonical.worker.state === 'auto' && canonical.review.state === 'manual') return 'balanced';
|
|
42
|
+
return 'custom';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function normalizeLegacySnapshot(raw, canonical) {
|
|
46
|
+
// A nested v3 legacy snapshot is canonical compatibility metadata. Flat
|
|
47
|
+
// fields are only a fallback for transitional/pre-v3 inputs.
|
|
48
|
+
const nested = validObject(raw?.legacy) ? raw.legacy : {};
|
|
49
|
+
const source = { ...raw, ...nested };
|
|
50
|
+
const mode = legacy.COLLABORATION_MODES.includes(source.collaboration_mode)
|
|
51
|
+
? source.collaboration_mode
|
|
52
|
+
: semanticLegacyMode(canonical);
|
|
53
|
+
|
|
54
|
+
let flash = legacy.TIER_STATES.includes(source.flash_state) ? source.flash_state : undefined;
|
|
55
|
+
let pro = legacy.TIER_STATES.includes(source.pro_state) ? source.pro_state : undefined;
|
|
56
|
+
if (mode === 'flash-only') { flash = 'auto'; pro = 'disabled'; }
|
|
57
|
+
else if (mode === 'pro-only') { flash = 'disabled'; pro = 'auto'; }
|
|
58
|
+
else if (mode === 'balanced' || mode === 'review-pipeline') { flash = 'auto'; pro = 'auto'; }
|
|
59
|
+
else {
|
|
60
|
+
flash ??= canonical.worker.state;
|
|
61
|
+
// reviewer=manual historically means the Pro tier is available/Auto but
|
|
62
|
+
// review itself is on-demand. Preserve an explicit nested pro state when
|
|
63
|
+
// present; otherwise use a conservative compatibility reconstruction.
|
|
64
|
+
pro ??= canonical.review.state === 'disabled' ? 'disabled' : 'auto';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
collaboration_mode: mode,
|
|
69
|
+
tier_policy: mode === 'flash-only' ? 'flash-only' : mode === 'pro-only' ? 'pro-only' : 'auto',
|
|
70
|
+
flash_state: flash,
|
|
71
|
+
pro_state: pro,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function modelPolicyWithAdaptive(basePolicy, rawPolicy) {
|
|
76
|
+
const adaptive = normalizeAdaptiveRouting(rawPolicy?.adaptive);
|
|
77
|
+
const ordering = rawPolicy?.ordering === 'health-aware' || rawPolicy?.ordering === 'manual'
|
|
78
|
+
? rawPolicy.ordering
|
|
79
|
+
: adaptive.enabled ? 'health-aware' : 'manual';
|
|
80
|
+
return {
|
|
81
|
+
...basePolicy,
|
|
82
|
+
adaptive: { ...adaptive, enabled: ordering === 'health-aware' },
|
|
83
|
+
ordering,
|
|
84
|
+
health_gate: rawPolicy?.health_gate === 'off' ? 'off' : 'hard-failures',
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function normalizeCanonical(raw) {
|
|
89
|
+
const base = legacy.getCanonical(raw);
|
|
90
|
+
const providerMode = legacy.normalizeWorkerProviderMode(base.worker?.provider_mode);
|
|
91
|
+
const canonical = {
|
|
92
|
+
...base,
|
|
93
|
+
execution: {
|
|
94
|
+
...base.execution,
|
|
95
|
+
// There is one global dispatch permission. `execution.enabled` is a
|
|
96
|
+
// canonical mirror of the top-level switch, never a second authority.
|
|
97
|
+
enabled: base.subagents_enabled,
|
|
98
|
+
transport: normalizeExecutionTransport(raw?.execution?.transport ?? base.execution?.transport),
|
|
99
|
+
},
|
|
100
|
+
worker: {
|
|
101
|
+
...base.worker,
|
|
102
|
+
provider_mode: providerMode,
|
|
103
|
+
model_policy: modelPolicyWithAdaptive(base.worker.model_policy, raw?.worker?.model_policy),
|
|
104
|
+
},
|
|
105
|
+
review: {
|
|
106
|
+
...base.review,
|
|
107
|
+
gate: ['required', 'optional', 'off'].includes(raw?.review?.gate) ? raw.review.gate : 'required',
|
|
108
|
+
// v0.3 still exposes one Worker Provider selector. Until per-role
|
|
109
|
+
// provider modes become first-class, keep both roles aligned.
|
|
110
|
+
provider_mode: providerMode,
|
|
111
|
+
model_policy: modelPolicyWithAdaptive(base.review.model_policy, raw?.review?.model_policy),
|
|
112
|
+
},
|
|
113
|
+
// One schedule regulates every restricted model; the per-model list decides
|
|
114
|
+
// who it applies to. Top-level rather than per-role because the same model
|
|
115
|
+
// can sit in either role's priority list, so the restriction is a property
|
|
116
|
+
// of the model, not of the role that happens to route to it.
|
|
117
|
+
model_schedule: normalizeModelSchedule(raw?.model_schedule),
|
|
118
|
+
};
|
|
119
|
+
canonical.legacy = normalizeLegacySnapshot(raw, canonical);
|
|
120
|
+
return canonical;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function proMirror(canonical) {
|
|
124
|
+
const escalation = canonical.worker.model_policy;
|
|
125
|
+
const reviewer = canonical.review.model_policy;
|
|
126
|
+
if (escalation.escalation_priority_configured || escalation.escalation_priority.length > 0) {
|
|
127
|
+
return {
|
|
128
|
+
priority: escalation.escalation_priority,
|
|
129
|
+
configured: escalation.escalation_priority_configured,
|
|
130
|
+
fallback: escalation.fallback,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
priority: reviewer.priority,
|
|
135
|
+
configured: reviewer.priorityConfigured,
|
|
136
|
+
fallback: reviewer.fallback,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function legacyRoutingMirror(canonical) {
|
|
141
|
+
// Legacy tier/UI behavior has its own canonical compatibility sub-domain.
|
|
142
|
+
// Never infer this back from flat mirrors: schema-v3 `legacy` owns it.
|
|
143
|
+
return normalizeLegacySnapshot({ legacy: canonical.legacy }, canonical);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Re-exported normalizer with schema-v3 precedence.
|
|
148
|
+
*
|
|
149
|
+
* `legacy.normalizeGlobalConfig` remains the import path for legacy-file
|
|
150
|
+
* migration. Once schema v3 is present, flat compatibility fields are rebuilt
|
|
151
|
+
* from the canonical snapshot so a stale/manual mirror cannot override runtime
|
|
152
|
+
* behavior.
|
|
153
|
+
*/
|
|
154
|
+
export function normalizeGlobalConfig(raw = {}) {
|
|
155
|
+
const normalized = legacy.normalizeGlobalConfig(raw);
|
|
156
|
+
if (!hasCanonicalAuthority(raw)) return normalized;
|
|
157
|
+
|
|
158
|
+
const canonical = normalizeCanonical(raw);
|
|
159
|
+
const pro = proMirror(canonical);
|
|
160
|
+
const routing = legacyRoutingMirror(canonical);
|
|
161
|
+
return {
|
|
162
|
+
...normalized,
|
|
163
|
+
config_schema_version: CONFIG_SCHEMA_VERSION,
|
|
164
|
+
subagents_enabled: canonical.subagents_enabled,
|
|
165
|
+
main_agent_mode: canonical.main_agent_mode,
|
|
166
|
+
default_effort: canonical.execution.default_effort,
|
|
167
|
+
default_timeout_seconds: canonical.execution.default_timeout_seconds,
|
|
168
|
+
mode: canonical.execution.mode,
|
|
169
|
+
max_parallel: canonical.execution.max_parallel,
|
|
170
|
+
isolation: canonical.execution.isolation,
|
|
171
|
+
collaboration_mode: routing.collaboration_mode,
|
|
172
|
+
tier_policy: routing.tier_policy,
|
|
173
|
+
flash_state: routing.flash_state,
|
|
174
|
+
pro_state: routing.pro_state,
|
|
175
|
+
worker_state: canonical.worker.state,
|
|
176
|
+
review_state: canonical.review.state,
|
|
177
|
+
auto_review: canonical.review.auto_review === true,
|
|
178
|
+
worker_provider_mode: canonical.worker.provider_mode,
|
|
179
|
+
model_schedule: canonical.model_schedule,
|
|
180
|
+
flash_model_priority: [...canonical.worker.model_policy.priority],
|
|
181
|
+
flash_model_priority_configured: canonical.worker.model_policy.priorityConfigured,
|
|
182
|
+
flash_model_fallback: canonical.worker.model_policy.fallback,
|
|
183
|
+
pro_model_priority: [...pro.priority],
|
|
184
|
+
pro_model_priority_configured: pro.configured,
|
|
185
|
+
pro_model_fallback: pro.fallback,
|
|
186
|
+
escalate_on_failure: canonical.worker.model_policy.escalation.enabled,
|
|
187
|
+
pro_reviews_flash: canonical.review.auto_review === true,
|
|
188
|
+
execution: canonical.execution,
|
|
189
|
+
worker: canonical.worker,
|
|
190
|
+
review: canonical.review,
|
|
191
|
+
legacy: canonical.legacy,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* v0.3 model-policy view. The frozen v0.2 resolver remains authoritative for
|
|
197
|
+
* every existing dimension. This facade only adds the normalized opt-in
|
|
198
|
+
* adaptive sub-domain, so direct canonical-ish v0.2 callers retain the exact
|
|
199
|
+
* priority/escalation semantics they had before schema-v3 existed.
|
|
200
|
+
*/
|
|
201
|
+
export function resolveModelPolicy(config = {}, role = 'worker', context = {}) {
|
|
202
|
+
const base = legacy.resolveModelPolicy(config, role, context);
|
|
203
|
+
const rawPolicy = role === 'reviewer'
|
|
204
|
+
? config?.review?.model_policy
|
|
205
|
+
: config?.worker?.model_policy;
|
|
206
|
+
const adaptive = normalizeAdaptiveRouting(rawPolicy?.adaptive ?? base.adaptive);
|
|
207
|
+
const ordering = rawPolicy?.ordering === 'health-aware' || rawPolicy?.ordering === 'manual'
|
|
208
|
+
? rawPolicy.ordering
|
|
209
|
+
: adaptive.enabled ? 'health-aware' : 'manual';
|
|
210
|
+
return {
|
|
211
|
+
...base,
|
|
212
|
+
adaptive: { ...adaptive, enabled: ordering === 'health-aware' },
|
|
213
|
+
ordering,
|
|
214
|
+
health_gate: rawPolicy?.health_gate === 'off' ? 'off' : 'hard-failures',
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Automatic review respects the v4 reviewer gate; session opt-out remains authoritative. */
|
|
219
|
+
export function shouldAutoReview(config = {}, session = {}) {
|
|
220
|
+
const normalized = normalizeGlobalConfig(config);
|
|
221
|
+
const gate = ['required', 'optional', 'off'].includes(config?.review?.gate)
|
|
222
|
+
? config.review.gate
|
|
223
|
+
: normalized.review?.gate;
|
|
224
|
+
if (gate === 'off') return false;
|
|
225
|
+
return legacy.shouldAutoReview(normalized, session);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Explicit legacy-import normalizer for the persistence layer. */
|
|
229
|
+
export function normalizeLegacyGlobalConfig(raw = {}) {
|
|
230
|
+
return legacy.normalizeGlobalConfig(raw);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function configHasCanonicalAuthority(raw = {}) {
|
|
234
|
+
return hasCanonicalAuthority(raw);
|
|
235
|
+
}
|