claude-code-templates 1.24.6 → 1.24.7

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,29 @@ 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
+ for await (const message of query({ prompt: promptContent, options })) {
248
+ if (message.type === 'text') {
249
+ generatedCode += message.text;
250
+ }
251
+ }
279
252
 
280
253
  if (!generatedCode) {
281
- throw new Error('Failed to generate code from Claude');
254
+ throw new Error('Failed to generate code from Claude Agent SDK');
282
255
  }
283
256
 
284
257
  log('Code generated successfully', 'success');
@@ -315,6 +288,65 @@ function extractAgents(componentsString: string): string[] {
315
288
  return agents;
316
289
  }
317
290
 
291
+ async function installAgents(agents: string[]): Promise<void> {
292
+ if (agents.length === 0) {
293
+ return;
294
+ }
295
+
296
+ log(`Installing ${agents.length} agent(s)...`);
297
+
298
+ // Create .claude/agents directory
299
+ const claudeDir = path.join(process.cwd(), '.claude');
300
+ const agentsDir = path.join(claudeDir, 'agents');
301
+
302
+ if (!fs.existsSync(agentsDir)) {
303
+ fs.mkdirSync(agentsDir, { recursive: true });
304
+ }
305
+
306
+ // Download each agent from GitHub
307
+ const GITHUB_RAW_BASE = 'https://raw.githubusercontent.com/davila7/claude-code-templates/main/cli-tool/components/agents';
308
+
309
+ for (const agent of agents) {
310
+ try {
311
+ log(`Downloading agent: ${agent}...`);
312
+
313
+ // Construct the GitHub URL for the agent
314
+ const agentUrl = `${GITHUB_RAW_BASE}/${agent}.md`;
315
+
316
+ // Download the agent file
317
+ const response = await fetch(agentUrl);
318
+
319
+ if (!response.ok) {
320
+ log(`Failed to download agent ${agent}: ${response.statusText}`, 'warning');
321
+ continue;
322
+ }
323
+
324
+ const agentContent = await response.text();
325
+
326
+ // Save to .claude/agents/
327
+ const agentFileName = agent.replace(/\//g, '-') + '.md';
328
+ const agentPath = path.join(agentsDir, agentFileName);
329
+
330
+ fs.writeFileSync(agentPath, agentContent, 'utf-8');
331
+ log(`Installed agent: ${agent}`, 'success');
332
+ } catch (error) {
333
+ log(`Error installing agent ${agent}: ${error instanceof Error ? error.message : String(error)}`, 'warning');
334
+ }
335
+ }
336
+
337
+ // Create settings.json to reference the agents
338
+ const settingsPath = path.join(claudeDir, 'settings.json');
339
+ const settings = {
340
+ agents: agents.map(agent => ({
341
+ name: agent.split('/').pop() || agent,
342
+ path: `.claude/agents/${agent.replace(/\//g, '-')}.md`
343
+ }))
344
+ };
345
+
346
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf-8');
347
+ log('Created .claude/settings.json', 'success');
348
+ }
349
+
318
350
  function displayResults(result: ExecutionResult, targetDir?: string) {
319
351
  console.log('');
320
352
  printSeparator();
@@ -418,6 +450,10 @@ async function main() {
418
450
  const agents = extractAgents(config.componentsToInstall);
419
451
  if (agents.length > 0) {
420
452
  log(`Agents: ${agents.join(', ')}`);
453
+
454
+ // Install agents before execution
455
+ console.log('');
456
+ await installAgents(agents);
421
457
  }
422
458
  }
423
459
 
@@ -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.7",
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": {