tachibot-mcp 2.34.0 → 2.35.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.
- package/CHANGELOG.md +45 -0
- package/README.md +24 -7
- package/dist/src/cli/init.js +1 -1
- package/dist/src/config/model-constants.js +75 -37
- package/dist/src/config/model-defaults.js +1 -1
- package/dist/src/config/timeout-config.js +5 -1
- package/dist/src/modes/architect.js +6 -5
- package/dist/src/modes/code-reviewer.js +3 -1
- package/dist/src/modes/commit-guardian.js +3 -1
- package/dist/src/modes/documentation-writer.js +3 -1
- package/dist/src/modes/scout.js +2 -2
- package/dist/src/optimization/model-router.js +10 -5
- package/dist/src/optimization/token-optimizer.js +2 -1
- package/dist/src/orchestrators/collaborative/services/tool-execution/ToolExecutionService.js +18 -2
- package/dist/src/profiles/balanced.js +2 -1
- package/dist/src/profiles/code_focus.js +3 -2
- package/dist/src/profiles/full.js +2 -1
- package/dist/src/profiles/heavy_coding.js +3 -2
- package/dist/src/profiles/minimal.js +2 -1
- package/dist/src/profiles/research_power.js +3 -2
- package/dist/src/tools/gemini-tools.js +29 -2
- package/dist/src/tools/grok-enhanced.js +53 -26
- package/dist/src/tools/grok-search-lite-tool.js +5 -3
- package/dist/src/tools/grok-tools.js +18 -11
- package/dist/src/tools/jev-tool.js +105 -0
- package/dist/src/tools/jury-tool.js +7 -15
- package/dist/src/tools/openai-tools.js +29 -11
- package/dist/src/tools/openrouter-tools.js +76 -67
- package/dist/src/tools/provider-catalog.js +2 -2
- package/dist/src/tools/registry.js +6 -4
- package/dist/src/tools/unified-ai-provider.js +2 -1
- package/dist/src/tools/workflow-validator-tool.js +13 -19
- package/dist/src/utils/ansi-styles.js +8 -0
- package/dist/src/utils/fallback-policy.js +47 -0
- package/dist/src/utils/file-reader.js +19 -8
- package/dist/src/utils/judge-runner.js +12 -5
- package/dist/src/utils/provider-failure.js +6 -1
- package/dist/src/validators/output-usage-validator.js +9 -1
- package/dist/src/workflows/engine/WorkflowExecutionEngine.js +7 -4
- package/dist/src/workflows/engine/WorkflowHelpers.js +83 -10
- package/dist/src/workflows/engine/handlers/StepExecutionHandler.js +2 -9
- package/dist/src/workflows/step-guard.js +103 -0
- package/dist/src/workflows/tool-mapper.js +127 -4
- package/docs/TOOLS_REFERENCE.md +37 -29
- package/docs/TOOL_PARAMETERS.md +6 -6
- package/docs/TOOL_PROFILES.md +13 -13
- package/docs/superpowers/plans/2026-09-29-model-watch-and-config.md +723 -0
- package/package.json +1 -1
- package/profiles/balanced.json +2 -2
- package/profiles/code_focus.json +3 -3
- package/profiles/full.json +2 -2
- package/profiles/heavy_coding.json +3 -3
- package/profiles/minimal.json +2 -2
- package/profiles/research_power.json +3 -3
- package/skills/council/SKILL.md +96 -27
- package/skills/prompt/SKILL.md +11 -0
- package/skills/review/SKILL.md +17 -2
- package/skills/write/SKILL.md +27 -5
- package/tools.config.json +2 -5
- package/workflows/accessibility-code-audit.yaml +1 -1
- package/workflows/jev-gated-answer.yaml +59 -0
package/dist/src/orchestrators/collaborative/services/tool-execution/ToolExecutionService.js
CHANGED
|
@@ -130,8 +130,11 @@ export class ToolExecutionService {
|
|
|
130
130
|
}
|
|
131
131
|
// OpenAI smart routing
|
|
132
132
|
if (modelLower === "openai" || modelLower === "gpt") {
|
|
133
|
-
//
|
|
134
|
-
|
|
133
|
+
// Explicit code-review intent only. A bare ``` is NOT intent: nextThought prompts carry
|
|
134
|
+
// prior thoughts' output, which often contains code fences, so every OpenAI step after
|
|
135
|
+
// one fenced answer was misrouted to code review (and, with no executor case, returned
|
|
136
|
+
// "[Tool openai_code_review not available …]" without calling any model).
|
|
137
|
+
if (/\b(review (this |the )?code|code review|debug|refactor)\b/i.test(prompt)) {
|
|
135
138
|
return "openai_code_review";
|
|
136
139
|
}
|
|
137
140
|
// Reasoning keywords
|
|
@@ -267,6 +270,10 @@ export class ToolExecutionService {
|
|
|
267
270
|
query: prompt,
|
|
268
271
|
mode: "analytical"
|
|
269
272
|
};
|
|
273
|
+
case "openai_code_review":
|
|
274
|
+
return {
|
|
275
|
+
code: prompt
|
|
276
|
+
};
|
|
270
277
|
default:
|
|
271
278
|
return { prompt: prompt };
|
|
272
279
|
}
|
|
@@ -477,6 +484,15 @@ Step-by-step reasoning:
|
|
|
477
484
|
}
|
|
478
485
|
});
|
|
479
486
|
return typeof openaiBrainstormResult === 'string' ? openaiBrainstormResult : JSON.stringify(openaiBrainstormResult);
|
|
487
|
+
case "openai_code_review":
|
|
488
|
+
const { openaiCodeReviewTool } = await import("../../../../tools/openai-tools.js");
|
|
489
|
+
const openaiCodeReviewResult = await openaiCodeReviewTool.execute(params, {
|
|
490
|
+
log: {
|
|
491
|
+
info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
|
|
492
|
+
error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
return typeof openaiCodeReviewResult === 'string' ? openaiCodeReviewResult : JSON.stringify(openaiCodeReviewResult);
|
|
480
496
|
case "gemini_brainstorm":
|
|
481
497
|
const { geminiBrainstormTool } = await import("../../../../tools/gemini-tools.js");
|
|
482
498
|
const geminiBrainstormResult = await geminiBrainstormTool.execute(params, {
|
|
@@ -46,7 +46,6 @@ export const balancedProfile = {
|
|
|
46
46
|
deepseek_algo: true,
|
|
47
47
|
glm_reason: true,
|
|
48
48
|
stepfun_reason: true,
|
|
49
|
-
ernie_reason: true,
|
|
50
49
|
local_query: true,
|
|
51
50
|
workflow: true,
|
|
52
51
|
list_workflows: true,
|
|
@@ -74,5 +73,7 @@ export const balancedProfile = {
|
|
|
74
73
|
diff_review: true,
|
|
75
74
|
// Adversarial plan red-team
|
|
76
75
|
plan_critique: true,
|
|
76
|
+
// Typed decisions
|
|
77
|
+
jev_decide: true,
|
|
77
78
|
}
|
|
78
79
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const codeFocusProfile = {
|
|
2
|
-
description: "Code-heavy work with debugging and analysis (
|
|
2
|
+
description: "Code-heavy work with debugging and analysis (44 tools)",
|
|
3
3
|
tools: {
|
|
4
4
|
think: true,
|
|
5
5
|
focus: true,
|
|
@@ -46,7 +46,6 @@ export const codeFocusProfile = {
|
|
|
46
46
|
deepseek_algo: true, // Algorithmic review - top AIME/CodeElo
|
|
47
47
|
glm_reason: true, // Agentic SWE reasoning
|
|
48
48
|
stepfun_reason: true, // Efficient reasoning for code logic
|
|
49
|
-
ernie_reason: false, // Broad-knowledge model not needed for code focus
|
|
50
49
|
local_query: true,
|
|
51
50
|
workflow: true,
|
|
52
51
|
list_workflows: true,
|
|
@@ -74,5 +73,7 @@ export const codeFocusProfile = {
|
|
|
74
73
|
diff_review: true,
|
|
75
74
|
// Adversarial plan red-team
|
|
76
75
|
plan_critique: true,
|
|
76
|
+
// Typed decisions
|
|
77
|
+
jev_decide: true,
|
|
77
78
|
}
|
|
78
79
|
};
|
|
@@ -46,7 +46,6 @@ export const fullProfile = {
|
|
|
46
46
|
deepseek_algo: true,
|
|
47
47
|
glm_reason: true,
|
|
48
48
|
stepfun_reason: true,
|
|
49
|
-
ernie_reason: true,
|
|
50
49
|
local_query: true,
|
|
51
50
|
workflow: true,
|
|
52
51
|
list_workflows: true,
|
|
@@ -74,5 +73,7 @@ export const fullProfile = {
|
|
|
74
73
|
diff_review: true,
|
|
75
74
|
// Adversarial plan red-team
|
|
76
75
|
plan_critique: true,
|
|
76
|
+
// Typed decisions
|
|
77
|
+
jev_decide: true,
|
|
77
78
|
}
|
|
78
79
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const heavyCodingProfile = {
|
|
2
|
-
description: "Heavy coding with all reasoning & code tools (
|
|
2
|
+
description: "Heavy coding with all reasoning & code tools (60 tools)",
|
|
3
3
|
tools: {
|
|
4
4
|
// Core reasoning - all enabled
|
|
5
5
|
think: true,
|
|
@@ -52,7 +52,6 @@ export const heavyCodingProfile = {
|
|
|
52
52
|
deepseek_algo: true, // Algorithmic review - top AIME/CodeElo
|
|
53
53
|
glm_reason: true, // Agentic SWE reasoning (SWE-Bench Pro leader)
|
|
54
54
|
stepfun_reason: true, // Efficient reasoning
|
|
55
|
-
ernie_reason: false, // Not needed for heavy coding
|
|
56
55
|
local_query: true, // Local open-weight coding model (zero-cost/offline)
|
|
57
56
|
// Workflow - minimal set for execution
|
|
58
57
|
workflow: true,
|
|
@@ -81,5 +80,7 @@ export const heavyCodingProfile = {
|
|
|
81
80
|
diff_review: true,
|
|
82
81
|
// Adversarial plan red-team
|
|
83
82
|
plan_critique: true,
|
|
83
|
+
// Typed decisions
|
|
84
|
+
jev_decide: true,
|
|
84
85
|
}
|
|
85
86
|
};
|
|
@@ -46,7 +46,6 @@ export const minimalProfile = {
|
|
|
46
46
|
deepseek_algo: false,
|
|
47
47
|
glm_reason: false,
|
|
48
48
|
stepfun_reason: false,
|
|
49
|
-
ernie_reason: false,
|
|
50
49
|
local_query: false,
|
|
51
50
|
workflow: true,
|
|
52
51
|
list_workflows: false,
|
|
@@ -74,5 +73,7 @@ export const minimalProfile = {
|
|
|
74
73
|
diff_review: false,
|
|
75
74
|
// Adversarial plan red-team
|
|
76
75
|
plan_critique: false,
|
|
76
|
+
// Typed decisions
|
|
77
|
+
jev_decide: false,
|
|
77
78
|
}
|
|
78
79
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const researchPowerProfile = {
|
|
2
|
-
description: "Research-focused with Grok search + all Perplexity + brainstorming (
|
|
2
|
+
description: "Research-focused with Grok search + all Perplexity + brainstorming (37 tools)",
|
|
3
3
|
tools: {
|
|
4
4
|
think: true,
|
|
5
5
|
focus: true,
|
|
@@ -46,7 +46,6 @@ export const researchPowerProfile = {
|
|
|
46
46
|
deepseek_algo: false, // Algo review not needed for research
|
|
47
47
|
glm_reason: true, // Agentic reasoning for research workflows
|
|
48
48
|
stepfun_reason: true, // Efficient reasoning for research
|
|
49
|
-
ernie_reason: true, // Broad-knowledge / arena strength for research
|
|
50
49
|
local_query: false, // Research leans on cloud/search, not local
|
|
51
50
|
workflow: true,
|
|
52
51
|
list_workflows: false,
|
|
@@ -74,5 +73,7 @@ export const researchPowerProfile = {
|
|
|
74
73
|
diff_review: false,
|
|
75
74
|
// Adversarial plan red-team
|
|
76
75
|
plan_critique: false,
|
|
76
|
+
// Typed decisions
|
|
77
|
+
jev_decide: false,
|
|
77
78
|
}
|
|
78
79
|
};
|
|
@@ -9,6 +9,7 @@ import * as path from "path";
|
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
10
|
import { validateToolInput } from "../utils/input-validator.js";
|
|
11
11
|
import { isProviderFailure } from "../utils/provider-failure.js";
|
|
12
|
+
import { modelFallbackEnabled, isBillingFailure, describeFailure, degradedBanner } from "../utils/fallback-policy.js";
|
|
12
13
|
import { GEMINI_MODELS } from "../config/model-constants.js";
|
|
13
14
|
import { tryOpenRouterGateway, isGatewayEnabled } from "../utils/openrouter-gateway.js";
|
|
14
15
|
import { stripFormatting } from "../utils/format-stripper.js";
|
|
@@ -92,17 +93,43 @@ export async function callGemini(prompt, model = GEMINI_MODELS.GEMINI_3_PRO, sys
|
|
|
92
93
|
console.error(`⏳ [Gemini] ${model} transient failure (attempt ${attempt}/${GEMINI_MAX_ATTEMPTS}), retrying in ${delay}ms`);
|
|
93
94
|
await sleep(delay);
|
|
94
95
|
}
|
|
96
|
+
// Gemini 4 Argon (Oct 13, 2026 GA) -> the previous Pro default, on ANY failure: a key/region
|
|
97
|
+
// without Argon access gets a non-retryable 403/404 that the Flash stage below would skip.
|
|
98
|
+
// The result carries a [degraded: …] banner naming the model that ACTUALLY answered and
|
|
99
|
+
// why (judge-runner reports it), and a double failure keeps BOTH errors. Skipped when
|
|
100
|
+
// TACHI_MODEL_FALLBACK=off or the failure is billing (another model bills the same key).
|
|
101
|
+
const mayFallBack = isProviderFailure(last) && modelFallbackEnabled() && !isBillingFailure(last);
|
|
102
|
+
if (mayFallBack && model === GEMINI_MODELS.GEMINI_4_ARGON) {
|
|
103
|
+
console.error(`🔻 [Gemini] ${model} failed, falling back to ${GEMINI_MODELS.GEMINI_3_1_PRO}`);
|
|
104
|
+
const fb = await callGemini(prompt, GEMINI_MODELS.GEMINI_3_1_PRO, systemPrompt, temperature, validationContext, maxTokens);
|
|
105
|
+
if (isProviderFailure(fb)) {
|
|
106
|
+
return `[Gemini error: ${model} failed (${firstLine(last)}); fallback ${GEMINI_MODELS.GEMINI_3_1_PRO} failed too (${firstLine(fb)})]`;
|
|
107
|
+
}
|
|
108
|
+
// 3.1 Pro may itself have degraded to Flash — keep the innermost answering model
|
|
109
|
+
const inner = parseDegradedBanner(fb);
|
|
110
|
+
const reason = describeFailure(last) + (inner ? `; ${GEMINI_MODELS.GEMINI_3_1_PRO} also degraded` : "");
|
|
111
|
+
return degradedBanner(model, inner?.answeredBy ?? GEMINI_MODELS.GEMINI_3_1_PRO, reason) + (inner ? inner.body : fb);
|
|
112
|
+
}
|
|
95
113
|
// Same-provider degrade: Pro -> Flash. Skipped when Flash was already the request.
|
|
96
|
-
if (
|
|
114
|
+
if (mayFallBack && GEMINI_RETRYABLE.test(last) && model !== GEMINI_MODELS.FLASH) {
|
|
97
115
|
console.error(`🔻 [Gemini] ${model} exhausted, degrading to ${GEMINI_MODELS.FLASH}`);
|
|
98
116
|
const flash = await callGeminiAttempt(prompt, GEMINI_MODELS.FLASH, systemPrompt, temperature, validationContext, maxTokens);
|
|
99
117
|
if (!isProviderFailure(flash)) {
|
|
100
|
-
return
|
|
118
|
+
return degradedBanner(model, GEMINI_MODELS.FLASH, describeFailure(last)) + flash;
|
|
101
119
|
}
|
|
102
120
|
}
|
|
103
121
|
return last;
|
|
104
122
|
}
|
|
123
|
+
const firstLine = (s) => s.trim().split("\n")[0].slice(0, 300);
|
|
124
|
+
/** Parse callGemini's leading "[degraded: X unavailable, answered by Y]" banner. */
|
|
125
|
+
export function parseDegradedBanner(text) {
|
|
126
|
+
const m = /^\[degraded: [^\]]*answered by ([^\]\s]+)\]\n\n/.exec(text);
|
|
127
|
+
return m ? { answeredBy: m[1], body: text.slice(m[0].length) } : null;
|
|
128
|
+
}
|
|
105
129
|
async function callGeminiAttempt(prompt, model = GEMINI_MODELS.GEMINI_3_PRO, systemPrompt, temperature = 0.7, validationContext = 'llm-orchestration', maxTokens = 18000) {
|
|
130
|
+
// Argon caps output at 32K (3.x Pro/Flash: 65K) — clamp rather than 400
|
|
131
|
+
if (model === GEMINI_MODELS.GEMINI_4_ARGON)
|
|
132
|
+
maxTokens = Math.min(maxTokens, 32768);
|
|
106
133
|
// Try OpenRouter gateway first if enabled
|
|
107
134
|
if (isGatewayEnabled()) {
|
|
108
135
|
const messages = [
|
|
@@ -11,6 +11,8 @@ import { readFilesIntoContext } from "../utils/file-reader.js";
|
|
|
11
11
|
import { link } from "../utils/ansi-renderer.js";
|
|
12
12
|
import { stripFormatting } from "../utils/format-stripper.js";
|
|
13
13
|
import { FORMAT_INSTRUCTION } from "../utils/format-constants.js";
|
|
14
|
+
import { getTimeoutConfig, formatTimeout } from "../config/timeout-config.js";
|
|
15
|
+
import { withHeartbeat } from "../utils/streaming-helper.js";
|
|
14
16
|
// Note: renderOutput is applied centrally in server.ts safeAddTool() - no need to call it here
|
|
15
17
|
const __filename = fileURLToPath(import.meta.url);
|
|
16
18
|
const __dirname = path.dirname(__filename);
|
|
@@ -21,6 +23,7 @@ const GROK_API_URL = "https://api.x.ai/v1/chat/completions";
|
|
|
21
23
|
const GROK_RESPONSES_URL = "https://api.x.ai/v1/responses"; // New Agent Tools API endpoint (Jan 2025)
|
|
22
24
|
// Unified GrokModel enum - single source of truth in grok-tools.ts
|
|
23
25
|
import { GrokModel } from './grok-tools.js';
|
|
26
|
+
import { modelFallbackEnabled, degradedBanner } from "../utils/fallback-policy.js";
|
|
24
27
|
export { GrokModel };
|
|
25
28
|
/**
|
|
26
29
|
* Enhanced Grok API call with live search support
|
|
@@ -53,19 +56,38 @@ export async function callGrokEnhanced(messages, options = {}) {
|
|
|
53
56
|
};
|
|
54
57
|
console.error('[Grok Search Debug] Using Responses API:', GROK_RESPONSES_URL);
|
|
55
58
|
console.error('[Grok Search Debug] Request:', JSON.stringify(searchRequestBody, null, 2));
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
const searchTimeoutMs = getTimeoutConfig().search;
|
|
60
|
+
const controller = new AbortController();
|
|
61
|
+
const timeoutId = setTimeout(() => controller.abort(), searchTimeoutMs);
|
|
62
|
+
// The timer must cover the BODY too: headers can arrive while the agentic search
|
|
63
|
+
// is still streaming, so clearing it right after fetch() resolved left a stalled
|
|
64
|
+
// body read unbounded (with heartbeats hiding the hang from the MCP client).
|
|
65
|
+
let data;
|
|
66
|
+
try {
|
|
67
|
+
const response = await fetch(GROK_RESPONSES_URL, {
|
|
68
|
+
method: "POST",
|
|
69
|
+
headers: {
|
|
70
|
+
"Authorization": `Bearer ${GROK_API_KEY}`,
|
|
71
|
+
"Content-Type": "application/json"
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify(searchRequestBody),
|
|
74
|
+
signal: controller.signal
|
|
75
|
+
});
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
const error = await response.text();
|
|
78
|
+
throw new Error(`Grok API error: ${response.statusText} - ${error}`);
|
|
79
|
+
}
|
|
80
|
+
data = await response.json();
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
84
|
+
throw new Error(`${model} live search exceeded ${formatTimeout(searchTimeoutMs)} (raise TACHI_SEARCH_TIMEOUT)`);
|
|
85
|
+
}
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
clearTimeout(timeoutId);
|
|
67
90
|
}
|
|
68
|
-
const data = await response.json();
|
|
69
91
|
// Responses API format: output[] interleaves reasoning, web_search_call and
|
|
70
92
|
// MULTIPLE "message" entries — agentic runs emit a preamble message ("I'll
|
|
71
93
|
// search…"), run the searches, then emit the ANSWER as a later message.
|
|
@@ -145,10 +167,13 @@ export async function callGrokEnhanced(messages, options = {}) {
|
|
|
145
167
|
}
|
|
146
168
|
catch (error) {
|
|
147
169
|
const errMsg = error instanceof Error ? error.message : String(error);
|
|
148
|
-
//
|
|
149
|
-
if (
|
|
150
|
-
console.error(`[Grok]
|
|
151
|
-
|
|
170
|
+
// 4.5+ flagship rollouts are region-staged — fall back to grok-4.3
|
|
171
|
+
if (/^grok-4\.[5-9]/.test(model) && errMsg.includes('not available in your region') && modelFallbackEnabled()) {
|
|
172
|
+
console.error(`[Grok] ${model} region-blocked, falling back to grok-4.3`);
|
|
173
|
+
const fb = await callGrokEnhanced(messages, { ...options, model: GrokModel.GROK_4_3 });
|
|
174
|
+
return fb.content.startsWith('[Grok')
|
|
175
|
+
? fb
|
|
176
|
+
: { ...fb, content: degradedBanner(model, GrokModel.GROK_4_3, 'not available in your region') + fb.content };
|
|
152
177
|
}
|
|
153
178
|
return {
|
|
154
179
|
content: `[Grok error: ${errMsg}]`
|
|
@@ -358,7 +383,7 @@ export const grokSearchTool = {
|
|
|
358
383
|
max_search_results: z.number().optional(),
|
|
359
384
|
recency: z.enum(["all", "day", "week", "month", "year"]).optional()
|
|
360
385
|
}),
|
|
361
|
-
execute: async (args, { log }) => {
|
|
386
|
+
execute: async (args, { log, reportProgress }) => {
|
|
362
387
|
const { query, sources = [{ type: "web" }], max_search_results = 20, recency = "all" } = args;
|
|
363
388
|
const recencyPrompt = recency !== "all"
|
|
364
389
|
? `Focus on information from the last ${recency}.`
|
|
@@ -366,7 +391,7 @@ export const grokSearchTool = {
|
|
|
366
391
|
const messages = [
|
|
367
392
|
{
|
|
368
393
|
role: "system",
|
|
369
|
-
content: `You are Grok 4.
|
|
394
|
+
content: `You are Grok 4.7 with live search. Search for: "${query}".
|
|
370
395
|
${recencyPrompt}
|
|
371
396
|
Provide concise, factual results with sources.
|
|
372
397
|
Limit search to ${max_search_results} sources for cost control.
|
|
@@ -377,21 +402,21 @@ ${FORMAT_INSTRUCTION}`
|
|
|
377
402
|
content: `Search for: ${query}`
|
|
378
403
|
}
|
|
379
404
|
];
|
|
380
|
-
log?.info(`Grok Search: ${max_search_results} sources, recency: ${recency} (using grok-4.
|
|
405
|
+
log?.info(`Grok Search: ${max_search_results} sources, recency: ${recency} (using grok-4.7, verified grounded)`);
|
|
381
406
|
// Extract domains from sources if specified
|
|
382
407
|
const domains = sources
|
|
383
408
|
?.filter((s) => s.allowed_websites)
|
|
384
409
|
?.flatMap((s) => s.allowed_websites) || [];
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
//
|
|
388
|
-
// (grok_search_lite is the cheap tier)
|
|
410
|
+
// Heartbeat keeps the MCP client's 60s request timeout from killing long searches
|
|
411
|
+
const result = await withHeartbeat(() => callGrokEnhanced(messages, {
|
|
412
|
+
model: GrokModel.GROK_4_7, // best-cited grounded search as of 2026-10-14 (see GrokModel notes);
|
|
413
|
+
// grok-4.5 never grounds on /v1/responses (grok_search_lite is the cheap tier)
|
|
389
414
|
enableLiveSearch: true,
|
|
390
415
|
searchSources: max_search_results,
|
|
391
416
|
searchDomains: domains,
|
|
392
417
|
temperature: 0.3, // Low temperature for factual search
|
|
393
418
|
maxTokens: 3000
|
|
394
|
-
});
|
|
419
|
+
}), reportProgress ?? (async () => { }));
|
|
395
420
|
// Format sources with ANSI links
|
|
396
421
|
let output = result.content;
|
|
397
422
|
if (result.sources && result.sources.length > 0) {
|
|
@@ -423,9 +448,11 @@ export function isGrokAvailable() {
|
|
|
423
448
|
export function getGrokStatus() {
|
|
424
449
|
return {
|
|
425
450
|
available: isGrokAvailable(),
|
|
426
|
-
model: "grok-4.
|
|
451
|
+
model: "grok-4.7",
|
|
427
452
|
features: [
|
|
428
|
-
'Grok 4.
|
|
453
|
+
'Grok 4.7 (grok-4.7): Flagship (Sep 21, 2026), 500K context, configurable reasoning effort ($2/$6, doubled above 200K prompt)',
|
|
454
|
+
'Grok 4.7 also powers live search (grok_search) — best-cited grounded answers',
|
|
455
|
+
'Grok 4.6 (grok-4.6): Previous flagship/search model, kept for explicit picks ($2/$6)',
|
|
429
456
|
'Grok 4.3 (grok-4.3): Previous flagship, kept as fallback — 1M context, lowest verified hallucination ($1.25/$2.50)',
|
|
430
457
|
'Grok Build (grok-build-0.1): Fast agentic coding specialist, 256k context',
|
|
431
458
|
'Live web search with citations',
|
|
@@ -26,6 +26,7 @@ import { defineModelTool } from "./factory/define-model-tool.js";
|
|
|
26
26
|
import { link } from "../utils/ansi-renderer.js";
|
|
27
27
|
import { stripFormatting } from "../utils/format-stripper.js";
|
|
28
28
|
import { FORMAT_INSTRUCTION } from "../utils/format-constants.js";
|
|
29
|
+
import { withHeartbeat } from "../utils/streaming-helper.js";
|
|
29
30
|
/** Pure prompt builder — exported for tests. */
|
|
30
31
|
export function buildGrokSearchLitePrompt(query, maxSearchResults, recency) {
|
|
31
32
|
const recencyPrompt = recency !== "all" ? `Focus on information from the last ${recency}.` : "";
|
|
@@ -50,7 +51,7 @@ export const grokSearchLiteTool = defineModelTool({
|
|
|
50
51
|
max_search_results: z.number().optional(),
|
|
51
52
|
recency: z.enum(["all", "day", "week", "month", "year"]).optional(),
|
|
52
53
|
}),
|
|
53
|
-
execute: async (args, { log }) => {
|
|
54
|
+
execute: async (args, { log, reportProgress }) => {
|
|
54
55
|
const { query, sources = [{ type: "web" }], max_search_results = 20, recency = "all", } = args;
|
|
55
56
|
const messages = [
|
|
56
57
|
{
|
|
@@ -67,14 +68,15 @@ export const grokSearchLiteTool = defineModelTool({
|
|
|
67
68
|
const domains = sources
|
|
68
69
|
?.filter((s) => s.allowed_websites)
|
|
69
70
|
?.flatMap((s) => s.allowed_websites) || [];
|
|
70
|
-
|
|
71
|
+
// Heartbeat keeps the MCP client's 60s request timeout from killing long searches
|
|
72
|
+
const result = await withHeartbeat(() => callGrokEnhanced(messages, {
|
|
71
73
|
model: GrokModel.GROK_4_3, // Cheapest surviving general tier (see header note on the retired 4-1-fast id)
|
|
72
74
|
enableLiveSearch: true,
|
|
73
75
|
searchSources: max_search_results,
|
|
74
76
|
searchDomains: domains,
|
|
75
77
|
temperature: 0.3, // Low temperature for factual search
|
|
76
78
|
maxTokens: 3000,
|
|
77
|
-
});
|
|
79
|
+
}), reportProgress ?? (async () => { }));
|
|
78
80
|
// Format sources with ANSI links (same shape as grok_search output)
|
|
79
81
|
let output = result.content;
|
|
80
82
|
if (result.sources && result.sources.length > 0) {
|
|
@@ -16,6 +16,7 @@ import { FORMAT_INSTRUCTION } from "../utils/format-constants.js";
|
|
|
16
16
|
import { tryOpenRouterGateway, isGatewayEnabled } from "../utils/openrouter-gateway.js";
|
|
17
17
|
import { withHeartbeat } from "../utils/streaming-helper.js";
|
|
18
18
|
import { readFilesIntoContext } from "../utils/file-reader.js";
|
|
19
|
+
import { modelFallbackEnabled, degradedBanner } from "../utils/fallback-policy.js";
|
|
19
20
|
// Note: renderOutput is applied centrally in server.ts safeAddTool() - no need to import here
|
|
20
21
|
const __filename = fileURLToPath(import.meta.url);
|
|
21
22
|
const __dirname = path.dirname(__filename);
|
|
@@ -33,6 +34,11 @@ export var GrokModel;
|
|
|
33
34
|
// 2026-08-15 with tools:[web_search,x_search] asking today's date: grok-4.3
|
|
34
35
|
// returned 2 web_search_call entries + 1 citation in 10.4s; grok-4.6 returned 2
|
|
35
36
|
// calls + 2 citations in 36.4s. grok-4.5 remains the one that does NOT ground.
|
|
37
|
+
// Grok 4.7 (Sep 21, 2026) - CURRENT FLAGSHIP. 500K ctx, $2/$6 (rates double above 200K prompt tokens), reasoning_effort. Verified 2026-09-29:
|
|
38
|
+
// chat 200 served "grok-4.7"; on /v1/responses search it ran 5 search calls but returned 1 citation
|
|
39
|
+
// vs 4.6's 18 for the same query. Re-verified 2026-10-14 over 3 queries: 4.7 now returns 19/79/2
|
|
40
|
+
// unique citations vs 4.6's 2/4/2 and found newer facts — so grok_search moved to 4.7.
|
|
41
|
+
GrokModel["GROK_4_7"] = "grok-4.7";
|
|
36
42
|
GrokModel["GROK_4_6"] = "grok-4.6";
|
|
37
43
|
// Grok 4.5 (Jul 8, 2026) - previous flagship ("Opus-class")
|
|
38
44
|
// 500K ctx (smaller than 4.3's 1M), $2/$6, configurable reasoning effort.
|
|
@@ -43,9 +49,9 @@ export var GrokModel;
|
|
|
43
49
|
GrokModel["GROK_4_3_LATEST"] = "grok-4.3-latest";
|
|
44
50
|
GrokModel["GROK_BUILD"] = "grok-build-0.1";
|
|
45
51
|
// Grok 4.20 keys (Mar 2026) - DEPRECATED, retained for back-compat → now resolve to the current flagship
|
|
46
|
-
GrokModel["GROK_4_20_REASONING"] = "grok-4.
|
|
47
|
-
GrokModel["GROK_4_20_NON_REASONING"] = "grok-4.
|
|
48
|
-
GrokModel["GROK_4_20_MULTI_AGENT"] = "grok-4.
|
|
52
|
+
GrokModel["GROK_4_20_REASONING"] = "grok-4.7";
|
|
53
|
+
GrokModel["GROK_4_20_NON_REASONING"] = "grok-4.7";
|
|
54
|
+
GrokModel["GROK_4_20_MULTI_AGENT"] = "grok-4.7";
|
|
49
55
|
// Grok 4.1 fast models (Nov 2025) - BEST VALUE (10x cheaper)
|
|
50
56
|
GrokModel["GROK_4_1_FAST_REASONING"] = "grok-4-1-fast-reasoning";
|
|
51
57
|
GrokModel["GROK_4_1_FAST"] = "grok-4-1-fast-non-reasoning";
|
|
@@ -64,7 +70,7 @@ export var GrokModel;
|
|
|
64
70
|
* - 'code-analysis': Relaxed for code analysis tools
|
|
65
71
|
* - 'llm-orchestration': Medium for LLM-to-LLM calls
|
|
66
72
|
*/
|
|
67
|
-
export async function callGrok(messages, model = GrokModel.
|
|
73
|
+
export async function callGrok(messages, model = GrokModel.GROK_4_7, temperature = 0.7, maxTokens = 16384, // Increased default for comprehensive responses
|
|
68
74
|
forceVisibleOutput = true, validationContext = 'llm-orchestration', reasoningEffort) {
|
|
69
75
|
// Try OpenRouter gateway first if enabled
|
|
70
76
|
if (isGatewayEnabled()) {
|
|
@@ -91,7 +97,7 @@ forceVisibleOutput = true, validationContext = 'llm-orchestration', reasoningEff
|
|
|
91
97
|
});
|
|
92
98
|
// Grok 4.x reasoning can take 60-90s; 4.3/4.5 flagship and multi-agent can take longer
|
|
93
99
|
const isReasoning = model.includes('reasoning') || model.includes('multi-agent');
|
|
94
|
-
const isFlagship = model.includes('4.20') ||
|
|
100
|
+
const isFlagship = model.includes('4.20') || /^grok-4\.\d/.test(model); // 4.3/4.5/4.6/4.7…
|
|
95
101
|
const timeoutMs = isFlagship ? 180000 : (isReasoning ? 120000 : 60000);
|
|
96
102
|
try {
|
|
97
103
|
// For Grok 4+ models, we need to handle reasoning tokens specially
|
|
@@ -106,7 +112,7 @@ forceVisibleOutput = true, validationContext = 'llm-orchestration', reasoningEff
|
|
|
106
112
|
const controller = new AbortController();
|
|
107
113
|
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
108
114
|
// grok-4.3/4.5 flagships and 4.20 multi-agent all accept reasoning.effort
|
|
109
|
-
const supportsReasoningEffort = model.includes('multi-agent') ||
|
|
115
|
+
const supportsReasoningEffort = model.includes('multi-agent') || /^grok-4\.\d/.test(model); // 4.3+ all accept it
|
|
110
116
|
const requestBody = {
|
|
111
117
|
model,
|
|
112
118
|
messages: validatedMessages,
|
|
@@ -154,13 +160,14 @@ forceVisibleOutput = true, validationContext = 'llm-orchestration', reasoningEff
|
|
|
154
160
|
}
|
|
155
161
|
catch (error) {
|
|
156
162
|
if (error instanceof Error && error.name === 'AbortError') {
|
|
157
|
-
return `[Grok timeout: ${model} exceeded ${
|
|
163
|
+
return `[Grok timeout: ${model} exceeded ${timeoutMs / 1000}s limit]`;
|
|
158
164
|
}
|
|
159
165
|
const errMsg = error instanceof Error ? error.message : String(error);
|
|
160
|
-
//
|
|
161
|
-
if (
|
|
162
|
-
console.error(`[Grok]
|
|
163
|
-
|
|
166
|
+
// 4.5+ flagship rollouts are region-staged — fall back to grok-4.3
|
|
167
|
+
if (/^grok-4\.[5-9]/.test(model) && errMsg.includes('not available in your region') && modelFallbackEnabled()) {
|
|
168
|
+
console.error(`[Grok] ${model} region-blocked, falling back to grok-4.3`);
|
|
169
|
+
const fb = await callGrok(validatedMessages, GrokModel.GROK_4_3, temperature, maxTokens, forceVisibleOutput, validationContext, reasoningEffort);
|
|
170
|
+
return fb.startsWith('[Grok') ? fb : degradedBanner(model, GrokModel.GROK_4_3, 'not available in your region') + fb;
|
|
164
171
|
}
|
|
165
172
|
return `[Grok error: ${errMsg}]`;
|
|
166
173
|
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* jev_decide — typed decisions via TypeSafe's Jev (System One model) on OpenRouter.
|
|
3
|
+
* Jev does NOT generate text: it takes a `state` plus named typed questions and
|
|
4
|
+
* returns calibrated values — `noul` (yes/no probability), `choice` (option +
|
|
5
|
+
* per-option probabilities), `score` (value on an ordered scale + confidence).
|
|
6
|
+
* Chat-completions does not serve it; it lives on OpenRouter's System One
|
|
7
|
+
* endpoint. Cheap (~$0.04/M input, output free) and fast (~0.3s) — meant for
|
|
8
|
+
* bounded judgments: routing, groundedness/eval gates, risk scoring.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { defineModelTool } from "./factory/define-model-tool.js";
|
|
12
|
+
import { getOpenRouterApiKey } from "../utils/api-keys.js";
|
|
13
|
+
import { JEV_MODELS } from "../config/model-constants.js";
|
|
14
|
+
export const JEV_API_URL = "https://openrouter.ai/api/v1/systemone";
|
|
15
|
+
export const JEV_DEFAULT_MODEL = JEV_MODELS.JEV_1_13;
|
|
16
|
+
const JEV_TIMEOUT_MS = 30000;
|
|
17
|
+
const questionSchema = z.object({
|
|
18
|
+
type: z.enum(["noul", "choice", "score"]).describe("noul = yes/no probability; choice = pick one option; score = rate on an ordered scale"),
|
|
19
|
+
instructions: z.string().describe("The question Jev should answer about the state"),
|
|
20
|
+
criteria: z
|
|
21
|
+
.union([z.record(z.string(), z.string()), z.array(z.string())])
|
|
22
|
+
.optional()
|
|
23
|
+
.describe("choice: {option: description} map. score: ordered levels, lowest first (e.g. ['low','medium','high']). Omit for noul."),
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Pure request builder. Returns the System One body, or an error string when a
|
|
27
|
+
* question's criteria don't match its type (the API rejects these with an
|
|
28
|
+
* opaque zod dump, so fail early with a readable message instead).
|
|
29
|
+
*/
|
|
30
|
+
export function buildJevRequest(args) {
|
|
31
|
+
const names = Object.keys(args.questions || {});
|
|
32
|
+
if (names.length === 0)
|
|
33
|
+
return { error: "Error: provide at least one question in 'questions'." };
|
|
34
|
+
for (const name of names) {
|
|
35
|
+
const q = args.questions[name];
|
|
36
|
+
if (q.type === "choice" && (!q.criteria || Array.isArray(q.criteria) || Object.keys(q.criteria).length < 2)) {
|
|
37
|
+
return { error: `Error: question '${name}' is 'choice' — 'criteria' must be an {option: description} map with at least 2 options.` };
|
|
38
|
+
}
|
|
39
|
+
if (q.type === "score" && (!Array.isArray(q.criteria) || q.criteria.length < 2)) {
|
|
40
|
+
return { error: `Error: question '${name}' is 'score' — 'criteria' must be an array of at least 2 ordered levels.` };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const questions = {};
|
|
44
|
+
for (const name of names) {
|
|
45
|
+
const { type, instructions, criteria } = args.questions[name];
|
|
46
|
+
questions[name] = type === "noul" ? { type, instructions } : { type, instructions, criteria };
|
|
47
|
+
}
|
|
48
|
+
return { body: { model: args.model || JEV_DEFAULT_MODEL, state: args.state, questions } };
|
|
49
|
+
}
|
|
50
|
+
export const jevDecideTool = defineModelTool({
|
|
51
|
+
name: "jev_decide",
|
|
52
|
+
description: "Typed decisions from TypeSafe Jev via OpenRouter — no prose. Send a 'state' plus named questions (noul = yes/no probability, choice = pick an option, score = rate on a scale); get calibrated probabilities back as JSON. Fast and near-free: use for routing, eval/groundedness gates, and risk scoring, not for writing or open-ended reasoning.",
|
|
53
|
+
parameters: z.object({
|
|
54
|
+
state: z
|
|
55
|
+
.union([z.string(), z.record(z.string(), z.unknown())])
|
|
56
|
+
.describe("The context to judge — text or an object (e.g. {request, policy, trace, answer})"),
|
|
57
|
+
questions: z
|
|
58
|
+
.record(z.string(), questionSchema)
|
|
59
|
+
.describe("Named questions, e.g. {refund: {type:'noul', instructions:'Is a refund requested?'}}"),
|
|
60
|
+
model: z.string().optional().describe("OpenRouter model id (default: typesafe/jev-1.13)"),
|
|
61
|
+
}),
|
|
62
|
+
execute: async (args) => {
|
|
63
|
+
const built = buildJevRequest(args);
|
|
64
|
+
if ("error" in built)
|
|
65
|
+
return built.error;
|
|
66
|
+
const apiKey = getOpenRouterApiKey();
|
|
67
|
+
if (!apiKey)
|
|
68
|
+
return "[OpenRouter API key not configured. Add OPENROUTER_API_KEY to .env file]";
|
|
69
|
+
const controller = new AbortController();
|
|
70
|
+
const timeoutId = setTimeout(() => controller.abort(), JEV_TIMEOUT_MS);
|
|
71
|
+
try {
|
|
72
|
+
const response = await fetch(JEV_API_URL, {
|
|
73
|
+
method: "POST",
|
|
74
|
+
headers: {
|
|
75
|
+
Authorization: `Bearer ${apiKey}`,
|
|
76
|
+
"Content-Type": "application/json",
|
|
77
|
+
"HTTP-Referer": "https://tachibot-mcp.local",
|
|
78
|
+
"X-Title": "Tachibot MCP Server",
|
|
79
|
+
},
|
|
80
|
+
body: JSON.stringify(built.body),
|
|
81
|
+
signal: controller.signal,
|
|
82
|
+
});
|
|
83
|
+
if (!response.ok) {
|
|
84
|
+
const errorText = await response.text();
|
|
85
|
+
return `[Jev error: ${response.status} ${response.statusText} - ${errorText.slice(0, 1500)}]`;
|
|
86
|
+
}
|
|
87
|
+
const data = (await response.json());
|
|
88
|
+
if (!data?.answers)
|
|
89
|
+
return `[Jev error: response had no answers - ${JSON.stringify(data).slice(0, 500)}]`;
|
|
90
|
+
return JSON.stringify({ model: data.model, answers: data.answers, usage: data.usage }, null, 2);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
94
|
+
return `[Jev timeout: request exceeded ${JEV_TIMEOUT_MS / 1000}s]`;
|
|
95
|
+
}
|
|
96
|
+
return `[Jev error: ${error instanceof Error ? error.message : String(error)}]`;
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
clearTimeout(timeoutId);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
export function getAllJevTools() {
|
|
104
|
+
return [jevDecideTool];
|
|
105
|
+
}
|
|
@@ -98,28 +98,20 @@ export const JUROR_REGISTRY = {
|
|
|
98
98
|
], OpenRouterModel.DEEPSEEK_V4_PRO, 0.3, JUROR_MAX_TOKENS),
|
|
99
99
|
},
|
|
100
100
|
glm: {
|
|
101
|
-
label: "GLM-5.
|
|
101
|
+
label: "GLM-5.3 (Agentic)",
|
|
102
102
|
role: "Reason as an agent: plan, anticipate failure modes, decide. Strong on tool-use and SWE.",
|
|
103
103
|
call: async (q) => callOpenRouter([
|
|
104
|
-
{ role: "system", content: `You are Zhipu GLM-5.
|
|
104
|
+
{ role: "system", content: `You are Zhipu GLM-5.3, a frontier open-weights agentic model (1M ctx, top long-horizon coding). Plan, reason through tool-use/steps, then give a decisive verdict. ${FORMAT_INSTRUCTION}` },
|
|
105
105
|
{ role: "user", content: q }
|
|
106
|
-
], OpenRouterModel.
|
|
106
|
+
], OpenRouterModel.GLM_5_3, 0.3, JUROR_MAX_TOKENS),
|
|
107
107
|
},
|
|
108
108
|
stepfun: {
|
|
109
|
-
label: "StepFun
|
|
109
|
+
label: "StepFun 5 Preview (Efficient Reasoning)",
|
|
110
110
|
role: "Reason efficiently and tightly. Strong on math/AIME-style problems at low cost.",
|
|
111
111
|
call: async (q) => callOpenRouter([
|
|
112
|
-
{ role: "system", content: `You are StepFun Step
|
|
112
|
+
{ role: "system", content: `You are StepFun Step 5, an efficient frontier reasoning model. Reason tightly, then conclude. ${FORMAT_INSTRUCTION}` },
|
|
113
113
|
{ role: "user", content: q }
|
|
114
|
-
], OpenRouterModel.
|
|
115
|
-
},
|
|
116
|
-
ernie: {
|
|
117
|
-
label: "ERNIE 4.5 VL (Broad Knowledge)",
|
|
118
|
-
role: "Bring broad knowledge and human-preference judgment. Uncorrelated with US labs.",
|
|
119
|
-
call: async (q) => callOpenRouter([
|
|
120
|
-
{ role: "system", content: `You are Baidu ERNIE 4.5 VL, a broad-knowledge MoE with strong human-preference alignment. Give a well-rounded, decisive judgment. ${FORMAT_INSTRUCTION}` },
|
|
121
|
-
{ role: "user", content: q }
|
|
122
|
-
], OpenRouterModel.ERNIE_4_5_VL, 0.4, JUROR_MAX_TOKENS),
|
|
114
|
+
], OpenRouterModel.STEPFUN_5_PREVIEW, 0.3, JUROR_MAX_TOKENS),
|
|
123
115
|
},
|
|
124
116
|
// Local open-weights juror — free, offline, ZERO token cost. Its judgment is
|
|
125
117
|
// uncorrelated with the frontier vendors above, which is exactly what reduces
|
|
@@ -152,7 +144,7 @@ export const juryTool = defineModelTool({
|
|
|
152
144
|
parameters: z.object({
|
|
153
145
|
question: z.string().describe("The question or problem for the jury to evaluate (REQUIRED)"),
|
|
154
146
|
jurors: z.string().optional()
|
|
155
|
-
.describe("Comma-separated juror models (default: grok,deepseek,kimi,openai). Available: grok, openai, qwen, qwen_reason, kimi, perplexity, minimax, deepseek, glm, stepfun,
|
|
147
|
+
.describe("Comma-separated juror models (default: grok,deepseek,kimi,openai). Available: grok, openai, qwen, qwen_reason, kimi, perplexity, minimax, deepseek, glm, stepfun, local (free offline — uses LOCAL_LLM_MODEL via Ollama/LM Studio; 'hermes' accepted as legacy alias)"),
|
|
156
148
|
mode: z.enum(["synthesize", "evaluate", "rank", "resolve"])
|
|
157
149
|
.optional()
|
|
158
150
|
.default("synthesize")
|