@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.
- package/dist/config/runtime.d.ts +4 -0
- package/dist/config/runtime.js +29 -5
- package/dist/harness/auto-escalation.d.ts +27 -0
- package/dist/harness/auto-escalation.js +68 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +29 -1621
- package/dist/knowledge/allocation-confirm.d.ts +115 -0
- package/dist/knowledge/allocation-confirm.js +534 -0
- package/dist/knowledge/allocation-context.d.ts +58 -0
- package/dist/knowledge/allocation-context.js +249 -0
- package/dist/knowledge/allocation-ledger.d.ts +67 -0
- package/dist/knowledge/allocation-ledger.js +463 -0
- package/dist/knowledge/allocation-puzzle.d.ts +135 -0
- package/dist/knowledge/allocation-puzzle.js +298 -0
- package/dist/knowledge/allocation-risk.d.ts +78 -0
- package/dist/knowledge/allocation-risk.js +568 -0
- package/dist/knowledge/allocation-templates.d.ts +38 -0
- package/dist/knowledge/allocation-templates.js +970 -0
- package/dist/knowledge/allocation-translation.d.ts +72 -0
- package/dist/knowledge/allocation-translation.js +585 -0
- package/dist/knowledge/arb-risk.d.ts +37 -0
- package/dist/knowledge/arb-risk.js +210 -0
- package/dist/knowledge/arbitration-confirm.d.ts +135 -0
- package/dist/knowledge/arbitration-confirm.js +559 -0
- package/dist/knowledge/arbitration-context.d.ts +81 -0
- package/dist/knowledge/arbitration-context.js +505 -0
- package/dist/knowledge/arbitration-ledger.d.ts +62 -0
- package/dist/knowledge/arbitration-ledger.js +521 -0
- package/dist/knowledge/arbitration-puzzle.d.ts +84 -0
- package/dist/knowledge/arbitration-puzzle.js +304 -0
- package/dist/knowledge/arbitration-risk.d.ts +112 -0
- package/dist/knowledge/arbitration-risk.js +433 -0
- package/dist/knowledge/arbitration-templates.d.ts +38 -0
- package/dist/knowledge/arbitration-templates.js +276 -0
- package/dist/knowledge/arbitration-translation.d.ts +91 -0
- package/dist/knowledge/arbitration-translation.js +487 -0
- package/dist/knowledge/bridge-risk.d.ts +36 -0
- package/dist/knowledge/bridge-risk.js +263 -0
- package/dist/knowledge/contact-risk.d.ts +32 -0
- package/dist/knowledge/contact-risk.js +200 -0
- package/dist/knowledge/demand-confirm.d.ts +32 -0
- package/dist/knowledge/demand-confirm.js +206 -0
- package/dist/knowledge/demand-risk.d.ts +30 -0
- package/dist/knowledge/demand-risk.js +240 -0
- package/dist/knowledge/demand-translation.d.ts +55 -0
- package/dist/knowledge/demand-translation.js +354 -0
- package/dist/knowledge/deployment-scanner.d.ts +63 -0
- package/dist/knowledge/deployment-scanner.js +762 -0
- package/dist/knowledge/examples-scanner-cli.d.ts +1 -0
- package/dist/knowledge/examples-scanner-cli.js +26 -0
- package/dist/knowledge/examples-scanner.d.ts +121 -0
- package/dist/knowledge/examples-scanner.js +825 -0
- package/dist/knowledge/flywheel-loop.d.ts +3 -0
- package/dist/knowledge/flywheel-loop.js +32 -3
- package/dist/knowledge/glossary.js +3 -1
- package/dist/knowledge/guard-confirm.d.ts +86 -0
- package/dist/knowledge/guard-confirm.js +406 -0
- package/dist/knowledge/guard-context.d.ts +56 -0
- package/dist/knowledge/guard-context.js +287 -0
- package/dist/knowledge/guard-design-patterns.d.ts +37 -0
- package/dist/knowledge/guard-design-patterns.js +257 -0
- package/dist/knowledge/guard-ledger.js +14 -0
- package/dist/knowledge/guard-lint.d.ts +1 -0
- package/dist/knowledge/guard-lint.js +83 -3
- package/dist/knowledge/guard-migration.d.ts +48 -0
- package/dist/knowledge/guard-migration.js +228 -0
- package/dist/knowledge/guard-puzzle.js +3 -2
- package/dist/knowledge/guard-risk.d.ts +3 -1
- package/dist/knowledge/guard-risk.js +832 -64
- package/dist/knowledge/guard-templates.d.ts +1 -0
- package/dist/knowledge/guard-templates.js +278 -2
- package/dist/knowledge/guard-translation.js +6 -5
- package/dist/knowledge/index.d.ts +342 -0
- package/dist/knowledge/index.js +344 -0
- package/dist/knowledge/machine-confirm.d.ts +102 -0
- package/dist/knowledge/machine-confirm.js +559 -0
- package/dist/knowledge/machine-context.d.ts +160 -0
- package/dist/knowledge/machine-context.js +812 -0
- package/dist/knowledge/machine-ledger.d.ts +41 -0
- package/dist/knowledge/machine-ledger.js +315 -0
- package/dist/knowledge/machine-puzzle.d.ts +206 -0
- package/dist/knowledge/machine-puzzle.js +494 -0
- package/dist/knowledge/machine-risk.d.ts +75 -0
- package/dist/knowledge/machine-risk.js +644 -0
- package/dist/knowledge/machine-templates.d.ts +92 -0
- package/dist/knowledge/machine-templates.js +1592 -0
- package/dist/knowledge/machine-topology.d.ts +57 -0
- package/dist/knowledge/machine-topology.js +234 -0
- package/dist/knowledge/machine-translation.d.ts +96 -0
- package/dist/knowledge/machine-translation.js +513 -0
- package/dist/knowledge/mcp-schema-audit-cli.d.ts +1 -0
- package/dist/knowledge/mcp-schema-audit-cli.js +45 -0
- package/dist/knowledge/mcp-schema-audit.d.ts +90 -0
- package/dist/knowledge/mcp-schema-audit.js +772 -0
- package/dist/knowledge/onchain-constants.d.ts +4 -0
- package/dist/knowledge/onchain-constants.js +35 -0
- package/dist/knowledge/order-confirm.d.ts +115 -0
- package/dist/knowledge/order-confirm.js +573 -0
- package/dist/knowledge/order-context.d.ts +66 -0
- package/dist/knowledge/order-context.js +390 -0
- package/dist/knowledge/order-ledger.d.ts +69 -0
- package/dist/knowledge/order-ledger.js +341 -0
- package/dist/knowledge/order-puzzle.d.ts +159 -0
- package/dist/knowledge/order-puzzle.js +255 -0
- package/dist/knowledge/order-risk.d.ts +66 -0
- package/dist/knowledge/order-risk.js +653 -0
- package/dist/knowledge/order-templates.d.ts +50 -0
- package/dist/knowledge/order-templates.js +368 -0
- package/dist/knowledge/order-translation.d.ts +78 -0
- package/dist/knowledge/order-translation.js +550 -0
- package/dist/knowledge/passport-confirm.d.ts +130 -0
- package/dist/knowledge/passport-confirm.js +531 -0
- package/dist/knowledge/passport-context.d.ts +59 -0
- package/dist/knowledge/passport-context.js +306 -0
- package/dist/knowledge/passport-ledger.d.ts +48 -0
- package/dist/knowledge/passport-ledger.js +282 -0
- package/dist/knowledge/passport-puzzle.d.ts +108 -0
- package/dist/knowledge/passport-puzzle.js +333 -0
- package/dist/knowledge/passport-risk.d.ts +70 -0
- package/dist/knowledge/passport-risk.js +450 -0
- package/dist/knowledge/passport-templates.d.ts +40 -0
- package/dist/knowledge/passport-templates.js +568 -0
- package/dist/knowledge/passport-translation.d.ts +68 -0
- package/dist/knowledge/passport-translation.js +516 -0
- package/dist/knowledge/payment-risk.d.ts +33 -0
- package/dist/knowledge/payment-risk.js +182 -0
- package/dist/knowledge/permission-confirm.d.ts +110 -0
- package/dist/knowledge/permission-confirm.js +426 -0
- package/dist/knowledge/permission-context.d.ts +58 -0
- package/dist/knowledge/permission-context.js +224 -0
- package/dist/knowledge/permission-ledger.d.ts +38 -0
- package/dist/knowledge/permission-ledger.js +403 -0
- package/dist/knowledge/permission-puzzle.d.ts +122 -0
- package/dist/knowledge/permission-puzzle.js +173 -0
- package/dist/knowledge/permission-risk.d.ts +76 -0
- package/dist/knowledge/permission-risk.js +411 -0
- package/dist/knowledge/permission-templates.d.ts +38 -0
- package/dist/knowledge/permission-templates.js +234 -0
- package/dist/knowledge/permission-translation.d.ts +57 -0
- package/dist/knowledge/permission-translation.js +350 -0
- package/dist/knowledge/personal-risk.d.ts +36 -0
- package/dist/knowledge/personal-risk.js +212 -0
- package/dist/knowledge/progress-confirm.d.ts +108 -0
- package/dist/knowledge/progress-confirm.js +456 -0
- package/dist/knowledge/progress-context.d.ts +123 -0
- package/dist/knowledge/progress-context.js +452 -0
- package/dist/knowledge/progress-ledger.d.ts +63 -0
- package/dist/knowledge/progress-ledger.js +327 -0
- package/dist/knowledge/progress-puzzle.d.ts +82 -0
- package/dist/knowledge/progress-puzzle.js +219 -0
- package/dist/knowledge/progress-risk.d.ts +74 -0
- package/dist/knowledge/progress-risk.js +461 -0
- package/dist/knowledge/progress-templates.d.ts +38 -0
- package/dist/knowledge/progress-templates.js +228 -0
- package/dist/knowledge/progress-translation.d.ts +52 -0
- package/dist/knowledge/progress-translation.js +401 -0
- package/dist/knowledge/proof-confirm.d.ts +31 -0
- package/dist/knowledge/proof-confirm.js +187 -0
- package/dist/knowledge/proof-risk.d.ts +33 -0
- package/dist/knowledge/proof-risk.js +207 -0
- package/dist/knowledge/proof-translation.d.ts +52 -0
- package/dist/knowledge/proof-translation.js +283 -0
- package/dist/knowledge/registrar-risk.d.ts +34 -0
- package/dist/knowledge/registrar-risk.js +217 -0
- package/dist/knowledge/repository-confirm.d.ts +36 -0
- package/dist/knowledge/repository-confirm.js +242 -0
- package/dist/knowledge/repository-risk.d.ts +40 -0
- package/dist/knowledge/repository-risk.js +312 -0
- package/dist/knowledge/repository-translation.d.ts +58 -0
- package/dist/knowledge/repository-translation.js +422 -0
- package/dist/knowledge/resource-risk.d.ts +32 -0
- package/dist/knowledge/resource-risk.js +157 -0
- package/dist/knowledge/reward-confirm.d.ts +113 -0
- package/dist/knowledge/reward-confirm.js +496 -0
- package/dist/knowledge/reward-context.d.ts +127 -0
- package/dist/knowledge/reward-context.js +504 -0
- package/dist/knowledge/reward-ledger.d.ts +96 -0
- package/dist/knowledge/reward-ledger.js +502 -0
- package/dist/knowledge/reward-puzzle.d.ts +97 -0
- package/dist/knowledge/reward-puzzle.js +288 -0
- package/dist/knowledge/reward-risk.d.ts +84 -0
- package/dist/knowledge/reward-risk.js +545 -0
- package/dist/knowledge/reward-translation.d.ts +58 -0
- package/dist/knowledge/reward-translation.js +501 -0
- package/dist/knowledge/safety-rules.js +11 -3
- package/dist/knowledge/scenario-modes.d.ts +53 -0
- package/dist/knowledge/scenario-modes.js +302 -0
- package/dist/knowledge/service-confirm.d.ts +152 -0
- package/dist/knowledge/service-confirm.js +699 -0
- package/dist/knowledge/service-context.d.ts +66 -0
- package/dist/knowledge/service-context.js +403 -0
- package/dist/knowledge/service-ledger.d.ts +71 -0
- package/dist/knowledge/service-ledger.js +609 -0
- package/dist/knowledge/service-puzzle.d.ts +158 -0
- package/dist/knowledge/service-puzzle.js +236 -0
- package/dist/knowledge/service-risk.d.ts +108 -0
- package/dist/knowledge/service-risk.js +615 -0
- package/dist/knowledge/service-templates.d.ts +39 -0
- package/dist/knowledge/service-templates.js +418 -0
- package/dist/knowledge/service-translation.d.ts +103 -0
- package/dist/knowledge/service-translation.js +622 -0
- package/dist/knowledge/tools-reference.d.ts +17 -0
- package/dist/knowledge/tools-reference.js +151 -0
- package/dist/knowledge/treasury-confirm.d.ts +133 -0
- package/dist/knowledge/treasury-confirm.js +512 -0
- package/dist/knowledge/treasury-context.d.ts +64 -0
- package/dist/knowledge/treasury-context.js +363 -0
- package/dist/knowledge/treasury-ledger.d.ts +42 -0
- package/dist/knowledge/treasury-ledger.js +300 -0
- package/dist/knowledge/treasury-puzzle.d.ts +163 -0
- package/dist/knowledge/treasury-puzzle.js +216 -0
- package/dist/knowledge/treasury-risk.d.ts +86 -0
- package/dist/knowledge/treasury-risk.js +440 -0
- package/dist/knowledge/treasury-templates.d.ts +38 -0
- package/dist/knowledge/treasury-templates.js +316 -0
- package/dist/knowledge/treasury-translation.d.ts +78 -0
- package/dist/knowledge/treasury-translation.js +498 -0
- package/dist/knowledge/util-risk.d.ts +30 -0
- package/dist/knowledge/util-risk.js +135 -0
- package/dist/project/business-puzzle.d.ts +47 -0
- package/dist/project/business-puzzle.js +372 -0
- package/dist/project/deployment-doc.d.ts +61 -0
- package/dist/project/deployment-doc.js +432 -0
- package/dist/project/graph.d.ts +1 -0
- package/dist/project/graph.js +27 -1
- package/dist/project/index.d.ts +1 -0
- package/dist/project/index.js +39 -2
- package/dist/project/namespace.d.ts +11 -1
- package/dist/project/namespace.js +27 -2
- package/dist/project/query.d.ts +2 -0
- package/dist/project/query.js +56 -15
- package/dist/project/risk-aggregator.d.ts +50 -0
- package/dist/project/risk-aggregator.js +280 -0
- package/dist/project/substep-trace.d.ts +130 -0
- package/dist/project/substep-trace.js +332 -0
- package/dist/rules.d.ts +12 -0
- package/dist/rules.js +9 -0
- package/dist/schema/call/allocation.d.ts +44 -44
- package/dist/schema/call/arbitration.d.ts +141 -141
- package/dist/schema/call/base.d.ts +386 -386
- package/dist/schema/call/base.js +6 -6
- package/dist/schema/call/bridge-handler.d.ts +5 -2
- package/dist/schema/call/bridge.d.ts +159 -159
- package/dist/schema/call/contact.d.ts +110 -110
- package/dist/schema/call/demand.d.ts +76 -76
- package/dist/schema/call/handler.d.ts +2 -3
- package/dist/schema/call/handler.js +1 -1
- package/dist/schema/call/machine.d.ts +96 -96
- package/dist/schema/call/order.d.ts +98 -110
- package/dist/schema/call/permission-handler.d.ts +5 -0
- package/dist/schema/call/permission-handler.js +54 -0
- package/dist/schema/call/permission.d.ts +108 -108
- package/dist/schema/call/personal.d.ts +14 -14
- package/dist/schema/call/progress.d.ts +57 -72
- package/dist/schema/call/progress.js +7 -4
- package/dist/schema/call/proof.d.ts +18 -18
- package/dist/schema/call/proof.js +12 -7
- package/dist/schema/call/repository.d.ts +154 -154
- package/dist/schema/call/reward.d.ts +55 -55
- package/dist/schema/call/semantic.js +1 -1
- package/dist/schema/call/service.d.ts +238 -238
- package/dist/schema/call/treasury.d.ts +93 -93
- package/dist/schema/config/index.d.ts +178 -5
- package/dist/schema/config/index.js +52 -1
- package/dist/schema/local/index.d.ts +3554 -836
- package/dist/schema/local/index.js +2 -1
- package/dist/schema/messenger/index.d.ts +162 -162
- package/dist/schema/operations.d.ts +1102 -1118
- package/dist/schema/operations.js +7 -1
- package/dist/schema/project/index.d.ts +1392 -6
- package/dist/schema/project/index.js +426 -2
- package/dist/schema/query/index.d.ts +818 -818
- package/dist/schema/query/index.js +15 -9
- package/dist/schema/schema-query/index.d.ts +23 -3
- package/dist/schema/schema-query/index.js +13 -2
- package/dist/schema/sync-layer4.d.ts +21 -0
- package/dist/schema/sync-layer4.js +261 -0
- package/dist/schema/trust/index.d.ts +26 -26
- package/dist/schema/utils/guard-query-utils.d.ts +7 -0
- package/dist/schema/utils/guard-query-utils.js +14 -1
- package/dist/schemas/account_operation.output.json +718 -0
- package/dist/schemas/bridge_operation.output.json +1 -1
- package/dist/schemas/config_operation.output.json +173 -0
- package/dist/schemas/index.json +9 -1
- package/dist/schemas/local_info_operation.output.json +718 -0
- package/dist/schemas/local_mark_operation.output.json +718 -0
- package/dist/schemas/messenger_operation.output.json +1 -1
- package/dist/schemas/onchain_events.output.json +1 -1
- package/dist/schemas/onchain_operations.output.json +5 -4
- package/dist/schemas/onchain_operations.schema.json +1813 -333
- package/dist/schemas/onchain_operations_allocation.schema.json +9 -11
- package/dist/schemas/onchain_operations_arbitration.schema.json +2 -1
- package/dist/schemas/onchain_operations_contact.schema.json +2 -1
- package/dist/schemas/onchain_operations_demand.schema.json +2 -1
- package/dist/schemas/onchain_operations_gen_passport.schema.json +878 -872
- package/dist/schemas/onchain_operations_gen_proof.schema.json +273 -0
- package/dist/schemas/onchain_operations_guard.schema.json +584 -70
- package/dist/schemas/onchain_operations_machine.schema.json +4 -6
- package/dist/schemas/onchain_operations_order.schema.json +13 -9
- package/dist/schemas/onchain_operations_payment.schema.json +2 -1
- package/dist/schemas/onchain_operations_permission.schema.json +2 -1
- package/dist/schemas/onchain_operations_personal.schema.json +2 -1
- package/dist/schemas/onchain_operations_progress.schema.json +14 -10
- package/dist/schemas/onchain_operations_proof.schema.json +699 -0
- package/dist/schemas/onchain_operations_repository.schema.json +2 -1
- package/dist/schemas/onchain_operations_reward.schema.json +2 -1
- package/dist/schemas/onchain_operations_service.schema.json +4 -6
- package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
- package/dist/schemas/onchain_table_data.output.json +6 -12
- package/dist/schemas/onchain_table_data.schema.json +32 -1
- package/dist/schemas/project_operation.output.json +879 -0
- package/dist/schemas/project_operation.schema.json +473 -2
- package/dist/schemas/query_toolkit.output.json +14906 -6
- package/dist/schemas/schema_query.output.json +38 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/tools/handlers/bridge.d.ts +1 -0
- package/dist/tools/handlers/bridge.js +1 -0
- package/dist/tools/handlers/config.d.ts +2 -0
- package/dist/tools/handlers/config.js +74 -0
- package/dist/tools/handlers/file-export.d.ts +3 -0
- package/dist/tools/handlers/file-export.js +90 -0
- package/dist/tools/handlers/local.d.ts +3 -0
- package/dist/tools/handlers/local.js +38 -0
- package/dist/tools/handlers/messenger.d.ts +16 -0
- package/dist/tools/handlers/messenger.js +188 -0
- package/dist/tools/handlers/onchain.d.ts +2 -0
- package/dist/tools/handlers/onchain.js +248 -0
- package/dist/tools/handlers/project.d.ts +2 -0
- package/dist/tools/handlers/project.js +293 -0
- package/dist/tools/handlers/query.d.ts +5 -0
- package/dist/tools/handlers/query.js +256 -0
- package/dist/tools/handlers/schema-query.d.ts +2 -0
- package/dist/tools/handlers/schema-query.js +93 -0
- package/dist/tools/handlers/trust.d.ts +2 -0
- package/dist/tools/handlers/trust.js +194 -0
- package/dist/tools/handlers/wip.d.ts +2 -0
- package/dist/tools/handlers/wip.js +44 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/tools/index.js +526 -0
- package/dist/tools/rules-hook.d.ts +2 -0
- package/dist/tools/rules-hook.js +23 -0
- package/dist/tools/shared.d.ts +20 -0
- package/dist/tools/shared.js +130 -0
- package/dist/tools/types.d.ts +35 -0
- package/dist/tools/types.js +1 -0
- package/dist/tools/wrap.d.ts +14 -0
- package/dist/tools/wrap.js +267 -0
- package/package.json +20 -6
|
@@ -0,0 +1,812 @@
|
|
|
1
|
+
import { MACHINE_LEDGER_VERSION, MACHINE_SCENES_COUNT, findScene, inferSceneFromFlow, } from "./machine-ledger.js";
|
|
2
|
+
import { MAX_NODE_COUNT, MAX_NODE_PAIR_COUNT, MAX_FORWARD_COUNT, } from "./onchain-constants.js";
|
|
3
|
+
import { MACHINE_TEMPLATES, MACHINE_TEMPLATES_VERSION, getAllTemplates, getTemplatesByScene, suggestTemplateForIntent, } from "./machine-templates.js";
|
|
4
|
+
import { SEMANTIC_TO_MACHINE_RULES, MACHINE_CONSTRAINT_RULES, MACHINE_TRANSLATION_VERSION, matchSemanticPattern, } from "./machine-translation.js";
|
|
5
|
+
import { MACHINE_RISK_RULES, MACHINE_RISK_VERSION, assessMachineRisks, } from "./machine-risk.js";
|
|
6
|
+
import { analyzeTopology, formatTopologySummary, MACHINE_TOPOLOGY_VERSION, } from "./machine-topology.js";
|
|
7
|
+
import { initPuzzleFromIntent, initPuzzleFromTemplate, checkPuzzleCompleteness, MACHINE_PUZZLE_VERSION, } from "./machine-puzzle.js";
|
|
8
|
+
import { PUBLISH_CHECKLIST, CONFIRMATION_QUESTIONS, MACHINE_CONFIRM_VERSION, progressiveCheck, } from "./machine-confirm.js";
|
|
9
|
+
import { GUARD_SCENES, } from "./guard-ledger.js";
|
|
10
|
+
export const MACHINE_CONTEXT_VERSION = "1.0.0";
|
|
11
|
+
export const MACHINE_VERIFICATION_NOTES = [
|
|
12
|
+
{
|
|
13
|
+
topic: "bReplace",
|
|
14
|
+
judgment: "YES",
|
|
15
|
+
verified_semantic: "bReplace acts at the pairs-list level of an ALREADY-EXISTING node, " +
|
|
16
|
+
"NOT at the whole-Machine level. bReplace=false merges new pairs into the " +
|
|
17
|
+
"existing node's pairs list; bReplace=true replaces that node's pairs list entirely.",
|
|
18
|
+
code_reference: "d:\\wowok\\agent\\mcp\\src\\tools\\machine.ts (node ops)",
|
|
19
|
+
affected_modes: ["initial_design", "mid_design_review", "pre_publish_check"],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
topic: "um",
|
|
23
|
+
judgment: "PARTIAL",
|
|
24
|
+
verified_semantic: "um is a Messenger Contact object reference (off-chain session metadata). " +
|
|
25
|
+
"It does NOT participate in any on-chain flow logic; omitting it has zero on-chain impact.",
|
|
26
|
+
code_reference: "machine.move (no um field in on-chain Machine)",
|
|
27
|
+
affected_modes: ["initial_design", "mid_design_review"],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
topic: "consensus_repositories",
|
|
31
|
+
judgment: "PARTIAL",
|
|
32
|
+
verified_semantic: "consensus_repositories is a declarative-only field. It is NOT consumed by any " +
|
|
33
|
+
"on-chain flow logic — it is a hint for off-chain tooling and human auditors.",
|
|
34
|
+
code_reference: "machine.move (no consensus_repositories field)",
|
|
35
|
+
affected_modes: ["initial_design", "mid_design_review"],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
topic: "namedOperator_assignment",
|
|
39
|
+
judgment: "PARTIAL",
|
|
40
|
+
verified_semantic: "Move progress::new does NOT accept namedOperator parameter. The MCP/SDK layer " +
|
|
41
|
+
"translates the API parameter into a separate namedOperator_add transaction " +
|
|
42
|
+
"(requires permission index 221). At runtime, Forward checks namedOperator membership.",
|
|
43
|
+
code_reference: "progress.move (progress::new signature) + agent\\mcp\\src\\tools\\progress.ts (namedOperator_add)",
|
|
44
|
+
affected_modes: ["initial_design", "mid_design_review", "pre_publish_check"],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
topic: "cross_machine_dependency",
|
|
48
|
+
judgment: "PARTIAL",
|
|
49
|
+
verified_semantic: "Cross-Machine dependency is INDIRECT: Machine A's Forward Guard queries Machine B's " +
|
|
50
|
+
"Progress via convert_witness (TypeOrderProgress=100/103). Machine B must be published " +
|
|
51
|
+
"before Progress can be created (progress::new -> assert_published).",
|
|
52
|
+
code_reference: "progress.move (progress::new, assert_published) + guard.move (convert_witness)",
|
|
53
|
+
affected_modes: ["cross_machine", "pre_publish_check"],
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
export function getMachineKnowledgeSnapshot() {
|
|
57
|
+
const verifiedYes = MACHINE_VERIFICATION_NOTES.filter((n) => n.judgment === "YES").length;
|
|
58
|
+
const verifiedPartial = MACHINE_VERIFICATION_NOTES.filter((n) => n.judgment === "PARTIAL").length;
|
|
59
|
+
const verifiedNo = MACHINE_VERIFICATION_NOTES.filter((n) => n.judgment === "NO").length;
|
|
60
|
+
return {
|
|
61
|
+
version: MACHINE_CONTEXT_VERSION,
|
|
62
|
+
modules: {
|
|
63
|
+
ledger: MACHINE_LEDGER_VERSION,
|
|
64
|
+
templates: MACHINE_TEMPLATES_VERSION,
|
|
65
|
+
translation: MACHINE_TRANSLATION_VERSION,
|
|
66
|
+
risk: MACHINE_RISK_VERSION,
|
|
67
|
+
topology: MACHINE_TOPOLOGY_VERSION,
|
|
68
|
+
puzzle: MACHINE_PUZZLE_VERSION,
|
|
69
|
+
confirm: MACHINE_CONFIRM_VERSION,
|
|
70
|
+
},
|
|
71
|
+
counts: {
|
|
72
|
+
scenes: MACHINE_SCENES_COUNT,
|
|
73
|
+
templates: MACHINE_TEMPLATES.length,
|
|
74
|
+
patterns: SEMANTIC_TO_MACHINE_RULES.length,
|
|
75
|
+
constraints: MACHINE_CONSTRAINT_RULES.length,
|
|
76
|
+
risk_rules: MACHINE_RISK_RULES.length,
|
|
77
|
+
puzzle_dimensions: 8,
|
|
78
|
+
publish_checklist_items: PUBLISH_CHECKLIST.length,
|
|
79
|
+
confirmation_questions: CONFIRMATION_QUESTIONS.length,
|
|
80
|
+
verification_notes: MACHINE_VERIFICATION_NOTES.length,
|
|
81
|
+
},
|
|
82
|
+
verification_summary: {
|
|
83
|
+
total_topics: MACHINE_VERIFICATION_NOTES.length,
|
|
84
|
+
verified_yes: verifiedYes,
|
|
85
|
+
verified_partial: verifiedPartial,
|
|
86
|
+
verified_no: verifiedNo,
|
|
87
|
+
topics: MACHINE_VERIFICATION_NOTES,
|
|
88
|
+
},
|
|
89
|
+
guard_bridge: {
|
|
90
|
+
available: true,
|
|
91
|
+
guard_scenes_count: GUARD_SCENES.length,
|
|
92
|
+
},
|
|
93
|
+
on_chain_limits: {
|
|
94
|
+
max_node_count: 100,
|
|
95
|
+
max_node_pair_count: 40,
|
|
96
|
+
max_forward_count: 20,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export function injectMachineContext(intent, mode, options = {}) {
|
|
101
|
+
const maxTemplates = options.max_templates ?? 3;
|
|
102
|
+
const maxConstraints = options.max_constraints ?? 10;
|
|
103
|
+
const maxRisks = options.max_risks ?? 10;
|
|
104
|
+
const includeNotes = options.include_verification_notes ?? true;
|
|
105
|
+
const includeGuardBridge = options.include_guard_bridge ?? mode === "guard_integration";
|
|
106
|
+
const matchedScene = inferSceneFromFlow(intent);
|
|
107
|
+
let suggestedTemplates = [];
|
|
108
|
+
if (matchedScene) {
|
|
109
|
+
suggestedTemplates = getTemplatesByScene(matchedScene.id).slice(0, maxTemplates);
|
|
110
|
+
}
|
|
111
|
+
if (suggestedTemplates.length === 0) {
|
|
112
|
+
const intentSuggestion = suggestTemplateForIntent(intent);
|
|
113
|
+
if (intentSuggestion) {
|
|
114
|
+
suggestedTemplates = [intentSuggestion].slice(0, maxTemplates);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (suggestedTemplates.length === 0) {
|
|
118
|
+
suggestedTemplates = getAllTemplates().slice(0, maxTemplates);
|
|
119
|
+
}
|
|
120
|
+
let relevantPatterns = [...SEMANTIC_TO_MACHINE_RULES];
|
|
121
|
+
if (options.filter_execution_mode) {
|
|
122
|
+
const modeToId = {
|
|
123
|
+
"Sequential": "P-M-SEQ",
|
|
124
|
+
"Parallel AND": "P-M-AND",
|
|
125
|
+
"Parallel OR": "P-M-OR",
|
|
126
|
+
"Weighted Voting": "P-M-VOTE",
|
|
127
|
+
"Hybrid": "P-M-HYBRID",
|
|
128
|
+
};
|
|
129
|
+
const expectedId = modeToId[options.filter_execution_mode];
|
|
130
|
+
if (expectedId) {
|
|
131
|
+
relevantPatterns = relevantPatterns.filter((p) => p.id === expectedId);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (options.filter_topology) {
|
|
135
|
+
const topoToId = {
|
|
136
|
+
"Linear": "P-M-LINEAR",
|
|
137
|
+
"ForkMerge": "P-M-FORKMERGE",
|
|
138
|
+
"Competing": "P-M-COMPETING",
|
|
139
|
+
};
|
|
140
|
+
const expectedId = topoToId[options.filter_topology];
|
|
141
|
+
if (expectedId) {
|
|
142
|
+
relevantPatterns = relevantPatterns.filter((p) => p.id === expectedId);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
relevantPatterns = filterPatternsByMode(relevantPatterns, mode);
|
|
146
|
+
let relevantConstraints = filterConstraintsByMode(MACHINE_CONSTRAINT_RULES, mode);
|
|
147
|
+
relevantConstraints = relevantConstraints.slice(0, maxConstraints);
|
|
148
|
+
let relevantRisks = filterRisksByMode(MACHINE_RISK_RULES, mode);
|
|
149
|
+
relevantRisks = relevantRisks.slice(0, maxRisks);
|
|
150
|
+
let puzzleState;
|
|
151
|
+
let puzzleCompleteness;
|
|
152
|
+
if (options.existing_puzzle) {
|
|
153
|
+
puzzleState = options.existing_puzzle;
|
|
154
|
+
puzzleCompleteness = checkPuzzleCompleteness(options.existing_puzzle);
|
|
155
|
+
}
|
|
156
|
+
else if (mode === "initial_design" || mode === "intent_match") {
|
|
157
|
+
puzzleState = initPuzzleFromIntent(intent);
|
|
158
|
+
puzzleCompleteness = checkPuzzleCompleteness(puzzleState);
|
|
159
|
+
}
|
|
160
|
+
let topologyAnalysis;
|
|
161
|
+
if (options.existing_machine_json) {
|
|
162
|
+
topologyAnalysis = analyzeTopology(options.existing_machine_json.nodes, options.existing_machine_json.pairs);
|
|
163
|
+
}
|
|
164
|
+
let riskAssessment;
|
|
165
|
+
if (options.existing_machine_json && options.project_context) {
|
|
166
|
+
const machineForRisk = {
|
|
167
|
+
nodes: options.existing_machine_json.nodes,
|
|
168
|
+
pairs: options.existing_machine_json.pairs,
|
|
169
|
+
};
|
|
170
|
+
riskAssessment = assessMachineRisks(machineForRisk, options.project_context);
|
|
171
|
+
}
|
|
172
|
+
let progressiveCheckResult;
|
|
173
|
+
if (mode === "pre_publish_check" && options.existing_machine_json) {
|
|
174
|
+
const machineForConfirm = {
|
|
175
|
+
nodes: options.existing_machine_json.nodes,
|
|
176
|
+
pairs: options.existing_machine_json.pairs,
|
|
177
|
+
template_id: options.existing_machine_json.template_id,
|
|
178
|
+
scene_id: options.existing_machine_json.scene_id,
|
|
179
|
+
};
|
|
180
|
+
progressiveCheckResult = progressiveCheck(machineForConfirm, "R5");
|
|
181
|
+
}
|
|
182
|
+
let guardBridge;
|
|
183
|
+
if (includeGuardBridge && matchedScene) {
|
|
184
|
+
guardBridge = buildGuardBridge(matchedScene);
|
|
185
|
+
}
|
|
186
|
+
let verificationNotes = [];
|
|
187
|
+
if (includeNotes) {
|
|
188
|
+
verificationNotes = MACHINE_VERIFICATION_NOTES.filter((n) => n.affected_modes.includes(mode));
|
|
189
|
+
}
|
|
190
|
+
const promptHints = buildPromptHints({
|
|
191
|
+
mode,
|
|
192
|
+
matched_scene: matchedScene,
|
|
193
|
+
suggested_templates: suggestedTemplates,
|
|
194
|
+
relevant_patterns: relevantPatterns,
|
|
195
|
+
relevant_constraints: relevantConstraints,
|
|
196
|
+
relevant_risks: relevantRisks,
|
|
197
|
+
puzzle_state: puzzleState,
|
|
198
|
+
puzzle_completeness: puzzleCompleteness,
|
|
199
|
+
topology_analysis: topologyAnalysis,
|
|
200
|
+
risk_assessment: riskAssessment,
|
|
201
|
+
progressive_check_result: progressiveCheckResult,
|
|
202
|
+
guard_bridge: guardBridge,
|
|
203
|
+
verification_notes: verificationNotes,
|
|
204
|
+
});
|
|
205
|
+
const recommendedNextAction = recommendNextAction(mode, {
|
|
206
|
+
matched_scene: matchedScene,
|
|
207
|
+
suggested_templates: suggestedTemplates,
|
|
208
|
+
puzzle_completeness: puzzleCompleteness,
|
|
209
|
+
risk_assessment: riskAssessment,
|
|
210
|
+
progressive_check_result: progressiveCheckResult,
|
|
211
|
+
});
|
|
212
|
+
return {
|
|
213
|
+
mode,
|
|
214
|
+
version: MACHINE_CONTEXT_VERSION,
|
|
215
|
+
matched_scene: matchedScene ?? undefined,
|
|
216
|
+
suggested_templates: suggestedTemplates,
|
|
217
|
+
relevant_patterns: relevantPatterns,
|
|
218
|
+
relevant_constraints: relevantConstraints,
|
|
219
|
+
relevant_risks: relevantRisks,
|
|
220
|
+
puzzle_state: puzzleState,
|
|
221
|
+
puzzle_completeness: puzzleCompleteness,
|
|
222
|
+
topology_analysis: topologyAnalysis,
|
|
223
|
+
risk_assessment: riskAssessment,
|
|
224
|
+
progressive_check_result: progressiveCheckResult,
|
|
225
|
+
guard_bridge: guardBridge,
|
|
226
|
+
prompt_hints: promptHints,
|
|
227
|
+
verification_notes: verificationNotes,
|
|
228
|
+
recommended_next_action: recommendedNextAction,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
export function suggestWorkflow(intent) {
|
|
232
|
+
const matchedScene = inferSceneFromFlow(intent);
|
|
233
|
+
const confidence = matchedScene ? 0.8 : 0.3;
|
|
234
|
+
const suggestedTemplates = [];
|
|
235
|
+
if (matchedScene) {
|
|
236
|
+
const sceneTemplates = getTemplatesByScene(matchedScene.id);
|
|
237
|
+
for (const t of sceneTemplates.slice(0, 3)) {
|
|
238
|
+
suggestedTemplates.push({
|
|
239
|
+
template: t,
|
|
240
|
+
rationale: `Template for scene "${matchedScene.name}"`,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (suggestedTemplates.length === 0) {
|
|
245
|
+
const t = suggestTemplateForIntent(intent);
|
|
246
|
+
if (t) {
|
|
247
|
+
suggestedTemplates.push({
|
|
248
|
+
template: t,
|
|
249
|
+
rationale: "Intent keyword match",
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (suggestedTemplates.length === 0) {
|
|
254
|
+
const all = getAllTemplates();
|
|
255
|
+
if (all.length > 0) {
|
|
256
|
+
suggestedTemplates.push({
|
|
257
|
+
template: all[0],
|
|
258
|
+
rationale: "Default (no specific match)",
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
let initialPuzzle;
|
|
263
|
+
if (suggestedTemplates.length > 0) {
|
|
264
|
+
const fromTemplate = initPuzzleFromTemplate(suggestedTemplates[0].template.id);
|
|
265
|
+
initialPuzzle = fromTemplate ?? initPuzzleFromIntent(intent);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
initialPuzzle = initPuzzleFromIntent(intent);
|
|
269
|
+
}
|
|
270
|
+
const matchedPattern = matchSemanticPattern(intent);
|
|
271
|
+
const recommendedPattern = matchedPattern ?? null;
|
|
272
|
+
let recommendedTopology = null;
|
|
273
|
+
if (matchedScene && matchedScene.recommended_topology.length > 0) {
|
|
274
|
+
recommendedTopology = matchedScene.recommended_topology[0];
|
|
275
|
+
}
|
|
276
|
+
const completeness = checkPuzzleCompleteness(initialPuzzle);
|
|
277
|
+
const nextStep = completeness.next_step;
|
|
278
|
+
return {
|
|
279
|
+
matched_scene: matchedScene ?? null,
|
|
280
|
+
confidence,
|
|
281
|
+
suggested_templates: suggestedTemplates,
|
|
282
|
+
initial_puzzle: initialPuzzle,
|
|
283
|
+
recommended_pattern: recommendedPattern,
|
|
284
|
+
recommended_topology: recommendedTopology,
|
|
285
|
+
next_step: nextStep,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
export function buildPromptFromContext(bundle) {
|
|
289
|
+
const lines = [];
|
|
290
|
+
lines.push(`# Machine Design Context (mode: ${bundle.mode})`);
|
|
291
|
+
lines.push("");
|
|
292
|
+
lines.push("> Context injected by machine-context.ts. Reflects verified on-chain behavior.");
|
|
293
|
+
lines.push("");
|
|
294
|
+
if (bundle.matched_scene) {
|
|
295
|
+
lines.push("## Matched Scene");
|
|
296
|
+
lines.push("");
|
|
297
|
+
lines.push(`- **ID**: ${bundle.matched_scene.id}`);
|
|
298
|
+
lines.push(`- **Name**: ${bundle.matched_scene.name}`);
|
|
299
|
+
lines.push(`- **Scenario**: ${bundle.matched_scene.scenario}`);
|
|
300
|
+
lines.push(`- **Industry**: ${bundle.matched_scene.industry.join(", ")}`);
|
|
301
|
+
lines.push(`- **Recommended patterns**: ${bundle.matched_scene.recommended_patterns.join(", ")}`);
|
|
302
|
+
lines.push(`- **Recommended topology**: ${bundle.matched_scene.recommended_topology.join(", ")}`);
|
|
303
|
+
lines.push("");
|
|
304
|
+
}
|
|
305
|
+
if (bundle.suggested_templates.length > 0) {
|
|
306
|
+
lines.push("## Suggested Templates");
|
|
307
|
+
lines.push("");
|
|
308
|
+
for (const t of bundle.suggested_templates) {
|
|
309
|
+
lines.push(`### ${t.id}: ${t.name}`);
|
|
310
|
+
lines.push("");
|
|
311
|
+
lines.push(`- **Scene**: ${t.scene_id}`);
|
|
312
|
+
lines.push(`- **Description**: ${t.description}`);
|
|
313
|
+
if (t.parameters.length > 0) {
|
|
314
|
+
lines.push(`- **Parameters**:`);
|
|
315
|
+
for (const p of t.parameters) {
|
|
316
|
+
lines.push(` - \`${p.name}\` (${p.type}): ${p.description}`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
lines.push("");
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (bundle.relevant_patterns.length > 0) {
|
|
323
|
+
lines.push("## Relevant Patterns");
|
|
324
|
+
lines.push("");
|
|
325
|
+
for (const p of bundle.relevant_patterns) {
|
|
326
|
+
lines.push(`### ${p.id}: ${p.pattern_name}`);
|
|
327
|
+
lines.push("");
|
|
328
|
+
lines.push(`- **Category**: ${p.category}`);
|
|
329
|
+
lines.push(`- **Intent**: ${p.semantic_intent}`);
|
|
330
|
+
if (p.match_keywords.length > 0) {
|
|
331
|
+
lines.push(`- **Keywords**: ${p.match_keywords.join(", ")}`);
|
|
332
|
+
}
|
|
333
|
+
lines.push("");
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (bundle.relevant_constraints.length > 0) {
|
|
337
|
+
lines.push("## Relevant Constraints");
|
|
338
|
+
lines.push("");
|
|
339
|
+
for (const c of bundle.relevant_constraints) {
|
|
340
|
+
lines.push(`- **${c.id}** (${c.category}, ${c.on_chain_enforced ? "on-chain" : "off-chain"}): ${c.description}`);
|
|
341
|
+
}
|
|
342
|
+
lines.push("");
|
|
343
|
+
}
|
|
344
|
+
if (bundle.relevant_risks.length > 0) {
|
|
345
|
+
lines.push("## Relevant Risks");
|
|
346
|
+
lines.push("");
|
|
347
|
+
for (const r of bundle.relevant_risks) {
|
|
348
|
+
lines.push(`- **${r.id}** [${r.severity}] ${r.name}: ${r.description}`);
|
|
349
|
+
lines.push(` - Fix: ${r.recommendation}`);
|
|
350
|
+
}
|
|
351
|
+
lines.push("");
|
|
352
|
+
}
|
|
353
|
+
if (bundle.puzzle_state && bundle.puzzle_completeness) {
|
|
354
|
+
lines.push("## Puzzle State");
|
|
355
|
+
lines.push("");
|
|
356
|
+
lines.push(`- **Complete**: ${bundle.puzzle_completeness.complete}`);
|
|
357
|
+
lines.push(`- **Next step**: ${bundle.puzzle_completeness.next_step}`);
|
|
358
|
+
lines.push("");
|
|
359
|
+
lines.push("### Per-dimension completeness:");
|
|
360
|
+
for (const d of bundle.puzzle_completeness.dimensions) {
|
|
361
|
+
const mark = d.complete ? "✓" : "✗";
|
|
362
|
+
lines.push(` - ${mark} ${d.dimension}`);
|
|
363
|
+
if (!d.complete && d.missing_fields.length > 0) {
|
|
364
|
+
lines.push(` - Missing: ${d.missing_fields.join(", ")}`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
lines.push("");
|
|
368
|
+
}
|
|
369
|
+
if (bundle.topology_analysis) {
|
|
370
|
+
lines.push("## Topology Analysis");
|
|
371
|
+
lines.push("");
|
|
372
|
+
lines.push("```");
|
|
373
|
+
lines.push(formatTopologySummary(bundle.topology_analysis));
|
|
374
|
+
lines.push("```");
|
|
375
|
+
lines.push("");
|
|
376
|
+
}
|
|
377
|
+
if (bundle.risk_assessment) {
|
|
378
|
+
lines.push("## Risk Assessment");
|
|
379
|
+
lines.push("");
|
|
380
|
+
lines.push(`- **Overall level**: ${bundle.risk_assessment.overall_level}`);
|
|
381
|
+
lines.push(`- **Recommendation**: ${bundle.risk_assessment.recommendation}`);
|
|
382
|
+
lines.push(`- **Summary**: ${JSON.stringify(bundle.risk_assessment.summary)}`);
|
|
383
|
+
if (bundle.risk_assessment.detected_risks.length > 0) {
|
|
384
|
+
lines.push("");
|
|
385
|
+
lines.push("### Detected risks:");
|
|
386
|
+
for (const r of bundle.risk_assessment.detected_risks) {
|
|
387
|
+
lines.push(`- [${r.severity}] ${r.name}: ${r.detail}`);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
lines.push("");
|
|
391
|
+
}
|
|
392
|
+
if (bundle.progressive_check_result) {
|
|
393
|
+
const r = bundle.progressive_check_result;
|
|
394
|
+
lines.push("## Progressive Checklist Result (R5)");
|
|
395
|
+
lines.push("");
|
|
396
|
+
lines.push(`- **Passed**: ${r.passed}`);
|
|
397
|
+
if (r.checked_items.length > 0) {
|
|
398
|
+
lines.push("");
|
|
399
|
+
lines.push("### Checked items:");
|
|
400
|
+
for (const item of r.checked_items) {
|
|
401
|
+
lines.push(` - [${item.status}] ${item.id}: ${item.description}`);
|
|
402
|
+
if (item.detail) {
|
|
403
|
+
lines.push(` - ${item.detail}`);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
lines.push("");
|
|
408
|
+
}
|
|
409
|
+
if (bundle.guard_bridge) {
|
|
410
|
+
lines.push("## Guard Bridge");
|
|
411
|
+
lines.push("");
|
|
412
|
+
lines.push(`Machine scene \`${bundle.guard_bridge.machine_scene_id}\` relates to:`);
|
|
413
|
+
lines.push("");
|
|
414
|
+
for (const m of bundle.guard_bridge.forward_guard_mapping) {
|
|
415
|
+
lines.push(`- Forward "${m.forward_purpose}" → Guard scene \`${m.guard_scene_id}\` (${m.guard_scene_name})`);
|
|
416
|
+
}
|
|
417
|
+
lines.push("");
|
|
418
|
+
}
|
|
419
|
+
if (bundle.prompt_hints.length > 0) {
|
|
420
|
+
lines.push("## Prompt Hints");
|
|
421
|
+
lines.push("");
|
|
422
|
+
for (const h of bundle.prompt_hints) {
|
|
423
|
+
lines.push(`- ${h}`);
|
|
424
|
+
}
|
|
425
|
+
lines.push("");
|
|
426
|
+
}
|
|
427
|
+
if (bundle.verification_notes.length > 0) {
|
|
428
|
+
lines.push("## Verification Notes (06 §14)");
|
|
429
|
+
lines.push("");
|
|
430
|
+
lines.push("> These notes reflect code-level verification of on-chain behavior.");
|
|
431
|
+
for (const n of bundle.verification_notes) {
|
|
432
|
+
lines.push("");
|
|
433
|
+
lines.push(`- **${n.topic}** (${n.judgment}): ${n.verified_semantic}`);
|
|
434
|
+
lines.push(` - Code reference: \`${n.code_reference}\``);
|
|
435
|
+
}
|
|
436
|
+
lines.push("");
|
|
437
|
+
}
|
|
438
|
+
lines.push("## Recommended Next Action");
|
|
439
|
+
lines.push("");
|
|
440
|
+
lines.push(bundle.recommended_next_action);
|
|
441
|
+
lines.push("");
|
|
442
|
+
return lines.join("\n");
|
|
443
|
+
}
|
|
444
|
+
export function getRelatedGuardScenes(machineSceneId) {
|
|
445
|
+
const machineScene = findScene(machineSceneId);
|
|
446
|
+
if (!machineScene) {
|
|
447
|
+
return [];
|
|
448
|
+
}
|
|
449
|
+
const relatedGuardSceneIds = new Set();
|
|
450
|
+
for (const req of machineScene.guard_requirements) {
|
|
451
|
+
relatedGuardSceneIds.add(req.scene);
|
|
452
|
+
}
|
|
453
|
+
return GUARD_SCENES.filter((g) => relatedGuardSceneIds.has(g.id));
|
|
454
|
+
}
|
|
455
|
+
export function getVerificationNotes(mode) {
|
|
456
|
+
if (!mode) {
|
|
457
|
+
return MACHINE_VERIFICATION_NOTES;
|
|
458
|
+
}
|
|
459
|
+
return MACHINE_VERIFICATION_NOTES.filter((n) => n.affected_modes.includes(mode));
|
|
460
|
+
}
|
|
461
|
+
export function identifyCrossMachineDependency(machineAId, machineJson, guardResolutions, publishedMachineIds) {
|
|
462
|
+
const deps = [];
|
|
463
|
+
for (const pair of machineJson.pairs) {
|
|
464
|
+
const pairId = `${pair.prev_node}->${pair.next_node}`;
|
|
465
|
+
for (const forward of pair.forwards) {
|
|
466
|
+
if (!forward.guard)
|
|
467
|
+
continue;
|
|
468
|
+
const resolution = guardResolutions.get(forward.guard);
|
|
469
|
+
if (!resolution)
|
|
470
|
+
continue;
|
|
471
|
+
deps.push({
|
|
472
|
+
machine_a_id: machineAId,
|
|
473
|
+
machine_b_id: resolution.upstream_machine_id,
|
|
474
|
+
machine_b_published: publishedMachineIds
|
|
475
|
+
? publishedMachineIds.has(resolution.upstream_machine_id)
|
|
476
|
+
: false,
|
|
477
|
+
dependency: {
|
|
478
|
+
machine_a_forward: `${pairId}:${forward.name}`,
|
|
479
|
+
machine_b_node: resolution.upstream_node_name,
|
|
480
|
+
},
|
|
481
|
+
guard_query: resolution.guard_query_description,
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return deps;
|
|
486
|
+
}
|
|
487
|
+
export function detectCrossMachineCycle(allDependencies) {
|
|
488
|
+
const adj = new Map();
|
|
489
|
+
for (const dep of allDependencies) {
|
|
490
|
+
if (!adj.has(dep.machine_a_id))
|
|
491
|
+
adj.set(dep.machine_a_id, new Set());
|
|
492
|
+
adj.get(dep.machine_a_id).add(dep.machine_b_id);
|
|
493
|
+
if (!adj.has(dep.machine_b_id))
|
|
494
|
+
adj.set(dep.machine_b_id, new Set());
|
|
495
|
+
}
|
|
496
|
+
const cycles = [];
|
|
497
|
+
const WHITE = 0, GRAY = 1, BLACK = 2;
|
|
498
|
+
const color = new Map();
|
|
499
|
+
for (const node of adj.keys())
|
|
500
|
+
color.set(node, WHITE);
|
|
501
|
+
const stack = [];
|
|
502
|
+
const dfs = (node) => {
|
|
503
|
+
color.set(node, GRAY);
|
|
504
|
+
stack.push(node);
|
|
505
|
+
const neighbors = adj.get(node) ?? new Set();
|
|
506
|
+
for (const next of neighbors) {
|
|
507
|
+
const nextColor = color.get(next) ?? WHITE;
|
|
508
|
+
if (nextColor === GRAY) {
|
|
509
|
+
const cycleStart = stack.indexOf(next);
|
|
510
|
+
const cycle = stack.slice(cycleStart).concat([next]);
|
|
511
|
+
cycles.push(cycle);
|
|
512
|
+
}
|
|
513
|
+
else if (nextColor === WHITE) {
|
|
514
|
+
dfs(next);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
stack.pop();
|
|
518
|
+
color.set(node, BLACK);
|
|
519
|
+
};
|
|
520
|
+
for (const node of adj.keys()) {
|
|
521
|
+
if (color.get(node) === WHITE) {
|
|
522
|
+
dfs(node);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return cycles;
|
|
526
|
+
}
|
|
527
|
+
export function aggregateProjectDependencies(machines, publishedMachineIds) {
|
|
528
|
+
const all = [];
|
|
529
|
+
for (const m of machines) {
|
|
530
|
+
const deps = identifyCrossMachineDependency(m.machine_id, m.machine_json, m.guard_resolutions, publishedMachineIds);
|
|
531
|
+
all.push(...deps);
|
|
532
|
+
}
|
|
533
|
+
return all;
|
|
534
|
+
}
|
|
535
|
+
function filterPatternsByMode(patterns, mode) {
|
|
536
|
+
switch (mode) {
|
|
537
|
+
case "cross_machine":
|
|
538
|
+
return patterns.filter((p) => p.id === "P-M-CROSS-MACHINE");
|
|
539
|
+
case "allocation_integration":
|
|
540
|
+
return patterns.filter((p) => p.id === "P-M-ALLOCATION-INTEGRATED");
|
|
541
|
+
case "guard_integration":
|
|
542
|
+
return patterns.filter((p) => p.match_keywords.some((k) => ["guard", "validation"].some((term) => k.toLowerCase().includes(term.toLowerCase()))) ||
|
|
543
|
+
p.semantic_intent.toLowerCase().includes("guard"));
|
|
544
|
+
case "post_publish_runtime":
|
|
545
|
+
return patterns.filter((p) => p.category === "execution" &&
|
|
546
|
+
["and", "or", "vote", "hybrid"].some((term) => p.pattern_name.toLowerCase().includes(term)));
|
|
547
|
+
default:
|
|
548
|
+
return patterns;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
function filterConstraintsByMode(constraints, mode) {
|
|
552
|
+
switch (mode) {
|
|
553
|
+
case "initial_design":
|
|
554
|
+
case "intent_match":
|
|
555
|
+
return constraints.filter((c) => c.category === "creation");
|
|
556
|
+
case "mid_design_review":
|
|
557
|
+
return constraints.filter((c) => ["creation", "structure", "node_operation"].includes(c.category));
|
|
558
|
+
case "pre_publish_check":
|
|
559
|
+
return constraints.filter((c) => ["publish", "structure", "node_operation"].includes(c.category));
|
|
560
|
+
case "post_publish_runtime":
|
|
561
|
+
return constraints.filter((c) => c.category === "runtime");
|
|
562
|
+
case "cross_machine":
|
|
563
|
+
return constraints.filter((c) => ["structure", "publish"].includes(c.category));
|
|
564
|
+
case "guard_integration":
|
|
565
|
+
return constraints.filter((c) => c.description.toLowerCase().includes("guard") ||
|
|
566
|
+
c.description.toLowerCase().includes("forward"));
|
|
567
|
+
case "allocation_integration":
|
|
568
|
+
return constraints.filter((c) => c.description.toLowerCase().includes("allocator") ||
|
|
569
|
+
c.description.toLowerCase().includes("terminal") ||
|
|
570
|
+
c.description.toLowerCase().includes("allocation"));
|
|
571
|
+
default:
|
|
572
|
+
return constraints;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
function filterRisksByMode(risks, mode) {
|
|
576
|
+
switch (mode) {
|
|
577
|
+
case "initial_design":
|
|
578
|
+
case "intent_match":
|
|
579
|
+
return risks.filter((r) => ["structural", "permission"].includes(r.category));
|
|
580
|
+
case "mid_design_review":
|
|
581
|
+
return risks.filter((r) => ["structural", "guard_integration", "permission"].includes(r.category));
|
|
582
|
+
case "pre_publish_check":
|
|
583
|
+
return risks
|
|
584
|
+
.slice()
|
|
585
|
+
.sort((a, b) => severityRank(b.severity) - severityRank(a.severity));
|
|
586
|
+
case "post_publish_runtime":
|
|
587
|
+
return risks.filter((r) => r.category === "environment");
|
|
588
|
+
case "cross_machine":
|
|
589
|
+
return risks.filter((r) => r.category === "guard_integration");
|
|
590
|
+
case "guard_integration":
|
|
591
|
+
return risks.filter((r) => r.category === "guard_integration");
|
|
592
|
+
case "allocation_integration":
|
|
593
|
+
return risks.filter((r) => r.description.toLowerCase().includes("allocator") ||
|
|
594
|
+
r.description.toLowerCase().includes("allocation") ||
|
|
595
|
+
r.description.toLowerCase().includes("terminal"));
|
|
596
|
+
default:
|
|
597
|
+
return risks;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function severityRank(s) {
|
|
601
|
+
switch (s) {
|
|
602
|
+
case "critical": return 5;
|
|
603
|
+
case "high": return 4;
|
|
604
|
+
case "medium": return 3;
|
|
605
|
+
case "low": return 2;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
function buildGuardBridge(machineScene) {
|
|
609
|
+
const guardSceneIds = new Set();
|
|
610
|
+
const forwardGuardMapping = [];
|
|
611
|
+
for (const req of machineScene.guard_requirements) {
|
|
612
|
+
guardSceneIds.add(req.scene);
|
|
613
|
+
const guardScene = GUARD_SCENES.find((g) => g.id === req.scene);
|
|
614
|
+
forwardGuardMapping.push({
|
|
615
|
+
forward_purpose: req.purpose,
|
|
616
|
+
guard_scene_id: req.scene,
|
|
617
|
+
guard_scene_name: guardScene?.name || req.scene,
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
const guardScenes = GUARD_SCENES.filter((g) => guardSceneIds.has(g.id));
|
|
621
|
+
return {
|
|
622
|
+
machine_scene_id: machineScene.id,
|
|
623
|
+
guard_scenes: guardScenes,
|
|
624
|
+
forward_guard_mapping: forwardGuardMapping,
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
function buildPromptHints(ctx) {
|
|
628
|
+
const hints = [];
|
|
629
|
+
switch (ctx.mode) {
|
|
630
|
+
case "initial_design":
|
|
631
|
+
case "intent_match":
|
|
632
|
+
hints.push("Start by confirming the matched scene and selecting a template.");
|
|
633
|
+
if (ctx.matched_scene) {
|
|
634
|
+
hints.push(`Scene "${ctx.matched_scene.name}" recommends patterns: ${ctx.matched_scene.recommended_patterns.join(", ")}.`);
|
|
635
|
+
}
|
|
636
|
+
if (ctx.suggested_templates.length > 0) {
|
|
637
|
+
hints.push(`Top template suggestion: ${ctx.suggested_templates[0].id} (${ctx.suggested_templates[0].name}).`);
|
|
638
|
+
}
|
|
639
|
+
break;
|
|
640
|
+
case "mid_design_review":
|
|
641
|
+
if (ctx.puzzle_completeness) {
|
|
642
|
+
if (ctx.puzzle_completeness.complete) {
|
|
643
|
+
hints.push("Puzzle is complete. Proceed to pre-publish check.");
|
|
644
|
+
}
|
|
645
|
+
else {
|
|
646
|
+
hints.push(`Puzzle incomplete. Next step: ${ctx.puzzle_completeness.next_step}`);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
if (ctx.topology_analysis) {
|
|
650
|
+
if (ctx.topology_analysis.has_cycles) {
|
|
651
|
+
hints.push("⚠ Cycle detected in topology — must fix before publish.");
|
|
652
|
+
}
|
|
653
|
+
if (ctx.topology_analysis.orphaned_nodes.length > 0) {
|
|
654
|
+
hints.push(`⚠ Orphaned nodes: ${ctx.topology_analysis.orphaned_nodes.join(", ")}`);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
break;
|
|
658
|
+
case "pre_publish_check":
|
|
659
|
+
if (ctx.risk_assessment) {
|
|
660
|
+
if (ctx.risk_assessment.overall_level === "critical") {
|
|
661
|
+
hints.push("⛔ CRITICAL risk detected — DO NOT publish until resolved.");
|
|
662
|
+
}
|
|
663
|
+
else if (ctx.risk_assessment.overall_level === "high") {
|
|
664
|
+
hints.push("⚠ HIGH risk — fix before publish or override with explicit reason.");
|
|
665
|
+
}
|
|
666
|
+
hints.push(`Risk recommendation: ${ctx.risk_assessment.recommendation}`);
|
|
667
|
+
}
|
|
668
|
+
if (ctx.progressive_check_result) {
|
|
669
|
+
if (!ctx.progressive_check_result.passed) {
|
|
670
|
+
const failed = ctx.progressive_check_result.checked_items
|
|
671
|
+
.filter((i) => i.status !== "pass")
|
|
672
|
+
.map((i) => i.id);
|
|
673
|
+
hints.push(`⛔ Pre-publish checklist FAILED on: ${failed.join(", ") || "see details"}`);
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
hints.push("✓ Pre-publish checklist (R5) passed.");
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
hints.push("Run full confirmPublish() with user confirmation before any on-chain publish transaction.");
|
|
680
|
+
break;
|
|
681
|
+
case "post_publish_runtime":
|
|
682
|
+
hints.push("Machine is already published — nodes cannot be modified.");
|
|
683
|
+
hints.push("Only progress advancement (Forward execution) is possible.");
|
|
684
|
+
if (ctx.topology_analysis) {
|
|
685
|
+
hints.push(`Current topology: ${ctx.topology_analysis.within_limits ? "within on-chain limits" : "EXCEEDS limits"}`);
|
|
686
|
+
}
|
|
687
|
+
break;
|
|
688
|
+
case "cross_machine":
|
|
689
|
+
hints.push("Cross-Machine dependency is INDIRECT: Machine A queries Machine B's Progress via convert_witness.");
|
|
690
|
+
hints.push("Machine B MUST be published before Progress::new can create a Progress for it (assert_published).");
|
|
691
|
+
hints.push("Use convert_witness TypeOrderProgress (100) or TypeOrderProgressSession (103) in Guard queries.");
|
|
692
|
+
break;
|
|
693
|
+
case "guard_integration":
|
|
694
|
+
if (ctx.guard_bridge) {
|
|
695
|
+
hints.push(`This scene integrates with ${ctx.guard_bridge.guard_scenes.length} Guard scene(s).`);
|
|
696
|
+
for (const m of ctx.guard_bridge.forward_guard_mapping) {
|
|
697
|
+
hints.push(` - Forward "${m.forward_purpose}" → Guard scene: ${m.guard_scene_name}`);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
hints.push("Forward.guard cannot be modified after Machine publish (immutable).");
|
|
701
|
+
hints.push("Use machine_forward_guard scene from guard-ledger.ts for Guard design.");
|
|
702
|
+
break;
|
|
703
|
+
case "allocation_integration":
|
|
704
|
+
hints.push("Terminal nodes map to Service order_allocators.");
|
|
705
|
+
hints.push("order_allocators is order-sensitive (first-match-wins).");
|
|
706
|
+
hints.push("Each Allocator requires a UNIQUE Guard object (no two allocators may share the same Guard).");
|
|
707
|
+
hints.push("order_allocators CANNOT be modified after Service publish (immutable).");
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
for (const n of ctx.verification_notes) {
|
|
711
|
+
hints.push(`[Verified ${n.judgment}] ${n.topic}: ${n.verified_semantic}`);
|
|
712
|
+
}
|
|
713
|
+
hints.push(`On-chain limits: MAX_NODE_COUNT=${MAX_NODE_COUNT}, MAX_NODE_PAIR_COUNT=${MAX_NODE_PAIR_COUNT}, MAX_FORWARD_COUNT=${MAX_FORWARD_COUNT}.`);
|
|
714
|
+
return hints;
|
|
715
|
+
}
|
|
716
|
+
function recommendNextAction(mode, ctx) {
|
|
717
|
+
switch (mode) {
|
|
718
|
+
case "initial_design":
|
|
719
|
+
case "intent_match": {
|
|
720
|
+
if (!ctx.matched_scene) {
|
|
721
|
+
return "Ask the user to clarify the business scenario — no scene matched.";
|
|
722
|
+
}
|
|
723
|
+
if (ctx.suggested_templates.length === 0) {
|
|
724
|
+
return `Scene "${ctx.matched_scene.name}" matched but no template available — design Machine manually using the scene's recommended patterns.`;
|
|
725
|
+
}
|
|
726
|
+
return `Present template "${ctx.suggested_templates[0].id}" to user. After user confirms, fill parameters and initialize puzzle.`;
|
|
727
|
+
}
|
|
728
|
+
case "mid_design_review": {
|
|
729
|
+
if (!ctx.puzzle_completeness) {
|
|
730
|
+
return "Initialize puzzle state and re-run injection with existing_puzzle option.";
|
|
731
|
+
}
|
|
732
|
+
if (ctx.puzzle_completeness.complete) {
|
|
733
|
+
return "Puzzle complete. Proceed to pre_publish_check mode.";
|
|
734
|
+
}
|
|
735
|
+
return `Complete missing puzzle dimensions: ${ctx.puzzle_completeness.next_step}`;
|
|
736
|
+
}
|
|
737
|
+
case "pre_publish_check": {
|
|
738
|
+
if (ctx.progressive_check_result && !ctx.progressive_check_result.passed) {
|
|
739
|
+
const failedIds = ctx.progressive_check_result.failed_items
|
|
740
|
+
.map((i) => i.id)
|
|
741
|
+
.join(", ");
|
|
742
|
+
return `⛔ Pre-publish checklist FAILED on: ${failedIds || "see checklist result"}. Fix these items before proceeding.`;
|
|
743
|
+
}
|
|
744
|
+
if (ctx.risk_assessment) {
|
|
745
|
+
if (ctx.risk_assessment.overall_level === "critical") {
|
|
746
|
+
return "⛔ CRITICAL risk — DO NOT publish. Fix risks first.";
|
|
747
|
+
}
|
|
748
|
+
if (ctx.risk_assessment.overall_level === "high") {
|
|
749
|
+
return "⚠ HIGH risk — fix risks OR obtain explicit user override with reason.";
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return "All checks passed. Present confirmation text to user and obtain explicit approval before publish transaction.";
|
|
753
|
+
}
|
|
754
|
+
case "post_publish_runtime":
|
|
755
|
+
return "Machine is published. Use onchain_operations to execute Forward advancements. Monitor Progress state via query tool.";
|
|
756
|
+
case "cross_machine":
|
|
757
|
+
return "Design Machine A's Forward.guard to query Machine B's Progress via convert_witness=100. Ensure Machine B is published first.";
|
|
758
|
+
case "guard_integration":
|
|
759
|
+
return "For each Forward.guard binding, design the Guard using the related Guard scene. Use guard-ledger + guard-templates + guard-puzzle modules.";
|
|
760
|
+
case "allocation_integration":
|
|
761
|
+
return "Map each terminal node to an Allocator in Service.order_allocators. Each Allocator needs a unique Guard object. Configure sharing.who (prefer Entity over Signer).";
|
|
762
|
+
default:
|
|
763
|
+
return "Proceed with current task.";
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
export const CONTEXT_PRESETS = {
|
|
767
|
+
newUserIntent: (intent) => injectMachineContext(intent, "intent_match", {
|
|
768
|
+
max_templates: 2,
|
|
769
|
+
max_constraints: 5,
|
|
770
|
+
max_risks: 3,
|
|
771
|
+
include_verification_notes: false,
|
|
772
|
+
include_guard_bridge: false,
|
|
773
|
+
}),
|
|
774
|
+
midDesignReview: (intent, puzzle) => injectMachineContext(intent, "mid_design_review", {
|
|
775
|
+
max_templates: 1,
|
|
776
|
+
max_constraints: 15,
|
|
777
|
+
max_risks: 10,
|
|
778
|
+
include_verification_notes: true,
|
|
779
|
+
include_guard_bridge: false,
|
|
780
|
+
existing_puzzle: puzzle,
|
|
781
|
+
}),
|
|
782
|
+
prePublishFull: (intent, machineJson, projectContext) => injectMachineContext(intent, "pre_publish_check", {
|
|
783
|
+
max_templates: 0,
|
|
784
|
+
max_constraints: 20,
|
|
785
|
+
max_risks: 39,
|
|
786
|
+
include_verification_notes: true,
|
|
787
|
+
include_guard_bridge: true,
|
|
788
|
+
existing_machine_json: machineJson,
|
|
789
|
+
project_context: projectContext,
|
|
790
|
+
}),
|
|
791
|
+
crossMachine: (intent) => injectMachineContext(intent, "cross_machine", {
|
|
792
|
+
max_templates: 2,
|
|
793
|
+
max_constraints: 10,
|
|
794
|
+
max_risks: 8,
|
|
795
|
+
include_verification_notes: true,
|
|
796
|
+
include_guard_bridge: true,
|
|
797
|
+
}),
|
|
798
|
+
guardIntegration: (intent) => injectMachineContext(intent, "guard_integration", {
|
|
799
|
+
max_templates: 1,
|
|
800
|
+
max_constraints: 10,
|
|
801
|
+
max_risks: 8,
|
|
802
|
+
include_verification_notes: true,
|
|
803
|
+
include_guard_bridge: true,
|
|
804
|
+
}),
|
|
805
|
+
allocationIntegration: (intent) => injectMachineContext(intent, "allocation_integration", {
|
|
806
|
+
max_templates: 1,
|
|
807
|
+
max_constraints: 8,
|
|
808
|
+
max_risks: 8,
|
|
809
|
+
include_verification_notes: false,
|
|
810
|
+
include_guard_bridge: false,
|
|
811
|
+
}),
|
|
812
|
+
};
|