@grainulation/wheat 1.0.12 → 1.0.13

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.
Files changed (2) hide show
  1. package/lib/serve-mcp.js +35 -17
  2. package/package.json +1 -1
package/lib/serve-mcp.js CHANGED
@@ -170,7 +170,8 @@ function toolAddClaim(dir, args) {
170
170
  }
171
171
 
172
172
  // Check for duplicate ID
173
- if (data.claims.some((c) => c.id === id)) {
173
+ const claims = data.claims || [];
174
+ if (claims.some((c) => c.id === id)) {
174
175
  return { status: "error", message: `Claim ID "${id}" already exists.` };
175
176
  }
176
177
 
@@ -182,15 +183,19 @@ function toolAddClaim(dir, args) {
182
183
  source: { origin: "mcp", artifact: null, connector: null },
183
184
  evidence: evidence || "stated",
184
185
  status: "active",
185
- phase_added: data.meta.phase || "research",
186
+ phase_added: (data.meta || {}).phase || "research",
186
187
  timestamp: new Date().toISOString(),
187
188
  conflicts_with: [],
188
189
  resolved_by: null,
189
190
  tags: tags || [],
190
191
  };
191
192
 
192
- data.claims.push(claim);
193
- fs.writeFileSync(paths.claims, JSON.stringify(data, null, 2) + "\n");
193
+ (data.claims || (data.claims = [])).push(claim);
194
+ try {
195
+ fs.writeFileSync(paths.claims, JSON.stringify(data, null, 2) + "\n");
196
+ } catch (err) {
197
+ return { status: "error", message: `Failed to write claims.json: ${err.message}` };
198
+ }
194
199
 
195
200
  return { status: "ok", message: `Claim ${id} added.`, claim };
196
201
  }
@@ -238,7 +243,11 @@ function toolResolve(dir, args) {
238
243
  loserClaim.status = "superseded";
239
244
  loserClaim.resolved_by = winner;
240
245
 
241
- fs.writeFileSync(paths.claims, JSON.stringify(data, null, 2) + "\n");
246
+ try {
247
+ fs.writeFileSync(paths.claims, JSON.stringify(data, null, 2) + "\n");
248
+ } catch (err) {
249
+ return { status: "error", message: `Failed to write claims.json: ${err.message}` };
250
+ }
242
251
 
243
252
  return {
244
253
  status: "ok",
@@ -324,8 +333,8 @@ function toolStatus(dir) {
324
333
 
325
334
  return {
326
335
  status: "ok",
327
- question: data.meta.question,
328
- phase: data.meta.phase,
336
+ question: (data.meta || {}).question || "(no question set)",
337
+ phase: (data.meta || {}).phase || "unknown",
329
338
  total_claims: claims.length,
330
339
  active_claims: active.length,
331
340
  conflicted_claims: conflicted.length,
@@ -828,16 +837,25 @@ function startServer(dir) {
828
837
  return;
829
838
  }
830
839
 
831
- const response = await handleRequest(
832
- dir,
833
- msg.method,
834
- msg.params || {},
835
- msg.id
836
- );
837
-
838
- // Notifications don't get responses
839
- if (response !== null) {
840
- process.stdout.write(response + "\n");
840
+ try {
841
+ const response = await handleRequest(
842
+ dir,
843
+ msg.method,
844
+ msg.params || {},
845
+ msg.id
846
+ );
847
+
848
+ // Notifications don't get responses
849
+ if (response !== null) {
850
+ process.stdout.write(response + "\n");
851
+ }
852
+ } catch (err) {
853
+ const resp = jsonRpcError(
854
+ msg.id ?? null,
855
+ -32603,
856
+ `Internal error: ${err.message}`
857
+ );
858
+ process.stdout.write(resp + "\n");
841
859
  }
842
860
  });
843
861
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grainulation/wheat",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Research-driven development framework — structured claims, compiled evidence, deterministic output",
5
5
  "license": "MIT",
6
6
  "author": "grainulation contributors",