@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.
- package/dist/config/index.js +1 -1
- package/dist/config/runtime.js +1 -238
- package/dist/customer/customer-advice.js +1 -130
- package/dist/customer/index.js +1 -11
- package/dist/customer/industry-risks.js +1 -438
- package/dist/customer/info-puzzle.js +1 -681
- package/dist/customer/order-monitor.js +1 -328
- package/dist/customer/order-strategy.js +1 -373
- package/dist/customer/post-purchase.js +1 -351
- package/dist/customer/preorder-compare.js +1 -34
- package/dist/customer/reminder-system.js +1 -316
- package/dist/customer/risk-assessment.js +1 -397
- package/dist/customer/types.js +1 -13
- package/dist/customer/user-preferences.js +1 -460
- package/dist/evaluation/arbitration-game.d.ts +9 -2
- package/dist/evaluation/arbitration-game.js +1 -48
- package/dist/evaluation/builtins/demand-match.js +1 -153
- package/dist/evaluation/builtins/index.js +1 -10
- package/dist/evaluation/builtins/service-risk.js +1 -55
- package/dist/evaluation/capability.js +1 -13
- package/dist/evaluation/composer.js +1 -40
- package/dist/evaluation/engine.js +1 -175
- package/dist/evaluation/extract.js +1 -115
- package/dist/evaluation/game-strategy.d.ts +27 -0
- package/dist/evaluation/game-strategy.js +1 -0
- package/dist/evaluation/gap.js +1 -100
- package/dist/evaluation/index.d.ts +1 -0
- package/dist/evaluation/index.js +1 -11
- package/dist/evaluation/node-game.d.ts +31 -3
- package/dist/evaluation/node-game.js +1 -57
- package/dist/evaluation/region.js +1 -36
- package/dist/evaluation/types.d.ts +1 -0
- package/dist/evaluation/types.js +1 -1
- package/dist/evaluation/user-injection.js +1 -27
- package/dist/experience/experience-reuse.js +1 -103
- package/dist/experience/index.js +1 -5
- package/dist/experience/intent-distill.js +1 -83
- package/dist/experience/realtime-feedback.js +1 -94
- package/dist/experience/types.js +1 -1
- package/dist/experience/user-profile.js +1 -171
- package/dist/extensions/business-modules.js +1 -287
- package/dist/extensions/capability-manifest.js +1 -781
- package/dist/extensions/constraint-registry.js +1 -198
- package/dist/extensions/index.js +1 -6
- package/dist/extensions/metric-registry.js +1 -257
- package/dist/extensions/mode-evaluator.js +1 -170
- package/dist/extensions/modes.js +1 -499
- package/dist/extensions/registry.js +1 -717
- package/dist/extensions/types.js +1 -1
- package/dist/harness/auto-escalation.js +1 -68
- package/dist/harness/checkpoint.js +1 -129
- package/dist/harness/index.js +1 -78
- package/dist/harness/plan.js +1 -315
- package/dist/harness/recover.js +1 -139
- package/dist/harness/types.js +1 -1
- package/dist/harness/verify.js +1 -237
- package/dist/index.js +1 -273
- package/dist/intent/enrich.js +1 -67
- package/dist/intent/index.js +1 -60
- package/dist/intent/matcher.js +1 -81
- package/dist/intent/store.js +1 -55
- package/dist/intent/types.js +1 -10
- package/dist/knowledge/acquisition-flywheel.js +1 -192
- package/dist/knowledge/allocation-confirm.js +1 -534
- package/dist/knowledge/allocation-context.js +1 -249
- package/dist/knowledge/allocation-ledger.js +1 -463
- package/dist/knowledge/allocation-puzzle.js +1 -298
- package/dist/knowledge/allocation-risk.js +1 -568
- package/dist/knowledge/allocation-templates.js +1 -970
- package/dist/knowledge/allocation-translation.js +1 -585
- package/dist/knowledge/arb-risk.js +1 -210
- package/dist/knowledge/arbitration-confirm.js +1 -559
- package/dist/knowledge/arbitration-context.js +1 -505
- package/dist/knowledge/arbitration-ledger.js +1 -521
- package/dist/knowledge/arbitration-puzzle.js +1 -304
- package/dist/knowledge/arbitration-risk.js +1 -423
- package/dist/knowledge/arbitration-templates.js +1 -276
- package/dist/knowledge/arbitration-translation.js +1 -487
- package/dist/knowledge/arbitration-trust.js +1 -117
- package/dist/knowledge/audit-rules.js +1 -141
- package/dist/knowledge/bridge-risk.js +1 -263
- package/dist/knowledge/contact-risk.js +1 -200
- package/dist/knowledge/contact-templates.js +1 -60
- package/dist/knowledge/demand-confirm.js +1 -206
- package/dist/knowledge/demand-matching.js +1 -132
- package/dist/knowledge/demand-risk.js +1 -240
- package/dist/knowledge/demand-translation.js +1 -354
- package/dist/knowledge/deployment-scanner.js +1 -823
- package/dist/knowledge/dynamic-pricing.js +1 -87
- package/dist/knowledge/examples-scanner-cli.js +1 -26
- package/dist/knowledge/examples-scanner.js +1 -843
- package/dist/knowledge/flywheel-loop.js +1 -404
- package/dist/knowledge/fund-layer.js +1 -973
- package/dist/knowledge/glossary.js +1 -211
- package/dist/knowledge/guard-confirm.js +1 -406
- package/dist/knowledge/guard-context.js +1 -287
- package/dist/knowledge/guard-design-patterns.js +1 -360
- package/dist/knowledge/guard-ledger.js +1 -260
- package/dist/knowledge/guard-lint.js +1 -670
- package/dist/knowledge/guard-migration.js +1 -228
- package/dist/knowledge/guard-puzzle.js +1 -805
- package/dist/knowledge/guard-render.js +1 -700
- package/dist/knowledge/guard-risk.js +1 -1879
- package/dist/knowledge/guard-submission-prompt.js +1 -171
- package/dist/knowledge/guard-templates.js +1 -1105
- package/dist/knowledge/guard-translation.js +1 -1119
- package/dist/knowledge/index.js +1 -436
- package/dist/knowledge/industry-evolution.js +1 -323
- package/dist/knowledge/industry-generalizer.js +1 -381
- package/dist/knowledge/industry-registry.js +1 -174
- package/dist/knowledge/intent-metrics.d.ts +4 -3
- package/dist/knowledge/intent-metrics.js +1 -566
- package/dist/knowledge/machine-confirm.js +1 -559
- package/dist/knowledge/machine-context.js +1 -833
- package/dist/knowledge/machine-ledger.js +1 -338
- package/dist/knowledge/machine-puzzle.js +1 -494
- package/dist/knowledge/machine-render.js +1 -565
- package/dist/knowledge/machine-risk.js +1 -669
- package/dist/knowledge/machine-templates.js +1 -1597
- package/dist/knowledge/machine-topology.js +1 -234
- package/dist/knowledge/machine-translation.js +1 -513
- package/dist/knowledge/mcp-schema-audit-cli.js +1 -45
- package/dist/knowledge/mcp-schema-audit.js +1 -777
- package/dist/knowledge/onchain-constants.js +1 -35
- package/dist/knowledge/order-confirm.js +1 -573
- package/dist/knowledge/order-context.js +1 -390
- package/dist/knowledge/order-ledger.js +1 -341
- package/dist/knowledge/order-puzzle.js +1 -255
- package/dist/knowledge/order-risk.js +1 -653
- package/dist/knowledge/order-templates.js +1 -368
- package/dist/knowledge/order-translation.js +1 -550
- package/dist/knowledge/overrides-loader.js +1 -65
- package/dist/knowledge/passport-confirm.js +1 -531
- package/dist/knowledge/passport-context.js +1 -306
- package/dist/knowledge/passport-ledger.js +1 -282
- package/dist/knowledge/passport-puzzle.js +1 -333
- package/dist/knowledge/passport-risk.js +1 -450
- package/dist/knowledge/passport-templates.js +1 -568
- package/dist/knowledge/passport-translation.js +1 -516
- package/dist/knowledge/payment-risk.js +1 -249
- package/dist/knowledge/permission-confirm.js +1 -426
- package/dist/knowledge/permission-context.js +1 -224
- package/dist/knowledge/permission-ledger.js +1 -403
- package/dist/knowledge/permission-puzzle.js +1 -173
- package/dist/knowledge/permission-risk.js +1 -411
- package/dist/knowledge/permission-templates.js +1 -234
- package/dist/knowledge/permission-translation.js +1 -350
- package/dist/knowledge/personal-risk.js +1 -212
- package/dist/knowledge/process-model.js +1 -160
- package/dist/knowledge/progress-confirm.js +1 -456
- package/dist/knowledge/progress-context.js +1 -452
- package/dist/knowledge/progress-ledger.js +1 -330
- package/dist/knowledge/progress-puzzle.js +1 -219
- package/dist/knowledge/progress-risk.js +1 -461
- package/dist/knowledge/progress-templates.js +1 -228
- package/dist/knowledge/progress-translation.js +1 -405
- package/dist/knowledge/proof-confirm.js +1 -187
- package/dist/knowledge/proof-risk.js +1 -207
- package/dist/knowledge/proof-translation.js +1 -283
- package/dist/knowledge/registrar-risk.js +1 -217
- package/dist/knowledge/repository-confirm.js +1 -286
- package/dist/knowledge/repository-risk.js +1 -373
- package/dist/knowledge/repository-translation.js +1 -445
- package/dist/knowledge/reputation-rules.js +1 -99
- package/dist/knowledge/resource-risk.js +1 -157
- package/dist/knowledge/reward-confirm.js +1 -526
- package/dist/knowledge/reward-context.js +1 -504
- package/dist/knowledge/reward-ledger.js +1 -502
- package/dist/knowledge/reward-puzzle.js +1 -300
- package/dist/knowledge/reward-risk.js +1 -627
- package/dist/knowledge/reward-templates.js +1 -197
- package/dist/knowledge/reward-translation.js +1 -501
- package/dist/knowledge/safety-rules.js +1 -404
- package/dist/knowledge/scenario-modes.js +1 -321
- package/dist/knowledge/service-confirm.js +1 -807
- package/dist/knowledge/service-context.js +1 -403
- package/dist/knowledge/service-ledger.js +1 -609
- package/dist/knowledge/service-puzzle.js +1 -236
- package/dist/knowledge/service-risk.js +1 -651
- package/dist/knowledge/service-templates.js +1 -456
- package/dist/knowledge/service-translation.js +1 -622
- package/dist/knowledge/template-registry.js +1 -353
- package/dist/knowledge/tool-constraints.js +1 -195
- package/dist/knowledge/tools-reference.js +1 -178
- package/dist/knowledge/treasury-confirm.js +1 -512
- package/dist/knowledge/treasury-context.js +1 -363
- package/dist/knowledge/treasury-ledger.js +1 -300
- package/dist/knowledge/treasury-puzzle.js +1 -216
- package/dist/knowledge/treasury-risk.js +1 -440
- package/dist/knowledge/treasury-templates.js +1 -358
- package/dist/knowledge/treasury-translation.js +1 -498
- package/dist/knowledge/trust-metrics.js +1 -198
- package/dist/knowledge/util-risk.js +1 -135
- package/dist/loop-engineering/aggregate.js +1 -132
- package/dist/loop-engineering/context-collect.js +1 -83
- package/dist/loop-engineering/diagnose.js +1 -273
- package/dist/loop-engineering/improve.js +1 -405
- package/dist/loop-engineering/index.js +1 -4
- package/dist/loop-engineering/pipeline.js +1 -56
- package/dist/mode-market/index.js +1 -3
- package/dist/mode-market/registry.js +1 -124
- package/dist/mode-market/review.js +1 -214
- package/dist/mode-market/submission.js +1 -85
- package/dist/participation/collaborator-interest.d.ts +23 -0
- package/dist/participation/collaborator-interest.js +1 -0
- package/dist/participation/customer-interest.d.ts +25 -0
- package/dist/participation/customer-interest.js +1 -0
- package/dist/participation/merchant-interest.js +1 -100
- package/dist/participation/radar-core.d.ts +13 -3
- package/dist/participation/radar-core.js +1 -269
- package/dist/participation/supplier-interest.d.ts +25 -0
- package/dist/participation/supplier-interest.js +1 -0
- package/dist/persona/analyzer.js +1 -66
- package/dist/persona/bridge.js +1 -86
- package/dist/persona/defaults.js +1 -195
- package/dist/persona/experience-bridge.js +1 -23
- package/dist/persona/index.js +1 -71
- package/dist/persona/model.js +1 -111
- package/dist/persona/store.js +1 -62
- package/dist/persona/types.d.ts +3 -1
- package/dist/persona/types.js +1 -5
- package/dist/project/business-puzzle.js +1 -383
- package/dist/project/context-assembly.js +1 -254
- package/dist/project/deployment-bridge.js +1 -120
- package/dist/project/deployment-doc.js +1 -1126
- package/dist/project/edit-planner.js +1 -1342
- package/dist/project/evaluation.js +1 -2011
- package/dist/project/game-theory.js +1 -177
- package/dist/project/graph-builder.js +1 -656
- package/dist/project/graph.js +1 -340
- package/dist/project/handlers.js +1 -1784
- package/dist/project/index.d.ts +1 -0
- package/dist/project/index.js +1 -301
- package/dist/project/intent-analyzer.js +1 -149
- package/dist/project/machine-nodes.js +1 -36
- package/dist/project/merchant-guide.js +1 -264
- package/dist/project/migration.js +1 -125
- package/dist/project/mode-actions.js +1 -309
- package/dist/project/namespace.js +1 -206
- package/dist/project/participation-radar.js +1 -428
- package/dist/project/pipeline-actions.js +1 -109
- package/dist/project/project-store.js +1 -422
- package/dist/project/query.js +1 -153
- package/dist/project/reverse-mapping.d.ts +34 -0
- package/dist/project/reverse-mapping.js +1 -0
- package/dist/project/risk-aggregator.js +1 -295
- package/dist/project/rollback-policy.js +1 -290
- package/dist/project/semantic-assembler.js +1 -345
- package/dist/project/semantic-graph.js +1 -292
- package/dist/project/stage-gate.js +1 -369
- package/dist/project/substep-trace.js +1 -332
- package/dist/project/task-tracker.js +1 -78
- package/dist/role/derivation.d.ts +18 -0
- package/dist/role/derivation.js +1 -0
- package/dist/role/index.d.ts +5 -0
- package/dist/role/index.js +1 -0
- package/dist/role/model.d.ts +8 -0
- package/dist/role/model.js +1 -0
- package/dist/role/resolution.d.ts +11 -0
- package/dist/role/resolution.js +1 -0
- package/dist/role/types.d.ts +11 -0
- package/dist/role/types.js +1 -0
- package/dist/rules.js +1 -52
- package/dist/safety/confirm-gate.js +1 -88
- package/dist/safety/index.js +1 -3
- package/dist/safety/preview.js +1 -52
- package/dist/schema/call/allocation.js +1 -34
- package/dist/schema/call/arbitration.js +1 -113
- package/dist/schema/call/base.d.ts +15 -15
- package/dist/schema/call/base.js +1 -370
- package/dist/schema/call/bridge-handler.js +1 -265
- package/dist/schema/call/bridge.d.ts +7 -7
- package/dist/schema/call/bridge.js +1 -458
- package/dist/schema/call/contact.js +1 -37
- package/dist/schema/call/demand.js +1 -47
- package/dist/schema/call/guard.js +1 -161
- package/dist/schema/call/handler.js +1 -322
- package/dist/schema/call/index.js +1 -20
- package/dist/schema/call/machine.js +1 -193
- package/dist/schema/call/order.js +1 -35
- package/dist/schema/call/payment.js +1 -37
- package/dist/schema/call/permission-handler.js +1 -54
- package/dist/schema/call/permission.js +1 -105
- package/dist/schema/call/personal.js +1 -78
- package/dist/schema/call/progress.js +1 -47
- package/dist/schema/call/proof.js +1 -33
- package/dist/schema/call/repository.js +1 -77
- package/dist/schema/call/reward.js +1 -30
- package/dist/schema/call/semantic.js +1 -1679
- package/dist/schema/call/service.js +1 -184
- package/dist/schema/call/treasury.js +1 -71
- package/dist/schema/common/index.js +1 -407
- package/dist/schema/config/index.js +1 -68
- package/dist/schema/evaluation/index.d.ts +213 -16
- package/dist/schema/evaluation/index.js +1 -356
- package/dist/schema/index.js +1 -17
- package/dist/schema/intent-radar/index.d.ts +13 -13
- package/dist/schema/intent-radar/index.js +1 -89
- package/dist/schema/local/index.d.ts +21 -21
- package/dist/schema/local/index.js +1 -927
- package/dist/schema/local/wip.js +1 -187
- package/dist/schema/messenger/index.d.ts +7 -7
- package/dist/schema/messenger/index.js +1 -475
- package/dist/schema/operations.d.ts +7 -7
- package/dist/schema/operations.js +1 -520
- package/dist/schema/persona/index.d.ts +54 -54
- package/dist/schema/persona/index.js +1 -148
- package/dist/schema/project/index.d.ts +94 -48
- package/dist/schema/project/index.js +1 -2057
- package/dist/schema/query/index.d.ts +423 -7
- package/dist/schema/query/index.js +1 -1646
- package/dist/schema/schema-query/index.js +1 -104
- package/dist/schema/schema-version.js +1 -76
- package/dist/schema/sync-layer4.js +1 -286
- package/dist/schema/task-status.js +1 -36
- package/dist/schema/trust/index.js +1 -314
- package/dist/schema/utils/guard-parser.js +1 -419
- package/dist/schema/utils/guard-query-utils.js +1 -46
- package/dist/schema/utils/node-parser.js +1 -369
- package/dist/schema/utils/object-type-utils.js +1 -35
- package/dist/schema/utils/permission-index-utils.js +1 -7
- package/dist/schema/utils/permission-machine-check.js +1 -121
- package/dist/schema/utils/skills-recommendation.js +1 -77
- package/dist/schema-query/index.js +1 -810
- package/dist/schemas/account_operation.output.json +5 -2
- package/dist/schemas/bridge_operation.output.json +5 -2
- package/dist/schemas/evaluation_operation.output.json +112 -7
- package/dist/schemas/evaluation_operation.schema.json +93 -6
- package/dist/schemas/index.json +1 -1
- package/dist/schemas/intent_radar.output.json +4 -1
- package/dist/schemas/intent_radar.schema.json +4 -1
- package/dist/schemas/local_info_operation.output.json +5 -2
- package/dist/schemas/local_mark_operation.output.json +5 -2
- package/dist/schemas/messenger_operation.output.json +5 -2
- package/dist/schemas/onchain_events.output.json +5 -2
- package/dist/schemas/onchain_operations.output.json +5 -2
- package/dist/schemas/onchain_operations.schema.json +4 -4
- package/dist/schemas/onchain_operations_allocation.schema.json +1 -1
- package/dist/schemas/onchain_operations_machine.schema.json +2 -2
- package/dist/schemas/onchain_operations_service.schema.json +1 -1
- package/dist/schemas/onchain_table_data.output.json +6 -3
- package/dist/schemas/persona_operation.output.json +4 -1
- package/dist/schemas/persona_operation.schema.json +4 -1
- package/dist/schemas/project_operation.output.json +28 -8
- package/dist/schemas/query_toolkit.output.json +8 -5
- package/dist/schemas/wowok_buildin_info.output.json +132 -0
- package/dist/schemas/wowok_buildin_info.schema.json +14 -0
- package/dist/telemetry/index.js +1 -112
- package/dist/telemetry/redact.js +1 -23
- package/dist/telemetry/storage.js +1 -80
- package/dist/tools/handlers/bridge.js +1 -1
- package/dist/tools/handlers/config.js +1 -74
- package/dist/tools/handlers/evaluation.js +1 -123
- package/dist/tools/handlers/file-export.js +1 -90
- package/dist/tools/handlers/intent-radar.js +1 -76
- package/dist/tools/handlers/local.js +1 -53
- package/dist/tools/handlers/messenger.js +1 -188
- package/dist/tools/handlers/onchain.js +1 -1180
- package/dist/tools/handlers/persona.js +1 -89
- package/dist/tools/handlers/project.js +1 -211
- package/dist/tools/handlers/query.js +1 -434
- package/dist/tools/handlers/schema-query.js +1 -176
- package/dist/tools/handlers/task-status.js +1 -26
- package/dist/tools/handlers/trust.js +1 -380
- package/dist/tools/handlers/wip.js +1 -90
- package/dist/tools/index.js +1 -1382
- package/dist/tools/retry.js +1 -85
- package/dist/tools/rules-hook.js +1 -23
- package/dist/tools/shared.js +1 -130
- package/dist/tools/types.js +1 -1
- package/dist/tools/upgrade-check.d.ts +19 -0
- package/dist/tools/upgrade-check.js +1 -0
- package/dist/tools/wip-deploy-assist.js +1 -306
- package/dist/tools/wrap.js +1 -500
- package/package.json +4 -2
|
@@ -1,198 +1 @@
|
|
|
1
|
-
export const TRUST_METRICS_VERSION = 1;
|
|
2
|
-
const TRUST_LEVELS = [
|
|
3
|
-
{ min: 75, level: "trusted", label: "High trust" },
|
|
4
|
-
{ min: 50, level: "moderate", label: "Moderate trust" },
|
|
5
|
-
{ min: 25, level: "caution", label: "Needs attention" },
|
|
6
|
-
{ min: 0, level: "high_risk", label: "High risk" },
|
|
7
|
-
];
|
|
8
|
-
export function computeServiceTrustScore(metrics) {
|
|
9
|
-
const breakdown = [];
|
|
10
|
-
const warnings = [];
|
|
11
|
-
const arbScore = computeArbitrationDimension(metrics);
|
|
12
|
-
breakdown.push(arbScore);
|
|
13
|
-
if (arbScore.score < arbScore.maxScore * 0.3) {
|
|
14
|
-
warnings.push("Arbitration trust score is low; recommend checking arbitration records");
|
|
15
|
-
}
|
|
16
|
-
const reviewScore = computeReviewDimension(metrics);
|
|
17
|
-
breakdown.push(reviewScore);
|
|
18
|
-
if (reviewScore.score < reviewScore.maxScore * 0.3 && metrics.reviewStats) {
|
|
19
|
-
warnings.push(`Low like rate (${metrics.reviewStats.likes}/${metrics.reviewStats.totalReviews})`);
|
|
20
|
-
}
|
|
21
|
-
const fulfillmentScore = computeFulfillmentDimension(metrics);
|
|
22
|
-
breakdown.push(fulfillmentScore);
|
|
23
|
-
if (metrics.completedRate !== undefined && metrics.completedRate < 0.7) {
|
|
24
|
-
warnings.push(`Completion rate only ${Math.round(metrics.completedRate * 100)}%`);
|
|
25
|
-
}
|
|
26
|
-
const fundScore = computeFundDimension(metrics);
|
|
27
|
-
breakdown.push(fundScore);
|
|
28
|
-
if (metrics.compensationFundBalance === undefined || metrics.compensationFundBalance === 0n) {
|
|
29
|
-
warnings.push("No compensation fund; insufficient protection of customer rights");
|
|
30
|
-
}
|
|
31
|
-
const transparencyScore = computeTransparencyDimension(metrics);
|
|
32
|
-
breakdown.push(transparencyScore);
|
|
33
|
-
const totalScore = breakdown.reduce((sum, d) => sum + d.score, 0);
|
|
34
|
-
const level = TRUST_LEVELS.find((l) => totalScore >= l.min)?.level ?? "high_risk";
|
|
35
|
-
const label = TRUST_LEVELS.find((l) => totalScore >= l.min)?.label ?? "High risk";
|
|
36
|
-
const summary = buildSummary(totalScore, label, metrics, breakdown);
|
|
37
|
-
return { score: totalScore, level, breakdown, summary, warnings };
|
|
38
|
-
}
|
|
39
|
-
function computeArbitrationDimension(metrics) {
|
|
40
|
-
const maxScore = 30;
|
|
41
|
-
if (metrics.arbitrationScore === undefined && metrics.arbitrationVotingGuardCount === undefined) {
|
|
42
|
-
return {
|
|
43
|
-
name: "arbitration",
|
|
44
|
-
score: maxScore * 0.25,
|
|
45
|
-
maxScore,
|
|
46
|
-
description: "Arbitration trust score (no data; default low because arbitration is critical)",
|
|
47
|
-
humanReadable: "Arbitration: no data (default low — critical missing)",
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
let score = 0;
|
|
51
|
-
const parts = [];
|
|
52
|
-
if (metrics.arbitrationScore !== undefined) {
|
|
53
|
-
const baseScore = Math.round((metrics.arbitrationScore / 100) * 10);
|
|
54
|
-
score += baseScore;
|
|
55
|
-
parts.push(`score ${metrics.arbitrationScore}/100`);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
score += 3;
|
|
59
|
-
}
|
|
60
|
-
if (metrics.arbitrationVotingGuardCount !== undefined && metrics.arbitrationVotingGuardCount > 0) {
|
|
61
|
-
score += 5;
|
|
62
|
-
parts.push(`${metrics.arbitrationVotingGuardCount} voting_guard(s)`);
|
|
63
|
-
}
|
|
64
|
-
if (metrics.arbitrationFeeBalance !== undefined && metrics.arbitrationFeeBalance > 0n) {
|
|
65
|
-
score += 5;
|
|
66
|
-
parts.push("fee funded");
|
|
67
|
-
}
|
|
68
|
-
if (metrics.arbitrationPaused === false) {
|
|
69
|
-
score += 5;
|
|
70
|
-
parts.push("active");
|
|
71
|
-
}
|
|
72
|
-
else if (metrics.arbitrationPaused === true) {
|
|
73
|
-
parts.push("paused");
|
|
74
|
-
}
|
|
75
|
-
if (metrics.arbitrationCases !== undefined && metrics.arbitrationCases > 0) {
|
|
76
|
-
score += 5;
|
|
77
|
-
parts.push(`${metrics.arbitrationCases} case(s)`);
|
|
78
|
-
}
|
|
79
|
-
score = Math.min(maxScore, score);
|
|
80
|
-
return {
|
|
81
|
-
name: "arbitration",
|
|
82
|
-
score,
|
|
83
|
-
maxScore,
|
|
84
|
-
description: `Arbitration config: ${parts.join(", ")}`,
|
|
85
|
-
humanReadable: `Arbitration: ${parts.join(", ")}`,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
function computeReviewDimension(metrics) {
|
|
89
|
-
const maxScore = 25;
|
|
90
|
-
if (!metrics.reviewStats || metrics.reviewStats.totalReviews === 0) {
|
|
91
|
-
return { name: "reviews", score: maxScore * 0.5, maxScore, description: "Review reputation (no review data)", humanReadable: "Reviews: no data" };
|
|
92
|
-
}
|
|
93
|
-
const { likes, dislikes, verifiedReviews, totalReviews } = metrics.reviewStats;
|
|
94
|
-
const likeRate = likes / Math.max(1, totalReviews);
|
|
95
|
-
const verifiedBoost = Math.min(5, verifiedReviews);
|
|
96
|
-
const score = Math.round(likeRate * (maxScore - 5) + verifiedBoost);
|
|
97
|
-
return {
|
|
98
|
-
name: "reviews",
|
|
99
|
-
score: Math.min(maxScore, score),
|
|
100
|
-
maxScore,
|
|
101
|
-
description: `Like rate ${Math.round(likeRate * 100)}% (${totalReviews} reviews, ${verifiedReviews} verified)`,
|
|
102
|
-
humanReadable: `Like rate ${Math.round(likeRate * 100)}% (${totalReviews} reviews)`,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
function computeFulfillmentDimension(metrics) {
|
|
106
|
-
const maxScore = 20;
|
|
107
|
-
if (metrics.orderCount === undefined) {
|
|
108
|
-
return { name: "fulfillment", score: maxScore * 0.5, maxScore, description: "Fulfillment record (no order data)", humanReadable: "Fulfillment: no data" };
|
|
109
|
-
}
|
|
110
|
-
let score = 0;
|
|
111
|
-
const orderScore = Math.min(10, Math.floor(metrics.orderCount / 5));
|
|
112
|
-
score += orderScore;
|
|
113
|
-
if (metrics.completedRate !== undefined) {
|
|
114
|
-
score += Math.round(metrics.completedRate * 10);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
score += 5;
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
name: "fulfillment",
|
|
121
|
-
score: Math.min(maxScore, score),
|
|
122
|
-
maxScore,
|
|
123
|
-
description: `Completed ${metrics.orderCount} orders, completion rate ${metrics.completedRate !== undefined ? Math.round(metrics.completedRate * 100) + "%" : "unknown"}`,
|
|
124
|
-
humanReadable: `Fulfillment: ${metrics.orderCount} orders${metrics.avgCompletionTime !== undefined ? `, avg ${metrics.avgCompletionTime}h` : ""}`,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function computeFundDimension(metrics) {
|
|
128
|
-
const maxScore = 15;
|
|
129
|
-
if (metrics.compensationFundBalance === undefined || metrics.compensationFundBalance === 0n) {
|
|
130
|
-
return { name: "fund_safety", score: 0, maxScore, description: "No compensation fund", humanReadable: "Compensation fund: none" };
|
|
131
|
-
}
|
|
132
|
-
const fund = metrics.compensationFundBalance;
|
|
133
|
-
if (metrics.typicalOrderAmount !== undefined && metrics.typicalOrderAmount > 0n) {
|
|
134
|
-
const ratio = Number((fund * 100n) / metrics.typicalOrderAmount) / 100;
|
|
135
|
-
let score;
|
|
136
|
-
let humanReadable;
|
|
137
|
-
if (ratio >= 10) {
|
|
138
|
-
score = maxScore;
|
|
139
|
-
humanReadable = `Compensation fund: ${ratio.toFixed(1)}x order amount (excellent)`;
|
|
140
|
-
}
|
|
141
|
-
else if (ratio >= 1) {
|
|
142
|
-
score = 10 + Math.round((ratio - 1) / 9 * 5);
|
|
143
|
-
humanReadable = `Compensation fund: ${ratio.toFixed(1)}x order amount (covers ≥1 payout)`;
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
score = Math.round(ratio * 10);
|
|
147
|
-
humanReadable = `Compensation fund: ${ratio.toFixed(1)}x order amount (insufficient)`;
|
|
148
|
-
}
|
|
149
|
-
return {
|
|
150
|
-
name: "fund_safety",
|
|
151
|
-
score: Math.min(maxScore, score),
|
|
152
|
-
maxScore,
|
|
153
|
-
description: `Fund ${fund.toString()} / typical order ${metrics.typicalOrderAmount.toString()} = ${ratio.toFixed(2)}x`,
|
|
154
|
-
humanReadable,
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
const threshold = 1000000000000n;
|
|
158
|
-
const ratio = Number(metrics.compensationFundBalance * 100n / threshold) / 100;
|
|
159
|
-
const score = Math.min(maxScore, Math.round(ratio * maxScore));
|
|
160
|
-
return {
|
|
161
|
-
name: "fund_safety",
|
|
162
|
-
score,
|
|
163
|
-
maxScore,
|
|
164
|
-
description: `Compensation fund ${metrics.compensationFundBalance} smallest unit (absolute threshold fallback)`,
|
|
165
|
-
humanReadable: `Compensation fund: ${ratio.toFixed(2)}x absolute threshold`,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
function computeTransparencyDimension(metrics) {
|
|
169
|
-
const maxScore = 10;
|
|
170
|
-
let score = 0;
|
|
171
|
-
if (metrics.hasPublishedEvents)
|
|
172
|
-
score += 4;
|
|
173
|
-
if (metrics.hasMachineBound)
|
|
174
|
-
score += 3;
|
|
175
|
-
if (metrics.hasBuyGuard)
|
|
176
|
-
score += 3;
|
|
177
|
-
return {
|
|
178
|
-
name: "transparency",
|
|
179
|
-
score: Math.min(maxScore, score),
|
|
180
|
-
maxScore,
|
|
181
|
-
description: `On-chain events ${metrics.hasPublishedEvents ? "✓" : "✗"}, Machine ${metrics.hasMachineBound ? "✓" : "✗"}, Guard ${metrics.hasBuyGuard ? "✓" : "✗"}`,
|
|
182
|
-
humanReadable: `Transparency: ${["Events", "Machine", "Guard"].filter((_, i) => [metrics.hasPublishedEvents, metrics.hasMachineBound, metrics.hasBuyGuard][i]).join("+") || "none"}`,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
function buildSummary(score, label, metrics, breakdown) {
|
|
186
|
-
const parts = [`Trust score ${score}/100 (${label})`];
|
|
187
|
-
for (const d of breakdown) {
|
|
188
|
-
parts.push(`${d.humanReadable}`);
|
|
189
|
-
}
|
|
190
|
-
return parts.join("; ");
|
|
191
|
-
}
|
|
192
|
-
export function quickTrustCheck(metrics) {
|
|
193
|
-
const result = computeServiceTrustScore(metrics);
|
|
194
|
-
if (result.score < 25) {
|
|
195
|
-
return { pass: false, reason: `Trust score ${result.score}/100, high risk: ${result.warnings.join("; ")}` };
|
|
196
|
-
}
|
|
197
|
-
return { pass: true, reason: `Trust score ${result.score}/100 (${result.level})` };
|
|
198
|
-
}
|
|
1
|
+
export const TRUST_METRICS_VERSION=0x1;const TRUST_LEVELS=[{'min':0x4b,'level':'trusted','label':'High\x20trust'},{'min':0x32,'level':'moderate','label':'Moderate\x20trust'},{'min':0x19,'level':'caution','label':'Needs\x20attention'},{'min':0x0,'level':'high_risk','label':'High\x20risk'}];export function computeServiceTrustScore(a){const b=[],c=[],d=computeArbitrationDimension(a);b['push'](d);d['score']<d['maxScore']*0.3&&c['push']('Arbitration\x20trust\x20score\x20is\x20low;\x20recommend\x20checking\x20arbitration\x20records');const e=computeReviewDimension(a);b['push'](e);e['score']<e['maxScore']*0.3&&a['reviewStats']&&c['push']('Low\x20like\x20rate\x20('+a['reviewStats']['likes']+'/'+a['reviewStats']['totalReviews']+')');const f=computeFulfillmentDimension(a);b['push'](f);a['completedRate']!==undefined&&a['completedRate']<0.7&&c['push']('Completion\x20rate\x20only\x20'+Math['round'](a['completedRate']*0x64)+'%');const g=computeFundDimension(a);b['push'](g);(a['compensationFundBalance']===undefined||a['compensationFundBalance']===0x0n)&&c['push']('No\x20compensation\x20fund;\x20insufficient\x20protection\x20of\x20customer\x20rights');const h=computeTransparencyDimension(a);b['push'](h);const i=b['reduce']((m,n)=>m+n['score'],0x0),j=TRUST_LEVELS['find'](m=>i>=m['min'])?.['level']??'high_risk',k=TRUST_LEVELS['find'](m=>i>=m['min'])?.['label']??'High\x20risk',l=buildSummary(i,k,a,b);return{'score':i,'level':j,'breakdown':b,'summary':l,'warnings':c};}function computeArbitrationDimension(a){const b=0x1e;if(a['arbitrationScore']===undefined&&a['arbitrationVotingGuardCount']===undefined)return{'name':'arbitration','score':b*0.25,'maxScore':b,'description':'Arbitration\x20trust\x20score\x20(no\x20data;\x20default\x20low\x20because\x20arbitration\x20is\x20critical)','humanReadable':'Arbitration:\x20no\x20data\x20(default\x20low\x20—\x20critical\x20missing)'};let c=0x0;const d=[];if(a['arbitrationScore']!==undefined){const e=Math['round'](a['arbitrationScore']/0x64*0xa);c+=e,d['push']('score\x20'+a['arbitrationScore']+'/100');}else c+=0x3;a['arbitrationVotingGuardCount']!==undefined&&a['arbitrationVotingGuardCount']>0x0&&(c+=0x5,d['push'](a['arbitrationVotingGuardCount']+'\x20voting_guard(s)'));a['arbitrationFeeBalance']!==undefined&&a['arbitrationFeeBalance']>0x0n&&(c+=0x5,d['push']('fee\x20funded'));if(a['arbitrationPaused']===![])c+=0x5,d['push']('active');else a['arbitrationPaused']===!![]&&d['push']('paused');return a['arbitrationCases']!==undefined&&a['arbitrationCases']>0x0&&(c+=0x5,d['push'](a['arbitrationCases']+'\x20case(s)')),c=Math['min'](b,c),{'name':'arbitration','score':c,'maxScore':b,'description':'Arbitration\x20config:\x20'+d['join'](',\x20'),'humanReadable':'Arbitration:\x20'+d['join'](',\x20')};}function computeReviewDimension(a){const b=0x19;if(!a['reviewStats']||a['reviewStats']['totalReviews']===0x0)return{'name':'reviews','score':b*0.5,'maxScore':b,'description':'Review\x20reputation\x20(no\x20review\x20data)','humanReadable':'Reviews:\x20no\x20data'};const {likes:c,dislikes:d,verifiedReviews:e,totalReviews:f}=a['reviewStats'],g=c/Math['max'](0x1,f),h=Math['min'](0x5,e),i=Math['round'](g*(b-0x5)+h);return{'name':'reviews','score':Math['min'](b,i),'maxScore':b,'description':'Like\x20rate\x20'+Math['round'](g*0x64)+'%\x20('+f+'\x20reviews,\x20'+e+'\x20verified)','humanReadable':'Like\x20rate\x20'+Math['round'](g*0x64)+'%\x20('+f+'\x20reviews)'};}function computeFulfillmentDimension(a){const b=0x14;if(a['orderCount']===undefined)return{'name':'fulfillment','score':b*0.5,'maxScore':b,'description':'Fulfillment\x20record\x20(no\x20order\x20data)','humanReadable':'Fulfillment:\x20no\x20data'};let c=0x0;const d=Math['min'](0xa,Math['floor'](a['orderCount']/0x5));return c+=d,a['completedRate']!==undefined?c+=Math['round'](a['completedRate']*0xa):c+=0x5,{'name':'fulfillment','score':Math['min'](b,c),'maxScore':b,'description':'Completed\x20'+a['orderCount']+'\x20orders,\x20completion\x20rate\x20'+(a['completedRate']!==undefined?Math['round'](a['completedRate']*0x64)+'%':'unknown'),'humanReadable':'Fulfillment:\x20'+a['orderCount']+'\x20orders'+(a['avgCompletionTime']!==undefined?',\x20avg\x20'+a['avgCompletionTime']+'h':'')};}function computeFundDimension(a){const b=0xf;if(a['compensationFundBalance']===undefined||a['compensationFundBalance']===0x0n)return{'name':'fund_safety','score':0x0,'maxScore':b,'description':'No\x20compensation\x20fund','humanReadable':'Compensation\x20fund:\x20none'};const c=a['compensationFundBalance'];if(a['typicalOrderAmount']!==undefined&&a['typicalOrderAmount']>0x0n){const g=Number(c*0x64n/a['typicalOrderAmount'])/0x64;let h,i;if(g>=0xa)h=b,i='Compensation\x20fund:\x20'+g['toFixed'](0x1)+'x\x20order\x20amount\x20(excellent)';else g>=0x1?(h=0xa+Math['round']((g-0x1)/0x9*0x5),i='Compensation\x20fund:\x20'+g['toFixed'](0x1)+'x\x20order\x20amount\x20(covers\x20≥1\x20payout)'):(h=Math['round'](g*0xa),i='Compensation\x20fund:\x20'+g['toFixed'](0x1)+'x\x20order\x20amount\x20(insufficient)');return{'name':'fund_safety','score':Math['min'](b,h),'maxScore':b,'description':'Fund\x20'+c['toString']()+'\x20/\x20typical\x20order\x20'+a['typicalOrderAmount']['toString']()+'\x20=\x20'+g['toFixed'](0x2)+'x','humanReadable':i};}const d=0xe8d4a51000n,e=Number(a['compensationFundBalance']*0x64n/d)/0x64,f=Math['min'](b,Math['round'](e*b));return{'name':'fund_safety','score':f,'maxScore':b,'description':'Compensation\x20fund\x20'+a['compensationFundBalance']+'\x20smallest\x20unit\x20(absolute\x20threshold\x20fallback)','humanReadable':'Compensation\x20fund:\x20'+e['toFixed'](0x2)+'x\x20absolute\x20threshold'};}function computeTransparencyDimension(a){const b=0xa;let c=0x0;if(a['hasPublishedEvents'])c+=0x4;if(a['hasMachineBound'])c+=0x3;if(a['hasBuyGuard'])c+=0x3;return{'name':'transparency','score':Math['min'](b,c),'maxScore':b,'description':'On-chain\x20events\x20'+(a['hasPublishedEvents']?'✓':'✗')+',\x20Machine\x20'+(a['hasMachineBound']?'✓':'✗')+',\x20Guard\x20'+(a['hasBuyGuard']?'✓':'✗'),'humanReadable':'Transparency:\x20'+(['Events','Machine','Guard']['filter']((d,e)=>[a['hasPublishedEvents'],a['hasMachineBound'],a['hasBuyGuard']][e])['join']('+')||'none')};}function buildSummary(a,b,c,e){const f=['Trust\x20score\x20'+a+'/100\x20('+b+')'];for(const g of e){f['push'](''+g['humanReadable']);}return f['join'](';\x20');}export function quickTrustCheck(a){const b=computeServiceTrustScore(a);if(b['score']<0x19)return{'pass':![],'reason':'Trust\x20score\x20'+b['score']+'/100,\x20high\x20risk:\x20'+b['warnings']['join'](';\x20')};return{'pass':!![],'reason':'Trust\x20score\x20'+b['score']+'/100\x20('+b['level']+')'};}
|
|
@@ -1,135 +1 @@
|
|
|
1
|
-
const USER_ADDRESS_BYTE_MAX =
|
|
2
|
-
const OBJECT_ADDRESS_BYTE = 0xf1;
|
|
3
|
-
const CHILD_OBJECT_ADDRESS_BYTE = 0xf0;
|
|
4
|
-
const R_U_01 = {
|
|
5
|
-
rule: {
|
|
6
|
-
id: "R-UTIL-01",
|
|
7
|
-
level: "LOW",
|
|
8
|
-
category: "semantic",
|
|
9
|
-
title: "is_chiild_object_address_byte has a typo ('chiild') — cannot be renamed post-publish",
|
|
10
|
-
description: "util.move:30 defines is_chiild_object_address_byte (note the 'chiild' typo). The " +
|
|
11
|
-
"function is already published on mainnet, so the name cannot be fixed without a " +
|
|
12
|
-
"breaking package upgrade. Callers must use the misspelled name exactly; SDK wrappers " +
|
|
13
|
-
"should expose a correctly-spelled alias and route to the typo function.",
|
|
14
|
-
affected_stakeholders: ["caller"],
|
|
15
|
-
scenario: "Caller writes is_child_object_address_byte; Move linker cannot resolve the symbol",
|
|
16
|
-
mitigation: "SDK should expose isChildObjectAddressByte as the public API and internally call the " +
|
|
17
|
-
"typo'd Move function. Document the typo so future maintainers don't 'fix' it.",
|
|
18
|
-
auto_fixable: false,
|
|
19
|
-
},
|
|
20
|
-
check: (ctx) => {
|
|
21
|
-
if (!ctx.uses_typo_function_name)
|
|
22
|
-
return null;
|
|
23
|
-
return { ...R_U_01.rule, evidence: "uses_typo_function_name=true (must use 'chiild')" };
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
const R_U_02 = {
|
|
27
|
-
rule: {
|
|
28
|
-
id: "R-UTIL-02",
|
|
29
|
-
level: "MEDIUM",
|
|
30
|
-
category: "semantic",
|
|
31
|
-
title: "Address-byte thresholds are hardcoded — Wow protocol upgrades could invalidate them",
|
|
32
|
-
description: `util.move classifies addresses by first byte: user (≤ ${USER_ADDRESS_BYTE_MAX}), ` +
|
|
33
|
-
`object (${OBJECT_ADDRESS_BYTE}), child_object (${CHILD_OBJECT_ADDRESS_BYTE}). ` +
|
|
34
|
-
`These thresholds are hardcoded as Move constants, not configurable. If a future Wow ` +
|
|
35
|
-
`protocol upgrade changes the address byte layout (e.g. reserves a new prefix), Util ` +
|
|
36
|
-
`would silently misclassify addresses until the Move code is upgraded.`,
|
|
37
|
-
affected_stakeholders: ["caller", "system"],
|
|
38
|
-
scenario: "Wow protocol upgrade introduces a new address prefix; Util misclassifies it as user",
|
|
39
|
-
mitigation: "Track Wow protocol upgrades that touch address layout. When a change ships, upgrade " +
|
|
40
|
-
"util.move and the SDK in lockstep. Add a sync test that asserts the byte values.",
|
|
41
|
-
auto_fixable: false,
|
|
42
|
-
},
|
|
43
|
-
check: (ctx) => {
|
|
44
|
-
if (!ctx.assumes_stable_address_bytes)
|
|
45
|
-
return null;
|
|
46
|
-
return { ...R_U_02.rule, evidence: `assumes_stable_address_bytes=true (hardcoded ${USER_ADDRESS_BYTE_MAX}/${OBJECT_ADDRESS_BYTE}/${CHILD_OBJECT_ADDRESS_BYTE})` };
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
const R_U_03 = {
|
|
50
|
-
rule: {
|
|
51
|
-
id: "R-UTIL-03",
|
|
52
|
-
level: "LOW",
|
|
53
|
-
category: "structural",
|
|
54
|
-
title: "util.ts is ~50KB — over-concentrated, hard to navigate",
|
|
55
|
-
description: "The SDK util.ts is ~50428 bytes, mixing BCS structure definitions, query condition " +
|
|
56
|
-
"builders, Guard query helpers, and address utilities. The size makes it hard to " +
|
|
57
|
-
"navigate and increases the risk of accidental circular imports. New contributors " +
|
|
58
|
-
"often import the wrong symbol because so many are exported from one file.",
|
|
59
|
-
affected_stakeholders: ["caller", "system"],
|
|
60
|
-
scenario: "Developer imports ProgressHistoryFindConditionsBCS and accidentally pulls in unrelated code",
|
|
61
|
-
mitigation: "Consider splitting util.ts into focused sub-modules (bcs.ts, query.ts, address.ts). " +
|
|
62
|
-
"Until then, prefer named imports over namespace imports to keep bundles lean.",
|
|
63
|
-
auto_fixable: false,
|
|
64
|
-
},
|
|
65
|
-
check: (ctx) => {
|
|
66
|
-
if (!ctx.large_util_import)
|
|
67
|
-
return null;
|
|
68
|
-
return { ...R_U_03.rule, evidence: "large_util_import=true (consider sub-modules)" };
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
const R_U_04 = {
|
|
72
|
-
rule: {
|
|
73
|
-
id: "R-UTIL-04",
|
|
74
|
-
level: "LOW",
|
|
75
|
-
category: "lifecycle",
|
|
76
|
-
title: "Util emits no events — tool-call observability is caller's responsibility",
|
|
77
|
-
description: "Util functions are pure: they neither emit nor consume events. Callers cannot rely on " +
|
|
78
|
-
"an event stream to trace Util invocations. For audit and debugging, the calling " +
|
|
79
|
-
"module must record its own log entries around Util calls.",
|
|
80
|
-
affected_stakeholders: ["caller"],
|
|
81
|
-
scenario: "Auditor expects Util-call events; none exist, the call chain is invisible",
|
|
82
|
-
mitigation: "Callers should emit their own events or write logs around Util calls when auditability " +
|
|
83
|
-
"is required. Treat Util as an opaque library function.",
|
|
84
|
-
auto_fixable: false,
|
|
85
|
-
},
|
|
86
|
-
check: (ctx) => {
|
|
87
|
-
if (!ctx.expects_util_events)
|
|
88
|
-
return null;
|
|
89
|
-
return { ...R_U_04.rule, evidence: "expects_util_events=true (none emitted)" };
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
const R_U_05 = {
|
|
93
|
-
rule: {
|
|
94
|
-
id: "R-UTIL-05",
|
|
95
|
-
level: "MEDIUM",
|
|
96
|
-
category: "cross_object",
|
|
97
|
-
title: "SDK BCS structures must stay in sync with Move structs — drift breaks queries",
|
|
98
|
-
description: "util.ts defines BCS structures for Progress History / Session / Forward / Record " +
|
|
99
|
-
"query conditions. These must match the Move struct layouts byte-for-byte. If a Move " +
|
|
100
|
-
"struct adds a field and the SDK BCS is not regenerated, query submissions will " +
|
|
101
|
-
"deserialize incorrectly on-chain, producing silent failures or aborts.",
|
|
102
|
-
affected_stakeholders: ["caller", "system"],
|
|
103
|
-
scenario: "Progress struct adds a field; SDK BCS is stale; queries return wrong results",
|
|
104
|
-
mitigation: "Generate BCS structures from Move source via codegen, or run a sync test that " +
|
|
105
|
-
"compares SDK BCS layouts against Move structs on every release.",
|
|
106
|
-
auto_fixable: false,
|
|
107
|
-
},
|
|
108
|
-
check: (ctx) => {
|
|
109
|
-
if (ctx.bcs_manually_synced === undefined)
|
|
110
|
-
return null;
|
|
111
|
-
if (!ctx.bcs_manually_synced)
|
|
112
|
-
return null;
|
|
113
|
-
return { ...R_U_05.rule, evidence: "bcs_manually_synced=true (drift risk)" };
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
export const UTIL_RISK_RULES = [
|
|
117
|
-
R_U_01,
|
|
118
|
-
R_U_02,
|
|
119
|
-
R_U_03,
|
|
120
|
-
R_U_04,
|
|
121
|
-
R_U_05,
|
|
122
|
-
];
|
|
123
|
-
export const UTIL_RISK_VERSION = "1.0.0";
|
|
124
|
-
export function checkUtilRisks(ctx) {
|
|
125
|
-
const risks = [];
|
|
126
|
-
for (const rule of UTIL_RISK_RULES) {
|
|
127
|
-
const r = rule.check(ctx);
|
|
128
|
-
if (r)
|
|
129
|
-
risks.push(r);
|
|
130
|
-
}
|
|
131
|
-
return risks;
|
|
132
|
-
}
|
|
133
|
-
export function getUtilRiskById(id) {
|
|
134
|
-
return UTIL_RISK_RULES.find(r => r.rule.id === id)?.rule;
|
|
135
|
-
}
|
|
1
|
+
const USER_ADDRESS_BYTE_MAX=0x6,OBJECT_ADDRESS_BYTE=0xf1,CHILD_OBJECT_ADDRESS_BYTE=0xf0,R_U_01={'rule':{'id':'R-UTIL-01','level':'LOW','category':'semantic','title':'is_chiild_object_address_byte\x20has\x20a\x20typo\x20(\x27chiild\x27)\x20—\x20cannot\x20be\x20renamed\x20post-publish','description':'util.move:30\x20defines\x20is_chiild_object_address_byte\x20(note\x20the\x20\x27chiild\x27\x20typo).\x20The\x20'+'function\x20is\x20already\x20published\x20on\x20mainnet,\x20so\x20the\x20name\x20cannot\x20be\x20fixed\x20without\x20a\x20'+'breaking\x20package\x20upgrade.\x20Callers\x20must\x20use\x20the\x20misspelled\x20name\x20exactly;\x20SDK\x20wrappers\x20'+'should\x20expose\x20a\x20correctly-spelled\x20alias\x20and\x20route\x20to\x20the\x20typo\x20function.','affected_stakeholders':['caller'],'scenario':'Caller\x20writes\x20is_child_object_address_byte;\x20Move\x20linker\x20cannot\x20resolve\x20the\x20symbol','mitigation':'SDK\x20should\x20expose\x20isChildObjectAddressByte\x20as\x20the\x20public\x20API\x20and\x20internally\x20call\x20the\x20'+'typo\x27d\x20Move\x20function.\x20Document\x20the\x20typo\x20so\x20future\x20maintainers\x20don\x27t\x20\x27fix\x27\x20it.','auto_fixable':![]},'check':a=>{if(!a['uses_typo_function_name'])return null;return{...R_U_01['rule'],'evidence':'uses_typo_function_name=true\x20(must\x20use\x20\x27chiild\x27)'};}},R_U_02={'rule':{'id':'R-UTIL-02','level':'MEDIUM','category':'semantic','title':'Address-byte\x20thresholds\x20are\x20hardcoded\x20—\x20Wow\x20protocol\x20upgrades\x20could\x20invalidate\x20them','description':'util.move\x20classifies\x20addresses\x20by\x20first\x20byte:\x20user\x20(≤\x20'+USER_ADDRESS_BYTE_MAX+'),\x20'+('object\x20('+OBJECT_ADDRESS_BYTE+'),\x20child_object\x20('+CHILD_OBJECT_ADDRESS_BYTE+').\x20')+'These\x20thresholds\x20are\x20hardcoded\x20as\x20Move\x20constants,\x20not\x20configurable.\x20If\x20a\x20future\x20Wow\x20'+'protocol\x20upgrade\x20changes\x20the\x20address\x20byte\x20layout\x20(e.g.\x20reserves\x20a\x20new\x20prefix),\x20Util\x20'+'would\x20silently\x20misclassify\x20addresses\x20until\x20the\x20Move\x20code\x20is\x20upgraded.','affected_stakeholders':['caller','system'],'scenario':'Wow\x20protocol\x20upgrade\x20introduces\x20a\x20new\x20address\x20prefix;\x20Util\x20misclassifies\x20it\x20as\x20user','mitigation':'Track\x20Wow\x20protocol\x20upgrades\x20that\x20touch\x20address\x20layout.\x20When\x20a\x20change\x20ships,\x20upgrade\x20'+'util.move\x20and\x20the\x20SDK\x20in\x20lockstep.\x20Add\x20a\x20sync\x20test\x20that\x20asserts\x20the\x20byte\x20values.','auto_fixable':![]},'check':a=>{if(!a['assumes_stable_address_bytes'])return null;return{...R_U_02['rule'],'evidence':'assumes_stable_address_bytes=true\x20(hardcoded\x20'+USER_ADDRESS_BYTE_MAX+'/'+OBJECT_ADDRESS_BYTE+'/'+CHILD_OBJECT_ADDRESS_BYTE+')'};}},R_U_03={'rule':{'id':'R-UTIL-03','level':'LOW','category':'structural','title':'util.ts\x20is\x20~50KB\x20—\x20over-concentrated,\x20hard\x20to\x20navigate','description':'The\x20SDK\x20util.ts\x20is\x20~50428\x20bytes,\x20mixing\x20BCS\x20structure\x20definitions,\x20query\x20condition\x20'+'builders,\x20Guard\x20query\x20helpers,\x20and\x20address\x20utilities.\x20The\x20size\x20makes\x20it\x20hard\x20to\x20'+'navigate\x20and\x20increases\x20the\x20risk\x20of\x20accidental\x20circular\x20imports.\x20New\x20contributors\x20'+'often\x20import\x20the\x20wrong\x20symbol\x20because\x20so\x20many\x20are\x20exported\x20from\x20one\x20file.','affected_stakeholders':['caller','system'],'scenario':'Developer\x20imports\x20ProgressHistoryFindConditionsBCS\x20and\x20accidentally\x20pulls\x20in\x20unrelated\x20code','mitigation':'Consider\x20splitting\x20util.ts\x20into\x20focused\x20sub-modules\x20(bcs.ts,\x20query.ts,\x20address.ts).\x20'+'Until\x20then,\x20prefer\x20named\x20imports\x20over\x20namespace\x20imports\x20to\x20keep\x20bundles\x20lean.','auto_fixable':![]},'check':a=>{if(!a['large_util_import'])return null;return{...R_U_03['rule'],'evidence':'large_util_import=true\x20(consider\x20sub-modules)'};}},R_U_04={'rule':{'id':'R-UTIL-04','level':'LOW','category':'lifecycle','title':'Util\x20emits\x20no\x20events\x20—\x20tool-call\x20observability\x20is\x20caller\x27s\x20responsibility','description':'Util\x20functions\x20are\x20pure:\x20they\x20neither\x20emit\x20nor\x20consume\x20events.\x20Callers\x20cannot\x20rely\x20on\x20'+'an\x20event\x20stream\x20to\x20trace\x20Util\x20invocations.\x20For\x20audit\x20and\x20debugging,\x20the\x20calling\x20'+'module\x20must\x20record\x20its\x20own\x20log\x20entries\x20around\x20Util\x20calls.','affected_stakeholders':['caller'],'scenario':'Auditor\x20expects\x20Util-call\x20events;\x20none\x20exist,\x20the\x20call\x20chain\x20is\x20invisible','mitigation':'Callers\x20should\x20emit\x20their\x20own\x20events\x20or\x20write\x20logs\x20around\x20Util\x20calls\x20when\x20auditability\x20'+'is\x20required.\x20Treat\x20Util\x20as\x20an\x20opaque\x20library\x20function.','auto_fixable':![]},'check':a=>{if(!a['expects_util_events'])return null;return{...R_U_04['rule'],'evidence':'expects_util_events=true\x20(none\x20emitted)'};}},R_U_05={'rule':{'id':'R-UTIL-05','level':'MEDIUM','category':'cross_object','title':'SDK\x20BCS\x20structures\x20must\x20stay\x20in\x20sync\x20with\x20Move\x20structs\x20—\x20drift\x20breaks\x20queries','description':'util.ts\x20defines\x20BCS\x20structures\x20for\x20Progress\x20History\x20/\x20Session\x20/\x20Forward\x20/\x20Record\x20'+'query\x20conditions.\x20These\x20must\x20match\x20the\x20Move\x20struct\x20layouts\x20byte-for-byte.\x20If\x20a\x20Move\x20'+'struct\x20adds\x20a\x20field\x20and\x20the\x20SDK\x20BCS\x20is\x20not\x20regenerated,\x20query\x20submissions\x20will\x20'+'deserialize\x20incorrectly\x20on-chain,\x20producing\x20silent\x20failures\x20or\x20aborts.','affected_stakeholders':['caller','system'],'scenario':'Progress\x20struct\x20adds\x20a\x20field;\x20SDK\x20BCS\x20is\x20stale;\x20queries\x20return\x20wrong\x20results','mitigation':'Generate\x20BCS\x20structures\x20from\x20Move\x20source\x20via\x20codegen,\x20or\x20run\x20a\x20sync\x20test\x20that\x20'+'compares\x20SDK\x20BCS\x20layouts\x20against\x20Move\x20structs\x20on\x20every\x20release.','auto_fixable':![]},'check':a=>{if(a['bcs_manually_synced']===undefined)return null;if(!a['bcs_manually_synced'])return null;return{...R_U_05['rule'],'evidence':'bcs_manually_synced=true\x20(drift\x20risk)'};}};export const UTIL_RISK_RULES=[R_U_01,R_U_02,R_U_03,R_U_04,R_U_05];export const UTIL_RISK_VERSION='1.0.0';export function checkUtilRisks(a){const b=[];for(const c of UTIL_RISK_RULES){const d=c['check'](a);if(d)b['push'](d);}return b;}export function getUtilRiskById(a){return UTIL_RISK_RULES['find'](b=>b['rule']['id']===a)?.['rule'];}
|
|
@@ -1,132 +1 @@
|
|
|
1
|
-
function percentile(
|
|
2
|
-
if (sortedValues.length === 0)
|
|
3
|
-
return 0;
|
|
4
|
-
const idx = Math.ceil((p / 100) * sortedValues.length) - 1;
|
|
5
|
-
return sortedValues[Math.max(0, idx)];
|
|
6
|
-
}
|
|
7
|
-
function topMessages(messages, limit = 5) {
|
|
8
|
-
const counts = new Map();
|
|
9
|
-
for (const msg of messages) {
|
|
10
|
-
if (!msg)
|
|
11
|
-
continue;
|
|
12
|
-
counts.set(msg, (counts.get(msg) || 0) + 1);
|
|
13
|
-
}
|
|
14
|
-
return Array.from(counts.entries())
|
|
15
|
-
.map(([message, count]) => ({ message, count }))
|
|
16
|
-
.sort((a, b) => b.count - a.count)
|
|
17
|
-
.slice(0, limit);
|
|
18
|
-
}
|
|
19
|
-
export function aggregateByTool(events) {
|
|
20
|
-
const groups = new Map();
|
|
21
|
-
for (const e of events) {
|
|
22
|
-
const key = e.tool_name || "unknown";
|
|
23
|
-
if (!groups.has(key))
|
|
24
|
-
groups.set(key, []);
|
|
25
|
-
groups.get(key).push(e);
|
|
26
|
-
}
|
|
27
|
-
const results = [];
|
|
28
|
-
for (const [tool_name, group] of groups) {
|
|
29
|
-
const total = group.length;
|
|
30
|
-
const success = group.filter((e) => e.status === "success").length;
|
|
31
|
-
const failed = group.filter((e) => e.status === "failed").length;
|
|
32
|
-
const pending = group.filter((e) => e.status === "pending_input").length;
|
|
33
|
-
const semanticHits = group.filter((e) => e.semantic_hit).length;
|
|
34
|
-
const durations = group.map((e) => e.duration_ms).sort((a, b) => a - b);
|
|
35
|
-
const errorDist = {};
|
|
36
|
-
const errorMsgs = [];
|
|
37
|
-
for (const e of group) {
|
|
38
|
-
if (e.error_code) {
|
|
39
|
-
errorDist[e.error_code] = (errorDist[e.error_code] || 0) + 1;
|
|
40
|
-
}
|
|
41
|
-
if (e.error_message)
|
|
42
|
-
errorMsgs.push(e.error_message);
|
|
43
|
-
}
|
|
44
|
-
results.push({
|
|
45
|
-
tool_name,
|
|
46
|
-
total_calls: total,
|
|
47
|
-
success_count: success,
|
|
48
|
-
failed_count: failed,
|
|
49
|
-
pending_input_count: pending,
|
|
50
|
-
success_rate: total > 0 ? success / total : 0,
|
|
51
|
-
avg_duration_ms: durations.length > 0 ? durations.reduce((a, b) => a + b, 0) / durations.length : 0,
|
|
52
|
-
p50_duration_ms: percentile(durations, 50),
|
|
53
|
-
p95_duration_ms: percentile(durations, 95),
|
|
54
|
-
semantic_hit_rate: total > 0 ? semanticHits / total : 0,
|
|
55
|
-
error_distribution: errorDist,
|
|
56
|
-
top_error_messages: topMessages(errorMsgs),
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
return results.sort((a, b) => b.total_calls - a.total_calls);
|
|
60
|
-
}
|
|
61
|
-
export function aggregateByOperation(events) {
|
|
62
|
-
const groups = new Map();
|
|
63
|
-
for (const e of events) {
|
|
64
|
-
const key = e.operation_type || "unknown";
|
|
65
|
-
if (!groups.has(key))
|
|
66
|
-
groups.set(key, []);
|
|
67
|
-
groups.get(key).push(e);
|
|
68
|
-
}
|
|
69
|
-
const results = [];
|
|
70
|
-
for (const [operation_type, group] of groups) {
|
|
71
|
-
const total = group.length;
|
|
72
|
-
const success = group.filter((e) => e.status === "success").length;
|
|
73
|
-
const semanticHits = group.filter((e) => e.semantic_hit).length;
|
|
74
|
-
const errorDist = {};
|
|
75
|
-
for (const e of group) {
|
|
76
|
-
if (e.error_code) {
|
|
77
|
-
errorDist[e.error_code] = (errorDist[e.error_code] || 0) + 1;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
results.push({
|
|
81
|
-
operation_type,
|
|
82
|
-
total_calls: total,
|
|
83
|
-
success_rate: total > 0 ? success / total : 0,
|
|
84
|
-
semantic_hit_rate: total > 0 ? semanticHits / total : 0,
|
|
85
|
-
error_distribution: errorDist,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
return results.sort((a, b) => b.total_calls - a.total_calls);
|
|
89
|
-
}
|
|
90
|
-
export function aggregate(events) {
|
|
91
|
-
const total = events.length;
|
|
92
|
-
const success = events.filter((e) => e.status === "success").length;
|
|
93
|
-
const semanticHits = events.filter((e) => e.semantic_hit).length;
|
|
94
|
-
const unknownErrors = events.filter((e) => e.error_code === "unknown").length;
|
|
95
|
-
const durations = events.map((e) => e.duration_ms);
|
|
96
|
-
const errorDist = {};
|
|
97
|
-
const intentDist = {};
|
|
98
|
-
for (const e of events) {
|
|
99
|
-
if (e.error_code) {
|
|
100
|
-
errorDist[e.error_code] = (errorDist[e.error_code] || 0) + 1;
|
|
101
|
-
}
|
|
102
|
-
if (e.intent) {
|
|
103
|
-
intentDist[e.intent] = (intentDist[e.intent] || 0) + 1;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
const timestamps = events
|
|
107
|
-
.map((e) => e.timestamp)
|
|
108
|
-
.filter(Boolean)
|
|
109
|
-
.sort();
|
|
110
|
-
return {
|
|
111
|
-
aggregation_date: new Date().toISOString(),
|
|
112
|
-
total_events: total,
|
|
113
|
-
date_range: {
|
|
114
|
-
earliest: timestamps[0] || "",
|
|
115
|
-
latest: timestamps[timestamps.length - 1] || "",
|
|
116
|
-
},
|
|
117
|
-
per_tool: aggregateByTool(events),
|
|
118
|
-
per_operation: aggregateByOperation(events),
|
|
119
|
-
overall: {
|
|
120
|
-
total_calls: total,
|
|
121
|
-
success_count: success,
|
|
122
|
-
failed_count: events.filter((e) => e.status === "failed").length,
|
|
123
|
-
success_rate: total > 0 ? success / total : 0,
|
|
124
|
-
semantic_hit_rate: total > 0 ? semanticHits / total : 0,
|
|
125
|
-
unknown_error_count: unknownErrors,
|
|
126
|
-
unknown_error_rate: total > 0 ? unknownErrors / total : 0,
|
|
127
|
-
avg_duration_ms: durations.length > 0 ? durations.reduce((a, b) => a + b, 0) / durations.length : 0,
|
|
128
|
-
},
|
|
129
|
-
error_code_distribution: errorDist,
|
|
130
|
-
intent_distribution: intentDist,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
1
|
+
function percentile(a,b){if(a['length']===0x0)return 0x0;const c=Math['ceil'](b/0x64*a['length'])-0x1;return a[Math['max'](0x0,c)];}function topMessages(a,b=0x5){const c=new Map();for(const d of a){if(!d)continue;c['set'](d,(c['get'](d)||0x0)+0x1);}return Array['from'](c['entries']())['map'](([e,f])=>({'message':e,'count':f}))['sort']((e,f)=>f['count']-e['count'])['slice'](0x0,b);}export function aggregateByTool(a){const b=new Map();for(const d of a){const f=d['tool_name']||'unknown';if(!b['has'](f))b['set'](f,[]);b['get'](f)['push'](d);}const c=[];for(const [g,h]of b){const i=h['length'],j=h['filter'](q=>q['status']==='success')['length'],k=h['filter'](q=>q['status']==='failed')['length'],l=h['filter'](q=>q['status']==='pending_input')['length'],m=h['filter'](q=>q['semantic_hit'])['length'],n=h['map'](q=>q['duration_ms'])['sort']((q,r)=>q-r),o={},p=[];for(const q of h){q['error_code']&&(o[q['error_code']]=(o[q['error_code']]||0x0)+0x1);if(q['error_message'])p['push'](q['error_message']);}c['push']({'tool_name':g,'total_calls':i,'success_count':j,'failed_count':k,'pending_input_count':l,'success_rate':i>0x0?j/ i:0x0,'avg_duration_ms':n['length']>0x0?n['reduce']((r,s)=>r+s,0x0)/n['length']:0x0,'p50_duration_ms':percentile(n,0x32),'p95_duration_ms':percentile(n,0x5f),'semantic_hit_rate':i>0x0?m/ i:0x0,'error_distribution':o,'top_error_messages':topMessages(p)});}return c['sort']((r,s)=>s['total_calls']-r['total_calls']);}export function aggregateByOperation(a){const b=new Map();for(const d of a){const f=d['operation_type']||'unknown';if(!b['has'](f))b['set'](f,[]);b['get'](f)['push'](d);}const c=[];for(const [g,h]of b){const i=h['length'],j=h['filter'](m=>m['status']==='success')['length'],k=h['filter'](m=>m['semantic_hit'])['length'],l={};for(const m of h){m['error_code']&&(l[m['error_code']]=(l[m['error_code']]||0x0)+0x1);}c['push']({'operation_type':g,'total_calls':i,'success_rate':i>0x0?j/ i:0x0,'semantic_hit_rate':i>0x0?k/ i:0x0,'error_distribution':l});}return c['sort']((n,o)=>o['total_calls']-n['total_calls']);}export function aggregate(a){const b=a['length'],c=a['filter'](k=>k['status']==='success')['length'],d=a['filter'](k=>k['semantic_hit'])['length'],f=a['filter'](k=>k['error_code']==='unknown')['length'],g=a['map'](k=>k['duration_ms']),h={},i={};for(const k of a){k['error_code']&&(h[k['error_code']]=(h[k['error_code']]||0x0)+0x1),k['intent']&&(i[k['intent']]=(i[k['intent']]||0x0)+0x1);}const j=a['map'](l=>l['timestamp'])['filter'](Boolean)['sort']();return{'aggregation_date':new Date()['toISOString'](),'total_events':b,'date_range':{'earliest':j[0x0]||'','latest':j[j['length']-0x1]||''},'per_tool':aggregateByTool(a),'per_operation':aggregateByOperation(a),'overall':{'total_calls':b,'success_count':c,'failed_count':a['filter'](l=>l['status']==='failed')['length'],'success_rate':b>0x0?c/b:0x0,'semantic_hit_rate':b>0x0?d/b:0x0,'unknown_error_count':f,'unknown_error_rate':b>0x0?f/b:0x0,'avg_duration_ms':g['length']>0x0?g['reduce']((l,m)=>l+m,0x0)/g['length']:0x0},'error_code_distribution':h,'intent_distribution':i};}
|
|
@@ -1,83 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { persistImprovementQueue } from "./improve.js";
|
|
3
|
-
export function collectContextExperience(result, network) {
|
|
4
|
-
const objectTypes = extractObjectTypes(result.objects);
|
|
5
|
-
const hasEmbeddedHistory = !!result.embedded_history;
|
|
6
|
-
const hasEvents = !!result.events && result.events.length > 0;
|
|
7
|
-
const signature = {
|
|
8
|
-
intent: "assemble_context",
|
|
9
|
-
signals: {
|
|
10
|
-
object_types: objectTypes,
|
|
11
|
-
object_count: result.objects.length,
|
|
12
|
-
has_embedded_history: hasEmbeddedHistory,
|
|
13
|
-
has_events: hasEvents,
|
|
14
|
-
context_digest: result.context_digest,
|
|
15
|
-
network,
|
|
16
|
-
},
|
|
17
|
-
timestamp: Date.now(),
|
|
18
|
-
outcome: "success",
|
|
19
|
-
};
|
|
20
|
-
let signatureRecorded = false;
|
|
21
|
-
try {
|
|
22
|
-
recordSignature(signature);
|
|
23
|
-
signatureRecorded = true;
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
}
|
|
27
|
-
let proposal;
|
|
28
|
-
if (objectTypes.length >= 3) {
|
|
29
|
-
proposal = {
|
|
30
|
-
proposal_id: `PROP-CTX-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
|
31
|
-
source_diagnosis_id: `CTX-${result.context_digest}`,
|
|
32
|
-
type: "description_rewrite",
|
|
33
|
-
priority: "P3",
|
|
34
|
-
automation: "semi",
|
|
35
|
-
apply_mode: "config_override",
|
|
36
|
-
override_category: "descriptions",
|
|
37
|
-
title: `Enrich assemble_context for ${objectTypes.join("+")} patterns`,
|
|
38
|
-
description: `Assembled context with ${objectTypes.length} object types (${objectTypes.join(", ")}). ` +
|
|
39
|
-
`Consider enriching the assemble_context action description to guide AI toward ` +
|
|
40
|
-
`common ${objectTypes.join("+")} business patterns.`,
|
|
41
|
-
target: "assemble_context",
|
|
42
|
-
proposed_change: {
|
|
43
|
-
action: "enrich_description",
|
|
44
|
-
object_types: objectTypes,
|
|
45
|
-
has_embedded_history: hasEmbeddedHistory,
|
|
46
|
-
has_events: hasEvents,
|
|
47
|
-
context_digest: result.context_digest,
|
|
48
|
-
},
|
|
49
|
-
evidence: {
|
|
50
|
-
context_digest: result.context_digest,
|
|
51
|
-
object_count: result.objects.length,
|
|
52
|
-
object_types: objectTypes,
|
|
53
|
-
network,
|
|
54
|
-
},
|
|
55
|
-
review_status: "pending",
|
|
56
|
-
ab_test_recommended: false,
|
|
57
|
-
};
|
|
58
|
-
try {
|
|
59
|
-
persistImprovementQueue([proposal]);
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
signature_recorded: signatureRecorded,
|
|
66
|
-
proposal_created: !!proposal,
|
|
67
|
-
proposal_id: proposal?.proposal_id,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function extractObjectTypes(objects) {
|
|
71
|
-
const types = new Set();
|
|
72
|
-
for (const obj of objects) {
|
|
73
|
-
const data = obj?.data ?? obj;
|
|
74
|
-
const type = data?.type;
|
|
75
|
-
if (typeof type === "string") {
|
|
76
|
-
const match = type.match(/::(\w+)$/);
|
|
77
|
-
if (match) {
|
|
78
|
-
types.add(match[1]);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return Array.from(types);
|
|
83
|
-
}
|
|
1
|
+
import{recordSignature}from'../experience/index.js';import{persistImprovementQueue}from'./improve.js';export function collectContextExperience(a,b){const c=extractObjectTypes(a['objects']),d=!!a['embedded_history'],e=!!a['events']&&a['events']['length']>0x0,f={'intent':'assemble_context','signals':{'object_types':c,'object_count':a['objects']['length'],'has_embedded_history':d,'has_events':e,'context_digest':a['context_digest'],'network':b},'timestamp':Date['now'](),'outcome':'success'};let g=![];try{recordSignature(f),g=!![];}catch{}let h;if(c['length']>=0x3){h={'proposal_id':'PROP-CTX-'+Date['now']()+'-'+Math['random']()['toString'](0x24)['slice'](0x2,0x6),'source_diagnosis_id':'CTX-'+a['context_digest'],'type':'description_rewrite','priority':'P3','automation':'semi','apply_mode':'config_override','override_category':'descriptions','title':'Enrich\x20assemble_context\x20for\x20'+c['join']('+')+'\x20patterns','description':'Assembled\x20context\x20with\x20'+c['length']+'\x20object\x20types\x20('+c['join'](',\x20')+').\x20'+'Consider\x20enriching\x20the\x20assemble_context\x20action\x20description\x20to\x20guide\x20AI\x20toward\x20'+('common\x20'+c['join']('+')+'\x20business\x20patterns.'),'target':'assemble_context','proposed_change':{'action':'enrich_description','object_types':c,'has_embedded_history':d,'has_events':e,'context_digest':a['context_digest']},'evidence':{'context_digest':a['context_digest'],'object_count':a['objects']['length'],'object_types':c,'network':b},'review_status':'pending','ab_test_recommended':![]};try{persistImprovementQueue([h]);}catch{}}return{'signature_recorded':g,'proposal_created':!!h,'proposal_id':h?.['proposal_id']};}function extractObjectTypes(a){const b=new Set();for(const c of a){const d=c?.['data']??c,e=d?.['type'];if(typeof e==='string'){const f=e['match'](/::(\w+)$/);f&&b['add'](f[0x1]);}}return Array['from'](b);}
|