lingshu-solver 1.0.12 → 1.0.13

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.
@@ -47,7 +47,7 @@ const solverCore = require('./solver-core');
47
47
  const { solve } = solverCore;
48
48
 
49
49
  const SERVER_NAME = 'lingshu-solver';
50
- const SERVER_VERSION = '1.0.12';
50
+ const SERVER_VERSION = '1.0.13';
51
51
  const PORT = parseInt(process.env.PORT || '3000', 10);
52
52
 
53
53
  // ---- 护栏常量(防畸形/恶意输入耗尽资源,与 stdio 版一致)----
package/index.html CHANGED
@@ -11192,7 +11192,63 @@ function _runTail(state) {
11192
11192
 
11193
11193
  // —— 可审计结构化溯源(切片A):每个结果附带完整证据链元数据 ——
11194
11194
  // 设计目标:Agent / 上层系统拿到的不只是裸数字,而是"为什么是这个解"的可读证据链。
11195
- var SOLVER_VERSION = "lingshu-solver/1.0.12-auditable";
11195
+ var SOLVER_VERSION = "lingshu-solver/1.0.13";
11196
+
11197
+ // —— 确定性可复现契约(Certified Real-Root Computation 六属性之「确定性可复现」)——
11198
+ // 纯 JS 同步 SHA-256(零依赖,浏览器/Node 通用,免 Web Crypto 异步)。
11199
+ // reportId = 'ls1-' + sha256(输入+版本+预算);相同输入跨运行/平台逐位重算一致 ⇒
11200
+ // 可复现性可被机器验证(Decision Physics DP-1),而非仅文字声称。
11201
+ function _utf8Bytes(str) {
11202
+ var b = [];
11203
+ for (var i = 0; i < str.length; i++) {
11204
+ var c = str.charCodeAt(i);
11205
+ if (c < 0x80) b.push(c);
11206
+ else if (c < 0x800) { b.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f)); }
11207
+ else if (c < 0xd800 || c >= 0xe000) { b.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f)); }
11208
+ else { i++; var c2 = str.charCodeAt(i); var cp = 0x10000 + ((c & 0x3ff) << 10) + (c2 & 0x3ff); b.push(0xf0 | (cp >> 18), 0x80 | ((cp >> 12) & 0x3f), 0x80 | ((cp >> 6) & 0x3f), 0x80 | (cp & 0x3f)); }
11209
+ }
11210
+ return b;
11211
+ }
11212
+ function _sha256(str) {
11213
+ function rrot(x, n) { return (x >>> n) | (x << (32 - n)); }
11214
+ var K = [0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2];
11215
+ var H = [0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19];
11216
+ var msg = _utf8Bytes(str);
11217
+ var l = msg.length;
11218
+ msg.push(0x80);
11219
+ while (msg.length % 64 !== 56) msg.push(0x00);
11220
+ var bitLen = l * 8;
11221
+ for (var p = 0; p < 4; p++) msg.push(0x00);
11222
+ msg.push((bitLen >>> 24) & 0xff, (bitLen >>> 16) & 0xff, (bitLen >>> 8) & 0xff, bitLen & 0xff);
11223
+ for (var off = 0; off < msg.length; off += 64) {
11224
+ var w = new Array(64);
11225
+ for (var t = 0; t < 16; t++) { var j = off + t * 4; w[t] = (msg[j] << 24) | (msg[j+1] << 16) | (msg[j+2] << 8) | msg[j+3]; }
11226
+ for (var t2 = 16; t2 < 64; t2++) { var s0 = rrot(w[t2-15],7) ^ rrot(w[t2-15],18) ^ (w[t2-15] >>> 3); var s1 = rrot(w[t2-2],17) ^ rrot(w[t2-2],19) ^ (w[t2-2] >>> 10); w[t2] = (w[t2-16] + s0 + w[t2-7] + s1) | 0; }
11227
+ var a=H[0],b=H[1],c=H[2],d=H[3],e=H[4],f=H[5],g=H[6],h=H[7];
11228
+ for (var t3 = 0; t3 < 64; t3++) {
11229
+ var S1 = rrot(e,6) ^ rrot(e,11) ^ rrot(e,25); var ch = (e & f) ^ (~e & g); var t1 = (h + S1 + ch + K[t3] + w[t3]) | 0;
11230
+ var S0 = rrot(a,2) ^ rrot(a,13) ^ rrot(a,22); var maj = (a & b) ^ (a & c) ^ (b & c); var t2v = (S0 + maj) | 0;
11231
+ h=g; g=f; f=e; e=(d+t1)|0; d=c; c=b; b=a; a=(t1+t2v)|0;
11232
+ }
11233
+ H[0]=(H[0]+a)|0; H[1]=(H[1]+b)|0; H[2]=(H[2]+c)|0; H[3]=(H[3]+d)|0; H[4]=(H[4]+e)|0; H[5]=(H[5]+f)|0; H[6]=(H[6]+g)|0; H[7]=(H[7]+h)|0;
11234
+ }
11235
+ var hex = '';
11236
+ for (var hi = 0; hi < 8; hi++) { var vv = H[hi]; for (var ss = 28; ss >= 0; ss -= 4) hex += ((vv >>> ss) & 0xf).toString(16); }
11237
+ return hex;
11238
+ }
11239
+ function _computeReportId(state) {
11240
+ try {
11241
+ var seed = JSON.stringify([
11242
+ state.equationStrs || [],
11243
+ state.varNames || [],
11244
+ state.decimals,
11245
+ state._initD0 || null,
11246
+ !!state.fastMode,
11247
+ SOLVER_VERSION
11248
+ ]);
11249
+ return 'ls1-' + _sha256(seed);
11250
+ } catch (e) { return null; }
11251
+ }
11196
11252
 
11197
11253
  // Movability 完整读取(切片B):每变量携带 status + width,供 Agent 读懂"为何是这个解"
11198
11254
  function _movabilityFull(state) {
@@ -11216,6 +11272,7 @@ function _buildMeta(state) {
11216
11272
  var term = truncated ? 'resource_exhausted' : (state.fastMode ? 'fast_mode' : 'converged');
11217
11273
  return {
11218
11274
  solverVersion: SOLVER_VERSION,
11275
+ reportId: _computeReportId(state),
11219
11276
  fastMode: !!state.fastMode,
11220
11277
  terminatedBy: term,
11221
11278
  truncated: truncated,
@@ -11734,6 +11791,46 @@ function _assignCompleteness(state) {
11734
11791
  };
11735
11792
  }
11736
11793
 
11794
+ // 认证实根计算层(Certified Real-Root Computation 六属性归一化输出):
11795
+ // 把零散的 certified/certifiedRadius/tier/provenCount 收敛为一个机器可读契约。
11796
+ // - 每个有限孤立解携带 cert:{ status, method, enclosure(闭世界 sound 误差包络), backwardError, krawczykRadius }
11797
+ // - enclosure 仅对 Krawczyk 认证解给出 [v-r, v+r];候选解 enclosure=null(绝不伪造误差界)
11798
+ // - 全局 certification 汇总 proven/candidate/structural/emptyProof + 可复现方法,供 Agent 程序化判定保证边界
11799
+ function _assignCertBlock(state) {
11800
+ if (!state || !state.result) return;
11801
+ var sols = state.result.solutions || [];
11802
+ for (var i = 0; i < sols.length; i++) {
11803
+ var sol = sols[i];
11804
+ var enclosure = null;
11805
+ if (sol.certified === true && typeof sol.certifiedRadius === 'number') {
11806
+ enclosure = (sol.values || []).map(function (v) {
11807
+ var r = sol.certifiedRadius;
11808
+ return [+(v - r).toFixed(12), +(v + r).toFixed(12)];
11809
+ });
11810
+ }
11811
+ sol.cert = {
11812
+ status: sol.tier || (sol.certified ? 'proven' : 'candidate'),
11813
+ method: sol.source || (sol.certified ? 'krawczyk_newton' : 'numeric_newton'),
11814
+ enclosure: enclosure,
11815
+ backwardError: (typeof sol.residual === 'number') ? sol.residual : null,
11816
+ krawczykRadius: (typeof sol.certifiedRadius === 'number') ? sol.certifiedRadius : null
11817
+ };
11818
+ }
11819
+ var pc = state.result.provenCount || 0, cc = state.result.candidateCount || 0;
11820
+ state.result.certification = {
11821
+ proven: pc,
11822
+ candidate: cc,
11823
+ structural: state.result.structuralCount || 0,
11824
+ emptyProof: state.result.emptyProof || null,
11825
+ certifiedCoverage: (pc + cc) > 0 ? +(pc / (pc + cc)).toFixed(4) : null,
11826
+ reproducibility: {
11827
+ method: 'SHA-256(reportId)',
11828
+ deterministic: true,
11829
+ note: 'reportId 由「输入+版本+预算」逐位可重算;相同输入跨运行/平台产出相同 reportId 即证明可复现(Decision Physics DP-1)'
11830
+ }
11831
+ };
11832
+ }
11833
+
11737
11834
  function _finish(state) {
11738
11835
  // 兜底保护(2026-08-21):全局硬超时/异常路径可能只设 state.done 而未设 state.result,
11739
11836
  // 若直接返回 undefined/null,UI 会崩。此处构造诚实的截断结果,杜绝"求解器返回空"。
@@ -11824,6 +11921,7 @@ function _finish(state) {
11824
11921
  _assignTiers(state);
11825
11922
  _assignEmptiness(state);
11826
11923
  _assignCompleteness(state);
11924
+ _assignCertBlock(state); // 认证实根计算层:每解附加 cert 块 + 全局 certification 汇总
11827
11925
  return state.result;
11828
11926
  }
11829
11927
 
package/mcp-server.js CHANGED
@@ -19,7 +19,7 @@ const path = require('path');
19
19
  const { solve } = require('./solver-core');
20
20
 
21
21
  const SERVER_NAME = 'lingshu-solver';
22
- const SERVER_VERSION = '1.0.12';
22
+ const SERVER_VERSION = '1.0.13';
23
23
 
24
24
  // ---- 护栏常量(防畸形/恶意输入耗尽资源)----
25
25
  const MAX_TOTAL_CHARS = 100 * 1024; // 单次请求方程文本总长上限 100KB
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lingshu-solver",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "灵数求解器 · 确定性实数方程组求解 MCP 工具(≤6变量):区间收缩 + Krawczyk 认证,离线零依赖零数据,诚实标记 truncated。本地 stdio 永久免费;另有常驻托管端点 https://hongchenlingjing.com/mcp(按次 ¥0.01/次,支持 honorPaid 免费放行)。",
5
5
  "homepage": "https://genesis-plan.github.io/lingshu-solver/",
6
6
  "repository": {