@ran-sh/dsh-crew 0.3.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.
Files changed (85) hide show
  1. package/.claude-plugin/marketplace.json +17 -0
  2. package/.claude-plugin/plugin.json +8 -0
  3. package/.mcp.json +8 -0
  4. package/LICENSE +21 -0
  5. package/README.de.md +359 -0
  6. package/README.es.md +359 -0
  7. package/README.fr.md +359 -0
  8. package/README.hi.md +359 -0
  9. package/README.id.md +359 -0
  10. package/README.ja.md +359 -0
  11. package/README.ko.md +359 -0
  12. package/README.md +360 -0
  13. package/README.pt.md +359 -0
  14. package/README.ru.md +359 -0
  15. package/README.th.md +359 -0
  16. package/README.tr.md +359 -0
  17. package/README.vi.md +359 -0
  18. package/README.zh-TW.md +359 -0
  19. package/README.zh.md +305 -0
  20. package/agents/ds-flash.md +26 -0
  21. package/agents/ds-pro.md +32 -0
  22. package/agents/ds-reviewer.md +23 -0
  23. package/agents/ds-worker.md +22 -0
  24. package/codex/agents/ds-flash.toml +30 -0
  25. package/codex/agents/ds-pro.toml +31 -0
  26. package/codex/agents/ds-reviewer.toml +28 -0
  27. package/codex/agents/ds-worker.toml +28 -0
  28. package/codex/prompts/dsh-config.md +3 -0
  29. package/codex/prompts/dsh-status.md +1 -0
  30. package/commands/config.md +11 -0
  31. package/commands/off.md +5 -0
  32. package/commands/on.md +5 -0
  33. package/commands/status.md +5 -0
  34. package/cordis.patch.yml +4 -0
  35. package/docs/images/dsh-crew-host.png +0 -0
  36. package/docs/images/dsh-crew-jobs.png +0 -0
  37. package/docs/images/dsh-crew-logo.png +0 -0
  38. package/docs/images/dsh-crew-overview.png +0 -0
  39. package/lib/client.js +2765 -0
  40. package/package.json +125 -0
  41. package/scripts/build-client.mjs +28 -0
  42. package/scripts/live-crew-smoke.mjs +39 -0
  43. package/scripts/live-policy-matrix.mjs +177 -0
  44. package/scripts/policy-probe.mjs +101 -0
  45. package/scripts/setup.mjs +294 -0
  46. package/scripts/smoke-real.mjs +110 -0
  47. package/scripts/smoke.mjs +78 -0
  48. package/scripts/verify-installer-fix.mjs +26 -0
  49. package/src/adaptive-routing.mjs +260 -0
  50. package/src/client/activation-summary.tsx +64 -0
  51. package/src/client/entry.tsx +236 -0
  52. package/src/client/index.tsx +1120 -0
  53. package/src/config-readiness.mjs +59 -0
  54. package/src/delivery.mjs +205 -0
  55. package/src/dsh-cli-runtime.mjs +251 -0
  56. package/src/failure-classification.mjs +172 -0
  57. package/src/hub/entry.mjs +98 -0
  58. package/src/hub/index.mjs +757 -0
  59. package/src/hub-client.mjs +132 -0
  60. package/src/hub-compatibility.mjs +49 -0
  61. package/src/i18n.mjs +19 -0
  62. package/src/install/cli.mjs +28 -0
  63. package/src/install/install-legacy.mjs +460 -0
  64. package/src/install/install.mjs +451 -0
  65. package/src/jobs.mjs +275 -0
  66. package/src/mcp-runtime.mjs +257 -0
  67. package/src/model-catalog.mjs +173 -0
  68. package/src/model-routing.mjs +391 -0
  69. package/src/multimodal.mjs +0 -0
  70. package/src/policy-legacy.mjs +830 -0
  71. package/src/policy.mjs +197 -0
  72. package/src/readiness-matrix.mjs +169 -0
  73. package/src/runtime-controls.mjs +90 -0
  74. package/src/runtime-identity.mjs +108 -0
  75. package/src/server.mjs +477 -0
  76. package/src/status-shard.mjs +52 -0
  77. package/src/structured-error-code.mjs +39 -0
  78. package/src/vision-route.mjs +138 -0
  79. package/src/workflow-runtime.mjs +567 -0
  80. package/src/workflow.mjs +160 -0
  81. package/src/workspace-audit.mjs +231 -0
  82. package/src/workspace-isolation.mjs +306 -0
  83. package/statusline/statusline.sh +14 -0
  84. package/statusline/worker-segment.sh +35 -0
  85. package/worker.cordis.yml +77 -0
package/src/policy.mjs ADDED
@@ -0,0 +1,197 @@
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
+
13
+ export { normalizeAdaptiveRouting };
14
+ export const CONFIG_SCHEMA_VERSION = 3;
15
+
16
+ function validObject(value) {
17
+ return !!value && typeof value === 'object' && !Array.isArray(value);
18
+ }
19
+
20
+ function hasCanonicalAuthority(raw) {
21
+ return Number(raw?.config_schema_version) >= CONFIG_SCHEMA_VERSION
22
+ && validObject(raw?.worker)
23
+ && validObject(raw?.review)
24
+ && validObject(raw?.execution);
25
+ }
26
+
27
+ function semanticLegacyMode(canonical) {
28
+ if (canonical.review.auto_review === true && canonical.review.state === 'auto') return 'review-pipeline';
29
+ if (canonical.worker.state === 'auto' && canonical.review.state === 'disabled'
30
+ && canonical.worker.model_policy.strategy === 'economy') return 'flash-only';
31
+ if (canonical.worker.state === 'auto' && canonical.review.state === 'disabled'
32
+ && canonical.worker.model_policy.strategy === 'quality') return 'pro-only';
33
+ if (canonical.worker.state === 'auto' && canonical.review.state === 'manual') return 'balanced';
34
+ return 'custom';
35
+ }
36
+
37
+ function normalizeLegacySnapshot(raw, canonical) {
38
+ // A nested v3 legacy snapshot is canonical compatibility metadata. Flat
39
+ // fields are only a fallback for transitional/pre-v3 inputs.
40
+ const nested = validObject(raw?.legacy) ? raw.legacy : {};
41
+ const source = { ...raw, ...nested };
42
+ const mode = legacy.COLLABORATION_MODES.includes(source.collaboration_mode)
43
+ ? source.collaboration_mode
44
+ : semanticLegacyMode(canonical);
45
+
46
+ let flash = legacy.TIER_STATES.includes(source.flash_state) ? source.flash_state : undefined;
47
+ let pro = legacy.TIER_STATES.includes(source.pro_state) ? source.pro_state : undefined;
48
+ if (mode === 'flash-only') { flash = 'auto'; pro = 'disabled'; }
49
+ else if (mode === 'pro-only') { flash = 'disabled'; pro = 'auto'; }
50
+ else if (mode === 'balanced' || mode === 'review-pipeline') { flash = 'auto'; pro = 'auto'; }
51
+ else {
52
+ flash ??= canonical.worker.state;
53
+ // reviewer=manual historically means the Pro tier is available/Auto but
54
+ // review itself is on-demand. Preserve an explicit nested pro state when
55
+ // present; otherwise use a conservative compatibility reconstruction.
56
+ pro ??= canonical.review.state === 'disabled' ? 'disabled' : 'auto';
57
+ }
58
+
59
+ return {
60
+ collaboration_mode: mode,
61
+ tier_policy: mode === 'flash-only' ? 'flash-only' : mode === 'pro-only' ? 'pro-only' : 'auto',
62
+ flash_state: flash,
63
+ pro_state: pro,
64
+ };
65
+ }
66
+
67
+ function modelPolicyWithAdaptive(basePolicy, rawPolicy) {
68
+ return {
69
+ ...basePolicy,
70
+ adaptive: normalizeAdaptiveRouting(rawPolicy?.adaptive),
71
+ };
72
+ }
73
+
74
+ function normalizeCanonical(raw) {
75
+ const base = legacy.getCanonical(raw);
76
+ const providerMode = legacy.normalizeWorkerProviderMode(base.worker?.provider_mode);
77
+ const canonical = {
78
+ ...base,
79
+ execution: {
80
+ ...base.execution,
81
+ // There is one global dispatch permission. `execution.enabled` is a
82
+ // canonical mirror of the top-level switch, never a second authority.
83
+ enabled: base.subagents_enabled,
84
+ },
85
+ worker: {
86
+ ...base.worker,
87
+ provider_mode: providerMode,
88
+ model_policy: modelPolicyWithAdaptive(base.worker.model_policy, raw?.worker?.model_policy),
89
+ },
90
+ review: {
91
+ ...base.review,
92
+ // v0.3 still exposes one Worker Provider selector. Until per-role
93
+ // provider modes become first-class, keep both roles aligned.
94
+ provider_mode: providerMode,
95
+ model_policy: modelPolicyWithAdaptive(base.review.model_policy, raw?.review?.model_policy),
96
+ },
97
+ };
98
+ canonical.legacy = normalizeLegacySnapshot(raw, canonical);
99
+ return canonical;
100
+ }
101
+
102
+ function proMirror(canonical) {
103
+ const escalation = canonical.worker.model_policy;
104
+ const reviewer = canonical.review.model_policy;
105
+ if (escalation.escalation_priority_configured || escalation.escalation_priority.length > 0) {
106
+ return {
107
+ priority: escalation.escalation_priority,
108
+ configured: escalation.escalation_priority_configured,
109
+ fallback: escalation.fallback,
110
+ };
111
+ }
112
+ return {
113
+ priority: reviewer.priority,
114
+ configured: reviewer.priorityConfigured,
115
+ fallback: reviewer.fallback,
116
+ };
117
+ }
118
+
119
+ function legacyRoutingMirror(canonical) {
120
+ // Legacy tier/UI behavior has its own canonical compatibility sub-domain.
121
+ // Never infer this back from flat mirrors: schema-v3 `legacy` owns it.
122
+ return normalizeLegacySnapshot({ legacy: canonical.legacy }, canonical);
123
+ }
124
+
125
+ /**
126
+ * Re-exported normalizer with schema-v3 precedence.
127
+ *
128
+ * `legacy.normalizeGlobalConfig` remains the import path for legacy-file
129
+ * migration. Once schema v3 is present, flat compatibility fields are rebuilt
130
+ * from the canonical snapshot so a stale/manual mirror cannot override runtime
131
+ * behavior.
132
+ */
133
+ export function normalizeGlobalConfig(raw = {}) {
134
+ const normalized = legacy.normalizeGlobalConfig(raw);
135
+ if (!hasCanonicalAuthority(raw)) return normalized;
136
+
137
+ const canonical = normalizeCanonical(raw);
138
+ const pro = proMirror(canonical);
139
+ const routing = legacyRoutingMirror(canonical);
140
+ return {
141
+ ...normalized,
142
+ config_schema_version: CONFIG_SCHEMA_VERSION,
143
+ subagents_enabled: canonical.subagents_enabled,
144
+ main_agent_mode: canonical.main_agent_mode,
145
+ default_effort: canonical.execution.default_effort,
146
+ default_timeout_seconds: canonical.execution.default_timeout_seconds,
147
+ mode: canonical.execution.mode,
148
+ max_parallel: canonical.execution.max_parallel,
149
+ isolation: canonical.execution.isolation,
150
+ collaboration_mode: routing.collaboration_mode,
151
+ tier_policy: routing.tier_policy,
152
+ flash_state: routing.flash_state,
153
+ pro_state: routing.pro_state,
154
+ worker_state: canonical.worker.state,
155
+ review_state: canonical.review.state,
156
+ auto_review: canonical.review.auto_review === true,
157
+ worker_provider_mode: canonical.worker.provider_mode,
158
+ flash_model_priority: [...canonical.worker.model_policy.priority],
159
+ flash_model_priority_configured: canonical.worker.model_policy.priorityConfigured,
160
+ flash_model_fallback: canonical.worker.model_policy.fallback,
161
+ pro_model_priority: [...pro.priority],
162
+ pro_model_priority_configured: pro.configured,
163
+ pro_model_fallback: pro.fallback,
164
+ escalate_on_failure: canonical.worker.model_policy.escalation.enabled,
165
+ pro_reviews_flash: canonical.review.auto_review === true,
166
+ execution: canonical.execution,
167
+ worker: canonical.worker,
168
+ review: canonical.review,
169
+ legacy: canonical.legacy,
170
+ };
171
+ }
172
+
173
+ /**
174
+ * v0.3 model-policy view. The frozen v0.2 resolver remains authoritative for
175
+ * every existing dimension. This facade only adds the normalized opt-in
176
+ * adaptive sub-domain, so direct canonical-ish v0.2 callers retain the exact
177
+ * priority/escalation semantics they had before schema-v3 existed.
178
+ */
179
+ export function resolveModelPolicy(config = {}, role = 'worker', context = {}) {
180
+ const base = legacy.resolveModelPolicy(config, role, context);
181
+ const rawPolicy = role === 'reviewer'
182
+ ? config?.review?.model_policy
183
+ : config?.worker?.model_policy;
184
+ return {
185
+ ...base,
186
+ adaptive: normalizeAdaptiveRouting(rawPolicy?.adaptive ?? base.adaptive),
187
+ };
188
+ }
189
+
190
+ /** Explicit legacy-import normalizer for the persistence layer. */
191
+ export function normalizeLegacyGlobalConfig(raw = {}) {
192
+ return legacy.normalizeGlobalConfig(raw);
193
+ }
194
+
195
+ export function configHasCanonicalAuthority(raw = {}) {
196
+ return hasCanonicalAuthority(raw);
197
+ }
@@ -0,0 +1,169 @@
1
+ // Conservative release/environment readiness matrix.
2
+ //
3
+ // A row is PASS only when the caller supplies direct evidence for that row.
4
+ // Missing evidence is NOT_RUN, not an inferred success. Runtime observations
5
+ // (Hub handshake / catalog read) are intentionally separate from execution
6
+ // verification (real worker, reviewer, cancellation, timeout, etc.).
7
+
8
+ export const READINESS_STATUSES = Object.freeze(['PASS', 'FAIL', 'BLOCKED', 'SKIP', 'NOT_RUN']);
9
+
10
+ export const READINESS_REASON_CODES = Object.freeze({
11
+ LIVE_CHECK_PASSED: 'LIVE_CHECK_PASSED',
12
+ HUB_UNREACHABLE: 'HUB_UNREACHABLE',
13
+ HUB_INCOMPATIBLE: 'HUB_INCOMPATIBLE',
14
+ PROVIDER_CATALOG_RESOLVED: 'PROVIDER_CATALOG_RESOLVED',
15
+ PROVIDER_CATALOG_UNAVAILABLE: 'PROVIDER_CATALOG_UNAVAILABLE',
16
+ PROVIDER_CATALOG_HEALTH_WARNING: 'PROVIDER_CATALOG_HEALTH_WARNING',
17
+ PROVIDER_CATALOG_NOT_REQUIRED: 'PROVIDER_CATALOG_NOT_REQUIRED',
18
+ PROVIDER_MODE_UNKNOWN: 'PROVIDER_MODE_UNKNOWN',
19
+ NO_CI_EVIDENCE: 'NO_CI_EVIDENCE',
20
+ NO_EXECUTION_EVIDENCE: 'NO_EXECUTION_EVIDENCE',
21
+ CREDENTIAL_STATUS_NOT_PROBED: 'CREDENTIAL_STATUS_NOT_PROBED',
22
+ EVIDENCE_REPORTED: 'EVIDENCE_REPORTED',
23
+ });
24
+
25
+ const TARGET_ROWS = Object.freeze([
26
+ ['linux_deterministic', 'ci'],
27
+ ['windows_regressions', 'ci'],
28
+ ['macos_smoke', 'ci'],
29
+ ['hub_compatibility', 'live-runtime'],
30
+ ['provider_catalog', 'live-runtime'],
31
+ ['deepseek_flash', 'real-execution'],
32
+ ['deepseek_pro', 'real-execution'],
33
+ ['opencode_go_mimo_qwen', 'real-execution'],
34
+ ['reviewer_pipeline', 'real-execution'],
35
+ ['cancellation_timeout_escalation', 'real-execution'],
36
+ ['standalone_official', 'real-execution'],
37
+ ]);
38
+
39
+ function baseRow(id, category, status, reasonCode, evidenceSource = 'none', extra = {}) {
40
+ return {
41
+ id,
42
+ category,
43
+ status,
44
+ reason_code: reasonCode,
45
+ evidence_source: evidenceSource,
46
+ ...extra,
47
+ };
48
+ }
49
+
50
+ function normalizeEvidence(row, evidence) {
51
+ if (!evidence || typeof evidence !== 'object') return row;
52
+ if (!READINESS_STATUSES.includes(evidence.status)) return row;
53
+ const reason = typeof evidence.reason_code === 'string' && evidence.reason_code.trim()
54
+ ? evidence.reason_code.trim()
55
+ : READINESS_REASON_CODES.EVIDENCE_REPORTED;
56
+ const source = typeof evidence.evidence_source === 'string' && evidence.evidence_source.trim()
57
+ ? evidence.evidence_source.trim()
58
+ : 'reported-evidence';
59
+ return {
60
+ ...row,
61
+ status: evidence.status,
62
+ reason_code: reason,
63
+ evidence_source: source,
64
+ ...(typeof evidence.evidence_ref === 'string' && evidence.evidence_ref.trim()
65
+ ? { evidence_ref: evidence.evidence_ref.trim() }
66
+ : {}),
67
+ };
68
+ }
69
+
70
+ function defaultRows() {
71
+ return Object.fromEntries(TARGET_ROWS.map(([id, category]) => {
72
+ const reason = category === 'ci'
73
+ ? READINESS_REASON_CODES.NO_CI_EVIDENCE
74
+ : id === 'standalone_official'
75
+ ? READINESS_REASON_CODES.CREDENTIAL_STATUS_NOT_PROBED
76
+ : READINESS_REASON_CODES.NO_EXECUTION_EVIDENCE;
77
+ return [id, baseRow(id, category, 'NOT_RUN', reason)];
78
+ }));
79
+ }
80
+
81
+ /**
82
+ * Build a secret-free readiness matrix from direct runtime observations plus
83
+ * optional trusted evidence supplied by a higher layer.
84
+ *
85
+ * `evidence` is deliberately inert metadata: this module never reads files,
86
+ * credentials, GitHub, provider config, or the network on its own.
87
+ */
88
+ export function buildReadinessMatrix({
89
+ platform = process.platform,
90
+ hubCompatibility = null,
91
+ workerProviderMode = null,
92
+ providerCatalogChecked = false,
93
+ providerCatalogOk = false,
94
+ evidence = {},
95
+ } = {}) {
96
+ const rows = defaultRows();
97
+
98
+ if (hubCompatibility?.compatible === true) {
99
+ rows.hub_compatibility = baseRow(
100
+ 'hub_compatibility', 'live-runtime', 'PASS',
101
+ READINESS_REASON_CODES.LIVE_CHECK_PASSED, 'hub-handshake',
102
+ {
103
+ runtime_version: hubCompatibility.runtime_version ?? null,
104
+ protocol_version: hubCompatibility.protocol_version ?? null,
105
+ },
106
+ );
107
+ } else if (hubCompatibility?.reachable === true) {
108
+ rows.hub_compatibility = baseRow(
109
+ 'hub_compatibility', 'live-runtime', 'FAIL',
110
+ READINESS_REASON_CODES.HUB_INCOMPATIBLE, 'hub-handshake',
111
+ { detail_code: hubCompatibility.code ?? null },
112
+ );
113
+ } else {
114
+ rows.hub_compatibility = baseRow(
115
+ 'hub_compatibility', 'live-runtime', 'BLOCKED',
116
+ READINESS_REASON_CODES.HUB_UNREACHABLE, 'hub-handshake',
117
+ { detail_code: hubCompatibility?.code ?? null },
118
+ );
119
+ }
120
+
121
+ if (workerProviderMode == null) {
122
+ rows.provider_catalog = baseRow(
123
+ 'provider_catalog', 'live-runtime', 'NOT_RUN',
124
+ READINESS_REASON_CODES.PROVIDER_MODE_UNKNOWN, 'none',
125
+ );
126
+ } else if (workerProviderMode === 'deepseek-official') {
127
+ rows.provider_catalog = baseRow(
128
+ 'provider_catalog', 'live-runtime', 'SKIP',
129
+ READINESS_REASON_CODES.PROVIDER_CATALOG_NOT_REQUIRED, 'runtime-policy',
130
+ );
131
+ } else if (!hubCompatibility?.compatible) {
132
+ rows.provider_catalog = baseRow(
133
+ 'provider_catalog', 'live-runtime', 'BLOCKED',
134
+ hubCompatibility?.reachable
135
+ ? READINESS_REASON_CODES.HUB_INCOMPATIBLE
136
+ : READINESS_REASON_CODES.HUB_UNREACHABLE,
137
+ 'hub-handshake',
138
+ { detail_code: hubCompatibility?.code ?? null },
139
+ );
140
+ } else if (providerCatalogChecked && providerCatalogOk) {
141
+ rows.provider_catalog = baseRow(
142
+ 'provider_catalog', 'live-runtime', 'PASS',
143
+ READINESS_REASON_CODES.PROVIDER_CATALOG_RESOLVED, 'harness-catalog',
144
+ );
145
+ } else if (providerCatalogChecked) {
146
+ rows.provider_catalog = baseRow(
147
+ 'provider_catalog', 'live-runtime', 'FAIL',
148
+ READINESS_REASON_CODES.PROVIDER_CATALOG_UNAVAILABLE, 'harness-catalog',
149
+ );
150
+ }
151
+
152
+ for (const [id] of TARGET_ROWS) {
153
+ rows[id] = normalizeEvidence(rows[id], evidence?.[id]);
154
+ }
155
+
156
+ const ordered = TARGET_ROWS.map(([id]) => rows[id]);
157
+ const counts = Object.fromEntries(READINESS_STATUSES.map((status) => [
158
+ status,
159
+ ordered.filter((row) => row.status === status).length,
160
+ ]));
161
+
162
+ return {
163
+ schema_version: 1,
164
+ platform,
165
+ conservative: true,
166
+ summary: counts,
167
+ rows: ordered,
168
+ };
169
+ }
@@ -0,0 +1,90 @@
1
+ // Runtime control activation contract.
2
+ //
3
+ // This is deliberately data, not UI prose. MCP diagnostics and the Settings
4
+ // surface consume the same boundary definitions so users are never told two
5
+ // different stories about when a config change takes effect.
6
+
7
+ export const ACTIVATION_BOUNDARY = Object.freeze({
8
+ LIVE: 'live',
9
+ NEXT_WORKFLOW: 'next-workflow',
10
+ NEXT_SESSION: 'next-session',
11
+ RESTART_REQUIRED: 'restart-required',
12
+ });
13
+
14
+ const N = ACTIVATION_BOUNDARY.NEXT_WORKFLOW;
15
+ const S = ACTIVATION_BOUNDARY.NEXT_SESSION;
16
+ const L = ACTIVATION_BOUNDARY.LIVE;
17
+ const R = ACTIVATION_BOUNDARY.RESTART_REQUIRED;
18
+
19
+ /**
20
+ * `global` describes a write made through persisted Settings/config.
21
+ * `session` describes an explicit dsh_worker_config override in the already
22
+ * running MCP process. `session: null` means the setting is not a session
23
+ * override surface.
24
+ */
25
+ export const RUNTIME_SETTING_ACTIVATION = Object.freeze({
26
+ max_parallel: Object.freeze({ global: L, session: null, note: 'Admission limit refreshes before new workflow starts and when slots release; lowering never cancels active work.' }),
27
+
28
+ subagents_enabled: Object.freeze({ global: N, session: N }),
29
+ collaboration_mode: Object.freeze({ global: N, session: N }),
30
+ main_agent_mode: Object.freeze({ global: N, session: N }),
31
+ flash_state: Object.freeze({ global: N, session: N }),
32
+ pro_state: Object.freeze({ global: N, session: N }),
33
+ worker_state: Object.freeze({ global: N, session: N }),
34
+ review_state: Object.freeze({ global: N, session: N }),
35
+ auto_review: Object.freeze({ global: N, session: N }),
36
+ pro_reviews_flash: Object.freeze({ global: N, session: N }),
37
+ worker_provider_mode: Object.freeze({ global: N, session: null }),
38
+ flash_model_priority: Object.freeze({ global: N, session: null }),
39
+ flash_model_fallback: Object.freeze({ global: N, session: null }),
40
+ pro_model_priority: Object.freeze({ global: N, session: null }),
41
+ pro_model_fallback: Object.freeze({ global: N, session: null }),
42
+ adaptive_routing: Object.freeze({ global: N, session: null, note: 'Opt-in provider health ordering is read for the next Hub model selection; existing explicit priorities remain authoritative.' }),
43
+ isolation: Object.freeze({ global: N, session: null }),
44
+ vision_provider: Object.freeze({ global: N, session: null }),
45
+ vision_model: Object.freeze({ global: N, session: null }),
46
+ imagegen_provider: Object.freeze({ global: N, session: null }),
47
+
48
+ // These values are copied into the MCP session defaults at process startup.
49
+ // dsh_worker_config can override them for subsequent workflows in that same
50
+ // session, but persisted global edits require a new MCP session to inherit.
51
+ default_tier: Object.freeze({ global: S, session: N }),
52
+ default_effort: Object.freeze({ global: S, session: N }),
53
+ mode: Object.freeze({ global: S, session: N }),
54
+ default_timeout_seconds: Object.freeze({ global: S, session: N }),
55
+ escalate_on_failure: Object.freeze({ global: S, session: N }),
56
+ preset_flash: Object.freeze({ global: S, session: N }),
57
+ preset_pro: Object.freeze({ global: S, session: N }),
58
+
59
+ // hub-client freezes its base URL at module initialization. Crew Vision and
60
+ // Image Generation tool registration is also decided at Hub plugin boot.
61
+ hub_url: Object.freeze({ global: R, session: null }),
62
+ vision_enabled: Object.freeze({ global: R, session: null }),
63
+ imagegen_enabled: Object.freeze({ global: R, session: null }),
64
+ });
65
+
66
+ export function activationForSetting(key) {
67
+ const entry = RUNTIME_SETTING_ACTIVATION[key];
68
+ return entry ? { ...entry } : null;
69
+ }
70
+
71
+ export function runtimeActivationMetadata() {
72
+ return Object.fromEntries(
73
+ Object.entries(RUNTIME_SETTING_ACTIVATION).map(([key, value]) => [key, { ...value }]),
74
+ );
75
+ }
76
+
77
+ export function summarizeActivationBoundaries(metadata = RUNTIME_SETTING_ACTIVATION) {
78
+ const out = {
79
+ live: [],
80
+ 'next-workflow': [],
81
+ 'next-session': [],
82
+ 'restart-required': [],
83
+ };
84
+ for (const [key, entry] of Object.entries(metadata)) {
85
+ const boundary = entry?.global;
86
+ if (out[boundary]) out[boundary].push(key);
87
+ }
88
+ for (const values of Object.values(out)) values.sort();
89
+ return out;
90
+ }
@@ -0,0 +1,108 @@
1
+ // Shared runtime identity and Hub compatibility contract.
2
+ //
3
+ // Package/release semver and the wire protocol are intentionally separate:
4
+ // - RUNTIME_VERSION identifies the source/runtime generation for diagnostics.
5
+ // - HUB_PROTOCOL_VERSION changes only when Hub <-> MCP wire semantics become
6
+ // incompatible.
7
+ //
8
+ // Keep this module pure and dependency-free so Hub, MCP and tests all use the
9
+ // exact same compatibility rules.
10
+
11
+ export const RUNTIME_VERSION = '0.3.0';
12
+ export const HUB_PROTOCOL_VERSION = 1;
13
+
14
+ export const HUB_CAPABILITIES = Object.freeze([
15
+ 'jobs',
16
+ 'jobs-wait',
17
+ 'jobs-cancel',
18
+ 'roles',
19
+ 'attempt-index',
20
+ 'model-policy',
21
+ 'model-catalog',
22
+ 'presets',
23
+ 'config',
24
+ ]);
25
+
26
+ // Capabilities the current MCP workflow depends on for full Hub execution.
27
+ // Additional capabilities may be advertised without breaking compatibility.
28
+ export const REQUIRED_HUB_CAPABILITIES = Object.freeze([
29
+ 'jobs',
30
+ 'jobs-wait',
31
+ 'jobs-cancel',
32
+ 'roles',
33
+ 'attempt-index',
34
+ 'model-policy',
35
+ ]);
36
+
37
+ export const HUB_COMPATIBILITY_CODES = Object.freeze({
38
+ UNREACHABLE: 'HUB_UNREACHABLE',
39
+ HTTP_ERROR: 'HUB_HTTP_ERROR',
40
+ SERVICE_MISMATCH: 'HUB_SERVICE_MISMATCH',
41
+ PROTOCOL_MISSING: 'HUB_PROTOCOL_MISSING',
42
+ PROTOCOL_MISMATCH: 'HUB_PROTOCOL_MISMATCH',
43
+ CAPABILITY_MISSING: 'HUB_CAPABILITY_MISSING',
44
+ });
45
+
46
+ function normalizedCapabilities(value) {
47
+ if (!Array.isArray(value)) return [];
48
+ return [...new Set(value.filter((item) => typeof item === 'string' && item.trim()).map((item) => item.trim()))];
49
+ }
50
+
51
+ export function getHubRuntimeIdentity() {
52
+ return {
53
+ service: 'dsh-crew-hub',
54
+ runtime_version: RUNTIME_VERSION,
55
+ protocol_version: HUB_PROTOCOL_VERSION,
56
+ capabilities: [...HUB_CAPABILITIES],
57
+ };
58
+ }
59
+
60
+ /**
61
+ * Evaluate an already-received Hub ping body.
62
+ *
63
+ * This function does no I/O. `reachable` means an HTTP response was received;
64
+ * `compatible` means the response is from dsh-crew and satisfies the current
65
+ * protocol + required capability contract.
66
+ */
67
+ export function evaluateHubHandshake(body, { requiredCapabilities = REQUIRED_HUB_CAPABILITIES } = {}) {
68
+ const capabilities = normalizedCapabilities(body?.capabilities);
69
+ const base = {
70
+ reachable: true,
71
+ compatible: false,
72
+ service: typeof body?.service === 'string' ? body.service : null,
73
+ runtime_version: typeof body?.runtime_version === 'string' ? body.runtime_version : null,
74
+ protocol_version: Number.isInteger(body?.protocol_version) ? body.protocol_version : null,
75
+ capabilities,
76
+ missing_capabilities: [],
77
+ code: null,
78
+ };
79
+
80
+ if (body?.service !== 'dsh-crew-hub') {
81
+ return { ...base, code: HUB_COMPATIBILITY_CODES.SERVICE_MISMATCH };
82
+ }
83
+
84
+ if (!Number.isInteger(body?.protocol_version)) {
85
+ return { ...base, code: HUB_COMPATIBILITY_CODES.PROTOCOL_MISSING };
86
+ }
87
+
88
+ if (body.protocol_version !== HUB_PROTOCOL_VERSION) {
89
+ return { ...base, code: HUB_COMPATIBILITY_CODES.PROTOCOL_MISMATCH };
90
+ }
91
+
92
+ const required = normalizedCapabilities(requiredCapabilities);
93
+ const advertised = new Set(capabilities);
94
+ const missing = required.filter((capability) => !advertised.has(capability));
95
+ if (missing.length > 0) {
96
+ return {
97
+ ...base,
98
+ missing_capabilities: missing,
99
+ code: HUB_COMPATIBILITY_CODES.CAPABILITY_MISSING,
100
+ };
101
+ }
102
+
103
+ return {
104
+ ...base,
105
+ compatible: true,
106
+ code: null,
107
+ };
108
+ }