@whyshu/argent-engine 0.0.0-stage → 0.6.1
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 +341 -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 +576 -0
- package/engine/scripts/billing-mode-daily.sh +13 -0
- package/engine/scripts/build-engine-package.mjs +126 -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 +378 -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/collect-evidence.mjs +42 -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 +135 -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 +47 -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 +261 -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/final-check.mjs +43 -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 +735 -0
- package/engine/scripts/flow-scaffold.py +275 -0
- package/engine/scripts/flow-timers-plist.sh +87 -0
- package/engine/scripts/flow-timers.sh +184 -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 +1025 -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 +2278 -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 +195 -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.sh +18 -0
- package/engine/scripts/lib/argent_datadir.py +285 -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 +295 -0
- package/engine/scripts/poll-invoice.sh +76 -0
- package/engine/scripts/profile-doctor.mjs +686 -0
- package/engine/scripts/provider-select.sh +71 -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/retire-inventory.mjs +40 -0
- package/engine/scripts/run-tests.sh +257 -0
- package/engine/scripts/s1-audit.mjs +85 -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 +137 -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 +74 -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 +35 -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 +217 -0
- package/engine/scripts/ziniao-post-upgrade-check.sh +121 -0
- package/engine/scripts/ziniao-windows.sh +154 -0
- package/engine/skills/README.md +86 -0
- package/engine/skills/argent-dev/SKILL.md +41 -0
- package/engine/skills/internal.json +37 -0
- package/engine/skills/lktop-pm/SKILL.md +35 -0
- package/engine/skills/lktopapp-dev/SKILL.md +34 -0
- package/engine/skills/ml-config-guide/SKILL.md +50 -0
- package/engine/skills/ml-fulfillment-sop/SKILL.md +178 -0
- package/engine/skills/ml-fulfillment-sop/references/andes-components.md +69 -0
- package/engine/skills/ml-fulfillment-sop/references/cdp-port-mapping.md +35 -0
- package/engine/skills/ml-fulfillment-sop/references/feishu-base-fulfillment-schema.md +136 -0
- package/engine/skills/ml-fulfillment-sop/references/multi-window-concurrency.md +69 -0
- package/engine/skills/ml-fulfillment-sop/references/pitfalls.md +77 -0
- package/engine/skills/ml-fulfillment-sop/references/selectors.md +243 -0
- package/engine/skills/ml-fulfillment-sop/scripts/fulfillment.js +586 -0
- package/engine/skills/ml-fulfillment-sop/scripts/poll-and-execute.sh +271 -0
- package/engine/skills/ml-fulfillment-sop/templates/report.md +55 -0
- package/engine/skills/ml-invoice/SKILL.md +506 -0
- package/engine/skills/ml-invoice/references/pitfalls.md +268 -0
- package/engine/skills/ml-invoice/references/portal-flow.md +360 -0
- package/engine/skills/ml-invoice/references/template-fill-contract.md +133 -0
- package/engine/skills/ml-invoice-xzh/SKILL.md +133 -0
- package/engine/skills/ml-invoice-xzh/references/pitfalls.md +230 -0
- package/engine/skills/ml-store-daily-report/SKILL.md +224 -0
- package/engine/skills/ml-store-daily-report/scripts/README.md +25 -0
- package/engine/skills/ml-store-daily-report/scripts/extract.js +691 -0
- package/engine/skills/ml-store-daily-report/scripts/generate.js +299 -0
- package/engine/skills/pet-dev/SKILL.md +42 -0
- package/engine/skills/whyshu-pm/SKILL.md +35 -0
- package/engine/skills/whyshu-web-dev/SKILL.md +50 -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 +738 -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 +22 -4
- package/requirements.txt +5 -0
- package/README.md +0 -3
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* argent-feishu-bridge — 飞书对话消息桥(Argent on DSH)
|
|
4
|
+
*
|
|
5
|
+
* 常驻进程:监听飞书 IM 消息 → 交给 DSH headless 会话处理 → 回复。
|
|
6
|
+
* 与 hermes 版 gateway 等价,走 lark-cli event consume(本地总线)。
|
|
7
|
+
*
|
|
8
|
+
* 用法:
|
|
9
|
+
* node feishu-bridge.js [--role general|ml-seller] [--dsh-profile headless]
|
|
10
|
+
* ARGENT_FEISHU_IDENTITY=bot|user # 监听身份(默认 bot)
|
|
11
|
+
*
|
|
12
|
+
* 契约(lark-event skill):
|
|
13
|
+
* - stderr 出现 `[event] ready event_key=...` 后才开始读 stdout
|
|
14
|
+
* - SIGTERM 优雅退出(consume 收到 SIGTERM 清理订阅)
|
|
15
|
+
* - 事件为 stdout NDJSON,每行一条(--jq 已投影)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { spawn, execFile } from 'node:child_process'
|
|
19
|
+
import { promisify } from 'node:util'
|
|
20
|
+
import readline from 'node:readline'
|
|
21
|
+
import { homedir } from 'node:os'
|
|
22
|
+
import { join } from 'node:path'
|
|
23
|
+
import { mkdirSync, existsSync, readFileSync, appendFileSync, writeFileSync } from 'node:fs'
|
|
24
|
+
|
|
25
|
+
const execFileAsync = promisify(execFile)
|
|
26
|
+
|
|
27
|
+
// ── 参数 ───────────────────────────────────────────────────
|
|
28
|
+
const args = process.argv.slice(2)
|
|
29
|
+
// 多实例(改造项7):bridge 随实例运行——配置按 $DSH_HOME 解析(未设置回退 ~/.dsh 主实例)
|
|
30
|
+
const BRIDGE_HOME = process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
31
|
+
// 飞书凭据:优先 $DSH_HOME/argent/config.json(Web UI 配置),否则 lark-cli 全局配置
|
|
32
|
+
// (readFileSync/join/homedir 已在顶部统一导入)
|
|
33
|
+
let _feishuEnv = null
|
|
34
|
+
try {
|
|
35
|
+
const cfg = JSON.parse(readFileSync(join(BRIDGE_HOME, 'argent', 'config.json'), 'utf8'))
|
|
36
|
+
if (cfg.feishuAppId && cfg.feishuAppSecret) {
|
|
37
|
+
_feishuEnv = { LARK_APP_ID: cfg.feishuAppId, LARK_APP_SECRET: cfg.feishuAppSecret }
|
|
38
|
+
}
|
|
39
|
+
} catch { /* 未配置则用 lark-cli 全局 */ }
|
|
40
|
+
const bridgeEnv = _feishuEnv ? { ...process.env, ..._feishuEnv } : process.env
|
|
41
|
+
const getArg = (name, def) => {
|
|
42
|
+
const i = args.indexOf(name)
|
|
43
|
+
return i >= 0 && args[i + 1] ? args[i + 1] : def
|
|
44
|
+
}
|
|
45
|
+
const ROLE = getArg('--role', 'general')
|
|
46
|
+
const DSH_PROFILE = getArg('--dsh-profile', 'headless')
|
|
47
|
+
const IDENTITY = process.env.ARGENT_FEISHU_IDENTITY || 'bot'
|
|
48
|
+
|
|
49
|
+
const ROLE_PREFIX = {
|
|
50
|
+
general: '你是 Argent 通用助手(问述科技)。处理以下飞书消息,简洁中文回复:\n',
|
|
51
|
+
'ml-seller': '你是 Argent 美客多卖家助手(问述科技)。处理以下飞书消息;涉及货件/店铺查询用 ml_* 工具(如不可用则说明环境未就绪),简洁中文回复:\n',
|
|
52
|
+
'ml-daily': '你是 Argent 美客多日报助手(问述科技)。只读查询与日报;FULL/发票不属本实例。处理以下飞书消息,简洁中文回复:\n',
|
|
53
|
+
'ml-fulfillment': '你是 Argent 美客多 FULL/发票助手(问述科技)。涉及 FULL 货件/发票流程;写操作先确认。处理以下飞书消息,简洁中文回复:\n',
|
|
54
|
+
'pet-dev': '你是 Argent 云宠乐园开发者(问述科技)。处理开发任务与部署请求;任务流转看板为准。处理以下飞书消息,简洁中文回复:\n',
|
|
55
|
+
'argent-dev': '你是 Argent 开发者(问述科技)。处理 Argent 开发任务。处理以下飞书消息,简洁中文回复:\n',
|
|
56
|
+
'whyshu-pm': '你是问述科技PM(问述科技)。掌握策划案需求,分发任务给开发者并在看板登记。处理以下飞书消息,简洁中文回复:\n',
|
|
57
|
+
'lktop-pm': '你是 LKTOPPM(问述科技)。掌握 LKTOP 需求,分发任务给 LKTOPAPP 开发者。处理以下飞书消息,简洁中文回复:\n',
|
|
58
|
+
'lktopapp-dev': '你是 LKTOPAPP开发者(问述科技)。处理 LKTOP APP 开发任务。处理以下飞书消息,简洁中文回复:\n',
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ── 多轮记忆(每会话上下文注入,方案 B)──────────────────
|
|
62
|
+
// 历史存 $DSH_HOME/argent/bridge-context/<chatId>.jsonl(最多 CONTEXT_MAX 条)
|
|
63
|
+
// 注入到 prompt 供参考;不跨会话共享,天然按聊天隔离
|
|
64
|
+
const CONTEXT_DIR = join(BRIDGE_HOME, 'argent', 'bridge-context')
|
|
65
|
+
const CONTEXT_MAX = 20
|
|
66
|
+
|
|
67
|
+
const contextFile = (chatId) => join(CONTEXT_DIR, String(chatId).replace(/[^a-zA-Z0-9_-]/g, '') + '.jsonl')
|
|
68
|
+
|
|
69
|
+
function readContext(chatId) {
|
|
70
|
+
try {
|
|
71
|
+
const f = contextFile(chatId)
|
|
72
|
+
if (!existsSync(f)) return []
|
|
73
|
+
const out = []
|
|
74
|
+
for (const l of readFileSync(f, 'utf-8').split('\n')) {
|
|
75
|
+
if (!l.trim()) continue
|
|
76
|
+
try {
|
|
77
|
+
const o = JSON.parse(l)
|
|
78
|
+
if (o && o.role && o.text) out.push(o)
|
|
79
|
+
} catch { /* 跳过坏行 */ }
|
|
80
|
+
}
|
|
81
|
+
return out.slice(-CONTEXT_MAX)
|
|
82
|
+
} catch { return [] }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function appendContext(chatId, role, text) {
|
|
86
|
+
try {
|
|
87
|
+
mkdirSync(CONTEXT_DIR, { recursive: true })
|
|
88
|
+
const f = contextFile(chatId)
|
|
89
|
+
appendFileSync(f, JSON.stringify({ role, text, ts: Date.now() }) + '\n')
|
|
90
|
+
const lines = readFileSync(f, 'utf-8').split('\n').filter(Boolean)
|
|
91
|
+
if (lines.length > CONTEXT_MAX * 2) {
|
|
92
|
+
writeFileSync(f, lines.slice(-CONTEXT_MAX * 2).join('\n') + '\n')
|
|
93
|
+
}
|
|
94
|
+
} catch { /* 记忆失败不阻断对话 */ }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function contextBlock(hist) {
|
|
98
|
+
if (!hist.length) return ''
|
|
99
|
+
const lines = hist.map((o) => (o.role === 'user' ? '用户' : '助手') + ':' + o.text)
|
|
100
|
+
return '以下为本会话之前的对话记录(供参考,不要复述历史,直接回答最新问题):\n' + lines.join('\n') + '\n\n'
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ── 去重(message_id,10 分钟 TTL)────────────────────────
|
|
104
|
+
const seen = new Map()
|
|
105
|
+
const isDuplicate = (id) => {
|
|
106
|
+
if (!id) return false
|
|
107
|
+
if (seen.has(id)) return true
|
|
108
|
+
seen.set(id, Date.now())
|
|
109
|
+
if (seen.size > 500) {
|
|
110
|
+
const now = Date.now()
|
|
111
|
+
for (const [k, t] of seen) if (now - t > 600000) seen.delete(k)
|
|
112
|
+
}
|
|
113
|
+
return false
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const shellQuote = (s) => `'${String(s ?? '').replace(/'/g, `'\\''`)}'`
|
|
117
|
+
|
|
118
|
+
// ── 回复飞书 ───────────────────────────────────────────────
|
|
119
|
+
async function reply(chatId, text) {
|
|
120
|
+
const { stdout } = await execFileAsync(
|
|
121
|
+
'lark-cli', ['im', '+messages-send', '--chat-id', String(chatId), '--text', String(text), '--as', IDENTITY],
|
|
122
|
+
{ timeout: 30000 },
|
|
123
|
+
)
|
|
124
|
+
console.log(`[bridge] 已回复 chat=${chatId} len=${String(text).length}`)
|
|
125
|
+
return stdout
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ── @ 过滤(2026-08-26 修复:仅回复 @ 自己的消息)──────────
|
|
129
|
+
// 事件带 mentions(被 @ 者 [{id, key, name}]);按显示名匹配本角色。
|
|
130
|
+
// 平台侧两种配置都兼容:
|
|
131
|
+
// - 推全部群消息(未关「接收群内所有消息」):无 @ 或 @ 别人 → 跳过
|
|
132
|
+
// - 只推 @ 自己的消息(已关):mentions 必含自己 → 命中
|
|
133
|
+
const MENTION_NAMES = {
|
|
134
|
+
'pet-dev': ['云宠乐园开发者', 'pet-dev'],
|
|
135
|
+
'argent-dev': ['Argent开发者', 'Argent 开发者', 'argent-dev'],
|
|
136
|
+
'whyshu-pm': ['问述科技PM', '问述科技 PM', 'whyshu-pm'],
|
|
137
|
+
'lktop-pm': ['LKTOPPM', 'LKTOP PM', 'lktop-pm'],
|
|
138
|
+
'lktopapp-dev': ['LKTOPAPP开发者', 'LKTOPAPP 开发者', 'lktopapp-dev'],
|
|
139
|
+
general: ['MeU'], // 主 Bot 群内显示名(精确匹配,防误命中其他角色名)
|
|
140
|
+
}
|
|
141
|
+
function shouldHandle(evt) {
|
|
142
|
+
const mentions = Array.isArray(evt.mentions) ? evt.mentions : []
|
|
143
|
+
if (!mentions.length) return false // 消息未 @ 任何人 → 不处理
|
|
144
|
+
const names = MENTION_NAMES[ROLE] || MENTION_NAMES.general
|
|
145
|
+
return mentions.some((m) => names.some((n) => {
|
|
146
|
+
if (ROLE === 'general') return String(m.name || '') === n // 主 Bot 精确匹配(防误命中「Argent开发者」)
|
|
147
|
+
return String(m.name || '').includes(n)
|
|
148
|
+
}))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ── 处理一条消息 ───────────────────────────────────────────
|
|
152
|
+
async function handleMessage(evt) {
|
|
153
|
+
const { chat_id: chatId, message_id: msgId, text } = evt || {}
|
|
154
|
+
if (!chatId || !text) return
|
|
155
|
+
if (isDuplicate(msgId)) return
|
|
156
|
+
if (!shouldHandle(evt)) {
|
|
157
|
+
console.log(`[bridge] 跳过非 @ 消息 chat=${chatId} msg=${msgId} mentions=${JSON.stringify((evt.mentions || []).map((m) => m.name))}`)
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// 机器人自己的消息不回(sender 过滤在 jq 层,见下方提示)
|
|
162
|
+
const hist = readContext(chatId)
|
|
163
|
+
const task = (ROLE_PREFIX[ROLE] || ROLE_PREFIX.general) + contextBlock(hist) + '当前问题:' + text
|
|
164
|
+
console.log(`[bridge] chat=${chatId} msg=${msgId} sender=${evt.sender_id || '?'} len=${text.length} hist=${hist.length} @命中`)
|
|
165
|
+
|
|
166
|
+
// 交给 headless 会话(一次性)
|
|
167
|
+
let answer
|
|
168
|
+
try {
|
|
169
|
+
const { stdout } = await execFileAsync('dsh', ['--profile', DSH_PROFILE, task], {
|
|
170
|
+
timeout: 300000,
|
|
171
|
+
maxBuffer: 2 * 1024 * 1024,
|
|
172
|
+
})
|
|
173
|
+
answer = (stdout || '').trim().slice(0, 1500)
|
|
174
|
+
} catch (err) {
|
|
175
|
+
answer = `⚠️ 处理失败:${(err.message || '').slice(0, 200)}`
|
|
176
|
+
console.error(`[bridge] dsh error: ${err.message}`)
|
|
177
|
+
}
|
|
178
|
+
if (!answer) answer = '⚠️ 没有得到回复'
|
|
179
|
+
|
|
180
|
+
// 记录本轮(仅记录成功回答,避免把错误回复带入上下文)
|
|
181
|
+
appendContext(chatId, 'user', text)
|
|
182
|
+
if (!answer.startsWith('⚠️')) appendContext(chatId, 'assistant', answer)
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
await reply(chatId, answer)
|
|
186
|
+
} catch (err) {
|
|
187
|
+
console.error(`[bridge] reply error: ${err.message}`)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ── 启动 consume ───────────────────────────────────────────
|
|
192
|
+
function start() {
|
|
193
|
+
const jq = 'select(.message_type=="text") | {chat_id, sender_id, message_id, text: .content, mentions: (.mentions // [])}'
|
|
194
|
+
const child = spawn('lark-cli', ['event', 'consume', 'im.message.receive_v1', '--as', IDENTITY, '--jq', jq], {
|
|
195
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
196
|
+
env: bridgeEnv,
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
let ready = false
|
|
200
|
+
const stderr = readline.createInterface({ input: child.stderr })
|
|
201
|
+
stderr.on('line', (line) => {
|
|
202
|
+
if (!ready && line.includes('[event] ready')) {
|
|
203
|
+
ready = true
|
|
204
|
+
console.log('[bridge] lark event bus ready')
|
|
205
|
+
return
|
|
206
|
+
}
|
|
207
|
+
// 错误 envelope(JSON)
|
|
208
|
+
if (line.includes('"ok":false')) {
|
|
209
|
+
console.error('[bridge] lark error:', line.slice(0, 500))
|
|
210
|
+
if (line.includes('"type":"auth"') || line.includes('missing_scope')) {
|
|
211
|
+
console.error('[bridge] 请先完成 lark-cli 登录/授权(lark-cli auth login --as bot)')
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
const stdout = readline.createInterface({ input: child.stdout })
|
|
217
|
+
stdout.on('line', (line) => {
|
|
218
|
+
if (!line.trim()) return
|
|
219
|
+
let evt
|
|
220
|
+
try { evt = JSON.parse(line) } catch { return }
|
|
221
|
+
handleMessage(evt).catch((err) => console.error('[bridge] handle error:', err.message))
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
child.on('exit', (code, signal) => {
|
|
225
|
+
console.log(`[bridge] consume exited code=${code} signal=${signal}`)
|
|
226
|
+
// 意外退出则 3s 后重启(守护);SIGTERM 传播则不重启
|
|
227
|
+
if (!shuttingDown && code !== 0) {
|
|
228
|
+
setTimeout(start, 3000)
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
return child
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
let shuttingDown = false
|
|
236
|
+
for (const sig of ['SIGINT', 'SIGTERM']) {
|
|
237
|
+
process.on(sig, () => {
|
|
238
|
+
shuttingDown = true
|
|
239
|
+
console.log(`[bridge] ${sig},退出中...`)
|
|
240
|
+
process.exit(0)
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
console.log(`[bridge] argent-feishu-bridge 启动(role=${ROLE} dsh=${DSH_PROFILE} identity=${IDENTITY})`)
|
|
245
|
+
console.log('[bridge] 提示:消费端请用 --as bot;若需要过滤机器人自身消息,在 jq 中加 sender 过滤')
|
|
246
|
+
start()
|