claude-code-templates 1.24.6 → 1.24.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@
4
4
  * Executes Claude Code prompts using Cloudflare Workers and Sandbox SDK
5
5
  */
6
6
 
7
- import Anthropic from '@anthropic-ai/sdk';
7
+ import { query, ClaudeAgentOptions } from '@anthropic-ai/claude-agent-sdk';
8
8
  import fetch from 'node-fetch';
9
9
  import * as fs from 'fs';
10
10
  import * as path from 'path';
@@ -192,41 +192,19 @@ async function executeViaWorker(
192
192
  }
193
193
 
194
194
  async function executeDirectly(config: LauncherConfig): Promise<ExecutionResult> {
195
- log('Executing directly using Anthropic SDK...');
195
+ log('Executing with Claude Agent SDK...');
196
196
 
197
- const anthropic = new Anthropic({
198
- apiKey: config.anthropicApiKey,
199
- });
200
-
201
- // Build enhanced prompt with component context
202
- let enhancedPrompt = config.prompt;
203
-
204
- if (config.componentsToInstall) {
205
- const agents = extractAgents(config.componentsToInstall);
206
- if (agents.length > 0) {
207
- enhancedPrompt = `You are Claude Code, an AI assistant specialized in software development.
208
-
209
- IMPORTANT INSTRUCTIONS:
210
- 1. Execute the user's request immediately and create the requested code/files
211
- 2. You have access to the following specialized agents: ${agents.join(', ')}
212
- 3. Use these agents appropriately for completing the task
213
- 4. Generate all necessary files and code to fulfill the request
214
- 5. Be proactive and create a complete, working implementation
215
-
216
- USER REQUEST: ${config.prompt}
217
-
218
- Now, please execute this request and provide the code.`;
219
- }
220
- }
197
+ // Extract agent names for context
198
+ const agents = config.componentsToInstall ? extractAgents(config.componentsToInstall) : [];
221
199
 
222
200
  try {
223
- log('Generating code with Claude Sonnet 4.5...');
201
+ log('Generating code with Claude Agent SDK...');
224
202
 
225
203
  // Detect if this is a web development request
226
- const isWebRequest = /html|css|javascript|webpage|website|form|ui|interface|frontend/i.test(enhancedPrompt);
204
+ const isWebRequest = /html|css|javascript|webpage|website|form|ui|interface|frontend/i.test(config.prompt);
227
205
 
228
206
  const promptContent = isWebRequest
229
- ? `Create a complete web application for: "${enhancedPrompt}"
207
+ ? `Create a complete web application for: "${config.prompt}"
230
208
 
231
209
  IMPORTANT FORMAT REQUIREMENTS:
232
210
  - Provide complete, working code for ALL files needed
@@ -251,34 +229,36 @@ Requirements:
251
229
  - Add proper comments
252
230
  - Ensure code is ready to run
253
231
  - Do NOT include any explanations, ONLY code blocks with filenames`
254
- : `Generate Python code to answer: "${enhancedPrompt}"
232
+ : config.prompt;
255
233
 
256
- Requirements:
257
- - Use only Python standard library
258
- - Print the result using print()
259
- - Keep code simple and safe
260
- - Include proper error handling
261
-
262
- Return ONLY the code, no explanations.`;
263
-
264
- const codeGeneration = await anthropic.messages.create({
234
+ // Configure Claude Agent SDK options
235
+ const options: ClaudeAgentOptions = {
265
236
  model: 'claude-sonnet-4-5',
266
- max_tokens: 4096,
267
- messages: [
268
- {
269
- role: 'user',
270
- content: promptContent,
271
- },
272
- ],
273
- });
237
+ apiKey: config.anthropicApiKey,
238
+ // Use Claude Code preset to get proper coding behavior
239
+ systemPrompt: { type: 'preset', preset: 'claude_code' },
240
+ // Load project settings to use agents and components
241
+ settingSources: ['project'],
242
+ };
274
243
 
275
- const generatedCode =
276
- codeGeneration.content[0]?.type === 'text'
277
- ? codeGeneration.content[0].text
278
- : '';
244
+ // Collect the full response
245
+ let generatedCode = '';
246
+
247
+ try {
248
+ for await (const message of query({ prompt: promptContent, options })) {
249
+ if (message.type === 'text') {
250
+ generatedCode += message.text;
251
+ }
252
+ }
253
+ } catch (queryError) {
254
+ const err = queryError as Error;
255
+ log(`Query error: ${err.message}`, 'error');
256
+ log(`Stack: ${err.stack}`, 'error');
257
+ throw new Error(`Claude Agent SDK query failed: ${err.message}`);
258
+ }
279
259
 
280
260
  if (!generatedCode) {
281
- throw new Error('Failed to generate code from Claude');
261
+ throw new Error('Failed to generate code from Claude Agent SDK (empty response)');
282
262
  }
283
263
 
284
264
  log('Code generated successfully', 'success');
@@ -315,6 +295,65 @@ function extractAgents(componentsString: string): string[] {
315
295
  return agents;
316
296
  }
317
297
 
298
+ async function installAgents(agents: string[]): Promise<void> {
299
+ if (agents.length === 0) {
300
+ return;
301
+ }
302
+
303
+ log(`Installing ${agents.length} agent(s)...`);
304
+
305
+ // Create .claude/agents directory
306
+ const claudeDir = path.join(process.cwd(), '.claude');
307
+ const agentsDir = path.join(claudeDir, 'agents');
308
+
309
+ if (!fs.existsSync(agentsDir)) {
310
+ fs.mkdirSync(agentsDir, { recursive: true });
311
+ }
312
+
313
+ // Download each agent from GitHub
314
+ const GITHUB_RAW_BASE = 'https://raw.githubusercontent.com/davila7/claude-code-templates/main/cli-tool/components/agents';
315
+
316
+ for (const agent of agents) {
317
+ try {
318
+ log(`Downloading agent: ${agent}...`);
319
+
320
+ // Construct the GitHub URL for the agent
321
+ const agentUrl = `${GITHUB_RAW_BASE}/${agent}.md`;
322
+
323
+ // Download the agent file
324
+ const response = await fetch(agentUrl);
325
+
326
+ if (!response.ok) {
327
+ log(`Failed to download agent ${agent}: ${response.statusText}`, 'warning');
328
+ continue;
329
+ }
330
+
331
+ const agentContent = await response.text();
332
+
333
+ // Save to .claude/agents/
334
+ const agentFileName = agent.replace(/\//g, '-') + '.md';
335
+ const agentPath = path.join(agentsDir, agentFileName);
336
+
337
+ fs.writeFileSync(agentPath, agentContent, 'utf-8');
338
+ log(`Installed agent: ${agent}`, 'success');
339
+ } catch (error) {
340
+ log(`Error installing agent ${agent}: ${error instanceof Error ? error.message : String(error)}`, 'warning');
341
+ }
342
+ }
343
+
344
+ // Create settings.json to reference the agents
345
+ const settingsPath = path.join(claudeDir, 'settings.json');
346
+ const settings = {
347
+ agents: agents.map(agent => ({
348
+ name: agent.split('/').pop() || agent,
349
+ path: `.claude/agents/${agent.replace(/\//g, '-')}.md`
350
+ }))
351
+ };
352
+
353
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf-8');
354
+ log('Created .claude/settings.json', 'success');
355
+ }
356
+
318
357
  function displayResults(result: ExecutionResult, targetDir?: string) {
319
358
  console.log('');
320
359
  printSeparator();
@@ -418,6 +457,10 @@ async function main() {
418
457
  const agents = extractAgents(config.componentsToInstall);
419
458
  if (agents.length > 0) {
420
459
  log(`Agents: ${agents.join(', ')}`);
460
+
461
+ // Install agents before execution
462
+ console.log('');
463
+ await installAgents(agents);
421
464
  }
422
465
  }
423
466
 
@@ -17,7 +17,7 @@
17
17
  "format:check": "prettier --check ."
18
18
  },
19
19
  "dependencies": {
20
- "@anthropic-ai/sdk": "^0.20.0",
20
+ "@anthropic-ai/claude-agent-sdk": "^0.1.0",
21
21
  "@cloudflare/sandbox": "^0.1.0",
22
22
  "node-fetch": "^3.3.2"
23
23
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-templates",
3
- "version": "1.24.6",
3
+ "version": "1.24.8",
4
4
  "description": "CLI tool to setup Claude Code configurations with framework-specific commands, automation hooks and MCP Servers for your projects",
5
5
  "main": "src/index.js",
6
6
  "bin": {