progmune-runtime 2.1.4 → 2.1.6
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 +453 -79
- package/WHITEPAPER.md +213 -91
- package/dist/extract-ir.js +6 -0
- package/dist/failure-collector.js +2 -0
- package/dist/failure-corpus.js +4 -0
- package/dist/feedback.js +56 -2
- package/dist/health-utils.js +1 -0
- package/dist/ledger-registry.js +2 -0
- package/dist/memory-layer.js +55 -11
- package/dist/planner.js +12 -1
- package/dist/session-utils.js +1 -0
- package/dist/stdlib.js +3 -0
- package/dist/strategy-planner.js +125 -20
- package/package.json +1 -1
package/WHITEPAPER.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
### Program Immunology for Generative Code
|
|
6
6
|
|
|
7
|
-
### 技术白皮书
|
|
7
|
+
### 技术白皮书 v2.1.4
|
|
8
8
|
|
|
9
9
|
开源地址:https://github.com/shenlian19831109/progmune-runtime
|
|
10
10
|
npm install progmune-runtime
|
|
@@ -74,11 +74,11 @@ Progmune Runtime 提出了一种新的范式:程序免疫学——确保 AI
|
|
|
74
74
|
|
|
75
75
|
#### 2.3 类比的价值与边界
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
这个类比的价值在于提供了一个清晰的、可扩展的思维框架:解释为什么静态验证器不够用,以及为什么系统需要学习、记忆和进化。然而,也必须明确其边界:程序免疫系统处理的是形式化的、确定性的程序状态,而非复杂的复杂生物化学信号。其学习是基于规则挖掘和模式匹配,而非生物神经元的突触可塑性。
|
|
78
78
|
|
|
79
|
-
### 3.
|
|
79
|
+
### 3. 技术架构与 v2.1.4 核心增强
|
|
80
80
|
|
|
81
|
-
Progmune Runtime 的架构由六个核心层组成,每一层对应特定的验证或学习职责。
|
|
81
|
+
Progmune Runtime 的架构由六个核心层组成,每一层对应特定的验证或学习职责。v2.1.4 版本在此基础上进行了关键增强,以提升系统的智能性、鲁棒性和可扩展性。
|
|
82
82
|
|
|
83
83
|
#### 3.1 IR(程序真相层)——自我模型
|
|
84
84
|
|
|
@@ -129,6 +129,10 @@ SESSION_ACTIVE(会话已激活)
|
|
|
129
129
|
|
|
130
130
|
每个函数声明了 `pre_states`(前置状态)、`post_states`(后置状态)和可选的 `invalidate`(失效状态)规则。SSG 验证器在处理动作树时模拟状态转移,拒绝任何前置状态与当前活跃状态无交集的调用——即使所有其他 SVL 级别均通过。这将验证从静态正确性提升为行为合法性。
|
|
131
131
|
|
|
132
|
+
**v2.1.4 增强:BFS 协议修复**
|
|
133
|
+
|
|
134
|
+
SSG 验证器现在使用广度优先搜索(BFS)寻找多步修复路径,能够自动补全复杂的协议缺失(如 `INIT` -> `EMAIL_OK` -> `PWD_HASHED`),显著提升了系统在面对不完整或模糊意图时的自适应能力。
|
|
135
|
+
|
|
132
136
|
#### 3.5 Immune Memory & Failure Corpus——免疫记忆层
|
|
133
137
|
|
|
134
138
|
**三层记忆架构**
|
|
@@ -141,6 +145,10 @@ SESSION_ACTIVE(会话已激活)
|
|
|
141
145
|
|
|
142
146
|
每次约束违规都被记录:包含意图、IR 摘要、违反的 SVL 级别、错误详情和 SSG 状态。这构成了一项独特资产:一个结构化、带标签的 AI 程序失败数据库。随时间积累,高频失败模式可被挖掘,自动生成候选的协议约束或 SSG 转换规则。
|
|
143
147
|
|
|
148
|
+
**v2.1.4 增强:抗体注册表 (Antibody Registry) 与信用循环 (Credit Loops)**
|
|
149
|
+
|
|
150
|
+
系统自动从 `Failure Corpus` 中提取修复模式,生成 ACL-1~4 置信度分级的“抗体”。高置信度(ACL-4)的抗体可触发“免疫快跑”,绕过 LLM 直接应用验证过的修复路径。同时,引入了**信用循环**机制,根据函数在历史上的成功率动态调整其权重,优化能力链的选择,使得系统在模糊意图下能够更智能地进行规划。
|
|
151
|
+
|
|
144
152
|
#### 3.6 Code Emitter——程序落地层
|
|
145
153
|
|
|
146
154
|
将验证通过的动作树确定性地翻译为可执行的 Python 或 TypeScript 代码,处理导入解析、变量作用域、对象字面量生成以及嵌套控制结构的正确缩进。
|
|
@@ -155,60 +163,201 @@ SVL 是 AI 生成代码正确性的形式化分类法,为系统提供分层、
|
|
|
155
163
|
| SVL-2 | 类型有效性 | 参数数量和类型与声明的签名相匹配 | 无类型不匹配错误 |
|
|
156
164
|
| SVL-3 | 数据流正确性 | 变量在使用前已声明;无循环引用或未初始化访问 | 无 NameError / UnboundLocalError |
|
|
157
165
|
| SVL-4 | 协议合法性 | 函数调用序列符合声明的前/后状态转换规则 | 无非法状态跳转(如认证前签发令牌) |
|
|
158
|
-
| SVL-5(未来) | 语义意图正确性 | 生成代码忠实实现预期业务逻辑 |
|
|
166
|
+
| SVL-5(未来) | 语义意图正确性 | 生成代码忠实实现预期业务逻辑 | 远期目标;当前版本通过 SVL-1~4 间接保障 |
|
|
167
|
+
|
|
168
|
+
Progmune Runtime v2.1.4 完整保证 SVL-1 至 SVL-3,SVL-4 作为可选协议约束系统实现。SVL-5 为开放性研究方向。
|
|
169
|
+
|
|
170
|
+
### 5. 技术路线与未来展望
|
|
171
|
+
|
|
172
|
+
Progmune Runtime 的技术路线图致力于构建一个更智能、更自适应的神经符号编译器基础设施。
|
|
173
|
+
|
|
174
|
+
* **全球免疫网络**:跨安装实例的脱敏 Failure Corpus 联邦汇聚,实现群体免疫级防御,共享全球范围内的失败模式和修复策略。
|
|
175
|
+
* **语义失败基准库**(Semantic Failure Benchmark):世界上首个 AI 生成代码可靠性的公开基准,由汇聚的、匿名的失败模式构建,为研究和开发提供标准化的评估工具。
|
|
176
|
+
* **企业语义防火墙**:集成到 CI/CD 管道中,作为 AI 生成拉取请求的合并前门禁,确保所有进入代码库的代码都经过严格的免疫检查。
|
|
177
|
+
* **增强的语义拓扑 (Semantic Topology)**:持续优化语义匹配机制,提升在复杂和模糊意图下能力链的发现和构建效率,使得系统能够更准确地理解和响应开发者意图。
|
|
178
|
+
* **语义快照引擎 (Semantic Snapshot Engine)**:进一步完善 IR 状态捕获和 `diff` 功能,为调试和版本控制提供更强大的支持。
|
|
179
|
+
|
|
180
|
+
### 6. 结论
|
|
181
|
+
|
|
182
|
+
Progmune Runtime v2.1.4 证明了:通过颠倒 LLM 与程序真相之间的关系——将 IR 确立为第一性原理,并使 LLM 成为受约束的启发式提议器——我们可以实现具有强语义保证的可验证代码合成。
|
|
183
|
+
|
|
184
|
+
分层的 SVL 分类法、SSG 协议引擎、持续积累的 Failure Corpus、三层记忆架构以及 v2.1.4 引入的各项增强,共同形成了一种全新的编程基础设施:一个会学习、会记忆、会防御的神经符号编译器运行时。
|
|
185
|
+
|
|
186
|
+
我们将此称为程序免疫学(Program Immunology)。
|
|
187
|
+
|
|
188
|
+
该系统以开源形式提供:https://github.com/shenlian19831109/progmune-runtime,也可通过 `npm install progmune-runtime` 安装使用。
|
|
189
|
+
|
|
190
|
+
## ENGLISH VERSION
|
|
191
|
+
|
|
192
|
+
### Abstract
|
|
193
|
+
|
|
194
|
+
Progmune Runtime introduces Program Immunology—a new paradigm for ensuring the safety and reliability of AI-generated code.
|
|
195
|
+
|
|
196
|
+
Inspired by the layered defense mechanisms of the biological immune system, Progmune establishes a constraint-guided program synthesis runtime that enforces semantic validity at multiple levels: from symbol existence and type compatibility to dataflow correctness and protocol legality. The system demotes large language models from unverified code generators to constrained heuristic proposers, operating within a closed world defined by the program's actual structure (Intermediate Representation).
|
|
197
|
+
|
|
198
|
+
We introduce Semantic Validity Levels (SVL) as a formal taxonomy of AI-generated code correctness, and demonstrate a working Semantic State Graph (SSG) that intercepts illegal state transitions. Progmune represents a step toward neural-symbolic compiler infrastructure where code generation is governed not by statistical likelihood, but by verifiable truth.
|
|
199
|
+
|
|
200
|
+
### 1. Problem Statement
|
|
201
|
+
|
|
202
|
+
#### 1.1 The Open-World Fallacy in AI Code Generation
|
|
203
|
+
|
|
204
|
+
Large language models (LLMs) operate under an implicit open-world assumption when generating code: any function, library, or API pattern encountered during training is presumed available in the current context. This assumption yields four distinct classes of errors:
|
|
205
|
+
|
|
206
|
+
* **Symbol Hallucination (SVL-1)**:Invoking functions or variables that do not exist in the target project
|
|
207
|
+
* **Type Drift (SVL-2)**:Mismatched parameter counts or incompatible types with the actual function signature
|
|
208
|
+
* **Dataflow Contamination (SVL-3)**:Using uninitialized variables, creating circular references, or introducing dead code paths
|
|
209
|
+
* **Protocol Violation (SVL-4)**:Violating the required ordering of business steps—for example, issuing a JWT token before authenticating the user
|
|
210
|
+
|
|
211
|
+
These errors do not arise from reasoning failures. They arise because the model lacks deterministic access to the ground truth of the program.
|
|
212
|
+
|
|
213
|
+
#### 1.2 Limitations of Current Mitigations
|
|
214
|
+
|
|
215
|
+
Existing strategies address these errors reactively:
|
|
159
216
|
|
|
160
|
-
|
|
217
|
+
* **Post-hoc validation**:Linters, test suites, manual review—detects errors after generation but cannot prevent them at the source
|
|
218
|
+
* **Retrieval-Augmented Generation (RAG)**:Injects project context into prompts, reducing but not eliminating hallucination; the model remains the sole arbiter of correctness
|
|
219
|
+
* **Iterative prompt engineering**:Guides model behavior through carefully designed instructions, yet offers no formal guarantee of compliance
|
|
220
|
+
|
|
221
|
+
All three strategies place the LLM at the center of the system and attempt to correct its output externally. They lack first-principle constraint mechanisms.
|
|
222
|
+
|
|
223
|
+
#### 1.3 Core Proposition: AI-Generated Programs Require an Immune System
|
|
224
|
+
|
|
225
|
+
We propose a paradigm shift: Program Immunology. AI-generated code must not be allowed to enter a codebase without passing through an immune layer—a verifiable, memory-equipped runtime that recognizes, remembers, and defends against recurrent error patterns.
|
|
226
|
+
|
|
227
|
+
This immune layer comprises three interdependent capabilities:
|
|
228
|
+
|
|
229
|
+
* **Innate Immunity**:Rapid, pattern-based rejection of symbol, type, and dataflow violations—the system's built-in defenses
|
|
230
|
+
* **Adaptive Immunity**:Learning from past failures (the Failure Corpus) to generate specific, targeted defenses such as protocol constraints, proactively preventing future errors
|
|
231
|
+
* **Immune Memory**:Structuring both successful and failed generation patterns into persistent knowledge, enabling continuous improvement with use
|
|
232
|
+
|
|
233
|
+
### 2. Biological Foundations and Analogy
|
|
234
|
+
|
|
235
|
+
#### 2.1 The Three-Layer Architecture of the Biological Immune System
|
|
236
|
+
|
|
237
|
+
* **Physical Barriers**:Skin, mucous membranes. Non-specific, preemptive first line of defense
|
|
238
|
+
* **Natural Immunity**:Macrophages, dendritic cells. Pattern recognition receptors (PRRs) rapidly identify pathogen-associated molecular patterns (PAMPs). Rapid response, but not precise enough
|
|
239
|
+
* **Acquired Immunity**:T cells, B cells. Generate highly specific receptors through gene rearrangement to recognize specific antigens. After the first infection, immune memory is generated, and a faster and stronger secondary response can be produced upon re-exposure
|
|
161
240
|
|
|
162
|
-
|
|
241
|
+
#### 2.2 Mapping to Program Immunology
|
|
163
242
|
|
|
164
|
-
|
|
243
|
+
| Biological Immune System | Program Immunity (Progmune) | Mapping Description |
|
|
244
|
+
|---|---|---|
|
|
245
|
+
| **Physical Barriers** | Sandboxes, CI/CD Gates, Access Control | Foundational engineering infrastructure to prevent unverified code from entering production |
|
|
246
|
+
| **Innate Immunity** | Constraint Engine (IR + SVL-1 to SVL-3) | Rapidly and automatically identifies and rejects hallucinated calls, type errors, etc. - the system's built-in defense capability |
|
|
247
|
+
| **Antigen Presentation** | Failure Corpus Recording | After an error action sequence is captured, its error type, state context, and other "antigenic features" are fully recorded |
|
|
248
|
+
| **Adaptive Immunity** | Semantic State Graph (SSG) | Learns from the failure corpus to generate specific protocol rules ("antibodies") to precisely prevent illegal state transitions |
|
|
249
|
+
| **Immune Memory** | Three-Layer Memory Architecture | Episodic memory and semantic memory together form the system's immune memory, allowing for rapid response without LLM in similar scenarios |
|
|
165
250
|
|
|
166
|
-
|
|
251
|
+
#### 2.3 Value and Boundaries of the Analogy
|
|
167
252
|
|
|
168
|
-
|
|
253
|
+
The value of this analogy lies in providing a clear, extensible mental framework: explaining why static verifiers are insufficient, and why the system needs to learn, remember, and evolve. However, its boundaries must also be clear: the program immune system deals with formalized, deterministic program states, not complex biochemical signals. Its learning is based on rule mining and pattern matching, not synaptic plasticity of biological neurons.
|
|
169
254
|
|
|
170
|
-
|
|
255
|
+
### 3. Technical Architecture and v2.1.4 Core Enhancements
|
|
171
256
|
|
|
172
|
-
|
|
257
|
+
The architecture of Progmune Runtime consists of six core layers, each corresponding to specific verification or learning responsibilities. Version 2.1.4 introduces key enhancements to improve the system's intelligence, robustness, and scalability.
|
|
173
258
|
|
|
174
|
-
|
|
259
|
+
#### 3.1 IR (Program Truth Layer) - Self-Model
|
|
260
|
+
|
|
261
|
+
The Intermediate Representation (IR) is the system's sole source of truth, statically extracted from source files, including:
|
|
262
|
+
|
|
263
|
+
* **SymbolTable**: All defined functions, classes, variables, and their locations
|
|
264
|
+
* **TypeGraph**: Parameter types, return types, and type aliases
|
|
265
|
+
* **CallGraph**: Call relationships between functions
|
|
266
|
+
* **Protocol Annotations** (optional): Pre-states, post-states, and invalidation rules for protocol-aware synthesis
|
|
267
|
+
|
|
268
|
+
This is the basis for distinguishing self from non-self - the system only allows calling components explicitly defined in the IR.
|
|
269
|
+
|
|
270
|
+
#### 3.2 Action Runtime - Deterministic Synthesis Boundary
|
|
271
|
+
|
|
272
|
+
LLMs no longer generate raw code or JSON strings, but instead call a set of deterministic APIs:
|
|
175
273
|
|
|
176
274
|
```
|
|
177
|
-
|
|
275
|
+
call(func, ...args) // Call function
|
|
276
|
+
callAssign(func, assignTo, ...) // Call and bind result
|
|
277
|
+
ifElse(condition, thenFn, elseFn) // Conditional branch
|
|
278
|
+
assign(target, value) // Variable assignment
|
|
279
|
+
output(value) // Return value
|
|
280
|
+
```
|
|
178
281
|
|
|
179
|
-
|
|
282
|
+
These calls are executed in a sandboxed JavaScript context, and the runtime captures all calls as a structured Action Tree, eliminating injection vulnerabilities and formatting errors at the source.
|
|
283
|
+
|
|
284
|
+
#### 3.3 Constraint Engine - Innate Immune Layer
|
|
285
|
+
|
|
286
|
+
This layer performs rapid, rule-based validation of the Action Tree based on the IR:
|
|
287
|
+
|
|
288
|
+
* **SVL-1** (Symbol Existence): Every called function exists in the project
|
|
289
|
+
* **SVL-2** (Type Validity): Parameter count and types match the declared signature
|
|
290
|
+
* **SVL-3** (Dataflow Correctness): Variables are declared before use; no self-referential assignments
|
|
291
|
+
|
|
292
|
+
#### 3.4 Semantic State Graph (SSG) - Adaptive Immune Layer
|
|
180
293
|
|
|
181
|
-
|
|
294
|
+
SSG models the valid states of system resources and their allowed transitions. Taking the authentication protocol as an example:
|
|
182
295
|
|
|
183
|
-
|
|
184
|
-
|
|
296
|
+
```
|
|
297
|
+
UNAUTHENTICATED
|
|
298
|
+
↓ verify_password
|
|
299
|
+
AUTHENTICATED
|
|
300
|
+
↓ generate_jwt
|
|
301
|
+
TOKEN_ISSUED
|
|
302
|
+
↓ create_session
|
|
303
|
+
SESSION_ACTIVE
|
|
185
304
|
```
|
|
186
305
|
|
|
187
|
-
|
|
306
|
+
Each function declares `pre_states`, `post_states`, and optional `invalidate` rules. The SSG validator simulates state transitions when processing the Action Tree, rejecting any calls where the pre-state has no intersection with the current active state - even if all other SVL levels pass. This elevates verification from static correctness to behavioral legality.
|
|
188
307
|
|
|
189
|
-
|
|
308
|
+
**v2.1.4 Enhancement: BFS Protocol Repair**
|
|
190
309
|
|
|
191
|
-
|
|
310
|
+
The SSG validator now uses Breadth-First Search (BFS) to find multi-step repair paths, capable of automatically completing complex missing protocols (e.g., `INIT` -> `EMAIL_OK` -> `PWD_HASHED`), significantly enhancing the system's adaptability when faced with incomplete or ambiguous intentions.
|
|
192
311
|
|
|
193
|
-
|
|
194
|
-
* 算法最优性或复杂度
|
|
195
|
-
* 对所有安全漏洞的免疫(例如注入攻击、权限绕过)
|
|
196
|
-
* 生成代码单元之外的整个应用程序功能正确性
|
|
312
|
+
#### 3.5 Immune Memory & Failure Corpus - Immune Memory Layer
|
|
197
313
|
|
|
198
|
-
|
|
314
|
+
**Three-Layer Memory Architecture**
|
|
315
|
+
|
|
316
|
+
* **Working Memory**: Variable bindings and user intent for the current session (cleared per session)
|
|
317
|
+
* **Episodic Memory**: Recent N successful/failed action sequences, with timestamps and result labels (pruned periodically)
|
|
318
|
+
* **Semantic Memory**: Path templates and protocol rules distilled from frequently successful patterns (consolidated offline)
|
|
199
319
|
|
|
200
|
-
|
|
320
|
+
**Failure Corpus**
|
|
201
321
|
|
|
202
|
-
|
|
203
|
-
* **语义失败基准库**(Semantic Failure Benchmark):世界上首个 AI 生成代码可靠性的公开基准,由汇聚的、匿名的失败模式构建
|
|
204
|
-
* **企业语义防火墙**:集成到 CI/CD 管道中,作为 AI 生成拉取请求的合并前门禁
|
|
205
|
-
* **确定性验证器**(Rust/WASM):在 IDE、CI 和生产环境之间实现位级一致的验证,确保同一段 Action Tree 在任何环境中得到完全一致的合法性判断
|
|
322
|
+
Each constraint violation is recorded: including intent, IR summary, violated SVL level, error details, and SSG state. This constitutes a unique asset: a structured, labeled database of AI program failures. Over time, high-frequency failure patterns can be mined to automatically generate candidate protocol constraints or SSG transition rules.
|
|
206
323
|
|
|
207
|
-
|
|
324
|
+
**v2.1.4 Enhancement: Antibody Registry and Credit Loops**
|
|
208
325
|
|
|
209
|
-
|
|
326
|
+
The system automatically extracts repair patterns from the `Failure Corpus` to generate "antibodies" with ACL-1~4 confidence ratings. High-confidence (ACL-4) antibodies can trigger "immune fast-runs," bypassing the LLM to directly apply validated repair paths. Concurrently, the **Credit Loops** mechanism dynamically adjusts function weights based on historical success rates, optimizing capability chain selection and enabling the system to plan more intelligently under ambiguous intentions.
|
|
210
327
|
|
|
211
|
-
|
|
328
|
+
#### 3.6 Code Emitter - Program Landing Layer
|
|
329
|
+
|
|
330
|
+
Deterministically translates the validated Action Tree into executable Python or TypeScript code, handling import resolution, variable scoping, object literal generation, and correct indentation for nested control structures.
|
|
331
|
+
|
|
332
|
+
### 4. 语义有效性级别(SVL)
|
|
333
|
+
|
|
334
|
+
SVL 是 AI 生成代码正确性的形式化分类法,为系统提供分层、可量化的验证保证:
|
|
335
|
+
|
|
336
|
+
| 级别 | 名称 | 描述 | 保证内容 |
|
|
337
|
+
|---|---|---|---|
|
|
338
|
+
| SVL-1 | 符号存在性 | 每个被调用的函数、变量和导入在项目中均实际存在 | 无幻觉 API 调用 |
|
|
339
|
+
| SVL-2 | 类型有效性 | 参数数量和类型与声明的签名相匹配 | 无类型不匹配错误 |
|
|
340
|
+
| SVL-3 | 数据流正确性 | 变量在使用前已声明;无循环引用或未初始化访问 | 无 NameError / UnboundLocalError |
|
|
341
|
+
| SVL-4 | 协议合法性 | 函数调用序列符合声明的前/后状态转换规则 | 无非法状态跳转(如认证前签发令牌) |
|
|
342
|
+
| SVL-5(未来) | 语义意图正确性 | 生成代码忠实实现预期业务逻辑 | 远期目标;当前版本通过 SVL-1~4 间接保障 |
|
|
343
|
+
|
|
344
|
+
Progmune Runtime v2.1.4 完整保证 SVL-1 至 SVL-3,SVL-4 作为可选协议约束系统实现。SVL-5 为开放性研究方向。
|
|
345
|
+
|
|
346
|
+
### 5. 技术路线与未来展望
|
|
347
|
+
|
|
348
|
+
Progmune Runtime 的技术路线图致力于构建一个更智能、更自适应的神经符号编译器基础设施。
|
|
349
|
+
|
|
350
|
+
* **全球免疫网络**:跨安装实例的脱敏 Failure Corpus 联邦汇聚,实现群体免疫级防御,共享全球范围内的失败模式和修复策略。
|
|
351
|
+
* **语义失败基准库**(Semantic Failure Benchmark):世界上首个 AI 生成代码可靠性的公开基准,由汇聚的、匿名的失败模式构建,为研究和开发提供标准化的评估工具。
|
|
352
|
+
* **企业语义防火墙**:集成到 CI/CD 管道中,作为 AI 生成拉取请求的合并前门禁,确保所有进入代码库的代码都经过严格的免疫检查。
|
|
353
|
+
* **增强的语义拓扑 (Semantic Topology)**:持续优化语义匹配机制,提升在复杂和模糊意图下能力链的发现和构建效率,使得系统能够更准确地理解和响应开发者意图。
|
|
354
|
+
* **语义快照引擎 (Semantic Snapshot Engine)**:进一步完善 IR 状态捕获和 `diff` 功能,为调试和版本控制提供更强大的支持。
|
|
355
|
+
|
|
356
|
+
### 6. 结论
|
|
357
|
+
|
|
358
|
+
Progmune Runtime v2.1.4 证明了:通过颠倒 LLM 与程序真相之间的关系——将 IR 确立为第一性原理,并使 LLM 成为受约束的启发式提议器——我们可以实现具有强语义保证的可验证代码合成。
|
|
359
|
+
|
|
360
|
+
分层的 SVL 分类法、SSG 协议引擎、持续积累的 Failure Corpus、三层记忆架构以及 v2.1.4 引入的各项增强,共同形成了一种全新的编程基础设施:一个会学习、会记忆、会防御的神经符号编译器运行时。
|
|
212
361
|
|
|
213
362
|
我们将此称为程序免疫学(Program Immunology)。
|
|
214
363
|
|
|
@@ -245,7 +394,7 @@ Existing strategies address these errors reactively:
|
|
|
245
394
|
* **Retrieval-Augmented Generation (RAG)**:Injects project context into prompts, reducing but not eliminating hallucination; the model remains the sole arbiter of correctness
|
|
246
395
|
* **Iterative prompt engineering**:Guides model behavior through carefully designed instructions, yet offers no formal guarantee of compliance
|
|
247
396
|
|
|
248
|
-
All three strategies place the LLM at the center of the system and attempt to correct its output
|
|
397
|
+
All three strategies place the LLM at the center of the system and attempt to correct its output externally. They lack first-principle constraint mechanisms.
|
|
249
398
|
|
|
250
399
|
#### 1.3 Core Proposition: AI-Generated Programs Require an Immune System
|
|
251
400
|
|
|
@@ -279,9 +428,9 @@ This immune layer comprises three interdependent capabilities:
|
|
|
279
428
|
|
|
280
429
|
The value of this analogy lies in providing a clear, extensible mental framework: explaining why static verifiers are insufficient, and why the system needs to learn, remember, and evolve. However, its boundaries must also be clear: the program immune system deals with formalized, deterministic program states, not complex biochemical signals. Its learning is based on rule mining and pattern matching, not synaptic plasticity of biological neurons.
|
|
281
430
|
|
|
282
|
-
### 3. Technical Architecture
|
|
431
|
+
### 3. Technical Architecture and v2.1.4 Core Enhancements
|
|
283
432
|
|
|
284
|
-
The architecture of Progmune Runtime consists of six core layers, each corresponding to specific verification or learning responsibilities.
|
|
433
|
+
The architecture of Progmune Runtime consists of six core layers, each corresponding to specific verification or learning responsibilities. Version 2.1.4 introduces key enhancements to improve the system's intelligence, robustness, and scalability.
|
|
285
434
|
|
|
286
435
|
#### 3.1 IR (Program Truth Layer) - Self-Model
|
|
287
436
|
|
|
@@ -332,6 +481,10 @@ SESSION_ACTIVE
|
|
|
332
481
|
|
|
333
482
|
Each function declares `pre_states`, `post_states`, and optional `invalidate` rules. The SSG validator simulates state transitions when processing the Action Tree, rejecting any calls where the pre-state has no intersection with the current active state - even if all other SVL levels pass. This elevates verification from static correctness to behavioral legality.
|
|
334
483
|
|
|
484
|
+
**v2.1.4 Enhancement: BFS Protocol Repair**
|
|
485
|
+
|
|
486
|
+
The SSG validator now uses Breadth-First Search (BFS) to find multi-step repair paths, capable of automatically completing complex missing protocols (e.g., `INIT` -> `EMAIL_OK` -> `PWD_HASHED`), significantly enhancing the system's adaptability when faced with incomplete or ambiguous intentions.
|
|
487
|
+
|
|
335
488
|
#### 3.5 Immune Memory & Failure Corpus - Immune Memory Layer
|
|
336
489
|
|
|
337
490
|
**Three-Layer Memory Architecture**
|
|
@@ -344,6 +497,10 @@ Each function declares `pre_states`, `post_states`, and optional `invalidate` ru
|
|
|
344
497
|
|
|
345
498
|
Each constraint violation is recorded: including intent, IR summary, violated SVL level, error details, and SSG state. This constitutes a unique asset: a structured, labeled database of AI program failures. Over time, high-frequency failure patterns can be mined to automatically generate candidate protocol constraints or SSG transition rules.
|
|
346
499
|
|
|
500
|
+
**v2.1.4 Enhancement: Antibody Registry and Credit Loops**
|
|
501
|
+
|
|
502
|
+
The system automatically extracts repair patterns from the `Failure Corpus` to generate "antibodies" with ACL-1~4 confidence ratings. High-confidence (ACL-4) antibodies can trigger "immune fast-runs," bypassing the LLM to directly apply validated repair paths. Concurrently, the **Credit Loops** mechanism dynamically adjusts function weights based on historical success rates, optimizing capability chain selection and enabling the system to plan more intelligently under ambiguous intentions.
|
|
503
|
+
|
|
347
504
|
#### 3.6 Code Emitter - Program Landing Layer
|
|
348
505
|
|
|
349
506
|
Deterministically translates the validated Action Tree into executable Python or TypeScript code, handling import resolution, variable scoping, object literal generation, and correct indentation for nested control structures.
|
|
@@ -352,67 +509,32 @@ Deterministically translates the validated Action Tree into executable Python or
|
|
|
352
509
|
|
|
353
510
|
SVL is a formal taxonomy for the correctness of AI-generated code, providing layered, quantifiable verification guarantees for the system:
|
|
354
511
|
|
|
355
|
-
| Level | Name | Description | Guarantee
|
|
512
|
+
| Level | Name | Description | Progmune's Guarantee |
|
|
356
513
|
|---|---|---|---|
|
|
357
|
-
| SVL-1 |
|
|
358
|
-
| SVL-2 | Type Validity | Parameter count and types
|
|
359
|
-
| SVL-3 | Dataflow Correctness | Variables are declared before use; no circular references or uninitialized access | No NameError / UnboundLocalError |
|
|
360
|
-
| SVL-4 | Protocol Legality | Function call
|
|
361
|
-
| SVL-5 (Future) | Semantic Intent Correctness | Generated code faithfully implements the intended business logic | Long-term goal;
|
|
362
|
-
|
|
363
|
-
Progmune Runtime v1.0 fully guarantees SVL-1 to SVL-3, with SVL-4 implemented as an optional protocol constraint system. SVL-5 is an open research direction.
|
|
364
|
-
|
|
365
|
-
### 5. Experimental Evaluation
|
|
366
|
-
|
|
367
|
-
#### 5.1 Stress Test
|
|
368
|
-
|
|
369
|
-
Evaluated on synthetic Python projects containing 3 to 338 functions. The LLM Planner achieved 100% success rate across all scales, with an average synthesis time of approximately 6 seconds and 1-2 LLM calls per intent. Performance scaled linearly with project size, validating the scalability of the IR truncation and constraint verification methods.
|
|
370
|
-
|
|
371
|
-
#### 5.2 Semantic Blocking Test
|
|
372
|
-
|
|
373
|
-
Built a test suite of 10 semantic intent cases, covering login, registration, cache query, bulk email, role check, session creation, data export, account locking, token refresh, and user logout scenarios. The system generated fully correct, runnable Python code in 7-8 cases, and the remaining cases were correctly intercepted by the constraint engine, demonstrating an 80–100% blocking rate for semantic errors.
|
|
374
|
-
|
|
375
|
-
#### 5.3 SSG Protocol Interception
|
|
376
|
-
|
|
377
|
-
Constructed an intent: create a session with a token (without specifying authentication). The LLM repeatedly attempted to call `generate_jwt` before `verify_password`. The SSG validator intercepted all three attempts and provided a diagnosis:
|
|
378
|
-
|
|
379
|
-
```
|
|
380
|
-
[PROGMUNE] L4 PROTOCOL VIOLATION
|
|
381
|
-
|
|
382
|
-
Function: generate_jwt
|
|
383
|
-
|
|
384
|
-
Reason: requires AUTHENTICATED state
|
|
385
|
-
|
|
386
|
-
Current state: UNAUTHENTICATED
|
|
387
|
-
Expected transition: verify_password → AUTHENTICATED
|
|
388
|
-
```
|
|
514
|
+
| **SVL-1** | Symbolic Existence | Every called function, variable, and import actually exists in the project | No hallucinated API calls |
|
|
515
|
+
| **SVL-2** | Type Validity | Parameter count and types match the declared signature | No type mismatch errors |
|
|
516
|
+
| **SVL-3** | Dataflow Correctness | Variables are declared before use; no circular references or uninitialized access | No NameError / UnboundLocalError |
|
|
517
|
+
| **SVL-4** | Protocol Legality | Function call sequences conform to declared pre/post-state transition rules | No illegal state jumps (e.g., issuing token before authentication) |
|
|
518
|
+
| **SVL-5 (Future)** | Semantic Intent Correctness | Generated code faithfully implements the intended business logic | Long-term goal; indirectly guaranteed by SVL-1~4 in current version |
|
|
389
519
|
|
|
390
|
-
|
|
520
|
+
Progmune Runtime v2.1.4 fully guarantees SVL-1 to SVL-3, with SVL-4 implemented as an optional protocol constraint system. SVL-5 is an open research direction。
|
|
391
521
|
|
|
392
|
-
###
|
|
522
|
+
### 5. Technical Roadmap and Future Outlook
|
|
393
523
|
|
|
394
|
-
Progmune Runtime
|
|
524
|
+
Progmune Runtime's roadmap is dedicated to building a smarter, more adaptive neural-symbolic compiler infrastructure.
|
|
395
525
|
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
526
|
+
* **Global Immune Network**: Federated aggregation of anonymized Failure Corpus across installed instances to achieve collective immunity-level defense, sharing global failure patterns and repair strategies.
|
|
527
|
+
* **Semantic Failure Benchmark**: The world's first public benchmark for AI-generated code reliability, built from aggregated, anonymized failure patterns, providing standardized evaluation tools for research and development.
|
|
528
|
+
* **Enterprise Semantic Firewall**: Integrated into CI/CD pipelines as a pre-merge gate for AI-generated pull requests, ensuring all code entering the codebase undergoes rigorous immune checks.
|
|
529
|
+
* **Enhanced Semantic Topology**: Continuously optimizes semantic matching mechanisms to improve the efficiency of capability chain discovery and construction under complex and ambiguous intentions, enabling the system to understand and respond to developer intentions more accurately.
|
|
530
|
+
* **Semantic Snapshot Engine**: Further refines IR state capture and `diff` functionality, providing more powerful support for debugging and version control.
|
|
400
531
|
|
|
401
|
-
|
|
532
|
+
### 6. Conclusion
|
|
402
533
|
|
|
403
|
-
|
|
534
|
+
Progmune Runtime v2.1.4 demonstrates that by inverting the relationship between LLMs and program truth—establishing IR as the first principle and making LLMs constrained heuristic proposers—we can achieve verifiable code synthesis with strong semantic guarantees.
|
|
404
535
|
|
|
405
|
-
|
|
406
|
-
* **Semantic Failure Benchmark**: The world's first public benchmark for AI-generated code reliability, built from aggregated, anonymized failure patterns
|
|
407
|
-
* **Enterprise Semantic Firewall**: Integrated into CI/CD pipelines as a pre-merge gate for AI-generated pull requests
|
|
408
|
-
* **Deterministic Verifier** (Rust/WASM): Achieves bit-level consistent verification between IDE, CI, and production environments, ensuring that the same Action Tree receives completely consistent legality judgments in any environment
|
|
536
|
+
分层的 SVL 分类法、SSG 协议引擎、持续积累的 Failure Corpus、三层记忆架构以及 v2.1.4 引入的各项增强,共同形成了一种全新的编程基础设施:一个会学习、会记忆、会防御的神经符号编译器运行时。
|
|
409
537
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
Progmune Runtime demonstrates that by inverting the relationship between LLMs and program truth—establishing IR as the first principle and making LLMs constrained heuristic proposers—we can achieve verifiable code synthesis with strong semantic guarantees.
|
|
413
|
-
|
|
414
|
-
The layered SVL taxonomy, SSG protocol engine, continuously accumulating Failure Corpus, and three-layer memory architecture collectively form a new programming infrastructure: a neural-symbolic compiler runtime that learns, remembers, and defends.
|
|
415
|
-
|
|
416
|
-
We call this Program Immunology.
|
|
538
|
+
我们将此称为程序免疫学(Program Immunology)。
|
|
417
539
|
|
|
418
|
-
|
|
540
|
+
该系统以开源形式提供:https://github.com/shenlian19831109/progmune-runtime,也可通过 `npm install progmune-runtime` 安装使用。
|
package/dist/extract-ir.js
CHANGED
|
@@ -84,6 +84,12 @@ function parseCapabilityFromJSDoc(node) {
|
|
|
84
84
|
result.produces = [];
|
|
85
85
|
result.produces.push(...val.split(/[,\s]+/).map((s) => s.trim()).filter(Boolean));
|
|
86
86
|
}
|
|
87
|
+
if (tn === "useWhen") {
|
|
88
|
+
const val = t.getCommentText?.() || "";
|
|
89
|
+
if (!result.useWhen)
|
|
90
|
+
result.useWhen = [];
|
|
91
|
+
result.useWhen.push(...val.split(/[;;]/).map((s) => s.trim()).filter(Boolean));
|
|
92
|
+
}
|
|
87
93
|
}
|
|
88
94
|
}
|
|
89
95
|
}
|
|
@@ -125,6 +125,7 @@ function loadFailures() {
|
|
|
125
125
|
/** @requires FAILURE_LIST @produces FAILURE_STATS */
|
|
126
126
|
/** @requires FAILURE_LIST @produces FAILURE_STATS */
|
|
127
127
|
/** @requires FAILURE_LIST @produces FAILURE_STATS */
|
|
128
|
+
/** @useWhen dashboard; health report; monitoring system status */
|
|
128
129
|
function failureStats() {
|
|
129
130
|
const failures = loadFailures();
|
|
130
131
|
const byRootCause = {};
|
|
@@ -143,6 +144,7 @@ function failureStats() {
|
|
|
143
144
|
/** @requires FAILURE_STATS @produces FORMATTED_REPORT */
|
|
144
145
|
/** @requires FAILURE_STATS @produces FORMATTED_REPORT */
|
|
145
146
|
/** @requires FAILURE_STATS @produces FORMATTED_REPORT */
|
|
147
|
+
/** @useWhen generating readable reports; CLI output; CI summary */
|
|
146
148
|
function formatFailureStats() {
|
|
147
149
|
const stats = failureStats();
|
|
148
150
|
if (stats.total === 0)
|
package/dist/failure-corpus.js
CHANGED
|
@@ -212,6 +212,7 @@ function getTopFailurePatterns(limit = 5) {
|
|
|
212
212
|
/** Get failure genome statistics: total failures by SVL, constraint type, and fix path. */
|
|
213
213
|
/** @requires FAILURE_DATA @produces FAILURE_GENOME */
|
|
214
214
|
/** @requires FAILURE_DATA @produces FAILURE_GENOME */
|
|
215
|
+
/** @useWhen user asks why generation failed; benchmark compile rate drops; analyzing error patterns */
|
|
215
216
|
function getFailureGenome() {
|
|
216
217
|
const sessions = getAllSessions();
|
|
217
218
|
const bySVL = { "SVL-1": 0, "SVL-2": 0, "SVL-3": 0, "SVL-4": 0 };
|
|
@@ -275,6 +276,7 @@ function getFailureGenome() {
|
|
|
275
276
|
/** @requires SESSION_CORPUS @produces SESSION_LIST */
|
|
276
277
|
/** @requires SESSION_CORPUS @produces SESSION_LIST */
|
|
277
278
|
/** @requires SESSION_CORPUS @produces SESSION_LIST */
|
|
279
|
+
/** @useWhen listing all past executions; auditing session history; checking coverage */
|
|
278
280
|
function getAllSessions() {
|
|
279
281
|
const sessions = [];
|
|
280
282
|
if (!fs.existsSync(SESSIONS_DIR))
|
|
@@ -367,6 +369,7 @@ function computeACL(count, distinctIntents, resolvedRate) {
|
|
|
367
369
|
}
|
|
368
370
|
/** Get antibody patterns learned from failure history. */
|
|
369
371
|
/** @requires FAILURE_HISTORY @produces LEARNED_PATTERNS */
|
|
372
|
+
/** @useWhen finding what fixes worked before; reusing successful repairs */
|
|
370
373
|
function getLearnedPatterns() {
|
|
371
374
|
const sessions = getAllSessions();
|
|
372
375
|
const agg = new Map();
|
|
@@ -518,6 +521,7 @@ function getSemanticHeatmap() {
|
|
|
518
521
|
*/
|
|
519
522
|
/** @requires ANTIBODY_DATA @produces ANTIBODY_STATS */
|
|
520
523
|
/** @requires ANTIBODY_DATA @produces ANTIBODY_STATS */
|
|
524
|
+
/** @useWhen checking immune system effectiveness; measuring token savings */
|
|
521
525
|
function getAntibodyStats() {
|
|
522
526
|
const sessions = getAllSessions();
|
|
523
527
|
let totalHits = 0;
|
package/dist/feedback.js
CHANGED
|
@@ -36,6 +36,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.loadFeedback = loadFeedback;
|
|
37
37
|
exports.saveFeedback = saveFeedback;
|
|
38
38
|
exports.getFunctionSuccessRate = getFunctionSuccessRate;
|
|
39
|
+
exports.getWeightedSuccessRate = getWeightedSuccessRate;
|
|
40
|
+
exports.getFailureAdjustedCredit = getFailureAdjustedCredit;
|
|
39
41
|
exports.recordRun = recordRun;
|
|
40
42
|
const fs = __importStar(require("fs"));
|
|
41
43
|
const path = __importStar(require("path"));
|
|
@@ -55,15 +57,67 @@ function saveFeedback(record) {
|
|
|
55
57
|
fs.writeFileSync(FEEDBACK_PATH, JSON.stringify(data, null, 2));
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
|
-
/** @requires FUNCTION_NAME @produces SUCCESS_RATE
|
|
60
|
+
/** @requires FUNCTION_NAME @produces SUCCESS_RATE
|
|
61
|
+
* Flat success rate (all records equal weight). */
|
|
59
62
|
function getFunctionSuccessRate(funcName) {
|
|
60
63
|
const records = loadFeedback();
|
|
61
64
|
const funcRecords = records.filter(r => r.functionName === funcName);
|
|
62
65
|
if (funcRecords.length === 0)
|
|
63
|
-
return 0.5;
|
|
66
|
+
return 0.5;
|
|
64
67
|
const successCount = funcRecords.filter(r => r.success).length;
|
|
65
68
|
return successCount / funcRecords.length;
|
|
66
69
|
}
|
|
70
|
+
/** @requires FUNCTION_NAME @produces WEIGHTED_SUCCESS_RATE
|
|
71
|
+
* Time-weighted success rate: recent results matter more.
|
|
72
|
+
* Decay: weight = 0.5^(age_days). */
|
|
73
|
+
function getWeightedSuccessRate(funcName) {
|
|
74
|
+
const records = loadFeedback();
|
|
75
|
+
const funcRecords = records
|
|
76
|
+
.filter(r => r.functionName === funcName)
|
|
77
|
+
.map(r => ({ ...r, age: (Date.now() - new Date(r.timestamp).getTime()) / 86400000 })); // age in days
|
|
78
|
+
if (funcRecords.length === 0)
|
|
79
|
+
return 0.5;
|
|
80
|
+
let totalWeight = 0, weightedSuccess = 0;
|
|
81
|
+
for (const r of funcRecords) {
|
|
82
|
+
const w = Math.pow(0.5, Math.max(0, r.age)); // half-life = 1 day
|
|
83
|
+
totalWeight += w;
|
|
84
|
+
if (r.success)
|
|
85
|
+
weightedSuccess += w;
|
|
86
|
+
}
|
|
87
|
+
return totalWeight > 0 ? weightedSuccess / totalWeight : 0.5;
|
|
88
|
+
}
|
|
89
|
+
/** @requires FUNCTION_NAME @produces FAILURE_ADJUSTED_CREDIT
|
|
90
|
+
* Credit score adjusted by failure severity.
|
|
91
|
+
* SVL-4 (protocol) violations penalize 2x more than SVL-1.
|
|
92
|
+
* Time-weighted + severity-weighted. */
|
|
93
|
+
function getFailureAdjustedCredit(funcName) {
|
|
94
|
+
const records = loadFeedback();
|
|
95
|
+
const funcRecords = records
|
|
96
|
+
.filter(r => r.functionName === funcName)
|
|
97
|
+
.map(r => ({ ...r, age: (Date.now() - new Date(r.timestamp).getTime()) / 86400000 }));
|
|
98
|
+
if (funcRecords.length === 0)
|
|
99
|
+
return 0.5;
|
|
100
|
+
const SVL_PENALTY = {
|
|
101
|
+
"SVL-1": 1.0, // missing function — minor
|
|
102
|
+
"SVL-2": 1.5, // type mismatch — moderate
|
|
103
|
+
"SVL-3": 2.0, // dataflow — significant
|
|
104
|
+
"SVL-4": 3.0, // protocol — severe
|
|
105
|
+
};
|
|
106
|
+
let totalWeight = 0, weightedSuccess = 0;
|
|
107
|
+
for (const r of funcRecords) {
|
|
108
|
+
const timeW = Math.pow(0.5, Math.max(0, r.age));
|
|
109
|
+
if (r.success) {
|
|
110
|
+
totalWeight += timeW;
|
|
111
|
+
weightedSuccess += timeW;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const penalty = SVL_PENALTY[r.svlLevel || ""] || 1.0;
|
|
115
|
+
totalWeight += timeW * penalty;
|
|
116
|
+
// weightedSuccess stays 0 for failures
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return totalWeight > 0 ? weightedSuccess / totalWeight : 0.5;
|
|
120
|
+
}
|
|
67
121
|
/** @requires EXECUTION_DATA @produces RUN_ID */
|
|
68
122
|
function recordRun(intent, actions, success, error) {
|
|
69
123
|
for (const action of actions) {
|
package/dist/health-utils.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.countSessionLedgers = countSessionLedgers;
|
|
|
7
7
|
* @requires FAILURE_GENOME @produces HEALTH_SCORE
|
|
8
8
|
* @tags health, score, immune
|
|
9
9
|
*/
|
|
10
|
+
/** @useWhen generating immune health metrics; dashboard; monitoring */
|
|
10
11
|
function computeHealthScore(failureGenome, antibodyStats) {
|
|
11
12
|
const totalFailures = failureGenome?.totalFailures || 0;
|
|
12
13
|
const totalHits = antibodyStats?.totalHits || 0;
|
package/dist/ledger-registry.js
CHANGED
|
@@ -153,6 +153,7 @@ function verifyFingerprint(sessionId, transitions, currentRuleHash) {
|
|
|
153
153
|
/** Verify all registered ledger fingerprints and return tampered status. */
|
|
154
154
|
/** @requires FINGERPRINT_DATA @produces VERIFICATION_RESULT */
|
|
155
155
|
/** @requires FINGERPRINT_DATA @produces VERIFICATION_RESULT */
|
|
156
|
+
/** @useWhen checking execution integrity; audit after tampering suspicion */
|
|
156
157
|
function verifyAllFingerprints(currentRuleHash) {
|
|
157
158
|
const fingerprints = getFingerprintRegistry();
|
|
158
159
|
const results = [];
|
|
@@ -210,6 +211,7 @@ function verifyAllFingerprints(currentRuleHash) {
|
|
|
210
211
|
* Called during `npm run check` to ensure all sessions are fingerprinted. */
|
|
211
212
|
/** Register fingerprints for all sessions that lack them. */
|
|
212
213
|
/** @requires SESSION_DATA @produces FINGERPRINT_DATA */
|
|
214
|
+
/** @useWhen first-time setup; after adding new sessions */
|
|
213
215
|
function registerAllMissingFingerprints() {
|
|
214
216
|
const sessionsDir = path.resolve(process.env.PROGMUNE_PROJECT_DIR || process.cwd(), ".progmune_corpus/sessions");
|
|
215
217
|
if (!fs.existsSync(sessionsDir))
|