@elizaos/plugin-commands 2.0.0-alpha.9 → 2.0.0-beta.1

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/auto-enable.ts ADDED
@@ -0,0 +1,24 @@
1
+ // Auto-enable check for @elizaos/plugin-commands.
2
+ //
3
+ // Plugin manifest entry-point — referenced by package.json's
4
+ // `elizaos.plugin.autoEnableModule`. Keep this module light: env reads only,
5
+ // no service init, no transitive imports of the full plugin runtime. The
6
+ // auto-enable engine loads dozens of these per boot.
7
+ import type { PluginAutoEnableContext } from "@elizaos/core";
8
+
9
+ function isFeatureEnabled(
10
+ config: PluginAutoEnableContext["config"],
11
+ key: string,
12
+ ): boolean {
13
+ const f = (config?.features as Record<string, unknown> | undefined)?.[key];
14
+ if (f === true) return true;
15
+ if (f && typeof f === "object" && f !== null) {
16
+ return (f as Record<string, unknown>).enabled !== false;
17
+ }
18
+ return false;
19
+ }
20
+
21
+ /** Enable when `config.features.commands` is truthy / not explicitly disabled. */
22
+ export function shouldEnable(ctx: PluginAutoEnableContext): boolean {
23
+ return isFeatureEnabled(ctx.config, "commands");
24
+ }
@@ -65,7 +65,7 @@ __export(exports_src, {
65
65
  commandRegistryProvider: () => commandRegistryProvider
66
66
  });
67
67
  module.exports = __toCommonJS(exports_src);
68
- var import_core3 = require("@elizaos/core");
68
+ var import_core = require("@elizaos/core");
69
69
 
70
70
  // src/registry.ts
71
71
  var DEFAULT_COMMANDS = [
@@ -577,407 +577,16 @@ function extractCommand(text) {
577
577
  return { command, remainingText: command.rawArgs };
578
578
  }
579
579
 
580
- // src/actions/commands-list.ts
581
- var commandsListAction = {
582
- name: "COMMANDS_LIST",
583
- description: "List all available commands with their aliases. Only activates for /commands or /cmds slash commands.",
584
- similes: ["/commands", "/cmds"],
585
- validate: async (runtime, message) => {
586
- const textRaw = message.content?.text ?? "";
587
- const text = textRaw.toLowerCase();
588
- const hasKeyword = text.includes("/commands") || text.includes("/cmds") || text.includes("commands");
589
- const hasRegex = /^(?:\/|!)\s*(?:commands|cmds)\b/i.test(textRaw);
590
- const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
591
- const hasInput = textRaw.trim().length > 0;
592
- if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
593
- return false;
594
- }
595
- const detection = detectCommand(textRaw);
596
- return detection.isCommand && detection.command?.key === "commands";
597
- },
598
- async handler(_runtime, _message, _state, _options, callback) {
599
- const commands = getEnabledCommands();
600
- const lines = [`**Commands (${commands.length}):**
601
- `];
602
- for (const cmd of commands) {
603
- const aliases = cmd.textAliases.join(", ");
604
- const authNote = cmd.requiresAuth ? " [auth]" : "";
605
- const elevatedNote = cmd.requiresElevated ? " [elevated]" : "";
606
- lines.push(`• **${cmd.key}**: ${aliases}${authNote}${elevatedNote}`);
607
- }
608
- const replyText = lines.join(`
609
- `);
610
- await callback?.({ text: replyText });
611
- return {
612
- success: true,
613
- text: replyText,
614
- data: { commandCount: commands.length }
615
- };
616
- },
617
- examples: [
618
- [
619
- { name: "user", content: { text: "/commands" } },
620
- {
621
- name: "assistant",
622
- content: {
623
- text: `**Commands (15):**
624
-
625
- • **help**: /help, /h, /?
626
- • **status**: /status, /s...`
627
- }
628
- }
629
- ]
630
- ]
631
- };
632
-
633
- // src/actions/help.ts
634
- function formatCommandList(commands) {
635
- const lines = [`**Available Commands:**
636
- `];
637
- const categories = [
638
- { key: "status", name: "Status" },
639
- { key: "session", name: "Session" },
640
- { key: "options", name: "Options" },
641
- { key: "management", name: "Management" },
642
- { key: "media", name: "Media" },
643
- { key: "tools", name: "Tools" }
644
- ];
645
- for (const cat of categories) {
646
- const catCommands = commands.filter((c) => c.category === cat.key);
647
- if (catCommands.length === 0)
648
- continue;
649
- lines.push(`
650
- **${cat.name}:**`);
651
- for (const cmd of catCommands) {
652
- const aliases = cmd.textAliases.slice(0, 2).join(", ");
653
- lines.push(`• ${aliases} - ${cmd.description}`);
654
- }
655
- }
656
- const uncategorized = commands.filter((c) => !c.category);
657
- if (uncategorized.length > 0) {
658
- lines.push(`
659
- **Other:**`);
660
- for (const cmd of uncategorized) {
661
- const aliases = cmd.textAliases.slice(0, 2).join(", ");
662
- lines.push(`• ${aliases} - ${cmd.description}`);
663
- }
664
- }
665
- return lines.join(`
666
- `);
667
- }
668
- var helpAction = {
669
- name: "HELP_COMMAND",
670
- description: "Show available commands and their descriptions. Only activates for /help, /h, or /? slash commands.",
671
- similes: ["/help", "/h", "/?"],
672
- validate: async (runtime, message) => {
673
- const textRaw = message.content?.text ?? "";
674
- const text = textRaw.toLowerCase();
675
- const hasKeyword = text.includes("/help") || text.includes("/h") || text.includes("/?");
676
- const hasRegex = /^(?:\/|!)\s*(?:help|h|\?)(?:\s|$|:)/i.test(textRaw);
677
- const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
678
- const hasInput = textRaw.trim().length > 0;
679
- if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
680
- return false;
681
- }
682
- const detection = detectCommand(textRaw);
683
- return detection.isCommand && detection.command?.key === "help";
684
- },
685
- async handler(_runtime, message, _state, _options, callback) {
686
- const detection = detectCommand(message?.content?.text ?? "");
687
- if (!detection.isCommand || detection.command?.key !== "help") {
688
- return { success: false, text: "" };
689
- }
690
- const commands = getEnabledCommands();
691
- const helpText = formatCommandList(commands);
692
- await callback?.({ text: helpText });
693
- return {
694
- success: true,
695
- text: helpText,
696
- data: { commandCount: commands.length }
697
- };
698
- },
699
- examples: [
700
- [
701
- { name: "user", content: { text: "/help" } },
702
- {
703
- name: "assistant",
704
- content: {
705
- text: `**Available Commands:**
706
-
707
- **Status:**
708
- • /help - Show available commands...`
709
- }
710
- }
711
- ],
712
- [
713
- { name: "user", content: { text: "/?" } },
714
- {
715
- name: "assistant",
716
- content: {
717
- text: `**Available Commands:**
718
-
719
- **Status:**
720
- • /help - Show available commands...`
721
- }
722
- }
723
- ]
724
- ]
725
- };
726
-
727
- // src/actions/models.ts
728
- var import_core = require("@elizaos/core");
729
- function describeModelType(modelType) {
730
- const descriptions = {
731
- [import_core.ModelType.TEXT_SMALL]: "Text (Small)",
732
- [import_core.ModelType.TEXT_LARGE]: "Text (Large)",
733
- [import_core.ModelType.TEXT_REASONING_SMALL]: "Reasoning (Small)",
734
- [import_core.ModelType.TEXT_REASONING_LARGE]: "Reasoning (Large)",
735
- [import_core.ModelType.TEXT_COMPLETION]: "Text Completion",
736
- [import_core.ModelType.TEXT_EMBEDDING]: "Embedding",
737
- [import_core.ModelType.IMAGE]: "Image Generation",
738
- [import_core.ModelType.IMAGE_DESCRIPTION]: "Image Description",
739
- [import_core.ModelType.TRANSCRIPTION]: "Transcription",
740
- [import_core.ModelType.TEXT_TO_SPEECH]: "Text-to-Speech",
741
- [import_core.ModelType.AUDIO]: "Audio",
742
- [import_core.ModelType.VIDEO]: "Video",
743
- [import_core.ModelType.OBJECT_SMALL]: "Object (Small)",
744
- [import_core.ModelType.OBJECT_LARGE]: "Object (Large)",
745
- [import_core.ModelType.RESEARCH]: "Research"
746
- };
747
- return descriptions[modelType] ?? modelType;
748
- }
749
- var modelsAction = {
750
- name: "MODELS_COMMAND",
751
- description: "List available AI models and providers. Only activates for /models slash command.",
752
- similes: ["/models"],
753
- validate: async (runtime, message) => {
754
- const textRaw = message.content?.text ?? "";
755
- const text = textRaw.toLowerCase();
756
- const hasKeyword = text.includes("/models") || text.includes("models");
757
- const hasRegex = /^(?:\/|!)\s*models\b/i.test(textRaw);
758
- const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
759
- const hasInput = textRaw.trim().length > 0;
760
- if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
761
- return false;
762
- }
763
- const detection = detectCommand(textRaw);
764
- return detection.isCommand && detection.command?.key === "models";
765
- },
766
- async handler(runtime, _message, _state, _options, callback) {
767
- const lines = [`**Available Models:**
768
- `];
769
- try {
770
- const registeredTypes = [];
771
- const seen = new Set;
772
- for (const modelType of Object.values(import_core.ModelType)) {
773
- if (seen.has(modelType))
774
- continue;
775
- seen.add(modelType);
776
- try {
777
- const handler = runtime.getModel(modelType);
778
- if (handler) {
779
- registeredTypes.push(modelType);
780
- }
781
- } catch {}
782
- }
783
- if (registeredTypes.length > 0) {
784
- lines.push("**Registered Model Types:**");
785
- for (const modelType of registeredTypes) {
786
- lines.push(`• ${describeModelType(modelType)} (\`${modelType}\`)`);
787
- }
788
- } else {
789
- lines.push("No model handlers are currently registered.");
790
- }
791
- const modelProvider = runtime.getSetting("MODEL_PROVIDER");
792
- const modelName = runtime.getSetting("MODEL_NAME");
793
- if (modelProvider || modelName) {
794
- lines.push(`
795
- **Current Configuration:**`);
796
- if (modelProvider)
797
- lines.push(`• Provider: ${modelProvider}`);
798
- if (modelName)
799
- lines.push(`• Model: ${modelName}`);
800
- }
801
- } catch (err) {
802
- import_core.logger.warn({ src: "plugin-commands", err }, "Error querying runtime models");
803
- lines.push("Unable to query available models.");
804
- }
805
- lines.push(`
806
-
807
- _Use /model <provider/model> to switch models._`);
808
- const replyText = lines.join(`
809
- `);
810
- await callback?.({ text: replyText });
811
- return {
812
- success: true,
813
- text: replyText
814
- };
815
- },
816
- examples: [
817
- [
818
- { name: "user", content: { text: "/models" } },
819
- {
820
- name: "assistant",
821
- content: {
822
- text: "**Available Models:**\n\n**Registered Model Types:**\n• Text (Large) (`text_large`)\n• Text (Small) (`text_small`)..."
823
- }
824
- }
825
- ]
826
- ]
827
- };
828
-
829
- // src/actions/status.ts
830
- async function buildStatusReport(runtime, roomId) {
831
- const lines = [`**Session Status:**
832
- `];
833
- lines.push(`**Agent:** ${runtime.character.name ?? runtime.agentId}`);
834
- lines.push(`**Room:** ${roomId}`);
835
- try {
836
- const directiveService = runtime.getService("directive-parser");
837
- if (directiveService) {
838
- const state = directiveService.getSessionState?.(roomId);
839
- if (state) {
840
- lines.push(`
841
- **Directives:**`);
842
- lines.push(`• Thinking: ${state.thinking}`);
843
- lines.push(`• Verbose: ${state.verbose}`);
844
- lines.push(`• Reasoning: ${state.reasoning}`);
845
- lines.push(`• Elevated: ${state.elevated}`);
846
- if (state.model?.provider || state.model?.model) {
847
- const modelStr = state.model.provider ? `${state.model.provider}/${state.model.model}` : state.model.model;
848
- lines.push(`• Model: ${modelStr}`);
849
- }
850
- }
851
- }
852
- } catch {}
853
- try {
854
- const tasks = await runtime.getTasks({
855
- roomId,
856
- agentIds: [runtime.agentId]
857
- });
858
- if (tasks.length > 0) {
859
- lines.push(`
860
- **Tasks:** ${tasks.length} pending`);
861
- }
862
- } catch {}
863
- return lines.join(`
864
- `);
865
- }
866
- var statusAction = {
867
- name: "STATUS_COMMAND",
868
- description: "Show session directive settings via /status slash command. Only activates for /status or /s prefix.",
869
- similes: ["/status", "/s"],
870
- validate: async (runtime, message) => {
871
- const textRaw = message.content?.text ?? "";
872
- const text = textRaw.toLowerCase();
873
- const hasKeyword = text.includes("/status") || text.includes("/s") || text.includes("status");
874
- const hasRegex = /^(?:\/|!)\s*(?:status|s)\b/i.test(textRaw);
875
- const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
876
- const hasInput = textRaw.trim().length > 0;
877
- if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
878
- return false;
879
- }
880
- const detection = detectCommand(textRaw);
881
- return detection.isCommand && detection.command?.key === "status";
882
- },
883
- async handler(runtime, message, _state, _options, callback) {
884
- const statusText = await buildStatusReport(runtime, message.roomId);
885
- await callback?.({ text: statusText });
886
- return {
887
- success: true,
888
- text: statusText
889
- };
890
- },
891
- examples: [
892
- [
893
- { name: "user", content: { text: "/status" } },
894
- {
895
- name: "assistant",
896
- content: {
897
- text: `**Session Status:**
898
-
899
- **Agent:** Eliza
900
- **Room:** room-456
901
-
902
- **Directives:**
903
- • Thinking: low...`
904
- }
905
- }
906
- ]
907
- ]
908
- };
909
-
910
- // src/actions/stop.ts
911
- var import_core2 = require("@elizaos/core");
912
- var stopAction = {
913
- name: "STOP_COMMAND",
914
- description: "Stop current operation or abort running tasks. Triggered by /stop, /abort, or /cancel slash commands only.",
915
- similes: ["/stop", "/abort", "/cancel"],
916
- validate: async (runtime, message) => {
917
- const textRaw = message.content?.text ?? "";
918
- const text = textRaw.toLowerCase();
919
- const hasKeyword = text.includes("/stop") || text.includes("/abort") || text.includes("/cancel") || text.includes("stop");
920
- const hasRegex = /^(?:\/|!)\s*(?:stop|abort|cancel)\b/i.test(textRaw);
921
- const hasContext = Boolean(runtime?.agentId || message?.roomId || message?.content);
922
- const hasInput = textRaw.trim().length > 0;
923
- if (!(hasKeyword && hasRegex && hasContext && hasInput)) {
924
- return false;
925
- }
926
- const detection = detectCommand(textRaw);
927
- return detection.isCommand && ["stop", "abort", "cancel"].includes(detection.command?.key ?? "");
928
- },
929
- async handler(runtime, message, _state, _options, callback) {
930
- try {
931
- await runtime.emitEvent(import_core2.EventType.HOOK_COMMAND_STOP, {
932
- runtime,
933
- sessionKey: message.roomId,
934
- messages: [],
935
- timestamp: new Date,
936
- context: {
937
- entityId: message.entityId,
938
- source: message.content?.source
939
- },
940
- command: "stop",
941
- senderId: message.entityId,
942
- commandSource: message.content?.source
943
- });
944
- } catch (err) {
945
- import_core2.logger.warn({ src: "plugin-commands", err }, "Failed to emit HOOK_COMMAND_STOP event");
946
- }
947
- const replyText = "✓ Stop requested. Current operations will be cancelled.";
948
- await callback?.({ text: replyText });
949
- return {
950
- success: true,
951
- text: replyText
952
- };
953
- },
954
- examples: [
955
- [
956
- { name: "user", content: { text: "/stop" } },
957
- {
958
- name: "assistant",
959
- content: {
960
- text: "✓ Stop requested. Current operations will be cancelled."
961
- }
962
- }
963
- ],
964
- [
965
- { name: "user", content: { text: "/abort" } },
966
- {
967
- name: "assistant",
968
- content: {
969
- text: "✓ Stop requested. Current operations will be cancelled."
970
- }
971
- }
972
- ]
973
- ]
974
- };
975
-
976
580
  // src/index.ts
977
581
  var commandRegistryProvider = {
978
582
  name: "COMMAND_REGISTRY",
979
583
  description: "Available chat commands and their descriptions",
584
+ descriptionCompressed: "Available chat commands and descriptions.",
980
585
  dynamic: true,
586
+ contexts: ["general", "automation"],
587
+ contextGate: { anyOf: ["general", "automation"] },
588
+ cacheStable: true,
589
+ cacheScope: "agent",
981
590
  async get(runtime, message, _state) {
982
591
  useRuntime(runtime.agentId);
983
592
  const text = message.content?.text ?? "";
@@ -1034,13 +643,12 @@ var commandsPlugin = {
1034
643
  name: "commands",
1035
644
  description: "Chat command system with /help, /status, /reset, etc.",
1036
645
  providers: [commandRegistryProvider],
1037
- actions: [
1038
- helpAction,
1039
- statusAction,
1040
- stopAction,
1041
- modelsAction,
1042
- commandsListAction
1043
- ],
646
+ autoEnable: {
647
+ shouldEnable: (_env, config) => {
648
+ const f = config?.features?.commands;
649
+ return f === true || typeof f === "object" && f !== null && f.enabled !== false;
650
+ }
651
+ },
1044
652
  config: {
1045
653
  COMMANDS_ENABLED: "true",
1046
654
  COMMANDS_CONFIG_ENABLED: "false",
@@ -1064,7 +672,7 @@ var commandsPlugin = {
1064
672
  if (hasCommand("hello world")) {
1065
673
  throw new Error("Should not detect plain text as command");
1066
674
  }
1067
- import_core3.logger.success("Command prefix detection works correctly");
675
+ import_core.logger.success("Command prefix detection works correctly");
1068
676
  }
1069
677
  },
1070
678
  {
@@ -1080,7 +688,7 @@ var commandsPlugin = {
1080
688
  if (detection.command?.args[0] !== "high") {
1081
689
  throw new Error(`Expected arg 'high', got '${detection.command?.args[0]}'`);
1082
690
  }
1083
- import_core3.logger.success("Command argument parsing works correctly");
691
+ import_core.logger.success("Command argument parsing works correctly");
1084
692
  }
1085
693
  },
1086
694
  {
@@ -1094,7 +702,7 @@ var commandsPlugin = {
1094
702
  if (normalized2 !== "/help") {
1095
703
  throw new Error(`Expected '/help', got '${normalized2}'`);
1096
704
  }
1097
- import_core3.logger.success("Command normalization works correctly");
705
+ import_core.logger.success("Command normalization works correctly");
1098
706
  }
1099
707
  },
1100
708
  {
@@ -1107,7 +715,7 @@ var commandsPlugin = {
1107
715
  if (cmd.key !== "help") {
1108
716
  throw new Error(`Expected key 'help', got '${cmd.key}'`);
1109
717
  }
1110
- import_core3.logger.success("Command alias lookup works correctly");
718
+ import_core.logger.success("Command alias lookup works correctly");
1111
719
  }
1112
720
  },
1113
721
  {
@@ -1120,7 +728,7 @@ var commandsPlugin = {
1120
728
  if (cmd.key !== "status") {
1121
729
  throw new Error(`Expected key 'status', got '${cmd.key}'`);
1122
730
  }
1123
- import_core3.logger.success("Command key lookup works correctly");
731
+ import_core.logger.success("Command key lookup works correctly");
1124
732
  }
1125
733
  }
1126
734
  ]
@@ -1140,7 +748,7 @@ var commandsPlugin = {
1140
748
  if (!cmdHelp || !cmdStatus) {
1141
749
  throw new Error("Should have help and status commands");
1142
750
  }
1143
- import_core3.logger.success("Command registry works correctly");
751
+ import_core.logger.success("Command registry works correctly");
1144
752
  }
1145
753
  },
1146
754
  {
@@ -1162,7 +770,7 @@ var commandsPlugin = {
1162
770
  if (notFound) {
1163
771
  throw new Error("Should not find unregistered command");
1164
772
  }
1165
- import_core3.logger.success("Custom command registration works correctly");
773
+ import_core.logger.success("Custom command registration works correctly");
1166
774
  }
1167
775
  },
1168
776
  {
@@ -1176,14 +784,14 @@ var commandsPlugin = {
1176
784
  if (!allStatus) {
1177
785
  throw new Error("All returned commands should be in status category");
1178
786
  }
1179
- import_core3.logger.success("Command categorization works correctly");
787
+ import_core.logger.success("Command categorization works correctly");
1180
788
  }
1181
789
  }
1182
790
  ]
1183
791
  }
1184
792
  ],
1185
793
  async init(config, runtime) {
1186
- import_core3.logger.log("[plugin-commands] Initializing command system");
794
+ import_core.logger.log("[plugin-commands] Initializing command system");
1187
795
  initForRuntime(runtime.agentId);
1188
796
  const configEnabled = config.COMMANDS_CONFIG_ENABLED === "true";
1189
797
  const debugEnabled = config.COMMANDS_DEBUG_ENABLED === "true";
@@ -1206,9 +814,9 @@ var commandsPlugin = {
1206
814
  restartCmd.enabled = restartEnabled;
1207
815
  }
1208
816
  const enabledCount = getEnabledCommands().length;
1209
- import_core3.logger.log(`[plugin-commands] ${enabledCount} commands enabled for agent ${runtime.agentId}`);
817
+ import_core.logger.log(`[plugin-commands] ${enabledCount} commands enabled for agent ${runtime.agentId}`);
1210
818
  }
1211
819
  };
1212
820
  var src_default = commandsPlugin;
1213
821
 
1214
- //# debugId=29584248BB32069264756E2164756E21
822
+ //# debugId=00FC26667A6E870A64756E2164756E21