sonance-brand-mcp 1.3.61 → 1.3.62

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.
@@ -511,7 +511,7 @@ function searchFilesSmart(
511
511
  return sortedResults.map(r => ({ path: r.path, content: r.content, score: r.score }));
512
512
  }
513
513
 
514
- const VISION_SYSTEM_PROMPT = `You edit code. Make ONLY the change requested.
514
+ const VISION_SYSTEM_PROMPT = `You edit code. Return ONLY valid JSON - no explanation, no preamble, no markdown.
515
515
 
516
516
  RULES:
517
517
  1. Copy code EXACTLY from the file - character for character
@@ -519,13 +519,8 @@ RULES:
519
519
  3. For color changes, just change the className
520
520
  4. Do not restructure or reorganize code
521
521
 
522
- Return JSON:
523
- {
524
- "modifications": [{
525
- "filePath": "path",
526
- "patches": [{ "search": "exact code from file", "replace": "changed code" }]
527
- }]
528
- }`;
522
+ RESPOND WITH ONLY THIS JSON FORMAT (nothing else):
523
+ {"modifications":[{"filePath":"path","patches":[{"search":"exact code","replace":"changed code"}]}]}`;
529
524
 
530
525
  export async function POST(request: Request) {
531
526
  // Only allow in development
@@ -992,12 +987,42 @@ This is better than generating patches with made-up code.`,
992
987
 
993
988
  jsonText = jsonText.trim();
994
989
 
995
- // Robust JSON extraction: find the first { and last } to extract JSON object
996
- // This handles cases where the LLM includes preamble text before the JSON
990
+ // Robust JSON extraction: look for {"modifications" pattern specifically
991
+ // This handles cases where the LLM includes preamble text with code blocks
992
+ const jsonStartPatterns = ['{"modifications"', '{ "modifications"', '{\n "modifications"'];
993
+ let jsonStart = -1;
994
+
995
+ for (const pattern of jsonStartPatterns) {
996
+ const idx = jsonText.indexOf(pattern);
997
+ if (idx !== -1 && (jsonStart === -1 || idx < jsonStart)) {
998
+ jsonStart = idx;
999
+ }
1000
+ }
1001
+
1002
+ if (jsonStart !== -1) {
1003
+ // Find the matching closing brace by counting braces
1004
+ let braceCount = 0;
1005
+ let jsonEnd = -1;
1006
+ for (let i = jsonStart; i < jsonText.length; i++) {
1007
+ if (jsonText[i] === '{') braceCount++;
1008
+ if (jsonText[i] === '}') {
1009
+ braceCount--;
1010
+ if (braceCount === 0) {
1011
+ jsonEnd = i;
1012
+ break;
1013
+ }
1014
+ }
1015
+ }
1016
+ if (jsonEnd !== -1) {
1017
+ jsonText = jsonText.substring(jsonStart, jsonEnd + 1);
1018
+ }
1019
+ } else {
1020
+ // Fallback: try first { to last }
997
1021
  const firstBrace = jsonText.indexOf('{');
998
1022
  const lastBrace = jsonText.lastIndexOf('}');
999
1023
  if (firstBrace !== -1 && lastBrace > firstBrace) {
1000
1024
  jsonText = jsonText.substring(firstBrace, lastBrace + 1);
1025
+ }
1001
1026
  }
1002
1027
 
1003
1028
  aiResponse = JSON.parse(jsonText);
@@ -507,7 +507,7 @@ function searchFilesSmart(
507
507
  return sortedResults.map(r => ({ path: r.path, content: r.content, score: r.score }));
508
508
  }
509
509
 
510
- const VISION_SYSTEM_PROMPT = `You edit code. Make ONLY the change requested.
510
+ const VISION_SYSTEM_PROMPT = `You edit code. Return ONLY valid JSON - no explanation, no preamble, no markdown.
511
511
 
512
512
  RULES:
513
513
  1. Copy code EXACTLY from the file - character for character
@@ -515,13 +515,8 @@ RULES:
515
515
  3. For color changes, just change the className
516
516
  4. Do not restructure or reorganize code
517
517
 
518
- Return JSON:
519
- {
520
- "modifications": [{
521
- "filePath": "path",
522
- "patches": [{ "search": "exact code from file", "replace": "changed code" }]
523
- }]
524
- }`;
518
+ RESPOND WITH ONLY THIS JSON FORMAT (nothing else):
519
+ {"modifications":[{"filePath":"path","patches":[{"search":"exact code","replace":"changed code"}]}]}`;
525
520
 
526
521
  export async function POST(request: Request) {
527
522
  // Only allow in development
@@ -958,12 +953,42 @@ This is better than generating patches with made-up code.`,
958
953
  // Clean up any remaining whitespace
959
954
  jsonText = jsonText.trim();
960
955
 
961
- // Robust JSON extraction: find the first { and last } to extract JSON object
962
- // This handles cases where the LLM includes preamble text before the JSON
956
+ // Robust JSON extraction: look for {"modifications" pattern specifically
957
+ // This handles cases where the LLM includes preamble text with code blocks
958
+ const jsonStartPatterns = ['{"modifications"', '{ "modifications"', '{\n "modifications"'];
959
+ let jsonStart = -1;
960
+
961
+ for (const pattern of jsonStartPatterns) {
962
+ const idx = jsonText.indexOf(pattern);
963
+ if (idx !== -1 && (jsonStart === -1 || idx < jsonStart)) {
964
+ jsonStart = idx;
965
+ }
966
+ }
967
+
968
+ if (jsonStart !== -1) {
969
+ // Find the matching closing brace by counting braces
970
+ let braceCount = 0;
971
+ let jsonEnd = -1;
972
+ for (let i = jsonStart; i < jsonText.length; i++) {
973
+ if (jsonText[i] === '{') braceCount++;
974
+ if (jsonText[i] === '}') {
975
+ braceCount--;
976
+ if (braceCount === 0) {
977
+ jsonEnd = i;
978
+ break;
979
+ }
980
+ }
981
+ }
982
+ if (jsonEnd !== -1) {
983
+ jsonText = jsonText.substring(jsonStart, jsonEnd + 1);
984
+ }
985
+ } else {
986
+ // Fallback: try first { to last }
963
987
  const firstBrace = jsonText.indexOf('{');
964
988
  const lastBrace = jsonText.lastIndexOf('}');
965
989
  if (firstBrace !== -1 && lastBrace > firstBrace) {
966
990
  jsonText = jsonText.substring(firstBrace, lastBrace + 1);
991
+ }
967
992
  }
968
993
 
969
994
  aiResponse = JSON.parse(jsonText);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sonance-brand-mcp",
3
- "version": "1.3.61",
3
+ "version": "1.3.62",
4
4
  "description": "MCP Server for Sonance Brand Guidelines and Component Library - gives Claude instant access to brand colors, typography, and UI components.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",