@moltium/cli 0.1.19 → 0.1.21

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/dist/index.js CHANGED
@@ -18,6 +18,8 @@ function codeTemplate(ctx) {
18
18
  const envKey = ctx.llmProvider === "anthropic" ? "ANTHROPIC_API_KEY" : "OPENAI_API_KEY";
19
19
  const model = ctx.llmProvider === "anthropic" ? "claude-sonnet-4-20250514" : "gpt-4o";
20
20
  const socialConfig = buildSocialConfig(ctx.socialPlatforms);
21
+ const a2aConfig = ctx.enableA2A !== false ? buildA2AConfig() : "";
22
+ const worldConfig = buildWorldConfig(ctx.connectToWorld, ctx.worldUrl);
21
23
  return `import type { AgentConfig } from '@moltium/core';
22
24
  import { exampleAction } from './actions/example.js';
23
25
 
@@ -40,7 +42,7 @@ export default {
40
42
 
41
43
  social: {${socialConfig}
42
44
  },
43
-
45
+ ${a2aConfig}${worldConfig}
44
46
  behaviors: {
45
47
  autonomous: true,
46
48
  decisionMaking: 'llm-driven',
@@ -100,9 +102,58 @@ function buildSocialConfig(platforms) {
100
102
  maxTweetsPerDay: 5,
101
103
  },`;
102
104
  }
105
+ function buildA2AConfig() {
106
+ return ` // A2A Protocol \u2014 Agent-to-Agent communication
107
+ // Uncomment and configure to enable communication with other agents
108
+ // When enabled, automatically registers 'talk_to_agent' action
109
+ // a2a: {
110
+ // enabled: true,
111
+ // // Define peer agents this agent can talk to
112
+ // peers: {
113
+ // // talk_to_analyst: 'http://localhost:3001',
114
+ // // talk_to_researcher: 'http://localhost:3002',
115
+ // },
116
+ // // Or use a default peer URL
117
+ // // defaultPeerUrl: 'http://localhost:3001',
118
+ // verbose: false,
119
+ // },
120
+
121
+ `;
122
+ }
123
+ function buildWorldConfig(connectToWorld, worldUrl) {
124
+ if (connectToWorld && worldUrl) {
125
+ return ` // World SDK Integration \u2014 connect this agent to a Moltium World
126
+ // The agent will auto-join the world on startup and register world actions:
127
+ // join_world, leave_world, query_world, send_world_message
128
+ world: {
129
+ url: process.env.WORLD_URL || '${worldUrl}',
130
+ autoJoin: true,
131
+ },
132
+
133
+ `;
134
+ }
135
+ return ` // World SDK Integration \u2014 connect this agent to a Moltium World
136
+ // Uncomment to join a world on startup. Automatically registers world actions:
137
+ // join_world, leave_world, query_world, send_world_message
138
+ // world: {
139
+ // url: process.env.WORLD_URL || 'http://localhost:4000',
140
+ // autoJoin: true,
141
+ // },
142
+
143
+ `;
144
+ }
103
145
 
104
146
  // src/templates/code-based/start.ts
105
147
  function codeStartTemplate(ctx) {
148
+ const a2aComment = ctx.enableA2A !== false ? `// A2A Protocol endpoints are enabled by default:
149
+ // - /.well-known/agent-card.json (Agent discovery)
150
+ // - /a2a/jsonrpc (JSON-RPC transport)
151
+ // - /a2a/rest (HTTP+JSON/REST transport)
152
+ // To disable, pass { enableA2A: false } to startServer()` : `// A2A Protocol is disabled
153
+ // To enable, pass { enableA2A: true } to startServer()`;
154
+ const a2aConfig = ctx.enableA2A !== false ? `,
155
+ enableA2A: true, // Enable A2A Protocol endpoints` : `,
156
+ enableA2A: false`;
106
157
  return `import 'dotenv/config';
107
158
  import { Agent, startServer } from '@moltium/core';
108
159
  import config from './agent.config.js';
@@ -118,6 +169,8 @@ import { onShutdown } from './hooks/onShutdown.js';
118
169
  * 2. Wires up lifecycle hooks (onInit, onTick, onShutdown)
119
170
  * 3. Starts the HTTP server with REST endpoints
120
171
  *
172
+ * ${a2aComment}
173
+ *
121
174
  * Run with: npx tsx start.ts
122
175
  * Or: npm start
123
176
  */
@@ -133,7 +186,13 @@ const agent = new Agent(config, {
133
186
 
134
187
  const port = parseInt(process.env.PORT || '3000', 10);
135
188
 
136
- startServer(agent, { port }).catch((err) => {
189
+ startServer(agent, {
190
+ port${a2aConfig},
191
+ a2aConfig: {
192
+ enabled: true,
193
+ baseUrl: \`http://0.0.0.0:\${port}\`,
194
+ },
195
+ }).catch((err) => {
137
196
  console.error('Failed to start agent:', err);
138
197
  process.exit(1);
139
198
  });
@@ -285,6 +344,8 @@ export async function onShutdown(agent: Agent): Promise<void> {
285
344
  // src/templates/markdown-based/index.ts
286
345
  function markdownTemplate(ctx) {
287
346
  const socialSections = buildSocialSections(ctx.socialPlatforms);
347
+ const a2aSection = ctx.enableA2A !== false ? buildA2ASection() : "";
348
+ const worldSection = buildWorldSection(ctx.connectToWorld, ctx.worldUrl);
288
349
  return `# Agent Configuration
289
350
 
290
351
  ## Identity
@@ -299,7 +360,7 @@ detailed trait definitions.
299
360
 
300
361
  ## Social Platforms
301
362
  ${socialSections}
302
-
363
+ ${a2aSection}${worldSection}
303
364
  ## Behaviors
304
365
  autonomous: true
305
366
  decision_making: llm-driven
@@ -372,11 +433,53 @@ Content strategy:
372
433
  - Minimal hashtag use (0-2 per tweet)`);
373
434
  return sections.join("\n\n");
374
435
  }
436
+ function buildA2ASection() {
437
+ return `
438
+ ## A2A Protocol (Agent-to-Agent Communication)
439
+ <!--
440
+ Uncomment to enable communication with other agents.
441
+ When enabled, automatically registers 'talk_to_agent' action.
442
+
443
+ a2a:
444
+ enabled: true
445
+ peers:
446
+ talk_to_analyst: http://localhost:3001
447
+ talk_to_researcher: http://localhost:3002
448
+ verbose: false
449
+ -->
450
+
451
+ `;
452
+ }
453
+ function buildWorldSection(connectToWorld, worldUrl) {
454
+ if (connectToWorld && worldUrl) {
455
+ return `## World
456
+ url: ${worldUrl}
457
+ auto_join: true
458
+
459
+ `;
460
+ }
461
+ return `## World
462
+ <!-- Uncomment to connect this agent to a Moltium World on startup -->
463
+ <!-- Automatically registers: join_world, leave_world, query_world, send_world_message -->
464
+ <!-- url: http://localhost:4000 -->
465
+ <!-- auto_join: true -->
466
+
467
+ `;
468
+ }
375
469
 
376
470
  // src/templates/markdown-based/start.ts
377
471
  function markdownStartTemplate(ctx) {
378
472
  const envKey = ctx.llmProvider === "anthropic" ? "ANTHROPIC_API_KEY" : "OPENAI_API_KEY";
379
473
  const model = ctx.llmProvider === "anthropic" ? "claude-sonnet-4-20250514" : "gpt-4o";
474
+ const a2aComment = ctx.enableA2A !== false ? `// A2A Protocol endpoints are enabled by default:
475
+ // - /.well-known/agent-card.json (Agent discovery)
476
+ // - /a2a/jsonrpc (JSON-RPC transport)
477
+ // - /a2a/rest (HTTP+JSON/REST transport)
478
+ // To disable, pass { enableA2A: false } to startServer()` : `// A2A Protocol is disabled
479
+ // To enable, pass { enableA2A: true } to startServer()`;
480
+ const a2aConfig = ctx.enableA2A !== false ? `,
481
+ enableA2A: true, // Enable A2A Protocol endpoints` : `,
482
+ enableA2A: false`;
380
483
  return `import 'dotenv/config';
381
484
  import { readFileSync, readdirSync, existsSync } from 'node:fs';
382
485
  import { join, basename } from 'node:path';
@@ -392,6 +495,8 @@ import type { AgentConfig } from '@moltium/core';
392
495
  * 3. Registers skills as LLM-interpreted actions
393
496
  * 4. Starts the HTTP server with REST endpoints
394
497
  *
498
+ * ${a2aComment}
499
+ *
395
500
  * Run with: npx tsx start.ts
396
501
  * Or: npm start
397
502
  */
@@ -437,6 +542,16 @@ if (config.social.twitter?.enabled) {
437
542
  };
438
543
  }
439
544
 
545
+ // \u2500\u2500 Wire world config from environment \u2500\u2500
546
+ // WORLD_URL env var overrides the value in agent.md
547
+ if (process.env.WORLD_URL) {
548
+ config.world = {
549
+ url: process.env.WORLD_URL,
550
+ autoJoin: config.world?.autoJoin !== false,
551
+ walletAddress: config.world?.walletAddress,
552
+ };
553
+ }
554
+
440
555
  // \u2500\u2500 Create agent \u2500\u2500
441
556
  const agent = new Agent(config);
442
557
 
@@ -516,7 +631,13 @@ agent.setHooks({
516
631
  // \u2500\u2500 Start \u2500\u2500
517
632
  const port = parseInt(process.env.PORT || '3000', 10);
518
633
 
519
- startServer(agent, { port }).catch((err) => {
634
+ startServer(agent, {
635
+ port${a2aConfig},
636
+ a2aConfig: {
637
+ enabled: true,
638
+ baseUrl: \`http://0.0.0.0:\${port}\`,
639
+ },
640
+ }).catch((err) => {
520
641
  console.error('Failed to start agent:', err);
521
642
  process.exit(1);
522
643
  });
@@ -1012,7 +1133,7 @@ function getCoreDepVersion() {
1012
1133
  const corePkg = require2("@moltium/core/package.json");
1013
1134
  return `^${corePkg.version}`;
1014
1135
  } catch {
1015
- return "^0.1.19";
1136
+ return "^0.1.21";
1016
1137
  }
1017
1138
  }
1018
1139
  var initCommand = new Command("init").description("Initialize a new Moltium agent").argument("[name]", "Agent name").action(async (name) => {
@@ -1058,6 +1179,25 @@ var initCommand = new Command("init").description("Initialize a new Moltium agen
1058
1179
  { name: "Twitter", value: "twitter" }
1059
1180
  ]
1060
1181
  },
1182
+ {
1183
+ type: "confirm",
1184
+ name: "enableA2A",
1185
+ message: "Enable A2A Protocol support? (Agent-to-Agent communication)",
1186
+ default: true
1187
+ },
1188
+ {
1189
+ type: "confirm",
1190
+ name: "connectToWorld",
1191
+ message: "Connect to a Moltium World? (World SDK integration)",
1192
+ default: false
1193
+ },
1194
+ {
1195
+ type: "input",
1196
+ name: "worldUrl",
1197
+ message: "World server URL:",
1198
+ default: "http://localhost:4000",
1199
+ when: (answers2) => answers2.connectToWorld
1200
+ },
1061
1201
  {
1062
1202
  type: "list",
1063
1203
  name: "deployTarget",
@@ -1222,6 +1362,13 @@ function generateEnvFile(ctx) {
1222
1362
  lines.push(`${tw}TWITTER_ACCESS_TOKEN=your-twitter-access-token`);
1223
1363
  lines.push(`${tw}TWITTER_ACCESS_SECRET=your-twitter-access-secret`);
1224
1364
  lines.push("");
1365
+ lines.push("# World SDK Integration (set URL to auto-connect on startup)");
1366
+ if (ctx.connectToWorld && ctx.worldUrl) {
1367
+ lines.push(`WORLD_URL=${ctx.worldUrl}`);
1368
+ } else {
1369
+ lines.push("# WORLD_URL=http://localhost:4000");
1370
+ }
1371
+ lines.push("");
1225
1372
  lines.push("PORT=3000");
1226
1373
  lines.push("LOG_LEVEL=info");
1227
1374
  lines.push("");
@@ -1238,7 +1385,7 @@ import ora2 from "ora";
1238
1385
  import { config as loadEnv } from "dotenv";
1239
1386
  import { createInterface } from "readline";
1240
1387
  import { ConfigLoader, Agent, MarkdownParser, startServer, AnthropicProvider, OpenAIProvider, buildSystemPrompt } from "@moltium/core";
1241
- var startCommand = new Command2("start").description("Start agent locally").option("-p, --port <number>", "Port to run on", "3000").option("-e, --env <file>", "Environment file", ".env").option("--debug", "Enable debug logging").option("--dry-run", "Test agent in terminal without posting to social platforms").option("--watch", "Watch for file changes (not yet implemented)").action(async (options) => {
1388
+ var startCommand = new Command2("start").description("Start agent locally").option("-p, --port <number>", "Port to run on", "3000").option("-e, --env <file>", "Environment file", ".env").option("--debug", "Enable debug logging").option("--dry-run", "Test agent in terminal without posting to social platforms").option("--no-a2a", "Disable A2A Protocol endpoints").option("--watch", "Watch for file changes (not yet implemented)").action(async (options) => {
1242
1389
  const agentDir = resolve2(process.cwd());
1243
1390
  loadEnv({ path: resolve2(agentDir, options.env) });
1244
1391
  if (options.debug) {
@@ -1275,7 +1422,11 @@ var startCommand = new Command2("start").description("Start agent locally").opti
1275
1422
  await wireMarkdownBasedAgent(agent, agentDir, spinner);
1276
1423
  }
1277
1424
  spinner.succeed(chalk2.green(`Agent "${config.name}" loaded (${type} config)`));
1278
- await startServer(agent, { port: parseInt(options.port, 10) });
1425
+ await startServer(agent, {
1426
+ port: parseInt(options.port, 10),
1427
+ enableA2A: options.a2a !== false
1428
+ // A2A enabled by default, disabled only if --no-a2a is passed
1429
+ });
1279
1430
  } catch (error) {
1280
1431
  spinner.fail(chalk2.red("Failed to start agent"));
1281
1432
  console.error(error instanceof Error ? error.message : error);
@@ -3262,7 +3413,7 @@ Failed to reach agent at ${url}`));
3262
3413
 
3263
3414
  // src/index.ts
3264
3415
  var program = new Command7();
3265
- program.name("moltium").description("Moltium Agent SDK \u2014 create and manage autonomous AI agents").version("0.1.19");
3416
+ program.name("moltium").description("Moltium Agent SDK \u2014 create and manage autonomous AI agents").version("0.1.20");
3266
3417
  program.addCommand(initCommand);
3267
3418
  program.addCommand(startCommand);
3268
3419
  program.addCommand(deployCommand);