@xdxer/dingtalk-agent 0.1.4-beta.1 → 0.1.4-beta.10

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 (273) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.en.md +397 -0
  3. package/README.md +497 -46
  4. package/dist/bin/dingtalk-agent.js +1162 -340
  5. package/dist/bin/dingtalk-agent.js.map +1 -1
  6. package/dist/src/actions.js +98 -14
  7. package/dist/src/actions.js.map +1 -1
  8. package/dist/src/agent-audit.js +460 -0
  9. package/dist/src/agent-audit.js.map +1 -0
  10. package/dist/src/agent-bindings.js +132 -0
  11. package/dist/src/agent-bindings.js.map +1 -0
  12. package/dist/src/agent-definition.js +182 -0
  13. package/dist/src/agent-definition.js.map +1 -0
  14. package/dist/src/agent-enhance.js +678 -0
  15. package/dist/src/agent-enhance.js.map +1 -0
  16. package/dist/src/bootstrap.js +125 -17
  17. package/dist/src/bootstrap.js.map +1 -1
  18. package/dist/src/config.js +1 -7
  19. package/dist/src/config.js.map +1 -1
  20. package/dist/src/development-workspace.js +729 -0
  21. package/dist/src/development-workspace.js.map +1 -0
  22. package/dist/src/doctor.js +18 -7
  23. package/dist/src/doctor.js.map +1 -1
  24. package/dist/src/dws.js +145 -0
  25. package/dist/src/dws.js.map +1 -1
  26. package/dist/src/eval-evidence.js +193 -0
  27. package/dist/src/eval-evidence.js.map +1 -0
  28. package/dist/src/init.js +1 -1
  29. package/dist/src/init.js.map +1 -1
  30. package/dist/src/invocation.js +36 -0
  31. package/dist/src/invocation.js.map +1 -0
  32. package/dist/src/lab.js +679 -0
  33. package/dist/src/lab.js.map +1 -0
  34. package/dist/src/lease.js +100 -0
  35. package/dist/src/lease.js.map +1 -0
  36. package/dist/src/memory/candidates.js +451 -0
  37. package/dist/src/memory/candidates.js.map +1 -0
  38. package/dist/src/memory/completion-evidence.js +536 -0
  39. package/dist/src/memory/completion-evidence.js.map +1 -0
  40. package/dist/src/memory/operational.js +263 -0
  41. package/dist/src/memory/operational.js.map +1 -0
  42. package/dist/src/memory/remote-state.js +478 -0
  43. package/dist/src/memory/remote-state.js.map +1 -0
  44. package/dist/src/memory/task-checkpoints.js +204 -0
  45. package/dist/src/memory/task-checkpoints.js.map +1 -0
  46. package/dist/src/multica-deploy.js +1480 -0
  47. package/dist/src/multica-deploy.js.map +1 -0
  48. package/dist/src/multica-provider.js +685 -0
  49. package/dist/src/multica-provider.js.map +1 -0
  50. package/dist/src/opencode-evals.js +1062 -0
  51. package/dist/src/opencode-evals.js.map +1 -0
  52. package/dist/src/opencode-provider.js +531 -0
  53. package/dist/src/opencode-provider.js.map +1 -0
  54. package/dist/src/opencode-workspace.js +197 -0
  55. package/dist/src/opencode-workspace.js.map +1 -0
  56. package/dist/src/perception.js +225 -0
  57. package/dist/src/perception.js.map +1 -0
  58. package/dist/src/personal-event-evals.js +595 -0
  59. package/dist/src/personal-event-evals.js.map +1 -0
  60. package/dist/src/promotion.js +786 -0
  61. package/dist/src/promotion.js.map +1 -0
  62. package/dist/src/remote-semantic-state-live-evals.js +888 -0
  63. package/dist/src/remote-semantic-state-live-evals.js.map +1 -0
  64. package/dist/src/remote-semantic-state-worker.js +38 -0
  65. package/dist/src/remote-semantic-state-worker.js.map +1 -0
  66. package/dist/src/remote-state-evals.js +501 -0
  67. package/dist/src/remote-state-evals.js.map +1 -0
  68. package/dist/src/response-gate.js +51 -0
  69. package/dist/src/response-gate.js.map +1 -0
  70. package/dist/src/robot-evals.js +770 -0
  71. package/dist/src/robot-evals.js.map +1 -0
  72. package/dist/src/sessions.js +66 -105
  73. package/dist/src/sessions.js.map +1 -1
  74. package/dist/src/setup.js +10 -9
  75. package/dist/src/setup.js.map +1 -1
  76. package/dist/src/skill-manager.js +102 -203
  77. package/dist/src/skill-manager.js.map +1 -1
  78. package/dist/src/skills.js.map +1 -1
  79. package/dist/src/storage-evals.js +26 -0
  80. package/dist/src/storage-evals.js.map +1 -0
  81. package/dist/src/types.js.map +1 -1
  82. package/dist/src/upgrade.js +137 -0
  83. package/dist/src/upgrade.js.map +1 -0
  84. package/dist/src/waits.js +5 -1
  85. package/dist/src/waits.js.map +1 -1
  86. package/dist/src/workspace.js +28 -3
  87. package/dist/src/workspace.js.map +1 -1
  88. package/docs/INSTALLATION.md +118 -13
  89. package/docs/SECOND-AGENT-ACCEPTANCE.md +62 -0
  90. package/docs/architecture/agent-memory-topology.png +0 -0
  91. package/docs/architecture/agent-memory-topology.svg +132 -0
  92. package/docs/architecture/general-agent-kernel-topology.png +0 -0
  93. package/docs/architecture/general-agent-kernel-topology.svg +149 -0
  94. package/docs/architecture/provider-bound-development-workspace.png +0 -0
  95. package/docs/architecture/provider-bound-development-workspace.svg +141 -0
  96. package/docs/architecture/task-completion-gate.png +0 -0
  97. package/docs/architecture/task-completion-gate.svg +191 -0
  98. package/docs/schemas/agent-audit-load-evidence.schema.json +14 -0
  99. package/docs/schemas/agent-audit.schema.json +92 -0
  100. package/docs/schemas/agent-bindings.schema.json +54 -0
  101. package/docs/schemas/agent-definition.schema.json +78 -0
  102. package/docs/schemas/agent-enhancement-plan.schema.json +88 -0
  103. package/docs/schemas/agent-enhancement-receipt.schema.json +37 -0
  104. package/docs/schemas/enriched-invocation.schema.json +46 -0
  105. package/docs/schemas/eval-candidate-plan.schema.json +28 -0
  106. package/docs/schemas/eval-candidate-result.schema.json +20 -0
  107. package/docs/schemas/eval-candidate.schema.json +30 -0
  108. package/docs/schemas/invocation.schema.json +19 -0
  109. package/docs/schemas/memory-candidate-proposal.schema.json +18 -0
  110. package/docs/schemas/memory-candidate.schema.json +76 -0
  111. package/docs/schemas/memory-publish-target.schema.json +25 -0
  112. package/docs/schemas/multica-deployment-list.schema.json +29 -0
  113. package/docs/schemas/multica-deployment-operation.schema.json +51 -0
  114. package/docs/schemas/multica-deployment-plan.schema.json +70 -0
  115. package/docs/schemas/multica-deployment-receipt.schema.json +87 -0
  116. package/docs/schemas/multica-deployment-status.schema.json +23 -0
  117. package/docs/schemas/multica-workspace-inspection.schema.json +77 -0
  118. package/docs/schemas/multica-workspace-plan.schema.json +68 -0
  119. package/docs/schemas/multica-workspace-resource-list.schema.json +27 -0
  120. package/docs/schemas/multica-workspace-status.schema.json +34 -0
  121. package/docs/schemas/observation.schema.json +21 -0
  122. package/docs/schemas/operational-memory-provider.schema.json +36 -0
  123. package/docs/schemas/operational-memory-record.schema.json +24 -0
  124. package/docs/schemas/perception-input.schema.json +56 -0
  125. package/docs/schemas/project.schema.json +112 -0
  126. package/docs/schemas/promotion-list.schema.json +36 -0
  127. package/docs/schemas/promotion-plan.schema.json +60 -0
  128. package/docs/schemas/promotion-policy.schema.json +29 -0
  129. package/docs/schemas/promotion-receipt.schema.json +43 -0
  130. package/docs/schemas/promotion-status.schema.json +23 -0
  131. package/docs/schemas/release-readiness.schema.json +65 -0
  132. package/docs/schemas/remote-semantic-state-live-eval.schema.json +60 -0
  133. package/docs/schemas/remote-semantic-state-manifest.schema.json +79 -0
  134. package/docs/schemas/remote-semantic-state-provider.schema.json +98 -0
  135. package/docs/schemas/response-gate.schema.json +20 -0
  136. package/docs/schemas/task-checkpoint.schema.json +71 -0
  137. package/docs/schemas/task-completion-evidence.schema.json +154 -0
  138. package/docs/schemas/workspace-doctor.schema.json +56 -0
  139. package/docs/schemas/workspace-state.schema.json +39 -0
  140. package/evals/baselines/2026-07-16/opencode-basic-010-completion-summary.json +123 -0
  141. package/evals/baselines/2026-07-16/opencode-basic-skill-required-summary.json +69 -0
  142. package/evals/baselines/2026-07-16/opencode-multi-surface-summary.json +63 -0
  143. package/evals/baselines/2026-07-16/remote-state-live-summary.json +70 -0
  144. package/evals/baselines/2026-07-17/agent-enhance-opencode-dogfood-summary.json +98 -0
  145. package/evals/baselines/2026-07-17/personal-event-live-readiness-summary.json +68 -0
  146. package/examples/agents/fde-coach/AGENTS.md +26 -0
  147. package/examples/agents/fde-coach/MEMORY.md +3 -0
  148. package/examples/agents/fde-coach/fields/default/field.json +24 -0
  149. package/examples/agents/fde-coach/knowledge/INDEX.md +4 -0
  150. package/examples/agents/fde-coach/skills/fde-coach/SKILL.md +13 -0
  151. package/examples/agents/release-manager/AGENTS.md +26 -0
  152. package/examples/agents/release-manager/MEMORY.md +3 -0
  153. package/examples/agents/release-manager/fields/default/field.json +24 -0
  154. package/examples/agents/release-manager/knowledge/INDEX.md +4 -0
  155. package/examples/agents/release-manager/skills/release-manager/SKILL.md +13 -0
  156. package/lab/README.md +109 -0
  157. package/lab/agent-eval/catalog.json +91 -0
  158. package/lab/agent-eval/classic-failures.json +177 -0
  159. package/lab/agent-eval/completion-gate-regression.json +99 -0
  160. package/lab/agent-eval/personal-event-live.example.json +94 -0
  161. package/lab/agent-eval/remote-semantic-state-live.example.json +70 -0
  162. package/lab/agent-eval/remote-semantic-state-provider.fixture.json +47 -0
  163. package/lab/agent-eval/remote-state-workspace/AGENTS.md +8 -0
  164. package/lab/agent-eval/remote-state-workspace/opencode.json +7 -0
  165. package/lab/agent-eval/remote-state-workspace/skills/remote-state-operator/SKILL.md +13 -0
  166. package/lab/agent-eval/remote-state.example.json +31 -0
  167. package/lab/agent-eval/workspace/AGENTS.md +7 -0
  168. package/lab/agent-eval/workspace/MEMORY.md +4 -0
  169. package/lab/agent-eval/workspace/artifacts/pending-review.md +3 -0
  170. package/lab/agent-eval/workspace/knowledge/INDEX.md +4 -0
  171. package/lab/agent-eval/workspace/opencode.json +20 -0
  172. package/lab/manifest.example.json +27 -0
  173. package/lab/manifest.personal-event.example.json +27 -0
  174. package/lab/project-workspace/README.md +11 -0
  175. package/lab/project-workspace/fake-multica-provider.mjs +266 -0
  176. package/lab/project-workspace/multica-deploy.fixture.json +29 -0
  177. package/lab/project-workspace/multica-readonly.fixture.json +69 -0
  178. package/lab/project-workspace/observation.fixture.json +14 -0
  179. package/lab/project-workspace/opencode-provider-suite.json +65 -0
  180. package/lab/project-workspace/project.fixture.json +44 -0
  181. package/lab/project-workspace/promotion-policy.fixture.json +15 -0
  182. package/lab/robot-eval/pool.example.json +30 -0
  183. package/lab/robot-eval/suite.json +123 -0
  184. package/lab/robot-eval/workspace/AGENTS.md +21 -0
  185. package/lab/robot-eval/workspace/MEMORY.md +3 -0
  186. package/lab/robot-eval/workspace/knowledge/INDEX.md +5 -0
  187. package/lab/robot-eval/workspace/opencode.json +22 -0
  188. package/lab/schemas/agent-eval-catalog.schema.json +47 -0
  189. package/lab/schemas/lab-manifest.schema.json +70 -0
  190. package/lab/schemas/personal-event-eval.schema.json +91 -0
  191. package/lab/schemas/remote-state-eval.schema.json +66 -0
  192. package/lab/schemas/robot-eval-suite.schema.json +184 -0
  193. package/lab/schemas/robot-pool.schema.json +56 -0
  194. package/package.json +26 -14
  195. package/skills/dingtalk-agent-boot-multica/SKILL.md +40 -0
  196. package/skills/dingtalk-agent-compose/SKILL.md +110 -0
  197. package/skills/dingtalk-agent-compose/assets/AGENTS.template.md +26 -0
  198. package/skills/dingtalk-agent-compose/assets/agent.bindings.dingtalk-doc.template.json +13 -0
  199. package/skills/dingtalk-agent-compose/assets/agent.bindings.local.template.json +13 -0
  200. package/skills/dingtalk-agent-compose/assets/opencode.template.json +12 -0
  201. package/skills/dingtalk-agent-compose/assets/role-skill.template.md +24 -0
  202. package/skills/dingtalk-agent-compose/evals/evals.json +94 -0
  203. package/skills/dingtalk-agent-compose/references/agent-definition-contract.md +55 -0
  204. package/skills/dingtalk-agent-compose/references/opencode-host-contract.md +65 -0
  205. package/skills/dingtalk-agent-compose/references/storage-routing.md +20 -0
  206. package/skills/dingtalk-agent-deploy/SKILL.md +60 -0
  207. package/skills/dingtalk-agent-deploy/references/multica-deployment-contract.md +49 -0
  208. package/skills/dingtalk-agent-deploy/references/promotion-observation-contract.md +49 -0
  209. package/skills/dingtalk-agent-eval/SKILL.md +116 -0
  210. package/skills/dingtalk-agent-eval/assets/eval-catalog.template.json +18 -0
  211. package/skills/dingtalk-agent-eval/evals/evals.json +61 -0
  212. package/skills/dingtalk-agent-eval/references/eval-topology.md +34 -0
  213. package/skills/dingtalk-agent-eval/references/evidence-contract.md +31 -0
  214. package/skills/dingtalk-agent-eval/references/scenario-taxonomy.md +25 -0
  215. package/skills/dingtalk-agent-eval/references/storage-modes.md +75 -0
  216. package/skills/dingtalk-basic-behavior/SKILL.md +63 -3
  217. package/skills/dingtalk-basic-behavior/assets/memory-candidate-proposal.json +10 -0
  218. package/skills/dingtalk-basic-behavior/assets/{task-checkpoint.md → task-checkpoint.json} +2 -21
  219. package/skills/dingtalk-basic-behavior/references/action-contract.md +2 -0
  220. package/skills/dingtalk-basic-behavior/references/memory-and-evolution.md +15 -1
  221. package/skills/dingtalk-basic-behavior/references/perception-and-gates.md +28 -0
  222. package/skills/dingtalk-basic-behavior/references/task-lifecycle.md +32 -7
  223. package/dist/src/boot.js +0 -70
  224. package/dist/src/boot.js.map +0 -1
  225. package/dist/src/duty.js +0 -74
  226. package/dist/src/duty.js.map +0 -1
  227. package/dist/src/kb.js +0 -240
  228. package/dist/src/kb.js.map +0 -1
  229. package/dist/src/runs.js +0 -79
  230. package/dist/src/runs.js.map +0 -1
  231. package/docs/ARCHITECTURE.md +0 -217
  232. package/docs/MINIMAL-WORKSPACE-V1.md +0 -172
  233. package/docs/OPEN-SOURCE-REFERENCES.md +0 -107
  234. package/docs/SELF-TEST.md +0 -252
  235. package/docs//345/206/205/347/275/221/345/256/236/347/233/270.md +0 -77
  236. package/evals/baselines/2026-07-14/behavior-summary.json +0 -28
  237. package/evals/baselines/2026-07-14/contract-summary.json +0 -18
  238. package/evals/baselines/2026-07-14/live-canary-summary.json +0 -25
  239. package/evals/baselines/2026-07-15/dingtalk-basic-behavior-0.3.0/SKILL.md +0 -72
  240. package/evals/baselines/2026-07-15/dingtalk-basic-behavior-0.3.0/references/action-contract.md +0 -31
  241. package/evals/baselines/2026-07-15/dingtalk-basic-behavior-0.3.0/references/event-to-behavior.md +0 -22
  242. package/evals/baselines/2026-07-15/dingtalk-basic-behavior-0.3.0/references/memory-and-evolution.md +0 -25
  243. package/evals/baselines/2026-07-15/dingtalk-basic-behavior-0.3.0/references/runtime-modes.md +0 -34
  244. package/evals/baselines/2026-07-15/task-lifecycle-summary.json +0 -50
  245. package/evals/evals.json +0 -316
  246. package/evals/fixtures/dm-ambiguous-send.json +0 -4
  247. package/evals/fixtures/dm-blocked.json +0 -4
  248. package/evals/fixtures/dm-clear.json +0 -4
  249. package/evals/fixtures/dm-discussion.json +0 -4
  250. package/evals/fixtures/dm-doc-write-no-tool.json +0 -4
  251. package/evals/fixtures/dm-long-task-ack.json +0 -4
  252. package/evals/fixtures/dm-nonblocking-gap.json +0 -4
  253. package/evals/fixtures/dm-structured-task.json +0 -4
  254. package/evals/fixtures/group.json +0 -10
  255. package/evals/fixtures/mentioned.json +0 -3
  256. package/evals/run-contract-evals.mjs +0 -1106
  257. package/evals/run-shadow-evals.mjs +0 -267
  258. package/evals/runners/README.md +0 -66
  259. package/evals/runners/claude-shadow.mjs +0 -533
  260. package/evals/schemas/action-request.schema.json +0 -77
  261. package/evals/shadow-evals.json +0 -133
  262. package/skills/AGENTS.md +0 -104
  263. package/skills//344/273/273/345/212/241.md +0 -48
  264. package/skills//345/237/272/347/241/200/350/241/214/344/270/272.md +0 -44
  265. package/skills//345/277/203/350/267/263.md +0 -79
  266. package/skills//346/266/210/346/201/257.md +0 -50
  267. package/skills//347/237/245/350/257/206.md +0 -55
  268. package/skills//350/257/204/346/265/213.md +0 -62
  269. package/skills//351/222/211/351/222/211.md +0 -64
  270. package/templates/ontology/index.md +0 -24
  271. package/templates/ontology/self/access.md +0 -38
  272. package/templates/ontology/self/role-spec.md +0 -34
  273. package/templates/ontology/self/workspace.md +0 -41
@@ -9,22 +9,35 @@
9
9
  //
10
10
  // 因为:文档会被漏读、误读、自我说服;**撞到闸门上就没得商量。**
11
11
  import { parseArgs } from 'node:util';
12
- import { join, resolve } from 'node:path';
13
- import { readFileSync } from 'node:fs';
12
+ import { join, relative, resolve } from 'node:path';
13
+ import { existsSync, readFileSync, realpathSync } from 'node:fs';
14
14
  import { spawn, spawnSync } from 'node:child_process';
15
15
  import * as cfgmod from '../src/config.js';
16
- import * as kbmod from '../src/kb.js';
17
- import * as runsmod from '../src/runs.js';
18
- import * as dutymod from '../src/duty.js';
19
- import { boot } from '../src/boot.js';
20
16
  import { init } from '../src/init.js';
21
17
  import { ackDispatch, listPendingDispatches, prepareSession } from '../src/sessions.js';
22
18
  import { readEventFile, consumeNdjson, heartbeatEvent } from '../src/driver.js';
23
19
  import { findRun, previewAction, executeAction } from '../src/actions.js';
24
20
  import { resolvePackageRoot } from '../src/package-root.js';
25
21
  import { bootstrap } from '../src/bootstrap.js';
22
+ import { loadAgentBindings } from '../src/agent-bindings.js';
23
+ import { auditAgent } from '../src/agent-audit.js';
24
+ import { applyAgentEnhancement, planAgentEnhancement, } from '../src/agent-enhance.js';
25
+ import { doctorLab, runLab, teardownLab, verifyLab } from '../src/lab.js';
26
+ import { runRobotEvaluation } from '../src/robot-evals.js';
27
+ import { runOpenCodeEvaluation } from '../src/opencode-evals.js';
28
+ import { runStorageEvaluation } from '../src/storage-evals.js';
29
+ import { runPersonalEventEvaluation } from '../src/personal-event-evals.js';
26
30
  import { doctor } from '../src/doctor.js';
31
+ import { doctorDevelopmentWorkspace, inspectAgentProject, showDevelopmentWorkspace, } from '../src/development-workspace.js';
32
+ import { applyOpenCodeWorkspace, evalOpenCodeWorkspace, planOpenCodeWorkspace, runOpenCodeWorkspace, useOpenCodeWorkspace, } from '../src/opencode-provider.js';
33
+ import { inspectMulticaWorkspace, listMulticaWorkspaceResources, planMulticaWorkspace, statusMulticaWorkspace, } from '../src/multica-provider.js';
34
+ import { applyMulticaDeployment, listMulticaDeployments, planMulticaDeployment, statusMulticaDeployment, } from '../src/multica-deploy.js';
35
+ import { applyObservation, applyPromotion, listPromotions, planObservation, planPromotion, statusPromotion, } from '../src/promotion.js';
27
36
  import { setup } from '../src/setup.js';
37
+ import { upgradeAgent } from '../src/upgrade.js';
38
+ import { checkpointTask, showTaskCheckpoint } from '../src/memory/task-checkpoints.js';
39
+ import { upsertOperationalMemory } from '../src/memory/operational.js';
40
+ import { proposeMemoryCandidate, publishMemoryCandidate, reviewMemoryCandidate, showMemoryCandidate, } from '../src/memory/candidates.js';
28
41
  import { installGlobalSkill, skillStatus, uninstallGlobalSkill, upgradeGlobalSkill, } from '../src/skill-manager.js';
29
42
  const PACKAGE_ROOT = resolvePackageRoot(import.meta.url);
30
43
  const PACKAGE_JSON = JSON.parse(readFileSync(join(PACKAGE_ROOT, 'package.json'), 'utf8'));
@@ -33,50 +46,41 @@ const PACKAGE_JSON = JSON.parse(readFileSync(join(PACKAGE_ROOT, 'package.json'),
33
46
  const ROOT = process.env.DTA_ROOT
34
47
  ? resolve(process.env.DTA_ROOT)
35
48
  : (cfgmod.findRoot(process.cwd()) || process.cwd());
49
+ const PROJECT_START = process.env.DTA_ROOT ? resolve(process.env.DTA_ROOT) : process.cwd();
36
50
  const HELP = `
37
- dingtalk-agent —— Skill-first 的钉钉数字员工行为容器
51
+ dta —— Agent 安装钉钉员工的基础行为和工作环境
38
52
 
39
- 首次使用(无全局命令时: npx --yes --registry=https://registry.npmjs.org @xdxer/dingtalk-agent@${PACKAGE_JSON.version} setup)
40
- setup 用户级安装 CLI、修复 PATH、安装 Skill、检查 DWS
41
- doctor 检查 PATH / Node / DWS / Skill / Agent 客户端
53
+ 装好后,Agent 可以:
54
+ · 判断 @、单聊和群消息是否应该回应
55
+ · 通过 DWS 回复消息、协作并使用钉钉标准产品
56
+ · 从本地目录或钉钉文档加载身份、记忆和知识
42
57
 
43
- Skill(不要求 Workspace)
44
- skill install 安装全局 Basic Behavior(Claude Code + Codex + OpenCode)
45
- skill status 检查版本、漂移和客户端可发现性
46
- skill upgrade 升级本工具管理的全局 Skill
47
- skill uninstall 安全卸载本工具管理的全局 Skill
48
- 通用: [--dry-run] [--json] [--discard-local-changes]
58
+ 开始使用:
59
+ dta setup 首次配置 CLI、DWS 和基础行为 Skill
60
+ dta bootstrap --json 为当前 Agent 会话加载工作区
61
+ dta agent enhance / audit 安全增强已有仓库,再审计定义、存储与 Skill 真加载
62
+ dta info / dta workspace doctor <name> 查看 Project 并只读诊断 Workspace
63
+ dta deploy ... / dta promote ... 预览 Multica 受控部署或已验版本晋级
49
64
 
50
- 每个 Agent Session(不要求 init)
51
- bootstrap 发现当前本地 Workspace;不修改项目文件
52
- [--storage <uri>] local-dir:<path> | dingtalk-doc:<node-or-url>
53
- [--state-dir <path>] 远端文档只读快照目录
54
- [--profile <dws-profile>] [--json]
65
+ 维护环境:
66
+ dta doctor 检查哪里没装好,并给出修复提示
67
+ dta upgrade 自升级,再重新检查完整环境
68
+ dta skill status 查看 Claude Code、Codex、OpenCode 能否发现 Skill
55
69
 
56
- 可信事件模式(可选;需要一次 init)
57
- init [--context-id X] 仅为 Prepared Run 建最小 Workspace
58
- prepare --event-file <file|-> 事件 → Session → Run
59
- act ack 对原消息贴「收到」;不代表接单
60
- act reply --text "…" 引用回复原消息
61
- act ask --text "…" 只问一个真正阻塞的问题
62
- act silence [--reason "…"] 不外发,但留下行为回执
63
- 通用: [--run <path>] [--dry-run] [--json]
64
-
65
- smoke 极简本地验收(不写钉钉)
66
- eval contract / behavior 完整合同或模型行为评测
67
-
68
- help runtime 事件宿主与 controller 命令
69
- help adapters 可选 DWS listen 适配器
70
- help legacy 查看兼容的本体、KB、值班与进化命令
70
+ 接入钉钉事件和可靠外发:dta help runtime
71
71
  `;
72
72
  const RUNTIME_HELP = `
73
73
  dingtalk-agent 可信事件运行时(可选宿主能力)
74
74
 
75
75
  init [--context-id X] [--memory <uri>] [--knowledge <uri>]
76
- prepare --event-file <file|->
76
+ prepare --event-file <file|-> [--perception-file <file>]
77
77
  run --stdin | --event-file <file> | --heartbeat
78
78
  dispatch pending
79
79
  dispatch ack --event-id X --run-id X
80
+ task show --json
81
+ task checkpoint --input checkpoint.json --expect-revision N
82
+ memory operational upsert --provider provider.json --input record.json [--live --yes]
83
+ memory candidate propose|show|review|publish
80
84
  act ack|reply|ask|silence
81
85
 
82
86
  这些命令负责目标冻结、Session/Run、Wait、幂等和回执;普通 Agent Session 不必使用。
@@ -90,19 +94,90 @@ dingtalk-agent 可选 Driver / 开发联调适配器
90
94
 
91
95
  listen 不是 Agent 主入口。Claude Code、DWS 云端或其他宿主都可以直接提供事件。
92
96
  `;
93
- const LEGACY_HELP = `
94
- dingtalk-agent 兼容命令(不属于 P0 四对象主链)
97
+ const LAB_HELP = `
98
+ dingtalk-agent 真实世界联调控制面
99
+
100
+ lab doctor --manifest lab/manifest.local.json
101
+ lab run --manifest <file> --event-file <file> --case-id <id> [--reply <text>]
102
+ lab verify --evidence <run-dir>
103
+ lab teardown --manifest <file> --evidence <run-dir>
104
+ lab eval --pool <pool.local.json> --suite <suite.json> [--lanes stateless,stateful]
105
+ lab eval --engine opencode --workspace <agent-dir> --suite <suite.json> [--cases id1,id2] [--runs 3] [--previous-skill <dir>]
106
+ lab eval --engine storage --workspace <agent-dir> --suite <remote-state.json> [--execute --live --yes]
107
+ lab eval --engine personal-event --workspace <agent-dir> --suite <suite.json> [--execute --live --yes]
108
+
109
+ mock-integration 还要求 DTA_LAB_FAKE_DWS=1;robot/personal Live 必须显式 --live --yes。
110
+ lab eval 默认只输出计划;Robot Live 用 --live --yes,OpenCode A/B 用 --execute --yes。
111
+ Remote State 用 --execute --yes 读取 DWS/调用模型,再加 --live 才执行唯一写探针。
112
+ OpenCode 对照强制验证每个 Basic Skill 的 load probe;提供 --previous-skill 时运行 current/previous,不连接 DWS。
113
+ Lab 只管理 allowlist、预算、marker、证据和清理;事件触发器仍在外部。
114
+ `;
115
+ const AGENT_HELP = `
116
+ dingtalk-agent 开发者装配验收
117
+
118
+ agent audit [--bindings agent.bindings.json] [--require-skill <name>]
119
+ agent audit [--bindings <file>] [--require-skill <name>] --verify-load --yes
120
+ agent audit [--bindings <file>] --load-report <agent-audit-load-evidence.json> [--remote-report <report.json>]
121
+ agent enhance --role-skill <name>[,<name>] [--project-name <name>] [--dry-run] [--json]
122
+ agent enhance --role-skill <name>[,<name>] --plan-id <current-plan-id> --yes [--json]
123
+
124
+ 默认只做本地静态审计,不访问 DWS、不调用模型;状态为 partial 时返回退出码 2。
125
+ --verify-load --yes 会运行隔离的 OpenCode load probe,但仍不访问钉钉。
126
+ 远端语义状态由 storage eval 独立验收,再通过 --remote-report 绑定证据。
127
+ `;
128
+ const WORKSPACE_HELP = `
129
+ dingtalk-agent Project / Development Workspace
130
+
131
+ info [--json]
132
+ workspace list [--json]
133
+ workspace show <name> [--json]
134
+ workspace doctor <name> [--json]
135
+ workspace plan <multica-name> [--json]
136
+ workspace inspect <multica-name> [--execute --yes] [--json]
137
+ workspace remote-list <multica-name> [--execute --yes] [--json]
138
+ workspace status <multica-name> [--json]
139
+ workspace create <name> [--dry-run | --yes] [--json]
140
+ workspace use <name> [--json]
141
+ workspace run <name> --prompt-file <file> [--execute --yes] [--json]
142
+ workspace eval <name> --suite <file> [--execute --yes] [--runs N] [--json]
143
+
144
+ 命令会从当前目录向上发现 dingtalk-agent.json;旧 workspace@1 只读显示为 legacy-prepared。
145
+ Multica plan/status 默认不调用 Provider;inspect/remote-list 只有 --execute --yes 才读取当前 profile 和远端 scope。
146
+ Multica readback 只保存脱敏事实,不执行 create/update/apply/deploy;OpenCode create 只物化本地环境。
147
+ 这些命令都不访问 DWS;Multica 远端写入只通过 dta deploy 的冻结 plan 闸门。
148
+ `;
149
+ const DEPLOY_HELP = `
150
+ dingtalk-agent Multica 受控部署
95
151
 
96
- boot
97
- kb mount|list|sync|search
98
- duty --check|--run|--list
99
- todo
100
- log / feedback / runs / evolve
152
+ deploy --workspace <name> --dry-run [--json]
153
+ deploy --workspace <name> --plan-id <id> --yes [--no-wait] [--json]
154
+ deploy --workspace <name> --status [--operation-id <id>] [--json]
155
+ deploy --workspace <name> --status --operation-id <id> --execute --yes [--json]
156
+ deploy --workspace <name> --list [--json]
157
+ deploy --workspace <name> --retire --dry-run [--json]
158
+ deploy --workspace <name> --retire --plan-id <id> --yes [--json]
101
159
 
102
- 这些能力继续可用,但新增 Agent 应先安装全局 Skill;只有可信事件宿主才需要 runtime。
160
+ dry-run 不启动 Multica。apply/retire 必须携带当前 planId;scope 或源码漂移会在写入前拒绝。
161
+ status 默认只验本地脱敏 operation/Receipt;--execute --yes 才做远端独立回读。
162
+ deploy 只管理 Agent、完整 Skill tree、assignment 和 load smoke,不创建机器人、Webhook、Autopilot 或定时 Trigger。
103
163
  `;
104
- function fail(msg, code = 1) {
105
- console.error(msg);
164
+ const PROMOTION_HELP = `
165
+ dingtalk-agent 已验版本晋级与反馈候选
166
+
167
+ promote --policy <file> --route <id> --dry-run [--json]
168
+ promote --policy <file> --route <id> --plan-id <id> --yes [--no-wait] [--json]
169
+ promote --status [--promotion-id <id>] [--json]
170
+ promote --list [--json]
171
+ observe --promotion-id <id> --input <observation.json> --dry-run [--json]
172
+ observe --promotion-id <id> --input <observation.json> --yes [--json]
173
+
174
+ Promotion 只接受指定 suite 的 load/hard/surface gate 与精确 W2 evidence hash,并委托 W4 deploy。
175
+ Observe 只写 gitignored、proposed、不可直接发布的 Eval candidate;不修改 AGENTS.md、Prompt、Skill 或 Trigger。
176
+ `;
177
+ function fail(msg, code = 1, hint = '') {
178
+ console.error(`错误: ${msg}`);
179
+ if (hint)
180
+ console.error(`提示: ${hint}`);
106
181
  process.exit(code);
107
182
  }
108
183
  const argv = process.argv.slice(2);
@@ -112,15 +187,11 @@ try {
112
187
  await main();
113
188
  }
114
189
  catch (e) {
115
- if (e.exitCode)
116
- process.exit(e.exitCode);
117
- fail(String(e.message || e), 2);
190
+ const error = e;
191
+ const message = String(error?.message || error);
192
+ fail(message, Number(error?.exitCode) || 2, errorHint(message));
118
193
  }
119
194
  async function main() {
120
- if (cmd === 'help' && sub === 'legacy') {
121
- console.log(LEGACY_HELP);
122
- return;
123
- }
124
195
  if (cmd === 'help' && sub === 'runtime') {
125
196
  console.log(RUNTIME_HELP);
126
197
  return;
@@ -129,6 +200,29 @@ async function main() {
129
200
  console.log(ADAPTER_HELP);
130
201
  return;
131
202
  }
203
+ if (cmd === 'help' && sub === 'lab') {
204
+ console.log(LAB_HELP);
205
+ return;
206
+ }
207
+ if (cmd === 'help' && sub === 'agent') {
208
+ console.log(AGENT_HELP);
209
+ return;
210
+ }
211
+ if (cmd === 'help' && sub === 'workspace') {
212
+ console.log(WORKSPACE_HELP);
213
+ return;
214
+ }
215
+ if (cmd === 'help' && sub === 'deploy') {
216
+ console.log(DEPLOY_HELP);
217
+ return;
218
+ }
219
+ if (cmd === 'help' && ['promote', 'observe'].includes(sub || '')) {
220
+ console.log(PROMOTION_HELP);
221
+ return;
222
+ }
223
+ if (cmd === 'help' && sub) {
224
+ fail(`不认识的帮助主题: ${sub}`, 1, '运行 dta --help 回到产品入口;事件宿主可用 dta help runtime。');
225
+ }
132
226
  if (!cmd || cmd === '--help' || cmd === '-h' || cmd === 'help') {
133
227
  console.log(HELP);
134
228
  return;
@@ -137,7 +231,387 @@ async function main() {
137
231
  console.log(PACKAGE_JSON.version);
138
232
  return;
139
233
  }
140
- // ── setup / doctor:npx 永远可启动的首次使用入口。──
234
+ if (cmd === 'deploy') {
235
+ const { values: o, positionals } = parseArgs({
236
+ args: argv.slice(1), allowPositionals: true,
237
+ options: {
238
+ workspace: { type: 'string' }, json: { type: 'boolean' },
239
+ 'dry-run': { type: 'boolean' }, yes: { type: 'boolean' },
240
+ 'plan-id': { type: 'string' }, 'no-wait': { type: 'boolean' },
241
+ status: { type: 'boolean' }, list: { type: 'boolean' },
242
+ execute: { type: 'boolean' }, 'operation-id': { type: 'string' },
243
+ timeout: { type: 'string' }, 'smoke-timeout': { type: 'string' },
244
+ retire: { type: 'boolean' },
245
+ },
246
+ });
247
+ if (positionals.length)
248
+ fail('deploy 不接受位置参数;使用 --workspace <name>');
249
+ if (!o.workspace)
250
+ fail('deploy 必须显式传 --workspace <name>');
251
+ const modes = [
252
+ Boolean(o.status), Boolean(o.list), Boolean(o['dry-run']), Boolean(o.yes && !o.status),
253
+ ]
254
+ .filter(Boolean).length;
255
+ if (modes !== 1) {
256
+ fail('deploy 必须且只能选择 --dry-run、--yes、--status 或 --list 之一');
257
+ }
258
+ const timeoutMs = parseOptionalTimeout(o.timeout, '--timeout');
259
+ const smokeTimeoutMs = parseOptionalTimeout(o['smoke-timeout'], '--smoke-timeout');
260
+ let out;
261
+ if (o.list) {
262
+ if (o.execute || o['operation-id'] || o.retire || o['plan-id'] || o['no-wait'] ||
263
+ o.timeout || o['smoke-timeout']) {
264
+ fail('deploy --list 只接受 --workspace 和 --json');
265
+ }
266
+ out = listMulticaDeployments(PROJECT_START, o.workspace, PACKAGE_JSON.version);
267
+ }
268
+ else if (o.status) {
269
+ if (o.retire || o['plan-id'] || o['no-wait'] || o['dry-run'] || o['smoke-timeout']) {
270
+ fail('deploy --status 不接受 retire/plan-id/no-wait/dry-run/smoke-timeout');
271
+ }
272
+ if (Boolean(o.execute) !== Boolean(o.yes)) {
273
+ fail('deploy --status 远端 reconcile 必须同时传 --execute --yes');
274
+ }
275
+ out = statusMulticaDeployment(PROJECT_START, o.workspace, {
276
+ execute: o.execute, yes: o.yes, operationId: o['operation-id'], timeoutMs,
277
+ cliVersion: PACKAGE_JSON.version,
278
+ });
279
+ }
280
+ else if (o['dry-run']) {
281
+ if (o.execute || o['operation-id'] || o['plan-id'] || o['no-wait'] ||
282
+ o.timeout || o['smoke-timeout']) {
283
+ fail('deploy --dry-run 不接受 execute/operation-id/plan-id/no-wait/timeout/smoke-timeout');
284
+ }
285
+ out = planMulticaDeployment(PROJECT_START, o.workspace, {
286
+ action: o.retire ? 'retire' : 'apply', cliVersion: PACKAGE_JSON.version,
287
+ });
288
+ }
289
+ else {
290
+ if (o.execute || o['operation-id'] || o.status || o.list || o['dry-run']) {
291
+ fail('deploy apply 不接受 execute/operation-id/status/list/dry-run');
292
+ }
293
+ if (o.retire && (o['no-wait'] || o['smoke-timeout'])) {
294
+ fail('deploy --retire 不接受 no-wait/smoke-timeout');
295
+ }
296
+ out = applyMulticaDeployment(PROJECT_START, o.workspace, {
297
+ yes: o.yes, planId: o['plan-id'], noWait: o['no-wait'],
298
+ timeoutMs, smokeTimeoutMs, cliVersion: PACKAGE_JSON.version,
299
+ }, o.retire ? 'retire' : 'apply');
300
+ }
301
+ if (o.json)
302
+ console.log(JSON.stringify(out, null, 2));
303
+ else
304
+ printMulticaDeployment(out);
305
+ if ('passed' in out && out.passed === false && out.status !== 'verifying')
306
+ process.exitCode = 2;
307
+ return;
308
+ }
309
+ if (cmd === 'promote') {
310
+ const { values: o, positionals } = parseArgs({
311
+ args: argv.slice(1), allowPositionals: true,
312
+ options: {
313
+ policy: { type: 'string' }, route: { type: 'string' },
314
+ 'dry-run': { type: 'boolean' }, yes: { type: 'boolean' }, json: { type: 'boolean' },
315
+ 'plan-id': { type: 'string' }, status: { type: 'boolean' }, list: { type: 'boolean' },
316
+ 'promotion-id': { type: 'string' }, 'no-wait': { type: 'boolean' },
317
+ timeout: { type: 'string' }, 'smoke-timeout': { type: 'string' },
318
+ },
319
+ });
320
+ if (positionals.length)
321
+ fail('promote 不接受位置参数');
322
+ const modes = [Boolean(o['dry-run']), Boolean(o.yes), Boolean(o.status), Boolean(o.list)]
323
+ .filter(Boolean).length;
324
+ if (modes !== 1)
325
+ fail('promote 必须且只能选择 --dry-run、--yes、--status 或 --list 之一');
326
+ let out;
327
+ if (o.list) {
328
+ if (o.policy || o.route || o['plan-id'] || o['promotion-id'] || o['no-wait'] ||
329
+ o.timeout || o['smoke-timeout'])
330
+ fail('promote --list 只接受 --json');
331
+ out = listPromotions(PROJECT_START);
332
+ }
333
+ else if (o.status) {
334
+ if (o.policy || o.route || o['plan-id'] || o['no-wait'] || o.timeout || o['smoke-timeout']) {
335
+ fail('promote --status 只接受 --promotion-id 和 --json');
336
+ }
337
+ out = statusPromotion(PROJECT_START, o['promotion-id'] || '');
338
+ }
339
+ else {
340
+ if (!o.policy || !o.route)
341
+ fail('promote dry-run/apply 必须传 --policy <file> --route <id>');
342
+ if (o['promotion-id'])
343
+ fail('promote dry-run/apply 不接受 --promotion-id');
344
+ if (o['dry-run']) {
345
+ if (o['plan-id'] || o['no-wait'] || o.timeout || o['smoke-timeout']) {
346
+ fail('promote --dry-run 不接受 plan-id/no-wait/timeout/smoke-timeout');
347
+ }
348
+ out = planPromotion(PROJECT_START, o.policy, o.route, { cliVersion: PACKAGE_JSON.version });
349
+ }
350
+ else {
351
+ out = applyPromotion(PROJECT_START, o.policy, o.route, {
352
+ yes: true, planId: o['plan-id'], noWait: o['no-wait'],
353
+ timeoutMs: parseOptionalTimeout(o.timeout, '--timeout'),
354
+ smokeTimeoutMs: parseOptionalTimeout(o['smoke-timeout'], '--smoke-timeout'),
355
+ cliVersion: PACKAGE_JSON.version,
356
+ });
357
+ }
358
+ }
359
+ if (o.json)
360
+ console.log(JSON.stringify(out, null, 2));
361
+ else
362
+ printPromotion(out);
363
+ if ('passed' in out && out.passed === false && out.status !== 'verifying' && out.status !== 'missing') {
364
+ process.exitCode = 2;
365
+ }
366
+ return;
367
+ }
368
+ if (cmd === 'observe') {
369
+ const { values: o, positionals } = parseArgs({
370
+ args: argv.slice(1), allowPositionals: true,
371
+ options: {
372
+ 'promotion-id': { type: 'string' }, input: { type: 'string' },
373
+ 'dry-run': { type: 'boolean' }, yes: { type: 'boolean' }, json: { type: 'boolean' },
374
+ },
375
+ });
376
+ if (positionals.length)
377
+ fail('observe 不接受位置参数');
378
+ if (!o['promotion-id'] || !o.input) {
379
+ fail('observe 必须传 --promotion-id <id> --input <observation.json>');
380
+ }
381
+ if (Boolean(o['dry-run']) === Boolean(o.yes)) {
382
+ fail('observe 必须且只能选择 --dry-run 或 --yes');
383
+ }
384
+ const out = o['dry-run']
385
+ ? planObservation(PROJECT_START, o['promotion-id'], o.input)
386
+ : applyObservation(PROJECT_START, o['promotion-id'], o.input, { yes: true });
387
+ if (o.json)
388
+ console.log(JSON.stringify(out, null, 2));
389
+ else
390
+ printPromotion(out);
391
+ return;
392
+ }
393
+ // ── Project / Development Workspace:W1 只读发现、状态与 Provider 诊断。──
394
+ if (cmd === 'info') {
395
+ const { values: o } = parseArgs({
396
+ args: argv.slice(1), options: { json: { type: 'boolean' } },
397
+ });
398
+ const out = inspectAgentProject(PROJECT_START, PACKAGE_JSON.version);
399
+ if (o.json)
400
+ console.log(JSON.stringify(out, null, 2));
401
+ else
402
+ printProjectInfo(out);
403
+ return;
404
+ }
405
+ if (cmd === 'workspace') {
406
+ const { values: o, positionals } = parseArgs({
407
+ args: argv.slice(2), allowPositionals: true,
408
+ options: {
409
+ json: { type: 'boolean' }, yes: { type: 'boolean' },
410
+ 'dry-run': { type: 'boolean' }, execute: { type: 'boolean' },
411
+ 'prompt-file': { type: 'string' }, suite: { type: 'string' },
412
+ cases: { type: 'string' }, lanes: { type: 'string' }, runs: { type: 'string' },
413
+ out: { type: 'string' }, timeout: { type: 'string' },
414
+ 'previous-skill': { type: 'string' },
415
+ },
416
+ });
417
+ if (sub === 'list') {
418
+ rejectWorkspaceOptions(o, ['json'], 'workspace list');
419
+ if (positionals.length)
420
+ fail('workspace list 不接受 Workspace name');
421
+ const info = inspectAgentProject(PROJECT_START, PACKAGE_JSON.version);
422
+ const out = {
423
+ $schema: 'dingtalk-agent/workspace-list@1',
424
+ root: info.root,
425
+ currentWorkspace: info.currentWorkspace,
426
+ workspaces: info.workspaces,
427
+ sideEffect: false,
428
+ dingtalkSideEffect: false,
429
+ };
430
+ if (o.json)
431
+ console.log(JSON.stringify(out, null, 2));
432
+ else
433
+ printWorkspaceList(info);
434
+ return;
435
+ }
436
+ if (sub === 'show') {
437
+ rejectWorkspaceOptions(o, ['json'], 'workspace show');
438
+ if (positionals.length !== 1)
439
+ fail('workspace show 需要且只接受一个 Workspace name');
440
+ const workspace = showDevelopmentWorkspace(PROJECT_START, positionals[0], PACKAGE_JSON.version);
441
+ const out = {
442
+ $schema: 'dingtalk-agent/development-workspace@1',
443
+ ...workspace,
444
+ sideEffect: false,
445
+ dingtalkSideEffect: false,
446
+ };
447
+ if (o.json)
448
+ console.log(JSON.stringify(out, null, 2));
449
+ else
450
+ printDevelopmentWorkspace(workspace);
451
+ return;
452
+ }
453
+ if (sub === 'doctor') {
454
+ rejectWorkspaceOptions(o, ['json'], 'workspace doctor');
455
+ if (positionals.length !== 1)
456
+ fail('workspace doctor 需要且只接受一个 Workspace name');
457
+ const out = doctorDevelopmentWorkspace(PROJECT_START, positionals[0], {
458
+ cliVersion: PACKAGE_JSON.version,
459
+ });
460
+ if (o.json)
461
+ console.log(JSON.stringify(out, null, 2));
462
+ else
463
+ printDevelopmentWorkspaceDoctor(out);
464
+ if (!out.ready)
465
+ process.exitCode = 2;
466
+ return;
467
+ }
468
+ if (sub === 'plan') {
469
+ rejectWorkspaceOptions(o, ['json', 'dry-run'], 'workspace plan');
470
+ if (positionals.length !== 1)
471
+ fail('workspace plan 需要且只接受一个 Multica Workspace name');
472
+ const out = planMulticaWorkspace(PROJECT_START, positionals[0], {
473
+ cliVersion: PACKAGE_JSON.version,
474
+ });
475
+ if (o.json)
476
+ console.log(JSON.stringify(out, null, 2));
477
+ else
478
+ printMulticaWorkspaceOperation(out);
479
+ if (out.blocking.length)
480
+ process.exitCode = 2;
481
+ return;
482
+ }
483
+ if (sub === 'inspect') {
484
+ rejectWorkspaceOptions(o, ['json', 'execute', 'yes', 'out', 'timeout'], 'workspace inspect');
485
+ if (positionals.length !== 1)
486
+ fail('workspace inspect 需要且只接受一个 Multica Workspace name');
487
+ if (Boolean(o.execute) !== Boolean(o.yes)) {
488
+ fail('workspace inspect 读取远端时必须同时传 --execute --yes');
489
+ }
490
+ const timeoutMs = o.timeout === undefined ? undefined : Number(o.timeout);
491
+ const out = inspectMulticaWorkspace(PROJECT_START, positionals[0], {
492
+ execute: o.execute, yes: o.yes, out: o.out, timeoutMs,
493
+ cliVersion: PACKAGE_JSON.version,
494
+ });
495
+ if (o.json)
496
+ console.log(JSON.stringify(out, null, 2));
497
+ else
498
+ printMulticaWorkspaceOperation(out);
499
+ if (o.execute && 'passed' in out && !out.passed)
500
+ process.exitCode = 2;
501
+ return;
502
+ }
503
+ if (sub === 'remote-list') {
504
+ rejectWorkspaceOptions(o, ['json', 'execute', 'yes', 'timeout'], 'workspace remote-list');
505
+ if (positionals.length !== 1)
506
+ fail('workspace remote-list 需要且只接受一个 Multica Workspace name');
507
+ if (Boolean(o.execute) !== Boolean(o.yes)) {
508
+ fail('workspace remote-list 读取远端时必须同时传 --execute --yes');
509
+ }
510
+ const timeoutMs = o.timeout === undefined ? undefined : Number(o.timeout);
511
+ const out = listMulticaWorkspaceResources(PROJECT_START, positionals[0], {
512
+ execute: o.execute, yes: o.yes, timeoutMs, cliVersion: PACKAGE_JSON.version,
513
+ });
514
+ if (o.json)
515
+ console.log(JSON.stringify(out, null, 2));
516
+ else
517
+ printMulticaWorkspaceOperation(out);
518
+ if (o.execute && 'passed' in out && !out.passed)
519
+ process.exitCode = 2;
520
+ return;
521
+ }
522
+ if (sub === 'status') {
523
+ rejectWorkspaceOptions(o, ['json'], 'workspace status');
524
+ if (positionals.length !== 1)
525
+ fail('workspace status 需要且只接受一个 Multica Workspace name');
526
+ const out = statusMulticaWorkspace(PROJECT_START, positionals[0], PACKAGE_JSON.version);
527
+ if (o.json)
528
+ console.log(JSON.stringify(out, null, 2));
529
+ else
530
+ printMulticaWorkspaceOperation(out);
531
+ if (!out.readyForApply)
532
+ process.exitCode = 2;
533
+ return;
534
+ }
535
+ if (sub === 'create') {
536
+ rejectWorkspaceOptions(o, ['json', 'yes', 'dry-run'], 'workspace create');
537
+ if (positionals.length !== 1)
538
+ fail('workspace create 需要且只接受一个 Workspace name');
539
+ if (o.yes && o['dry-run'])
540
+ fail('workspace create 的 --dry-run 与 --yes 不能同时使用');
541
+ const out = o.yes
542
+ ? applyOpenCodeWorkspace(PROJECT_START, positionals[0], {
543
+ yes: true, cliVersion: PACKAGE_JSON.version,
544
+ })
545
+ : planOpenCodeWorkspace(PROJECT_START, positionals[0], PACKAGE_JSON.version);
546
+ if (o.json)
547
+ console.log(JSON.stringify(out, null, 2));
548
+ else
549
+ printOpenCodeWorkspaceOperation(out);
550
+ return;
551
+ }
552
+ if (sub === 'use') {
553
+ rejectWorkspaceOptions(o, ['json'], 'workspace use');
554
+ if (positionals.length !== 1)
555
+ fail('workspace use 需要且只接受一个 Workspace name');
556
+ const out = useOpenCodeWorkspace(PROJECT_START, positionals[0], PACKAGE_JSON.version);
557
+ if (o.json)
558
+ console.log(JSON.stringify(out, null, 2));
559
+ else
560
+ console.log(`✅ current workspace: ${out.previous || '-'} → ${out.current}`);
561
+ return;
562
+ }
563
+ if (sub === 'run') {
564
+ rejectWorkspaceOptions(o, ['json', 'yes', 'execute', 'prompt-file', 'out', 'timeout'], 'workspace run');
565
+ if (positionals.length !== 1 || !o['prompt-file']) {
566
+ fail('workspace run 需要一个 Workspace name 和 --prompt-file <file>');
567
+ }
568
+ const timeoutMs = o.timeout === undefined ? undefined : Number(o.timeout);
569
+ const prompt = readProjectText(PROJECT_START, o['prompt-file'], 'workspace run prompt');
570
+ const out = runOpenCodeWorkspace(PROJECT_START, positionals[0], prompt, {
571
+ execute: o.execute, yes: o.yes, timeoutMs, out: o.out,
572
+ });
573
+ if (o.json)
574
+ console.log(JSON.stringify(out, null, 2));
575
+ else if (out.$schema === 'dingtalk-agent/opencode-workspace-run-plan@1') {
576
+ console.log(`DRY-RUN workspace=${out.workspace} model=${out.model} prompt=${out.promptHash}`);
577
+ }
578
+ else {
579
+ console.log(`${out.passed ? '✅' : '❌'} workspace run ${out.runId}`);
580
+ if (out.execution?.answer)
581
+ console.log(out.execution.answer);
582
+ if (out.evidencePath)
583
+ console.log(`evidence=${out.evidencePath}`);
584
+ }
585
+ if (o.execute && !out.passed)
586
+ process.exitCode = 2;
587
+ return;
588
+ }
589
+ if (sub === 'eval') {
590
+ rejectWorkspaceOptions(o, ['json', 'yes', 'execute', 'suite', 'cases', 'lanes', 'runs', 'out', 'previous-skill'], 'workspace eval');
591
+ if (positionals.length !== 1 || !o.suite) {
592
+ fail('workspace eval 需要一个 Workspace name 和 --suite <file>');
593
+ }
594
+ const lanes = String(o.lanes || '').split(',').map((item) => item.trim()).filter(Boolean);
595
+ const invalid = lanes.filter((item) => !['stateless', 'stateful', 'role'].includes(item));
596
+ if (invalid.length)
597
+ fail(`workspace eval lanes 非法: ${invalid.join(',')}`);
598
+ const cases = String(o.cases || '').split(',').map((item) => item.trim()).filter(Boolean);
599
+ const runs = o.runs === undefined ? undefined : Number(o.runs);
600
+ const out = evalOpenCodeWorkspace(PROJECT_START, positionals[0], o.suite, {
601
+ lanes: lanes, caseIds: cases, runs, out: o.out,
602
+ previousSkill: o['previous-skill'], execute: o.execute, yes: o.yes,
603
+ });
604
+ if (o.json)
605
+ console.log(JSON.stringify(out, null, 2));
606
+ else
607
+ printLab(out.report || out);
608
+ if (o.execute && !out.passed)
609
+ process.exitCode = 2;
610
+ return;
611
+ }
612
+ fail(`不认识的 workspace 子命令: ${sub || '(缺失)'}`, 1, `可用命令: dta workspace list | show | doctor | plan | inspect | remote-list | status | create | use | run | eval${suggest(sub || '', ['list', 'show', 'doctor', 'plan', 'inspect', 'remote-list', 'status', 'create', 'use', 'run', 'eval'], 'dta workspace')}`);
613
+ }
614
+ // ── setup / upgrade / doctor:机器级安装与环境闭环。──
141
615
  if (cmd === 'setup') {
142
616
  const { values: o } = parseArgs({
143
617
  args: argv.slice(1),
@@ -174,19 +648,39 @@ async function main() {
174
648
  process.exitCode = 2;
175
649
  return;
176
650
  }
651
+ if (cmd === 'upgrade') {
652
+ const { values: o } = parseArgs({
653
+ args: argv.slice(1),
654
+ options: {
655
+ channel: { type: 'string' }, version: { type: 'string' }, prefix: { type: 'string' },
656
+ 'dry-run': { type: 'boolean' }, force: { type: 'boolean' }, json: { type: 'boolean' },
657
+ },
658
+ });
659
+ const out = upgradeAgent(PACKAGE_ROOT, {
660
+ channel: o.channel,
661
+ version: o.version, prefix: o.prefix,
662
+ dryRun: o['dry-run'], force: o.force,
663
+ });
664
+ if (o.json)
665
+ console.log(JSON.stringify(out, null, 2));
666
+ else
667
+ printUpgrade(out);
668
+ if (!out.dryRun && !out.ready)
669
+ process.exitCode = 2;
670
+ return;
671
+ }
177
672
  // ── skill:唯一一次性的主入口;完全不依赖 Workspace。──
178
673
  if (cmd === 'skill') {
179
- const { values: o } = parseArgs({
674
+ const { values: o, positionals } = parseArgs({
180
675
  args: argv.slice(2),
676
+ allowPositionals: true,
181
677
  options: {
182
- 'dry-run': { type: 'boolean' }, json: { type: 'boolean' },
183
- 'discard-local-changes': { type: 'boolean' },
678
+ name: { type: 'string' }, 'dry-run': { type: 'boolean' }, json: { type: 'boolean' },
184
679
  },
185
680
  });
186
- const options = {
187
- dryRun: o['dry-run'],
188
- discardLocalChanges: o['discard-local-changes'],
189
- };
681
+ if (positionals.length > 1)
682
+ fail('skill 最多接受一个 Skill name');
683
+ const options = { dryRun: o['dry-run'], name: o.name || positionals[0] };
190
684
  let out;
191
685
  if (sub === 'install')
192
686
  out = installGlobalSkill(PACKAGE_ROOT, options);
@@ -197,7 +691,7 @@ async function main() {
197
691
  else if (sub === 'uninstall')
198
692
  out = uninstallGlobalSkill(PACKAGE_ROOT, options);
199
693
  else
200
- fail('skill 的子命令: install / status / upgrade / uninstall');
694
+ fail(`不认识的 skill 子命令: ${sub || '(缺失)'}`, 1, `可用命令: dta skill install | status | upgrade | uninstall${suggest(sub || '', ['install', 'status', 'upgrade', 'uninstall'], 'dta skill')}`);
201
695
  if (o.json)
202
696
  console.log(JSON.stringify(out, null, 2));
203
697
  else
@@ -209,18 +703,27 @@ async function main() {
209
703
  const { values: o } = parseArgs({
210
704
  args: argv.slice(1),
211
705
  options: {
212
- storage: { type: 'string' }, 'state-dir': { type: 'string' },
213
- profile: { type: 'string' }, json: { type: 'boolean' },
706
+ agent: { type: 'string' }, storage: { type: 'string' },
707
+ memory: { type: 'string' }, knowledge: { type: 'string' },
708
+ skills: { type: 'string' }, artifacts: { type: 'string' },
709
+ 'state-dir': { type: 'string' }, profile: { type: 'string' },
710
+ 'expected-user-id': { type: 'string' }, bindings: { type: 'string' },
711
+ json: { type: 'boolean' },
214
712
  },
215
713
  });
714
+ const loaded = loadConventionalBindings(o.bindings);
216
715
  const out = bootstrap(ROOT, {
217
- storage: o.storage, stateDir: o['state-dir'], profile: o.profile,
716
+ agent: o.agent, storage: o.storage,
717
+ memory: o.memory, knowledge: o.knowledge, skills: o.skills,
718
+ artifacts: o.artifacts, stateDir: o['state-dir'], profile: o.profile,
719
+ expectedUserId: o['expected-user-id'], context: loaded?.context,
218
720
  });
219
721
  if (o.json)
220
722
  console.log(JSON.stringify(out, null, 2));
221
723
  else {
222
724
  console.log(`✅ ${out.mode === 'workspace' ? '已装载 Workspace' : '直接会话模式'}`);
223
725
  console.log(` scope=${out.scopeId} initialized=${out.initialized}`);
726
+ console.log(` agent=${out.definition.id} definition=${out.definition.status}`);
224
727
  if (!out.mounts.length)
225
728
  console.log(' 没有发现持久上下文;这不是错误,也不需要自动 init。');
226
729
  for (const mount of out.mounts)
@@ -229,6 +732,189 @@ async function main() {
229
732
  }
230
733
  return;
231
734
  }
735
+ // ── agent audit:本地定义、Host exposure、真加载与存储证据的稳定验收面。──
736
+ if (cmd === 'agent') {
737
+ if (!['audit', 'enhance'].includes(sub || ''))
738
+ fail(`不认识的 agent 子命令: ${sub || '(缺失)'}`, 1, `可用命令: dta agent audit / dta agent enhance${suggest(sub || '', ['audit', 'enhance'], 'dta agent')}`);
739
+ if (sub === 'enhance') {
740
+ const { values: o } = parseArgs({
741
+ args: argv.slice(2),
742
+ options: {
743
+ bindings: { type: 'string' }, 'project-name': { type: 'string' },
744
+ 'role-skill': { type: 'string' }, model: { type: 'string' },
745
+ memory: { type: 'string' }, knowledge: { type: 'string' },
746
+ artifacts: { type: 'string' }, 'state-dir': { type: 'string' },
747
+ profile: { type: 'string' }, 'expected-user-id': { type: 'string' },
748
+ 'plan-id': { type: 'string' }, 'dry-run': { type: 'boolean' },
749
+ yes: { type: 'boolean' }, json: { type: 'boolean' },
750
+ },
751
+ });
752
+ if (o.yes && o['dry-run'])
753
+ fail('agent enhance 的 --dry-run 与 --yes 不能同时使用');
754
+ if (!o.yes && o['plan-id'])
755
+ fail('agent enhance plan 不接受 --plan-id;它由 dry-run 生成');
756
+ const options = {
757
+ bindings: o.bindings, projectName: o['project-name'],
758
+ roleSkills: o['role-skill']?.split(','), model: o.model,
759
+ memory: o.memory, knowledge: o.knowledge, artifacts: o.artifacts,
760
+ stateDir: o['state-dir'], profile: o.profile,
761
+ expectedUserId: o['expected-user-id'], cliVersion: PACKAGE_JSON.version,
762
+ planId: o['plan-id'], yes: o.yes,
763
+ };
764
+ const out = o.yes
765
+ ? applyAgentEnhancement(ROOT, options)
766
+ : planAgentEnhancement(ROOT, options);
767
+ if (o.json)
768
+ console.log(JSON.stringify(out, null, 2));
769
+ else
770
+ printAgentEnhance(out);
771
+ if ('$schema' in out && out.$schema === 'dingtalk-agent/agent-enhancement-plan@1' && !out.ready) {
772
+ process.exitCode = 2;
773
+ }
774
+ return;
775
+ }
776
+ const { values: o } = parseArgs({
777
+ args: argv.slice(2),
778
+ options: {
779
+ bindings: { type: 'string' }, agent: { type: 'string' }, storage: { type: 'string' },
780
+ memory: { type: 'string' }, knowledge: { type: 'string' },
781
+ skills: { type: 'string' }, artifacts: { type: 'string' },
782
+ 'state-dir': { type: 'string' }, profile: { type: 'string' },
783
+ 'expected-user-id': { type: 'string' }, 'require-skill': { type: 'string' },
784
+ 'verify-load': { type: 'boolean' }, yes: { type: 'boolean' },
785
+ model: { type: 'string' }, out: { type: 'string' },
786
+ 'load-report': { type: 'string' }, 'remote-report': { type: 'string' },
787
+ json: { type: 'boolean' },
788
+ },
789
+ });
790
+ const loaded = loadConventionalBindings(o.bindings);
791
+ const out = auditAgent(ROOT, {
792
+ bootstrap: {
793
+ agent: o.agent, storage: o.storage,
794
+ memory: o.memory, knowledge: o.knowledge, skills: o.skills,
795
+ artifacts: o.artifacts, stateDir: o['state-dir'], profile: o.profile,
796
+ expectedUserId: o['expected-user-id'], context: loaded?.context,
797
+ },
798
+ bindings: loaded ? { path: loaded.path, hash: loaded.hash } : undefined,
799
+ requiredSkills: o['require-skill']?.split(','),
800
+ verifyLoad: o['verify-load'], yes: o.yes, model: o.model, out: o.out,
801
+ loadReport: o['load-report'], remoteReport: o['remote-report'],
802
+ });
803
+ if (o.json)
804
+ console.log(JSON.stringify(out, null, 2));
805
+ else
806
+ printAgentAudit(out);
807
+ if (!out.ready)
808
+ process.exitCode = 2;
809
+ return;
810
+ }
811
+ // ── lab:测试控制面;默认无副作用,Live 必须 manifest + --live --yes。──
812
+ if (cmd === 'lab') {
813
+ const { values: o } = parseArgs({
814
+ args: argv.slice(2),
815
+ options: {
816
+ manifest: { type: 'string' }, evidence: { type: 'string' },
817
+ 'event-file': { type: 'string' }, 'case-id': { type: 'string' },
818
+ pool: { type: 'string' }, suite: { type: 'string' }, lanes: { type: 'string' },
819
+ cases: { type: 'string' },
820
+ engine: { type: 'string' }, workspace: { type: 'string' }, model: { type: 'string' },
821
+ runs: { type: 'string' }, out: { type: 'string' },
822
+ 'previous-skill': { type: 'string' }, execute: { type: 'boolean' },
823
+ reply: { type: 'string' }, input: { type: 'string' },
824
+ live: { type: 'boolean' }, yes: { type: 'boolean' }, json: { type: 'boolean' },
825
+ },
826
+ });
827
+ let out;
828
+ if (sub === 'doctor') {
829
+ if (!o.manifest)
830
+ fail('lab doctor 需要 --manifest <file>');
831
+ out = doctorLab(ROOT, o.manifest);
832
+ if (!out.ready)
833
+ process.exitCode = 2;
834
+ }
835
+ else if (sub === 'run') {
836
+ if (!o.manifest || !o['case-id'])
837
+ fail('lab run 需要 --manifest 和 --case-id');
838
+ const rawEvent = o['event-file']
839
+ ? readEventFile(o['event-file']) : null;
840
+ out = runLab(ROOT, cfgmod.must(ROOT), o.manifest, rawEvent, {
841
+ caseId: o['case-id'], replyText: o.reply, inputText: o.input,
842
+ live: o.live, yes: o.yes,
843
+ });
844
+ }
845
+ else if (sub === 'verify') {
846
+ if (!o.evidence)
847
+ fail('lab verify 需要 --evidence <run-dir>');
848
+ out = verifyLab(ROOT, o.evidence);
849
+ if (!out.passed)
850
+ process.exitCode = 2;
851
+ }
852
+ else if (sub === 'teardown') {
853
+ if (!o.manifest || !o.evidence)
854
+ fail('lab teardown 需要 --manifest 和 --evidence');
855
+ out = teardownLab(ROOT, o.manifest, o.evidence, { live: o.live, yes: o.yes });
856
+ }
857
+ else if (sub === 'eval') {
858
+ if (!o.suite)
859
+ fail('lab eval 需要 --suite');
860
+ const lanes = String(o.lanes || '').split(',').map((item) => item.trim()).filter(Boolean);
861
+ const invalid = lanes.filter((item) => !['stateless', 'stateful', 'role'].includes(item));
862
+ if (invalid.length)
863
+ fail(`lab eval lanes 非法: ${invalid.join(',')}`);
864
+ const cases = String(o.cases || '').split(',').map((item) => item.trim()).filter(Boolean);
865
+ const engine = o.engine || 'robot';
866
+ if (engine === 'opencode') {
867
+ if (!o.workspace)
868
+ fail('OpenCode eval 需要 --workspace <agent-dir>');
869
+ const runs = o.runs === undefined ? undefined : Number(o.runs);
870
+ out = runOpenCodeEvaluation(ROOT, o.workspace, o.suite, {
871
+ lanes: lanes, model: o.model, runs,
872
+ caseIds: cases, previousSkill: o['previous-skill'],
873
+ execute: o.execute, yes: o.yes, out: o.out,
874
+ });
875
+ if (o.execute && !out.passed)
876
+ process.exitCode = 2;
877
+ }
878
+ else if (engine === 'storage') {
879
+ if (!o.workspace)
880
+ fail('Remote State eval 需要 --workspace <agent-dir>');
881
+ out = runStorageEvaluation(ROOT, o.workspace, o.suite, {
882
+ model: o.model, execute: o.execute, live: o.live, yes: o.yes, out: o.out,
883
+ });
884
+ if (o.execute && !out.passed)
885
+ process.exitCode = 2;
886
+ }
887
+ else if (engine === 'personal-event') {
888
+ if (!o.workspace)
889
+ fail('Personal Event eval 需要 --workspace <agent-dir>');
890
+ out = runPersonalEventEvaluation(ROOT, o.workspace, o.suite, {
891
+ execute: o.execute, live: o.live, yes: o.yes, out: o.out,
892
+ });
893
+ if (o.execute && !out.passed)
894
+ process.exitCode = 2;
895
+ }
896
+ else if (engine === 'robot') {
897
+ if (!o.pool)
898
+ fail('Robot eval 需要 --pool <pool.local.json>');
899
+ out = runRobotEvaluation(ROOT, o.pool, o.suite, {
900
+ lanes: lanes, live: o.live, yes: o.yes,
901
+ });
902
+ if (o.live && !out.passed)
903
+ process.exitCode = 2;
904
+ }
905
+ else {
906
+ fail(`lab eval engine 非法: ${engine};只支持 robot、opencode、storage 或 personal-event`);
907
+ }
908
+ }
909
+ else {
910
+ fail(`不认识的 lab 子命令: ${sub || '(缺失)'}`, 1, '可用命令: dta lab doctor | run | verify | teardown | eval;详见 dta help lab。');
911
+ }
912
+ if (o.json)
913
+ console.log(JSON.stringify(out, null, 2));
914
+ else
915
+ printLab(out);
916
+ return;
917
+ }
232
918
  // ── init ──
233
919
  if (cmd === 'init') {
234
920
  const { values: o } = parseArgs({
@@ -253,6 +939,7 @@ async function main() {
253
939
  options: {
254
940
  'event-file': { type: 'string' }, field: { type: 'string' },
255
941
  'session-key': { type: 'string' }, 'context-id': { type: 'string' },
942
+ 'perception-file': { type: 'string' },
256
943
  json: { type: 'boolean' },
257
944
  },
258
945
  });
@@ -261,6 +948,7 @@ async function main() {
261
948
  fail('prepare 需要 --event-file <file|->');
262
949
  const out = prepareSession(ROOT, cfg, readEventFile(file), {
263
950
  fieldId: o.field, sessionKey: o['session-key'], contextId: o['context-id'],
951
+ perception: o['perception-file'] ? readEventFile(o['perception-file']) : undefined,
264
952
  });
265
953
  printDispatch(out, o.json);
266
954
  return;
@@ -274,12 +962,14 @@ async function main() {
274
962
  stdin: { type: 'boolean' }, 'event-file': { type: 'string' },
275
963
  field: { type: 'string' }, 'session-key': { type: 'string' },
276
964
  'context-id': { type: 'string' },
965
+ 'perception-file': { type: 'string' },
277
966
  heartbeat: { type: 'boolean' }, 'heartbeat-key': { type: 'string' },
278
967
  'heartbeat-event-id': { type: 'string' },
279
968
  },
280
969
  });
281
970
  const options = {
282
971
  fieldId: o.field, sessionKey: o['session-key'], contextId: o['context-id'],
972
+ perception: o['perception-file'] ? readEventFile(o['perception-file']) : undefined,
283
973
  };
284
974
  const modes = [Boolean(o.stdin), Boolean(o.heartbeat), Boolean(o['event-file'] || positionals[0])];
285
975
  if (modes.filter(Boolean).length !== 1) {
@@ -391,6 +1081,133 @@ async function main() {
391
1081
  }
392
1082
  fail('dispatch 的子命令: pending / ack');
393
1083
  }
1084
+ // ── task:Session 语义 checkpoint;revision CAS,不承担 Wait/锁/Receipt。──
1085
+ if (cmd === 'task') {
1086
+ const cfg = cfgmod.must(ROOT);
1087
+ const { values: o } = parseArgs({
1088
+ args: argv.slice(2),
1089
+ options: {
1090
+ input: { type: 'string' }, session: { type: 'string' },
1091
+ 'expect-revision': { type: 'string' }, json: { type: 'boolean' },
1092
+ },
1093
+ });
1094
+ let out;
1095
+ if (sub === 'show') {
1096
+ out = showTaskCheckpoint(ROOT, cfg, {
1097
+ sessionPath: o.session || process.env.DTA_SESSION,
1098
+ runPath: process.env.DTA_RUN,
1099
+ });
1100
+ }
1101
+ else if (sub === 'checkpoint') {
1102
+ if (!o.input || o['expect-revision'] === undefined) {
1103
+ fail('task checkpoint 需要 --input 和 --expect-revision');
1104
+ }
1105
+ const expectedRevision = Number(o['expect-revision']);
1106
+ out = checkpointTask(ROOT, cfg, readEventFile(o.input), expectedRevision, {
1107
+ sessionPath: o.session || process.env.DTA_SESSION,
1108
+ runPath: process.env.DTA_RUN,
1109
+ });
1110
+ }
1111
+ else {
1112
+ fail('task 的子命令: show / checkpoint');
1113
+ }
1114
+ if (o.json)
1115
+ console.log(JSON.stringify(out, null, 2));
1116
+ else if (!out.found)
1117
+ console.log('当前 Session 尚无 Task checkpoint。');
1118
+ else {
1119
+ console.log(`✅ Task ${out.checkpoint.taskId} · ${out.checkpoint.status}`);
1120
+ console.log(` revision=${out.checkpoint.revision} hash=${out.hash}`);
1121
+ console.log(` next=${out.checkpoint.nextAction || '-'}`);
1122
+ }
1123
+ return;
1124
+ }
1125
+ // ── memory:Provider-neutral 语义路由;当前首个远端事实源是 AI 表格。──
1126
+ if (cmd === 'memory') {
1127
+ const action = argv[2];
1128
+ if (sub === 'operational' && action === 'upsert') {
1129
+ const { values: o } = parseArgs({
1130
+ args: argv.slice(3),
1131
+ options: {
1132
+ provider: { type: 'string' }, input: { type: 'string' },
1133
+ live: { type: 'boolean' }, yes: { type: 'boolean' }, json: { type: 'boolean' },
1134
+ },
1135
+ });
1136
+ const providerPath = o.provider || process.env.DTA_OPERATIONAL_MEMORY_PROVIDER;
1137
+ if (!providerPath || !o.input) {
1138
+ fail('memory operational upsert 需要 --provider(或 DTA_OPERATIONAL_MEMORY_PROVIDER)和 --input');
1139
+ }
1140
+ const out = upsertOperationalMemory(readEventFile(providerPath), readEventFile(o.input), { execute: Boolean(o.live), yes: Boolean(o.yes) });
1141
+ if (o.json || !o.live)
1142
+ console.log(JSON.stringify(out, null, 2));
1143
+ else {
1144
+ console.log(`${out.verified ? '✅' : '⚠️'} Operational Memory · ${out.mode}`);
1145
+ console.log(` record=${out.recordId || '-'} verification=${out.verification}`);
1146
+ }
1147
+ if (out.mode === 'uncertain')
1148
+ process.exitCode = 2;
1149
+ return;
1150
+ }
1151
+ if (sub === 'candidate') {
1152
+ const { values: o } = parseArgs({
1153
+ args: argv.slice(3),
1154
+ options: {
1155
+ input: { type: 'string' }, id: { type: 'string' }, target: { type: 'string' },
1156
+ decision: { type: 'string' }, reviewer: { type: 'string' }, reason: { type: 'string' },
1157
+ 'state-dir': { type: 'string' }, 'expect-revision': { type: 'string' },
1158
+ 'expect-target-hash': { type: 'string' },
1159
+ live: { type: 'boolean' }, yes: { type: 'boolean' }, json: { type: 'boolean' },
1160
+ },
1161
+ });
1162
+ const options = { stateDir: o['state-dir'], runPath: process.env.DTA_RUN };
1163
+ let out;
1164
+ if (action === 'propose') {
1165
+ if (!o.input)
1166
+ fail('memory candidate propose 需要 --input');
1167
+ out = proposeMemoryCandidate(ROOT, readEventFile(o.input), options);
1168
+ }
1169
+ else if (action === 'show') {
1170
+ if (!o.id)
1171
+ fail('memory candidate show 需要 --id');
1172
+ out = showMemoryCandidate(ROOT, o.id, options);
1173
+ }
1174
+ else if (action === 'review') {
1175
+ if (!o.id || !o.decision || !o.reviewer || !o.reason ||
1176
+ o['expect-revision'] === undefined) {
1177
+ fail('memory candidate review 需要 --id/--decision/--reviewer/--reason/--expect-revision');
1178
+ }
1179
+ out = reviewMemoryCandidate(ROOT, o.id, o.decision, o.reviewer, o.reason, Number(o['expect-revision']), options);
1180
+ }
1181
+ else if (action === 'publish') {
1182
+ if (!o.id || !o.target || o['expect-revision'] === undefined) {
1183
+ fail('memory candidate publish 需要 --id/--target/--expect-revision');
1184
+ }
1185
+ out = publishMemoryCandidate(ROOT, o.id, readEventFile(o.target), Number(o['expect-revision']), o['expect-target-hash'] || '', {
1186
+ ...options,
1187
+ execute: Boolean(o.yes || o.live),
1188
+ yes: Boolean(o.yes),
1189
+ live: Boolean(o.live),
1190
+ });
1191
+ }
1192
+ else {
1193
+ fail('memory candidate 的子命令: propose / show / review / publish');
1194
+ }
1195
+ if (o.json)
1196
+ console.log(JSON.stringify(out, null, 2));
1197
+ else if (action === 'publish') {
1198
+ console.log(`${out.verified ? '✅' : out.mode === 'dry-run' ? '🔎' : '⚠️'} Candidate ${o.id}`);
1199
+ console.log(` mode=${out.mode} targetHash=${out.currentTargetHash}`);
1200
+ }
1201
+ else {
1202
+ console.log(`✅ Candidate ${out.candidate.id} · ${out.candidate.status}`);
1203
+ console.log(` revision=${out.candidate.revision} path=${out.path}`);
1204
+ }
1205
+ if (action === 'publish' && out.mode === 'uncertain')
1206
+ process.exitCode = 2;
1207
+ return;
1208
+ }
1209
+ fail('memory 当前支持: operational upsert / candidate propose|show|review|publish');
1210
+ }
394
1211
  // ── act:元语化动作;目标/身份/预算/状态转移都由 Run 固定 ──
395
1212
  if (cmd === 'act') {
396
1213
  const kind = sub;
@@ -423,284 +1240,70 @@ async function main() {
423
1240
  process.exitCode = 2;
424
1241
  return;
425
1242
  }
426
- // ── eval:宿主评测入口;shadow 永不调用 act / DWS。──
427
- if (cmd === 'eval') {
428
- const script = sub === 'contract'
429
- ? join(PACKAGE_ROOT, 'evals', 'run-contract-evals.mjs')
430
- : sub === 'shadow'
431
- ? join(PACKAGE_ROOT, 'evals', 'runners', 'claude-shadow.mjs')
432
- : sub === 'behavior'
433
- ? join(PACKAGE_ROOT, 'evals', 'run-shadow-evals.mjs')
434
- : '';
435
- if (!script)
436
- fail('eval 的子命令: contract / shadow / behavior');
437
- const childEnv = { ...process.env };
438
- // 合同评测会创建隔离工作区;继承宿主 DTA_ROOT 会让 Action Gate 错读外层 control store。
439
- delete childEnv.DTA_ROOT;
440
- const child = spawnSync(process.execPath, [script, ...argv.slice(2)], {
441
- cwd: ROOT,
442
- env: childEnv,
443
- stdio: 'inherit',
444
- });
445
- if (child.error)
446
- throw child.error;
447
- if (child.signal)
448
- throw new Error(`评测进程被 ${child.signal} 终止`);
449
- process.exitCode = child.status ?? 2;
450
- return;
1243
+ fail(`不认识的命令: ${cmd}`, 1, `运行 dta --help 查看全部命令${suggest(cmd, [
1244
+ 'setup', 'upgrade', 'doctor', 'skill', 'bootstrap', 'init', 'prepare', 'run', 'dispatch', 'task', 'memory', 'act',
1245
+ 'agent',
1246
+ 'info', 'workspace',
1247
+ ])}`);
1248
+ }
1249
+ function loadConventionalBindings(input) {
1250
+ const conventional = 'agent.bindings.json';
1251
+ const selected = input || (existsSync(resolve(ROOT, conventional)) ? conventional : '');
1252
+ return selected ? loadAgentBindings(ROOT, selected) : null;
1253
+ }
1254
+ function errorHint(message) {
1255
+ if (/unknown option|未知选项|unexpected argument/i.test(message)) {
1256
+ return '检查参数拼写;运行 dta --help 查看当前版本支持的参数。';
451
1257
  }
452
- if (cmd === 'smoke') {
453
- const script = join(PACKAGE_ROOT, 'evals', 'run-contract-evals.mjs');
454
- const childEnv = { ...process.env };
455
- delete childEnv.DTA_ROOT;
456
- const child = spawnSync(process.execPath, [script, '--smoke'], {
457
- cwd: ROOT, env: childEnv, stdio: 'inherit',
458
- });
459
- if (child.error)
460
- throw child.error;
461
- if (child.signal)
462
- throw new Error(`Smoke 被 ${child.signal} 终止`);
463
- process.exitCode = child.status ?? 2;
464
- return;
1258
+ if (/找不到当前 Run|必须由能访问 DTA_ROOT 的宿主侧执行/.test(message)) {
1259
+ return 'act 只能用于可信事件 Run;先由宿主执行 dta prepare --event-file <file>,再进入返回的 cwd。';
465
1260
  }
466
- // ── kb ──
467
- if (cmd === 'kb') {
468
- const cfg = cfgmod.must(ROOT);
469
- const { values: o } = parseArgs({
470
- args: argv.slice(2), allowPositionals: true,
471
- options: {
472
- name: { type: 'string' }, from: { type: 'string' }, own: { type: 'string' },
473
- sync: { type: 'string' }, local: { type: 'string' }, force: { type: 'boolean' },
474
- },
475
- });
476
- if (sub === 'mount') {
477
- if (!o.name || !o.from)
478
- fail('要 --name 和 --from。源的写法见 --help');
479
- kbmod.parseSource(o.from); // 写错了当场炸
480
- const own = o.own || kbmod.EXTERNAL;
481
- const sync = o.sync || (own === kbmod.OWNED ? kbmod.PUSH : kbmod.PULL);
482
- if (own === kbmod.OWNED && sync === kbmod.PULL) {
483
- fail('owned 的真值在 Git,不该 pull —— 那会把远端的东西覆盖到本地。\n' +
484
- ' **所有权决定真值方向。** owned → push;external → pull。');
485
- }
486
- const local = o.local || join('.cache/kb', o.name);
487
- cfg.kb = (cfg.kb || []).filter((k) => k.name !== o.name);
488
- cfg.kb.push({ name: o.name, from: o.from, own, sync, local });
489
- cfgmod.save(ROOT, cfg);
490
- console.log(`✅ 挂上「${o.name}」 ${o.from}`);
491
- console.log(` 所有权=${own} · 同步=${sync} · 落在 ${local}`);
492
- console.log(own === kbmod.OWNED
493
- ? ' (真值在 Git,钉钉是暴露层。人在钉钉里改了 → sync 时会【停下来问】,不盲覆盖。)'
494
- : ' (真值在钉钉,本地只是【可丢弃的缓存】。过期了 kb search 会警告。)');
495
- return;
496
- }
497
- if (sub === 'list') {
498
- if (!cfg.kb?.length)
499
- return console.log('一个都没挂。 kb mount --help');
500
- for (const kb of cfg.kb) {
501
- const s = kbmod.stale(kb);
502
- console.log(` ${s ? '⚠️' : '·'} ${kb.name.padEnd(14)} ${kb.own.padEnd(9)} ${kb.sync.padEnd(5)} ${kb.from}`);
503
- console.log(` 落在 ${kb.local} 上次同步 ${kb._syncedAt || '从未'}${s ? ' ← **过期了,不许拿来回答**' : ''}`);
504
- }
505
- return;
506
- }
507
- if (sub === 'sync') {
508
- const targets = (cfg.kb || []).filter((k) => !o.name || k.name === o.name);
509
- if (!targets.length)
510
- fail('没有这个知识库。 kb list');
511
- for (const kb of targets) {
512
- if (kb.sync === kbmod.NONE) {
513
- console.log(` skip ${kb.name}(sync=none)`);
514
- continue;
515
- }
516
- if (kb.sync === kbmod.PULL)
517
- kbmod.pull(kb, ROOT, o.force);
518
- else
519
- kbmod.push(kb, ROOT, o.force);
520
- }
521
- cfgmod.save(ROOT, cfg);
522
- return;
523
- }
524
- if (sub === 'search') {
525
- const kw = argv[2];
526
- if (!kw)
527
- fail('要给关键词。 kb search "<关键词>"');
528
- kbmod.search(cfg, ROOT, kw);
529
- return;
530
- }
531
- fail('kb 的子命令: mount / list / sync / search');
1261
+ if (/OpenCode/.test(message)) {
1262
+ return '检查 OpenCode 版本、模型认证与项目 Skill/config;运行 dta workspace doctor <name> 查看精确缺口。';
532
1263
  }
533
- // ── boot ──
534
- if (cmd === 'boot') {
535
- boot(cfgmod.must(ROOT), ROOT);
536
- return;
1264
+ if (/Multica|multica/.test(message)) {
1265
+ return '先运行 dta workspace plan <name> 和 doctor;确认 profile/ID 来源后,再用 inspect --execute --yes 做只读回读。';
537
1266
  }
538
- // ── duty ──
539
- if (cmd === 'duty') {
540
- const cfg = cfgmod.must(ROOT);
541
- const { values: o } = parseArgs({
542
- args: argv.slice(1), allowPositionals: true,
543
- options: { check: { type: 'boolean' }, run: { type: 'string' },
544
- list: { type: 'boolean' }, force: { type: 'boolean' } },
545
- });
546
- const duties = dutymod.loadDuties(cfg, ROOT);
547
- if (o.list) {
548
- const ks = Object.keys(duties);
549
- console.log(ks.length ? ks.join('\n')
550
- : '(值班表是空的 —— 母体出厂如此,这是【正确】的。在 .dingtalk-agent/config.json 的 duties 里加。)');
551
- return;
552
- }
553
- if (o.run) {
554
- const fn = duties[o.run];
555
- if (!fn)
556
- fail(`没有这个值班: ${o.run}(有: ${Object.keys(duties).join('、') || '无'})`);
557
- const s = fn();
558
- if (s.kind === '交付' && !dutymod.inDeliver() && !o.force) {
559
- return console.log(`⏸ 「${o.run}」是外发动作,静默时段顺延,**不打扰第三方**。`);
560
- }
561
- if (s.done)
562
- return console.log(`✅ 「${o.run}」已完成,本拍无需执行。${s.detail}`);
563
- console.log(`【${o.run}】该做了。${s.gap}`);
564
- console.log(` 剧本: ${s.playbook || '(没写剧本 —— 这个值班不合格)'}`);
565
- console.log(` ⚠️ 送达【回读确认】之后才准记 pass。没送达就写 pass = 自己骗自己。`);
566
- return;
567
- }
568
- // --check(默认)
569
- console.log('值班表(**完成状态在数据里,不在记忆里**;幂等,漏拍下一拍自愈)');
570
- console.log(` 现在 ${runsmod.now().slice(11, 16)} · ${dutymod.inNight() ? '夜间窗口(重活可跑)' : '白天(重活挂起)'} · 外发窗口${dutymod.inDeliver() ? '开' : '关'}`);
571
- const ids = Object.keys(duties);
572
- if (!ids.length) {
573
- console.log('\n (值班表是空的 —— 母体出厂如此。)');
574
- return;
575
- }
576
- const todo = [];
577
- for (const id of ids) {
578
- const s = duties[id]();
579
- const mark = s.done ? '✅ 已完成' : (s.due ? '⬜ 待补齐' : '⏸ 不在窗口');
580
- console.log(` ${s.id.padEnd(8)} [${s.kind}] ${mark} ${s.detail}${s.gap ? ' → ' + s.gap : ''}`);
581
- if (!s.done && s.due)
582
- todo.push(s.id);
583
- }
584
- if (todo.length) {
585
- console.log(`\n本拍要做: ${todo.map((t) => 'duty --run ' + t).join('、')}`);
586
- process.exit(1);
587
- }
588
- console.log('\n全部补齐,静默即可(**不要为此打扰主人**)');
589
- return;
1267
+ if (/\bDWS\b|\bdws\b/.test(message)) {
1268
+ return '运行 dta doctor 检查 DWS 路径、版本和认证;需要登录时执行 dws auth login。';
590
1269
  }
591
- // ── 留痕与进化 ──
592
- if (cmd === 'log' || cmd === 'logq') {
593
- const { values: o } = parseArgs({
594
- args: argv.slice(1),
595
- options: { did: { type: 'string' }, asked: { type: 'string' }, kind: { type: 'string' },
596
- secs: { type: 'string' }, r: { type: 'string' }, ev: { type: 'string' },
597
- ch: { type: 'string' }, issue: { type: 'string' },
598
- conv: { type: 'string' }, msg: { type: 'string' } },
599
- });
600
- if (!o.did)
601
- fail('要 --did(我怎么答的)');
602
- const t = runsmod.logq(ROOT, {
603
- ...o, did: o.did, secs: +(o.secs || 0), r: o.r || 'pass',
604
- });
605
- console.log(`运行记录已落: runs/${runsmod.today()}.md @${t}`);
606
- if (!o.conv)
607
- console.log(' ⚠️ 没带 --conv —— 事后【拉不出对话流】,这一条基本没有训练价值。');
608
- return;
1270
+ if (/dingtalk-agent\.json|Project 未声明|current-workspace|Development Workspace/.test(message)) {
1271
+ return '在 Agent Project 内运行 dta info;用 dta workspace list/show/doctor 检查声明和漂移。';
609
1272
  }
610
- if (cmd === 'feedback') {
611
- const { values: o } = parseArgs({
612
- args: argv.slice(1),
613
- options: { kind: { type: 'string' }, text: { type: 'string' },
614
- conv: { type: 'string' }, at: { type: 'string' } },
615
- });
616
- if (!o.kind || ![runsmod.FB_OK, runsmod.FB_MORE, runsmod.FB_FIX].includes(o.kind)) {
617
- fail('--kind 只能是 认可 / 追问 / 纠正');
618
- }
619
- const day = runsmod.today();
620
- const rows = runsmod.read(ROOT, day);
621
- let cand = rows.filter((r) => r.asked);
622
- if (o.conv)
623
- cand = cand.filter((r) => r.conv === o.conv);
624
- if (!cand.length)
625
- fail(`今天没有可回填的问答行 —— **是不是答完忘了 logq?**`);
626
- const tgt = o.at ? cand.find((r) => r.t === o.at) : cand[cand.length - 1];
627
- if (!tgt)
628
- fail(`找不到 t=${o.at} 的行`);
629
- tgt.fb = o.kind;
630
- if (o.text)
631
- tgt.fbt = o.text.slice(0, 600);
632
- runsmod.write(ROOT, day, rows);
633
- console.log(`已回填: ${day} @${tgt.t} → 「${o.kind}」(原问: ${(tgt.asked || '').slice(0, 40)})`);
634
- return;
1273
+ if (/skills CLI|\bnpx\b/.test(message)) {
1274
+ return '确认 node、npm、npx PATH 中;也可以复制错误中的 npx skills 命令单独执行。';
635
1275
  }
636
- if (cmd === 'runs') {
637
- const { values: o } = parseArgs({
638
- args: argv.slice(1),
639
- options: { days: { type: 'string' }, conv: { type: 'string' },
640
- issue: { type: 'string' }, top: { type: 'string' } },
641
- });
642
- let rows = runsmod.scan(ROOT, +(o.days || 1));
643
- if (o.conv) {
644
- rows = rows.filter((r) => r.conv === o.conv);
645
- console.log(`【对话流】会话 ${o.conv} · ${rows.length} 条 —— **这就是训练素材**`);
646
- for (const r of rows) {
647
- console.log(` ── ${r._day} ${r.t} issue=${r.issue || '-'} msg=${r.msg || '-'}`);
648
- if (r.asked)
649
- console.log(` 主人: ${r.asked}`);
650
- console.log(` 我 : ${r.did} [${r.r}]`);
651
- if (r.fb)
652
- console.log(` 反馈: ${r.fb}${r.fbt ? ` 「${r.fbt}」` : ''}`);
653
- }
654
- if (!rows.length)
655
- console.log(' (空 —— 这个会话没留痕。**没留痕 = 这些交互等于没发生过。**)');
656
- return;
657
- }
658
- if (o.issue) {
659
- const issue = o.issue;
660
- rows = rows.filter((r) => (r.issue || '').startsWith(issue));
661
- }
662
- console.log(`运行记录 runs/ · ${rows.length} 条`);
663
- for (const r of rows.slice(-(+(o.top || 30)))) {
664
- console.log(` ${r._day} ${r.t} [${(r.r || '').padEnd(11)}] ${(r.ch || '').padEnd(6)} ${(r.did || '').slice(0, 30)} ${r.fb ? '← ' + r.fb : ''}`);
665
- }
666
- return;
1276
+ if (/升级目标|CLI 升级|npm view|npm install/.test(message)) {
1277
+ return '检查 npm registry 与网络后重试 dta upgrade;可先运行 dta upgrade --dry-run 查看目标和完整命令。';
667
1278
  }
668
- if (cmd === 'evolve') {
669
- const { values: o } = parseArgs({ args: argv.slice(1), options: { days: { type: 'string' } } });
670
- const rows = runsmod.scan(ROOT, +(o.days || 7));
671
- const ans = rows.filter((r) => r.asked);
672
- const bad = ans.filter((r) => [runsmod.FB_FIX, runsmod.FB_MORE].includes(r.fb || ''));
673
- const unk = ans.filter((r) => !r.fb);
674
- const failed = rows.filter((r) => ['fail', 'unsupported', 'degraded'].includes(r.r));
675
- console.log(`【进化清单】近 ${o.days || 7} 天`);
676
- console.log(` 面向主人的回答 ${ans.length} 条 · 被【打回】${bad.length} 条 · 引擎层没答出来 ${failed.length} 条`);
677
- if (unk.length)
678
- console.log(` ⚠️ ${unk.length} 条【没收到反馈就结案了】—— 答完没回填,这次交互等于白跑。`);
679
- if (bad.length) {
680
- console.log('\n── 主人打回的(**直接就是这周该改什么**)──');
681
- for (const r of bad) {
682
- console.log(` ${r._day} ${r.t} [${r.fb}] 会话=${r.conv || '-'}`);
683
- console.log(` 主人问: ${(r.asked || '').slice(0, 60)}`);
684
- console.log(` 我答 : ${(r.did || '').slice(0, 60)}`);
685
- console.log(` 他说 : ${r.fbt || '(没记下来)'}`);
686
- console.log(` 复盘 : dingtalk-agent runs --conv ${r.conv || '<会话id>'}`);
687
- }
688
- }
689
- if (!bad.length && !failed.length) {
690
- console.log('\n (没有打回,也没有失败 —— 要么真的都对,要么【没人回填反馈】。看上面那行。)');
691
- }
692
- return;
1279
+ if (/Workspace|Field|Storage|contextId/.test(message)) {
1280
+ return '先运行 dta bootstrap --json 查看当前上下文;确实需要持久 Workspace 时再运行 dta init。';
693
1281
  }
694
- // ── todo:把待办拉全(心跳收件用)──
695
- if (cmd === 'todo') {
696
- const dws = await import('../src/dws.js');
697
- const all = dws.todosAll('false');
698
- console.log(`未完成待办 ${all.length} 条(**已翻页拉全** —— 只看第一页会漏掉循环件)`);
699
- for (const t of all)
700
- console.log(` ${t.taskId} ${(t.subject || '').slice(0, 60)}`);
701
- return;
1282
+ return '运行 dta doctor 检查环境;运行 dta --help 查看可用命令。';
1283
+ }
1284
+ function suggest(input, candidates, prefix = 'dta') {
1285
+ if (!input)
1286
+ return '';
1287
+ const ranked = candidates
1288
+ .map((candidate) => ({ candidate, distance: editDistance(input, candidate) }))
1289
+ .sort((a, b) => a.distance - b.distance);
1290
+ const best = ranked[0];
1291
+ return best && best.distance <= Math.max(2, Math.floor(best.candidate.length / 3))
1292
+ ? `;你是否想输入 ${prefix} ${best.candidate}?`
1293
+ : '';
1294
+ }
1295
+ function editDistance(a, b) {
1296
+ const row = Array.from({ length: b.length + 1 }, (_, index) => index);
1297
+ for (let i = 1; i <= a.length; i += 1) {
1298
+ let previous = row[0];
1299
+ row[0] = i;
1300
+ for (let j = 1; j <= b.length; j += 1) {
1301
+ const before = row[j];
1302
+ row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (a[i - 1] === b[j - 1] ? 0 : 1));
1303
+ previous = before;
1304
+ }
702
1305
  }
703
- fail(`不认识的命令: ${cmd}\n${HELP}`);
1306
+ return row[b.length];
704
1307
  }
705
1308
  function printDispatch(out, json = false) {
706
1309
  if (json)
@@ -714,20 +1317,75 @@ function printDispatch(out, json = false) {
714
1317
  console.log(` allowed=${out.allowedActions.join(', ')} default=${out.defaultAction}`);
715
1318
  console.log(' Local 模式可直接用 cwd/env;生产模式由宿主 Broker 保留 DWS 与 control 权限。');
716
1319
  }
1320
+ function printLab(out) {
1321
+ const passed = out.ready ?? out.passed ?? out.assertions?.passed;
1322
+ console.log(`${passed === false ? '❌' : '✅'} ${out.$schema || 'dingtalk-agent/lab'}`);
1323
+ if (out.mode)
1324
+ console.log(` mode=${out.mode}`);
1325
+ if (out.marker)
1326
+ console.log(` marker=${out.marker}`);
1327
+ if (out.evidencePath)
1328
+ console.log(` evidence=${out.evidencePath}`);
1329
+ if (Array.isArray(out.checks)) {
1330
+ for (const check of out.checks) {
1331
+ console.log(` ${check.passed ? 'PASS' : 'FAIL'} ${check.id}: ${check.detail}`);
1332
+ }
1333
+ }
1334
+ }
1335
+ function printAgentAudit(out) {
1336
+ console.log(`dingtalk-agent agent audit · ${out.ready ? 'READY' : 'PARTIAL'}`);
1337
+ console.log(` definition=${out.definition.hash} storage=${out.storageMode}`);
1338
+ console.log(` dingtalkSideEffect=${out.dingtalkSideEffect} sideEffect=${out.sideEffect}`);
1339
+ for (const check of out.checks) {
1340
+ const mark = check.level === 'pass' ? 'PASS' : check.level === 'warn' ? 'WARN' : 'FAIL';
1341
+ console.log(` ${mark} ${check.id}: ${check.summary}`);
1342
+ }
1343
+ if (out.repairs.length) {
1344
+ console.log('\n修复建议:');
1345
+ for (const repair of out.repairs) {
1346
+ console.log(` ${repair.id}: ${repair.why}`);
1347
+ for (const action of repair.actions)
1348
+ console.log(` - ${action}`);
1349
+ }
1350
+ }
1351
+ }
1352
+ function printAgentEnhance(out) {
1353
+ if (out.$schema === 'dingtalk-agent/agent-enhancement-plan@1') {
1354
+ console.log(`dingtalk-agent agent enhance · ${out.ready ? 'READY PLAN' : 'BLOCKED'}`);
1355
+ console.log(` planId=${out.planId} project=${out.projectName}`);
1356
+ console.log(` sideEffect=${out.sideEffect} dingtalkSideEffect=${out.dingtalkSideEffect}`);
1357
+ for (const operation of out.operations) {
1358
+ console.log(` ${operation.kind.toUpperCase()} ${operation.path}: ${operation.reason}`);
1359
+ }
1360
+ if (out.semanticReview.required) {
1361
+ console.log(` REVIEW ${out.semanticReview.files.join(', ')}: ${out.semanticReview.why}`);
1362
+ }
1363
+ for (const blocker of out.blockers)
1364
+ console.log(` BLOCK ${blocker}`);
1365
+ if (out.ready)
1366
+ console.log(`\nApply:\n ${out.apply.command}`);
1367
+ return;
1368
+ }
1369
+ console.log('dingtalk-agent agent enhance · APPLIED');
1370
+ console.log(` operation=${out.operationId} planId=${out.planId}`);
1371
+ console.log(` changes=${out.changes.length} idempotent=${out.idempotent}`);
1372
+ if (out.backupRoot)
1373
+ console.log(` backup=${out.backupRoot}`);
1374
+ console.log(` audit=${out.audit.status} missing=${out.audit.missing.join(', ') || '-'}`);
1375
+ }
717
1376
  function printSkillStatus(out, action, dryRun) {
718
1377
  const prefix = dryRun ? 'DRY-RUN' : '✅';
719
1378
  const verb = action === 'status' ? '全局 Skill 状态' : `skill ${action}`;
720
1379
  console.log(`${prefix} ${verb}: ${out.name}`);
721
- console.log(` bundled=${out.bundled.skillVersion || '-'} hash=${out.bundled.hash.slice(0, 12)}`);
1380
+ console.log(` manager=${out.manager} bundled=${out.bundled.skillVersion || '-'}`);
722
1381
  console.log(` canonical=${out.canonical.path}`);
723
- console.log(` installed=${out.canonical.exists} managed=${out.canonical.managed} ` +
724
- `modified=${out.canonical.modified} current=${out.canonical.current}`);
1382
+ console.log(` installed=${out.canonical.exists} installedVersion=${out.canonical.installedVersion || '-'} ` +
1383
+ `current=${out.canonical.current}`);
1384
+ if (out.operation)
1385
+ console.log(` delegated: ${out.operation.command}`);
725
1386
  for (const client of out.clients) {
726
1387
  console.log(` ${client.label}=${client.state} (${client.discovery}: ${client.path})`);
727
1388
  }
728
- if (out.legacyCodex.conflict) {
729
- console.log(` ⚠️ legacy Codex 同名路径存在: ${out.legacyCodex.path}`);
730
- }
731
1389
  if (action === 'install' && !dryRun) {
732
1390
  console.log(' 新 Agent 会话将自动发现;当前会话未发现时请重启 Claude Code/Codex。');
733
1391
  }
@@ -748,9 +1406,156 @@ function printDoctor(out) {
748
1406
  console.log(` ${step}`);
749
1407
  }
750
1408
  }
1409
+ function printProjectInfo(out) {
1410
+ console.log(`dingtalk-agent Project · ${out.project.name}`);
1411
+ console.log(` root=${out.root}`);
1412
+ console.log(` source=${out.source} manifest=${out.manifest || '(synthetic legacy)'}`);
1413
+ console.log(` hash=${out.manifestHash} dta=${out.project.dtaVersion}`);
1414
+ console.log(` current=${out.currentWorkspace || '(not selected)'}`);
1415
+ for (const workspace of out.workspaces) {
1416
+ console.log(` ${workspace.current ? '*' : '-'} ${workspace.name} · ${workspace.provider.kind} · ${workspace.status}`);
1417
+ }
1418
+ }
1419
+ function printWorkspaceList(out) {
1420
+ console.log(`dingtalk-agent workspaces · ${out.project.name}`);
1421
+ if (!out.workspaces.length)
1422
+ console.log(' 尚未声明 Development Workspace。');
1423
+ for (const workspace of out.workspaces) {
1424
+ console.log(` ${workspace.current ? '*' : '-'} ${workspace.name} provider=${workspace.provider.kind} ` +
1425
+ `stage=${workspace.stage} status=${workspace.status}`);
1426
+ }
1427
+ }
1428
+ function printDevelopmentWorkspace(out) {
1429
+ console.log(`dingtalk-agent workspace · ${out.name}`);
1430
+ console.log(` provider=${out.provider.kind} stage=${out.stage} status=${out.status}`);
1431
+ console.log(` desired=${out.desiredHash} observed=${out.observedHash || '-'}`);
1432
+ console.log(` current=${out.current} legacy=${out.legacy}`);
1433
+ for (const [slot, route] of Object.entries(out.storage))
1434
+ console.log(` ${slot}=${route}`);
1435
+ for (const source of out.configSources)
1436
+ console.log(` source=${source}`);
1437
+ }
1438
+ function printDevelopmentWorkspaceDoctor(out) {
1439
+ console.log(`dingtalk-agent workspace doctor · ${out.workspace} · ${out.ready ? 'READY' : 'PARTIAL'}`);
1440
+ console.log(` provider=${out.provider} status=${out.status}`);
1441
+ console.log(` sideEffect=${out.sideEffect} dingtalkSideEffect=${out.dingtalkSideEffect}`);
1442
+ for (const check of out.checks) {
1443
+ const mark = check.level === 'pass' ? 'PASS' : check.level === 'warn' ? 'WARN' : 'FAIL';
1444
+ console.log(` ${mark} ${check.id}: ${check.summary}`);
1445
+ if (check.fix && check.level !== 'pass')
1446
+ console.log(` fix: ${check.fix}`);
1447
+ }
1448
+ }
1449
+ function printOpenCodeWorkspaceOperation(out) {
1450
+ const applied = out.$schema === 'dingtalk-agent/opencode-workspace-apply@1';
1451
+ console.log(`${applied ? out.applied ? '✅' : '↩️' : 'DRY-RUN'} OpenCode Workspace ${out.workspace}`);
1452
+ console.log(` action=${out.action} model=${out.model}`);
1453
+ console.log(` desired=${out.desiredHash} observed=${out.observedHash || '-'}`);
1454
+ console.log(` managed=${out.managedPath}`);
1455
+ if (!applied && out.writes?.length)
1456
+ console.log(` writes=${out.writes.join(', ')}`);
1457
+ }
1458
+ function printMulticaWorkspaceOperation(out) {
1459
+ const passed = out.passed ?? out.readyForApply ?? out.blocking?.length === 0;
1460
+ const mode = out.remoteRead ? 'REMOTE-READ' : 'DRY-RUN';
1461
+ console.log(`${passed ? '✅' : '⚠️'} ${mode} Multica Workspace ${out.workspace}`);
1462
+ console.log(` schema=${out.$schema} profile=${out.profile || '-'}`);
1463
+ if (out.planId)
1464
+ console.log(` plan=${out.planId}`);
1465
+ if (out.inspectionId)
1466
+ console.log(` inspection=${out.inspectionId}`);
1467
+ if (out.desiredHash)
1468
+ console.log(` desired=${out.desiredHash}`);
1469
+ if (out.observedHash)
1470
+ console.log(` observed=${out.observedHash}`);
1471
+ if (out.diff?.length)
1472
+ console.log(` diff=${out.diff.join(', ')}`);
1473
+ if (out.blocking?.length)
1474
+ console.log(` blocking=${out.blocking.join(', ')}`);
1475
+ if (out.failures?.length)
1476
+ console.log(` failures=${out.failures.join(', ')}`);
1477
+ if (out.evidencePath)
1478
+ console.log(` evidence=${out.evidencePath}`);
1479
+ console.log(` remoteWrite=${out.remoteWrite} dingtalkSideEffect=${out.dingtalkSideEffect}`);
1480
+ }
1481
+ function printMulticaDeployment(out) {
1482
+ console.log(`Multica deploy: ${out.workspace || '<unknown>'}`);
1483
+ if (out.planId)
1484
+ console.log(` plan: ${out.planId}`);
1485
+ if (out.operationId)
1486
+ console.log(` operation: ${out.operationId}`);
1487
+ if (out.receiptId)
1488
+ console.log(` receipt: ${out.receiptId}`);
1489
+ if (out.action)
1490
+ console.log(` action: ${out.action}`);
1491
+ if (out.status)
1492
+ console.log(` status: ${out.status}`);
1493
+ if (typeof out.providerReady === 'boolean')
1494
+ console.log(` provider ready: ${out.providerReady}`);
1495
+ if (Array.isArray(out.blocking) && out.blocking.length) {
1496
+ console.log(` blocking: ${out.blocking.join(', ')}`);
1497
+ }
1498
+ if (Array.isArray(out.failures) && out.failures.length) {
1499
+ console.log(` failures: ${out.failures.join(', ')}`);
1500
+ }
1501
+ if (out.triggerWrite === false)
1502
+ console.log(' triggers: unchanged');
1503
+ }
1504
+ function printPromotion(out) {
1505
+ console.log(`Promotion: ${out.promotionId || out.candidateId || out.candidate?.candidateId || '<none>'}`);
1506
+ if (out.planId)
1507
+ console.log(` plan: ${out.planId}`);
1508
+ if (out.routeId)
1509
+ console.log(` route: ${out.routeId}`);
1510
+ if (out.status)
1511
+ console.log(` status: ${out.status}`);
1512
+ if (out.target?.observedHash)
1513
+ console.log(` observed: ${out.target.observedHash}`);
1514
+ if (out.candidatePath)
1515
+ console.log(` candidate: ${out.candidatePath}`);
1516
+ if (out.candidate?.evidencePath)
1517
+ console.log(` candidate: ${out.candidate.evidencePath}`);
1518
+ if (Array.isArray(out.blocking) && out.blocking.length)
1519
+ console.log(` blocking: ${out.blocking.join(', ')}`);
1520
+ if (out.triggerWrite === false)
1521
+ console.log(' triggers: unchanged');
1522
+ }
1523
+ function parseOptionalTimeout(value, label) {
1524
+ if (value === undefined)
1525
+ return undefined;
1526
+ const parsed = Number(value);
1527
+ if (!Number.isInteger(parsed) || parsed < 100 || parsed > 300_000) {
1528
+ fail(`${label} 必须是 100..300000 的整数毫秒`);
1529
+ }
1530
+ return parsed;
1531
+ }
1532
+ function readProjectText(start, ref, label) {
1533
+ const root = inspectAgentProject(start, PACKAGE_JSON.version).root;
1534
+ const candidate = resolve(root, ref);
1535
+ const lexical = relative(root, candidate);
1536
+ if (lexical === '..' || lexical.startsWith(`..${process.platform === 'win32' ? '\\' : '/'}`)) {
1537
+ throw new Error(`${label} 必须位于 Agent Project 内: ${ref}`);
1538
+ }
1539
+ if (!existsSync(candidate))
1540
+ throw new Error(`${label} 不存在: ${ref}`);
1541
+ const actual = realpathSync(candidate);
1542
+ const resolved = relative(root, actual);
1543
+ if (resolved === '..' || resolved.startsWith(`..${process.platform === 'win32' ? '\\' : '/'}`)) {
1544
+ throw new Error(`${label} 真实路径越出 Agent Project: ${ref}`);
1545
+ }
1546
+ return readFileSync(actual, 'utf8');
1547
+ }
1548
+ function rejectWorkspaceOptions(values, allowed, command) {
1549
+ const extras = Object.entries(values)
1550
+ .filter(([key, value]) => !allowed.includes(key) && value !== undefined && value !== false)
1551
+ .map(([key]) => `--${key}`);
1552
+ if (extras.length)
1553
+ fail(`${command} 不接受参数: ${extras.join(', ')}`);
1554
+ }
751
1555
  function printSetup(out) {
752
1556
  console.log(`${out.dryRun ? 'DRY-RUN' : '✅'} dingtalk-agent setup`);
753
1557
  console.log(` CLI: ${out.cli.executable}`);
1558
+ console.log(` 短命令: ${out.cli.alias}`);
754
1559
  console.log(` Skill: ${out.skill.canonical.path}`);
755
1560
  if (!out.shell.pathReady) {
756
1561
  console.log(` 当前 shell 尚未加载 PATH;本次终端执行: ${out.shell.activateCommand}`);
@@ -760,4 +1565,21 @@ function printSetup(out) {
760
1565
  printDoctor(out.doctor);
761
1566
  console.log(`\n开始使用: ${out.nextCommand}`);
762
1567
  }
1568
+ function printUpgrade(out) {
1569
+ const mark = out.dryRun ? 'DRY-RUN' : out.ready ? '✅' : '⚠️';
1570
+ const relation = out.changed ? `${out.currentVersion} → ${out.targetVersion}` : `${out.targetVersion}(已是当前版本)`;
1571
+ console.log(`${mark} dta upgrade: ${relation}`);
1572
+ console.log(` target=${out.target}`);
1573
+ console.log(` CLI=${out.executable}`);
1574
+ if (out.dryRun) {
1575
+ console.log(` 将执行: ${out.commands.install}`);
1576
+ console.log(` 将复核: ${out.commands.verify}`);
1577
+ }
1578
+ else if (out.ready) {
1579
+ console.log(' setup / DWS / Skill / Claude Code / Codex / OpenCode 全部 ready');
1580
+ }
1581
+ else {
1582
+ console.log(` CLI 已更新;环境复核未完全 ready,请运行: ${out.commands.verify}`);
1583
+ }
1584
+ }
763
1585
  //# sourceMappingURL=dingtalk-agent.js.map