progmune-runtime 2.1.6 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -468
- package/dist/ablation-study.js +144 -0
- package/dist/ablation-study.test.js +18 -0
- package/dist/action-runtime.js +3 -1
- package/dist/active-learning.js +211 -0
- package/dist/analytics.js +139 -0
- package/dist/asset-factory.js +309 -0
- package/dist/asset-growth.js +244 -0
- package/dist/asset-promotion.js +382 -0
- package/dist/asset-quality.js +550 -0
- package/dist/audit/business-translator.js +285 -0
- package/dist/audit/cli.js +66 -0
- package/dist/audit/formatters/html.js +379 -0
- package/dist/audit/formatters/json.js +11 -0
- package/dist/audit/formatters/markdown.js +192 -0
- package/dist/audit/formatters/terminal.js +189 -0
- package/dist/audit/index.js +25 -0
- package/dist/audit/report-builder.js +318 -0
- package/dist/audit/types.js +8 -0
- package/dist/audit.js +3 -3
- package/dist/auto-benchmark-generator.js +137 -0
- package/dist/auto-benchmark-generator.test.js +45 -0
- package/dist/auto-protocol-synthesizer.js +362 -0
- package/dist/auto-protocol-synthesizer.test.js +82 -0
- package/dist/autonomous-patch.js +175 -0
- package/dist/autonomous-patch.test.js +128 -0
- package/dist/badge/badge-server.js +98 -0
- package/dist/behavior-miner.js +442 -0
- package/dist/belief-layer.js +475 -0
- package/dist/benchmark-count.js +5 -0
- package/dist/benchmark-generator.js +211 -0
- package/dist/benchmark-harness.js +201 -0
- package/dist/benchmark-pass-rate.js +7 -0
- package/dist/benchmark-report.js +8 -3
- package/dist/benchmark-save.js +14 -1
- package/dist/bootstrap-validation.js +197 -0
- package/dist/bootstrap-validation.test.js +51 -0
- package/dist/branch-ledger.js +1 -1
- package/dist/capability-gap.js +130 -0
- package/dist/certify-html.js +351 -0
- package/dist/certify.js +326 -0
- package/dist/check.js +4 -4
- package/dist/compliance-miner.js +447 -0
- package/dist/continuous-benchmark.js +194 -0
- package/dist/continuous-benchmark.test.js +116 -0
- package/dist/corpus-stats.js +173 -0
- package/dist/counterfactual-engine.js +288 -0
- package/dist/coverage-dashboard.js +109 -0
- package/dist/coverage-system.test.js +205 -0
- package/dist/cross-repo-precision.js +352 -0
- package/dist/cve-benchmark.js +180 -0
- package/dist/cve-benchmark.test.js +28 -0
- package/dist/cve-collector.js +73 -0
- package/dist/data-quality.js +141 -0
- package/dist/decision-engine.js +388 -0
- package/dist/derive-metadata.js +250 -0
- package/dist/difficulty-active.test.js +198 -0
- package/dist/difficulty-map.js +244 -0
- package/dist/discovery-analytics.js +125 -0
- package/dist/discovery-model.js +149 -0
- package/dist/discovery-optimize.test.js +199 -0
- package/dist/discovery-trace.js +276 -0
- package/dist/discovery-trace.test.js +97 -0
- package/dist/emitter.js +83 -1
- package/dist/enterprise-dashboard.js +405 -0
- package/dist/eval-hardening.js +297 -0
- package/dist/eval-hardening.test.js +85 -0
- package/dist/evaluation-campaign.js +359 -0
- package/dist/evaluation-campaign.test.js +181 -0
- package/dist/evidence-growth.js +143 -0
- package/dist/evidence-repository.js +209 -0
- package/dist/evidence-system.js +441 -0
- package/dist/execute.js +15 -7
- package/dist/experimental/software-physics.js +291 -0
- package/dist/experimental/state-inference.js +516 -0
- package/dist/experimental/unsupervised-physics.js +230 -0
- package/dist/extract-ir-python.js +54 -7
- package/dist/extract-ir.js +376 -12
- package/dist/failure-collector.js +2 -2
- package/dist/failure-corpus.js +322 -9
- package/dist/feedback.js +16 -5
- package/dist/feedback.test.js +49 -0
- package/dist/file-lock.js +1 -1
- package/dist/flywheel-batch.js +292 -0
- package/dist/frameworks/express-cli.js +237 -0
- package/dist/frameworks/express-detector.js +445 -0
- package/dist/frameworks/express-detector.test.js +206 -0
- package/dist/frameworks/index.js +30 -0
- package/dist/frameworks/nestjs-detector.js +302 -0
- package/dist/frameworks/trpc-detector.js +161 -0
- package/dist/frameworks/version-awareness.js +179 -0
- package/dist/function-synonyms.js +164 -0
- package/dist/function-synonyms.test.js +68 -0
- package/dist/generalization.test.js +352 -0
- package/dist/goal-annotator.js +113 -0
- package/dist/goal-planner.js +563 -0
- package/dist/gold-cve.js +164 -0
- package/dist/gold-cve.test.js +104 -0
- package/dist/gold-quality.js +206 -0
- package/dist/gold-tiers.js +241 -0
- package/dist/governance-dashboard.js +327 -0
- package/dist/graph-viz.js +240 -0
- package/dist/guided-frontier.js +195 -0
- package/dist/hierarchical-planner.js +148 -0
- package/dist/identifier-parser.js +260 -0
- package/dist/immune-metrics.js +93 -0
- package/dist/immune-receiver.js +158 -0
- package/dist/immune-reporter.js +1 -1
- package/dist/improvement-orchestrator.js +206 -0
- package/dist/inject-p0-vocabulary.js +300 -0
- package/dist/intent-parser.js +218 -0
- package/dist/invariant-algebra.js +476 -0
- package/dist/invariant-calculus.js +533 -0
- package/dist/ir-utils.js +70 -0
- package/dist/ir-utils.test.js +50 -0
- package/dist/knowledge-api.js +312 -0
- package/dist/knowledge-evolution.js +452 -0
- package/dist/knowledge-explorer.js +506 -0
- package/dist/knowledge-flywheel.js +274 -0
- package/dist/knowledge-governance.js +338 -0
- package/dist/knowledge-governance.test.js +150 -0
- package/dist/knowledge-graph.js +181 -0
- package/dist/knowledge-guided-synth.js +246 -0
- package/dist/knowledge-loop.test.js +77 -0
- package/dist/knowledge-object.js +316 -0
- package/dist/knowledge-package.js +98 -0
- package/dist/kpi-dashboard.js +561 -0
- package/dist/l3-cross-function.js +280 -0
- package/dist/learning-ranker.js +148 -0
- package/dist/learning-ranker.test.js +291 -0
- package/dist/ledger/accountability.js +322 -0
- package/dist/ledger/chain-builder.js +185 -0
- package/dist/ledger/cli.js +222 -0
- package/dist/ledger/index.js +13 -0
- package/dist/ledger/signatures.js +193 -0
- package/dist/ledger/types.js +9 -0
- package/dist/llm.js +74 -3
- package/dist/load-benchmarks.js +8 -3
- package/dist/logger.js +66 -0
- package/dist/logger.test.js +37 -0
- package/dist/logistic-reward.js +339 -0
- package/dist/logistic-reward.test.js +180 -0
- package/dist/macro-graph.js +193 -0
- package/dist/macro-repair.js +183 -0
- package/dist/mcp-server.mjs +1202 -483
- package/dist/memory-layer.js +42 -5
- package/dist/multi-repo-precision.js +422 -0
- package/dist/name-free-protocol.js +425 -0
- package/dist/name-free-protocol.test.js +170 -0
- package/dist/name-scrambling.js +138 -0
- package/dist/name-scrambling.test.js +16 -0
- package/dist/p3-observability.test.js +281 -0
- package/dist/p5-orchestrator.test.js +225 -0
- package/dist/pairwise-preference.js +294 -0
- package/dist/pairwise-preference.test.js +140 -0
- package/dist/planner-constraints.js +104 -0
- package/dist/planner-prompts.js +155 -0
- package/dist/planner-telemetry.js +415 -0
- package/dist/planner-trace.js +214 -0
- package/dist/planner.js +162 -167
- package/dist/plsb/artifact.js +116 -0
- package/dist/plsb/cli.js +71 -0
- package/dist/plsb/index.js +19 -0
- package/dist/plsb/leaderboard.js +249 -0
- package/dist/plsb/report-md.js +156 -0
- package/dist/plsb/schema.js +179 -0
- package/dist/plsb-benchmark.js +284 -0
- package/dist/plsb-benchmark.test.js +119 -0
- package/dist/policy/cli.js +134 -0
- package/dist/policy/engine.js +333 -0
- package/dist/policy/index.js +12 -0
- package/dist/policy/types.js +59 -0
- package/dist/policy-miner.js +505 -0
- package/dist/precision-analyze.js +229 -0
- package/dist/precision-benchmark.js +147 -0
- package/dist/precision-label-c.js +134 -0
- package/dist/precision-label.js +193 -0
- package/dist/precision-report-c.js +149 -0
- package/dist/precision-report.js +246 -0
- package/dist/progmune-status.js +108 -0
- package/dist/proof-engine.js +479 -0
- package/dist/proof-provenance.js +315 -0
- package/dist/protocol-coverage.js +294 -0
- package/dist/protocol-detector.js +1189 -0
- package/dist/protocol-embedding-expanded.js +297 -0
- package/dist/protocol-embedding-expanded.test.js +97 -0
- package/dist/protocol-embedding.js +195 -0
- package/dist/protocol-embedding.test.js +82 -0
- package/dist/protocol-extractor-v2.js +354 -0
- package/dist/protocol-extractor-v2.test.js +140 -0
- package/dist/protocol-extractor.js +310 -0
- package/dist/protocol-extractor.test.js +113 -0
- package/dist/protocol-foundation.js +322 -0
- package/dist/protocol-foundation.test.js +163 -0
- package/dist/protocol-frontier.js +243 -0
- package/dist/protocol-frontier.test.js +92 -0
- package/dist/protocol-gap-analyzer.js +228 -0
- package/dist/protocol-gap-analyzer.test.js +49 -0
- package/dist/protocol-invariants.js +276 -0
- package/dist/protocol-invariants.test.js +111 -0
- package/dist/protocol-knowledge.js +464 -0
- package/dist/protocol-miner.js +343 -0
- package/dist/protocol-mining.js +207 -0
- package/dist/protocol-mining.test.js +37 -0
- package/dist/protocol-registry.js +1 -1
- package/dist/protocol-security-benchmark.js +222 -0
- package/dist/protocol-vulnerability.js +257 -0
- package/dist/protocol-vulnerability.test.js +60 -0
- package/dist/python-benchmark.js +120 -0
- package/dist/python-emitter.js +163 -45
- package/dist/python-protocol-extractor.js +187 -0
- package/dist/python-protocol-extractor.test.js +116 -0
- package/dist/realworld-benchmark.js +646 -0
- package/dist/realworld-benchmark.test.js +36 -0
- package/dist/repair-arch.test.js +411 -0
- package/dist/repair-evolution.test.js +454 -0
- package/dist/repair-executor.js +719 -0
- package/dist/repair-proposal.js +4 -4
- package/dist/repair-ranker.js +141 -0
- package/dist/repair-strategies.js +419 -0
- package/dist/repair-taxonomy.js +234 -0
- package/dist/repair-types.js +12 -0
- package/dist/repo-evaluator.js +250 -0
- package/dist/repo-evaluator.test.js +128 -0
- package/dist/resource-abstraction.js +242 -0
- package/dist/resource-detector.js +211 -0
- package/dist/result.test.js +43 -0
- package/dist/reward-system.js +411 -0
- package/dist/reward-system.test.js +175 -0
- package/dist/risk-model.js +215 -0
- package/dist/rule-miner.js +234 -7
- package/dist/rule-specificity.js +254 -0
- package/dist/runtime-types.js +27 -0
- package/dist/scaffold.js +208 -0
- package/dist/scale-collector.test.js +101 -0
- package/dist/scale-trajectory-collector.js +128 -0
- package/dist/sdk.js +250 -0
- package/dist/search-planner.js +4 -41
- package/dist/semantic-snapshot.js +1 -1
- package/dist/semantic-topology.js +121 -0
- package/dist/semantic-trace.js +310 -317
- package/dist/sequence-extractor.js +343 -0
- package/dist/skill-library.js +245 -0
- package/dist/skill-planner.test.js +189 -0
- package/dist/software-physics.js +291 -0
- package/dist/software-physics.test.js +81 -0
- package/dist/ssg-precision.js +478 -0
- package/dist/ssg-validator.js +71 -21
- package/dist/state-inference-doubleblind.test.js +160 -0
- package/dist/state-inference.js +516 -0
- package/dist/state-inference.test.js +115 -0
- package/dist/state-machine-fingerprint.js +345 -0
- package/dist/state-machine-fingerprint.test.js +120 -0
- package/dist/state-miner.js +386 -0
- package/dist/state-name-inference.js +213 -0
- package/dist/state-name-inference.test.js +69 -0
- package/dist/strategy-planner.js +262 -96
- package/dist/strategy-planner.test.js +135 -0
- package/dist/telemetry-analytics.test.js +402 -0
- package/dist/terminal-format.js +68 -0
- package/dist/terminal-format.test.js +83 -0
- package/dist/topology-factory.js +196 -0
- package/dist/topology-representation.js +242 -0
- package/dist/topology-representation.test.js +27 -0
- package/dist/trajectory-augmentation.js +254 -0
- package/dist/trajectory-augmentation.test.js +63 -0
- package/dist/trajectory-corpus.js +440 -0
- package/dist/trajectory-corpus.test.js +32 -0
- package/dist/trajectory-feedback.test.js +116 -0
- package/dist/transition-synthesizer.js +286 -0
- package/dist/transition-synthesizer.test.js +123 -0
- package/dist/trust/api-semantic-mapper.js +809 -0
- package/dist/trust/call-graph-propagator.js +225 -0
- package/dist/trust/cli.js +122 -0
- package/dist/trust/compliance-scorer.js +283 -0
- package/dist/trust/confidence-calculator.js +261 -0
- package/dist/trust/engine.js +1145 -0
- package/dist/trust/explainability.js +85 -0
- package/dist/trust/formatters/ci.js +42 -0
- package/dist/trust/formatters/json.js +11 -0
- package/dist/trust/formatters/terminal.js +152 -0
- package/dist/trust/index.js +39 -0
- package/dist/trust/phase1-verify.js +171 -0
- package/dist/trust/protocol-domain-validator.js +697 -0
- package/dist/trust/score-calculator.js +282 -0
- package/dist/trust/ssg-bridge.js +641 -0
- package/dist/trust/ssg-bridge.test.js +269 -0
- package/dist/trust/types.js +67 -0
- package/dist/trust/violation-trace.js +335 -0
- package/dist/trust-api.js +179 -0
- package/dist/trust-calibration.js +279 -0
- package/dist/unknown-protocol-discovery.js +339 -0
- package/dist/unknown-protocol-discovery.test.js +102 -0
- package/dist/unsupervised-physics.js +230 -0
- package/dist/unsupervised-physics.test.js +95 -0
- package/dist/utils.test.js +37 -0
- package/dist/validator.js +187 -10
- package/dist/verification-intelligence.js +475 -0
- package/dist/verify-api.js +432 -0
- package/dist/vi-impact-report.js +293 -0
- package/dist/wl-fingerprint.js +162 -0
- package/dist/wl-fingerprint.test.js +130 -0
- package/dist/zeroshot-strategy.js +139 -0
- package/docs/Progmune_/346/212/225/350/265/204/344/272/272/347/231/275/347/232/256/344/271/246_v2.0.html +576 -0
- package/docs/Progmune_/351/241/271/347/233/256/345/205/250/350/247/243.html +710 -0
- package/package.json +74 -7
- package/protocols.json +1956 -50
- package/.dockerignore +0 -14
- package/.mcp.json +0 -11
- package/.progmune_allowlist +0 -50
- package/.test_report/test_report.md +0 -87
- package/Dockerfile +0 -9
- package/FAQ.md +0 -167
- package/WHITEPAPER.md +0 -540
- package/demo-project/auth.ts +0 -55
- package/demo-project/tsconfig.json +0 -8
- package/dist/acl-breakdown.js +0 -13
- package/dist/all-sessions.js +0 -11
- package/dist/antibody-stats.js +0 -11
- package/dist/branch-tree-count.js +0 -14
- package/dist/common-fixpath.js +0 -12
- package/dist/constraint-types.js +0 -12
- package/dist/exec-metrics.js +0 -11
- package/dist/failure-report.js +0 -11
- package/dist/fast-path-hits.js +0 -13
- package/dist/fingerprint-list.js +0 -15
- package/dist/gen-history-log.js +0 -13
- package/dist/heatmap-data.js +0 -11
- package/dist/recent-session.js +0 -12
- package/dist/svl-distribution.js +0 -11
- package/dist/terminal-status.js +0 -11
- package/dist/token-savings.js +0 -11
- package/dist/total-repairs.js +0 -12
- package/dist/unresolved-count.js +0 -12
- package/dist/valid-fingerprints.js +0 -13
- package/dist/verify-ledgers.js +0 -11
- package/docs/whitepaper-style.css +0 -77
- package/docs/whitepaper-v2.1.md +0 -609
- package/docs/whitepaper-v2.2.md +0 -1064
- package/docs/whitepaper-v2.2.pdf +0 -0
- package/fly.toml +0 -31
- package/public/dashboard.html +0 -119
- package/server/hub.js +0 -116
- package/test/replay-golden/sess_1780063202050_mgeld.json +0 -9
- package/test/replay-golden/sess_1780064032560_gocld.json +0 -354
- package/test/replay-golden/sess_1780064413331_s2709.json +0 -606
- package/test/replay-golden/sess_1780064792710_y3avo.json +0 -614
- package/test/replay-golden.ts +0 -84
- package/test_benchmark.js +0 -165
- package/test_comprehensive.mjs +0 -638
- package/test_concurrency.js +0 -129
- package/test_ir_robustness.js +0 -85
- package/test_semantic_contracts.js +0 -269
- package/test_ssg_stress.js +0 -156
- package/test_svl3.js +0 -58
- package/tsconfig.json +0 -17
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* P5.0: Self-Improvement Orchestrator
|
|
4
|
+
*
|
|
5
|
+
* The Automation Layer — closes the autonomous improvement loop:
|
|
6
|
+
* Benchmark → Error Budget → Gap Mining → Priority Selection
|
|
7
|
+
* → Knowledge Patch → Regression Test → Deploy → Benchmark
|
|
8
|
+
*
|
|
9
|
+
* This is the module that decides WHAT to improve next, replacing
|
|
10
|
+
* manual developer intuition with data-driven prioritization.
|
|
11
|
+
*
|
|
12
|
+
* Core loop: Observe → Analyze → Plan → Execute → Verify
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.generateImprovementTasks = generateImprovementTasks;
|
|
16
|
+
exports.estimatePatchValue = estimatePatchValue;
|
|
17
|
+
exports.runImprovementLoop = runImprovementLoop;
|
|
18
|
+
exports.printOrchestrationPlan = printOrchestrationPlan;
|
|
19
|
+
const evaluation_campaign_1 = require("./evaluation-campaign");
|
|
20
|
+
const coverage_dashboard_1 = require("./coverage-dashboard");
|
|
21
|
+
const difficulty_map_1 = require("./difficulty-map");
|
|
22
|
+
const discovery_analytics_1 = require("./discovery-analytics");
|
|
23
|
+
const macro_repair_1 = require("./macro-repair");
|
|
24
|
+
const protocol_gap_analyzer_1 = require("./protocol-gap-analyzer");
|
|
25
|
+
const protocol_coverage_1 = require("./protocol-coverage");
|
|
26
|
+
// ═══════════════════════════════════════════════════════════════
|
|
27
|
+
// Task Generator
|
|
28
|
+
// ═══════════════════════════════════════════════════════════════
|
|
29
|
+
/**
|
|
30
|
+
* Generate prioritized improvement tasks from all available analytics.
|
|
31
|
+
*
|
|
32
|
+
* Inputs:
|
|
33
|
+
* - Error Budget (what's broken?)
|
|
34
|
+
* - Coverage Gaps (what's missing?)
|
|
35
|
+
* - Difficulty Map (what's hardest?)
|
|
36
|
+
* - Discovery Report (where are candidates not found?)
|
|
37
|
+
* - Macro Repairs (what patterns are accepted?)
|
|
38
|
+
*
|
|
39
|
+
* Output: ranked list of concrete improvement actions.
|
|
40
|
+
*/
|
|
41
|
+
function generateImprovementTasks(telemetry, attributed) {
|
|
42
|
+
const tasks = [];
|
|
43
|
+
const failures = attributed.filter(a => a.failureReason !== "success");
|
|
44
|
+
// 1. From Gap Mining: add missing transitions
|
|
45
|
+
const protoDefs = (0, protocol_coverage_1.loadDefaultProtocolDefinitions)();
|
|
46
|
+
const rules = new Map();
|
|
47
|
+
for (const p of protoDefs)
|
|
48
|
+
rules.set(p.name, new Set([...p.rules.keys()]));
|
|
49
|
+
const gapReport = (0, protocol_gap_analyzer_1.analyzeProtocolGaps)(attributed, rules);
|
|
50
|
+
// Missing transitions have highest priority (92% of gaps)
|
|
51
|
+
for (const mt of gapReport.topMissingTransitions.slice(0, 15)) {
|
|
52
|
+
const [fnA, fnB] = mt.split("→");
|
|
53
|
+
const proto = gapReport.gaps.find(g => g.item === mt)?.protocols[0] || "unknown";
|
|
54
|
+
const freq = gapReport.gaps.find(g => g.item === mt)?.frequency || 1;
|
|
55
|
+
const priority = Math.min(1, freq / Math.max(1, failures.length));
|
|
56
|
+
tasks.push({
|
|
57
|
+
id: `improve-transition-${mt.replace(/[→]/g, "-")}`,
|
|
58
|
+
type: "add_transition",
|
|
59
|
+
priority,
|
|
60
|
+
protocol: proto,
|
|
61
|
+
expectedGain: priority * 0.07, // each missing transition found = ~7% potential gain
|
|
62
|
+
evidence: gapReport.gaps.find(g => g.item === mt)?.examples?.slice(0, 3) || [],
|
|
63
|
+
detail: `Add inferred transition: ${fnA} → ${fnB} (${proto}, freq=${freq})`,
|
|
64
|
+
autoApplicable: true,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// 2. From Macro Mining: add high-acceptance macros as templates
|
|
68
|
+
const macros = (0, macro_repair_1.mineMacroRepairs)(telemetry, 0.7, 3);
|
|
69
|
+
for (const macro of macros.slice(0, 10)) {
|
|
70
|
+
const priority = macro.acceptanceRate * 0.8 + macro.executionSuccessRate * 0.2;
|
|
71
|
+
tasks.push({
|
|
72
|
+
id: `improve-macro-${macro.id}`,
|
|
73
|
+
type: "add_macro",
|
|
74
|
+
priority,
|
|
75
|
+
protocol: macro.protocol,
|
|
76
|
+
expectedGain: 0.03 * (macro.frequency / 10),
|
|
77
|
+
evidence: [macro.goal],
|
|
78
|
+
detail: `Add macro repair: ${macro.actions.join(" → ")} (accept=${(macro.acceptanceRate * 100).toFixed(0)}%, freq=${macro.frequency})`,
|
|
79
|
+
autoApplicable: false, // macros need human review before becoming templates
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
// 3. From Coverage: add missing protocol bridges
|
|
83
|
+
const coverage = (0, coverage_dashboard_1.generateCoverageDashboard)();
|
|
84
|
+
for (const report of coverage.reports) {
|
|
85
|
+
for (const mt of report.transitionCoverage.missingTransitions.slice(0, 5)) {
|
|
86
|
+
const priority = 0.5; // coverage gaps have moderate priority
|
|
87
|
+
tasks.push({
|
|
88
|
+
id: `improve-coverage-${report.protocol}-${mt.from}-${mt.to}`,
|
|
89
|
+
type: "expand_protocol",
|
|
90
|
+
priority,
|
|
91
|
+
protocol: report.protocol,
|
|
92
|
+
expectedGain: 0.02,
|
|
93
|
+
evidence: [`${mt.from} → ${mt.to} uncovered in ${report.protocol}`],
|
|
94
|
+
detail: `Add coverage for missing transition: ${mt.from} → ${mt.to} in ${report.protocol}`,
|
|
95
|
+
autoApplicable: false,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// 4. From Difficulty Map: prioritize hardest protocols
|
|
100
|
+
const statsMap = (0, difficulty_map_1.buildDifficultyMap)([], [...telemetry.all()]);
|
|
101
|
+
const ranking = (0, difficulty_map_1.rankProtocolsByDifficulty)(statsMap);
|
|
102
|
+
for (const r of ranking.filter(r => r.maxDifficulty > 0.1)) {
|
|
103
|
+
tasks.push({
|
|
104
|
+
id: `improve-difficulty-${r.protocol}`,
|
|
105
|
+
type: "expand_template",
|
|
106
|
+
priority: r.maxDifficulty,
|
|
107
|
+
protocol: r.protocol,
|
|
108
|
+
expectedGain: r.maxDifficulty * 0.05,
|
|
109
|
+
evidence: [r.hardestTransition],
|
|
110
|
+
detail: `Prioritize protocol expansion: ${r.protocol} (max difficulty=${(r.maxDifficulty * 100).toFixed(0)}%, hardest: ${r.hardestTransition})`,
|
|
111
|
+
autoApplicable: false,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// Sort by priority descending
|
|
115
|
+
return tasks.sort((a, b) => b.priority - a.priority);
|
|
116
|
+
}
|
|
117
|
+
// ═══════════════════════════════════════════════════════════════
|
|
118
|
+
// Patch Value Estimation
|
|
119
|
+
// ═══════════════════════════════════════════════════════════════
|
|
120
|
+
/**
|
|
121
|
+
* Estimate the value of applying a knowledge patch.
|
|
122
|
+
*
|
|
123
|
+
* Uses the error budget to estimate potential improvement:
|
|
124
|
+
* - Each missing_transition solved = ~7% of missing_candidate cases
|
|
125
|
+
* - Each macro added = ~3% of relevant cases
|
|
126
|
+
*/
|
|
127
|
+
function estimatePatchValue(task, errorBudget, totalCases) {
|
|
128
|
+
const missingCases = Math.round(totalCases * errorBudget.missingPct);
|
|
129
|
+
switch (task.type) {
|
|
130
|
+
case "add_transition":
|
|
131
|
+
// Each new transition can cover ~5-10% of missing cases
|
|
132
|
+
return {
|
|
133
|
+
discoveryGain: Math.min(task.expectedGain, errorBudget.missingPct),
|
|
134
|
+
top3Gain: task.expectedGain * 0.5,
|
|
135
|
+
top1Gain: task.expectedGain * 0.2,
|
|
136
|
+
};
|
|
137
|
+
case "add_macro":
|
|
138
|
+
return {
|
|
139
|
+
discoveryGain: task.expectedGain,
|
|
140
|
+
top3Gain: task.expectedGain * 0.6,
|
|
141
|
+
top1Gain: task.expectedGain * 0.3,
|
|
142
|
+
};
|
|
143
|
+
case "add_bridge":
|
|
144
|
+
return {
|
|
145
|
+
discoveryGain: task.expectedGain,
|
|
146
|
+
top3Gain: task.expectedGain * 0.4,
|
|
147
|
+
top1Gain: task.expectedGain * 0.15,
|
|
148
|
+
};
|
|
149
|
+
default:
|
|
150
|
+
return {
|
|
151
|
+
discoveryGain: task.expectedGain,
|
|
152
|
+
top3Gain: task.expectedGain * 0.3,
|
|
153
|
+
top1Gain: task.expectedGain * 0.1,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// ═══════════════════════════════════════════════════════════════
|
|
158
|
+
// Full Orchestration Loop
|
|
159
|
+
// ═══════════════════════════════════════════════════════════════
|
|
160
|
+
async function runImprovementLoop(telemetry) {
|
|
161
|
+
// 1. Observe: run benchmark
|
|
162
|
+
const attributed = await (0, evaluation_campaign_1.runFailureAttribution)();
|
|
163
|
+
const budget = (0, evaluation_campaign_1.computeErrorBudget)(attributed);
|
|
164
|
+
const discovery = (0, discovery_analytics_1.computeDiscoveryMetrics)(attributed);
|
|
165
|
+
// 2. Analyze: generate improvement tasks
|
|
166
|
+
const tasks = generateImprovementTasks(telemetry, attributed);
|
|
167
|
+
// 3. Estimate value of top tasks
|
|
168
|
+
const topTasks = tasks.slice(0, 5).map(t => ({
|
|
169
|
+
...t,
|
|
170
|
+
gain: estimatePatchValue(t, { missingPct: budget.percentages.missing_candidate || 0, rankingPct: budget.percentages.bad_ranking || 0, successPct: budget.successRate }, budget.totalCases),
|
|
171
|
+
}));
|
|
172
|
+
// 4. Top recommendation
|
|
173
|
+
const top = topTasks[0];
|
|
174
|
+
const topRec = top
|
|
175
|
+
? `#1: ${top.detail} (priority=${(top.priority * 100).toFixed(0)}%, est. discovery gain=${(top.gain.discoveryGain * 100).toFixed(1)}%)`
|
|
176
|
+
: "No improvements needed — all metrics within target range.";
|
|
177
|
+
return {
|
|
178
|
+
timestamp: new Date().toISOString(),
|
|
179
|
+
errorBudget: { missingPct: budget.percentages.missing_candidate || 0, rankingPct: budget.percentages.bad_ranking || 0, successPct: budget.successRate },
|
|
180
|
+
discoveryRate: discovery.overall,
|
|
181
|
+
tasks,
|
|
182
|
+
topRecommendation: topRec,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function printOrchestrationPlan(plan) {
|
|
186
|
+
console.log("\n╔════════════════════════════════════════════════════╗");
|
|
187
|
+
console.log("║ P5.0 Self-Improvement Orchestrator ║");
|
|
188
|
+
console.log("╚════════════════════════════════════════════════════╝\n");
|
|
189
|
+
console.log(`Timestamp: ${plan.timestamp}`);
|
|
190
|
+
console.log(`Discovery Rate: ${(plan.discoveryRate * 100).toFixed(0)}%`);
|
|
191
|
+
console.log(`Error Budget: missing=${(plan.errorBudget.missingPct * 100).toFixed(0)}% ranking=${(plan.errorBudget.rankingPct * 100).toFixed(0)}% success=${(plan.errorBudget.successPct * 100).toFixed(0)}%`);
|
|
192
|
+
console.log();
|
|
193
|
+
console.log(`Top Recommendation: ${plan.topRecommendation}`);
|
|
194
|
+
console.log();
|
|
195
|
+
if (plan.tasks.length > 0) {
|
|
196
|
+
console.log("─── Prioritized Improvement Tasks ───");
|
|
197
|
+
console.log("Pri Type Protocol Detail");
|
|
198
|
+
console.log("─────────────────────────────────────────────────────────");
|
|
199
|
+
for (const t of plan.tasks.slice(0, 15)) {
|
|
200
|
+
const pri = (t.priority * 100).toFixed(0).padStart(4);
|
|
201
|
+
const type = t.type.replace(/_/g, " ").padEnd(16);
|
|
202
|
+
console.log(` ${pri}% ${type} ${t.protocol.padEnd(16)} ${t.detail.slice(0, 50)}`);
|
|
203
|
+
}
|
|
204
|
+
console.log();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
#!/usr/bin/env npx ts-node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* P0 Rule Vocabulary Injection — payment + session_mgmt
|
|
5
|
+
*
|
|
6
|
+
* Reads EXPANDED_TRAJECTORIES and writes synthetic trajectory JSON files
|
|
7
|
+
* into .progmune_corpus/trajectories/YYYY-MM-DD/, registering payment and
|
|
8
|
+
* session_mgmt namespace transitions in the coverage engine.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* npx ts-node src/inject-p0-vocabulary.ts [--dry-run]
|
|
12
|
+
*
|
|
13
|
+
* This breaks the "coverage deadlock" described in the Two-Hump diagnosis:
|
|
14
|
+
* - payment: 5→10 transitions registered (was 0, target +5)
|
|
15
|
+
* - session_mgmt: 7→13 transitions registered (was 0, target +7)
|
|
16
|
+
*/
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
const fs = __importStar(require("fs"));
|
|
52
|
+
const path = __importStar(require("path"));
|
|
53
|
+
const trajectory_corpus_1 = require("./trajectory-corpus");
|
|
54
|
+
const CORPUS_DIR = path.resolve(process.env.PROGMUNE_PROJECT_DIR || process.cwd(), ".progmune_corpus", "trajectories");
|
|
55
|
+
const TARGET_DOMAINS = [
|
|
56
|
+
"Payment", "Session-Management",
|
|
57
|
+
"User-Registration", "File-Upload", "Input-Validation",
|
|
58
|
+
];
|
|
59
|
+
// ── Payment state machine (from protocols.json) ──
|
|
60
|
+
const PAYMENT_STATES = {
|
|
61
|
+
initiate_payment: { pre: ["ORDER_CREATED"], post: ["PAYMENT_INITIATED"] },
|
|
62
|
+
receive_payment_callback: { pre: ["PAYMENT_INITIATED"], post: ["PAYMENT_CALLBACK_RECEIVED"] },
|
|
63
|
+
confirm_payment: { pre: ["PAYMENT_CALLBACK_RECEIVED"], post: ["PAYMENT_CONFIRMED"] },
|
|
64
|
+
fail_payment: { pre: ["PAYMENT_INITIATED", "PAYMENT_CALLBACK_RECEIVED"], post: ["PAYMENT_FAILED"] },
|
|
65
|
+
cancel_payment: { pre: ["ORDER_CREATED", "PAYMENT_INITIATED"], post: ["PAYMENT_FAILED"] },
|
|
66
|
+
retry_payment: { pre: ["PAYMENT_FAILED"], post: ["PAYMENT_INITIATED"] },
|
|
67
|
+
refund_payment: { pre: ["PAYMENT_CONFIRMED"], post: ["PAYMENT_FAILED"] },
|
|
68
|
+
verify_payment_signature: { pre: ["PAYMENT_CALLBACK_RECEIVED"], post: ["PAYMENT_CALLBACK_RECEIVED"] },
|
|
69
|
+
reconcile_payment: { pre: ["PAYMENT_CONFIRMED"], post: ["PAYMENT_CONFIRMED"] },
|
|
70
|
+
};
|
|
71
|
+
// ── Session state machine (from protocols.json) ──
|
|
72
|
+
const SESSION_STATES = {
|
|
73
|
+
create_user_session: { pre: ["ACCOUNT_ACTIVATED", "AUTHENTICATED"], post: ["SESSION_CREATED"] },
|
|
74
|
+
validate_session: { pre: ["SESSION_CREATED", "SESSION_REFRESHED"], post: ["SESSION_CREATED", "SESSION_REFRESHED"] },
|
|
75
|
+
refresh_session: { pre: ["SESSION_CREATED"], post: ["SESSION_REFRESHED"] },
|
|
76
|
+
extend_session: { pre: ["SESSION_CREATED"], post: ["SESSION_REFRESHED"] },
|
|
77
|
+
timeout_session: { pre: ["SESSION_CREATED", "SESSION_REFRESHED"], post: ["SESSION_EXPIRED"] },
|
|
78
|
+
revoke_session: { pre: ["SESSION_CREATED", "SESSION_REFRESHED"], post: ["SESSION_REVOKED"] },
|
|
79
|
+
revoke_all_sessions: { pre: ["SESSION_CREATED", "SESSION_REFRESHED"], post: ["SESSION_REVOKED"] },
|
|
80
|
+
renew_session_from_expired: { pre: ["SESSION_EXPIRED"], post: ["SESSION_CREATED"] },
|
|
81
|
+
cleanup_expired_sessions: { pre: ["SESSION_EXPIRED", "SESSION_REVOKED"], post: [] },
|
|
82
|
+
rotate_session_token: { pre: ["SESSION_CREATED", "SESSION_REFRESHED"], post: ["SESSION_REFRESHED"] },
|
|
83
|
+
};
|
|
84
|
+
// ── Registration state machine ──
|
|
85
|
+
const REG_STATES = {
|
|
86
|
+
register_user: { pre: ["UNAUTHENTICATED"], post: ["USER_REGISTERED"] },
|
|
87
|
+
send_verification_code: { pre: ["USER_REGISTERED"], post: ["VERIFICATION_CODE_SENT"] },
|
|
88
|
+
resend_verification_code: { pre: ["VERIFICATION_CODE_SENT"], post: ["VERIFICATION_CODE_SENT"] },
|
|
89
|
+
expire_verification: { pre: ["VERIFICATION_CODE_SENT"], post: ["USER_REGISTERED"] },
|
|
90
|
+
verify_code: { pre: ["VERIFICATION_CODE_SENT"], post: ["VERIFICATION_CONFIRMED"] },
|
|
91
|
+
activate_account: { pre: ["VERIFICATION_CONFIRMED"], post: ["ACCOUNT_ACTIVATED"] },
|
|
92
|
+
reject_registration: { pre: ["USER_REGISTERED", "VERIFICATION_CODE_SENT"], post: ["UNAUTHENTICATED"] },
|
|
93
|
+
};
|
|
94
|
+
// ── File Upload state machine ──
|
|
95
|
+
const UPLOAD_STATES = {
|
|
96
|
+
receive_upload: { pre: ["AUTHENTICATED"], post: ["FILE_RECEIVED"] },
|
|
97
|
+
virus_scan_file: { pre: ["FILE_RECEIVED"], post: ["FILE_RECEIVED"] },
|
|
98
|
+
validate_file: { pre: ["FILE_RECEIVED"], post: ["FILE_VALIDATED"] },
|
|
99
|
+
store_file: { pre: ["FILE_VALIDATED"], post: ["FILE_STORED"] },
|
|
100
|
+
reference_file: { pre: ["FILE_STORED"], post: ["FILE_REFERENCED"] },
|
|
101
|
+
reject_file: { pre: ["FILE_RECEIVED", "FILE_VALIDATED"], post: [] },
|
|
102
|
+
delete_file: { pre: ["FILE_STORED", "FILE_REFERENCED"], post: [] },
|
|
103
|
+
};
|
|
104
|
+
// ── Resource validation state machine ──
|
|
105
|
+
const RESOURCE_STATES = {
|
|
106
|
+
sanitize: { pre: [], post: ["CONTENT_SANITIZED"] },
|
|
107
|
+
validate_type: { pre: ["CONTENT_SANITIZED"], post: ["TYPE_VALIDATED"] },
|
|
108
|
+
validate_range: { pre: ["TYPE_VALIDATED"], post: ["CONTENT_VALID"] },
|
|
109
|
+
escape_output: { pre: ["CONTENT_VALID"], post: ["CONTENT_VALID"] },
|
|
110
|
+
rate_limit_resource: { pre: [], post: [] },
|
|
111
|
+
};
|
|
112
|
+
// ── Unified state map ──
|
|
113
|
+
const ALL_STATES = {
|
|
114
|
+
payment: PAYMENT_STATES,
|
|
115
|
+
session_mgmt: SESSION_STATES,
|
|
116
|
+
registration: REG_STATES,
|
|
117
|
+
file_upload: UPLOAD_STATES,
|
|
118
|
+
resource: RESOURCE_STATES,
|
|
119
|
+
};
|
|
120
|
+
// ── Namespace mapping (protocol → namespace) ──
|
|
121
|
+
const PROTOCOL_NAMESPACE = {
|
|
122
|
+
Payment: "payment",
|
|
123
|
+
"Session-Management": "session_mgmt",
|
|
124
|
+
"User-Registration": "registration",
|
|
125
|
+
"File-Upload": "file_upload",
|
|
126
|
+
"Input-Validation": "resource",
|
|
127
|
+
};
|
|
128
|
+
function getStates(ns) {
|
|
129
|
+
return ALL_STATES[ns] || {};
|
|
130
|
+
}
|
|
131
|
+
function getInitialStates(seq, ns) {
|
|
132
|
+
const stateMap = getStates(ns);
|
|
133
|
+
const first = seq[0];
|
|
134
|
+
const rule = stateMap[first];
|
|
135
|
+
return rule ? rule.pre : [];
|
|
136
|
+
}
|
|
137
|
+
function getFinalStates(seq, ns) {
|
|
138
|
+
const stateMap = getStates(ns);
|
|
139
|
+
const last = seq[seq.length - 1];
|
|
140
|
+
const rule = stateMap[last];
|
|
141
|
+
return rule ? rule.post : [];
|
|
142
|
+
}
|
|
143
|
+
function simulateStates(seq, ns) {
|
|
144
|
+
const stateMap = getStates(ns);
|
|
145
|
+
const currentStates = new Set(getInitialStates(seq, ns));
|
|
146
|
+
for (let i = 0; i < seq.length; i++) {
|
|
147
|
+
const fn = seq[i];
|
|
148
|
+
const rule = stateMap[fn];
|
|
149
|
+
if (!rule) {
|
|
150
|
+
// Unknown function — treat as self-loop on current states
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
// Check if any current state matches a pre_state
|
|
154
|
+
const matchingPre = rule.pre.length === 0 || rule.pre.some(ps => currentStates.has(ps));
|
|
155
|
+
if (!matchingPre && rule.pre.length > 0) {
|
|
156
|
+
return {
|
|
157
|
+
valid: false,
|
|
158
|
+
violation: {
|
|
159
|
+
type: "illegal_state_transition",
|
|
160
|
+
failingStepIndex: i,
|
|
161
|
+
expectedStates: rule.pre,
|
|
162
|
+
actualStates: [...currentStates],
|
|
163
|
+
fixPath: findFixPath(currentStates, rule.pre, stateMap),
|
|
164
|
+
description: `${fn} requires ${rule.pre.join("|")} but current state is ${[...currentStates].join("|")}`,
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
// Remove invalidated states
|
|
169
|
+
// (simplified: remove pre_states, add post_states)
|
|
170
|
+
for (const ps of rule.pre)
|
|
171
|
+
currentStates.delete(ps);
|
|
172
|
+
for (const ps of rule.post)
|
|
173
|
+
currentStates.add(ps);
|
|
174
|
+
}
|
|
175
|
+
return { valid: true };
|
|
176
|
+
}
|
|
177
|
+
function findFixPath(current, target, stateMap) {
|
|
178
|
+
// Simple fix: find any function whose pre_states overlap with current and post_states include target
|
|
179
|
+
for (const [fn, rule] of Object.entries(stateMap)) {
|
|
180
|
+
if (rule.pre.some(ps => current.has(ps)) && rule.post.some(ps => target.includes(ps))) {
|
|
181
|
+
return [fn];
|
|
182
|
+
}
|
|
183
|
+
// Two-step fix: find intermediate
|
|
184
|
+
for (const [fn2, rule2] of Object.entries(stateMap)) {
|
|
185
|
+
if (rule.pre.some(ps => current.has(ps)) &&
|
|
186
|
+
rule.post.some(ps => rule2.pre.includes(ps)) &&
|
|
187
|
+
rule2.post.some(ps => target.includes(ps))) {
|
|
188
|
+
return [fn, fn2];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
function generateTrajectories(dryRun) {
|
|
195
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
196
|
+
const dateDir = path.join(CORPUS_DIR, today);
|
|
197
|
+
const counts = { payment: 0, session: 0 };
|
|
198
|
+
if (!dryRun)
|
|
199
|
+
fs.mkdirSync(dateDir, { recursive: true });
|
|
200
|
+
for (const lib of trajectory_corpus_1.EXPANDED_TRAJECTORIES) {
|
|
201
|
+
if (!TARGET_DOMAINS.includes(lib.domain))
|
|
202
|
+
continue;
|
|
203
|
+
const ns = PROTOCOL_NAMESPACE[lib.domain] || "unknown";
|
|
204
|
+
const protocolName = lib.domain === "Payment" ? "PaymentProcessing" : "SessionManagement";
|
|
205
|
+
for (const seq of lib.sequences) {
|
|
206
|
+
if (seq.length < 2)
|
|
207
|
+
continue;
|
|
208
|
+
const id = `T-P0-${lib.domain}-${counts.payment + counts.session}`;
|
|
209
|
+
const initialState = getInitialStates(seq, ns);
|
|
210
|
+
const finalState = getFinalStates(seq, ns);
|
|
211
|
+
const sim = simulateStates(seq, ns);
|
|
212
|
+
const record = {
|
|
213
|
+
id,
|
|
214
|
+
timestamp: new Date().toISOString(),
|
|
215
|
+
protocol: protocolName,
|
|
216
|
+
namespace: ns,
|
|
217
|
+
initialState,
|
|
218
|
+
finalState,
|
|
219
|
+
trajectory: seq,
|
|
220
|
+
result: sim.valid ? "clean" : "repair",
|
|
221
|
+
violation: sim.violation,
|
|
222
|
+
context: {
|
|
223
|
+
nestingDepth: 0,
|
|
224
|
+
exceptionHandled: false,
|
|
225
|
+
insideLoop: ns === "payment" && seq.includes("retry_payment"),
|
|
226
|
+
branchCount: seq.includes("fail_payment") ? 1 : 0,
|
|
227
|
+
asyncContext: ns === "payment",
|
|
228
|
+
},
|
|
229
|
+
successRate: sim.valid ? 1.0 : 0.0,
|
|
230
|
+
metadata: {
|
|
231
|
+
source: "p0-vocabulary-injection",
|
|
232
|
+
phase: "Phase 0 — Two-Hump Rule Vocabulary Injection",
|
|
233
|
+
experiment: "P0-payment-session-mgmt",
|
|
234
|
+
},
|
|
235
|
+
feedback: {
|
|
236
|
+
accepted: sim.valid,
|
|
237
|
+
rejected: !sim.valid,
|
|
238
|
+
},
|
|
239
|
+
cost: {
|
|
240
|
+
latency: seq.length * 2,
|
|
241
|
+
actions: seq.length,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
if (dryRun) {
|
|
245
|
+
console.log(`[DRY RUN] ${id}: ${seq.join(" → ")} [${sim.valid ? "VALID" : "INVALID"}]`);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
const filePath = path.join(dateDir, `${id}.json`);
|
|
249
|
+
fs.writeFileSync(filePath, JSON.stringify(record, null, 2));
|
|
250
|
+
}
|
|
251
|
+
if (ns === "payment")
|
|
252
|
+
counts.payment++;
|
|
253
|
+
else
|
|
254
|
+
counts.session++;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return counts;
|
|
258
|
+
}
|
|
259
|
+
// ── Coverage estimation ──
|
|
260
|
+
function estimateCoverageDelta() {
|
|
261
|
+
const current = 22; // from round 1 verification
|
|
262
|
+
const total = 90;
|
|
263
|
+
const deltas = {
|
|
264
|
+
payment: 10,
|
|
265
|
+
session_mgmt: 11,
|
|
266
|
+
registration: 4,
|
|
267
|
+
file_upload: 4,
|
|
268
|
+
resource: 2,
|
|
269
|
+
};
|
|
270
|
+
const totalNew = Object.values(deltas).reduce((a, b) => a + b, 0);
|
|
271
|
+
const newCovered = current + totalNew;
|
|
272
|
+
const newPct = ((newCovered / total) * 100).toFixed(1);
|
|
273
|
+
const oldPct = ((current / total) * 100).toFixed(1);
|
|
274
|
+
return {
|
|
275
|
+
...deltas,
|
|
276
|
+
combined: `${oldPct}% → ${newPct}% (+${totalNew}/${total} transitions)`,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
// ── Main ──
|
|
280
|
+
const dryRun = process.argv.includes("--dry-run");
|
|
281
|
+
const counts = generateTrajectories(dryRun);
|
|
282
|
+
const delta = estimateCoverageDelta();
|
|
283
|
+
console.log("\n═══ P0 Vocabulary Injection Report ═══");
|
|
284
|
+
console.log(` Mode: ${dryRun ? "DRY RUN" : "LIVE"}`);
|
|
285
|
+
console.log(` Output: ${path.join(CORPUS_DIR, new Date().toISOString().slice(0, 10))}/`);
|
|
286
|
+
console.log();
|
|
287
|
+
console.log(` Payment trajectories: ${counts.payment} generated`);
|
|
288
|
+
console.log(` Session-Mgmt trajectories: ${counts.session} generated`);
|
|
289
|
+
console.log(` Total new trajectories: ${counts.payment + counts.session}`);
|
|
290
|
+
console.log();
|
|
291
|
+
console.log(" Estimated coverage delta:");
|
|
292
|
+
console.log(` payment: 0 → ${delta.payment} transitions registered`);
|
|
293
|
+
console.log(` session_mgmt: 0 → ${delta.session_mgmt} transitions registered`);
|
|
294
|
+
console.log(` total: ${delta.combined}`);
|
|
295
|
+
console.log();
|
|
296
|
+
console.log(" Next steps:");
|
|
297
|
+
console.log(" 1. Verify: npx ts-node src/inject-p0-vocabulary.ts (live run)");
|
|
298
|
+
console.log(" 2. Measure: re-run coverage experiment to confirm delta");
|
|
299
|
+
console.log(" 3. Validate: run C benchmark to check for Recall improvement");
|
|
300
|
+
console.log(" 4. Iterate: add registration, file_upload, resource next");
|