progmune-runtime 3.6.0 → 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,32 @@
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
+
23
+ ## [3.6.1] — 2026-08-23
24
+
25
+ ### 文档
26
+
27
+ - README 社区章节直展双群二维码:微信(`assets/wechat-group.png`)+ WhatsApp(`assets/whatsapp-group.jpg`),中英双语同步
28
+ - 微信群码 7 天过期提醒 workflow 文案同步直展形态
29
+
3
30
  ## [3.6.0] — 2026-08-23
4
31
 
5
32
  ### 新增:SSG endState 检查(序列末尾资源未释放)
package/README.md CHANGED
@@ -197,10 +197,12 @@ SDK (src/sdk.ts) verify() → APPROVED / NEEDS_REVIEW / BLOCKED
197
197
  ## Community & Feedback
198
198
 
199
199
  <p align="center">
200
- <img src="https://raw.githubusercontent.com/shenlian19831109/progmune-runtime/main/assets/wechat-group.png" width="240" alt="Progmune user discussion group QR code" />
200
+ <img src="https://github.com/shenlian19831109/progmune-runtime/blob/main/assets/wechat-group.png?raw=true" width="200" alt="WeChat group QR code" />
201
+ &nbsp;&nbsp;&nbsp;
202
+ <img src="https://github.com/shenlian19831109/progmune-runtime/blob/main/assets/whatsapp-group.jpg?raw=true" width="200" alt="WhatsApp group QR code" />
201
203
  </p>
202
204
 
203
- Your feedback shapes Progmune. Scan the QR code to join the user discussion group (WeChat), or open a [GitHub Issue](https://github.com/shenlian19831109/progmune-runtime/issues) for bug reports, feature requests, and suggestions.
205
+ Your feedback shapes Progmune. Scan the QR code to join the user discussion group (WeChat / WhatsApp), or open a [GitHub Issue](https://github.com/shenlian19831109/progmune-runtime/issues) for bug reports, feature requests, and suggestions.
204
206
 
205
207
  ---
206
208
 
package/README.zh-CN.md CHANGED
@@ -196,10 +196,12 @@ SDK (src/sdk.ts) verify() → APPROVED / NEEDS_REVIEW / BLOCKED
196
196
  ## 社区与反馈
197
197
 
198
198
  <p align="center">
199
- <img src="https://raw.githubusercontent.com/shenlian19831109/progmune-runtime/main/assets/wechat-group.png" width="240" alt="Progmune 用户讨论群二维码" />
199
+ <img src="https://github.com/shenlian19831109/progmune-runtime/blob/main/assets/wechat-group.png?raw=true" width="200" alt="微信群二维码" />
200
+ &nbsp;&nbsp;&nbsp;
201
+ <img src="https://github.com/shenlian19831109/progmune-runtime/blob/main/assets/whatsapp-group.jpg?raw=true" width="200" alt="WhatsApp 群二维码" />
200
202
  </p>
201
203
 
202
- 你的意见塑造 Progmune。扫码加入用户讨论群(微信),或通过 [GitHub Issue](https://github.com/shenlian19831109/progmune-runtime/issues) 提交缺陷报告、功能需求与建议。
204
+ 你的意见塑造 Progmune。扫码加入用户讨论群(微信 / WhatsApp),或通过 [GitHub Issue](https://github.com/shenlian19831109/progmune-runtime/issues) 提交缺陷报告、功能需求与建议。
203
205
 
204
206
  ---
205
207
 
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ /**
3
+ * 跨函数调用序列构建(P4.6:跨函数传播)
4
+ *
5
+ * per-function 序列验证的扩展模型:
6
+ * - 入口函数(不被任何项目函数调用的函数)的调用序列做传递展开——
7
+ * 内联被调项目函数体(深度 ≤ MAX_DEPTH、环安全),外部调用(非项目函数)
8
+ * 原样保留给规则匹配层(别名/词段匹配)。
9
+ * - 非入口函数的孤立片段不再单独验证——违规归因到调用它的入口函数,
10
+ * 消除"helper 单独 close_file / read_file"类的片段误报。
11
+ *
12
+ * 边界(与 C 的 L3 同类,如实记录):展开是语法内联(调用链扁平化),
13
+ * 不做数据流/指针/分支分析;跨文件依赖 IR 的 calls[] 图。
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.buildCallSequences = buildCallSequences;
17
+ const MAX_DEPTH = 4;
18
+ /** 项目函数判定:有真实文件且非外部导入条目(external 条目无函数体可内联)。 */
19
+ function isProjectFn(f) {
20
+ return !f.external && !!f.file && f.file !== "(external)";
21
+ }
22
+ /**
23
+ * 从 IR 构建验证序列:入口函数展开 + 非入口抑制。
24
+ * @param ir - FunctionInfo 列表(TS 或 Python 提取器输出)
25
+ * @param keepNames - 协议规则名集合:命中这些名字的项目函数是验证单元
26
+ * (其调用名保留给规则匹配),不内联其函数体——否则 create_session 等
27
+ * 规则函数的平凡函数体会把调用名"吞掉"
28
+ */
29
+ function buildCallSequences(ir, keepNames) {
30
+ const fnMap = new Map();
31
+ for (const f of ir) {
32
+ if (isProjectFn(f))
33
+ fnMap.set(f.name, f);
34
+ }
35
+ // 被项目函数调用过的函数不是入口(其片段并入调用方展开序列)
36
+ const calledBy = new Set();
37
+ for (const f of ir) {
38
+ if (!isProjectFn(f))
39
+ continue;
40
+ for (const c of f.calls || []) {
41
+ if (fnMap.has(c))
42
+ calledBy.add(c);
43
+ }
44
+ }
45
+ /** 展开函数体内的调用(入口序列 = 函数体调用,不含函数自己的名字) */
46
+ const expandBody = (fn, depth, visiting) => {
47
+ const out = [];
48
+ for (const c of fn.calls || []) {
49
+ if (typeof c !== "string" || c.startsWith("__progmune_"))
50
+ continue;
51
+ out.push(...expandCall(c, depth, visiting));
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);
69
+ visiting.delete(name);
70
+ return out;
71
+ };
72
+ const sequences = [];
73
+ for (const f of ir) {
74
+ if (!isProjectFn(f))
75
+ continue;
76
+ if (calledBy.has(f.name))
77
+ continue; // 非入口:片段并入调用方
78
+ if (keepNames && keepNames.has(f.name))
79
+ continue; // 协议原语不是入口:只在调用链内验证
80
+ const calls = expandBody(f, 0, new Set());
81
+ if (calls.length === 0)
82
+ continue;
83
+ sequences.push({ calls, file: f.file, function: f.name });
84
+ }
85
+ return sequences;
86
+ }
@@ -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.0",
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/",