agda-mcp-server 0.4.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/LICENSE +23 -0
- package/README.md +472 -0
- package/dist/agda/advanced-queries.d.ts +52 -0
- package/dist/agda/advanced-queries.js +249 -0
- package/dist/agda/advanced-queries.js.map +1 -0
- package/dist/agda/batch.d.ts +6 -0
- package/dist/agda/batch.js +59 -0
- package/dist/agda/batch.js.map +1 -0
- package/dist/agda/expression-operations.d.ts +17 -0
- package/dist/agda/expression-operations.js +86 -0
- package/dist/agda/expression-operations.js.map +1 -0
- package/dist/agda/goal-operations.d.ts +29 -0
- package/dist/agda/goal-operations.js +156 -0
- package/dist/agda/goal-operations.js.map +1 -0
- package/dist/agda/response-parsing.d.ts +4 -0
- package/dist/agda/response-parsing.js +44 -0
- package/dist/agda/response-parsing.js.map +1 -0
- package/dist/agda/session.d.ts +88 -0
- package/dist/agda/session.js +340 -0
- package/dist/agda/session.js.map +1 -0
- package/dist/agda/types.d.ts +99 -0
- package/dist/agda/types.js +5 -0
- package/dist/agda/types.js.map +1 -0
- package/dist/agda-process.d.ts +4 -0
- package/dist/agda-process.js +14 -0
- package/dist/agda-process.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +91 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/navigation.d.ts +3 -0
- package/dist/tools/navigation.js +192 -0
- package/dist/tools/navigation.js.map +1 -0
- package/dist/tools/proof.d.ts +3 -0
- package/dist/tools/proof.js +250 -0
- package/dist/tools/proof.js.map +1 -0
- package/dist/tools/session.d.ts +3 -0
- package/dist/tools/session.js +108 -0
- package/dist/tools/session.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// MIT License — see LICENSE
|
|
2
|
+
//
|
|
3
|
+
// Agda wire-format helpers: message extraction and string escaping.
|
|
4
|
+
/** Extract a human-readable message from an Agda DisplayInfo payload. */
|
|
5
|
+
export function extractMessage(info) {
|
|
6
|
+
// Try common message fields
|
|
7
|
+
if (typeof info.message === "string")
|
|
8
|
+
return info.message;
|
|
9
|
+
if (typeof info.payload === "string")
|
|
10
|
+
return info.payload;
|
|
11
|
+
// GoalSpecific wraps another goalInfo
|
|
12
|
+
if (info.goalInfo && typeof info.goalInfo === "object") {
|
|
13
|
+
return extractMessage(info.goalInfo);
|
|
14
|
+
}
|
|
15
|
+
// Some responses use "contents" or "text"
|
|
16
|
+
if (typeof info.contents === "string")
|
|
17
|
+
return info.contents;
|
|
18
|
+
if (typeof info.text === "string")
|
|
19
|
+
return info.text;
|
|
20
|
+
// AllGoalsWarnings has visibleGoals and invisibleGoals
|
|
21
|
+
if (info.visibleGoals !== undefined || info.invisibleGoals !== undefined) {
|
|
22
|
+
const parts = [];
|
|
23
|
+
if (typeof info.visibleGoals === "string")
|
|
24
|
+
parts.push(info.visibleGoals);
|
|
25
|
+
if (typeof info.invisibleGoals === "string")
|
|
26
|
+
parts.push(info.invisibleGoals);
|
|
27
|
+
if (typeof info.warnings === "string")
|
|
28
|
+
parts.push(info.warnings);
|
|
29
|
+
if (typeof info.errors === "string")
|
|
30
|
+
parts.push(info.errors);
|
|
31
|
+
if (parts.length > 0)
|
|
32
|
+
return parts.join("\n\n");
|
|
33
|
+
}
|
|
34
|
+
// Fallback: stringify
|
|
35
|
+
return JSON.stringify(info, null, 2);
|
|
36
|
+
}
|
|
37
|
+
/** Escape a string for embedding in an Agda IOTCM command. */
|
|
38
|
+
export function escapeAgdaString(s) {
|
|
39
|
+
return s
|
|
40
|
+
.replace(/\\/g, "\\\\")
|
|
41
|
+
.replace(/"/g, '\\"')
|
|
42
|
+
.replace(/\n/g, "\\n");
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=response-parsing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-parsing.js","sourceRoot":"","sources":["../../src/agda/response-parsing.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B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MAAM,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;IAED,sBAAsB;IACtB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACvC,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,gBAAgB,CAAC,CAAS;IACxC,OAAO,CAAC;SACL,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ChildProcess } from "node:child_process";
|
|
2
|
+
import { EventEmitter } from "node:events";
|
|
3
|
+
import type { AgdaResponse, AgdaGoal, LoadResult, GoalInfo, CaseSplitResult, GiveResult, ComputeResult, InferResult, AutoResult, WhyInScopeResult, ElaborateResult, HelperFunctionResult, ModuleContentsResult, SearchAboutResult, GoalTypeContextInferResult } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Find the repo-pinned Agda binary.
|
|
6
|
+
*/
|
|
7
|
+
export declare function findAgdaBinary(repoRoot: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* A stateful Agda interaction session.
|
|
10
|
+
*
|
|
11
|
+
* Spawns `agda --interaction-json` and keeps it alive. Commands are sent
|
|
12
|
+
* via stdin as IOTCM strings; JSON responses are collected from stdout
|
|
13
|
+
* until a "status" response signals command completion.
|
|
14
|
+
*
|
|
15
|
+
* Domain-specific command logic is delegated to standalone functions in
|
|
16
|
+
* goal-operations, expression-operations, and advanced-queries modules.
|
|
17
|
+
* This class implements AgdaSessionContext implicitly so delegate
|
|
18
|
+
* functions can access the shared transport and state.
|
|
19
|
+
*/
|
|
20
|
+
export declare class AgdaSession {
|
|
21
|
+
proc: ChildProcess | null;
|
|
22
|
+
repoRoot: string;
|
|
23
|
+
currentFile: string | null;
|
|
24
|
+
goalIds: number[];
|
|
25
|
+
buffer: string;
|
|
26
|
+
responseQueue: AgdaResponse[];
|
|
27
|
+
emitter: EventEmitter<[never]>;
|
|
28
|
+
collecting: boolean;
|
|
29
|
+
constructor(repoRoot: string);
|
|
30
|
+
/** Start the Agda process if not already running. */
|
|
31
|
+
ensureProcess(): ChildProcess;
|
|
32
|
+
/** Parse newline-delimited JSON from the stdout buffer. */
|
|
33
|
+
private drainBuffer;
|
|
34
|
+
/**
|
|
35
|
+
* Send an IOTCM command and collect responses until completion.
|
|
36
|
+
* Returns all JSON responses received during this command.
|
|
37
|
+
*/
|
|
38
|
+
sendCommand(command: string, timeoutMs?: number): Promise<AgdaResponse[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Build an IOTCM command string.
|
|
41
|
+
* Format: IOTCM "<filepath>" NonInteractive Direct (<agda-command>)
|
|
42
|
+
*/
|
|
43
|
+
iotcm(agdaCmd: string): string;
|
|
44
|
+
/** Get the currently loaded file path, or throw if none loaded. */
|
|
45
|
+
requireFile(): string;
|
|
46
|
+
/**
|
|
47
|
+
* Load (type-check) a file. This is always the first command — it
|
|
48
|
+
* establishes the interaction state and assigns goal IDs.
|
|
49
|
+
*/
|
|
50
|
+
load(filePath: string): Promise<LoadResult>;
|
|
51
|
+
goalTypeContext(goalId: number): Promise<GoalInfo>;
|
|
52
|
+
caseSplit(goalId: number, variable: string): Promise<CaseSplitResult>;
|
|
53
|
+
give(goalId: number, expr: string): Promise<GiveResult>;
|
|
54
|
+
refine(goalId: number, expr: string): Promise<GiveResult>;
|
|
55
|
+
autoOne(goalId: number): Promise<AutoResult>;
|
|
56
|
+
metas(): Promise<{
|
|
57
|
+
goals: AgdaGoal[];
|
|
58
|
+
text: string;
|
|
59
|
+
raw: AgdaResponse[];
|
|
60
|
+
}>;
|
|
61
|
+
compute(goalId: number, expr: string): Promise<ComputeResult>;
|
|
62
|
+
computeTopLevel(expr: string): Promise<ComputeResult>;
|
|
63
|
+
infer(goalId: number, expr: string): Promise<InferResult>;
|
|
64
|
+
inferTopLevel(expr: string): Promise<InferResult>;
|
|
65
|
+
constraints(): Promise<{
|
|
66
|
+
text: string;
|
|
67
|
+
raw: AgdaResponse[];
|
|
68
|
+
}>;
|
|
69
|
+
solveAll(): Promise<{
|
|
70
|
+
solutions: string[];
|
|
71
|
+
raw: AgdaResponse[];
|
|
72
|
+
}>;
|
|
73
|
+
whyInScope(goalId: number, name: string): Promise<WhyInScopeResult>;
|
|
74
|
+
whyInScopeTopLevel(name: string): Promise<WhyInScopeResult>;
|
|
75
|
+
elaborate(goalId: number, expr: string): Promise<ElaborateResult>;
|
|
76
|
+
helperFunction(goalId: number, expr: string): Promise<HelperFunctionResult>;
|
|
77
|
+
showModuleContents(goalId: number, moduleName: string): Promise<ModuleContentsResult>;
|
|
78
|
+
showModuleContentsTopLevel(moduleName: string): Promise<ModuleContentsResult>;
|
|
79
|
+
searchAbout(query: string): Promise<SearchAboutResult>;
|
|
80
|
+
autoAll(): Promise<AutoResult>;
|
|
81
|
+
goalTypeContextInfer(goalId: number, expr: string): Promise<GoalTypeContextInferResult>;
|
|
82
|
+
/** Get current goal IDs. */
|
|
83
|
+
getGoalIds(): number[];
|
|
84
|
+
/** Get the currently loaded file. */
|
|
85
|
+
getLoadedFile(): string | null;
|
|
86
|
+
/** Kill the Agda process and reset state. */
|
|
87
|
+
destroy(): void;
|
|
88
|
+
}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// MIT License — see LICENSE
|
|
2
|
+
//
|
|
3
|
+
// Stateful Agda interaction process manager
|
|
4
|
+
//
|
|
5
|
+
// Manages a long-running Agda process using --interaction-json mode.
|
|
6
|
+
// Agda's IOTCM protocol is stateful: after Cmd_load, interaction points
|
|
7
|
+
// (goals) are assigned integer IDs that persist for subsequent commands
|
|
8
|
+
// like Cmd_goal_type_context, Cmd_make_case, Cmd_give, etc.
|
|
9
|
+
//
|
|
10
|
+
// Protocol reference:
|
|
11
|
+
// Input: IOTCM "<filepath>" NonInteractive Direct (<command>)
|
|
12
|
+
// Output: Newline-delimited JSON with "kind" field
|
|
13
|
+
// Commands: Cmd_load, Cmd_metas, Cmd_goal_type_context, Cmd_make_case,
|
|
14
|
+
// Cmd_give, Cmd_refine_or_intro, Cmd_auto, Cmd_compute,
|
|
15
|
+
// Cmd_infer, Cmd_constraints, Cmd_solveAll
|
|
16
|
+
//
|
|
17
|
+
// Architecture:
|
|
18
|
+
// This file owns process lifecycle and the IOTCM transport layer.
|
|
19
|
+
// Domain-specific command logic is delegated to:
|
|
20
|
+
// goal-operations.ts — goal type/context, case split, give, refine, auto, metas
|
|
21
|
+
// expression-operations.ts — compute, infer (goal-level and top-level)
|
|
22
|
+
// advanced-queries.ts — constraints, solve, scope, elaborate, modules, search
|
|
23
|
+
import { spawn } from "node:child_process";
|
|
24
|
+
import { resolve } from "node:path";
|
|
25
|
+
import { existsSync } from "node:fs";
|
|
26
|
+
import { EventEmitter } from "node:events";
|
|
27
|
+
import { extractMessage } from "./response-parsing.js";
|
|
28
|
+
// Delegate modules
|
|
29
|
+
import * as GoalOps from "./goal-operations.js";
|
|
30
|
+
import * as ExprOps from "./expression-operations.js";
|
|
31
|
+
import * as AdvancedOps from "./advanced-queries.js";
|
|
32
|
+
// ── Binary discovery ──────────────────────────────────────────────────
|
|
33
|
+
/**
|
|
34
|
+
* Find the repo-pinned Agda binary.
|
|
35
|
+
*/
|
|
36
|
+
export function findAgdaBinary(repoRoot) {
|
|
37
|
+
const pinned = resolve(repoRoot, "tooling/scripts/run-pinned-agda.sh");
|
|
38
|
+
if (existsSync(pinned)) {
|
|
39
|
+
return pinned;
|
|
40
|
+
}
|
|
41
|
+
return "agda";
|
|
42
|
+
}
|
|
43
|
+
// ── Agda Session ──────────────────────────────────────────────────────
|
|
44
|
+
/**
|
|
45
|
+
* A stateful Agda interaction session.
|
|
46
|
+
*
|
|
47
|
+
* Spawns `agda --interaction-json` and keeps it alive. Commands are sent
|
|
48
|
+
* via stdin as IOTCM strings; JSON responses are collected from stdout
|
|
49
|
+
* until a "status" response signals command completion.
|
|
50
|
+
*
|
|
51
|
+
* Domain-specific command logic is delegated to standalone functions in
|
|
52
|
+
* goal-operations, expression-operations, and advanced-queries modules.
|
|
53
|
+
* This class implements AgdaSessionContext implicitly so delegate
|
|
54
|
+
* functions can access the shared transport and state.
|
|
55
|
+
*/
|
|
56
|
+
export class AgdaSession {
|
|
57
|
+
proc = null;
|
|
58
|
+
repoRoot;
|
|
59
|
+
currentFile = null;
|
|
60
|
+
goalIds = [];
|
|
61
|
+
buffer = "";
|
|
62
|
+
responseQueue = [];
|
|
63
|
+
emitter = new EventEmitter();
|
|
64
|
+
collecting = false;
|
|
65
|
+
constructor(repoRoot) {
|
|
66
|
+
this.repoRoot = repoRoot;
|
|
67
|
+
}
|
|
68
|
+
/** Start the Agda process if not already running. */
|
|
69
|
+
ensureProcess() {
|
|
70
|
+
if (this.proc && this.proc.exitCode === null) {
|
|
71
|
+
return this.proc;
|
|
72
|
+
}
|
|
73
|
+
const agdaBin = findAgdaBinary(this.repoRoot);
|
|
74
|
+
this.proc = spawn(agdaBin, ["--interaction-json"], {
|
|
75
|
+
cwd: this.repoRoot,
|
|
76
|
+
env: { ...process.env },
|
|
77
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
78
|
+
});
|
|
79
|
+
this.proc.stdout?.on("data", (chunk) => {
|
|
80
|
+
this.buffer += chunk.toString();
|
|
81
|
+
this.drainBuffer();
|
|
82
|
+
});
|
|
83
|
+
this.proc.stderr?.on("data", (chunk) => {
|
|
84
|
+
// Agda prints progress/warnings to stderr — capture for diagnostics
|
|
85
|
+
const text = chunk.toString();
|
|
86
|
+
if (this.collecting) {
|
|
87
|
+
this.responseQueue.push({
|
|
88
|
+
kind: "StderrOutput",
|
|
89
|
+
text,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
this.proc.on("close", () => {
|
|
94
|
+
this.proc = null;
|
|
95
|
+
this.currentFile = null;
|
|
96
|
+
this.goalIds = [];
|
|
97
|
+
// Signal any waiting command
|
|
98
|
+
this.emitter.emit("done");
|
|
99
|
+
});
|
|
100
|
+
this.proc.on("error", (err) => {
|
|
101
|
+
this.emitter.emit("error", err);
|
|
102
|
+
});
|
|
103
|
+
return this.proc;
|
|
104
|
+
}
|
|
105
|
+
/** Parse newline-delimited JSON from the stdout buffer. */
|
|
106
|
+
drainBuffer() {
|
|
107
|
+
const lines = this.buffer.split("\n");
|
|
108
|
+
this.buffer = lines.pop() ?? "";
|
|
109
|
+
for (const line of lines) {
|
|
110
|
+
const trimmed = line.trim();
|
|
111
|
+
if (!trimmed)
|
|
112
|
+
continue;
|
|
113
|
+
// Agda may emit non-JSON preamble lines (e.g. "Agda2>")
|
|
114
|
+
if (!trimmed.startsWith("{") && !trimmed.startsWith("["))
|
|
115
|
+
continue;
|
|
116
|
+
try {
|
|
117
|
+
const resp = JSON.parse(trimmed);
|
|
118
|
+
if (this.collecting) {
|
|
119
|
+
this.responseQueue.push(resp);
|
|
120
|
+
}
|
|
121
|
+
// A Status response with checked=true signals command completion
|
|
122
|
+
if (resp.kind === "Status") {
|
|
123
|
+
this.emitter.emit("done");
|
|
124
|
+
}
|
|
125
|
+
// ClearHighlighting/ClearRunningInfo can also signal end of response
|
|
126
|
+
if (resp.kind === "ClearRunningInfo") {
|
|
127
|
+
// Give a small delay for any trailing responses, then signal
|
|
128
|
+
setTimeout(() => this.emitter.emit("done"), 100);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// Non-JSON line — skip
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Send an IOTCM command and collect responses until completion.
|
|
138
|
+
* Returns all JSON responses received during this command.
|
|
139
|
+
*/
|
|
140
|
+
sendCommand(command, timeoutMs = 120_000) {
|
|
141
|
+
const proc = this.ensureProcess();
|
|
142
|
+
this.responseQueue = [];
|
|
143
|
+
this.collecting = true;
|
|
144
|
+
return new Promise((resolveCmd, rejectCmd) => {
|
|
145
|
+
const timeout = setTimeout(() => {
|
|
146
|
+
this.collecting = false;
|
|
147
|
+
resolveCmd([...this.responseQueue]);
|
|
148
|
+
}, timeoutMs);
|
|
149
|
+
const onDone = () => {
|
|
150
|
+
// Wait briefly for any trailing responses
|
|
151
|
+
setTimeout(() => {
|
|
152
|
+
clearTimeout(timeout);
|
|
153
|
+
this.collecting = false;
|
|
154
|
+
this.emitter.removeListener("done", onDone);
|
|
155
|
+
this.emitter.removeListener("error", onError);
|
|
156
|
+
resolveCmd([...this.responseQueue]);
|
|
157
|
+
}, 200);
|
|
158
|
+
};
|
|
159
|
+
const onError = (err) => {
|
|
160
|
+
clearTimeout(timeout);
|
|
161
|
+
this.collecting = false;
|
|
162
|
+
this.emitter.removeListener("done", onDone);
|
|
163
|
+
rejectCmd(err);
|
|
164
|
+
};
|
|
165
|
+
this.emitter.on("done", onDone);
|
|
166
|
+
this.emitter.on("error", onError);
|
|
167
|
+
proc.stdin?.write(command + "\n");
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Build an IOTCM command string.
|
|
172
|
+
* Format: IOTCM "<filepath>" NonInteractive Direct (<agda-command>)
|
|
173
|
+
*/
|
|
174
|
+
iotcm(agdaCmd) {
|
|
175
|
+
const fp = this.currentFile ?? "";
|
|
176
|
+
return `IOTCM "${fp}" NonInteractive Direct (${agdaCmd})`;
|
|
177
|
+
}
|
|
178
|
+
/** Get the currently loaded file path, or throw if none loaded. */
|
|
179
|
+
requireFile() {
|
|
180
|
+
if (!this.currentFile) {
|
|
181
|
+
throw new Error("No file loaded. Call load() first.");
|
|
182
|
+
}
|
|
183
|
+
return this.currentFile;
|
|
184
|
+
}
|
|
185
|
+
// ── Public API ────────────────────────────────────────────────────
|
|
186
|
+
/**
|
|
187
|
+
* Load (type-check) a file. This is always the first command — it
|
|
188
|
+
* establishes the interaction state and assigns goal IDs.
|
|
189
|
+
*/
|
|
190
|
+
async load(filePath) {
|
|
191
|
+
const absPath = resolve(this.repoRoot, filePath);
|
|
192
|
+
if (!existsSync(absPath)) {
|
|
193
|
+
return {
|
|
194
|
+
success: false,
|
|
195
|
+
errors: [`File not found: ${absPath}`],
|
|
196
|
+
warnings: [],
|
|
197
|
+
goals: [],
|
|
198
|
+
allGoalsText: "",
|
|
199
|
+
raw: [],
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
this.currentFile = absPath;
|
|
203
|
+
this.goalIds = [];
|
|
204
|
+
const cmd = this.iotcm(`Cmd_load "${absPath}" []`);
|
|
205
|
+
const responses = await this.sendCommand(cmd);
|
|
206
|
+
const errors = [];
|
|
207
|
+
const warnings = [];
|
|
208
|
+
const goals = [];
|
|
209
|
+
let allGoalsText = "";
|
|
210
|
+
let success = true;
|
|
211
|
+
for (const resp of responses) {
|
|
212
|
+
// Extract interaction points (goal IDs)
|
|
213
|
+
if (resp.kind === "InteractionPoints") {
|
|
214
|
+
const points = resp.interactionPoints;
|
|
215
|
+
if (Array.isArray(points)) {
|
|
216
|
+
for (const pt of points) {
|
|
217
|
+
const id = typeof pt === "number" ? pt : pt.id;
|
|
218
|
+
this.goalIds.push(id);
|
|
219
|
+
goals.push({ goalId: id, type: "?", context: [] });
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// Extract errors from DisplayInfo
|
|
224
|
+
if (resp.kind === "DisplayInfo") {
|
|
225
|
+
const info = resp.info;
|
|
226
|
+
if (info) {
|
|
227
|
+
if (info.kind === "Error") {
|
|
228
|
+
success = false;
|
|
229
|
+
const msg = extractMessage(info);
|
|
230
|
+
errors.push(msg);
|
|
231
|
+
}
|
|
232
|
+
if (info.kind === "AllGoalsWarnings") {
|
|
233
|
+
allGoalsText = extractMessage(info);
|
|
234
|
+
// Parse warnings from the all-goals text
|
|
235
|
+
const warnMatch = allGoalsText.match(/———— Warnings? ————[\s\S]*$/);
|
|
236
|
+
if (warnMatch) {
|
|
237
|
+
warnings.push(warnMatch[0]);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Stderr errors
|
|
243
|
+
if (resp.kind === "StderrOutput") {
|
|
244
|
+
const text = String(resp.text ?? "").trim();
|
|
245
|
+
if (text && (text.includes("Error") || text.includes("error"))) {
|
|
246
|
+
errors.push(text);
|
|
247
|
+
success = false;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return { success, errors, warnings, goals, allGoalsText, raw: responses };
|
|
252
|
+
}
|
|
253
|
+
// ── Goal operations (delegated) ───────────────────────────────────
|
|
254
|
+
async goalTypeContext(goalId) {
|
|
255
|
+
return GoalOps.goalTypeContext(this, goalId);
|
|
256
|
+
}
|
|
257
|
+
async caseSplit(goalId, variable) {
|
|
258
|
+
return GoalOps.caseSplit(this, goalId, variable);
|
|
259
|
+
}
|
|
260
|
+
async give(goalId, expr) {
|
|
261
|
+
return GoalOps.give(this, goalId, expr);
|
|
262
|
+
}
|
|
263
|
+
async refine(goalId, expr) {
|
|
264
|
+
return GoalOps.refine(this, goalId, expr);
|
|
265
|
+
}
|
|
266
|
+
async autoOne(goalId) {
|
|
267
|
+
return GoalOps.autoOne(this, goalId);
|
|
268
|
+
}
|
|
269
|
+
async metas() {
|
|
270
|
+
return GoalOps.metas(this);
|
|
271
|
+
}
|
|
272
|
+
// ── Expression operations (delegated) ─────────────────────────────
|
|
273
|
+
async compute(goalId, expr) {
|
|
274
|
+
return ExprOps.compute(this, goalId, expr);
|
|
275
|
+
}
|
|
276
|
+
async computeTopLevel(expr) {
|
|
277
|
+
return ExprOps.computeTopLevel(this, expr);
|
|
278
|
+
}
|
|
279
|
+
async infer(goalId, expr) {
|
|
280
|
+
return ExprOps.infer(this, goalId, expr);
|
|
281
|
+
}
|
|
282
|
+
async inferTopLevel(expr) {
|
|
283
|
+
return ExprOps.inferTopLevel(this, expr);
|
|
284
|
+
}
|
|
285
|
+
// ── Advanced queries (delegated) ──────────────────────────────────
|
|
286
|
+
async constraints() {
|
|
287
|
+
return AdvancedOps.constraints(this);
|
|
288
|
+
}
|
|
289
|
+
async solveAll() {
|
|
290
|
+
return AdvancedOps.solveAll(this);
|
|
291
|
+
}
|
|
292
|
+
async whyInScope(goalId, name) {
|
|
293
|
+
return AdvancedOps.whyInScope(this, goalId, name);
|
|
294
|
+
}
|
|
295
|
+
async whyInScopeTopLevel(name) {
|
|
296
|
+
return AdvancedOps.whyInScopeTopLevel(this, name);
|
|
297
|
+
}
|
|
298
|
+
async elaborate(goalId, expr) {
|
|
299
|
+
return AdvancedOps.elaborate(this, goalId, expr);
|
|
300
|
+
}
|
|
301
|
+
async helperFunction(goalId, expr) {
|
|
302
|
+
return AdvancedOps.helperFunction(this, goalId, expr);
|
|
303
|
+
}
|
|
304
|
+
async showModuleContents(goalId, moduleName) {
|
|
305
|
+
return AdvancedOps.showModuleContents(this, goalId, moduleName);
|
|
306
|
+
}
|
|
307
|
+
async showModuleContentsTopLevel(moduleName) {
|
|
308
|
+
return AdvancedOps.showModuleContentsTopLevel(this, moduleName);
|
|
309
|
+
}
|
|
310
|
+
async searchAbout(query) {
|
|
311
|
+
return AdvancedOps.searchAbout(this, query);
|
|
312
|
+
}
|
|
313
|
+
async autoAll() {
|
|
314
|
+
return AdvancedOps.autoAll(this);
|
|
315
|
+
}
|
|
316
|
+
async goalTypeContextInfer(goalId, expr) {
|
|
317
|
+
return AdvancedOps.goalTypeContextInfer(this, goalId, expr);
|
|
318
|
+
}
|
|
319
|
+
// ── Accessors ─────────────────────────────────────────────────────
|
|
320
|
+
/** Get current goal IDs. */
|
|
321
|
+
getGoalIds() {
|
|
322
|
+
return [...this.goalIds];
|
|
323
|
+
}
|
|
324
|
+
/** Get the currently loaded file. */
|
|
325
|
+
getLoadedFile() {
|
|
326
|
+
return this.currentFile;
|
|
327
|
+
}
|
|
328
|
+
/** Kill the Agda process and reset state. */
|
|
329
|
+
destroy() {
|
|
330
|
+
if (this.proc) {
|
|
331
|
+
this.proc.kill();
|
|
332
|
+
this.proc = null;
|
|
333
|
+
}
|
|
334
|
+
this.currentFile = null;
|
|
335
|
+
this.goalIds = [];
|
|
336
|
+
this.buffer = "";
|
|
337
|
+
this.responseQueue = [];
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/agda/session.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,EAAE;AACF,4CAA4C;AAC5C,EAAE;AACF,qEAAqE;AACrE,wEAAwE;AACxE,wEAAwE;AACxE,4DAA4D;AAC5D,EAAE;AACF,sBAAsB;AACtB,iEAAiE;AACjE,qDAAqD;AACrD,yEAAyE;AACzE,oEAAoE;AACpE,uDAAuD;AACvD,EAAE;AACF,gBAAgB;AAChB,oEAAoE;AACpE,mDAAmD;AACnD,0FAA0F;AAC1F,2EAA2E;AAC3E,uFAAuF;AAEvF,OAAO,EAAE,KAAK,EAAgB,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAkB3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,mBAAmB;AACnB,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,OAAO,MAAM,4BAA4B,CAAC;AACtD,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAC;AAErD,yEAAyE;AAEzE;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC7C,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,oCAAoC,CAAC,CAAC;IACvE,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACvB,OA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IAAI,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,OAAO;QACX,OAAO,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,MAAc,EAAE,IAAY;QACrD,OAAO,WAAW,CAAC,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;IAED,qEAAqE;IAErE,4BAA4B;IAC5B,UAAU;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,qCAAqC;IACrC,aAAa;QACX,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,6CAA6C;IAC7C,OAAO;QACL,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACnB,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { ChildProcess } from "node:child_process";
|
|
2
|
+
import type { EventEmitter } from "node:events";
|
|
3
|
+
/**
|
|
4
|
+
* Shared mutable state exposed by AgdaSession to delegate functions.
|
|
5
|
+
*
|
|
6
|
+
* Delegate modules (goal-operations, expression-operations,
|
|
7
|
+
* advanced-queries) accept this interface as their first argument,
|
|
8
|
+
* keeping them decoupled from the full AgdaSession class.
|
|
9
|
+
*/
|
|
10
|
+
export interface AgdaSessionContext {
|
|
11
|
+
proc: ChildProcess | null;
|
|
12
|
+
repoRoot: string;
|
|
13
|
+
currentFile: string | null;
|
|
14
|
+
goalIds: number[];
|
|
15
|
+
buffer: string;
|
|
16
|
+
responseQueue: AgdaResponse[];
|
|
17
|
+
emitter: EventEmitter;
|
|
18
|
+
collecting: boolean;
|
|
19
|
+
ensureProcess(): ChildProcess;
|
|
20
|
+
sendCommand(cmd: string): Promise<AgdaResponse[]>;
|
|
21
|
+
iotcm(agdaCmd: string): string;
|
|
22
|
+
requireFile(): string;
|
|
23
|
+
}
|
|
24
|
+
export interface AgdaResponse {
|
|
25
|
+
kind: string;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
export interface AgdaGoal {
|
|
29
|
+
goalId: number;
|
|
30
|
+
type: string;
|
|
31
|
+
context: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface LoadResult {
|
|
34
|
+
success: boolean;
|
|
35
|
+
errors: string[];
|
|
36
|
+
warnings: string[];
|
|
37
|
+
goals: AgdaGoal[];
|
|
38
|
+
allGoalsText: string;
|
|
39
|
+
raw: AgdaResponse[];
|
|
40
|
+
}
|
|
41
|
+
export interface GoalInfo {
|
|
42
|
+
goalId: number;
|
|
43
|
+
type: string;
|
|
44
|
+
context: string[];
|
|
45
|
+
raw: AgdaResponse[];
|
|
46
|
+
}
|
|
47
|
+
export interface CaseSplitResult {
|
|
48
|
+
clauses: string[];
|
|
49
|
+
raw: AgdaResponse[];
|
|
50
|
+
}
|
|
51
|
+
export interface GiveResult {
|
|
52
|
+
result: string;
|
|
53
|
+
raw: AgdaResponse[];
|
|
54
|
+
}
|
|
55
|
+
export interface ComputeResult {
|
|
56
|
+
normalForm: string;
|
|
57
|
+
raw: AgdaResponse[];
|
|
58
|
+
}
|
|
59
|
+
export interface InferResult {
|
|
60
|
+
type: string;
|
|
61
|
+
raw: AgdaResponse[];
|
|
62
|
+
}
|
|
63
|
+
export interface AutoResult {
|
|
64
|
+
solution: string;
|
|
65
|
+
raw: AgdaResponse[];
|
|
66
|
+
}
|
|
67
|
+
export interface WhyInScopeResult {
|
|
68
|
+
explanation: string;
|
|
69
|
+
raw: AgdaResponse[];
|
|
70
|
+
}
|
|
71
|
+
export interface ElaborateResult {
|
|
72
|
+
elaboration: string;
|
|
73
|
+
raw: AgdaResponse[];
|
|
74
|
+
}
|
|
75
|
+
export interface HelperFunctionResult {
|
|
76
|
+
helperType: string;
|
|
77
|
+
raw: AgdaResponse[];
|
|
78
|
+
}
|
|
79
|
+
export interface ModuleContentsResult {
|
|
80
|
+
contents: string;
|
|
81
|
+
raw: AgdaResponse[];
|
|
82
|
+
}
|
|
83
|
+
export interface SearchAboutResult {
|
|
84
|
+
results: string;
|
|
85
|
+
raw: AgdaResponse[];
|
|
86
|
+
}
|
|
87
|
+
export interface GoalTypeContextInferResult {
|
|
88
|
+
goalType: string;
|
|
89
|
+
context: string[];
|
|
90
|
+
inferredType: string;
|
|
91
|
+
raw: AgdaResponse[];
|
|
92
|
+
}
|
|
93
|
+
export interface TypeCheckResult {
|
|
94
|
+
success: boolean;
|
|
95
|
+
errors: string[];
|
|
96
|
+
warnings: string[];
|
|
97
|
+
goals: AgdaGoal[];
|
|
98
|
+
raw: AgdaResponse[];
|
|
99
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/agda/types.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,EAAE;AACF,0DAA0D"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { AgdaResponse, AgdaGoal, LoadResult, GoalInfo, CaseSplitResult, GiveResult, ComputeResult, InferResult, AutoResult, WhyInScopeResult, ElaborateResult, HelperFunctionResult, ModuleContentsResult, SearchAboutResult, GoalTypeContextInferResult, TypeCheckResult, } from "./agda/types.js";
|
|
2
|
+
export { AgdaSession, findAgdaBinary } from "./agda/session.js";
|
|
3
|
+
export { typeCheckBatch } from "./agda/batch.js";
|
|
4
|
+
export { extractMessage, escapeAgdaString } from "./agda/response-parsing.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// MIT License — see LICENSE
|
|
2
|
+
//
|
|
3
|
+
// Barrel re-export — preserves backward compatibility for all consumers.
|
|
4
|
+
// Internal modules live in src/agda/.
|
|
5
|
+
//
|
|
6
|
+
// Architecture:
|
|
7
|
+
// agda/types.ts — shared type definitions
|
|
8
|
+
// agda/response-parsing.ts — Agda wire-format helpers
|
|
9
|
+
// agda/session.ts — stateful AgdaSession class
|
|
10
|
+
// agda/batch.ts — stateless batch type-checking
|
|
11
|
+
export { AgdaSession, findAgdaBinary } from "./agda/session.js";
|
|
12
|
+
export { typeCheckBatch } from "./agda/batch.js";
|
|
13
|
+
export { extractMessage, escapeAgdaString } from "./agda/response-parsing.js";
|
|
14
|
+
//# sourceMappingURL=agda-process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agda-process.js","sourceRoot":"","sources":["../src/agda-process.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,EAAE;AACF,yEAAyE;AACzE,sCAAsC;AACtC,EAAE;AACF,gBAAgB;AAChB,wDAAwD;AACxD,yDAAyD;AACzD,2DAA2D;AAC3D,8DAA8D;AAqB9D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { AgdaSession } from "./agda-process.js";
|
|
4
|
+
type ExtensionRegister = (server: McpServer, session: AgdaSession, repoRoot: string) => void | Promise<void>;
|
|
5
|
+
declare const REPO_ROOT: string;
|
|
6
|
+
declare const session: AgdaSession;
|
|
7
|
+
declare const server: McpServer;
|
|
8
|
+
export { AgdaSession } from "./agda-process.js";
|
|
9
|
+
export type { AgdaResponse, AgdaGoal, LoadResult, GoalInfo } from "./agda-process.js";
|
|
10
|
+
export type { ExtensionRegister };
|
|
11
|
+
export { server, session, REPO_ROOT };
|