Skip to content

Commit a1609e1

Browse files
twishabansalhelloevegemini-code-assist[bot]
authored
feat(skills): add Claude Code support to generated scripts (#2966)
## Description Note: We do not yet support binary invocations for claude code. Claude code skills will be packaged with npx for now. ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [ ] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #<issue_number_goes_here> --------- Co-authored-by: Haoyu Wang <whaoyu@google.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 4655bcd commit a1609e1

2 files changed

Lines changed: 49 additions & 26 deletions

File tree

cmd/internal/skills/generator.go

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,42 +135,53 @@ const OPTIONAL_VARS_TO_OMIT_IF_EMPTY = [
135135
{{end}}
136136
137137
function mergeEnvVars(env) {
138-
const envPath = path.resolve(__dirname, '../../../.env');
139-
if (fs.existsSync(envPath)) {
138+
if (process.env.GEMINI_CLI === '1') {
139+
const envPath = path.resolve(__dirname, '../../../.env');
140+
if (fs.existsSync(envPath)) {
140141
const envContent = fs.readFileSync(envPath, 'utf-8');
141142
envContent.split('\n').forEach(line => {
142-
const trimmed = line.trim();
143-
if (trimmed && !trimmed.startsWith('#')) {
144-
const splitIdx = trimmed.indexOf('=');
145-
if (splitIdx !== -1) {
146-
const key = trimmed.slice(0, splitIdx).trim();
147-
let value = trimmed.slice(splitIdx + 1).trim();
148-
value = value.replace(/(^['"]|['"]$)/g, '');
149-
if (env[key] === undefined) {
150-
env[key] = value;
151-
}
152-
}
143+
const trimmed = line.trim();
144+
if (trimmed && !trimmed.startsWith('#')) {
145+
const splitIdx = trimmed.indexOf('=');
146+
if (splitIdx !== -1) {
147+
const key = trimmed.slice(0, splitIdx).trim();
148+
let value = trimmed.slice(splitIdx + 1).trim();
149+
value = value.replace(/(^['"]|['"]$)/g, '');
150+
if (env[key] === undefined) {
151+
env[key] = value;
152+
}
153153
}
154+
}
154155
});
156+
}
157+
} else if (process.env.CLAUDECODE === '1') {
158+
const prefix = 'CLAUDE_PLUGIN_OPTION_';
159+
for (const key in process.env) {
160+
if (key.startsWith(prefix)) {
161+
env[key.substring(prefix.length)] = process.env[key];
162+
}
163+
}
155164
}
156165
}
157166
158167
function prepareEnvironment() {
159-
let env = { ...process.env };
160-
let userAgent = "skills";
161-
if (process.env.GEMINI_CLI === '1') {
162-
userAgent = "skills-geminicli";
163-
mergeEnvVars(env);
168+
let env = { ...process.env };
169+
let userAgent = "skills";
170+
if (process.env.GEMINI_CLI === '1') {
171+
userAgent = "skills-geminicli";
172+
} else if (process.env.CLAUDECODE === '1') {
173+
userAgent = "skills-claudecode";
174+
}
175+
mergeEnvVars(env);
176+
{{if .OptionalVars}}
177+
OPTIONAL_VARS_TO_OMIT_IF_EMPTY.forEach(varName => {
178+
if (env[varName] === '') {
179+
delete env[varName];
164180
}
165-
{{if .OptionalVars}}
166-
OPTIONAL_VARS_TO_OMIT_IF_EMPTY.forEach(varName => {
167-
if (env[varName] === '') {
168-
delete env[varName];
169-
}
170-
});
171-
{{end}}
181+
});
182+
{{end}}
172183
173-
return { env, userAgent };
184+
return { env, userAgent };
174185
}
175186
176187
function main() {

cmd/internal/skills/generator_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,18 @@ func TestGenerateScriptContent(t *testing.T) {
285285
`const npxArgs = ["--yes", "@toolbox-sdk/server@0.31.0"`,
286286
},
287287
},
288+
{
289+
name: "claude code script",
290+
toolName: "claude-tool",
291+
configArgs: `"--prebuilt", "test"`,
292+
mode: "bin",
293+
wantContains: []string{
294+
`userAgent = "skills-claudecode";`,
295+
`const prefix = 'CLAUDE_PLUGIN_OPTION_';`,
296+
`if (key.startsWith(prefix)) {`,
297+
`env[key.substring(prefix.length)] = process.env[key];`,
298+
},
299+
},
288300
}
289301

290302
for _, tt := range tests {

0 commit comments

Comments
 (0)