@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,65 +1 @@
1
- import { readFileSync, existsSync, readdirSync } from "fs";
2
- import { join } from "path";
3
- import { getWowMcpDir } from "@wowok/wowok";
4
- function wowokRootDir() {
5
- return getWowMcpDir();
6
- }
7
- function overridesDir() {
8
- return join(wowokRootDir(), "overrides");
9
- }
10
- let overrideCache;
11
- export function loadOverrides(forceReload = false) {
12
- if (overrideCache && !forceReload)
13
- return overrideCache;
14
- const config = {};
15
- const dir = overridesDir();
16
- if (!existsSync(dir)) {
17
- overrideCache = config;
18
- return config;
19
- }
20
- const categories = [
21
- "risk-thresholds",
22
- "descriptions",
23
- "industry-profiles",
24
- "scenario-defaults",
25
- "recovery-priorities",
26
- ];
27
- for (const cat of categories) {
28
- const filePath = join(dir, `${cat}.json`);
29
- if (!existsSync(filePath))
30
- continue;
31
- try {
32
- const raw = readFileSync(filePath, "utf-8");
33
- const parsed = JSON.parse(raw);
34
- const { _last_applied_proposal, _last_applied_at, ...userFields } = parsed;
35
- void _last_applied_proposal;
36
- void _last_applied_at;
37
- config[cat] = userFields;
38
- }
39
- catch {
40
- }
41
- }
42
- overrideCache = config;
43
- return config;
44
- }
45
- export function getOverride(category) {
46
- const config = loadOverrides();
47
- return config[category];
48
- }
49
- export function clearOverrideCache() {
50
- overrideCache = undefined;
51
- }
52
- export function listOverrideFiles() {
53
- const dir = overridesDir();
54
- if (!existsSync(dir))
55
- return [];
56
- try {
57
- return readdirSync(dir).filter((f) => f.endsWith(".json"));
58
- }
59
- catch {
60
- return [];
61
- }
62
- }
63
- export function getOverridesDirPath() {
64
- return overridesDir();
65
- }
1
+ import{readFileSync,existsSync,readdirSync}from'fs';import{join}from'path';import{getWowMcpDir}from'@wowok/wowok';function wowokRootDir(){return getWowMcpDir();}function overridesDir(){return join(wowokRootDir(),'overrides');}let overrideCache;export function loadOverrides(a=![]){if(overrideCache&&!a)return overrideCache;const b={},c=overridesDir();if(!existsSync(c))return overrideCache=b,b;const d=['risk-thresholds','descriptions','industry-profiles','scenario-defaults','recovery-priorities'];for(const e of d){const f=join(c,e+'.json');if(!existsSync(f))continue;try{const g=readFileSync(f,'utf-8'),h=JSON['parse'](g),{_last_applied_proposal:i,_last_applied_at:j,...k}=h;void i,void j,b[e]=k;}catch{}}return overrideCache=b,b;}export function getOverride(a){const b=loadOverrides();return b[a];}export function clearOverrideCache(){overrideCache=undefined;}export function listOverrideFiles(){const a=overridesDir();if(!existsSync(a))return[];try{return readdirSync(a)['filter'](b=>b['endsWith']('.json'));}catch{return[];}}export function getOverridesDirPath(){return overridesDir();}
@@ -1,531 +1 @@
1
- import { MAX_GUARD_COUNT_PASSPORT, MAX_SUBMISSION_SIZE_PASSPORT, PASSPORT_ERROR_CODES, } from "./passport-ledger.js";
2
- import { assessPassportRisks, } from "./passport-risk.js";
3
- export const PASSPORT_CONFIRMATION_RULES = {
4
- creation: [
5
- {
6
- id: "C-PASS-01",
7
- check: "Confirm Clock object is accessible (new requires Clock argument)",
8
- severity: "HIGH",
9
- action: "block",
10
- layer: "creation",
11
- },
12
- {
13
- id: "C-PASS-02",
14
- check: "Confirm current transaction context is valid (tx_hash will bind to this transaction)",
15
- severity: "CRITICAL",
16
- action: "block",
17
- layer: "creation",
18
- },
19
- ],
20
- operation: [
21
- {
22
- id: "C-PASS-03",
23
- check: "guard_add: confirm has_verified=false (E_HAS_VERIFIED)",
24
- severity: "CRITICAL",
25
- action: "block",
26
- related_error: "E_HAS_VERIFIED (4)",
27
- layer: "operation",
28
- },
29
- {
30
- id: "C-PASS-04",
31
- check: "guard_add: confirm tx_hash matches current transaction (E_DIGEST_NOT_MATCH)",
32
- severity: "CRITICAL",
33
- action: "block",
34
- related_error: "E_DIGEST_NOT_MATCH (11)",
35
- layer: "operation",
36
- },
37
- {
38
- id: "C-PASS-05",
39
- check: "guard_add: confirm depended-on Guards already added (E_RELIES_GUARD_NOT_ADDED)",
40
- severity: "HIGH",
41
- action: "block",
42
- related_error: "E_RELIES_GUARD_NOT_ADDED (2)",
43
- layer: "operation",
44
- },
45
- {
46
- id: "C-PASS-06",
47
- check: "guard_add: warn Guard count approaching MAX_GUARD_COUNT=20 limit",
48
- severity: "MEDIUM",
49
- action: "warn",
50
- related_error: "E_GUARD_COUNT_EXCEEDED (1)",
51
- layer: "operation",
52
- },
53
- {
54
- id: "C-PASS-07",
55
- check: "guard_add: warn impack Guard failure will cause overall result=false",
56
- severity: "HIGH",
57
- action: "warn",
58
- layer: "operation",
59
- },
60
- {
61
- id: "C-PASS-08",
62
- check: "guard_add: warn submission serialized size must be ≤ 256 bytes",
63
- severity: "MEDIUM",
64
- action: "warn",
65
- related_error: "E_SUBMISSION_SIZE_EXCEEDED (3)",
66
- layer: "operation",
67
- },
68
- {
69
- id: "C-PASS-09",
70
- check: "verify: warn this is a one-time operation; after verify, configuration cannot be modified",
71
- severity: "HIGH",
72
- action: "confirm_twice",
73
- related_error: "E_HAS_VERIFIED (4)",
74
- layer: "operation",
75
- },
76
- {
77
- id: "C-PASS-10",
78
- check: "verify: confirm at least 1 impack Guard exists (E_IMPACK_GUARD_NOT_FOUND)",
79
- severity: "CRITICAL",
80
- action: "block",
81
- related_error: "E_IMPACK_GUARD_NOT_FOUND (9)",
82
- layer: "operation",
83
- },
84
- {
85
- id: "C-PASS-11",
86
- check: "guard_clear: warn this will clear all Guards (allowed before verify)",
87
- severity: "MEDIUM",
88
- action: "confirm_twice",
89
- layer: "operation",
90
- },
91
- {
92
- id: "C-PASS-12",
93
- check: "freezen: warn after freezing, Passport is permanently retained and cannot be destroyed",
94
- severity: "MEDIUM",
95
- action: "confirm_twice",
96
- layer: "operation",
97
- },
98
- {
99
- id: "C-PASS-13",
100
- check: "destroy: warn Passport cannot be recovered after destruction (must be before freeze)",
101
- severity: "HIGH",
102
- action: "confirm_twice",
103
- layer: "operation",
104
- },
105
- ],
106
- consistency: [
107
- {
108
- id: "C-PASS-14",
109
- check: "Confirm Passport object is not frozen (no operations allowed after freeze)",
110
- severity: "HIGH",
111
- action: "block",
112
- layer: "consistency",
113
- },
114
- {
115
- id: "C-PASS-15",
116
- check: "Confirm referenced Guard objects have not been deleted",
117
- severity: "HIGH",
118
- action: "block",
119
- layer: "consistency",
120
- },
121
- {
122
- id: "C-PASS-16",
123
- check: "Confirm has_verified=true when querying result (E_NOT_VERIFIED)",
124
- severity: "HIGH",
125
- action: "block",
126
- related_error: "E_NOT_VERIFIED (5)",
127
- layer: "consistency",
128
- },
129
- {
130
- id: "C-PASS-17",
131
- check: "Confirm tx_hash matches current transaction when querying result (E_TX_NOT_MATCH)",
132
- severity: "CRITICAL",
133
- action: "block",
134
- related_error: "E_TX_NOT_MATCH (8)",
135
- layer: "consistency",
136
- },
137
- {
138
- id: "C-PASS-18",
139
- check: "Info: relies dependencies (avoid circular dependencies)",
140
- severity: "INFO",
141
- action: "info",
142
- layer: "consistency",
143
- },
144
- {
145
- id: "C-PASS-19",
146
- check: "Warn: non-impack Guard result does not affect final result",
147
- severity: "INFO",
148
- action: "info",
149
- layer: "consistency",
150
- },
151
- {
152
- id: "C-PASS-20",
153
- check: "Info: Passport emits no events; status must be queried actively",
154
- severity: "INFO",
155
- action: "info",
156
- layer: "consistency",
157
- },
158
- ],
159
- };
160
- export function preCheckPassportCreation(input) {
161
- const errors = [];
162
- const warnings = [];
163
- const requiresConfirmation = [];
164
- if (!input.clock) {
165
- errors.push("Clock object is required for Passport creation (C-PASS-01, passport::new requires Clock argument)");
166
- }
167
- if (!input.txDigest) {
168
- errors.push("Valid transaction context required — tx_hash will bind to this transaction (C-PASS-02)");
169
- }
170
- return {
171
- errors,
172
- warnings,
173
- requiresConfirmation,
174
- canProceed: errors.length === 0,
175
- };
176
- }
177
- export function preCheckPassportOperation(input) {
178
- const errors = [];
179
- const warnings = [];
180
- const requiresConfirmation = [];
181
- const { passport, operation, guardObjects } = input;
182
- switch (operation.type) {
183
- case "guard_add": {
184
- if (passport.has_verified) {
185
- errors.push(`Passport already verified, cannot add guard (C-PASS-03, E_HAS_VERIFIED=${PASSPORT_ERROR_CODES.E_HAS_VERIFIED})`);
186
- break;
187
- }
188
- warnings.push(`tx_hash must match current transaction (C-PASS-04, E_DIGEST_NOT_MATCH=${PASSPORT_ERROR_CODES.E_DIGEST_NOT_MATCH})`);
189
- const guardObj = guardObjects.get(operation.guard);
190
- if (guardObj?.relies && guardObj.relies.length > 0) {
191
- for (const relyAddr of guardObj.relies) {
192
- const relyAdded = passport.info.some(g => g.guard === relyAddr);
193
- if (!relyAdded) {
194
- errors.push(`Dependency Guard ${relyAddr} not added yet (C-PASS-05, E_RELIES_GUARD_NOT_ADDED=${PASSPORT_ERROR_CODES.E_RELIES_GUARD_NOT_ADDED})`);
195
- }
196
- }
197
- }
198
- if (passport.info.length >= MAX_GUARD_COUNT_PASSPORT) {
199
- errors.push(`Guard count ${passport.info.length} >= MAX_GUARD_COUNT_PASSPORT=${MAX_GUARD_COUNT_PASSPORT} (C-PASS-06, E_GUARD_COUNT_EXCEEDED=${PASSPORT_ERROR_CODES.E_GUARD_COUNT_EXCEEDED})`);
200
- }
201
- else if (passport.info.length >= MAX_GUARD_COUNT_PASSPORT - 5) {
202
- warnings.push(`Guard count ${passport.info.length} approaching limit ${MAX_GUARD_COUNT_PASSPORT} (C-PASS-06)`);
203
- }
204
- if (operation.impack) {
205
- warnings.push("impack=true Guard failure will cause overall result=false (C-PASS-07)");
206
- }
207
- if (operation.submission) {
208
- const estimatedSize = estimateSubmissionSize(operation.submission);
209
- if (estimatedSize > MAX_SUBMISSION_SIZE_PASSPORT) {
210
- errors.push(`Submission size ${estimatedSize} > MAX_SUBMISSION_SIZE_PASSPORT=${MAX_SUBMISSION_SIZE_PASSPORT} (C-PASS-08, E_SUBMISSION_SIZE_EXCEEDED=${PASSPORT_ERROR_CODES.E_SUBMISSION_SIZE_EXCEEDED})`);
211
- }
212
- else if (estimatedSize > MAX_SUBMISSION_SIZE_PASSPORT * 0.8) {
213
- warnings.push(`Submission size ${estimatedSize} approaching limit ${MAX_SUBMISSION_SIZE_PASSPORT} (C-PASS-08)`);
214
- }
215
- }
216
- break;
217
- }
218
- case "verify": {
219
- requiresConfirmation.push("WARNING: verify is ONE-TIME operation. After verify, guard configuration cannot be modified. Type 'CONFIRM' to proceed. (C-PASS-09)");
220
- const hasImpack = passport.info.some(g => g.impack);
221
- if (!hasImpack) {
222
- errors.push(`No impack Guard found, verify will fail (C-PASS-10, E_IMPACK_GUARD_NOT_FOUND=${PASSPORT_ERROR_CODES.E_IMPACK_GUARD_NOT_FOUND})`);
223
- }
224
- break;
225
- }
226
- case "guard_clear": {
227
- requiresConfirmation.push(`WARNING: guard_clear will remove all ${passport.info.length} guards. Type 'CONFIRM' to proceed. (C-PASS-11)`);
228
- if (passport.has_verified) {
229
- errors.push(`Passport already verified, cannot clear guards (C-PASS-11, E_HAS_VERIFIED=${PASSPORT_ERROR_CODES.E_HAS_VERIFIED})`);
230
- }
231
- break;
232
- }
233
- case "freezen": {
234
- requiresConfirmation.push("WARNING: freezen will PERMANENTLY freeze the Passport. It cannot be destroyed after freezing. Type 'CONFIRM' to proceed. (C-PASS-12)");
235
- break;
236
- }
237
- case "destroy": {
238
- requiresConfirmation.push("WARNING: destroy will delete the Passport permanently. This must be done BEFORE freezing. Type 'CONFIRM' to proceed. (C-PASS-13)");
239
- break;
240
- }
241
- case "result_query":
242
- case "result_for_guard":
243
- case "result_for_permission": {
244
- if (!passport.has_verified) {
245
- errors.push(`result query requires has_verified=true (C-PASS-16, E_NOT_VERIFIED=${PASSPORT_ERROR_CODES.E_NOT_VERIFIED})`);
246
- }
247
- warnings.push(`result query requires tx_hash match current transaction (C-PASS-17, E_TX_NOT_MATCH=${PASSPORT_ERROR_CODES.E_TX_NOT_MATCH})`);
248
- if (operation.type === "result_for_guard") {
249
- const guardInfo = passport.info.find(g => g.guard === operation.guard);
250
- if (!guardInfo) {
251
- errors.push(`Guard ${operation.guard} not found in Passport (C-PASS-15)`);
252
- }
253
- else if (!guardInfo.impack) {
254
- errors.push(`Guard ${operation.guard} is not impack, result_for_guard will abort (C-PASS-10, E_NOT_IMPACK_GUARD=${PASSPORT_ERROR_CODES.E_NOT_IMPACK_GUARD})`);
255
- }
256
- }
257
- break;
258
- }
259
- case "submission_get": {
260
- break;
261
- }
262
- }
263
- return {
264
- errors,
265
- warnings,
266
- requiresConfirmation,
267
- canProceed: errors.length === 0,
268
- };
269
- }
270
- export function checkPassportStateConsistency(input) {
271
- const errors = [];
272
- const warnings = [];
273
- const { passport, guardObjects, isFrozen } = input;
274
- if (isFrozen) {
275
- errors.push("Passport is frozen (immutable), no write operations permitted (C-PASS-14)");
276
- }
277
- for (const g of passport.info) {
278
- if (!guardObjects.has(g.guard)) {
279
- warnings.push(`Guard ${g.guard} not found, verification may fail (C-PASS-15)`);
280
- }
281
- }
282
- if (!passport.has_verified) {
283
- warnings.push("Passport not yet verified — result queries will fail (C-PASS-16, E_NOT_VERIFIED)");
284
- }
285
- for (const g of passport.info) {
286
- const guardObj = guardObjects.get(g.guard);
287
- if (guardObj?.relies && guardObj.relies.length > 0) {
288
- const logic = guardObj.relies_logic_and === false ? "OR" : "AND";
289
- warnings.push(`Guard ${g.guard} relies on ${guardObj.relies.length} guards (${logic} logic) (C-PASS-18)`);
290
- }
291
- }
292
- const nonImpack = passport.info.filter(g => !g.impack);
293
- if (nonImpack.length > 0) {
294
- warnings.push(`${nonImpack.length} non-impack guards will not affect final result (C-PASS-19)`);
295
- }
296
- warnings.push("Passport does not emit events, must query object state directly (C-PASS-20)");
297
- return {
298
- errors,
299
- warnings,
300
- requiresConfirmation: [],
301
- canProceed: errors.length === 0,
302
- };
303
- }
304
- export const PASSPORT_CONFIRM_VERSION = "1.0.0";
305
- export function runPassportConfirmGate(input) {
306
- const layersPassed = [];
307
- const layersFailed = [];
308
- let riskAssessment;
309
- if (input.creation_input) {
310
- const creationResult = preCheckPassportCreation(input.creation_input);
311
- if (!creationResult.canProceed) {
312
- layersFailed.push("L1_creation");
313
- return {
314
- status: "blocked_creation",
315
- creation_result: creationResult,
316
- risk_assessment: riskAssessment,
317
- confirmation_text: generateConfirmationText(input, creationResult),
318
- block_reason: `Creation blocked: ${creationResult.errors.join("; ")}`,
319
- decision_record: {
320
- timestamp: new Date().toISOString(),
321
- gate_version: PASSPORT_CONFIRM_VERSION,
322
- final_status: "blocked_creation",
323
- layers_passed: layersPassed,
324
- layers_failed: layersFailed,
325
- },
326
- };
327
- }
328
- layersPassed.push("L1_creation");
329
- }
330
- if (input.operation_input) {
331
- const opResult = preCheckPassportOperation(input.operation_input);
332
- if (!opResult.canProceed) {
333
- layersFailed.push("L2_operation");
334
- return {
335
- status: "blocked_operation",
336
- operation_result: opResult,
337
- risk_assessment: riskAssessment,
338
- confirmation_text: generateConfirmationText(input, undefined, opResult),
339
- block_reason: `Operation blocked: ${opResult.errors.join("; ")}`,
340
- decision_record: {
341
- timestamp: new Date().toISOString(),
342
- gate_version: PASSPORT_CONFIRM_VERSION,
343
- final_status: "blocked_operation",
344
- layers_passed: layersPassed,
345
- layers_failed: layersFailed,
346
- },
347
- };
348
- }
349
- if (!input.skip_user_confirmation && opResult.requiresConfirmation.length > 0) {
350
- layersFailed.push("L2_operation_pending_confirmation");
351
- return {
352
- status: "pending_confirmation",
353
- operation_result: opResult,
354
- risk_assessment: riskAssessment,
355
- confirmation_text: generateConfirmationText(input, undefined, opResult),
356
- block_reason: `User confirmation required: ${opResult.requiresConfirmation.length} item(s)`,
357
- decision_record: {
358
- timestamp: new Date().toISOString(),
359
- gate_version: PASSPORT_CONFIRM_VERSION,
360
- final_status: "pending_confirmation",
361
- layers_passed: layersPassed,
362
- layers_failed: layersFailed,
363
- },
364
- };
365
- }
366
- layersPassed.push("L2_operation");
367
- }
368
- if (input.consistency_input) {
369
- const consResult = checkPassportStateConsistency(input.consistency_input);
370
- if (!consResult.canProceed) {
371
- layersFailed.push("L3_consistency");
372
- return {
373
- status: "blocked_consistency",
374
- consistency_result: consResult,
375
- risk_assessment: riskAssessment,
376
- confirmation_text: generateConfirmationText(input, undefined, undefined, consResult),
377
- block_reason: `Consistency blocked: ${consResult.errors.join("; ")}`,
378
- decision_record: {
379
- timestamp: new Date().toISOString(),
380
- gate_version: PASSPORT_CONFIRM_VERSION,
381
- final_status: "blocked_consistency",
382
- layers_passed: layersPassed,
383
- layers_failed: layersFailed,
384
- },
385
- };
386
- }
387
- layersPassed.push("L3_consistency");
388
- }
389
- if (!input.skip_risk_assessment && input.operation_input) {
390
- const riskCtx = {
391
- object: input.operation_input.passport.object,
392
- has_verified: input.operation_input.passport.has_verified,
393
- guard_count: input.operation_input.passport.info.length,
394
- has_impack_guard: input.operation_input.passport.info.some(g => g.impack),
395
- operation_type: input.operation_input.operation.type === "guard_add" ? "guard_add"
396
- : input.operation_input.operation.type === "verify" ? "verify"
397
- : input.operation_input.operation.type === "freezen" ? "freezen"
398
- : input.operation_input.operation.type === "destroy" ? "destroy"
399
- : "use",
400
- is_frozen: input.consistency_input?.isFrozen ?? false,
401
- matched_scenario: input.scenario,
402
- constants_synced: true,
403
- knowledge_files_present: true,
404
- };
405
- riskAssessment = assessPassportRisks(riskCtx);
406
- }
407
- return {
408
- status: "approved",
409
- creation_result: input.creation_input ? preCheckPassportCreation(input.creation_input) : undefined,
410
- operation_result: input.operation_input ? preCheckPassportOperation(input.operation_input) : undefined,
411
- consistency_result: input.consistency_input ? checkPassportStateConsistency(input.consistency_input) : undefined,
412
- risk_assessment: riskAssessment,
413
- confirmation_text: generateConfirmationText(input),
414
- decision_record: {
415
- timestamp: new Date().toISOString(),
416
- gate_version: PASSPORT_CONFIRM_VERSION,
417
- final_status: "approved",
418
- layers_passed: layersPassed,
419
- layers_failed: layersFailed,
420
- },
421
- };
422
- }
423
- function generateConfirmationText(input, creation, operation, consistency) {
424
- const lines = [];
425
- lines.push("═══ Passport Confirmation ═══");
426
- lines.push("");
427
- if (input.scenario) {
428
- lines.push(`Scenario: ${input.scenario.name}`);
429
- lines.push(`Consumer: ${input.scenario.consumer_object} (${input.scenario.sdk_entry})`);
430
- lines.push(`Purpose: ${input.scenario.passport_purpose}`);
431
- lines.push("");
432
- }
433
- if (creation) {
434
- lines.push("─ Layer 1: Creation ──────────────");
435
- if (creation.errors.length > 0) {
436
- for (const e of creation.errors)
437
- lines.push(` ✗ ${e}`);
438
- }
439
- else {
440
- lines.push(" ✓ All creation checks passed");
441
- }
442
- lines.push("");
443
- }
444
- if (operation) {
445
- lines.push("─ Layer 2: Operation ──────────────");
446
- if (operation.errors.length > 0) {
447
- for (const e of operation.errors)
448
- lines.push(` ✗ ${e}`);
449
- }
450
- if (operation.warnings.length > 0) {
451
- for (const w of operation.warnings)
452
- lines.push(` ⚠ ${w}`);
453
- }
454
- if (operation.requiresConfirmation.length > 0) {
455
- for (const c of operation.requiresConfirmation)
456
- lines.push(` ? ${c}`);
457
- }
458
- if (operation.errors.length === 0 && operation.warnings.length === 0 && operation.requiresConfirmation.length === 0) {
459
- lines.push(" ✓ All operation checks passed");
460
- }
461
- lines.push("");
462
- }
463
- if (consistency) {
464
- lines.push("─ Layer 3: Consistency ──────────────");
465
- if (consistency.errors.length > 0) {
466
- for (const e of consistency.errors)
467
- lines.push(` ✗ ${e}`);
468
- }
469
- if (consistency.warnings.length > 0) {
470
- for (const w of consistency.warnings)
471
- lines.push(` ⚠ ${w}`);
472
- }
473
- if (consistency.errors.length === 0 && consistency.warnings.length === 0) {
474
- lines.push(" ✓ All consistency checks passed");
475
- }
476
- lines.push("");
477
- }
478
- lines.push("─ Error Code Reference ──────────────");
479
- lines.push(` E_GUARD_COUNT_EXCEEDED=${PASSPORT_ERROR_CODES.E_GUARD_COUNT_EXCEEDED}, E_RELIES_GUARD_NOT_ADDED=${PASSPORT_ERROR_CODES.E_RELIES_GUARD_NOT_ADDED}, E_SUBMISSION_SIZE_EXCEEDED=${PASSPORT_ERROR_CODES.E_SUBMISSION_SIZE_EXCEEDED}`);
480
- lines.push(` E_HAS_VERIFIED=${PASSPORT_ERROR_CODES.E_HAS_VERIFIED}, E_NOT_VERIFIED=${PASSPORT_ERROR_CODES.E_NOT_VERIFIED}, E_NOT_IMPACK_GUARD=${PASSPORT_ERROR_CODES.E_NOT_IMPACK_GUARD}`);
481
- lines.push(` E_VERIFY_FAILED=${PASSPORT_ERROR_CODES.E_VERIFY_FAILED}, E_TX_NOT_MATCH=${PASSPORT_ERROR_CODES.E_TX_NOT_MATCH}, E_IMPACK_GUARD_NOT_FOUND=${PASSPORT_ERROR_CODES.E_IMPACK_GUARD_NOT_FOUND}`);
482
- lines.push(` E_SUBMISSION_NOT_FOUND=${PASSPORT_ERROR_CODES.E_SUBMISSION_NOT_FOUND}, E_DIGEST_NOT_MATCH=${PASSPORT_ERROR_CODES.E_DIGEST_NOT_MATCH}`);
483
- lines.push("");
484
- return lines.join("\n");
485
- }
486
- export function estimateSubmissionSize(submission) {
487
- let total = 0;
488
- for (const item of submission) {
489
- total += 1;
490
- switch (item.value_type) {
491
- case "bool":
492
- total += 1;
493
- break;
494
- case "u8":
495
- total += 1;
496
- break;
497
- case "u64":
498
- total += 8;
499
- break;
500
- case "address":
501
- total += 32;
502
- break;
503
- case "string": {
504
- const len = typeof item.value === "string" ? item.value.length : 0;
505
- total += 1 + len;
506
- break;
507
- }
508
- case "vector<u8>": {
509
- const len = Array.isArray(item.value) ? item.value.length : 0;
510
- total += 1 + len;
511
- break;
512
- }
513
- default:
514
- total += 64;
515
- }
516
- }
517
- return total;
518
- }
519
- export function getAllConfirmationRules() {
520
- return [
521
- ...PASSPORT_CONFIRMATION_RULES.creation,
522
- ...PASSPORT_CONFIRMATION_RULES.operation,
523
- ...PASSPORT_CONFIRMATION_RULES.consistency,
524
- ];
525
- }
526
- export function getConfirmationRulesByLayer(layer) {
527
- return PASSPORT_CONFIRMATION_RULES[layer];
528
- }
529
- export function getConfirmationRuleById(id) {
530
- return getAllConfirmationRules().find(r => r.id === id);
531
- }
1
+ import{MAX_GUARD_COUNT_PASSPORT,MAX_SUBMISSION_SIZE_PASSPORT,PASSPORT_ERROR_CODES}from'./passport-ledger.js';import{assessPassportRisks}from'./passport-risk.js';export const PASSPORT_CONFIRMATION_RULES={'creation':[{'id':'C-PASS-01','check':'Confirm\x20Clock\x20object\x20is\x20accessible\x20(new\x20requires\x20Clock\x20argument)','severity':'HIGH','action':'block','layer':'creation'},{'id':'C-PASS-02','check':'Confirm\x20current\x20transaction\x20context\x20is\x20valid\x20(tx_hash\x20will\x20bind\x20to\x20this\x20transaction)','severity':'CRITICAL','action':'block','layer':'creation'}],'operation':[{'id':'C-PASS-03','check':'guard_add:\x20confirm\x20has_verified=false\x20(E_HAS_VERIFIED)','severity':'CRITICAL','action':'block','related_error':'E_HAS_VERIFIED\x20(4)','layer':'operation'},{'id':'C-PASS-04','check':'guard_add:\x20confirm\x20tx_hash\x20matches\x20current\x20transaction\x20(E_DIGEST_NOT_MATCH)','severity':'CRITICAL','action':'block','related_error':'E_DIGEST_NOT_MATCH\x20(11)','layer':'operation'},{'id':'C-PASS-05','check':'guard_add:\x20confirm\x20depended-on\x20Guards\x20already\x20added\x20(E_RELIES_GUARD_NOT_ADDED)','severity':'HIGH','action':'block','related_error':'E_RELIES_GUARD_NOT_ADDED\x20(2)','layer':'operation'},{'id':'C-PASS-06','check':'guard_add:\x20warn\x20Guard\x20count\x20approaching\x20MAX_GUARD_COUNT=20\x20limit','severity':'MEDIUM','action':'warn','related_error':'E_GUARD_COUNT_EXCEEDED\x20(1)','layer':'operation'},{'id':'C-PASS-07','check':'guard_add:\x20warn\x20impack\x20Guard\x20failure\x20will\x20cause\x20overall\x20result=false','severity':'HIGH','action':'warn','layer':'operation'},{'id':'C-PASS-08','check':'guard_add:\x20warn\x20submission\x20serialized\x20size\x20must\x20be\x20≤\x20256\x20bytes','severity':'MEDIUM','action':'warn','related_error':'E_SUBMISSION_SIZE_EXCEEDED\x20(3)','layer':'operation'},{'id':'C-PASS-09','check':'verify:\x20warn\x20this\x20is\x20a\x20one-time\x20operation;\x20after\x20verify,\x20configuration\x20cannot\x20be\x20modified','severity':'HIGH','action':'confirm_twice','related_error':'E_HAS_VERIFIED\x20(4)','layer':'operation'},{'id':'C-PASS-10','check':'verify:\x20confirm\x20at\x20least\x201\x20impack\x20Guard\x20exists\x20(E_IMPACK_GUARD_NOT_FOUND)','severity':'CRITICAL','action':'block','related_error':'E_IMPACK_GUARD_NOT_FOUND\x20(9)','layer':'operation'},{'id':'C-PASS-11','check':'guard_clear:\x20warn\x20this\x20will\x20clear\x20all\x20Guards\x20(allowed\x20before\x20verify)','severity':'MEDIUM','action':'confirm_twice','layer':'operation'},{'id':'C-PASS-12','check':'freezen:\x20warn\x20after\x20freezing,\x20Passport\x20is\x20permanently\x20retained\x20and\x20cannot\x20be\x20destroyed','severity':'MEDIUM','action':'confirm_twice','layer':'operation'},{'id':'C-PASS-13','check':'destroy:\x20warn\x20Passport\x20cannot\x20be\x20recovered\x20after\x20destruction\x20(must\x20be\x20before\x20freeze)','severity':'HIGH','action':'confirm_twice','layer':'operation'}],'consistency':[{'id':'C-PASS-14','check':'Confirm\x20Passport\x20object\x20is\x20not\x20frozen\x20(no\x20operations\x20allowed\x20after\x20freeze)','severity':'HIGH','action':'block','layer':'consistency'},{'id':'C-PASS-15','check':'Confirm\x20referenced\x20Guard\x20objects\x20have\x20not\x20been\x20deleted','severity':'HIGH','action':'block','layer':'consistency'},{'id':'C-PASS-16','check':'Confirm\x20has_verified=true\x20when\x20querying\x20result\x20(E_NOT_VERIFIED)','severity':'HIGH','action':'block','related_error':'E_NOT_VERIFIED\x20(5)','layer':'consistency'},{'id':'C-PASS-17','check':'Confirm\x20tx_hash\x20matches\x20current\x20transaction\x20when\x20querying\x20result\x20(E_TX_NOT_MATCH)','severity':'CRITICAL','action':'block','related_error':'E_TX_NOT_MATCH\x20(8)','layer':'consistency'},{'id':'C-PASS-18','check':'Info:\x20relies\x20dependencies\x20(avoid\x20circular\x20dependencies)','severity':'INFO','action':'info','layer':'consistency'},{'id':'C-PASS-19','check':'Warn:\x20non-impack\x20Guard\x20result\x20does\x20not\x20affect\x20final\x20result','severity':'INFO','action':'info','layer':'consistency'},{'id':'C-PASS-20','check':'Info:\x20Passport\x20emits\x20no\x20events;\x20status\x20must\x20be\x20queried\x20actively','severity':'INFO','action':'info','layer':'consistency'}]};export function preCheckPassportCreation(a){const b=[],c=[],d=[];return!a['clock']&&b['push']('Clock\x20object\x20is\x20required\x20for\x20Passport\x20creation\x20(C-PASS-01,\x20passport::new\x20requires\x20Clock\x20argument)'),!a['txDigest']&&b['push']('Valid\x20transaction\x20context\x20required\x20—\x20tx_hash\x20will\x20bind\x20to\x20this\x20transaction\x20(C-PASS-02)'),{'errors':b,'warnings':c,'requiresConfirmation':d,'canProceed':b['length']===0x0};}export function preCheckPassportOperation(a){const b=[],c=[],d=[],{passport:e,operation:f,guardObjects:g}=a;switch(f['type']){case'guard_add':{if(e['has_verified']){b['push']('Passport\x20already\x20verified,\x20cannot\x20add\x20guard\x20(C-PASS-03,\x20E_HAS_VERIFIED='+PASSPORT_ERROR_CODES['E_HAS_VERIFIED']+')');break;}c['push']('tx_hash\x20must\x20match\x20current\x20transaction\x20(C-PASS-04,\x20E_DIGEST_NOT_MATCH='+PASSPORT_ERROR_CODES['E_DIGEST_NOT_MATCH']+')');const h=g['get'](f['guard']);if(h?.['relies']&&h['relies']['length']>0x0)for(const i of h['relies']){const j=e['info']['some'](k=>k['guard']===i);!j&&b['push']('Dependency\x20Guard\x20'+i+'\x20not\x20added\x20yet\x20(C-PASS-05,\x20E_RELIES_GUARD_NOT_ADDED='+PASSPORT_ERROR_CODES['E_RELIES_GUARD_NOT_ADDED']+')');}if(e['info']['length']>=MAX_GUARD_COUNT_PASSPORT)b['push']('Guard\x20count\x20'+e['info']['length']+'\x20>=\x20MAX_GUARD_COUNT_PASSPORT='+MAX_GUARD_COUNT_PASSPORT+'\x20(C-PASS-06,\x20E_GUARD_COUNT_EXCEEDED='+PASSPORT_ERROR_CODES['E_GUARD_COUNT_EXCEEDED']+')');else e['info']['length']>=MAX_GUARD_COUNT_PASSPORT-0x5&&c['push']('Guard\x20count\x20'+e['info']['length']+'\x20approaching\x20limit\x20'+MAX_GUARD_COUNT_PASSPORT+'\x20(C-PASS-06)');f['impack']&&c['push']('impack=true\x20Guard\x20failure\x20will\x20cause\x20overall\x20result=false\x20(C-PASS-07)');if(f['submission']){const k=estimateSubmissionSize(f['submission']);if(k>MAX_SUBMISSION_SIZE_PASSPORT)b['push']('Submission\x20size\x20'+k+'\x20>\x20MAX_SUBMISSION_SIZE_PASSPORT='+MAX_SUBMISSION_SIZE_PASSPORT+'\x20(C-PASS-08,\x20E_SUBMISSION_SIZE_EXCEEDED='+PASSPORT_ERROR_CODES['E_SUBMISSION_SIZE_EXCEEDED']+')');else k>MAX_SUBMISSION_SIZE_PASSPORT*0.8&&c['push']('Submission\x20size\x20'+k+'\x20approaching\x20limit\x20'+MAX_SUBMISSION_SIZE_PASSPORT+'\x20(C-PASS-08)');}break;}case'verify':{d['push']('WARNING:\x20verify\x20is\x20ONE-TIME\x20operation.\x20After\x20verify,\x20guard\x20configuration\x20cannot\x20be\x20modified.\x20Type\x20\x27CONFIRM\x27\x20to\x20proceed.\x20(C-PASS-09)');const l=e['info']['some'](m=>m['impack']);!l&&b['push']('No\x20impack\x20Guard\x20found,\x20verify\x20will\x20fail\x20(C-PASS-10,\x20E_IMPACK_GUARD_NOT_FOUND='+PASSPORT_ERROR_CODES['E_IMPACK_GUARD_NOT_FOUND']+')');break;}case'guard_clear':{d['push']('WARNING:\x20guard_clear\x20will\x20remove\x20all\x20'+e['info']['length']+'\x20guards.\x20Type\x20\x27CONFIRM\x27\x20to\x20proceed.\x20(C-PASS-11)');e['has_verified']&&b['push']('Passport\x20already\x20verified,\x20cannot\x20clear\x20guards\x20(C-PASS-11,\x20E_HAS_VERIFIED='+PASSPORT_ERROR_CODES['E_HAS_VERIFIED']+')');break;}case'freezen':{d['push']('WARNING:\x20freezen\x20will\x20PERMANENTLY\x20freeze\x20the\x20Passport.\x20It\x20cannot\x20be\x20destroyed\x20after\x20freezing.\x20Type\x20\x27CONFIRM\x27\x20to\x20proceed.\x20(C-PASS-12)');break;}case'destroy':{d['push']('WARNING:\x20destroy\x20will\x20delete\x20the\x20Passport\x20permanently.\x20This\x20must\x20be\x20done\x20BEFORE\x20freezing.\x20Type\x20\x27CONFIRM\x27\x20to\x20proceed.\x20(C-PASS-13)');break;}case'result_query':case'result_for_guard':case'result_for_permission':{!e['has_verified']&&b['push']('result\x20query\x20requires\x20has_verified=true\x20(C-PASS-16,\x20E_NOT_VERIFIED='+PASSPORT_ERROR_CODES['E_NOT_VERIFIED']+')');c['push']('result\x20query\x20requires\x20tx_hash\x20match\x20current\x20transaction\x20(C-PASS-17,\x20E_TX_NOT_MATCH='+PASSPORT_ERROR_CODES['E_TX_NOT_MATCH']+')');if(f['type']==='result_for_guard'){const m=e['info']['find'](n=>n['guard']===f['guard']);if(!m)b['push']('Guard\x20'+f['guard']+'\x20not\x20found\x20in\x20Passport\x20(C-PASS-15)');else!m['impack']&&b['push']('Guard\x20'+f['guard']+'\x20is\x20not\x20impack,\x20result_for_guard\x20will\x20abort\x20(C-PASS-10,\x20E_NOT_IMPACK_GUARD='+PASSPORT_ERROR_CODES['E_NOT_IMPACK_GUARD']+')');}break;}case'submission_get':{break;}}return{'errors':b,'warnings':c,'requiresConfirmation':d,'canProceed':b['length']===0x0};}export function checkPassportStateConsistency(a){const b=[],c=[],{passport:d,guardObjects:e,isFrozen:f}=a;f&&b['push']('Passport\x20is\x20frozen\x20(immutable),\x20no\x20write\x20operations\x20permitted\x20(C-PASS-14)');for(const i of d['info']){!e['has'](i['guard'])&&c['push']('Guard\x20'+i['guard']+'\x20not\x20found,\x20verification\x20may\x20fail\x20(C-PASS-15)');}!d['has_verified']&&c['push']('Passport\x20not\x20yet\x20verified\x20—\x20result\x20queries\x20will\x20fail\x20(C-PASS-16,\x20E_NOT_VERIFIED)');for(const j of d['info']){const k=e['get'](j['guard']);if(k?.['relies']&&k['relies']['length']>0x0){const l=k['relies_logic_and']===![]?'OR':'AND';c['push']('Guard\x20'+j['guard']+'\x20relies\x20on\x20'+k['relies']['length']+'\x20guards\x20('+l+'\x20logic)\x20(C-PASS-18)');}}const h=d['info']['filter'](m=>!m['impack']);return h['length']>0x0&&c['push'](h['length']+'\x20non-impack\x20guards\x20will\x20not\x20affect\x20final\x20result\x20(C-PASS-19)'),c['push']('Passport\x20does\x20not\x20emit\x20events,\x20must\x20query\x20object\x20state\x20directly\x20(C-PASS-20)'),{'errors':b,'warnings':c,'requiresConfirmation':[],'canProceed':b['length']===0x0};}export const PASSPORT_CONFIRM_VERSION='1.0.0';export function runPassportConfirmGate(a){const b=[],c=[];let d;if(a['creation_input']){const e=preCheckPassportCreation(a['creation_input']);if(!e['canProceed'])return c['push']('L1_creation'),{'status':'blocked_creation','creation_result':e,'risk_assessment':d,'confirmation_text':generateConfirmationText(a,e),'block_reason':'Creation\x20blocked:\x20'+e['errors']['join'](';\x20'),'decision_record':{'timestamp':new Date()['toISOString'](),'gate_version':PASSPORT_CONFIRM_VERSION,'final_status':'blocked_creation','layers_passed':b,'layers_failed':c}};b['push']('L1_creation');}if(a['operation_input']){const f=preCheckPassportOperation(a['operation_input']);if(!f['canProceed'])return c['push']('L2_operation'),{'status':'blocked_operation','operation_result':f,'risk_assessment':d,'confirmation_text':generateConfirmationText(a,undefined,f),'block_reason':'Operation\x20blocked:\x20'+f['errors']['join'](';\x20'),'decision_record':{'timestamp':new Date()['toISOString'](),'gate_version':PASSPORT_CONFIRM_VERSION,'final_status':'blocked_operation','layers_passed':b,'layers_failed':c}};if(!a['skip_user_confirmation']&&f['requiresConfirmation']['length']>0x0)return c['push']('L2_operation_pending_confirmation'),{'status':'pending_confirmation','operation_result':f,'risk_assessment':d,'confirmation_text':generateConfirmationText(a,undefined,f),'block_reason':'User\x20confirmation\x20required:\x20'+f['requiresConfirmation']['length']+'\x20item(s)','decision_record':{'timestamp':new Date()['toISOString'](),'gate_version':PASSPORT_CONFIRM_VERSION,'final_status':'pending_confirmation','layers_passed':b,'layers_failed':c}};b['push']('L2_operation');}if(a['consistency_input']){const g=checkPassportStateConsistency(a['consistency_input']);if(!g['canProceed'])return c['push']('L3_consistency'),{'status':'blocked_consistency','consistency_result':g,'risk_assessment':d,'confirmation_text':generateConfirmationText(a,undefined,undefined,g),'block_reason':'Consistency\x20blocked:\x20'+g['errors']['join'](';\x20'),'decision_record':{'timestamp':new Date()['toISOString'](),'gate_version':PASSPORT_CONFIRM_VERSION,'final_status':'blocked_consistency','layers_passed':b,'layers_failed':c}};b['push']('L3_consistency');}if(!a['skip_risk_assessment']&&a['operation_input']){const h={'object':a['operation_input']['passport']['object'],'has_verified':a['operation_input']['passport']['has_verified'],'guard_count':a['operation_input']['passport']['info']['length'],'has_impack_guard':a['operation_input']['passport']['info']['some'](i=>i['impack']),'operation_type':a['operation_input']['operation']['type']==='guard_add'?'guard_add':a['operation_input']['operation']['type']==='verify'?'verify':a['operation_input']['operation']['type']==='freezen'?'freezen':a['operation_input']['operation']['type']==='destroy'?'destroy':'use','is_frozen':a['consistency_input']?.['isFrozen']??![],'matched_scenario':a['scenario'],'constants_synced':!![],'knowledge_files_present':!![]};d=assessPassportRisks(h);}return{'status':'approved','creation_result':a['creation_input']?preCheckPassportCreation(a['creation_input']):undefined,'operation_result':a['operation_input']?preCheckPassportOperation(a['operation_input']):undefined,'consistency_result':a['consistency_input']?checkPassportStateConsistency(a['consistency_input']):undefined,'risk_assessment':d,'confirmation_text':generateConfirmationText(a),'decision_record':{'timestamp':new Date()['toISOString'](),'gate_version':PASSPORT_CONFIRM_VERSION,'final_status':'approved','layers_passed':b,'layers_failed':c}};}function generateConfirmationText(a,b,d,f){const g=[];g['push']('═══\x20Passport\x20Confirmation\x20═══'),g['push']('');a['scenario']&&(g['push']('Scenario:\x20'+a['scenario']['name']),g['push']('Consumer:\x20'+a['scenario']['consumer_object']+'\x20('+a['scenario']['sdk_entry']+')'),g['push']('Purpose:\x20'+a['scenario']['passport_purpose']),g['push'](''));if(b){g['push']('─\x20Layer\x201:\x20Creation\x20──────────────');if(b['errors']['length']>0x0){for(const h of b['errors'])g['push']('\x20\x20✗\x20'+h);}else g['push']('\x20\x20✓\x20All\x20creation\x20checks\x20passed');g['push']('');}if(d){g['push']('─\x20Layer\x202:\x20Operation\x20──────────────');if(d['errors']['length']>0x0){for(const i of d['errors'])g['push']('\x20\x20✗\x20'+i);}if(d['warnings']['length']>0x0){for(const j of d['warnings'])g['push']('\x20\x20⚠\x20'+j);}if(d['requiresConfirmation']['length']>0x0){for(const k of d['requiresConfirmation'])g['push']('\x20\x20?\x20'+k);}d['errors']['length']===0x0&&d['warnings']['length']===0x0&&d['requiresConfirmation']['length']===0x0&&g['push']('\x20\x20✓\x20All\x20operation\x20checks\x20passed'),g['push']('');}if(f){g['push']('─\x20Layer\x203:\x20Consistency\x20──────────────');if(f['errors']['length']>0x0){for(const l of f['errors'])g['push']('\x20\x20✗\x20'+l);}if(f['warnings']['length']>0x0){for(const m of f['warnings'])g['push']('\x20\x20⚠\x20'+m);}f['errors']['length']===0x0&&f['warnings']['length']===0x0&&g['push']('\x20\x20✓\x20All\x20consistency\x20checks\x20passed'),g['push']('');}return g['push']('─\x20Error\x20Code\x20Reference\x20──────────────'),g['push']('\x20\x20E_GUARD_COUNT_EXCEEDED='+PASSPORT_ERROR_CODES['E_GUARD_COUNT_EXCEEDED']+',\x20E_RELIES_GUARD_NOT_ADDED='+PASSPORT_ERROR_CODES['E_RELIES_GUARD_NOT_ADDED']+',\x20E_SUBMISSION_SIZE_EXCEEDED='+PASSPORT_ERROR_CODES['E_SUBMISSION_SIZE_EXCEEDED']),g['push']('\x20\x20E_HAS_VERIFIED='+PASSPORT_ERROR_CODES['E_HAS_VERIFIED']+',\x20E_NOT_VERIFIED='+PASSPORT_ERROR_CODES['E_NOT_VERIFIED']+',\x20E_NOT_IMPACK_GUARD='+PASSPORT_ERROR_CODES['E_NOT_IMPACK_GUARD']),g['push']('\x20\x20E_VERIFY_FAILED='+PASSPORT_ERROR_CODES['E_VERIFY_FAILED']+',\x20E_TX_NOT_MATCH='+PASSPORT_ERROR_CODES['E_TX_NOT_MATCH']+',\x20E_IMPACK_GUARD_NOT_FOUND='+PASSPORT_ERROR_CODES['E_IMPACK_GUARD_NOT_FOUND']),g['push']('\x20\x20E_SUBMISSION_NOT_FOUND='+PASSPORT_ERROR_CODES['E_SUBMISSION_NOT_FOUND']+',\x20E_DIGEST_NOT_MATCH='+PASSPORT_ERROR_CODES['E_DIGEST_NOT_MATCH']),g['push'](''),g['join']('\x0a');}export function estimateSubmissionSize(a){let b=0x0;for(const c of a){b+=0x1;switch(c['value_type']){case'bool':b+=0x1;break;case'u8':b+=0x1;break;case'u64':b+=0x8;break;case'address':b+=0x20;break;case'string':{const d=typeof c['value']==='string'?c['value']['length']:0x0;b+=0x1+d;break;}case'vector<u8>':{const e=Array['isArray'](c['value'])?c['value']['length']:0x0;b+=0x1+e;break;}default:b+=0x40;}}return b;}export function getAllConfirmationRules(){return[...PASSPORT_CONFIRMATION_RULES['creation'],...PASSPORT_CONFIRMATION_RULES['operation'],...PASSPORT_CONFIRMATION_RULES['consistency']];}export function getConfirmationRulesByLayer(a){return PASSPORT_CONFIRMATION_RULES[a];}export function getConfirmationRuleById(a){return getAllConfirmationRules()['find'](b=>b['id']===a);}