lawspec 0.31.1 → 0.31.3
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 +89 -2
- package/README.md +85 -9
- package/api.mjs +14 -9
- package/authoring.mjs +899 -0
- package/beam-coverage.mjs +190 -65
- package/beam-doctor.mjs +343 -124
- package/bin/lawspec.mjs +1949 -661
- package/build.json +134 -128
- package/component-packages.mjs +662 -176
- package/component.d.ts +82 -20
- package/component.mjs +317 -94
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -5
- package/doctor.mjs +558 -299
- package/examples-command.mjs +44 -23
- package/failure-database.mjs +60 -17
- package/files.mjs +122 -62
- package/index.d.ts +585 -312
- package/input-files.mjs +90 -25
- package/launcher.mjs +72 -31
- package/learn/coverage.json +184 -112
- package/learn/curriculum.json +4 -1
- package/learn/vendor/fantomas/{LawSpec.Learn.Formatter.5arcua4vy0.wasm → LawSpec.Learn.Formatter.poiijdbsl9.wasm} +0 -0
- package/learn/vendor/fantomas/dotnet.js +3 -3
- package/learn/vendor/manifest.json +4 -8
- package/lsp.mjs +444 -133
- package/mcp.mjs +250 -0
- package/native-evidence.mjs +668 -182
- package/native-examples.mjs +56 -19
- package/native-host.mjs +136 -42
- package/native-parsers/clojure.LICENSE +121 -0
- package/native-parsers/clojure.wasm +0 -0
- package/native-parsers/csharp.LICENSE +21 -0
- package/native-parsers/csharp.wasm +0 -0
- package/native-parsers/elixir.LICENSE +176 -0
- package/native-parsers/elixir.wasm +0 -0
- package/native-parsers/erlang.LICENSE +201 -0
- package/native-parsers/erlang.wasm +0 -0
- package/native-parsers/fsharp.LICENSE +21 -0
- package/native-parsers/fsharp.wasm +0 -0
- package/native-parsers/gleam.LICENSE +202 -0
- package/native-parsers/gleam.wasm +0 -0
- package/native-parsers/go.LICENSE +21 -0
- package/native-parsers/go.wasm +0 -0
- package/native-parsers/groovy.LICENSE +21 -0
- package/native-parsers/groovy.wasm +0 -0
- package/native-parsers/haskell.LICENSE +21 -0
- package/native-parsers/haskell.wasm +0 -0
- package/native-parsers/java.LICENSE +21 -0
- package/native-parsers/java.wasm +0 -0
- package/native-parsers/javascript.LICENSE +21 -0
- package/native-parsers/javascript.wasm +0 -0
- package/native-parsers/kotlin.LICENSE +9 -0
- package/native-parsers/kotlin.wasm +0 -0
- package/native-parsers/lock.json +114 -0
- package/native-parsers/prolog.LICENSE +21 -0
- package/native-parsers/prolog.wasm +0 -0
- package/native-parsers/python.LICENSE +21 -0
- package/native-parsers/python.wasm +0 -0
- package/native-parsers/rust.LICENSE +21 -0
- package/native-parsers/rust.wasm +0 -0
- package/native-parsers/scala.LICENSE +21 -0
- package/native-parsers/scala.wasm +0 -0
- package/native-parsers/swift.LICENSE +21 -0
- package/native-parsers/swift.wasm +0 -0
- package/native-parsers/typescript.LICENSE +21 -0
- package/native-parsers/typescript.wasm +0 -0
- package/node-events-reporter.mjs +41 -17
- package/package.json +4 -3
- package/project.mjs +338 -0
- package/proof.d.ts +93 -19
- package/proof.mjs +1538 -447
- package/read-only-hpack.mjs +6 -5
- package/scala-build-state.mjs +131 -41
- package/scala-coverage.mjs +57 -34
- package/scalars.mjs +23 -8
- package/templates.mjs +566 -617
- package/test-command.mjs +1671 -521
- package/learn/vendor/fantomas/LawSpec.Learn.Formatter.u1ne3a6xd2.wasm +0 -0
package/mcp.mjs
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// Generated from templates/npm/mcp.mjs by lawspec-dev generate. Do not edit.
|
|
2
|
+
import {McpServer} from '@modelcontextprotocol/server';
|
|
3
|
+
import {serveStdio} from '@modelcontextprotocol/server/stdio';
|
|
4
|
+
import * as z from 'zod/v4';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {createCompiler} from './api.mjs';
|
|
7
|
+
import {readManifest, findManifest, dependencyRanges} from './component.mjs';
|
|
8
|
+
import {resolveDependencies} from './component-packages.mjs';
|
|
9
|
+
import {collectNativeSources} from './authoring.mjs';
|
|
10
|
+
import {collectSources} from './files.mjs';
|
|
11
|
+
const VERSION = '0.31.3';
|
|
12
|
+
function diagnostics(result)
|
|
13
|
+
{
|
|
14
|
+
if (result.diagnostics?.length)
|
|
15
|
+
{
|
|
16
|
+
const error = new Error(
|
|
17
|
+
result.diagnostics
|
|
18
|
+
.map(
|
|
19
|
+
item =>
|
|
20
|
+
`${item.at ? `${item.at.file}:${item.at.line}:${item.at.column}: ` : ''}${item.code}: ${item.message}`,
|
|
21
|
+
)
|
|
22
|
+
.join('\n'),
|
|
23
|
+
);
|
|
24
|
+
error.diagnostics = result.diagnostics;
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
function toolError(error)
|
|
30
|
+
{
|
|
31
|
+
return {content: [{type: 'text', text: error.message}], isError: true};
|
|
32
|
+
}
|
|
33
|
+
export async function serveLawSpec(configFile)
|
|
34
|
+
{
|
|
35
|
+
let root;
|
|
36
|
+
const compiler = await createCompiler();
|
|
37
|
+
async function request()
|
|
38
|
+
{
|
|
39
|
+
configFile ??= await findManifest();
|
|
40
|
+
configFile = path.resolve(configFile);
|
|
41
|
+
root = path.dirname(configFile);
|
|
42
|
+
const config = await readManifest(configFile);
|
|
43
|
+
const dependencies = await resolveDependencies(configFile, config, {
|
|
44
|
+
writeLock: false,
|
|
45
|
+
offline: true,
|
|
46
|
+
readOnly: true,
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
sources: await collectSources(root, config.sources, root),
|
|
50
|
+
languageProfile: config.languageProfile,
|
|
51
|
+
verification: config.verification ?? {layers: []},
|
|
52
|
+
...(config.package ? {package: config.package} : {}),
|
|
53
|
+
dependencies: dependencyRanges(config),
|
|
54
|
+
packages: dependencies.packages,
|
|
55
|
+
...(config.generation ? {generation: config.generation} : {}),
|
|
56
|
+
machineBits: config.machineBits ?? 64,
|
|
57
|
+
...((config.component?.version ?? config.package?.version)
|
|
58
|
+
? {projectVersion: config.component?.version ?? config.package?.version}
|
|
59
|
+
: {}),
|
|
60
|
+
now: new Date().toISOString(),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const server = new McpServer({name: 'lawspec', version: VERSION});
|
|
64
|
+
server.registerTool(
|
|
65
|
+
'lawspec_prelude',
|
|
66
|
+
{
|
|
67
|
+
description:
|
|
68
|
+
'Read the installed compiler prelude inventory without a project.',
|
|
69
|
+
inputSchema: z.object({query: z.string().optional()}),
|
|
70
|
+
annotations: {readOnlyHint: true},
|
|
71
|
+
},
|
|
72
|
+
async input =>
|
|
73
|
+
{
|
|
74
|
+
try
|
|
75
|
+
{
|
|
76
|
+
return {
|
|
77
|
+
content: [
|
|
78
|
+
{
|
|
79
|
+
type: 'text',
|
|
80
|
+
text: JSON.stringify(diagnostics(await compiler.prelude(input))),
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error)
|
|
86
|
+
{
|
|
87
|
+
return toolError(error);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
for (const method of ['inspect', 'advise'])
|
|
92
|
+
server.registerTool(
|
|
93
|
+
`lawspec_${method}`,
|
|
94
|
+
{
|
|
95
|
+
description:
|
|
96
|
+
method === 'inspect'
|
|
97
|
+
? 'Read actual generated or bound interfaces without writing files.'
|
|
98
|
+
: 'Read authoring review candidates and explicit analysis limits. No application files are changed.',
|
|
99
|
+
inputSchema: z.object({target: z.string()}),
|
|
100
|
+
annotations: {readOnlyHint: true},
|
|
101
|
+
},
|
|
102
|
+
async ({target}) =>
|
|
103
|
+
{
|
|
104
|
+
try
|
|
105
|
+
{
|
|
106
|
+
const input = await request();
|
|
107
|
+
const config = await readManifest(configFile);
|
|
108
|
+
const selected = config.targets?.find(
|
|
109
|
+
item => item.language === target,
|
|
110
|
+
);
|
|
111
|
+
if (!selected) throw new Error('No matching configured target');
|
|
112
|
+
const result = diagnostics(
|
|
113
|
+
await compiler[method]({
|
|
114
|
+
...input,
|
|
115
|
+
target,
|
|
116
|
+
sourceDir: selected.sourceDir,
|
|
117
|
+
testDir: selected.testDir,
|
|
118
|
+
nativeBindings: selected.nativeBindings,
|
|
119
|
+
...(method === 'advise'
|
|
120
|
+
? {
|
|
121
|
+
nativeSources: await collectNativeSources(
|
|
122
|
+
path.resolve(root, selected.root),
|
|
123
|
+
),
|
|
124
|
+
exceptions: config.authoringExceptions ?? [],
|
|
125
|
+
}
|
|
126
|
+
: {}),
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
return {
|
|
130
|
+
content: [
|
|
131
|
+
{
|
|
132
|
+
type: 'text',
|
|
133
|
+
text: JSON.stringify(
|
|
134
|
+
method === 'advise' ? result.advice : result.interface,
|
|
135
|
+
),
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
catch (error)
|
|
141
|
+
{
|
|
142
|
+
return toolError(error);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
server.registerTool(
|
|
147
|
+
'lawspec_check',
|
|
148
|
+
{
|
|
149
|
+
description:
|
|
150
|
+
'Validate the current LawSpec project and run only the law checks selected by lawspec.edn. Returns compiler diagnostics, verification selection, and explicit evidence statuses.',
|
|
151
|
+
inputSchema: z.object({}),
|
|
152
|
+
annotations: {readOnlyHint: true},
|
|
153
|
+
},
|
|
154
|
+
async () =>
|
|
155
|
+
{
|
|
156
|
+
try
|
|
157
|
+
{
|
|
158
|
+
return {
|
|
159
|
+
content: [
|
|
160
|
+
{
|
|
161
|
+
type: 'text',
|
|
162
|
+
text: JSON.stringify(
|
|
163
|
+
diagnostics(await compiler.check(await request())),
|
|
164
|
+
null,
|
|
165
|
+
2,
|
|
166
|
+
),
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
catch (error)
|
|
172
|
+
{
|
|
173
|
+
return toolError(error);
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
);
|
|
177
|
+
server.registerTool(
|
|
178
|
+
'lawspec_list_laws',
|
|
179
|
+
{
|
|
180
|
+
description:
|
|
181
|
+
'List the laws declared in the current LawSpec project after validating its definitions. This does not imply that laws have been proved or tested.',
|
|
182
|
+
inputSchema: z.object({}),
|
|
183
|
+
annotations: {readOnlyHint: true},
|
|
184
|
+
},
|
|
185
|
+
async () =>
|
|
186
|
+
{
|
|
187
|
+
try
|
|
188
|
+
{
|
|
189
|
+
const result = diagnostics(
|
|
190
|
+
await compiler.check({
|
|
191
|
+
...(await request()),
|
|
192
|
+
verification: {layers: []},
|
|
193
|
+
}),
|
|
194
|
+
);
|
|
195
|
+
const laws = [
|
|
196
|
+
...(result.laws ?? []),
|
|
197
|
+
...(result.temporalLaws ?? []),
|
|
198
|
+
].map(law => ({
|
|
199
|
+
id: `${law.owner}::${law.name}`,
|
|
200
|
+
owner: law.owner,
|
|
201
|
+
name: law.name,
|
|
202
|
+
description: law.description,
|
|
203
|
+
location: law.location,
|
|
204
|
+
kind: law.kind ?? 'property',
|
|
205
|
+
declaration: law.id,
|
|
206
|
+
...(law.scope ? {scope: law.scope} : {}),
|
|
207
|
+
}));
|
|
208
|
+
return {
|
|
209
|
+
content: [{type: 'text', text: JSON.stringify({laws}, null, 2)}],
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
catch (error)
|
|
213
|
+
{
|
|
214
|
+
return toolError(error);
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
);
|
|
218
|
+
server.registerTool(
|
|
219
|
+
'lawspec_explain',
|
|
220
|
+
{
|
|
221
|
+
description:
|
|
222
|
+
'Explain one LawSpec law in readable, mathematical, or developer form. Reads and validates the current project before explaining it.',
|
|
223
|
+
inputSchema: z.object({
|
|
224
|
+
law: z
|
|
225
|
+
.string()
|
|
226
|
+
.describe('Law identity, such as example.codec::round trip'),
|
|
227
|
+
view: z
|
|
228
|
+
.enum(['eng', 'math', 'dev'])
|
|
229
|
+
.default('eng')
|
|
230
|
+
.describe('Explanation style'),
|
|
231
|
+
}),
|
|
232
|
+
annotations: {readOnlyHint: true},
|
|
233
|
+
},
|
|
234
|
+
async ({law, view}) =>
|
|
235
|
+
{
|
|
236
|
+
try
|
|
237
|
+
{
|
|
238
|
+
const result = diagnostics(
|
|
239
|
+
await compiler.explain({...(await request()), law, view}),
|
|
240
|
+
);
|
|
241
|
+
return {content: [{type: 'text', text: result.text}]};
|
|
242
|
+
}
|
|
243
|
+
catch (error)
|
|
244
|
+
{
|
|
245
|
+
return toolError(error);
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
);
|
|
249
|
+
void serveStdio(() => server);
|
|
250
|
+
}
|