progmune-runtime 3.3.7 → 3.4.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/CHANGELOG.md ADDED
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+
3
+ ## [3.4.0] — 2026-08-21
4
+
5
+ ### 新增:Agent 化 P1–P4.5
6
+
7
+ - `npm run agent "意图"` — 免疫门在环内的自主实现循环:目标分解 → 8 门验证 → SSG 确定性修复 → 写盘+指纹 → 编译/指纹/测试验证门 → 失败反馈重试(≤3)→ 审计轨迹 + 带指纹 diff
8
+ - `npm run patrol -- --project X [--watch]` — 免疫巡逻:trust_check → 违规报告 + 建议补丁(**绝不自动合并**,修复需人工审批)
9
+ - 感知层:Git 仓库上下文注入、IR 增量差集、文件变更监听(RepoWatcher)
10
+ - 自监督层:项目测试门(npm test / pytest 自动探测,失败摘要注入重试反馈)
11
+
12
+ ### 行为变化:Trust 引擎协议验证语义(P4.5)
13
+
14
+ - 协议违规收集从「正则扫描文件声明序列」改为「IR 函数体调用序列」:
15
+ - 函数声明顺序不再被当作执行链(消除 auth.ts 类声明误报)
16
+ - 单调用违规文件不再被 `≥4` 阈值跳过(修复 bad_flow 类漏报)
17
+ - 合并项目 `@protocol` 注解(IR 优先、缺 namespace 继承内置 JSON,对齐 planner 语义)——项目级前置约束现在生效
18
+ - **升级后 trust 检查结果可能与 3.3.x 不同:误报减少、真违规命中增多**
19
+
20
+ ### 修复
21
+
22
+ - `verifyCompiles` 绝对路径漏匹配——编译验证门静默漏报
23
+ - `@protocol` 注解解析早退——文件首函数协议丢失,SSG 误拦正确调用链
24
+ - 语义 marker(`__progmune_*`)泄漏进 LLM 可见函数表,被生成为真实调用
25
+ - LLM 调用异常静默吞没——改为可见日志(铁律:不许静默绕过)
26
+ - `git status --porcelain` 首字符状态列被整串 trim 截断
27
+
28
+ ### 已知问题
29
+
30
+ - `npm run check` 的 Ledger 不变量 / 回放 / 覆盖率失败为历史遗留(基线核查确认与本次改动无关),待单独排期
31
+
32
+ ## [3.3.8] — 2026-08-18
33
+
34
+ - README 链接跨平台修复(npm 页面语言切换链接)
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![TS Benchmark](https://img.shields.io/badge/TS%20R98.5%25%20P100%25-22c55e)]()
8
8
  [![Python Benchmark](https://img.shields.io/badge/Python%20R100%25%20P100%25-22c55e)]()
9
9
 
10
- > [中文版](README.zh-CN.md) · English Version
10
+ > [中文版](https://github.com/shenlian19831109/progmune-runtime/blob/main/README.zh-CN.md) · English Version
11
11
 
12
12
  **Verify AI-generated code before it reaches production.** Progmune checks whether your AI-generated code follows correct protocol lifecycles — TLS handshakes, auth flows, payment integrity, resource management — violations that SAST and SCA tools cannot see because they span sequences of function calls, not single statements.
13
13
 
@@ -91,7 +91,7 @@ Progmune's output is a **decision** backed by evidence, not a raw list of findin
91
91
 
92
92
  **Critical violations → hard BLOCK regardless of score.** Enterprises care about "can I deploy?" not "is my score 58 or 61."
93
93
 
94
- → [Trust Decision Model](docs/ai-trust-decision-model-v1.md)
94
+ → [Trust Decision Model](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/ai-trust-decision-model-v1.md)
95
95
 
96
96
  ---
97
97
 
@@ -103,7 +103,7 @@ Progmune is honest about what it can and cannot verify.
103
103
  |----------|--------|----------|
104
104
  | **TypeScript / JavaScript** | ✅ Production | Blind benchmark: **recall 98.5% / precision 100%** (795 gold findings, 100 projects) |
105
105
  | **Python** | ✅ Production | Blind benchmark: **recall 100% / precision 100%** (729 gold findings, 90 projects); real-world validation: PyGoat (OWASP vulnerable-by-design Django app) **67 TP / 0 FP, 100% labeled precision**; three well-written apps (django/fastapi realworld, django-unicorn) with 0 false-positive true findings |
106
- | **C** | ⚠️ Research-only | Gold benchmark F1=16.5%. L3 cross-function experiment terminated; L4 not planned. See [C Language Status](docs/c-language-status.md). |
106
+ | **C** | ⚠️ Research-only | Gold benchmark F1=16.5%. L3 cross-function experiment terminated; L4 not planned. See [C Language Status](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/c-language-status.md). |
107
107
  | **Go, Java** | ❌ None | Planned |
108
108
 
109
109
  **Framework adapters: 2/13.** Express ✅ and tRPC ✅ have dedicated detectors; Next.js has version-aware governance; NestJS is partial. Django, FastAPI and 8 more remain — framework adaptation is the #1 product gap.
@@ -116,7 +116,7 @@ Progmune is honest about what it can and cannot verify.
116
116
  - **Framework internals** — well-known framework dispatch/cache machinery (e.g. django-unicorn internals) can produce a small number of boundary false positives; they are documented per-corpus in the benchmark gold files.
117
117
  - **Known failure boundaries are documented** rather than hidden: if Progmune cannot verify a language (e.g. Go), Confidence is lowered instead of pretending 100%.
118
118
 
119
- → [Full Coverage Matrix](docs/coverage-matrix.md)
119
+ → [Full Coverage Matrix](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/coverage-matrix.md)
120
120
 
121
121
  ---
122
122
 
@@ -148,11 +148,11 @@ Public, reproducible precision data. All numbers measured against gold-annotated
148
148
  | Classes covered | 14 vulnerability classes incl. SQLi, SSRF, path traversal, XSS, SSTI, XXE, command injection, deserialization, CSRF (both shapes), cookie authorization, hardcoded secrets |
149
149
  | Well-written apps | django-realworld, fastapi-realworld, django-unicorn — 0 false-positive true findings; 3 documented framework-internal boundary FPs |
150
150
 
151
- → [Real-world validation report](blind-benchmark/REALWORLD_APP_V1.md) · [Benchmark baseline](blind-benchmark/BASELINE_v6.md)
151
+ → [Real-world validation report](https://github.com/shenlian19831109/progmune-runtime/blob/main/blind-benchmark/REALWORLD_APP_V1.md) · [Benchmark baseline](https://github.com/shenlian19831109/progmune-runtime/blob/main/blind-benchmark/BASELINE_v6.md)
152
152
 
153
153
  ### C (Gold Benchmark — research status)
154
154
 
155
- C analysis is **research-only**: gold benchmark F1=16.5% across 4 repos (curl, libssh, nginx, openssl). The bottleneck is rule coverage, not context. L3 (cross-function) was terminated with data; L4 (pointer/CFG) is a multi-year research problem and not planned. See [C Language Status](docs/c-language-status.md) for the full picture and reasoning.
155
+ C analysis is **research-only**: gold benchmark F1=16.5% across 4 repos (curl, libssh, nginx, openssl). The bottleneck is rule coverage, not context. L3 (cross-function) was terminated with data; L4 (pointer/CFG) is a multi-year research problem and not planned. See [C Language Status](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/c-language-status.md) for the full picture and reasoning.
156
156
 
157
157
  ### P0-P3 Rule Injection (2026-08)
158
158
 
@@ -160,7 +160,7 @@ C analysis is **research-only**: gold benchmark F1=16.5% across 4 repos (curl, l
160
160
  - Bootstrapping deadlock broken: all 21 protocol namespaces now have rule vocabulary
161
161
  - `excludePatterns` + `languages` architecture for FP management
162
162
 
163
- → [Two-Hump Report](docs/two-hump-report.md) · [P0-P3 Final Report](docs/p0-p3-final-report.md)
163
+ → [Two-Hump Report](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/two-hump-report.md) · [P0-P3 Final Report](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/p0-p3-final-report.md)
164
164
 
165
165
  ---
166
166
 
@@ -195,15 +195,15 @@ SDK (src/sdk.ts) verify() → APPROVED / NEEDS_REVIEW / BLOCKED
195
195
 
196
196
  Progmune is built on the premise that **LLM outputs are statistical performances, not reasoning** — a view developed by Subbarao Kambhampati et al. in the position paper ["Stop Anthropomorphizing Intermediate Tokens as Reasoning/Thinking Traces!"](https://arxiv.org/abs/2505.22285) (arXiv:2505.22285, 2025) and elaborated in his ICML 2026 talk "On the Role of Verifiers and Thinking Traces in Reasoning Models". Rather than trusting what the model says about code, Progmune verifies what the program actually does — using protocol state machines, IR extraction, and evidence-backed decision chains.
197
197
 
198
- Coverage-gap analysis borrows the "two-hump problem" terminology **as a cross-domain analogy** from Sergei Gukov's work in mathematical physics (the Andrews-Curtis conjecture in group theory, 2026) — it describes a bimodal coverage distribution, not a collaboration. See [Two-Hump Report](docs/two-hump-report.md) for the full methodology.
198
+ Coverage-gap analysis borrows the "two-hump problem" terminology **as a cross-domain analogy** from Sergei Gukov's work in mathematical physics (the Andrews-Curtis conjecture in group theory, 2026) — it describes a bimodal coverage distribution, not a collaboration. See [Two-Hump Report](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/two-hump-report.md) for the full methodology.
199
199
 
200
- → [Investor Whitepaper](docs/Progmune_投资人白皮书_v2.0.html) · [Trust Decision Model](docs/ai-trust-decision-model-v1.md)
200
+ → [Investor Whitepaper](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/Progmune_投资人白皮书_v2.0.html) · [Trust Decision Model](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/ai-trust-decision-model-v1.md)
201
201
 
202
202
  ---
203
203
 
204
204
  ## Contributing
205
205
 
206
- See [CLAUDE.md](CLAUDE.md) for architecture and code conventions, and [CONTRIBUTING.md](CONTRIBUTING.md) for the development workflow.
206
+ See [CLAUDE.md](https://github.com/shenlian19831109/progmune-runtime/blob/main/CLAUDE.md) for architecture and code conventions, and [CONTRIBUTING.md](https://github.com/shenlian19831109/progmune-runtime/blob/main/CONTRIBUTING.md) for the development workflow.
207
207
 
208
208
  High-impact contribution areas:
209
209
  - **Framework adapters** (Express, Next.js, FastAPI) — the #1 product gap
@@ -226,4 +226,4 @@ High-impact contribution areas:
226
226
 
227
227
  ## License
228
228
 
229
- MIT — [LICENSE](LICENSE)
229
+ MIT — [LICENSE](https://github.com/shenlian19831109/progmune-runtime/blob/main/LICENSE)
package/README.zh-CN.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![TS Benchmark](https://img.shields.io/badge/TS%20R98.5%25%20P100%25-22c55e)]()
8
8
  [![Python Benchmark](https://img.shields.io/badge/Python%20R100%25%20P100%25-22c55e)]()
9
9
 
10
- > [English Version](README.md) · 中文版
10
+ > [English Version](https://github.com/shenlian19831109/progmune-runtime/blob/main/README.md) · 中文版
11
11
 
12
12
  **在 AI 生成的代码进入生产前验证它。** Progmune 检查你的 AI 生成代码是否遵循正确的协议生命周期——TLS 握手、认证流程、支付完整性、资源管理——这些违规横跨**函数调用序列**而非单条语句,SAST 和 SCA 工具都看不见。
13
13
 
@@ -91,7 +91,7 @@ Progmune 的输出是**有证据支撑的决策**,不是原始发现列表:
91
91
 
92
92
  **严重违规 → 无论评分多少一律硬 BLOCK。** 企业关心的是"能不能上线",不是"我的评分是 58 还是 61"。
93
93
 
94
- → [信任决策模型](docs/ai-trust-decision-model-v1.md)
94
+ → [信任决策模型](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/ai-trust-decision-model-v1.md)
95
95
 
96
96
  ---
97
97
 
@@ -103,7 +103,7 @@ Progmune 对能验证什么、不能验证什么保持诚实。
103
103
  |------|------|------|
104
104
  | **TypeScript / JavaScript** | ✅ 生产 | 盲测基准:**召回 98.5% / 精确率 100%**(795 条 gold finding,100 个项目) |
105
105
  | **Python** | ✅ 生产 | 盲测基准:**召回 100% / 精确率 100%**(729 条 gold finding,90 个项目);真实应用验证:PyGoat(OWASP 故意脆弱 Django 应用)**67 TP / 0 FP,标记精确率 100%**;三个良构应用(django/fastapi realworld、django-unicorn)0 误报真阳性 |
106
- | **C** | ⚠️ 仅研究 | 黄金基准 F1=16.5%。L3 跨函数实验已终止;L4 无计划。见 [C 语言状态](docs/c-language-status.md)。 |
106
+ | **C** | ⚠️ 仅研究 | 黄金基准 F1=16.5%。L3 跨函数实验已终止;L4 无计划。见 [C 语言状态](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/c-language-status.md)。 |
107
107
  | **Go, Java** | ❌ 无 | 规划中 |
108
108
 
109
109
  **框架适配器:2/13。** Express ✅ 与 tRPC ✅ 有专用检测器;Next.js 有版本感知治理;NestJS 部分支持。Django、FastAPI 及另外 8 个待适配——框架适配是 #1 产品缺口。
@@ -116,7 +116,7 @@ Progmune 对能验证什么、不能验证什么保持诚实。
116
116
  - **框架内部件**——知名框架的分发/缓存机制(如 django-unicorn 内部件)可能产生少量边界误报;各语料基准 gold 文件中已逐条记录。
117
117
  - **已知失败边界一律记录**而非隐藏:如果 Progmune 无法验证某语言(如 Go),置信度会降低而不是假装 100%。
118
118
 
119
- → [完整覆盖矩阵](docs/coverage-matrix.md)
119
+ → [完整覆盖矩阵](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/coverage-matrix.md)
120
120
 
121
121
  ---
122
122
 
@@ -148,11 +148,11 @@ Progmune 对能验证什么、不能验证什么保持诚实。
148
148
  | 覆盖类别 | 14 个漏洞类别,含 SQLi、SSRF、路径穿越、XSS、SSTI、XXE、命令注入、反序列化、CSRF(双形态)、cookie 授权、硬编码密钥 |
149
149
  | 良构应用 | django-realworld、fastapi-realworld、django-unicorn——0 误报真阳性 |
150
150
 
151
- → [真实验证报告](blind-benchmark/REALWORLD_APP_V1.md) · [基准基线](blind-benchmark/BASELINE_v6.md)
151
+ → [真实验证报告](https://github.com/shenlian19831109/progmune-runtime/blob/main/blind-benchmark/REALWORLD_APP_V1.md) · [基准基线](https://github.com/shenlian19831109/progmune-runtime/blob/main/blind-benchmark/BASELINE_v6.md)
152
152
 
153
153
  ### C(黄金基准——研究状态)
154
154
 
155
- C 分析**仅研究**:黄金基准 F1=16.5%,覆盖 4 个仓库(curl、libssh、nginx、openssl)。瓶颈是规则覆盖而非上下文。L3(跨函数)已带数据终止;L4(指针/CFG)是多年研究问题,无计划。详见 [C 语言状态](docs/c-language-status.md)。
155
+ C 分析**仅研究**:黄金基准 F1=16.5%,覆盖 4 个仓库(curl、libssh、nginx、openssl)。瓶颈是规则覆盖而非上下文。L3(跨函数)已带数据终止;L4(指针/CFG)是多年研究问题,无计划。详见 [C 语言状态](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/c-language-status.md)。
156
156
 
157
157
  ### P0-P3 规则注入(2026-08)
158
158
 
@@ -160,7 +160,7 @@ C 分析**仅研究**:黄金基准 F1=16.5%,覆盖 4 个仓库(curl、libs
160
160
  - 打破引导死锁:全部 21 个协议命名空间已有规则词汇
161
161
  - `excludePatterns` + `languages` 架构管理误报
162
162
 
163
- → [双峰报告](docs/two-hump-report.md) · [P0-P3 终报](docs/p0-p3-final-report.md)
163
+ → [双峰报告](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/two-hump-report.md) · [P0-P3 终报](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/p0-p3-final-report.md)
164
164
 
165
165
  ---
166
166
 
@@ -194,15 +194,15 @@ SDK (src/sdk.ts) verify() → APPROVED / NEEDS_REVIEW / BLOCKED
194
194
 
195
195
  Progmune 建立在"**LLM 输出是统计表演而非推理**"这一前提上——该观点源自 Subbarao Kambhampati 等人的立场论文 ["Stop Anthropomorphizing Intermediate Tokens as Reasoning/Thinking Traces!"](https://arxiv.org/abs/2505.22285)(arXiv:2505.22285,2025),并在其 ICML 2026 演讲 "On the Role of Verifiers and Thinking Traces in Reasoning Models" 中展开。Progmune 不信任模型对代码的说法,而是用协议状态机、IR 提取与证据链验证程序实际行为。
196
196
 
197
- 覆盖缺口分析借用"双峰问题"术语作为**跨域类比**,源自 Sergei Gukov 在数学物理领域的工作(群论中的 Andrews-Curtis 猜想,2026)——它描述的是双峰覆盖分布,而非合作关系。详见 [双峰报告](docs/two-hump-report.md)。
197
+ 覆盖缺口分析借用"双峰问题"术语作为**跨域类比**,源自 Sergei Gukov 在数学物理领域的工作(群论中的 Andrews-Curtis 猜想,2026)——它描述的是双峰覆盖分布,而非合作关系。详见 [双峰报告](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/two-hump-report.md)。
198
198
 
199
- → [投资人白皮书](docs/Progmune_投资人白皮书_v2.0.html) · [信任决策模型](docs/ai-trust-decision-model-v1.md)
199
+ → [投资人白皮书](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/Progmune_投资人白皮书_v2.0.html) · [信任决策模型](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/ai-trust-decision-model-v1.md)
200
200
 
201
201
  ---
202
202
 
203
203
  ## 贡献
204
204
 
205
- 架构与代码规范见 [CLAUDE.md](CLAUDE.md),开发流程见 [CONTRIBUTING.md](CONTRIBUTING.md)。
205
+ 架构与代码规范见 [CLAUDE.md](https://github.com/shenlian19831109/progmune-runtime/blob/main/CLAUDE.md),开发流程见 [CONTRIBUTING.md](https://github.com/shenlian19831109/progmune-runtime/blob/main/CONTRIBUTING.md)。
206
206
 
207
207
  高价值贡献方向:
208
208
  - **框架适配器**(Express、Next.js、FastAPI)——#1 产品缺口
@@ -225,4 +225,4 @@ Progmune 建立在"**LLM 输出是统计表演而非推理**"这一前提上—
225
225
 
226
226
  ## License
227
227
 
228
- MIT — [LICENSE](LICENSE)
228
+ MIT — [LICENSE](https://github.com/shenlian19831109/progmune-runtime/blob/main/LICENSE)
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ /**
3
+ * Phase 12: Progmune Agent CLI — `progmune agent "意图"`
4
+ *
5
+ * P1 最小 agent loop 的命令行入口。免疫门在环内:意图 → 目标分解 →
6
+ * execute()(plan→8门验证→SSG修复→emit→写盘+指纹)→ 编译/指纹验证门 →
7
+ * 失败反馈重试 → 带指纹 diff 输出。
8
+ *
9
+ * Usage:
10
+ * npx ts-node src/agent-cli.ts "实现 XX" [options]
11
+ * npm run agent -- "实现 XX" [options] (构建后)
12
+ *
13
+ * Options:
14
+ * --file <path> 输出文件(相对 project 目录)
15
+ * --project <dir> 目标项目目录(默认 CWD)
16
+ * --iterations <n> 最大迭代轮数(默认 5)
17
+ * --retries <n> 每轮最大重试(默认 3)
18
+ * --timeout <ms> 单次执行超时毫秒(默认 120000)
19
+ * --context 注入 git 仓库上下文(默认开启)
20
+ * --no-context 关闭 git 上下文注入
21
+ * --test 编译/指纹通过后追加项目测试门
22
+ * --json JSON 输出
23
+ * --help, -h 显示帮助
24
+ */
25
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ var desc = Object.getOwnPropertyDescriptor(m, k);
28
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
29
+ desc = { enumerable: true, get: function() { return m[k]; } };
30
+ }
31
+ Object.defineProperty(o, k2, desc);
32
+ }) : (function(o, m, k, k2) {
33
+ if (k2 === undefined) k2 = k;
34
+ o[k2] = m[k];
35
+ }));
36
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
37
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
38
+ }) : function(o, v) {
39
+ o["default"] = v;
40
+ });
41
+ var __importStar = (this && this.__importStar) || (function () {
42
+ var ownKeys = function(o) {
43
+ ownKeys = Object.getOwnPropertyNames || function (o) {
44
+ var ar = [];
45
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
46
+ return ar;
47
+ };
48
+ return ownKeys(o);
49
+ };
50
+ return function (mod) {
51
+ if (mod && mod.__esModule) return mod;
52
+ var result = {};
53
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
54
+ __setModuleDefault(result, mod);
55
+ return result;
56
+ };
57
+ })();
58
+ Object.defineProperty(exports, "__esModule", { value: true });
59
+ const path = __importStar(require("path"));
60
+ const agent_loop_1 = require("./agent-loop");
61
+ const args = process.argv.slice(2);
62
+ // ── Help ──
63
+ if (args.includes("--help") || args.includes("-h")) {
64
+ console.log(`
65
+ Progmune Agent — 免疫门在环内的自主实现循环 (P1)
66
+
67
+ Usage:
68
+ npx ts-node src/agent-cli.ts "实现 XX" [options]
69
+ npm run agent -- "实现 XX" [options]
70
+
71
+ Options:
72
+ --file <path> 输出文件(相对 project 目录)
73
+ --project <dir> 目标项目目录(默认当前目录)
74
+ --iterations <n> 最大迭代轮数(默认 5)
75
+ --retries <n> 每轮最大重试(默认 3)
76
+ --timeout <ms> 单次执行超时毫秒(默认 120000)
77
+ --context 注入 git 仓库上下文(默认开启)
78
+ --no-context 关闭 git 上下文注入
79
+ --test 编译/指纹通过后追加项目测试门
80
+ --json JSON 输出
81
+ --help, -h 显示帮助
82
+
83
+ Example:
84
+ npm run agent -- "实现会话刷新函数" --project demo-project --file refresh_session.ts
85
+ `);
86
+ process.exit(0);
87
+ }
88
+ // ── Arg parsing ──
89
+ function parseArgs(argv) {
90
+ const intentParts = [];
91
+ let file;
92
+ let project = process.cwd();
93
+ let iterations = 5;
94
+ let retries = 3;
95
+ let timeout = 120000;
96
+ let context = true;
97
+ let test = false;
98
+ let json = false;
99
+ for (let i = 0; i < argv.length; i++) {
100
+ const a = argv[i];
101
+ if (a === "--file") {
102
+ file = argv[++i];
103
+ }
104
+ else if (a === "--project") {
105
+ project = argv[++i];
106
+ }
107
+ else if (a === "--iterations") {
108
+ iterations = parseInt(argv[++i], 10) || 5;
109
+ }
110
+ else if (a === "--retries") {
111
+ retries = parseInt(argv[++i], 10) || 3;
112
+ }
113
+ else if (a === "--timeout") {
114
+ timeout = parseInt(argv[++i], 10) || 120000;
115
+ }
116
+ else if (a === "--context") {
117
+ context = true;
118
+ }
119
+ else if (a === "--no-context") {
120
+ context = false;
121
+ }
122
+ else if (a === "--test") {
123
+ test = true;
124
+ }
125
+ else if (a === "--json") {
126
+ json = true;
127
+ }
128
+ else {
129
+ intentParts.push(a);
130
+ }
131
+ }
132
+ const intent = intentParts.join(" ").trim();
133
+ if (!intent) {
134
+ console.error("❌ 缺少意图参数。用法: progmune agent \"实现 XX\" [--file path] [--project dir]");
135
+ process.exit(2);
136
+ }
137
+ return { intent, file, project, iterations, retries, timeout, context, test, json };
138
+ }
139
+ // ── Formatting ──
140
+ function printAttempt(i, r) {
141
+ const a = r.attempts[i];
142
+ const mark = a.success ? "✅" : "❌";
143
+ const testGate = a.testRan ? ` test=${a.testPass ? "pass" : "FAIL"}` : "";
144
+ const gates = a.success
145
+ ? `compile=${a.compilePass} marker=${a.markerPass}${testGate}`
146
+ : `compile=${a.compilePass} marker=${a.markerPass}${testGate}${a.error ? ` err=${a.error.slice(0, 80)}` : ""}`;
147
+ console.log(`[#${a.attempt}] iter ${a.iteration} retry ${a.attempt - 1 - (a.iteration - 1) * 3} ${mark} ` +
148
+ `session=${a.sessionId || "-"} fp=${a.fingerprint || "-"} repair=${a.repairCount} ${gates}`);
149
+ }
150
+ function printResult(r, opts) {
151
+ console.log("");
152
+ if (r.success) {
153
+ console.log(`✅ 完成: intent="${opts.intent}"`);
154
+ if (r.filePath)
155
+ console.log(` 文件: ${r.filePath}`);
156
+ console.log(` 指纹: ${r.fingerprint}`);
157
+ console.log(` 迭代: ${r.iterations} 轮 / 重试: ${r.retries} 次${r.degraded ? " / ⚠️ 降级(LLM 回退)" : ""}`);
158
+ if (r.irDelta) {
159
+ console.log(` IR 增量: +${r.irDelta.added.length} -${r.irDelta.removed.length}` +
160
+ (r.irDelta.added.length > 0 ? ` 新增: ${r.irDelta.added.join(", ")}` : ""));
161
+ }
162
+ console.log(` 审计事件: ${r.auditTrail.length} 条(含 ${r.attempts.length} 次尝试记录)`);
163
+ console.log("");
164
+ console.log("── diff ──");
165
+ console.log(r.diff.slice(0, 2000) || "(空)");
166
+ }
167
+ else {
168
+ console.log(`❌ 失败: intent="${opts.intent}" 共 ${r.attempts.length} 次尝试`);
169
+ console.log(` 最后错误: ${r.attempts[r.attempts.length - 1]?.error || "迭代耗尽"}`);
170
+ console.log(` 审计轨迹 ${r.auditTrail.length} 条事件(可回放)`);
171
+ }
172
+ }
173
+ // ── Main ──
174
+ async function main() {
175
+ const opts = parseArgs(args);
176
+ const projectPath = path.resolve(opts.project);
177
+ // 切到项目目录:execute 写 ir.json 到 CWD,verifyCompiles 跑项目 tsconfig,
178
+ // git diff 也相对项目。dotenv/.env 在模块加载时已按启动 CWD 读取。
179
+ process.chdir(projectPath);
180
+ console.log(`⚙️ Progmune Agent (P2+P3) — 免疫门在环内`);
181
+ console.log(` 意图: ${opts.intent}`);
182
+ console.log(` 项目: ${projectPath}`);
183
+ console.log(` 输出: ${opts.file ? path.resolve(opts.file) : "(未指定)"}`);
184
+ console.log(` 感知: git上下文=${opts.context ? "开" : "关"} 测试门=${opts.test ? "开" : "关"}`);
185
+ console.log("");
186
+ const result = await (0, agent_loop_1.runAgentLoop)({
187
+ projectPath,
188
+ intent: opts.intent,
189
+ filePath: opts.file,
190
+ maxIterations: opts.iterations,
191
+ maxRetries: opts.retries,
192
+ timeoutMs: opts.timeout,
193
+ includeContext: opts.context,
194
+ runTests: opts.test,
195
+ });
196
+ if (opts.json) {
197
+ console.log(JSON.stringify(result, null, 2));
198
+ }
199
+ else {
200
+ console.log(` 目标分解: ${result.subgoals.length > 0 ? result.subgoals.join(" → ") : "无模板命中"}`);
201
+ result.attempts.forEach((_, i) => printAttempt(i, result));
202
+ printResult(result, { intent: opts.intent, file: opts.file });
203
+ }
204
+ process.exit(result.success ? 0 : 1);
205
+ }
206
+ main().catch((e) => {
207
+ console.error(`❌ Agent CLI 异常: ${e?.message || e}`);
208
+ process.exit(1);
209
+ });