lingshu-solver 1.0.14 → 1.0.16

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/LICENSE CHANGED
@@ -1,101 +1,101 @@
1
- 灵数求解器 (LingShu Solver) 商业授权许可协议
2
- LingShu Solver Commercial License
3
-
4
- Copyright (c) 2026 红尘灵境数字科技有限公司 / 太白(邓其聪).
5
- 版权所有,保留一切权利。All rights reserved.
6
-
7
- --------------------------------------------------------------------------------
8
- 一、著作权与权利保留
9
- --------------------------------------------------------------------------------
10
- 本软件(包括但不限于源代码、目标代码、二进制文件、文档及随附资料,以下简称
11
- "本软件")的著作权及相关知识产权均归上述版权方(以下简称"版权方")所有。
12
- 除本协议明确授予的有限许可外,任何权利(包括但不限于复制、修改、分发、再许可、
13
- 出租、出借、商业使用、制作衍生作品之权利)均由版权方保留。
14
-
15
- --------------------------------------------------------------------------------
16
- 二、非商业性使用(免费)
17
- --------------------------------------------------------------------------------
18
- 在同时满足下列全部条件的"非商业性使用"范围内,版权方免费授予您一项非独占、
19
- 不可转让、可随时撤销的使用许可:
20
- 1. 个人学习、研究、教学或技术评测;
21
- 2. 非营利组织、开源社区或教育机构的内部非营利用途;
22
- 3. 年营业收入不超过人民币 100 万元的团队,将本软件仅用于内部评估,且同时
23
- 运行的实例数不超过 3 个。
24
- 上述许可的前提条件:
25
- (a) 您须在每一份副本或任何实质性部分中完整保留本版权声明与许可声明;
26
- (b) 未经版权方书面同意,不得移除、遮挡或篡改本软件中的任何版权、商标或
27
- 许可标识;
28
- (c) 为互操作性所必须的法定反向工程情形除外,您不得对本软件进行反向工程、
29
- 反编译或反汇编。
30
-
31
- --------------------------------------------------------------------------------
32
- 三、商业使用(须事先取得书面授权)
33
- --------------------------------------------------------------------------------
34
- 任何"商业使用"均须事先取得版权方签署的书面《商业授权协议》(Commercial
35
- License),未获书面授权一律禁止。商业使用包括但不限于:
36
- - 将本软件用于任何以营利为目的的产品、服务或业务;
37
- - 通过 SaaS、云部署、API 或任何其他方式,向第三方提供基于本软件的能力
38
- (无论是否收费);
39
- - 将本软件集成、嵌入或捆绑进任何商业发行物、设备或解决方案;
40
- - 对本软件进行再分发、转授权或对外提供托管;
41
- - 任何超出第二条"非商业性使用"范围的使用。
42
- 未经书面授权的任何商业使用均构成对版权的侵权,版权方保留依法追究全部法律
43
- 责任(包括但不限于停止侵权、损害赔偿及诉讼费用)的权利。
44
-
45
- --------------------------------------------------------------------------------
46
- 四、获取商业授权
47
- --------------------------------------------------------------------------------
48
- 商业授权申请与商务合作,请通过以下渠道联系版权方:
49
- 联系人:红尘灵境数字科技有限公司 / 太白(邓其聪)
50
- 邮箱:553420544@qq.com
51
- 仓库:https://github.com/genesis-plan/lingshu-solver(Issues 亦可用于商务咨询)
52
- 授权范围、地域、期限与费用以双方签署的书面协议为准。
53
-
54
- --------------------------------------------------------------------------------
55
- 五、商标与品牌
56
- --------------------------------------------------------------------------------
57
- "灵数 / 灵数求解器 / LingShu Solver" 及相关名称、标识为版权方的商标或商号。
58
- 本协议不授予任何商标使用权。未经书面许可,您不得使用上述名称、标识进行任何
59
- 宣传或背书。
60
-
61
- --------------------------------------------------------------------------------
62
- 六、无担保与责任限制
63
- --------------------------------------------------------------------------------
64
- 本软件按"现状"提供,不提供任何明示或默示担保(包括但不限于对适销性、
65
- 特定用途适用性及不侵权的担保)。在任何情况下,无论基于合同、侵权或其他法
66
- 理,版权方均不对因使用或无法使用本软件所产生的任何直接、间接、附带、特殊
67
- 或后果性损害承担责任。
68
-
69
- --------------------------------------------------------------------------------
70
- 七、终止
71
- --------------------------------------------------------------------------------
72
- 若您违反本协议任何条款,本许可自动终止。终止后您须立即停止使用本软件,并
73
- 销毁所持有的全部副本(包括任何备份与衍生作品)。
74
-
75
- --------------------------------------------------------------------------------
76
- 八、适用法律
77
- --------------------------------------------------------------------------------
78
- 本协议受中华人民共和国法律管辖,并按其解释。因本协议产生的争议,提交版权
79
- 方所在地有管辖权的人民法院诉讼解决。
80
-
81
- --------------------------------------------------------------------------------
82
- 九、版本适用范围(重要)
83
- --------------------------------------------------------------------------------
84
- 自 lingshu-solver@1.0.4 起的版本适用本协议。更早版本(含 1.0.3 及此前)曾
85
- 以 Apache License 2.0 发布,该等已发布版本继续按其发布时随附的 Apache
86
- License 2.0 条款提供,此为历史事实且不可撤回;但其不延伸适用于本协议生效
87
- 后的任何新版本。
88
-
89
- --------------------------------------------------------------------------------
90
- 英文摘要 / English Summary
91
- --------------------------------------------------------------------------------
92
- Copyright (c) 2026 红尘灵境数字科技有限公司 / 太白(邓其聪). All rights reserved.
93
- This software is NOT open source and NOT free for commercial use. Non-commercial
94
- use (personal study, research, non-profit / educational internal use, or limited
95
- internal evaluation within a small low-revenue team) is permitted free of charge
96
- subject to retaining this notice. ANY commercial use requires a prior written
97
- Commercial License from the copyright holder. Unauthorized commercial use is
98
- prohibited and constitutes copyright infringement. This license applies to
99
- lingshu-solver@1.0.4 and later; earlier versions remain under the Apache License
100
- 2.0 as originally distributed. Provided "AS IS" without warranty; liability is
101
- excluded to the maximum extent permitted by law.
1
+ 灵数求解器 (LingShu Solver) 商业授权许可协议
2
+ LingShu Solver Commercial License
3
+
4
+ Copyright (c) 2026 红尘灵境数字科技有限公司 / 太白(邓其聪).
5
+ 版权所有,保留一切权利。All rights reserved.
6
+
7
+ --------------------------------------------------------------------------------
8
+ 一、著作权与权利保留
9
+ --------------------------------------------------------------------------------
10
+ 本软件(包括但不限于源代码、目标代码、二进制文件、文档及随附资料,以下简称
11
+ "本软件")的著作权及相关知识产权均归上述版权方(以下简称"版权方")所有。
12
+ 除本协议明确授予的有限许可外,任何权利(包括但不限于复制、修改、分发、再许可、
13
+ 出租、出借、商业使用、制作衍生作品之权利)均由版权方保留。
14
+
15
+ --------------------------------------------------------------------------------
16
+ 二、非商业性使用(免费)
17
+ --------------------------------------------------------------------------------
18
+ 在同时满足下列全部条件的"非商业性使用"范围内,版权方免费授予您一项非独占、
19
+ 不可转让、可随时撤销的使用许可:
20
+ 1. 个人学习、研究、教学或技术评测;
21
+ 2. 非营利组织、开源社区或教育机构的内部非营利用途;
22
+ 3. 年营业收入不超过人民币 100 万元的团队,将本软件仅用于内部评估,且同时
23
+ 运行的实例数不超过 3 个。
24
+ 上述许可的前提条件:
25
+ (a) 您须在每一份副本或任何实质性部分中完整保留本版权声明与许可声明;
26
+ (b) 未经版权方书面同意,不得移除、遮挡或篡改本软件中的任何版权、商标或
27
+ 许可标识;
28
+ (c) 为互操作性所必须的法定反向工程情形除外,您不得对本软件进行反向工程、
29
+ 反编译或反汇编。
30
+
31
+ --------------------------------------------------------------------------------
32
+ 三、商业使用(须事先取得书面授权)
33
+ --------------------------------------------------------------------------------
34
+ 任何"商业使用"均须事先取得版权方签署的书面《商业授权协议》(Commercial
35
+ License),未获书面授权一律禁止。商业使用包括但不限于:
36
+ - 将本软件用于任何以营利为目的的产品、服务或业务;
37
+ - 通过 SaaS、云部署、API 或任何其他方式,向第三方提供基于本软件的能力
38
+ (无论是否收费);
39
+ - 将本软件集成、嵌入或捆绑进任何商业发行物、设备或解决方案;
40
+ - 对本软件进行再分发、转授权或对外提供托管;
41
+ - 任何超出第二条"非商业性使用"范围的使用。
42
+ 未经书面授权的任何商业使用均构成对版权的侵权,版权方保留依法追究全部法律
43
+ 责任(包括但不限于停止侵权、损害赔偿及诉讼费用)的权利。
44
+
45
+ --------------------------------------------------------------------------------
46
+ 四、获取商业授权
47
+ --------------------------------------------------------------------------------
48
+ 商业授权申请与商务合作,请通过以下渠道联系版权方:
49
+ 联系人:红尘灵境数字科技有限公司 / 太白(邓其聪)
50
+ 邮箱:553420544@qq.com
51
+ 仓库:https://github.com/genesis-plan/lingshu-solver(Issues 亦可用于商务咨询)
52
+ 授权范围、地域、期限与费用以双方签署的书面协议为准。
53
+
54
+ --------------------------------------------------------------------------------
55
+ 五、商标与品牌
56
+ --------------------------------------------------------------------------------
57
+ "灵数 / 灵数求解器 / LingShu Solver" 及相关名称、标识为版权方的商标或商号。
58
+ 本协议不授予任何商标使用权。未经书面许可,您不得使用上述名称、标识进行任何
59
+ 宣传或背书。
60
+
61
+ --------------------------------------------------------------------------------
62
+ 六、无担保与责任限制
63
+ --------------------------------------------------------------------------------
64
+ 本软件按"现状"提供,不提供任何明示或默示担保(包括但不限于对适销性、
65
+ 特定用途适用性及不侵权的担保)。在任何情况下,无论基于合同、侵权或其他法
66
+ 理,版权方均不对因使用或无法使用本软件所产生的任何直接、间接、附带、特殊
67
+ 或后果性损害承担责任。
68
+
69
+ --------------------------------------------------------------------------------
70
+ 七、终止
71
+ --------------------------------------------------------------------------------
72
+ 若您违反本协议任何条款,本许可自动终止。终止后您须立即停止使用本软件,并
73
+ 销毁所持有的全部副本(包括任何备份与衍生作品)。
74
+
75
+ --------------------------------------------------------------------------------
76
+ 八、适用法律
77
+ --------------------------------------------------------------------------------
78
+ 本协议受中华人民共和国法律管辖,并按其解释。因本协议产生的争议,提交版权
79
+ 方所在地有管辖权的人民法院诉讼解决。
80
+
81
+ --------------------------------------------------------------------------------
82
+ 九、版本适用范围(重要)
83
+ --------------------------------------------------------------------------------
84
+ 自 lingshu-solver@1.0.4 起的版本适用本协议。更早版本(含 1.0.3 及此前)曾
85
+ 以 Apache License 2.0 发布,该等已发布版本继续按其发布时随附的 Apache
86
+ License 2.0 条款提供,此为历史事实且不可撤回;但其不延伸适用于本协议生效
87
+ 后的任何新版本。
88
+
89
+ --------------------------------------------------------------------------------
90
+ 英文摘要 / English Summary
91
+ --------------------------------------------------------------------------------
92
+ Copyright (c) 2026 红尘灵境数字科技有限公司 / 太白(邓其聪). All rights reserved.
93
+ This software is NOT open source and NOT free for commercial use. Non-commercial
94
+ use (personal study, research, non-profit / educational internal use, or limited
95
+ internal evaluation within a small low-revenue team) is permitted free of charge
96
+ subject to retaining this notice. ANY commercial use requires a prior written
97
+ Commercial License from the copyright holder. Unauthorized commercial use is
98
+ prohibited and constitutes copyright infringement. This license applies to
99
+ lingshu-solver@1.0.4 and later; earlier versions remain under the Apache License
100
+ 2.0 as originally distributed. Provided "AS IS" without warranty; liability is
101
+ excluded to the maximum extent permitted by law.
package/README.md CHANGED
@@ -1,109 +1,136 @@
1
- # 灵数求解器 · Lingshu Solver
1
+ # Lingshu Solver
2
2
 
3
- [![License](https://img.shields.io/badge/license-非商业免费%20%2F%20商业须书面授权-blue)](LICENSE)
3
+ **Category:** Certified Real-Root Computation
4
+
5
+ [![License](https://img.shields.io/badge/license-free%20for%20non--commercial%20%2F%20commercial%20needs%20written%20permission-blue)](LICENSE)
4
6
  [![MCP](https://img.shields.io/badge/MCP-Streamable%20HTTP%20%2B%20stdio-blue)](https://modelcontextprotocol.io)
5
- [![Deterministic](https://img.shields.io/badge/core-deterministic%20%2F%20non--LLM-green)](docs/03-设计思想.md)
7
+ [![Deterministic](https://img.shields.io/badge/core-deterministic%20%2F%20non--LLM-green)](docs/03-%E8%AE%BE%E8%AE%A1%E6%80%9D%E6%83%B3.md)
6
8
  [![npm](https://img.shields.io/npm/v/lingshu-solver)](https://www.npmjs.com/package/lingshu-solver)
7
9
 
8
- > **确定性**实数方程组求解器 —— 同样的题永远得到同样的答案,不含大模型、无随机、无幻觉。
9
- > 每个找到的解都经 **Krawczyk 区间认证**(`certified: true`),可复现、可回代验证、可进审计链。
10
+ > A **deterministic** solver for systems of real equations. The same problem always produces the same
11
+ > answer — no language model, no randomness, no hallucination. Every solution it reports is
12
+ > **Krawczyk-certified** (`certified: true`), reproducible, checkable by substitution, and usable as an
13
+ > audit trail.
14
+
15
+ **Two audiences:** people who just want an answer (open the web page, no install), and AI agents (a
16
+ standard MCP tool, one line to connect).
10
17
 
11
- **它给两种对象用**:普通用户(网页打开即用)与 AI Agent(标准 MCP 工具,一行接入)。
18
+ 🔬 **Live demo against the production endpoint:**
19
+ <https://hclj-1409755229.cos.ap-guangzhou.myqcloud.com/lingshu-solver/demo.html> — call the real MCP
20
+ endpoint right from the browser and watch `poly_roots` return certified real roots and `verify` judge a
21
+ candidate value. Thirty seconds is enough to see why "an LLM will mis-compute this, Lingshu can certify it".
12
22
 
13
- | | 说明 |
23
+ | | |
14
24
  |---|---|
15
- | **是** | 确定性(非大模型)的实数方程组**数值**求解引擎;代数方程与常见超越函数(`sin/cos/tan/log/exp/sqrt/abs`)均可 |
16
- | **不是** | 符号 CAS(不输出解析推导)、微分方程求解器、整数规划求解器,也不是"保证不漏解"的完备判定器 |
25
+ | **Yes** | a deterministic (non-LLM) **numerical** engine for systems of real equations; algebraic equations and common transcendentals (`sin/cos/tan/log/exp/sqrt/abs`) all work |
26
+ | **No** | a symbolic CAS (no analytic derivation), an ODE solver, an integer-programming solver, and it does **not** claim guaranteed completeness |
17
27
 
18
28
  ---
19
29
 
20
- ## 30 秒上手
30
+ ## 30 seconds to start
21
31
 
22
- **① 网页版(零安装,永久免费)**
32
+ **① Web (zero install, permanently free)**
23
33
 
24
- - 主站:<https://hongchenlingjing.com/>
25
- - 备用镜像:<https://genesis-plan.github.io/lingshu-solver/> | <https://hclj-1409755229.cos.ap-guangzhou.myqcloud.com/lingshu-solver/index.html>
34
+ - Main site: <https://hongchenlingjing.com/>
35
+ - Mirrors: <https://genesis-plan.github.io/lingshu-solver/> ·
36
+ <https://hclj-1409755229.cos.ap-guangzhou.myqcloud.com/lingshu-solver/index.html>
26
37
 
27
- 在输入框写方程(如 `x^2 + y^2 = 25` 与 `x + y = 7`),点求解。计算全部在浏览器内完成,方程不出设备。
38
+ Type equations into the box (for example `x^2 + y^2 = 25` and `x + y = 7`) and press solve. Everything is
39
+ computed inside your browser; the equations never leave your device.
28
40
 
29
- **② AI Agent 接入(MCP,两种形态任选)**
41
+ **② AI agent (MCP — pick either form)**
30
42
 
31
43
  ```json
32
- // 本地 stdio —— 永久免费、不限次数、离线,推荐
44
+ // local stdio — permanently free, unlimited, offline. Recommended.
33
45
  { "mcpServers": { "lingshu-solver": { "command": "npx", "args": ["-y", "lingshu-solver"] } } }
34
46
  ```
35
47
 
36
48
  ```json
37
- // 远程托管端点 —— 免安装、常驻、公网直连(固定 ¥0.01/次;传 honorPaid 即免费放行)
49
+ // hosted endpoint — no install, always on, reachable over the public internet
38
50
  { "mcpServers": { "lingshu-solver": { "type": "http", "url": "https://hongchenlingjing.com/mcp" } } }
39
51
  ```
40
52
 
41
- > **不想付费也照常用**:远程端点走**信任制** —— `solve` 入参加 `"honorPaid": true` 即免费放行(不验证、不扣余额);
42
- > 本地 `npx` 版与网页版永久免费。愿意支持请看[付款页](https://hongchenlingjing.com/pay/)(对公账户,付款后自助入账、立即生效,无需任何人审核)。
53
+ > **It also works if you never pay:** the hosted endpoint runs on an honor system — pass
54
+ > `"honorPaid": true` in the `solve` arguments and the call is released for free (no verification, no
55
+ > balance deduction). The `npx` local version and the web version are permanently free. If you do want to
56
+ > support it, see the [payment page](https://hongchenlingjing.com/pay/) — a corporate account, self-service
57
+ > crediting, effective immediately, no human approval anywhere in the loop.
43
58
 
44
- **③ 开发者**
59
+ **③ Developer**
45
60
 
46
61
  ```bash
47
62
  git clone https://github.com/genesis-plan/lingshu-solver.git
48
63
  cd lingshu-solver
49
- node mcp-server.js # 启动本地 MCP(stdio)服务端
50
- node test/regression.js # 常驻考卷回归
64
+ node mcp-server.js # start the local MCP (stdio) server
65
+ node test/regression.js # standing regression suite
51
66
  ```
52
67
 
53
68
  ---
54
69
 
55
- ## 能力边界(诚实声明)
70
+ ## Honest boundaries
56
71
 
57
- | 维度 | 说明 |
72
+ | Dimension | What it means |
58
73
  |---|---|
59
- | 已验证解 | 每个找到的解经 Krawczyk 认证(`tier=proven`),误差 ≤ 认证半径,数学保真 |
60
- | 穷尽性 | **尽力穷尽多解**;预算内未证明穷尽时显式标 `truncated=true`,**绝不谎称已完备** |
61
- | `truncated` 语义 | 仅表示「全局分支未在预算内完全判定」,**不等于一定漏解**;多数情况下全部真解已找到 |
62
- | 变量数 | ≤ 6 |
63
- | 方程数 | 1–64 条(服务端护栏),且须 ≥ 变量数 |
64
- | 数值范围 | 默认搜索域 ±1e6;对快增长函数(`exp/sinh`)建议显式给定 `domain` |
65
- | 输出精度 | 固定 6 位小数(不提供位数切换) |
66
- | 确定性 | 无随机分支,同输入永远同输出,可安全缓存 |
67
- | 数据 | 网页端零上行;本地版离线;托管端点不落盘方程内容 |
68
- | 依赖 | 零第三方依赖(只用 Node 内置模块与浏览器标准 API) |
69
-
70
- **不保证**:对一切输入 100% 穷尽;对高度病态系统在预算内必收敛。
71
- 这是数值数学的诚实下界('保证找到全部解'在一般情形下不可判定),不是待修缺陷。
74
+ | Verified solutions | every reported solution is Krawczyk-certified (`tier=proven`); error is within the certified radius; mathematically faithful |
75
+ | Completeness | **best effort** at finding all solutions; when exhaustiveness could not be proven within budget it says so explicitly with `truncated=true` — it never claims completeness it did not prove |
76
+ | `truncated` semantics | only means "the global branch search did not finish inside the budget"; it does **not** mean solutions were missed. In most cases every real solution was found |
77
+ | Variables | ≤ 6 |
78
+ | Equations | 1–64 (server-side guard), and the count must be ≥ the variable count |
79
+ | Search range | default ±1e6 per variable; supply `domain` explicitly for fast-growing functions (`exp/sinh`) |
80
+ | Output precision | fixed at 6 decimal places (there is no precision switch) |
81
+ | Determinism | no random branching; identical input always yields identical output, so caching is safe |
82
+ | Data | web version sends nothing upward; local version runs offline; the hosted endpoint does not persist equation contents |
83
+ | Dependencies | zero third-party dependencies (Node built-ins and standard browser APIs only) |
84
+
85
+ **Not guaranteed:** 100% exhaustiveness for every input, or convergence inside budget for highly
86
+ pathological systems. That is the honest floor of numerical mathematics ("guaranteeing all solutions"
87
+ is undecidable in the general case), not a defect to be fixed.
72
88
 
73
89
  ---
74
90
 
75
- ## 文档
91
+ ## Documentation
92
+
93
+ The design docs are written in Chinese; the machine-readable description for AI agents lives at
94
+ [llms.txt](llms.txt).
76
95
 
77
- | 文档 | 内容 |
96
+ | Doc | Contents |
78
97
  |---|---|
79
- | [01 · 产品作用](docs/01-产品作用.md) | 它是什么、解决什么问题、给谁用、能力与边界、对外口径 |
80
- | [02 · 使用指南](docs/02-使用指南.md) | 三种形态上手、MCP 工具契约(入参/出参/错误)、自托管部署、常见问题 |
81
- | [03 · 设计思想](docs/03-设计思想.md) | 六条设计原则、为什么可信、为什么不用大模型、有意不做的事 |
82
- | [04 · 技术参考](docs/04-技术参考.md) | 数学框架、算法流水线、49 个算子全表、规格硬约束、测试体系 |
83
- | [05 · 应用场景](docs/05-应用场景.md) | 七类可落地场景(Agent 后端 / 多 Agent / 链下计算 / 财税风控 / 私有化 / 教育 / 审计)与不适用场景 |
84
- | [06 · 商业授权与收费](docs/06-商业授权与收费.md) | 许可模型、免费范围、托管端点计费、企业年授权、发票与收款 |
85
- | [07 · 授权合同](docs/07-授权合同.md) | 商业授权合同模板、关键条款说明、签署流程 |
86
- | [08 · 版本管理](docs/08-版本管理.md) | 版本号语义、发布流程与一致性清单、兼容性承诺、版本历史 |
87
- | [09 · 项目历史](docs/09-项目历史.md) | 从起因到当前的阶段沿革与定位 |
88
-
89
- > 隐私与安全承诺另见:[privacy.html](privacy.html)(对外页面)。
98
+ | [01 · Product role](docs/01-%E4%BA%A7%E5%93%81%E4%BD%9C%E7%94%A8.md) | what it is, what problem it solves, who it is for, capabilities and limits, official wording |
99
+ | [02 · User guide](docs/02-%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97.md) | the three forms, the MCP tool contract (input/output/errors), self-hosting, FAQ |
100
+ | [03 · Design ideas](docs/03-%E8%AE%BE%E8%AE%A1%E6%80%9D%E6%83%B3.md) | six design principles, why it is trustworthy, why no LLM, what it deliberately refuses to do |
101
+ | [04 · Technical reference](docs/04-%E6%8A%80%E6%9C%AF%E5%8F%82%E8%80%83.md) | mathematical framework, algorithm pipeline, operator table, hard spec constraints, test suite |
102
+ | [05 · Use cases](docs/05-%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF.md) | seven applicable scenarios (agent backend / multi-agent / off-chain computation / tax and finance control / on-prem / education / audit) and the ones that do not apply |
103
+ | [06 · Commercial licence and pricing](docs/06-%E5%95%86%E4%B8%9A%E6%8E%88%E6%9D%83%E4%B8%8E%E6%94%B6%E8%B4%B9.md) | licence model, what is free, hosted-endpoint metering, enterprise annual licence, invoicing |
104
+ | [07 · Licence contract](docs/07-%E6%8E%88%E6%9D%83%E5%90%88%E5%90%8C.md) | commercial licence template, clause walkthrough, signing flow |
105
+ | [08 · Versioning](docs/08-%E7%89%88%E6%9C%AC%E7%AE%A1%E7%90%86.md) | version semantics, release flow and the consistency checklist, compatibility promises, history |
106
+ | [09 · Project history](docs/09-%E9%A1%B9%E7%9B%AE%E5%8E%86%E5%8F%B2.md) | how it got from the original problem to where it stands now |
107
+
108
+ > Privacy and security commitments are published separately: [privacy.html](privacy.html).
90
109
 
91
110
  ---
92
111
 
93
- ## 许可(摘要)
112
+ ## Licence (summary)
94
113
 
95
- **非商业免费 + 商业须书面授权**(自有《灵数求解器商业授权许可协议》,非开源协议):
114
+ **Free for non-commercial use; commercial use requires written permission** (a proprietary licence of our
115
+ own, not an open-source licence):
96
116
 
97
- - **非商业用途免费**:个人学习/研究/教学/评测;非营利组织与教育机构内部使用;年营收 ≤ 100 万元的团队内部评估(≤ 3 实例)。
98
- - **商业用途须事先取得书面授权**:任何以营利为目的的产品/服务/业务、SaaS/云/API 转售、集成嵌入、再分发托管,均须取得《商业授权协议》。
99
- - **版本适用**:`1.0.4` 起适用本协议;`1.0.3` 及更早版本按其发布时的 Apache License 2.0 提供(历史事实,不可撤回,但不延伸至新版本)。
117
+ - **Non-commercial, free:** personal study / research / teaching / evaluation; internal use by non-profit
118
+ organisations and educational institutions; internal evaluation by teams with annual revenue up to RMB 1
119
+ million (≤ 3 instances).
120
+ - **Commercial use needs prior written permission:** any product, service or business operated for profit,
121
+ resale of SaaS/cloud/API, integration, embedding, or redistribution as a hosted service.
122
+ - **Version applicability:** this licence applies from `1.0.4`. Versions `1.0.3` and earlier remain under
123
+ the Apache License 2.0 as published at the time (a historical fact, not revocable, and it does not extend
124
+ to later versions).
100
125
 
101
- 完整条款见 [LICENSE](LICENSE) | 授权范围与报价见 [06 · 商业授权与收费](docs/06-商业授权与收费.md) | 合同见 [07 · 授权合同](docs/07-授权合同.md)
126
+ Full terms in [LICENSE](LICENSE) · scope and pricing in
127
+ [06 · Commercial licence and pricing](docs/06-%E5%95%86%E4%B8%9A%E6%8E%88%E6%9D%83%E4%B8%8E%E6%94%B6%E8%B4%B9.md)
128
+ · contract in [07 · Licence contract](docs/07-%E6%8E%88%E6%9D%83%E5%90%88%E5%90%8C.md)
102
129
 
103
130
  ---
104
131
 
105
- ## 联系
132
+ ## Contact
106
133
 
107
- - 商务 / 授权 / 反馈:553420544@qq.com(亦可用仓库 Issues)
108
- - 版权方:广州市红尘灵境数字科技有限公司
109
- - 备案:粤ICP备2026031206号-3 | 粤公网安备44011402001444号
134
+ - Business / licence / feedback: 553420544@qq.com (or open an issue in this repository)
135
+ - Copyright holder: Guangzhou Hongchen Lingjing Digital Technology Co., Ltd. (广州市红尘灵境数字科技有限公司)
136
+ - Filing: 粤ICP备2026031206号-3 · 粤公网安备44011402001444号
@@ -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.14';
50
+ const SERVER_VERSION = '1.0.16';
51
51
  const PORT = parseInt(process.env.PORT || '3000', 10);
52
52
 
53
53
  // ---- 护栏常量(防畸形/恶意输入耗尽资源,与 stdio 版一致)----
@@ -854,68 +854,160 @@ function doSolve(args) {
854
854
  return shapeResult(r);
855
855
  }
856
856
 
857
+ // ---- 新工具:poly_roots / verify(agent 时代适配,薄封装 solve,不碰内核)----
858
+ function buildPolyEquation(coeffs) {
859
+ const n = coeffs.length - 1;
860
+ let s = '';
861
+ for (let i = 0; i < coeffs.length; i++) {
862
+ const c = coeffs[i]; const deg = n - i;
863
+ if (c === 0 && deg !== 0) continue;
864
+ const abs = Math.abs(c);
865
+ const sign = (s === '' ? (c < 0 ? '-' : '') : (c < 0 ? ' - ' : ' + '));
866
+ const term = deg === 0 ? '' + abs : deg === 1 ? abs + '*x' : abs + '*x^' + deg;
867
+ s += sign + term;
868
+ }
869
+ return s + ' = 0';
870
+ }
871
+
872
+ function doPolyRoots(args) {
873
+ const coeffs = args && args.coefficients;
874
+ if (!Array.isArray(coeffs) || coeffs.length < 2) throw { type: 'invalid_input', message: 'coefficients 必须是长度≥2 的数组(最高次系数在前)' };
875
+ for (const c of coeffs) if (typeof c !== 'number' || !isFinite(c)) throw { type: 'invalid_input', message: 'coefficients 须为有限数字' };
876
+ const eq = buildPolyEquation(coeffs);
877
+ const r = solve([eq], ['x'], 6, undefined, false, {});
878
+ return shapeResult(r);
879
+ }
880
+
881
+ function doVerify(args) {
882
+ const eq = args && args.equation;
883
+ if (typeof eq !== 'string' || !eq.includes('=')) throw { type: 'invalid_input', message: 'equation 须为含 "=" 的字符串' };
884
+ const cand = args.candidate;
885
+ let varNames, candPoint;
886
+ if (typeof cand === 'number') {
887
+ varNames = (args && Array.isArray(args.variables) && args.variables[0]) ? [args.variables[0]] : ['x'];
888
+ candPoint = [cand];
889
+ } else if (cand && typeof cand === 'object' && !Array.isArray(cand)) {
890
+ varNames = Object.keys(cand);
891
+ candPoint = varNames.map(function (v) { return cand[v]; });
892
+ } else if (Array.isArray(cand)) {
893
+ varNames = (args && Array.isArray(args.variables)) ? args.variables : [];
894
+ if (varNames.length !== cand.length) throw { type: 'invalid_input', message: 'candidate 数组长度须与 variables 一致' };
895
+ candPoint = cand;
896
+ } else {
897
+ throw { type: 'invalid_input', message: 'candidate 须为数字 / {变量:值} / [值...]' };
898
+ }
899
+ const margin = (args && typeof args.tolerance === 'number' && args.tolerance > 0) ? args.tolerance : 1e-3;
900
+ const domain = {};
901
+ varNames.forEach(function (v, i) { domain[v] = [candPoint[i] - margin, candPoint[i] + margin]; });
902
+ const r = solve([eq], varNames, 6, domain, false, {});
903
+ const shaped = shapeResult(r);
904
+ const matched = (r.solutions || []).find(function (s) {
905
+ return Array.isArray(s.values) && s.values.every(function (val, i) { return Math.abs(val - candPoint[i]) <= 1e-6; });
906
+ });
907
+ if (matched) {
908
+ return {
909
+ verdict: 'verified', isRoot: true, candidate: cand,
910
+ matchedRoot: { values: matched.values, tier: matched.tier, certified: !!matched.certified, cert: matched.cert || null,
911
+ text: varNames.map(function (vn, i) { return vn + '=' + fmt6(matched.values[i]); }).join(', ') },
912
+ reportId: shaped.reportId, certification: shaped.certification
913
+ };
914
+ }
915
+ let nearest = null;
916
+ try {
917
+ // refuted:在更宽域(默认 ±1e6)重算,给 Agent 全局最近的「真认证根」——
918
+ // 否则当 LLM 把根算偏(如猜 2.1、真根 2)时,窄邻域内无解会导致 nearest 为空,
919
+ // Agent 看不到正确值,verify 就失去了「纠正 LLM」的核心价值。
920
+ const rb = solve([eq], varNames, 6, undefined, false, {});
921
+ const solsB = (rb.solutions || []).filter(function (s) { return Array.isArray(s.values); });
922
+ if (solsB.length) {
923
+ let bestD = Infinity, bestS = null;
924
+ for (const s of solsB) { let d = 0; for (let i = 0; i < s.values.length; i++) d += (s.values[i] - candPoint[i]) * (s.values[i] - candPoint[i]); if (d < bestD) { bestD = d; bestS = s; } }
925
+ nearest = { values: bestS.values, tier: bestS.tier || null, certified: !!bestS.certified, cert: bestS.cert || null,
926
+ text: varNames.map(function (vn, i) { return vn + '=' + fmt6(bestS.values[i]); }).join(', ') };
927
+ }
928
+ } catch (_e) { /* 宽域重算失败不致命,nearest 保持 null */ }
929
+ return {
930
+ verdict: 'refuted_or_unverified', isRoot: false, candidate: cand,
931
+ message: '在候选点 ±' + margin + ' 邻域内未找到与之匹配的认证根;候选不是经验证的实根。' + (nearest ? '(全局最近认证根见 nearestCertifiedRoot)' : '(该方程在默认域内也无实根)'),
932
+ nearestCertifiedRoot: nearest, reportId: shaped.reportId
933
+ };
934
+ }
935
+
857
936
  // ---- 工具定义(与 stdio 版一致)----
858
937
  const TOOLS = [
859
938
  {
860
939
  name: 'solve',
861
- description: '求解实数方程组的确定性数值引擎(非大模型,无随机、同输入输出可复现)。适用:需可验证、可复现的实数解(代数或 sin/cos/tan/log/exp/sqrt/abs 等常见超越函数),尤其给 AI Agent 当"不会胡说"的数学后端。' +
862
- '不适用:纯符号推导/闭式证明、微分方程初值问题、整数/必不等于等强制约束(暂不支持)。' +
863
- '输入:equations 为含 "=" 的方程字符串数组,如 ["x^2+y^2=25","x+y=7"];variables 可选(不填自动识别,最多6个);domain 可选(如 {"x":[-30,30]}),否则默认每变量 ±1e6。' +
864
- '硬限制:变量 ≤6;方程 1–64 条且数量须 ≥ 变量数;单次方程文本 ≤100KB;输出固定 6 位小数(不可切换)。' +
865
- '输出(JSON):resultType=empty(严格证无实数解)/finite(有限已验证解)/infinite(无限解集,仅给距原点最近推荐解);summary=中文一句话总览;solutions[] 每解含 values[](6位小数数值)、tier(proven=Krawczyk已认证/likely/candidate)、certified、text(人类可读如"x=4.000000, y=3.000000"),残差等内部数值收在 internals 子块(机器可跳过);certified=是否全proven;recommended=距原点最近解的精简结构。' +
866
- 'truncated=true:预算内未完成全局分支判定、未证明已穷尽——不等于一定漏解,多数情况全部真解已找到;极端病态下可能遗漏个别解,可缩 domain 或提高 budget 重试。' +
867
- '错误返回 error.type(invalid_input=输入不合法/超限,internal_error=内部异常)。遇卡点或认为结果有误,请调用 give_feedback(内容仅落本地日志,不外传)。相同输入永远返回完全相同结果,可安全缓存与重复调用。' +
868
- '★ 计费边界(Agent 必读):本端点按信任制运转 —— 不付钱也能用。solve 入参传 honorPaid:true(声明「个人/评估用途」)即免费放行、不验证、不扣余额;若结果用于产品或商业/自动化流程,欢迎走付费通道支持作者(GET /pricing 取得订单与 key)——付费属自愿,非强制。',
940
+ description: 'Deterministic solver for systems of real equations. This is not a language model: no randomness, and identical input always returns an identical, reproducible result. Use it when you need a verifiable, reproducible numeric answer for algebraic equations or common transcendentals (sin/cos/tan/log/exp/sqrt/abs); it works well as a non-hallucinating math backend for an AI agent. Not suitable for symbolic algebra, closed-form proofs, initial-value ODEs, or mandatory integer equality. INPUT: equations (array of strings containing an equals sign, e.g. ["x^2+y^2=25","x+y=7"]); supported operators + - * / ^ sqrt log sin cos tan exp abs, with in-text domain constraints such as x in [-30,30]; variables (optional, auto-detected, max 6); domain (optional, e.g. {"x":[-30,30]}), defaulting to +/-1e6 per variable. HARD LIMITS: at most 6 variables; 1 to 64 equations and the equation count must be at least the variable count; up to 100KB of equation text per call; output is fixed at 6 decimal places and is not configurable. OUTPUT (JSON): resultType is empty (no real solutions, proven), finite (finite verified solutions) or infinite (infinite solution set, only the recommended nearest-to-origin solution is given); summary; solutions[] with values[] (6-decimal numbers), tier (proven means Krawczyk-certified, otherwise likely or candidate), certified, text; residual and other internals under internals; recommended holds the compact nearest-to-origin structure. truncated=true means the global branch-and-bound did not finish inside the budget; it does not necessarily mean solutions were missed and in most cases every real solution was found; narrow the domain or raise options.budget and retry if you need a completeness guarantee. Errors return error.type (invalid_input or internal_error). If something looks wrong, call give_feedback rather than guessing. The same input always produces the exact same output, so caching and retries are safe. PAYMENT: this endpoint is free to use. Pass honorPaid:true to declare personal or evaluation use and the call is served with no verification and no balance deduction; payment is voluntary and never enforced.',
869
941
  inputSchema: {
870
942
  type: 'object',
871
943
  properties: {
872
944
  equations: {
873
945
  type: 'array', items: { type: 'string' },
874
- description: '方程字符串数组,如 ["x^2 + y^2 = 25", "x + y = 7"]。支持 + - * / ^ sqrt log sin cos tan exp abs,以及 in-text 域约束 "x ∈ [-30,30]"。'
946
+ description: 'Array of equation strings, e.g. ["x^2 + y^2 = 25", "x + y = 7"]. Supports + - * / ^ sqrt log sin cos tan exp abs, plus in-text domain constraints such as x in [-30,30].'
875
947
  },
876
948
  variables: {
877
949
  type: 'array', items: { type: 'string' },
878
- description: '变量名数组(可选)。不填则由方程文本自动识别,顺序按出现。最多 6 个。'
950
+ description: 'Variable names (optional). If omitted they are auto-detected from the equation text, in order of appearance. Maximum 6.'
879
951
  },
880
952
  domain: {
881
953
  type: 'object',
882
- description: '显式搜索域(可选)。形如 {"x":[-30,30],"y":[-30,30]}。对"有限解·部分"演示或快增长函数(exp/sinh)建议显式给定,否则默认 ±1e6 可能剪枝失效并触发 truncated。'
954
+ description: 'Explicit search domain (optional), e.g. {"x":[-30,30],"y":[-30,30]}. Recommended for near-infinite solution sets or fast-growing functions such as exp or sinh; without it the default +/-1e6 may fail to prune and set truncated.'
883
955
  },
884
- fastMode: { type: 'boolean', description: '快速模式(默认 false)' },
885
- honorPaid: { type: 'boolean', description: '信任制:声明本次为「个人/评估用途」即放行(不验证、不扣余额)——不付钱也能用。若结果用于产品/商业/自动化流程,欢迎改走付费通道(GET /pricing 取得订单与 key)支持作者;付费属自愿,本服务不做强制验证。' },
886
- options: { type: 'object', description: '高级选项(可选),如 {budget:500000, maxDepth:28}' }
956
+ fastMode: { type: 'boolean', description: 'Fast mode (default false).' },
957
+ honorPaid: { type: 'boolean', description: 'Honor system: set true to declare this call personal or evaluation use. It is released for free with no verification and no balance deduction. Set false only when this runs inside a product, a commercial pipeline or an automated workflow; payment is voluntary and never enforced.' },
958
+ options: { type: 'object', description: 'Advanced options (optional), e.g. {budget:500000, maxDepth:28}' }
887
959
  },
888
960
  required: ['equations']
889
961
  }
890
962
  },
891
963
  {
892
964
  name: 'give_feedback',
893
- description: 'AI 智能体在调用 solve 遇到卡点、错误、或认为结果有问题时,主动回报。' +
894
- '回报内容仅落本地 feedback.log,不会外传。帮助作者持续改进。',
965
+ description: 'Report a problem to the operator when solve hits a dead end, returns an error, or produces something you believe is wrong. The text is written to a local log only and is never transmitted anywhere else.',
895
966
  inputSchema: {
896
967
  type: 'object',
897
968
  properties: {
898
- message: { type: 'string', description: '反馈内容:遇到了什么、期望什么、实际得到什么。' },
899
- context: { type: 'string', description: '可选上下文:触发场景、输入特征等。' }
969
+ message: { type: 'string', description: 'What you hit, what you expected, and what you actually got.' },
970
+ context: { type: 'string', description: 'Optional context: the triggering scenario or input characteristics.' }
900
971
  },
901
972
  required: ['message']
902
973
  }
903
974
  },
975
+ {
976
+ name: 'poly_roots',
977
+ description: 'All real roots of a polynomial, each individually certified by Krawczyk with a strict error box. Coefficients are ordered highest degree first, so [1,-2,-5,6] means x^3-2x^2-5x+6. Deterministic and reproducible; complex roots are not returned (real numbers only). Use it as a reliable polynomial root component instead of letting a general language model estimate roots. Free to use: pass honorPaid:true to declare personal or evaluation use.',
978
+ inputSchema: {
979
+ type: 'object',
980
+ properties: {
981
+ coefficients: { type: 'array', items: { type: 'number' }, description: 'Polynomial coefficients, highest degree first. [1,-2,-5,6] means x^3-2x^2-5x+6.' },
982
+ tolerance: { type: 'number', description: 'Tolerance used to decide a root (optional; internal precision is used by default).' }
983
+ },
984
+ required: ['coefficients']
985
+ }
986
+ },
987
+ {
988
+ name: 'verify',
989
+ description: 'Check whether a claimed answer is correct. Give the equation plus a candidate value (a number for a single variable, {variable:value} pairs, or an array in variable order); the same certified kernel runs in a neighbourhood around the candidate. If a matching certified root is found the result is verified together with the error box; otherwise it is refuted and the nearest certified root is returned, so the calling agent immediately sees the correct value. Deterministic, not an LLM, reproducible across calls. Free to use: pass honorPaid:true to declare personal or evaluation use.',
990
+ inputSchema: {
991
+ type: 'object',
992
+ properties: {
993
+ equation: { type: 'string', description: 'A single equation containing an equals sign, e.g. "x^2 = 4".' },
994
+ candidate: { description: 'The claimed answer: a number (single variable, default variable x), {variable:value} for multiple variables, or an array in variables order.', oneOf: [{ type: 'number' }, { type: 'object' }, { type: 'array' }] },
995
+ variables: { type: 'array', items: { type: 'string' }, description: 'Variable names (required for multiple variables or array candidates), e.g. ["x","y"].' },
996
+ tolerance: { type: 'number', description: 'Neighbourhood radius (optional, default 1e-3) within which a matching certified root is searched.' }
997
+ },
998
+ required: ['equation', 'candidate']
999
+ }
1000
+ },
904
1001
  {
905
1002
  name: 'pay',
906
- description: '对公收款:为本次/后续求解创建一笔真实付费订单(' + yuan(PRICE_CENTS) + '/次),返回订单号、专属 key 与结构化付款意图(payIntent)。' +
907
- '统一收款入口 = 工银e支付银联聚合码(支持支付宝/微信/银联扫码),钱落公司对公户,不接任何支付平台商户 API。' +
908
- '【付款后自助入账·推荐】付款完成后再调一次本工具并传 orderId + selfReportPaid:true,即**立即入账、立即放行**,' +
909
- '不需要任何人工核对、不需要等对账 —— 本服务按信任制运转(同一道门 honorPaid 本来就免费,' +
910
- '所以「声明已付款」不会多出任何损失,只是把诚实付款的人从「等入账」里解放出来)。' +
911
- '若服务端未配置收款方式(LS_PAY_TO 为空),订单仍可创建但 payIntent.payTo 为 null,此时请改用 honorPaid:true 或联系作者。',
1003
+ description: 'Create a real payment order for this or future solving. Returns the order id, a dedicated key, and a structured payment intent. The payment channel is a corporate static collection code (UnionPay aggregate QR) settling into a corporate bank account; no payment-platform merchant API is used. AFTER PAYING: call this tool again with orderId and selfReportPaid:true and the order is credited and released immediately, with no manual check and no waiting for reconciliation, because this service runs on an honor system. If the server has no payment method configured the order is still created but payIntent.payTo is null; use honorPaid:true or contact the operator instead.',
912
1004
  inputSchema: {
913
1005
  type: 'object',
914
1006
  properties: {
915
- channel: { type: 'string', description: '付款通道:当前固定为 corporate-static(对公静态收款,对公收款);留空即可。' },
916
- orderId: { type: 'string', description: '自助入账用:上一次 pay 返回的订单号(形如 LS-YYYYMMDD-xxxxxx)。' },
917
- selfReportPaid: { type: 'boolean', description: '自助入账用:付款完成后置 true,声明「本单已付」。服务端不验证、立即按订单面值入账放行(信任制);入账会标注 amountVerified:false / creditedBy:self_report,便于事后与银行流水核对。' },
918
- selfReportNote: { type: 'string', description: '可选:付款备注(如付款人/渠道/时间),仅用于对账留痕,长度上限 200。' }
1007
+ channel: { type: 'string', description: 'Payment channel: currently fixed to corporate-static (corporate bank collection). Leave empty.' },
1008
+ orderId: { type: 'string', description: 'For self-reporting: the order id returned by a previous pay call, shaped like LS-YYYYMMDD-xxxxxx.' },
1009
+ selfReportPaid: { type: 'boolean', description: 'For self-reporting: set true after paying to declare that this order was paid. The server does not verify and credits the order amount and releases it immediately (honor system); the credit is marked amountVerified:false / creditedBy:self_report so it can be reconciled against bank statements afterwards.' },
1010
+ selfReportNote: { type: 'string', description: 'Optional payment note (payer, channel, time), kept only for reconciliation, up to 200 characters.' }
919
1011
  },
920
1012
  required: []
921
1013
  }
@@ -967,15 +1059,22 @@ function handleRpc(msg, ip, ctx) {
967
1059
  let honorClaimed = false;
968
1060
  try {
969
1061
  let result;
970
- if (name === 'solve') {
1062
+ if (name === 'solve' || name === 'poly_roots' || name === 'verify') {
971
1063
  // ── 信任制(honor system):调用方声明「我已付款」即放行,不验证、不扣余额。
972
1064
  // 设计取舍(用户决策):没有支付通道凭证、又想直接用的人,给一个零摩擦入口。
973
1065
  // 最坏情况=白嫖(求解是确定性离线计算,边际成本≈0,不亏);最好情况=有人真去
974
1066
  // 付静态收款码那 1 分。转化靠 calls.log 里的 honorClaimed 计数衡量。
1067
+ // poly_roots / verify 与 solve 同属「认证数值计算」,共用信任制 + 计费路径。
1068
+ const isSolve = (name === 'solve');
1069
+ const runSolver = function () {
1070
+ if (name === 'solve') return doSolve(args);
1071
+ if (name === 'poly_roots') return doPolyRoots(args);
1072
+ return doVerify(args);
1073
+ };
975
1074
  const honor = !!(args && args.honorPaid === true);
976
1075
  if (honor) {
977
- result = doSolve(args);
978
- result.support = honorSupportBlock(); // 层1:代传微请求,借 Agent「忠实转发器」特性触达付款人
1076
+ result = runSolver();
1077
+ if (isSolve) result.support = honorSupportBlock(); // 层1:代传微请求,借 Agent「忠实转发器」特性触达付款人
979
1078
  freeCall = true;
980
1079
  honorClaimed = true;
981
1080
  honorClaims++;
@@ -984,7 +1083,7 @@ function handleRpc(msg, ip, ctx) {
984
1083
  const meter = meterPreCheck(ctx);
985
1084
  if (!meter.ok) throw meter.err; // 落到下方 catch → isError,不扣费
986
1085
  freeCall = !!meter.free;
987
- result = doSolve(args);
1086
+ result = runSolver();
988
1087
  // 只有成功产出结果、且不是「解析失败」才扣
989
1088
  chargedCents = (meter.free || !isBillable(result)) ? 0 : meterCharge(ctx);
990
1089
  }
package/index.html CHANGED
@@ -8,7 +8,10 @@
8
8
  <meta name="description" content="灵数求解器 — 高维代数方程组求解工具,支持导数/积分/ODE/极限,输出确定性解">
9
9
  <link rel="manifest" href="manifest.json">
10
10
  <link rel="icon" href="icon.svg" type="image/svg+xml">
11
- <link rel="apple-touch-icon" href="icon.svg">
11
+ <link rel="apple-touch-icon" href="icon-512.png">
12
+ <meta name="apple-mobile-web-app-capable" content="yes">
13
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
14
+ <meta name="apple-mobile-web-app-title" content="灵数">
12
15
  <title>灵数求解器</title>
13
16
  <style>
14
17
  * {
@@ -11192,7 +11195,7 @@ function _runTail(state) {
11192
11195
 
11193
11196
  // —— 可审计结构化溯源(切片A):每个结果附带完整证据链元数据 ——
11194
11197
  // 设计目标:Agent / 上层系统拿到的不只是裸数字,而是"为什么是这个解"的可读证据链。
11195
- var SOLVER_VERSION = "lingshu-solver/1.0.14";
11198
+ var SOLVER_VERSION = "lingshu-solver/1.0.16";
11196
11199
 
11197
11200
  // —— 确定性可复现契约(Certified Real-Root Computation 六属性之「确定性可复现」)——
11198
11201
  // 纯 JS 同步 SHA-256(零依赖,浏览器/Node 通用,免 Web Crypto 异步)。
@@ -12521,5 +12524,6 @@ function showError(msg) {
12521
12524
  </div>
12522
12525
  <div style="color:#475569;">本网页版永久免费、不限次数、离线计算。托管端点也支持「不付费照常用」(调用时传 honorPaid)。</div>
12523
12526
  </footer>
12527
+ <script>if('serviceWorker' in navigator){navigator.serviceWorker.register('sw.js').catch(function(){});}</script>
12524
12528
  </body>
12525
12529
  </html>
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.14';
22
+ const SERVER_VERSION = '1.0.16';
23
23
 
24
24
  // ---- 护栏常量(防畸形/恶意输入耗尽资源)----
25
25
  const MAX_TOTAL_CHARS = 100 * 1024; // 单次请求方程文本总长上限 100KB
@@ -150,50 +150,148 @@ function doSolve(args) {
150
150
  return shapeResult(r);
151
151
  }
152
152
 
153
+ // ---- 新工具:poly_roots / verify(agent 时代适配,薄封装 solve,不碰内核)----
154
+ function buildPolyEquation(coeffs) {
155
+ const n = coeffs.length - 1;
156
+ let s = '';
157
+ for (let i = 0; i < coeffs.length; i++) {
158
+ const c = coeffs[i]; const deg = n - i;
159
+ if (c === 0 && deg !== 0) continue;
160
+ const abs = Math.abs(c);
161
+ const sign = (s === '' ? (c < 0 ? '-' : '') : (c < 0 ? ' - ' : ' + '));
162
+ const term = deg === 0 ? '' + abs : deg === 1 ? abs + '*x' : abs + '*x^' + deg;
163
+ s += sign + term;
164
+ }
165
+ return s + ' = 0';
166
+ }
167
+
168
+ function doPolyRoots(args) {
169
+ const coeffs = args && args.coefficients;
170
+ if (!Array.isArray(coeffs) || coeffs.length < 2) throw { type: 'invalid_input', message: 'coefficients 必须是长度≥2 的数组(最高次系数在前)' };
171
+ for (const c of coeffs) if (typeof c !== 'number' || !isFinite(c)) throw { type: 'invalid_input', message: 'coefficients 须为有限数字' };
172
+ const eq = buildPolyEquation(coeffs);
173
+ const r = solve([eq], ['x'], 6, undefined, false, {});
174
+ return shapeResult(r);
175
+ }
176
+
177
+ function doVerify(args) {
178
+ const eq = args && args.equation;
179
+ if (typeof eq !== 'string' || !eq.includes('=')) throw { type: 'invalid_input', message: 'equation 须为含 "=" 的字符串' };
180
+ const cand = args.candidate;
181
+ let varNames, candPoint;
182
+ if (typeof cand === 'number') {
183
+ varNames = (args && Array.isArray(args.variables) && args.variables[0]) ? [args.variables[0]] : ['x'];
184
+ candPoint = [cand];
185
+ } else if (cand && typeof cand === 'object' && !Array.isArray(cand)) {
186
+ varNames = Object.keys(cand);
187
+ candPoint = varNames.map(function (v) { return cand[v]; });
188
+ } else if (Array.isArray(cand)) {
189
+ varNames = (args && Array.isArray(args.variables)) ? args.variables : [];
190
+ if (varNames.length !== cand.length) throw { type: 'invalid_input', message: 'candidate 数组长度须与 variables 一致' };
191
+ candPoint = cand;
192
+ } else {
193
+ throw { type: 'invalid_input', message: 'candidate 须为数字 / {变量:值} / [值...]' };
194
+ }
195
+ const margin = (args && typeof args.tolerance === 'number' && args.tolerance > 0) ? args.tolerance : 1e-3;
196
+ const domain = {};
197
+ varNames.forEach(function (v, i) { domain[v] = [candPoint[i] - margin, candPoint[i] + margin]; });
198
+ const r = solve([eq], varNames, 6, domain, false, {});
199
+ const shaped = shapeResult(r);
200
+ const matched = (r.solutions || []).find(function (s) {
201
+ return Array.isArray(s.values) && s.values.every(function (val, i) { return Math.abs(val - candPoint[i]) <= 1e-6; });
202
+ });
203
+ if (matched) {
204
+ return {
205
+ verdict: 'verified', isRoot: true, candidate: cand,
206
+ matchedRoot: { values: matched.values, tier: matched.tier, certified: !!matched.certified, cert: matched.cert || null,
207
+ text: varNames.map(function (vn, i) { return vn + '=' + fmt6(matched.values[i]); }).join(', ') },
208
+ reportId: shaped.reportId, certification: shaped.certification
209
+ };
210
+ }
211
+ let nearest = null;
212
+ try {
213
+ // refuted:在更宽域(默认 ±1e6)重算,给 Agent 全局最近的「真认证根」——
214
+ // 否则当 LLM 把根算偏(如猜 2.1、真根 2)时,窄邻域内无解会导致 nearest 为空,
215
+ // Agent 看不到正确值,verify 就失去了「纠正 LLM」的核心价值。
216
+ const rb = solve([eq], varNames, 6, undefined, false, {});
217
+ const solsB = (rb.solutions || []).filter(function (s) { return Array.isArray(s.values); });
218
+ if (solsB.length) {
219
+ let bestD = Infinity, bestS = null;
220
+ for (const s of solsB) { let d = 0; for (let i = 0; i < s.values.length; i++) d += (s.values[i] - candPoint[i]) * (s.values[i] - candPoint[i]); if (d < bestD) { bestD = d; bestS = s; } }
221
+ nearest = { values: bestS.values, tier: bestS.tier || null, certified: !!bestS.certified, cert: bestS.cert || null,
222
+ text: varNames.map(function (vn, i) { return vn + '=' + fmt6(bestS.values[i]); }).join(', ') };
223
+ }
224
+ } catch (_e) { /* 宽域重算失败不致命,nearest 保持 null */ }
225
+ return {
226
+ verdict: 'refuted_or_unverified', isRoot: false, candidate: cand,
227
+ message: '在候选点 ±' + margin + ' 邻域内未找到与之匹配的认证根;候选不是经验证的实根。' + (nearest ? '(全局最近认证根见 nearestCertifiedRoot)' : '(该方程在默认域内也无实根)'),
228
+ nearestCertifiedRoot: nearest, reportId: shaped.reportId
229
+ };
230
+ }
231
+
153
232
  // ---- 工具定义 ----
154
233
  const TOOLS = [
155
234
  {
156
235
  name: 'solve',
157
- description: '求解实数方程组的确定性数值引擎(非大模型,无随机、同输入输出可复现)。适用:需可验证、可复现的实数解(代数或 sin/cos/tan/log/exp/sqrt/abs 等常见超越函数),尤其给 AI Agent 当"不会胡说"的数学后端。' +
158
- '不适用:纯符号推导/闭式证明、微分方程初值问题、整数/必不等于等强制约束(暂不支持)。' +
159
- '输入:equations 为含 "=" 的方程字符串数组,如 ["x^2+y^2=25","x+y=7"];variables 可选(不填自动识别,最多6个);domain 可选(如 {"x":[-30,30]}),否则默认每变量 ±1e6。' +
160
- '硬限制:变量 ≤6;方程 1–64 条且数量须 ≥ 变量数;单次方程文本 ≤100KB;输出固定 6 位小数(不可切换)。' +
161
- '输出(JSON):resultType=empty(严格证无实数解)/finite(有限已验证解)/infinite(无限解集,仅给距原点最近推荐解);summary=中文一句话总览;solutions[] 每解含 values[](6位小数数值)、tier(proven=Krawczyk已认证/likely/candidate)、certified、text(人类可读如"x=4.000000, y=3.000000"),残差等内部数值收在 internals 子块(机器可跳过);certified=是否全proven;recommended=距原点最近解的精简结构。' +
162
- 'truncated=true:预算内未完成全局分支判定、未证明已穷尽——不等于一定漏解,多数情况全部真解已找到;极端病态下可能遗漏个别解,可缩 domain 或提高 budget 重试。' +
163
- '错误返回 error.type(invalid_input=输入不合法/超限,internal_error=内部异常)。遇卡点或认为结果有误,请调用 give_feedback(内容仅落本地日志,不外传)。相同输入永远返回完全相同结果,可安全缓存与重复调用。',
236
+ description: 'Deterministic solver for systems of real equations. This is not a language model: no randomness, and identical input always returns an identical, reproducible result. Use it when you need a verifiable, reproducible numeric answer for algebraic equations or common transcendentals (sin/cos/tan/log/exp/sqrt/abs); it works well as a non-hallucinating math backend for an AI agent. Not suitable for symbolic algebra, closed-form proofs, initial-value ODEs, or mandatory integer equality. INPUT: equations (array of strings containing an equals sign, e.g. ["x^2+y^2=25","x+y=7"]); supported operators + - * / ^ sqrt log sin cos tan exp abs, with in-text domain constraints such as x in [-30,30]; variables (optional, auto-detected, max 6); domain (optional, e.g. {"x":[-30,30]}), defaulting to +/-1e6 per variable. HARD LIMITS: at most 6 variables; 1 to 64 equations and the equation count must be at least the variable count; up to 100KB of equation text per call; output is fixed at 6 decimal places and is not configurable. OUTPUT (JSON): resultType is empty (no real solutions, proven), finite (finite verified solutions) or infinite (infinite solution set, only the recommended nearest-to-origin solution is given); summary; solutions[] with values[] (6-decimal numbers), tier (proven means Krawczyk-certified, otherwise likely or candidate), certified, text; residual and other internals under internals; recommended holds the compact nearest-to-origin structure. truncated=true means the global branch-and-bound did not finish inside the budget; it does not necessarily mean solutions were missed and in most cases every real solution was found; narrow the domain or raise options.budget and retry if you need a completeness guarantee. Errors return error.type (invalid_input or internal_error). If something looks wrong, call give_feedback rather than guessing. The same input always produces the exact same output, so caching and retries are safe. PAYMENT: this endpoint is free to use. Pass honorPaid:true to declare personal or evaluation use and the call is served with no verification and no balance deduction; payment is voluntary and never enforced.',
164
237
  inputSchema: {
165
238
  type: 'object',
166
239
  properties: {
167
240
  equations: {
168
241
  type: 'array', items: { type: 'string' },
169
- description: '方程字符串数组,如 ["x^2 + y^2 = 25", "x + y = 7"]。支持 + - * / ^ sqrt log sin cos tan exp abs,以及 in-text 域约束 "x ∈ [-30,30]"。'
242
+ description: 'Array of equation strings, e.g. ["x^2 + y^2 = 25", "x + y = 7"]. Supports + - * / ^ sqrt log sin cos tan exp abs, plus in-text domain constraints such as x in [-30,30].'
170
243
  },
171
244
  variables: {
172
245
  type: 'array', items: { type: 'string' },
173
- description: '变量名数组(可选)。不填则由方程文本自动识别,顺序按出现。最多 6 个。'
246
+ description: 'Variable names (optional). If omitted they are auto-detected from the equation text, in order of appearance. Maximum 6.'
174
247
  },
175
248
  domain: {
176
249
  type: 'object',
177
- description: '显式搜索域(可选)。形如 {"x":[-30,30],"y":[-30,30]}。对"有限解·部分"演示或快增长函数(exp/sinh)建议显式给定,否则默认 ±1e6 可能剪枝失效并触发 truncated。'
250
+ description: 'Explicit search domain (optional), e.g. {"x":[-30,30],"y":[-30,30]}. Recommended for near-infinite solution sets or fast-growing functions such as exp or sinh; without it the default +/-1e6 may fail to prune and set truncated.'
178
251
  },
179
- fastMode: { type: 'boolean', description: '快速模式(默认 false)' },
180
- options: { type: 'object', description: '高级选项(可选),如 {budget:500000, maxDepth:28}' }
252
+ fastMode: { type: 'boolean', description: 'Fast mode (default false).' },
253
+ options: { type: 'object', description: 'Advanced options (optional), e.g. {budget:500000, maxDepth:28}' }
181
254
  },
182
255
  required: ['equations']
183
256
  }
184
257
  },
185
258
  {
186
259
  name: 'give_feedback',
187
- description: 'AI 智能体在调用 solve 遇到卡点、错误、或认为结果有问题时,主动回报。' +
188
- '回报内容仅落本地 feedback.log,不会外传。帮助作者持续改进。',
260
+ description: 'Report a problem to the operator when solve hits a dead end, returns an error, or produces something you believe is wrong. The text is written to a local log only and is never transmitted anywhere else.',
189
261
  inputSchema: {
190
262
  type: 'object',
191
263
  properties: {
192
- message: { type: 'string', description: '反馈内容:遇到了什么、期望什么、实际得到什么。' },
193
- context: { type: 'string', description: '可选上下文:触发场景、输入特征等。' }
264
+ message: { type: 'string', description: 'What you hit, what you expected, and what you actually got.' },
265
+ context: { type: 'string', description: 'Optional context: the triggering scenario or input characteristics.' }
194
266
  },
195
267
  required: ['message']
196
268
  }
269
+ },
270
+ {
271
+ name: 'poly_roots',
272
+ description: 'All real roots of a polynomial, each individually certified by Krawczyk with a strict error box. Coefficients are ordered highest degree first, so [1,-2,-5,6] means x^3-2x^2-5x+6. Deterministic and reproducible; complex roots are not returned (real numbers only). Use it as a reliable polynomial root component instead of letting a general language model estimate roots. Free to use: pass honorPaid:true to declare personal or evaluation use.',
273
+ inputSchema: {
274
+ type: 'object',
275
+ properties: {
276
+ coefficients: { type: 'array', items: { type: 'number' }, description: 'Polynomial coefficients, highest degree first. [1,-2,-5,6] means x^3-2x^2-5x+6.' },
277
+ tolerance: { type: 'number', description: 'Tolerance used to decide a root (optional; internal precision is used by default).' }
278
+ },
279
+ required: ['coefficients']
280
+ }
281
+ },
282
+ {
283
+ name: 'verify',
284
+ description: 'Check whether a claimed answer is correct. Give the equation plus a candidate value (a number for a single variable, {variable:value} pairs, or an array in variable order); the same certified kernel runs in a neighbourhood around the candidate. If a matching certified root is found the result is verified together with the error box; otherwise it is refuted and the nearest certified root is returned, so the calling agent immediately sees the correct value. Deterministic, not an LLM, reproducible across calls. Free to use: pass honorPaid:true to declare personal or evaluation use.',
285
+ inputSchema: {
286
+ type: 'object',
287
+ properties: {
288
+ equation: { type: 'string', description: 'A single equation containing an equals sign, e.g. "x^2 = 4".' },
289
+ candidate: { description: 'The claimed answer: a number (single variable, default variable x), {variable:value} for multiple variables, or an array in variables order.', oneOf: [{ type: 'number' }, { type: 'object' }, { type: 'array' }] },
290
+ variables: { type: 'array', items: { type: 'string' }, description: 'Variable names (required for multiple variables or array candidates), e.g. ["x","y"].' },
291
+ tolerance: { type: 'number', description: 'Neighbourhood radius (optional, default 1e-3) within which a matching certified root is searched.' }
292
+ },
293
+ required: ['equation', 'candidate']
294
+ }
197
295
  }
198
296
  ];
199
297
 
@@ -240,6 +338,10 @@ function handle(msg) {
240
338
  ts: new Date().toISOString(), message: msg_fb, context: args.context || null
241
339
  }) + '\n');
242
340
  result = { acknowledged: true, note: '反馈已记录(本地,不外传)' };
341
+ } else if (name === 'poly_roots') {
342
+ result = doPolyRoots(args);
343
+ } else if (name === 'verify') {
344
+ result = doVerify(args);
243
345
  } else {
244
346
  throw { type: 'unknown_tool', message: '未知工具: ' + name };
245
347
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lingshu-solver",
3
- "version": "1.0.14",
4
- "description": "灵数求解器 · 确定性实数方程组求解 MCP 工具(≤6变量):区间收缩 + Krawczyk 认证,离线零依赖零数据,诚实标记 truncated。本地 stdio 永久免费;另有常驻托管端点 https://hongchenlingjing.com/mcp(按次 ¥0.01/次,支持 honorPaid 免费放行)。",
3
+ "version": "1.0.16",
4
+ "description": "Lingshu Solver — deterministic (non-LLM) MCP tool for solving systems of real equations, up to 6 variables: interval arithmetic + affine arithmetic + constructive Krawczyk certification, zero dependencies, offline, no data upload, unproven-completeness honestly flagged as truncated. Local stdio is permanently free; the hosted endpoint works without paying via honorPaid. Hosted endpoint: https://hongchenlingjing.com/mcp",
5
5
  "homepage": "https://genesis-plan.github.io/lingshu-solver/",
6
6
  "repository": {
7
7
  "type": "git",