@whyshu/argent-engine 0.8.0-rc.8 → 0.13.27

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 (113) hide show
  1. package/MANIFEST.json +109 -43
  2. package/bin/runtime-install.mjs +92 -0
  3. package/engine/VERSION +1 -1
  4. package/engine/configs/billing-actions.json +30 -0
  5. package/engine/configs/mcp-tools.snapshot.json +47 -0
  6. package/engine/core/contracts/argent.contracts.json +3 -3
  7. package/engine/core/contracts/verbs.schema.json +64 -1
  8. package/engine/core/lib/account-token.mjs +37 -0
  9. package/engine/core/lib/contract.mjs +30 -0
  10. package/engine/core/lib/redact.mjs +34 -0
  11. package/engine/core/mcp/billing-upload.mjs +77 -0
  12. package/engine/core/mcp/erp-server.mjs +300 -0
  13. package/engine/core/mcp/gateway.mjs +333 -0
  14. package/engine/core/mcp/meter.mjs +101 -0
  15. package/engine/core/mcp/server.mjs +416 -2
  16. package/engine/core/mcp/vault.mjs +78 -0
  17. package/engine/scripts/appointment-worker.mjs +456 -35
  18. package/engine/scripts/appointment_grab.py +1389 -264
  19. package/engine/scripts/appointment_rules.py +118 -0
  20. package/engine/scripts/argent-timers.mjs +227 -0
  21. package/engine/scripts/argent-web-preflight.mjs +123 -0
  22. package/engine/scripts/argent-web-verify.mjs +105 -0
  23. package/engine/scripts/billing-upload.mjs +26 -0
  24. package/engine/scripts/build-doc-index.mjs +68 -0
  25. package/engine/scripts/build-engine-package.mjs +7 -1
  26. package/engine/scripts/capability-packs.lock.json +323 -300
  27. package/engine/scripts/check-docs-drift.mjs +51 -4
  28. package/engine/scripts/check-version-consistency.mjs +14 -1
  29. package/engine/scripts/ci-run.sh +2 -2
  30. package/engine/scripts/collect-intel.mjs +108 -0
  31. package/engine/scripts/daily-report-timer-plist.sh +18 -4
  32. package/engine/scripts/daily-report-timers.sh +36 -3
  33. package/engine/scripts/daily-report.mjs +78 -2
  34. package/engine/scripts/doc-status.mjs +212 -0
  35. package/engine/scripts/dsh-web-doctor.mjs +84 -0
  36. package/engine/scripts/engine-manifest.mjs +90 -0
  37. package/engine/scripts/engine-runtime-install.mjs +92 -0
  38. package/engine/scripts/erp-ui-install.mjs +127 -0
  39. package/engine/scripts/erp-ui-preflight.mjs +104 -0
  40. package/engine/scripts/erp-ui-verify.mjs +135 -0
  41. package/engine/scripts/flow-requirements.json +122 -99
  42. package/engine/scripts/full-exec-worker.mjs +251 -0
  43. package/engine/scripts/gen-preset-rows.mjs +1 -1
  44. package/engine/scripts/invoice_lip_runner.py +1 -0
  45. package/engine/scripts/invoice_runner.py +17 -6
  46. package/engine/scripts/invoice_stageb.py +21 -4
  47. package/engine/scripts/lib/bootcheck-wiring.mjs +7 -5
  48. package/engine/scripts/lib/intel-card.mjs +43 -0
  49. package/engine/scripts/lib/invoice_names.py +23 -0
  50. package/engine/scripts/lib/ml-ads-core.mjs +100 -18
  51. package/engine/scripts/lib/ml-ads-rules.mjs +275 -0
  52. package/engine/scripts/lib/ml-bridge-auth.mjs +50 -0
  53. package/engine/scripts/lib/ml-category-core.mjs +120 -0
  54. package/engine/scripts/lib/ml-insight-core.mjs +621 -0
  55. package/engine/scripts/lib/ml-insight-facts.mjs +424 -0
  56. package/engine/scripts/lib/ml-items.mjs +40 -0
  57. package/engine/scripts/lib/ml-listing-core.mjs +342 -0
  58. package/engine/scripts/lib/ml-market-core.mjs +774 -0
  59. package/engine/scripts/lib/plugin-packages.mjs +13 -0
  60. package/engine/scripts/lib/webdriver_ipc.py +61 -1
  61. package/engine/scripts/line_pack.py +196 -0
  62. package/engine/scripts/mcp-gateway-switch.mjs +100 -0
  63. package/engine/scripts/migrate-providers.mjs +3 -3
  64. package/engine/scripts/ml-ads-advice.mjs +140 -0
  65. package/engine/scripts/ml-ads.mjs +221 -0
  66. package/engine/scripts/ml-category-baseline.mjs +174 -0
  67. package/engine/scripts/ml-insight-diagnose.mjs +247 -0
  68. package/engine/scripts/ml-insight-run.sh +183 -0
  69. package/engine/scripts/ml-insight-timers.sh +224 -0
  70. package/engine/scripts/ml-listing-audit.mjs +170 -0
  71. package/engine/scripts/ml-market-matrix.mjs +84 -0
  72. package/engine/scripts/ml-market-snapshot.mjs +261 -0
  73. package/engine/scripts/ml-messages.mjs +145 -0
  74. package/engine/scripts/ml-oauth-setup.mjs +1 -1
  75. package/engine/scripts/npm-publish-argent.mjs +14 -0
  76. package/engine/scripts/ops-codefix-pr.mjs +87 -0
  77. package/engine/scripts/ops-codefix-queue.mjs +30 -0
  78. package/engine/scripts/ops-digest.mjs +98 -0
  79. package/engine/scripts/ops-verify.mjs +67 -0
  80. package/engine/scripts/orchestrator.py +410 -20
  81. package/engine/scripts/orchestrator_br.py +146 -4
  82. package/engine/scripts/plugin-bootcheck.mjs +50 -1
  83. package/engine/scripts/publish-engine.mjs +111 -0
  84. package/engine/scripts/restart-dsh-with-tunnel.sh +129 -0
  85. package/engine/scripts/skuflow_invoice_runner.py +43 -3
  86. package/engine/scripts/v0.9-acceptance.mjs +107 -0
  87. package/engine/scripts/vertical-lint.mjs +12 -1
  88. package/engine/scripts/web-switch.mjs +121 -0
  89. package/engine/scripts/wenyao_fill_template.py +52 -15
  90. package/engine/scripts/wenyao_run.py +2 -1
  91. package/engine/skills/README.md +3 -3
  92. package/engine/skills/bilibili-upload/SKILL.md +109 -0
  93. package/engine/skills/douyin-upload/SKILL.md +74 -0
  94. package/engine/skills/internal.json +28 -0
  95. package/engine/skills/kuaishou-upload/SKILL.md +109 -0
  96. package/engine/skills/ml-appointment-safety/SKILL.md +42 -0
  97. package/engine/skills/ml-full-appointment/SKILL.md +23 -0
  98. package/engine/skills/ml-invoice/SKILL.md +2 -2
  99. package/engine/skills/ml-invoice/references/template-fill-contract.md +1 -1
  100. package/engine/skills/ml-label-recovery/SKILL.md +43 -0
  101. package/engine/skills/ml-listing-audit/SKILL.md +66 -0
  102. package/engine/skills/ml-store-daily-report/SKILL.md +68 -0
  103. package/engine/skills/ml-store-daily-report/scripts/generate.js +35 -0
  104. package/engine/skills/ml-store-insight/SKILL.md +81 -0
  105. package/engine/skills/tencent-upload/SKILL.md +60 -0
  106. package/engine/skills/weibo-upload/SKILL.md +106 -0
  107. package/engine/skills/whyshu-social-ops/SKILL.md +136 -0
  108. package/engine/skills/xiaohongshu-upload/SKILL.md +122 -0
  109. package/engine/version.mjs +1 -1
  110. package/engine/verticals/README.md +7 -0
  111. package/engine/verticals/_engine-words.baseline.txt +27 -59
  112. package/engine/verticals/mercadolibre/manifest.json +132 -6
  113. package/package.json +5 -1
@@ -0,0 +1,212 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * doc-status.mjs —— 文档状态体检(**默认 dry-run,只报告,不写任何文件**)
4
+ *
5
+ * 背景(2026-11-02):docs 下 105 篇,零 frontmatter;INDEX 里写死过版本号 ⇒ "新旧误会"。
6
+ * 本脚本按 INDEX 归属 + 文件名 + 已有横幅,给每篇一个**候选 status** 与依据,
7
+ * 供人工审阅后再落 frontmatter(见 docs/INDEX.md §文档状态约定)。
8
+ *
9
+ * 用法:
10
+ * node scripts/doc-status.mjs # 全部 docs/*.md,打印表格
11
+ * node scripts/doc-status.mjs --limit 20 # 只看前 20 行
12
+ * node scripts/doc-status.mjs --json # 机器可读
13
+ * node scripts/doc-status.mjs --dirs # 连 docs/*∕ 子目录一起扫
14
+ *
15
+ * 退出码:恒为 0(只报告)。门禁在 check-docs-drift.mjs(R5 规则族)。
16
+ */
17
+ import { readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
18
+ import { join, basename, relative } from 'node:path'
19
+
20
+ const ROOT = new URL('..', import.meta.url).pathname
21
+ const DOCS = join(ROOT, 'docs')
22
+ const args = process.argv.slice(2)
23
+ const LIMIT = args.includes('--limit') ? Number(args[args.indexOf('--limit') + 1]) : 0
24
+ const JSON_OUT = args.includes('--json')
25
+ const WITH_DIRS = !args.includes('--top-only') // 默认递归(排除 archive/)
26
+ const APPLY = args.includes('--apply') // 显式开启才写文件(默认 dry-run)
27
+
28
+ const SUPERSEDED_BY = {
29
+ 'docs/分层职责与判断归属.md': 'docs/Argent-宿主适配契约.md', // AGENTS.md:已并入库,只剩指针
30
+ }
31
+
32
+ // 2026-11-02 人工判定(17 篇自动分类判不出来的;改这里再跑 --apply 即可)
33
+ const MANUAL = {
34
+ // 现行:运维/接口/数据口径手册,仍被使用
35
+ 'docs/dsh-api-protocol.md': 'current',
36
+ 'docs/dsh-client-plugin-pitfalls.md': 'current',
37
+ 'docs/full-lip-operational-guide.md': 'current',
38
+ 'docs/ml-dev-failure-sop.md': 'current',
39
+ 'docs/机器接入Skill-分发说明.md': 'current',
40
+ 'docs/美客多日报-数据指标清单.md': 'current',
41
+ 'docs/ml-agent-architecture.md': 'current',
42
+ // 历史:方案/评估/路线记录,仅作证据
43
+ 'docs/agentic-tools-contract-v1.md': 'historical',
44
+ 'docs/Argent-智能体平台-设计.md': 'historical',
45
+ 'docs/Argent-陪跑式交付-实施方案.md': 'historical',
46
+ 'docs/Argent-许可自助签发与续期-实施方案.md': 'historical',
47
+ 'docs/branding-roadmap.md': 'historical',
48
+ 'docs/dsh-排程插件评估与迁移设计.md': 'historical',
49
+ 'docs/invoice-usage.md': 'historical',
50
+ 'docs/策划案-可读性根治与按能力交付与结果计费.md': 'historical',
51
+ 'docs/ml-invoice-automation.md': 'historical',
52
+ 'docs/内部运维-dsh升级与旧版本清场方案(不属 Argent 产品路径).md': 'historical',
53
+ }
54
+
55
+ const VERSION = readFileSync(join(ROOT, 'VERSION'), 'utf8').trim()
56
+ const CURRENT_MAJOR = VERSION.split('.').slice(0, 2).join('.') // 0.8
57
+
58
+ // ── INDEX 解析 ────────────────────────────────────────────────────────
59
+ const indexText = readFileSync(join(DOCS, 'INDEX.md'), 'utf8')
60
+ const sections = {}
61
+ let cur = null
62
+ for (const line of indexText.split('\n')) {
63
+ const h = line.match(/^##\s+(.*)$/)
64
+ if (h) { cur = h[1].trim(); sections[cur] = []; continue }
65
+ if (cur) sections[cur].push(line)
66
+ }
67
+ const currentLines = sections['当前有效(操作/契约以此为准)'] || []
68
+ const historicalLines = sections['历史文档(仅作证据,不作为当前操作依据)'] || []
69
+
70
+ const currentPaths = new Set()
71
+ for (const line of currentLines) {
72
+ if (!line.startsWith('|')) continue
73
+ for (const m of line.matchAll(/`([^`]+)`/g)) {
74
+ // ⚠️ 只在「空格 + / + 空格」处切分(`docs/release.md` / `docs/xxx.md` 这种一格两项),
75
+ // 否则 `skills/*/SKILL.md` 会被切成 `*` ⇒ 前缀匹配命中一切(2026-11-02 实测踩到)。
76
+ for (const p of m[1].split(/\s+\/\s+/)) currentPaths.add(p.replace(/^\.\//, ''))
77
+ }
78
+ }
79
+ const historicalPatterns = []
80
+ for (const line of historicalLines) {
81
+ if (!line.startsWith('- ')) continue
82
+ for (const m of line.matchAll(/`([^`]+)`/g)) {
83
+ for (const p of m[1].split(/\s+[·、]\s+/)) {
84
+ const t = p.trim()
85
+ if (t) historicalPatterns.push(t)
86
+ }
87
+ }
88
+ }
89
+
90
+ function matches(p, token) {
91
+ if (!token || token === '*' || token.endsWith('/*')) return false
92
+ if (token.endsWith('*')) return basename(p).startsWith(token.slice(0, -1))
93
+ if (token.includes('/')) return p === token || p.endsWith('/' + token)
94
+ return basename(p) === token || basename(p) === token + '.md'
95
+ }
96
+
97
+ // ── 文件扫描 ──────────────────────────────────────────────────────────
98
+ function walk(dir) {
99
+ const out = []
100
+ for (const e of readdirSync(dir)) {
101
+ const p = join(dir, e)
102
+ const st = statSync(p)
103
+ if (st.isDirectory()) { if (WITH_DIRS && e !== 'archive') out.push(...walk(p)); continue }
104
+ if (e.endsWith('.md')) out.push(p)
105
+ }
106
+ return out
107
+ }
108
+ const files = walk(DOCS).filter((f) => basename(f) !== 'INDEX.md')
109
+
110
+ function frontmatter(text) {
111
+ const lines = text.split('\n')
112
+ if (lines[0]?.trim() !== '---') return null
113
+ const end = lines.indexOf('---', 1)
114
+ if (end < 0) return null
115
+ const fm = {}
116
+ for (const l of lines.slice(1, end)) {
117
+ const m = l.match(/^([A-Za-z]+):\s*(.*)$/)
118
+ if (m) fm[m[1]] = m[2].trim()
119
+ }
120
+ return fm
121
+ }
122
+
123
+ // 现行引用面:INDEX 的"当前有效"文档正文 + 新会话真正读的入口(AGENTS/WORKSPACE)
124
+ const corpus = [
125
+ ...[...currentPaths]
126
+ .filter((x) => x.startsWith('docs/') && x.endsWith('.md'))
127
+ .map((x) => join(ROOT, x)),
128
+ join(process.env.HOME || '', '.dsh', 'AGENTS.md'),
129
+ join(ROOT, '..', 'WORKSPACE.md'),
130
+ ]
131
+ .map((f) => { try { return readFileSync(f, 'utf8') } catch { return '' } })
132
+ .join('\n')
133
+
134
+
135
+ const rows = []
136
+ for (const f of files) {
137
+ const rel = relative(ROOT, f).split('\\').join('/')
138
+ const text = readFileSync(f, 'utf8')
139
+ const fm = frontmatter(text)
140
+ const head = text.split('\n').slice(0, 6).join('\n')
141
+ const hasBanner = /历史文档|已归档|⛔\s*\*\*本文|superseded/i.test(head)
142
+ const name = basename(f)
143
+ const verMatch = name.match(/-(0\.\d)(?:\.\d)?-/)
144
+ const hasDate = /20\d{2}-\d{2}-\d{2}/.test(name)
145
+ const inCurrent = [...currentPaths].some((p) => matches(rel, p))
146
+ const inHistorical = historicalPatterns.some((p) => matches(rel, p))
147
+
148
+ let status, why, risk = ''
149
+ if (fm?.status) { status = fm.status; why = '已有 frontmatter' }
150
+ else if (inCurrent) { status = 'current'; why = 'INDEX「当前有效」' }
151
+ else if (hasBanner) { status = 'historical'; why = '已有历史横幅' }
152
+ else if (inHistorical) { status = 'historical'; why = 'INDEX「历史文档」' }
153
+ else if (/^release-/.test(name)) { status = 'historical'; why = '发布记录(事件)'; risk = '不取代任何文档' }
154
+ else if (MANUAL[rel]) { status = MANUAL[rel]; why = '人工判定(2026-11-02)' }
155
+ else if (rel.startsWith('docs/ops/')) { status = 'historical'; why = '运维事件记录(证据)' }
156
+ else if (rel.startsWith('docs/releases/')) { status = 'current'; why = '版本索引页' }
157
+ else if (rel.startsWith('docs/samples/')) { status = 'current'; why = '对外样例(脱敏)' }
158
+ else if (SUPERSEDED_BY[rel]) { status = 'superseded'; why = '已并入其他文档(人工确认)' }
159
+ else if (verMatch && verMatch[1] !== CURRENT_MAJOR) { status = 'historical'; why = `旧版本线 ${verMatch[1]}`; risk = '建议人工确认是否 superseded' }
160
+ else if (hasDate) { status = 'historical'; why = '时间型记录'; risk = '建议人工确认' }
161
+ else if (corpus.includes(name)) { status = 'current'; why = '被现行文档引用'; risk = '建议人工确认' }
162
+ else { status = 'needs-review'; why = '未命中任何规则,也无人引用'; risk = '需人工判定' }
163
+
164
+ rows.push({
165
+ file: rel, status, why, risk,
166
+ frontmatter: fm ? 'yes' : 'no',
167
+ hasAppliesTo: Boolean(fm?.appliesTo),
168
+ })
169
+ }
170
+
171
+ // ── apply(仅 --apply)──────────────────────────────────────────────
172
+ if (APPLY) {
173
+ let written = 0
174
+ for (const r of rows) {
175
+ if (r.frontmatter === 'yes') continue
176
+ // ⛔ 不替人做决定:needs-review 不写(留给人工判定,门禁会点名)
177
+ if (r.status === 'needs-review') continue
178
+ const abs = join(ROOT, r.file)
179
+ const text = readFileSync(abs, 'utf8')
180
+ const ver = r.file.match(/-(0\.\d)(?:\.\d)?-/)
181
+ const fm = [
182
+ '---',
183
+ `status: ${r.status === 'needs-review' ? 'draft' : r.status}`,
184
+ `appliesTo: ${ver ? `argent ${ver[1]}.x` : '—'}`,
185
+ ...(r.status === 'superseded' ? [`supersededBy: ${SUPERSEDED_BY[r.file]}`] : []),
186
+ 'updated: 2026-11-02',
187
+ '---',
188
+ '',
189
+ ].join('\n')
190
+ writeFileSync(abs, fm + text)
191
+ written++
192
+ }
193
+ console.log(`已写入 frontmatter:${written} 篇(其余已有,跳过)`)
194
+ }
195
+
196
+ // ── 输出 ──────────────────────────────────────────────────────────────
197
+ const order = { current: 0, 'needs-review': 1, superseded: 2, historical: 3, draft: 4 }
198
+ rows.sort((a, b) => (order[a.status] ?? 9) - (order[b.status] ?? 9) || a.file.localeCompare(b.file))
199
+ const counts = rows.reduce((m, r) => ((m[r.status] = (m[r.status] || 0) + 1), m), {})
200
+
201
+ if (JSON_OUT) {
202
+ console.log(JSON.stringify({ version: VERSION, counts, rows }, null, 2))
203
+ } else {
204
+ console.log(`doc-status —— 文档状态体检(dry-run,不写文件)`)
205
+ console.log(` 当前 VERSION: ${VERSION} 扫描: ${rows.length} 篇 frontmatter 覆盖: ${rows.filter((r) => r.frontmatter === 'yes').length}/${rows.length}`)
206
+ console.log(` 候选分布: ${Object.entries(counts).map(([k, v]) => `${k}=${v}`).join(' ')}`)
207
+ console.log('')
208
+ console.log(['STATUS', 'FILE', 'WHY', 'RISK'].join('\t'))
209
+ const show = LIMIT > 0 ? rows.slice(0, LIMIT) : rows
210
+ for (const r of show) console.log([r.status, r.file, r.why, r.risk].join('\t'))
211
+ if (LIMIT > 0 && rows.length > LIMIT) console.log(`... 还有 ${rows.length - LIMIT} 篇(用 --limit 0 看全部)`)
212
+ }
@@ -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,90 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 引擎包清单(P0 更新通道,2026-11-16)
4
+ *
5
+ * 为什么需要:客户机此前要用 `npx @whyshu/argent-engine ... argent-engine-runtime` 手动更新引擎资产,
6
+ * 这背离"只装一个 dsh 插件"的定位。现在改由插件自己查清单、下载、校验、切换。
7
+ *
8
+ * 本文件只做**纯逻辑**(可单测,不联网):
9
+ * · 清单形状校验与生成
10
+ * · 版本比较
11
+ * · 文件 sha256
12
+ */
13
+ import { createHash } from 'node:crypto'
14
+ import { readFileSync } from 'node:fs'
15
+
16
+ /** @typedef {{version:string,url:string,sha256:string,size:number,minShell?:string,releasedAt?:string}} EngineManifest */
17
+
18
+ const SHA256_RE = /^[0-9a-f]{64}$/
19
+ const SEMVER_RE = /^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?$/
20
+
21
+ /** 解析 1~3 段版本;非法返回 null */
22
+ export function parseVersion(v) {
23
+ const m = SEMVER_RE.exec(String(v || '').trim())
24
+ return m ? [Number(m[1]), Number(m[2] || 0), Number(m[3] || 0)] : null
25
+ }
26
+
27
+ /** -1 / 0 / 1;任一侧非法返回 null(调用方必须处理 null,别当成"相等") */
28
+ export function compareVersions(a, b) {
29
+ const x = parseVersion(a)
30
+ const y = parseVersion(b)
31
+ if (!x || !y) return null
32
+ for (let i = 0; i < 3; i += 1) if (x[i] !== y[i]) return x[i] > y[i] ? 1 : -1
33
+ return 0
34
+ }
35
+
36
+ export function sha256File(path) {
37
+ return createHash('sha256').update(readFileSync(path)).digest('hex')
38
+ }
39
+
40
+ export function sha256Buffer(buf) {
41
+ return createHash('sha256').update(buf).digest('hex')
42
+ }
43
+
44
+ /**
45
+ * 校验清单(服务端下发的东西**一律当不可信**)。
46
+ * @returns {{ok:true, value:EngineManifest} | {ok:false, reason:string}}
47
+ */
48
+ export function validateManifest(raw) {
49
+ if (!raw || typeof raw !== 'object') return { ok: false, reason: 'manifest_not_object' }
50
+ const version = String(raw.version || '').trim()
51
+ if (!parseVersion(version)) return { ok: false, reason: 'bad_version' }
52
+ const url = String(raw.url || '').trim()
53
+ if (!/^https:\/\//.test(url)) return { ok: false, reason: 'bad_url' }
54
+ const sha256 = String(raw.sha256 || '').trim().toLowerCase()
55
+ if (!SHA256_RE.test(sha256)) return { ok: false, reason: 'bad_sha256' }
56
+ const size = Number(raw.size)
57
+ if (!Number.isFinite(size) || size <= 0) return { ok: false, reason: 'bad_size' }
58
+ const minShell = raw.minShell === undefined ? '' : String(raw.minShell)
59
+ return { ok: true, value: { version, url, sha256, size, minShell, releasedAt: String(raw.releasedAt || '') } }
60
+ }
61
+
62
+ /**
63
+ * 生成清单条目(发布脚本用)。
64
+ * @param {{version:string, url:string, sha256:string, size:number, minShell?:string}} p
65
+ */
66
+ export function buildManifest({ version, url, sha256, size, minShell = '', releasedAt = new Date().toISOString() }) {
67
+ const m = { version, url, sha256, size, minShell, releasedAt }
68
+ const v = validateManifest(m)
69
+ if (!v.ok) throw new Error(`清单不合法:${v.reason}`)
70
+ return m
71
+ }
72
+
73
+ /** 服务端清单文件的整体形状:{ latest, engines: { <version>: manifest } } */
74
+ export function emptyManifestDoc() {
75
+ return { latest: '', engines: {} }
76
+ }
77
+
78
+ /**
79
+ * 把新版本并入清单文档(保留旧版本,便于回滚)。
80
+ * @param {object} doc 现有文档(可为空)
81
+ * @param {EngineManifest} m
82
+ */
83
+ export function upsertManifest(doc, m) {
84
+ const v = validateManifest(m)
85
+ if (!v.ok) throw new Error(`清单不合法:${v.reason}`)
86
+ const next = { latest: doc?.latest || '', engines: { ...(doc?.engines || {}) } }
87
+ next.engines[v.value.version] = v.value
88
+ if (!next.latest || (compareVersions(v.value.version, next.latest) ?? 1) > 0) next.latest = v.value.version
89
+ return next
90
+ }
@@ -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(⛔ 本脚本不重启,由用户手动)')