@mcpc-tech/cli 0.1.6 → 0.1.8-beta.1
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/bin/mcpc.mjs +78 -45
- package/package.json +1 -1
- package/types/src/app.d.ts.map +1 -1
- package/types/src/config/loader.d.ts.map +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
|
-
|
|
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
|
|
718
|
-
if (
|
|
719
|
-
text =
|
|
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
|
}
|
|
@@ -1452,13 +1477,13 @@ var AgenticExecutor = class {
|
|
|
1452
1477
|
this.tracingEnabled = false;
|
|
1453
1478
|
}
|
|
1454
1479
|
}
|
|
1455
|
-
async execute(args, schema) {
|
|
1480
|
+
async execute(args, schema, parentSpan) {
|
|
1456
1481
|
const executeSpan = this.tracingEnabled ? startSpan("mcpc.agentic_execute", {
|
|
1457
1482
|
agent: this.name,
|
|
1458
1483
|
action: String(args[this.ACTION_KEY] ?? "unknown"),
|
|
1459
1484
|
nextAction: String(args[this.NEXT_ACTION_KEY] ?? "none"),
|
|
1460
1485
|
args: JSON.stringify(args)
|
|
1461
|
-
}) : null;
|
|
1486
|
+
}, parentSpan ?? void 0) : null;
|
|
1462
1487
|
try {
|
|
1463
1488
|
const validationResult = this.validate(args, schema);
|
|
1464
1489
|
if (!validationResult.valid) {
|
|
@@ -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
|
|
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
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
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}`;
|
|
@@ -2120,7 +2143,7 @@ var BaseSamplingExecutor = class {
|
|
|
2120
2143
|
if (iterationSpan) endSpan(iterationSpan);
|
|
2121
2144
|
continue;
|
|
2122
2145
|
}
|
|
2123
|
-
const result = await this.processAction(parsedData, schema, state,
|
|
2146
|
+
const result = await this.processAction(parsedData, schema, state, iterationSpan);
|
|
2124
2147
|
this.logIterationProgress(parsedData, result, model, stopReason, role);
|
|
2125
2148
|
if (iterationSpan) {
|
|
2126
2149
|
let rawJson = "{}";
|
|
@@ -2174,23 +2197,15 @@ var BaseSamplingExecutor = class {
|
|
|
2174
2197
|
return await this.createExecutionError(error, loopSpan);
|
|
2175
2198
|
}
|
|
2176
2199
|
}
|
|
2177
|
-
addParsingErrorToHistory(
|
|
2178
|
-
|
|
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:
|
|
2190
|
-
errorMessage: `JSON parsing failed: ${parseError instanceof Error ? parseError.message : String(parseError)}
|
|
2206
|
+
text: `Invalid JSON: ${errorMsg}
|
|
2191
2207
|
|
|
2192
|
-
|
|
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
|
|
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
|
|
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,
|
|
@@ -2408,12 +2423,21 @@ var SamplingExecutor = class extends BaseSamplingExecutor {
|
|
|
2408
2423
|
}
|
|
2409
2424
|
async processAction(parsedData, schema, _state, parentSpan) {
|
|
2410
2425
|
const toolCallData = parsedData;
|
|
2426
|
+
const isComplete = toolCallData.decision === "complete";
|
|
2427
|
+
const actionName = toolCallData.action;
|
|
2428
|
+
if (isComplete && actionName && actionName !== "complete") {
|
|
2429
|
+
this.logger.debug({
|
|
2430
|
+
message: "Decision is 'complete' with action present, treating as 'proceed'",
|
|
2431
|
+
action: actionName
|
|
2432
|
+
});
|
|
2433
|
+
toolCallData.decision = "proceed";
|
|
2434
|
+
}
|
|
2411
2435
|
if (toolCallData.decision === "complete") {
|
|
2412
2436
|
return await this.createCompletionResult("Task completed", parentSpan);
|
|
2413
2437
|
}
|
|
2414
2438
|
try {
|
|
2415
2439
|
const { action: _action, decision: _decision, ..._toolArgs } = toolCallData;
|
|
2416
|
-
const toolResult = await this.agenticExecutor.execute(toolCallData, schema);
|
|
2440
|
+
const toolResult = await this.agenticExecutor.execute(toolCallData, schema, parentSpan);
|
|
2417
2441
|
const resultText = toolResult.content?.filter((content) => content.type === "text")?.map((content) => content.text)?.join("\n") || "No result";
|
|
2418
2442
|
this.conversationHistory.push({
|
|
2419
2443
|
role: "assistant",
|
|
@@ -2453,10 +2477,10 @@ ${JSON.stringify(context2, null, 2)}`;
|
|
|
2453
2477
|
const taskPrompt = `
|
|
2454
2478
|
|
|
2455
2479
|
## Current Task
|
|
2456
|
-
|
|
2480
|
+
You will now use agentic sampling to complete the following task: "${userRequest}"${contextInfo}
|
|
2457
2481
|
|
|
2458
|
-
When
|
|
2459
|
-
When the task is complete,
|
|
2482
|
+
When you need to use a tool, specify the tool name in 'action' and provide tool-specific parameters as additional properties.
|
|
2483
|
+
When the task is complete, use "action": "complete".`;
|
|
2460
2484
|
return this.injectJsonInstruction({
|
|
2461
2485
|
prompt: basePrompt + taskPrompt,
|
|
2462
2486
|
schema: agenticSchema
|
|
@@ -3028,6 +3052,15 @@ var WorkflowSamplingExecutor = class extends BaseSamplingExecutor {
|
|
|
3028
3052
|
throw new Error("WorkflowState is required for workflow");
|
|
3029
3053
|
}
|
|
3030
3054
|
const toolCallData = parsedData;
|
|
3055
|
+
const isComplete = toolCallData.decision === "complete";
|
|
3056
|
+
const actionName = toolCallData.action;
|
|
3057
|
+
if (isComplete && actionName && actionName !== "complete") {
|
|
3058
|
+
this.logger.debug({
|
|
3059
|
+
message: "Decision is 'complete' with action present, treating as 'proceed'",
|
|
3060
|
+
action: actionName
|
|
3061
|
+
});
|
|
3062
|
+
toolCallData.decision = "proceed";
|
|
3063
|
+
}
|
|
3031
3064
|
if (toolCallData.decision === "complete") {
|
|
3032
3065
|
return await this.createCompletionResult("Task completed", parentSpan);
|
|
3033
3066
|
}
|
package/package.json
CHANGED
package/types/src/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sources":["../../src/app.ts"],"names":[],"mappings":"AAAA,SAAS,WAAW,4BAAwC;AAI5D,cAAc,mBAAmB,
|
|
1
|
+
{"version":3,"file":"app.d.ts","sources":["../../src/app.ts"],"names":[],"mappings":"AAAA,SAAS,WAAW,4BAAwC;AAI5D,cAAc,mBAAmB,0BAA0D;AAC3F,cAAc,UAAU,6BAA6B;AAErD,OAAO,cAAM,eACX,SAAS,eACR,QAAQ,qBA8BT;AAEF,OAAO,cAAM,iBAAgB,YAO3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sources":["../../../src/config/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CC,GAED,cAAc,iBAAiB,
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sources":["../../../src/config/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CC,GAED,cAAc,iBAAiB,0BAAuC;AAKtE,iBAAiB;EACf;;GAEC,GACD,OAAO,MAAM;EACb;;GAEC,GACD,UAAU,MAAM;EAChB;;GAEC,GACD;IACE,QAAQ,OAAO,MAAM,EAAE,OAAO;IAC9B,WAAW,OAAO,MAAM,EAAE,OAAO;;EAEnC;;GAEC,GACD,QAAQ;;AAwHV;;;CAGC,GACD,OAAO,iBAAe,cAAc,QAAQ,aAAa,IAAI;AAoK7D;;CAEC,GACD,OAAO,iBAAS,eAAe,QAAQ,UAAU,GAAG,IAAI"}
|