Skip to content

Commit 8c561fc

Browse files
authored
Merge pull request #17 from IMvision12/tool
Remove Tool
2 parents 50d48b0 + e4edb72 commit 8c561fc

26 files changed

Lines changed: 160 additions & 3911 deletions

README.md

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Code without a keyboard. Send a message from your phone, and **txtcode** dispatc
3535

3636
1. **Text your AI** from WhatsApp, Telegram, Discord, Slack, Teams, or Signal
3737
2. **It writes code** using Claude Code, Cursor, Codex, Gemini CLI, or other adapters
38-
3. **You stay in control** with mode switching, tool calling, and session logs
38+
3. **You stay in control** with mode switching and session logs
3939

4040
No port forwarding. No VPN. Just message and code.
4141

@@ -66,10 +66,6 @@ Claude Code, Cursor CLI, OpenAI Codex, Gemini CLI, Kiro CLI, OpenCode, and Ollam
6666
</td>
6767
<td width="50%">
6868

69-
### 9 Built-in Tools
70-
71-
Terminal, process manager, git, file search, HTTP client, environment variables, network diagnostics, cron jobs, and system info all callable by the LLM.
72-
7369
### Session Logging
7470

7571
Per-session logs accessible from the TUI. Follow live, view by index, auto-pruned after 7 days.
@@ -159,7 +155,7 @@ txtcode supports **9 LLM providers** for chat mode. Configure one or more during
159155
| **HuggingFace** | _Discovered at runtime_ | Inference Providers API |
160156
| **OpenRouter** | _Discovered at runtime_ | Unified API for 100+ models |
161157

162-
All providers support tool calling and the LLM can invoke any built-in tool.
158+
All providers are used in chat mode for general conversation and coding questions.
163159

164160
---
165161

@@ -179,37 +175,19 @@ Use `/code` mode to route messages directly to a coding adapter with full coding
179175

180176
---
181177

182-
## 🛠️ Built-in Tools
183-
184-
The primary LLM in chat mode has access to **9 built-in tools** that it can call autonomously:
185-
186-
| Tool | Capabilities |
187-
| :----------- | :---------------------------------------------------------------------------------------- |
188-
| **Terminal** | Execute shell commands with timeout and output capture |
189-
| **Process** | Manage background processes: list, poll, stream logs, kill, send input |
190-
| **Git** | Full git operations (blocks force-push and credential config for safety) |
191-
| **Search** | File and content search across the project |
192-
| **HTTP** | Make HTTP requests (GET, POST, PUT, DELETE, PATCH, HEAD). Blocks cloud metadata endpoints |
193-
| **Env** | Get, set, list, and delete environment variables. Masks sensitive values |
194-
| **Network** | Ping, DNS lookup, reachability checks, port scanning |
195-
| **Cron** | Create, list, and manage cron jobs |
196-
| **Sysinfo** | CPU, memory, disk, uptime, OS details |
197-
198-
---
199-
200178
## 💬 Chat Commands
201179

202180
Send these commands in any messaging app while connected:
203181

204-
| Command | Description |
205-
| :----------- | :----------------------------------------------------------------------------- |
206-
| `/chat` | Switch to **Chat mode** to send messages to primary LLM with tools _(default)_ |
207-
| `/code` | Switch to **Code mode** to send messages to coding adapter (full CLI control) |
208-
| `/switch` | Switch primary LLM provider or coding adapter on the fly |
209-
| `/cli-model` | Change the model used by the current coding adapter |
210-
| `/cancel` | Cancel the currently running command |
211-
| `/status` | Show adapter connection and current configuration |
212-
| `/help` | Show available commands |
182+
| Command | Description |
183+
| :----------- | :---------------------------------------------------------------------------- |
184+
| `/chat` | Switch to **Chat mode** to send messages to primary LLM _(default)_ |
185+
| `/code` | Switch to **Code mode** to send messages to coding adapter (full CLI control) |
186+
| `/switch` | Switch primary LLM provider or coding adapter on the fly |
187+
| `/cli-model` | Change the model used by the current coding adapter |
188+
| `/cancel` | Cancel the currently running command |
189+
| `/status` | Show adapter connection and current configuration |
190+
| `/help` | Show available commands |
213191

214192
---
215193

src/core/router.ts

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ import { processWithOpenRouter } from "../providers/openrouter";
1616
import { processWithXAI } from "../providers/xai";
1717
import { logger } from "../shared/logger";
1818
import { IDEAdapter, ModelInfo } from "../shared/types";
19-
import { CronTool } from "../tools/cron";
20-
import { EnvTool } from "../tools/env";
21-
import { GitTool } from "../tools/git";
22-
import { HttpTool } from "../tools/http";
23-
import { NetworkTool } from "../tools/network";
24-
import { ProcessTool } from "../tools/process";
25-
import { ToolRegistry } from "../tools/registry";
26-
import { SearchTool } from "../tools/search";
27-
import { SysinfoTool } from "../tools/sysinfo";
28-
import { TerminalTool } from "../tools/terminal";
2919
import { ContextManager } from "./context-manager";
3020

3121
export const AVAILABLE_ADAPTERS = [
@@ -43,7 +33,6 @@ export class Router {
4333
private provider: string;
4434
private apiKey: string;
4535
private model: string;
46-
private toolRegistry: ToolRegistry;
4736
private contextManager: ContextManager;
4837
private pendingHandoff: string | null = null;
4938
private currentAbortController: AbortController | null = null;
@@ -53,17 +42,6 @@ export class Router {
5342
this.apiKey = process.env.AI_API_KEY || "";
5443
this.model = process.env.AI_MODEL || "";
5544

56-
this.toolRegistry = new ToolRegistry();
57-
this.toolRegistry.register(new TerminalTool());
58-
this.toolRegistry.register(new ProcessTool());
59-
this.toolRegistry.register(new GitTool());
60-
this.toolRegistry.register(new SearchTool());
61-
this.toolRegistry.register(new HttpTool());
62-
this.toolRegistry.register(new EnvTool());
63-
this.toolRegistry.register(new NetworkTool());
64-
this.toolRegistry.register(new CronTool());
65-
this.toolRegistry.register(new SysinfoTool());
66-
6745
this.contextManager = new ContextManager();
6846

6947
const ideType = process.env.IDE_TYPE || "";
@@ -151,28 +129,23 @@ export class Router {
151129
private async _routeToProvider(instruction: string): Promise<string> {
152130
switch (this.provider) {
153131
case "anthropic":
154-
return await processWithAnthropic(instruction, this.apiKey, this.model, this.toolRegistry);
132+
return await processWithAnthropic(instruction, this.apiKey, this.model);
155133
case "openai":
156-
return await processWithOpenAI(instruction, this.apiKey, this.model, this.toolRegistry);
134+
return await processWithOpenAI(instruction, this.apiKey, this.model);
157135
case "gemini":
158-
return await processWithGemini(instruction, this.apiKey, this.model, this.toolRegistry);
136+
return await processWithGemini(instruction, this.apiKey, this.model);
159137
case "openrouter":
160-
return await processWithOpenRouter(instruction, this.apiKey, this.model, this.toolRegistry);
138+
return await processWithOpenRouter(instruction, this.apiKey, this.model);
161139
case "moonshot":
162-
return await processWithMoonshot(instruction, this.apiKey, this.model, this.toolRegistry);
140+
return await processWithMoonshot(instruction, this.apiKey, this.model);
163141
case "minimax":
164-
return await processWithMiniMax(instruction, this.apiKey, this.model, this.toolRegistry);
142+
return await processWithMiniMax(instruction, this.apiKey, this.model);
165143
case "huggingface":
166-
return await processWithHuggingFace(
167-
instruction,
168-
this.apiKey,
169-
this.model,
170-
this.toolRegistry,
171-
);
144+
return await processWithHuggingFace(instruction, this.apiKey, this.model);
172145
case "mistral":
173-
return await processWithMistral(instruction, this.apiKey, this.model, this.toolRegistry);
146+
return await processWithMistral(instruction, this.apiKey, this.model);
174147
case "xai":
175-
return await processWithXAI(instruction, this.apiKey, this.model, this.toolRegistry);
148+
return await processWithXAI(instruction, this.apiKey, this.model);
176149
default:
177150
return `[ERROR] Unsupported AI provider: ${this.provider}. Run: txtcode config`;
178151
}

src/data/primary_llm_system_prompt.txt

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/providers/anthropic.ts

Lines changed: 19 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,38 @@
1-
import fs from "fs";
2-
import path from "path";
31
import Anthropic from "@anthropic-ai/sdk";
4-
import type {
5-
ContentBlock,
6-
MessageParam,
7-
TextBlock,
8-
ToolResultBlockParam,
9-
ToolUnion,
10-
ToolUseBlock,
11-
} from "@anthropic-ai/sdk/resources/messages/messages";
122
import { logger } from "../shared/logger";
13-
import { ToolRegistry } from "../tools/registry";
143

15-
const MAX_ITERATIONS = 10;
16-
17-
function loadSystemPrompt(): string {
18-
try {
19-
const promptPath = path.join(__dirname, "..", "data", "primary_llm_system_prompt.txt");
20-
return fs.readFileSync(promptPath, "utf-8");
21-
} catch {
22-
return "You are a helpful coding assistant.";
23-
}
24-
}
4+
const SYSTEM_PROMPT =
5+
"You are TxtCode AI — a helpful, knowledgeable coding assistant accessible via messaging. Be concise, use markdown for clarity, and suggest /code mode for deep coding work.";
256

267
export async function processWithAnthropic(
278
instruction: string,
289
apiKey: string,
2910
model: string,
30-
toolRegistry?: ToolRegistry,
3111
): Promise<string> {
3212
const startTime = Date.now();
3313
logger.debug(`[Anthropic] Request → model=${model}, prompt=${instruction.length} chars`);
3414

3515
try {
3616
const anthropic = new Anthropic({ apiKey });
3717

38-
const tools = toolRegistry
39-
? (toolRegistry.getDefinitionsForProvider("anthropic") as unknown as ToolUnion[])
40-
: undefined;
41-
42-
const messages: MessageParam[] = [{ role: "user", content: instruction }];
43-
44-
for (let i = 0; i < MAX_ITERATIONS; i++) {
45-
const iterStart = Date.now();
46-
const response = await anthropic.messages.create({
47-
model,
48-
max_tokens: 4096,
49-
system: loadSystemPrompt(),
50-
messages,
51-
...(tools ? { tools } : {}),
52-
});
53-
54-
logger.debug(
55-
`[Anthropic] Response ← iteration=${i + 1}, stop=${response.stop_reason}, ` +
56-
`tokens=${response.usage.input_tokens}in/${response.usage.output_tokens}out, ` +
57-
`time=${Date.now() - iterStart}ms`,
58-
);
59-
60-
const textParts = response.content
61-
.filter((block: ContentBlock): block is TextBlock => block.type === "text")
62-
.map((block: TextBlock) => block.text);
63-
64-
const toolCalls = response.content.filter(
65-
(block: ContentBlock): block is ToolUseBlock => block.type === "tool_use",
66-
);
67-
68-
if (toolCalls.length === 0 || !toolRegistry) {
69-
logger.debug(`[Anthropic] Done in ${Date.now() - startTime}ms (${i + 1} iteration(s))`);
70-
return textParts.join("\n") || "No response from Claude";
71-
}
72-
73-
logger.debug(`[Anthropic] Tool calls: ${toolCalls.map((t) => t.name).join(", ")}`);
74-
75-
messages.push({ role: "assistant", content: response.content });
76-
77-
const toolResults: ToolResultBlockParam[] = [];
78-
for (const toolUse of toolCalls) {
79-
const result = await toolRegistry.execute(
80-
toolUse.name,
81-
toolUse.input as Record<string, unknown>,
82-
);
83-
toolResults.push({
84-
type: "tool_result",
85-
tool_use_id: toolUse.id,
86-
content: result.output,
87-
});
88-
}
89-
90-
messages.push({ role: "user", content: toolResults });
91-
}
18+
const response = await anthropic.messages.create({
19+
model,
20+
max_tokens: 4096,
21+
system: SYSTEM_PROMPT,
22+
messages: [{ role: "user", content: instruction }],
23+
});
24+
25+
const text = response.content
26+
.filter((block): block is Anthropic.TextBlock => block.type === "text")
27+
.map((block) => block.text)
28+
.join("\n");
29+
30+
logger.debug(
31+
`[Anthropic] Done in ${Date.now() - startTime}ms, ` +
32+
`tokens=${response.usage.input_tokens}in/${response.usage.output_tokens}out`,
33+
);
9234

93-
logger.warn(`[Anthropic] Reached max ${MAX_ITERATIONS} iterations`);
94-
return "Reached maximum tool iterations.";
35+
return text || "No response from Claude";
9536
} catch (error: unknown) {
9637
logger.error(`[Anthropic] API error after ${Date.now() - startTime}ms`, error);
9738
throw new Error(

0 commit comments

Comments
 (0)