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
19 changes: 19 additions & 0 deletions packages/core/src/tools/glob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,25 @@ describe('GlobTool', () => {
expect(result.llmContent).toContain('[5 files truncated] ...');
});
});

describe('getDefaultPermission', () => {
it('should return allow for paths within workspace', async () => {
const params: GlobToolParams = { pattern: '*', path: 'sub' };
const invocation = globTool.build(params);
const permission = await invocation.getDefaultPermission();
expect(permission).toBe('allow');
});

it('should return ask for tilde paths outside workspace', async () => {
const params: GlobToolParams = {
pattern: '*',
path: '~/outside-workspace',
};
const invocation = globTool.build(params);
const permission = await invocation.getDefaultPermission();
expect(permission).toBe('ask');
});
});
});

describe('sortFileEntries', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/tools/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { BaseDeclarativeTool, BaseToolInvocation, Kind } from './tools.js';
import { ToolNames, ToolDisplayNames } from './tool-names.js';
import {
resolveAndValidatePath,
resolvePath,
isSubpath,
unescapePath,
} from '../utils/paths.js';
Expand Down Expand Up @@ -114,7 +115,7 @@ class GlobToolInvocation extends BaseToolInvocation<
return 'allow'; // Default workspace directory
}
const workspaceContext = this.config.getWorkspaceContext();
const resolvedPath = path.resolve(
const resolvedPath = resolvePath(
this.config.getTargetDir(),
this.params.path,
);
Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/tools/grep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,25 @@ describe('GrepTool', () => {
});
});

describe('getDefaultPermission', () => {
it('should return allow for paths within workspace', async () => {
const params: GrepToolParams = { pattern: 'hello', path: 'sub' };
const invocation = grepTool.build(params);
const permission = await invocation.getDefaultPermission();
expect(permission).toBe('allow');
});

it('should return ask for tilde paths outside workspace', async () => {
const params: GrepToolParams = {
pattern: 'hello',
path: '~/outside-workspace',
};
const invocation = grepTool.build(params);
const permission = await invocation.getDefaultPermission();
expect(permission).toBe('ask');
});
});

describe('Result limiting', () => {
beforeEach(async () => {
// Create many test files with matches to test limiting
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/tools/grep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ToolNames, ToolDisplayNames } from './tool-names.js';
import { createDebugLogger } from '../utils/debugLogger.js';
import {
resolveAndValidatePath,
resolvePath,
isSubpath,
unescapePath,
} from '../utils/paths.js';
Expand Down Expand Up @@ -91,7 +92,7 @@ class GrepToolInvocation extends BaseToolInvocation<
return 'allow'; // Default workspace directory
}
const workspaceContext = this.config.getWorkspaceContext();
const resolvedPath = path.resolve(
const resolvedPath = resolvePath(
this.config.getTargetDir(),
this.params.path,
);
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/tools/ripGrep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1132,5 +1132,15 @@ describe('RipGrepTool', () => {
const permission = await invocation.getDefaultPermission();
expect(permission).toBe('ask');
});

it('should return ask for tilde paths outside workspace', async () => {
const params: RipGrepToolParams = {
pattern: 'hello',
path: '~/outside-workspace',
};
const invocation = grepTool.build(params);
const permission = await invocation.getDefaultPermission();
expect(permission).toBe('ask');
});
});
});
8 changes: 6 additions & 2 deletions packages/core/src/tools/ripGrep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import path from 'node:path';
import type { ToolInvocation, ToolResult } from './tools.js';
import { BaseDeclarativeTool, BaseToolInvocation, Kind } from './tools.js';
import { ToolNames } from './tool-names.js';
import { resolveAndValidatePath, unescapePath } from '../utils/paths.js';
import {
resolveAndValidatePath,
resolvePath,
unescapePath,
} from '../utils/paths.js';
import { getErrorMessage } from '../utils/errors.js';
import type { Config } from '../config/config.js';
import { runRipgrep } from '../utils/ripgrepUtils.js';
Expand Down Expand Up @@ -149,7 +153,7 @@ class GrepToolInvocation extends BaseToolInvocation<
return 'allow'; // Default workspace directory
}
const workspaceContext = this.config.getWorkspaceContext();
const resolvedPath = path.resolve(
const resolvedPath = resolvePath(
this.config.getTargetDir(),
this.params.path,
);
Expand Down
Loading