@hyperfixi/mcp-server 2.3.1 → 2.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.
@@ -0,0 +1,247 @@
1
+ // src/tools/feedback-tools.ts
2
+ var feedbackTools = [
3
+ {
4
+ name: "lse_validate_and_feedback",
5
+ description: "Validate LSE input and return structured feedback with machine-actionable hints, corrected examples, and schema context for LLM self-correction.",
6
+ inputSchema: {
7
+ type: "object",
8
+ properties: {
9
+ input: {
10
+ type: "string",
11
+ description: "The LSE input to validate (bracket syntax, JSON, or natural language)"
12
+ },
13
+ format: {
14
+ type: "string",
15
+ description: "Input format: explicit (default), json, protocol (full-fidelity v1.1/v1.2), envelope (v1.2 multi-node), or natural"
16
+ },
17
+ domain: {
18
+ type: "string",
19
+ description: "Domain to validate against (flow, sql, bdd, llm, jsx, todo, behaviorspec, voice)"
20
+ }
21
+ },
22
+ required: ["input"]
23
+ }
24
+ },
25
+ {
26
+ name: "lse_pattern_stats",
27
+ description: "Return pattern hit-rate statistics: success rates by command and language, top diagnostic failures, and outcome distribution.",
28
+ inputSchema: {
29
+ type: "object",
30
+ properties: {
31
+ domain: {
32
+ type: "string",
33
+ description: "Filter stats by domain (optional)"
34
+ }
35
+ }
36
+ }
37
+ }
38
+ ];
39
+ async function handleFeedbackTool(name, args) {
40
+ switch (name) {
41
+ case "lse_validate_and_feedback":
42
+ return handleValidateAndFeedback(args);
43
+ case "lse_pattern_stats":
44
+ return handlePatternStats();
45
+ default:
46
+ return {
47
+ content: [{ type: "text", text: `Unknown feedback tool: ${name}` }],
48
+ isError: true
49
+ };
50
+ }
51
+ }
52
+ async function handleValidateAndFeedback(args) {
53
+ try {
54
+ const { buildFeedback, parseExplicit } = await import("@lokascript/framework");
55
+ const input = args.input;
56
+ if (!input) {
57
+ return {
58
+ content: [{ type: "text", text: "Missing required parameter: input" }],
59
+ isError: true
60
+ };
61
+ }
62
+ const format = args.format || "explicit";
63
+ const domain = args.domain;
64
+ let action;
65
+ let schemaLookup;
66
+ const diagnostics = [];
67
+ if (domain) {
68
+ const schemas = await loadDomainSchemas(domain);
69
+ if (schemas) {
70
+ schemaLookup = createSchemaLookup(schemas);
71
+ }
72
+ }
73
+ if (format === "explicit") {
74
+ try {
75
+ const result = parseExplicit(input, { schemaLookup });
76
+ if (result) {
77
+ action = result.action;
78
+ }
79
+ } catch (e) {
80
+ diagnostics.push({
81
+ severity: "error",
82
+ message: e instanceof Error ? e.message : "Parse error: invalid bracket syntax",
83
+ code: "parse-error"
84
+ });
85
+ }
86
+ } else if (format === "json") {
87
+ try {
88
+ const parsed = JSON.parse(input);
89
+ action = parsed.action;
90
+ if (!action) {
91
+ diagnostics.push({
92
+ severity: "error",
93
+ message: 'JSON missing required "action" field',
94
+ code: "missing-role"
95
+ });
96
+ }
97
+ } catch {
98
+ diagnostics.push({
99
+ severity: "error",
100
+ message: "Invalid JSON syntax",
101
+ code: "parse-error"
102
+ });
103
+ }
104
+ } else if (format === "protocol") {
105
+ try {
106
+ const { validateProtocolJSON, fromProtocolJSON } = await import("@lokascript/framework");
107
+ const parsed = JSON.parse(input);
108
+ const protoDiags = validateProtocolJSON(parsed);
109
+ for (const d of protoDiags) {
110
+ diagnostics.push({ severity: d.severity, message: d.message, code: d.code });
111
+ }
112
+ if (protoDiags.filter((d) => d.severity === "error").length === 0) {
113
+ const node = fromProtocolJSON(parsed);
114
+ action = node.action;
115
+ }
116
+ } catch (e) {
117
+ diagnostics.push({
118
+ severity: "error",
119
+ message: e instanceof Error ? e.message : "Invalid protocol JSON",
120
+ code: "parse-error"
121
+ });
122
+ }
123
+ } else if (format === "envelope") {
124
+ try {
125
+ const { isEnvelope, fromEnvelopeJSON, validateProtocolJSON } = await import("@lokascript/framework");
126
+ const parsed = JSON.parse(input);
127
+ if (!isEnvelope(parsed)) {
128
+ diagnostics.push({
129
+ severity: "error",
130
+ message: "Not a valid LSE envelope: missing lseVersion or nodes",
131
+ code: "invalid-envelope"
132
+ });
133
+ } else {
134
+ for (let i = 0; i < parsed.nodes.length; i++) {
135
+ const nodeDiags = validateProtocolJSON(parsed.nodes[i]);
136
+ for (const d of nodeDiags) {
137
+ diagnostics.push({
138
+ severity: d.severity,
139
+ message: `Node ${i}: ${d.message}`,
140
+ code: d.code
141
+ });
142
+ }
143
+ }
144
+ if (diagnostics.filter((d) => d.severity === "error").length === 0) {
145
+ const envelope = fromEnvelopeJSON(parsed);
146
+ action = envelope.nodes[0]?.action;
147
+ }
148
+ }
149
+ } catch (e) {
150
+ diagnostics.push({
151
+ severity: "error",
152
+ message: e instanceof Error ? e.message : "Invalid envelope JSON",
153
+ code: "parse-error"
154
+ });
155
+ }
156
+ }
157
+ const feedbackFormat = format === "protocol" || format === "envelope" ? "json" : format;
158
+ const feedback = buildFeedback(input, feedbackFormat, diagnostics, schemaLookup, action);
159
+ return {
160
+ content: [{ type: "text", text: JSON.stringify(feedback, null, 2) }]
161
+ };
162
+ } catch (error) {
163
+ return {
164
+ content: [
165
+ {
166
+ type: "text",
167
+ text: `Feedback tool error: ${error instanceof Error ? error.message : String(error)}`
168
+ }
169
+ ],
170
+ isError: true
171
+ };
172
+ }
173
+ }
174
+ var _tracker = null;
175
+ async function getTracker() {
176
+ if (!_tracker) {
177
+ const { PatternTracker } = await import("@lokascript/framework");
178
+ _tracker = new PatternTracker(1e3);
179
+ }
180
+ return _tracker;
181
+ }
182
+ async function getSharedTracker() {
183
+ return getTracker();
184
+ }
185
+ async function handlePatternStats() {
186
+ try {
187
+ const tracker = await getTracker();
188
+ const summary = tracker.getSummary();
189
+ const text = summary.totalEvents === 0 ? "No pattern events recorded yet. Events are recorded as LSE inputs are validated." : JSON.stringify(summary, null, 2);
190
+ return {
191
+ content: [{ type: "text", text }]
192
+ };
193
+ } catch (error) {
194
+ return {
195
+ content: [
196
+ {
197
+ type: "text",
198
+ text: `Pattern stats error: ${error instanceof Error ? error.message : String(error)}`
199
+ }
200
+ ],
201
+ isError: true
202
+ };
203
+ }
204
+ }
205
+ async function loadDomainSchemas(domain) {
206
+ try {
207
+ switch (domain) {
208
+ case "flow":
209
+ return (await import("@lokascript/domain-flow")).allSchemas;
210
+ case "sql":
211
+ return (await import("@lokascript/domain-sql")).allSchemas;
212
+ case "bdd":
213
+ return (await import("@lokascript/domain-bdd")).allSchemas;
214
+ case "llm":
215
+ return (await import("@lokascript/domain-llm")).allSchemas;
216
+ case "jsx":
217
+ return (await import("@lokascript/domain-jsx")).allSchemas;
218
+ case "todo":
219
+ return (await import("@lokascript/domain-todo")).allSchemas;
220
+ case "behaviorspec":
221
+ return (await import("@lokascript/domain-behaviorspec")).allSchemas;
222
+ case "voice":
223
+ return (await import("@lokascript/domain-voice")).allSchemas;
224
+ default:
225
+ return null;
226
+ }
227
+ } catch {
228
+ return null;
229
+ }
230
+ }
231
+ function createSchemaLookup(schemas) {
232
+ const map = /* @__PURE__ */ new Map();
233
+ for (const s of schemas) {
234
+ map.set(s.action, s);
235
+ }
236
+ return {
237
+ getSchema(action) {
238
+ return map.get(action);
239
+ }
240
+ };
241
+ }
242
+
243
+ export {
244
+ feedbackTools,
245
+ handleFeedbackTool,
246
+ getSharedTracker
247
+ };