Skip to content

feat(skill): tool invocation via npx#2916

Draft
helloeve wants to merge 1 commit intomainfrom
skill-npx
Draft

feat(skill): tool invocation via npx#2916
helloeve wants to merge 1 commit intomainfrom
skill-npx

Conversation

@helloeve
Copy link
Copy Markdown
Contributor

@helloeve helloeve commented Apr 1, 2026

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the skill generator template to invoke tools via npx @toolbox-sdk/server instead of a local binary and adds a custom execution path for Windows. Feedback includes removing the now-unused execSync import, addressing the regression in local development support, and replacing the fragile Windows bypass logic with the standard shell: true option in spawn for better reliability.

@@ -124,37 +124,11 @@ const nodeScriptTemplate = `#!/usr/bin/env node
const { spawn, execSync } = require('child_process');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

execSync is no longer used in the script template after the removal of the getToolboxPath function. It should be removed from the require statement to keep the script clean.

Suggested change
const { spawn, execSync } = require('child_process');
const { spawn } = require('child_process');

}

const args = process.argv.slice(2);
const npxArgs = ["--yes", "@toolbox-sdk/server", "--log-level", "error", ...configArgs, "invoke", toolName, "--user-agent-metadata", userAgent, ...args];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Switching to npx @toolbox-sdk/server removes the ability to use a local toolbox binary for tool invocation, which was previously supported (especially via the GEMINI_CLI=1 environment variable). This is a regression for developers who want to test local changes to the toolbox without publishing to npm. Consider allowing the package source or version to be configurable, or restoring the logic to check for a local binary first.

Comment on lines +165 to +182
let command = 'npx';
let spawnArgs = npxArgs;

// The Windows Dependency-Free Bypass
if (os.platform() === 'win32') {
const nodeDir = path.dirname(process.execPath);
const npxCliJs = path.join(nodeDir, 'node_modules', 'npm', 'bin', 'npx-cli.js');

if (fs.existsSync(npxCliJs)) {
command = process.execPath;
spawnArgs = [npxCliJs, ...npxArgs];
} else {
console.error("Error: Could not find the npx executable to launch.");
process.exit(1);
}
}

const toolboxArgs = ["--log-level", "error", ...configArgs, "invoke", toolName, "--user-agent-metadata", userAgent, ...args];

const child = spawn(toolboxBinary, toolboxArgs, { stdio: 'inherit', env });
const child = spawn(command, spawnArgs, { stdio: 'inherit', env });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The "Windows Dependency-Free Bypass" logic is fragile as it assumes a specific directory structure for the Node.js installation to find npx-cli.js. This is likely to fail on systems using version managers (like NVM) or non-standard installation paths. A more robust and standard approach for Windows is to invoke npx using the shell: true option, which correctly handles the .cmd extension and path resolution while avoiding fragile path discovery.

Suggested change
let command = 'npx';
let spawnArgs = npxArgs;
// The Windows Dependency-Free Bypass
if (os.platform() === 'win32') {
const nodeDir = path.dirname(process.execPath);
const npxCliJs = path.join(nodeDir, 'node_modules', 'npm', 'bin', 'npx-cli.js');
if (fs.existsSync(npxCliJs)) {
command = process.execPath;
spawnArgs = [npxCliJs, ...npxArgs];
} else {
console.error("Error: Could not find the npx executable to launch.");
process.exit(1);
}
}
const toolboxArgs = ["--log-level", "error", ...configArgs, "invoke", toolName, "--user-agent-metadata", userAgent, ...args];
const child = spawn(toolboxBinary, toolboxArgs, { stdio: 'inherit', env });
const child = spawn(command, spawnArgs, { stdio: 'inherit', env });
const child = spawn('npx', npxArgs, {
stdio: 'inherit',
env,
shell: os.platform() === 'win32'
});

@twishabansal
Copy link
Copy Markdown
Contributor

Testing it for macOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants