calc-mcp-server 0.1.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/.claude/commands/opsx/apply.md +152 -0
- package/.claude/commands/opsx/archive.md +157 -0
- package/.claude/commands/opsx/bulk-archive.md +242 -0
- package/.claude/commands/opsx/continue.md +114 -0
- package/.claude/commands/opsx/explore.md +174 -0
- package/.claude/commands/opsx/ff.md +94 -0
- package/.claude/commands/opsx/new.md +69 -0
- package/.claude/commands/opsx/onboard.md +534 -0
- package/.claude/commands/opsx/sync.md +134 -0
- package/.claude/commands/opsx/verify.md +164 -0
- package/.claude/settings.local.json +8 -0
- package/.claude/skills/npm-publish/SKILL.md +164 -0
- package/.claude/skills/openspec-apply-change/SKILL.md +156 -0
- package/.claude/skills/openspec-archive-change/SKILL.md +161 -0
- package/.claude/skills/openspec-bulk-archive-change/SKILL.md +246 -0
- package/.claude/skills/openspec-continue-change/SKILL.md +118 -0
- package/.claude/skills/openspec-explore/SKILL.md +289 -0
- package/.claude/skills/openspec-ff-change/SKILL.md +101 -0
- package/.claude/skills/openspec-new-change/SKILL.md +74 -0
- package/.claude/skills/openspec-onboard/SKILL.md +538 -0
- package/.claude/skills/openspec-sync-specs/SKILL.md +138 -0
- package/.claude/skills/openspec-verify-change/SKILL.md +168 -0
- package/CLAUDE.md +92 -0
- package/README.md +319 -0
- package/build/engines/decimal.d.ts +10 -0
- package/build/engines/decimal.d.ts.map +1 -0
- package/build/engines/decimal.js +61 -0
- package/build/engines/decimal.js.map +1 -0
- package/build/engines/programmer.d.ts +18 -0
- package/build/engines/programmer.d.ts.map +1 -0
- package/build/engines/programmer.js +103 -0
- package/build/engines/programmer.js.map +1 -0
- package/build/errors/handler.d.ts +10 -0
- package/build/errors/handler.d.ts.map +1 -0
- package/build/errors/handler.js +37 -0
- package/build/errors/handler.js.map +1 -0
- package/build/errors/types.d.ts +25 -0
- package/build/errors/types.d.ts.map +1 -0
- package/build/errors/types.js +2 -0
- package/build/errors/types.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +16 -0
- package/build/index.js.map +1 -0
- package/build/mcp/server.d.ts +3 -0
- package/build/mcp/server.d.ts.map +1 -0
- package/build/mcp/server.js +270 -0
- package/build/mcp/server.js.map +1 -0
- package/build/mcp/tools/ascii.d.ts +11 -0
- package/build/mcp/tools/ascii.d.ts.map +1 -0
- package/build/mcp/tools/ascii.js +93 -0
- package/build/mcp/tools/ascii.js.map +1 -0
- package/build/mcp/tools/basic.d.ts +6 -0
- package/build/mcp/tools/basic.d.ts.map +1 -0
- package/build/mcp/tools/basic.js +34 -0
- package/build/mcp/tools/basic.js.map +1 -0
- package/build/mcp/tools/conversion.d.ts +8 -0
- package/build/mcp/tools/conversion.d.ts.map +1 -0
- package/build/mcp/tools/conversion.js +81 -0
- package/build/mcp/tools/conversion.js.map +1 -0
- package/build/mcp/tools/programmer.d.ts +6 -0
- package/build/mcp/tools/programmer.d.ts.map +1 -0
- package/build/mcp/tools/programmer.js +29 -0
- package/build/mcp/tools/programmer.js.map +1 -0
- package/build/parser/ast.d.ts +47 -0
- package/build/parser/ast.d.ts.map +1 -0
- package/build/parser/ast.js +2 -0
- package/build/parser/ast.js.map +1 -0
- package/build/parser/lexer.d.ts +24 -0
- package/build/parser/lexer.d.ts.map +1 -0
- package/build/parser/lexer.js +168 -0
- package/build/parser/lexer.js.map +1 -0
- package/build/parser/parser.d.ts +14 -0
- package/build/parser/parser.d.ts.map +1 -0
- package/build/parser/parser.js +115 -0
- package/build/parser/parser.js.map +1 -0
- package/docs/plans/2025-02-24-mcp-calculator-design.md +344 -0
- package/docs/plans/2025-02-24-mcp-calculator-implementation.md +2626 -0
- package/openspec/changes/archive/2026-02-24-simplify-ascii-tools/.openspec.yaml +2 -0
- package/openspec/changes/archive/2026-02-24-simplify-ascii-tools/design.md +46 -0
- package/openspec/changes/archive/2026-02-24-simplify-ascii-tools/proposal.md +21 -0
- package/openspec/changes/archive/2026-02-24-simplify-ascii-tools/specs/ascii-conversion/spec.md +22 -0
- package/openspec/changes/archive/2026-02-24-simplify-ascii-tools/tasks.md +24 -0
- package/openspec/config.yaml +20 -0
- package/openspec/specs/ascii-conversion/spec.md +43 -0
- package/package.json +40 -0
- package/src/engines/decimal.ts +69 -0
- package/src/engines/programmer.ts +112 -0
- package/src/errors/handler.ts +55 -0
- package/src/errors/types.ts +37 -0
- package/src/index.ts +20 -0
- package/src/mcp/server.ts +287 -0
- package/src/mcp/tools/ascii.ts +116 -0
- package/src/mcp/tools/basic.ts +44 -0
- package/src/mcp/tools/conversion.ts +95 -0
- package/src/mcp/tools/programmer.ts +36 -0
- package/src/parser/ast.ts +51 -0
- package/src/parser/lexer.ts +216 -0
- package/src/parser/parser.ts +154 -0
- package/test/integration/ascii.test.ts +450 -0
- package/test/integration/basic-calculate.test.ts +272 -0
- package/test/integration/conversion.test.ts +357 -0
- package/test/integration/programmer-calculate.test.ts +363 -0
- package/test/unit/decimal-engine.test.ts +134 -0
- package/test/unit/error-handler.test.ts +173 -0
- package/test/unit/lexer.test.ts +176 -0
- package/test/unit/parser.test.ts +197 -0
- package/test/unit/programmer-engine.test.ts +234 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +13 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: openspec-sync-specs
|
|
3
|
+
description: 将变更中的增量规范同步到主规范。当用户想要用增量规范中的更改更新主规范,而不归档变更时使用。
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: Requires openspec CLI.
|
|
6
|
+
metadata:
|
|
7
|
+
author: openspec
|
|
8
|
+
version: "1.0"
|
|
9
|
+
generatedBy: "1.1.1"
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
将变更中的增量规范同步到主规范。
|
|
13
|
+
|
|
14
|
+
这是一个 **Agent 驱动** 的操作 - 你将阅读增量规范并直接编辑主规范以应用更改。这允许智能合并(例如,添加一个场景而不复制整个需求)。
|
|
15
|
+
|
|
16
|
+
**输入**:可选择指定变更名称。如果省略,检查是否可以从对话上下文中推断。如果模糊或不明确,必须提示可用的变更。
|
|
17
|
+
|
|
18
|
+
**步骤**
|
|
19
|
+
|
|
20
|
+
1. **如果没有提供变更名称,提示选择**
|
|
21
|
+
|
|
22
|
+
运行 `openspec list --json` 获取可用变更。使用 **AskUserQuestion 工具** 让用户选择。
|
|
23
|
+
|
|
24
|
+
显示具有增量规范(在 `specs/` 目录下)的变更。
|
|
25
|
+
|
|
26
|
+
**重要**:不要猜测或自动选择变更。始终让用户选择。
|
|
27
|
+
|
|
28
|
+
2. **查找增量规范**
|
|
29
|
+
|
|
30
|
+
在 `openspec/changes/<name>/specs/*/spec.md` 中查找增量规范文件。
|
|
31
|
+
|
|
32
|
+
每个增量规范文件包含如下部分:
|
|
33
|
+
- `## ADDED Requirements` - 要添加的新需求
|
|
34
|
+
- `## MODIFIED Requirements` - 对现有需求的更改
|
|
35
|
+
- `## REMOVED Requirements` - 要删除的需求
|
|
36
|
+
- `## RENAMED Requirements` - 要重命名的需求(FROM:/TO: 格式)
|
|
37
|
+
|
|
38
|
+
如果未找到增量规范,通知用户并停止。
|
|
39
|
+
|
|
40
|
+
3. **对于每个增量规范,将更改应用到主规范**
|
|
41
|
+
|
|
42
|
+
对于在 `openspec/changes/<name>/specs/<capability>/spec.md` 具有增量规范的每个 capability:
|
|
43
|
+
|
|
44
|
+
a. **阅读增量规范** 以了解预期的更改
|
|
45
|
+
|
|
46
|
+
b. **阅读主规范** `openspec/specs/<capability>/spec.md`(可能还不存在)
|
|
47
|
+
|
|
48
|
+
c. **智能应用更改**:
|
|
49
|
+
|
|
50
|
+
**ADDED Requirements:**
|
|
51
|
+
- 如果主规范中不存在需求 → 添加它
|
|
52
|
+
- 如果需求已存在 → 更新它以匹配(视为隐式 MODIFIED)
|
|
53
|
+
|
|
54
|
+
**MODIFIED Requirements:**
|
|
55
|
+
- 在主规范中找到需求
|
|
56
|
+
- 应用更改 - 这可能是:
|
|
57
|
+
- 添加新场景(不需要复制现有的)
|
|
58
|
+
- 修改现有场景
|
|
59
|
+
- 更改需求描述
|
|
60
|
+
- 保留未在增量中提及的场景/内容
|
|
61
|
+
|
|
62
|
+
**REMOVED Requirements:**
|
|
63
|
+
- 从主规范中删除整个需求块
|
|
64
|
+
|
|
65
|
+
**RENAMED Requirements:**
|
|
66
|
+
- 找到 FROM 需求,重命名为 TO
|
|
67
|
+
|
|
68
|
+
d. **创建新主规范** 如果 capability 尚不存在:
|
|
69
|
+
- 创建 `openspec/specs/<capability>/spec.md`
|
|
70
|
+
- 添加 Purpose 部分(可以简短,标记为 TBD)
|
|
71
|
+
- 添加 Requirements 部分包含 ADDED requirements
|
|
72
|
+
|
|
73
|
+
4. **显示总结**
|
|
74
|
+
|
|
75
|
+
应用所有更改后,总结:
|
|
76
|
+
- 更新了哪些 capabilities
|
|
77
|
+
- 做了什么更改(需求添加/修改/删除/重命名)
|
|
78
|
+
|
|
79
|
+
**增量规范格式参考**
|
|
80
|
+
|
|
81
|
+
```markdown
|
|
82
|
+
## ADDED Requirements
|
|
83
|
+
|
|
84
|
+
### Requirement: New Feature
|
|
85
|
+
The system SHALL do something new.
|
|
86
|
+
|
|
87
|
+
#### Scenario: Basic case
|
|
88
|
+
- **WHEN** user does X
|
|
89
|
+
- **THEN** system does Y
|
|
90
|
+
|
|
91
|
+
## MODIFIED Requirements
|
|
92
|
+
|
|
93
|
+
### Requirement: Existing Feature
|
|
94
|
+
#### Scenario: New scenario to add
|
|
95
|
+
- **WHEN** user does A
|
|
96
|
+
- **THEN** system does B
|
|
97
|
+
|
|
98
|
+
## REMOVED Requirements
|
|
99
|
+
|
|
100
|
+
### Requirement: Deprecated Feature
|
|
101
|
+
|
|
102
|
+
## RENAMED Requirements
|
|
103
|
+
|
|
104
|
+
- FROM: `### Requirement: Old Name`
|
|
105
|
+
- TO: `### Requirement: New Name`
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**关键原则:智能合并**
|
|
109
|
+
|
|
110
|
+
与程序化合并不同,你可以应用 **部分更新**:
|
|
111
|
+
- 要添加场景,只需在 MODIFIED 下包含该场景 - 不要复制现有场景
|
|
112
|
+
- 增量代表 *意图*,而不是全盘替换
|
|
113
|
+
- 使用你的判断力合理合并更改
|
|
114
|
+
|
|
115
|
+
**成功时的输出**
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
## 规范已同步:<change-name>
|
|
119
|
+
|
|
120
|
+
已更新主规范:
|
|
121
|
+
|
|
122
|
+
**<capability-1>**:
|
|
123
|
+
- 添加需求:"New Feature"
|
|
124
|
+
- 修改需求:"Existing Feature"(添加了 1 个场景)
|
|
125
|
+
|
|
126
|
+
**<capability-2>**:
|
|
127
|
+
- 创建了新规范文件
|
|
128
|
+
- 添加需求:"Another Feature"
|
|
129
|
+
|
|
130
|
+
主规范现已更新。变更保持活跃 - 在实施完成后归档。
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**护栏**
|
|
134
|
+
- 在进行更改之前阅读增量规范和主规范
|
|
135
|
+
- 保留未在增量中提及的现有内容
|
|
136
|
+
- 如果某事不清楚,寻求澄清
|
|
137
|
+
- 在进行时显示你正在更改的内容
|
|
138
|
+
- 操作应是幂等的 - 运行两次应得到相同的结果
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: openspec-verify-change
|
|
3
|
+
description: Verify implementation matches change artifacts. Use when the user wants to validate that implementation is complete, correct, and coherent before archiving.
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: Requires openspec CLI.
|
|
6
|
+
metadata:
|
|
7
|
+
author: openspec
|
|
8
|
+
version: "1.0"
|
|
9
|
+
generatedBy: "1.1.1"
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Verify that an implementation matches the change artifacts (specs, tasks, design).
|
|
13
|
+
|
|
14
|
+
**Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
|
|
15
|
+
|
|
16
|
+
**Steps**
|
|
17
|
+
|
|
18
|
+
1. **If no change name provided, prompt for selection**
|
|
19
|
+
|
|
20
|
+
Run `openspec list --json` to get available changes. Use the **AskUserQuestion tool** to let the user select.
|
|
21
|
+
|
|
22
|
+
Show changes that have implementation tasks (tasks artifact exists).
|
|
23
|
+
Include the schema used for each change if available.
|
|
24
|
+
Mark changes with incomplete tasks as "(In Progress)".
|
|
25
|
+
|
|
26
|
+
**IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
|
|
27
|
+
|
|
28
|
+
2. **Check status to understand the schema**
|
|
29
|
+
```bash
|
|
30
|
+
openspec status --change "<name>" --json
|
|
31
|
+
```
|
|
32
|
+
Parse the JSON to understand:
|
|
33
|
+
- `schemaName`: The workflow being used (e.g., "spec-driven")
|
|
34
|
+
- Which artifacts exist for this change
|
|
35
|
+
|
|
36
|
+
3. **Get the change directory and load artifacts**
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
openspec instructions apply --change "<name>" --json
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This returns the change directory and context files. Read all available artifacts from `contextFiles`.
|
|
43
|
+
|
|
44
|
+
4. **Initialize verification report structure**
|
|
45
|
+
|
|
46
|
+
Create a report structure with three dimensions:
|
|
47
|
+
- **Completeness**: Track tasks and spec coverage
|
|
48
|
+
- **Correctness**: Track requirement implementation and scenario coverage
|
|
49
|
+
- **Coherence**: Track design adherence and pattern consistency
|
|
50
|
+
|
|
51
|
+
Each dimension can have CRITICAL, WARNING, or SUGGESTION issues.
|
|
52
|
+
|
|
53
|
+
5. **Verify Completeness**
|
|
54
|
+
|
|
55
|
+
**Task Completion**:
|
|
56
|
+
- If tasks.md exists in contextFiles, read it
|
|
57
|
+
- Parse checkboxes: `- [ ]` (incomplete) vs `- [x]` (complete)
|
|
58
|
+
- Count complete vs total tasks
|
|
59
|
+
- If incomplete tasks exist:
|
|
60
|
+
- Add CRITICAL issue for each incomplete task
|
|
61
|
+
- Recommendation: "Complete task: <description>" or "Mark as done if already implemented"
|
|
62
|
+
|
|
63
|
+
**Spec Coverage**:
|
|
64
|
+
- If delta specs exist in `openspec/changes/<name>/specs/`:
|
|
65
|
+
- Extract all requirements (marked with "### Requirement:")
|
|
66
|
+
- For each requirement:
|
|
67
|
+
- Search codebase for keywords related to the requirement
|
|
68
|
+
- Assess if implementation likely exists
|
|
69
|
+
- If requirements appear unimplemented:
|
|
70
|
+
- Add CRITICAL issue: "Requirement not found: <requirement name>"
|
|
71
|
+
- Recommendation: "Implement requirement X: <description>"
|
|
72
|
+
|
|
73
|
+
6. **Verify Correctness**
|
|
74
|
+
|
|
75
|
+
**Requirement Implementation Mapping**:
|
|
76
|
+
- For each requirement from delta specs:
|
|
77
|
+
- Search codebase for implementation evidence
|
|
78
|
+
- If found, note file paths and line ranges
|
|
79
|
+
- Assess if implementation matches requirement intent
|
|
80
|
+
- If divergence detected:
|
|
81
|
+
- Add WARNING: "Implementation may diverge from spec: <details>"
|
|
82
|
+
- Recommendation: "Review <file>:<lines> against requirement X"
|
|
83
|
+
|
|
84
|
+
**Scenario Coverage**:
|
|
85
|
+
- For each scenario in delta specs (marked with "#### Scenario:"):
|
|
86
|
+
- Check if conditions are handled in code
|
|
87
|
+
- Check if tests exist covering the scenario
|
|
88
|
+
- If scenario appears uncovered:
|
|
89
|
+
- Add WARNING: "Scenario not covered: <scenario name>"
|
|
90
|
+
- Recommendation: "Add test or implementation for scenario: <description>"
|
|
91
|
+
|
|
92
|
+
7. **Verify Coherence**
|
|
93
|
+
|
|
94
|
+
**Design Adherence**:
|
|
95
|
+
- If design.md exists in contextFiles:
|
|
96
|
+
- Extract key decisions (look for sections like "Decision:", "Approach:", "Architecture:")
|
|
97
|
+
- Verify implementation follows those decisions
|
|
98
|
+
- If contradiction detected:
|
|
99
|
+
- Add WARNING: "Design decision not followed: <decision>"
|
|
100
|
+
- Recommendation: "Update implementation or revise design.md to match reality"
|
|
101
|
+
- If no design.md: Skip design adherence check, note "No design.md to verify against"
|
|
102
|
+
|
|
103
|
+
**Code Pattern Consistency**:
|
|
104
|
+
- Review new code for consistency with project patterns
|
|
105
|
+
- Check file naming, directory structure, coding style
|
|
106
|
+
- If significant deviations found:
|
|
107
|
+
- Add SUGGESTION: "Code pattern deviation: <details>"
|
|
108
|
+
- Recommendation: "Consider following project pattern: <example>"
|
|
109
|
+
|
|
110
|
+
8. **Generate Verification Report**
|
|
111
|
+
|
|
112
|
+
**Summary Scorecard**:
|
|
113
|
+
```
|
|
114
|
+
## Verification Report: <change-name>
|
|
115
|
+
|
|
116
|
+
### Summary
|
|
117
|
+
| Dimension | Status |
|
|
118
|
+
|--------------|------------------|
|
|
119
|
+
| Completeness | X/Y tasks, N reqs|
|
|
120
|
+
| Correctness | M/N reqs covered |
|
|
121
|
+
| Coherence | Followed/Issues |
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Issues by Priority**:
|
|
125
|
+
|
|
126
|
+
1. **CRITICAL** (Must fix before archive):
|
|
127
|
+
- Incomplete tasks
|
|
128
|
+
- Missing requirement implementations
|
|
129
|
+
- Each with specific, actionable recommendation
|
|
130
|
+
|
|
131
|
+
2. **WARNING** (Should fix):
|
|
132
|
+
- Spec/design divergences
|
|
133
|
+
- Missing scenario coverage
|
|
134
|
+
- Each with specific recommendation
|
|
135
|
+
|
|
136
|
+
3. **SUGGESTION** (Nice to fix):
|
|
137
|
+
- Pattern inconsistencies
|
|
138
|
+
- Minor improvements
|
|
139
|
+
- Each with specific recommendation
|
|
140
|
+
|
|
141
|
+
**Final Assessment**:
|
|
142
|
+
- If CRITICAL issues: "X critical issue(s) found. Fix before archiving."
|
|
143
|
+
- If only warnings: "No critical issues. Y warning(s) to consider. Ready for archive (with noted improvements)."
|
|
144
|
+
- If all clear: "All checks passed. Ready for archive."
|
|
145
|
+
|
|
146
|
+
**Verification Heuristics**
|
|
147
|
+
|
|
148
|
+
- **Completeness**: Focus on objective checklist items (checkboxes, requirements list)
|
|
149
|
+
- **Correctness**: Use keyword search, file path analysis, reasonable inference - don't require perfect certainty
|
|
150
|
+
- **Coherence**: Look for glaring inconsistencies, don't nitpick style
|
|
151
|
+
- **False Positives**: When uncertain, prefer SUGGESTION over WARNING, WARNING over CRITICAL
|
|
152
|
+
- **Actionability**: Every issue must have a specific recommendation with file/line references where applicable
|
|
153
|
+
|
|
154
|
+
**Graceful Degradation**
|
|
155
|
+
|
|
156
|
+
- If only tasks.md exists: verify task completion only, skip spec/design checks
|
|
157
|
+
- If tasks + specs exist: verify completeness and correctness, skip design
|
|
158
|
+
- If full artifacts: verify all three dimensions
|
|
159
|
+
- Always note which checks were skipped and why
|
|
160
|
+
|
|
161
|
+
**Output Format**
|
|
162
|
+
|
|
163
|
+
Use clear markdown with:
|
|
164
|
+
- Table for summary scorecard
|
|
165
|
+
- Grouped lists for issues (CRITICAL/WARNING/SUGGESTION)
|
|
166
|
+
- Code references in format: `file.ts:123`
|
|
167
|
+
- Specific, actionable recommendations
|
|
168
|
+
- No vague suggestions like "consider reviewing"
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
本文件为 Claude Code (claude.ai/code) 在此仓库中工作时提供指导。
|
|
4
|
+
|
|
5
|
+
## 项目概述
|
|
6
|
+
|
|
7
|
+
这是一个使用 TypeScript 实现的 MCP (Model Context Protocol) Server 计算器项目。
|
|
8
|
+
|
|
9
|
+
## 常用命令
|
|
10
|
+
|
|
11
|
+
### 构建与开发
|
|
12
|
+
```bash
|
|
13
|
+
npm run build # 构建项目到 dist/
|
|
14
|
+
npm run dev # 开发模式(监听文件变化)
|
|
15
|
+
npm run typecheck # TypeScript 类型检查
|
|
16
|
+
npm run lint # ESLint 代码检查
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 测试
|
|
20
|
+
```bash
|
|
21
|
+
npm run test # 运行所有测试
|
|
22
|
+
npm run test:ui # 运行测试(带 UI)
|
|
23
|
+
npm run test:coverage # 运行测试并生成覆盖率报告
|
|
24
|
+
|
|
25
|
+
# 运行单个测试文件
|
|
26
|
+
npm test -- <test-file-path>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### MCP Server
|
|
30
|
+
```bash
|
|
31
|
+
# 构建后可运行
|
|
32
|
+
node dist/index.js
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 架构概览
|
|
36
|
+
|
|
37
|
+
项目采用经典的编译器架构,分为以下层次:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
src/
|
|
41
|
+
├── index.ts # MCP Server 入口(stdio 传输)
|
|
42
|
+
├── mcp/
|
|
43
|
+
│ ├── server.ts # MCP Server 实现,注册所有工具
|
|
44
|
+
│ └── tools/ # MCP 工具封装层
|
|
45
|
+
│ ├── basic.ts # basic_calculate 工具
|
|
46
|
+
│ ├── programmer.ts # programmer_calculate 工具
|
|
47
|
+
│ ├── conversion.ts # convert_base 工具
|
|
48
|
+
│ └── ascii.ts # ASCII 转换工具
|
|
49
|
+
├── engines/
|
|
50
|
+
│ ├── decimal.ts # 高精度十进制计算引擎(使用 Decimal.js)
|
|
51
|
+
│ └── programmer.ts # 程序员整数计算引擎(使用 BigInt)
|
|
52
|
+
├── parser/
|
|
53
|
+
│ ├── lexer.ts # 词法分析器(Token 化)
|
|
54
|
+
│ ├── parser.ts # 语法分析器(AST 构建)
|
|
55
|
+
│ └── ast.ts # 抽象语法树类型定义
|
|
56
|
+
└── errors/
|
|
57
|
+
├── types.ts # 错误类型和响应类型
|
|
58
|
+
└── handler.ts # 错误处理器
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 核心设计
|
|
62
|
+
|
|
63
|
+
1. **双层计算引擎**:
|
|
64
|
+
- `DecimalEngine`:使用 Decimal.js 处理高精度十进制运算,解决浮点数精度问题(如 0.1 + 0.2)
|
|
65
|
+
- `ProgrammerEngine`:使用 BigInt 处理整数运算和位运算(&、|、^、~、<<、>>、>>>)
|
|
66
|
+
|
|
67
|
+
2. **统一响应格式**(`src/errors/types.ts`):
|
|
68
|
+
```typescript
|
|
69
|
+
// 成功响应
|
|
70
|
+
{ success: true, result: string, details?: { expression?, steps?[] } }
|
|
71
|
+
// 错误响应
|
|
72
|
+
{ success: false, error: { type, message, position?, suggestion } }
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
3. **AST 节点类型**(`src/parser/ast.ts`):
|
|
76
|
+
- `BinaryOp`:二元运算(+、-、*、/、%、&、|、^、<<、>>、>>>)
|
|
77
|
+
- `UnaryOp`:一元运算(-、+、~)
|
|
78
|
+
- `Literal`:字面量(支持十进制、十六进制 0x、二进制 0b、八进制 0o、字符字面量 'A')
|
|
79
|
+
- `Group`:括号分组
|
|
80
|
+
|
|
81
|
+
4. **MCP 工具注册**:在 `src/mcp/server.ts` 中注册新工具,添加到 `TOOLS` 数组和 `CallToolRequestSchema` 处理器的 switch 语句中。
|
|
82
|
+
|
|
83
|
+
## 必须遵守
|
|
84
|
+
|
|
85
|
+
不管是**提问**还是生成 Markdown **文档**,都必须使用中文。
|
|
86
|
+
|
|
87
|
+
包括但不限于以下文档生成:
|
|
88
|
+
- 在使用 OpenSpec 规范驱动开发过程中生成的文档(proposal.md、design.md、tasks.md 和 spec.md)
|
|
89
|
+
- 在使用 superpower 规范驱动开发过程中生成的文档(设计文档、实施文档)
|
|
90
|
+
- README.md 说明文档
|
|
91
|
+
- 使用指南文档
|
|
92
|
+
- 任何需要生成文档的地方
|