progmune-runtime 3.7.4 → 3.7.5

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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.7.5] — 2026-08-27
4
+
5
+ ### C 真实语料验证 + 注解驱动演示 + 引擎修复(DSH 双轮评审合入)
6
+
7
+ - **修复(DSH):单行指针返回函数系统性漏提取**——`char *foo(`/`SSL *foo(` 类定义被 `(?:^|\s)` 锚点漏掉(名字前是 `*` 非空白);改为 lookbehind `(?<![a-zA-Z0-9_])` + 回归测试。openssl 等指针密集型仓库补回 ~1,500 函数(如 openssl 15,539 含指针修复与表面过滤的净效果)
8
+ - **修复:P4.6 展开兆级序列**(DSH 实测 openssl 单序列可达 1M+ 调用、全扫描 15–25 分钟)——`buildCallSequences` 预算制展开(`MAX_SEQUENCE_CALLS=2000` 可注入,入口自身调用按序优先、超预算即停,`CallSequence.truncated` 标记,不去重——重复调用对状态机有语义);openssl 全扫描 **15–25 分钟 → 222s**。零漂移前置实测:Python 盲测语料最大序列 23、TS 自身 IR 最大 824(预算零影响),Python 盲测复跑 64 违规不变。**截断是诚实的召回边界**(超大序列尾部违规不可见,非静默回归)
9
+ - **真实语料四仓库**(libssh/redis/nginx/openssl):24 flags 全部人工标注 FP(0 TP)——误报类别稳定(OS API 桥接 11、回调 endState、包装器词段、跨函数窗口),keyword 白名单方向的观测前提已达标待决策;稳定指标 = 黄金函数恢复率 97–100%
10
+
11
+ - **真实 C 语料验证 v1**(`blind-benchmark/scan-real-c.ts` + `REALWORLD_C_V1.md`):生产管线扫 libssh/redis/nginx——表面过滤后 16 flags 逐条人工标注全 FP(真实误报率观测:标记精确率 0%);「命名鸿沟」发现(exact-name 0 次触发,合成金标 95.7% F1 全靠按名+注解命中);误报源分类:回调生命周期 endState 12 / OS API 关键词桥接 3 / 跨函数窗口 1
12
+ - **提取器非生产表面过滤**(对齐 `tools/extract_ir.py` Python 先例):`collectCFiles` 跳过 `tests/test/examples/docs/docs_src/scripts/deps/vendor/third_party` 目录与 `test_*.c`/`*_test.c`——libssh 63→1、redis 1→0 条 flags;C 金标恢复率零漂移(97/97/89/98/100/99)
13
+ - **注解驱动真实项目演示**(`demo-real-c-redis/` + `REALWORLD_C_V2.md`):真实 redis acl.c 代码 + 3 条注解 → 合法流 APPROVED 85 零误报、植入 missing-auth-check 精确定位;标注成本 ~3 注解/协议——**注解驱动是 C 生产化的现实形态,可行性已验证**
14
+ - **引擎修复①(CamelCase 注解规则不可触达)**:注解合并同步注册 normalized 形态(加性,snake_case 注解零变化)
15
+ - **引擎修复②(注解合并晚于序列构建)**:P4.5 合并移到 `extractCallSequencesFromProject` 之前——有函数体的注解原语不再被内联掉、post 状态生效;与盲测 harness 语义对齐
16
+ - **引擎修复③(fixPath 输出真实函数名)**:`StateAnnotation.displayName` 机制——注解合并记录真实函数名,BFS 展开项目原语优先(stable sort 零漂移)+ 渲染映射;修复建议从通用规则名(`verify_token`)变为项目真实函数(`checkPasswordBasedAuth`),sdk 修复解析直接插入真实调用。三处边界如实记录:establish 赋值状态机不可见(L4 不投入)、模块认证 hook 在状态机外、单条 medium 违规不翻转 APPROVED(决策阈值层独立议题)
17
+ - **零漂移验证**:Python 协议盲测 v1.2 复跑 64 违规(报告仅时间戳差异);引擎相关套件 113/113 + 2 个新回归测试(tests/trust/engine.test.ts)
18
+ - **如实记录**:C 语言状态标签维持「研究」;不修项(按评估决策)——establish 赋值不可见(L4 不投入)、medium 违规不翻转 APPROVED(累计扣分设计逻辑,非缺陷)
19
+
3
20
  ## [3.7.4] — 2026-08-26
4
21
 
5
22
  ### 新增:C 语言 IR 提取(注册表第三语言)
@@ -7,7 +24,7 @@
7
24
  - **`src/extract-ir-c.ts`**:纯 TS C 提取器(无子进程桥、无原生依赖)——函数签名(含多行、`static`/`inline`/`__attribute__`、指针/数组/函数指针参数)、调用列表(成员调用取 `->`/`.` 后的调用名,`goto` 合成 `goto_<label>`)、`@progmune`/`@protocol` 注解与 `@purpose/@tags/@requires/@produces/@useWhen/@inputs/@outputs` 文档标签(C 注释块镜像 Python 装饰器语法);注释/字符串感知的括号计数(修复 v2 提取器已知缺口,未改动 `sequence-extractor`——C 金标基准管线保持不动)
8
25
  - **`LANGUAGE_EXTRACTORS` 注册 `c`**(detect `.c`/`.h`,extract `extractIRC`)——agent 循环、execute() 的 ir.json 写入与 MCP 自动生效;C 项目从纯正则回退切换到 IR-first 序列验证 + SSG 状态机,C 函数名进入词段匹配门控(仅项目函数);协议行与 protocols.json 规则名(`verify_password` 等)按名命中
9
26
  - **端到端验证**:临时 C 项目上 extractProjectIR → evaluateTrust 走通——4 条植入违规全部精确定位(内置 auth×2 / db×1 + 自定义 pay 命名空间注解×1),合法链零误报(NEEDS_REVIEW 72 分);**应用级 C 金标 v1**(`blind-benchmark/scan-protocol-c-app.ts`,镜像 Python 盲测方法学):10 clean × 7 违规 → **P=87.5% / R=100% / F1=93.3%**(唯一 FP 为跨函数窗口边界,与 Python 盲测 T2×S5 同类)
10
- - **规模化提取**(`blind-benchmark/scan-protocol-c.ts`):6 个 vendored 仓库(curl 4192 / libssh 3689 / nginx 2970 / openssl 14394 / nghttp2 1274 / redis 9590 函数)秒级提取,黄金函数恢复率 8199%;旧 TLS 级金标上 SSG 命中 0/38(口径差异:SSG 无 TLS 规则,如实记录);nginx 3 FP 为 `ngx_*` 前缀包装器撞词段匹配(引擎层问题,记录待议,未动 SSG 桥避免 TS/Python 漂移)
27
+ - **规模化提取**(`blind-benchmark/scan-protocol-c.ts`):6 个 vendored 仓库(curl 5068 / libssh 3989 / nginx 3199 / openssl 15896 / nghttp2 1315 / redis 10170 函数,3.7.4 发布时代码状态——后续版本口径见 3.7.5)秒级提取,黄金函数恢复率 89100%;旧 TLS 级金标上 SSG 命中 0/38(口径差异:SSG 无 TLS 规则,如实记录);nginx 3 FP 为 `ngx_*` 前缀包装器撞词段匹配(引擎层问题,记录待议,未动 SSG 桥避免 TS/Python 漂移)
11
28
  - **修复:签名正则指数级回溯**——v2 风格类型 token 循环对 `name = ssh_userauth_kbdint_getname(...)` 类行穷举标识符切分(44 字符缓冲 ~11s),改为候选迭代(跳过关键字/类型名候选,返回类型从缓冲区前缀推导);libssh 提取 >15min(病态)→ 1.8s,回归测试已加
12
29
  - **评审修复轮(detect/extract 口径、死代码、TU 绑定等)**:①`hasSourceFiles` SKIP_DIRS 补 `benchmarks`(与 extract 口径一致,本仓库自身不再误标 C);②`#if 0` 死代码块预处理剥离(真实仓库不平衡花括号不再腐蚀函数体计数);③顶层 `#` 行只跳自身不再吞相邻函数(openssl 14,394→15,896 函数,黄金函数恢复率升至 89–100%);④`buildCallSequences` 同文件定义优先绑定(跨文件同名 static 不再 last-wins 错绑,入口判定文件化;Python 盲测 v1.2 复测零漂移——报告与基线逐字节一致仅时间戳不同);⑤提取器取消调用去重(状态机重复调用有语义,双 close/重复 logout 可检出,与 TS/Python 提取器一致);⑥删死代码 `isCProject`;⑦混合 TS+C 项目回归测试。应用级 C 金标扩至 v2(11 clean × 11 违规 + helper 中介风格 + 逐命名空间分解):**TP 11/11 FP 1 FN 0 → P=91.7% / R=100% / F1=95.7%**(唯一 FP 为 do_logout 跨函数窗口边界)。已知系统性风险文档化:C 前缀包装器(`ngx_*` 等)撞词段匹配(nginx 3 FP),缓解方案(前缀剥离/连续词段)留待下一轮并强制盲测复跑
13
30
  - **限制如实记录**:函数指针分发静态不可见(L3 结论不变)、宏/K&R/C++ 不解析、无数据流/指针分析(L4 无计划);提取器遍历跳过 vendored `benchmarks/`;`docs/c-language-status.md` 已更新(新路线小节 + 基准结果 + Decision record)
package/README.md CHANGED
@@ -154,7 +154,7 @@ Public, reproducible precision data. All numbers measured against gold-annotated
154
154
 
155
155
  ### C (IR extraction + app-level protocol verification — research status)
156
156
 
157
- Since 3.7.4, C has an IR extractor in the multi-language registry: C projects flow into IR-first sequence validation + the SSG state machine. App-level protocol lifecycles (auth/db/file/payment) are verifiable on C — app-level gold v2: **11/11 violations caught (Recall 100%), 1 FP, F1=95.7%**; extraction scales to 10k+ functions per repo in seconds with 89–100% gold-function recovery (curl/libssh/nginx/openssl/nghttp2/redis). Two boundaries remain: the old regex-route gold benchmark F1=16.5% measured **TLS-level misuse** (SSG has no TLS state machines — that gap is unchanged), and L3/L4 conclusions stand (function-pointer dispatch is statically invisible; no pointer/CFG analysis planned). See [C Language Status](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/c-language-status.md) for the full picture and reasoning.
157
+ Since 3.7.4, C has an IR extractor in the multi-language registry: C projects flow into IR-first sequence validation + the SSG state machine. App-level protocol lifecycles (auth/db/file/payment) are verifiable on C — app-level gold v2: **11/11 violations caught (Recall 100%), 1 FP, F1=95.7%**; annotation-driven verification validated on real redis ACL code (demo-real-c-redis). Extraction covers large real repos in seconds (openssl 15.5k / redis 5.7k / curl 4.2k functions, gold-function recovery 97–100%). Two boundaries remain: the old regex-route gold benchmark F1=16.5% measured **TLS-level misuse** (SSG has no TLS state machines — that gap is unchanged), and L3/L4 conclusions stand (function-pointer dispatch is statically invisible; no pointer/CFG analysis planned). See [C Language Status](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/c-language-status.md) for the full picture and reasoning.
158
158
 
159
159
  ### P0-P3 Rule Injection (2026-08)
160
160
 
package/README.zh-CN.md CHANGED
@@ -154,7 +154,7 @@ Progmune 对能验证什么、不能验证什么保持诚实。
154
154
 
155
155
  ### C(IR 提取 + 应用级协议验证——研究状态)
156
156
 
157
- 3.7.4 起 C 拥有多语言注册表中的 IR 提取器:C 项目进入 IR-first 序列验证 + SSG 状态机。应用级协议生命周期(认证/数据库/文件/支付)在 C 上可验证——应用级金标 v2:**11/11 违规全检出(召回 100%)、1 误报、F1=95.7%**;提取规模化至每仓库 1 万+ 函数、秒级完成、黄金函数恢复率 89–100%(curl/libssh/nginx/openssl/nghttp2/redis)。两条边界不变:旧正则口径黄金基准 F1=16.5% 测的是 **TLS 级误用**(SSG 无 TLS 状态机,该口径不变);L3/L4 结论维持(函数指针分发静态不可见;无指针/CFG 分析计划)。详见 [C 语言状态](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/c-language-status.md)。
157
+ 3.7.4 起 C 拥有多语言注册表中的 IR 提取器:C 项目进入 IR-first 序列验证 + SSG 状态机。应用级协议生命周期(认证/数据库/文件/支付)在 C 上可验证——应用级金标 v2:**11/11 违规全检出(召回 100%)、1 误报、F1=95.7%**;注解驱动验证在真实 redis ACL 代码上走通(demo-real-c-redis)。提取覆盖大型真实仓库(openssl 15.5k / redis 5.7k / curl 4.2k 函数,秒级,黄金函数恢复率 97–100%)。两条边界不变:旧正则口径黄金基准 F1=16.5% 测的是 **TLS 级误用**(SSG 无 TLS 状态机,该口径不变);L3/L4 结论维持(函数指针分发静态不可见;无指针/CFG 分析计划)。详见 [C 语言状态](https://github.com/shenlian19831109/progmune-runtime/blob/main/docs/c-language-status.md)。
158
158
 
159
159
  ### P0-P3 规则注入(2026-08)
160
160
 
@@ -13,10 +13,17 @@
13
13
  * 不做数据流/指针/分支分析;跨文件依赖 IR 的 calls[] 图。
14
14
  */
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.MAX_SEQUENCE_CALLS = void 0;
16
17
  exports.isProjectFn = isProjectFn;
17
18
  exports.collectProjectFunctionNames = collectProjectFunctionNames;
18
19
  exports.buildCallSequences = buildCallSequences;
19
20
  const MAX_DEPTH = 4;
21
+ /**
22
+ * 每序列调用预算上限。真实语料实测:Python 盲测语料 350 序列最大 23、
23
+ * TS 自身 IR 469 序列最大 824——2,000 对现有语料零影响;C 巨型函数
24
+ * (openssl 单序列可达 1M+ 调用)在预算处截断。
25
+ */
26
+ exports.MAX_SEQUENCE_CALLS = 2000;
20
27
  /** 项目函数判定:有真实文件且非外部导入条目(external 条目无函数体可内联)。 */
21
28
  function isProjectFn(f) {
22
29
  return !f.external && !!f.file && f.file !== "(external)";
@@ -53,7 +60,7 @@ function collectProjectFunctionNames(ir) {
53
60
  * (其调用名保留给规则匹配),不内联其函数体——否则 create_session 等
54
61
  * 规则函数的平凡函数体会把调用名"吞掉"
55
62
  */
56
- function buildCallSequences(ir, keepNames) {
63
+ function buildCallSequences(ir, keepNames, maxCalls = exports.MAX_SEQUENCE_CALLS) {
57
64
  // 全局按名回退 + 同文件优先映射:C 中跨文件同名 static 函数极常见
58
65
  // (每个 .c 都有 static cleanup/helper),名字级 Map 会让 last-wins 的
59
66
  // 定义绑定到错误的调用方。同翻译单元(文件)定义优先解析——
@@ -88,12 +95,23 @@ function buildCallSequences(ir, keepNames) {
88
95
  calledBy.add(fnKey(resolved.file, resolved.name));
89
96
  }
90
97
  }
98
+ /** 调用预算:预算制展开——入口自身调用按序优先,预算耗尽即停(截断),
99
+ * 不在事后截断百万级序列(内存/时间双浪费) */
100
+ const budget = { left: maxCalls, truncated: false };
91
101
  /** 展开函数体内的调用(入口序列 = 函数体调用,不含函数自己的名字) */
92
102
  const expandBody = (fn, depth, visiting) => {
103
+ if (budget.left <= 0) {
104
+ budget.truncated = true;
105
+ return [];
106
+ }
93
107
  const out = [];
94
108
  for (const c of fn.calls || []) {
95
109
  if (typeof c !== "string" || c.startsWith("__progmune_"))
96
110
  continue;
111
+ if (budget.left <= 0) {
112
+ budget.truncated = true;
113
+ return out;
114
+ }
97
115
  out.push(...expandCall(c, depth, visiting, fn.file));
98
116
  }
99
117
  return out;
@@ -102,14 +120,19 @@ function buildCallSequences(ir, keepNames) {
102
120
  if (depth > MAX_DEPTH || visiting.has(name))
103
121
  return [];
104
122
  const fn = resolveCall(fromFile, name);
105
- // 外部调用或规则函数:调用名保留给匹配层,不内联
106
- if (!fn || (keepNames && keepNames.has(name)))
123
+ // 外部调用或规则函数:调用名保留给匹配层,不内联(记 1 个调用)
124
+ if (!fn || (keepNames && keepNames.has(name))) {
125
+ budget.left--;
107
126
  return [name];
127
+ }
108
128
  // 叶子函数(函数体只调外部原语)是协议原语或叶子 helper:
109
129
  // 保留名字,不内联——否则 S5 改名协议函数的平凡函数体会吞掉调用名
110
130
  const hasProjectCalls = (fn.calls || []).some((c) => resolveCall(fn.file, c));
111
- if (!hasProjectCalls)
131
+ if (!hasProjectCalls) {
132
+ budget.left--;
112
133
  return [name];
134
+ }
135
+ // 内联:函数体自身的调用在递归内各自记账
113
136
  visiting.add(name);
114
137
  const out = expandBody(fn, depth + 1, visiting);
115
138
  visiting.delete(name);
@@ -123,10 +146,12 @@ function buildCallSequences(ir, keepNames) {
123
146
  continue; // 非入口:片段并入调用方
124
147
  if (keepNames && keepNames.has(f.name))
125
148
  continue; // 协议原语不是入口:只在调用链内验证
149
+ budget.left = maxCalls;
150
+ budget.truncated = false;
126
151
  const calls = expandBody(f, 0, new Set());
127
152
  if (calls.length === 0)
128
153
  continue;
129
- sequences.push({ calls, file: f.file, function: f.name });
154
+ sequences.push({ calls, file: f.file, function: f.name, truncated: budget.truncated || undefined });
130
155
  }
131
156
  return sequences;
132
157
  }
@@ -82,6 +82,46 @@ function fn(name, file, calls) {
82
82
  (0, vitest_1.expect)(seqs[0].calls).toEqual(["verify_password"]);
83
83
  });
84
84
  });
85
+ (0, vitest_1.describe)("buildCallSequences(调用预算 / 截断,兆级序列防护)", () => {
86
+ (0, vitest_1.it)("超预算截断:序列长度 = maxCalls,truncated 标记", () => {
87
+ const ext = Array.from({ length: 15 }, (_, i) => `ext_${i}`);
88
+ const ir = [fn("entry", "a.c", ext)];
89
+ const seqs = (0, call_sequence_1.buildCallSequences)(ir, undefined, 10);
90
+ (0, vitest_1.expect)(seqs).toHaveLength(1);
91
+ (0, vitest_1.expect)(seqs[0].calls).toHaveLength(10);
92
+ (0, vitest_1.expect)(seqs[0].calls).toEqual(ext.slice(0, 10)); // 入口自身调用按序优先
93
+ (0, vitest_1.expect)(seqs[0].truncated).toBe(true);
94
+ });
95
+ (0, vitest_1.it)("预算内序列:无 truncated 标记(现有语料零影响)", () => {
96
+ const ir = [fn("entry", "a.c", ["g", "h"])];
97
+ const seqs = (0, call_sequence_1.buildCallSequences)(ir, undefined, 2000);
98
+ (0, vitest_1.expect)(seqs).toHaveLength(1);
99
+ (0, vitest_1.expect)(seqs[0].calls).toEqual(["g", "h"]);
100
+ (0, vitest_1.expect)(seqs[0].truncated).toBeUndefined();
101
+ });
102
+ (0, vitest_1.it)("内联超预算:已发出的调用保留,入口后续调用被截(召回边界语义)", () => {
103
+ const bigBody = Array.from({ length: 20 }, (_, i) => `big_call_${i}`);
104
+ const ir = [
105
+ fn("helper", "a.c", ["ext"]), // 项目函数:big 因调它而可内联(叶子规则)
106
+ fn("big", "a.c", ["helper", ...bigBody]),
107
+ fn("entry", "a.c", ["big", "tail_call"]),
108
+ ];
109
+ const seqs = (0, call_sequence_1.buildCallSequences)(ir, undefined, 5);
110
+ (0, vitest_1.expect)(seqs).toHaveLength(1);
111
+ (0, vitest_1.expect)(seqs[0].calls).toEqual(["helper", "big_call_0", "big_call_1", "big_call_2", "big_call_3"]);
112
+ (0, vitest_1.expect)(seqs[0].truncated).toBe(true);
113
+ });
114
+ (0, vitest_1.it)("多入口各自独立预算", () => {
115
+ const ext = Array.from({ length: 8 }, (_, i) => `ext_${i}`);
116
+ const ir = [fn("e1", "a.c", ext), fn("e2", "b.c", ext)];
117
+ const seqs = (0, call_sequence_1.buildCallSequences)(ir, undefined, 5);
118
+ (0, vitest_1.expect)(seqs).toHaveLength(2);
119
+ for (const s of seqs) {
120
+ (0, vitest_1.expect)(s.calls).toHaveLength(5);
121
+ (0, vitest_1.expect)(s.truncated).toBe(true);
122
+ }
123
+ });
124
+ });
85
125
  (0, vitest_1.describe)("collectProjectFunctionNames", () => {
86
126
  (0, vitest_1.it)("全名/裸名/小写三形态收录", () => {
87
127
  const ir = [fn("FlowService.svc_x", "a.ts", [])];
@@ -64,6 +64,22 @@ const SKIP_DIRS = new Set([
64
64
  "node_modules", "dist", "build", ".git", ".progmune_corpus",
65
65
  "__pycache__", "venv", ".venv", "benchmarks",
66
66
  ]);
67
+ /**
68
+ * 非生产表面目录(与 tools/extract_ir.py 的 Python 先例对齐:
69
+ * "Skip test files — tests are not production surface for a security
70
+ * scanner"):安全扫描只看随产品发布的生产代码路径。真实 C 仓库验证
71
+ * (libssh/redis/nginx,scan-real-c.ts)中 65/79 条误报来自 tests/
72
+ * examples/ 与 vendored deps/(jemalloc)。
73
+ */
74
+ const NON_SURFACE_DIRS = new Set([
75
+ "tests", "test", "examples", "docs", "docs_src", "scripts",
76
+ "deps", "vendor", "third_party",
77
+ ]);
78
+ /** 测试文件名模式(test_*.c / *_test.c / *_test.h,Python 先例同款) */
79
+ function isTestFilename(name) {
80
+ const base = name.replace(/\.[^.]+$/, "");
81
+ return base.startsWith("test_") || base.endsWith("_test");
82
+ }
67
83
  /** Copied from sequence-extractor.ts:107-111 (kept local — decoupled benchmark path must not change). */
68
84
  const C_KEYWORDS = new Set([
69
85
  "if", "for", "while", "switch", "return", "sizeof", "typeof",
@@ -384,8 +400,12 @@ function stripAttributes(s) {
384
400
  * type-name candidates, and derive the return type from the buffer text
385
401
  * BEFORE the chosen candidate. `[^;]*?` keeps the params scan bounded.
386
402
  * Groups: 1 = name, 2 = params.
403
+ * Lookbehind anchor: the old `(?:^|\s)` silently dropped every single-line
404
+ * pointer-return definition (`char *foo(`, `SSL *foo(` — name preceded by
405
+ * `*`/`&`, not whitespace). `(?<![a-zA-Z0-9_])` allows those while still
406
+ * rejecting identifiers glued to the name.
387
407
  */
388
- const FUNC_CAND_RE = /(?:^|\s)([a-zA-Z_][a-zA-Z0-9_]*)\s*\(([^;]*?)\)\s*\{/g;
408
+ const FUNC_CAND_RE = /(?<![a-zA-Z0-9_])([a-zA-Z_][a-zA-Z0-9_]*)\s*\(([^;]*?)\)\s*\{/g;
389
409
  /** struct/union/enum definition bodies must be skipped, not parsed as functions. */
390
410
  const STRUCT_DECL_RE = /^(?:typedef\s+)?(?:struct|union|enum)\b/;
391
411
  /** Call-name + goto extraction filters. */
@@ -675,10 +695,10 @@ function collectCFiles(projectRoot) {
675
695
  for (const e of entries) {
676
696
  const full = path.join(dir, e.name);
677
697
  if (e.isDirectory()) {
678
- if (!SKIP_DIRS.has(e.name) && !e.name.startsWith("."))
698
+ if (!SKIP_DIRS.has(e.name) && !NON_SURFACE_DIRS.has(e.name) && !e.name.startsWith("."))
679
699
  stack.push(full);
680
700
  }
681
- else if (C_EXTENSIONS.has(path.extname(e.name))) {
701
+ else if (C_EXTENSIONS.has(path.extname(e.name)) && !isTestFilename(e.name)) {
682
702
  out.push(full);
683
703
  }
684
704
  }
@@ -359,6 +359,24 @@ int g(void) { return 1; }
359
359
  (0, vitest_1.expect)(Date.now() - t0).toBeLessThan(2000);
360
360
  (0, vitest_1.expect)(ir.map((x) => x.name)).toEqual(["f", "g"]);
361
361
  });
362
+ (0, vitest_1.it)("非生产表面目录被跳过:tests/examples/deps 与测试文件名(Python 先例同款)", () => {
363
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pm-surface-"));
364
+ try {
365
+ fs.writeFileSync(path.join(dir, "main.c"), "void prod(void) {}\n");
366
+ fs.mkdirSync(path.join(dir, "tests"), { recursive: true });
367
+ fs.writeFileSync(path.join(dir, "tests", "torture_x.c"), "void in_tests(void) {}\n");
368
+ fs.mkdirSync(path.join(dir, "examples"), { recursive: true });
369
+ fs.writeFileSync(path.join(dir, "examples", "demo.c"), "void in_examples(void) {}\n");
370
+ fs.mkdirSync(path.join(dir, "deps", "vendor_lib"), { recursive: true });
371
+ fs.writeFileSync(path.join(dir, "deps", "vendor_lib", "lib.c"), "void in_deps(void) {}\n");
372
+ fs.writeFileSync(path.join(dir, "helper_test.c"), "void testfile(void) {}\n");
373
+ const ir = (0, extract_ir_c_1.extractIRC)(dir);
374
+ (0, vitest_1.expect)(ir.map((f) => f.name)).toEqual(["prod"]);
375
+ }
376
+ finally {
377
+ fs.rmSync(dir, { recursive: true, force: true });
378
+ }
379
+ });
362
380
  (0, vitest_1.it)("#if 0 死代码块被剥离:体内不平衡花括号不腐蚀计数", () => {
363
381
  const ir = parse(`
364
382
  void f(void) {
@@ -398,3 +416,23 @@ void after(void) { h(); }
398
416
  (0, vitest_1.expect)(fn(ir, "maybe_live").calls).toEqual(["g"]);
399
417
  });
400
418
  });
419
+ (0, vitest_1.describe)("extract-ir-c pointer-return regression", () => {
420
+ (0, vitest_1.it)("单行指针返回函数必须被提取(char */SSL */const char */FILE * 等)", () => {
421
+ const src = [
422
+ "int a(void) { return 1; }",
423
+ "char *b(void) { return 0; }",
424
+ "SSL *c(SSL_CTX *ctx) { return 0; }",
425
+ "const char *d(int x) { return 0; }",
426
+ "static FILE *f(void) { return 0; }",
427
+ "int (*handler)(int) { return 0; }",
428
+ ].join("\n");
429
+ const fns = (0, extract_ir_c_1.parseCSource)(src, "ptr.c", "/");
430
+ const names = fns.map((f) => f.name);
431
+ (0, vitest_1.expect)(names).toEqual(vitest_1.expect.arrayContaining(["b", "c", "d", "f"]));
432
+ // 函数指针变量不是函数定义
433
+ (0, vitest_1.expect)(names).not.toContain("handler");
434
+ // 返回类型保留指针
435
+ const c = fns.find((f) => f.name === "c");
436
+ (0, vitest_1.expect)(c?.returnType).toBe("SSL *");
437
+ });
438
+ });
package/dist/sdk.js CHANGED
@@ -20,7 +20,7 @@ const risk_model_1 = require("./risk-model");
20
20
  const protocol_knowledge_1 = require("./protocol-knowledge");
21
21
  const evidence_repository_1 = require("./evidence-repository");
22
22
  /** Runtime version — stable public identifier. Internal layers evolve underneath. */
23
- exports.RUNTIME_VERSION = "3.7.4";
23
+ exports.RUNTIME_VERSION = "3.7.5";
24
24
  function verify(filePath) {
25
25
  const cert = (0, certify_1.certify)(filePath);
26
26
  const kb = (0, protocol_knowledge_1.buildKnowledgeBase)();
@@ -163,6 +163,13 @@ function findFixPathStatic(rules, namespace, current, targetPreStates) {
163
163
  nsFuncs.push({ name: fn, rule });
164
164
  }
165
165
  }
166
+ // 项目注解原语优先展开(修复路径输出真实函数名而非通用规则名);
167
+ // stable sort:无 displayName 的规则(内置/TS/Python 惯例)相对顺序不变
168
+ nsFuncs.sort((a, b) => {
169
+ const pa = a.rule.displayName ? 0 : 1;
170
+ const pb = b.rule.displayName ? 0 : 1;
171
+ return pa - pb;
172
+ });
166
173
  // BFS
167
174
  const startKey = [...new Set(current)].sort().join(",");
168
175
  const visited = new Set();
@@ -722,28 +722,15 @@ async function collectProtocolViolations(ctx, callGraph) {
722
722
  }
723
723
  // ── SSG State Machine: load protocol rules once ──
724
724
  protocolRulesData = (0, ssg_bridge_1.loadProtocolRules)(ctx.projectPath);
725
- // ── Phase 1-5 Semantic Pipeline ──
726
- // 规则名集合作为展开的保留单元:规则函数不内联(调用名保留给匹配层)
727
- const callSequences = extractCallSequencesFromProject(ctx.projectPath, ctx.language, protocolRulesData ? new Set(protocolRulesData.rules.keys()) : undefined);
728
- const flaggedCount = { value: 0 };
729
- const cleanCount = { value: 0 };
730
- // ── P4.6.1: 词段匹配门控的项目函数集合(best-effort,与注解合并共用 ir.json) ──
731
- // 词段匹配只对项目函数适用(改名协议原语);外部库调用走 alias/关键词桥接。
732
- let projectFunctions;
733
- try {
734
- const fs = require("fs");
735
- const irPath = path.join(ctx.projectPath, "ir.json");
736
- if (fs.existsSync(irPath)) {
737
- const ir = JSON.parse(fs.readFileSync(irPath, "utf-8"));
738
- const functions = Array.isArray(ir) ? ir : (ir.functions || []);
739
- projectFunctions = (0, call_sequence_1.collectProjectFunctionNames)(functions);
740
- }
741
- }
742
- catch { /* best-effort */ }
743
725
  // ── P4.5: 合并项目 IR 注解协议(IR 优先,缺 namespace 继承内置 JSON) ──
744
726
  // 内置 protocols.json 的规则是通用弱约束(如 generate_jwt pre=[]),
745
727
  // 项目文件里的 @protocol 注解才是项目真实协议(如 pre=[PASSWORD_VERIFIED])。
746
728
  // planner 已用此合并语义,trust 引擎需对齐,否则项目级前置约束不生效。
729
+ // 合并必须在序列构建【之前】:规则名是展开的保留单元(不内联),若合并
730
+ // 晚于 extractCallSequencesFromProject,注解原语(有函数体、调项目函数的)
731
+ // 会被内联掉,其 post 状态永不生效——真实 redis ACL 演示暴露(
732
+ // checkPasswordBasedAuth 被内联 → AUTHENTICATED 未建立 → good 流误报)。
733
+ // 与盲测 harness(scan-protocol-python)先合并后建序列的语义对齐。
747
734
  if (protocolRulesData) {
748
735
  try {
749
736
  const fs = require("fs");
@@ -761,12 +748,40 @@ async function collectProtocolViolations(ctx, callGraph) {
761
748
  if (existing?.namespace && !protocol.namespace) {
762
749
  protocol.namespace = existing.namespace;
763
750
  }
751
+ // 修复路径渲染真实函数名(fixPath 输出项目原语而非通用规则名)
752
+ protocol.displayName = String(f.name);
764
753
  protocolRulesData.rules.set(String(f.name), protocol);
754
+ // CamelCase 真实命名(C 代码普遍,如 ACLCheckAllPerm)注册的规则
755
+ // 原样无法被任何匹配策略触达(normalize 只作用于调用名;词段匹配
756
+ // 要求 ≥2 个下划线词段)——同步注册规范化形态使注解原语可被按名命中。
757
+ // 加性改动:snake_case 注解(TS/Python 惯例)normalized === 原名,无变化。
758
+ const normalized = (0, ssg_bridge_1.normalizeName)(String(f.name));
759
+ if (normalized !== String(f.name)) {
760
+ protocolRulesData.rules.set(normalized, protocol);
761
+ }
765
762
  }
766
763
  }
767
764
  }
768
765
  catch { /* best-effort */ }
769
766
  }
767
+ // ── Phase 1-5 Semantic Pipeline ──
768
+ // 规则名集合作为展开的保留单元:规则函数不内联(调用名保留给匹配层)
769
+ const callSequences = extractCallSequencesFromProject(ctx.projectPath, ctx.language, protocolRulesData ? new Set(protocolRulesData.rules.keys()) : undefined);
770
+ const flaggedCount = { value: 0 };
771
+ const cleanCount = { value: 0 };
772
+ // ── P4.6.1: 词段匹配门控的项目函数集合(best-effort,与注解合并共用 ir.json) ──
773
+ // 词段匹配只对项目函数适用(改名协议原语);外部库调用走 alias/关键词桥接。
774
+ let projectFunctions;
775
+ try {
776
+ const fs = require("fs");
777
+ const irPath = path.join(ctx.projectPath, "ir.json");
778
+ if (fs.existsSync(irPath)) {
779
+ const ir = JSON.parse(fs.readFileSync(irPath, "utf-8"));
780
+ const functions = Array.isArray(ir) ? ir : (ir.functions || []);
781
+ projectFunctions = (0, call_sequence_1.collectProjectFunctionNames)(functions);
782
+ }
783
+ }
784
+ catch { /* best-effort */ }
770
785
  for (const seq of callSequences) {
771
786
  try {
772
787
  const semantic = await (0, api_semantic_mapper_1.mapSequenceToSemanticWithLLM)(seq.calls);
@@ -50,6 +50,7 @@ var __importStar = (this && this.__importStar) || (function () {
50
50
  };
51
51
  })();
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.normalizeName = normalizeName;
53
54
  exports.validateSequenceWithSSG = validateSequenceWithSSG;
54
55
  exports.ssgViolationsToTrustViolations = ssgViolationsToTrustViolations;
55
56
  exports.loadProjectAliases = loadProjectAliases;
@@ -421,6 +422,8 @@ projectFunctions) {
421
422
  let fixPath = [];
422
423
  try {
423
424
  fixPath = (0, ssg_validator_1.findFixPathStatic)(rules, ruleNamespace, rejection.currentState, rejection.requiredState);
425
+ // 修复路径渲染真实函数名:项目注解原语的 displayName 优先于通用规则名
426
+ fixPath = fixPath.map((n) => rules.get(n)?.displayName ?? n);
424
427
  }
425
428
  catch {
426
429
  fixPath = rejection.missingFunctions || [];
@@ -482,18 +485,20 @@ projectFunctions) {
482
485
  if (!cur.includes(hs.state))
483
486
  continue;
484
487
  violatedCalls++;
488
+ // 释放函数渲染真实名(项目注解原语的 displayName 优先)
489
+ const releaseDisplay = rules.get(hs.releaseFn)?.displayName ?? hs.releaseFn;
485
490
  violations.push({
486
491
  callName: "(end-of-sequence)",
487
492
  namespace: hs.namespace,
488
493
  currentState: cur,
489
494
  requiredState: [],
490
- fixPath: [hs.releaseFn],
495
+ fixPath: [releaseDisplay],
491
496
  matchedRule: hs.releaseFn,
492
497
  endState: true,
493
498
  explanation: `SSG end-state violation: resource state [${hs.state}] ` +
494
499
  `acquired in this function is still held at end of sequence ` +
495
500
  `(namespace ${hs.namespace}, current [${cur.join(", ")}]) — ` +
496
- `missing release call: ${hs.releaseFn}.`,
501
+ `missing release call: ${releaseDisplay}.`,
497
502
  });
498
503
  trace.push({
499
504
  call: "(end-of-sequence)",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "progmune-runtime",
3
- "version": "3.7.4",
3
+ "version": "3.7.5",
4
4
  "description": "Progmune — AI Trust Decision Engine. Verify AI-generated code before it reaches production. Outputs APPROVED / NEEDS_REVIEW / BLOCKED with evidence.",
5
5
  "files": [
6
6
  "dist/",