@mcpc-tech/cli 0.1.6 → 0.1.7

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/bin/mcpc.mjs +56 -41
  2. package/package.json +1 -1
package/bin/mcpc.mjs CHANGED
@@ -140,16 +140,8 @@ var init_logger = __esm({
140
140
  }
141
141
  logToConsole(level, data) {
142
142
  const message = typeof data === "string" ? data : JSON.stringify(data);
143
- const prefix = `[${this.loggerName}]`;
144
- if (level === "debug") {
145
- console.debug(prefix, message);
146
- } else if (level === "info" || level === "notice") {
147
- console.info(prefix, message);
148
- } else if (level === "warning") {
149
- console.warn(prefix, message);
150
- } else {
151
- console.error(prefix, message);
152
- }
143
+ const prefix = `[${this.loggerName}:${level}]`;
144
+ console.error(prefix, message);
153
145
  }
154
146
  debug(data) {
155
147
  return this.log("debug", data);
@@ -714,9 +706,42 @@ function stripMarkdownAndText(text) {
714
706
  text = text.replace(/^```(?:json)?\s*\n?/i, "");
715
707
  text = text.replace(/\n?```\s*$/, "");
716
708
  text = text.replace(/^(?:here is|here's|response|result|output|json):\s*/i, "");
717
- const jsonMatch = text.match(/(\{[\s\S]*\}|\[[\s\S]*\])/);
718
- if (jsonMatch) {
719
- text = jsonMatch[1];
709
+ const firstJsonIndex = text.search(/[\{\[]/);
710
+ if (firstJsonIndex >= 0) {
711
+ text = text.slice(firstJsonIndex);
712
+ let depth = 0;
713
+ let inString = false;
714
+ let escapeNext = false;
715
+ const startChar = text[0];
716
+ const endChar = startChar === "{" ? "}" : "]";
717
+ for (let i = 0; i < text.length; i++) {
718
+ const char = text[i];
719
+ if (escapeNext) {
720
+ escapeNext = false;
721
+ continue;
722
+ }
723
+ if (char === "\\") {
724
+ escapeNext = true;
725
+ continue;
726
+ }
727
+ if (char === '"' && !inString) {
728
+ inString = true;
729
+ continue;
730
+ }
731
+ if (char === '"' && inString) {
732
+ inString = false;
733
+ continue;
734
+ }
735
+ if (inString) continue;
736
+ if (char === startChar) {
737
+ depth++;
738
+ } else if (char === endChar) {
739
+ depth--;
740
+ if (depth === 0) {
741
+ return text.slice(0, i + 1);
742
+ }
743
+ }
744
+ }
720
745
  }
721
746
  return text.trim();
722
747
  }
@@ -2052,7 +2077,7 @@ var BaseSamplingExecutor = class {
2052
2077
  role: "user",
2053
2078
  content: {
2054
2079
  type: "text",
2055
- text: 'Return ONLY raw JSON (no code fences or explanations). The JSON MUST include action and decision. Example: {"action":"<tool>","decision":"proceed|complete","<tool>":{}}'
2080
+ text: 'Return ONE AND ONLY ONE raw JSON object (no code fences, explanations, or multiple objects). The JSON MUST include action and decision. Example: {"action":"<tool>","decision":"proceed|complete","<tool>":{}}'
2056
2081
  }
2057
2082
  }
2058
2083
  ];
@@ -2088,15 +2113,13 @@ var BaseSamplingExecutor = class {
2088
2113
  if (iterationSpan) endSpan(iterationSpan);
2089
2114
  continue;
2090
2115
  }
2091
- if (parsedData) {
2092
- this.conversationHistory.push({
2093
- role: "assistant",
2094
- content: {
2095
- type: "text",
2096
- text: JSON.stringify(parsedData, null, 2)
2097
- }
2098
- });
2099
- }
2116
+ this.conversationHistory.push({
2117
+ role: "assistant",
2118
+ content: {
2119
+ type: "text",
2120
+ text: JSON.stringify(parsedData, null, 2)
2121
+ }
2122
+ });
2100
2123
  const action = parsedData["action"];
2101
2124
  const actionStr = action && typeof action === "string" ? String(action) : "unknown_action";
2102
2125
  const spanName = `mcpc.sampling_iteration.${actionStr}`;
@@ -2174,23 +2197,15 @@ var BaseSamplingExecutor = class {
2174
2197
  return await this.createExecutionError(error, loopSpan);
2175
2198
  }
2176
2199
  }
2177
- addParsingErrorToHistory(responseText, parseError) {
2178
- this.conversationHistory.push({
2179
- role: "assistant",
2180
- content: {
2181
- type: "text",
2182
- text: `JSON parsing failed. Response was: ${responseText}`
2183
- }
2184
- });
2200
+ addParsingErrorToHistory(_responseText, parseError) {
2201
+ const errorMsg = parseError instanceof Error ? parseError.message : String(parseError);
2185
2202
  this.conversationHistory.push({
2186
2203
  role: "user",
2187
2204
  content: {
2188
2205
  type: "text",
2189
- text: CompiledPrompts.errorResponse({
2190
- errorMessage: `JSON parsing failed: ${parseError instanceof Error ? parseError.message : String(parseError)}
2206
+ text: `Invalid JSON: ${errorMsg}
2191
2207
 
2192
- Please respond with valid JSON.`
2193
- })
2208
+ Respond with valid JSON.`
2194
2209
  }
2195
2210
  });
2196
2211
  }
@@ -2328,11 +2343,11 @@ ${msg.content.text}`;
2328
2343
  });
2329
2344
  }
2330
2345
  injectJsonInstruction({ prompt, schema, schemaPrefix = "JSON schema:", schemaSuffix = `STRICT REQUIREMENTS:
2331
- 1. Return ONLY raw JSON that passes JSON.parse() - no markdown, code blocks, explanatory text, or extra characters
2346
+ 1. Return ONE AND ONLY ONE raw JSON object that passes JSON.parse() - no markdown, code blocks, explanatory text, or multiple JSON objects
2332
2347
  2. Include ALL required fields with correct data types and satisfy ALL schema constraints (anyOf, oneOf, allOf, not, enum, pattern, min/max, conditionals)
2333
- 3. Your response must be the JSON object itself, nothing else
2348
+ 3. Your response must be a single JSON object, nothing else
2334
2349
 
2335
- INVALID: \`\`\`json{"key":"value"}\`\`\` or "Here is: {"key":"value"}"
2350
+ INVALID: \`\`\`json{"key":"value"}\`\`\` or "Here is: {"key":"value"}" or {"key":"value"}{"key":"value"}
2336
2351
  VALID: {"key":"value"}` }) {
2337
2352
  return [
2338
2353
  prompt != null && prompt.length > 0 ? prompt : void 0,
@@ -2453,10 +2468,10 @@ ${JSON.stringify(context2, null, 2)}`;
2453
2468
  const taskPrompt = `
2454
2469
 
2455
2470
  ## Current Task
2456
- I will now use agentic sampling to complete the following task: "${userRequest}"${contextInfo}
2471
+ You will now use agentic sampling to complete the following task: "${userRequest}"${contextInfo}
2457
2472
 
2458
- When I need to use a tool, I should specify the tool name in 'action' and provide tool-specific parameters as additional properties.
2459
- When the task is complete, I should use "action": "complete".`;
2473
+ When you need to use a tool, specify the tool name in 'action' and provide tool-specific parameters as additional properties.
2474
+ When the task is complete, use "action": "complete".`;
2460
2475
  return this.injectJsonInstruction({
2461
2476
  prompt: basePrompt + taskPrompt,
2462
2477
  schema: agenticSchema
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpc-tech/cli",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "homepage": "https://jsr.io/@mcpc/cli",
5
5
  "type": "module",
6
6
  "dependencies": {