mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 21:05:51 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
478091567d | ||
|
|
b4e52d0c9e |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "claude-code-best",
|
"name": "claude-code-best",
|
||||||
"version": "2.4.2",
|
"version": "2.4.3",
|
||||||
"description": "Reverse-engineered Anthropic Claude Code CLI — interactive AI coding assistant in the terminal",
|
"description": "Reverse-engineered Anthropic Claude Code CLI — interactive AI coding assistant in the terminal",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"author": "claude-code-best <claude-code-best@proton.me>",
|
"author": "claude-code-best <claude-code-best@proton.me>",
|
||||||
|
|||||||
@@ -10,8 +10,14 @@ import {
|
|||||||
} from 'src/Tool.js'
|
} from 'src/Tool.js'
|
||||||
import { lazySchema } from 'src/utils/lazySchema.js'
|
import { lazySchema } from 'src/utils/lazySchema.js'
|
||||||
import { createUserMessage } from 'src/utils/messages.js'
|
import { createUserMessage } from 'src/utils/messages.js'
|
||||||
|
import {
|
||||||
|
extractDiscoveredToolNames,
|
||||||
|
isSearchExtraToolsEnabledOptimistic,
|
||||||
|
isSearchExtraToolsToolAvailable,
|
||||||
|
} from 'src/utils/searchExtraTools.js'
|
||||||
import { DESCRIPTION, getPrompt } from './prompt.js'
|
import { DESCRIPTION, getPrompt } from './prompt.js'
|
||||||
import { EXECUTE_TOOL_NAME } from './constants.js'
|
import { EXECUTE_TOOL_NAME } from './constants.js'
|
||||||
|
import { isDeferredTool } from '../SearchExtraToolsTool/prompt.js'
|
||||||
|
|
||||||
export const inputSchema = lazySchema(() =>
|
export const inputSchema = lazySchema(() =>
|
||||||
z.object({
|
z.object({
|
||||||
@@ -74,6 +80,32 @@ export const ExecuteTool = buildTool({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Guard: block execution of undiscovered deferred tools.
|
||||||
|
// When tool search is active, deferred tools must be discovered via
|
||||||
|
// SearchExtraTools first so the model has seen their schemas and knows
|
||||||
|
// the correct parameters. Executing an undiscovered tool almost always
|
||||||
|
// fails with parameter validation errors.
|
||||||
|
if (
|
||||||
|
isSearchExtraToolsEnabledOptimistic() &&
|
||||||
|
isSearchExtraToolsToolAvailable(tools) &&
|
||||||
|
isDeferredTool(targetTool)
|
||||||
|
) {
|
||||||
|
const discovered = extractDiscoveredToolNames(context.messages)
|
||||||
|
if (!discovered.has(input.tool_name)) {
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
result: null,
|
||||||
|
tool_name: input.tool_name,
|
||||||
|
},
|
||||||
|
newMessages: [
|
||||||
|
createUserMessage({
|
||||||
|
content: `Tool "${input.tool_name}" has not been discovered yet. You must first use SearchExtraTools to discover this tool before executing it.\n\nUsage: SearchExtraTools("select:${input.tool_name}")`,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the target tool is currently enabled
|
// Check if the target tool is currently enabled
|
||||||
if (!targetTool.isEnabled()) {
|
if (!targetTool.isEnabled()) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ mock.module('src/utils/searchExtraTools.js', () => ({
|
|||||||
isSearchExtraToolsEnabledOptimistic: () => true,
|
isSearchExtraToolsEnabledOptimistic: () => true,
|
||||||
getAutoSearchExtraToolsCharThreshold: () => 100,
|
getAutoSearchExtraToolsCharThreshold: () => 100,
|
||||||
getSearchExtraToolsMode: () => 'tst' as const,
|
getSearchExtraToolsMode: () => 'tst' as const,
|
||||||
isSearchExtraToolsToolAvailable: async () => true,
|
isSearchExtraToolsToolAvailable: () => true,
|
||||||
isSearchExtraToolsEnabled: async () => true,
|
isSearchExtraToolsEnabled: async () => true,
|
||||||
isToolReferenceBlock: () => false,
|
isToolReferenceBlock: () => false,
|
||||||
extractDiscoveredToolNames: () => new Set(),
|
extractDiscoveredToolNames: () => new Set(['TestTool', 'SecretTool']),
|
||||||
isDeferredToolsDeltaEnabled: () => false,
|
isDeferredToolsDeltaEnabled: () => false,
|
||||||
getDeferredToolsDelta: () => null,
|
getDeferredToolsDelta: () => null,
|
||||||
}))
|
}))
|
||||||
@@ -154,6 +154,26 @@ describe('ExecuteTool', () => {
|
|||||||
expect(result.newMessages).toBeDefined()
|
expect(result.newMessages).toBeDefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('returns error when deferred tool has not been discovered via SearchExtraTools', async () => {
|
||||||
|
const mockTarget = makeMockTool('UndiscoveredTool', 'result')
|
||||||
|
const ctx = makeContext([mockTarget])
|
||||||
|
|
||||||
|
const result = await ExecuteTool.call(
|
||||||
|
{ tool_name: 'UndiscoveredTool', params: {} },
|
||||||
|
ctx,
|
||||||
|
async () => ({ behavior: 'allow' }),
|
||||||
|
{ type: 'assistant', content: [], uuid: 'msg1' } as never,
|
||||||
|
undefined,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(result.data).toEqual({
|
||||||
|
result: null,
|
||||||
|
tool_name: 'UndiscoveredTool',
|
||||||
|
})
|
||||||
|
expect(result.newMessages).toBeDefined()
|
||||||
|
expect(result.newMessages![0].content).toContain('has not been discovered')
|
||||||
|
})
|
||||||
|
|
||||||
test('has correct name', () => {
|
test('has correct name', () => {
|
||||||
expect(ExecuteTool.name).toBe(EXECUTE_TOOL_NAME)
|
expect(ExecuteTool.name).toBe(EXECUTE_TOOL_NAME)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1396,7 +1396,7 @@ async function* queryModel(
|
|||||||
messagesForAPI = [
|
messagesForAPI = [
|
||||||
...messagesForAPI,
|
...messagesForAPI,
|
||||||
createUserMessage({
|
createUserMessage({
|
||||||
content: `<system-reminder>\n<available-deferred-tools>\n${deferredToolList}\n</available-deferred-tools>\nTo invoke any tool listed above, use ExecuteExtraTool with {"tool_name": "<name>", "params": {...}}. This is the ONLY way to call deferred tools — do not read source code or analyze implementation, just call ExecuteExtraTool directly.\n</system-reminder>`,
|
content: `<system-reminder>\n<available-deferred-tools>\n${deferredToolList}\n</available-deferred-tools>\nIMPORTANT: These tools are deferred-loading. You MUST first discover a tool via SearchExtraTools before invoking it with ExecuteExtraTool. Do NOT call ExecuteExtraTool directly — it will fail if the tool has not been discovered.\n\nSteps:\n1. SearchExtraTools("select:<tool_name>") — discover the tool and its schema\n2. ExecuteExtraTool({"tool_name": "<name>", "params": {...}}) — invoke it with correct parameters\n</system-reminder>`,
|
||||||
isMeta: true,
|
isMeta: true,
|
||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user