progmune-runtime 2.0.4 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/.mcp.json +11 -0
  2. package/.progmune_allowlist +50 -0
  3. package/.test_report/test_report.md +87 -0
  4. package/Dockerfile +2 -10
  5. package/FAQ.md +167 -0
  6. package/README.md +108 -54
  7. package/demo-project/auth.ts +55 -0
  8. package/demo-project/tsconfig.json +8 -0
  9. package/dist/ab-stats.js +11 -0
  10. package/dist/acl-breakdown.js +13 -0
  11. package/dist/action-runtime.js +1 -0
  12. package/dist/all-sessions.js +11 -0
  13. package/dist/antibody-stats.js +11 -0
  14. package/dist/audit.js +222 -0
  15. package/dist/benchmark-count.js +7 -0
  16. package/dist/benchmark-full.js +17 -0
  17. package/dist/benchmark-pass-rate.js +54 -0
  18. package/dist/benchmark-report.js +67 -0
  19. package/dist/benchmark-save.js +62 -0
  20. package/dist/benchmark-status.js +15 -0
  21. package/dist/branch-ledger.js +393 -0
  22. package/dist/branch-tree-count.js +14 -0
  23. package/dist/check.js +506 -0
  24. package/dist/common-fixpath.js +12 -0
  25. package/dist/constraint-types.js +12 -0
  26. package/dist/deterministic-replay.js +283 -0
  27. package/dist/emitter.js +143 -12
  28. package/dist/exec-metrics.js +11 -0
  29. package/dist/execute.js +251 -0
  30. package/dist/extract-ir.js +592 -5
  31. package/dist/failure-collector.js +163 -0
  32. package/dist/failure-corpus.js +507 -35
  33. package/dist/failure-report.js +11 -0
  34. package/dist/failures.js +11 -0
  35. package/dist/fast-path-hits.js +13 -0
  36. package/dist/feedback.js +10 -3
  37. package/dist/file-lock.js +82 -0
  38. package/dist/find-session.js +10 -0
  39. package/dist/fingerprint-list.js +15 -0
  40. package/dist/gen-history-log.js +13 -0
  41. package/dist/generate.js +2 -1
  42. package/dist/generate_500.js +4 -2
  43. package/dist/genome.js +11 -0
  44. package/dist/heatmap-data.js +11 -0
  45. package/dist/heatmap.js +11 -0
  46. package/dist/immune-reporter.js +34 -22
  47. package/dist/ir-utils.js +18 -0
  48. package/dist/learned.js +11 -0
  49. package/dist/ledger-registry.js +252 -0
  50. package/dist/llm.js +46 -2
  51. package/dist/load-benchmarks.js +47 -0
  52. package/dist/main.js +2 -1
  53. package/dist/mcp-server.mjs +445 -43
  54. package/dist/memory-layer.js +54 -13
  55. package/dist/metrics.js +11 -0
  56. package/dist/obs-web.js +561 -0
  57. package/dist/p0_ssg_demo.js +255 -40
  58. package/dist/planner.js +996 -80
  59. package/dist/protocol-registry.js +112 -0
  60. package/dist/recent-session.js +12 -0
  61. package/dist/repair-proposal.js +363 -0
  62. package/dist/runtime-invariants.js +170 -0
  63. package/dist/runtime-types.js +117 -0
  64. package/dist/runtime.js +1 -0
  65. package/dist/search-planner.js +39 -9
  66. package/dist/semantic-snapshot.js +157 -0
  67. package/dist/semantic-trace.js +1497 -0
  68. package/dist/semantic-validator.js +3 -2
  69. package/dist/semantic_guard_test.js +2 -1
  70. package/dist/session-utils.js +19 -0
  71. package/dist/sessions.js +11 -0
  72. package/dist/ssg-validator.js +666 -20
  73. package/dist/svl-distribution.js +11 -0
  74. package/dist/terminal-status.js +11 -0
  75. package/dist/test_failure_corpus.js +3 -1
  76. package/dist/token-savings.js +11 -0
  77. package/dist/total-repairs.js +12 -0
  78. package/dist/unresolved-count.js +12 -0
  79. package/dist/utils.js +2 -0
  80. package/dist/valid-fingerprints.js +13 -0
  81. package/dist/validator.js +118 -60
  82. package/dist/verify-fps.js +11 -0
  83. package/dist/verify-ledgers.js +11 -0
  84. package/docs/whitepaper-style.css +77 -0
  85. package/docs/whitepaper-v2.1.md +609 -0
  86. package/docs/whitepaper-v2.2.md +1064 -0
  87. package/docs/whitepaper-v2.2.pdf +0 -0
  88. package/fly.toml +1 -1
  89. package/package.json +13 -4
  90. package/protocols.json +131 -11
  91. package/public/dashboard.html +119 -0
  92. package/server/hub.js +84 -12
  93. package/test/replay-golden/sess_1780063202050_mgeld.json +9 -0
  94. package/test/replay-golden/sess_1780064032560_gocld.json +354 -0
  95. package/test/replay-golden/sess_1780064413331_s2709.json +606 -0
  96. package/test/replay-golden/sess_1780064792710_y3avo.json +614 -0
  97. package/test/replay-golden.ts +84 -0
  98. package/test_benchmark.js +165 -0
  99. package/test_comprehensive.mjs +638 -0
  100. package/test_concurrency.js +129 -0
  101. package/test_ir_robustness.js +85 -0
  102. package/test_semantic_contracts.js +269 -0
  103. package/test_ssg_stress.js +156 -0
  104. package/test_svl3.js +58 -0
  105. package/tsconfig.json +1 -1
  106. package/.env.example +0 -3
  107. package/.progmune_memory/episodic.json +0 -186
  108. package/.progmune_memory/fingerprints.json +0 -7
  109. package/.progmune_memory/opt_in.json +0 -4
  110. package/immune_hub_data/2026-05-14.json +0 -50
@@ -41,7 +41,17 @@ exports.consolidateSemantic = consolidateSemantic;
41
41
  exports.findSemanticTemplate = findSemanticTemplate;
42
42
  const fs = __importStar(require("fs"));
43
43
  const path = __importStar(require("path"));
44
- const MEMORY_DIR = path.resolve(__dirname, "../.progmune_memory");
44
+ const file_lock_1 = require("./file-lock");
45
+ // 基于项目路径的隔离记忆目录,可通过环境变量 PROGMUNE_MEMORY_DIR 自定义
46
+ // 优先使用 PROGMUNE_PROJECT_DIR(由 MCP 服务器在调用时设置),确保多项目隔离
47
+ const projectDir = process.env.PROGMUNE_PROJECT_DIR || process.cwd();
48
+ const MEMORY_DIR = process.env.PROGMUNE_MEMORY_DIR
49
+ || path.resolve(projectDir, ".progmune_memory");
50
+ function ensureDir(dir) {
51
+ if (!fs.existsSync(dir))
52
+ fs.mkdirSync(dir, { recursive: true });
53
+ }
54
+ // ========== 工作记忆 ==========
45
55
  class WorkMemory {
46
56
  constructor() {
47
57
  this.bindings = new Map();
@@ -56,20 +66,32 @@ class WorkMemory {
56
66
  exports.WorkMemory = WorkMemory;
57
67
  const EPISODIC_FILE = path.join(MEMORY_DIR, "episodic.json");
58
68
  const MAX_EPISODES = 50;
59
- function ensureDir(dir) {
60
- if (!fs.existsSync(dir))
61
- fs.mkdirSync(dir, { recursive: true });
62
- }
69
+ const EPISODE_TTL_MS = 7 * 24 * 60 * 60 * 1000; // 7 天
63
70
  function loadEpisodes() {
64
71
  ensureDir(MEMORY_DIR);
65
72
  if (!fs.existsSync(EPISODIC_FILE))
66
73
  return [];
67
- return JSON.parse(fs.readFileSync(EPISODIC_FILE, "utf-8"));
74
+ const all = JSON.parse(fs.readFileSync(EPISODIC_FILE, "utf-8"));
75
+ const cutoff = Date.now() - EPISODE_TTL_MS;
76
+ const fresh = all.filter(e => new Date(e.timestamp).getTime() > cutoff);
77
+ if (fresh.length < all.length) {
78
+ console.error(`[记忆衰减-读取] 过滤了 ${all.length - fresh.length} 条过期情景记忆`);
79
+ fs.writeFileSync(EPISODIC_FILE, JSON.stringify(fresh, null, 2));
80
+ }
81
+ return fresh;
68
82
  }
69
83
  function saveEpisodes(episodes) {
70
- ensureDir(MEMORY_DIR);
71
- fs.writeFileSync(EPISODIC_FILE, JSON.stringify(episodes.slice(0, MAX_EPISODES), null, 2));
84
+ (0, file_lock_1.withLock)("episodic.json", () => {
85
+ ensureDir(MEMORY_DIR);
86
+ const cutoff = Date.now() - EPISODE_TTL_MS;
87
+ const fresh = episodes.filter(e => new Date(e.timestamp).getTime() > cutoff);
88
+ if (fresh.length !== episodes.length) {
89
+ console.error(`[记忆衰减-写入] 清理了 ${episodes.length - fresh.length} 条过期情景记忆`);
90
+ }
91
+ fs.writeFileSync(EPISODIC_FILE, JSON.stringify(fresh.slice(0, MAX_EPISODES), null, 2));
92
+ });
72
93
  }
94
+ /** @requires EXECUTION_DATA @produces MEMORY_ID */
73
95
  function recordEpisode(episode) {
74
96
  const episodes = loadEpisodes();
75
97
  const newEpisode = {
@@ -78,10 +100,12 @@ function recordEpisode(episode) {
78
100
  timestamp: new Date().toISOString(),
79
101
  };
80
102
  episodes.unshift(newEpisode);
81
- if (episodes.length > MAX_EPISODES)
103
+ if (episodes.length > MAX_EPISODES) {
82
104
  episodes.length = MAX_EPISODES;
105
+ }
83
106
  saveEpisodes(episodes);
84
107
  }
108
+ /** @requires LIMIT @produces EPISODE_LIST */
85
109
  function getRecentEpisodes(limit = 10) {
86
110
  return loadEpisodes().slice(0, limit);
87
111
  }
@@ -89,15 +113,31 @@ function getSuccessfulEpisodes(limit = 10) {
89
113
  return loadEpisodes().filter(e => e.success).slice(0, limit);
90
114
  }
91
115
  const SEMANTIC_FILE = path.join(MEMORY_DIR, "semantic.json");
116
+ const SEMANTIC_TTL_MS = 30 * 24 * 60 * 60 * 1000; // 30 天
92
117
  function loadSemantic() {
93
118
  ensureDir(MEMORY_DIR);
94
119
  if (!fs.existsSync(SEMANTIC_FILE))
95
120
  return [];
96
- return JSON.parse(fs.readFileSync(SEMANTIC_FILE, "utf-8"));
121
+ const all = JSON.parse(fs.readFileSync(SEMANTIC_FILE, "utf-8"));
122
+ const cutoff = Date.now() - SEMANTIC_TTL_MS;
123
+ const fresh = all.filter(t => new Date(t.lastUsedAt).getTime() > cutoff);
124
+ if (fresh.length < all.length) {
125
+ console.error(`[记忆衰减-读取] 清理了 ${all.length - fresh.length} 个过期语义模板`);
126
+ fs.writeFileSync(SEMANTIC_FILE, JSON.stringify(fresh, null, 2));
127
+ }
128
+ return fresh;
97
129
  }
98
130
  function saveSemantic(templates) {
99
- ensureDir(MEMORY_DIR);
100
- fs.writeFileSync(SEMANTIC_FILE, JSON.stringify(templates, null, 2));
131
+ (0, file_lock_1.withLock)("semantic.json", () => {
132
+ ensureDir(MEMORY_DIR);
133
+ // TTL 衰减:清理超过 30 天未使用的语义模板
134
+ const cutoff = Date.now() - SEMANTIC_TTL_MS;
135
+ const fresh = templates.filter(t => new Date(t.lastUsedAt).getTime() > cutoff);
136
+ if (fresh.length !== templates.length) {
137
+ console.error(`[记忆衰减] 清理了 ${templates.length - fresh.length} 个过期语义模板`);
138
+ }
139
+ fs.writeFileSync(SEMANTIC_FILE, JSON.stringify(fresh, null, 2));
140
+ });
101
141
  }
102
142
  function consolidateSemantic(minOccurrences = 3) {
103
143
  const episodes = getSuccessfulEpisodes(MAX_EPISODES);
@@ -132,8 +172,9 @@ function consolidateSemantic(minOccurrences = 3) {
132
172
  }
133
173
  }
134
174
  saveSemantic(templates);
135
- console.log(`[语义记忆] 巩固完成,模板数量: ${templates.length}`);
175
+ console.error(`[语义记忆] 巩固完成,模板数量: ${templates.length}`);
136
176
  }
177
+ /** @requires INTENT @produces TEMPLATE */
137
178
  function findSemanticTemplate(intent) {
138
179
  const templates = loadSemantic();
139
180
  if (templates.length === 0)
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.main = main;
4
+ // @progmune-generated session=sess_1780345721473_u5ik3 timestamp=2026-06-01T20:28:42.736Z ruleHash=9dec68bc2995e92a
5
+ // Generated with IR constraint: 387 functions, 17 protocol rules
6
+ const execute_1 = require("./execute");
7
+ function main() {
8
+ const metrics = (0, execute_1.getExecutionMetrics)();
9
+ return metrics;
10
+ }
11
+ main();