@elizaos/plugin-commands 1.0.0

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 ADDED
@@ -0,0 +1,1049 @@
1
+ // src/index.ts
2
+ import {
3
+ logger
4
+ } from "@elizaos/core";
5
+
6
+ // src/registry.ts
7
+ var DEFAULT_COMMANDS = [
8
+ {
9
+ key: "help",
10
+ nativeName: "help",
11
+ description: "Show available commands",
12
+ textAliases: ["/help", "/h", "/?"],
13
+ scope: "both",
14
+ category: "status",
15
+ acceptsArgs: false
16
+ },
17
+ {
18
+ key: "commands",
19
+ nativeName: "commands",
20
+ description: "List all commands",
21
+ textAliases: ["/commands", "/cmds"],
22
+ scope: "both",
23
+ category: "status",
24
+ acceptsArgs: false
25
+ },
26
+ {
27
+ key: "status",
28
+ nativeName: "status",
29
+ description: "Show current session status",
30
+ textAliases: ["/status", "/s"],
31
+ scope: "both",
32
+ category: "status",
33
+ acceptsArgs: false
34
+ },
35
+ {
36
+ key: "context",
37
+ nativeName: "context",
38
+ description: "Show current context information",
39
+ textAliases: ["/context", "/ctx"],
40
+ scope: "both",
41
+ category: "status",
42
+ acceptsArgs: true,
43
+ args: [{ name: "mode", description: "Output mode (list, detail, json)" }]
44
+ },
45
+ {
46
+ key: "whoami",
47
+ nativeName: "whoami",
48
+ description: "Show your identity information",
49
+ textAliases: ["/whoami", "/who"],
50
+ scope: "both",
51
+ category: "status",
52
+ acceptsArgs: false
53
+ },
54
+ {
55
+ key: "stop",
56
+ nativeName: "stop",
57
+ description: "Stop current operation",
58
+ textAliases: ["/stop", "/abort", "/cancel"],
59
+ scope: "both",
60
+ category: "session",
61
+ acceptsArgs: false
62
+ },
63
+ {
64
+ key: "restart",
65
+ nativeName: "restart",
66
+ description: "Restart the session",
67
+ textAliases: ["/restart"],
68
+ scope: "both",
69
+ category: "session",
70
+ acceptsArgs: false,
71
+ requiresAuth: true
72
+ },
73
+ {
74
+ key: "reset",
75
+ nativeName: "reset",
76
+ description: "Reset session state",
77
+ textAliases: ["/reset"],
78
+ scope: "both",
79
+ category: "session",
80
+ acceptsArgs: false,
81
+ requiresAuth: true
82
+ },
83
+ {
84
+ key: "new",
85
+ nativeName: "new",
86
+ description: "Start a new conversation",
87
+ textAliases: ["/new"],
88
+ scope: "both",
89
+ category: "session",
90
+ acceptsArgs: false
91
+ },
92
+ {
93
+ key: "compact",
94
+ nativeName: "compact",
95
+ description: "Compact conversation history",
96
+ textAliases: ["/compact"],
97
+ scope: "both",
98
+ category: "session",
99
+ acceptsArgs: true,
100
+ args: [
101
+ { name: "instructions", description: "Optional compaction instructions" }
102
+ ]
103
+ },
104
+ {
105
+ key: "think",
106
+ nativeName: "think",
107
+ description: "Set thinking level",
108
+ textAliases: ["/think", "/thinking", "/t"],
109
+ scope: "both",
110
+ category: "options",
111
+ acceptsArgs: true,
112
+ args: [
113
+ { name: "level", description: "off, minimal, low, medium, high, xhigh" }
114
+ ]
115
+ },
116
+ {
117
+ key: "verbose",
118
+ nativeName: "verbose",
119
+ description: "Set verbose output level",
120
+ textAliases: ["/verbose", "/v"],
121
+ scope: "both",
122
+ category: "options",
123
+ acceptsArgs: true,
124
+ args: [{ name: "level", description: "off, on, full" }]
125
+ },
126
+ {
127
+ key: "reasoning",
128
+ nativeName: "reasoning",
129
+ description: "Set reasoning visibility",
130
+ textAliases: ["/reasoning", "/reason"],
131
+ scope: "both",
132
+ category: "options",
133
+ acceptsArgs: true,
134
+ args: [{ name: "level", description: "off, on, stream" }]
135
+ },
136
+ {
137
+ key: "elevated",
138
+ nativeName: "elevated",
139
+ description: "Set elevated permission mode",
140
+ textAliases: ["/elevated", "/elev"],
141
+ scope: "both",
142
+ category: "options",
143
+ acceptsArgs: true,
144
+ args: [{ name: "level", description: "off, on, ask, full" }],
145
+ requiresAuth: true
146
+ },
147
+ {
148
+ key: "model",
149
+ nativeName: "model",
150
+ description: "Set or show current model",
151
+ textAliases: ["/model", "/m"],
152
+ scope: "both",
153
+ category: "options",
154
+ acceptsArgs: true,
155
+ args: [{ name: "model", description: "provider/model or alias" }]
156
+ },
157
+ {
158
+ key: "models",
159
+ nativeName: "models",
160
+ description: "List available models",
161
+ textAliases: ["/models"],
162
+ scope: "both",
163
+ category: "options",
164
+ acceptsArgs: false
165
+ },
166
+ {
167
+ key: "usage",
168
+ nativeName: "usage",
169
+ description: "Show token usage",
170
+ textAliases: ["/usage"],
171
+ scope: "both",
172
+ category: "options",
173
+ acceptsArgs: false
174
+ },
175
+ {
176
+ key: "queue",
177
+ nativeName: "queue",
178
+ description: "Set queue mode",
179
+ textAliases: ["/queue", "/q"],
180
+ scope: "both",
181
+ category: "options",
182
+ acceptsArgs: true,
183
+ args: [
184
+ {
185
+ name: "mode",
186
+ description: "steer, followup, collect, interrupt, or options"
187
+ }
188
+ ]
189
+ },
190
+ {
191
+ key: "allowlist",
192
+ nativeName: "allowlist",
193
+ description: "Manage sender allowlist",
194
+ textAliases: ["/allowlist", "/allow"],
195
+ scope: "both",
196
+ category: "management",
197
+ acceptsArgs: true,
198
+ args: [
199
+ { name: "action", description: "list, add, remove" },
200
+ { name: "value", description: "sender to add/remove" }
201
+ ],
202
+ requiresAuth: true
203
+ },
204
+ {
205
+ key: "approve",
206
+ nativeName: "approve",
207
+ description: "Approve or deny a pending action",
208
+ textAliases: ["/approve"],
209
+ scope: "both",
210
+ category: "management",
211
+ acceptsArgs: true,
212
+ args: [
213
+ { name: "id", description: "Approval ID", required: true },
214
+ { name: "action", description: "allow-once, allow-always, deny" }
215
+ ],
216
+ requiresAuth: true
217
+ },
218
+ {
219
+ key: "subagents",
220
+ nativeName: "subagents",
221
+ description: "Manage subagents",
222
+ textAliases: ["/subagents", "/sub"],
223
+ scope: "both",
224
+ category: "management",
225
+ acceptsArgs: true,
226
+ args: [{ name: "action", description: "list, stop, log, info, send" }],
227
+ requiresAuth: true
228
+ },
229
+ {
230
+ key: "config",
231
+ nativeName: "config",
232
+ description: "View or set configuration",
233
+ textAliases: ["/config", "/cfg"],
234
+ scope: "both",
235
+ category: "management",
236
+ acceptsArgs: true,
237
+ args: [
238
+ { name: "key", description: "Configuration key" },
239
+ { name: "value", description: "Value to set" }
240
+ ],
241
+ requiresAuth: true,
242
+ enabled: false
243
+ },
244
+ {
245
+ key: "debug",
246
+ nativeName: "debug",
247
+ description: "Debug information",
248
+ textAliases: ["/debug"],
249
+ scope: "both",
250
+ category: "management",
251
+ acceptsArgs: true,
252
+ requiresAuth: true,
253
+ enabled: false
254
+ },
255
+ {
256
+ key: "tts",
257
+ nativeName: "tts",
258
+ description: "Text-to-speech settings",
259
+ textAliases: ["/tts", "/voice"],
260
+ scope: "both",
261
+ category: "media",
262
+ acceptsArgs: true,
263
+ args: [
264
+ {
265
+ name: "action",
266
+ description: "on, off, status, provider, limit, audio"
267
+ }
268
+ ]
269
+ },
270
+ {
271
+ key: "bash",
272
+ nativeName: "bash",
273
+ description: "Execute shell command",
274
+ textAliases: ["/bash", "/sh", "/!"],
275
+ scope: "text",
276
+ category: "tools",
277
+ acceptsArgs: true,
278
+ args: [
279
+ {
280
+ name: "command",
281
+ description: "Shell command to execute",
282
+ captureRemaining: true
283
+ }
284
+ ],
285
+ requiresAuth: true,
286
+ requiresElevated: true
287
+ }
288
+ ];
289
+ var commands = [...DEFAULT_COMMANDS];
290
+ var aliasMap = null;
291
+ function getCommands() {
292
+ return [...commands];
293
+ }
294
+ function getEnabledCommands() {
295
+ return commands.filter((cmd) => cmd.enabled !== false);
296
+ }
297
+ function getCommandsByCategory(category) {
298
+ return commands.filter((cmd) => cmd.category === category && cmd.enabled !== false);
299
+ }
300
+ function registerCommand(command) {
301
+ commands = commands.filter((c) => c.key !== command.key);
302
+ commands.push(command);
303
+ aliasMap = null;
304
+ }
305
+ function registerCommands(newCommands) {
306
+ for (const command of newCommands) {
307
+ registerCommand(command);
308
+ }
309
+ }
310
+ function unregisterCommand(key) {
311
+ commands = commands.filter((c) => c.key !== key);
312
+ aliasMap = null;
313
+ }
314
+ function resetCommands() {
315
+ commands = [...DEFAULT_COMMANDS];
316
+ aliasMap = null;
317
+ }
318
+ function getAliasMap() {
319
+ if (aliasMap)
320
+ return aliasMap;
321
+ aliasMap = new Map;
322
+ for (const command of commands) {
323
+ if (command.enabled === false)
324
+ continue;
325
+ for (const alias of command.textAliases) {
326
+ const normalized = alias.toLowerCase().trim();
327
+ if (!aliasMap.has(normalized)) {
328
+ aliasMap.set(normalized, command);
329
+ }
330
+ }
331
+ }
332
+ return aliasMap;
333
+ }
334
+ function findCommandByAlias(alias) {
335
+ const map = getAliasMap();
336
+ return map.get(alias.toLowerCase().trim());
337
+ }
338
+ function findCommandByKey(key) {
339
+ return commands.find((c) => c.key === key);
340
+ }
341
+ function startsWithCommand(text) {
342
+ const map = getAliasMap();
343
+ const normalized = text.toLowerCase().trim();
344
+ for (const [alias, command] of map) {
345
+ if (normalized === alias) {
346
+ return command;
347
+ }
348
+ if (normalized.startsWith(alias + " ") || normalized.startsWith(alias + ":")) {
349
+ return command;
350
+ }
351
+ }
352
+ return;
353
+ }
354
+
355
+ // src/parser.ts
356
+ var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
357
+ function hasCommand(text) {
358
+ if (!text)
359
+ return false;
360
+ const trimmed = text.trim();
361
+ if (!trimmed.startsWith("/") && !trimmed.startsWith("!"))
362
+ return false;
363
+ return Boolean(startsWithCommand(trimmed));
364
+ }
365
+ function detectCommand(text) {
366
+ if (!text) {
367
+ return { isCommand: false };
368
+ }
369
+ const trimmed = text.trim();
370
+ if (!trimmed.startsWith("/") && !trimmed.startsWith("!")) {
371
+ return { isCommand: false };
372
+ }
373
+ const command = startsWithCommand(trimmed);
374
+ if (!command) {
375
+ return { isCommand: false };
376
+ }
377
+ const parsed = parseCommand(trimmed, command);
378
+ if (!parsed) {
379
+ return { isCommand: false };
380
+ }
381
+ return { isCommand: true, command: parsed };
382
+ }
383
+ function parseCommand(text, definition) {
384
+ const trimmed = text.trim();
385
+ let matchedAlias = null;
386
+ for (const alias of definition.textAliases) {
387
+ const normalized = alias.toLowerCase();
388
+ if (trimmed.toLowerCase() === normalized) {
389
+ matchedAlias = alias;
390
+ break;
391
+ }
392
+ if (trimmed.toLowerCase().startsWith(normalized + " ") || trimmed.toLowerCase().startsWith(normalized + ":")) {
393
+ matchedAlias = alias;
394
+ break;
395
+ }
396
+ }
397
+ if (!matchedAlias) {
398
+ return null;
399
+ }
400
+ let rawArgs = trimmed.slice(matchedAlias.length).trim();
401
+ if (rawArgs.startsWith(":")) {
402
+ rawArgs = rawArgs.slice(1).trim();
403
+ }
404
+ const args = parseArgs(rawArgs, definition);
405
+ return {
406
+ key: definition.key,
407
+ canonical: definition.textAliases[0] ?? `/${definition.key}`,
408
+ args,
409
+ rawArgs: rawArgs || undefined
410
+ };
411
+ }
412
+ function parseArgs(rawArgs, definition) {
413
+ if (!rawArgs || !definition.acceptsArgs) {
414
+ return [];
415
+ }
416
+ const parsing = definition.argsParsing ?? "positional";
417
+ if (parsing === "none") {
418
+ return rawArgs ? [rawArgs] : [];
419
+ }
420
+ const args = [];
421
+ const argDefs = definition.args ?? [];
422
+ const tokens = tokenize(rawArgs);
423
+ for (let i = 0;i < tokens.length; i++) {
424
+ const argDef = argDefs[i];
425
+ if (argDef?.captureRemaining) {
426
+ args.push(tokens.slice(i).join(" "));
427
+ break;
428
+ }
429
+ args.push(tokens[i]);
430
+ }
431
+ return args;
432
+ }
433
+ function tokenize(input) {
434
+ const tokens = [];
435
+ let current = "";
436
+ let inQuote = false;
437
+ let quoteChar = "";
438
+ for (let i = 0;i < input.length; i++) {
439
+ const char = input[i];
440
+ if (inQuote) {
441
+ if (char === quoteChar) {
442
+ inQuote = false;
443
+ if (current) {
444
+ tokens.push(current);
445
+ current = "";
446
+ }
447
+ } else {
448
+ current += char;
449
+ }
450
+ } else if (char === '"' || char === "'") {
451
+ inQuote = true;
452
+ quoteChar = char;
453
+ } else if (/\s/.test(char)) {
454
+ if (current) {
455
+ tokens.push(current);
456
+ current = "";
457
+ }
458
+ } else {
459
+ current += char;
460
+ }
461
+ }
462
+ if (current) {
463
+ tokens.push(current);
464
+ }
465
+ return tokens;
466
+ }
467
+ function normalizeCommandBody(text, botMention) {
468
+ let normalized = text.trim();
469
+ if (botMention) {
470
+ const mentionPattern = new RegExp(`^@${escapeRegExp(botMention)}\\s*`, "i");
471
+ normalized = normalized.replace(mentionPattern, "");
472
+ }
473
+ normalized = normalized.replace(/^(\/\w+):\s*/, "$1 ");
474
+ return normalized.trim();
475
+ }
476
+ function isCommandOnly(text) {
477
+ const detection = detectCommand(text);
478
+ if (!detection.isCommand || !detection.command) {
479
+ return false;
480
+ }
481
+ if (!detection.command.rawArgs) {
482
+ return true;
483
+ }
484
+ return detection.command.rawArgs.trim().length === 0;
485
+ }
486
+ function extractCommand(text) {
487
+ const detection = detectCommand(text);
488
+ if (!detection.isCommand || !detection.command) {
489
+ return null;
490
+ }
491
+ const { command } = detection;
492
+ if (!command.rawArgs) {
493
+ return { command, remainingText: "" };
494
+ }
495
+ return { command, remainingText: command.rawArgs };
496
+ }
497
+
498
+ // src/actions/commands-list.ts
499
+ var commandsListAction = {
500
+ name: "COMMANDS_LIST",
501
+ description: "List all available commands with their aliases",
502
+ similes: ["/commands", "/cmds", "list all commands"],
503
+ async validate(runtime, message) {
504
+ const text = message.content?.text ?? "";
505
+ const detection = detectCommand(text);
506
+ return detection.isCommand && detection.command?.key === "commands";
507
+ },
508
+ async handler(runtime, message, state, options, callback) {
509
+ const commands2 = getEnabledCommands();
510
+ const lines = [`**Commands (${commands2.length}):**
511
+ `];
512
+ for (const cmd of commands2) {
513
+ const aliases = cmd.textAliases.join(", ");
514
+ const authNote = cmd.requiresAuth ? " [auth]" : "";
515
+ const elevatedNote = cmd.requiresElevated ? " [elevated]" : "";
516
+ lines.push(`• **${cmd.key}**: ${aliases}${authNote}${elevatedNote}`);
517
+ }
518
+ const replyText = lines.join(`
519
+ `);
520
+ await callback?.({ text: replyText });
521
+ return {
522
+ success: true,
523
+ text: replyText,
524
+ data: { commandCount: commands2.length }
525
+ };
526
+ },
527
+ examples: [
528
+ [
529
+ { user: "user", content: { text: "/commands" } },
530
+ {
531
+ user: "assistant",
532
+ content: {
533
+ text: `**Commands (15):**
534
+
535
+ • **help**: /help, /h, /?
536
+ • **status**: /status, /s...`
537
+ }
538
+ }
539
+ ]
540
+ ]
541
+ };
542
+
543
+ // src/actions/help.ts
544
+ function formatCommandList(commands2) {
545
+ const lines = [`**Available Commands:**
546
+ `];
547
+ const categories = [
548
+ { key: "status", name: "Status" },
549
+ { key: "session", name: "Session" },
550
+ { key: "options", name: "Options" },
551
+ { key: "management", name: "Management" },
552
+ { key: "media", name: "Media" },
553
+ { key: "tools", name: "Tools" }
554
+ ];
555
+ for (const cat of categories) {
556
+ const catCommands = commands2.filter((c) => c.category === cat.key);
557
+ if (catCommands.length === 0)
558
+ continue;
559
+ lines.push(`
560
+ **${cat.name}:**`);
561
+ for (const cmd of catCommands) {
562
+ const aliases = cmd.textAliases.slice(0, 2).join(", ");
563
+ lines.push(`• ${aliases} - ${cmd.description}`);
564
+ }
565
+ }
566
+ const uncategorized = commands2.filter((c) => !c.category);
567
+ if (uncategorized.length > 0) {
568
+ lines.push(`
569
+ **Other:**`);
570
+ for (const cmd of uncategorized) {
571
+ const aliases = cmd.textAliases.slice(0, 2).join(", ");
572
+ lines.push(`• ${aliases} - ${cmd.description}`);
573
+ }
574
+ }
575
+ return lines.join(`
576
+ `);
577
+ }
578
+ var helpAction = {
579
+ name: "HELP_COMMAND",
580
+ description: "Show available commands and their descriptions",
581
+ similes: ["/help", "/h", "/?", "help", "show help", "list commands"],
582
+ async validate(runtime, message) {
583
+ const text = message.content?.text ?? "";
584
+ const detection = detectCommand(text);
585
+ return detection.isCommand && detection.command?.key === "help";
586
+ },
587
+ async handler(runtime, message, state, options, callback) {
588
+ const commands2 = getEnabledCommands();
589
+ const helpText = formatCommandList(commands2);
590
+ await callback?.({ text: helpText });
591
+ return {
592
+ success: true,
593
+ text: helpText,
594
+ data: { commandCount: commands2.length }
595
+ };
596
+ },
597
+ examples: [
598
+ [
599
+ { user: "user", content: { text: "/help" } },
600
+ {
601
+ user: "assistant",
602
+ content: {
603
+ text: `**Available Commands:**
604
+
605
+ **Status:**
606
+ • /help - Show available commands...`
607
+ }
608
+ }
609
+ ],
610
+ [
611
+ { user: "user", content: { text: "/?" } },
612
+ {
613
+ user: "assistant",
614
+ content: {
615
+ text: `**Available Commands:**
616
+
617
+ **Status:**
618
+ • /help - Show available commands...`
619
+ }
620
+ }
621
+ ]
622
+ ]
623
+ };
624
+
625
+ // src/actions/models.ts
626
+ var modelsAction = {
627
+ name: "MODELS_COMMAND",
628
+ description: "List available AI models and providers",
629
+ similes: ["/models", "list models", "show models", "available models"],
630
+ async validate(runtime, message) {
631
+ const text = message.content?.text ?? "";
632
+ const detection = detectCommand(text);
633
+ return detection.isCommand && detection.command?.key === "models";
634
+ },
635
+ async handler(runtime, message, state, options, callback) {
636
+ const lines = [`**Available Models:**
637
+ `];
638
+ const providers = [
639
+ {
640
+ name: "Anthropic",
641
+ models: [
642
+ "claude-3-opus",
643
+ "claude-3-sonnet",
644
+ "claude-3-haiku",
645
+ "claude-3.5-sonnet"
646
+ ]
647
+ },
648
+ {
649
+ name: "OpenAI",
650
+ models: [
651
+ "gpt-4o",
652
+ "gpt-4o-mini",
653
+ "gpt-4-turbo",
654
+ "gpt-4",
655
+ "gpt-3.5-turbo"
656
+ ]
657
+ },
658
+ {
659
+ name: "Google",
660
+ models: ["gemini-pro", "gemini-pro-vision", "gemini-ultra"]
661
+ }
662
+ ];
663
+ for (const provider of providers) {
664
+ lines.push(`
665
+ **${provider.name}:**`);
666
+ for (const model of provider.models) {
667
+ lines.push(`• ${provider.name.toLowerCase()}/${model}`);
668
+ }
669
+ }
670
+ lines.push(`
671
+
672
+ _Use /model <provider/model> to switch models._`);
673
+ const replyText = lines.join(`
674
+ `);
675
+ await callback?.({ text: replyText });
676
+ return {
677
+ success: true,
678
+ text: replyText,
679
+ data: { providers }
680
+ };
681
+ },
682
+ examples: [
683
+ [
684
+ { user: "user", content: { text: "/models" } },
685
+ {
686
+ user: "assistant",
687
+ content: {
688
+ text: `**Available Models:**
689
+
690
+ **Anthropic:**
691
+ • anthropic/claude-3-opus
692
+ • anthropic/claude-3-sonnet...`
693
+ }
694
+ }
695
+ ]
696
+ ]
697
+ };
698
+
699
+ // src/actions/status.ts
700
+ async function buildStatusReport(runtime, roomId) {
701
+ const lines = [`**Session Status:**
702
+ `];
703
+ lines.push(`**Agent:** ${runtime.agentId}`);
704
+ lines.push(`**Room:** ${roomId}`);
705
+ try {
706
+ const directiveService = runtime.getService("directive-parser");
707
+ if (directiveService) {
708
+ const state = directiveService.getSessionState?.(roomId);
709
+ if (state) {
710
+ lines.push(`
711
+ **Directives:**`);
712
+ lines.push(`• Thinking: ${state.thinking}`);
713
+ lines.push(`• Verbose: ${state.verbose}`);
714
+ lines.push(`• Reasoning: ${state.reasoning}`);
715
+ lines.push(`• Elevated: ${state.elevated}`);
716
+ if (state.model?.provider || state.model?.model) {
717
+ const modelStr = state.model.provider ? `${state.model.provider}/${state.model.model}` : state.model.model;
718
+ lines.push(`• Model: ${modelStr}`);
719
+ }
720
+ }
721
+ }
722
+ } catch {}
723
+ return lines.join(`
724
+ `);
725
+ }
726
+ var statusAction = {
727
+ name: "STATUS_COMMAND",
728
+ description: "Show current session status, model, and settings",
729
+ similes: ["/status", "/s", "status", "show status", "what's my status"],
730
+ async validate(runtime, message) {
731
+ const text = message.content?.text ?? "";
732
+ const detection = detectCommand(text);
733
+ return detection.isCommand && detection.command?.key === "status";
734
+ },
735
+ async handler(runtime, message, state, options, callback) {
736
+ const statusText = await buildStatusReport(runtime, message.roomId);
737
+ await callback?.({ text: statusText });
738
+ return {
739
+ success: true,
740
+ text: statusText
741
+ };
742
+ },
743
+ examples: [
744
+ [
745
+ { user: "user", content: { text: "/status" } },
746
+ {
747
+ user: "assistant",
748
+ content: {
749
+ text: `**Session Status:**
750
+
751
+ **Agent:** agent-123
752
+ **Room:** room-456
753
+
754
+ **Directives:**
755
+ • Thinking: low...`
756
+ }
757
+ }
758
+ ]
759
+ ]
760
+ };
761
+
762
+ // src/actions/stop.ts
763
+ var stopAction = {
764
+ name: "STOP_COMMAND",
765
+ description: "Stop current operation or abort running tasks",
766
+ similes: ["/stop", "/abort", "/cancel", "stop", "abort", "cancel"],
767
+ async validate(runtime, message) {
768
+ const text = message.content?.text ?? "";
769
+ const detection = detectCommand(text);
770
+ return detection.isCommand && ["stop", "abort", "cancel"].includes(detection.command?.key ?? "");
771
+ },
772
+ async handler(runtime, message, state, options, callback) {
773
+ try {
774
+ await runtime.emitEvent?.("ABORT_REQUESTED", {
775
+ roomId: message.roomId,
776
+ userId: message.userId,
777
+ requestedAt: Date.now()
778
+ });
779
+ } catch {}
780
+ const replyText = "✓ Stop requested. Current operations will be cancelled.";
781
+ await callback?.({ text: replyText });
782
+ return {
783
+ success: true,
784
+ text: replyText
785
+ };
786
+ },
787
+ examples: [
788
+ [
789
+ { user: "user", content: { text: "/stop" } },
790
+ {
791
+ user: "assistant",
792
+ content: {
793
+ text: "✓ Stop requested. Current operations will be cancelled."
794
+ }
795
+ }
796
+ ],
797
+ [
798
+ { user: "user", content: { text: "/abort" } },
799
+ {
800
+ user: "assistant",
801
+ content: {
802
+ text: "✓ Stop requested. Current operations will be cancelled."
803
+ }
804
+ }
805
+ ]
806
+ ]
807
+ };
808
+
809
+ // src/index.ts
810
+ var commandRegistryProvider = {
811
+ name: "COMMAND_REGISTRY",
812
+ description: "Available chat commands and their descriptions",
813
+ dynamic: true,
814
+ async get(runtime, message, _state) {
815
+ const commands2 = getEnabledCommands();
816
+ const commandList = commands2.map((cmd) => {
817
+ const auth = cmd.requiresAuth ? " (requires auth)" : "";
818
+ return `- ${cmd.textAliases[0]}: ${cmd.description}${auth}`;
819
+ });
820
+ return {
821
+ text: `Available commands:
822
+ ${commandList.join(`
823
+ `)}`,
824
+ values: {
825
+ commandCount: commands2.length,
826
+ hasElevatedCommands: commands2.some((c) => c.requiresElevated)
827
+ },
828
+ data: { commands: commands2 }
829
+ };
830
+ }
831
+ };
832
+ function formatCommandResult(result) {
833
+ if (result.error) {
834
+ return `❌ Error: ${result.error}`;
835
+ }
836
+ return result.reply ?? "✓ Command executed";
837
+ }
838
+ function isAuthorized(context, command) {
839
+ if (!command.requiresAuth) {
840
+ return true;
841
+ }
842
+ return context.isAuthorized;
843
+ }
844
+ function isElevated(context, command) {
845
+ if (!command.requiresElevated) {
846
+ return true;
847
+ }
848
+ return context.isElevated;
849
+ }
850
+ var commandsPlugin = {
851
+ name: "commands",
852
+ description: "Chat command system with /help, /status, /reset, etc.",
853
+ providers: [commandRegistryProvider],
854
+ actions: [
855
+ helpAction,
856
+ statusAction,
857
+ stopAction,
858
+ modelsAction,
859
+ commandsListAction
860
+ ],
861
+ config: {
862
+ COMMANDS_ENABLED: "true",
863
+ COMMANDS_CONFIG_ENABLED: "false",
864
+ COMMANDS_DEBUG_ENABLED: "false",
865
+ COMMANDS_BASH_ENABLED: "false",
866
+ COMMANDS_RESTART_ENABLED: "true"
867
+ },
868
+ tests: [
869
+ {
870
+ name: "command-detection",
871
+ tests: [
872
+ {
873
+ name: "Detect command prefix",
874
+ fn: async (_runtime) => {
875
+ if (!hasCommand("/help")) {
876
+ throw new Error("Should detect /help command");
877
+ }
878
+ if (!hasCommand("/status test")) {
879
+ throw new Error("Should detect /status with args");
880
+ }
881
+ if (hasCommand("hello world")) {
882
+ throw new Error("Should not detect plain text as command");
883
+ }
884
+ logger.success("Command prefix detection works correctly");
885
+ }
886
+ },
887
+ {
888
+ name: "Parse command with args",
889
+ fn: async (_runtime) => {
890
+ const detection = detectCommand("/think:high");
891
+ if (!detection.isCommand) {
892
+ throw new Error("Should detect think command");
893
+ }
894
+ if (detection.command?.key !== "think") {
895
+ throw new Error(`Expected key 'think', got '${detection.command?.key}'`);
896
+ }
897
+ if (detection.command?.args[0] !== "high") {
898
+ throw new Error(`Expected arg 'high', got '${detection.command?.args[0]}'`);
899
+ }
900
+ logger.success("Command argument parsing works correctly");
901
+ }
902
+ },
903
+ {
904
+ name: "Normalize command body",
905
+ fn: async (_runtime) => {
906
+ const normalized1 = normalizeCommandBody("/status: test");
907
+ if (normalized1 !== "/status test") {
908
+ throw new Error(`Expected '/status test', got '${normalized1}'`);
909
+ }
910
+ const normalized2 = normalizeCommandBody("@bot /help", "bot");
911
+ if (normalized2 !== "/help") {
912
+ throw new Error(`Expected '/help', got '${normalized2}'`);
913
+ }
914
+ logger.success("Command normalization works correctly");
915
+ }
916
+ },
917
+ {
918
+ name: "Find command by alias",
919
+ fn: async (_runtime) => {
920
+ const cmd = findCommandByAlias("/h");
921
+ if (!cmd) {
922
+ throw new Error("Should find help command by /h alias");
923
+ }
924
+ if (cmd.key !== "help") {
925
+ throw new Error(`Expected key 'help', got '${cmd.key}'`);
926
+ }
927
+ logger.success("Command alias lookup works correctly");
928
+ }
929
+ },
930
+ {
931
+ name: "Find command by key",
932
+ fn: async (_runtime) => {
933
+ const cmd = findCommandByKey("status");
934
+ if (!cmd) {
935
+ throw new Error("Should find status command by key");
936
+ }
937
+ if (cmd.key !== "status") {
938
+ throw new Error(`Expected key 'status', got '${cmd.key}'`);
939
+ }
940
+ logger.success("Command key lookup works correctly");
941
+ }
942
+ }
943
+ ]
944
+ },
945
+ {
946
+ name: "command-registry",
947
+ tests: [
948
+ {
949
+ name: "Get enabled commands",
950
+ fn: async (_runtime) => {
951
+ const commands2 = getEnabledCommands();
952
+ if (commands2.length === 0) {
953
+ throw new Error("Should have enabled commands");
954
+ }
955
+ const hasHelp = commands2.some((c) => c.key === "help");
956
+ const hasStatus = commands2.some((c) => c.key === "status");
957
+ if (!hasHelp || !hasStatus) {
958
+ throw new Error("Should have help and status commands");
959
+ }
960
+ logger.success("Command registry works correctly");
961
+ }
962
+ },
963
+ {
964
+ name: "Register custom command",
965
+ fn: async (_runtime) => {
966
+ const customCmd = {
967
+ key: "test-custom",
968
+ description: "Test custom command",
969
+ textAliases: ["/test-custom", "/tc"],
970
+ scope: "text"
971
+ };
972
+ registerCommand(customCmd);
973
+ const found = findCommandByKey("test-custom");
974
+ if (!found) {
975
+ throw new Error("Should find registered custom command");
976
+ }
977
+ unregisterCommand("test-custom");
978
+ const notFound = findCommandByKey("test-custom");
979
+ if (notFound) {
980
+ throw new Error("Should not find unregistered command");
981
+ }
982
+ logger.success("Custom command registration works correctly");
983
+ }
984
+ },
985
+ {
986
+ name: "Get commands by category",
987
+ fn: async (_runtime) => {
988
+ const statusCommands = getCommandsByCategory("status");
989
+ if (statusCommands.length === 0) {
990
+ throw new Error("Should have status category commands");
991
+ }
992
+ const allStatus = statusCommands.every((c) => c.category === "status");
993
+ if (!allStatus) {
994
+ throw new Error("All returned commands should be in status category");
995
+ }
996
+ logger.success("Command categorization works correctly");
997
+ }
998
+ }
999
+ ]
1000
+ }
1001
+ ],
1002
+ async init(config, runtime) {
1003
+ logger.log("[plugin-commands] Initializing command system");
1004
+ const configEnabled = config.COMMANDS_CONFIG_ENABLED === "true";
1005
+ const debugEnabled = config.COMMANDS_DEBUG_ENABLED === "true";
1006
+ const bashEnabled = config.COMMANDS_BASH_ENABLED === "true";
1007
+ const configCmd = findCommandByKey("config");
1008
+ if (configCmd) {
1009
+ configCmd.enabled = configEnabled;
1010
+ }
1011
+ const debugCmd = findCommandByKey("debug");
1012
+ if (debugCmd) {
1013
+ debugCmd.enabled = debugEnabled;
1014
+ }
1015
+ const bashCmd = findCommandByKey("bash");
1016
+ if (bashCmd) {
1017
+ bashCmd.enabled = bashEnabled;
1018
+ }
1019
+ const enabledCount = getEnabledCommands().length;
1020
+ logger.log(`[plugin-commands] ${enabledCount} commands enabled`);
1021
+ }
1022
+ };
1023
+ var src_default = commandsPlugin;
1024
+ export {
1025
+ unregisterCommand,
1026
+ startsWithCommand,
1027
+ resetCommands,
1028
+ registerCommands,
1029
+ registerCommand,
1030
+ parseCommand,
1031
+ normalizeCommandBody,
1032
+ isElevated,
1033
+ isCommandOnly,
1034
+ isAuthorized,
1035
+ hasCommand,
1036
+ getEnabledCommands,
1037
+ getCommandsByCategory,
1038
+ getCommands,
1039
+ formatCommandResult,
1040
+ findCommandByKey,
1041
+ findCommandByAlias,
1042
+ extractCommand,
1043
+ detectCommand,
1044
+ src_default as default,
1045
+ commandsPlugin,
1046
+ commandRegistryProvider
1047
+ };
1048
+
1049
+ //# debugId=4D1F6605A437A12664756E2164756E21