-
Notifications
You must be signed in to change notification settings - Fork 1
fix: migrate SDK Pi integration for v0.68.1 #1402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { AgentDefinition } from './protocol.ts'; | ||
|
|
||
| const READ_ONLY_TOOL_NAMES = ['read', 'grep', 'find', 'ls'] as const; | ||
| const CODING_TOOL_NAMES = ['read', 'bash', 'edit', 'write'] as const; | ||
|
|
||
| function normalizeToolName(name: string): string { | ||
| return name.trim().toLowerCase(); | ||
| } | ||
|
|
||
| export function selectSubAgentToolNames(agentConfig: AgentDefinition): string[] { | ||
| const declared = new Set( | ||
| (agentConfig.tools ?? []) | ||
| .filter((name): name is string => typeof name === 'string' && name.trim().length > 0) | ||
| .map(normalizeToolName) | ||
| ); | ||
| const needsBash = declared.has('bash'); | ||
| const baseToolNames = | ||
| agentConfig.readOnly && !needsBash ? READ_ONLY_TOOL_NAMES : CODING_TOOL_NAMES; | ||
| const allowLegacyFallback = | ||
| agentConfig.strictToolSelection !== true && agentConfig.source === 'builtin'; | ||
|
|
||
| if (declared.size === 0) { | ||
| return allowLegacyFallback ? [...baseToolNames] : []; | ||
| } | ||
|
|
||
| const filtered = baseToolNames.filter((toolName) => declared.has(toolName)); | ||
|
|
||
| if (filtered.length > 0) { | ||
| return filtered; | ||
| } | ||
|
|
||
| return allowLegacyFallback ? [...baseToolNames] : []; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { describe, expect, it } from 'bun:test'; | ||
| import type { AgentDefinition } from '../src/protocol.ts'; | ||
| import { selectSubAgentToolNames } from '../src/subagent-tool-selection.ts'; | ||
|
rblalock marked this conversation as resolved.
|
||
|
|
||
| function createAgent(overrides?: Partial<AgentDefinition>): AgentDefinition { | ||
| return { | ||
| name: 'runner', | ||
| source: 'builtin', | ||
| description: 'test', | ||
| systemPrompt: 'test', | ||
| tools: ['read', 'grep', 'find', 'ls'], | ||
| readOnly: true, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe('selectSubAgentToolNames', () => { | ||
| it('uses the read-only baseline for read-only agents without bash', () => { | ||
| expect(selectSubAgentToolNames(createAgent())).toEqual(['read', 'grep', 'find', 'ls']); | ||
| }); | ||
|
|
||
| it('switches to the coding baseline when a read-only agent declares bash', () => { | ||
| expect( | ||
| selectSubAgentToolNames(createAgent({ tools: ['read', 'bash', 'ls'], readOnly: true })) | ||
| ).toEqual(['read', 'bash']); | ||
| }); | ||
|
|
||
| it('keeps the legacy fallback for non-strict agents when declarations do not match', () => { | ||
| expect(selectSubAgentToolNames(createAgent({ tools: ['totally_unknown_tool'] }))).toEqual([ | ||
| 'read', | ||
| 'grep', | ||
| 'find', | ||
| 'ls', | ||
| ]); | ||
| }); | ||
|
|
||
| it('keeps custom agents deny-by-default when declarations do not match', () => { | ||
| expect( | ||
| selectSubAgentToolNames( | ||
| createAgent({ | ||
| name: 'qa-review', | ||
| source: 'custom', | ||
| tools: ['totally_unknown_tool'], | ||
| }) | ||
| ) | ||
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it('does not widen tool access for strict custom agents when names do not match', () => { | ||
| expect( | ||
| selectSubAgentToolNames( | ||
| createAgent({ | ||
| name: 'code-review', | ||
| source: 'custom', | ||
| tools: ['totally_unknown_tool'], | ||
| strictToolSelection: true, | ||
| }) | ||
| ) | ||
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it('returns the coding baseline for non-read-only agents without declared Pi tools', () => { | ||
| expect( | ||
| selectSubAgentToolNames( | ||
| createAgent({ | ||
| readOnly: false, | ||
| tools: undefined, | ||
| }) | ||
| ) | ||
| ).toEqual(['read', 'bash', 'edit', 'write']); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.