tachibot-mcp 2.35.0 → 2.37.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 +50 -0
- package/README.md +31 -4
- package/dist/src/cli/trace.js +194 -0
- package/dist/src/config/model-constants.js +79 -39
- package/dist/src/config/model-defaults.js +3 -3
- package/dist/src/config/model-preferences.js +12 -11
- package/dist/src/config/timeout-config.js +22 -0
- package/dist/src/config.js +1 -1
- package/dist/src/modes/architect.js +1 -1
- package/dist/src/optimization/model-router.js +12 -6
- package/dist/src/sequential-thinking.js +3 -0
- package/dist/src/server-main.js +56 -6
- package/dist/src/server.js +10 -0
- package/dist/src/tools/gemini-tools.js +20 -6
- package/dist/src/tools/grok-enhanced.js +0 -1
- package/dist/src/tools/grok-tools.js +10 -2
- package/dist/src/tools/jury-tool.js +9 -1
- package/dist/src/tools/openai-tools.js +164 -74
- package/dist/src/tools/openrouter-tools.js +16 -9
- package/dist/src/tools/perplexity-tools.js +2 -2
- package/dist/src/tools/planner-tools.js +66 -28
- package/dist/src/tools/provider-catalog.js +1 -1
- package/dist/src/tools/registry.js +9 -4
- package/dist/src/utils/api-keys.js +72 -7
- package/dist/src/utils/client-render.js +35 -0
- package/dist/src/utils/format-constants.js +2 -1
- package/dist/src/utils/judge-runner.js +3 -1
- package/dist/src/utils/openai-transport.js +60 -0
- package/dist/src/utils/openrouter-gateway.js +3 -1
- package/dist/src/utils/provider-lock.js +105 -0
- package/dist/src/utils/trace-bus.js +150 -0
- package/dist/src/utils/trace-open.js +69 -0
- package/dist/src/utils/trace-page.js +157 -0
- package/dist/src/utils/trace-server.js +215 -0
- package/dist/src/workflows/tool-mapper.js +12 -8
- package/docs/API_KEYS.md +34 -0
- package/docs/CONFIGURATION.md +24 -0
- package/docs/TOOLS_REFERENCE.md +4 -3
- package/docs/plans/2026-11-13-azure-foundry-backend.md +182 -0
- package/package.json +1 -1
- package/workflows/jev-gated-answer.yaml +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Model Preferences Configuration
|
|
3
3
|
* Allows users to set their preferred models based on available API tokens
|
|
4
4
|
*/
|
|
5
|
-
import { hasGrokApiKey } from "../utils/api-keys.js";
|
|
5
|
+
import { hasGrokApiKey, hasOpenAIApiKey, hasGeminiApiKey, hasPerplexityApiKey, hasOpenRouterApiKey, hasDeepSeekApiKey } from "../utils/api-keys.js";
|
|
6
6
|
/**
|
|
7
7
|
* Default model configurations with user preferences
|
|
8
8
|
*/
|
|
@@ -49,7 +49,7 @@ export class ModelPreferencesManager {
|
|
|
49
49
|
*/
|
|
50
50
|
loadModelOverrides() {
|
|
51
51
|
// GPT-5 configuration (assumes OpenAI key)
|
|
52
|
-
if (
|
|
52
|
+
if (hasOpenAIApiKey()) {
|
|
53
53
|
this.preferences.modelOverrides["gpt5"] = {
|
|
54
54
|
enabled: process.env.DISABLE_GPT5 !== "true",
|
|
55
55
|
priority: parseInt(process.env.GPT5_PRIORITY || "0"),
|
|
@@ -79,7 +79,7 @@ export class ModelPreferencesManager {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
// GPT-5 reasoning configuration
|
|
82
|
-
if (
|
|
82
|
+
if (hasOpenAIApiKey()) {
|
|
83
83
|
this.preferences.modelOverrides["gpt5_reason"] = {
|
|
84
84
|
enabled: process.env.ENABLE_GPT5 === "true",
|
|
85
85
|
priority: parseInt(process.env.GPT5_REASON_PRIORITY || "1"),
|
|
@@ -94,7 +94,7 @@ export class ModelPreferencesManager {
|
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
// DeepSeek R1
|
|
97
|
-
if (
|
|
97
|
+
if (hasDeepSeekApiKey()) {
|
|
98
98
|
this.preferences.modelOverrides["deepseek_r1"] = {
|
|
99
99
|
enabled: process.env.ENABLE_DEEPSEEK_R1 === "true",
|
|
100
100
|
priority: parseInt(process.env.DEEPSEEK_R1_PRIORITY || "3"),
|
|
@@ -103,7 +103,7 @@ export class ModelPreferencesManager {
|
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
105
|
// Qwen models via OpenRouter
|
|
106
|
-
if (
|
|
106
|
+
if (hasOpenRouterApiKey()) {
|
|
107
107
|
this.preferences.modelOverrides["qwen_coder"] = {
|
|
108
108
|
enabled: true,
|
|
109
109
|
priority: parseInt(process.env.QWEN_CODER_PRIORITY || "4"),
|
|
@@ -124,11 +124,12 @@ export class ModelPreferencesManager {
|
|
|
124
124
|
initializeModels() {
|
|
125
125
|
// Check which APIs are available
|
|
126
126
|
const hasGrok = hasGrokApiKey();
|
|
127
|
-
const hasOpenAI =
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
const
|
|
127
|
+
const hasOpenAI = hasOpenAIApiKey();
|
|
128
|
+
// via api-keys.ts so the provider lock is honoured
|
|
129
|
+
const hasGemini = hasGeminiApiKey();
|
|
130
|
+
const hasPerplexity = hasPerplexityApiKey();
|
|
131
|
+
const hasOpenRouter = hasOpenRouterApiKey();
|
|
132
|
+
const hasDeepSeek = hasDeepSeekApiKey();
|
|
132
133
|
// Set up available models with default configs
|
|
133
134
|
if (hasGrok) {
|
|
134
135
|
this.availableModels.set("grok_reason", {
|
|
@@ -350,7 +351,7 @@ export class ModelPreferencesManager {
|
|
|
350
351
|
getRecommendations() {
|
|
351
352
|
const recommendations = [];
|
|
352
353
|
const hasGrok = hasGrokApiKey();
|
|
353
|
-
const hasOpenAI =
|
|
354
|
+
const hasOpenAI = hasOpenAIApiKey();
|
|
354
355
|
if (hasGrok && !this.preferences.enableExpensiveModels) {
|
|
355
356
|
recommendations.push("You have Grok API access. Enable ENABLE_EXPENSIVE_MODELS=true to use Grok Heavy (256k context).");
|
|
356
357
|
}
|
|
@@ -174,3 +174,25 @@ export function getSmartTimeout(provider, priority) {
|
|
|
174
174
|
export const timeouts = getTimeoutConfig();
|
|
175
175
|
// Re-export for convenience
|
|
176
176
|
export { getTimeoutConfig as default };
|
|
177
|
+
/**
|
|
178
|
+
* Hard request timeout for a reasoning model call. Provider docs (Oct 2026) give no
|
|
179
|
+
* fixed latency ceiling: OpenAI recommends budgeting ~10–15 min for xhigh (more for
|
|
180
|
+
* max), xAI up to 900s for Grok 4.7 at high/xhigh (we allow 600s). The old flat 180s cut real runs
|
|
181
|
+
* (gpt-6-astra xhigh on a council prompt fell back to gpt-6-sol). Progress heartbeats
|
|
182
|
+
* keep the MCP call alive meanwhile. TACHI_REASONING_TIMEOUT_MS overrides every tier.
|
|
183
|
+
*/
|
|
184
|
+
export function reasoningTimeoutMs(provider, effort) {
|
|
185
|
+
const override = Number(process.env.TACHI_REASONING_TIMEOUT_MS);
|
|
186
|
+
// Clamp: setTimeout silently turns any delay above 2^31-1 ms into 1 ms.
|
|
187
|
+
if (Number.isFinite(override) && override > 0)
|
|
188
|
+
return Math.min(override, 2147483647);
|
|
189
|
+
if (provider === 'grok')
|
|
190
|
+
return 600000;
|
|
191
|
+
if (effort === 'max')
|
|
192
|
+
return 900000;
|
|
193
|
+
if (effort === 'xhigh')
|
|
194
|
+
return 600000;
|
|
195
|
+
if (effort === 'high')
|
|
196
|
+
return 300000;
|
|
197
|
+
return 90000;
|
|
198
|
+
}
|
package/dist/src/config.js
CHANGED
|
@@ -128,7 +128,7 @@ export function getAvailableModels(config) {
|
|
|
128
128
|
models.push('sonar-pro', 'sonar-reasoning-pro', 'sonar-deep-research');
|
|
129
129
|
}
|
|
130
130
|
if (config.apiKeys.grok) {
|
|
131
|
-
models.push('grok-4.3', 'grok-4.3-latest'
|
|
131
|
+
models.push('grok-4.3', 'grok-4.3-latest');
|
|
132
132
|
}
|
|
133
133
|
if (config.apiKeys.openrouter) {
|
|
134
134
|
models.push('qwen3-coder', 'qwq-32b', 'qwen3-32b');
|
|
@@ -80,7 +80,7 @@ export class Architect {
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
selectGeminiModel(options) {
|
|
83
|
-
// Active Pro model (gemini-4-
|
|
83
|
+
// Active Pro model (gemini-4-carbon unless TACHI_GEMINI_PRO_MODEL overrides it)
|
|
84
84
|
return getGeminiProModel();
|
|
85
85
|
}
|
|
86
86
|
calculateGeminiTokens(options) {
|
|
@@ -13,19 +13,22 @@ export var ModelTier;
|
|
|
13
13
|
// Tier 1: Fast & Efficient
|
|
14
14
|
ModelTier["ULTRA_EFFICIENT"] = "gemini-3.8-flash";
|
|
15
15
|
ModelTier["EFFICIENT"] = "gpt-6-luna";
|
|
16
|
-
// Tier 2: Balanced — gpt-
|
|
17
|
-
ModelTier["STANDARD"] = "gpt-
|
|
16
|
+
// Tier 2: Balanced — gpt-6.1-terra at $1/$5 (Oct 26, 2026)
|
|
17
|
+
ModelTier["STANDARD"] = "gpt-6.1-terra";
|
|
18
18
|
ModelTier["GPT5_MINI"] = "gpt-6-luna";
|
|
19
19
|
// Tier 3: Advanced
|
|
20
20
|
ModelTier["WEB_SEARCH"] = "perplexity-sonar-pro";
|
|
21
21
|
// Tier 4: Premium (opt-in only)
|
|
22
|
-
ModelTier["GPT5_FULL"] = "gpt-6.
|
|
22
|
+
ModelTier["GPT5_FULL"] = "gpt-6.2-sol";
|
|
23
23
|
})(ModelTier || (ModelTier = {}));
|
|
24
24
|
// Prices are per 1K tokens (0.005 = $5.00 per 1M). Any model missing here silently
|
|
25
25
|
// falls through to estimateCost()'s flat $0.001 default, so every routable tier above
|
|
26
26
|
// MUST have an entry.
|
|
27
27
|
const MODEL_COSTS = {
|
|
28
|
-
// GPT-6 Astra (
|
|
28
|
+
// GPT-6.2 Astra (Nov 17, 2026) — current OpenAI default. Latencies are estimates, not measured.
|
|
29
|
+
"gpt-6.2-astra": { input: 0.008, output: 0.040, latency: 2400 },
|
|
30
|
+
"gpt-6.2-sol": { input: 0.002, output: 0.010, latency: 1500 },
|
|
31
|
+
"gpt-6.1-terra": { input: 0.001, output: 0.005, latency: 1300 },
|
|
29
32
|
"gpt-6-astra": { input: 0.010, output: 0.050, latency: 2400 },
|
|
30
33
|
"gpt-6.1-sol": { input: 0.002, output: 0.010, latency: 1500 },
|
|
31
34
|
"gpt-6-sol": { input: 0.002, output: 0.010, latency: 1500 },
|
|
@@ -46,8 +49,11 @@ const MODEL_COSTS = {
|
|
|
46
49
|
"gemini-3.6-flash": { input: 0.0015, output: 0.0075, latency: 600 }, // Jul 21, 2026
|
|
47
50
|
"gemini-3.5-flash-lite": { input: 0.0003, output: 0.0025, latency: 400 }, // Jul 21, 2026
|
|
48
51
|
"gemini-3.5-flash": { input: 0.0015, output: 0.009, latency: 600 }, // May 19, 2026
|
|
49
|
-
"gemini-4-
|
|
50
|
-
"gemini-
|
|
52
|
+
"gemini-4-carbon": { input: 0.004, output: 0.020, latency: 1400 }, // Judge/reasoning default (Nov 10, 2026)
|
|
53
|
+
"gemini-4-neon": { input: 0.003, output: 0.015, latency: 1200 }, // Faster co-flagship (Nov 18, 2026)
|
|
54
|
+
"gemini-4-hydrogen": { input: 0.0015, output: 0.0075, latency: 800 }, // General-purpose tier (Nov 12, 2026)
|
|
55
|
+
"gemini-4-argon": { input: 0.004, output: 0.020, latency: 1400 }, // Deprecated Dec 1, 2026; served by Carbon from Dec 15
|
|
56
|
+
"gemini-3.1-pro-preview": { input: 0.002, output: 0.012, latency: 1200 }, // Older Pro default, the Gemini 4 fallback
|
|
51
57
|
"gemini-3-flash-preview": { input: 0.0005, output: 0.003, latency: 500 }, // Legacy
|
|
52
58
|
// Other models
|
|
53
59
|
qwencoder: { input: 0.00015, output: 0.0006, latency: 1000 },
|
|
@@ -10,6 +10,7 @@ import { ReasoningMode } from "./reasoning-chain.js";
|
|
|
10
10
|
import { isModelAvailable, getAvailableModelNames } from "./utils/model-availability.js";
|
|
11
11
|
import { formatMemorySaveHint } from "./utils/memory-provider.js";
|
|
12
12
|
import { FORMAT_INSTRUCTION } from "./utils/format-constants.js";
|
|
13
|
+
import { traceThought } from "./utils/trace-bus.js";
|
|
13
14
|
// import { icon } from "./utils/ink-renderer.js";
|
|
14
15
|
// Ink disabled - using plain emojis instead
|
|
15
16
|
const icon = (name) => {
|
|
@@ -106,6 +107,7 @@ export class SequentialThinking {
|
|
|
106
107
|
// Add the thought
|
|
107
108
|
session.thoughts.push(newThought);
|
|
108
109
|
session.currentThought = newThought.number;
|
|
110
|
+
traceThought(newThought.number, thought, model, newThought.modelResponse);
|
|
109
111
|
// Update total thoughts if provided
|
|
110
112
|
if (totalThoughts !== undefined) {
|
|
111
113
|
session.totalThoughts = totalThoughts;
|
|
@@ -635,6 +637,7 @@ export class SequentialThinking {
|
|
|
635
637
|
// Add the thought
|
|
636
638
|
session.thoughts.push(newThought);
|
|
637
639
|
session.currentThought = newThought.number;
|
|
640
|
+
traceThought(newThought.number, thought, model, newThought.modelResponse);
|
|
638
641
|
// Update total thoughts if provided
|
|
639
642
|
if (totalThoughts !== undefined) {
|
|
640
643
|
session.totalThoughts = totalThoughts;
|
package/dist/src/server-main.js
CHANGED
|
@@ -35,7 +35,7 @@ if (savedThemeVars.RENDER_OUTPUT)
|
|
|
35
35
|
if (savedThemeVars.TACHIBOT_THEME)
|
|
36
36
|
process.env.TACHIBOT_THEME = savedThemeVars.TACHIBOT_THEME;
|
|
37
37
|
// Import centralized API key utilities
|
|
38
|
-
import { hasGrokApiKey, hasOpenAIApiKey, hasPerplexityApiKey, hasGeminiApiKey, hasOpenRouterApiKey } from "./utils/api-keys.js";
|
|
38
|
+
import { hasGrokApiKey, hasOpenAIApiKey, hasPerplexityApiKey, hasGeminiApiKey, hasOpenRouterApiKey, isProviderLocked, isAzureOpenAIRequested } from "./utils/api-keys.js";
|
|
39
39
|
// Debug: Log API key status (for troubleshooting)
|
|
40
40
|
if (process.env.DEBUG === 'true') {
|
|
41
41
|
console.error('[ENV] Loaded from:', envPath);
|
|
@@ -52,11 +52,15 @@ import { z } from "zod";
|
|
|
52
52
|
import { InstructionOrchestrator } from "./orchestrator-instructions.js";
|
|
53
53
|
import { validateToolInput, sanitizeForLogging } from "./utils/input-validator.js";
|
|
54
54
|
import { isToolEnabled, logToolConfiguration } from "./utils/tool-config.js";
|
|
55
|
-
import { renderOutput } from "./utils/ansi-renderer.js";
|
|
55
|
+
import { renderOutput, stripAnsi } from "./utils/ansi-renderer.js";
|
|
56
|
+
import { allowAnsiForClient } from "./utils/client-render.js";
|
|
56
57
|
import { getToolAnnotations } from "./utils/tool-annotations.js";
|
|
58
|
+
import { traceSpan } from "./utils/trace-bus.js";
|
|
59
|
+
import { initTraceUi } from "./utils/trace-server.js";
|
|
57
60
|
import { truncateSmart } from "./utils/stream-distill.js";
|
|
58
61
|
import { trackToolCall, inferModelFromTool, estimateTokens, isTrackingEnabled, getUsageSummary, getAllReposSummary, getStatsJson, resetStats } from "./utils/usage-tracker.js";
|
|
59
62
|
import { checkForUpdates } from "./utils/update-checker.js";
|
|
63
|
+
import { getProviderLock, validateProviderLock, installEgressGuard, allowedOrigin } from "./utils/provider-lock.js";
|
|
60
64
|
// import { renderBigText, renderToolBadge } from "./utils/ink-renderer.js"; // Disabled - plain text only
|
|
61
65
|
// import { WorkflowVisualizerLite } from "./visualizer-lite.js"; // Unused - removed
|
|
62
66
|
import { collaborativeOrchestrator } from "./collaborative-orchestrator.js";
|
|
@@ -122,6 +126,21 @@ const focusToolService = new FocusToolService(focusModeRegistry, collaborativeOr
|
|
|
122
126
|
const orchestrator = new InstructionOrchestrator();
|
|
123
127
|
// Set MCP server reference for collaborative orchestrator
|
|
124
128
|
collaborativeOrchestrator.setMCPServer(server);
|
|
129
|
+
/** Name the connected MCP client sent in initialize (e.g. "claude-code", "claude-ai"). */
|
|
130
|
+
let loggedClientName;
|
|
131
|
+
function getConnectedClientName() {
|
|
132
|
+
try {
|
|
133
|
+
const name = server.sessions[0]?.server?.getClientVersion?.()?.name;
|
|
134
|
+
if (name && name !== loggedClientName) {
|
|
135
|
+
loggedClientName = name;
|
|
136
|
+
console.error(`🔌 MCP client: ${name} (ANSI ${allowAnsiForClient(name) ? 'on' : 'off'})`);
|
|
137
|
+
}
|
|
138
|
+
return name;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
125
144
|
// Track registered tools to prevent duplicates
|
|
126
145
|
const registeredTools = new Set();
|
|
127
146
|
// ============================================================================
|
|
@@ -154,7 +173,7 @@ function safeAddTool(tool) {
|
|
|
154
173
|
...tool,
|
|
155
174
|
...(annotations && { annotations }),
|
|
156
175
|
execute: async (...args) => {
|
|
157
|
-
const result = await originalExecute(...args);
|
|
176
|
+
const result = await traceSpan('tool', tool.name, args[0], () => originalExecute(...args));
|
|
158
177
|
// Track usage (fire and forget, don't block)
|
|
159
178
|
if (isTrackingEnabled()) {
|
|
160
179
|
try {
|
|
@@ -185,7 +204,11 @@ function safeAddTool(tool) {
|
|
|
185
204
|
if (raw.length > MAX_RAW_CHARS) {
|
|
186
205
|
raw = truncateSmart(raw, MAX_RAW_CHARS);
|
|
187
206
|
}
|
|
188
|
-
|
|
207
|
+
// GUI clients (Claude Desktop, Cursor…) can't display ANSI — send clean
|
|
208
|
+
// markdown there; terminal clients keep the configured RENDER_OUTPUT.
|
|
209
|
+
const rendered = allowAnsiForClient(getConnectedClientName())
|
|
210
|
+
? renderOutput(raw, { model, summary: tool.name })
|
|
211
|
+
: stripAnsi(renderOutput(raw, { model, summary: tool.name, mode: 'markdown' }));
|
|
189
212
|
return { type: "text", text: rendered };
|
|
190
213
|
}
|
|
191
214
|
return result;
|
|
@@ -566,9 +589,33 @@ const providerInfo = getProviderInfo();
|
|
|
566
589
|
const availableProviders = Object.entries(providerInfo)
|
|
567
590
|
.filter(([_, info]) => info.available)
|
|
568
591
|
.map(([name]) => name);
|
|
569
|
-
|
|
592
|
+
// getProviderInfo() is a key-presence catalogue that knows nothing of the provider lock —
|
|
593
|
+
// under the lock it would list providers whose tools are not registered.
|
|
594
|
+
console.error(isProviderLocked()
|
|
595
|
+
? `🔒 Provider lock set — keys for other providers are ignored; only Azure-backed and keyless tools register`
|
|
596
|
+
: `✅ Available AI providers: ${availableProviders.join(', ')}`);
|
|
570
597
|
// Async initialization function to handle dynamic imports and startup
|
|
571
598
|
async function initializeServer() {
|
|
599
|
+
// Provider lock first, before any provider call: an invalid lock stops the server
|
|
600
|
+
// (never degrade to unlocked), a valid one confines fetch to the Azure resource.
|
|
601
|
+
try {
|
|
602
|
+
validateProviderLock();
|
|
603
|
+
if (getProviderLock()) {
|
|
604
|
+
installEgressGuard();
|
|
605
|
+
console.error(`🔒 TACHI_PROVIDER_LOCK=azure — outbound requests limited to ${allowedOrigin()} and loopback`);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
catch (error) {
|
|
609
|
+
console.error(`❌ ${error instanceof Error ? error.message : String(error)}`);
|
|
610
|
+
process.exit(1);
|
|
611
|
+
}
|
|
612
|
+
// Make the transport choice visible either way — it decides where prompts are sent.
|
|
613
|
+
if (isAzureOpenAIRequested()) {
|
|
614
|
+
console.error(`☁️ OpenAI tools use Azure OpenAI${process.env.OPENAI_API_KEY ? ' (OPENAI_API_KEY is ignored)' : ''}`);
|
|
615
|
+
}
|
|
616
|
+
else if (process.env.AZURE_OPENAI_ENDPOINT?.trim()) {
|
|
617
|
+
console.error(`ℹ️ AZURE_OPENAI_ENDPOINT is set but not used — set TACHI_OPENAI_TRANSPORT=azure to route the OpenAI tools to Azure`);
|
|
618
|
+
}
|
|
572
619
|
try {
|
|
573
620
|
// Register ALL provider tools via the central scan registry. getAllTools()
|
|
574
621
|
// evaluates the SAME is*Available() guards, in the SAME order, with the SAME
|
|
@@ -602,6 +649,7 @@ async function initializeServer() {
|
|
|
602
649
|
console.error(`Mode: ${config.isClaudeCode ? 'Claude Code' : 'Standalone'}`);
|
|
603
650
|
console.error(`Tools registered: ${registeredTools.size} active (${totalTools} available)`);
|
|
604
651
|
logToolConfiguration();
|
|
652
|
+
initTraceUi();
|
|
605
653
|
if (config.isClaudeCode) {
|
|
606
654
|
console.error(`Claude model: ${config.claudeModel}`);
|
|
607
655
|
}
|
|
@@ -623,7 +671,9 @@ async function initializeServer() {
|
|
|
623
671
|
}
|
|
624
672
|
console.error(`Ready for orchestration!`);
|
|
625
673
|
// Check for updates (non-blocking, fire and forget)
|
|
626
|
-
|
|
674
|
+
// Skipped under the provider lock — it calls the npm registry.
|
|
675
|
+
if (!getProviderLock())
|
|
676
|
+
checkForUpdates().catch(() => { }); // Silent fail
|
|
627
677
|
// Start the server with stdio transport
|
|
628
678
|
console.error("🚀 Starting server with stdio transport...");
|
|
629
679
|
server.start({
|
package/dist/src/server.js
CHANGED
|
@@ -8,7 +8,17 @@ if (process.argv[2] === "init") {
|
|
|
8
8
|
await runInitWizard();
|
|
9
9
|
process.exit(0);
|
|
10
10
|
}
|
|
11
|
+
else if (process.argv[2] === "trace") {
|
|
12
|
+
const { runTraceCli } = await import("./cli/trace.js");
|
|
13
|
+
await runTraceCli(process.argv.slice(3));
|
|
14
|
+
}
|
|
11
15
|
else {
|
|
16
|
+
// Provider lock: guard fetch BEFORE server-main's static imports run their side effects.
|
|
17
|
+
// (A lock set only in .env is picked up later, by initializeServer in server-main.)
|
|
18
|
+
if (process.env.TACHI_PROVIDER_LOCK?.trim()) {
|
|
19
|
+
const { installEgressGuard } = await import("./utils/provider-lock.js");
|
|
20
|
+
installEgressGuard();
|
|
21
|
+
}
|
|
12
22
|
await import("./server-main.js");
|
|
13
23
|
}
|
|
14
24
|
export {};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* No need for separate gemini-mcp server
|
|
5
5
|
*/
|
|
6
6
|
import { z } from "zod";
|
|
7
|
+
import { isProviderLocked } from "../utils/api-keys.js";
|
|
7
8
|
import { config } from "dotenv";
|
|
8
9
|
import * as path from "path";
|
|
9
10
|
import { fileURLToPath } from "url";
|
|
@@ -20,6 +21,7 @@ import { getTimeoutConfig } from "../config/timeout-config.js";
|
|
|
20
21
|
import { readFilesIntoContext } from "../utils/file-reader.js";
|
|
21
22
|
import { defineModelTool } from "./factory/define-model-tool.js";
|
|
22
23
|
import { filesField } from "./factory/base-schemas.js";
|
|
24
|
+
import { traceSpan, traceUsage } from "../utils/trace-bus.js";
|
|
23
25
|
// Note: renderOutput is applied centrally in server.ts safeAddTool() - no need to import here
|
|
24
26
|
// Load .env here rather than relying on a sibling module to have done it.
|
|
25
27
|
//
|
|
@@ -80,7 +82,11 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
80
82
|
* which lives in utils/judge-runner.ts rather than here — a Gemini helper silently
|
|
81
83
|
* answering as GPT would be a surprise to every other caller.
|
|
82
84
|
*/
|
|
83
|
-
|
|
85
|
+
/** Traced entry point — one span per call in the trace view (pass-through when TACHIBOT_TRACE_UI is off). */
|
|
86
|
+
export function callGemini(...args) {
|
|
87
|
+
return traceSpan('model', `gemini:${args[1] ?? GEMINI_MODELS.GEMINI_3_PRO}`, args[0], () => callGeminiImpl(...args));
|
|
88
|
+
}
|
|
89
|
+
async function callGeminiImpl(prompt, model = GEMINI_MODELS.GEMINI_3_PRO, systemPrompt, temperature = 0.7, validationContext = 'llm-orchestration', maxTokens = 18000) {
|
|
84
90
|
let last = "";
|
|
85
91
|
for (let attempt = 1; attempt <= GEMINI_MAX_ATTEMPTS; attempt++) {
|
|
86
92
|
last = await callGeminiAttempt(prompt, model, systemPrompt, temperature, validationContext, maxTokens);
|
|
@@ -93,13 +99,13 @@ export async function callGemini(prompt, model = GEMINI_MODELS.GEMINI_3_PRO, sys
|
|
|
93
99
|
console.error(`⏳ [Gemini] ${model} transient failure (attempt ${attempt}/${GEMINI_MAX_ATTEMPTS}), retrying in ${delay}ms`);
|
|
94
100
|
await sleep(delay);
|
|
95
101
|
}
|
|
96
|
-
// Gemini 4
|
|
97
|
-
// without
|
|
102
|
+
// Gemini 4 Pro tier (Carbon, Neon, the deprecated Argon) -> gemini-3.1-pro-preview, on ANY failure:
|
|
103
|
+
// a key/region without access gets a non-retryable 403/404 that the Flash stage below would skip.
|
|
98
104
|
// The result carries a [degraded: …] banner naming the model that ACTUALLY answered and
|
|
99
105
|
// why (judge-runner reports it), and a double failure keeps BOTH errors. Skipped when
|
|
100
106
|
// TACHI_MODEL_FALLBACK=off or the failure is billing (another model bills the same key).
|
|
101
107
|
const mayFallBack = isProviderFailure(last) && modelFallbackEnabled() && !isBillingFailure(last);
|
|
102
|
-
if (mayFallBack && model
|
|
108
|
+
if (mayFallBack && GEMINI_4_PRO_TIER.has(model)) {
|
|
103
109
|
console.error(`🔻 [Gemini] ${model} failed, falling back to ${GEMINI_MODELS.GEMINI_3_1_PRO}`);
|
|
104
110
|
const fb = await callGemini(prompt, GEMINI_MODELS.GEMINI_3_1_PRO, systemPrompt, temperature, validationContext, maxTokens);
|
|
105
111
|
if (isProviderFailure(fb)) {
|
|
@@ -121,13 +127,19 @@ export async function callGemini(prompt, model = GEMINI_MODELS.GEMINI_3_PRO, sys
|
|
|
121
127
|
return last;
|
|
122
128
|
}
|
|
123
129
|
const firstLine = (s) => s.trim().split("\n")[0].slice(0, 300);
|
|
130
|
+
/** Gemini 4 reasoning models that fall back to gemini-3.1-pro-preview when they fail. */
|
|
131
|
+
const GEMINI_4_PRO_TIER = new Set([
|
|
132
|
+
GEMINI_MODELS.GEMINI_4_CARBON,
|
|
133
|
+
GEMINI_MODELS.GEMINI_4_NEON,
|
|
134
|
+
GEMINI_MODELS.GEMINI_4_ARGON,
|
|
135
|
+
]);
|
|
124
136
|
/** Parse callGemini's leading "[degraded: X unavailable, answered by Y]" banner. */
|
|
125
137
|
export function parseDegradedBanner(text) {
|
|
126
138
|
const m = /^\[degraded: [^\]]*answered by ([^\]\s]+)\]\n\n/.exec(text);
|
|
127
139
|
return m ? { answeredBy: m[1], body: text.slice(m[0].length) } : null;
|
|
128
140
|
}
|
|
129
141
|
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
|
|
142
|
+
// Argon caps output at 32K (Carbon/Neon and 3.x Pro/Flash: 65K) — clamp rather than 400
|
|
131
143
|
if (model === GEMINI_MODELS.GEMINI_4_ARGON)
|
|
132
144
|
maxTokens = Math.min(maxTokens, 32768);
|
|
133
145
|
// Try OpenRouter gateway first if enabled
|
|
@@ -231,6 +243,7 @@ async function callGeminiAttempt(prompt, model = GEMINI_MODELS.GEMINI_3_PRO, sys
|
|
|
231
243
|
throw err;
|
|
232
244
|
}
|
|
233
245
|
const data = await response.json();
|
|
246
|
+
traceUsage(data?.usageMetadata);
|
|
234
247
|
// Debug logging for response structure
|
|
235
248
|
if (!data.candidates?.[0]?.content?.parts?.[0]?.text) {
|
|
236
249
|
console.warn('Gemini response missing text:', JSON.stringify(data, null, 2).substring(0, 500));
|
|
@@ -687,6 +700,7 @@ IMPORTANT:
|
|
|
687
700
|
throw new Error(`Gemini Search API error: ${response.status} - ${errorText}`);
|
|
688
701
|
}
|
|
689
702
|
const data = await response.json();
|
|
703
|
+
traceUsage(data?.usageMetadata);
|
|
690
704
|
// Extract response text
|
|
691
705
|
const candidate = data.candidates?.[0];
|
|
692
706
|
const text = candidate?.content?.parts?.[0]?.text;
|
|
@@ -726,7 +740,7 @@ IMPORTANT:
|
|
|
726
740
|
* Check if Gemini is available
|
|
727
741
|
*/
|
|
728
742
|
export function isGeminiAvailable() {
|
|
729
|
-
return !!GEMINI_API_KEY;
|
|
743
|
+
return !isProviderLocked() && !!GEMINI_API_KEY;
|
|
730
744
|
}
|
|
731
745
|
/**
|
|
732
746
|
* Get all Gemini tools
|
|
@@ -454,7 +454,6 @@ export function getGrokStatus() {
|
|
|
454
454
|
'Grok 4.7 also powers live search (grok_search) — best-cited grounded answers',
|
|
455
455
|
'Grok 4.6 (grok-4.6): Previous flagship/search model, kept for explicit picks ($2/$6)',
|
|
456
456
|
'Grok 4.3 (grok-4.3): Previous flagship, kept as fallback — 1M context, lowest verified hallucination ($1.25/$2.50)',
|
|
457
|
-
'Grok Build (grok-build-0.1): Fast agentic coding specialist, 256k context',
|
|
458
457
|
'Live web search with citations',
|
|
459
458
|
'Function calling',
|
|
460
459
|
'Structured outputs',
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Provides Grok 4 reasoning and code analysis capabilities
|
|
4
4
|
*/
|
|
5
5
|
import { z } from "zod";
|
|
6
|
+
import { reasoningTimeoutMs } from '../config/timeout-config.js';
|
|
6
7
|
import { config } from "dotenv";
|
|
7
8
|
import * as path from 'path';
|
|
8
9
|
import { fileURLToPath } from 'url';
|
|
@@ -17,6 +18,7 @@ import { tryOpenRouterGateway, isGatewayEnabled } from "../utils/openrouter-gate
|
|
|
17
18
|
import { withHeartbeat } from "../utils/streaming-helper.js";
|
|
18
19
|
import { readFilesIntoContext } from "../utils/file-reader.js";
|
|
19
20
|
import { modelFallbackEnabled, degradedBanner } from "../utils/fallback-policy.js";
|
|
21
|
+
import { traceSpan, traceUsage, lastMessageText } from "../utils/trace-bus.js";
|
|
20
22
|
// Note: renderOutput is applied centrally in server.ts safeAddTool() - no need to import here
|
|
21
23
|
const __filename = fileURLToPath(import.meta.url);
|
|
22
24
|
const __dirname = path.dirname(__filename);
|
|
@@ -70,7 +72,11 @@ export var GrokModel;
|
|
|
70
72
|
* - 'code-analysis': Relaxed for code analysis tools
|
|
71
73
|
* - 'llm-orchestration': Medium for LLM-to-LLM calls
|
|
72
74
|
*/
|
|
73
|
-
|
|
75
|
+
/** Traced entry point — one span per call in the trace view (pass-through when TACHIBOT_TRACE_UI is off). */
|
|
76
|
+
export function callGrok(...args) {
|
|
77
|
+
return traceSpan('model', `grok:${args[1] ?? GrokModel.GROK_4_7}`, lastMessageText(args[0]), () => callGrokImpl(...args));
|
|
78
|
+
}
|
|
79
|
+
async function callGrokImpl(messages, model = GrokModel.GROK_4_7, temperature = 0.7, maxTokens = 16384, // Increased default for comprehensive responses
|
|
74
80
|
forceVisibleOutput = true, validationContext = 'llm-orchestration', reasoningEffort) {
|
|
75
81
|
// Try OpenRouter gateway first if enabled
|
|
76
82
|
if (isGatewayEnabled()) {
|
|
@@ -98,7 +104,8 @@ forceVisibleOutput = true, validationContext = 'llm-orchestration', reasoningEff
|
|
|
98
104
|
// Grok 4.x reasoning can take 60-90s; 4.3/4.5 flagship and multi-agent can take longer
|
|
99
105
|
const isReasoning = model.includes('reasoning') || model.includes('multi-agent');
|
|
100
106
|
const isFlagship = model.includes('4.20') || /^grok-4\.\d/.test(model); // 4.3/4.5/4.6/4.7…
|
|
101
|
-
|
|
107
|
+
// flagship reasoning: xAI recommends ≥900s for high/xhigh; 180s timed out a council debate
|
|
108
|
+
const timeoutMs = isFlagship ? reasoningTimeoutMs('grok') : (isReasoning ? 120000 : 60000);
|
|
102
109
|
try {
|
|
103
110
|
// For Grok 4+ models, we need to handle reasoning tokens specially
|
|
104
111
|
const isGrok4Plus = model.includes('grok-4');
|
|
@@ -138,6 +145,7 @@ forceVisibleOutput = true, validationContext = 'llm-orchestration', reasoningEff
|
|
|
138
145
|
throw new Error(`Grok API error: ${response.statusText} - ${error}`);
|
|
139
146
|
}
|
|
140
147
|
const data = await response.json();
|
|
148
|
+
traceUsage(data?.usage);
|
|
141
149
|
const content = data.choices?.[0]?.message?.content;
|
|
142
150
|
// Handle Grok 4's reasoning tokens
|
|
143
151
|
if (!content && data.usage?.completion_tokens_details?.reasoning_tokens > 0) {
|
|
@@ -11,12 +11,20 @@ import { callGrok } from "./grok-tools.js";
|
|
|
11
11
|
import { callOpenAI } from "./openai-tools.js";
|
|
12
12
|
import { callOpenRouter, OpenRouterModel } from "./openrouter-tools.js";
|
|
13
13
|
import { callLocal } from "./local-tools.js";
|
|
14
|
+
import { OPENAI_MODELS } from "../config/model-constants.js";
|
|
14
15
|
import { FORMAT_INSTRUCTION } from "../utils/format-constants.js";
|
|
15
16
|
import { isProviderFailure } from "../utils/provider-failure.js";
|
|
16
17
|
import { runJudge, judgeAttribution } from "../utils/judge-runner.js";
|
|
17
18
|
import { JUDGE_MODE_INSTRUCTIONS, JUDGE_METHOD, JUDGE_EPISTEMIC_LIMIT, JUDGE_BIAS_CONTROLS, JUDGE_FORMAT_EXCEPTION, } from "../utils/judge-constants.js";
|
|
18
19
|
import { stripFormatting } from "../utils/format-stripper.js";
|
|
19
20
|
import { withHeartbeat } from "../utils/streaming-helper.js";
|
|
21
|
+
// GPT juror model. Was implicit (callOpenAI's cheap default, now gpt-6-luna)
|
|
22
|
+
// since v2.14.7 — never a deliberate choice. Pinned to the GPT-6 sol mid
|
|
23
|
+
// tier ($2/$10); TACHI_JURY_OPENAI_MODEL overrides (e.g. gpt-6.2-astra, gpt-6-luna).
|
|
24
|
+
// Read at call time so .env (loaded after this module) is honoured.
|
|
25
|
+
export function getJuryOpenAIModel() {
|
|
26
|
+
return process.env.TACHI_JURY_OPENAI_MODEL?.trim() || OPENAI_MODELS.SOL;
|
|
27
|
+
}
|
|
20
28
|
// Per-juror output budget. Reasoning-heavy jurors (GLM, Kimi, DeepSeek,
|
|
21
29
|
// GPT-5.5 high-effort) spend much of their token budget on internal reasoning
|
|
22
30
|
// BEFORE the visible answer, so a tight cap truncates the verdict mid-sentence
|
|
@@ -41,7 +49,7 @@ export const JUROR_REGISTRY = {
|
|
|
41
49
|
call: async (q) => callOpenAI([
|
|
42
50
|
{ role: "system", content: `You are an analytical reasoner. Consider tradeoffs, edge cases, and nuance. ${FORMAT_INSTRUCTION}` },
|
|
43
51
|
{ role: "user", content: q }
|
|
44
|
-
],
|
|
52
|
+
], getJuryOpenAIModel(), 0.7, JUROR_MAX_TOKENS, "high"),
|
|
45
53
|
},
|
|
46
54
|
qwen: {
|
|
47
55
|
label: "Qwen (Code & Logic)",
|