@ran-sh/dsh-crew 0.3.0 → 0.3.2

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 (78) hide show
  1. package/.claude-plugin/marketplace.json +17 -17
  2. package/.claude-plugin/plugin.json +8 -8
  3. package/.mcp.json +8 -8
  4. package/LICENSE +21 -21
  5. package/README.de.md +359 -359
  6. package/README.es.md +359 -359
  7. package/README.fr.md +359 -359
  8. package/README.hi.md +359 -359
  9. package/README.id.md +359 -359
  10. package/README.ja.md +359 -359
  11. package/README.ko.md +359 -359
  12. package/README.md +140 -360
  13. package/README.pt.md +359 -359
  14. package/README.ru.md +359 -359
  15. package/README.th.md +359 -359
  16. package/README.tr.md +359 -359
  17. package/README.vi.md +359 -359
  18. package/README.zh-TW.md +359 -359
  19. package/README.zh.md +140 -305
  20. package/agents/ds-flash.md +26 -26
  21. package/agents/ds-pro.md +32 -32
  22. package/agents/ds-reviewer.md +23 -23
  23. package/agents/ds-worker.md +22 -22
  24. package/codex/agents/ds-flash.toml +30 -30
  25. package/codex/agents/ds-pro.toml +31 -31
  26. package/codex/agents/ds-reviewer.toml +28 -28
  27. package/codex/agents/ds-worker.toml +28 -28
  28. package/codex/prompts/dsh-config.md +3 -3
  29. package/codex/prompts/dsh-status.md +1 -1
  30. package/commands/config.md +11 -11
  31. package/commands/off.md +5 -5
  32. package/commands/on.md +5 -5
  33. package/commands/status.md +5 -5
  34. package/cordis.patch.yml +4 -4
  35. package/lib/client.js +2765 -2765
  36. package/package.json +127 -125
  37. package/scripts/build-client.mjs +28 -28
  38. package/scripts/live-crew-smoke.mjs +39 -39
  39. package/scripts/live-policy-matrix.mjs +177 -177
  40. package/scripts/policy-probe.mjs +101 -101
  41. package/scripts/setup.mjs +295 -294
  42. package/scripts/smoke-real.mjs +110 -110
  43. package/scripts/smoke.mjs +78 -78
  44. package/scripts/verify-installer-fix.mjs +26 -26
  45. package/scripts/verify-npm-install.mjs +297 -0
  46. package/src/adaptive-routing.mjs +260 -260
  47. package/src/client/activation-summary.tsx +64 -64
  48. package/src/client/entry.tsx +236 -236
  49. package/src/client/index.tsx +1120 -1120
  50. package/src/config-readiness.mjs +59 -59
  51. package/src/delivery.mjs +205 -205
  52. package/src/dsh-cli-runtime.mjs +435 -251
  53. package/src/failure-classification.mjs +172 -172
  54. package/src/hub/entry.mjs +98 -98
  55. package/src/hub-client.mjs +132 -132
  56. package/src/hub-compatibility.mjs +49 -49
  57. package/src/i18n.mjs +19 -19
  58. package/src/install/cli.mjs +28 -28
  59. package/src/install/install-legacy.mjs +460 -460
  60. package/src/install/install.mjs +451 -451
  61. package/src/mcp-runtime.mjs +257 -257
  62. package/src/model-catalog.mjs +173 -173
  63. package/src/model-routing.mjs +391 -391
  64. package/src/policy.mjs +197 -197
  65. package/src/readiness-matrix.mjs +169 -169
  66. package/src/runtime-controls.mjs +90 -90
  67. package/src/runtime-identity.mjs +108 -108
  68. package/src/server.mjs +477 -477
  69. package/src/status-shard.mjs +52 -52
  70. package/src/structured-error-code.mjs +38 -38
  71. package/src/vision-route.mjs +138 -138
  72. package/src/workflow-runtime.mjs +573 -567
  73. package/src/workflow.mjs +160 -160
  74. package/src/workspace-audit.mjs +231 -231
  75. package/src/workspace-isolation.mjs +365 -306
  76. package/statusline/statusline.sh +14 -14
  77. package/statusline/worker-segment.sh +35 -35
  78. package/worker.cordis.yml +77 -77
@@ -0,0 +1,297 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Regression gate for the published-package peer contract.
4
+ // This intentionally uses npm's default resolver for the candidate install:
5
+ // no peer-resolution bypass or equivalent override is permitted here.
6
+ //
7
+ // The official DSH check is deliberately bounded. It audits authoritative
8
+ // public registry manifests and cross-cohort ranges instead of materializing
9
+ // or fully resolving the very large official DSH dependency graph.
10
+
11
+ import { mkdtemp, readFile, rm } from 'node:fs/promises';
12
+ import os from 'node:os';
13
+ import path from 'node:path';
14
+ import { spawnSync } from 'node:child_process';
15
+ import { fileURLToPath } from 'node:url';
16
+
17
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
18
+ const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
19
+ const registry = process.env.NPM_REGISTRY ?? 'https://registry.npmjs.org/';
20
+ export const supportedDshVersion = '0.1.1-rc.2';
21
+ const verifyOfficialDsh = process.argv.includes('--with-official-dsh');
22
+ const DSH_PACKAGE = '@deepseek-ai/dsh';
23
+ const DSH_PREFIX = '@deepseek-ai/dsh-';
24
+ const MAX_DIRECT_PEERS = 64;
25
+
26
+ /**
27
+ * The candidate version is derived from the candidate package manifest at the
28
+ * checkout root instead of a hard-coded release literal, so the verifier never
29
+ * needs a source edit for the next candidate version. The audit guard still
30
+ * requires the passed-in manifest to match this authoritative value.
31
+ */
32
+ export async function readCandidateVersion({ rootDir = root, readFileImpl = readFile } = {}) {
33
+ const packageJson = await readFileImpl(path.join(rootDir, 'package.json'), 'utf8');
34
+ return JSON.parse(packageJson).version;
35
+ }
36
+
37
+ function isDshPackage(name) {
38
+ return name === DSH_PACKAGE || name.startsWith(DSH_PREFIX);
39
+ }
40
+
41
+ function parseVersion(value) {
42
+ const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(value);
43
+ if (!match) return null;
44
+ return {
45
+ major: Number(match[1]),
46
+ minor: Number(match[2]),
47
+ patch: Number(match[3]),
48
+ prerelease: match[4] ? match[4].split('.') : [],
49
+ };
50
+ }
51
+
52
+ function compareVersions(left, right) {
53
+ for (const key of ['major', 'minor', 'patch']) {
54
+ if (left[key] !== right[key]) return left[key] > right[key] ? 1 : -1;
55
+ }
56
+ if (left.prerelease.length === 0 && right.prerelease.length === 0) return 0;
57
+ if (left.prerelease.length === 0) return 1;
58
+ if (right.prerelease.length === 0) return -1;
59
+ const length = Math.max(left.prerelease.length, right.prerelease.length);
60
+ for (let index = 0; index < length; index += 1) {
61
+ const a = left.prerelease[index];
62
+ const b = right.prerelease[index];
63
+ if (a === undefined) return -1;
64
+ if (b === undefined) return 1;
65
+ if (a === b) continue;
66
+ const aNumber = /^\d+$/.test(a);
67
+ const bNumber = /^\d+$/.test(b);
68
+ if (aNumber && bNumber) return Number(a) > Number(b) ? 1 : -1;
69
+ if (aNumber !== bNumber) return aNumber ? -1 : 1;
70
+ return a > b ? 1 : -1;
71
+ }
72
+ return 0;
73
+ }
74
+
75
+ function upperBoundForCaret(version) {
76
+ if (version.major > 0) return { major: version.major + 1, minor: 0, patch: 0, prerelease: [] };
77
+ if (version.minor > 0) return { major: 0, minor: version.minor + 1, patch: 0, prerelease: [] };
78
+ return { major: 0, minor: 0, patch: version.patch + 1, prerelease: [] };
79
+ }
80
+
81
+ function upperBoundForTilde(version) {
82
+ return { major: version.major, minor: version.minor + 1, patch: 0, prerelease: [] };
83
+ }
84
+
85
+ function satisfiesComparator(version, operator, expected) {
86
+ const comparison = compareVersions(version, expected);
87
+ if (operator === '>') return comparison > 0;
88
+ if (operator === '>=') return comparison >= 0;
89
+ if (operator === '<') return comparison < 0;
90
+ if (operator === '<=') return comparison <= 0;
91
+ return comparison === 0;
92
+ }
93
+
94
+ function satisfiesAlternative(version, alternative) {
95
+ const normalized = alternative.trim();
96
+ if (!normalized || /[*xX]|workspace:|^npm:|^file:|^git:/.test(normalized)) return false;
97
+ const tokens = normalized.replace(/,/g, ' ').split(/\s+/).filter(Boolean);
98
+ return tokens.every((token) => {
99
+ const prefix = /^(\^|~|>=|<=|>|<|=)/.exec(token)?.[1] ?? '';
100
+ const raw = prefix ? token.slice(prefix.length) : token;
101
+ const expected = parseVersion(raw);
102
+ if (!expected) return false;
103
+ if (prefix === '^') {
104
+ return compareVersions(version, expected) >= 0 && compareVersions(version, upperBoundForCaret(expected)) < 0;
105
+ }
106
+ if (prefix === '~') {
107
+ return compareVersions(version, expected) >= 0 && compareVersions(version, upperBoundForTilde(expected)) < 0;
108
+ }
109
+ return satisfiesComparator(version, prefix, expected);
110
+ });
111
+ }
112
+
113
+ export function satisfiesCohortRange(versionString, range) {
114
+ const version = parseVersion(versionString);
115
+ if (!version || typeof range !== 'string') return false;
116
+ return range.split(/\s*\|\|\s*/).some((alternative) => satisfiesAlternative(version, alternative));
117
+ }
118
+
119
+ function assertManifest(manifest, expectedName, expectedVersion) {
120
+ if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) {
121
+ throw new Error(`invalid registry manifest for ${expectedName}@${expectedVersion}`);
122
+ }
123
+ if (manifest.name !== expectedName || manifest.version !== expectedVersion) {
124
+ throw new Error(`registry manifest identity mismatch for ${expectedName}@${expectedVersion}`);
125
+ }
126
+ return manifest;
127
+ }
128
+
129
+ function manifestUrl(registryUrl, name, version) {
130
+ const encodedName = name.startsWith('@') ? name.replace('/', '%2f') : encodeURIComponent(name);
131
+ return `${registryUrl.replace(/\/+$/, '')}/${encodedName}/${encodeURIComponent(version)}`;
132
+ }
133
+
134
+ export async function fetchPublicManifest(name, version, {
135
+ registryUrl = registry,
136
+ fetchImpl = globalThis.fetch,
137
+ } = {}) {
138
+ if (typeof fetchImpl !== 'function') throw new Error('global fetch is unavailable');
139
+ const response = await fetchImpl(manifestUrl(registryUrl, name, version), {
140
+ headers: { accept: 'application/json', 'user-agent': 'dsh-crew-cohort-audit' },
141
+ });
142
+ if (!response?.ok) throw new Error(`public manifest unavailable for ${name}@${version} (HTTP ${response?.status ?? 'unknown'})`);
143
+ let manifest;
144
+ try {
145
+ manifest = await response.json();
146
+ } catch {
147
+ throw new Error(`public manifest was not valid JSON for ${name}@${version}`);
148
+ }
149
+ return assertManifest(manifest, name, version);
150
+ }
151
+
152
+ function dshReferences(manifest) {
153
+ return [
154
+ ...Object.entries(manifest.dependencies ?? {}),
155
+ ...Object.entries(manifest.optionalDependencies ?? {}),
156
+ ...Object.entries(manifest.peerDependencies ?? {}),
157
+ ].filter(([name]) => isDshPackage(name));
158
+ }
159
+
160
+ function assertCrossCohortRanges(manifest, label) {
161
+ const references = dshReferences(manifest);
162
+ for (const [name, range] of references) {
163
+ if (!satisfiesCohortRange(supportedDshVersion, range)) {
164
+ throw new Error(`${label} has incompatible ${name} range ${JSON.stringify(range)} for ${supportedDshVersion}`);
165
+ }
166
+ }
167
+ return references.length;
168
+ }
169
+
170
+ export async function auditOfficialDshCohort({
171
+ candidateManifest,
172
+ expectedCandidateVersion,
173
+ registryUrl = registry,
174
+ fetchManifest = (name, version) => fetchPublicManifest(name, version, { registryUrl }),
175
+ } = {}) {
176
+ if (!candidateManifest || typeof candidateManifest !== 'object') throw new Error('candidate package manifest is missing');
177
+ if (typeof expectedCandidateVersion !== 'string' || expectedCandidateVersion.length === 0) {
178
+ throw new Error('expectedCandidateVersion is required (derive it with readCandidateVersion)');
179
+ }
180
+ if (candidateManifest.version !== expectedCandidateVersion) {
181
+ throw new Error(`package.json must be ${expectedCandidateVersion}`);
182
+ }
183
+
184
+ const directPeers = Object.entries(candidateManifest.peerDependencies ?? {})
185
+ .filter(([name]) => isDshPackage(name));
186
+ if (directPeers.length === 0 || directPeers.length > MAX_DIRECT_PEERS) {
187
+ throw new Error(`candidate DSH peer count is outside the bounded audit limit: ${directPeers.length}`);
188
+ }
189
+ for (const [name, range] of directPeers) {
190
+ if (range !== supportedDshVersion) {
191
+ throw new Error(`candidate peer ${name} must pin exact cohort ${supportedDshVersion}, got ${JSON.stringify(range)}`);
192
+ }
193
+ }
194
+
195
+ const officialManifest = assertManifest(
196
+ await fetchManifest(DSH_PACKAGE, supportedDshVersion),
197
+ DSH_PACKAGE,
198
+ supportedDshVersion,
199
+ );
200
+ const manifests = [officialManifest];
201
+ let crossCohortChecks = assertCrossCohortRanges(officialManifest, `${DSH_PACKAGE}@${supportedDshVersion}`);
202
+
203
+ for (const [name] of directPeers) {
204
+ const manifest = assertManifest(await fetchManifest(name, supportedDshVersion), name, supportedDshVersion);
205
+ manifests.push(manifest);
206
+ crossCohortChecks += assertCrossCohortRanges(manifest, `${name}@${supportedDshVersion}`);
207
+ }
208
+
209
+ return {
210
+ marker: 'PASS',
211
+ candidate: expectedCandidateVersion,
212
+ officialDsh: supportedDshVersion,
213
+ directPeerCount: directPeers.length,
214
+ manifestCount: manifests.length,
215
+ crossCohortChecks,
216
+ };
217
+ }
218
+
219
+ function run(args, cwd = root) {
220
+ const result = spawnSync(npmCommand, args, {
221
+ cwd,
222
+ encoding: 'utf8',
223
+ shell: process.platform === 'win32',
224
+ windowsHide: true,
225
+ });
226
+ if (result.error) throw result.error;
227
+ return {
228
+ status: result.status ?? 1,
229
+ stdout: result.stdout ?? '',
230
+ stderr: result.stderr ?? '',
231
+ };
232
+ }
233
+
234
+ function fail(label, result) {
235
+ const detail = `${result.stdout}\n${result.stderr}`.trim().replace(/\s+/g, ' ').slice(0, 800);
236
+ throw new Error(`${label} failed (exit ${result.status}): ${detail}`);
237
+ }
238
+
239
+ export async function assertInstalled(prefix, label, expectedVersion) {
240
+ const packageRoot = path.join(prefix, 'node_modules', '@ran-sh', 'dsh-crew');
241
+ const packageJson = JSON.parse(await readFile(path.join(packageRoot, 'package.json'), 'utf8'));
242
+ const runtimeSource = await readFile(path.join(packageRoot, 'src', 'runtime-identity.mjs'), 'utf8');
243
+ const runtimeVersion = runtimeSource.match(/RUNTIME_VERSION\s*=\s*'([^']+)'/)?.[1];
244
+ const entryExists = await readFile(path.join(packageRoot, 'src', 'hub', 'entry.mjs')).then(() => true, () => false);
245
+ const clientExists = await readFile(path.join(packageRoot, 'lib', 'client.js')).then(() => true, () => false);
246
+ if (packageJson.version !== expectedVersion || runtimeVersion !== expectedVersion || !entryExists || !clientExists) {
247
+ throw new Error(`${label} did not install the expected ${expectedVersion} package/runtime entries`);
248
+ }
249
+ }
250
+
251
+ async function main() {
252
+ const tempRoot = await mkdtemp(path.join(os.tmpdir(), 'dsh-crew-install-verify-'));
253
+ const paths = {
254
+ pack: await mkdtemp(path.join(tempRoot, 'pack-')),
255
+ standalone: await mkdtemp(path.join(tempRoot, 'standalone-')),
256
+ };
257
+
258
+ try {
259
+ const packageJson = JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8'));
260
+ const candidateVersion = await readCandidateVersion();
261
+ if (packageJson.version !== candidateVersion) throw new Error(`package.json must be ${candidateVersion}`);
262
+
263
+ const packed = run(['pack', '--json', '--pack-destination', paths.pack]);
264
+ if (packed.status !== 0) fail('npm pack', packed);
265
+ const packInfo = JSON.parse(packed.stdout)[0];
266
+ const tarball = path.join(paths.pack, packInfo.filename);
267
+
268
+ const standalone = run([
269
+ 'install', '--prefix', paths.standalone, '--no-save', '--package-lock=false', '--ignore-scripts', '--no-audit', '--no-fund',
270
+ '--registry', registry, tarball,
271
+ ]);
272
+ if (standalone.status !== 0) fail('plain npm candidate install', standalone);
273
+ await assertInstalled(paths.standalone, 'standalone candidate', candidateVersion);
274
+
275
+ let officialMarker = 'not-run';
276
+ if (verifyOfficialDsh) {
277
+ const audit = await auditOfficialDshCohort({
278
+ candidateManifest: packageJson,
279
+ expectedCandidateVersion: candidateVersion,
280
+ registryUrl: registry,
281
+ });
282
+ officialMarker = `${supportedDshVersion}:manifest-audit`;
283
+ console.log(`DSH_COHORT_AUDIT=PASS official_dsh=${audit.officialDsh} direct_peers=${audit.directPeerCount} manifests=${audit.manifestCount} cross_cohort_checks=${audit.crossCohortChecks}`);
284
+ }
285
+
286
+ console.log(`NPM_INSTALL_CONTRACT=PASS candidate=${candidateVersion} official_dsh=${officialMarker}`);
287
+ } finally {
288
+ await rm(tempRoot, { recursive: true, force: true });
289
+ }
290
+ }
291
+
292
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
293
+ main().catch((error) => {
294
+ console.error(error instanceof Error ? error.message : String(error));
295
+ process.exitCode = 1;
296
+ });
297
+ }