@ran-sh/dsh-crew 1.1.0 → 1.2.0-rc.4
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 -17
- package/.claude-plugin/plugin.json +7 -1
- package/README.md +44 -15
- package/README.zh.md +37 -12
- package/agents/ds-flash.md +16 -18
- package/agents/ds-pro.md +16 -24
- package/agents/ds-reviewer.md +15 -15
- package/agents/ds-worker.md +16 -16
- package/bin/dsh-crew.mjs +16 -12
- package/codex/AGENTS.md +37 -85
- package/codex/agents/ds-flash.toml +18 -14
- package/codex/agents/ds-pro.toml +18 -15
- package/codex/agents/ds-reviewer.toml +17 -13
- package/codex/agents/ds-worker.toml +17 -13
- package/codex/prompts/dsh-config.md +17 -1
- package/codex/prompts/dsh-status.md +5 -1
- package/commands/config.md +16 -4
- package/commands/status.md +6 -2
- package/docs/installation.md +54 -9
- package/docs/readiness-matrix.md +14 -6
- package/docs/ui-surfaces.md +32 -17
- package/lib/client.js +5434 -4844
- package/official-web-bridge/lib/client.js +567 -479
- package/official-web-bridge/overlay-entry.mjs +59 -0
- package/package.json +6 -3
- package/scripts/build-client.mjs +2 -0
- package/scripts/setup.mjs +8 -7
- package/scripts/verify-crew-ui-polish.mjs +145 -0
- package/scripts/verify-history-ui.mjs +97 -0
- package/scripts/verify-npm-install.mjs +1 -1
- package/src/client/history-panel.tsx +108 -0
- package/src/client/host-readiness.mjs +15 -6
- package/src/client/index.tsx +86 -64
- package/src/client/model-callability-view.mjs +17 -0
- package/src/client/panel-chrome.tsx +40 -0
- package/src/client/quick-panel.tsx +88 -73
- package/src/client/readiness-envelope.mjs +34 -0
- package/src/config-readiness.mjs +181 -115
- package/src/extension-contract.mjs +44 -26
- package/src/history/admission-gate.mjs +51 -0
- package/src/history/archive-store.mjs +261 -0
- package/src/history/cleanup-plan.mjs +64 -0
- package/src/history/http.mjs +32 -0
- package/src/history/operation.mjs +86 -0
- package/src/history/runner.mjs +51 -0
- package/src/history/runtime.mjs +28 -0
- package/src/history/service.mjs +137 -0
- package/src/history/state.mjs +27 -0
- package/src/hub/index.mjs +141 -24
- package/src/hub-client.mjs +17 -15
- package/src/image-output.mjs +71 -0
- package/src/install/install-legacy.mjs +126 -23
- package/src/install/npx-lifecycle.mjs +373 -64
- package/src/install/official-frontend-assets.mjs +78 -0
- package/src/install/payload-content.mjs +88 -0
- package/src/install/windows-startup.mjs +107 -19
- package/src/install/windows-supervisor-adapter.mjs +443 -0
- package/src/install/windows-supervisor-lifecycle.mjs +782 -0
- package/src/install/zcode.mjs +53 -14
- package/src/job-contracts.mjs +37 -31
- package/src/jobs.mjs +2 -2
- package/src/mcp-runtime.mjs +74 -9
- package/src/model-callability-contract.mjs +79 -0
- package/src/multimodal.mjs +0 -0
- package/src/official-web-bridge.mjs +0 -2
- package/src/provider-health.mjs +130 -124
- package/src/provider-profile-store.mjs +12 -0
- package/src/provider-settings-store.mjs +347 -5
- package/src/readiness-matrix.mjs +20 -15
- package/src/runtime-identity-contract.mjs +34 -0
- package/src/runtime-identity.mjs +14 -4
- package/src/runtime-readiness-snapshot.mjs +285 -87
- package/src/server.mjs +86 -76
- package/src/standalone-sdk.mjs +23 -0
- package/src/supervisor/restart-request.mjs +64 -10
- package/src/workflow-runtime.mjs +28 -13
- package/windows/start-dsh-crew.cmd +57 -57
- package/windows/start-dsh-crew.ps1 +327 -55
- package/windows/supervisor-control.ps1 +467 -0
- package/zcode/AGENTS.md +4 -1
- package/zcode/agents/ds-reviewer.md +31 -36
- package/zcode/agents/ds-worker.md +31 -39
- package/zcode/commands/dsh-config.md +17 -6
- package/zcode/commands/dsh-status.md +5 -4
- package/.mcp.json +0 -8
|
@@ -11,14 +11,28 @@ const PROVIDER_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/u;
|
|
|
11
11
|
function sha256(value) { return createHash('sha256').update(value, 'utf8').digest('hex'); }
|
|
12
12
|
function indentOf(line) { return (line.match(/^\s*/u) ?? [''])[0].length; }
|
|
13
13
|
function nonBlank(line) { return line.trim() !== '' && !line.trimStart().startsWith('#'); }
|
|
14
|
+
function nextContentLine(lines, start, end = lines.length) {
|
|
15
|
+
for (let index = start; index < end; index += 1) if (nonBlank(lines[index])) return index;
|
|
16
|
+
return -1;
|
|
17
|
+
}
|
|
18
|
+
function unquoteScalar(value) {
|
|
19
|
+
const input = typeof value === 'string' ? value.trim() : '';
|
|
20
|
+
if (!input) return null;
|
|
21
|
+
if (input.startsWith('"') && input.endsWith('"')) {
|
|
22
|
+
try { return JSON.parse(input); } catch { return null; }
|
|
23
|
+
}
|
|
24
|
+
if (input.startsWith("'") && input.endsWith("'")) return input.slice(1, -1).replace(/''/gu, "'");
|
|
25
|
+
return input;
|
|
26
|
+
}
|
|
14
27
|
function scalarField(lines, entry, field) {
|
|
15
|
-
const
|
|
28
|
+
const indent = Number.isInteger(entry?.fieldIndent) ? entry.fieldIndent : null;
|
|
29
|
+
const pattern = new RegExp(`^${indent === null ? '\\s+' : ` {${indent}}`}${field}:\\s*(.*?)\\s*$`);
|
|
16
30
|
for (const line of lines.slice(entry.start, entry.end)) {
|
|
17
31
|
const match = line.match(pattern);
|
|
18
32
|
if (!match) continue;
|
|
19
|
-
const value = match[1].trim();
|
|
33
|
+
const value = (entry?.style === 'flow' ? match[1].replace(/,\s*$/u, '') : match[1]).trim();
|
|
20
34
|
if (!value) return null;
|
|
21
|
-
return value
|
|
35
|
+
return unquoteScalar(value);
|
|
22
36
|
}
|
|
23
37
|
return null;
|
|
24
38
|
}
|
|
@@ -51,6 +65,39 @@ function parseProviderMap(source) {
|
|
|
51
65
|
}
|
|
52
66
|
const providersLine = lines.findIndex((line, index) => index > llmStart && index < blockEnd && /^ {2}providers:\s*(?:\{\s*\})?\s*$/u.test(line));
|
|
53
67
|
if (providersLine < 0) return { ok: false, code: 'PROVIDER_SETTINGS_SCHEMA_UNSUPPORTED' };
|
|
68
|
+
const flowOpenLine = nextContentLine(lines, providersLine + 1, blockEnd);
|
|
69
|
+
if (flowOpenLine >= 0 && /^ {4}\{\s*$/u.test(lines[flowOpenLine])) {
|
|
70
|
+
let flowCloseLine = -1;
|
|
71
|
+
const entries = [];
|
|
72
|
+
let index = flowOpenLine + 1;
|
|
73
|
+
while (index < blockEnd) {
|
|
74
|
+
index = nextContentLine(lines, index, blockEnd);
|
|
75
|
+
if (index < 0) break;
|
|
76
|
+
if (/^ {4}\}\s*$/u.test(lines[index])) { flowCloseLine = index; break; }
|
|
77
|
+
const match = lines[index].match(/^ {6}([A-Za-z0-9][A-Za-z0-9._-]*):\s*$/u);
|
|
78
|
+
if (!match) return { ok: false, code: 'PROVIDER_SETTINGS_SCHEMA_UNSUPPORTED' };
|
|
79
|
+
const objectOpen = nextContentLine(lines, index + 1, blockEnd);
|
|
80
|
+
if (objectOpen < 0 || !/^ {8}\{\s*$/u.test(lines[objectOpen])) return { ok: false, code: 'PROVIDER_SETTINGS_SCHEMA_UNSUPPORTED' };
|
|
81
|
+
let objectClose = -1;
|
|
82
|
+
for (let cursor = objectOpen + 1; cursor < blockEnd; cursor += 1) {
|
|
83
|
+
if (/^ {8}\},?\s*$/u.test(lines[cursor])) { objectClose = cursor; break; }
|
|
84
|
+
}
|
|
85
|
+
if (objectClose < 0) return { ok: false, code: 'PROVIDER_SETTINGS_SCHEMA_UNSUPPORTED' };
|
|
86
|
+
entries.push({ id: match[1], start: index, end: objectClose + 1, style: 'flow', fieldIndent: 10, objectOpen, objectClose });
|
|
87
|
+
index = objectClose + 1;
|
|
88
|
+
}
|
|
89
|
+
if (flowCloseLine < 0) return { ok: false, code: 'PROVIDER_SETTINGS_SCHEMA_UNSUPPORTED' };
|
|
90
|
+
for (let entryIndex = 0; entryIndex < entries.length - 1; entryIndex += 1) {
|
|
91
|
+
if (!/^ {8}\},\s*$/u.test(lines[entries[entryIndex].objectClose])) return { ok: false, code: 'PROVIDER_SETTINGS_SCHEMA_UNSUPPORTED' };
|
|
92
|
+
}
|
|
93
|
+
if (entries.some((entry) => !validFlowEntryStructure(lines, entry))) {
|
|
94
|
+
return { ok: false, code: 'PROVIDER_SETTINGS_SCHEMA_UNSUPPORTED' };
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
ok: true, style: 'flow', lines, llmStart, blockEnd, providersLine,
|
|
98
|
+
providersBlockEnd: flowCloseLine + 1, flowOpenLine, flowCloseLine, entries,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
54
101
|
let providersBlockEnd = blockEnd;
|
|
55
102
|
for (let index = providersLine + 1; index < blockEnd; index += 1) {
|
|
56
103
|
if (nonBlank(lines[index]) && indentOf(lines[index]) <= 2) { providersBlockEnd = index; break; }
|
|
@@ -74,10 +121,235 @@ function parseProviderMap(source) {
|
|
|
74
121
|
if (nonBlank(next) && indentOf(next) <= providerIndent) break;
|
|
75
122
|
end += 1;
|
|
76
123
|
}
|
|
77
|
-
entries.push({ id: match[1], start: index, end });
|
|
124
|
+
entries.push({ id: match[1], start: index, end, style: 'block', fieldIndent: 6 });
|
|
78
125
|
index = end - 1;
|
|
79
126
|
}
|
|
80
|
-
return { ok: true, lines, llmStart, blockEnd, providersLine, providersBlockEnd, entries };
|
|
127
|
+
return { ok: true, style: 'block', lines, llmStart, blockEnd, providersLine, providersBlockEnd, entries };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function splitFlowItems(source) {
|
|
131
|
+
const items = [];
|
|
132
|
+
let start = 0;
|
|
133
|
+
let braces = 0;
|
|
134
|
+
let brackets = 0;
|
|
135
|
+
let quote = null;
|
|
136
|
+
let escaped = false;
|
|
137
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
138
|
+
const char = source[index];
|
|
139
|
+
if (quote) {
|
|
140
|
+
if (quote === '"' && escaped) { escaped = false; continue; }
|
|
141
|
+
if (quote === '"' && char === '\\') { escaped = true; continue; }
|
|
142
|
+
if (char === quote) quote = null;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (char === '"' || char === "'") { quote = char; continue; }
|
|
146
|
+
if (char === '{') braces += 1;
|
|
147
|
+
else if (char === '}') braces -= 1;
|
|
148
|
+
else if (char === '[') brackets += 1;
|
|
149
|
+
else if (char === ']') brackets -= 1;
|
|
150
|
+
else if (char === ',' && braces === 0 && brackets === 0) {
|
|
151
|
+
items.push(source.slice(start, index).trim());
|
|
152
|
+
start = index + 1;
|
|
153
|
+
}
|
|
154
|
+
if (braces < 0 || brackets < 0) return null;
|
|
155
|
+
}
|
|
156
|
+
if (quote || braces !== 0 || brackets !== 0) return null;
|
|
157
|
+
const tail = source.slice(start).trim();
|
|
158
|
+
if (tail) items.push(tail);
|
|
159
|
+
return items;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function parseFlowObject(source, depth = 0) {
|
|
163
|
+
if (depth > 8) return null;
|
|
164
|
+
const input = source.trim().replace(/,\s*$/u, '');
|
|
165
|
+
if (!input.startsWith('{') || !input.endsWith('}')) return null;
|
|
166
|
+
const items = splitFlowItems(input.slice(1, -1));
|
|
167
|
+
if (!items) return null;
|
|
168
|
+
const fields = new Map();
|
|
169
|
+
for (const item of items) {
|
|
170
|
+
let splitAt = -1;
|
|
171
|
+
let quote = null;
|
|
172
|
+
let escaped = false;
|
|
173
|
+
for (let index = 0; index < item.length; index += 1) {
|
|
174
|
+
const char = item[index];
|
|
175
|
+
if (quote) {
|
|
176
|
+
if (quote === '"' && escaped) { escaped = false; continue; }
|
|
177
|
+
if (quote === '"' && char === '\\') { escaped = true; continue; }
|
|
178
|
+
if (char === quote) quote = null;
|
|
179
|
+
} else if (char === '"' || char === "'") quote = char;
|
|
180
|
+
else if (char === ':') { splitAt = index; break; }
|
|
181
|
+
}
|
|
182
|
+
if (splitAt < 1 || hasUnseparatedFlowMapping(item, splitAt)) return null;
|
|
183
|
+
const key = item.slice(0, splitAt).trim();
|
|
184
|
+
const value = item.slice(splitAt + 1).trim();
|
|
185
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]*$/u.test(key) || !value || fields.has(key)) return null;
|
|
186
|
+
if (value.startsWith('{') && (!value.endsWith('}') || parseFlowObject(value, depth + 1) === null)) return null;
|
|
187
|
+
fields.set(key, value);
|
|
188
|
+
}
|
|
189
|
+
return fields;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function hasUnseparatedFlowMapping(item, firstColon) {
|
|
193
|
+
let braces = 0;
|
|
194
|
+
let brackets = 0;
|
|
195
|
+
let quote = null;
|
|
196
|
+
let escaped = false;
|
|
197
|
+
for (let index = firstColon + 1; index < item.length; index += 1) {
|
|
198
|
+
const char = item[index];
|
|
199
|
+
if (quote) {
|
|
200
|
+
if (quote === '"' && escaped) { escaped = false; continue; }
|
|
201
|
+
if (quote === '"' && char === '\\') { escaped = true; continue; }
|
|
202
|
+
if (char === quote) quote = null;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (char === '"' || char === "'") { quote = char; continue; }
|
|
206
|
+
if (char === '{') braces += 1;
|
|
207
|
+
else if (char === '}') braces -= 1;
|
|
208
|
+
else if (char === '[') brackets += 1;
|
|
209
|
+
else if (char === ']') brackets -= 1;
|
|
210
|
+
else if (char === ':' && braces === 0 && brackets === 0 && /\s/u.test(item[index + 1] ?? '')) return true;
|
|
211
|
+
if (braces < 0 || brackets < 0) return true;
|
|
212
|
+
}
|
|
213
|
+
return quote !== null || braces !== 0 || brackets !== 0;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function validFlowEntryStructure(lines, entry) {
|
|
217
|
+
const fields = [];
|
|
218
|
+
let cursor = entry.objectOpen + 1;
|
|
219
|
+
while (cursor < entry.objectClose) {
|
|
220
|
+
cursor = nextContentLine(lines, cursor, entry.objectClose);
|
|
221
|
+
if (cursor < 0) break;
|
|
222
|
+
const line = lines[cursor];
|
|
223
|
+
if (indentOf(line) !== entry.fieldIndent) return false;
|
|
224
|
+
const field = line.match(/^\s+([A-Za-z][A-Za-z0-9_-]*):\s*(.*?)\s*$/u);
|
|
225
|
+
if (!field) return false;
|
|
226
|
+
let terminator = cursor;
|
|
227
|
+
if (!field[2]) {
|
|
228
|
+
const listOpen = nextContentLine(lines, cursor + 1, entry.objectClose);
|
|
229
|
+
if (listOpen < 0 || indentOf(lines[listOpen]) !== entry.fieldIndent + 2 || !/^\s*\[\s*$/u.test(lines[listOpen])) return false;
|
|
230
|
+
const items = [];
|
|
231
|
+
let listClose = -1;
|
|
232
|
+
for (let nested = listOpen + 1; nested < entry.objectClose; nested += 1) {
|
|
233
|
+
if (!nonBlank(lines[nested])) continue;
|
|
234
|
+
if (indentOf(lines[nested]) === entry.fieldIndent + 2 && /^\s*\]\s*,?\s*$/u.test(lines[nested])) {
|
|
235
|
+
listClose = nested;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
if (indentOf(lines[nested]) !== entry.fieldIndent + 4 || !parseFlowObject(lines[nested])) return false;
|
|
239
|
+
items.push(nested);
|
|
240
|
+
}
|
|
241
|
+
if (listClose < 0) return false;
|
|
242
|
+
for (let index = 0; index < items.length - 1; index += 1) if (!/,\s*$/u.test(lines[items[index]])) return false;
|
|
243
|
+
terminator = listClose;
|
|
244
|
+
cursor = listClose + 1;
|
|
245
|
+
} else {
|
|
246
|
+
cursor += 1;
|
|
247
|
+
}
|
|
248
|
+
fields.push({ terminator });
|
|
249
|
+
}
|
|
250
|
+
for (let index = 0; index < fields.length - 1; index += 1) {
|
|
251
|
+
if (!/,\s*$/u.test(lines[fields[index].terminator])) return false;
|
|
252
|
+
}
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function parseFlowModel(source) {
|
|
257
|
+
const fields = parseFlowObject(source);
|
|
258
|
+
if (!fields) return null;
|
|
259
|
+
const allowed = new Set(['id', 'name', 'contextWindow', 'maxTokens', 'input', 'reasoningEfforts', 'compat']);
|
|
260
|
+
if ([...fields.keys()].some((key) => !allowed.has(key))) return null;
|
|
261
|
+
const id = unquoteScalar(fields.get('id'));
|
|
262
|
+
if (!id || id.length > 256 || /[\r\n]/u.test(id)) return null;
|
|
263
|
+
const model = { id };
|
|
264
|
+
if (fields.has('name')) {
|
|
265
|
+
const name = unquoteScalar(fields.get('name'));
|
|
266
|
+
if (!name || name.length > 256 || /[\r\n]/u.test(name)) return null;
|
|
267
|
+
model.name = name;
|
|
268
|
+
}
|
|
269
|
+
for (const [sourceKey, targetKey] of [['contextWindow', 'context_window'], ['maxTokens', 'max_tokens']]) {
|
|
270
|
+
if (!fields.has(sourceKey)) continue;
|
|
271
|
+
const value = Number(unquoteScalar(fields.get(sourceKey)));
|
|
272
|
+
if (!Number.isSafeInteger(value) || value <= 0) return null;
|
|
273
|
+
model[targetKey] = value;
|
|
274
|
+
}
|
|
275
|
+
if (fields.has('input')) {
|
|
276
|
+
const input = fields.get('input').trim();
|
|
277
|
+
if (!input.startsWith('[') || !input.endsWith(']')) return null;
|
|
278
|
+
const modalities = splitFlowItems(input.slice(1, -1));
|
|
279
|
+
if (!modalities) return null;
|
|
280
|
+
const normalized = modalities.map(unquoteScalar);
|
|
281
|
+
if (normalized.some((value) => !['text', 'image'].includes(value))) return null;
|
|
282
|
+
model.input = [...new Set(normalized)];
|
|
283
|
+
}
|
|
284
|
+
if (fields.has('reasoningEfforts')) {
|
|
285
|
+
const efforts = parseFlowObject(fields.get('reasoningEfforts'));
|
|
286
|
+
if (!efforts) return null;
|
|
287
|
+
const normalized = {};
|
|
288
|
+
for (const [key, raw] of efforts) {
|
|
289
|
+
const value = unquoteScalar(raw);
|
|
290
|
+
if (raw === 'null' || raw === '~') normalized[key] = null;
|
|
291
|
+
else if (!value || value.length > 256 || /[\r\n]/u.test(value)) return null;
|
|
292
|
+
else normalized[key] = value;
|
|
293
|
+
}
|
|
294
|
+
model.reasoning_efforts = normalized;
|
|
295
|
+
}
|
|
296
|
+
if (fields.has('compat')) {
|
|
297
|
+
if (fields.get('compat').trim() !== '{}') return null;
|
|
298
|
+
model.compat = {};
|
|
299
|
+
}
|
|
300
|
+
return model;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function readFlowMaterialization(parsed, entry, file) {
|
|
304
|
+
const directFields = new Set();
|
|
305
|
+
for (const line of parsed.lines.slice(entry.objectOpen + 1, entry.objectClose)) {
|
|
306
|
+
if (!nonBlank(line) || indentOf(line) !== entry.fieldIndent) continue;
|
|
307
|
+
const match = line.match(/^\s+([A-Za-z][A-Za-z0-9_-]*):/u);
|
|
308
|
+
if (!match || directFields.has(match[1])) return { ok: false, code: 'PROVIDER_MATERIALIZATION_UNSUPPORTED_FIELDS' };
|
|
309
|
+
directFields.add(match[1]);
|
|
310
|
+
}
|
|
311
|
+
const allowed = new Set(['displayName', 'apiKeyEnv', 'api', 'baseURL', 'models']);
|
|
312
|
+
if ([...directFields].some((field) => !allowed.has(field))) return { ok: false, code: 'PROVIDER_MATERIALIZATION_UNSUPPORTED_FIELDS' };
|
|
313
|
+
const rawDisplayName = scalarField(parsed.lines, entry, 'displayName');
|
|
314
|
+
const displayName = rawDisplayName && rawDisplayName.length <= 256 && !/[\r\n]/u.test(rawDisplayName) ? rawDisplayName : entry.id;
|
|
315
|
+
const rawCredentialRef = scalarField(parsed.lines, entry, 'apiKeyEnv');
|
|
316
|
+
const credential = classifyCredentialReference(rawCredentialRef, { kind: 'env' });
|
|
317
|
+
if (credential.redacted) return { ok: false, code: 'PROVIDER_CREDENTIAL_REFERENCE_UNSAFE' };
|
|
318
|
+
const api = scalarField(parsed.lines, entry, 'api');
|
|
319
|
+
if (api && (!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/u.test(api) || /^(?:sk|pk|rk|token|secret)[_-]/iu.test(api))) return { ok: false, code: 'PROVIDER_API_SCHEMA_UNSUPPORTED' };
|
|
320
|
+
const rawBaseUrl = scalarField(parsed.lines, entry, 'baseURL');
|
|
321
|
+
const baseUrl = rawBaseUrl && rawBaseUrl.length <= 2048 && !/[\r\n]/u.test(rawBaseUrl) ? rawBaseUrl : null;
|
|
322
|
+
if (baseUrl) {
|
|
323
|
+
try {
|
|
324
|
+
const url = new URL(baseUrl);
|
|
325
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search || url.hash || !url.hostname) return { ok: false, code: 'PROVIDER_BASE_URL_UNSAFE' };
|
|
326
|
+
} catch { return { ok: false, code: 'PROVIDER_BASE_URL_UNSAFE' }; }
|
|
327
|
+
}
|
|
328
|
+
const models = [];
|
|
329
|
+
if (directFields.has('models')) {
|
|
330
|
+
const modelsLine = parsed.lines.findIndex((line, index) => index > entry.objectOpen && index < entry.objectClose && /^ {10}models:\s*$/u.test(line));
|
|
331
|
+
const listOpen = nextContentLine(parsed.lines, modelsLine + 1, entry.objectClose);
|
|
332
|
+
if (modelsLine < 0 || listOpen < 0 || !/^ {12}\[\s*$/u.test(parsed.lines[listOpen])) return { ok: false, code: 'PROVIDER_MODEL_SCHEMA_UNSUPPORTED' };
|
|
333
|
+
let listClose = -1;
|
|
334
|
+
for (let index = listOpen + 1; index < entry.objectClose; index += 1) {
|
|
335
|
+
if (/^ {12}\]\s*,?\s*$/u.test(parsed.lines[index])) { listClose = index; break; }
|
|
336
|
+
if (!nonBlank(parsed.lines[index])) continue;
|
|
337
|
+
if (indentOf(parsed.lines[index]) !== 14) return { ok: false, code: 'PROVIDER_MODEL_SCHEMA_UNSUPPORTED' };
|
|
338
|
+
const model = parseFlowModel(parsed.lines[index]);
|
|
339
|
+
if (!model || models.some((candidate) => candidate.id === model.id)) return { ok: false, code: 'PROVIDER_MODEL_SCHEMA_UNSUPPORTED' };
|
|
340
|
+
models.push(model);
|
|
341
|
+
}
|
|
342
|
+
if (listClose < 0) return { ok: false, code: 'PROVIDER_MODEL_SCHEMA_UNSUPPORTED' };
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
ok: true,
|
|
346
|
+
provider: {
|
|
347
|
+
id: entry.id, display_name: displayName,
|
|
348
|
+
...(credential.value ? { credential_ref: credential.value } : {}),
|
|
349
|
+
...(api ? { api } : {}), ...(baseUrl ? { base_url: baseUrl } : {}),
|
|
350
|
+
models: models.slice(0, 256), source_file: file,
|
|
351
|
+
},
|
|
352
|
+
};
|
|
81
353
|
}
|
|
82
354
|
|
|
83
355
|
const SENSITIVE_CREDENTIAL_FIELD = /(?:api[_-]?key|access[_-]?token|refresh[_-]?token|(?:^|[_-])token(?:$|[_-])|secret|password|authorization|credential|private[_-]?key|client[_-]?secret|cookie|bearer|webhook)/iu;
|
|
@@ -142,6 +414,7 @@ export function readProviderSettingsMaterialization(source, { providerId, file =
|
|
|
142
414
|
if (!parsed.ok) return { ok: false, code: parsed.code };
|
|
143
415
|
const entry = parsed.entries.find((candidate) => candidate.id === providerId);
|
|
144
416
|
if (!entry) return { ok: false, code: 'PROVIDER_NOT_FOUND' };
|
|
417
|
+
if (parsed.style === 'flow') return readFlowMaterialization(parsed, entry, file);
|
|
145
418
|
const block = parsed.lines.slice(entry.start, entry.end).map((line) => ` ${line}`);
|
|
146
419
|
const synthetic = ['- id: llm-pi-ai', ' config:', ' providers:', ...block, ''].join('\n');
|
|
147
420
|
const result = readProviderMaterialization(synthetic, { providerId, file });
|
|
@@ -159,6 +432,47 @@ function yamlScalar(value, max = 2048) {
|
|
|
159
432
|
return JSON.stringify(value.trim());
|
|
160
433
|
}
|
|
161
434
|
|
|
435
|
+
function flowModelLine(model) {
|
|
436
|
+
const fields = [`id: ${yamlScalar(model.id, 256)}`];
|
|
437
|
+
const name = yamlScalar(model.name, 256);
|
|
438
|
+
if (name) fields.push(`name: ${name}`);
|
|
439
|
+
if (Number.isSafeInteger(model.context_window) && model.context_window > 0) fields.push(`contextWindow: ${model.context_window}`);
|
|
440
|
+
if (Number.isSafeInteger(model.max_tokens) && model.max_tokens > 0) fields.push(`maxTokens: ${model.max_tokens}`);
|
|
441
|
+
if (Array.isArray(model.input) && model.input.every((value) => value === 'text' || value === 'image')) fields.push(`input: [${[...new Set(model.input)].join(', ')}]`);
|
|
442
|
+
if (model.reasoning_efforts && typeof model.reasoning_efforts === 'object' && !Array.isArray(model.reasoning_efforts)) {
|
|
443
|
+
const efforts = [];
|
|
444
|
+
for (const [key, value] of Object.entries(model.reasoning_efforts)) {
|
|
445
|
+
if (/^[A-Za-z][A-Za-z0-9_-]*$/u.test(key) && (value === null || yamlScalar(value, 256))) efforts.push(`${key}: ${value === null ? 'null' : yamlScalar(value, 256)}`);
|
|
446
|
+
}
|
|
447
|
+
if (efforts.length > 0) fields.push(`reasoningEfforts: { ${efforts.join(', ')} }`);
|
|
448
|
+
}
|
|
449
|
+
if (model.compat && typeof model.compat === 'object' && !Array.isArray(model.compat) && Object.keys(model.compat).length === 0) fields.push('compat: {}');
|
|
450
|
+
return `{ ${fields.join(', ')} }`;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function flowProviderLines(provider) {
|
|
454
|
+
const displayName = yamlScalar(provider.display_name ?? provider.id, 256);
|
|
455
|
+
if (!displayName) return null;
|
|
456
|
+
const credential = provider.credential_ref ? classifyCredentialReference(provider.credential_ref, { kind: 'env' }).value : null;
|
|
457
|
+
if (provider.credential_ref && !credential) return null;
|
|
458
|
+
const api = yamlScalar(provider.api, 128);
|
|
459
|
+
const baseUrl = yamlScalar(provider.base_url, 2048);
|
|
460
|
+
const models = Array.isArray(provider.models)
|
|
461
|
+
? provider.models.filter((model) => model && typeof model.id === 'string' && yamlScalar(model.id, 256)).slice(0, 256)
|
|
462
|
+
: [];
|
|
463
|
+
const fields = [` displayName: ${displayName}`];
|
|
464
|
+
if (api) fields.push(` api: ${api}`);
|
|
465
|
+
if (baseUrl) fields.push(` baseURL: ${baseUrl}`);
|
|
466
|
+
if (credential) fields.push(` apiKeyEnv: ${yamlScalar(credential, 256)}`);
|
|
467
|
+
if (models.length === 0) {
|
|
468
|
+
return [` ${provider.id}:`, ' {', ...fields.map((line, index) => `${line}${index < fields.length - 1 ? ',' : ''}`), ' }'];
|
|
469
|
+
}
|
|
470
|
+
const lines = [` ${provider.id}:`, ' {', ...fields.map((line) => `${line},`), ' models:', ' ['];
|
|
471
|
+
for (let index = 0; index < models.length; index += 1) lines.push(` ${flowModelLine(models[index])}${index < models.length - 1 ? ',' : ''}`);
|
|
472
|
+
lines.push(' ]', ' }');
|
|
473
|
+
return lines;
|
|
474
|
+
}
|
|
475
|
+
|
|
162
476
|
/**
|
|
163
477
|
* Add one already-sanitized provider projection to the Harness user layer.
|
|
164
478
|
* The operation is pure and revision-bound; callers perform the atomic write.
|
|
@@ -172,6 +486,17 @@ export function addProviderSettings(source, { provider, expectedRevision } = {})
|
|
|
172
486
|
const parsed = parseProviderMap(source);
|
|
173
487
|
if (!parsed.ok) return { ok: false, code: parsed.code, revision: currentRevision };
|
|
174
488
|
if (parsed.entries.some((entry) => entry.id === provider.id)) return { ok: false, code: 'PROVIDER_SETTINGS_PROVIDER_EXISTS', revision: currentRevision };
|
|
489
|
+
if (parsed.style === 'flow') {
|
|
490
|
+
const providerLines = flowProviderLines(provider);
|
|
491
|
+
if (!providerLines) return { ok: false, code: 'PROVIDER_MATERIALIZATION_INVALID', revision: currentRevision };
|
|
492
|
+
const nextLines = [...parsed.lines];
|
|
493
|
+
const previous = parsed.entries.at(-1);
|
|
494
|
+
if (previous && !/,\s*$/u.test(nextLines[previous.objectClose])) nextLines[previous.objectClose] = `${nextLines[previous.objectClose]},`;
|
|
495
|
+
nextLines.splice(parsed.flowCloseLine, 0, ...providerLines);
|
|
496
|
+
const newline = source.includes('\r\n') ? '\r\n' : '\n';
|
|
497
|
+
const text = nextLines.join(newline);
|
|
498
|
+
return { ok: true, text, added: provider.id, revision: sha256(text) };
|
|
499
|
+
}
|
|
175
500
|
const displayName = yamlScalar(provider.display_name ?? provider.id, 256);
|
|
176
501
|
if (!displayName) return { ok: false, code: 'PROVIDER_MATERIALIZATION_INVALID', revision: currentRevision };
|
|
177
502
|
const lines = [` ${provider.id}:`, ` displayName: ${displayName}`];
|
|
@@ -256,6 +581,23 @@ export function mutateProviderSettings(source, {
|
|
|
256
581
|
}
|
|
257
582
|
const ranges = providerEntry ? [[providerEntry.start, providerEntry.end]] : [];
|
|
258
583
|
const finalProvider = providerEntry && parsed.entries.length === 1;
|
|
584
|
+
if (removeProvider && parsed.style === 'flow' && finalProvider) {
|
|
585
|
+
const lines = [...parsed.lines];
|
|
586
|
+
lines.splice(parsed.providersLine, parsed.flowCloseLine - parsed.providersLine + 1, ' providers: {}');
|
|
587
|
+
if (defaultParsed) {
|
|
588
|
+
const removedBeforeProvider = parsed.providersLine <= defaultParsed.providerLine ? parsed.flowCloseLine - parsed.providersLine : 0;
|
|
589
|
+
const removedBeforeModel = parsed.providersLine <= defaultParsed.modelLine ? parsed.flowCloseLine - parsed.providersLine : 0;
|
|
590
|
+
lines[defaultParsed.providerLine - removedBeforeProvider] = ` provider: ${replacementDefault.trim()}`;
|
|
591
|
+
lines[defaultParsed.modelLine - removedBeforeModel] = ` model: ${replacementModel.trim()}`;
|
|
592
|
+
}
|
|
593
|
+
const newline = source.includes('\r\n') ? '\r\n' : '\n';
|
|
594
|
+
const text = lines.join(newline);
|
|
595
|
+
return {
|
|
596
|
+
ok: true, text, removed: [providerId], remaining: [],
|
|
597
|
+
...(defaultParsed ? { previous_default: { provider: defaultParsed.provider, model: defaultParsed.model } } : {}),
|
|
598
|
+
revision: sha256(text),
|
|
599
|
+
};
|
|
600
|
+
}
|
|
259
601
|
const nextLines = parsed.lines.map((line, index) => {
|
|
260
602
|
if (ranges.some(([start, end]) => index >= start && index < end)) return null;
|
|
261
603
|
if (finalProvider && index === parsed.providersLine) return ' providers: {}';
|
package/src/readiness-matrix.mjs
CHANGED
|
@@ -13,11 +13,11 @@ export const READINESS_REASON_CODES = Object.freeze({
|
|
|
13
13
|
HUB_INCOMPATIBLE: 'HUB_INCOMPATIBLE',
|
|
14
14
|
PROVIDER_CATALOG_RESOLVED: 'PROVIDER_CATALOG_RESOLVED',
|
|
15
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_LIFECYCLE_CONSISTENT: 'PROVIDER_LIFECYCLE_CONSISTENT',
|
|
19
|
-
PROVIDER_LIFECYCLE_INCONSISTENT: 'PROVIDER_LIFECYCLE_INCONSISTENT',
|
|
20
|
-
PROVIDER_INVENTORY_UNAVAILABLE: 'PROVIDER_INVENTORY_UNAVAILABLE',
|
|
16
|
+
PROVIDER_CATALOG_HEALTH_WARNING: 'PROVIDER_CATALOG_HEALTH_WARNING',
|
|
17
|
+
PROVIDER_CATALOG_NOT_REQUIRED: 'PROVIDER_CATALOG_NOT_REQUIRED',
|
|
18
|
+
PROVIDER_LIFECYCLE_CONSISTENT: 'PROVIDER_LIFECYCLE_CONSISTENT',
|
|
19
|
+
PROVIDER_LIFECYCLE_INCONSISTENT: 'PROVIDER_LIFECYCLE_INCONSISTENT',
|
|
20
|
+
PROVIDER_INVENTORY_UNAVAILABLE: 'PROVIDER_INVENTORY_UNAVAILABLE',
|
|
21
21
|
PROVIDER_MODE_UNKNOWN: 'PROVIDER_MODE_UNKNOWN',
|
|
22
22
|
NO_CI_EVIDENCE: 'NO_CI_EVIDENCE',
|
|
23
23
|
NO_EXECUTION_EVIDENCE: 'NO_EXECUTION_EVIDENCE',
|
|
@@ -29,16 +29,18 @@ const TARGET_ROWS = Object.freeze([
|
|
|
29
29
|
['linux_deterministic', 'ci'],
|
|
30
30
|
['windows_regressions', 'ci'],
|
|
31
31
|
['macos_smoke', 'ci'],
|
|
32
|
-
['hub_compatibility', 'live-runtime'],
|
|
33
|
-
['provider_catalog', 'live-runtime'],
|
|
34
|
-
['
|
|
35
|
-
['
|
|
36
|
-
['
|
|
37
|
-
['
|
|
38
|
-
['
|
|
39
|
-
['
|
|
40
|
-
['
|
|
41
|
-
['
|
|
32
|
+
['hub_compatibility', 'live-runtime'],
|
|
33
|
+
['provider_catalog', 'live-runtime'],
|
|
34
|
+
['provider_health', 'live-runtime'],
|
|
35
|
+
['reviewer_health', 'live-runtime'],
|
|
36
|
+
['model_execution', 'real-execution'],
|
|
37
|
+
['worker_primary_callable', 'real-execution'],
|
|
38
|
+
['worker_escalation_callable', 'real-execution'],
|
|
39
|
+
['reviewer_primary_callable', 'real-execution'],
|
|
40
|
+
['provider_lifecycle_consistent', 'live-runtime'],
|
|
41
|
+
['deepseek_flash', 'real-execution'],
|
|
42
|
+
['deepseek_pro', 'real-execution'],
|
|
43
|
+
['reviewer_pipeline', 'real-execution'],
|
|
42
44
|
['cancellation_timeout_escalation', 'real-execution'],
|
|
43
45
|
['standalone_official', 'real-execution'],
|
|
44
46
|
]);
|
|
@@ -71,6 +73,9 @@ function normalizeEvidence(row, evidence) {
|
|
|
71
73
|
...(typeof evidence.evidence_ref === 'string' && evidence.evidence_ref.trim()
|
|
72
74
|
? { evidence_ref: evidence.evidence_ref.trim() }
|
|
73
75
|
: {}),
|
|
76
|
+
...(typeof evidence.detail_code === 'string' && /^[A-Z][A-Z0-9_]{0,127}$/u.test(evidence.detail_code)
|
|
77
|
+
? { detail_code: evidence.detail_code }
|
|
78
|
+
: {}),
|
|
74
79
|
};
|
|
75
80
|
}
|
|
76
81
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Browser-safe runtime identity primitives shared by the Hub, extension
|
|
2
|
+
// contract and client. Do not coerce missing values: an incomplete identity
|
|
3
|
+
// is never evidence of the native 3210 Crew runtime.
|
|
4
|
+
|
|
5
|
+
export const PRODUCTION_EXECUTION_PLANE = 'hub-3210';
|
|
6
|
+
export const PRODUCTION_PROFILE = 'dsh-crew';
|
|
7
|
+
export const PRODUCTION_LISTEN_PORT = 3210;
|
|
8
|
+
|
|
9
|
+
function nonEmpty(value) {
|
|
10
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isCompleteRuntimeIdentity(identity) {
|
|
14
|
+
return Boolean(identity && typeof identity === 'object'
|
|
15
|
+
&& nonEmpty(identity.execution_plane)
|
|
16
|
+
&& nonEmpty(identity.profile)
|
|
17
|
+
&& Number.isInteger(identity.listen_port) && identity.listen_port > 0
|
|
18
|
+
&& nonEmpty(identity.runtime_id));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function sameCompleteRuntimeIdentity(left, right) {
|
|
22
|
+
return isCompleteRuntimeIdentity(left) && isCompleteRuntimeIdentity(right)
|
|
23
|
+
&& left.execution_plane === right.execution_plane
|
|
24
|
+
&& left.profile === right.profile
|
|
25
|
+
&& left.listen_port === right.listen_port
|
|
26
|
+
&& left.runtime_id === right.runtime_id;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function isExactNativeCrewIdentity(identity) {
|
|
30
|
+
return isCompleteRuntimeIdentity(identity)
|
|
31
|
+
&& identity.execution_plane === PRODUCTION_EXECUTION_PLANE
|
|
32
|
+
&& identity.profile === PRODUCTION_PROFILE
|
|
33
|
+
&& identity.listen_port === PRODUCTION_LISTEN_PORT;
|
|
34
|
+
}
|
package/src/runtime-identity.mjs
CHANGED
|
@@ -17,16 +17,26 @@ import { randomUUID } from 'node:crypto';
|
|
|
17
17
|
import { existsSync, readFileSync } from 'node:fs';
|
|
18
18
|
import { homedir } from 'node:os';
|
|
19
19
|
import { join } from 'node:path';
|
|
20
|
+
import {
|
|
21
|
+
PRODUCTION_EXECUTION_PLANE,
|
|
22
|
+
PRODUCTION_PROFILE,
|
|
23
|
+
PRODUCTION_LISTEN_PORT,
|
|
24
|
+
} from './runtime-identity-contract.mjs';
|
|
25
|
+
export {
|
|
26
|
+
PRODUCTION_EXECUTION_PLANE,
|
|
27
|
+
PRODUCTION_PROFILE,
|
|
28
|
+
PRODUCTION_LISTEN_PORT,
|
|
29
|
+
isCompleteRuntimeIdentity,
|
|
30
|
+
sameCompleteRuntimeIdentity,
|
|
31
|
+
isExactNativeCrewIdentity,
|
|
32
|
+
} from './runtime-identity-contract.mjs';
|
|
20
33
|
|
|
21
34
|
// Production Crew execution is intentionally bound to the isolated 3210 Hub.
|
|
22
35
|
// These fields are public provenance only; no credential or session secret is
|
|
23
36
|
// included in the identity contract.
|
|
24
|
-
export const PRODUCTION_EXECUTION_PLANE = 'hub-3210';
|
|
25
|
-
export const PRODUCTION_PROFILE = 'dsh-crew';
|
|
26
|
-
export const PRODUCTION_LISTEN_PORT = 3210;
|
|
27
37
|
const RUNTIME_ID = randomUUID();
|
|
28
38
|
|
|
29
|
-
export const RUNTIME_VERSION = '1.
|
|
39
|
+
export const RUNTIME_VERSION = '1.2.0-rc.4';
|
|
30
40
|
export const HUB_PROTOCOL_VERSION = 1;
|
|
31
41
|
|
|
32
42
|
export const HUB_CAPABILITIES = Object.freeze([
|