@whyshu/argent-engine 0.0.0-stage → 0.6.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.
- package/MANIFEST.json +307 -0
- package/engine/VERSION +1 -0
- package/engine/agents/catalog.json +454 -0
- package/engine/configs/_aliases.proposed.json +651 -0
- package/engine/configs/_migration-plan.proposed.json +899 -0
- package/engine/configs/account.json +272 -0
- package/engine/configs/advanced.json +205 -0
- package/engine/configs/host.json +149 -0
- package/engine/configs/hr.json +27 -0
- package/engine/configs/notify.json +264 -0
- package/engine/core/cli/argent.mjs +277 -0
- package/engine/core/contracts/argent.contracts.json +1065 -0
- package/engine/core/contracts/verbs.schema.json +2539 -0
- package/engine/core/lib/argent-datadir.mjs +223 -0
- package/engine/core/lib/audit.mjs +187 -0
- package/engine/core/lib/claim.mjs +258 -0
- package/engine/core/lib/config-catalog.mjs +1172 -0
- package/engine/core/lib/doctor-customer.mjs +577 -0
- package/engine/core/lib/flow-list.mjs +138 -0
- package/engine/core/lib/flow-registry.mjs +48 -0
- package/engine/core/lib/init.mjs +247 -0
- package/engine/core/lib/ledger.mjs +124 -0
- package/engine/core/lib/license-activate.mjs +813 -0
- package/engine/core/lib/license-device.mjs +314 -0
- package/engine/core/lib/license-file.mjs +349 -0
- package/engine/core/lib/license-guard.mjs +123 -0
- package/engine/core/lib/license-ops.mjs +1645 -0
- package/engine/core/lib/license-verdict.mjs +133 -0
- package/engine/core/lib/license.mjs +577 -0
- package/engine/core/lib/notify/dedup.mjs +101 -0
- package/engine/core/lib/notify/feishu.mjs +38 -0
- package/engine/core/lib/notify/index.mjs +95 -0
- package/engine/core/lib/notify/verb.mjs +327 -0
- package/engine/core/lib/notify/webhook.mjs +135 -0
- package/engine/core/lib/notify/wecom.mjs +36 -0
- package/engine/core/lib/python.mjs +145 -0
- package/engine/core/lib/sop.mjs +116 -0
- package/engine/core/lib/versions.mjs +205 -0
- package/engine/core/mcp/client.mjs +67 -0
- package/engine/core/mcp/http.mjs +138 -0
- package/engine/core/mcp/server.mjs +702 -0
- package/engine/scripts/_engine_rules_probe.py +15 -0
- package/engine/scripts/analyze-full-day.py +568 -0
- package/engine/scripts/archive/feishu-bridge.js +246 -0
- package/engine/scripts/argent-agents.mjs +527 -0
- package/engine/scripts/argent-capabilities.mjs +776 -0
- package/engine/scripts/argent-catalog.mjs +186 -0
- package/engine/scripts/argent-datadir.py +62 -0
- package/engine/scripts/argent-doctor.mjs +624 -0
- package/engine/scripts/argent-env-write.mjs +302 -0
- package/engine/scripts/argent-schedule.mjs +620 -0
- package/engine/scripts/argent-setup-check.mjs +369 -0
- package/engine/scripts/argent-upgrade.mjs +1046 -0
- package/engine/scripts/base-bootstrap.sh +575 -0
- package/engine/scripts/billing-mode-daily.sh +12 -0
- package/engine/scripts/build-engine-package.mjs +123 -0
- package/engine/scripts/capability-packs.lock.json +484 -0
- package/engine/scripts/capability_pack.py +1242 -0
- package/engine/scripts/check-1.0-criteria.mjs +355 -0
- package/engine/scripts/check-agent-catalog.mjs +141 -0
- package/engine/scripts/check-billing-mode.sh +377 -0
- package/engine/scripts/check-child-sessions.mjs +83 -0
- package/engine/scripts/check-config-catalog.mjs +677 -0
- package/engine/scripts/check-docs-drift.mjs +522 -0
- package/engine/scripts/check-dsh-web-expose.sh +98 -0
- package/engine/scripts/check-judgment-drift.mjs +403 -0
- package/engine/scripts/check-license.mjs +199 -0
- package/engine/scripts/check-model-auth.py +443 -0
- package/engine/scripts/check-pack-closure.mjs +661 -0
- package/engine/scripts/check-portable-symbols.mjs +116 -0
- package/engine/scripts/check-preset-landing.mjs +124 -0
- package/engine/scripts/check-production-home.mjs +602 -0
- package/engine/scripts/check-role-mapping.mjs +461 -0
- package/engine/scripts/check-sample-redaction.mjs +320 -0
- package/engine/scripts/check-skill-classification.mjs +188 -0
- package/engine/scripts/check-sop-consistency.mjs +431 -0
- package/engine/scripts/check-test-env-safety.mjs +627 -0
- package/engine/scripts/check-version-consistency.mjs +452 -0
- package/engine/scripts/ci-run.sh +558 -0
- package/engine/scripts/config-explain.mjs +278 -0
- package/engine/scripts/configure-provider.rb +29 -0
- package/engine/scripts/customer-config-migrate.mjs +179 -0
- package/engine/scripts/customer-preflight.py +892 -0
- package/engine/scripts/customer-readiness.sh +134 -0
- package/engine/scripts/daily-report-inbox.py +242 -0
- package/engine/scripts/daily-report-reconcile.mjs +312 -0
- package/engine/scripts/daily-report.mjs +1310 -0
- package/engine/scripts/daily-report.sh +46 -0
- package/engine/scripts/data/lip-product-dict.json +306 -0
- package/engine/scripts/deliver-customer.mjs +932 -0
- package/engine/scripts/delivery-faces.txt +31 -0
- package/engine/scripts/desktop-trial.sh +146 -0
- package/engine/scripts/dev-window.sh +260 -0
- package/engine/scripts/drill-clean-machine.sh +315 -0
- package/engine/scripts/dsh-api-client.mjs +215 -0
- package/engine/scripts/dsh-backup-scope.sh +83 -0
- package/engine/scripts/dsh-offline-pack.mjs +77 -0
- package/engine/scripts/dsh-overlay-pin.sh +87 -0
- package/engine/scripts/dsh-plane.mjs +153 -0
- package/engine/scripts/dsh-portforward.py +223 -0
- package/engine/scripts/dsh-preflight.mjs +179 -0
- package/engine/scripts/dsh-release-watch-daily.sh +19 -0
- package/engine/scripts/dsh-release-watch.mjs +458 -0
- package/engine/scripts/dsh-remote-check.sh +99 -0
- package/engine/scripts/dsh-restart.sh +179 -0
- package/engine/scripts/dsh-restore.sh +111 -0
- package/engine/scripts/dsh-scope-rewire.mjs +803 -0
- package/engine/scripts/dsh-snapshot.mjs +116 -0
- package/engine/scripts/dsh-upgrade-readiness.mjs +165 -0
- package/engine/scripts/dsh-upgrade.mjs +612 -0
- package/engine/scripts/dsh-url.sh +86 -0
- package/engine/scripts/dsh-web-launch.mjs +155 -0
- package/engine/scripts/ensure-store-windows.py +509 -0
- package/engine/scripts/entitlements.py +458 -0
- package/engine/scripts/env_probe.py +411 -0
- package/engine/scripts/feishu-card.mjs +252 -0
- package/engine/scripts/fix-skill-frontmatter.py +209 -0
- package/engine/scripts/flow-auto-retry.py +454 -0
- package/engine/scripts/flow-requirements.json +720 -0
- package/engine/scripts/flow-scaffold.py +275 -0
- package/engine/scripts/flow-timers-plist.sh +86 -0
- package/engine/scripts/flow-timers.sh +182 -0
- package/engine/scripts/flow-trigger-wake.mjs +284 -0
- package/engine/scripts/flow-trigger.sh +571 -0
- package/engine/scripts/flow_billing.py +354 -0
- package/engine/scripts/flow_capability_stats.py +314 -0
- package/engine/scripts/flow_case.py +194 -0
- package/engine/scripts/flow_claim.py +497 -0
- package/engine/scripts/flow_config.py +1024 -0
- package/engine/scripts/flow_failure.py +588 -0
- package/engine/scripts/flow_learn.py +105 -0
- package/engine/scripts/flow_ledger.py +235 -0
- package/engine/scripts/flow_policy.py +238 -0
- package/engine/scripts/flow_preflight.py +339 -0
- package/engine/scripts/flow_registry.py +341 -0
- package/engine/scripts/flow_retry.py +304 -0
- package/engine/scripts/flow_return_to_ops.py +191 -0
- package/engine/scripts/flow_source.py +315 -0
- package/engine/scripts/flow_sources/__init__.py +53 -0
- package/engine/scripts/flow_sources/cases_json.py +106 -0
- package/engine/scripts/flow_sources/common.py +428 -0
- package/engine/scripts/flow_sources/feishu_base.py +273 -0
- package/engine/scripts/flow_stale.py +185 -0
- package/engine/scripts/flow_status_reconcile.py +344 -0
- package/engine/scripts/flow_triage.py +849 -0
- package/engine/scripts/flow_write_verify.py +496 -0
- package/engine/scripts/fulfillment.js +586 -0
- package/engine/scripts/gen-agent-bundles.mjs +276 -0
- package/engine/scripts/gen-preset-rows.mjs +259 -0
- package/engine/scripts/init-ml.sh +2275 -0
- package/engine/scripts/install-internal-role.sh +190 -0
- package/engine/scripts/install-license.mjs +641 -0
- package/engine/scripts/install-one-shot.mjs +665 -0
- package/engine/scripts/integration_contract.py +220 -0
- package/engine/scripts/integrations/wenyao/adapter.py +98 -0
- package/engine/scripts/integrations/xzh/adapter.py +75 -0
- package/engine/scripts/invoice-mapping.example.json +40 -0
- package/engine/scripts/invoice-table.sh +194 -0
- package/engine/scripts/invoice_carrier_notice.py +279 -0
- package/engine/scripts/invoice_fail_closeout.py +297 -0
- package/engine/scripts/invoice_lip_runner.py +1508 -0
- package/engine/scripts/invoice_lip_runner.py.bak-20260922-1710-freready +1090 -0
- package/engine/scripts/invoice_ready_audit.py +191 -0
- package/engine/scripts/invoice_runner.py +675 -0
- package/engine/scripts/invoice_stageb.py +516 -0
- package/engine/scripts/launchd/com.whyshu.argent-bridge.plist.example +42 -0
- package/engine/scripts/launchd/com.whyshu.fulfillment-poll.plist.example +29 -0
- package/engine/scripts/lease.py +377 -0
- package/engine/scripts/lib/agent-install.mjs +649 -0
- package/engine/scripts/lib/argent-datadir.mjs +16 -0
- package/engine/scripts/lib/argent_datadir.py +262 -0
- package/engine/scripts/lib/argent_filelock.py +507 -0
- package/engine/scripts/lib/bootcheck-wiring.mjs +510 -0
- package/engine/scripts/lib/cdp_ports.py +197 -0
- package/engine/scripts/lib/customer-env.mjs +102 -0
- package/engine/scripts/lib/daily-report-core.mjs +517 -0
- package/engine/scripts/lib/dep-declaration.mjs +81 -0
- package/engine/scripts/lib/deps-migrate.mjs +310 -0
- package/engine/scripts/lib/dsh-host-resolve.mjs +109 -0
- package/engine/scripts/lib/dsh-scope.mjs +500 -0
- package/engine/scripts/lib/dsh-snapshot-path.mjs +35 -0
- package/engine/scripts/lib/dsh-versions.mjs +96 -0
- package/engine/scripts/lib/dsh-web-probe.mjs +214 -0
- package/engine/scripts/lib/is-direct-run.mjs +61 -0
- package/engine/scripts/lib/patch-compose.mjs +241 -0
- package/engine/scripts/lib/patch-target.mjs +35 -0
- package/engine/scripts/lib/plugin-lifecycle.mjs +128 -0
- package/engine/scripts/lib/plugin-packages.mjs +332 -0
- package/engine/scripts/lib/preset-compat.mjs +127 -0
- package/engine/scripts/lib/preset-install.mjs +575 -0
- package/engine/scripts/lib/preset-mechanism.mjs +56 -0
- package/engine/scripts/lib/preset-sync.mjs +59 -0
- package/engine/scripts/lib/profile-retire.mjs +97 -0
- package/engine/scripts/lib/python-runtime.mjs +190 -0
- package/engine/scripts/lib/registry.mjs +72 -0
- package/engine/scripts/lib/repo-root.sh +56 -0
- package/engine/scripts/lib/schedule-mechanism.mjs +659 -0
- package/engine/scripts/lib/schedule-probe.mjs +835 -0
- package/engine/scripts/lib/scope-pointer.mjs +164 -0
- package/engine/scripts/lib/settings-panels.mjs +816 -0
- package/engine/scripts/lib/stdio_utf8.py +86 -0
- package/engine/scripts/lib/wake-auth.mjs +392 -0
- package/engine/scripts/lib/webdriver_ipc.py +264 -0
- package/engine/scripts/lib/zstd-frames.mjs +104 -0
- package/engine/scripts/license-e2e-drill.mjs +426 -0
- package/engine/scripts/license-gate.mjs +245 -0
- package/engine/scripts/lip_backlog.py +171 -0
- package/engine/scripts/lip_table.py +185 -0
- package/engine/scripts/local-usage.mjs +214 -0
- package/engine/scripts/migrate-providers.mjs +127 -0
- package/engine/scripts/migrate-skills.sh +65 -0
- package/engine/scripts/ml-oauth-setup.mjs +550 -0
- package/engine/scripts/ml-store-ids.json +26 -0
- package/engine/scripts/ml_artifact_attribution.py +333 -0
- package/engine/scripts/ml_capacity_probe.py +1158 -0
- package/engine/scripts/ml_hub_status.py +1556 -0
- package/engine/scripts/ml_schema_check.py +115 -0
- package/engine/scripts/ml_store_ids.py +139 -0
- package/engine/scripts/npm-publish-argent.mjs +499 -0
- package/engine/scripts/npm-publish-argent.sh +20 -0
- package/engine/scripts/orchestrator.py +13811 -0
- package/engine/scripts/pack-plugins.mjs +140 -0
- package/engine/scripts/patches/dsh-llm-deepseek--transport-diagnostics.patch +297 -0
- package/engine/scripts/patches/dsh-session--append-message-shape.patch +15 -0
- package/engine/scripts/patches/dsh-session--tool-result-block-017.patch +28 -0
- package/engine/scripts/patches/dsh-session-format-v0-to-v1--permission-preset-origin.patch +11 -0
- package/engine/scripts/patches/dsh-session-format-v3-to-v4--turn-outside-replace.patch +20 -0
- package/engine/scripts/patches/dsh-session-persistence-jsonl--worker-bundled-migrators.patch +39 -0
- package/engine/scripts/patches/dsh-tools--render-return-shape.patch +50 -0
- package/engine/scripts/patches/verify-bundled-migrators.mjs +79 -0
- package/engine/scripts/patches/verify-hardening.mjs +167 -0
- package/engine/scripts/patches/verify-session-migration.mjs +149 -0
- package/engine/scripts/patches/verify-transport-diagnostics.mjs +227 -0
- package/engine/scripts/plan-role-rename.mjs +125 -0
- package/engine/scripts/plugin-bootcheck.mjs +451 -0
- package/engine/scripts/plugin-composition.json +15 -0
- package/engine/scripts/poc-mcp-host.mjs +455 -0
- package/engine/scripts/poll-fulfillment.sh +293 -0
- package/engine/scripts/poll-invoice.sh +74 -0
- package/engine/scripts/profile-doctor.mjs +686 -0
- package/engine/scripts/provider-select.sh +70 -0
- package/engine/scripts/provider-switch.sh +146 -0
- package/engine/scripts/provider-sync-target.check.mjs +64 -0
- package/engine/scripts/python-runtime.sh +78 -0
- package/engine/scripts/query_runner.py +310 -0
- package/engine/scripts/release-argent.sh +574 -0
- package/engine/scripts/repair-unresolved-tools.mjs +178 -0
- package/engine/scripts/run-tests.sh +256 -0
- package/engine/scripts/self-sign-license.mjs +179 -0
- package/engine/scripts/session-health-scan.mjs +63 -0
- package/engine/scripts/session-repair-tool-result-content.mjs +181 -0
- package/engine/scripts/setup.sh +22 -0
- package/engine/scripts/skill-install.mjs +629 -0
- package/engine/scripts/sku_translate.py +148 -0
- package/engine/scripts/sync-plugins.sh +90 -0
- package/engine/scripts/sync-presets.sh +27 -0
- package/engine/scripts/sync-scripts.sh +445 -0
- package/engine/scripts/telemetry.py +873 -0
- package/engine/scripts/ui-copy-count.mjs +220 -0
- package/engine/scripts/usage-anchor.sh +136 -0
- package/engine/scripts/usage_report.py +531 -0
- package/engine/scripts/validate-preset-schema.mjs +208 -0
- package/engine/scripts/vertical-init.mjs +323 -0
- package/engine/scripts/vertical-lint.mjs +482 -0
- package/engine/scripts/wenyao-browser.sh +73 -0
- package/engine/scripts/wenyao-fixture-export.py +116 -0
- package/engine/scripts/wenyao-invoice-writeback.mjs +540 -0
- package/engine/scripts/wenyao-login.sh +34 -0
- package/engine/scripts/wenyao-template-map.json +292 -0
- package/engine/scripts/wenyao_attach.py +131 -0
- package/engine/scripts/wenyao_download_template.py +144 -0
- package/engine/scripts/wenyao_fill_template.py +568 -0
- package/engine/scripts/wenyao_login.py +145 -0
- package/engine/scripts/wenyao_portal.py +633 -0
- package/engine/scripts/wenyao_recon.py +230 -0
- package/engine/scripts/wenyao_run.py +503 -0
- package/engine/scripts/wenyao_shadow_diff.py +160 -0
- package/engine/scripts/wenyao_skill_contract.py +156 -0
- package/engine/scripts/wenyao_template_fetch.py +175 -0
- package/engine/scripts/win/dsh-web-autostart.ps1 +372 -0
- package/engine/scripts/ziniao-auth-probe.sh +268 -0
- package/engine/scripts/ziniao-keepalive.sh +216 -0
- package/engine/scripts/ziniao-post-upgrade-check.sh +120 -0
- package/engine/scripts/ziniao-windows.sh +153 -0
- package/engine/version.mjs +1 -0
- package/engine/verticals/README.md +103 -0
- package/engine/verticals/_engine-words.baseline.txt +237 -0
- package/engine/verticals/_engine-words.json +19 -0
- package/engine/verticals/mercadolibre/README.md +43 -0
- package/engine/verticals/mercadolibre/config.json +709 -0
- package/engine/verticals/mercadolibre/flows.json +706 -0
- package/engine/verticals/mercadolibre/manifest.json +538 -0
- package/engine/verticals/mercadolibre/migrate-machine-state.mjs +138 -0
- package/engine/verticals/mercadolibre/preflight.py +143 -0
- package/engine/verticals/mercadolibre/prompts/daily-report.failure.md +69 -0
- package/engine/verticals/mercadolibre/prompts/daily-report.md +47 -0
- package/engine/verticals/mercadolibre/prompts/daily-report.scheduled.md +79 -0
- package/engine/verticals/mercadolibre/prompts/full.failure.md +125 -0
- package/engine/verticals/mercadolibre/prompts/full.md +91 -0
- package/engine/verticals/mercadolibre/prompts/wenyao-invoice.failure.md +88 -0
- package/engine/verticals/mercadolibre/prompts/wenyao-invoice.md +64 -0
- package/engine/verticals/mercadolibre/prompts/xzh-invoice.failure.md +91 -0
- package/engine/verticals/mercadolibre/prompts/xzh-invoice.md +46 -0
- package/package.json +21 -4
- package/README.md +0 -3
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* argent-mcp-client(0.3 P2)—— **自建最简 MCP client**(用户选定的"第二宿主")
|
|
4
|
+
*
|
|
5
|
+
* 用途:① 证明"Argent 能力可被非 dsh 宿主通过 MCP 使用";② 做影子比对(下一步)时充当对照执行器。
|
|
6
|
+
* 用法:
|
|
7
|
+
* node core/mcp/client.mjs --selftest # 握手 + tools/list + 调 version/license/ledger
|
|
8
|
+
* node core/mcp/client.mjs --flow wenyao-invoice --preflight # 只读:跑一个流程的环境自检
|
|
9
|
+
*/
|
|
10
|
+
import { spawn } from 'node:child_process'
|
|
11
|
+
import { dirname, join, resolve } from 'node:path'
|
|
12
|
+
import { fileURLToPath } from 'node:url'
|
|
13
|
+
|
|
14
|
+
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
15
|
+
const SERVER = join(resolve(HERE, '..', '..'), 'core', 'mcp', 'server.mjs')
|
|
16
|
+
|
|
17
|
+
export function connect(serverPath = SERVER) {
|
|
18
|
+
const child = spawn(process.execPath, [serverPath], { stdio: ['pipe', 'pipe', 'inherit'] })
|
|
19
|
+
const pending = new Map()
|
|
20
|
+
let nextId = 1
|
|
21
|
+
let buf = ''
|
|
22
|
+
child.stdout.setEncoding('utf8')
|
|
23
|
+
child.stdout.on('data', (c) => {
|
|
24
|
+
buf += c
|
|
25
|
+
let i
|
|
26
|
+
while ((i = buf.indexOf('\n')) >= 0) {
|
|
27
|
+
const line = buf.slice(0, i).trim(); buf = buf.slice(i + 1)
|
|
28
|
+
if (!line) continue
|
|
29
|
+
let msg; try { msg = JSON.parse(line) } catch { continue }
|
|
30
|
+
const p = pending.get(msg.id)
|
|
31
|
+
if (p) { pending.delete(msg.id); msg.error ? p.reject(new Error(msg.error.message)) : p.resolve(msg.result) }
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
const rpc = (method, params) => new Promise((resolve_, reject) => {
|
|
35
|
+
const id = nextId++
|
|
36
|
+
pending.set(id, { resolve: resolve_, reject })
|
|
37
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`)
|
|
38
|
+
})
|
|
39
|
+
const notify = (method, params) => child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', method, params })}\n`)
|
|
40
|
+
return { rpc, notify, close: () => child.kill() }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (process.argv[1] && process.argv[1].endsWith('client.mjs')) {
|
|
44
|
+
const args = process.argv.slice(2)
|
|
45
|
+
const arg = (n, d) => { const i = args.indexOf(n); return i > -1 ? args[i + 1] : d }
|
|
46
|
+
const c = connect()
|
|
47
|
+
const init = await c.rpc('initialize', { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'argent-selfclient', version: '0.1.0' } })
|
|
48
|
+
c.notify('notifications/initialized')
|
|
49
|
+
console.log(`✅ 握手成功:server=${init.serverInfo.name}@${init.serverInfo.version}(协议 ${init.protocolVersion})`)
|
|
50
|
+
const tools = await c.rpc('tools/list', {})
|
|
51
|
+
console.log(`✅ tools:${tools.tools.map((t) => t.name).join(', ')}`)
|
|
52
|
+
const call = async (name, a = {}) => {
|
|
53
|
+
const r = await c.rpc('tools/call', { name, arguments: a })
|
|
54
|
+
const text = (r.content && r.content[0] && r.content[0].text) || ''
|
|
55
|
+
console.log(`\n--- ${name}(isError=${!!r.isError})\n${text.slice(0, 700)}`)
|
|
56
|
+
return text
|
|
57
|
+
}
|
|
58
|
+
if (args.includes('--preflight')) {
|
|
59
|
+
const flow = arg('--flow', 'full')
|
|
60
|
+
await call('argent_preflight', { flow })
|
|
61
|
+
} else {
|
|
62
|
+
await call('argent_version')
|
|
63
|
+
await call('argent_license')
|
|
64
|
+
await call('argent_ledger', { tail: 2 })
|
|
65
|
+
}
|
|
66
|
+
c.close()
|
|
67
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* argent-mcp HTTP 包装(0.3 P3,2026-09-29)
|
|
4
|
+
*
|
|
5
|
+
* 为什么需要:MCP 的 stdio 传输**只能本机**(宿主 spawn 子进程);要让**云端托管**的 MCP 被远程宿主调用,
|
|
6
|
+
* 必须给它一个可远程访问的入口 ⇒ 本文件把 stdio server 包成一个 HTTP JSON-RPC 端点。
|
|
7
|
+
*
|
|
8
|
+
* 设计要点(与用户决策一致):
|
|
9
|
+
* 1. **复用 stdio server**:本进程 spawn `server.mjs` 并代理 JSON-RPC(**零重复实现**,
|
|
10
|
+
* tools 只有一份定义,改一处两边生效);
|
|
11
|
+
* 2. **鉴权 = 问述账号体系**(不另造一套):要求 `Authorization: Bearer <WHYSHU_KEY>`,
|
|
12
|
+
* 用该 token 调 `GET /api/argent/entitlements` 验证(200 ⇒ 通过),结果**内存缓存 5 分钟**;
|
|
13
|
+
* 云端因此**不需要**保存客户密钥,只做验证;
|
|
14
|
+
* 3. **不用组网/IP 白名单**:公开部署 + 账号鉴权(用户明确要求);
|
|
15
|
+
* 4. 每请求带 `userId`(由验证接口身份确定)写入审计日志行(谁在何时调了哪个 tool)。
|
|
16
|
+
*/
|
|
17
|
+
import { spawn } from 'node:child_process'
|
|
18
|
+
import { createServer } from 'node:http'
|
|
19
|
+
import { dirname, join, resolve } from 'node:path'
|
|
20
|
+
import { fileURLToPath } from 'node:url'
|
|
21
|
+
import { readFileSync } from 'node:fs'
|
|
22
|
+
|
|
23
|
+
// ⚠️ **不要** import server.mjs:它有 `process.stdin.on('end', … process.exit(0))`,
|
|
24
|
+
// 而 systemd 下 stdin 是 /dev/null ⇒ 'end' 立即触发 ⇒ HTTP 进程自杀、重启循环(2026-09-30 实测)。
|
|
25
|
+
// 作用域表改为**运行时读** core/contracts/verbs.schema.json(单一真源、零副作用)。
|
|
26
|
+
// 路径直接用 import.meta.url 解析(**不依赖 HERE**:此前插在 HERE 定义之前 ⇒ join(undefined,…) 抛错
|
|
27
|
+
// 被 catch 吞掉 ⇒ 作用域表全空、门禁静默失效 —— 实测审计里 scope 全是 account 才发现)。
|
|
28
|
+
const SCHEMA_URL = new URL('../contracts/verbs.schema.json', import.meta.url)
|
|
29
|
+
const SCOPE = (() => {
|
|
30
|
+
try {
|
|
31
|
+
const sc = JSON.parse(readFileSync(SCHEMA_URL, 'utf8')).scope || {}
|
|
32
|
+
const m = {}
|
|
33
|
+
for (const t of sc.local || []) m[t] = 'local'
|
|
34
|
+
for (const t of sc.account || []) m[t] = 'account'
|
|
35
|
+
if (!Object.keys(m).length) throw new Error('scope 表为空')
|
|
36
|
+
return m
|
|
37
|
+
} catch (e) {
|
|
38
|
+
// 不静默:作用域表读不到 = 门禁失效,必须显式可见
|
|
39
|
+
console.error(`[argent-mcp] ⚠️ 作用域表加载失败(门禁将退化为"全部放行"):${String(e.message)}`)
|
|
40
|
+
return {}
|
|
41
|
+
}
|
|
42
|
+
})()
|
|
43
|
+
const toolScope = (name) => SCOPE[String(name || '').replace(/^argent_/, '')] || 'account'
|
|
44
|
+
|
|
45
|
+
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
46
|
+
const SERVER = join(HERE, 'server.mjs')
|
|
47
|
+
const PORT = Number(process.env.ARGENT_MCP_PORT || 8790)
|
|
48
|
+
const BIND = process.env.ARGENT_MCP_BIND || '127.0.0.1'
|
|
49
|
+
const VERIFY_URL = process.env.ARGENT_MCP_VERIFY_URL || 'https://whyshu.com/api/argent/entitlements'
|
|
50
|
+
const PROXY_VERIFY_URL = process.env.ARGENT_MCP_PROXY_VERIFY_URL || 'https://whyshu.com/api/argent/v1/models'
|
|
51
|
+
const AUTH_CACHE_MS = 5 * 60 * 1000
|
|
52
|
+
|
|
53
|
+
const child = spawn(process.execPath, [SERVER], { stdio: ['pipe', 'pipe', 'inherit'] })
|
|
54
|
+
const pending = new Map()
|
|
55
|
+
let nextId = 1
|
|
56
|
+
let buf = ''
|
|
57
|
+
child.stdout.setEncoding('utf8')
|
|
58
|
+
child.stdout.on('data', (c) => {
|
|
59
|
+
buf += c
|
|
60
|
+
let i
|
|
61
|
+
while ((i = buf.indexOf('\n')) >= 0) {
|
|
62
|
+
const line = buf.slice(0, i).trim(); buf = buf.slice(i + 1)
|
|
63
|
+
if (!line) continue
|
|
64
|
+
let msg; try { msg = JSON.parse(line) } catch { continue }
|
|
65
|
+
const p = pending.get(msg.id)
|
|
66
|
+
if (p) { pending.delete(msg.id); p(msg) }
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
child.on('exit', (code) => { console.error(`[argent-mcp] stdio server 退出(code=${code})`); process.exit(1) })
|
|
70
|
+
|
|
71
|
+
const rpc = (method, params) => new Promise((res) => {
|
|
72
|
+
const id = nextId++
|
|
73
|
+
pending.set(id, res)
|
|
74
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const authCache = new Map()
|
|
78
|
+
async function authorize(token) {
|
|
79
|
+
if (!token) return { ok: false, reason: 'no_token' }
|
|
80
|
+
const hit = authCache.get(token)
|
|
81
|
+
if (hit && Date.now() - hit.at < AUTH_CACHE_MS) return hit.result
|
|
82
|
+
// **两类凭据都接受**(2026-09-30 实测发现它们是两种东西、两个端点):
|
|
83
|
+
// ① 账号会话令牌(JWT,224 位,见 ~/.dsh/argent/whyshu.env)⇒ /api/argent/entitlements
|
|
84
|
+
// ② 问述代理 API Key(`sk-…`,35 位,见 credentials refs.WHYSHU_API_KEY)⇒ /v1/models
|
|
85
|
+
const VERIFY_ENDPOINTS = [
|
|
86
|
+
{ url: VERIFY_URL, kind: 'account', headers: (t) => ({ Authorization: `Bearer ${t}` }) },
|
|
87
|
+
{ url: PROXY_VERIFY_URL, kind: 'proxy_key', headers: (t) => ({ Authorization: `Bearer ${t}`, 'x-api-key': t }) },
|
|
88
|
+
]
|
|
89
|
+
let result = { ok: false, reason: 'verify_failed' }
|
|
90
|
+
for (const ep of VERIFY_ENDPOINTS) {
|
|
91
|
+
try {
|
|
92
|
+
const r = await fetch(ep.url, { headers: { ...ep.headers(token), 'cache-control': 'no-store' }, cache: 'no-store' })
|
|
93
|
+
if (!r.ok) { result = { ok: false, reason: `verify_${r.status}(${ep.kind})` }; continue }
|
|
94
|
+
let j = {}
|
|
95
|
+
try { j = await r.json() } catch { /* 非 JSON 也认为通过 */ }
|
|
96
|
+
result = { ok: true, kind: ep.kind, plan: j.plan || '', billingMode: j.billingMode || '', licenseActive: j.licenseActive !== false }
|
|
97
|
+
break
|
|
98
|
+
} catch (e) { result = { ok: false, reason: `verify_error:${String(e.message).slice(0, 60)}` } }
|
|
99
|
+
}
|
|
100
|
+
authCache.set(token, { at: Date.now(), result })
|
|
101
|
+
return result
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const audit = (row) => console.log(JSON.stringify({ at: new Date().toISOString(), ...row }))
|
|
105
|
+
|
|
106
|
+
const server = createServer(async (req, res) => {
|
|
107
|
+
const send = (code, body) => { res.writeHead(code, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' }); res.end(JSON.stringify(body)) }
|
|
108
|
+
if (req.method === 'GET' && req.url === '/mcp/health') return send(200, { ok: true, tools: pending.size >= 0, auth: 'whyshu-account', bind: `${BIND}:${PORT}` })
|
|
109
|
+
if (!(req.method === 'POST' && (req.url === '/mcp' || req.url === '/mcp/'))) return send(404, { error: 'not_found' })
|
|
110
|
+
|
|
111
|
+
const h = req.headers.authorization || ''
|
|
112
|
+
const token = h.startsWith('Bearer ') ? h.slice(7) : (req.headers['x-api-key'] || '')
|
|
113
|
+
const who = await authorize(token)
|
|
114
|
+
if (!who.ok) { audit({ event: 'deny', reason: who.reason }); return send(401, { error: 'unauthorized', reason: who.reason }) }
|
|
115
|
+
|
|
116
|
+
let raw = ''
|
|
117
|
+
for await (const chunk of req) raw += chunk
|
|
118
|
+
let body
|
|
119
|
+
try { body = JSON.parse(raw || '{}') } catch { return send(400, { error: 'bad_json' }) }
|
|
120
|
+
|
|
121
|
+
// 单条 JSON-RPC(MCP 的 tools/list、tools/call 都是单条;通知无 id 直接 202)
|
|
122
|
+
const id = body && body.id
|
|
123
|
+
const name = body && body.params && body.params.name
|
|
124
|
+
if (id === undefined) { audit({ event: 'notify', method: body && body.method, user: who.plan }); return send(202, { ok: true }) }
|
|
125
|
+
// **作用域门禁**(2026-09-30):`local` 类 tool(写台账/回写生产表等)在云上**默认禁止**
|
|
126
|
+
// —— 它们只在本机(有数据面与凭据)有意义;云端放行等于让公网调用者操作我们不掌握的机器状态。
|
|
127
|
+
// 需要时由运维显式 `ARGENT_MCP_ALLOW_LOCAL=1` 放开(默认安全)。
|
|
128
|
+
if (name && toolScope(name) === 'local' && process.env.ARGENT_MCP_ALLOW_LOCAL !== '1') {
|
|
129
|
+
audit({ event: 'scope_blocked', tool: name, plan: who.plan })
|
|
130
|
+
return send(403, { error: 'scope_blocked', scope: 'local', tool: name,
|
|
131
|
+
hint: '该 tool 只在本机有意义(数据面/凭据在客户端);云端默认拒绝,运维可用 ARGENT_MCP_ALLOW_LOCAL=1 显式放开' })
|
|
132
|
+
}
|
|
133
|
+
const out = await rpc(body.method, body.params)
|
|
134
|
+
audit({ event: 'call', method: body.method, tool: name || '', plan: who.plan, scope: name ? toolScope(name) : '', billingMode: who.billingMode, ok: !out.error })
|
|
135
|
+
return send(200, out)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
server.listen(PORT, BIND, () => console.error(`[argent-mcp] HTTP 就绪:http://${BIND}:${PORT}/mcp (鉴权=问述账号;验证端点 ${VERIFY_URL})`))
|