feat(sdk): initial package bootstrap for SDK#18861
Conversation
|
Hi @mbleigh, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
|
Hi there! Thank you for your contribution to Gemini CLI. To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md. This pull request is being closed because it is not currently linked to an issue. Once you have updated the description of this PR to link an issue (e.g., by adding How to link an issue: Thank you for your understanding and for being a part of our community! |
Summary of ChangesHello @mbleigh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request establishes the foundational structure for a new SDK package, Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new SDK package with an initial structure, including GeminiCliAgent and tool definition helpers. However, a security audit identified two high-severity prompt injection vulnerabilities in packages/sdk/src/agent.ts, which could lead to manipulation of the language model. Additionally, there's a major bug in agent.ts causing crashes with JSON string tool arguments, and the sendStream method and tool action functions lack support for cancellation via AbortSignal. Addressing these security and functional issues is crucial for the robustness and usability of the new SDK.
|
Size Change: +122 B (0%) Total Size: 24.4 MB ℹ️ View Unchanged
|
|
I've fixed the issue with JSON string tool arguments by parsing them if they are strings. I've also added a TODO to support AbortSignal cancellation properly in a future PR. Regarding prompt injection warnings, since this is an SDK designed to execute user prompts, these are expected and I'm proceeding without changes for those. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new SDK package, @google/gemini-cli-sdk, providing a public API for interacting with the Gemini CLI's core agent. A critical security vulnerability was identified in the agent's tool execution loop, as the implementation bypasses the core library's security policy engine and user confirmation, potentially allowing unauthorized tool execution via prompt injection. This must be addressed before the SDK is used for sensitive tasks. Furthermore, the usage example in the README is incorrect, and the sendStream method does not support cancellation via an AbortSignal.
|
/gemini review |
…emove placeholder README
There was a problem hiding this comment.
Code Review
This pull request introduces a new SDK package with an initial structure, including an agent, tool definitions, and example usage. The setup is generally good, but there are a few critical issues to address. The README contains an incorrect usage example which will be confusing for new users. Additionally, the implementation for tool cancellation is incomplete, as AbortSignal is not properly propagated and handled, which violates a general repository rule for cancellable async operations and could lead to dangling processes. Finally, there's an unsafe type assertion in the agent implementation that bypasses TypeScript's type safety and violates the project's linting rules.
I am having trouble creating individual review comments. Click here to see my feedback.
packages/sdk/README.md (14-16)
The usage example in the README refers to a function helloSdk which does not seem to be exported by the SDK. This will confuse users trying to get started with the package. The example should be updated to use the actual exported members like GeminiCliAgent.
import { GeminiCliAgent } from '@google/gemini-cli-sdk';
async function main() {
const agent = new GeminiCliAgent({
instructions: 'You are a helpful assistant.',
});
for await (const chunk of agent.sendStream('Why is the sky blue?')) {
if (chunk.type === 'text') {
process.stdout.write(chunk.value.text);
}
}
}
main().catch(console.error);
packages/sdk/src/agent.ts (82-83)
The AbortSignal is created but not passed down to the tool execution logic, as noted by the TODO. This means long-running tools cannot be cancelled, which can lead to dangling processes. This violates a general rule for the repository regarding cancellable async operations.
The signal should be passed to invocation.execute() on line 125. This will also require updating the action signature in packages/sdk/src/tool.ts to accept and handle the signal.
References
- Asynchronous operations that can be cancelled by the user should accept and propagate an
AbortSignalto ensure cancellability and prevent dangling processes or network requests.
packages/sdk/src/agent.ts (144-147)
Using as unknown as ... is an unsafe type assertion that bypasses TypeScript's type checking. This can lead to runtime errors if the shape of functionResponses is not what sendMessageStream expects. This also violates the project's linting rules which disallow unsafe assertions in product code.
Please define a more specific type for functionResponses and use a single, more specific type assertion if necessary, or align the types to avoid assertions altogether.
packages/sdk/src/tool.ts (47-50)
The _signal parameter is ignored in the execute method. This means that if the action is a long-running asynchronous operation, it cannot be cancelled. The AbortSignal should be passed to the action function so it can listen for cancellation events.
This will also require updating the Tool interface and the tool helper function to accept the AbortSignal in the action signature, and then using it in the execute method: const result = await this.action(this.params, signal);
async execute(
signal: AbortSignal,
_updateOutput?: (output: string) => void,
): Promise<ToolResult> {
References
- Asynchronous operations that can be cancelled by the user should accept and propagate an
AbortSignalto ensure cancellability and prevent dangling processes or network requests.
|
Hi there! Thank you for your contribution to Gemini CLI. To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md. This pull request is being closed because it is not currently linked to an issue. Once you have updated the description of this PR to link an issue (e.g., by adding How to link an issue: Thank you for your understanding and for being a part of our community! |
packages/sdk/src/agent.ts
Outdated
| } | ||
|
|
||
| export class GeminiCliAgent { | ||
| private config: Config; |
There was a problem hiding this comment.
Should mark this and tools as readonly
Replaces custom tool execution loop with scheduleAgentTools to align with CLI behavior, support hooks/policy, and ensure consistent error handling. Adds AbortSignal support to sendStream and updates README example.
|
Hi there! Thank you for your contribution to Gemini CLI. To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md. This pull request is being closed because it is not currently linked to an issue. Once you have updated the description of this PR to link an issue (e.g., by adding How to link an issue: Thank you for your understanding and for being a part of our community! |
Aligns GeminiCliAgent with CLI behavior by using scheduleAgentTools for tool execution. Unifies authentication detection logic by moving getAuthTypeFromEnv from CLI to Core, ensuring exact behavior parity. SDK falls back to COMPUTE_ADC if env vars are unset. Addresses PR #18861 feedback.
…i into sdk-01-bootstrap
…i into sdk-01-bootstrap
…i into sdk-01-bootstrap
Initial structure for the SDK package.