Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export enum Constants {
/** Anthropic server tool ID prefix (web_search, code_execution, etc.) */
ANTHROPIC_SERVER_TOOL_PREFIX = 'srvtoolu_',
SKILL_TOOL = 'skill',
READ_FILE = 'read_file',
BASH_TOOL = 'bash_tool',
BASH_PROGRAMMATIC_TOOL_CALLING = 'run_tools_with_bash',
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from './tools/BashExecutor';
export * from './tools/ProgrammaticToolCalling';
export * from './tools/BashProgrammaticToolCalling';
export * from './tools/SkillTool';
export * from './tools/ReadFile';
export * from './tools/skillCatalog';
export * from './tools/ToolSearch';
export * from './tools/ToolNode';
Expand Down
39 changes: 39 additions & 0 deletions src/tools/ReadFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// src/tools/ReadFile.ts
import { Constants } from '@/common';

export const ReadFileToolName = Constants.READ_FILE;

export const ReadFileToolDescription = `Read the contents of a file. Returns text content with line numbers for easy reference.

For skill files, use the path format: {skillName}/{filePath} (e.g. "pdf-analyzer/src/utils.py", "code-review/SKILL.md").

BEHAVIOR:
- Text files: returned with numbered lines.
- Images (png, jpeg, gif, webp): returned as visual content the model can see.
- PDFs: returned as document content.
- Other binary files: metadata returned with a note to use bash for processing.
- Large files (>256KB text, >10MB binary): metadata only.
- SKILL.md: returns the skill's instructions directly.

CONSTRAINTS:
- Only files from invoked skills or code execution output are accessible.
- Do not guess file paths. Use paths from the skill documentation or tool output.`;

export const ReadFileToolSchema = {
type: 'object',
properties: {
file_path: {
type: 'string',
description:
'Path to the file. For skill files: "{skillName}/{path}" (e.g. "pdf-analyzer/src/utils.py"). For code execution output: the path as returned by the execution tool.',
},
},
required: ['file_path'],
} as const;

export const ReadFileToolDefinition = {
name: ReadFileToolName,
description: ReadFileToolDescription,
parameters: ReadFileToolSchema,
responseFormat: 'content_and_artifact' as const,
} as const;
44 changes: 44 additions & 0 deletions src/tools/__tests__/ReadFile.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, it, expect } from '@jest/globals';
import { Constants } from '@/common';
import {
ReadFileToolName,
ReadFileToolSchema,
ReadFileToolDescription,
ReadFileToolDefinition,
} from '../ReadFile';

describe('ReadFile', () => {
describe('schema structure', () => {
it('has file_path as required string property', () => {
expect(ReadFileToolSchema.properties.file_path.type).toBe('string');
expect(ReadFileToolSchema.required).toContain('file_path');
});

it('is an object type schema', () => {
expect(ReadFileToolSchema.type).toBe('object');
});
});

describe('ReadFileToolDefinition', () => {
it('has correct name', () => {
expect(ReadFileToolDefinition.name).toBe(Constants.READ_FILE);
expect(ReadFileToolDefinition.name).toBe('read_file');
});

it('references the same ReadFileToolSchema object', () => {
expect(ReadFileToolDefinition.parameters).toBe(ReadFileToolSchema);
});

it('has a non-empty description', () => {
expect(ReadFileToolDefinition.description).toBe(ReadFileToolDescription);
expect(ReadFileToolDefinition.description.length).toBeGreaterThan(0);
});
});

describe('ReadFileToolName', () => {
it('equals Constants.READ_FILE', () => {
expect(ReadFileToolName).toBe('read_file');
expect(ReadFileToolName).toBe(Constants.READ_FILE);
});
});
});