dsh-agent-router 1.9.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 (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +304 -0
  3. package/README.md +304 -0
  4. package/client.js +3061 -0
  5. package/cordis.patch.yml +20 -0
  6. package/docs/ARCHITECTURE_DIAGNOSIS_AND_PLAN.md +414 -0
  7. package/docs/DETAIL.ja.md +1 -0
  8. package/docs/DETAIL.md +1 -0
  9. package/docs/DETAIL.zh.md +1 -0
  10. package/docs/IMPLEMENTATION_PLAN.md +99 -0
  11. package/docs/ITERATION_PLAN_2026-11.md +377 -0
  12. package/docs/RELEASE.md +133 -0
  13. package/docs/RELEASE_CHECKLIST.md +88 -0
  14. package/docs/preview.svg +69 -0
  15. package/docs/preview.zh.svg +63 -0
  16. package/icon.svg +16 -0
  17. package/index.js +24 -0
  18. package/lib/classifier.js +405 -0
  19. package/lib/cli/discover.js +187 -0
  20. package/lib/cli/invoke.js +294 -0
  21. package/lib/cli/parsers.js +234 -0
  22. package/lib/cli/shared.js +145 -0
  23. package/lib/cli-runners.js +39 -0
  24. package/lib/config-limits.js +67 -0
  25. package/lib/config-normalize.js +147 -0
  26. package/lib/config-presets.js +89 -0
  27. package/lib/config-schema.js +347 -0
  28. package/lib/defaults.js +117 -0
  29. package/lib/diagnose-fallback.js +96 -0
  30. package/lib/error-classify.js +160 -0
  31. package/lib/eval-routing.js +96 -0
  32. package/lib/guardrails.js +70 -0
  33. package/lib/integrations.js +173 -0
  34. package/lib/job-runner.js +287 -0
  35. package/lib/ledger.js +360 -0
  36. package/lib/legacy-config.js +34 -0
  37. package/lib/model-capabilities.js +135 -0
  38. package/lib/model-score.js +65 -0
  39. package/lib/plugin.js +184 -0
  40. package/lib/profile-mount.js +524 -0
  41. package/lib/route-edit.js +82 -0
  42. package/lib/router/candidates.js +194 -0
  43. package/lib/router/catalog.js +121 -0
  44. package/lib/router/cli-select.js +84 -0
  45. package/lib/router/config-manager.js +122 -0
  46. package/lib/router/doctor.js +159 -0
  47. package/lib/router/local-models.js +126 -0
  48. package/lib/router/policy.js +61 -0
  49. package/lib/router/rpc.js +263 -0
  50. package/lib/router/system-prompt.js +29 -0
  51. package/lib/router/tools.js +1028 -0
  52. package/lib/router/util.js +99 -0
  53. package/lib/rpc-contract.js +46 -0
  54. package/lib/sessions.js +59 -0
  55. package/lib/task-queue.js +201 -0
  56. package/lib/tier-presets.js +595 -0
  57. package/lib/typert.host.js +79 -0
  58. package/lib/update-check.js +205 -0
  59. package/lib/worktree-lock.js +86 -0
  60. package/lib/worktree.js +268 -0
  61. package/locale/en.json +7 -0
  62. package/locale/ja.json +7 -0
  63. package/locale/zh.json +7 -0
  64. package/package.json +136 -0
  65. package/scripts/profile-maintenance.mjs +287 -0
package/package.json ADDED
@@ -0,0 +1,136 @@
1
+ {
2
+ "name": "dsh-agent-router",
3
+ "version": "1.9.0",
4
+ "description": "Multi-agent orchestration and difficulty-based model router for DeepSeek Harness: route tasks by configurable difficulty tiers (default T1-T4) across native DSH subagents and local CLIs (Claude Code, Codex, Gemini, OpenCode, Antigravity) with capability-aware filtering, adaptive CLI selection, opt-in local models, health cooldowns, classified failover, live run status, feedback/eval, session lifecycle, config presets with portable import/export, metrics export, worktree locking, auto-escalation, async CLI queue, and Git worktree diff/merge isolation.",
5
+ "license": "MIT",
6
+ "author": "liwenzhi <695598532@qq.com>",
7
+ "icon": "./icon.svg",
8
+ "os": [
9
+ "win32",
10
+ "darwin",
11
+ "linux"
12
+ ],
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "type": "module",
17
+ "main": "./index.js",
18
+ "exports": {
19
+ ".": "./index.js",
20
+ "./client": "./client.js",
21
+ "./typert": "./lib/typert.host.js",
22
+ "./cordis.patch.yml": "./cordis.patch.yml",
23
+ "./locale/*.json": "./locale/*.json",
24
+ "./icon": "./icon.svg",
25
+ "./package.json": "./package.json"
26
+ },
27
+ "files": [
28
+ "index.js",
29
+ "client.js",
30
+ "lib/**/*.js",
31
+ "scripts/profile-maintenance.mjs",
32
+ "cordis.patch.yml",
33
+ "locale/*.json",
34
+ "docs/*",
35
+ "icon.svg",
36
+ "README.md",
37
+ "README.en.md",
38
+ "LICENSE"
39
+ ],
40
+ "keywords": [
41
+ "dsh",
42
+ "dsh-plugin",
43
+ "dsh-bundle",
44
+ "deepseek-harness",
45
+ "model-routing",
46
+ "multi-agent",
47
+ "agent-orchestration",
48
+ "local-models",
49
+ "ollama",
50
+ "claude-code",
51
+ "codex",
52
+ "gemini",
53
+ "opencode",
54
+ "antigravity"
55
+ ],
56
+ "scripts": {
57
+ "build:client": "node scripts/build-client.mjs",
58
+ "test": "node --test --test-isolation=none test/router.test.mjs test/cli-fixtures.test.mjs test/e2e.test.mjs test/update-check.test.mjs test/profile-mount.test.mjs",
59
+ "test:cli-smoke": "node --test --test-isolation=none test/cli-integration.mjs",
60
+ "test:cli-fixtures": "node --test --test-isolation=none test/cli-fixtures.test.mjs",
61
+ "test:e2e": "node --test --test-isolation=none test/e2e.test.mjs",
62
+ "test:coverage": "node --test --experimental-test-coverage --test-isolation=none test/router.test.mjs test/cli-fixtures.test.mjs test/e2e.test.mjs test/update-check.test.mjs test/profile-mount.test.mjs",
63
+ "smoke:dsh": "node scripts/smoke-dsh.mjs",
64
+ "profile:check": "node scripts/profile-maintenance.mjs check",
65
+ "profile:repair": "node scripts/profile-maintenance.mjs repair",
66
+ "profile:install": "node scripts/profile-maintenance.mjs install",
67
+ "profile:uninstall": "node scripts/profile-maintenance.mjs uninstall",
68
+ "eval:routing": "node scripts/eval-routing.mjs",
69
+ "market:index": "node scripts/generate-market-index.mjs",
70
+ "verify": "node scripts/verify-manifest.mjs",
71
+ "release:check": "node scripts/verify-release.mjs",
72
+ "ci": "npm run verify && npm test && npm run release:check && npm run smoke:dsh",
73
+ "prepublishOnly": "npm run verify && npm test && npm run release:check"
74
+ },
75
+ "dsh": {
76
+ "bundle": {
77
+ "patch": "./cordis.patch.yml"
78
+ },
79
+ "client": {
80
+ "platform": "web",
81
+ "immediately": true,
82
+ "inject": [
83
+ "@deepseek-ai/dsh-client-ui-renderer",
84
+ "@deepseek-ai/dsh-client-ui-tool",
85
+ "@deepseek-ai/dsh-client-ui-plugin-manager",
86
+ "@deepseek-ai/dsh-api-remotes",
87
+ "@deepseek-ai/dsh-client-locale"
88
+ ]
89
+ },
90
+ "compatibility": {
91
+ "dshReleases": {
92
+ "0.2.2-rc.1+": "compatible",
93
+ "0.2.2-rc.5+": "compatible"
94
+ }
95
+ }
96
+ },
97
+ "dshhub": {
98
+ "schemaVersion": 1,
99
+ "displayName": "Multi-Agent Difficulty Router",
100
+ "categories": [
101
+ "AI",
102
+ "Orchestration",
103
+ "Multi-Agent"
104
+ ],
105
+ "surfaces": [
106
+ "host",
107
+ "web"
108
+ ],
109
+ "capabilities": {
110
+ "provides": [
111
+ "service:dsh-agent-router",
112
+ "tools:router_plan",
113
+ "tools:router_dispatch",
114
+ "tools:router_continue",
115
+ "tools:router_status"
116
+ ]
117
+ },
118
+ "permissions": [
119
+ "subprocess:local-cli",
120
+ "fs:ledger-home",
121
+ "git:worktree"
122
+ ]
123
+ },
124
+ "engines": {
125
+ "dsh": ">=0.2.2-rc.1 <0.3.0-0",
126
+ "node": ">=24.9.0"
127
+ },
128
+ "repository": {
129
+ "type": "git",
130
+ "url": "git+https://github.com/qingxuan233/dsh-agent-router.git"
131
+ },
132
+ "homepage": "https://github.com/qingxuan233/dsh-agent-router#readme",
133
+ "bugs": {
134
+ "url": "https://github.com/qingxuan233/dsh-agent-router/issues"
135
+ }
136
+ }
@@ -0,0 +1,287 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Profile maintenance helper for `dsh-agent-router`.
4
+ *
5
+ * Subcommands:
6
+ * check Print how the plugin is mounted (read-only).
7
+ * repair Remove hand-written `- insert:` blocks, ensure the standard
8
+ * bundle entry, and back up every changed file.
9
+ * install Run `pnpm add <spec>` in the profile directory, then ensure
10
+ * `dsh-agent-router` is listed in `dsh.profile.bundles`.
11
+ * uninstall Remove the bundle entry and run `pnpm remove dsh-agent-router`.
12
+ * Refuses when a manual insert remains.
13
+ *
14
+ * All subcommands accept `--profile <name>` and honor `DSH_HOME`.
15
+ * No external dependencies. Never reads network resources.
16
+ *
17
+ * @module scripts/profile-maintenance
18
+ */
19
+
20
+ import { spawn } from 'node:child_process'
21
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs'
22
+ import { join } from 'node:path'
23
+
24
+ import { applyMountRepair, inspectMount } from '../lib/profile-mount.js'
25
+
26
+ const PLUGIN_NAME = 'dsh-agent-router'
27
+ const PNPM = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm'
28
+
29
+ function parseArgs(argv) {
30
+ const result = { command: null, profile: null, spec: null }
31
+ for (let i = 0; i < argv.length; i += 1) {
32
+ const arg = argv[i]
33
+ if (!result.command && !arg.startsWith('-')) {
34
+ result.command = arg
35
+ continue
36
+ }
37
+ if (arg === '--profile') {
38
+ result.profile = argv[i + 1] || null
39
+ i += 1
40
+ } else if (arg.startsWith('--profile=')) {
41
+ result.profile = arg.slice('--profile='.length) || null
42
+ } else if (arg === '--spec') {
43
+ result.spec = argv[i + 1] || null
44
+ i += 1
45
+ } else if (arg.startsWith('--spec=')) {
46
+ result.spec = arg.slice('--spec='.length) || null
47
+ }
48
+ }
49
+ return result
50
+ }
51
+
52
+ function argvFor(profile) {
53
+ return profile ? ['--profile', profile] : []
54
+ }
55
+
56
+ function printInspection(inspection) {
57
+ console.log(`state: ${inspection.state}`)
58
+ console.log(`profile: ${inspection.profile || '(none)'}`)
59
+ console.log(`profileDir: ${inspection.profileDir || '(none)'}`)
60
+ console.log(`dependency: ${inspection.dependency || '(missing)'}`)
61
+ console.log(`bundleRegistered: ${inspection.bundleRegistered}`)
62
+ if (inspection.reason) console.log(`reason: ${inspection.reason}`)
63
+ console.log(`files: profilePatch=${inspection.files?.profilePatch || '(none)'} homePatch=${inspection.files?.homePatch || '(none)'} profilePackage=${inspection.files?.profilePackage || '(none)'}`)
64
+ if (inspection.manualInserts.length > 0) {
65
+ console.log('manual inserts:')
66
+ for (const insert of inspection.manualInserts) console.log(` - ${insert.file}:${insert.line}`)
67
+ }
68
+ if (inspection.issues.length > 0) {
69
+ console.log('issues:')
70
+ for (const issue of inspection.issues) {
71
+ console.log(` - [${issue.code}] ${issue.message}${issue.file ? ` (${issue.file})` : ''}`)
72
+ }
73
+ }
74
+ if (inspection.guidance.length > 0) {
75
+ console.log('guidance:')
76
+ for (const line of inspection.guidance) console.log(` - ${line}`)
77
+ }
78
+ }
79
+
80
+ function runPnpm(args, cwd) {
81
+ return new Promise((resolve, reject) => {
82
+ let child
83
+ try {
84
+ child = spawn(PNPM, args, {
85
+ cwd,
86
+ stdio: 'inherit',
87
+ // Node >= 20 on Windows refuses to spawn .cmd shims without a shell.
88
+ shell: process.platform === 'win32',
89
+ })
90
+ } catch (error) {
91
+ reject(error)
92
+ return
93
+ }
94
+ child.on('error', reject)
95
+ child.on('close', (code) => resolve(code ?? 1))
96
+ })
97
+ }
98
+
99
+ function ensureBundleEntry(packageFile) {
100
+ const pkg = JSON.parse(readFileSync(packageFile, 'utf8'))
101
+ if (!pkg.dsh || typeof pkg.dsh !== 'object') pkg.dsh = {}
102
+ if (!pkg.dsh.profile || typeof pkg.dsh.profile !== 'object') pkg.dsh.profile = {}
103
+ if (!Array.isArray(pkg.dsh.profile.bundles)) pkg.dsh.profile.bundles = []
104
+ if (pkg.dsh.profile.bundles.includes(PLUGIN_NAME)) return false
105
+ pkg.dsh.profile.bundles.push(PLUGIN_NAME)
106
+ writeFileSync(packageFile, `${JSON.stringify(pkg, null, 2)}\n`, 'utf8')
107
+ return true
108
+ }
109
+
110
+ function removeBundleEntry(packageFile) {
111
+ const pkg = JSON.parse(readFileSync(packageFile, 'utf8'))
112
+ const bundles = pkg?.dsh?.profile?.bundles
113
+ if (!Array.isArray(bundles) || !bundles.includes(PLUGIN_NAME)) return false
114
+ pkg.dsh.profile.bundles = bundles.filter((item) => item !== PLUGIN_NAME)
115
+ writeFileSync(packageFile, `${JSON.stringify(pkg, null, 2)}\n`, 'utf8')
116
+ return true
117
+ }
118
+
119
+ function inspect(options) {
120
+ return inspectMount({ pluginName: PLUGIN_NAME, argv: argvFor(options.profile) })
121
+ }
122
+
123
+ function commandCheck(options) {
124
+ try {
125
+ printInspection(inspect(options))
126
+ return 0
127
+ } catch (error) {
128
+ console.error(`profile:check failed: ${error instanceof Error ? error.message : String(error)}`)
129
+ return 1
130
+ }
131
+ }
132
+
133
+ function commandRepair(options) {
134
+ let inspection
135
+ try {
136
+ inspection = inspect(options)
137
+ } catch (error) {
138
+ console.error(`profile:repair failed to inspect: ${error instanceof Error ? error.message : String(error)}`)
139
+ return 1
140
+ }
141
+ printInspection(inspection)
142
+
143
+ if (inspection.state !== 'manual' && inspection.state !== 'duplicate') {
144
+ console.log('[repair] 无需修复:安装方式正常或无法判定。')
145
+ return 0
146
+ }
147
+
148
+ const targets = []
149
+ for (const insert of inspection.manualInserts) {
150
+ if (!targets.includes(insert.file)) targets.push(insert.file)
151
+ }
152
+ if (!inspection.bundleRegistered && inspection.files?.profilePackage) {
153
+ targets.push(inspection.files.profilePackage)
154
+ }
155
+ console.log('[repair] 将修改以下文件(修改前会先备份):')
156
+ for (const file of targets) console.log(` - ${file}`)
157
+
158
+ const result = applyMountRepair(inspection)
159
+ if (!result.ok) {
160
+ console.error('[repair] 修复未完成:')
161
+ for (const line of result.guidance || []) console.error(` - ${line}`)
162
+ for (const issue of result.remainingIssues || []) console.error(` - [${issue.code}] ${issue.message}`)
163
+ return 1
164
+ }
165
+
166
+ if (result.changed.length === 0) {
167
+ console.log('[repair] 未修改任何文件。')
168
+ return 0
169
+ }
170
+ console.log('[repair] 已修改:')
171
+ for (const file of result.changed) console.log(` - ${file}`)
172
+ console.log(`[repair] 备份目录:${result.backupDir}`)
173
+ if (result.remainingIssues.length > 0) {
174
+ console.log('[repair] 剩余待处理问题:')
175
+ for (const issue of result.remainingIssues) console.log(` - [${issue.code}] ${issue.message}`)
176
+ }
177
+ console.log('[repair] restart DSH required:请完整重启 DSH 使挂载变更生效。')
178
+ return 0
179
+ }
180
+
181
+ async function commandInstall(options) {
182
+ if (!options.spec) {
183
+ console.error('用法:node scripts/profile-maintenance.mjs install --spec <pnpm spec> [--profile <name>]')
184
+ return 1
185
+ }
186
+ const inspection = inspect(options)
187
+ if (!inspection.profileDir) {
188
+ console.error('[install] 无法定位 profile 目录。请用 --profile <name> 指定目标 profile。')
189
+ if (inspection.reason) console.error(` - ${inspection.reason}`)
190
+ return 1
191
+ }
192
+ const packageFile = inspection.files?.profilePackage
193
+ const packageExisted = Boolean(packageFile && existsSync(packageFile))
194
+
195
+ console.log(`[install] 将在 ${inspection.profileDir} 执行:${PNPM} add ${options.spec}`)
196
+ console.log(`[install] 完成后将确保 ${PLUGIN_NAME} 位于 dsh.profile.bundles。`)
197
+
198
+ const code = await runPnpm(['add', options.spec], inspection.profileDir)
199
+ if (code !== 0) {
200
+ console.error(`[install] pnpm add 失败(退出码 ${code}),未修改 dsh.profile.bundles。`)
201
+ return code || 1
202
+ }
203
+ if (!packageFile || !existsSync(packageFile)) {
204
+ console.error(`[install] 安装后未找到 ${packageFile || 'profile package.json'}。`)
205
+ return 1
206
+ }
207
+ if (!packageExisted) console.log('[install] profile package.json 由 pnpm 创建。')
208
+
209
+ if (ensureBundleEntry(packageFile)) {
210
+ console.log(`[install] 已写入 dsh.profile.bundles:${PLUGIN_NAME}`)
211
+ } else {
212
+ console.log(`[install] dsh.profile.bundles 已包含 ${PLUGIN_NAME},无需变更。`)
213
+ }
214
+
215
+ const after = inspect(options)
216
+ if (after.manualInserts.length > 0) {
217
+ console.warn('[install] 仍检测到手工 - insert: 挂载块;请运行 profile-maintenance.mjs repair 后再重启 DSH:')
218
+ for (const insert of after.manualInserts) console.warn(` - ${insert.file}:${insert.line}`)
219
+ } else {
220
+ console.log('[install] 未检测到手工挂载。请完整重启 DSH。')
221
+ }
222
+ return 0
223
+ }
224
+
225
+ async function commandUninstall(options) {
226
+ const inspection = inspect(options)
227
+ printInspection(inspection)
228
+
229
+ if (inspection.manualInserts.length > 0) {
230
+ console.error('[uninstall] 检测到手工 - insert: 挂载块,已拒绝卸载。')
231
+ console.error('[uninstall] 请先运行 profile-maintenance.mjs repair 移除手工挂载,再执行卸载。')
232
+ for (const insert of inspection.manualInserts) console.error(` - ${insert.file}:${insert.line}`)
233
+ return 1
234
+ }
235
+ if (!inspection.profileDir || !inspection.files?.profilePackage) {
236
+ console.error('[uninstall] 无法定位 profile 目录。请用 --profile <name> 指定目标 profile。')
237
+ return 1
238
+ }
239
+
240
+ const packageFile = inspection.files.profilePackage
241
+ const hasBundle = inspection.bundleRegistered
242
+ const hasDependency = Boolean(inspection.dependency)
243
+ if (!hasBundle && !hasDependency) {
244
+ console.log(`[uninstall] profile ${inspection.profile || ''} 未安装 ${PLUGIN_NAME},无需卸载。`)
245
+ return 0
246
+ }
247
+
248
+ console.log(`[uninstall] 将先在 ${inspection.profileDir} 执行:${PNPM} remove ${PLUGIN_NAME}`)
249
+ console.log(`[uninstall] 成功后再从 ${packageFile} 的 dsh.profile.bundles 移除 ${PLUGIN_NAME}(如存在)。`)
250
+
251
+ const code = await runPnpm(['remove', PLUGIN_NAME], inspection.profileDir)
252
+ if (code !== 0) {
253
+ console.error(`[uninstall] pnpm remove 失败(退出码 ${code}),未修改 dsh.profile.bundles。`)
254
+ return code || 1
255
+ }
256
+
257
+ if (removeBundleEntry(packageFile)) {
258
+ console.log(`[uninstall] 已从 dsh.profile.bundles 移除 ${PLUGIN_NAME}。`)
259
+ }
260
+
261
+ const after = inspect(options)
262
+ console.log(`[uninstall] 卸载后状态:${after.state}`)
263
+ if (after.manualInserts.length > 0) {
264
+ console.warn('[uninstall] 仍检测到手工挂载,请运行 profile-maintenance.mjs repair。')
265
+ }
266
+ console.log('[uninstall] 请完整重启 DSH 使卸载生效。')
267
+ return 0
268
+ }
269
+
270
+ async function main(argv) {
271
+ const options = parseArgs(argv)
272
+ switch (options.command) {
273
+ case 'check':
274
+ return commandCheck(options)
275
+ case 'repair':
276
+ return commandRepair(options)
277
+ case 'install':
278
+ return commandInstall(options)
279
+ case 'uninstall':
280
+ return commandUninstall(options)
281
+ default:
282
+ console.error('用法:node scripts/profile-maintenance.mjs <check|repair|install|uninstall> [--profile <name>] [--spec <pnpm spec>]')
283
+ return 1
284
+ }
285
+ }
286
+
287
+ process.exitCode = await main(process.argv.slice(2))