@wowok/agent-mcp 2.4.3 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/dist/config/runtime.d.ts +4 -0
  2. package/dist/config/runtime.js +29 -5
  3. package/dist/harness/auto-escalation.d.ts +27 -0
  4. package/dist/harness/auto-escalation.js +68 -0
  5. package/dist/index.js +21 -0
  6. package/dist/knowledge/allocation-confirm.d.ts +115 -0
  7. package/dist/knowledge/allocation-confirm.js +534 -0
  8. package/dist/knowledge/allocation-context.d.ts +58 -0
  9. package/dist/knowledge/allocation-context.js +249 -0
  10. package/dist/knowledge/allocation-ledger.d.ts +67 -0
  11. package/dist/knowledge/allocation-ledger.js +463 -0
  12. package/dist/knowledge/allocation-puzzle.d.ts +135 -0
  13. package/dist/knowledge/allocation-puzzle.js +298 -0
  14. package/dist/knowledge/allocation-risk.d.ts +78 -0
  15. package/dist/knowledge/allocation-risk.js +568 -0
  16. package/dist/knowledge/allocation-templates.d.ts +38 -0
  17. package/dist/knowledge/allocation-templates.js +970 -0
  18. package/dist/knowledge/allocation-translation.d.ts +72 -0
  19. package/dist/knowledge/allocation-translation.js +585 -0
  20. package/dist/knowledge/arb-risk.d.ts +37 -0
  21. package/dist/knowledge/arb-risk.js +210 -0
  22. package/dist/knowledge/arbitration-confirm.d.ts +135 -0
  23. package/dist/knowledge/arbitration-confirm.js +559 -0
  24. package/dist/knowledge/arbitration-context.d.ts +81 -0
  25. package/dist/knowledge/arbitration-context.js +505 -0
  26. package/dist/knowledge/arbitration-ledger.d.ts +62 -0
  27. package/dist/knowledge/arbitration-ledger.js +521 -0
  28. package/dist/knowledge/arbitration-puzzle.d.ts +84 -0
  29. package/dist/knowledge/arbitration-puzzle.js +304 -0
  30. package/dist/knowledge/arbitration-risk.d.ts +112 -0
  31. package/dist/knowledge/arbitration-risk.js +433 -0
  32. package/dist/knowledge/arbitration-templates.d.ts +38 -0
  33. package/dist/knowledge/arbitration-templates.js +276 -0
  34. package/dist/knowledge/arbitration-translation.d.ts +91 -0
  35. package/dist/knowledge/arbitration-translation.js +487 -0
  36. package/dist/knowledge/bridge-risk.d.ts +36 -0
  37. package/dist/knowledge/bridge-risk.js +263 -0
  38. package/dist/knowledge/contact-risk.d.ts +32 -0
  39. package/dist/knowledge/contact-risk.js +200 -0
  40. package/dist/knowledge/demand-confirm.d.ts +32 -0
  41. package/dist/knowledge/demand-confirm.js +206 -0
  42. package/dist/knowledge/demand-risk.d.ts +30 -0
  43. package/dist/knowledge/demand-risk.js +240 -0
  44. package/dist/knowledge/demand-translation.d.ts +55 -0
  45. package/dist/knowledge/demand-translation.js +354 -0
  46. package/dist/knowledge/deployment-scanner.d.ts +63 -0
  47. package/dist/knowledge/deployment-scanner.js +762 -0
  48. package/dist/knowledge/examples-scanner-cli.d.ts +1 -0
  49. package/dist/knowledge/examples-scanner-cli.js +26 -0
  50. package/dist/knowledge/examples-scanner.d.ts +121 -0
  51. package/dist/knowledge/examples-scanner.js +825 -0
  52. package/dist/knowledge/flywheel-loop.d.ts +3 -0
  53. package/dist/knowledge/flywheel-loop.js +32 -3
  54. package/dist/knowledge/glossary.js +3 -1
  55. package/dist/knowledge/guard-confirm.d.ts +86 -0
  56. package/dist/knowledge/guard-confirm.js +406 -0
  57. package/dist/knowledge/guard-context.d.ts +56 -0
  58. package/dist/knowledge/guard-context.js +287 -0
  59. package/dist/knowledge/guard-design-patterns.d.ts +37 -0
  60. package/dist/knowledge/guard-design-patterns.js +257 -0
  61. package/dist/knowledge/guard-puzzle.js +3 -2
  62. package/dist/knowledge/guard-risk.d.ts +1 -1
  63. package/dist/knowledge/guard-risk.js +12 -14
  64. package/dist/knowledge/guard-templates.js +1 -1
  65. package/dist/knowledge/guard-translation.js +6 -5
  66. package/dist/knowledge/index.d.ts +342 -0
  67. package/dist/knowledge/index.js +344 -0
  68. package/dist/knowledge/machine-confirm.d.ts +102 -0
  69. package/dist/knowledge/machine-confirm.js +559 -0
  70. package/dist/knowledge/machine-context.d.ts +160 -0
  71. package/dist/knowledge/machine-context.js +812 -0
  72. package/dist/knowledge/machine-ledger.d.ts +41 -0
  73. package/dist/knowledge/machine-ledger.js +315 -0
  74. package/dist/knowledge/machine-puzzle.d.ts +206 -0
  75. package/dist/knowledge/machine-puzzle.js +494 -0
  76. package/dist/knowledge/machine-risk.d.ts +75 -0
  77. package/dist/knowledge/machine-risk.js +644 -0
  78. package/dist/knowledge/machine-templates.d.ts +92 -0
  79. package/dist/knowledge/machine-templates.js +1592 -0
  80. package/dist/knowledge/machine-topology.d.ts +57 -0
  81. package/dist/knowledge/machine-topology.js +234 -0
  82. package/dist/knowledge/machine-translation.d.ts +96 -0
  83. package/dist/knowledge/machine-translation.js +513 -0
  84. package/dist/knowledge/mcp-schema-audit-cli.d.ts +1 -0
  85. package/dist/knowledge/mcp-schema-audit-cli.js +45 -0
  86. package/dist/knowledge/mcp-schema-audit.d.ts +90 -0
  87. package/dist/knowledge/mcp-schema-audit.js +772 -0
  88. package/dist/knowledge/onchain-constants.d.ts +4 -0
  89. package/dist/knowledge/onchain-constants.js +35 -0
  90. package/dist/knowledge/order-confirm.d.ts +115 -0
  91. package/dist/knowledge/order-confirm.js +573 -0
  92. package/dist/knowledge/order-context.d.ts +66 -0
  93. package/dist/knowledge/order-context.js +390 -0
  94. package/dist/knowledge/order-ledger.d.ts +69 -0
  95. package/dist/knowledge/order-ledger.js +341 -0
  96. package/dist/knowledge/order-puzzle.d.ts +159 -0
  97. package/dist/knowledge/order-puzzle.js +255 -0
  98. package/dist/knowledge/order-risk.d.ts +66 -0
  99. package/dist/knowledge/order-risk.js +653 -0
  100. package/dist/knowledge/order-templates.d.ts +50 -0
  101. package/dist/knowledge/order-templates.js +368 -0
  102. package/dist/knowledge/order-translation.d.ts +78 -0
  103. package/dist/knowledge/order-translation.js +550 -0
  104. package/dist/knowledge/passport-confirm.d.ts +130 -0
  105. package/dist/knowledge/passport-confirm.js +531 -0
  106. package/dist/knowledge/passport-context.d.ts +59 -0
  107. package/dist/knowledge/passport-context.js +306 -0
  108. package/dist/knowledge/passport-ledger.d.ts +48 -0
  109. package/dist/knowledge/passport-ledger.js +282 -0
  110. package/dist/knowledge/passport-puzzle.d.ts +108 -0
  111. package/dist/knowledge/passport-puzzle.js +333 -0
  112. package/dist/knowledge/passport-risk.d.ts +70 -0
  113. package/dist/knowledge/passport-risk.js +450 -0
  114. package/dist/knowledge/passport-templates.d.ts +40 -0
  115. package/dist/knowledge/passport-templates.js +568 -0
  116. package/dist/knowledge/passport-translation.d.ts +68 -0
  117. package/dist/knowledge/passport-translation.js +516 -0
  118. package/dist/knowledge/payment-risk.d.ts +33 -0
  119. package/dist/knowledge/payment-risk.js +182 -0
  120. package/dist/knowledge/permission-confirm.d.ts +110 -0
  121. package/dist/knowledge/permission-confirm.js +426 -0
  122. package/dist/knowledge/permission-context.d.ts +58 -0
  123. package/dist/knowledge/permission-context.js +224 -0
  124. package/dist/knowledge/permission-ledger.d.ts +38 -0
  125. package/dist/knowledge/permission-ledger.js +403 -0
  126. package/dist/knowledge/permission-puzzle.d.ts +122 -0
  127. package/dist/knowledge/permission-puzzle.js +173 -0
  128. package/dist/knowledge/permission-risk.d.ts +76 -0
  129. package/dist/knowledge/permission-risk.js +411 -0
  130. package/dist/knowledge/permission-templates.d.ts +38 -0
  131. package/dist/knowledge/permission-templates.js +234 -0
  132. package/dist/knowledge/permission-translation.d.ts +57 -0
  133. package/dist/knowledge/permission-translation.js +350 -0
  134. package/dist/knowledge/personal-risk.d.ts +36 -0
  135. package/dist/knowledge/personal-risk.js +212 -0
  136. package/dist/knowledge/progress-confirm.d.ts +108 -0
  137. package/dist/knowledge/progress-confirm.js +456 -0
  138. package/dist/knowledge/progress-context.d.ts +123 -0
  139. package/dist/knowledge/progress-context.js +452 -0
  140. package/dist/knowledge/progress-ledger.d.ts +63 -0
  141. package/dist/knowledge/progress-ledger.js +327 -0
  142. package/dist/knowledge/progress-puzzle.d.ts +82 -0
  143. package/dist/knowledge/progress-puzzle.js +219 -0
  144. package/dist/knowledge/progress-risk.d.ts +74 -0
  145. package/dist/knowledge/progress-risk.js +461 -0
  146. package/dist/knowledge/progress-templates.d.ts +38 -0
  147. package/dist/knowledge/progress-templates.js +228 -0
  148. package/dist/knowledge/progress-translation.d.ts +52 -0
  149. package/dist/knowledge/progress-translation.js +401 -0
  150. package/dist/knowledge/proof-confirm.d.ts +31 -0
  151. package/dist/knowledge/proof-confirm.js +187 -0
  152. package/dist/knowledge/proof-risk.d.ts +33 -0
  153. package/dist/knowledge/proof-risk.js +207 -0
  154. package/dist/knowledge/proof-translation.d.ts +52 -0
  155. package/dist/knowledge/proof-translation.js +283 -0
  156. package/dist/knowledge/registrar-risk.d.ts +34 -0
  157. package/dist/knowledge/registrar-risk.js +217 -0
  158. package/dist/knowledge/repository-confirm.d.ts +36 -0
  159. package/dist/knowledge/repository-confirm.js +242 -0
  160. package/dist/knowledge/repository-risk.d.ts +40 -0
  161. package/dist/knowledge/repository-risk.js +312 -0
  162. package/dist/knowledge/repository-translation.d.ts +58 -0
  163. package/dist/knowledge/repository-translation.js +422 -0
  164. package/dist/knowledge/resource-risk.d.ts +32 -0
  165. package/dist/knowledge/resource-risk.js +157 -0
  166. package/dist/knowledge/reward-confirm.d.ts +113 -0
  167. package/dist/knowledge/reward-confirm.js +496 -0
  168. package/dist/knowledge/reward-context.d.ts +127 -0
  169. package/dist/knowledge/reward-context.js +504 -0
  170. package/dist/knowledge/reward-ledger.d.ts +96 -0
  171. package/dist/knowledge/reward-ledger.js +502 -0
  172. package/dist/knowledge/reward-puzzle.d.ts +97 -0
  173. package/dist/knowledge/reward-puzzle.js +288 -0
  174. package/dist/knowledge/reward-risk.d.ts +84 -0
  175. package/dist/knowledge/reward-risk.js +545 -0
  176. package/dist/knowledge/reward-translation.d.ts +58 -0
  177. package/dist/knowledge/reward-translation.js +501 -0
  178. package/dist/knowledge/safety-rules.js +11 -3
  179. package/dist/knowledge/scenario-modes.d.ts +53 -0
  180. package/dist/knowledge/scenario-modes.js +302 -0
  181. package/dist/knowledge/service-confirm.d.ts +152 -0
  182. package/dist/knowledge/service-confirm.js +699 -0
  183. package/dist/knowledge/service-context.d.ts +66 -0
  184. package/dist/knowledge/service-context.js +403 -0
  185. package/dist/knowledge/service-ledger.d.ts +71 -0
  186. package/dist/knowledge/service-ledger.js +609 -0
  187. package/dist/knowledge/service-puzzle.d.ts +158 -0
  188. package/dist/knowledge/service-puzzle.js +236 -0
  189. package/dist/knowledge/service-risk.d.ts +108 -0
  190. package/dist/knowledge/service-risk.js +615 -0
  191. package/dist/knowledge/service-templates.d.ts +39 -0
  192. package/dist/knowledge/service-templates.js +418 -0
  193. package/dist/knowledge/service-translation.d.ts +103 -0
  194. package/dist/knowledge/service-translation.js +622 -0
  195. package/dist/knowledge/tools-reference.d.ts +17 -0
  196. package/dist/knowledge/tools-reference.js +151 -0
  197. package/dist/knowledge/treasury-confirm.d.ts +133 -0
  198. package/dist/knowledge/treasury-confirm.js +512 -0
  199. package/dist/knowledge/treasury-context.d.ts +64 -0
  200. package/dist/knowledge/treasury-context.js +363 -0
  201. package/dist/knowledge/treasury-ledger.d.ts +42 -0
  202. package/dist/knowledge/treasury-ledger.js +300 -0
  203. package/dist/knowledge/treasury-puzzle.d.ts +163 -0
  204. package/dist/knowledge/treasury-puzzle.js +216 -0
  205. package/dist/knowledge/treasury-risk.d.ts +86 -0
  206. package/dist/knowledge/treasury-risk.js +440 -0
  207. package/dist/knowledge/treasury-templates.d.ts +38 -0
  208. package/dist/knowledge/treasury-templates.js +316 -0
  209. package/dist/knowledge/treasury-translation.d.ts +78 -0
  210. package/dist/knowledge/treasury-translation.js +498 -0
  211. package/dist/knowledge/util-risk.d.ts +30 -0
  212. package/dist/knowledge/util-risk.js +135 -0
  213. package/dist/project/business-puzzle.d.ts +47 -0
  214. package/dist/project/business-puzzle.js +372 -0
  215. package/dist/project/deployment-doc.d.ts +61 -0
  216. package/dist/project/deployment-doc.js +432 -0
  217. package/dist/project/risk-aggregator.d.ts +50 -0
  218. package/dist/project/risk-aggregator.js +280 -0
  219. package/dist/project/substep-trace.d.ts +130 -0
  220. package/dist/project/substep-trace.js +332 -0
  221. package/dist/schema/call/allocation.d.ts +34 -34
  222. package/dist/schema/call/arbitration.d.ts +141 -141
  223. package/dist/schema/call/base.d.ts +386 -386
  224. package/dist/schema/call/base.js +3 -3
  225. package/dist/schema/call/bridge-handler.d.ts +5 -2
  226. package/dist/schema/call/bridge.d.ts +159 -159
  227. package/dist/schema/call/contact.d.ts +110 -110
  228. package/dist/schema/call/demand.d.ts +76 -76
  229. package/dist/schema/call/handler.d.ts +2 -3
  230. package/dist/schema/call/handler.js +1 -1
  231. package/dist/schema/call/machine.d.ts +58 -58
  232. package/dist/schema/call/order.d.ts +98 -110
  233. package/dist/schema/call/permission-handler.d.ts +5 -0
  234. package/dist/schema/call/permission-handler.js +54 -0
  235. package/dist/schema/call/permission.d.ts +108 -108
  236. package/dist/schema/call/personal.d.ts +14 -14
  237. package/dist/schema/call/progress.d.ts +57 -72
  238. package/dist/schema/call/progress.js +7 -4
  239. package/dist/schema/call/proof.d.ts +18 -18
  240. package/dist/schema/call/proof.js +12 -7
  241. package/dist/schema/call/repository.d.ts +154 -154
  242. package/dist/schema/call/reward.d.ts +55 -55
  243. package/dist/schema/call/service.d.ts +231 -231
  244. package/dist/schema/call/treasury.d.ts +93 -93
  245. package/dist/schema/config/index.d.ts +178 -5
  246. package/dist/schema/config/index.js +52 -1
  247. package/dist/schema/local/index.d.ts +3554 -836
  248. package/dist/schema/local/index.js +2 -1
  249. package/dist/schema/messenger/index.d.ts +162 -162
  250. package/dist/schema/operations.d.ts +1058 -1074
  251. package/dist/schema/operations.js +7 -1
  252. package/dist/schema/project/index.d.ts +1412 -6
  253. package/dist/schema/project/index.js +441 -3
  254. package/dist/schema/query/index.d.ts +672 -672
  255. package/dist/schema/schema-query/index.d.ts +23 -3
  256. package/dist/schema/schema-query/index.js +13 -2
  257. package/dist/schema/sync-layer4.d.ts +21 -0
  258. package/dist/schema/sync-layer4.js +261 -0
  259. package/dist/schema/trust/index.d.ts +26 -26
  260. package/dist/schemas/account_operation.output.json +718 -0
  261. package/dist/schemas/config_operation.output.json +173 -0
  262. package/dist/schemas/index.json +9 -1
  263. package/dist/schemas/local_info_operation.output.json +718 -0
  264. package/dist/schemas/local_mark_operation.output.json +718 -0
  265. package/dist/schemas/onchain_operations.output.json +3 -2
  266. package/dist/schemas/onchain_operations.schema.json +1809 -336
  267. package/dist/schemas/onchain_operations_allocation.schema.json +2 -1
  268. package/dist/schemas/onchain_operations_arbitration.schema.json +2 -1
  269. package/dist/schemas/onchain_operations_contact.schema.json +2 -1
  270. package/dist/schemas/onchain_operations_demand.schema.json +2 -1
  271. package/dist/schemas/onchain_operations_gen_passport.schema.json +878 -872
  272. package/dist/schemas/onchain_operations_gen_proof.schema.json +273 -0
  273. package/dist/schemas/onchain_operations_guard.schema.json +578 -579
  274. package/dist/schemas/onchain_operations_machine.schema.json +2 -1
  275. package/dist/schemas/onchain_operations_order.schema.json +13 -9
  276. package/dist/schemas/onchain_operations_payment.schema.json +0 -514
  277. package/dist/schemas/onchain_operations_permission.schema.json +0 -514
  278. package/dist/schemas/onchain_operations_personal.schema.json +0 -514
  279. package/dist/schemas/onchain_operations_progress.schema.json +14 -10
  280. package/dist/schemas/onchain_operations_proof.schema.json +699 -0
  281. package/dist/schemas/onchain_operations_repository.schema.json +2 -1
  282. package/dist/schemas/onchain_operations_reward.schema.json +2 -1
  283. package/dist/schemas/onchain_operations_service.schema.json +2 -1
  284. package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
  285. package/dist/schemas/onchain_table_data.schema.json +32 -1
  286. package/dist/schemas/project_operation.output.json +918 -0
  287. package/dist/schemas/project_operation.schema.json +474 -3
  288. package/dist/schemas/query_toolkit.output.json +14906 -6
  289. package/dist/schemas/schema_query.output.json +38 -1
  290. package/dist/telemetry/index.d.ts +1 -1
  291. package/dist/tools/handlers/config.d.ts +1 -1
  292. package/dist/tools/handlers/config.js +21 -18
  293. package/dist/tools/handlers/file-export.d.ts +2 -2
  294. package/dist/tools/handlers/local.d.ts +3 -30
  295. package/dist/tools/handlers/local.js +14 -3
  296. package/dist/tools/handlers/messenger.d.ts +1 -1
  297. package/dist/tools/handlers/messenger.js +2 -1
  298. package/dist/tools/handlers/onchain.d.ts +1 -1
  299. package/dist/tools/handlers/onchain.js +24 -22
  300. package/dist/tools/handlers/project.d.ts +1 -1
  301. package/dist/tools/handlers/project.js +262 -18
  302. package/dist/tools/handlers/query.d.ts +4 -4
  303. package/dist/tools/handlers/schema-query.d.ts +1 -1
  304. package/dist/tools/handlers/schema-query.js +21 -20
  305. package/dist/tools/handlers/trust.d.ts +1 -1
  306. package/dist/tools/handlers/trust.js +2 -2
  307. package/dist/tools/handlers/wip.d.ts +1 -1
  308. package/dist/tools/handlers/wip.js +1 -1
  309. package/dist/tools/index.d.ts +1 -1
  310. package/dist/tools/index.js +96 -25
  311. package/dist/tools/rules-hook.d.ts +1 -1
  312. package/dist/tools/rules-hook.js +3 -2
  313. package/dist/tools/shared.d.ts +13 -22
  314. package/dist/tools/types.d.ts +5 -5
  315. package/dist/tools/wrap.d.ts +10 -2
  316. package/dist/tools/wrap.js +212 -0
  317. package/package.json +3 -3
@@ -0,0 +1,332 @@
1
+ function buildEdgesFromInputRefs(substeps) {
2
+ const edges = [];
3
+ for (const substep of substeps) {
4
+ for (const ref of substep.dependencies.input_refs) {
5
+ const field_path = substep.dependencies.output_refs
6
+ .find((r) => r.substep_id === ref)?.field_path ?? "input_ref";
7
+ edges.push({ source: ref, target: substep.step_id, field_path });
8
+ }
9
+ }
10
+ return edges;
11
+ }
12
+ function groupByParentStep(substeps) {
13
+ const groups = new Map();
14
+ for (const s of substeps) {
15
+ if (!groups.has(s.parent_step))
16
+ groups.set(s.parent_step, []);
17
+ groups.get(s.parent_step).push(s);
18
+ }
19
+ return groups;
20
+ }
21
+ function buildStepDetails(substeps) {
22
+ const groups = groupByParentStep(substeps);
23
+ const details = [];
24
+ for (const [parent_step, group] of groups.entries()) {
25
+ let successful = 0, failed = 0, pending = 0, skipped = 0;
26
+ const substep_ids = [];
27
+ for (const s of group) {
28
+ substep_ids.push(s.step_id);
29
+ switch (s.status) {
30
+ case "SUCCESS":
31
+ successful++;
32
+ break;
33
+ case "FAILED":
34
+ failed++;
35
+ break;
36
+ case "PENDING":
37
+ pending++;
38
+ break;
39
+ case "SKIPPED":
40
+ skipped++;
41
+ break;
42
+ }
43
+ }
44
+ details.push({
45
+ parent_step,
46
+ total_substeps: group.length,
47
+ successful,
48
+ failed,
49
+ pending,
50
+ skipped,
51
+ substep_ids,
52
+ });
53
+ }
54
+ details.sort((a, b) => {
55
+ const na = parseInt(a.parent_step.replace(/^T/, ""), 10) || 0;
56
+ const nb = parseInt(b.parent_step.replace(/^T/, ""), 10) || 0;
57
+ return na - nb;
58
+ });
59
+ return details;
60
+ }
61
+ export function detectDanglingInputs(substeps, edges) {
62
+ if (!substeps || substeps.length === 0)
63
+ return [];
64
+ const substep_ids = new Set(substeps.map((s) => s.step_id));
65
+ const dangling = [];
66
+ for (const substep of substeps) {
67
+ for (const ref of substep.dependencies.input_refs) {
68
+ if (!substep_ids.has(ref)) {
69
+ const field_path = substep.dependencies.output_refs.find((r) => r.substep_id === ref)?.field_path ??
70
+ edges?.find((e) => e.source === ref && e.target === substep.step_id)?.field_path ??
71
+ "input_ref";
72
+ dangling.push({
73
+ substep_id: substep.step_id,
74
+ missing_ref: ref,
75
+ field_path,
76
+ });
77
+ }
78
+ }
79
+ }
80
+ return dangling;
81
+ }
82
+ export function detectCircularRefs(substeps, edges) {
83
+ if (!substeps || substeps.length === 0)
84
+ return [];
85
+ if (!edges || edges.length === 0)
86
+ return [];
87
+ const cycles = [];
88
+ const visited = new Set();
89
+ const recursion_stack = new Set();
90
+ const path = [];
91
+ const adjacency = new Map();
92
+ for (const s of substeps)
93
+ adjacency.set(s.step_id, []);
94
+ for (const edge of edges) {
95
+ if (!adjacency.has(edge.source))
96
+ adjacency.set(edge.source, []);
97
+ adjacency.get(edge.source).push(edge.target);
98
+ }
99
+ const dfs = (node) => {
100
+ if (recursion_stack.has(node)) {
101
+ const cycle_start = path.indexOf(node);
102
+ if (cycle_start >= 0) {
103
+ cycles.push({ cycle: [...path.slice(cycle_start), node] });
104
+ }
105
+ return;
106
+ }
107
+ if (visited.has(node))
108
+ return;
109
+ visited.add(node);
110
+ recursion_stack.add(node);
111
+ path.push(node);
112
+ const neighbors = adjacency.get(node) ?? [];
113
+ for (const next of neighbors) {
114
+ dfs(next);
115
+ }
116
+ path.pop();
117
+ recursion_stack.delete(node);
118
+ };
119
+ for (const s of substeps) {
120
+ if (!visited.has(s.step_id)) {
121
+ dfs(s.step_id);
122
+ }
123
+ }
124
+ return cycles;
125
+ }
126
+ export function detectMissingOutputs(substeps) {
127
+ if (!substeps || substeps.length === 0)
128
+ return [];
129
+ const missing = [];
130
+ for (const substep of substeps) {
131
+ for (const dep of substep.dependencies.output_refs) {
132
+ const field_path = dep.field_path;
133
+ const has_field = !!substep.output &&
134
+ typeof substep.output === "object" &&
135
+ field_path in substep.output;
136
+ if (!has_field) {
137
+ missing.push({
138
+ substep_id: substep.step_id,
139
+ expected_field: field_path,
140
+ dependent_substeps: [dep.substep_id],
141
+ });
142
+ }
143
+ }
144
+ }
145
+ return missing;
146
+ }
147
+ export function detectCrossStepBreaks(substeps, edges) {
148
+ if (!substeps || substeps.length === 0 || !edges || edges.length === 0)
149
+ return [];
150
+ const breaks = [];
151
+ const id_to_step = new Map();
152
+ for (const s of substeps)
153
+ id_to_step.set(s.step_id, s.parent_step);
154
+ const step_groups = groupByParentStep(substeps);
155
+ const failed_steps = new Set();
156
+ for (const [parent_step, group] of step_groups.entries()) {
157
+ if (group.some((s) => s.status === "FAILED")) {
158
+ failed_steps.add(parent_step);
159
+ }
160
+ }
161
+ const seen = new Set();
162
+ for (const edge of edges) {
163
+ const source_step = id_to_step.get(edge.source);
164
+ const target_step = id_to_step.get(edge.target);
165
+ if (!source_step || !target_step)
166
+ continue;
167
+ if (source_step === target_step)
168
+ continue;
169
+ if (!failed_steps.has(source_step))
170
+ continue;
171
+ const key = `${source_step}|${target_step}|${edge.field_path}`;
172
+ if (seen.has(key))
173
+ continue;
174
+ seen.add(key);
175
+ breaks.push({
176
+ source_step,
177
+ target_step,
178
+ missing_field: edge.field_path,
179
+ });
180
+ }
181
+ return breaks;
182
+ }
183
+ function topologicalSort(substeps, edges) {
184
+ if (!substeps || substeps.length === 0)
185
+ return [];
186
+ const in_degree = new Map();
187
+ const adjacency = new Map();
188
+ for (const s of substeps) {
189
+ in_degree.set(s.step_id, 0);
190
+ adjacency.set(s.step_id, []);
191
+ }
192
+ for (const edge of edges) {
193
+ if (!adjacency.has(edge.source))
194
+ adjacency.set(edge.source, []);
195
+ if (!in_degree.has(edge.target))
196
+ in_degree.set(edge.target, 0);
197
+ adjacency.get(edge.source).push(edge.target);
198
+ in_degree.set(edge.target, (in_degree.get(edge.target) ?? 0) + 1);
199
+ }
200
+ const queue = [];
201
+ for (const s of substeps) {
202
+ if ((in_degree.get(s.step_id) ?? 0) === 0)
203
+ queue.push(s.step_id);
204
+ }
205
+ const order = [];
206
+ while (queue.length > 0) {
207
+ const node = queue.shift();
208
+ order.push(node);
209
+ const neighbors = adjacency.get(node) ?? [];
210
+ for (const next of neighbors) {
211
+ const d = (in_degree.get(next) ?? 0) - 1;
212
+ in_degree.set(next, d);
213
+ if (d === 0)
214
+ queue.push(next);
215
+ }
216
+ }
217
+ if (order.length !== substeps.length)
218
+ return [];
219
+ return order;
220
+ }
221
+ function buildD10Check(dangling, circular, missing, breaks) {
222
+ const notes = [];
223
+ if (dangling.length > 0) {
224
+ notes.push(`${dangling.length} dangling input(s) detected`);
225
+ }
226
+ if (circular.length > 0) {
227
+ notes.push(`${circular.length} circular reference(s) detected`);
228
+ }
229
+ if (missing.length > 0) {
230
+ notes.push(`${missing.length} missing output(s) detected`);
231
+ }
232
+ if (breaks.length > 0) {
233
+ notes.push(`${breaks.length} cross-step break(s) detected`);
234
+ }
235
+ let status;
236
+ if (dangling.length === 0 && circular.length === 0 && breaks.length === 0 && missing.length === 0) {
237
+ status = "PASS";
238
+ }
239
+ else if (circular.length > 0 || dangling.length > 0 || breaks.length > 0) {
240
+ status = "FAIL";
241
+ }
242
+ else {
243
+ status = "WARN";
244
+ }
245
+ return {
246
+ check_id: "D-10",
247
+ description: "Substep coherence (dangling inputs, circular refs, missing outputs, cross-step breaks)",
248
+ status,
249
+ notes: notes.length > 0 ? notes : ["All substep coherence checks passed"],
250
+ };
251
+ }
252
+ export function traceSubsteps(input) {
253
+ const substeps = input.substeps ?? [];
254
+ const edges = input.edges ?? buildEdgesFromInputRefs(substeps);
255
+ const dangling_inputs = detectDanglingInputs(substeps, edges);
256
+ const circular_refs = detectCircularRefs(substeps, edges);
257
+ const missing_outputs = detectMissingOutputs(substeps);
258
+ const cross_step_breaks = detectCrossStepBreaks(substeps, edges);
259
+ const coherent = dangling_inputs.length === 0 &&
260
+ circular_refs.length === 0 &&
261
+ missing_outputs.length === 0 &&
262
+ cross_step_breaks.length === 0;
263
+ const topological_order = topologicalSort(substeps, edges);
264
+ const step_details = buildStepDetails(substeps);
265
+ const d10_check = buildD10Check(dangling_inputs, circular_refs, missing_outputs, cross_step_breaks);
266
+ return {
267
+ namespace: { prefix: input.project_prefix, version: input.version },
268
+ network: input.network,
269
+ coherent,
270
+ dangling_inputs,
271
+ circular_refs,
272
+ missing_outputs,
273
+ cross_step_breaks,
274
+ step_details,
275
+ topological_order,
276
+ d10_check,
277
+ };
278
+ }
279
+ export class SubstepTracer {
280
+ records = new Map();
281
+ namespace;
282
+ network;
283
+ constructor(prefix, version, network) {
284
+ this.namespace = { prefix, version };
285
+ this.network = network;
286
+ }
287
+ record(rec) {
288
+ if (!rec || !rec.step_id)
289
+ return;
290
+ this.records.set(rec.step_id, rec);
291
+ }
292
+ getTrace() {
293
+ return Array.from(this.records.values()).filter((s) => s.network === this.network);
294
+ }
295
+ updateStatus(step_id, status, output, failure_reason) {
296
+ const rec = this.records.get(step_id);
297
+ if (!rec)
298
+ return;
299
+ rec.status = status;
300
+ if (output)
301
+ rec.output = { ...(rec.output ?? {}), ...output };
302
+ if (failure_reason)
303
+ rec.failure_reason = failure_reason;
304
+ rec.timestamp = Date.now();
305
+ }
306
+ getDAG() {
307
+ const substeps = this.getTrace();
308
+ const edges = buildEdgesFromInputRefs(substeps);
309
+ return {
310
+ namespace: this.namespace,
311
+ network: this.network,
312
+ substeps,
313
+ edges,
314
+ topological_order: topologicalSort(substeps, edges),
315
+ };
316
+ }
317
+ checkCoherence() {
318
+ return traceSubsteps({
319
+ project_prefix: this.namespace.prefix,
320
+ version: this.namespace.version,
321
+ network: this.network,
322
+ substeps: this.getTrace(),
323
+ });
324
+ }
325
+ toJSON() {
326
+ return {
327
+ namespace: this.namespace,
328
+ network: this.network,
329
+ substeps: this.getTrace(),
330
+ };
331
+ }
332
+ }