progmune-runtime 2.0.2 → 2.1.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/.mcp.json +11 -0
- package/.progmune_allowlist +50 -0
- package/.test_report/test_report.md +87 -0
- package/Dockerfile +2 -10
- package/FAQ.md +167 -0
- package/demo-project/auth.ts +55 -0
- package/demo-project/tsconfig.json +8 -0
- package/dist/ab-stats.js +11 -0
- package/dist/acl-breakdown.js +13 -0
- package/dist/all-sessions.js +11 -0
- package/dist/antibody-stats.js +11 -0
- package/dist/audit.js +218 -0
- package/dist/benchmark-count.js +7 -0
- package/dist/benchmark-full.js +17 -0
- package/dist/benchmark-pass-rate.js +54 -0
- package/dist/benchmark-report.js +67 -0
- package/dist/benchmark-save.js +62 -0
- package/dist/benchmark-status.js +15 -0
- package/dist/branch-ledger.js +365 -0
- package/dist/branch-tree-count.js +14 -0
- package/dist/check.js +506 -0
- package/dist/common-fixpath.js +12 -0
- package/dist/constraint-types.js +12 -0
- package/dist/deterministic-replay.js +277 -0
- package/dist/emitter.js +112 -12
- package/dist/exec-metrics.js +11 -0
- package/dist/execute.js +242 -0
- package/dist/extract-ir.js +550 -5
- package/dist/failure-collector.js +143 -0
- package/dist/failure-corpus.js +481 -35
- package/dist/failure-report.js +11 -0
- package/dist/failures.js +11 -0
- package/dist/fast-path-hits.js +13 -0
- package/dist/feedback.js +6 -3
- package/dist/file-lock.js +82 -0
- package/dist/find-session.js +10 -0
- package/dist/fingerprint-list.js +15 -0
- package/dist/gen-history-log.js +13 -0
- package/dist/generate.js +2 -1
- package/dist/generate_500.js +4 -2
- package/dist/genome.js +11 -0
- package/dist/heatmap-data.js +11 -0
- package/dist/heatmap.js +11 -0
- package/dist/immune-reporter.js +137 -0
- package/dist/learned.js +11 -0
- package/dist/ledger-registry.js +241 -0
- package/dist/llm.js +43 -2
- package/dist/load-benchmarks.js +47 -0
- package/dist/main.js +2 -1
- package/dist/mcp-server.mjs +446 -34
- package/dist/memory-layer.js +51 -13
- package/dist/metrics.js +11 -0
- package/dist/obs-web.js +561 -0
- package/dist/p0_ssg_demo.js +255 -40
- package/dist/planner.js +933 -65
- package/dist/protocol-registry.js +105 -0
- package/dist/recent-session.js +12 -0
- package/dist/repair-proposal.js +353 -0
- package/dist/report.js +32 -0
- package/dist/runtime-invariants.js +161 -0
- package/dist/runtime-types.js +117 -0
- package/dist/search-planner.js +38 -9
- package/dist/semantic-snapshot.js +155 -0
- package/dist/semantic-trace.js +1497 -0
- package/dist/semantic-validator.js +3 -2
- package/dist/semantic_guard_test.js +2 -1
- package/dist/sessions.js +11 -0
- package/dist/ssg-validator.js +658 -20
- package/dist/svl-distribution.js +11 -0
- package/dist/terminal-status.js +11 -0
- package/dist/test_failure_corpus.js +3 -1
- package/dist/token-savings.js +11 -0
- package/dist/total-repairs.js +12 -0
- package/dist/unresolved-count.js +12 -0
- package/dist/valid-fingerprints.js +13 -0
- package/dist/validator.js +116 -60
- package/dist/verify-fps.js +11 -0
- package/dist/verify-ledgers.js +11 -0
- package/docs/whitepaper-style.css +77 -0
- package/docs/whitepaper-v2.1.md +609 -0
- package/docs/whitepaper-v2.2.md +1064 -0
- package/docs/whitepaper-v2.2.pdf +0 -0
- package/fly.toml +1 -1
- package/package.json +13 -4
- package/protocols.json +136 -0
- package/public/dashboard.html +119 -0
- package/readme.md +829 -0
- package/server/hub.js +84 -12
- package/test/replay-golden/sess_1780063202050_mgeld.json +9 -0
- package/test/replay-golden/sess_1780064032560_gocld.json +354 -0
- package/test/replay-golden/sess_1780064413331_s2709.json +606 -0
- package/test/replay-golden/sess_1780064792710_y3avo.json +614 -0
- package/test/replay-golden.ts +84 -0
- package/test_benchmark.js +165 -0
- package/test_comprehensive.mjs +638 -0
- package/test_concurrency.js +129 -0
- package/test_ir_robustness.js +85 -0
- package/test_semantic_contracts.js +269 -0
- package/test_ssg_stress.js +156 -0
- package/test_svl3.js +58 -0
- package/tsconfig.json +1 -1
- package/.env.example +0 -3
- package/.progmune_memory/fingerprints.json +0 -7
- package/.progmune_memory/opt_in.json +0 -4
- package/README.md +0 -118
- package/dist/mcp-server.js +0 -55
- package/immune_hub_data/2026-05-14.json +0 -50
package/test_svl3.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
|
|
3
|
+
// 确保 ir.json 存在
|
|
4
|
+
const ir = [
|
|
5
|
+
{ name: 'cache_get', params: [{ name: 'key', type: 'str' }], returnType: 'any', file: 'auth.py' },
|
|
6
|
+
];
|
|
7
|
+
fs.writeFileSync('ir.json', JSON.stringify(ir, null, 2));
|
|
8
|
+
|
|
9
|
+
// 内联 checkVariableFlow 逻辑
|
|
10
|
+
function checkVariableFlow(actions) {
|
|
11
|
+
const errors = [];
|
|
12
|
+
const declared = new Map();
|
|
13
|
+
|
|
14
|
+
const isLiteral = (val) => {
|
|
15
|
+
if (typeof val !== 'string') return true;
|
|
16
|
+
if (/^["'`]/.test(val) || /["'`]$/.test(val)) return true;
|
|
17
|
+
if (/^\d+$/.test(val)) return true;
|
|
18
|
+
if (val === 'true' || val === 'false' || val === 'null' || val === 'undefined') return true;
|
|
19
|
+
if (/\s/.test(val) || /[^\w]/.test(val)) return true;
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const processAction = (action) => {
|
|
24
|
+
console.log('处理动作:', JSON.stringify(action));
|
|
25
|
+
if (action.kind === 'call') {
|
|
26
|
+
for (const arg of (action.args || [])) {
|
|
27
|
+
const val = arg.value;
|
|
28
|
+
console.log(' 参数值:', val, '类型:', typeof val, 'isLiteral:', isLiteral(val), '是否为标识符:', /^[a-zA-Z_]\w*$/.test(val));
|
|
29
|
+
if (typeof val === 'string' && !isLiteral(val)) {
|
|
30
|
+
if (/^[a-zA-Z_]\w*$/.test(val) && !declared.has(val)) {
|
|
31
|
+
const errMsg = "变量 '" + val + "' 未声明就使用";
|
|
32
|
+
errors.push(errMsg);
|
|
33
|
+
console.log(' -> 检测到错误:', errMsg);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (action.assignTo) {
|
|
38
|
+
declared.set(action.assignTo, 'any');
|
|
39
|
+
console.log(' 声明变量:', action.assignTo);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
for (const action of actions) processAction(action);
|
|
45
|
+
return errors;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const actions = [
|
|
49
|
+
{
|
|
50
|
+
kind: 'call',
|
|
51
|
+
function: 'cache_get',
|
|
52
|
+
args: [{ name: 'key', type: 'str', value: 'myCacheKey' }]
|
|
53
|
+
}
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
const errors = checkVariableFlow(actions);
|
|
57
|
+
console.log('\n最终错误列表:', JSON.stringify(errors));
|
|
58
|
+
console.log(errors.length > 0 ? '✅ SVL-3 生效了!' : '❌ SVL-3 仍未生效');
|
package/tsconfig.json
CHANGED
package/.env.example
DELETED
package/README.md
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# Progmune Runtime(免序)
|
|
2
|
-
|
|
3
|
-
**程序免疫学:为生成式程序建立免疫系统**
|
|
4
|
-
|
|
5
|
-
[](https://opensource.org/licenses/MIT)
|
|
6
|
-
[](https://modelcontextprotocol.io)
|
|
7
|
-
[]()
|
|
8
|
-
|
|
9
|
-
**Progmune(免序)不是一个 AI 编程助手,而是一个面向生成式程序的免疫系统。** 它将大语言模型(LLM)从开放世界的代码生成器,降级为在程序真相层(IR)严格约束下的启发式搜索器,确保生成的代码不仅在符号和类型上正确,更在行为协议上合法。
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## 核心命题:AI 生成的程序必须具备免疫系统
|
|
14
|
-
|
|
15
|
-
LLM 在生成代码时会产生“幻觉”——调用不存在的函数、违反类型约束、跳过关键的业务步骤。传统的提示工程和事后校验无法根除这些问题,因为它们将 LLM 置于系统的中心,缺乏第一性原理的约束。
|
|
16
|
-
|
|
17
|
-
Progmune 提出**程序免疫学(Program Immunology)**范式,为生成式程序建立一套可识别、可记忆、可进化的防御体系。我们证明了,通过将程序的真实结构(IR)确立为唯一真相源,可以使 AI 生成的代码具备:
|
|
18
|
-
|
|
19
|
-
1. **天然免疫**:快速识别并拒绝违反符号存在性、类型兼容性和数据流规则的代码。
|
|
20
|
-
2. **获得性免疫**:从过去的失败案例中学习,生成特异性的防御规则,主动预防未来同类错误。
|
|
21
|
-
3. **免疫记忆**:将成功和失败的模式沉淀为结构化的知识,使系统随着使用持续进化,越用越可靠。
|
|
22
|
-
|
|
23
|
-
**详细理论框架请参阅《[Program Immunology 白皮书](./WHITEPAPER.md)》。**
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## 架构概览:一个会学习、会记忆、会防御的运行时
|
|
28
|
-
|
|
29
|
-
Progmune 的架构受生物免疫系统启发,分为六个核心层:
|
|
30
|
-
|
|
31
|
-
| 生物免疫系统 | 程序免疫 (Progmune) | 核心职责 |
|
|
32
|
-
|-------------|---------------------|----------|
|
|
33
|
-
| **天然免疫** | **约束引擎** (IR + SVL-1~SVL-3) | 快速、自动地拒绝调用不存在的函数、类型错误和数据流问题。 |
|
|
34
|
-
| **获得性免疫** | **语义状态图 (SSG)** | 通过可编程的状态机,精确拦截非法业务逻辑跃迁(如“未认证即签发令牌”)。 |
|
|
35
|
-
| **免疫记忆** | **三层记忆架构** | 工作记忆、情景记忆和语义记忆协同,让系统越用越聪明,相似意图可跳过LLM直接复用验证过的路径。 |
|
|
36
|
-
| **抗原呈递** | **Failure Corpus** | 结构化的失败案例库,每一次拦截都转化为可分析的“错误指纹”,为系统进化提供数据基础。 |
|
|
37
|
-
|
|
38
|
-
---
|
|
39
|
-
|
|
40
|
-
## 快速开始
|
|
41
|
-
|
|
42
|
-
### 前置条件
|
|
43
|
-
- [Node.js](https://nodejs.org/) >= 18
|
|
44
|
-
- 一个有效的 LLM API 密钥(DeepSeek 或 OpenAI 兼容接口)
|
|
45
|
-
|
|
46
|
-
### 1. 安装
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
npm install -g progmune-runtime
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### 2. 配置 LLM API 密钥
|
|
53
|
-
```bash
|
|
54
|
-
export LLM_API_KEY="你的DeepSeek或OpenAI密钥"
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### 3. 在 MCP 客户端中配置
|
|
58
|
-
**Claude Code**: 编辑 `~/.claude/settings.json` 并添加:
|
|
59
|
-
|
|
60
|
-
```json
|
|
61
|
-
{
|
|
62
|
-
"mcpServers": {
|
|
63
|
-
"progmune": {
|
|
64
|
-
"command": "npx",
|
|
65
|
-
"args": ["progmune-runtime"]
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
**Manus / 其他客户端**: Command: `npx`, Args: `progmune-runtime`。
|
|
72
|
-
|
|
73
|
-
配置完成后,在对话中直接描述编程需求,AI 代理会自动调用 Progmune 生成安全代码。
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
## 全球免疫网络 (Global Immune Network)
|
|
78
|
-
Progmune 支持将本地脱敏后的错误指纹安全上报至中央免疫服务器,实现“群体免疫”。
|
|
79
|
-
|
|
80
|
-
**设置中央服务器地址**:
|
|
81
|
-
```bash
|
|
82
|
-
export PROGMUNE_HUB="https://progmune-runtime.fly.dev/report"
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
**预览待上报的脱敏数据**:
|
|
86
|
-
```bash
|
|
87
|
-
npx ts-node src/report.ts preview
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
**执行安全上报**:
|
|
91
|
-
```bash
|
|
92
|
-
npx ts-node src/report.ts report
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
**隐私保护**: 只上传函数名序列、SVL级别、状态迁移,绝不包含任何代码片段、变量值或用户数据。
|
|
96
|
-
|
|
97
|
-
---
|
|
98
|
-
|
|
99
|
-
## 语义有效性级别 (SVL)
|
|
100
|
-
Progmune 定义了 AI 生成代码正确性的分层标准:
|
|
101
|
-
|
|
102
|
-
| 级别 | 名称 | 保证 |
|
|
103
|
-
|---|---|---|
|
|
104
|
-
| SVL-1 | 符号存在性 | 绝不调用项目中不存在的函数 |
|
|
105
|
-
| SVL-2 | 类型有效性 | 参数数量和类型严格匹配 |
|
|
106
|
-
| SVL-3 | 数据流正确性 | 变量先声明后使用,无循环引用 |
|
|
107
|
-
| SVL-4 | 协议合法性 | 业务步骤顺序必须遵守状态迁移规则 |
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
## 如何贡献
|
|
112
|
-
Progmune 的核心护城河在于不断积累的语义失败语料库。欢迎通过 GitHub Issues 提交您在使用过程中遇到的“看似合法但实际危险”的生成案例(请务必脱敏),帮助我们完善语义状态图(SSG)协议。
|
|
113
|
-
|
|
114
|
-
## 许可证
|
|
115
|
-
MIT License。
|
|
116
|
-
|
|
117
|
-
Progmune 正在重新定义 AI 辅助编程——不是“让模型更聪明”,而是“让程序真相主导生成”。
|
|
118
|
-
加入我们的技术预览,一起构建可验证的 AI 编码未来。
|
package/dist/mcp-server.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
-
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
-
import { createRequire } from 'module';
|
|
5
|
-
|
|
6
|
-
const require = createRequire(import.meta.url);
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
|
|
9
|
-
const { plan } = require('./planner.js');
|
|
10
|
-
const { extractIRPython } = require('./extract-ir-python.js');
|
|
11
|
-
const { emitPython } = require('./python-emitter.js');
|
|
12
|
-
const { recordRun } = require('./feedback.js');
|
|
13
|
-
|
|
14
|
-
async function main() {
|
|
15
|
-
const server = new Server({
|
|
16
|
-
name: "progmune",
|
|
17
|
-
version: "2.0.0"
|
|
18
|
-
}, { capabilities: { tools: {} } });
|
|
19
|
-
|
|
20
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
21
|
-
tools: [{
|
|
22
|
-
name: "generate_verified_code",
|
|
23
|
-
description: "生成类型安全的Python代码,仅使用项目中真实存在的函数。",
|
|
24
|
-
inputSchema: {
|
|
25
|
-
type: "object",
|
|
26
|
-
properties: {
|
|
27
|
-
intent: { type: "string", description: "编程意图" },
|
|
28
|
-
projectPath: { type: "string", description: "项目根目录绝对路径" }
|
|
29
|
-
},
|
|
30
|
-
required: ["intent", "projectPath"]
|
|
31
|
-
}
|
|
32
|
-
}]
|
|
33
|
-
}));
|
|
34
|
-
|
|
35
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
36
|
-
if (request.params.name === "generate_verified_code") {
|
|
37
|
-
const { intent, projectPath } = request.params.arguments;
|
|
38
|
-
const fns = extractIRPython(projectPath);
|
|
39
|
-
fs.writeFileSync("ir.json", JSON.stringify(fns, null, 2));
|
|
40
|
-
const actions = await plan(intent);
|
|
41
|
-
if (!actions || actions.length === 0) {
|
|
42
|
-
return { content: [{ type: "text", text: "无法生成满足约束的代码。" }] };
|
|
43
|
-
}
|
|
44
|
-
const code = emitPython(actions);
|
|
45
|
-
recordRun(intent, actions, true);
|
|
46
|
-
return { content: [{ type: "text", text: code }] };
|
|
47
|
-
}
|
|
48
|
-
throw new Error("未知工具");
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const transport = new StdioServerTransport();
|
|
52
|
-
await server.connect(transport);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
main().catch(console.error);
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"instance_id": "1009ae6be3d4526c",
|
|
4
|
-
"timestamp": "2026-05-13T18:53:16.840Z",
|
|
5
|
-
"violatedSVL": "SVL-4",
|
|
6
|
-
"constraintType": "protocol",
|
|
7
|
-
"functionSequence": [
|
|
8
|
-
"generate_jwt"
|
|
9
|
-
],
|
|
10
|
-
"preState": [
|
|
11
|
-
"UNAUTHENTICATED"
|
|
12
|
-
],
|
|
13
|
-
"count": 1
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"instance_id": "1009ae6be3d4526c",
|
|
17
|
-
"timestamp": "2026-05-13T21:24:45.973Z",
|
|
18
|
-
"violatedSVL": "SVL-4",
|
|
19
|
-
"constraintType": "protocol",
|
|
20
|
-
"functionSequence": [
|
|
21
|
-
"generate_jwt",
|
|
22
|
-
"create_session"
|
|
23
|
-
],
|
|
24
|
-
"count": 1
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"instance_id": "1009ae6be3d4526c",
|
|
28
|
-
"timestamp": "2026-05-13T21:24:47.155Z",
|
|
29
|
-
"violatedSVL": "SVL-4",
|
|
30
|
-
"constraintType": "protocol",
|
|
31
|
-
"functionSequence": [
|
|
32
|
-
"query_data",
|
|
33
|
-
"generate_jwt",
|
|
34
|
-
"create_session"
|
|
35
|
-
],
|
|
36
|
-
"count": 1
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"instance_id": "1009ae6be3d4526c",
|
|
40
|
-
"timestamp": "2026-05-13T21:24:48.290Z",
|
|
41
|
-
"violatedSVL": "SVL-4",
|
|
42
|
-
"constraintType": "protocol",
|
|
43
|
-
"functionSequence": [
|
|
44
|
-
"query_data",
|
|
45
|
-
"generate_jwt",
|
|
46
|
-
"create_session"
|
|
47
|
-
],
|
|
48
|
-
"count": 1
|
|
49
|
-
}
|
|
50
|
-
]
|