@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,404 +1 @@
|
|
|
1
|
-
import { aggregateIndustryMetrics, evaluateIndustryHealth, suggestIndustryUpdate, } from "./industry-evolution.js";
|
|
2
|
-
import { getIndustryProfile, resolveIndustryName } from "./industry-registry.js";
|
|
3
|
-
import { evaluateIndustryHealthByIntent, suggestIndustryUpdateByIntent, getRoleAdvice, filterSuggestionsByRole, getIntentProfile, } from "./intent-metrics.js";
|
|
4
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
5
|
-
import { dirname, join } from "path";
|
|
6
|
-
import { getWowMcpDir } from "@wowok/wowok";
|
|
7
|
-
export const FLYWHEEL_LOOP_VERSION = 2;
|
|
8
|
-
const MIN_SIGNALS_FOR_EVOLUTION = 10;
|
|
9
|
-
const DEFAULT_SCHEDULE = {
|
|
10
|
-
mode: "semi_realtime",
|
|
11
|
-
signal_threshold: 20,
|
|
12
|
-
time_interval_ms: 5 * 60 * 1000,
|
|
13
|
-
auto_apply: false,
|
|
14
|
-
};
|
|
15
|
-
const industrySchedules = new Map();
|
|
16
|
-
const industryLastUpdate = new Map();
|
|
17
|
-
const industryIntent = new Map();
|
|
18
|
-
const signalBuffer = new Map();
|
|
19
|
-
const decisionContexts = new Map();
|
|
20
|
-
const latestMetrics = new Map();
|
|
21
|
-
const latestHealth = new Map();
|
|
22
|
-
const pendingSuggestions = new Map();
|
|
23
|
-
export function recordIndustrySignal(industry, operation, outcome) {
|
|
24
|
-
if (!industry)
|
|
25
|
-
return;
|
|
26
|
-
const resolved = resolveIndustryName(industry) ?? industry;
|
|
27
|
-
const rawSignal = {
|
|
28
|
-
industry: resolved,
|
|
29
|
-
operation_type: operation.type,
|
|
30
|
-
success: outcome.success,
|
|
31
|
-
error_code: outcome.error_code,
|
|
32
|
-
timestamp: Date.now(),
|
|
33
|
-
};
|
|
34
|
-
const signal = sanitizeSignal(rawSignal);
|
|
35
|
-
const list = signalBuffer.get(resolved) ?? [];
|
|
36
|
-
list.push(signal);
|
|
37
|
-
signalBuffer.set(resolved, list);
|
|
38
|
-
tryMaybeAutoTrigger(resolved, list.length);
|
|
39
|
-
}
|
|
40
|
-
function tryMaybeAutoTrigger(resolved, signalCount) {
|
|
41
|
-
const schedule = industrySchedules.get(resolved) ?? DEFAULT_SCHEDULE;
|
|
42
|
-
if (schedule.mode === "manual")
|
|
43
|
-
return;
|
|
44
|
-
const now = Date.now();
|
|
45
|
-
const lastUpdate = industryLastUpdate.get(resolved) ?? 0;
|
|
46
|
-
if (schedule.mode === "realtime") {
|
|
47
|
-
if (signalCount >= MIN_SIGNALS_FOR_EVOLUTION &&
|
|
48
|
-
signalCount % MIN_SIGNALS_FOR_EVOLUTION === 0) {
|
|
49
|
-
doAutoUpdate(resolved, schedule);
|
|
50
|
-
}
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (schedule.mode === "semi_realtime") {
|
|
54
|
-
const threshold = schedule.signal_threshold ?? 20;
|
|
55
|
-
const interval = schedule.time_interval_ms ?? 5 * 60 * 1000;
|
|
56
|
-
const signalMet = signalCount >= threshold && signalCount % threshold === 0;
|
|
57
|
-
const timeMet = lastUpdate > 0 && (now - lastUpdate) >= interval;
|
|
58
|
-
if (signalMet || timeMet) {
|
|
59
|
-
doAutoUpdate(resolved, schedule);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function doAutoUpdate(resolved, schedule) {
|
|
64
|
-
try {
|
|
65
|
-
const result = updateIndustryCognition(resolved);
|
|
66
|
-
industryLastUpdate.set(resolved, Date.now());
|
|
67
|
-
if (schedule.auto_apply && result.suggestions_generated > 0) {
|
|
68
|
-
const suggestions = pendingSuggestions.get(resolved) ?? [];
|
|
69
|
-
const { applyIndustryUpdate } = require("./industry-evolution.js");
|
|
70
|
-
for (const s of suggestions) {
|
|
71
|
-
try {
|
|
72
|
-
applyIndustryUpdate(resolved, s);
|
|
73
|
-
}
|
|
74
|
-
catch { }
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
export function setEvolutionSchedule(industry, config) {
|
|
82
|
-
if (!industry)
|
|
83
|
-
return;
|
|
84
|
-
const resolved = resolveIndustryName(industry) ?? industry;
|
|
85
|
-
industrySchedules.set(resolved, config);
|
|
86
|
-
}
|
|
87
|
-
export function getEvolutionSchedule(industry) {
|
|
88
|
-
const resolved = resolveIndustryName(industry) ?? industry;
|
|
89
|
-
return industrySchedules.get(resolved) ?? DEFAULT_SCHEDULE;
|
|
90
|
-
}
|
|
91
|
-
export function setIndustryIntent(industry, intent) {
|
|
92
|
-
if (!industry)
|
|
93
|
-
return;
|
|
94
|
-
const resolved = resolveIndustryName(industry) ?? industry;
|
|
95
|
-
industryIntent.set(resolved, intent);
|
|
96
|
-
}
|
|
97
|
-
export function getIndustryIntent(industry) {
|
|
98
|
-
const resolved = resolveIndustryName(industry) ?? industry;
|
|
99
|
-
return industryIntent.get(resolved) ?? "default";
|
|
100
|
-
}
|
|
101
|
-
export function getIndustrySignalCount(industry) {
|
|
102
|
-
const resolved = resolveIndustryName(industry) ?? industry;
|
|
103
|
-
return signalBuffer.get(resolved)?.length ?? 0;
|
|
104
|
-
}
|
|
105
|
-
export function getIndustrySignals(industry) {
|
|
106
|
-
const resolved = resolveIndustryName(industry) ?? industry;
|
|
107
|
-
return [...(signalBuffer.get(resolved) ?? [])];
|
|
108
|
-
}
|
|
109
|
-
export function listIndustriesWithSignals() {
|
|
110
|
-
return Array.from(signalBuffer.keys());
|
|
111
|
-
}
|
|
112
|
-
export function getPendingSuggestions(industry) {
|
|
113
|
-
const resolved = resolveIndustryName(industry) ?? industry;
|
|
114
|
-
return [...(pendingSuggestions.get(resolved) ?? [])];
|
|
115
|
-
}
|
|
116
|
-
export function recordDecisionContext(ctx, graph) {
|
|
117
|
-
if (!ctx.id || !ctx.node_id)
|
|
118
|
-
return;
|
|
119
|
-
const sanitized = sanitizeDecisionContext(ctx);
|
|
120
|
-
decisionContexts.set(ctx.id, sanitized);
|
|
121
|
-
if (graph) {
|
|
122
|
-
try {
|
|
123
|
-
graph.attachDecisionContext(ctx.node_id, {
|
|
124
|
-
id: ctx.id,
|
|
125
|
-
decided_at: ctx.decided_at,
|
|
126
|
-
decider: ctx.decider,
|
|
127
|
-
industry: ctx.industry,
|
|
128
|
-
intent: ctx.intent,
|
|
129
|
-
alternatives: ctx.alternatives,
|
|
130
|
-
rationale: ctx.rationale,
|
|
131
|
-
outcome: ctx.outcome,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
catch {
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
export function queryDecisionsByIndustry(industry) {
|
|
139
|
-
const resolved = resolveIndustryName(industry) ?? industry;
|
|
140
|
-
return Array.from(decisionContexts.values())
|
|
141
|
-
.filter((d) => d.industry === resolved)
|
|
142
|
-
.sort((a, b) => b.decided_at - a.decided_at);
|
|
143
|
-
}
|
|
144
|
-
export function queryDecisionsByNode(nodeId) {
|
|
145
|
-
return Array.from(decisionContexts.values())
|
|
146
|
-
.filter((d) => d.node_id === nodeId)
|
|
147
|
-
.sort((a, b) => b.decided_at - a.decided_at);
|
|
148
|
-
}
|
|
149
|
-
export function backfillDecisionOutcome(decisionId, outcome) {
|
|
150
|
-
const ctx = decisionContexts.get(decisionId);
|
|
151
|
-
if (!ctx)
|
|
152
|
-
return false;
|
|
153
|
-
ctx.outcome = outcome;
|
|
154
|
-
return true;
|
|
155
|
-
}
|
|
156
|
-
export function updateIndustryCognition(industry, rawData) {
|
|
157
|
-
const resolved = resolveIndustryName(industry) ?? industry;
|
|
158
|
-
const signals = signalBuffer.get(resolved) ?? [];
|
|
159
|
-
const result = {
|
|
160
|
-
industry: resolved,
|
|
161
|
-
metrics_updated: false,
|
|
162
|
-
health_recomputed: false,
|
|
163
|
-
suggestions_generated: 0,
|
|
164
|
-
evolution_ready: signals.length >= MIN_SIGNALS_FOR_EVOLUTION,
|
|
165
|
-
};
|
|
166
|
-
if (signals.length < MIN_SIGNALS_FOR_EVOLUTION && (!rawData || rawData.length === 0)) {
|
|
167
|
-
return result;
|
|
168
|
-
}
|
|
169
|
-
let metrics;
|
|
170
|
-
if (rawData && rawData.length > 0) {
|
|
171
|
-
metrics = aggregateIndustryMetrics(resolved, rawData);
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
const synthesizedRaw = signals.map((s) => ({
|
|
175
|
-
industry: resolved,
|
|
176
|
-
completed: s.success,
|
|
177
|
-
has_dispute: !!s.error_code && s.error_code.includes("dispute"),
|
|
178
|
-
has_refund: !!s.error_code && s.error_code.includes("refund"),
|
|
179
|
-
ticket_size: 0n,
|
|
180
|
-
timestamp: s.timestamp,
|
|
181
|
-
}));
|
|
182
|
-
metrics = aggregateIndustryMetrics(resolved, synthesizedRaw);
|
|
183
|
-
}
|
|
184
|
-
latestMetrics.set(resolved, metrics);
|
|
185
|
-
result.metrics_updated = true;
|
|
186
|
-
const intent = industryIntent.get(resolved) ?? "default";
|
|
187
|
-
let health;
|
|
188
|
-
let suggestions;
|
|
189
|
-
if (intent !== "default") {
|
|
190
|
-
health = evaluateIndustryHealthByIntent(resolved, metrics, intent);
|
|
191
|
-
suggestions = suggestIndustryUpdateByIntent(resolved, metrics, intent);
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
health = evaluateIndustryHealth(resolved, metrics);
|
|
195
|
-
suggestions = suggestIndustryUpdate(resolved, metrics);
|
|
196
|
-
}
|
|
197
|
-
latestHealth.set(resolved, health);
|
|
198
|
-
result.health_recomputed = true;
|
|
199
|
-
pendingSuggestions.set(resolved, suggestions);
|
|
200
|
-
result.suggestions_generated = suggestions.length;
|
|
201
|
-
return result;
|
|
202
|
-
}
|
|
203
|
-
export function injectEvolutionContext(_semantic, industry, role) {
|
|
204
|
-
if (!industry) {
|
|
205
|
-
return { confidence: 0 };
|
|
206
|
-
}
|
|
207
|
-
const resolved = resolveIndustryName(industry) ?? industry;
|
|
208
|
-
const profile = getIndustryProfile(resolved);
|
|
209
|
-
if (!profile) {
|
|
210
|
-
return {
|
|
211
|
-
confidence: 0,
|
|
212
|
-
industry_signal: `Industry ${resolved} is not yet registered; recommend synthesizing a profile via the generalizer engine`,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
const health = latestHealth.get(resolved);
|
|
216
|
-
const metrics = latestMetrics.get(resolved);
|
|
217
|
-
const suggestions = pendingSuggestions.get(resolved) ?? [];
|
|
218
|
-
const signalCount = signalBuffer.get(resolved)?.length ?? 0;
|
|
219
|
-
const intent = industryIntent.get(resolved) ?? "default";
|
|
220
|
-
const parts = [];
|
|
221
|
-
let advice;
|
|
222
|
-
let confidence = 0.5;
|
|
223
|
-
if (health) {
|
|
224
|
-
parts.push(`Industry health ${health.health_score}/100 (${health.level})`);
|
|
225
|
-
confidence = Math.max(confidence, 0.7);
|
|
226
|
-
if (health.weaknesses.length > 0) {
|
|
227
|
-
advice = `Weakness: ${health.weaknesses[0]}`;
|
|
228
|
-
}
|
|
229
|
-
if (health.recommendations.length > 0) {
|
|
230
|
-
advice = advice
|
|
231
|
-
? `${advice}; recommendation: ${health.recommendations[0]}`
|
|
232
|
-
: `Recommendation: ${health.recommendations[0]}`;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
if (metrics && metrics.anomalies.length > 0) {
|
|
236
|
-
parts.push(`Anomaly: ${metrics.anomalies[0]}`);
|
|
237
|
-
confidence = Math.max(confidence, 0.8);
|
|
238
|
-
}
|
|
239
|
-
if (signalCount > 0) {
|
|
240
|
-
parts.push(`Accumulated ${signalCount} industry signals`);
|
|
241
|
-
}
|
|
242
|
-
if (intent !== "default") {
|
|
243
|
-
parts.push(`Current intent: ${intent}`);
|
|
244
|
-
}
|
|
245
|
-
if (!advice && suggestions.length > 0) {
|
|
246
|
-
const highPriority = suggestions.find((s) => s.priority === "high") ?? suggestions[0];
|
|
247
|
-
advice = `${highPriority.suggestion_type}: ${highPriority.evidence}`;
|
|
248
|
-
confidence = Math.max(confidence, highPriority.confidence);
|
|
249
|
-
}
|
|
250
|
-
let roleAdvice;
|
|
251
|
-
let filteredSuggestions = suggestions;
|
|
252
|
-
if (role) {
|
|
253
|
-
const intentSpec = getIntentProfile(intent);
|
|
254
|
-
if (intentSpec) {
|
|
255
|
-
roleAdvice = getRoleAdvice(intent, role);
|
|
256
|
-
}
|
|
257
|
-
const triggers = intentSpec?.suggestion_triggers ?? [];
|
|
258
|
-
filteredSuggestions = filterSuggestionsByRole(suggestions, role, triggers);
|
|
259
|
-
if (filteredSuggestions.length > 0) {
|
|
260
|
-
const topRole = filteredSuggestions.find((s) => s.priority === "high") ?? filteredSuggestions[0];
|
|
261
|
-
advice = `${topRole.suggestion_type} (${role}): ${topRole.evidence}`;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return {
|
|
265
|
-
industry_signal: parts.length > 0 ? parts.join("; ") : undefined,
|
|
266
|
-
evolution_advice: advice,
|
|
267
|
-
confidence,
|
|
268
|
-
health_score: health?.health_score,
|
|
269
|
-
pending_suggestions: filteredSuggestions.length,
|
|
270
|
-
intent: intent !== "default" ? intent : undefined,
|
|
271
|
-
role_advice: roleAdvice && roleAdvice.length > 0 ? roleAdvice : undefined,
|
|
272
|
-
role,
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
export function getIndustryEvolutionStatus(industry) {
|
|
276
|
-
const resolved = resolveIndustryName(industry) ?? industry;
|
|
277
|
-
const profile = getIndustryProfile(resolved);
|
|
278
|
-
return {
|
|
279
|
-
industry: resolved,
|
|
280
|
-
version: profile?.version ?? "v0",
|
|
281
|
-
last_updated: profile?.evolution?.last_updated ?? 0,
|
|
282
|
-
signal_count: signalBuffer.get(resolved)?.length ?? 0,
|
|
283
|
-
health: latestHealth.get(resolved),
|
|
284
|
-
pending_suggestions: pendingSuggestions.get(resolved)?.length ?? 0,
|
|
285
|
-
evolution_ready: (signalBuffer.get(resolved)?.length ?? 0) >= MIN_SIGNALS_FOR_EVOLUTION,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
export const EVOLUTION_STATE_VERSION = 1;
|
|
289
|
-
function evolutionStateFilePath() {
|
|
290
|
-
return join(getWowMcpDir(), "evolution-state.json");
|
|
291
|
-
}
|
|
292
|
-
export function saveEvolutionState() {
|
|
293
|
-
const path = evolutionStateFilePath();
|
|
294
|
-
const dir = dirname(path);
|
|
295
|
-
if (!existsSync(dir))
|
|
296
|
-
mkdirSync(dir, { recursive: true });
|
|
297
|
-
const snap = {
|
|
298
|
-
version: EVOLUTION_STATE_VERSION,
|
|
299
|
-
saved_at: Date.now(),
|
|
300
|
-
signal_buffer: Object.fromEntries(signalBuffer),
|
|
301
|
-
decision_contexts: Object.fromEntries(decisionContexts),
|
|
302
|
-
latest_metrics: Object.fromEntries(latestMetrics),
|
|
303
|
-
latest_health: Object.fromEntries(latestHealth),
|
|
304
|
-
pending_suggestions: Object.fromEntries(pendingSuggestions),
|
|
305
|
-
industry_schedules: Object.fromEntries(industrySchedules),
|
|
306
|
-
industry_last_update: Object.fromEntries(industryLastUpdate),
|
|
307
|
-
industry_intent: Object.fromEntries(industryIntent),
|
|
308
|
-
};
|
|
309
|
-
const replacer = (_key, value) => {
|
|
310
|
-
if (typeof value === "bigint") {
|
|
311
|
-
return { __bigint__: value.toString() };
|
|
312
|
-
}
|
|
313
|
-
return value;
|
|
314
|
-
};
|
|
315
|
-
writeFileSync(path, JSON.stringify(snap, replacer, 2), "utf-8");
|
|
316
|
-
return path;
|
|
317
|
-
}
|
|
318
|
-
export function loadEvolutionState() {
|
|
319
|
-
const path = evolutionStateFilePath();
|
|
320
|
-
if (!existsSync(path))
|
|
321
|
-
return false;
|
|
322
|
-
try {
|
|
323
|
-
const raw = readFileSync(path, "utf-8");
|
|
324
|
-
const reviver = (_key, value) => {
|
|
325
|
-
if (value && typeof value === "object" && "__bigint__" in value) {
|
|
326
|
-
return BigInt(value.__bigint__);
|
|
327
|
-
}
|
|
328
|
-
return value;
|
|
329
|
-
};
|
|
330
|
-
const snap = JSON.parse(raw, reviver);
|
|
331
|
-
if (!snap || snap.version !== EVOLUTION_STATE_VERSION)
|
|
332
|
-
return false;
|
|
333
|
-
_resetFlywheelLoopForTest();
|
|
334
|
-
for (const [k, v] of Object.entries(snap.signal_buffer)) {
|
|
335
|
-
signalBuffer.set(k, v);
|
|
336
|
-
}
|
|
337
|
-
for (const [k, v] of Object.entries(snap.decision_contexts)) {
|
|
338
|
-
decisionContexts.set(k, v);
|
|
339
|
-
}
|
|
340
|
-
for (const [k, v] of Object.entries(snap.latest_metrics)) {
|
|
341
|
-
latestMetrics.set(k, v);
|
|
342
|
-
}
|
|
343
|
-
for (const [k, v] of Object.entries(snap.latest_health)) {
|
|
344
|
-
latestHealth.set(k, v);
|
|
345
|
-
}
|
|
346
|
-
for (const [k, v] of Object.entries(snap.pending_suggestions)) {
|
|
347
|
-
pendingSuggestions.set(k, v);
|
|
348
|
-
}
|
|
349
|
-
for (const [k, v] of Object.entries(snap.industry_schedules)) {
|
|
350
|
-
industrySchedules.set(k, v);
|
|
351
|
-
}
|
|
352
|
-
for (const [k, v] of Object.entries(snap.industry_last_update)) {
|
|
353
|
-
industryLastUpdate.set(k, v);
|
|
354
|
-
}
|
|
355
|
-
for (const [k, v] of Object.entries(snap.industry_intent)) {
|
|
356
|
-
industryIntent.set(k, v);
|
|
357
|
-
}
|
|
358
|
-
return true;
|
|
359
|
-
}
|
|
360
|
-
catch {
|
|
361
|
-
return false;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
export function hasPersistedEvolutionState() {
|
|
365
|
-
return existsSync(evolutionStateFilePath());
|
|
366
|
-
}
|
|
367
|
-
export function sanitizeSignal(signal) {
|
|
368
|
-
return {
|
|
369
|
-
industry: signal.industry,
|
|
370
|
-
operation_type: signal.operation_type,
|
|
371
|
-
success: signal.success,
|
|
372
|
-
error_code: signal.error_code,
|
|
373
|
-
timestamp: signal.timestamp,
|
|
374
|
-
decision_context_id: signal.decision_context_id,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
export function sanitizeDecisionContext(ctx) {
|
|
378
|
-
return {
|
|
379
|
-
id: ctx.id,
|
|
380
|
-
node_id: ctx.node_id,
|
|
381
|
-
decided_at: ctx.decided_at,
|
|
382
|
-
decider: ctx.decider,
|
|
383
|
-
industry: ctx.industry,
|
|
384
|
-
intent: ctx.intent,
|
|
385
|
-
outcome: ctx.outcome,
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
export function checkAndTriggerCognitionUpdate(industry) {
|
|
389
|
-
return updateIndustryCognition(industry);
|
|
390
|
-
}
|
|
391
|
-
export function _resetFlywheelLoopForTest() {
|
|
392
|
-
signalBuffer.clear();
|
|
393
|
-
decisionContexts.clear();
|
|
394
|
-
latestMetrics.clear();
|
|
395
|
-
latestHealth.clear();
|
|
396
|
-
pendingSuggestions.clear();
|
|
397
|
-
industrySchedules.clear();
|
|
398
|
-
industryLastUpdate.clear();
|
|
399
|
-
industryIntent.clear();
|
|
400
|
-
}
|
|
401
|
-
export function _snapshotSignalBuffer() {
|
|
402
|
-
return Object.fromEntries(signalBuffer);
|
|
403
|
-
}
|
|
404
|
-
export { MIN_SIGNALS_FOR_EVOLUTION as FLYWHEEL_LOOP_MIN_SIGNALS };
|
|
1
|
+
import{aggregateIndustryMetrics,evaluateIndustryHealth,suggestIndustryUpdate}from'./industry-evolution.js';import{getIndustryProfile,resolveIndustryName}from'./industry-registry.js';import{evaluateIndustryHealthByIntent,suggestIndustryUpdateByIntent,getRoleAdvice,filterSuggestionsByRole,getIntentProfile}from'./intent-metrics.js';import{existsSync,mkdirSync,readFileSync,writeFileSync}from'fs';import{dirname,join}from'path';import{getWowMcpDir}from'@wowok/wowok';export const FLYWHEEL_LOOP_VERSION=0x2;const MIN_SIGNALS_FOR_EVOLUTION=0xa,DEFAULT_SCHEDULE={'mode':'semi_realtime','signal_threshold':0x14,'time_interval_ms':0x5*0x3c*0x3e8,'auto_apply':![]},industrySchedules=new Map(),industryLastUpdate=new Map(),industryIntent=new Map(),signalBuffer=new Map(),decisionContexts=new Map(),latestMetrics=new Map(),latestHealth=new Map(),pendingSuggestions=new Map();export function recordIndustrySignal(a,b,c){if(!a)return;const d=resolveIndustryName(a)??a,e={'industry':d,'operation_type':b['type'],'success':c['success'],'error_code':c['error_code'],'timestamp':Date['now']()},f=sanitizeSignal(e),g=signalBuffer['get'](d)??[];g['push'](f),signalBuffer['set'](d,g),tryMaybeAutoTrigger(d,g['length']);}function tryMaybeAutoTrigger(a,b){const c=industrySchedules['get'](a)??DEFAULT_SCHEDULE;if(c['mode']==='manual')return;const d=Date['now'](),e=industryLastUpdate['get'](a)??0x0;if(c['mode']==='realtime'){b>=MIN_SIGNALS_FOR_EVOLUTION&&b%MIN_SIGNALS_FOR_EVOLUTION===0x0&&doAutoUpdate(a,c);return;}if(c['mode']==='semi_realtime'){const f=c['signal_threshold']??0x14,g=c['time_interval_ms']??0x5*0x3c*0x3e8,h=b>=f&&b%f===0x0,i=e>0x0&&d-e>=g;(h||i)&&doAutoUpdate(a,c);}}function doAutoUpdate(a,b){try{const c=updateIndustryCognition(a);industryLastUpdate['set'](a,Date['now']());if(b['auto_apply']&&c['suggestions_generated']>0x0){const d=pendingSuggestions['get'](a)??[],{applyIndustryUpdate:e}=require('./industry-evolution.js');for(const f of d){try{e(a,f);}catch{}}}}catch{}}export function setEvolutionSchedule(a,b){if(!a)return;const c=resolveIndustryName(a)??a;industrySchedules['set'](c,b);}export function getEvolutionSchedule(a){const b=resolveIndustryName(a)??a;return industrySchedules['get'](b)??DEFAULT_SCHEDULE;}export function setIndustryIntent(a,b){if(!a)return;const c=resolveIndustryName(a)??a;industryIntent['set'](c,b);}export function getIndustryIntent(a){const b=resolveIndustryName(a)??a;return industryIntent['get'](b)??'default';}export function getIndustrySignalCount(a){const b=resolveIndustryName(a)??a;return signalBuffer['get'](b)?.['length']??0x0;}export function getIndustrySignals(a){const b=resolveIndustryName(a)??a;return[...signalBuffer['get'](b)??[]];}export function listIndustriesWithSignals(){return Array['from'](signalBuffer['keys']());}export function getPendingSuggestions(a){const b=resolveIndustryName(a)??a;return[...pendingSuggestions['get'](b)??[]];}export function recordDecisionContext(a,b){if(!a['id']||!a['node_id'])return;const c=sanitizeDecisionContext(a);decisionContexts['set'](a['id'],c);if(b)try{b['attachDecisionContext'](a['node_id'],{'id':a['id'],'decided_at':a['decided_at'],'decider':a['decider'],'industry':a['industry'],'intent':a['intent'],'alternatives':a['alternatives'],'rationale':a['rationale'],'outcome':a['outcome']});}catch{}}export function queryDecisionsByIndustry(a){const b=resolveIndustryName(a)??a;return Array['from'](decisionContexts['values']())['filter'](c=>c['industry']===b)['sort']((c,d)=>d['decided_at']-c['decided_at']);}export function queryDecisionsByNode(a){return Array['from'](decisionContexts['values']())['filter'](b=>b['node_id']===a)['sort']((c,d)=>d['decided_at']-c['decided_at']);}export function backfillDecisionOutcome(a,b){const c=decisionContexts['get'](a);if(!c)return![];return c['outcome']=b,!![];}export function updateIndustryCognition(a,b){const c=resolveIndustryName(a)??a,d=signalBuffer['get'](c)??[],e={'industry':c,'metrics_updated':![],'health_recomputed':![],'suggestions_generated':0x0,'evolution_ready':d['length']>=MIN_SIGNALS_FOR_EVOLUTION};if(d['length']<MIN_SIGNALS_FOR_EVOLUTION&&(!b||b['length']===0x0))return e;let f;if(b&&b['length']>0x0)f=aggregateIndustryMetrics(c,b);else{const j=d['map'](k=>({'industry':c,'completed':k['success'],'has_dispute':!!k['error_code']&&k['error_code']['includes']('dispute'),'has_refund':!!k['error_code']&&k['error_code']['includes']('refund'),'ticket_size':0x0n,'timestamp':k['timestamp']}));f=aggregateIndustryMetrics(c,j);}latestMetrics['set'](c,f),e['metrics_updated']=!![];const g=industryIntent['get'](c)??'default';let h,i;return g!=='default'?(h=evaluateIndustryHealthByIntent(c,f,g),i=suggestIndustryUpdateByIntent(c,f,g)):(h=evaluateIndustryHealth(c,f),i=suggestIndustryUpdate(c,f)),latestHealth['set'](c,h),e['health_recomputed']=!![],pendingSuggestions['set'](c,i),e['suggestions_generated']=i['length'],e;}export function injectEvolutionContext(a,b,c){if(!b)return{'confidence':0x0};const d=resolveIndustryName(b)??b,e=getIndustryProfile(d);if(!e)return{'confidence':0x0,'industry_signal':'Industry\x20'+d+'\x20is\x20not\x20yet\x20registered;\x20recommend\x20synthesizing\x20a\x20profile\x20via\x20the\x20generalizer\x20engine'};const f=latestHealth['get'](d),g=latestMetrics['get'](d),h=pendingSuggestions['get'](d)??[],i=signalBuffer['get'](d)?.['length']??0x0,j=industryIntent['get'](d)??'default',k=[];let l,m=0.5;f&&(k['push']('Industry\x20health\x20'+f['health_score']+'/100\x20('+f['level']+')'),m=Math['max'](m,0.7),f['weaknesses']['length']>0x0&&(l='Weakness:\x20'+f['weaknesses'][0x0]),f['recommendations']['length']>0x0&&(l=l?l+';\x20recommendation:\x20'+f['recommendations'][0x0]:'Recommendation:\x20'+f['recommendations'][0x0]));g&&g['anomalies']['length']>0x0&&(k['push']('Anomaly:\x20'+g['anomalies'][0x0]),m=Math['max'](m,0.8));i>0x0&&k['push']('Accumulated\x20'+i+'\x20industry\x20signals');j!=='default'&&k['push']('Current\x20intent:\x20'+j);if(!l&&h['length']>0x0){const p=h['find'](q=>q['priority']==='high')??h[0x0];l=p['suggestion_type']+':\x20'+p['evidence'],m=Math['max'](m,p['confidence']);}let n,o=h;if(c){const q=getIntentProfile(j);q&&(n=getRoleAdvice(j,c));const r=q?.['suggestion_triggers']??[];o=filterSuggestionsByRole(h,c,r);if(o['length']>0x0){const s=o['find'](t=>t['priority']==='high')??o[0x0];l=s['suggestion_type']+'\x20('+c+'):\x20'+s['evidence'];}}return{'industry_signal':k['length']>0x0?k['join'](';\x20'):undefined,'evolution_advice':l,'confidence':m,'health_score':f?.['health_score'],'pending_suggestions':o['length'],'intent':j!=='default'?j:undefined,'role_advice':n&&n['length']>0x0?n:undefined,'role':c};}export function getIndustryEvolutionStatus(a){const b=resolveIndustryName(a)??a,c=getIndustryProfile(b);return{'industry':b,'version':c?.['version']??'v0','last_updated':c?.['evolution']?.['last_updated']??0x0,'signal_count':signalBuffer['get'](b)?.['length']??0x0,'health':latestHealth['get'](b),'pending_suggestions':pendingSuggestions['get'](b)?.['length']??0x0,'evolution_ready':(signalBuffer['get'](b)?.['length']??0x0)>=MIN_SIGNALS_FOR_EVOLUTION};}export const EVOLUTION_STATE_VERSION=0x1;function evolutionStateFilePath(){return join(getWowMcpDir(),'evolution-state.json');}export function saveEvolutionState(){const a=evolutionStateFilePath(),b=dirname(a);if(!existsSync(b))mkdirSync(b,{'recursive':!![]});const c={'version':EVOLUTION_STATE_VERSION,'saved_at':Date['now'](),'signal_buffer':Object['fromEntries'](signalBuffer),'decision_contexts':Object['fromEntries'](decisionContexts),'latest_metrics':Object['fromEntries'](latestMetrics),'latest_health':Object['fromEntries'](latestHealth),'pending_suggestions':Object['fromEntries'](pendingSuggestions),'industry_schedules':Object['fromEntries'](industrySchedules),'industry_last_update':Object['fromEntries'](industryLastUpdate),'industry_intent':Object['fromEntries'](industryIntent)},d=(e,f)=>{if(typeof f==='bigint')return{'__bigint__':f['toString']()};return f;};return writeFileSync(a,JSON['stringify'](c,d,0x2),'utf-8'),a;}export function loadEvolutionState(){const a=evolutionStateFilePath();if(!existsSync(a))return![];try{const b=readFileSync(a,'utf-8'),c=(e,f)=>{if(f&&typeof f==='object'&&'__bigint__'in f)return BigInt(f['__bigint__']);return f;},d=JSON['parse'](b,c);if(!d||d['version']!==EVOLUTION_STATE_VERSION)return![];_resetFlywheelLoopForTest();for(const [e,f]of Object['entries'](d['signal_buffer'])){signalBuffer['set'](e,f);}for(const [g,h]of Object['entries'](d['decision_contexts'])){decisionContexts['set'](g,h);}for(const [i,j]of Object['entries'](d['latest_metrics'])){latestMetrics['set'](i,j);}for(const [l,m]of Object['entries'](d['latest_health'])){latestHealth['set'](l,m);}for(const [n,o]of Object['entries'](d['pending_suggestions'])){pendingSuggestions['set'](n,o);}for(const [p,q]of Object['entries'](d['industry_schedules'])){industrySchedules['set'](p,q);}for(const [r,s]of Object['entries'](d['industry_last_update'])){industryLastUpdate['set'](r,s);}for(const [t,u]of Object['entries'](d['industry_intent'])){industryIntent['set'](t,u);}return!![];}catch{return![];}}export function hasPersistedEvolutionState(){return existsSync(evolutionStateFilePath());}export function sanitizeSignal(a){return{'industry':a['industry'],'operation_type':a['operation_type'],'success':a['success'],'error_code':a['error_code'],'timestamp':a['timestamp'],'decision_context_id':a['decision_context_id']};}export function sanitizeDecisionContext(a){return{'id':a['id'],'node_id':a['node_id'],'decided_at':a['decided_at'],'decider':a['decider'],'industry':a['industry'],'intent':a['intent'],'outcome':a['outcome']};}export function checkAndTriggerCognitionUpdate(a){return updateIndustryCognition(a);}export function _resetFlywheelLoopForTest(){signalBuffer['clear'](),decisionContexts['clear'](),latestMetrics['clear'](),latestHealth['clear'](),pendingSuggestions['clear'](),industrySchedules['clear'](),industryLastUpdate['clear'](),industryIntent['clear']();}export function _snapshotSignalBuffer(){return Object['fromEntries'](signalBuffer);}export{MIN_SIGNALS_FOR_EVOLUTION as FLYWHEEL_LOOP_MIN_SIGNALS};
|