@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.
Files changed (151) hide show
  1. package/.claude-plugin/marketplace.json +16 -16
  2. package/.claude-plugin/plugin.json +14 -14
  3. package/LICENSE +21 -21
  4. package/README.de.md +359 -359
  5. package/README.es.md +359 -359
  6. package/README.fr.md +359 -359
  7. package/README.hi.md +359 -359
  8. package/README.id.md +359 -359
  9. package/README.ja.md +359 -359
  10. package/README.ko.md +359 -359
  11. package/README.md +126 -126
  12. package/README.pt.md +359 -359
  13. package/README.ru.md +359 -359
  14. package/README.th.md +359 -359
  15. package/README.tr.md +359 -359
  16. package/README.vi.md +359 -359
  17. package/README.zh-TW.md +359 -359
  18. package/README.zh.md +116 -116
  19. package/agents/ds-flash.md +24 -24
  20. package/agents/ds-pro.md +24 -24
  21. package/agents/ds-reviewer.md +23 -23
  22. package/agents/ds-worker.md +23 -23
  23. package/bin/dsh-crew.mjs +16 -16
  24. package/codex/agents/ds-flash.toml +34 -34
  25. package/codex/agents/ds-pro.toml +34 -34
  26. package/codex/agents/ds-reviewer.toml +32 -32
  27. package/codex/agents/ds-worker.toml +32 -32
  28. package/codex/prompts/dsh-config.md +19 -19
  29. package/codex/prompts/dsh-status.md +5 -5
  30. package/commands/config.md +23 -23
  31. package/commands/off.md +5 -5
  32. package/commands/on.md +5 -5
  33. package/commands/status.md +9 -9
  34. package/cordis.patch.yml +4 -4
  35. package/docs/gpt-relay-extension.md +103 -103
  36. package/docs/installation.md +138 -138
  37. package/docs/job-contracts.md +103 -103
  38. package/docs/readiness-matrix.md +85 -85
  39. package/docs/ui-surfaces.md +107 -107
  40. package/official-web-bridge/cordis.patch.yml +4 -4
  41. package/official-web-bridge/entry.mjs +1 -1
  42. package/official-web-bridge/overlay-entry.mjs +59 -59
  43. package/official-web-bridge/package.json +25 -25
  44. package/package.json +3 -2
  45. package/scripts/build-client.mjs +49 -49
  46. package/scripts/live-crew-smoke.mjs +39 -39
  47. package/scripts/live-policy-matrix.mjs +177 -177
  48. package/scripts/policy-probe.mjs +101 -101
  49. package/scripts/remove-legacy-official-bridge.ps1 +89 -89
  50. package/scripts/setup.mjs +393 -393
  51. package/scripts/smoke-real.mjs +110 -110
  52. package/scripts/smoke.mjs +78 -78
  53. package/scripts/verify-crew-ui-polish.mjs +145 -145
  54. package/scripts/verify-history-ui.mjs +97 -97
  55. package/scripts/verify-installer-fix.mjs +26 -26
  56. package/scripts/verify-npm-install.mjs +311 -311
  57. package/scripts/verify-official-bridge-e2e.mjs +192 -192
  58. package/src/adaptive-routing.mjs +260 -260
  59. package/src/client/activation-summary.tsx +64 -64
  60. package/src/client/collapsible-sections.mjs +55 -55
  61. package/src/client/history-panel.tsx +108 -108
  62. package/src/client/host-readiness.mjs +71 -71
  63. package/src/client/index.tsx +1711 -1711
  64. package/src/client/model-callability-view.mjs +17 -17
  65. package/src/client/panel-chrome.tsx +40 -40
  66. package/src/client/quick-entry.tsx +10 -10
  67. package/src/client/quick-panel.tsx +275 -275
  68. package/src/client/readiness-envelope.mjs +34 -34
  69. package/src/client/surface-detection.mjs +43 -43
  70. package/src/config-readiness.mjs +226 -226
  71. package/src/credential-reference.mjs +38 -38
  72. package/src/delivery.mjs +205 -205
  73. package/src/dsh-cli-runtime.mjs +1021 -1021
  74. package/src/dsh-cohort.mjs +20 -20
  75. package/src/extension-contract.mjs +104 -104
  76. package/src/failure-classification.mjs +201 -201
  77. package/src/history/admission-gate.mjs +67 -67
  78. package/src/history/archive-store.mjs +272 -272
  79. package/src/history/cleanup-plan.mjs +89 -89
  80. package/src/history/http.mjs +32 -32
  81. package/src/history/operation.mjs +86 -86
  82. package/src/history/runner-detach.mjs +34 -34
  83. package/src/history/runner.mjs +52 -52
  84. package/src/history/runtime.mjs +36 -36
  85. package/src/history/service.mjs +177 -177
  86. package/src/history/state.mjs +27 -27
  87. package/src/hub/entry.mjs +104 -104
  88. package/src/hub/index.mjs +2694 -2694
  89. package/src/hub-client.mjs +154 -154
  90. package/src/hub-compatibility.mjs +42 -42
  91. package/src/i18n.mjs +19 -19
  92. package/src/information-flow.mjs +67 -67
  93. package/src/install/cli.mjs +28 -28
  94. package/src/install/install-legacy.mjs +711 -711
  95. package/src/install/install.mjs +483 -483
  96. package/src/install/npx-lifecycle.mjs +3456 -3456
  97. package/src/install/official-frontend-assets.mjs +78 -78
  98. package/src/install/official-web.mjs +95 -95
  99. package/src/install/payload-content.mjs +88 -88
  100. package/src/install/windows-startup.mjs +236 -236
  101. package/src/install/windows-supervisor-adapter.mjs +443 -443
  102. package/src/install/windows-supervisor-lifecycle.mjs +782 -782
  103. package/src/install/zcode.mjs +397 -397
  104. package/src/job-contracts.mjs +255 -255
  105. package/src/local-request-guard.mjs +60 -60
  106. package/src/mcp-runtime.mjs +340 -340
  107. package/src/model-callability-contract.mjs +79 -79
  108. package/src/model-catalog.mjs +180 -180
  109. package/src/model-routing.mjs +586 -586
  110. package/src/model-schedule.mjs +207 -207
  111. package/src/official-web-bridge.mjs +447 -447
  112. package/src/policy.mjs +235 -235
  113. package/src/provider-delete-adapters.mjs +1934 -1934
  114. package/src/provider-health.mjs +130 -130
  115. package/src/provider-inventory.mjs +182 -182
  116. package/src/provider-layer-migration-adapters.mjs +759 -759
  117. package/src/provider-layer-migration.mjs +198 -198
  118. package/src/provider-lifecycle-state.mjs +103 -103
  119. package/src/provider-lifecycle.mjs +252 -252
  120. package/src/provider-profile-store.mjs +390 -390
  121. package/src/provider-settings-store.mjs +633 -633
  122. package/src/provider-store-lock.mjs +67 -67
  123. package/src/readiness-matrix.mjs +181 -181
  124. package/src/removable-waiter.mjs +29 -29
  125. package/src/role-profiles.mjs +107 -107
  126. package/src/runtime-controls.mjs +84 -84
  127. package/src/runtime-identity-contract.mjs +34 -34
  128. package/src/runtime-identity.mjs +235 -235
  129. package/src/runtime-readiness-snapshot.mjs +285 -285
  130. package/src/server.mjs +581 -581
  131. package/src/session-origins.mjs +60 -60
  132. package/src/standalone-sdk.mjs +23 -23
  133. package/src/status-shard.mjs +63 -63
  134. package/src/structured-error-code.mjs +38 -38
  135. package/src/supervisor/restart-request.mjs +256 -256
  136. package/src/workflow-runtime.mjs +739 -739
  137. package/src/workflow.mjs +155 -155
  138. package/src/workspace-audit.mjs +231 -231
  139. package/src/workspace-context.mjs +146 -146
  140. package/src/workspace-isolation.mjs +463 -455
  141. package/src/workspace-readiness.mjs +32 -32
  142. package/statusline/statusline.sh +14 -14
  143. package/statusline/worker-segment.sh +35 -35
  144. package/windows/start-dsh-crew.cmd +57 -57
  145. package/windows/start-dsh-crew.ps1 +1302 -1302
  146. package/windows/supervisor-control.ps1 +467 -467
  147. package/worker.cordis.yml +67 -67
  148. package/zcode/agents/ds-reviewer.md +31 -31
  149. package/zcode/agents/ds-worker.md +31 -31
  150. package/zcode/commands/dsh-config.md +17 -17
  151. package/zcode/commands/dsh-status.md +5 -5
@@ -1,79 +1,79 @@
1
- import { isExactNativeCrewIdentity, sameCompleteRuntimeIdentity } from './runtime-identity-contract.mjs';
2
-
3
- export const MODEL_CALLABILITY_SCHEMA_VERSION = 2;
4
- const ROLES = ['worker', 'reviewer'];
5
- const STATES = new Set(['CALLABLE', 'NOT_CALLABLE', 'STALE', 'UNKNOWN', 'NOT_APPLICABLE']);
6
- const SOURCES = new Set(['provider_health', 'execution']);
7
- const MAX_EVIDENCE_TTL_MS = 24 * 60 * 60 * 1000;
8
-
9
- function exactKeys(value, keys) {
10
- return value && typeof value === 'object' && !Array.isArray(value)
11
- && Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
12
- }
13
-
14
- function route(value) {
15
- return typeof value?.provider === 'string' && value.provider.trim()
16
- && typeof value?.model === 'string' && value.model.trim()
17
- ? { provider: value.provider.trim(), model: value.model.trim() } : null;
18
- }
19
-
20
- function validEvidence(role, now) {
21
- if (!SOURCES.has(role.source) || !Number.isFinite(role.observed_at) || role.observed_at > now
22
- || !Number.isFinite(role.expires_at) || role.expires_at <= now
23
- || role.expires_at - role.observed_at > MAX_EVIDENCE_TTL_MS) return false;
24
- if (role.source === 'execution') {
25
- if (!role.last_success || typeof role.last_success !== 'object'
26
- || typeof role.last_success.job_id !== 'string' || !role.last_success.job_id.trim()
27
- || role.last_success.observed_at !== role.observed_at
28
- || role.last_success.expires_at !== role.expires_at) return false;
29
- }
30
- return true;
31
- }
32
-
33
- export function validateModelCallabilityV2({ projection, runtime, expectedEnabledRoles, expectedSelections, now = Date.now() } = {}) {
34
- const fail = (reason_code) => ({ ok: false, reason_code, state: 'UNKNOWN' });
35
- if (!projection || typeof projection !== 'object' || projection.schema_version !== MODEL_CALLABILITY_SCHEMA_VERSION) return fail('MODEL_CALLABILITY_SCHEMA_INVALID');
36
- if (!isExactNativeCrewIdentity(runtime) || !isExactNativeCrewIdentity(projection.runtime_identity)
37
- || !sameCompleteRuntimeIdentity(runtime, projection.runtime_identity)
38
- || projection.current_runtime_id !== runtime.runtime_id) return fail('MODEL_CALLABILITY_RUNTIME_MISMATCH');
39
- if (!Number.isFinite(projection.captured_at) || projection.captured_at > now) return fail('MODEL_CALLABILITY_CAPTURE_INVALID');
40
- if (!exactKeys(projection.enabled_roles, ROLES) || ROLES.some((role) => typeof projection.enabled_roles[role] !== 'boolean')) return fail('MODEL_CALLABILITY_ROLES_INVALID');
41
- if (expectedEnabledRoles && (!exactKeys(expectedEnabledRoles, ROLES) || ROLES.some((role) => projection.enabled_roles[role] !== expectedEnabledRoles[role]))) return fail('MODEL_CALLABILITY_ROLE_CONFIG_MISMATCH');
42
- if (expectedSelections && !exactKeys(expectedSelections, ROLES)) return fail('MODEL_CALLABILITY_EXPECTED_SELECTIONS_INVALID');
43
- if (!exactKeys(projection.roles, ROLES)) return fail('MODEL_CALLABILITY_ROLE_EVIDENCE_MISSING');
44
-
45
- for (const roleName of ROLES) {
46
- const role = projection.roles[roleName];
47
- if (!role || !STATES.has(role.state)) return fail('MODEL_CALLABILITY_ROLE_STATE_INVALID');
48
- const selected = route(role.selected);
49
- if (role.selected !== undefined && role.selected !== null && !selected) return fail('MODEL_CALLABILITY_SELECTION_INVALID');
50
- if (expectedSelections) {
51
- const expectedRaw = expectedSelections[roleName];
52
- const expected = expectedRaw === null ? null : route(expectedRaw);
53
- if (expectedRaw !== null && !expected) return fail('MODEL_CALLABILITY_EXPECTED_SELECTION_INVALID');
54
- if ((expected === null) !== (selected === null)
55
- || expected && (expected.provider !== selected.provider || expected.model !== selected.model)) return fail('MODEL_CALLABILITY_SELECTION_MISMATCH');
56
- }
57
- if (projection.enabled_roles[roleName] === false) {
58
- if (role.state !== 'NOT_APPLICABLE' || role.reason_code !== 'ROLE_DISABLED') return fail('MODEL_CALLABILITY_DISABLED_ROLE_INVALID');
59
- continue;
60
- }
61
- if (['CALLABLE', 'NOT_CALLABLE'].includes(role.state) && !selected) return fail('MODEL_CALLABILITY_SELECTION_INVALID');
62
- if (projection.enabled_roles[roleName] === true && role.state === 'NOT_APPLICABLE') return fail('MODEL_CALLABILITY_ENABLED_ROLE_NOT_APPLICABLE');
63
- if (['CALLABLE', 'NOT_CALLABLE'].includes(role.state)) {
64
- if (!validEvidence(role, now)) return fail('MODEL_CALLABILITY_EVIDENCE_INVALID');
65
- }
66
- }
67
-
68
- const activeRoles = ROLES.map((role) => projection.roles[role]).filter((_, index) => projection.enabled_roles[ROLES[index]] === true);
69
- const activeStates = activeRoles.map((role) => role.state);
70
- const state = activeStates.includes('NOT_CALLABLE') ? 'NOT_CALLABLE'
71
- : activeStates.length > 0 && activeStates.every((value) => value === 'CALLABLE') ? 'CALLABLE'
72
- : activeStates.includes('STALE') ? 'STALE' : 'UNKNOWN';
73
- if (projection.overall !== state) return fail('MODEL_CALLABILITY_OVERALL_CONTRADICTION');
74
- const evidenceExpirations = activeRoles.map((role) => role.expires_at).filter((value) => Number.isFinite(value));
75
- const expectedExpires = evidenceExpirations.length ? Math.min(...evidenceExpirations) : null;
76
- if (projection.expires_at !== expectedExpires) return fail('MODEL_CALLABILITY_EXPIRY_CONTRADICTION');
77
- if (state === 'CALLABLE' && (!Number.isFinite(projection.expires_at) || projection.expires_at <= now)) return fail('MODEL_CALLABILITY_EXPIRED');
78
- return { ok: true, state, reason_code: 'MODEL_CALLABILITY_VALID' };
79
- }
1
+ import { isExactNativeCrewIdentity, sameCompleteRuntimeIdentity } from './runtime-identity-contract.mjs';
2
+
3
+ export const MODEL_CALLABILITY_SCHEMA_VERSION = 2;
4
+ const ROLES = ['worker', 'reviewer'];
5
+ const STATES = new Set(['CALLABLE', 'NOT_CALLABLE', 'STALE', 'UNKNOWN', 'NOT_APPLICABLE']);
6
+ const SOURCES = new Set(['provider_health', 'execution']);
7
+ const MAX_EVIDENCE_TTL_MS = 24 * 60 * 60 * 1000;
8
+
9
+ function exactKeys(value, keys) {
10
+ return value && typeof value === 'object' && !Array.isArray(value)
11
+ && Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
12
+ }
13
+
14
+ function route(value) {
15
+ return typeof value?.provider === 'string' && value.provider.trim()
16
+ && typeof value?.model === 'string' && value.model.trim()
17
+ ? { provider: value.provider.trim(), model: value.model.trim() } : null;
18
+ }
19
+
20
+ function validEvidence(role, now) {
21
+ if (!SOURCES.has(role.source) || !Number.isFinite(role.observed_at) || role.observed_at > now
22
+ || !Number.isFinite(role.expires_at) || role.expires_at <= now
23
+ || role.expires_at - role.observed_at > MAX_EVIDENCE_TTL_MS) return false;
24
+ if (role.source === 'execution') {
25
+ if (!role.last_success || typeof role.last_success !== 'object'
26
+ || typeof role.last_success.job_id !== 'string' || !role.last_success.job_id.trim()
27
+ || role.last_success.observed_at !== role.observed_at
28
+ || role.last_success.expires_at !== role.expires_at) return false;
29
+ }
30
+ return true;
31
+ }
32
+
33
+ export function validateModelCallabilityV2({ projection, runtime, expectedEnabledRoles, expectedSelections, now = Date.now() } = {}) {
34
+ const fail = (reason_code) => ({ ok: false, reason_code, state: 'UNKNOWN' });
35
+ if (!projection || typeof projection !== 'object' || projection.schema_version !== MODEL_CALLABILITY_SCHEMA_VERSION) return fail('MODEL_CALLABILITY_SCHEMA_INVALID');
36
+ if (!isExactNativeCrewIdentity(runtime) || !isExactNativeCrewIdentity(projection.runtime_identity)
37
+ || !sameCompleteRuntimeIdentity(runtime, projection.runtime_identity)
38
+ || projection.current_runtime_id !== runtime.runtime_id) return fail('MODEL_CALLABILITY_RUNTIME_MISMATCH');
39
+ if (!Number.isFinite(projection.captured_at) || projection.captured_at > now) return fail('MODEL_CALLABILITY_CAPTURE_INVALID');
40
+ if (!exactKeys(projection.enabled_roles, ROLES) || ROLES.some((role) => typeof projection.enabled_roles[role] !== 'boolean')) return fail('MODEL_CALLABILITY_ROLES_INVALID');
41
+ if (expectedEnabledRoles && (!exactKeys(expectedEnabledRoles, ROLES) || ROLES.some((role) => projection.enabled_roles[role] !== expectedEnabledRoles[role]))) return fail('MODEL_CALLABILITY_ROLE_CONFIG_MISMATCH');
42
+ if (expectedSelections && !exactKeys(expectedSelections, ROLES)) return fail('MODEL_CALLABILITY_EXPECTED_SELECTIONS_INVALID');
43
+ if (!exactKeys(projection.roles, ROLES)) return fail('MODEL_CALLABILITY_ROLE_EVIDENCE_MISSING');
44
+
45
+ for (const roleName of ROLES) {
46
+ const role = projection.roles[roleName];
47
+ if (!role || !STATES.has(role.state)) return fail('MODEL_CALLABILITY_ROLE_STATE_INVALID');
48
+ const selected = route(role.selected);
49
+ if (role.selected !== undefined && role.selected !== null && !selected) return fail('MODEL_CALLABILITY_SELECTION_INVALID');
50
+ if (expectedSelections) {
51
+ const expectedRaw = expectedSelections[roleName];
52
+ const expected = expectedRaw === null ? null : route(expectedRaw);
53
+ if (expectedRaw !== null && !expected) return fail('MODEL_CALLABILITY_EXPECTED_SELECTION_INVALID');
54
+ if ((expected === null) !== (selected === null)
55
+ || expected && (expected.provider !== selected.provider || expected.model !== selected.model)) return fail('MODEL_CALLABILITY_SELECTION_MISMATCH');
56
+ }
57
+ if (projection.enabled_roles[roleName] === false) {
58
+ if (role.state !== 'NOT_APPLICABLE' || role.reason_code !== 'ROLE_DISABLED') return fail('MODEL_CALLABILITY_DISABLED_ROLE_INVALID');
59
+ continue;
60
+ }
61
+ if (['CALLABLE', 'NOT_CALLABLE'].includes(role.state) && !selected) return fail('MODEL_CALLABILITY_SELECTION_INVALID');
62
+ if (projection.enabled_roles[roleName] === true && role.state === 'NOT_APPLICABLE') return fail('MODEL_CALLABILITY_ENABLED_ROLE_NOT_APPLICABLE');
63
+ if (['CALLABLE', 'NOT_CALLABLE'].includes(role.state)) {
64
+ if (!validEvidence(role, now)) return fail('MODEL_CALLABILITY_EVIDENCE_INVALID');
65
+ }
66
+ }
67
+
68
+ const activeRoles = ROLES.map((role) => projection.roles[role]).filter((_, index) => projection.enabled_roles[ROLES[index]] === true);
69
+ const activeStates = activeRoles.map((role) => role.state);
70
+ const state = activeStates.includes('NOT_CALLABLE') ? 'NOT_CALLABLE'
71
+ : activeStates.length > 0 && activeStates.every((value) => value === 'CALLABLE') ? 'CALLABLE'
72
+ : activeStates.includes('STALE') ? 'STALE' : 'UNKNOWN';
73
+ if (projection.overall !== state) return fail('MODEL_CALLABILITY_OVERALL_CONTRADICTION');
74
+ const evidenceExpirations = activeRoles.map((role) => role.expires_at).filter((value) => Number.isFinite(value));
75
+ const expectedExpires = evidenceExpirations.length ? Math.min(...evidenceExpirations) : null;
76
+ if (projection.expires_at !== expectedExpires) return fail('MODEL_CALLABILITY_EXPIRY_CONTRADICTION');
77
+ if (state === 'CALLABLE' && (!Number.isFinite(projection.expires_at) || projection.expires_at <= now)) return fail('MODEL_CALLABILITY_EXPIRED');
78
+ return { ok: true, state, reason_code: 'MODEL_CALLABILITY_VALID' };
79
+ }
@@ -1,180 +1,180 @@
1
- // Read-only adapter from the DSH LLM registry to a credential-free Settings
2
- // payload. Provider/model discovery stays owned by Harness; Crew only reads
3
- // its registered routes and advertised catalog.
4
-
5
- export const MODEL_CATALOG_UNAVAILABLE = 'MODEL_CATALOG_UNAVAILABLE';
6
-
7
- export const CATALOG_HEALTH_CODES = Object.freeze({
8
- EMPTY_CATALOG: 'EMPTY_CATALOG',
9
- EMPTY_PROVIDER_MODELS: 'EMPTY_PROVIDER_MODELS',
10
- PROVIDER_MODEL_LIST_FAILED: 'PROVIDER_MODEL_LIST_FAILED',
11
- HARNESS_DEFAULT_PROVIDER_MISSING: 'HARNESS_DEFAULT_PROVIDER_MISSING',
12
- HARNESS_DEFAULT_MODEL_UNADVERTISED: 'HARNESS_DEFAULT_MODEL_UNADVERTISED',
13
- CATALOG_CONSTRAINED: 'CATALOG_CONSTRAINED',
14
- });
15
-
16
- function catalogError() {
17
- return Object.assign(new Error('Unable to read Harness model catalog.'), { code: MODEL_CATALOG_UNAVAILABLE });
18
- }
19
-
20
- function normalizeProvider(raw) {
21
- if (!raw || typeof raw.id !== 'string' || raw.id.trim() === '') return null;
22
- const id = raw.id.trim();
23
- const adapterOwned = typeof raw.adapter_owned === 'boolean'
24
- ? raw.adapter_owned
25
- : typeof raw.adapterOwned === 'boolean' ? raw.adapterOwned : undefined;
26
- return {
27
- id,
28
- name: typeof raw.name === 'string' && raw.name.trim() ? raw.name.trim() : id,
29
- ...(adapterOwned === undefined ? {} : { adapter_owned: adapterOwned }),
30
- };
31
- }
32
-
33
- function normalizeModels(raw, provider) {
34
- if (!Array.isArray(raw)) return [];
35
- const seen = new Set();
36
- const result = [];
37
- for (const item of raw) {
38
- if (!item || typeof item.id !== 'string' || item.id.trim() === '') continue;
39
- const id = item.id.trim();
40
- if (seen.has(id)) continue;
41
- seen.add(id);
42
- result.push({
43
- id,
44
- name: typeof item.name === 'string' && item.name.trim() ? item.name.trim() : id,
45
- ...(typeof item.description === 'string' && item.description.trim() ? { description: item.description.trim() } : {}),
46
- ...(Array.isArray(item.inputModalities) ? { inputModalities: item.inputModalities.filter((v) => v === 'text' || v === 'image') } : {}),
47
- });
48
- }
49
- return result;
50
- }
51
-
52
- function safeDefault(getCurrentSelection) {
53
- try {
54
- const raw = typeof getCurrentSelection === 'function' ? getCurrentSelection() : undefined;
55
- if (!raw || typeof raw.provider !== 'string' || typeof raw.model !== 'string') return null;
56
- return {
57
- provider: raw.provider,
58
- model: raw.model,
59
- ...(typeof raw.reasoningEffort === 'string' ? { reasoningEffort: raw.reasoningEffort } : {}),
60
- };
61
- } catch {
62
- return null;
63
- }
64
- }
65
-
66
- function healthHint(code, level, { provider, model, signal } = {}) {
67
- return {
68
- code,
69
- level,
70
- ...(typeof provider === 'string' && provider ? { provider } : {}),
71
- ...(typeof model === 'string' && model ? { model } : {}),
72
- ...(typeof signal === 'string' && signal ? { signal } : {}),
73
- };
74
- }
75
-
76
- /**
77
- * Analyze only the effective, already-sanitized Harness catalog.
78
- *
79
- * This intentionally does not know an "expected" third-party catalog. A
80
- * narrow advertised list is therefore informational only: it can point a user
81
- * toward upstream/provider configuration, but it is never proof of a bad
82
- * override and never changes routing eligibility.
83
- */
84
- export function analyzeCatalogHealth({ providers = [], harnessDefault = null } = {}) {
85
- const safeProviders = Array.isArray(providers) ? providers : [];
86
- const hints = [];
87
-
88
- if (safeProviders.length === 0) {
89
- hints.push(healthHint(CATALOG_HEALTH_CODES.EMPTY_CATALOG, 'warning'));
90
- }
91
-
92
- for (const provider of safeProviders) {
93
- const providerId = typeof provider?.id === 'string' ? provider.id : null;
94
- const models = Array.isArray(provider?.models) ? provider.models : [];
95
- if (provider?.error === 'MODEL_LIST_FAILED') {
96
- hints.push(healthHint(CATALOG_HEALTH_CODES.PROVIDER_MODEL_LIST_FAILED, 'warning', { provider: providerId }));
97
- continue;
98
- }
99
- if (models.length === 0) {
100
- // Some providers intentionally accept exact model ids without advertising
101
- // them. Keep this informational rather than turning it into a failure.
102
- hints.push(healthHint(CATALOG_HEALTH_CODES.EMPTY_PROVIDER_MODELS, 'info', { provider: providerId }));
103
- }
104
- }
105
-
106
- if (harnessDefault && typeof harnessDefault.provider === 'string' && typeof harnessDefault.model === 'string') {
107
- const defaultProvider = safeProviders.find((provider) => provider?.id === harnessDefault.provider);
108
- if (!defaultProvider) {
109
- hints.push(healthHint(CATALOG_HEALTH_CODES.HARNESS_DEFAULT_PROVIDER_MISSING, 'warning', {
110
- provider: harnessDefault.provider,
111
- model: harnessDefault.model,
112
- }));
113
- } else if (defaultProvider.error !== 'MODEL_LIST_FAILED' && Array.isArray(defaultProvider.models) && defaultProvider.models.length > 0) {
114
- const advertised = defaultProvider.models.some((model) => model?.id === harnessDefault.model);
115
- if (!advertised) {
116
- hints.push(healthHint(CATALOG_HEALTH_CODES.HARNESS_DEFAULT_MODEL_UNADVERTISED, 'info', {
117
- provider: harnessDefault.provider,
118
- model: harnessDefault.model,
119
- }));
120
- }
121
- }
122
- }
123
-
124
- // A single provider advertising only one or two explicit models is a useful
125
- // signal because local/provider overrides can produce this shape. It is only
126
- // an INFO heuristic: legitimate providers can also have intentionally small
127
- // catalogs, so Crew must not claim an override or route around it.
128
- const healthyProviders = safeProviders.filter((provider) => provider?.error !== 'MODEL_LIST_FAILED');
129
- const totalAdvertised = healthyProviders.reduce(
130
- (sum, provider) => sum + (Array.isArray(provider?.models) ? provider.models.length : 0),
131
- 0,
132
- );
133
- if (healthyProviders.length === 1 && totalAdvertised > 0 && totalAdvertised <= 2) {
134
- hints.push(healthHint(CATALOG_HEALTH_CODES.CATALOG_CONSTRAINED, 'info', {
135
- provider: healthyProviders[0].id,
136
- signal: 'single-provider-small-explicit-catalog',
137
- }));
138
- }
139
-
140
- const warningCount = hints.filter((hint) => hint.level === 'warning').length;
141
- const infoCount = hints.filter((hint) => hint.level === 'info').length;
142
- return {
143
- schema_version: 1,
144
- warning_count: warningCount,
145
- info_count: infoCount,
146
- attention: warningCount > 0,
147
- hints,
148
- };
149
- }
150
-
151
- export async function readHarnessModelCatalog({ llm, getCurrentSelection, now = () => new Date().toISOString() } = {}) {
152
- if (!llm || typeof llm.listProviders !== 'function' || typeof llm.listModels !== 'function') throw catalogError();
153
- let rawProviders;
154
- try {
155
- rawProviders = llm.listProviders();
156
- } catch {
157
- throw catalogError();
158
- }
159
- if (!Array.isArray(rawProviders)) throw catalogError();
160
- const providers = rawProviders.map(normalizeProvider).filter(Boolean);
161
- let failed = 0;
162
- const hydrated = await Promise.all(providers.map(async (provider) => {
163
- try {
164
- return { ...provider, models: normalizeModels(await llm.listModels(provider.id), provider.id) };
165
- } catch {
166
- failed += 1;
167
- return { ...provider, models: [], error: 'MODEL_LIST_FAILED' };
168
- }
169
- }));
170
- const harnessDefault = safeDefault(getCurrentSelection);
171
- return {
172
- providers: hydrated,
173
- provider_count: hydrated.length,
174
- model_count: hydrated.reduce((sum, provider) => sum + provider.models.length, 0),
175
- harness_default: harnessDefault,
176
- refreshed_at: now(),
177
- partial: failed > 0,
178
- health: analyzeCatalogHealth({ providers: hydrated, harnessDefault }),
179
- };
180
- }
1
+ // Read-only adapter from the DSH LLM registry to a credential-free Settings
2
+ // payload. Provider/model discovery stays owned by Harness; Crew only reads
3
+ // its registered routes and advertised catalog.
4
+
5
+ export const MODEL_CATALOG_UNAVAILABLE = 'MODEL_CATALOG_UNAVAILABLE';
6
+
7
+ export const CATALOG_HEALTH_CODES = Object.freeze({
8
+ EMPTY_CATALOG: 'EMPTY_CATALOG',
9
+ EMPTY_PROVIDER_MODELS: 'EMPTY_PROVIDER_MODELS',
10
+ PROVIDER_MODEL_LIST_FAILED: 'PROVIDER_MODEL_LIST_FAILED',
11
+ HARNESS_DEFAULT_PROVIDER_MISSING: 'HARNESS_DEFAULT_PROVIDER_MISSING',
12
+ HARNESS_DEFAULT_MODEL_UNADVERTISED: 'HARNESS_DEFAULT_MODEL_UNADVERTISED',
13
+ CATALOG_CONSTRAINED: 'CATALOG_CONSTRAINED',
14
+ });
15
+
16
+ function catalogError() {
17
+ return Object.assign(new Error('Unable to read Harness model catalog.'), { code: MODEL_CATALOG_UNAVAILABLE });
18
+ }
19
+
20
+ function normalizeProvider(raw) {
21
+ if (!raw || typeof raw.id !== 'string' || raw.id.trim() === '') return null;
22
+ const id = raw.id.trim();
23
+ const adapterOwned = typeof raw.adapter_owned === 'boolean'
24
+ ? raw.adapter_owned
25
+ : typeof raw.adapterOwned === 'boolean' ? raw.adapterOwned : undefined;
26
+ return {
27
+ id,
28
+ name: typeof raw.name === 'string' && raw.name.trim() ? raw.name.trim() : id,
29
+ ...(adapterOwned === undefined ? {} : { adapter_owned: adapterOwned }),
30
+ };
31
+ }
32
+
33
+ function normalizeModels(raw, provider) {
34
+ if (!Array.isArray(raw)) return [];
35
+ const seen = new Set();
36
+ const result = [];
37
+ for (const item of raw) {
38
+ if (!item || typeof item.id !== 'string' || item.id.trim() === '') continue;
39
+ const id = item.id.trim();
40
+ if (seen.has(id)) continue;
41
+ seen.add(id);
42
+ result.push({
43
+ id,
44
+ name: typeof item.name === 'string' && item.name.trim() ? item.name.trim() : id,
45
+ ...(typeof item.description === 'string' && item.description.trim() ? { description: item.description.trim() } : {}),
46
+ ...(Array.isArray(item.inputModalities) ? { inputModalities: item.inputModalities.filter((v) => v === 'text' || v === 'image') } : {}),
47
+ });
48
+ }
49
+ return result;
50
+ }
51
+
52
+ function safeDefault(getCurrentSelection) {
53
+ try {
54
+ const raw = typeof getCurrentSelection === 'function' ? getCurrentSelection() : undefined;
55
+ if (!raw || typeof raw.provider !== 'string' || typeof raw.model !== 'string') return null;
56
+ return {
57
+ provider: raw.provider,
58
+ model: raw.model,
59
+ ...(typeof raw.reasoningEffort === 'string' ? { reasoningEffort: raw.reasoningEffort } : {}),
60
+ };
61
+ } catch {
62
+ return null;
63
+ }
64
+ }
65
+
66
+ function healthHint(code, level, { provider, model, signal } = {}) {
67
+ return {
68
+ code,
69
+ level,
70
+ ...(typeof provider === 'string' && provider ? { provider } : {}),
71
+ ...(typeof model === 'string' && model ? { model } : {}),
72
+ ...(typeof signal === 'string' && signal ? { signal } : {}),
73
+ };
74
+ }
75
+
76
+ /**
77
+ * Analyze only the effective, already-sanitized Harness catalog.
78
+ *
79
+ * This intentionally does not know an "expected" third-party catalog. A
80
+ * narrow advertised list is therefore informational only: it can point a user
81
+ * toward upstream/provider configuration, but it is never proof of a bad
82
+ * override and never changes routing eligibility.
83
+ */
84
+ export function analyzeCatalogHealth({ providers = [], harnessDefault = null } = {}) {
85
+ const safeProviders = Array.isArray(providers) ? providers : [];
86
+ const hints = [];
87
+
88
+ if (safeProviders.length === 0) {
89
+ hints.push(healthHint(CATALOG_HEALTH_CODES.EMPTY_CATALOG, 'warning'));
90
+ }
91
+
92
+ for (const provider of safeProviders) {
93
+ const providerId = typeof provider?.id === 'string' ? provider.id : null;
94
+ const models = Array.isArray(provider?.models) ? provider.models : [];
95
+ if (provider?.error === 'MODEL_LIST_FAILED') {
96
+ hints.push(healthHint(CATALOG_HEALTH_CODES.PROVIDER_MODEL_LIST_FAILED, 'warning', { provider: providerId }));
97
+ continue;
98
+ }
99
+ if (models.length === 0) {
100
+ // Some providers intentionally accept exact model ids without advertising
101
+ // them. Keep this informational rather than turning it into a failure.
102
+ hints.push(healthHint(CATALOG_HEALTH_CODES.EMPTY_PROVIDER_MODELS, 'info', { provider: providerId }));
103
+ }
104
+ }
105
+
106
+ if (harnessDefault && typeof harnessDefault.provider === 'string' && typeof harnessDefault.model === 'string') {
107
+ const defaultProvider = safeProviders.find((provider) => provider?.id === harnessDefault.provider);
108
+ if (!defaultProvider) {
109
+ hints.push(healthHint(CATALOG_HEALTH_CODES.HARNESS_DEFAULT_PROVIDER_MISSING, 'warning', {
110
+ provider: harnessDefault.provider,
111
+ model: harnessDefault.model,
112
+ }));
113
+ } else if (defaultProvider.error !== 'MODEL_LIST_FAILED' && Array.isArray(defaultProvider.models) && defaultProvider.models.length > 0) {
114
+ const advertised = defaultProvider.models.some((model) => model?.id === harnessDefault.model);
115
+ if (!advertised) {
116
+ hints.push(healthHint(CATALOG_HEALTH_CODES.HARNESS_DEFAULT_MODEL_UNADVERTISED, 'info', {
117
+ provider: harnessDefault.provider,
118
+ model: harnessDefault.model,
119
+ }));
120
+ }
121
+ }
122
+ }
123
+
124
+ // A single provider advertising only one or two explicit models is a useful
125
+ // signal because local/provider overrides can produce this shape. It is only
126
+ // an INFO heuristic: legitimate providers can also have intentionally small
127
+ // catalogs, so Crew must not claim an override or route around it.
128
+ const healthyProviders = safeProviders.filter((provider) => provider?.error !== 'MODEL_LIST_FAILED');
129
+ const totalAdvertised = healthyProviders.reduce(
130
+ (sum, provider) => sum + (Array.isArray(provider?.models) ? provider.models.length : 0),
131
+ 0,
132
+ );
133
+ if (healthyProviders.length === 1 && totalAdvertised > 0 && totalAdvertised <= 2) {
134
+ hints.push(healthHint(CATALOG_HEALTH_CODES.CATALOG_CONSTRAINED, 'info', {
135
+ provider: healthyProviders[0].id,
136
+ signal: 'single-provider-small-explicit-catalog',
137
+ }));
138
+ }
139
+
140
+ const warningCount = hints.filter((hint) => hint.level === 'warning').length;
141
+ const infoCount = hints.filter((hint) => hint.level === 'info').length;
142
+ return {
143
+ schema_version: 1,
144
+ warning_count: warningCount,
145
+ info_count: infoCount,
146
+ attention: warningCount > 0,
147
+ hints,
148
+ };
149
+ }
150
+
151
+ export async function readHarnessModelCatalog({ llm, getCurrentSelection, now = () => new Date().toISOString() } = {}) {
152
+ if (!llm || typeof llm.listProviders !== 'function' || typeof llm.listModels !== 'function') throw catalogError();
153
+ let rawProviders;
154
+ try {
155
+ rawProviders = llm.listProviders();
156
+ } catch {
157
+ throw catalogError();
158
+ }
159
+ if (!Array.isArray(rawProviders)) throw catalogError();
160
+ const providers = rawProviders.map(normalizeProvider).filter(Boolean);
161
+ let failed = 0;
162
+ const hydrated = await Promise.all(providers.map(async (provider) => {
163
+ try {
164
+ return { ...provider, models: normalizeModels(await llm.listModels(provider.id), provider.id) };
165
+ } catch {
166
+ failed += 1;
167
+ return { ...provider, models: [], error: 'MODEL_LIST_FAILED' };
168
+ }
169
+ }));
170
+ const harnessDefault = safeDefault(getCurrentSelection);
171
+ return {
172
+ providers: hydrated,
173
+ provider_count: hydrated.length,
174
+ model_count: hydrated.reduce((sum, provider) => sum + provider.models.length, 0),
175
+ harness_default: harnessDefault,
176
+ refreshed_at: now(),
177
+ partial: failed > 0,
178
+ health: analyzeCatalogHealth({ providers: hydrated, harnessDefault }),
179
+ };
180
+ }