progmune-runtime 3.6.1 → 3.7.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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.7.0] — 2026-08-23
4
+
5
+ ### 新增:P4.6 跨函数传播(入口展开 + 片段抑制)
6
+
7
+ - `src/call-sequence.ts`:`buildCallSequences` 共享序列构建——入口函数(不被项目函数调用)的调用链做传递展开(内联被调项目函数体,深度 ≤4、环安全);非入口函数的孤立片段不再单独验证(违规归因到调用它的入口),消除 helper 片段误报
8
+ - 规则名函数与叶子原语(函数体只调外部调用)不内联——协议原语只在调用链内验证,调用名保留给匹配层
9
+ - trust 引擎接线:`extractCallSequencesFromIR` 换用 `buildCallSequences`,规则名集合作为展开保留单元;生效范围如实记录——ir.json 为函数数组形态(协议盲测语料 / extractIR 直出)时 P4.6 生效;合并形态 `{ typeMap, functions }`(execute/MCP 写盘)沿用既有回退路径(3.5.0 起的既有行为,恢复 IR-first 需先做词段匹配门控的 FP 打磨)
10
+ - 边界(与 C 的 L3 同类,如实记录):展开是语法内联(调用链扁平化),不做数据流/指针/分支分析
11
+
12
+ ### 新增:协议盲测 v1.2(跨函数 + 任意命名变体)
13
+
14
+ - 语料网格扩至 38 项目:T0–T5 × S1–S5(30)+ T6/T7 × S1–S4(8);新增违规类 T6 cross_function_precondition、T7 cross_function_cleanup、风格 S5 renamed(无 `@progmune` 注解 + 改名协议函数,词段匹配验证)
15
+ - **复测结果:66 可测金标,检出 64(Recall 97%)/ Precision 100% / 0 FP**;2 处漏检为 T2×S5 注解依赖前置约束(无注解项目级前置不可恢复,命名匹配本身正常),金标与基线如实单列
16
+ - 回归测试 `tests/python-protocol-benchmark.test.ts` 扩至 6 例(T1 broken / T0 clean 含分离式清洁链 / T5 endState / T6 cross-function / S5 renamed)
17
+
18
+ ### 文档
19
+
20
+ - 覆盖矩阵(中英)Python 协议行(Auth / Resource Lifecycle)由 ⚠️ 升级 ✅,证据引用协议盲测 v1.2;升级条件(跨函数传播、任意命名验证)全部勾选
21
+ - 基线 `BASELINE_PROTOCOL_PYTHON_v1.md` 更新至 v1.2:语料、结果、已知缺口(注解依赖 / LLM 桥接不在测量范围 / P4.6 展开语义边界)如实记录
22
+
3
23
  ## [3.6.1] — 2026-08-23
4
24
 
5
25
  ### 文档
@@ -22,8 +22,11 @@ function isProjectFn(f) {
22
22
  /**
23
23
  * 从 IR 构建验证序列:入口函数展开 + 非入口抑制。
24
24
  * @param ir - FunctionInfo 列表(TS 或 Python 提取器输出)
25
+ * @param keepNames - 协议规则名集合:命中这些名字的项目函数是验证单元
26
+ * (其调用名保留给规则匹配),不内联其函数体——否则 create_session 等
27
+ * 规则函数的平凡函数体会把调用名"吞掉"
25
28
  */
26
- function buildCallSequences(ir) {
29
+ function buildCallSequences(ir, keepNames) {
27
30
  const fnMap = new Map();
28
31
  for (const f of ir) {
29
32
  if (isProjectFn(f))
@@ -39,19 +42,30 @@ function buildCallSequences(ir) {
39
42
  calledBy.add(c);
40
43
  }
41
44
  }
42
- const expand = (name, depth, visiting) => {
43
- if (depth > MAX_DEPTH || visiting.has(name))
44
- return [];
45
- const fn = fnMap.get(name);
46
- if (!fn)
47
- return [name]; // 外部调用:保留给规则匹配
48
- visiting.add(name);
45
+ /** 展开函数体内的调用(入口序列 = 函数体调用,不含函数自己的名字) */
46
+ const expandBody = (fn, depth, visiting) => {
49
47
  const out = [];
50
48
  for (const c of fn.calls || []) {
51
49
  if (typeof c !== "string" || c.startsWith("__progmune_"))
52
50
  continue;
53
- out.push(...expand(c, depth + 1, visiting));
51
+ out.push(...expandCall(c, depth, visiting));
54
52
  }
53
+ return out;
54
+ };
55
+ const expandCall = (name, depth, visiting) => {
56
+ if (depth > MAX_DEPTH || visiting.has(name))
57
+ return [];
58
+ const fn = fnMap.get(name);
59
+ // 外部调用或规则函数:调用名保留给匹配层,不内联
60
+ if (!fn || (keepNames && keepNames.has(name)))
61
+ return [name];
62
+ // 叶子函数(函数体只调外部原语)是协议原语或叶子 helper:
63
+ // 保留名字,不内联——否则 S5 改名协议函数的平凡函数体会吞掉调用名
64
+ const hasProjectCalls = (fn.calls || []).some((c) => fnMap.has(c));
65
+ if (!hasProjectCalls)
66
+ return [name];
67
+ visiting.add(name);
68
+ const out = expandBody(fn, depth + 1, visiting);
55
69
  visiting.delete(name);
56
70
  return out;
57
71
  };
@@ -61,7 +75,9 @@ function buildCallSequences(ir) {
61
75
  continue;
62
76
  if (calledBy.has(f.name))
63
77
  continue; // 非入口:片段并入调用方
64
- const calls = expand(f.name, 0, new Set());
78
+ if (keepNames && keepNames.has(f.name))
79
+ continue; // 协议原语不是入口:只在调用链内验证
80
+ const calls = expandBody(f, 0, new Set());
65
81
  if (calls.length === 0)
66
82
  continue;
67
83
  sequences.push({ calls, file: f.file, function: f.name });
@@ -62,6 +62,7 @@ const api_semantic_mapper_1 = require("./api-semantic-mapper");
62
62
  const protocol_domain_validator_1 = require("./protocol-domain-validator");
63
63
  const call_graph_propagator_1 = require("./call-graph-propagator");
64
64
  const ssg_bridge_1 = require("./ssg-bridge");
65
+ const call_sequence_1 = require("../call-sequence");
65
66
  // ── Main Entry Point ──
66
67
  async function evaluateTrust(ctx) {
67
68
  const engineVersion = "trust-runtime-v1.0.0";
@@ -719,12 +720,13 @@ async function collectProtocolViolations(ctx, callGraph) {
719
720
  }
720
721
  catch { /* best-effort — 回退正则扫描 */ }
721
722
  }
723
+ // ── SSG State Machine: load protocol rules once ──
724
+ protocolRulesData = (0, ssg_bridge_1.loadProtocolRules)(ctx.projectPath);
722
725
  // ── Phase 1-5 Semantic Pipeline ──
723
- const callSequences = extractCallSequencesFromProject(ctx.projectPath, ctx.language);
726
+ // 规则名集合作为展开的保留单元:规则函数不内联(调用名保留给匹配层)
727
+ const callSequences = extractCallSequencesFromProject(ctx.projectPath, ctx.language, protocolRulesData ? new Set(protocolRulesData.rules.keys()) : undefined);
724
728
  const flaggedCount = { value: 0 };
725
729
  const cleanCount = { value: 0 };
726
- // ── SSG State Machine: load protocol rules once ──
727
- protocolRulesData = (0, ssg_bridge_1.loadProtocolRules)(ctx.projectPath);
728
730
  // ── P4.5: 合并项目 IR 注解协议(IR 优先,缺 namespace 继承内置 JSON) ──
729
731
  // 内置 protocols.json 的规则是通用弱约束(如 generate_jwt pre=[]),
730
732
  // 项目文件里的 @protocol 注解才是项目真实协议(如 pre=[PASSWORD_VERIFIED])。
@@ -904,20 +906,21 @@ async function collectProtocolViolations(ctx, callGraph) {
904
906
  } : undefined,
905
907
  };
906
908
  }
907
- function extractCallSequencesFromProject(projectPath, language) {
908
- // P4.5: 优先 IR 精确序列(每个函数体内的真实调用,从各自入口验证)
909
- const irSequences = extractCallSequencesFromIR(projectPath);
909
+ function extractCallSequencesFromProject(projectPath, language, keepNames) {
910
+ // P4.5/P4.6: 优先 IR 精确序列(入口函数展开 + 非入口抑制,跨函数传播)
911
+ const irSequences = extractCallSequencesFromIR(projectPath, keepNames);
910
912
  if (irSequences.length > 0)
911
913
  return irSequences;
912
914
  // 回退:正则扫描(C 等无 IR 语言保持原行为)
913
915
  return extractCallSequencesRegex(projectPath, language);
914
916
  }
915
917
  /**
916
- * P4.5: 从 ir.json 构建 per-function 调用序列。
917
- * 每个函数体内的 calls[] 是一条独立序列(从协议初始状态起步验证)——
918
- * 函数声明名单不再是验证对象;语义 marker(__progmune_*)供规则消费,不作真实调用。
918
+ * P4.5/P4.6: 从 ir.json 构建验证序列——入口函数展开 + 非入口抑制
919
+ * (共享实现见 src/call-sequence.ts buildCallSequences):
920
+ * 函数声明名单不再是验证对象;语义 marker(__progmune_*)供规则消费,
921
+ * 不作真实调用;被项目函数调用的函数片段并入调用方展开序列。
919
922
  */
920
- function extractCallSequencesFromIR(projectPath) {
923
+ function extractCallSequencesFromIR(projectPath, keepNames) {
921
924
  try {
922
925
  const fs = require("fs");
923
926
  const irPath = path.join(projectPath, "ir.json");
@@ -926,18 +929,7 @@ function extractCallSequencesFromIR(projectPath) {
926
929
  const ir = JSON.parse(fs.readFileSync(irPath, "utf-8"));
927
930
  if (!Array.isArray(ir))
928
931
  return [];
929
- const sequences = [];
930
- for (const f of ir) {
931
- const calls = (f.calls || []).filter((c) => typeof c === "string" && !c.startsWith("__progmune_"));
932
- if (calls.length === 0)
933
- continue;
934
- sequences.push({
935
- calls,
936
- file: String(f.file || ""),
937
- function: String(f.name || "unknown"),
938
- });
939
- }
940
- return sequences;
932
+ return (0, call_sequence_1.buildCallSequences)(ir, keepNames);
941
933
  }
942
934
  catch {
943
935
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "progmune-runtime",
3
- "version": "3.6.1",
3
+ "version": "3.7.0",
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/",