@wowok/agent-mcp 2.4.1 → 2.5.0

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 (348) 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.d.ts +2 -2
  6. package/dist/index.js +29 -1621
  7. package/dist/knowledge/allocation-confirm.d.ts +115 -0
  8. package/dist/knowledge/allocation-confirm.js +534 -0
  9. package/dist/knowledge/allocation-context.d.ts +58 -0
  10. package/dist/knowledge/allocation-context.js +249 -0
  11. package/dist/knowledge/allocation-ledger.d.ts +67 -0
  12. package/dist/knowledge/allocation-ledger.js +463 -0
  13. package/dist/knowledge/allocation-puzzle.d.ts +135 -0
  14. package/dist/knowledge/allocation-puzzle.js +298 -0
  15. package/dist/knowledge/allocation-risk.d.ts +78 -0
  16. package/dist/knowledge/allocation-risk.js +568 -0
  17. package/dist/knowledge/allocation-templates.d.ts +38 -0
  18. package/dist/knowledge/allocation-templates.js +970 -0
  19. package/dist/knowledge/allocation-translation.d.ts +72 -0
  20. package/dist/knowledge/allocation-translation.js +585 -0
  21. package/dist/knowledge/arb-risk.d.ts +37 -0
  22. package/dist/knowledge/arb-risk.js +210 -0
  23. package/dist/knowledge/arbitration-confirm.d.ts +135 -0
  24. package/dist/knowledge/arbitration-confirm.js +559 -0
  25. package/dist/knowledge/arbitration-context.d.ts +81 -0
  26. package/dist/knowledge/arbitration-context.js +505 -0
  27. package/dist/knowledge/arbitration-ledger.d.ts +62 -0
  28. package/dist/knowledge/arbitration-ledger.js +521 -0
  29. package/dist/knowledge/arbitration-puzzle.d.ts +84 -0
  30. package/dist/knowledge/arbitration-puzzle.js +304 -0
  31. package/dist/knowledge/arbitration-risk.d.ts +112 -0
  32. package/dist/knowledge/arbitration-risk.js +433 -0
  33. package/dist/knowledge/arbitration-templates.d.ts +38 -0
  34. package/dist/knowledge/arbitration-templates.js +276 -0
  35. package/dist/knowledge/arbitration-translation.d.ts +91 -0
  36. package/dist/knowledge/arbitration-translation.js +487 -0
  37. package/dist/knowledge/bridge-risk.d.ts +36 -0
  38. package/dist/knowledge/bridge-risk.js +263 -0
  39. package/dist/knowledge/contact-risk.d.ts +32 -0
  40. package/dist/knowledge/contact-risk.js +200 -0
  41. package/dist/knowledge/demand-confirm.d.ts +32 -0
  42. package/dist/knowledge/demand-confirm.js +206 -0
  43. package/dist/knowledge/demand-risk.d.ts +30 -0
  44. package/dist/knowledge/demand-risk.js +240 -0
  45. package/dist/knowledge/demand-translation.d.ts +55 -0
  46. package/dist/knowledge/demand-translation.js +354 -0
  47. package/dist/knowledge/deployment-scanner.d.ts +63 -0
  48. package/dist/knowledge/deployment-scanner.js +762 -0
  49. package/dist/knowledge/examples-scanner-cli.d.ts +1 -0
  50. package/dist/knowledge/examples-scanner-cli.js +26 -0
  51. package/dist/knowledge/examples-scanner.d.ts +121 -0
  52. package/dist/knowledge/examples-scanner.js +825 -0
  53. package/dist/knowledge/flywheel-loop.d.ts +3 -0
  54. package/dist/knowledge/flywheel-loop.js +32 -3
  55. package/dist/knowledge/glossary.js +3 -1
  56. package/dist/knowledge/guard-confirm.d.ts +86 -0
  57. package/dist/knowledge/guard-confirm.js +406 -0
  58. package/dist/knowledge/guard-context.d.ts +56 -0
  59. package/dist/knowledge/guard-context.js +287 -0
  60. package/dist/knowledge/guard-design-patterns.d.ts +37 -0
  61. package/dist/knowledge/guard-design-patterns.js +257 -0
  62. package/dist/knowledge/guard-ledger.js +14 -0
  63. package/dist/knowledge/guard-lint.d.ts +1 -0
  64. package/dist/knowledge/guard-lint.js +83 -3
  65. package/dist/knowledge/guard-migration.d.ts +48 -0
  66. package/dist/knowledge/guard-migration.js +228 -0
  67. package/dist/knowledge/guard-puzzle.js +3 -2
  68. package/dist/knowledge/guard-risk.d.ts +3 -1
  69. package/dist/knowledge/guard-risk.js +832 -64
  70. package/dist/knowledge/guard-templates.d.ts +1 -0
  71. package/dist/knowledge/guard-templates.js +278 -2
  72. package/dist/knowledge/guard-translation.js +6 -5
  73. package/dist/knowledge/index.d.ts +342 -0
  74. package/dist/knowledge/index.js +344 -0
  75. package/dist/knowledge/machine-confirm.d.ts +102 -0
  76. package/dist/knowledge/machine-confirm.js +559 -0
  77. package/dist/knowledge/machine-context.d.ts +160 -0
  78. package/dist/knowledge/machine-context.js +812 -0
  79. package/dist/knowledge/machine-ledger.d.ts +41 -0
  80. package/dist/knowledge/machine-ledger.js +315 -0
  81. package/dist/knowledge/machine-puzzle.d.ts +206 -0
  82. package/dist/knowledge/machine-puzzle.js +494 -0
  83. package/dist/knowledge/machine-risk.d.ts +75 -0
  84. package/dist/knowledge/machine-risk.js +644 -0
  85. package/dist/knowledge/machine-templates.d.ts +92 -0
  86. package/dist/knowledge/machine-templates.js +1592 -0
  87. package/dist/knowledge/machine-topology.d.ts +57 -0
  88. package/dist/knowledge/machine-topology.js +234 -0
  89. package/dist/knowledge/machine-translation.d.ts +96 -0
  90. package/dist/knowledge/machine-translation.js +513 -0
  91. package/dist/knowledge/mcp-schema-audit-cli.d.ts +1 -0
  92. package/dist/knowledge/mcp-schema-audit-cli.js +45 -0
  93. package/dist/knowledge/mcp-schema-audit.d.ts +90 -0
  94. package/dist/knowledge/mcp-schema-audit.js +772 -0
  95. package/dist/knowledge/onchain-constants.d.ts +4 -0
  96. package/dist/knowledge/onchain-constants.js +35 -0
  97. package/dist/knowledge/order-confirm.d.ts +115 -0
  98. package/dist/knowledge/order-confirm.js +573 -0
  99. package/dist/knowledge/order-context.d.ts +66 -0
  100. package/dist/knowledge/order-context.js +390 -0
  101. package/dist/knowledge/order-ledger.d.ts +69 -0
  102. package/dist/knowledge/order-ledger.js +341 -0
  103. package/dist/knowledge/order-puzzle.d.ts +159 -0
  104. package/dist/knowledge/order-puzzle.js +255 -0
  105. package/dist/knowledge/order-risk.d.ts +66 -0
  106. package/dist/knowledge/order-risk.js +653 -0
  107. package/dist/knowledge/order-templates.d.ts +50 -0
  108. package/dist/knowledge/order-templates.js +368 -0
  109. package/dist/knowledge/order-translation.d.ts +78 -0
  110. package/dist/knowledge/order-translation.js +550 -0
  111. package/dist/knowledge/passport-confirm.d.ts +130 -0
  112. package/dist/knowledge/passport-confirm.js +531 -0
  113. package/dist/knowledge/passport-context.d.ts +59 -0
  114. package/dist/knowledge/passport-context.js +306 -0
  115. package/dist/knowledge/passport-ledger.d.ts +48 -0
  116. package/dist/knowledge/passport-ledger.js +282 -0
  117. package/dist/knowledge/passport-puzzle.d.ts +108 -0
  118. package/dist/knowledge/passport-puzzle.js +333 -0
  119. package/dist/knowledge/passport-risk.d.ts +70 -0
  120. package/dist/knowledge/passport-risk.js +450 -0
  121. package/dist/knowledge/passport-templates.d.ts +40 -0
  122. package/dist/knowledge/passport-templates.js +568 -0
  123. package/dist/knowledge/passport-translation.d.ts +68 -0
  124. package/dist/knowledge/passport-translation.js +516 -0
  125. package/dist/knowledge/payment-risk.d.ts +33 -0
  126. package/dist/knowledge/payment-risk.js +182 -0
  127. package/dist/knowledge/permission-confirm.d.ts +110 -0
  128. package/dist/knowledge/permission-confirm.js +426 -0
  129. package/dist/knowledge/permission-context.d.ts +58 -0
  130. package/dist/knowledge/permission-context.js +224 -0
  131. package/dist/knowledge/permission-ledger.d.ts +38 -0
  132. package/dist/knowledge/permission-ledger.js +403 -0
  133. package/dist/knowledge/permission-puzzle.d.ts +122 -0
  134. package/dist/knowledge/permission-puzzle.js +173 -0
  135. package/dist/knowledge/permission-risk.d.ts +76 -0
  136. package/dist/knowledge/permission-risk.js +411 -0
  137. package/dist/knowledge/permission-templates.d.ts +38 -0
  138. package/dist/knowledge/permission-templates.js +234 -0
  139. package/dist/knowledge/permission-translation.d.ts +57 -0
  140. package/dist/knowledge/permission-translation.js +350 -0
  141. package/dist/knowledge/personal-risk.d.ts +36 -0
  142. package/dist/knowledge/personal-risk.js +212 -0
  143. package/dist/knowledge/progress-confirm.d.ts +108 -0
  144. package/dist/knowledge/progress-confirm.js +456 -0
  145. package/dist/knowledge/progress-context.d.ts +123 -0
  146. package/dist/knowledge/progress-context.js +452 -0
  147. package/dist/knowledge/progress-ledger.d.ts +63 -0
  148. package/dist/knowledge/progress-ledger.js +327 -0
  149. package/dist/knowledge/progress-puzzle.d.ts +82 -0
  150. package/dist/knowledge/progress-puzzle.js +219 -0
  151. package/dist/knowledge/progress-risk.d.ts +74 -0
  152. package/dist/knowledge/progress-risk.js +461 -0
  153. package/dist/knowledge/progress-templates.d.ts +38 -0
  154. package/dist/knowledge/progress-templates.js +228 -0
  155. package/dist/knowledge/progress-translation.d.ts +52 -0
  156. package/dist/knowledge/progress-translation.js +401 -0
  157. package/dist/knowledge/proof-confirm.d.ts +31 -0
  158. package/dist/knowledge/proof-confirm.js +187 -0
  159. package/dist/knowledge/proof-risk.d.ts +33 -0
  160. package/dist/knowledge/proof-risk.js +207 -0
  161. package/dist/knowledge/proof-translation.d.ts +52 -0
  162. package/dist/knowledge/proof-translation.js +283 -0
  163. package/dist/knowledge/registrar-risk.d.ts +34 -0
  164. package/dist/knowledge/registrar-risk.js +217 -0
  165. package/dist/knowledge/repository-confirm.d.ts +36 -0
  166. package/dist/knowledge/repository-confirm.js +242 -0
  167. package/dist/knowledge/repository-risk.d.ts +40 -0
  168. package/dist/knowledge/repository-risk.js +312 -0
  169. package/dist/knowledge/repository-translation.d.ts +58 -0
  170. package/dist/knowledge/repository-translation.js +422 -0
  171. package/dist/knowledge/resource-risk.d.ts +32 -0
  172. package/dist/knowledge/resource-risk.js +157 -0
  173. package/dist/knowledge/reward-confirm.d.ts +113 -0
  174. package/dist/knowledge/reward-confirm.js +496 -0
  175. package/dist/knowledge/reward-context.d.ts +127 -0
  176. package/dist/knowledge/reward-context.js +504 -0
  177. package/dist/knowledge/reward-ledger.d.ts +96 -0
  178. package/dist/knowledge/reward-ledger.js +502 -0
  179. package/dist/knowledge/reward-puzzle.d.ts +97 -0
  180. package/dist/knowledge/reward-puzzle.js +288 -0
  181. package/dist/knowledge/reward-risk.d.ts +84 -0
  182. package/dist/knowledge/reward-risk.js +545 -0
  183. package/dist/knowledge/reward-translation.d.ts +58 -0
  184. package/dist/knowledge/reward-translation.js +501 -0
  185. package/dist/knowledge/safety-rules.js +11 -3
  186. package/dist/knowledge/scenario-modes.d.ts +53 -0
  187. package/dist/knowledge/scenario-modes.js +302 -0
  188. package/dist/knowledge/service-confirm.d.ts +152 -0
  189. package/dist/knowledge/service-confirm.js +699 -0
  190. package/dist/knowledge/service-context.d.ts +66 -0
  191. package/dist/knowledge/service-context.js +403 -0
  192. package/dist/knowledge/service-ledger.d.ts +71 -0
  193. package/dist/knowledge/service-ledger.js +609 -0
  194. package/dist/knowledge/service-puzzle.d.ts +158 -0
  195. package/dist/knowledge/service-puzzle.js +236 -0
  196. package/dist/knowledge/service-risk.d.ts +108 -0
  197. package/dist/knowledge/service-risk.js +615 -0
  198. package/dist/knowledge/service-templates.d.ts +39 -0
  199. package/dist/knowledge/service-templates.js +418 -0
  200. package/dist/knowledge/service-translation.d.ts +103 -0
  201. package/dist/knowledge/service-translation.js +622 -0
  202. package/dist/knowledge/tools-reference.d.ts +17 -0
  203. package/dist/knowledge/tools-reference.js +151 -0
  204. package/dist/knowledge/treasury-confirm.d.ts +133 -0
  205. package/dist/knowledge/treasury-confirm.js +512 -0
  206. package/dist/knowledge/treasury-context.d.ts +64 -0
  207. package/dist/knowledge/treasury-context.js +363 -0
  208. package/dist/knowledge/treasury-ledger.d.ts +42 -0
  209. package/dist/knowledge/treasury-ledger.js +300 -0
  210. package/dist/knowledge/treasury-puzzle.d.ts +163 -0
  211. package/dist/knowledge/treasury-puzzle.js +216 -0
  212. package/dist/knowledge/treasury-risk.d.ts +86 -0
  213. package/dist/knowledge/treasury-risk.js +440 -0
  214. package/dist/knowledge/treasury-templates.d.ts +38 -0
  215. package/dist/knowledge/treasury-templates.js +316 -0
  216. package/dist/knowledge/treasury-translation.d.ts +78 -0
  217. package/dist/knowledge/treasury-translation.js +498 -0
  218. package/dist/knowledge/util-risk.d.ts +30 -0
  219. package/dist/knowledge/util-risk.js +135 -0
  220. package/dist/project/business-puzzle.d.ts +47 -0
  221. package/dist/project/business-puzzle.js +372 -0
  222. package/dist/project/deployment-doc.d.ts +61 -0
  223. package/dist/project/deployment-doc.js +432 -0
  224. package/dist/project/graph.d.ts +1 -0
  225. package/dist/project/graph.js +27 -1
  226. package/dist/project/index.d.ts +1 -0
  227. package/dist/project/index.js +39 -2
  228. package/dist/project/namespace.d.ts +11 -1
  229. package/dist/project/namespace.js +27 -2
  230. package/dist/project/query.d.ts +2 -0
  231. package/dist/project/query.js +56 -15
  232. package/dist/project/risk-aggregator.d.ts +50 -0
  233. package/dist/project/risk-aggregator.js +280 -0
  234. package/dist/project/substep-trace.d.ts +130 -0
  235. package/dist/project/substep-trace.js +332 -0
  236. package/dist/rules.d.ts +12 -0
  237. package/dist/rules.js +9 -0
  238. package/dist/schema/call/allocation.d.ts +44 -44
  239. package/dist/schema/call/arbitration.d.ts +141 -141
  240. package/dist/schema/call/base.d.ts +386 -386
  241. package/dist/schema/call/base.js +6 -6
  242. package/dist/schema/call/bridge-handler.d.ts +5 -2
  243. package/dist/schema/call/bridge.d.ts +159 -159
  244. package/dist/schema/call/contact.d.ts +110 -110
  245. package/dist/schema/call/demand.d.ts +76 -76
  246. package/dist/schema/call/handler.d.ts +2 -3
  247. package/dist/schema/call/handler.js +1 -1
  248. package/dist/schema/call/machine.d.ts +96 -96
  249. package/dist/schema/call/order.d.ts +98 -110
  250. package/dist/schema/call/permission-handler.d.ts +5 -0
  251. package/dist/schema/call/permission-handler.js +54 -0
  252. package/dist/schema/call/permission.d.ts +108 -108
  253. package/dist/schema/call/personal.d.ts +14 -14
  254. package/dist/schema/call/progress.d.ts +57 -72
  255. package/dist/schema/call/progress.js +7 -4
  256. package/dist/schema/call/proof.d.ts +18 -18
  257. package/dist/schema/call/proof.js +12 -7
  258. package/dist/schema/call/repository.d.ts +154 -154
  259. package/dist/schema/call/reward.d.ts +55 -55
  260. package/dist/schema/call/semantic.js +1 -1
  261. package/dist/schema/call/service.d.ts +238 -238
  262. package/dist/schema/call/treasury.d.ts +93 -93
  263. package/dist/schema/config/index.d.ts +178 -5
  264. package/dist/schema/config/index.js +52 -1
  265. package/dist/schema/local/index.d.ts +3554 -836
  266. package/dist/schema/local/index.js +2 -1
  267. package/dist/schema/messenger/index.d.ts +162 -162
  268. package/dist/schema/operations.d.ts +1102 -1118
  269. package/dist/schema/operations.js +7 -1
  270. package/dist/schema/project/index.d.ts +1392 -6
  271. package/dist/schema/project/index.js +426 -2
  272. package/dist/schema/query/index.d.ts +818 -818
  273. package/dist/schema/query/index.js +15 -9
  274. package/dist/schema/schema-query/index.d.ts +23 -3
  275. package/dist/schema/schema-query/index.js +13 -2
  276. package/dist/schema/sync-layer4.d.ts +21 -0
  277. package/dist/schema/sync-layer4.js +261 -0
  278. package/dist/schema/trust/index.d.ts +26 -26
  279. package/dist/schema/utils/guard-query-utils.d.ts +7 -0
  280. package/dist/schema/utils/guard-query-utils.js +14 -1
  281. package/dist/schemas/account_operation.output.json +718 -0
  282. package/dist/schemas/bridge_operation.output.json +1 -1
  283. package/dist/schemas/config_operation.output.json +173 -0
  284. package/dist/schemas/index.json +9 -1
  285. package/dist/schemas/local_info_operation.output.json +718 -0
  286. package/dist/schemas/local_mark_operation.output.json +718 -0
  287. package/dist/schemas/messenger_operation.output.json +1 -1
  288. package/dist/schemas/onchain_events.output.json +1 -1
  289. package/dist/schemas/onchain_operations.output.json +5 -4
  290. package/dist/schemas/onchain_operations.schema.json +1813 -333
  291. package/dist/schemas/onchain_operations_allocation.schema.json +9 -11
  292. package/dist/schemas/onchain_operations_arbitration.schema.json +2 -1
  293. package/dist/schemas/onchain_operations_contact.schema.json +2 -1
  294. package/dist/schemas/onchain_operations_demand.schema.json +2 -1
  295. package/dist/schemas/onchain_operations_gen_passport.schema.json +878 -872
  296. package/dist/schemas/onchain_operations_gen_proof.schema.json +273 -0
  297. package/dist/schemas/onchain_operations_guard.schema.json +584 -70
  298. package/dist/schemas/onchain_operations_machine.schema.json +4 -6
  299. package/dist/schemas/onchain_operations_order.schema.json +13 -9
  300. package/dist/schemas/onchain_operations_payment.schema.json +2 -1
  301. package/dist/schemas/onchain_operations_permission.schema.json +2 -1
  302. package/dist/schemas/onchain_operations_personal.schema.json +2 -1
  303. package/dist/schemas/onchain_operations_progress.schema.json +14 -10
  304. package/dist/schemas/onchain_operations_proof.schema.json +699 -0
  305. package/dist/schemas/onchain_operations_repository.schema.json +2 -1
  306. package/dist/schemas/onchain_operations_reward.schema.json +2 -1
  307. package/dist/schemas/onchain_operations_service.schema.json +4 -6
  308. package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
  309. package/dist/schemas/onchain_table_data.output.json +6 -12
  310. package/dist/schemas/onchain_table_data.schema.json +32 -1
  311. package/dist/schemas/project_operation.output.json +879 -0
  312. package/dist/schemas/project_operation.schema.json +473 -2
  313. package/dist/schemas/query_toolkit.output.json +14906 -6
  314. package/dist/schemas/schema_query.output.json +38 -1
  315. package/dist/telemetry/index.d.ts +1 -1
  316. package/dist/tools/handlers/bridge.d.ts +1 -0
  317. package/dist/tools/handlers/bridge.js +1 -0
  318. package/dist/tools/handlers/config.d.ts +2 -0
  319. package/dist/tools/handlers/config.js +74 -0
  320. package/dist/tools/handlers/file-export.d.ts +3 -0
  321. package/dist/tools/handlers/file-export.js +90 -0
  322. package/dist/tools/handlers/local.d.ts +3 -0
  323. package/dist/tools/handlers/local.js +38 -0
  324. package/dist/tools/handlers/messenger.d.ts +16 -0
  325. package/dist/tools/handlers/messenger.js +188 -0
  326. package/dist/tools/handlers/onchain.d.ts +2 -0
  327. package/dist/tools/handlers/onchain.js +248 -0
  328. package/dist/tools/handlers/project.d.ts +2 -0
  329. package/dist/tools/handlers/project.js +293 -0
  330. package/dist/tools/handlers/query.d.ts +5 -0
  331. package/dist/tools/handlers/query.js +256 -0
  332. package/dist/tools/handlers/schema-query.d.ts +2 -0
  333. package/dist/tools/handlers/schema-query.js +93 -0
  334. package/dist/tools/handlers/trust.d.ts +2 -0
  335. package/dist/tools/handlers/trust.js +194 -0
  336. package/dist/tools/handlers/wip.d.ts +2 -0
  337. package/dist/tools/handlers/wip.js +44 -0
  338. package/dist/tools/index.d.ts +13 -0
  339. package/dist/tools/index.js +526 -0
  340. package/dist/tools/rules-hook.d.ts +2 -0
  341. package/dist/tools/rules-hook.js +23 -0
  342. package/dist/tools/shared.d.ts +20 -0
  343. package/dist/tools/shared.js +130 -0
  344. package/dist/tools/types.d.ts +35 -0
  345. package/dist/tools/types.js +1 -0
  346. package/dist/tools/wrap.d.ts +14 -0
  347. package/dist/tools/wrap.js +267 -0
  348. package/package.json +20 -6
@@ -0,0 +1,248 @@
1
+ import { readFileSync } from "fs";
2
+ import { resolve } from "path";
3
+ import { CallService, CallMachine, CallProgress, CallGuard, CallArbitration, CallRepository, CallContact, CallTreasury, CallReward, CallAllocation, CallPersonal, CallPayment, CallDemand, CallOrder, gen_passport, CallProof, gen_proof, parseGuardFile, formatGuardParseErrors, transformRewardInput, transformPersonalInput, } from "@wowok/wowok";
4
+ import { OnchainOperationsSchema, strictParse, getEnvConfig, handleCallResult, checkClientSchemaCompatibility, parseMachineNodesFromText, formatNodeErrors as formatMachineNodeErrors, transformSubmission, } from "../../schema/index.js";
5
+ import { handlePermissionOperations } from "../../schema/call/permission-handler.js";
6
+ import { isProjectServiceEnabled, normalize as projectNormalize, } from "../../project/index.js";
7
+ import { withHarness } from "../shared.js";
8
+ export async function handleOnchainOperations(args) {
9
+ let validated;
10
+ let constraintWarnings = [];
11
+ let projectWarnings = [];
12
+ try {
13
+ if (typeof args === 'object' && args !== null
14
+ && 'description' in args && !('operation_type' in args)) {
15
+ const desc = args.description;
16
+ const hasWrappedParams = typeof desc === 'string' &&
17
+ (desc.includes('operation_type') || desc.includes('data'));
18
+ if (hasWrappedParams) {
19
+ throw new Error("Invalid parameter structure. Parameters should NOT be wrapped in 'description' field.\n" +
20
+ "Correct format: { operation_type: '...', data: {...} }\n" +
21
+ "Incorrect format: { description: '{ operation_type: ... }' }");
22
+ }
23
+ }
24
+ validated = strictParse(OnchainOperationsSchema, args, "onchain_operations input");
25
+ const env = getEnvConfig(validated.env);
26
+ const clientSchemaVersion = env.client_schema_version;
27
+ const schemaStrictMode = env.schema_strict_mode;
28
+ const schemaCheck = clientSchemaVersion
29
+ ? checkClientSchemaCompatibility(clientSchemaVersion, { mode: schemaStrictMode ? "strict" : "warn" })
30
+ : undefined;
31
+ const buildCtx = (data) => ({
32
+ operation_type: validated.operation_type,
33
+ data,
34
+ pre_warnings: [...constraintWarnings, ...projectWarnings].length
35
+ ? [...constraintWarnings, ...projectWarnings]
36
+ : undefined,
37
+ schema_check: schemaCheck,
38
+ });
39
+ const projectEnvPrefix = env.project;
40
+ if (isProjectServiceEnabled() && 'data' in validated && validated.data) {
41
+ const pn = projectNormalize({
42
+ operation_type: validated.operation_type,
43
+ data: validated.data,
44
+ projectPrefix: projectEnvPrefix,
45
+ });
46
+ validated.data = pn.data;
47
+ projectWarnings = pn.warnings ?? [];
48
+ }
49
+ delete env.confirmed;
50
+ delete env.user_intent_phrases;
51
+ delete env.project;
52
+ delete env.client_schema_version;
53
+ delete env.schema_strict_mode;
54
+ switch (validated.operation_type) {
55
+ case "service": {
56
+ const callService = new CallService(validated.data);
57
+ const result = validated.submission
58
+ ? await callService.call_with_submission(env, await transformSubmission(validated.submission))
59
+ : await callService.call(env);
60
+ const data = validated.data;
61
+ const intent = data?.publish ? "publish service" : data?.bPublished !== undefined ? "modify service" : "create service";
62
+ return handleCallResult(result, withHarness(buildCtx(data), "service", intent));
63
+ }
64
+ case "machine": {
65
+ if (validated.data.node && typeof validated.data.node === 'object' && 'json_or_markdown_file' in validated.data.node) {
66
+ const filePathStr = validated.data.node.json_or_markdown_file;
67
+ let fileContent;
68
+ try {
69
+ const filePath = resolve(filePathStr);
70
+ fileContent = readFileSync(filePath, 'utf-8');
71
+ }
72
+ catch (e) {
73
+ throw new Error(`Failed to read file '${filePathStr}': ${e.message}`);
74
+ }
75
+ const parseResult = parseMachineNodesFromText(fileContent);
76
+ if (!parseResult.success) {
77
+ const errorMessages = formatMachineNodeErrors(parseResult.errors);
78
+ throw new Error(`Machine node validation failed for file '${filePathStr}':\n\n${errorMessages}`);
79
+ }
80
+ if (!parseResult.data) {
81
+ throw new Error(`No nodes found in file '${filePathStr}'`);
82
+ }
83
+ validated.data.node = {
84
+ op: "set",
85
+ nodes: parseResult.data,
86
+ bReplace: true
87
+ };
88
+ }
89
+ const callMachine = new CallMachine(validated.data);
90
+ const result = validated.submission
91
+ ? await callMachine.call_with_submission(env, await transformSubmission(validated.submission))
92
+ : await callMachine.call(env);
93
+ return handleCallResult(result, buildCtx(validated.data));
94
+ }
95
+ case "progress": {
96
+ const callProgress = new CallProgress(validated.data);
97
+ const result = validated.submission
98
+ ? await callProgress.call_with_submission(env, await transformSubmission(validated.submission))
99
+ : await callProgress.call(env);
100
+ return handleCallResult(result, buildCtx(validated.data));
101
+ }
102
+ case "repository": {
103
+ const callRepository = new CallRepository(validated.data);
104
+ const result = validated.submission
105
+ ? await callRepository.call_with_submission(env, await transformSubmission(validated.submission))
106
+ : await callRepository.call(env);
107
+ return handleCallResult(result, buildCtx(validated.data));
108
+ }
109
+ case "arbitration": {
110
+ const callArbitration = new CallArbitration(validated.data);
111
+ const result = validated.submission
112
+ ? await callArbitration.call_with_submission(env, await transformSubmission(validated.submission))
113
+ : await callArbitration.call(env);
114
+ return handleCallResult(result, buildCtx(validated.data));
115
+ }
116
+ case "contact": {
117
+ const callContact = new CallContact(validated.data);
118
+ const result = validated.submission
119
+ ? await callContact.call_with_submission(env, await transformSubmission(validated.submission))
120
+ : await callContact.call(env);
121
+ return handleCallResult(result, buildCtx(validated.data));
122
+ }
123
+ case "treasury": {
124
+ const callTreasury = new CallTreasury(validated.data);
125
+ const result = validated.submission
126
+ ? await callTreasury.call_with_submission(env, await transformSubmission(validated.submission))
127
+ : await callTreasury.call(env);
128
+ return handleCallResult(result, buildCtx(validated.data));
129
+ }
130
+ case "reward": {
131
+ const transformedData = transformRewardInput(validated.data);
132
+ const callReward = new CallReward(transformedData);
133
+ const result = validated.submission
134
+ ? await callReward.call_with_submission(env, await transformSubmission(validated.submission))
135
+ : await callReward.call(env);
136
+ return handleCallResult(result, buildCtx(validated.data));
137
+ }
138
+ case "allocation": {
139
+ const callAllocation = new CallAllocation(validated.data);
140
+ const result = validated.submission
141
+ ? await callAllocation.call_with_submission(env, await transformSubmission(validated.submission))
142
+ : await callAllocation.call(env);
143
+ return handleCallResult(result, buildCtx(validated.data));
144
+ }
145
+ case "permission": {
146
+ return handlePermissionOperations(validated.data, env, buildCtx);
147
+ }
148
+ case "guard": {
149
+ const validatedData = validated.data;
150
+ if (validatedData.root?.type === "file") {
151
+ const filePath = resolve(validatedData.root.file_path);
152
+ let fileContent;
153
+ try {
154
+ fileContent = readFileSync(filePath, 'utf-8');
155
+ }
156
+ catch (e) {
157
+ throw new Error(`Failed to read Guard definition file '${validatedData.root.file_path}': ${e.message}`);
158
+ }
159
+ const parseResult = parseGuardFile(fileContent, validatedData.root.format);
160
+ if (!parseResult.success) {
161
+ const errorMessages = formatGuardParseErrors(parseResult.errors);
162
+ throw new Error(`Guard validation failed for file '${validatedData.root.file_path}':\n\n${errorMessages}`);
163
+ }
164
+ const fileData = parseResult.data;
165
+ validatedData.root = { type: "node", node: fileData.root };
166
+ if (fileData.table !== undefined && validatedData.table === undefined) {
167
+ validatedData.table = fileData.table;
168
+ }
169
+ if (fileData.description !== undefined && validatedData.description === undefined) {
170
+ validatedData.description = fileData.description;
171
+ }
172
+ if (fileData.rely !== undefined && validatedData.rely === undefined) {
173
+ validatedData.rely = fileData.rely;
174
+ }
175
+ if (fileData.namedNew !== undefined && validatedData.namedNew === undefined) {
176
+ validatedData.namedNew = fileData.namedNew;
177
+ }
178
+ }
179
+ if (validatedData.root && typeof validatedData.root === 'object') {
180
+ const rootObj = validatedData.root;
181
+ if (rootObj.type === 'node' && rootObj.node) {
182
+ validatedData.root = rootObj.node;
183
+ }
184
+ }
185
+ if (!validatedData.table || validatedData.table.length === 0) {
186
+ throw new Error("Guard 'table' field is required and cannot be empty");
187
+ }
188
+ if (!validatedData.root) {
189
+ throw new Error("Guard 'root' field is required");
190
+ }
191
+ const callGuard = new CallGuard(validatedData);
192
+ const result = await callGuard.call(env);
193
+ return handleCallResult(result, buildCtx(validated.data));
194
+ }
195
+ case "personal": {
196
+ const transformedData = transformPersonalInput(validated.data);
197
+ const callPersonal = new CallPersonal(transformedData);
198
+ const result = await callPersonal.call(env);
199
+ return handleCallResult(result, buildCtx(validated.data));
200
+ }
201
+ case "payment": {
202
+ const callPayment = new CallPayment(validated.data);
203
+ const result = await callPayment.call(env);
204
+ return handleCallResult(result, buildCtx(validated.data));
205
+ }
206
+ case "demand": {
207
+ const callDemand = new CallDemand(validated.data);
208
+ const result = validated.submission
209
+ ? await callDemand.call_with_submission(env, await transformSubmission(validated.submission))
210
+ : await callDemand.call(env);
211
+ return handleCallResult(result, buildCtx(validated.data));
212
+ }
213
+ case "order": {
214
+ const callOrder = new CallOrder(validated.data);
215
+ const result = validated.submission
216
+ ? await callOrder.call_with_submission(env, await transformSubmission(validated.submission))
217
+ : await callOrder.call(env);
218
+ return handleCallResult(result, buildCtx(validated.data));
219
+ }
220
+ case "gen_passport": {
221
+ const result = await gen_passport(env, validated.guard, validated.info);
222
+ return handleCallResult(result, buildCtx(validated.data));
223
+ }
224
+ case "proof": {
225
+ const callProof = new CallProof(validated.data);
226
+ const result = validated.submission
227
+ ? await callProof.call_with_submission(env, await transformSubmission(validated.submission))
228
+ : await callProof.call(env);
229
+ return handleCallResult(result, buildCtx(validated.data));
230
+ }
231
+ case "gen_proof": {
232
+ const result = await gen_proof(env, validated.proof, validated.server_pubkey, validated.server_signature, validated.proof_type, validated.description, validated.item_count, validated.about_address);
233
+ return handleCallResult(result, buildCtx(validated.data));
234
+ }
235
+ }
236
+ const exhaustiveOp = validated;
237
+ throw new Error(`Unknown on-chain operation type: ${String(exhaustiveOp.operation_type)}`);
238
+ }
239
+ catch (error) {
240
+ const errorMessage = error instanceof Error ? error.message : String(error);
241
+ const opType = validated?.operation_type;
242
+ const ctxData = validated && 'data' in validated ? validated.data : undefined;
243
+ return handleCallResult({ error: errorMessage }, opType ? {
244
+ operation_type: opType,
245
+ data: ctxData,
246
+ } : undefined);
247
+ }
248
+ }
@@ -0,0 +1,2 @@
1
+ import type { ToolDispatchResult } from "../types.js";
2
+ export declare function handleProjectOperation(args: unknown): Promise<ToolDispatchResult>;
@@ -0,0 +1,293 @@
1
+ import { queryProjects, queryProjectObjects, queryShareableObjects, queryDependencies, queryReferencedBy, queryPrePublishCheck, queryCrossProjectReferences, queryGraphStats, saveGraph, loadGraph, } from "../../project/index.js";
2
+ import { analyzeBusinessIntent } from "../../project/business-puzzle.js";
3
+ import { aggregateProjectRisks } from "../../project/risk-aggregator.js";
4
+ import { generateDeploymentDoc, validateDeploymentDoc, } from "../../project/deployment-doc.js";
5
+ import { traceSubsteps } from "../../project/substep-trace.js";
6
+ import { strictParse } from "../../schema/index.js";
7
+ import { ProjectOperationInputSchema } from "../../schema/project/index.js";
8
+ import { injectEvolutionContext } from "../../knowledge/flywheel-loop.js";
9
+ import { getExperienceFeedback } from "../../experience/index.js";
10
+ function requireProject(v) {
11
+ if (!v.project) {
12
+ throw new Error("'project' (prefix) is required for this action");
13
+ }
14
+ if (!v.version) {
15
+ throw new Error("'version' is required for this action (e.g. 'v1')");
16
+ }
17
+ return { prefix: v.project, version: v.version };
18
+ }
19
+ function requireUserIntent(v) {
20
+ if (!v.user_intent) {
21
+ throw new Error("'user_intent' is required for analyze_intent");
22
+ }
23
+ return v.user_intent;
24
+ }
25
+ function requirePuzzles(v) {
26
+ if (!v.puzzles || Object.keys(v.puzzles).length === 0) {
27
+ throw new Error("'puzzles' is required for this action (obtain from analyze_intent)");
28
+ }
29
+ return v.puzzles;
30
+ }
31
+ function requireDeploymentInputs(v) {
32
+ if (!v.business_intent) {
33
+ throw new Error("'business_intent' is required for generate_deployment_doc");
34
+ }
35
+ if (!v.objects || v.objects.length === 0) {
36
+ throw new Error("'objects' is required for generate_deployment_doc");
37
+ }
38
+ if (!v.edges) {
39
+ throw new Error("'edges' is required for generate_deployment_doc");
40
+ }
41
+ if (!v.steps) {
42
+ throw new Error("'steps' is required for generate_deployment_doc");
43
+ }
44
+ return {
45
+ business_intent: v.business_intent,
46
+ objects: v.objects,
47
+ edges: v.edges,
48
+ steps: v.steps,
49
+ };
50
+ }
51
+ function requireSubsteps(v) {
52
+ if (!v.network) {
53
+ throw new Error("'network' is required for trace_substeps");
54
+ }
55
+ if (v.network !== "testnet" && v.network !== "mainnet") {
56
+ throw new Error("'network' must be 'testnet' or 'mainnet'");
57
+ }
58
+ if (!v.substeps || v.substeps.length === 0) {
59
+ throw new Error("'substeps' is required for trace_substeps");
60
+ }
61
+ return {
62
+ network: v.network,
63
+ substeps: v.substeps,
64
+ };
65
+ }
66
+ async function handleAnalyzeIntent(validated) {
67
+ const { prefix, version } = requireProject(validated);
68
+ const userIntent = requireUserIntent(validated);
69
+ const result = analyzeBusinessIntent({
70
+ user_intent: userIntent,
71
+ project_name: `${prefix}_${version}`,
72
+ industry: validated.industry,
73
+ target_objects: validated.target_objects,
74
+ });
75
+ const industry = validated.industry ?? "general";
76
+ let evolutionContext;
77
+ let experienceFeedback;
78
+ try {
79
+ evolutionContext = injectEvolutionContext(undefined, industry);
80
+ }
81
+ catch {
82
+ evolutionContext = undefined;
83
+ }
84
+ try {
85
+ experienceFeedback = getExperienceFeedback("analyze_intent", { user_intent: userIntent, industry, target_objects: validated.target_objects }, `project:analyze_intent`);
86
+ }
87
+ catch {
88
+ experienceFeedback = undefined;
89
+ }
90
+ return {
91
+ action: "analyze_intent",
92
+ intent_parsed: result.intent_parsed,
93
+ puzzles: result.puzzles,
94
+ overall_completeness: result.overall_completeness,
95
+ next_step: result.next_step,
96
+ warnings: result.warnings,
97
+ evolution_context: evolutionContext,
98
+ experience_feedback: experienceFeedback,
99
+ };
100
+ }
101
+ async function handleAggregateRisks(validated) {
102
+ const { prefix, version } = requireProject(validated);
103
+ const puzzles = requirePuzzles(validated);
104
+ const result = aggregateProjectRisks({
105
+ project_prefix: prefix,
106
+ version: version,
107
+ industry: validated.industry,
108
+ puzzles,
109
+ severity_threshold: validated.severity_threshold,
110
+ user_confirmed_high_risks: validated.user_confirmed_high_risks,
111
+ });
112
+ const hasCritical = result.severity_summary.CRITICAL > 0;
113
+ const unconfirmedHigh = result.findings.filter((r) => r.severity === "HIGH").length;
114
+ return {
115
+ action: "aggregate_risks",
116
+ namespace: result.namespace,
117
+ findings: result.findings,
118
+ severity_summary: result.severity_summary,
119
+ status: result.status,
120
+ pending_confirmations: result.pending_confirmations,
121
+ calibrated_at: result.calibrated_at,
122
+ warnings: result.warnings,
123
+ can_proceed: !hasCritical,
124
+ user_action_required: hasCritical
125
+ ? `Fix ${result.severity_summary.CRITICAL} CRITICAL risk(s) before proceeding`
126
+ : unconfirmedHigh > 0
127
+ ? `Review ${unconfirmedHigh} HIGH risk(s). You may proceed at your own risk.`
128
+ : "All risks reviewed. You may proceed.",
129
+ };
130
+ }
131
+ async function handleGenerateDeploymentDoc(validated) {
132
+ const { prefix, version } = requireProject(validated);
133
+ const required = requireDeploymentInputs(validated);
134
+ const docInput = {
135
+ project_prefix: prefix,
136
+ version: version,
137
+ business_intent: required.business_intent,
138
+ industry: validated.industry ?? "general",
139
+ author: validated.author,
140
+ objects: required.objects,
141
+ edges: required.edges,
142
+ steps: required.steps,
143
+ scenarios: validated.scenarios,
144
+ risk_status: validated.risk_status,
145
+ risk_critical_count: validated.risk_critical_count,
146
+ risk_high_count: validated.risk_high_count,
147
+ };
148
+ const markdown = generateDeploymentDoc(docInput);
149
+ const generatedAt = new Date().toISOString();
150
+ const shouldRunScanner = validated.run_scanner !== false;
151
+ let validationResult;
152
+ if (shouldRunScanner) {
153
+ const validation = validateDeploymentDoc(docInput);
154
+ validationResult = {
155
+ valid: validation.valid,
156
+ checks: validation.checks,
157
+ errors: validation.errors,
158
+ };
159
+ }
160
+ const errorCount = validationResult
161
+ ? validationResult.checks.filter((c) => c.status === "FAIL").length
162
+ : 0;
163
+ const warningCount = validationResult
164
+ ? validationResult.checks.filter((c) => c.status === "WARN").length
165
+ : 0;
166
+ return {
167
+ action: "generate_deployment_doc",
168
+ markdown,
169
+ meta: {
170
+ project_prefix: prefix,
171
+ version: version,
172
+ generated_at: generatedAt,
173
+ object_count: required.objects.length,
174
+ step_count: required.steps.length,
175
+ },
176
+ validation: validationResult,
177
+ can_proceed: errorCount === 0,
178
+ user_action_required: errorCount > 0
179
+ ? `Fix ${errorCount} D-error(s) before deploying`
180
+ : warningCount > 0
181
+ ? `${warningCount} D-warning(s) found. You may proceed at your own risk.`
182
+ : "Deployment document ready. You may proceed to stage 5.",
183
+ };
184
+ }
185
+ async function handleTraceSubsteps(validated) {
186
+ const { prefix, version } = requireProject(validated);
187
+ const { network, substeps } = requireSubsteps(validated);
188
+ const result = traceSubsteps({
189
+ project_prefix: prefix,
190
+ version: version,
191
+ network: network,
192
+ substeps,
193
+ });
194
+ const hasFailedSubstep = substeps.some((s) => s.status === "FAILED");
195
+ const canProceed = result.coherent && !hasFailedSubstep;
196
+ const issueParts = [];
197
+ if (result.dangling_inputs.length > 0) {
198
+ issueParts.push(`${result.dangling_inputs.length} dangling inputs`);
199
+ }
200
+ if (result.circular_refs.length > 0) {
201
+ issueParts.push(`${result.circular_refs.length} circular refs`);
202
+ }
203
+ if (result.missing_outputs.length > 0) {
204
+ issueParts.push(`${result.missing_outputs.length} missing outputs`);
205
+ }
206
+ if (result.cross_step_breaks.length > 0) {
207
+ issueParts.push(`${result.cross_step_breaks.length} cross-step breaks`);
208
+ }
209
+ if (hasFailedSubstep) {
210
+ const failedCount = substeps.filter((s) => s.status === "FAILED").length;
211
+ issueParts.push(`${failedCount} failed substep(s)`);
212
+ }
213
+ return {
214
+ action: "trace_substeps",
215
+ namespace: result.namespace,
216
+ network: result.network,
217
+ coherent: result.coherent,
218
+ dangling_inputs: result.dangling_inputs,
219
+ circular_refs: result.circular_refs,
220
+ missing_outputs: result.missing_outputs,
221
+ cross_step_breaks: result.cross_step_breaks,
222
+ step_details: result.step_details,
223
+ topological_order: result.topological_order,
224
+ d10_check: result.d10_check,
225
+ can_proceed: canProceed,
226
+ user_action_required: issueParts.length > 0
227
+ ? `Fix: ${issueParts.join(", ")}`
228
+ : "All substeps passed. Deployment complete.",
229
+ };
230
+ }
231
+ export async function handleProjectOperation(args) {
232
+ const validated = strictParse(ProjectOperationInputSchema, args, "project_operation input");
233
+ const { action } = validated;
234
+ let result;
235
+ switch (action) {
236
+ case "list_projects":
237
+ result = { action: "list_projects", items: await queryProjects() };
238
+ break;
239
+ case "list_objects":
240
+ if (!validated.project)
241
+ throw new Error("'project' param is required for list_objects");
242
+ result = { action: "list_objects", items: await queryProjectObjects(validated.project) };
243
+ break;
244
+ case "shareable":
245
+ result = { action: "shareable", items: await queryShareableObjects() };
246
+ break;
247
+ case "dependencies":
248
+ if (!validated.object)
249
+ throw new Error("'object' param is required for dependencies");
250
+ result = { action: "dependencies", items: queryDependencies(validated.object) };
251
+ break;
252
+ case "referenced_by":
253
+ if (!validated.object)
254
+ throw new Error("'object' param is required for referenced_by");
255
+ result = { action: "referenced_by", items: queryReferencedBy(validated.object) };
256
+ break;
257
+ case "pre_publish_check":
258
+ if (!validated.object)
259
+ throw new Error("'object' param is required for pre_publish_check");
260
+ result = { action: "pre_publish_check", warnings: queryPrePublishCheck(validated.object) };
261
+ break;
262
+ case "cross_project_refs":
263
+ result = { action: "cross_project_refs", items: queryCrossProjectReferences() };
264
+ break;
265
+ case "graph_stats":
266
+ result = { action: "graph_stats", stats: queryGraphStats() };
267
+ break;
268
+ case "save_graph":
269
+ result = { action: "save_graph", saved: true, path: saveGraph() };
270
+ break;
271
+ case "load_graph":
272
+ result = { action: "load_graph", loaded: loadGraph() };
273
+ break;
274
+ case "analyze_intent":
275
+ result = await handleAnalyzeIntent(validated);
276
+ break;
277
+ case "aggregate_risks":
278
+ result = await handleAggregateRisks(validated);
279
+ break;
280
+ case "generate_deployment_doc":
281
+ result = await handleGenerateDeploymentDoc(validated);
282
+ break;
283
+ case "trace_substeps":
284
+ result = await handleTraceSubsteps(validated);
285
+ break;
286
+ default:
287
+ throw new Error(`Unknown project_operation action: ${String(action)}`);
288
+ }
289
+ return {
290
+ content: [{ type: "text", text: JSON.stringify({ result }) }],
291
+ structuredContent: { result },
292
+ };
293
+ }
@@ -0,0 +1,5 @@
1
+ import type { ToolDispatchResult } from "../types.js";
2
+ export declare function handleWatchQueryOperations(args: unknown): Promise<ToolDispatchResult>;
3
+ export declare function handleOnchainTableData(args: unknown): Promise<ToolDispatchResult>;
4
+ export declare function handleOnchainEvents(args: unknown): Promise<ToolDispatchResult>;
5
+ export declare function handleWowokInfo(args: unknown): Promise<ToolDispatchResult>;