@whyshu/argent-engine 0.8.0-rc.11 → 0.8.0-rc.13
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/MANIFEST.json +34 -7
- package/bin/runtime-install.mjs +92 -0
- package/engine/VERSION +1 -1
- package/engine/configs/billing-actions.json +30 -0
- package/engine/configs/mcp-tools.snapshot.json +40 -0
- package/engine/core/lib/account-token.mjs +37 -0
- package/engine/core/lib/redact.mjs +34 -0
- package/engine/core/mcp/billing-upload.mjs +77 -0
- package/engine/core/mcp/erp-server.mjs +296 -0
- package/engine/core/mcp/gateway.mjs +333 -0
- package/engine/core/mcp/meter.mjs +101 -0
- package/engine/core/mcp/vault.mjs +78 -0
- package/engine/scripts/appointment_grab.py +100 -20
- package/engine/scripts/argent-web-preflight.mjs +123 -0
- package/engine/scripts/argent-web-verify.mjs +105 -0
- package/engine/scripts/billing-upload.mjs +26 -0
- package/engine/scripts/build-engine-package.mjs +7 -1
- package/engine/scripts/dsh-web-doctor.mjs +84 -0
- package/engine/scripts/engine-runtime-install.mjs +92 -0
- package/engine/scripts/erp-ui-install.mjs +127 -0
- package/engine/scripts/erp-ui-preflight.mjs +104 -0
- package/engine/scripts/erp-ui-verify.mjs +135 -0
- package/engine/scripts/lib/plugin-packages.mjs +13 -0
- package/engine/scripts/mcp-gateway-switch.mjs +100 -0
- package/engine/scripts/migrate-providers.mjs +3 -3
- package/engine/scripts/v0.9-acceptance.mjs +107 -0
- package/engine/scripts/web-switch.mjs +121 -0
- package/engine/skills/README.md +3 -3
- package/engine/skills/bilibili-upload/SKILL.md +109 -0
- package/engine/skills/douyin-upload/SKILL.md +74 -0
- package/engine/skills/internal.json +28 -0
- package/engine/skills/kuaishou-upload/SKILL.md +109 -0
- package/engine/skills/tencent-upload/SKILL.md +60 -0
- package/engine/skills/weibo-upload/SKILL.md +106 -0
- package/engine/skills/whyshu-social-ops/SKILL.md +136 -0
- package/engine/skills/xiaohongshu-upload/SKILL.md +122 -0
- package/engine/version.mjs +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* dsh-web-doctor.mjs —— 给"不懂技术"的人用的一条命令:诊断并修复 dsh web 起不来
|
|
4
|
+
*
|
|
5
|
+
* 覆盖 2026-11-05 实测的故障:profile 里残留一整套旧版 dsh 包(155MB/306 个),
|
|
6
|
+
* 与官方 npx 拉到的宿主版本不一致 ⇒ dsh 一次性禁用 97 个核心行 ⇒
|
|
7
|
+
* `webserver (required)` 等不到 `webStartup` ⇒ 启动失败。
|
|
8
|
+
*
|
|
9
|
+
* 用法:
|
|
10
|
+
* node scripts/dsh-web-doctor.mjs # 只诊断(不动文件)
|
|
11
|
+
* node scripts/dsh-web-doctor.mjs --fix # 修复:把旧包移到备份目录(不删)
|
|
12
|
+
* node scripts/dsh-web-doctor.mjs --fix --profile web2
|
|
13
|
+
*
|
|
14
|
+
* 判据(都是可复算的):
|
|
15
|
+
* · profile/node_modules/@deepseek-ai 的包数(干净 profile 应为 0,由宿主提供)
|
|
16
|
+
* · 这些包的版本 ≠ 当前宿主 dsh 版本 ⇒ 会被禁用
|
|
17
|
+
* · profile 里是否装了我们的插件、bundles 是否只剩 base/web-app/argent-web
|
|
18
|
+
*/
|
|
19
|
+
import { existsSync, lstatSync, readdirSync, readFileSync, renameSync } from 'node:fs'
|
|
20
|
+
import { homedir } from 'node:os'
|
|
21
|
+
import { join } from 'node:path'
|
|
22
|
+
import { execFileSync } from 'node:child_process'
|
|
23
|
+
|
|
24
|
+
const args = process.argv.slice(2)
|
|
25
|
+
const fix = args.includes('--fix')
|
|
26
|
+
const profile = args.includes('--profile') ? args[args.indexOf('--profile') + 1] : 'web'
|
|
27
|
+
const dshHome = process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
28
|
+
const profileDir = join(dshHome, 'profiles', profile)
|
|
29
|
+
const dshMods = join(profileDir, 'node_modules', '@deepseek-ai')
|
|
30
|
+
|
|
31
|
+
let problems = 0
|
|
32
|
+
const bad = (m) => { console.log(`❌ ${m}`); problems++ }
|
|
33
|
+
const good = (m) => console.log(`✅ ${m}`)
|
|
34
|
+
const info = (m) => console.log(`ℹ️ ${m}`)
|
|
35
|
+
|
|
36
|
+
if (!existsSync(profileDir)) { bad(`profile 不存在:${profileDir}(先跑一次 dsh web 生成)`); process.exit(1) }
|
|
37
|
+
|
|
38
|
+
// 1) 旧 dsh 树
|
|
39
|
+
let stale = []
|
|
40
|
+
if (existsSync(dshMods)) {
|
|
41
|
+
for (const d of readdirSync(dshMods)) {
|
|
42
|
+
const pj = join(dshMods, d, 'package.json')
|
|
43
|
+
if (!existsSync(pj)) continue
|
|
44
|
+
try { stale.push({ name: `@deepseek-ai/${d}`, version: JSON.parse(readFileSync(pj, 'utf8')).version }) } catch { /* skip */ }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const versions = [...new Set(stale.map((s) => s.version))]
|
|
48
|
+
if (stale.length) bad(`profile 里残留 ${stale.length} 个 @deepseek-ai 包(版本:${versions.join(', ')})—— 它们会盖住宿主自带版本`)
|
|
49
|
+
else good('profile 里没有 @deepseek-ai 包(干净:由宿主提供)')
|
|
50
|
+
|
|
51
|
+
// 2) 宿主版本
|
|
52
|
+
let hostVer = ''
|
|
53
|
+
try { hostVer = execFileSync('dsh', ['--version'], { encoding: 'utf8', timeout: 5000 }).trim() } catch { /* ignore */ }
|
|
54
|
+
if (hostVer) info(`全局 dsh 版本:${hostVer}`)
|
|
55
|
+
if (stale.length && hostVer && !versions.includes(hostVer)) {
|
|
56
|
+
bad(`版本不一致:profile 里是 ${versions.join('/')},宿主是 ${hostVer} ⇒ 启动时会一次性禁用大量核心插件`)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 3) 插件与 bundles
|
|
60
|
+
const pkgFile = join(profileDir, 'package.json')
|
|
61
|
+
const pkg = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, 'utf8')) : {}
|
|
62
|
+
const bundles = (pkg.dsh && pkg.dsh.profile && pkg.dsh.profile.bundles) || []
|
|
63
|
+
const hasPlugin = Boolean((pkg.dependencies || {})['@whyshu/argent-web'])
|
|
64
|
+
hasPlugin ? good('已安装 @whyshu/argent-web') : info('未安装 @whyshu/argent-web(需要的话:dsh plugin --profile web install @whyshu/argent-web)')
|
|
65
|
+
info(`bundles:${bundles.join(', ')}`)
|
|
66
|
+
|
|
67
|
+
// 4) 修复
|
|
68
|
+
if (problems && fix) {
|
|
69
|
+
if (stale.length) {
|
|
70
|
+
const bak = join(dshHome, 'profiles', `${profile}-stale-deepseek-ai-${new Date().toISOString().replace(/[:.]/g, '-').slice(0, 17)}`)
|
|
71
|
+
renameSync(dshMods, bak)
|
|
72
|
+
console.log(`\n🔧 已把旧包移到:${bak}`)
|
|
73
|
+
console.log(' (保留备份;确认 web 正常后可删除)')
|
|
74
|
+
}
|
|
75
|
+
console.log('\n修复完成。下一步:')
|
|
76
|
+
console.log(' npx @deepseek-ai/dsh@latest web # 或 dsh web')
|
|
77
|
+
problems = 0
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (problems) {
|
|
81
|
+
console.log(`\n❌ 发现 ${problems} 个问题。加 --fix 自动修复(旧包会被移到备份目录,不删除)`)
|
|
82
|
+
process.exit(1)
|
|
83
|
+
}
|
|
84
|
+
console.log('\n✅ 没有发现会导致启动失败的问题')
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @whyshu/argent-engine 自带 runtime 安装器(2026-11-07,替代已退役启动器)。
|
|
4
|
+
*
|
|
5
|
+
* 用法(客户机出站,不推文件):
|
|
6
|
+
* npx -y @whyshu/argent-engine@<version> argent-engine-runtime --target ~/.argent-dsh
|
|
7
|
+
*
|
|
8
|
+
* 行为:
|
|
9
|
+
* · 只写引擎文件(scripts/core/verticals/configs/agents/skills/tools/agentic + VERSION),
|
|
10
|
+
* **不动** venv、数据、台账、agent-report、license;
|
|
11
|
+
* · 覆盖前把旧文件备份到 <target>/.runtime-backup/<timestamp>/;
|
|
12
|
+
* · 安装前按 MANIFEST.json 校验包内文件 sha256(fail-closed),安装后写 VERSION;
|
|
13
|
+
* · `.sh` 安装为 0755,其余 0644(客户机执行位事故的既有口径)。
|
|
14
|
+
*/
|
|
15
|
+
import { readFileSync, writeFileSync, mkdirSync, rmSync, existsSync, readdirSync, statSync, chmodSync, copyFileSync } from 'node:fs'
|
|
16
|
+
import { createHash } from 'node:crypto'
|
|
17
|
+
import { join, dirname, relative, sep } from 'node:path'
|
|
18
|
+
import { homedir } from 'node:os'
|
|
19
|
+
import { fileURLToPath } from 'node:url'
|
|
20
|
+
|
|
21
|
+
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
22
|
+
const PKG_ROOT = dirname(HERE) // published layout: <pkg>/bin/runtime-install.mjs
|
|
23
|
+
const SRC = join(PKG_ROOT, 'engine')
|
|
24
|
+
|
|
25
|
+
function parseArgs(argv) {
|
|
26
|
+
const out = { target: join(homedir(), '.argent-dsh'), dryRun: false }
|
|
27
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
28
|
+
if (argv[i] === '--target') out.target = argv[++i]
|
|
29
|
+
else if (argv[i] === '--dry-run') out.dryRun = true
|
|
30
|
+
else if (argv[i] === '--help') { console.log('用法:argent-engine-runtime --target <dir> [--dry-run]'); process.exit(0) }
|
|
31
|
+
}
|
|
32
|
+
return out
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const sha = (buf) => createHash('sha256').update(buf).digest('hex')
|
|
36
|
+
|
|
37
|
+
function listFiles(dir, base = SRC) {
|
|
38
|
+
const out = []
|
|
39
|
+
for (const e of readdirSync(dir)) {
|
|
40
|
+
const p = join(dir, e)
|
|
41
|
+
const st = statSync(p)
|
|
42
|
+
if (st.isDirectory()) out.push(...listFiles(p))
|
|
43
|
+
else out.push(relative(base, p).split(sep).join('/'))
|
|
44
|
+
}
|
|
45
|
+
return out
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function main() {
|
|
49
|
+
const opts = parseArgs(process.argv.slice(2))
|
|
50
|
+
if (!existsSync(SRC)) { console.error(`✗ 包内缺少 engine/(${SRC})`); process.exit(2) }
|
|
51
|
+
const manifest = JSON.parse(readFileSync(join(PKG_ROOT, 'MANIFEST.json'), 'utf8'))
|
|
52
|
+
const version = readFileSync(join(SRC, 'VERSION'), 'utf8').trim()
|
|
53
|
+
const files = listFiles(SRC)
|
|
54
|
+
// ① 包内自检:字节与 MANIFEST 一致(fail-closed)
|
|
55
|
+
for (const rel of files) {
|
|
56
|
+
const buf = readFileSync(join(SRC, rel))
|
|
57
|
+
if (manifest.files[rel] && sha(buf) !== manifest.files[rel]) {
|
|
58
|
+
console.error(`✗ 包内文件摘要不符:${rel}`)
|
|
59
|
+
process.exit(2)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (opts.dryRun) {
|
|
63
|
+
console.log(JSON.stringify({ ok: true, dryRun: true, version, target: opts.target, files: files.length }))
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
const target = opts.target
|
|
67
|
+
const ts = new Date().toISOString().replace(/[:.]/g, '-')
|
|
68
|
+
const backup = join(target, '.runtime-backup', ts)
|
|
69
|
+
mkdirSync(backup, { recursive: true })
|
|
70
|
+
let copied = 0
|
|
71
|
+
for (const rel of files) {
|
|
72
|
+
const src = join(SRC, rel)
|
|
73
|
+
const dst = join(target, rel)
|
|
74
|
+
if (existsSync(dst)) {
|
|
75
|
+
const oldBuf = readFileSync(dst)
|
|
76
|
+
const newBuf = readFileSync(src)
|
|
77
|
+
if (sha(oldBuf) !== sha(newBuf)) {
|
|
78
|
+
const b = join(backup, rel)
|
|
79
|
+
mkdirSync(dirname(b), { recursive: true })
|
|
80
|
+
copyFileSync(dst, b)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
mkdirSync(dirname(dst), { recursive: true })
|
|
84
|
+
copyFileSync(src, dst)
|
|
85
|
+
chmodSync(dst, rel.endsWith('.sh') ? 0o755 : 0o644)
|
|
86
|
+
copied += 1
|
|
87
|
+
}
|
|
88
|
+
writeFileSync(join(target, 'VERSION'), `${version}\n`)
|
|
89
|
+
console.log(JSON.stringify({ ok: true, version, target, files: copied, backupDir: backup }))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
main()
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* erp-ui-install.mjs —— 把 `@whyshu/argent-erp-ui` 装进某个 dsh profile(v0.9.0)
|
|
4
|
+
*
|
|
5
|
+
* 为什么需要脚本:手工改 profile 有三处必错点(2026-11-02 实测过两次):
|
|
6
|
+
* ① `pnpm install` 会把 `node_modules/@whyshu/*` 的**软链重建成新目录**(桌面插件曾是软链,重建后
|
|
7
|
+
* "改代码不生效"但没有任何报错);
|
|
8
|
+
* ② bundles 数组漏加 ⇒ 包装了但**根本不会被加载**;
|
|
9
|
+
* ③ 不备份 ⇒ 出问题只能靠记忆回滚。
|
|
10
|
+
*
|
|
11
|
+
* 用法:
|
|
12
|
+
* node scripts/erp-ui-install.mjs # 默认 dry-run(只打印将做什么)
|
|
13
|
+
* node scripts/erp-ui-install.mjs --apply # 真正写入 + pnpm install
|
|
14
|
+
* node scripts/erp-ui-install.mjs --apply --profile desktop
|
|
15
|
+
* node scripts/erp-ui-install.mjs --rollback <备份目录>
|
|
16
|
+
*
|
|
17
|
+
* 安全:只动 profile 的 package.json / node_modules;⛔ 不重启 dsh(由用户手动)。
|
|
18
|
+
*/
|
|
19
|
+
import { cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, realpathSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
20
|
+
import { homedir } from 'node:os'
|
|
21
|
+
import { join, resolve } from 'node:path'
|
|
22
|
+
import { spawnSync } from 'node:child_process'
|
|
23
|
+
|
|
24
|
+
const REPO = resolve(import.meta.dirname, '..')
|
|
25
|
+
const PKG = '@whyshu/argent-erp-ui'
|
|
26
|
+
const PKG_DIR = join(REPO, 'plugins', 'argent-erp-ui')
|
|
27
|
+
const args = process.argv.slice(2)
|
|
28
|
+
const apply = args.includes('--apply')
|
|
29
|
+
const profileArg = args.includes('--profile') ? args[args.indexOf('--profile') + 1] : 'desktop'
|
|
30
|
+
const rollbackIdx = args.indexOf('--rollback')
|
|
31
|
+
|
|
32
|
+
const dshHome = process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
33
|
+
const profileDir = join(dshHome, 'profiles', profileArg)
|
|
34
|
+
const pkgFile = join(profileDir, 'package.json')
|
|
35
|
+
const ts = new Date().toISOString().replace(/[-:T]/g, '').slice(0, 14)
|
|
36
|
+
|
|
37
|
+
function resolvePnpm() {
|
|
38
|
+
const cands = [process.env.ARGENT_PNPM, '/opt/homebrew/bin/pnpm', join(homedir(), 'Library', 'pnpm', 'pnpm')].filter(Boolean)
|
|
39
|
+
for (const c of cands) if (existsSync(c)) return c
|
|
40
|
+
const which = spawnSync('pnpm', ['--version'], { encoding: 'utf8' })
|
|
41
|
+
return which.status === 0 ? 'pnpm' : ''
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function fail(msg) { console.error(`❌ ${msg}`); process.exit(1) }
|
|
45
|
+
|
|
46
|
+
if (rollbackIdx >= 0) {
|
|
47
|
+
const dir = args[rollbackIdx + 1]
|
|
48
|
+
if (!dir || !existsSync(dir)) fail(`找不到备份目录:${dir}`)
|
|
49
|
+
cpSync(join(dir, 'package.json'), pkgFile)
|
|
50
|
+
const patchBak = join(dir, 'cordis.patch.yml')
|
|
51
|
+
if (existsSync(patchBak)) cpSync(patchBak, join(profileDir, 'cordis.patch.yml'))
|
|
52
|
+
console.log(`✅ 已回滚 package.json${existsSync(patchBak) ? ' + cordis.patch.yml' : ''}(来自 ${dir})`)
|
|
53
|
+
console.log(' 下一步:重启 DSH Desktop(由用户手动)')
|
|
54
|
+
process.exit(0)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!existsSync(pkgFile)) fail(`profile 不存在:${pkgFile}`)
|
|
58
|
+
if (!existsSync(join(PKG_DIR, 'package.json'))) fail(`插件不存在:${PKG_DIR}`)
|
|
59
|
+
|
|
60
|
+
const before = JSON.parse(readFileSync(pkgFile, 'utf8'))
|
|
61
|
+
const deps = before.dependencies || {}
|
|
62
|
+
const bundles = (before.dsh && before.dsh.profile && before.dsh.profile.bundles) || []
|
|
63
|
+
const needDep = deps[PKG] !== `file:${PKG_DIR}`
|
|
64
|
+
const needBundle = !bundles.includes(PKG)
|
|
65
|
+
|
|
66
|
+
console.log(`profile: ${profileDir}`)
|
|
67
|
+
console.log(` 依赖 ${PKG}: ${needDep ? '需要添加' : '已存在'}`)
|
|
68
|
+
console.log(` bundles: ${needBundle ? '需要追加' : '已包含'}`)
|
|
69
|
+
|
|
70
|
+
const pnpm = resolvePnpm()
|
|
71
|
+
if (!pnpm) console.log(' ⚠️ 找不到 pnpm:--apply 时只能改 manifest,需你手动 pnpm install')
|
|
72
|
+
|
|
73
|
+
// 现有 @whyshu 软链(pnpm install 可能重建)
|
|
74
|
+
const nmWhyshu = join(profileDir, 'node_modules', '@whyshu')
|
|
75
|
+
if (existsSync(nmWhyshu)) {
|
|
76
|
+
for (const d of ['argent-desktop', 'argent-erp-ui']) {
|
|
77
|
+
const p = join(nmWhyshu, d)
|
|
78
|
+
if (!existsSync(p)) continue
|
|
79
|
+
const st = lstatSync(p)
|
|
80
|
+
console.log(` node_modules/@whyshu/${d}: ${st.isSymbolicLink() ? `symlink → ${readlinkSync(p)}` : `目录(真实路径 ${realpathSync(p)})`}`)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!apply) {
|
|
85
|
+
console.log('\n[dry-run] 未写入。要执行:node scripts/erp-ui-install.mjs --apply')
|
|
86
|
+
process.exit(0)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const bakDir = join(profileDir, `backup-erpui-${ts}`)
|
|
90
|
+
mkdirSync(bakDir, { recursive: true })
|
|
91
|
+
cpSync(pkgFile, join(bakDir, 'package.json'))
|
|
92
|
+
if (existsSync(join(profileDir, 'cordis.patch.yml'))) cpSync(join(profileDir, 'cordis.patch.yml'), join(bakDir, 'cordis.patch.yml'))
|
|
93
|
+
console.log(`\n备份:${bakDir}`)
|
|
94
|
+
|
|
95
|
+
const after = JSON.parse(JSON.stringify(before))
|
|
96
|
+
after.dependencies = { ...(after.dependencies || {}), [PKG]: `file:${PKG_DIR}` }
|
|
97
|
+
after.dsh = after.dsh || {}
|
|
98
|
+
after.dsh.profile = after.dsh.profile || {}
|
|
99
|
+
const b = after.dsh.profile.bundles || []
|
|
100
|
+
if (!b.includes(PKG)) b.push(PKG)
|
|
101
|
+
after.dsh.profile.bundles = b
|
|
102
|
+
writeFileSync(pkgFile, JSON.stringify(after, null, 2) + '\n')
|
|
103
|
+
console.log('✅ package.json 已更新')
|
|
104
|
+
|
|
105
|
+
if (pnpm) {
|
|
106
|
+
console.log(`\n$ ${pnpm} install --ignore-scripts(在 ${profileDir})`)
|
|
107
|
+
const r = spawnSync(pnpm, ['install', '--ignore-scripts'], { cwd: profileDir, stdio: 'inherit' })
|
|
108
|
+
if (r.status !== 0) fail(`pnpm install 失败(status=${r.status})`)
|
|
109
|
+
} else {
|
|
110
|
+
console.log('⚠️ 跳过 pnpm install(未找到 pnpm)——请手动执行后再重启')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// install 后核软链(桌面插件历史上被重建过)
|
|
114
|
+
const desktopLink = join(nmWhyshu, 'argent-desktop')
|
|
115
|
+
const repoDesktop = join(REPO, 'plugins', 'argent-desktop')
|
|
116
|
+
if (existsSync(desktopLink) && !lstatSync(desktopLink).isSymbolicLink()) {
|
|
117
|
+
const real = realpathSync(desktopLink)
|
|
118
|
+
if (real !== realpathSync(repoDesktop)) {
|
|
119
|
+
console.log(`⚠️ @whyshu/argent-desktop 已不是软链(${real})⇒ 恢复软链,否则改仓库代码不生效`)
|
|
120
|
+
unlinkSync(desktopLink)
|
|
121
|
+
symlinkSync(repoDesktop, desktopLink)
|
|
122
|
+
console.log('✅ 软链已恢复')
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
console.log(`\n完成。回滚:node scripts/erp-ui-install.mjs --rollback ${bakDir}`)
|
|
127
|
+
console.log('生效需要重启 DSH Desktop(⛔ 本脚本不重启,由用户手动)')
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* erp-ui-preflight.mjs —— 重启**前**的结构自检(v0.9.0)
|
|
4
|
+
*
|
|
5
|
+
* 为什么需要:改完 profile 到重启之间,任何一环错都只会表现为"重启后看不到面板",且没有报错。
|
|
6
|
+
* 本脚本把"能提前发现"的都查一遍,避免拿一次重启去试错。
|
|
7
|
+
*
|
|
8
|
+
* 查什么(全部离线、不碰网络):
|
|
9
|
+
* 1. profile package.json:依赖存在 / bundles 含该包 / JSON 合法
|
|
10
|
+
* 2. node_modules 软链指向仓库且 package.json 可解析
|
|
11
|
+
* 3. cordis.patch.yml 含 gateway insert(且旧的 engine/ml 两条已并掉)
|
|
12
|
+
* 4. 客户端 bundle 能被 loader 装载并注册 3 个 slot(用 vm 桩,不需要浏览器)
|
|
13
|
+
* 5. 网关 insert 指向的文件存在
|
|
14
|
+
*
|
|
15
|
+
* 退出码:0 全通 | 1 有 FAIL
|
|
16
|
+
*/
|
|
17
|
+
import { readFileSync, existsSync, lstatSync, readlinkSync, realpathSync } from 'node:fs'
|
|
18
|
+
import { homedir } from 'node:os'
|
|
19
|
+
import { join, resolve } from 'node:path'
|
|
20
|
+
|
|
21
|
+
const REPO = resolve(import.meta.dirname, '..')
|
|
22
|
+
const profileArg = process.argv.includes('--profile') ? process.argv[process.argv.indexOf('--profile') + 1] : 'desktop'
|
|
23
|
+
const profileDir = join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'profiles', profileArg)
|
|
24
|
+
const PKG = '@whyshu/argent-erp-ui'
|
|
25
|
+
|
|
26
|
+
let fails = 0
|
|
27
|
+
const ok = (c, msg) => { console.log(`${c ? '✅' : '❌'} ${msg}`); if (!c) fails++ }
|
|
28
|
+
|
|
29
|
+
// 1) package.json
|
|
30
|
+
let pkg = null
|
|
31
|
+
try { pkg = JSON.parse(readFileSync(join(profileDir, 'package.json'), 'utf8')) } catch (e) { ok(false, `package.json 读不了:${e.message}`) }
|
|
32
|
+
if (pkg) {
|
|
33
|
+
ok(Boolean(pkg.dependencies && pkg.dependencies[PKG]), `依赖 ${PKG} 已登记`)
|
|
34
|
+
const bundles = (pkg.dsh && pkg.dsh.profile && pkg.dsh.profile.bundles) || []
|
|
35
|
+
ok(bundles.includes(PKG), `bundles 含 ${PKG}`)
|
|
36
|
+
ok(Array.isArray(bundles) && bundles.length > 0, `bundles 非空(${bundles.length} 条)`)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 2) node_modules
|
|
40
|
+
const nm = join(profileDir, 'node_modules', '@whyshu', 'argent-erp-ui')
|
|
41
|
+
if (!existsSync(nm)) ok(false, `node_modules 缺 ${PKG}`)
|
|
42
|
+
else {
|
|
43
|
+
const st = lstatSync(nm)
|
|
44
|
+
ok(st.isSymbolicLink(), `node_modules/${PKG} 是软链(改仓库代码即生效)`)
|
|
45
|
+
if (st.isSymbolicLink()) {
|
|
46
|
+
const target = realpathSync(nm)
|
|
47
|
+
ok(target === realpathSync(join(REPO, 'plugins', 'argent-erp-ui')), `软链指向仓库(${target})`)
|
|
48
|
+
}
|
|
49
|
+
ok(existsSync(join(nm, 'package.json')), '包 package.json 可解析')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 3) patch
|
|
53
|
+
const patch = join(profileDir, 'cordis.patch.yml')
|
|
54
|
+
if (!existsSync(patch)) ok(false, '缺 cordis.patch.yml')
|
|
55
|
+
else {
|
|
56
|
+
const txt = readFileSync(patch, 'utf8')
|
|
57
|
+
// MCP 形态二选一:单条网关(target)或旧的 engine+ml 两条(兼容态,同样能用)
|
|
58
|
+
const hasGateway = txt.includes('mcp-argent-gateway')
|
|
59
|
+
ok(txt.includes('mcp-argent-engine') || hasGateway, `patch 至少有一条 argent MCP(${hasGateway ? '网关' : 'engine/ml'})`)
|
|
60
|
+
ok(!(hasGateway && txt.includes('mcp-argent-engine')), '网关与旧 engine 条目不同时存在(不重复工具)')
|
|
61
|
+
if (hasGateway) ok(txt.includes('core/mcp/gateway.mjs'), 'patch 指向 gateway.mjs')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 4) bundle 装载(vm 桩)
|
|
65
|
+
const bundle = join(REPO, 'plugins', 'argent-erp-ui', 'dist', 'client.js')
|
|
66
|
+
if (!existsSync(bundle)) ok(false, '缺 dist/client.js')
|
|
67
|
+
else {
|
|
68
|
+
const src = readFileSync(bundle, 'utf8')
|
|
69
|
+
const regs = []
|
|
70
|
+
let mod = null
|
|
71
|
+
const reactStub = { createElement: () => null, useState: (v) => [v, () => {}], useEffect: () => {}, useCallback: (f) => f }
|
|
72
|
+
const windowStub = { __ModuleLoader__: { load: ({ factory }) => { mod = factory((n) => (n === 'react' ? reactStub : {})) } } }
|
|
73
|
+
try {
|
|
74
|
+
new Function('window', src)(windowStub)
|
|
75
|
+
ok(Boolean(mod && typeof mod.apply === 'function'), 'bundle 可装载(导出 apply)')
|
|
76
|
+
mod.apply({ effect: (f) => f(), slots: { inject: (n, f) => f(), register: (m) => regs.push(m.name) } })
|
|
77
|
+
const need = ['sidebar.right.pane.tab', 'sidebar.right.pane.tab.title', 'sidebar.toggle.badge']
|
|
78
|
+
ok(need.every((n) => regs.includes(n)), `注册了 3 个 slot(${regs.length})`)
|
|
79
|
+
} catch (e) { ok(false, `bundle 装载失败:${e.message}`) }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 4.5) 插件不得跨目录 import 仓库 core/lib(复制安装时会 ERR_MODULE_NOT_FOUND ⇒ web boot 失败)
|
|
83
|
+
{
|
|
84
|
+
const srcFiles = ['src/index.js', 'src/data.mjs']
|
|
85
|
+
let bad = []
|
|
86
|
+
for (const f of srcFiles) {
|
|
87
|
+
const fp = join(REPO, 'plugins', 'argent-erp-ui', f)
|
|
88
|
+
if (!existsSync(fp)) continue
|
|
89
|
+
const t = readFileSync(fp, 'utf8')
|
|
90
|
+
const m = t.match(/from\s+['"](\.\.\/\.\.\/\.\.[^'"]+)['"]/)
|
|
91
|
+
if (m) bad.push(`${f} → ${m[1]}`)
|
|
92
|
+
}
|
|
93
|
+
ok(bad.length === 0, bad.length ? `插件存在跨目录 import(复制安装会崩):${bad.join('; ')}` : '插件不依赖仓库相对路径(复制安装安全)')
|
|
94
|
+
for (const v of ['vendor/account-token.mjs', 'vendor/redact.mjs']) {
|
|
95
|
+
ok(existsSync(join(REPO, 'plugins', 'argent-erp-ui', 'src', v)), `vendor 副本存在:${v}`)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 5) gateway 文件
|
|
100
|
+
ok(existsSync(join(REPO, 'core', 'mcp', 'gateway.mjs')), 'core/mcp/gateway.mjs 存在')
|
|
101
|
+
ok(existsSync(join(REPO, 'core', 'mcp', 'erp-server.mjs')), 'core/mcp/erp-server.mjs 存在')
|
|
102
|
+
|
|
103
|
+
console.log(fails ? `\n❌ ${fails} 项未通过 —— 先修,别拿重启试错` : '\n✅ 结构自检全通:可以重启 DSH Desktop,之后跑 scripts/erp-ui-verify.mjs')
|
|
104
|
+
process.exit(fails ? 1 : 0)
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* erp-ui-verify.mjs —— 重启后 30 秒验收:面板端点是否真的挂上了(v0.9.0)
|
|
4
|
+
*
|
|
5
|
+
* 为什么需要:改完 profile 不重启,dsh 里**什么都看不到也没有报错**(路由 404/401 落到宿主兜底)。
|
|
6
|
+
* 判据只能来自"真打一次端点"。
|
|
7
|
+
*
|
|
8
|
+
* 用法:
|
|
9
|
+
* node scripts/erp-ui-verify.mjs # 默认打 http://127.0.0.1:55866
|
|
10
|
+
* node scripts/erp-ui-verify.mjs --base http://127.0.0.1:55866
|
|
11
|
+
*
|
|
12
|
+
* 退出码:0 全通 | 1 端点未就绪(多半是没重启) | 2 端点存在但数据取不到(token/网络/权限)
|
|
13
|
+
*/
|
|
14
|
+
import { execSync } from 'node:child_process'
|
|
15
|
+
import { statSync } from 'node:fs'
|
|
16
|
+
import { join } from 'node:path'
|
|
17
|
+
|
|
18
|
+
const args = process.argv.slice(2)
|
|
19
|
+
|
|
20
|
+
/** 自动发现 dsh 桌面进程监听的端口(每次启动都会变,别让用户自己查) */
|
|
21
|
+
function discoverPorts() {
|
|
22
|
+
const ports = new Set()
|
|
23
|
+
try {
|
|
24
|
+
const out = execSync('lsof -nP -iTCP -sTCP:LISTEN 2>/dev/null || true', { encoding: 'utf8', timeout: 8000 })
|
|
25
|
+
for (const line of out.split('\n')) {
|
|
26
|
+
if (!/DeepSeek|dsh/i.test(line)) continue
|
|
27
|
+
const m = line.match(/:(\d{4,5})\s+\(LISTEN\)/)
|
|
28
|
+
if (m) ports.add(Number(m[1]))
|
|
29
|
+
}
|
|
30
|
+
} catch { /* 忽略 */ }
|
|
31
|
+
return [...ports].sort((a, b) => a - b)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function pickBase() {
|
|
35
|
+
const explicit = args.includes('--base') ? args[args.indexOf('--base') + 1] : process.env.DSH_WEB_BASE
|
|
36
|
+
if (explicit) return explicit.replace(/\/+$/, '')
|
|
37
|
+
const ports = discoverPorts()
|
|
38
|
+
if (!ports.length) return 'http://127.0.0.1:55866'
|
|
39
|
+
for (const port of ports) {
|
|
40
|
+
const b = `http://127.0.0.1:${port}`
|
|
41
|
+
try {
|
|
42
|
+
const r = await fetch(`${b}/api/argent-desktop/health`, { signal: AbortSignal.timeout(1500) })
|
|
43
|
+
if (r.status > 0) return b // 该端口能应答(200/401 都算"是 dsh 服务")
|
|
44
|
+
} catch { /* 试下一个 */ }
|
|
45
|
+
}
|
|
46
|
+
return `http://127.0.0.1:${ports[0]}`
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** App 启动时间 vs 客户端 bundle 修改时间:bundle 更新更晚 ⇒ 你跑的是旧版(不重启就不生效) */
|
|
50
|
+
function bundleStaleness() {
|
|
51
|
+
try {
|
|
52
|
+
// pgrep -f 在这里匹配不到(实测返回空),用 ps + grep 更可靠
|
|
53
|
+
const pid = execSync("ps -eo pid,command | grep dsh-desktop-host | grep -v grep | awk '{print $1}' | head -1", { encoding: 'utf8' }).trim()
|
|
54
|
+
if (!pid) return null
|
|
55
|
+
const started = execSync(`ps -p ${pid} -o lstart=`, { encoding: 'utf8' }).trim()
|
|
56
|
+
const startMs = Date.parse(started)
|
|
57
|
+
const bundle = statSync(join(process.cwd(), 'plugins', 'argent-erp-ui', 'dist', 'client.js')).mtimeMs
|
|
58
|
+
if (Number.isNaN(startMs)) return null
|
|
59
|
+
return { started, startMs, bundleMs: bundle, stale: bundle > startMs }
|
|
60
|
+
} catch { return null }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const base = await pickBase()
|
|
64
|
+
|
|
65
|
+
const get = async (path) => {
|
|
66
|
+
const r = await fetch(`${base}${path}`, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(15000) })
|
|
67
|
+
const text = await r.text()
|
|
68
|
+
let body = null
|
|
69
|
+
try { body = JSON.parse(text) } catch { body = { raw: text.slice(0, 120) } }
|
|
70
|
+
return { status: r.status, body }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const line = (ok, msg) => console.log(`${ok ? '✅' : '❌'} ${msg}`)
|
|
74
|
+
|
|
75
|
+
;(async () => {
|
|
76
|
+
console.log(`base: ${base}\n`)
|
|
77
|
+
const fresh = bundleStaleness()
|
|
78
|
+
if (fresh && fresh.stale) {
|
|
79
|
+
console.log(`⚠️ 客户端 bundle 比 App 启动时间新(bundle ${new Date(fresh.bundleMs).toLocaleString()} > 启动 ${new Date(fresh.startMs).toLocaleString()})`)
|
|
80
|
+
console.log(' ⇒ 你看到的仍是旧版面板;**退出 App 再打开**后才生效\n')
|
|
81
|
+
}
|
|
82
|
+
let h
|
|
83
|
+
try { h = await get('/api/argent-erp/health') } catch (e) {
|
|
84
|
+
line(false, `连不上 dsh 服务:${e.message}`)
|
|
85
|
+
console.log('\n⇒ 先确认 DSH Desktop 在运行;端口不是 55866 时用 --base 指定')
|
|
86
|
+
process.exit(1)
|
|
87
|
+
}
|
|
88
|
+
if (h.status !== 200 || !h.body || h.body.ok !== true) {
|
|
89
|
+
line(false, `/api/argent-erp/health → HTTP ${h.status}(路由未注册)`)
|
|
90
|
+
console.log('\n⇒ 插件尚未加载:**重启 DSH Desktop**(⛔ 不能由 agent 重启)')
|
|
91
|
+
console.log(' 回滚:node scripts/erp-ui-install.mjs --rollback ~/.dsh/profiles/desktop/backup-erpui-<ts>')
|
|
92
|
+
process.exit(1)
|
|
93
|
+
}
|
|
94
|
+
line(true, `/health 200(version=${h.body.version})`)
|
|
95
|
+
if (h.body.clientPingAt) console.log(` ✅ 客户端 bundle 已加载(ping ${h.body.clientPingAt})`)
|
|
96
|
+
else console.log(' ⚠️ 客户端 bundle 尚未 ping:面板不会出现(bundle 未加载,或还没触发)')
|
|
97
|
+
|
|
98
|
+
let failed = 0
|
|
99
|
+
for (const p of ['/api/argent-erp/whoami', '/api/argent-erp/overview', '/api/argent-erp/timeline', '/api/argent-erp/badge']) {
|
|
100
|
+
const r = await get(p)
|
|
101
|
+
const ok = r.status === 200 && r.body && r.body.ok === true
|
|
102
|
+
line(ok, `${p} → ${r.status}${ok ? '' : `(${(r.body && (r.body.message || r.body.error)) || '无 body'})`}`)
|
|
103
|
+
if (!ok) failed++
|
|
104
|
+
if (ok && p.endsWith('/timeline')) {
|
|
105
|
+
const tl = r.body.data || {}
|
|
106
|
+
console.log(` 时间线:${tl.total} 个流程,${(tl.days || []).length} 天`)
|
|
107
|
+
}
|
|
108
|
+
if (ok && p.endsWith('/overview')) {
|
|
109
|
+
const k = r.body.data.kpis || {}
|
|
110
|
+
console.log(` KPI:待处理 ${k.pending} · 在办 ${k.inProgress} · 今日完成 ${k.doneToday} · 执行机 ${k.agentsOnline}/${k.agentsTotal}`)
|
|
111
|
+
console.log(` 待办 ${(r.body.data.workItems || []).length} 条 · 凭据来源 ${r.body.data.authSource || '?'}`)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// 端到端:拿时间线第一条 → 打开它的 flow 详情(面板点击走的正是这条路径)
|
|
115
|
+
try {
|
|
116
|
+
const tl = await get('/api/argent-erp/timeline?days=30')
|
|
117
|
+
const ev = tl.body && tl.body.data && tl.body.data.days && tl.body.data.days[0] && tl.body.data.days[0].events[0]
|
|
118
|
+
if (ev && ev.id) {
|
|
119
|
+
const fd = await get(`/api/argent-erp/flow?id=${encodeURIComponent(ev.id)}`)
|
|
120
|
+
const nodes = fd.body && fd.body.data && fd.body.data.nodes
|
|
121
|
+
line(fd.status === 200 && Array.isArray(nodes) && nodes.length > 0, `/flow?id=${ev.id.slice(0, 8)}… → ${fd.status}(${Array.isArray(nodes) ? nodes.length : 0} 个节点)`)
|
|
122
|
+
} else {
|
|
123
|
+
console.log(' (时间线暂无数据,跳过 /flow 端到端)')
|
|
124
|
+
}
|
|
125
|
+
} catch (e) {
|
|
126
|
+
line(false, `/flow 端到端失败:${e.message}`)
|
|
127
|
+
failed++
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (failed) {
|
|
131
|
+
console.log('\n⇒ 端点已挂但取数失败:检查账号 token(~/.dsh/.credentials.yaml 的 WHYSHU_API_KEY)与网络')
|
|
132
|
+
process.exit(2)
|
|
133
|
+
}
|
|
134
|
+
console.log('\n全部通过。侧栏应出现「ERP」tab;有待办时侧栏开关上会出现红色角标。')
|
|
135
|
+
})()
|
|
@@ -62,6 +62,19 @@ export const PLUGIN_PACKAGES = [
|
|
|
62
62
|
// Desktop 端 ERP 连接器(2026-10-29):单 bundle + 单 insert,只做 office/ERP 通道
|
|
63
63
|
// (快照/对话/建会话/本地任务),不装 core/skin/flow/gateway ⇒ 与 web 端套装解耦。
|
|
64
64
|
{ id: 'argent-desktop', npm: `${NPM_SCOPE}/argent-desktop` },
|
|
65
|
+
// web 端单 bundle(2026-11-06,0.9.0 起):皮肤/积分/登录/ERP 连接器/伞伞一次装;
|
|
66
|
+
// 与 argent-desktop 同构(单 bundle + 单 insert)。此前漏登记 ⇒ 0.9.0 不是走本发布器发的。
|
|
67
|
+
// ⚠️ 2026-11-07 起两者已合并为 `@whyshu/argent`(见下),本行只为历史版本/回滚保留。
|
|
68
|
+
{ id: 'argent-web', npm: `${NPM_SCOPE}/argent-web` },
|
|
69
|
+
// 单插件(2026-11-07):web + DSH Desktop 同一 bundle;同时**复用启动器旧名**
|
|
70
|
+
// `@whyshu/argent`(启动器 0.1.x 退役,0.2.0 起该包名即插件)。
|
|
71
|
+
{ id: 'argent', npm: `${NPM_SCOPE}/argent` },
|
|
72
|
+
// ERP 会话视图 + 六禾园办公室助理 preset(2026-11-07):**角色随插件**形态——
|
|
73
|
+
// 一次 `install_bundle` 同时落「对话顶部 ERP tab」与「preset-argent-office 行」,
|
|
74
|
+
// 用户只装这一个包就能在 preset 选择器里看到「六禾园办公室助理」。
|
|
75
|
+
// ⚠️ 依赖同机 `@whyshu/argent`(提供 ERP MCP 工具 + whyshu provider);缺它时角色被
|
|
76
|
+
// office-guard 安全降级为「无工具」,宿主 /api/argent-erp/health 的 erpTools=0 会提示。
|
|
77
|
+
{ id: 'argent-erp', npm: `${NPM_SCOPE}/argent-erp` },
|
|
65
78
|
]
|
|
66
79
|
|
|
67
80
|
/**
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* mcp-gateway-switch.mjs —— 把 profile 里两条 MCP(engine + ml)换成**一条网关**(v0.9.0)
|
|
4
|
+
*
|
|
5
|
+
* 为什么需要脚本:patch 是手写 YAML,手工删两块 insert 很容易删错行/漏删注释;
|
|
6
|
+
* 本脚本按 id 定位、整块替换,dry-run 先打印,失败可一键回滚。
|
|
7
|
+
*
|
|
8
|
+
* 用法:
|
|
9
|
+
* node scripts/mcp-gateway-switch.mjs # dry-run(只打印将删除/插入的块)
|
|
10
|
+
* node scripts/mcp-gateway-switch.mjs --apply # 备份 + 写入
|
|
11
|
+
* node scripts/mcp-gateway-switch.mjs --rollback <备份文件>
|
|
12
|
+
* node scripts/mcp-gateway-switch.mjs --profile web --data-dir ~/.dsh/argent/gateway-web # web 宿主独立台账
|
|
13
|
+
*
|
|
14
|
+
* ⚠️ 改完必须重启 DSH Desktop;重启后跑 scripts/erp-ui-verify.mjs 与 MCP 工具列表检查。
|
|
15
|
+
*/
|
|
16
|
+
import { copyFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
17
|
+
import { homedir } from 'node:os'
|
|
18
|
+
import { join, resolve } from 'node:path'
|
|
19
|
+
|
|
20
|
+
const REPO = resolve(import.meta.dirname, '..')
|
|
21
|
+
const args = process.argv.slice(2)
|
|
22
|
+
const apply = args.includes('--apply')
|
|
23
|
+
const profile = args.includes('--profile') ? args[args.indexOf('--profile') + 1] : 'desktop'
|
|
24
|
+
const rollback = args.includes('--rollback') ? args[args.indexOf('--rollback') + 1] : ''
|
|
25
|
+
// 同一台机器跑多个 dsh 宿主时,各自用独立数据目录,避免并发写同一份 metering/audit
|
|
26
|
+
const dataDir = args.includes('--data-dir') ? args[args.indexOf('--data-dir') + 1] : join(homedir(), '.dsh', 'argent')
|
|
27
|
+
const patchFile = join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'profiles', profile, 'cordis.patch.yml')
|
|
28
|
+
|
|
29
|
+
if (rollback) {
|
|
30
|
+
if (!existsSync(rollback)) { console.error(`❌ 备份不存在:${rollback}`); process.exit(1) }
|
|
31
|
+
copyFileSync(rollback, patchFile)
|
|
32
|
+
console.log(`✅ 已回滚 ${patchFile} ← ${rollback}`)
|
|
33
|
+
console.log(' 下一步:重启 DSH Desktop')
|
|
34
|
+
process.exit(0)
|
|
35
|
+
}
|
|
36
|
+
if (!existsSync(patchFile)) { console.error(`❌ 找不到 ${patchFile}`); process.exit(1) }
|
|
37
|
+
|
|
38
|
+
const OLD_IDS = ['mcp-argent-engine', 'mcp-argent-ml']
|
|
39
|
+
const GATEWAY_BLOCK = `# v0.9.0(2026-11-04):MCP 网关——一个 endpoint 聚合 engine.* / erp.* / ml.*
|
|
40
|
+
- insert:
|
|
41
|
+
- id: mcp-argent-gateway
|
|
42
|
+
name: '@deepseek-ai/dsh-mcp-client'
|
|
43
|
+
config:
|
|
44
|
+
transport: stdio
|
|
45
|
+
serverName: argent
|
|
46
|
+
command: /opt/homebrew/bin/node
|
|
47
|
+
args:
|
|
48
|
+
- ${join(REPO, 'core', 'mcp', 'gateway.mjs')}
|
|
49
|
+
cwd: ${REPO}
|
|
50
|
+
env:
|
|
51
|
+
ARGENT_DATA_DIR: ${dataDir}
|
|
52
|
+
ARGENT_TENANT: ly-0001
|
|
53
|
+
ARGENT_ENGINE_PY: ${join(homedir(), '.dsh', 'argent', 'venv', 'bin', 'python3')}
|
|
54
|
+
ARGENT_ENGINE_DIR: ${REPO}
|
|
55
|
+
ARGENT_GATEWAY_ML: "1"
|
|
56
|
+
toolCallTimeoutMs: 180000
|
|
57
|
+
failOnStartupError: false`
|
|
58
|
+
|
|
59
|
+
const text = readFileSync(patchFile, 'utf8')
|
|
60
|
+
const lines = text.split('\n')
|
|
61
|
+
const keep = []
|
|
62
|
+
const removed = []
|
|
63
|
+
let i = 0
|
|
64
|
+
while (i < lines.length) {
|
|
65
|
+
const line = lines[i]
|
|
66
|
+
const isOld = OLD_IDS.some((id) => line.includes(`id: ${id}`))
|
|
67
|
+
if (!isOld) { keep.push(line); i++; continue }
|
|
68
|
+
// 向上吃掉紧邻的注释块(# 开头的连续行)
|
|
69
|
+
let start = keep.length - 1
|
|
70
|
+
while (start >= 0 && keep[start].trim().startsWith('#')) start--
|
|
71
|
+
const header = keep.splice(start + 1)
|
|
72
|
+
// 向下吃掉到 failOnStartupError: false 为止
|
|
73
|
+
let j = i
|
|
74
|
+
while (j < lines.length && !lines[j].includes('failOnStartupError: false')) j++
|
|
75
|
+
removed.push({ id: OLD_IDS.find((id) => line.includes(`id: ${id}`)), from: i + 1, to: j + 1, header: header.length })
|
|
76
|
+
i = j + 1
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const hasGateway = keep.some((l) => l.includes('id: mcp-argent-gateway'))
|
|
80
|
+
const out = hasGateway ? keep.join('\n') : `${keep.join('\n').replace(/\s+$/, '')}\n\n${GATEWAY_BLOCK}\n`
|
|
81
|
+
|
|
82
|
+
if (!removed.length && hasGateway) {
|
|
83
|
+
console.log('✅ 已经是网关形态(无 engine/ml 条目),无需改动')
|
|
84
|
+
process.exit(0)
|
|
85
|
+
}
|
|
86
|
+
console.log(`profile: ${patchFile}`)
|
|
87
|
+
for (const r of removed) console.log(` 将删除 ${r.id}(第 ${r.from}-${r.to} 行,含注释 ${r.header} 行)`)
|
|
88
|
+
console.log(hasGateway ? ' 网关条目已存在(只删旧条目)' : ' 将插入 mcp-argent-gateway(serverName=argent)')
|
|
89
|
+
|
|
90
|
+
if (!apply) {
|
|
91
|
+
console.log('\n[dry-run] 未写入。执行:node scripts/mcp-gateway-switch.mjs --apply')
|
|
92
|
+
process.exit(0)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const backup = `${patchFile}.bak-gatewayswitch-${Date.now()}`
|
|
96
|
+
copyFileSync(patchFile, backup)
|
|
97
|
+
writeFileSync(patchFile, out)
|
|
98
|
+
console.log(`\n✅ 已写入(备份:${backup})`)
|
|
99
|
+
console.log(` 回滚:node scripts/mcp-gateway-switch.mjs --rollback ${backup}`)
|
|
100
|
+
console.log(' 下一步:重启 DSH Desktop;会话里工具应显示为 engine.* / erp.*(不再有 argent-engine 前缀)')
|