@zoraxylia/dsh-codex-adapter 0.0.0-stage → 0.1.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 (87) hide show
  1. package/.claude-plugin/marketplace.json +15 -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 +480 -0
  6. package/README.es.md +480 -0
  7. package/README.fr.md +480 -0
  8. package/README.hi.md +480 -0
  9. package/README.id.md +480 -0
  10. package/README.ja.md +478 -0
  11. package/README.ko.md +480 -0
  12. package/README.md +483 -2
  13. package/README.pt.md +480 -0
  14. package/README.ru.md +480 -0
  15. package/README.th.md +480 -0
  16. package/README.tr.md +480 -0
  17. package/README.vi.md +480 -0
  18. package/README.zh-TW.md +478 -0
  19. package/README.zh.md +482 -0
  20. package/agents/ds-flash.md +17 -0
  21. package/agents/ds-pro.md +17 -0
  22. package/agy/agents/ds-flash.md +18 -0
  23. package/agy/agents/ds-pro.md +18 -0
  24. package/agy/skills/dsh-config/SKILL.md +6 -0
  25. package/agy/skills/dsh-playbook/SKILL.md +65 -0
  26. package/agy/skills/dsh-status/SKILL.md +6 -0
  27. package/codex/agents/ds-flash.toml +23 -0
  28. package/codex/agents/ds-pro.toml +23 -0
  29. package/codex/prompts/dsh-config.md +3 -0
  30. package/codex/prompts/dsh-playbook.md +60 -0
  31. package/codex/prompts/dsh-status.md +1 -0
  32. package/commands/config.md +9 -0
  33. package/commands/off.md +5 -0
  34. package/commands/on.md +5 -0
  35. package/commands/playbook.md +64 -0
  36. package/commands/status.md +5 -0
  37. package/cordis.patch.yml +4 -0
  38. package/docs/images/dsh-crew-host.png +0 -0
  39. package/docs/images/dsh-crew-jobs.png +0 -0
  40. package/docs/images/dsh-crew-logo.png +0 -0
  41. package/docs/images/dsh-crew-overview.png +0 -0
  42. package/grok/agents/ds-flash.md +19 -0
  43. package/grok/agents/ds-pro.md +19 -0
  44. package/grok/commands/dsh-config.md +9 -0
  45. package/grok/commands/dsh-playbook.md +66 -0
  46. package/grok/commands/dsh-status.md +5 -0
  47. package/lib/client.js +2684 -0
  48. package/lib/server.mjs +15417 -0
  49. package/package.json +137 -4
  50. package/scripts/build-client.mjs +23 -0
  51. package/scripts/build-mcp.mjs +43 -0
  52. package/scripts/fake-agy.sh +23 -0
  53. package/scripts/release-local.mjs +87 -0
  54. package/scripts/smoke-bundle.mjs +166 -0
  55. package/scripts/smoke-cwd.mjs +41 -0
  56. package/scripts/smoke-pack.mjs +285 -0
  57. package/scripts/smoke.mjs +79 -0
  58. package/scripts/verify-cli-workers.mjs +133 -0
  59. package/scripts/verify-wpc10-client.mjs +237 -0
  60. package/scripts/verify-wpc14-proc-endpoints.mjs +356 -0
  61. package/scripts/verify-wpc9-guardrails.mjs +432 -0
  62. package/src/cli-workers.mjs +396 -0
  63. package/src/client/index.tsx +1133 -0
  64. package/src/client/jobs-view.ts +374 -0
  65. package/src/cwd-lock.mjs +91 -0
  66. package/src/hub/index.mjs +643 -0
  67. package/src/hub-client.mjs +72 -0
  68. package/src/i18n.mjs +19 -0
  69. package/src/install/cli.mjs +34 -0
  70. package/src/install/install.mjs +577 -0
  71. package/src/jobs.mjs +289 -0
  72. package/src/multimodal.mjs +744 -0
  73. package/src/origin-guard.mjs +133 -0
  74. package/src/paths.mjs +43 -0
  75. package/src/plugin-env.mjs +65 -0
  76. package/src/proc-kill.mjs +208 -0
  77. package/src/process-info.mjs +60 -0
  78. package/src/provider-probe.mjs +35 -0
  79. package/src/server.mjs +438 -0
  80. package/src/status-shard.mjs +95 -0
  81. package/src/tier-binding.mjs +63 -0
  82. package/src/vision-route.mjs +139 -0
  83. package/src/worker-profiles.mjs +95 -0
  84. package/src/worker-question.mjs +22 -0
  85. package/statusline/statusline.sh +14 -0
  86. package/statusline/worker-segment.sh +35 -0
  87. package/worker.cordis.yml +77 -0
package/package.json CHANGED
@@ -1,6 +1,139 @@
1
1
  {
2
2
  "name": "@zoraxylia/dsh-codex-adapter",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./src/hub/index.mjs",
6
+ "description": "DeepSeek Harness plugin: dispatch work to DSH agents from Claude Code / Codex, as native subagents with live progress",
7
+ "dsh": {
8
+ "bundle": {
9
+ "patch": "./cordis.patch.yml"
10
+ },
11
+ "client": {
12
+ "inject": [
13
+ "@deepseek-ai/dsh-client-locale",
14
+ "@deepseek-ai/dsh-client-ui-settings"
15
+ ],
16
+ "platform": "web"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "mcp": "node src/server.mjs",
21
+ "build": "npm run build:client && npm run build:mcp",
22
+ "build:client": "tsdown src/client/index.tsx --format cjs --platform browser --target es2022 --tsconfig tsconfig.client.json --deps.never-bundle react --deps.never-bundle react/jsx-runtime --deps.never-bundle react-dom --deps.never-bundle react-dom/client --out-dir .client-build --clean --logLevel warn && node scripts/build-client.mjs",
23
+ "build:mcp": "node scripts/build-mcp.mjs",
24
+ "smoke:cwd": "node scripts/smoke-cwd.mjs",
25
+ "smoke:mcp": "node scripts/smoke-bundle.mjs",
26
+ "smoke:pack": "node scripts/smoke-pack.mjs",
27
+ "release:local": "node scripts/release-local.mjs",
28
+ "prepack": "npm run smoke:cwd && npm run smoke:mcp",
29
+ "prepublishOnly": "npm run smoke:mcp && npm run smoke:pack",
30
+ "test": "node --test tests/*.test.mjs"
31
+ },
32
+ "dependencies": {
33
+ "@modelcontextprotocol/sdk": "^1.17.5",
34
+ "zod": "^3.24.0"
35
+ },
36
+ "exports": {
37
+ ".": "./src/hub/index.mjs",
38
+ "./client": "./lib/client.js",
39
+ "./package.json": "./package.json"
40
+ },
41
+ "peerDependencies": {
42
+ "react": "^18.0.0",
43
+ "react-dom": "^18.0.0"
44
+ },
45
+ "dshHostRuntime": {
46
+ "_comment": "Documentation only - these @deepseek-ai/* packages are provided by the DSH HOST at runtime (worker.cordis.yml composition + host profile), never by this package. They were peerDependencies in <=0.1.0-rc.2, but npm 7+ auto-installs peers (optional ones included when placeable), and the pinned versions ERESOLVE against the host newer transitive tree (issue #3): a plain npm install of @zoraxylia/dsh-codex-adapter failed. Keep these pins in sync with the DSH version this release is tested against (README badge).",
47
+ "@deepseek-ai/dsh-agent": "0.1.0-rc.6",
48
+ "@deepseek-ai/dsh-agent-presets": "0.1.0-rc.6",
49
+ "@deepseek-ai/dsh-agent-spine-demo": "0.1.0-rc.6",
50
+ "@deepseek-ai/dsh-bash-local": "0.1.0-rc.6",
51
+ "@deepseek-ai/dsh-compaction-basic": "0.1.0-rc.6",
52
+ "@deepseek-ai/dsh-fs-local": "0.1.0-rc.6",
53
+ "@deepseek-ai/dsh-fs-observation-policy": "0.1.0-rc.6",
54
+ "@deepseek-ai/dsh-llm": "0.1.0-rc.6",
55
+ "@deepseek-ai/dsh-llm-deepseek": "0.1.0-rc.6",
56
+ "@deepseek-ai/dsh-sandbox-local": "0.1.0-rc.6",
57
+ "@deepseek-ai/dsh-sandbox-policy": "0.1.0-rc.6",
58
+ "@deepseek-ai/dsh-sdk-client": "0.1.0-rc.6",
59
+ "@deepseek-ai/dsh-sdk-jsonrpc-demo": "0.1.0-rc.6",
60
+ "@deepseek-ai/dsh-sdk-jsonrpc-server": "0.1.0-rc.6",
61
+ "@deepseek-ai/dsh-session": "0.1.0-rc.6",
62
+ "@deepseek-ai/dsh-session-persistence-jsonl": "0.1.0-rc.6",
63
+ "@deepseek-ai/dsh-subprocess-local": "0.1.0-rc.6",
64
+ "@deepseek-ai/dsh-token-meter": "0.1.0-rc.6",
65
+ "@deepseek-ai/dsh-tool-fs": "0.1.0-rc.6",
66
+ "@deepseek-ai/dsh-tool-todo": "0.1.0-rc.6"
67
+ },
68
+ "devDependencies": {
69
+ "@deepseek-ai/dsh-agent": "0.1.0-rc.6",
70
+ "@deepseek-ai/dsh-agent-presets": "0.1.0-rc.6",
71
+ "@deepseek-ai/dsh-agent-spine-demo": "0.1.0-rc.6",
72
+ "@deepseek-ai/dsh-bash-local": "0.1.0-rc.6",
73
+ "@deepseek-ai/dsh-compaction-basic": "0.1.0-rc.6",
74
+ "@deepseek-ai/dsh-fs-local": "0.1.0-rc.6",
75
+ "@deepseek-ai/dsh-fs-observation-policy": "0.1.0-rc.6",
76
+ "@deepseek-ai/dsh-llm": "0.1.0-rc.6",
77
+ "@deepseek-ai/dsh-llm-deepseek": "0.1.0-rc.6",
78
+ "@deepseek-ai/dsh-sandbox-local": "0.1.0-rc.6",
79
+ "@deepseek-ai/dsh-sandbox-policy": "0.1.0-rc.6",
80
+ "@deepseek-ai/dsh-sdk-client": "^0.1.0-rc.5",
81
+ "@deepseek-ai/dsh-sdk-jsonrpc-demo": "^0.1.0-rc.5",
82
+ "@deepseek-ai/dsh-sdk-jsonrpc-server": "0.1.0-rc.6",
83
+ "@deepseek-ai/dsh-session": "0.1.0-rc.6",
84
+ "@deepseek-ai/dsh-session-persistence-jsonl": "0.1.0-rc.6",
85
+ "@deepseek-ai/dsh-subprocess-local": "0.1.0-rc.6",
86
+ "@deepseek-ai/dsh-token-meter": "0.1.0-rc.6",
87
+ "@deepseek-ai/dsh-tool-fs": "0.1.0-rc.6",
88
+ "@deepseek-ai/dsh-tool-todo": "0.1.0-rc.6",
89
+ "@types/react": "^18.3.0",
90
+ "esbuild": "^0.28.2",
91
+ "react": "^18.3.1",
92
+ "react-dom": "^18.3.1",
93
+ "tsdown": "^0.12.0",
94
+ "typescript": "^5.6.0"
95
+ },
96
+ "license": "MIT",
97
+ "author": "zx-yk",
98
+ "packageManager": "pnpm@11.21.0",
99
+ "repository": {
100
+ "type": "git",
101
+ "url": "git+https://github.com/zx-yk/dsh-codex-adapter.git"
102
+ },
103
+ "keywords": [
104
+ "dsh",
105
+ "deepseek",
106
+ "claude-code",
107
+ "codex",
108
+ "subagent",
109
+ "worker",
110
+ "multimodal",
111
+ "plugin",
112
+ "agent"
113
+ ],
114
+ "files": [
115
+ "lib",
116
+ "src",
117
+ "scripts",
118
+ "agents",
119
+ "commands",
120
+ "codex",
121
+ "agy",
122
+ "grok",
123
+ "statusline",
124
+ "cordis.patch.yml",
125
+ "worker.cordis.yml",
126
+ ".claude-plugin",
127
+ ".mcp.json",
128
+ "README.md",
129
+ "README.*.md",
130
+ "docs/images/dsh-crew-logo.png",
131
+ "docs/images/dsh-crew-overview.png",
132
+ "docs/images/dsh-crew-host.png",
133
+ "docs/images/dsh-crew-jobs.png",
134
+ "LICENSE"
135
+ ],
136
+ "publishConfig": {
137
+ "access": "public"
138
+ }
139
+ }
@@ -0,0 +1,23 @@
1
+ // Wrap the compiled client bundle into the dsh-web module-loader artifact:
2
+ // `window.__ModuleLoader__.load({ id, factory })`. The id must equal the
3
+ // package name (= the cordis entry name). Pattern from dsh-noema.
4
+
5
+ import { readFile, writeFile, rm, mkdir } from 'node:fs/promises';
6
+ import { dirname, join } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+
9
+ const root = dirname(dirname(fileURLToPath(import.meta.url)));
10
+ const manifest = JSON.parse(await readFile(join(root, 'package.json'), 'utf8'));
11
+ const pluginId = manifest.name;
12
+ const source = await readFile(join(root, '.client-build', 'index.cjs'), 'utf8');
13
+ const wrapped = [
14
+ `window.__ModuleLoader__.load({ id: ${JSON.stringify(pluginId)}, factory: (require) => {`,
15
+ 'var module = { exports: {} }; var exports = module.exports;',
16
+ source.replace(/\n?\/\/# sourceMappingURL=.*$/u, ''),
17
+ 'return module.exports; } });',
18
+ '',
19
+ ].join('\n');
20
+ await mkdir(join(root, 'lib'), { recursive: true });
21
+ await writeFile(join(root, 'lib', 'client.js'), wrapped);
22
+ await rm(join(root, '.client-build'), { recursive: true, force: true });
23
+ console.log(`built lib/client.js (${wrapped.length} bytes) as module "${pluginId}"`);
@@ -0,0 +1,43 @@
1
+ // Builds lib/server.mjs: a self-contained bundle of the MCP stdio server.
2
+ // Only the third-party packages the MCP protocol itself needs - the MCP SDK
3
+ // and zod - are inlined, so the published plugin works from a plain
4
+ // directory copy with no node_modules (Claude Code's directory marketplace
5
+ // copies the repo without installing anything, and a bundled file needs no
6
+ // install step).
7
+ //
8
+ // Every @deepseek-ai/* package stays external. The standalone dispatch path
9
+ // loads @deepseek-ai/dsh-sdk-client lazily (dynamic import inside
10
+ // startJob), and hub mode never touches it. Inlining the DSH stack here
11
+ // would re-couple the MCP server to the SDK version and bloat the bundle
12
+ // (the previous build carried a 580 KB closure for a lazy optional path).
13
+ //
14
+ // Equivalent esbuild CLI (what `npm run build:mcp` asks for):
15
+ // esbuild src/server.mjs --bundle --platform=node --format=esm --packages=bundle --external:@deepseek-ai/* --target=node18 --outfile=lib/server.mjs
16
+ //
17
+ // --target=node18: the MCP SDK requires node >= 18; this keeps the bundle
18
+ // runnable on every node that can run the SDK, instead of pinning the
19
+ // output to the build machine's node version.
20
+
21
+ import { build } from 'esbuild';
22
+ import { mkdirSync } from 'node:fs';
23
+ import { dirname, join } from 'node:path';
24
+ import { fileURLToPath } from 'node:url';
25
+
26
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
27
+ mkdirSync(join(ROOT, 'lib'), { recursive: true });
28
+
29
+ await build({
30
+ entryPoints: [join(ROOT, 'src', 'server.mjs')],
31
+ bundle: true,
32
+ platform: 'node',
33
+ format: 'esm',
34
+ packages: 'bundle',
35
+ // @deepseek-ai/* resolves at runtime only when standalone dispatch is
36
+ // actually used (jobs.mjs startJob); external takes precedence over
37
+ // packages:bundle for these specifiers.
38
+ external: ['@deepseek-ai/*'],
39
+ target: 'node18',
40
+ outfile: join(ROOT, 'lib', 'server.mjs'),
41
+ logLevel: 'info',
42
+ });
43
+
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bash
2
+ # WPC9 test double for the agy CLI: emits the stream-json events the
3
+ # cli-workers adapter parses (init / step_update / result). Behavior is
4
+ # controlled through env: FAKE_AGY_MODE / FAKE_AGY_MODE_FILE (NORMAL|HANG),
5
+ # FAKE_AGY_DELAY_MS / FAKE_AGY_DELAY_FILE (ms before the result event),
6
+ # FAKE_AGY_CAPTURE (if set, the inherited DSH_CREW_ORIGIN_CHAIN / _DEPTH are
7
+ # written next to it so tests can assert env propagation).
8
+ mode="${FAKE_AGY_MODE:-NORMAL}"
9
+ [ -n "${FAKE_AGY_MODE_FILE:-}" ] && mode="$(cat "$FAKE_AGY_MODE_FILE")"
10
+ delay_ms="${FAKE_AGY_DELAY_MS:-150}"
11
+ [ -n "${FAKE_AGY_DELAY_FILE:-}" ] && delay_ms="$(cat "$FAKE_AGY_DELAY_FILE")"
12
+ if [ -n "${FAKE_AGY_CAPTURE:-}" ]; then
13
+ printf '%s' "${DSH_CREW_ORIGIN_CHAIN:-}" > "$FAKE_AGY_CAPTURE"
14
+ printf '%s' "${DSH_CREW_DEPTH:-}" > "$FAKE_AGY_CAPTURE.depth"
15
+ fi
16
+ printf '%s\n' '{"event":"init","init":{"permission_mode":"acceptEdits","tools":[]}}'
17
+ sleep 0.05
18
+ printf '%s\n' '{"event":"step_update","step_update":{"step_index":0,"step_type":"agent_response","text_delta":"working","usage":{"input_tokens":12,"output_tokens":4}}}'
19
+ if [ "$mode" = "HANG" ]; then
20
+ while :; do sleep 5; done
21
+ fi
22
+ sleep "$(awk -v ms="$delay_ms" 'BEGIN{printf "%.3f", ms/1000}')"
23
+ printf '%s\n' '{"event":"result","result":{"status":"SUCCESS","response":"ok"}}'
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+ // Local release: build, verify, optionally publish and tag — no GitHub Actions.
3
+ //
4
+ // Why: a fork pays for every workflow run it starts, and the upstream tag
5
+ // pipeline cannot publish from a fork anyway (OIDC trust is bound to
6
+ // ZSeven-W/dsh-crew). Doing the same gates on the machine costs nothing and
7
+ // takes about two minutes.
8
+ //
9
+ // node scripts/release-local.mjs # build + smoke only
10
+ // node scripts/release-local.mjs --publish # …then npm publish
11
+ // node scripts/release-local.mjs --tag # …then git tag/push v<version>
12
+ // node scripts/release-local.mjs --force # skip the clean-tree check
13
+ //
14
+ // The script never bumps the version: run `npm version <patch|minor|...>`
15
+ // first so the tag, package.json and published artifact agree.
16
+
17
+ import { execFileSync } from 'node:child_process';
18
+ import { existsSync, readFileSync } from 'node:fs';
19
+ import { dirname, join } from 'node:path';
20
+ import { fileURLToPath } from 'node:url';
21
+
22
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
23
+ const flags = new Set(process.argv.slice(2));
24
+ const doPublish = flags.has('--publish');
25
+ const doTag = flags.has('--tag');
26
+ const force = flags.has('--force');
27
+
28
+ const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
29
+ const version = pkg.version;
30
+
31
+ function run(cmd, argv, extra = {}) {
32
+ console.log(`\n$ ${cmd} ${argv.join(' ')}`);
33
+ execFileSync(cmd, argv, { cwd: ROOT, stdio: 'inherit', ...extra });
34
+ }
35
+
36
+ function capture(cmd, argv) {
37
+ try {
38
+ return execFileSync(cmd, argv, { cwd: ROOT, encoding: 'utf8' }).trim();
39
+ } catch {
40
+ return '';
41
+ }
42
+ }
43
+
44
+ // pnpm keeps the lockfile authoritative, but a machine without pnpm can use
45
+ // npm for the same scripts; force one with CREW_PM=pnpm|npm.
46
+ const pm = process.env.CREW_PM || (capture('pnpm', ['--version']) ? 'pnpm' : 'npm');
47
+ console.log(`package manager: ${pm} | ${pkg.name}@${version}`);
48
+
49
+ if (!force) {
50
+ const dirty = capture('git', ['status', '--porcelain']);
51
+ if (dirty) {
52
+ console.error('\nWorking tree is not clean. Commit first, or pass --force:\n' + dirty);
53
+ process.exit(1);
54
+ }
55
+ }
56
+
57
+ if (!existsSync(join(ROOT, 'node_modules'))) {
58
+ run(pm, ['install']);
59
+ }
60
+
61
+ run(pm, ['run', 'build']);
62
+ run(pm, ['run', 'smoke:mcp']);
63
+ run(pm, ['run', 'smoke:pack']);
64
+
65
+ if (doPublish) {
66
+ if (!pkg.name.startsWith('@')) {
67
+ console.warn('\nNote: unscoped package names are first-come on npm.');
68
+ }
69
+ console.log(`\nPublishing ${pkg.name}@${version} (requires npm login).`);
70
+ run('npm', ['publish', '--access', 'public', '--tag', 'latest']);
71
+ }
72
+
73
+ if (doTag) {
74
+ const tag = `v${version}`;
75
+ const existing = capture('git', ['tag', '--list', tag]);
76
+ if (existing) {
77
+ console.log(`\nTag ${tag} already exists locally — skipping creation.`);
78
+ } else {
79
+ run('git', ['tag', '-a', tag, '-m', tag]);
80
+ }
81
+ run('git', ['push', 'origin', tag]);
82
+ console.log(`\nPushed ${tag}. No workflow listens to tags, so this costs no Actions minutes.`);
83
+ }
84
+
85
+ console.log(`\nOK — ${pkg.name}@${version} built and verified.`);
86
+ if (!doPublish) console.log('Package not published (pass --publish to publish).');
87
+ if (!doTag) console.log('Tag not pushed (pass --tag to tag and push).');
@@ -0,0 +1,166 @@
1
+ // Smoke assertion for the bundled MCP server: the published plugin is a
2
+ // plain directory copy with NO node_modules (Claude Code's directory
3
+ // marketplace copies the repo without installing anything). The bundle must
4
+ // therefore start and speak MCP over stdio with zero install-time
5
+ // dependencies. If anyone adds an import that is not inlined by build:mcp,
6
+ // this test fails immediately instead of shipping a plugin whose MCP server
7
+ // dies at startup with a silent ERR_MODULE_NOT_FOUND.
8
+ //
9
+ // pnpm run smoke:mcp
10
+ //
11
+ // Flow: rebuild lib/server.mjs from the current sources, copy the release
12
+ // payload (lib/server.mjs, package.json, .mcp.json) into a brand-new temp
13
+ // directory, start `node lib/server.mjs` there, and run a real MCP stdio
14
+ // handshake: initialize -> notifications/initialized -> tools/list.
15
+
16
+ import { spawn } from 'node:child_process';
17
+ import { mkdtempSync, cpSync, existsSync, readFileSync, rmSync, statSync } from 'node:fs';
18
+ import { tmpdir } from 'node:os';
19
+ import { join, dirname } from 'node:path';
20
+ import { fileURLToPath } from 'node:url';
21
+
22
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
23
+ const EXPECTED_TOOLS = [
24
+ 'dsh_run_worker',
25
+ 'dsh_worker_config',
26
+ 'dsh_worker_probe',
27
+ 'dsh_spawn_worker',
28
+ 'dsh_worker_status',
29
+ 'dsh_worker_result',
30
+ 'dsh_worker_cancel',
31
+ ];
32
+
33
+ function fail(msg) {
34
+ console.error('\nSMOKE FAILED: ' + msg);
35
+ process.exit(1);
36
+ }
37
+
38
+ // 1. Rebuild from current sources: an unresolvable / unbundled import breaks
39
+ // the build here, before anything can be copied.
40
+ console.log('[smoke:mcp] rebuilding lib/server.mjs from current sources ...');
41
+ await import('./build-mcp.mjs');
42
+ const bundlePath = join(ROOT, 'lib', 'server.mjs');
43
+ if (!existsSync(bundlePath)) fail('lib/server.mjs was not produced by build:mcp');
44
+
45
+ // 1b. The DSH SDK must never be inlined again. Standalone dispatch loads
46
+ // @deepseek-ai/dsh-sdk-client lazily, so the bundle may only *reference*
47
+ // the bare specifier - never carry SDK code. Inlined SDK code ships with
48
+ // esbuild source-path banners (node_modules/.pnpm/@deepseek-ai) and pulls
49
+ // in @deepseek-ai/dsh-sdk-protocol; neither may appear in the bundle.
50
+ const bundleText = readFileSync(bundlePath, 'utf8');
51
+ if (bundleText.includes('node_modules/.pnpm/@deepseek-ai')) fail('bundle contains inlined @deepseek-ai/* code (node_modules/.pnpm/@deepseek-ai banner found); build:mcp must keep @deepseek-ai/* external');
52
+ if (bundleText.includes('dsh-sdk-protocol')) fail('bundle contains inlined @deepseek-ai/* code (dsh-sdk-protocol found); build:mcp must keep @deepseek-ai/* external');
53
+ if (!bundleText.includes('@deepseek-ai/dsh-sdk-client')) fail('bundle lost the lazy @deepseek-ai/dsh-sdk-client import specifier');
54
+ if (!bundleText.includes('MAX_POLL_SLICE_SECONDS')) fail('bundle lost the MAX_POLL_SLICE_SECONDS long-poll slicing logic');
55
+ console.log('[smoke:mcp] bundle assertions OK: no inlined @deepseek-ai/* code; lazy dsh-sdk-client specifier and MAX_POLL_SLICE_SECONDS present');
56
+
57
+ // 2. Fresh temp dir - the 'installed plugin copy'. Nothing but the payload.
58
+ const tmp = mkdtempSync(join(tmpdir(), 'dsh-crew-smoke-'));
59
+ let child = null;
60
+ let finished = false;
61
+
62
+ // Windows keeps the child's handles on the copied tree until the process is
63
+ // really gone, so wait for exit before deleting the temp dir.
64
+ async function stopChild() {
65
+ if (!child || child.exitCode !== null) return;
66
+ child.kill();
67
+ await Promise.race([
68
+ new Promise((resolve) => child.once('exit', resolve)),
69
+ new Promise((resolve) => setTimeout(resolve, 3000)),
70
+ ]);
71
+ if (process.platform === 'win32') await new Promise((resolve) => setTimeout(resolve, 300));
72
+ }
73
+ try {
74
+ for (const f of ['lib/server.mjs', 'package.json', '.mcp.json']) {
75
+ cpSync(join(ROOT, f), join(tmp, f), { recursive: true });
76
+ }
77
+ if (existsSync(join(tmp, 'node_modules'))) fail('temp copy unexpectedly has node_modules');
78
+ console.log('[smoke:mcp] clean copy at ' + tmp + ' (no node_modules, ' + statSync(join(tmp, 'lib/server.mjs')).size + ' bytes)');
79
+
80
+ // 3. Start the bundled server with cwd = the clean copy.
81
+ child = spawn(process.execPath, ['lib/server.mjs'], { cwd: tmp, stdio: ['pipe', 'pipe', 'pipe'] });
82
+ let stderr = '';
83
+ child.stderr.on('data', (d) => { stderr += d.toString(); });
84
+ child.on('exit', (code) => {
85
+ if (!finished) fail('server exited early (code ' + code + ') - it could not start from a node_modules-free copy. stderr: ' + stderr.trim());
86
+ });
87
+
88
+ const pending = new Map(); // id -> { resolve, reject, timer }
89
+ const responses = []; // raw response lines, for the report
90
+ let buf = '';
91
+ let nextId = 1;
92
+
93
+ function send(msg) { child.stdin.write(JSON.stringify(msg) + '\n'); }
94
+ function request(method, params) {
95
+ return new Promise((resolve, reject) => {
96
+ const id = nextId++;
97
+ const timer = setTimeout(() => reject(new Error('timed out waiting for ' + method + ' response (stderr: ' + stderr.trim() + ')')), 15000);
98
+ pending.set(id, { resolve, reject, timer });
99
+ send({ jsonrpc: '2.0', id, method, params });
100
+ });
101
+ }
102
+
103
+ function routeLine(line) {
104
+ const raw = line.trim();
105
+ if (!raw) return;
106
+ let msg;
107
+ try { msg = JSON.parse(raw); }
108
+ catch { fail('non-JSON line on stdout (protocol broken): ' + raw.slice(0, 200)); }
109
+ if (msg.id !== undefined && pending.has(msg.id)) {
110
+ const p = pending.get(msg.id);
111
+ pending.delete(msg.id);
112
+ clearTimeout(p.timer);
113
+ if (msg.error) p.reject(new Error(msg.error.code + ': ' + msg.error.message));
114
+ else p.resolve(msg);
115
+ }
116
+ // notifications (no id) are ignored, as an MCP client should.
117
+ }
118
+
119
+ child.stdout.on('data', (d) => {
120
+ buf += d.toString();
121
+ let i;
122
+ while ((i = buf.indexOf('\n')) >= 0) {
123
+ const line = buf.slice(0, i);
124
+ buf = buf.slice(i + 1);
125
+ if (line.trim()) { responses.push(line.trim()); routeLine(line); }
126
+ }
127
+ });
128
+
129
+ const initParams = { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'smoke-bundle', version: '0.0.0' } };
130
+ console.log('--- initialize request ---');
131
+ console.log(JSON.stringify({ jsonrpc: '2.0', method: 'initialize', params: initParams }));
132
+
133
+ const init = await request('initialize', initParams);
134
+ console.log('--- initialize response (raw) ---');
135
+ console.log(responses[responses.length - 1]);
136
+ if (!init.result || !init.result.protocolVersion) fail('initialize result missing protocolVersion');
137
+ if (!init.result.serverInfo || init.result.serverInfo.name !== 'dsh-crew') fail('initialize serverInfo.name is ' + JSON.stringify(init.result && init.result.serverInfo && init.result.serverInfo.name) + ', expected dsh-crew');
138
+ console.log('[smoke:mcp] initialize OK: protocolVersion=' + init.result.protocolVersion + ', serverInfo=' + JSON.stringify(init.result.serverInfo));
139
+
140
+ // Per the MCP spec the client must announce readiness before other calls.
141
+ send({ jsonrpc: '2.0', method: 'notifications/initialized' });
142
+
143
+ const list = await request('tools/list', {});
144
+ console.log('--- tools/list response (raw) ---');
145
+ console.log(responses[responses.length - 1]);
146
+ const names = (list.result && list.result.tools || []).map((t) => t.name).sort();
147
+ const expected = EXPECTED_TOOLS.slice().sort();
148
+ if (JSON.stringify(names) !== JSON.stringify(expected)) {
149
+ fail('tools/list returned ' + JSON.stringify(names) + ', expected ' + JSON.stringify(expected));
150
+ }
151
+ console.log('[smoke:mcp] tools/list OK: all ' + names.length + ' tools present: ' + names.join(', '));
152
+
153
+ finished = true;
154
+ await stopChild();
155
+ // Windows can hold a handle on the copied tree for a moment after the child
156
+ // exits; retrying avoids a spurious EPERM that would fail an otherwise
157
+ // passing smoke test.
158
+ rmSync(tmp, { recursive: true, force: true, maxRetries: 10, retryDelay: 200 });
159
+ console.log('\nSMOKE PASSED: the bundled MCP server starts and serves initialize + tools/list from a node_modules-free copy.');
160
+ } catch (err) {
161
+ finished = true;
162
+ await stopChild();
163
+ rmSync(tmp, { recursive: true, force: true, maxRetries: 10, retryDelay: 200 });
164
+ fail(err && err.message ? err.message : String(err));
165
+ }
166
+
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ // Smoke assertions for the cross-platform cwd helpers (issue #5): the hub
3
+ // must accept Windows drive / UNC paths as absolute, and the MCP layer must
4
+ // map unset / "." / "current" cwd values onto the caller's workspace while
5
+ // relative paths resolve against it. No framework — node:assert only.
6
+ //
7
+ // node scripts/smoke-cwd.mjs
8
+
9
+ import assert from 'node:assert/strict';
10
+ import { resolve } from 'node:path';
11
+ import { canonicalCwd, isAbsoluteCwd, resolveWorkerCwd } from '../src/paths.mjs';
12
+
13
+ // Absolute-path predicate: POSIX, Windows drive (both slash styles) and UNC.
14
+ for (const p of ['/a/b', 'D:\\a\\b', 'C:/a/b', '\\\\srv\\share\\p']) {
15
+ assert.equal(isAbsoluteCwd(p), true, JSON.stringify(p) + ' should be absolute');
16
+ }
17
+ // Relative, empty and non-string values are never absolute.
18
+ for (const p of ['a/b', '', undefined]) {
19
+ assert.equal(isAbsoluteCwd(p), false, JSON.stringify(p) + ' should not be absolute');
20
+ }
21
+
22
+ // MCP-side resolver: unset / "." / "current" mean the caller's workspace,
23
+ // relative paths resolve against it, absolute paths normalize as-is.
24
+ const base = resolve('project');
25
+ assert.equal(resolveWorkerCwd(undefined, base), base);
26
+ assert.equal(resolveWorkerCwd('.', base), base);
27
+ assert.equal(resolveWorkerCwd('current', base), base);
28
+ assert.equal(resolveWorkerCwd('', base), base);
29
+ assert.equal(resolveWorkerCwd('sub/dir', base), resolve(base, 'sub/dir'));
30
+ assert.equal(resolveWorkerCwd('/abs', base), resolve('/abs'));
31
+
32
+ // Canonical form never re-roots a foreign-platform absolute path under
33
+ // process.cwd(): a Windows path on a POSIX hub is only normalized.
34
+ if (process.platform !== 'win32') {
35
+ assert.equal(canonicalCwd('D:/AI/../floorplan'), 'D:\\floorplan');
36
+ assert.equal(canonicalCwd('\\\\srv\\share\\p\\.'), '\\\\srv\\share\\p');
37
+ assert.equal(canonicalCwd('/a/../b'), '/b');
38
+ assert.equal(resolveWorkerCwd('D:\\AI\\floorplan', base), 'D:\\AI\\floorplan');
39
+ }
40
+
41
+ console.log('smoke-cwd: all assertions passed');