@wowok/agent-mcp 2.7.0 → 2.7.2

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 (427) hide show
  1. package/dist/config/index.js +1 -1
  2. package/dist/config/runtime.js +1 -238
  3. package/dist/customer/customer-advice.js +1 -130
  4. package/dist/customer/index.js +1 -11
  5. package/dist/customer/industry-risks.js +1 -438
  6. package/dist/customer/info-puzzle.js +1 -681
  7. package/dist/customer/order-monitor.js +1 -328
  8. package/dist/customer/order-strategy.js +1 -373
  9. package/dist/customer/post-purchase.js +1 -351
  10. package/dist/customer/preorder-compare.js +1 -34
  11. package/dist/customer/reminder-system.js +1 -316
  12. package/dist/customer/risk-assessment.d.ts +5 -1
  13. package/dist/customer/risk-assessment.js +1 -397
  14. package/dist/customer/types.js +1 -13
  15. package/dist/customer/user-preferences.js +1 -460
  16. package/dist/evaluation/arbitration-game.d.ts +23 -0
  17. package/dist/evaluation/arbitration-game.js +1 -0
  18. package/dist/evaluation/builtins/demand-match.d.ts +15 -0
  19. package/dist/evaluation/builtins/demand-match.js +1 -0
  20. package/dist/evaluation/builtins/index.d.ts +3 -0
  21. package/dist/evaluation/builtins/index.js +1 -0
  22. package/dist/evaluation/builtins/service-risk.d.ts +6 -0
  23. package/dist/evaluation/builtins/service-risk.js +1 -0
  24. package/dist/evaluation/capability.d.ts +50 -0
  25. package/dist/evaluation/capability.js +1 -0
  26. package/dist/evaluation/composer.d.ts +13 -0
  27. package/dist/evaluation/composer.js +1 -0
  28. package/dist/evaluation/engine.d.ts +18 -0
  29. package/dist/evaluation/engine.js +1 -0
  30. package/dist/evaluation/extract.d.ts +30 -0
  31. package/dist/evaluation/extract.js +1 -0
  32. package/dist/evaluation/game-strategy.d.ts +27 -0
  33. package/dist/evaluation/game-strategy.js +1 -0
  34. package/dist/evaluation/gap.d.ts +2 -0
  35. package/dist/evaluation/gap.js +1 -0
  36. package/dist/evaluation/index.d.ts +12 -0
  37. package/dist/evaluation/index.js +1 -0
  38. package/dist/evaluation/node-game.d.ts +62 -0
  39. package/dist/evaluation/node-game.js +1 -0
  40. package/dist/evaluation/region.d.ts +10 -0
  41. package/dist/evaluation/region.js +1 -0
  42. package/dist/evaluation/types.d.ts +77 -0
  43. package/dist/evaluation/types.js +1 -0
  44. package/dist/evaluation/user-injection.d.ts +6 -0
  45. package/dist/evaluation/user-injection.js +1 -0
  46. package/dist/examples/education-contact-create.json +40 -0
  47. package/dist/examples/freelance-contact-create.json +40 -0
  48. package/dist/examples/insurance-machine-create.json +1 -1
  49. package/dist/examples/insurance-service-allocators.json +1 -1
  50. package/dist/examples/machine-publish.json +1 -1
  51. package/dist/examples/rental-ziroom-service-create.json +1 -1
  52. package/dist/examples/retail-adv-guard-messenger-proof-create.json +1 -1
  53. package/dist/examples/retail-myshop-service-create.json +1 -1
  54. package/dist/examples/retail-myshop-service-customer-required.json +1 -1
  55. package/dist/examples/subscription-contact-create.json +40 -0
  56. package/dist/examples/threebody-machine-create.json +1 -1
  57. package/dist/examples/travel-machine-create.json +1 -1
  58. package/dist/examples/travel-service-create.json +1 -1
  59. package/dist/experience/experience-reuse.js +1 -103
  60. package/dist/experience/index.js +1 -5
  61. package/dist/experience/intent-distill.js +1 -83
  62. package/dist/experience/realtime-feedback.js +1 -94
  63. package/dist/experience/types.js +1 -1
  64. package/dist/experience/user-profile.js +1 -171
  65. package/dist/extensions/business-modules.js +1 -287
  66. package/dist/extensions/capability-manifest.js +1 -781
  67. package/dist/extensions/constraint-registry.js +1 -198
  68. package/dist/extensions/index.js +1 -6
  69. package/dist/extensions/metric-registry.js +1 -257
  70. package/dist/extensions/mode-evaluator.js +1 -170
  71. package/dist/extensions/modes.js +1 -499
  72. package/dist/extensions/registry.js +1 -717
  73. package/dist/extensions/types.js +1 -1
  74. package/dist/harness/auto-escalation.js +1 -68
  75. package/dist/harness/checkpoint.js +1 -129
  76. package/dist/harness/index.js +1 -78
  77. package/dist/harness/plan.js +1 -276
  78. package/dist/harness/recover.js +1 -139
  79. package/dist/harness/types.js +1 -1
  80. package/dist/harness/verify.js +1 -237
  81. package/dist/index.js +1 -273
  82. package/dist/intent/enrich.d.ts +1 -0
  83. package/dist/intent/enrich.js +1 -0
  84. package/dist/intent/index.d.ts +23 -0
  85. package/dist/intent/index.js +1 -0
  86. package/dist/intent/matcher.d.ts +2 -0
  87. package/dist/intent/matcher.js +1 -0
  88. package/dist/intent/store.d.ts +19 -0
  89. package/dist/intent/store.js +1 -0
  90. package/dist/intent/types.d.ts +33 -0
  91. package/dist/intent/types.js +1 -0
  92. package/dist/knowledge/acquisition-flywheel.js +1 -192
  93. package/dist/knowledge/allocation-confirm.js +1 -534
  94. package/dist/knowledge/allocation-context.js +1 -249
  95. package/dist/knowledge/allocation-ledger.js +1 -463
  96. package/dist/knowledge/allocation-puzzle.js +1 -298
  97. package/dist/knowledge/allocation-risk.js +1 -568
  98. package/dist/knowledge/allocation-templates.js +1 -970
  99. package/dist/knowledge/allocation-translation.js +1 -585
  100. package/dist/knowledge/arb-risk.js +1 -210
  101. package/dist/knowledge/arbitration-confirm.js +1 -559
  102. package/dist/knowledge/arbitration-context.js +1 -505
  103. package/dist/knowledge/arbitration-ledger.js +1 -521
  104. package/dist/knowledge/arbitration-puzzle.js +1 -304
  105. package/dist/knowledge/arbitration-risk.js +1 -433
  106. package/dist/knowledge/arbitration-templates.js +1 -276
  107. package/dist/knowledge/arbitration-translation.js +1 -487
  108. package/dist/knowledge/arbitration-trust.js +1 -117
  109. package/dist/knowledge/audit-rules.js +1 -141
  110. package/dist/knowledge/bridge-risk.js +1 -263
  111. package/dist/knowledge/contact-risk.js +1 -200
  112. package/dist/knowledge/contact-templates.d.ts +27 -0
  113. package/dist/knowledge/contact-templates.js +1 -0
  114. package/dist/knowledge/demand-confirm.js +1 -206
  115. package/dist/knowledge/demand-matching.js +1 -132
  116. package/dist/knowledge/demand-risk.js +1 -240
  117. package/dist/knowledge/demand-translation.js +1 -354
  118. package/dist/knowledge/deployment-scanner.js +1 -823
  119. package/dist/knowledge/dynamic-pricing.js +1 -87
  120. package/dist/knowledge/examples-scanner-cli.js +1 -26
  121. package/dist/knowledge/examples-scanner.js +1 -825
  122. package/dist/knowledge/flywheel-loop.js +1 -404
  123. package/dist/knowledge/fund-layer.js +1 -973
  124. package/dist/knowledge/glossary.js +1 -211
  125. package/dist/knowledge/guard-confirm.js +1 -406
  126. package/dist/knowledge/guard-context.js +1 -287
  127. package/dist/knowledge/guard-design-patterns.js +1 -360
  128. package/dist/knowledge/guard-ledger.js +1 -260
  129. package/dist/knowledge/guard-lint.js +1 -670
  130. package/dist/knowledge/guard-migration.js +1 -228
  131. package/dist/knowledge/guard-puzzle.js +1 -805
  132. package/dist/knowledge/guard-render.js +1 -700
  133. package/dist/knowledge/guard-risk.js +1 -1879
  134. package/dist/knowledge/guard-submission-prompt.js +1 -171
  135. package/dist/knowledge/guard-templates.js +1 -1105
  136. package/dist/knowledge/guard-translation.js +1 -1119
  137. package/dist/knowledge/index.js +1 -436
  138. package/dist/knowledge/industry-evolution.js +1 -323
  139. package/dist/knowledge/industry-generalizer.js +1 -381
  140. package/dist/knowledge/industry-registry.js +1 -174
  141. package/dist/knowledge/intent-metrics.d.ts +4 -3
  142. package/dist/knowledge/intent-metrics.js +1 -566
  143. package/dist/knowledge/machine-confirm.js +1 -559
  144. package/dist/knowledge/machine-context.js +1 -833
  145. package/dist/knowledge/machine-ledger.js +1 -338
  146. package/dist/knowledge/machine-puzzle.js +1 -494
  147. package/dist/knowledge/machine-render.js +1 -565
  148. package/dist/knowledge/machine-risk.js +1 -670
  149. package/dist/knowledge/machine-templates.js +1 -1597
  150. package/dist/knowledge/machine-topology.js +1 -234
  151. package/dist/knowledge/machine-translation.js +1 -513
  152. package/dist/knowledge/mcp-schema-audit-cli.js +1 -45
  153. package/dist/knowledge/mcp-schema-audit.d.ts +1 -1
  154. package/dist/knowledge/mcp-schema-audit.js +1 -773
  155. package/dist/knowledge/onchain-constants.js +1 -35
  156. package/dist/knowledge/order-confirm.js +1 -573
  157. package/dist/knowledge/order-context.js +1 -390
  158. package/dist/knowledge/order-ledger.js +1 -341
  159. package/dist/knowledge/order-puzzle.js +1 -255
  160. package/dist/knowledge/order-risk.js +1 -653
  161. package/dist/knowledge/order-templates.js +1 -368
  162. package/dist/knowledge/order-translation.js +1 -550
  163. package/dist/knowledge/overrides-loader.js +1 -65
  164. package/dist/knowledge/passport-confirm.js +1 -531
  165. package/dist/knowledge/passport-context.js +1 -306
  166. package/dist/knowledge/passport-ledger.js +1 -282
  167. package/dist/knowledge/passport-puzzle.js +1 -333
  168. package/dist/knowledge/passport-risk.js +1 -450
  169. package/dist/knowledge/passport-templates.js +1 -568
  170. package/dist/knowledge/passport-translation.js +1 -516
  171. package/dist/knowledge/payment-risk.js +1 -249
  172. package/dist/knowledge/permission-confirm.js +1 -426
  173. package/dist/knowledge/permission-context.js +1 -224
  174. package/dist/knowledge/permission-ledger.js +1 -403
  175. package/dist/knowledge/permission-puzzle.js +1 -173
  176. package/dist/knowledge/permission-risk.js +1 -411
  177. package/dist/knowledge/permission-templates.js +1 -234
  178. package/dist/knowledge/permission-translation.js +1 -350
  179. package/dist/knowledge/personal-risk.js +1 -212
  180. package/dist/knowledge/process-model.js +1 -160
  181. package/dist/knowledge/progress-confirm.js +1 -456
  182. package/dist/knowledge/progress-context.js +1 -452
  183. package/dist/knowledge/progress-ledger.js +1 -330
  184. package/dist/knowledge/progress-puzzle.js +1 -219
  185. package/dist/knowledge/progress-risk.js +1 -461
  186. package/dist/knowledge/progress-templates.js +1 -228
  187. package/dist/knowledge/progress-translation.js +1 -405
  188. package/dist/knowledge/proof-confirm.js +1 -187
  189. package/dist/knowledge/proof-risk.js +1 -207
  190. package/dist/knowledge/proof-translation.js +1 -283
  191. package/dist/knowledge/registrar-risk.js +1 -217
  192. package/dist/knowledge/repository-confirm.js +1 -286
  193. package/dist/knowledge/repository-risk.js +1 -373
  194. package/dist/knowledge/repository-translation.js +1 -445
  195. package/dist/knowledge/reputation-rules.js +1 -99
  196. package/dist/knowledge/resource-risk.js +1 -157
  197. package/dist/knowledge/reward-confirm.js +1 -526
  198. package/dist/knowledge/reward-context.js +1 -504
  199. package/dist/knowledge/reward-ledger.js +1 -502
  200. package/dist/knowledge/reward-puzzle.js +1 -300
  201. package/dist/knowledge/reward-risk.js +1 -627
  202. package/dist/knowledge/reward-templates.js +1 -197
  203. package/dist/knowledge/reward-translation.js +1 -501
  204. package/dist/knowledge/safety-rules.js +1 -404
  205. package/dist/knowledge/scenario-modes.js +1 -321
  206. package/dist/knowledge/service-confirm.js +1 -807
  207. package/dist/knowledge/service-context.js +1 -403
  208. package/dist/knowledge/service-ledger.js +1 -609
  209. package/dist/knowledge/service-puzzle.js +1 -236
  210. package/dist/knowledge/service-risk.js +1 -615
  211. package/dist/knowledge/service-templates.js +1 -456
  212. package/dist/knowledge/service-translation.js +1 -622
  213. package/dist/knowledge/template-registry.d.ts +1 -1
  214. package/dist/knowledge/template-registry.js +1 -341
  215. package/dist/knowledge/tool-constraints.js +1 -195
  216. package/dist/knowledge/tools-reference.js +1 -155
  217. package/dist/knowledge/treasury-confirm.js +1 -512
  218. package/dist/knowledge/treasury-context.js +1 -363
  219. package/dist/knowledge/treasury-ledger.js +1 -300
  220. package/dist/knowledge/treasury-puzzle.js +1 -216
  221. package/dist/knowledge/treasury-risk.js +1 -440
  222. package/dist/knowledge/treasury-templates.js +1 -358
  223. package/dist/knowledge/treasury-translation.js +1 -498
  224. package/dist/knowledge/trust-metrics.js +1 -198
  225. package/dist/knowledge/util-risk.js +1 -135
  226. package/dist/loop-engineering/aggregate.js +1 -132
  227. package/dist/loop-engineering/context-collect.js +1 -83
  228. package/dist/loop-engineering/diagnose.js +1 -273
  229. package/dist/loop-engineering/improve.js +1 -405
  230. package/dist/loop-engineering/index.js +1 -4
  231. package/dist/loop-engineering/pipeline.js +1 -56
  232. package/dist/mode-market/index.js +1 -3
  233. package/dist/mode-market/registry.js +1 -124
  234. package/dist/mode-market/review.js +1 -214
  235. package/dist/mode-market/submission.js +1 -85
  236. package/dist/participation/collaborator-interest.d.ts +23 -0
  237. package/dist/participation/collaborator-interest.js +1 -0
  238. package/dist/participation/customer-interest.d.ts +25 -0
  239. package/dist/participation/customer-interest.js +1 -0
  240. package/dist/participation/merchant-interest.js +1 -100
  241. package/dist/participation/radar-core.d.ts +13 -3
  242. package/dist/participation/radar-core.js +1 -269
  243. package/dist/participation/supplier-interest.d.ts +25 -0
  244. package/dist/participation/supplier-interest.js +1 -0
  245. package/dist/persona/analyzer.d.ts +16 -0
  246. package/dist/persona/analyzer.js +1 -0
  247. package/dist/persona/bridge.d.ts +5 -0
  248. package/dist/persona/bridge.js +1 -0
  249. package/dist/persona/defaults.d.ts +4 -0
  250. package/dist/persona/defaults.js +1 -0
  251. package/dist/persona/experience-bridge.d.ts +3 -0
  252. package/dist/persona/experience-bridge.js +1 -0
  253. package/dist/persona/index.d.ts +18 -0
  254. package/dist/persona/index.js +1 -0
  255. package/dist/persona/model.d.ts +7 -0
  256. package/dist/persona/model.js +1 -0
  257. package/dist/persona/store.d.ts +19 -0
  258. package/dist/persona/store.js +1 -0
  259. package/dist/persona/types.d.ts +45 -0
  260. package/dist/persona/types.js +1 -0
  261. package/dist/project/business-puzzle.js +1 -383
  262. package/dist/project/context-assembly.js +1 -254
  263. package/dist/project/deployment-bridge.js +1 -120
  264. package/dist/project/deployment-doc.js +1 -1126
  265. package/dist/project/edit-planner.js +1 -1342
  266. package/dist/project/evaluation.js +1 -2011
  267. package/dist/project/game-theory.js +1 -177
  268. package/dist/project/graph-builder.js +1 -656
  269. package/dist/project/graph.js +1 -340
  270. package/dist/project/handlers.d.ts +5 -0
  271. package/dist/project/handlers.js +1 -1762
  272. package/dist/project/index.d.ts +1 -0
  273. package/dist/project/index.js +1 -301
  274. package/dist/project/intent-analyzer.js +1 -149
  275. package/dist/project/machine-nodes.js +1 -36
  276. package/dist/project/merchant-guide.js +1 -264
  277. package/dist/project/migration.js +1 -125
  278. package/dist/project/mode-actions.js +1 -309
  279. package/dist/project/namespace.js +1 -206
  280. package/dist/project/participation-radar.js +1 -428
  281. package/dist/project/pipeline-actions.js +1 -109
  282. package/dist/project/project-store.js +1 -422
  283. package/dist/project/query.js +1 -153
  284. package/dist/project/reverse-mapping.d.ts +34 -0
  285. package/dist/project/reverse-mapping.js +1 -0
  286. package/dist/project/risk-aggregator.js +1 -295
  287. package/dist/project/rollback-policy.js +1 -290
  288. package/dist/project/semantic-assembler.js +1 -345
  289. package/dist/project/semantic-graph.js +1 -245
  290. package/dist/project/stage-gate.js +1 -369
  291. package/dist/project/substep-trace.js +1 -332
  292. package/dist/project/task-tracker.js +1 -78
  293. package/dist/role/derivation.d.ts +18 -0
  294. package/dist/role/derivation.js +1 -0
  295. package/dist/role/index.d.ts +5 -0
  296. package/dist/role/index.js +1 -0
  297. package/dist/role/model.d.ts +8 -0
  298. package/dist/role/model.js +1 -0
  299. package/dist/role/resolution.d.ts +11 -0
  300. package/dist/role/resolution.js +1 -0
  301. package/dist/role/types.d.ts +11 -0
  302. package/dist/role/types.js +1 -0
  303. package/dist/rules.d.ts +2 -0
  304. package/dist/rules.js +1 -9
  305. package/dist/safety/confirm-gate.js +1 -88
  306. package/dist/safety/index.js +1 -3
  307. package/dist/safety/preview.js +1 -52
  308. package/dist/schema/call/allocation.js +1 -34
  309. package/dist/schema/call/arbitration.js +1 -113
  310. package/dist/schema/call/base.d.ts +15 -15
  311. package/dist/schema/call/base.js +1 -370
  312. package/dist/schema/call/bridge-handler.js +1 -265
  313. package/dist/schema/call/bridge.d.ts +7 -7
  314. package/dist/schema/call/bridge.js +1 -458
  315. package/dist/schema/call/contact.js +1 -37
  316. package/dist/schema/call/demand.js +1 -47
  317. package/dist/schema/call/guard.js +1 -161
  318. package/dist/schema/call/handler.js +1 -322
  319. package/dist/schema/call/index.js +1 -20
  320. package/dist/schema/call/machine.js +1 -193
  321. package/dist/schema/call/order.js +1 -35
  322. package/dist/schema/call/payment.js +1 -37
  323. package/dist/schema/call/permission-handler.js +1 -54
  324. package/dist/schema/call/permission.js +1 -105
  325. package/dist/schema/call/personal.js +1 -78
  326. package/dist/schema/call/progress.js +1 -47
  327. package/dist/schema/call/proof.js +1 -33
  328. package/dist/schema/call/repository.js +1 -77
  329. package/dist/schema/call/reward.js +1 -30
  330. package/dist/schema/call/semantic.js +1 -1657
  331. package/dist/schema/call/service.js +1 -178
  332. package/dist/schema/call/treasury.js +1 -71
  333. package/dist/schema/common/index.js +1 -407
  334. package/dist/schema/config/index.js +1 -68
  335. package/dist/schema/evaluation/index.d.ts +4436 -0
  336. package/dist/schema/evaluation/index.js +1 -0
  337. package/dist/schema/index.d.ts +4 -0
  338. package/dist/schema/index.js +1 -13
  339. package/dist/schema/intent-radar/index.d.ts +284 -0
  340. package/dist/schema/intent-radar/index.js +1 -0
  341. package/dist/schema/local/index.d.ts +21 -21
  342. package/dist/schema/local/index.js +1 -927
  343. package/dist/schema/local/wip.js +1 -187
  344. package/dist/schema/messenger/index.d.ts +7 -7
  345. package/dist/schema/messenger/index.js +1 -475
  346. package/dist/schema/operations.d.ts +7 -7
  347. package/dist/schema/operations.js +1 -520
  348. package/dist/schema/persona/index.d.ts +1985 -0
  349. package/dist/schema/persona/index.js +1 -0
  350. package/dist/schema/project/index.d.ts +96 -50
  351. package/dist/schema/project/index.js +1 -2057
  352. package/dist/schema/query/index.d.ts +423 -7
  353. package/dist/schema/query/index.js +1 -1640
  354. package/dist/schema/schema-query/index.js +1 -104
  355. package/dist/schema/schema-version.js +1 -76
  356. package/dist/schema/sync-layer4.d.ts +1 -1
  357. package/dist/schema/sync-layer4.js +1 -282
  358. package/dist/schema/task-status.d.ts +168 -0
  359. package/dist/schema/task-status.js +1 -0
  360. package/dist/schema/trust/index.js +1 -314
  361. package/dist/schema/utils/guard-parser.js +1 -419
  362. package/dist/schema/utils/guard-query-utils.js +1 -46
  363. package/dist/schema/utils/node-parser.js +1 -369
  364. package/dist/schema/utils/object-type-utils.js +1 -35
  365. package/dist/schema/utils/permission-index-utils.js +1 -7
  366. package/dist/schema/utils/permission-machine-check.js +1 -121
  367. package/dist/schema/utils/skills-recommendation.js +1 -77
  368. package/dist/schema-query/index.js +1 -810
  369. package/dist/schemas/account_operation.output.json +5 -2
  370. package/dist/schemas/bridge_operation.output.json +5 -2
  371. package/dist/schemas/evaluation_operation.output.json +782 -0
  372. package/dist/schemas/evaluation_operation.schema.json +990 -0
  373. package/dist/schemas/index.json +25 -1
  374. package/dist/schemas/intent_radar.output.json +232 -0
  375. package/dist/schemas/intent_radar.schema.json +138 -0
  376. package/dist/schemas/local_info_operation.output.json +5 -2
  377. package/dist/schemas/local_mark_operation.output.json +5 -2
  378. package/dist/schemas/messenger_operation.output.json +5 -2
  379. package/dist/schemas/onchain_events.output.json +5 -2
  380. package/dist/schemas/onchain_operations.output.json +5 -2
  381. package/dist/schemas/onchain_operations.schema.json +6 -6
  382. package/dist/schemas/onchain_operations_allocation.schema.json +1 -1
  383. package/dist/schemas/onchain_operations_machine.schema.json +2 -2
  384. package/dist/schemas/onchain_operations_service.schema.json +3 -3
  385. package/dist/schemas/onchain_table_data.output.json +6 -3
  386. package/dist/schemas/persona_operation.output.json +392 -0
  387. package/dist/schemas/persona_operation.schema.json +250 -0
  388. package/dist/schemas/project_operation.output.json +28 -8
  389. package/dist/schemas/query_task_status.output.json +115 -0
  390. package/dist/schemas/query_task_status.schema.json +24 -0
  391. package/dist/schemas/query_toolkit.output.json +9 -6
  392. package/dist/schemas/trust_score.schema.json +1 -1
  393. package/dist/schemas/wowok_buildin_info.output.json +132 -0
  394. package/dist/schemas/wowok_buildin_info.schema.json +14 -0
  395. package/dist/telemetry/index.js +1 -112
  396. package/dist/telemetry/redact.js +1 -23
  397. package/dist/telemetry/storage.js +1 -80
  398. package/dist/tools/handlers/bridge.js +1 -1
  399. package/dist/tools/handlers/config.js +1 -74
  400. package/dist/tools/handlers/evaluation.d.ts +2 -0
  401. package/dist/tools/handlers/evaluation.js +1 -0
  402. package/dist/tools/handlers/file-export.js +1 -90
  403. package/dist/tools/handlers/intent-radar.d.ts +2 -0
  404. package/dist/tools/handlers/intent-radar.js +1 -0
  405. package/dist/tools/handlers/local.js +1 -53
  406. package/dist/tools/handlers/messenger.js +1 -188
  407. package/dist/tools/handlers/onchain.js +1 -1082
  408. package/dist/tools/handlers/persona.d.ts +4 -0
  409. package/dist/tools/handlers/persona.js +1 -0
  410. package/dist/tools/handlers/project.js +1 -211
  411. package/dist/tools/handlers/query.js +1 -434
  412. package/dist/tools/handlers/schema-query.js +1 -176
  413. package/dist/tools/handlers/task-status.d.ts +0 -168
  414. package/dist/tools/handlers/task-status.js +1 -55
  415. package/dist/tools/handlers/trust.js +1 -380
  416. package/dist/tools/handlers/wip.js +1 -90
  417. package/dist/tools/index.js +1 -1306
  418. package/dist/tools/retry.js +1 -85
  419. package/dist/tools/rules-hook.js +1 -23
  420. package/dist/tools/shared.js +1 -130
  421. package/dist/tools/types.js +1 -1
  422. package/dist/tools/upgrade-check.d.ts +19 -0
  423. package/dist/tools/upgrade-check.js +1 -0
  424. package/dist/tools/wip-deploy-assist.d.ts +1 -1
  425. package/dist/tools/wip-deploy-assist.js +1 -278
  426. package/dist/tools/wrap.js +1 -500
  427. package/package.json +5 -3
@@ -1,565 +1 @@
1
- function sanitizeMermaidLabel(text) {
2
- if (/[<>"\[\]{}()|&]/.test(text)) {
3
- return `"${text.replace(/"/g, "'")}"`;
4
- }
5
- return text;
6
- }
7
- const MACHINE_NODE_COLORS = {
8
- entry: { fill: "#10b981", stroke: "#065f46" },
9
- terminal: { fill: "#ef4444", stroke: "#991b1b" },
10
- revision: { fill: "#f59e0b", stroke: "#92400e" },
11
- normal: { fill: "#3b82f6", stroke: "#1e40af" },
12
- };
13
- function classifyMachineNode(nodeName, edges, entryNodes) {
14
- const outEdges = edges.filter(e => e.from === nodeName);
15
- if (outEdges.length === 0)
16
- return "terminal";
17
- const hasOutgoingToNode = outEdges.some(e => e.to !== "");
18
- if (!hasOutgoingToNode)
19
- return "terminal";
20
- const isRevisionTarget = edges.some(e => e.to === nodeName && e.from === nodeName);
21
- if (isRevisionTarget)
22
- return "revision";
23
- if (entryNodes.has(nodeName))
24
- return "entry";
25
- return "normal";
26
- }
27
- export function sanitizeMermaidNodeId(name) {
28
- if (/[^a-zA-Z0-9_]/.test(name)) {
29
- return `"${name}"`;
30
- }
31
- return name;
32
- }
33
- export function renderMachineMermaid(nodes, edges, options) {
34
- const colored = options?.colored !== false;
35
- const lines = ["stateDiagram-v2"];
36
- if (colored) {
37
- lines.push(" %% Color Legend (BehaviorTree.CPP-inspired workflow roles):");
38
- lines.push(" %% green #10b981 - entry (start state, targeted by [*])");
39
- lines.push(" %% red #ef4444 - terminal (end state, no outgoing edges)");
40
- lines.push(" %% amber #f59e0b - revision (self-loop / revision cycle)");
41
- lines.push(" %% blue #3b82f6 - normal (regular intermediate state)");
42
- lines.push(" %% Priority: terminal > revision > entry > normal");
43
- }
44
- const nodesWithIncoming = new Set(edges.filter(e => e.from !== "").map(e => e.to));
45
- const entryNodes = new Set();
46
- for (const node of nodes) {
47
- if (!nodesWithIncoming.has(node.name)) {
48
- entryNodes.add(node.name);
49
- }
50
- }
51
- const entryNodesList = nodes.filter(n => entryNodes.has(n.name));
52
- for (const entry of entryNodesList) {
53
- const entryEdges = edges.filter(e => e.from === "" && e.to === entry.name);
54
- if (entryEdges.length > 0) {
55
- for (const edge of entryEdges) {
56
- for (const fwd of edge.forwards) {
57
- const label = buildForwardLabel(fwd, edge.threshold);
58
- lines.push(` [*] --> ${sanitizeMermaidNodeId(entry.name)}: ${sanitizeMermaidLabel(label)}`);
59
- }
60
- }
61
- }
62
- else {
63
- lines.push(` [*] --> ${sanitizeMermaidNodeId(entry.name)}`);
64
- }
65
- }
66
- for (const edge of edges) {
67
- if (edge.from === "")
68
- continue;
69
- const fromId = sanitizeMermaidNodeId(edge.from);
70
- const toId = edge.to === "" ? "[*]" : sanitizeMermaidNodeId(edge.to);
71
- for (const fwd of edge.forwards) {
72
- const label = buildForwardLabel(fwd, edge.threshold);
73
- lines.push(` ${fromId} --> ${toId}: ${sanitizeMermaidLabel(label)}`);
74
- }
75
- }
76
- for (const node of nodes) {
77
- if (node.description) {
78
- lines.push(` ${sanitizeMermaidNodeId(node.name)}: ${sanitizeMermaidLabel(node.description)}`);
79
- }
80
- }
81
- if (colored) {
82
- lines.push("");
83
- lines.push(" %% Node colors (BehaviorTree.CPP-inspired workflow roles)");
84
- for (const node of nodes) {
85
- const category = classifyMachineNode(node.name, edges, entryNodes);
86
- const color = MACHINE_NODE_COLORS[category];
87
- lines.push(` style ${sanitizeMermaidNodeId(node.name)} fill:${color.fill},stroke:${color.stroke},color:#fff`);
88
- }
89
- }
90
- return lines.join("\n");
91
- }
92
- function buildForwardLabel(fwd, threshold) {
93
- let label = fwd.name;
94
- const annotations = [];
95
- if (threshold > 1) {
96
- annotations.push(`threshold=${threshold}`);
97
- }
98
- if (fwd.guard) {
99
- const shortGuard = fwd.guard.length > 10
100
- ? `${fwd.guard.slice(0, 6)}…${fwd.guard.slice(-4)}`
101
- : fwd.guard;
102
- annotations.push(`guard=${shortGuard}`);
103
- }
104
- if (annotations.length > 0) {
105
- label += ` (${annotations.join(", ")})`;
106
- }
107
- return label;
108
- }
109
- export function renderMachineTreeIndented(input) {
110
- const { nodes, edges, machineName, machineAddress, published, paused } = input;
111
- const lines = [];
112
- lines.push("# Machine Workflow Definition");
113
- lines.push("");
114
- if (machineName) {
115
- lines.push(`**Machine:** ${machineName}`);
116
- }
117
- if (machineAddress) {
118
- lines.push(`**Address:** ${machineAddress}`);
119
- }
120
- lines.push(`**Total Nodes:** ${nodes.length}`);
121
- lines.push(`**Total Edges:** ${edges.length}`);
122
- if (published !== null && published !== undefined) {
123
- lines.push(`**Published:** ${published}`);
124
- }
125
- if (paused !== null && paused !== undefined) {
126
- lines.push(`**Paused:** ${paused}`);
127
- }
128
- lines.push("");
129
- lines.push("## Topology (directed graph outline)");
130
- lines.push("");
131
- const entryEdges = edges.filter(e => e.from === "");
132
- const regularEdges = edges.filter(e => e.from !== "");
133
- for (const edge of entryEdges) {
134
- const header = `- [*] --> ${edge.to} (threshold=${edge.threshold})`;
135
- lines.push(header);
136
- for (const fwd of edge.forwards) {
137
- lines.push(` - forward: ${formatForwardInline(fwd)}`);
138
- }
139
- }
140
- for (const edge of regularEdges) {
141
- const isSelfLoop = edge.from === edge.to;
142
- const annotation = isSelfLoop ? " # self-loop (revision cycle)" : "";
143
- const toLabel = edge.to === "" ? "[*]" : edge.to;
144
- const header = `- ${edge.from} --> ${toLabel} (threshold=${edge.threshold})${annotation}`;
145
- lines.push(header);
146
- for (const fwd of edge.forwards) {
147
- lines.push(` - forward: ${formatForwardInline(fwd)}`);
148
- }
149
- }
150
- const nodesWithDesc = nodes.filter(n => n.description);
151
- if (nodesWithDesc.length > 0) {
152
- lines.push("");
153
- lines.push("## Node Descriptions");
154
- lines.push("");
155
- for (const node of nodes) {
156
- if (node.description) {
157
- lines.push(`- ${node.name}: ${node.description}`);
158
- }
159
- }
160
- }
161
- const incomingMap = new Map();
162
- for (const edge of edges) {
163
- if (!incomingMap.has(edge.to))
164
- incomingMap.set(edge.to, []);
165
- incomingMap.get(edge.to).push({
166
- from: edge.from === "" ? "[*]" : edge.from,
167
- forwards: edge.forwards.map(f => f.name),
168
- });
169
- }
170
- if (incomingMap.size > 0) {
171
- lines.push("");
172
- lines.push("## Backrefs (incoming edges per node)");
173
- lines.push("");
174
- for (const node of nodes) {
175
- const incoming = incomingMap.get(node.name);
176
- if (!incoming || incoming.length === 0)
177
- continue;
178
- const parts = incoming.map(inc => {
179
- const fwdStr = inc.forwards.length > 0 ? ` (${inc.forwards.join(", ")})` : "";
180
- const selfLoop = inc.from === node.name ? " # self-loop" : "";
181
- return `<- ${inc.from}${fwdStr}${selfLoop}`;
182
- });
183
- lines.push(`- ${node.name}: ${parts.join(", ")}`);
184
- }
185
- }
186
- lines.push("");
187
- lines.push("## JSON Definition");
188
- lines.push("");
189
- lines.push("```json");
190
- lines.push(JSON.stringify({ nodes, edges }, null, 2));
191
- lines.push("```");
192
- return lines.join("\n");
193
- }
194
- function formatForwardInline(fwd) {
195
- const parts = [`weight=${fwd.weight}`];
196
- if (fwd.named_operator !== null && fwd.named_operator !== undefined) {
197
- parts.push(`namedOperator='${fwd.named_operator}'`);
198
- }
199
- if (fwd.permission_index !== null && fwd.permission_index !== undefined) {
200
- parts.push(`permissionIndex=${fwd.permission_index}`);
201
- }
202
- if (fwd.guard) {
203
- parts.push(`guard=${fwd.guard}`);
204
- }
205
- if (fwd.retained_submission) {
206
- const rsStr = Array.isArray(fwd.retained_submission)
207
- ? `[${fwd.retained_submission.join(",")}]`
208
- : String(fwd.retained_submission);
209
- parts.push(`retained_submission=${rsStr}`);
210
- }
211
- return `${fwd.name} (${parts.join(", ")})`;
212
- }
213
- export function parseMachineTreeIndented(text) {
214
- const errors = [];
215
- const jsonMatch = text.match(/```json\s*\n([\s\S]*?)```/);
216
- if (jsonMatch) {
217
- try {
218
- const data = JSON.parse(jsonMatch[1].trim());
219
- if (data && typeof data === "object" && Array.isArray(data.nodes) && Array.isArray(data.edges)) {
220
- return { success: true, data, errors: [] };
221
- }
222
- if (Array.isArray(data)) {
223
- const { nodes, edges } = convertNodeArrayToGraph(data);
224
- return { success: true, data: { nodes, edges }, errors: [] };
225
- }
226
- }
227
- catch (e) {
228
- errors.push(`JSON code block parse error: ${e.message}`);
229
- }
230
- }
231
- const topologyMatch = text.match(/##\s*Topology[^\n]*\n([\s\S]*?)(?=\n##\s|$)/i);
232
- if (!topologyMatch) {
233
- return {
234
- success: false,
235
- errors: [
236
- "No '## Topology' section found. " +
237
- "Use the format produced by renderMachineTreeIndented() or a JSON code block.",
238
- ],
239
- };
240
- }
241
- const topologySection = topologyMatch[1];
242
- const nodeNames = new Set();
243
- const edges = [];
244
- const edgeLines = topologySection.split("\n").filter(l => l.trim().startsWith("- "));
245
- const pendingForwards = [];
246
- let currentEdge = null;
247
- for (const line of edgeLines) {
248
- const trimmed = line.trim();
249
- const isIndented = line.startsWith(" -");
250
- if (isIndented) {
251
- const fwdMatch = trimmed.match(/^-\s*forward:\s*(.+)$/);
252
- if (fwdMatch && currentEdge) {
253
- const fwd = parseForwardInline(fwdMatch[1]);
254
- if (fwd) {
255
- currentEdge.forwards.push(fwd);
256
- }
257
- }
258
- continue;
259
- }
260
- const edgeMatch = trimmed.match(/^-\s+(.+?)\s+-->\s+(\S+)(?:\s+\(threshold=(\d+)\))?(.*)$/);
261
- if (edgeMatch) {
262
- if (currentEdge) {
263
- edges.push(currentEdge);
264
- }
265
- const fromRaw = edgeMatch[1].trim();
266
- const to = edgeMatch[2].trim();
267
- const threshold = edgeMatch[3] ? parseInt(edgeMatch[3], 10) : 1;
268
- const from = fromRaw === "[*]" ? "" : fromRaw;
269
- currentEdge = {
270
- from,
271
- to,
272
- threshold,
273
- forwards: [],
274
- };
275
- nodeNames.add(to);
276
- if (from)
277
- nodeNames.add(from);
278
- }
279
- }
280
- if (currentEdge) {
281
- edges.push(currentEdge);
282
- }
283
- if (edges.length === 0) {
284
- return {
285
- success: false,
286
- errors: ["No edges found in '## Topology' section. Expected lines like '- A --> B (threshold=1)'."],
287
- };
288
- }
289
- const descMatch = text.match(/##\s*Node Descriptions[^\n]*\n([\s\S]*?)(?=\n##\s|$)/i);
290
- const nodeDescMap = new Map();
291
- if (descMatch) {
292
- const descLines = descMatch[1].split("\n");
293
- for (const line of descLines) {
294
- const m = line.match(/^-\s+(\S+):\s*(.+)$/);
295
- if (m) {
296
- nodeDescMap.set(m[1], m[2]);
297
- }
298
- }
299
- }
300
- const nodes = [];
301
- for (const name of nodeNames) {
302
- nodes.push({
303
- name,
304
- description: nodeDescMap.get(name) ?? null,
305
- });
306
- }
307
- return { success: true, data: { nodes, edges }, errors };
308
- }
309
- function parseForwardInline(text) {
310
- const match = text.match(/^(\S+)\s*\(([^)]*)\)$/);
311
- if (!match) {
312
- return {
313
- name: text.trim(),
314
- weight: 1,
315
- named_operator: null,
316
- permission_index: null,
317
- guard: null,
318
- retained_submission: null,
319
- };
320
- }
321
- const name = match[1];
322
- const annotationStr = match[2];
323
- const fwd = {
324
- name,
325
- weight: 1,
326
- named_operator: null,
327
- permission_index: null,
328
- guard: null,
329
- retained_submission: null,
330
- };
331
- for (const part of annotationStr.split(",").map(s => s.trim())) {
332
- if (!part)
333
- continue;
334
- const [key, ...valParts] = part.split("=");
335
- const val = valParts.join("=").trim();
336
- switch (key.trim()) {
337
- case "weight":
338
- fwd.weight = parseInt(val, 10) || 1;
339
- break;
340
- case "namedOperator":
341
- fwd.named_operator = val.replace(/^'|'$/g, "");
342
- break;
343
- case "permissionIndex":
344
- fwd.permission_index = parseInt(val, 10) || null;
345
- break;
346
- case "guard":
347
- fwd.guard = val || null;
348
- break;
349
- case "retained_submission":
350
- if (val.startsWith("[") && val.endsWith("]")) {
351
- fwd.retained_submission = val
352
- .slice(1, -1)
353
- .split(",")
354
- .map(s => parseInt(s.trim(), 10))
355
- .filter(n => !isNaN(n));
356
- }
357
- else {
358
- fwd.retained_submission = val;
359
- }
360
- break;
361
- }
362
- }
363
- return fwd;
364
- }
365
- function convertNodeArrayToGraph(data) {
366
- const nodes = [];
367
- const edges = [];
368
- for (const item of data) {
369
- if (!item || typeof item !== "object")
370
- continue;
371
- const node = item;
372
- const name = typeof node.name === "string" ? node.name : "";
373
- if (!name)
374
- continue;
375
- nodes.push({
376
- name,
377
- description: typeof node.description === "string" ? node.description : null,
378
- });
379
- const pairs = Array.isArray(node.pairs) ? node.pairs : [];
380
- for (const pairRaw of pairs) {
381
- if (!pairRaw || typeof pairRaw !== "object")
382
- continue;
383
- const pair = pairRaw;
384
- const prevNode = typeof pair.prev_node === "string" ? pair.prev_node : "";
385
- const threshold = typeof pair.threshold === "number" ? pair.threshold : 1;
386
- const forwardsRaw = Array.isArray(pair.forwards) ? pair.forwards : [];
387
- const forwards = forwardsRaw.map((f) => {
388
- const fwd = f;
389
- return {
390
- name: typeof fwd.name === "string" ? fwd.name : "",
391
- weight: typeof fwd.weight === "number" ? fwd.weight : 1,
392
- named_operator: typeof fwd.namedOperator === "string" ? fwd.namedOperator : null,
393
- permission_index: typeof fwd.permissionIndex === "number" ? fwd.permissionIndex : null,
394
- guard: typeof fwd.guard === "string"
395
- ? fwd.guard
396
- : (fwd.guard && typeof fwd.guard.guard === "string")
397
- ? fwd.guard.guard
398
- : null,
399
- retained_submission: null,
400
- };
401
- });
402
- edges.push({
403
- from: prevNode,
404
- to: name,
405
- threshold,
406
- forwards,
407
- });
408
- }
409
- }
410
- return { nodes, edges };
411
- }
412
- export function renderMachineAscii(input) {
413
- const { nodes, edges, machineName, machineAddress, published, paused } = input;
414
- const lines = [];
415
- if (machineName) {
416
- lines.push(`Machine: ${machineName}`);
417
- }
418
- if (machineAddress) {
419
- lines.push(`Address: ${machineAddress}`);
420
- }
421
- if (published !== null && published !== undefined) {
422
- lines.push(`Published: ${published}`);
423
- }
424
- if (paused !== null && paused !== undefined) {
425
- lines.push(`Paused: ${paused}`);
426
- }
427
- if (machineName || machineAddress) {
428
- lines.push("");
429
- }
430
- const outgoingMap = new Map();
431
- for (const edge of edges) {
432
- if (edge.from === "")
433
- continue;
434
- if (!outgoingMap.has(edge.from))
435
- outgoingMap.set(edge.from, []);
436
- outgoingMap.get(edge.from).push(edge);
437
- }
438
- const terminalNodes = new Set();
439
- for (const node of nodes) {
440
- const outEdges = outgoingMap.get(node.name) ?? [];
441
- const hasOutgoingToNode = outEdges.some(e => e.to !== "");
442
- if (!hasOutgoingToNode) {
443
- const isTargeted = edges.some(e => e.to === node.name);
444
- if (isTargeted) {
445
- terminalNodes.add(node.name);
446
- }
447
- }
448
- }
449
- const entryNodes = new Set();
450
- for (const edge of edges) {
451
- if (edge.from === "") {
452
- entryNodes.add(edge.to);
453
- }
454
- }
455
- const revisionNodes = new Set();
456
- for (const edge of edges) {
457
- if (edge.from === edge.to && edge.from !== "") {
458
- revisionNodes.add(edge.from);
459
- }
460
- }
461
- for (const edge of edges) {
462
- const fromLabel = edge.from === "" ? "[*]" : edge.from;
463
- const toLabel = edge.to === "" ? "[*]" : edge.to;
464
- const isCycle = edge.from === edge.to && edge.from !== "";
465
- for (const fwd of edge.forwards) {
466
- const annotations = [];
467
- if (isCycle)
468
- annotations.push("cycle");
469
- if (fwd.guard)
470
- annotations.push(`guard=${fwd.guard}`);
471
- if (fwd.named_operator !== null && fwd.named_operator !== undefined && fwd.named_operator !== "") {
472
- annotations.push(`op=${fwd.named_operator}`);
473
- }
474
- if (fwd.permission_index !== null && fwd.permission_index !== undefined) {
475
- annotations.push(`perm=${fwd.permission_index}`);
476
- }
477
- if (edge.threshold > 1)
478
- annotations.push(`threshold=${edge.threshold}`);
479
- const annotationStr = annotations.length > 0 ? ` [${annotations.join(", ")}]` : "";
480
- const cycleStr = isCycle ? " ⟲" : "";
481
- lines.push(`${fromLabel} ─${fwd.name}→ ${toLabel}${cycleStr}${annotationStr}`);
482
- }
483
- }
484
- const annotatedNodes = [];
485
- for (const node of nodes) {
486
- const annotations = [];
487
- if (entryNodes.has(node.name))
488
- annotations.push("entry");
489
- if (terminalNodes.has(node.name))
490
- annotations.push("terminal");
491
- if (revisionNodes.has(node.name))
492
- annotations.push("revision");
493
- if (annotations.length > 0) {
494
- annotatedNodes.push(` ${node.name}: ${annotations.join(", ")}`);
495
- }
496
- }
497
- if (annotatedNodes.length > 0) {
498
- lines.push("");
499
- lines.push("Node roles:");
500
- lines.push(...annotatedNodes);
501
- }
502
- return lines.join("\n");
503
- }
504
- export function renderMachineMarkmap(input) {
505
- const { nodes, edges, machineName, machineAddress, published, paused } = input;
506
- const lines = [];
507
- const titleParts = ["Machine"];
508
- if (machineName)
509
- titleParts.push(machineName);
510
- lines.push(`# ${titleParts.join(": ")}`);
511
- if (machineAddress || published !== null || paused !== null) {
512
- lines.push("");
513
- if (machineAddress)
514
- lines.push(`**Address:** ${machineAddress}`);
515
- if (published !== null && published !== undefined)
516
- lines.push(`**Published:** ${published}`);
517
- if (paused !== null && paused !== undefined)
518
- lines.push(`**Paused:** ${paused}`);
519
- }
520
- lines.push("");
521
- const outgoingMap = new Map();
522
- for (const edge of edges) {
523
- if (edge.from === "")
524
- continue;
525
- if (!outgoingMap.has(edge.from))
526
- outgoingMap.set(edge.from, []);
527
- outgoingMap.get(edge.from).push(edge);
528
- }
529
- const terminalNodes = new Set();
530
- for (const node of nodes) {
531
- const outEdges = outgoingMap.get(node.name) ?? [];
532
- const hasOutgoingToNode = outEdges.some(e => e.to !== "");
533
- if (!hasOutgoingToNode) {
534
- const isTargeted = edges.some(e => e.to === node.name);
535
- if (isTargeted)
536
- terminalNodes.add(node.name);
537
- }
538
- }
539
- for (const edge of edges) {
540
- const fromLabel = edge.from === "" ? "[*]" : edge.from;
541
- const toLabel = edge.to === "" ? "[*]" : edge.to;
542
- const isCycle = edge.from === edge.to && edge.from !== "";
543
- const cycleStr = isCycle ? " (cycle)" : "";
544
- const terminalStr = terminalNodes.has(edge.to) ? " (terminal)" : "";
545
- lines.push(`## ${fromLabel} → ${toLabel}${cycleStr}${terminalStr}`);
546
- for (const fwd of edge.forwards) {
547
- const parts = [`weight=${fwd.weight}`];
548
- if (fwd.named_operator !== null && fwd.named_operator !== undefined) {
549
- parts.push(`namedOperator='${fwd.named_operator}'`);
550
- }
551
- if (fwd.permission_index !== null && fwd.permission_index !== undefined) {
552
- parts.push(`permissionIndex=${fwd.permission_index}`);
553
- }
554
- if (fwd.guard) {
555
- parts.push(`guard=${fwd.guard}`);
556
- }
557
- if (edge.threshold > 1) {
558
- parts.push(`threshold=${edge.threshold}`);
559
- }
560
- lines.push(`### forward: ${fwd.name} (${parts.join(", ")})`);
561
- }
562
- lines.push("");
563
- }
564
- return lines.join("\n");
565
- }
1
+ function sanitizeMermaidLabel(a){if(/[<>"\[\]{}()|&]/['test'](a))return'\x22'+a['replace'](/"/g,'\x27')+'\x22';return a;}const MACHINE_NODE_COLORS={'entry':{'fill':'#10b981','stroke':'#065f46'},'terminal':{'fill':'#ef4444','stroke':'#991b1b'},'revision':{'fill':'#f59e0b','stroke':'#92400e'},'normal':{'fill':'#3b82f6','stroke':'#1e40af'}};function classifyMachineNode(a,b,c){const d=b['filter'](g=>g['from']===a);if(d['length']===0x0)return'terminal';const e=d['some'](g=>g['to']!=='');if(!e)return'terminal';const f=b['some'](g=>g['to']===a&&g['from']===a);if(f)return'revision';if(c['has'](a))return'entry';return'normal';}export function sanitizeMermaidNodeId(a){if(/[^a-zA-Z0-9_]/['test'](a))return'\x22'+a+'\x22';return a;}export function renderMachineMermaid(a,b,c){const d=c?.['colored']!==![],e=['stateDiagram-v2'];d&&(e['push']('\x20\x20%%\x20Color\x20Legend\x20(BehaviorTree.CPP-inspired\x20workflow\x20roles):'),e['push']('\x20\x20%%\x20\x20\x20green\x20\x20#10b981\x20-\x20entry\x20\x20\x20\x20(start\x20state,\x20targeted\x20by\x20[*])'),e['push']('\x20\x20%%\x20\x20\x20red\x20\x20\x20\x20#ef4444\x20-\x20terminal\x20(end\x20state,\x20no\x20outgoing\x20edges)'),e['push']('\x20\x20%%\x20\x20\x20amber\x20\x20#f59e0b\x20-\x20revision\x20(self-loop\x20/\x20revision\x20cycle)'),e['push']('\x20\x20%%\x20\x20\x20blue\x20\x20\x20#3b82f6\x20-\x20normal\x20\x20\x20(regular\x20intermediate\x20state)'),e['push']('\x20\x20%%\x20Priority:\x20terminal\x20>\x20revision\x20>\x20entry\x20>\x20normal'));const f=new Set(b['filter'](i=>i['from']!=='')['map'](i=>i['to'])),g=new Set();for(const i of a){!f['has'](i['name'])&&g['add'](i['name']);}const h=a['filter'](j=>g['has'](j['name']));for(const j of h){const k=b['filter'](l=>l['from']===''&&l['to']===j['name']);if(k['length']>0x0)for(const l of k){for(const m of l['forwards']){const n=buildForwardLabel(m,l['threshold']);e['push']('\x20\x20[*]\x20-->\x20'+sanitizeMermaidNodeId(j['name'])+':\x20'+sanitizeMermaidLabel(n));}}else e['push']('\x20\x20[*]\x20-->\x20'+sanitizeMermaidNodeId(j['name']));}for(const o of b){if(o['from']==='')continue;const p=sanitizeMermaidNodeId(o['from']),q=o['to']===''?'[*]':sanitizeMermaidNodeId(o['to']);for(const r of o['forwards']){const s=buildForwardLabel(r,o['threshold']);e['push']('\x20\x20'+p+'\x20-->\x20'+q+':\x20'+sanitizeMermaidLabel(s));}}for(const t of a){t['description']&&e['push']('\x20\x20'+sanitizeMermaidNodeId(t['name'])+':\x20'+sanitizeMermaidLabel(t['description']));}if(d){e['push'](''),e['push']('\x20\x20%%\x20Node\x20colors\x20(BehaviorTree.CPP-inspired\x20workflow\x20roles)');for(const u of a){const v=classifyMachineNode(u['name'],b,g),w=MACHINE_NODE_COLORS[v];e['push']('\x20\x20style\x20'+sanitizeMermaidNodeId(u['name'])+'\x20fill:'+w['fill']+',stroke:'+w['stroke']+',color:#fff');}}return e['join']('\x0a');}function buildForwardLabel(a,b){let c=a['name'];const d=[];b>0x1&&d['push']('threshold='+b);if(a['guard']){const e=a['guard']['length']>0xa?a['guard']['slice'](0x0,0x6)+'…'+a['guard']['slice'](-0x4):a['guard'];d['push']('guard='+e);}return d['length']>0x0&&(c+='\x20('+d['join'](',\x20')+')'),c;}export function renderMachineTreeIndented(a){const {nodes:b,edges:c,machineName:d,machineAddress:e,published:f,paused:g}=a,h=[];h['push']('#\x20Machine\x20Workflow\x20Definition'),h['push']('');d&&h['push']('**Machine:**\x20'+d);e&&h['push']('**Address:**\x20'+e);h['push']('**Total\x20Nodes:**\x20'+b['length']),h['push']('**Total\x20Edges:**\x20'+c['length']);f!==null&&f!==undefined&&h['push']('**Published:**\x20'+f);g!==null&&g!==undefined&&h['push']('**Paused:**\x20'+g);h['push'](''),h['push']('##\x20Topology\x20(directed\x20graph\x20outline)'),h['push']('');const i=c['filter'](m=>m['from']===''),j=c['filter'](m=>m['from']!=='');for(const m of i){const n='-\x20[*]\x20-->\x20'+m['to']+'\x20(threshold='+m['threshold']+')';h['push'](n);for(const o of m['forwards']){h['push']('\x20\x20-\x20forward:\x20'+formatForwardInline(o));}}for(const p of j){const q=p['from']===p['to'],r=q?'\x20\x20#\x20self-loop\x20(revision\x20cycle)':'',s=p['to']===''?'[*]':p['to'],t='-\x20'+p['from']+'\x20-->\x20'+s+'\x20(threshold='+p['threshold']+')'+r;h['push'](t);for(const u of p['forwards']){h['push']('\x20\x20-\x20forward:\x20'+formatForwardInline(u));}}const k=b['filter'](v=>v['description']);if(k['length']>0x0){h['push'](''),h['push']('##\x20Node\x20Descriptions'),h['push']('');for(const v of b){v['description']&&h['push']('-\x20'+v['name']+':\x20'+v['description']);}}const l=new Map();for(const w of c){if(!l['has'](w['to']))l['set'](w['to'],[]);l['get'](w['to'])['push']({'from':w['from']===''?'[*]':w['from'],'forwards':w['forwards']['map'](x=>x['name'])});}if(l['size']>0x0){h['push'](''),h['push']('##\x20Backrefs\x20(incoming\x20edges\x20per\x20node)'),h['push']('');for(const x of b){const y=l['get'](x['name']);if(!y||y['length']===0x0)continue;const z=y['map'](A=>{const B=A['forwards']['length']>0x0?'\x20('+A['forwards']['join'](',\x20')+')':'',C=A['from']===x['name']?'\x20#\x20self-loop':'';return'<-\x20'+A['from']+B+C;});h['push']('-\x20'+x['name']+':\x20'+z['join'](',\x20'));}}return h['push'](''),h['push']('##\x20JSON\x20Definition'),h['push'](''),h['push']('```json'),h['push'](JSON['stringify']({'nodes':b,'edges':c},null,0x2)),h['push']('```'),h['join']('\x0a');}function formatForwardInline(a){const b=['weight='+a['weight']];a['named_operator']!==null&&a['named_operator']!==undefined&&b['push']('namedOperator=\x27'+a['named_operator']+'\x27');a['permission_index']!==null&&a['permission_index']!==undefined&&b['push']('permissionIndex='+a['permission_index']);a['guard']&&b['push']('guard='+a['guard']);if(a['retained_submission']){const c=Array['isArray'](a['retained_submission'])?'['+a['retained_submission']['join'](',')+']':String(a['retained_submission']);b['push']('retained_submission='+c);}return a['name']+'\x20('+b['join'](',\x20')+')';}export function parseMachineTreeIndented(a){const b=[],c=a['match'](/```json\s*\n([\s\S]*?)```/);if(c)try{const p=JSON['parse'](c[0x1]['trim']());if(p&&typeof p==='object'&&Array['isArray'](p['nodes'])&&Array['isArray'](p['edges']))return{'success':!![],'data':p,'errors':[]};if(Array['isArray'](p)){const {nodes:q,edges:r}=convertNodeArrayToGraph(p);return{'success':!![],'data':{'nodes':q,'edges':r},'errors':[]};}}catch(s){b['push']('JSON\x20code\x20block\x20parse\x20error:\x20'+s['message']);}const d=a['match'](/##\s*Topology[^\n]*\n([\s\S]*?)(?=\n##\s|$)/i);if(!d)return{'success':![],'errors':['No\x20\x27##\x20Topology\x27\x20section\x20found.\x20'+'Use\x20the\x20format\x20produced\x20by\x20renderMachineTreeIndented()\x20or\x20a\x20JSON\x20code\x20block.']};const f=d[0x1],g=new Set(),h=[],i=f['split']('\x0a')['filter'](t=>t['trim']()['startsWith']('-\x20')),j=[];let k=null;for(const t of i){const u=t['trim'](),v=t['startsWith']('\x20\x20-');if(v){const x=u['match'](/^-\s*forward:\s*(.+)$/);if(x&&k){const y=parseForwardInline(x[0x1]);y&&k['forwards']['push'](y);}continue;}const w=u['match'](/^-\s+(.+?)\s+-->\s+(\S+)(?:\s+\(threshold=(\d+)\))?(.*)$/);if(w){k&&h['push'](k);const z=w[0x1]['trim'](),A=w[0x2]['trim'](),B=w[0x3]?parseInt(w[0x3],0xa):0x1,C=z==='[*]'?'':z;k={'from':C,'to':A,'threshold':B,'forwards':[]},g['add'](A);if(C)g['add'](C);}}k&&h['push'](k);if(h['length']===0x0)return{'success':![],'errors':['No\x20edges\x20found\x20in\x20\x27##\x20Topology\x27\x20section.\x20Expected\x20lines\x20like\x20\x27-\x20A\x20-->\x20B\x20(threshold=1)\x27.']};const l=a['match'](/##\s*Node Descriptions[^\n]*\n([\s\S]*?)(?=\n##\s|$)/i),n=new Map();if(l){const D=l[0x1]['split']('\x0a');for(const E of D){const F=E['match'](/^-\s+(\S+):\s*(.+)$/);F&&n['set'](F[0x1],F[0x2]);}}const o=[];for(const G of g){o['push']({'name':G,'description':n['get'](G)??null});}return{'success':!![],'data':{'nodes':o,'edges':h},'errors':b};}function parseForwardInline(a){const b=a['match'](/^(\S+)\s*\(([^)]*)\)$/);if(!b)return{'name':a['trim'](),'weight':0x1,'named_operator':null,'permission_index':null,'guard':null,'retained_submission':null};const c=b[0x1],d=b[0x2],e={'name':c,'weight':0x1,'named_operator':null,'permission_index':null,'guard':null,'retained_submission':null};for(const f of d['split'](',')['map'](g=>g['trim']())){if(!f)continue;const [g,...h]=f['split']('='),i=h['join']('=')['trim']();switch(g['trim']()){case'weight':e['weight']=parseInt(i,0xa)||0x1;break;case'namedOperator':e['named_operator']=i['replace'](/^'|'$/g,'');break;case'permissionIndex':e['permission_index']=parseInt(i,0xa)||null;break;case'guard':e['guard']=i||null;break;case'retained_submission':i['startsWith']('[')&&i['endsWith'](']')?e['retained_submission']=i['slice'](0x1,-0x1)['split'](',')['map'](j=>parseInt(j['trim'](),0xa))['filter'](j=>!isNaN(j)):e['retained_submission']=i;break;}}return e;}function convertNodeArrayToGraph(a){const b=[],c=[];for(const d of a){if(!d||typeof d!=='object')continue;const e=d,f=typeof e['name']==='string'?e['name']:'';if(!f)continue;b['push']({'name':f,'description':typeof e['description']==='string'?e['description']:null});const g=Array['isArray'](e['pairs'])?e['pairs']:[];for(const h of g){if(!h||typeof h!=='object')continue;const i=h,j=typeof i['prev_node']==='string'?i['prev_node']:'',k=typeof i['threshold']==='number'?i['threshold']:0x1,l=Array['isArray'](i['forwards'])?i['forwards']:[],m=l['map'](n=>{const o=n;return{'name':typeof o['name']==='string'?o['name']:'','weight':typeof o['weight']==='number'?o['weight']:0x1,'named_operator':typeof o['namedOperator']==='string'?o['namedOperator']:null,'permission_index':typeof o['permissionIndex']==='number'?o['permissionIndex']:null,'guard':typeof o['guard']==='string'?o['guard']:o['guard']&&typeof o['guard']['guard']==='string'?o['guard']['guard']:null,'retained_submission':null};});c['push']({'from':j,'to':f,'threshold':k,'forwards':m});}}return{'nodes':b,'edges':c};}export function renderMachineAscii(a){const {nodes:b,edges:c,machineName:d,machineAddress:e,published:f,paused:g}=a,h=[];d&&h['push']('Machine:\x20'+d);e&&h['push']('Address:\x20'+e);f!==null&&f!==undefined&&h['push']('Published:\x20'+f);g!==null&&g!==undefined&&h['push']('Paused:\x20'+g);(d||e)&&h['push']('');const i=new Map();for(const n of c){if(n['from']==='')continue;if(!i['has'](n['from']))i['set'](n['from'],[]);i['get'](n['from'])['push'](n);}const j=new Set();for(const o of b){const p=i['get'](o['name'])??[],q=p['some'](r=>r['to']!=='');if(!q){const r=c['some'](s=>s['to']===o['name']);r&&j['add'](o['name']);}}const k=new Set();for(const s of c){s['from']===''&&k['add'](s['to']);}const l=new Set();for(const t of c){t['from']===t['to']&&t['from']!==''&&l['add'](t['from']);}for(const u of c){const v=u['from']===''?'[*]':u['from'],w=u['to']===''?'[*]':u['to'],x=u['from']===u['to']&&u['from']!=='';for(const y of u['forwards']){const z=[];if(x)z['push']('cycle');if(y['guard'])z['push']('guard='+y['guard']);y['named_operator']!==null&&y['named_operator']!==undefined&&y['named_operator']!==''&&z['push']('op='+y['named_operator']);y['permission_index']!==null&&y['permission_index']!==undefined&&z['push']('perm='+y['permission_index']);if(u['threshold']>0x1)z['push']('threshold='+u['threshold']);const A=z['length']>0x0?'\x20['+z['join'](',\x20')+']':'',B=x?'\x20⟲':'';h['push'](v+'\x20─'+y['name']+'→\x20'+w+B+A);}}const m=[];for(const C of b){const D=[];if(k['has'](C['name']))D['push']('entry');if(j['has'](C['name']))D['push']('terminal');if(l['has'](C['name']))D['push']('revision');D['length']>0x0&&m['push']('\x20\x20'+C['name']+':\x20'+D['join'](',\x20'));}return m['length']>0x0&&(h['push'](''),h['push']('Node\x20roles:'),h['push'](...m)),h['join']('\x0a');}export function renderMachineMarkmap(a){const {nodes:b,edges:c,machineName:d,machineAddress:e,published:f,paused:g}=a,h=[],i=['Machine'];if(d)i['push'](d);h['push']('#\x20'+i['join'](':\x20'));if(e||f!==null||g!==null){h['push']('');if(e)h['push']('**Address:**\x20'+e);if(f!==null&&f!==undefined)h['push']('**Published:**\x20'+f);if(g!==null&&g!==undefined)h['push']('**Paused:**\x20'+g);}h['push']('');const j=new Map();for(const l of c){if(l['from']==='')continue;if(!j['has'](l['from']))j['set'](l['from'],[]);j['get'](l['from'])['push'](l);}const k=new Set();for(const m of b){const n=j['get'](m['name'])??[],o=n['some'](p=>p['to']!=='');if(!o){const p=c['some'](q=>q['to']===m['name']);if(p)k['add'](m['name']);}}for(const q of c){const r=q['from']===''?'[*]':q['from'],s=q['to']===''?'[*]':q['to'],t=q['from']===q['to']&&q['from']!=='',u=t?'\x20(cycle)':'',v=k['has'](q['to'])?'\x20(terminal)':'';h['push']('##\x20'+r+'\x20→\x20'+s+u+v);for(const w of q['forwards']){const x=['weight='+w['weight']];w['named_operator']!==null&&w['named_operator']!==undefined&&x['push']('namedOperator=\x27'+w['named_operator']+'\x27'),w['permission_index']!==null&&w['permission_index']!==undefined&&x['push']('permissionIndex='+w['permission_index']),w['guard']&&x['push']('guard='+w['guard']),q['threshold']>0x1&&x['push']('threshold='+q['threshold']),h['push']('###\x20forward:\x20'+w['name']+'\x20('+x['join'](',\x20')+')');}h['push']('');}return h['join']('\x0a');}