@wowok/agent-mcp 2.7.1 → 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 (375) 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.js +1 -397
  13. package/dist/customer/types.js +1 -13
  14. package/dist/customer/user-preferences.js +1 -460
  15. package/dist/evaluation/arbitration-game.d.ts +9 -2
  16. package/dist/evaluation/arbitration-game.js +1 -48
  17. package/dist/evaluation/builtins/demand-match.js +1 -153
  18. package/dist/evaluation/builtins/index.js +1 -10
  19. package/dist/evaluation/builtins/service-risk.js +1 -55
  20. package/dist/evaluation/capability.js +1 -13
  21. package/dist/evaluation/composer.js +1 -40
  22. package/dist/evaluation/engine.js +1 -175
  23. package/dist/evaluation/extract.js +1 -115
  24. package/dist/evaluation/game-strategy.d.ts +27 -0
  25. package/dist/evaluation/game-strategy.js +1 -0
  26. package/dist/evaluation/gap.js +1 -100
  27. package/dist/evaluation/index.d.ts +1 -0
  28. package/dist/evaluation/index.js +1 -11
  29. package/dist/evaluation/node-game.d.ts +31 -3
  30. package/dist/evaluation/node-game.js +1 -57
  31. package/dist/evaluation/region.js +1 -36
  32. package/dist/evaluation/types.d.ts +1 -0
  33. package/dist/evaluation/types.js +1 -1
  34. package/dist/evaluation/user-injection.js +1 -27
  35. package/dist/experience/experience-reuse.js +1 -103
  36. package/dist/experience/index.js +1 -5
  37. package/dist/experience/intent-distill.js +1 -83
  38. package/dist/experience/realtime-feedback.js +1 -94
  39. package/dist/experience/types.js +1 -1
  40. package/dist/experience/user-profile.js +1 -171
  41. package/dist/extensions/business-modules.js +1 -287
  42. package/dist/extensions/capability-manifest.js +1 -781
  43. package/dist/extensions/constraint-registry.js +1 -198
  44. package/dist/extensions/index.js +1 -6
  45. package/dist/extensions/metric-registry.js +1 -257
  46. package/dist/extensions/mode-evaluator.js +1 -170
  47. package/dist/extensions/modes.js +1 -499
  48. package/dist/extensions/registry.js +1 -717
  49. package/dist/extensions/types.js +1 -1
  50. package/dist/harness/auto-escalation.js +1 -68
  51. package/dist/harness/checkpoint.js +1 -129
  52. package/dist/harness/index.js +1 -78
  53. package/dist/harness/plan.js +1 -315
  54. package/dist/harness/recover.js +1 -139
  55. package/dist/harness/types.js +1 -1
  56. package/dist/harness/verify.js +1 -237
  57. package/dist/index.js +1 -273
  58. package/dist/intent/enrich.js +1 -67
  59. package/dist/intent/index.js +1 -60
  60. package/dist/intent/matcher.js +1 -81
  61. package/dist/intent/store.js +1 -55
  62. package/dist/intent/types.js +1 -10
  63. package/dist/knowledge/acquisition-flywheel.js +1 -192
  64. package/dist/knowledge/allocation-confirm.js +1 -534
  65. package/dist/knowledge/allocation-context.js +1 -249
  66. package/dist/knowledge/allocation-ledger.js +1 -463
  67. package/dist/knowledge/allocation-puzzle.js +1 -298
  68. package/dist/knowledge/allocation-risk.js +1 -568
  69. package/dist/knowledge/allocation-templates.js +1 -970
  70. package/dist/knowledge/allocation-translation.js +1 -585
  71. package/dist/knowledge/arb-risk.js +1 -210
  72. package/dist/knowledge/arbitration-confirm.js +1 -559
  73. package/dist/knowledge/arbitration-context.js +1 -505
  74. package/dist/knowledge/arbitration-ledger.js +1 -521
  75. package/dist/knowledge/arbitration-puzzle.js +1 -304
  76. package/dist/knowledge/arbitration-risk.js +1 -423
  77. package/dist/knowledge/arbitration-templates.js +1 -276
  78. package/dist/knowledge/arbitration-translation.js +1 -487
  79. package/dist/knowledge/arbitration-trust.js +1 -117
  80. package/dist/knowledge/audit-rules.js +1 -141
  81. package/dist/knowledge/bridge-risk.js +1 -263
  82. package/dist/knowledge/contact-risk.js +1 -200
  83. package/dist/knowledge/contact-templates.js +1 -60
  84. package/dist/knowledge/demand-confirm.js +1 -206
  85. package/dist/knowledge/demand-matching.js +1 -132
  86. package/dist/knowledge/demand-risk.js +1 -240
  87. package/dist/knowledge/demand-translation.js +1 -354
  88. package/dist/knowledge/deployment-scanner.js +1 -823
  89. package/dist/knowledge/dynamic-pricing.js +1 -87
  90. package/dist/knowledge/examples-scanner-cli.js +1 -26
  91. package/dist/knowledge/examples-scanner.js +1 -843
  92. package/dist/knowledge/flywheel-loop.js +1 -404
  93. package/dist/knowledge/fund-layer.js +1 -973
  94. package/dist/knowledge/glossary.js +1 -211
  95. package/dist/knowledge/guard-confirm.js +1 -406
  96. package/dist/knowledge/guard-context.js +1 -287
  97. package/dist/knowledge/guard-design-patterns.js +1 -360
  98. package/dist/knowledge/guard-ledger.js +1 -260
  99. package/dist/knowledge/guard-lint.js +1 -670
  100. package/dist/knowledge/guard-migration.js +1 -228
  101. package/dist/knowledge/guard-puzzle.js +1 -805
  102. package/dist/knowledge/guard-render.js +1 -700
  103. package/dist/knowledge/guard-risk.js +1 -1879
  104. package/dist/knowledge/guard-submission-prompt.js +1 -171
  105. package/dist/knowledge/guard-templates.js +1 -1105
  106. package/dist/knowledge/guard-translation.js +1 -1119
  107. package/dist/knowledge/index.js +1 -436
  108. package/dist/knowledge/industry-evolution.js +1 -323
  109. package/dist/knowledge/industry-generalizer.js +1 -381
  110. package/dist/knowledge/industry-registry.js +1 -174
  111. package/dist/knowledge/intent-metrics.d.ts +4 -3
  112. package/dist/knowledge/intent-metrics.js +1 -566
  113. package/dist/knowledge/machine-confirm.js +1 -559
  114. package/dist/knowledge/machine-context.js +1 -833
  115. package/dist/knowledge/machine-ledger.js +1 -338
  116. package/dist/knowledge/machine-puzzle.js +1 -494
  117. package/dist/knowledge/machine-render.js +1 -565
  118. package/dist/knowledge/machine-risk.js +1 -669
  119. package/dist/knowledge/machine-templates.js +1 -1597
  120. package/dist/knowledge/machine-topology.js +1 -234
  121. package/dist/knowledge/machine-translation.js +1 -513
  122. package/dist/knowledge/mcp-schema-audit-cli.js +1 -45
  123. package/dist/knowledge/mcp-schema-audit.js +1 -777
  124. package/dist/knowledge/onchain-constants.js +1 -35
  125. package/dist/knowledge/order-confirm.js +1 -573
  126. package/dist/knowledge/order-context.js +1 -390
  127. package/dist/knowledge/order-ledger.js +1 -341
  128. package/dist/knowledge/order-puzzle.js +1 -255
  129. package/dist/knowledge/order-risk.js +1 -653
  130. package/dist/knowledge/order-templates.js +1 -368
  131. package/dist/knowledge/order-translation.js +1 -550
  132. package/dist/knowledge/overrides-loader.js +1 -65
  133. package/dist/knowledge/passport-confirm.js +1 -531
  134. package/dist/knowledge/passport-context.js +1 -306
  135. package/dist/knowledge/passport-ledger.js +1 -282
  136. package/dist/knowledge/passport-puzzle.js +1 -333
  137. package/dist/knowledge/passport-risk.js +1 -450
  138. package/dist/knowledge/passport-templates.js +1 -568
  139. package/dist/knowledge/passport-translation.js +1 -516
  140. package/dist/knowledge/payment-risk.js +1 -249
  141. package/dist/knowledge/permission-confirm.js +1 -426
  142. package/dist/knowledge/permission-context.js +1 -224
  143. package/dist/knowledge/permission-ledger.js +1 -403
  144. package/dist/knowledge/permission-puzzle.js +1 -173
  145. package/dist/knowledge/permission-risk.js +1 -411
  146. package/dist/knowledge/permission-templates.js +1 -234
  147. package/dist/knowledge/permission-translation.js +1 -350
  148. package/dist/knowledge/personal-risk.js +1 -212
  149. package/dist/knowledge/process-model.js +1 -160
  150. package/dist/knowledge/progress-confirm.js +1 -456
  151. package/dist/knowledge/progress-context.js +1 -452
  152. package/dist/knowledge/progress-ledger.js +1 -330
  153. package/dist/knowledge/progress-puzzle.js +1 -219
  154. package/dist/knowledge/progress-risk.js +1 -461
  155. package/dist/knowledge/progress-templates.js +1 -228
  156. package/dist/knowledge/progress-translation.js +1 -405
  157. package/dist/knowledge/proof-confirm.js +1 -187
  158. package/dist/knowledge/proof-risk.js +1 -207
  159. package/dist/knowledge/proof-translation.js +1 -283
  160. package/dist/knowledge/registrar-risk.js +1 -217
  161. package/dist/knowledge/repository-confirm.js +1 -286
  162. package/dist/knowledge/repository-risk.js +1 -373
  163. package/dist/knowledge/repository-translation.js +1 -445
  164. package/dist/knowledge/reputation-rules.js +1 -99
  165. package/dist/knowledge/resource-risk.js +1 -157
  166. package/dist/knowledge/reward-confirm.js +1 -526
  167. package/dist/knowledge/reward-context.js +1 -504
  168. package/dist/knowledge/reward-ledger.js +1 -502
  169. package/dist/knowledge/reward-puzzle.js +1 -300
  170. package/dist/knowledge/reward-risk.js +1 -627
  171. package/dist/knowledge/reward-templates.js +1 -197
  172. package/dist/knowledge/reward-translation.js +1 -501
  173. package/dist/knowledge/safety-rules.js +1 -404
  174. package/dist/knowledge/scenario-modes.js +1 -321
  175. package/dist/knowledge/service-confirm.js +1 -807
  176. package/dist/knowledge/service-context.js +1 -403
  177. package/dist/knowledge/service-ledger.js +1 -609
  178. package/dist/knowledge/service-puzzle.js +1 -236
  179. package/dist/knowledge/service-risk.js +1 -651
  180. package/dist/knowledge/service-templates.js +1 -456
  181. package/dist/knowledge/service-translation.js +1 -622
  182. package/dist/knowledge/template-registry.js +1 -353
  183. package/dist/knowledge/tool-constraints.js +1 -195
  184. package/dist/knowledge/tools-reference.js +1 -178
  185. package/dist/knowledge/treasury-confirm.js +1 -512
  186. package/dist/knowledge/treasury-context.js +1 -363
  187. package/dist/knowledge/treasury-ledger.js +1 -300
  188. package/dist/knowledge/treasury-puzzle.js +1 -216
  189. package/dist/knowledge/treasury-risk.js +1 -440
  190. package/dist/knowledge/treasury-templates.js +1 -358
  191. package/dist/knowledge/treasury-translation.js +1 -498
  192. package/dist/knowledge/trust-metrics.js +1 -198
  193. package/dist/knowledge/util-risk.js +1 -135
  194. package/dist/loop-engineering/aggregate.js +1 -132
  195. package/dist/loop-engineering/context-collect.js +1 -83
  196. package/dist/loop-engineering/diagnose.js +1 -273
  197. package/dist/loop-engineering/improve.js +1 -405
  198. package/dist/loop-engineering/index.js +1 -4
  199. package/dist/loop-engineering/pipeline.js +1 -56
  200. package/dist/mode-market/index.js +1 -3
  201. package/dist/mode-market/registry.js +1 -124
  202. package/dist/mode-market/review.js +1 -214
  203. package/dist/mode-market/submission.js +1 -85
  204. package/dist/participation/collaborator-interest.d.ts +23 -0
  205. package/dist/participation/collaborator-interest.js +1 -0
  206. package/dist/participation/customer-interest.d.ts +25 -0
  207. package/dist/participation/customer-interest.js +1 -0
  208. package/dist/participation/merchant-interest.js +1 -100
  209. package/dist/participation/radar-core.d.ts +13 -3
  210. package/dist/participation/radar-core.js +1 -269
  211. package/dist/participation/supplier-interest.d.ts +25 -0
  212. package/dist/participation/supplier-interest.js +1 -0
  213. package/dist/persona/analyzer.js +1 -66
  214. package/dist/persona/bridge.js +1 -86
  215. package/dist/persona/defaults.js +1 -195
  216. package/dist/persona/experience-bridge.js +1 -23
  217. package/dist/persona/index.js +1 -71
  218. package/dist/persona/model.js +1 -111
  219. package/dist/persona/store.js +1 -62
  220. package/dist/persona/types.d.ts +3 -1
  221. package/dist/persona/types.js +1 -5
  222. package/dist/project/business-puzzle.js +1 -383
  223. package/dist/project/context-assembly.js +1 -254
  224. package/dist/project/deployment-bridge.js +1 -120
  225. package/dist/project/deployment-doc.js +1 -1126
  226. package/dist/project/edit-planner.js +1 -1342
  227. package/dist/project/evaluation.js +1 -2011
  228. package/dist/project/game-theory.js +1 -177
  229. package/dist/project/graph-builder.js +1 -656
  230. package/dist/project/graph.js +1 -340
  231. package/dist/project/handlers.js +1 -1784
  232. package/dist/project/index.d.ts +1 -0
  233. package/dist/project/index.js +1 -301
  234. package/dist/project/intent-analyzer.js +1 -149
  235. package/dist/project/machine-nodes.js +1 -36
  236. package/dist/project/merchant-guide.js +1 -264
  237. package/dist/project/migration.js +1 -125
  238. package/dist/project/mode-actions.js +1 -309
  239. package/dist/project/namespace.js +1 -206
  240. package/dist/project/participation-radar.js +1 -428
  241. package/dist/project/pipeline-actions.js +1 -109
  242. package/dist/project/project-store.js +1 -422
  243. package/dist/project/query.js +1 -153
  244. package/dist/project/reverse-mapping.d.ts +34 -0
  245. package/dist/project/reverse-mapping.js +1 -0
  246. package/dist/project/risk-aggregator.js +1 -295
  247. package/dist/project/rollback-policy.js +1 -290
  248. package/dist/project/semantic-assembler.js +1 -345
  249. package/dist/project/semantic-graph.js +1 -292
  250. package/dist/project/stage-gate.js +1 -369
  251. package/dist/project/substep-trace.js +1 -332
  252. package/dist/project/task-tracker.js +1 -78
  253. package/dist/role/derivation.d.ts +18 -0
  254. package/dist/role/derivation.js +1 -0
  255. package/dist/role/index.d.ts +5 -0
  256. package/dist/role/index.js +1 -0
  257. package/dist/role/model.d.ts +8 -0
  258. package/dist/role/model.js +1 -0
  259. package/dist/role/resolution.d.ts +11 -0
  260. package/dist/role/resolution.js +1 -0
  261. package/dist/role/types.d.ts +11 -0
  262. package/dist/role/types.js +1 -0
  263. package/dist/rules.js +1 -52
  264. package/dist/safety/confirm-gate.js +1 -88
  265. package/dist/safety/index.js +1 -3
  266. package/dist/safety/preview.js +1 -52
  267. package/dist/schema/call/allocation.js +1 -34
  268. package/dist/schema/call/arbitration.js +1 -113
  269. package/dist/schema/call/base.d.ts +15 -15
  270. package/dist/schema/call/base.js +1 -370
  271. package/dist/schema/call/bridge-handler.js +1 -265
  272. package/dist/schema/call/bridge.d.ts +7 -7
  273. package/dist/schema/call/bridge.js +1 -458
  274. package/dist/schema/call/contact.js +1 -37
  275. package/dist/schema/call/demand.js +1 -47
  276. package/dist/schema/call/guard.js +1 -161
  277. package/dist/schema/call/handler.js +1 -322
  278. package/dist/schema/call/index.js +1 -20
  279. package/dist/schema/call/machine.js +1 -193
  280. package/dist/schema/call/order.js +1 -35
  281. package/dist/schema/call/payment.js +1 -37
  282. package/dist/schema/call/permission-handler.js +1 -54
  283. package/dist/schema/call/permission.js +1 -105
  284. package/dist/schema/call/personal.js +1 -78
  285. package/dist/schema/call/progress.js +1 -47
  286. package/dist/schema/call/proof.js +1 -33
  287. package/dist/schema/call/repository.js +1 -77
  288. package/dist/schema/call/reward.js +1 -30
  289. package/dist/schema/call/semantic.js +1 -1679
  290. package/dist/schema/call/service.js +1 -184
  291. package/dist/schema/call/treasury.js +1 -71
  292. package/dist/schema/common/index.js +1 -407
  293. package/dist/schema/config/index.js +1 -68
  294. package/dist/schema/evaluation/index.d.ts +213 -16
  295. package/dist/schema/evaluation/index.js +1 -356
  296. package/dist/schema/index.js +1 -17
  297. package/dist/schema/intent-radar/index.d.ts +13 -13
  298. package/dist/schema/intent-radar/index.js +1 -89
  299. package/dist/schema/local/index.d.ts +21 -21
  300. package/dist/schema/local/index.js +1 -927
  301. package/dist/schema/local/wip.js +1 -187
  302. package/dist/schema/messenger/index.d.ts +7 -7
  303. package/dist/schema/messenger/index.js +1 -475
  304. package/dist/schema/operations.d.ts +7 -7
  305. package/dist/schema/operations.js +1 -520
  306. package/dist/schema/persona/index.d.ts +54 -54
  307. package/dist/schema/persona/index.js +1 -148
  308. package/dist/schema/project/index.d.ts +94 -48
  309. package/dist/schema/project/index.js +1 -2057
  310. package/dist/schema/query/index.d.ts +423 -7
  311. package/dist/schema/query/index.js +1 -1646
  312. package/dist/schema/schema-query/index.js +1 -104
  313. package/dist/schema/schema-version.js +1 -76
  314. package/dist/schema/sync-layer4.js +1 -286
  315. package/dist/schema/task-status.js +1 -36
  316. package/dist/schema/trust/index.js +1 -314
  317. package/dist/schema/utils/guard-parser.js +1 -419
  318. package/dist/schema/utils/guard-query-utils.js +1 -46
  319. package/dist/schema/utils/node-parser.js +1 -369
  320. package/dist/schema/utils/object-type-utils.js +1 -35
  321. package/dist/schema/utils/permission-index-utils.js +1 -7
  322. package/dist/schema/utils/permission-machine-check.js +1 -121
  323. package/dist/schema/utils/skills-recommendation.js +1 -77
  324. package/dist/schema-query/index.js +1 -810
  325. package/dist/schemas/account_operation.output.json +5 -2
  326. package/dist/schemas/bridge_operation.output.json +5 -2
  327. package/dist/schemas/evaluation_operation.output.json +112 -7
  328. package/dist/schemas/evaluation_operation.schema.json +93 -6
  329. package/dist/schemas/index.json +1 -1
  330. package/dist/schemas/intent_radar.output.json +4 -1
  331. package/dist/schemas/intent_radar.schema.json +4 -1
  332. package/dist/schemas/local_info_operation.output.json +5 -2
  333. package/dist/schemas/local_mark_operation.output.json +5 -2
  334. package/dist/schemas/messenger_operation.output.json +5 -2
  335. package/dist/schemas/onchain_events.output.json +5 -2
  336. package/dist/schemas/onchain_operations.output.json +5 -2
  337. package/dist/schemas/onchain_operations.schema.json +4 -4
  338. package/dist/schemas/onchain_operations_allocation.schema.json +1 -1
  339. package/dist/schemas/onchain_operations_machine.schema.json +2 -2
  340. package/dist/schemas/onchain_operations_service.schema.json +1 -1
  341. package/dist/schemas/onchain_table_data.output.json +6 -3
  342. package/dist/schemas/persona_operation.output.json +4 -1
  343. package/dist/schemas/persona_operation.schema.json +4 -1
  344. package/dist/schemas/project_operation.output.json +28 -8
  345. package/dist/schemas/query_toolkit.output.json +8 -5
  346. package/dist/schemas/wowok_buildin_info.output.json +132 -0
  347. package/dist/schemas/wowok_buildin_info.schema.json +14 -0
  348. package/dist/telemetry/index.js +1 -112
  349. package/dist/telemetry/redact.js +1 -23
  350. package/dist/telemetry/storage.js +1 -80
  351. package/dist/tools/handlers/bridge.js +1 -1
  352. package/dist/tools/handlers/config.js +1 -74
  353. package/dist/tools/handlers/evaluation.js +1 -123
  354. package/dist/tools/handlers/file-export.js +1 -90
  355. package/dist/tools/handlers/intent-radar.js +1 -76
  356. package/dist/tools/handlers/local.js +1 -53
  357. package/dist/tools/handlers/messenger.js +1 -188
  358. package/dist/tools/handlers/onchain.js +1 -1180
  359. package/dist/tools/handlers/persona.js +1 -89
  360. package/dist/tools/handlers/project.js +1 -211
  361. package/dist/tools/handlers/query.js +1 -434
  362. package/dist/tools/handlers/schema-query.js +1 -176
  363. package/dist/tools/handlers/task-status.js +1 -26
  364. package/dist/tools/handlers/trust.js +1 -380
  365. package/dist/tools/handlers/wip.js +1 -90
  366. package/dist/tools/index.js +1 -1382
  367. package/dist/tools/retry.js +1 -85
  368. package/dist/tools/rules-hook.js +1 -23
  369. package/dist/tools/shared.js +1 -130
  370. package/dist/tools/types.js +1 -1
  371. package/dist/tools/upgrade-check.d.ts +19 -0
  372. package/dist/tools/upgrade-check.js +1 -0
  373. package/dist/tools/wip-deploy-assist.js +1 -306
  374. package/dist/tools/wrap.js +1 -500
  375. package/package.json +4 -2
@@ -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');}