@agentskit/cli 0.7.0 → 0.8.2

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.
package/README.md CHANGED
@@ -4,8 +4,8 @@ Chat with any LLM, scaffold projects, and run agents — all from your terminal.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@agentskit/cli?color=blue)](https://www.npmjs.com/package/@agentskit/cli)
6
6
  [![npm downloads](https://img.shields.io/npm/dm/@agentskit/cli)](https://www.npmjs.com/package/@agentskit/cli)
7
- [![bundle size](https://img.shields.io/bundlephobia/minzip/@agentskit/cli)](https://bundlephobia.com/package/@agentskit/cli)
8
- [![license](https://img.shields.io/npm/l/@agentskit/cli)](../../LICENSE)
7
+ [![bundle size](https://img.shields.io/bundlejs/size/@agentskit/cli?label=bundle)](https://bundlejs.com/?q=@agentskit/cli)
8
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](../../LICENSE)
9
9
  [![stability](https://img.shields.io/badge/stability-stable-brightgreen)](../../docs/STABILITY.md)
10
10
  [![GitHub stars](https://img.shields.io/github/stars/AgentsKit-io/agentskit?style=social)](https://github.com/AgentsKit-io/agentskit)
11
11
 
package/dist/bin.cjs CHANGED
@@ -22,6 +22,7 @@ var prompts = require('@inquirer/prompts');
22
22
  var kleur = require('kleur');
23
23
  var chokidar = require('chokidar');
24
24
  var rag = require('@agentskit/rag');
25
+ var agentSchema = require('@agentskit/core/agent-schema');
25
26
 
26
27
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
27
28
 
@@ -2951,6 +2952,187 @@ function registerRagCommand(program) {
2951
2952
  });
2952
2953
  }
2953
2954
 
2955
+ // src/ai/scaffold.ts
2956
+ function snakeToCamel(name) {
2957
+ return name.replace(/[-_](\w)/g, (_, c) => c.toUpperCase());
2958
+ }
2959
+ function toolStub(tool) {
2960
+ const fnName = snakeToCamel(tool.name);
2961
+ const schema = tool.schema ? JSON.stringify(tool.schema, null, 2) : '{ type: "object", properties: {} }';
2962
+ return `import { defineTool } from '@agentskit/core'
2963
+
2964
+ /**
2965
+ * ${tool.description ?? tool.name}
2966
+ * ${tool.implementation ? `
2967
+ * Implementation hint: ${tool.implementation}` : ""}
2968
+ */
2969
+ export const ${fnName} = defineTool({
2970
+ name: '${tool.name}',
2971
+ description: ${JSON.stringify(tool.description ?? "")},
2972
+ schema: ${schema} as const,
2973
+ ${tool.requiresConfirmation ? "requiresConfirmation: true," : ""}
2974
+ async execute(args) {
2975
+ // TODO: implement ${tool.name}
2976
+ return { args }
2977
+ },
2978
+ })
2979
+ `;
2980
+ }
2981
+ function indexTs(schema) {
2982
+ const toolImports2 = (schema.tools ?? []).map((t) => `import { ${snakeToCamel(t.name)} } from './tools/${t.name}'`).join("\n");
2983
+ const toolList2 = (schema.tools ?? []).map((t) => snakeToCamel(t.name)).join(", ");
2984
+ return `import { createRuntime } from '@agentskit/runtime'
2985
+ ${toolImports2}
2986
+
2987
+ export const agent = {
2988
+ name: '${schema.name}',
2989
+ systemPrompt: ${JSON.stringify(schema.systemPrompt ?? "")},
2990
+ tools: [${toolList2}],
2991
+ }
2992
+
2993
+ export function createAgent(adapter: Parameters<typeof createRuntime>[0]['adapter']) {
2994
+ return createRuntime({
2995
+ adapter,
2996
+ systemPrompt: agent.systemPrompt,
2997
+ tools: agent.tools,
2998
+ })
2999
+ }
3000
+ `;
3001
+ }
3002
+ function readme(schema) {
3003
+ const lines = [];
3004
+ lines.push(`# ${schema.name}`);
3005
+ lines.push("");
3006
+ if (schema.description) lines.push(schema.description, "");
3007
+ lines.push(`## Model`);
3008
+ lines.push("");
3009
+ lines.push(`- Provider: \`${schema.model.provider}\``);
3010
+ if (schema.model.model) lines.push(`- Model: \`${schema.model.model}\``);
3011
+ lines.push("");
3012
+ if (schema.tools && schema.tools.length > 0) {
3013
+ lines.push("## Tools");
3014
+ lines.push("");
3015
+ for (const t of schema.tools) {
3016
+ lines.push(`- \`${t.name}\` \u2014 ${t.description ?? ""}`);
3017
+ }
3018
+ lines.push("");
3019
+ }
3020
+ if (schema.skills && schema.skills.length > 0) {
3021
+ lines.push("## Skills");
3022
+ lines.push("");
3023
+ for (const s of schema.skills) lines.push(`- ${s}`);
3024
+ lines.push("");
3025
+ }
3026
+ lines.push("## Generated by");
3027
+ lines.push("");
3028
+ lines.push('`npx agentskit ai "<description>"`');
3029
+ lines.push("");
3030
+ return lines.join("\n");
3031
+ }
3032
+ function scaffoldAgent(schema) {
3033
+ const files = [
3034
+ { path: "agent.json", content: JSON.stringify(schema, null, 2) + "\n" },
3035
+ { path: "agent.ts", content: indexTs(schema) },
3036
+ { path: "README.md", content: readme(schema) }
3037
+ ];
3038
+ for (const tool of schema.tools ?? []) {
3039
+ files.push({ path: `tools/${tool.name}.ts`, content: toolStub(tool) });
3040
+ }
3041
+ return files;
3042
+ }
3043
+ async function writeScaffold(files, outDir, opts = {}) {
3044
+ const { writeFile: writeFile2, mkdir: mkdir2, access } = await import('fs/promises');
3045
+ const { dirname, join: join5 } = await import('path');
3046
+ const written = [];
3047
+ for (const f of files) {
3048
+ const full = join5(outDir, f.path);
3049
+ await mkdir2(dirname(full), { recursive: true });
3050
+ if (!opts.overwrite) {
3051
+ try {
3052
+ await access(full);
3053
+ continue;
3054
+ } catch {
3055
+ }
3056
+ }
3057
+ await writeFile2(full, f.content, "utf8");
3058
+ written.push(f.path);
3059
+ }
3060
+ return written;
3061
+ }
3062
+ var PLANNER_SYSTEM_PROMPT = `You design AI agents for the AgentsKit framework.
3063
+ Given a user's plain-language description, return a single JSON object
3064
+ matching the AgentsKit AgentSchema type. Do not include commentary or
3065
+ markdown fences \u2014 emit raw JSON only.
3066
+
3067
+ Schema:
3068
+ {
3069
+ "name": "kebab-or-snake-case",
3070
+ "description": "short summary",
3071
+ "systemPrompt": "you are...",
3072
+ "model": { "provider": "anthropic"|"openai"|"gemini"|..., "model": "..." },
3073
+ "tools": [{ "name": "search", "description": "...", "schema": {...}, "implementation": "fetch('/api/search?q=...')" }],
3074
+ "memory": { "kind": "inMemory"|"localStorage", "key": "..." },
3075
+ "skills": ["researcher", "critic"]
3076
+ }
3077
+
3078
+ Prefer fewer well-scoped tools over many overlapping ones. Name tools
3079
+ in snake_case.`;
3080
+ function extractJson(text) {
3081
+ const fenced = text.match(/```(?:json)?\s*([\s\S]+?)```/);
3082
+ const raw = fenced?.[1] ?? text;
3083
+ const start = raw.indexOf("{");
3084
+ const end = raw.lastIndexOf("}");
3085
+ if (start < 0 || end <= start) throw new Error("Planner response did not contain a JSON object");
3086
+ return raw.slice(start, end + 1);
3087
+ }
3088
+ function createAdapterPlanner(adapter) {
3089
+ return async (description) => {
3090
+ const messages = [
3091
+ { id: "sys", role: "system", content: PLANNER_SYSTEM_PROMPT, status: "complete", createdAt: /* @__PURE__ */ new Date(0) },
3092
+ { id: "user", role: "user", content: description, status: "complete", createdAt: /* @__PURE__ */ new Date(0) }
3093
+ ];
3094
+ const request = { messages, context: { temperature: 0 } };
3095
+ const source = adapter.createSource(request);
3096
+ let text = "";
3097
+ for await (const chunk of source.stream()) {
3098
+ if (chunk.type === "text" && chunk.content) text += chunk.content;
3099
+ }
3100
+ const json = extractJson(text);
3101
+ return agentSchema.validateAgentSchema(JSON.parse(json));
3102
+ };
3103
+ }
3104
+
3105
+ // src/commands/ai.ts
3106
+ function registerAiCommand(program) {
3107
+ program.command("ai <description...>").description("Generate an agent (config + tools + skill wiring) from a natural-language description.").option("-o, --out <dir>", "Output directory", "./my-agent").option("--provider <provider>", "Planner provider (openai | anthropic | ...)", "anthropic").option("--model <model>", "Planner model id").option("--api-key <key>", "API key (falls back to env)").option("--base-url <url>", "Override base URL (for OpenAI-compatible endpoints)").option("--overwrite", "Overwrite existing files", false).option("--dry-run", "Print the plan + files without writing", false).action(async (descriptionWords, options) => {
3108
+ const description = descriptionWords.join(" ").trim();
3109
+ if (!description) {
3110
+ process.stderr.write("agentskit ai: missing description.\n");
3111
+ process.exit(1);
3112
+ }
3113
+ const resolved = resolveChatProvider({
3114
+ provider: options.provider,
3115
+ model: options.model,
3116
+ apiKey: options.apiKey,
3117
+ baseUrl: options.baseUrl
3118
+ });
3119
+ const planner2 = createAdapterPlanner(resolved.adapter);
3120
+ process.stderr.write(`Planning agent for: "${description}"
3121
+ `);
3122
+ const schema = await planner2(description);
3123
+ const files = scaffoldAgent(schema);
3124
+ if (options.dryRun) {
3125
+ process.stdout.write(JSON.stringify({ schema, files: files.map((f) => f.path) }, null, 2) + "\n");
3126
+ return;
3127
+ }
3128
+ const written = await writeScaffold(files, options.out, { overwrite: options.overwrite });
3129
+ process.stderr.write(`Wrote ${written.length} file(s) to ${options.out}
3130
+ `);
3131
+ for (const f of written) process.stderr.write(` + ${f}
3132
+ `);
3133
+ });
3134
+ }
3135
+
2954
3136
  // src/commands/index.ts
2955
3137
  function createCli() {
2956
3138
  const program = new commander.Command();
@@ -2963,6 +3145,7 @@ function createCli() {
2963
3145
  registerConfigCommand(program);
2964
3146
  registerTunnelCommand(program);
2965
3147
  registerRagCommand(program);
3148
+ registerAiCommand(program);
2966
3149
  return program;
2967
3150
  }
2968
3151