@agent-smith/cli 0.0.115 → 0.0.118

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.
Files changed (114) hide show
  1. package/README.md +274 -34
  2. package/dist/cli.js +4 -8
  3. package/dist/cmd/{clicmds/aliases.d.ts → aliases.d.ts} +1 -1
  4. package/dist/cmd/{clicmds/aliases.js → aliases.js} +1 -26
  5. package/dist/cmd/{clicmds/base.js → base.js} +21 -17
  6. package/dist/cmd/build.d.ts +9 -0
  7. package/dist/cmd/build.js +59 -0
  8. package/dist/cmd/callbacks.d.ts +11 -0
  9. package/dist/cmd/callbacks.js +90 -0
  10. package/dist/cmd/cmds.d.ts +8 -9
  11. package/dist/cmd/cmds.js +134 -103
  12. package/dist/cmd/features.d.ts +6 -0
  13. package/dist/cmd/features.js +57 -0
  14. package/dist/cmd/{sys/read_cmds.d.ts → read_cmds.d.ts} +1 -1
  15. package/dist/cmd/{sys/read_cmds.js → read_cmds.js} +1 -1
  16. package/dist/cmd/user_cmds.d.ts +3 -0
  17. package/dist/cmd/user_cmds.js +23 -0
  18. package/dist/index.js +11 -11
  19. package/dist/main.d.ts +3 -38
  20. package/dist/main.js +3 -37
  21. package/dist/state.d.ts +6 -0
  22. package/dist/state.js +8 -0
  23. package/dist/utils.d.ts +8 -0
  24. package/dist/utils.js +50 -0
  25. package/package.json +10 -20
  26. package/dist/cmd/clicmds/cmds.d.ts +0 -7
  27. package/dist/cmd/clicmds/cmds.js +0 -135
  28. package/dist/cmd/clicmds/updateconf.d.ts +0 -3
  29. package/dist/cmd/clicmds/updateconf.js +0 -74
  30. package/dist/cmd/lib/actions/cmd.d.ts +0 -6
  31. package/dist/cmd/lib/actions/cmd.js +0 -154
  32. package/dist/cmd/lib/actions/read.d.ts +0 -3
  33. package/dist/cmd/lib/actions/read.js +0 -17
  34. package/dist/cmd/lib/adaptaters/cmd.d.ts +0 -2
  35. package/dist/cmd/lib/adaptaters/cmd.js +0 -39
  36. package/dist/cmd/lib/agents/cmd.d.ts +0 -3
  37. package/dist/cmd/lib/agents/cmd.js +0 -11
  38. package/dist/cmd/lib/mcp.d.ts +0 -16
  39. package/dist/cmd/lib/mcp.js +0 -105
  40. package/dist/cmd/lib/options_parsers.d.ts +0 -7
  41. package/dist/cmd/lib/options_parsers.js +0 -52
  42. package/dist/cmd/lib/tasks/cmd.d.ts +0 -4
  43. package/dist/cmd/lib/tasks/cmd.js +0 -419
  44. package/dist/cmd/lib/tasks/conf.d.ts +0 -6
  45. package/dist/cmd/lib/tasks/conf.js +0 -131
  46. package/dist/cmd/lib/tasks/read.d.ts +0 -14
  47. package/dist/cmd/lib/tasks/read.js +0 -186
  48. package/dist/cmd/lib/tasks/utils.d.ts +0 -8
  49. package/dist/cmd/lib/tasks/utils.js +0 -48
  50. package/dist/cmd/lib/tools.d.ts +0 -15
  51. package/dist/cmd/lib/tools.js +0 -147
  52. package/dist/cmd/lib/utils.d.ts +0 -3
  53. package/dist/cmd/lib/utils.js +0 -54
  54. package/dist/cmd/lib/workflows/cmd.d.ts +0 -3
  55. package/dist/cmd/lib/workflows/cmd.js +0 -230
  56. package/dist/cmd/lib/workflows/read.d.ts +0 -6
  57. package/dist/cmd/lib/workflows/read.js +0 -61
  58. package/dist/cmd/sys/clipboard.d.ts +0 -3
  59. package/dist/cmd/sys/clipboard.js +0 -33
  60. package/dist/cmd/sys/delete_file.d.ts +0 -2
  61. package/dist/cmd/sys/delete_file.js +0 -10
  62. package/dist/cmd/sys/dirs.d.ts +0 -2
  63. package/dist/cmd/sys/dirs.js +0 -9
  64. package/dist/cmd/sys/execute.d.ts +0 -13
  65. package/dist/cmd/sys/execute.js +0 -48
  66. package/dist/cmd/sys/read.d.ts +0 -3
  67. package/dist/cmd/sys/read.js +0 -21
  68. package/dist/cmd/sys/read_conf.d.ts +0 -6
  69. package/dist/cmd/sys/read_conf.js +0 -12
  70. package/dist/cmd/sys/read_features.d.ts +0 -3
  71. package/dist/cmd/sys/read_features.js +0 -112
  72. package/dist/cmd/sys/read_task.d.ts +0 -6
  73. package/dist/cmd/sys/read_task.js +0 -23
  74. package/dist/cmd/sys/read_yml_file.d.ts +0 -5
  75. package/dist/cmd/sys/read_yml_file.js +0 -11
  76. package/dist/cmd/sys/run_python.d.ts +0 -6
  77. package/dist/cmd/sys/run_python.js +0 -39
  78. package/dist/conf.d.ts +0 -14
  79. package/dist/conf.js +0 -166
  80. package/dist/const.d.ts +0 -3
  81. package/dist/const.js +0 -24
  82. package/dist/db/db.d.ts +0 -4
  83. package/dist/db/db.js +0 -23
  84. package/dist/db/read.d.ts +0 -34
  85. package/dist/db/read.js +0 -128
  86. package/dist/db/schemas.d.ts +0 -2
  87. package/dist/db/schemas.js +0 -105
  88. package/dist/db/write.d.ts +0 -15
  89. package/dist/db/write.js +0 -376
  90. package/dist/interfaces.d.ts +0 -165
  91. package/dist/interfaces.js +0 -1
  92. package/dist/state/backends.d.ts +0 -7
  93. package/dist/state/backends.js +0 -159
  94. package/dist/state/chat.d.ts +0 -7
  95. package/dist/state/chat.js +0 -10
  96. package/dist/state/features.d.ts +0 -8
  97. package/dist/state/features.js +0 -35
  98. package/dist/state/plugins.d.ts +0 -6
  99. package/dist/state/plugins.js +0 -27
  100. package/dist/state/state.d.ts +0 -20
  101. package/dist/state/state.js +0 -80
  102. package/dist/state/tasks.d.ts +0 -6
  103. package/dist/state/tasks.js +0 -28
  104. package/dist/utils/perf.d.ts +0 -9
  105. package/dist/utils/perf.js +0 -63
  106. package/dist/utils/text.d.ts +0 -6
  107. package/dist/utils/text.js +0 -41
  108. package/dist/utils/user_msgs.d.ts +0 -5
  109. package/dist/utils/user_msgs.js +0 -19
  110. /package/dist/cmd/{clicmds/base.d.ts → base.d.ts} +0 -0
  111. /package/dist/{cmd/options.d.ts → options.d.ts} +0 -0
  112. /package/dist/{cmd/options.js → options.js} +0 -0
  113. /package/dist/{cmd/lib/user_msgs.d.ts → user_msgs.d.ts} +0 -0
  114. /package/dist/{cmd/lib/user_msgs.js → user_msgs.js} +0 -0
@@ -0,0 +1,90 @@
1
+ import ora from "ora";
2
+ import { printToken } from "../utils.js";
3
+ import { default as color } from "ansi-colors";
4
+ import { utils } from "@agent-smith/core";
5
+ const useInferenceCallbacks = (agentName, options) => {
6
+ let emittedThinkingTokens = 0;
7
+ let emittedTokens = 0;
8
+ let isToolCallInProgress = false;
9
+ let isToolCallRunning = false;
10
+ const perfTimer = utils.usePerfTimer();
11
+ const spinner = ora({ discardStdin: false, color: "green" });
12
+ //const thinkIcon = " ";
13
+ //const talkIcon = "🏁";
14
+ const toolIcon = "⚒️";
15
+ const onToken = (t, from) => {
16
+ if (emittedTokens == 0) {
17
+ perfTimer.start();
18
+ //console.log(talkIcon, from);
19
+ }
20
+ //if (!isToolCallRunning) {
21
+ printToken(t, options?.showTokens);
22
+ ++emittedTokens;
23
+ //}
24
+ };
25
+ const onStartThinking = (from) => {
26
+ //console.log("START THINKING");
27
+ if (!options?.debug && !options?.verbose) {
28
+ spinner.start(`${from} is thinking ...`);
29
+ }
30
+ };
31
+ const onEndThinking = (from) => {
32
+ //console.log("END THINKING");
33
+ if (!options?.debug && !options?.verbose) {
34
+ spinner.stop();
35
+ let msg = `${color.dim("Thinking")} ${from} ${color.bold(emittedThinkingTokens.toString())} ${color.dim("tokens")}`;
36
+ msg = msg + " " + color.dim(perfTimer.time());
37
+ //const space = agentName == from ? thinkIcon + " " : ` ${thinkIcon} `;
38
+ const space = agentName == from ? "" : " ";
39
+ console.log(space + msg);
40
+ }
41
+ emittedThinkingTokens = 0;
42
+ };
43
+ const onThinkingToken = (t, from) => {
44
+ if (options?.debug || options?.verbose) {
45
+ printToken(t, options?.showTokens, options?.showTokens ? false : true);
46
+ }
47
+ else {
48
+ let msg = `${color.dim("Thinking")} ${from} ${color.bold(emittedThinkingTokens.toString())} ${color.dim("tokens")}`;
49
+ msg = msg + " " + color.dim(perfTimer.time());
50
+ const space = agentName == from ? "" : " ";
51
+ spinner.prefixText = space;
52
+ spinner.text = msg;
53
+ }
54
+ emittedThinkingTokens++;
55
+ };
56
+ const onToolCallInProgress = (tc, from) => {
57
+ const txt = color.dim("Preparing tool call") + ` ${from} ${color.yellowBright(tc[tc.length - 1].name)} ...`;
58
+ if (!isToolCallInProgress) {
59
+ spinner.start(txt);
60
+ isToolCallInProgress = true;
61
+ }
62
+ else {
63
+ spinner.text = txt;
64
+ }
65
+ };
66
+ const onToolCall = (tc, type, from) => {
67
+ isToolCallInProgress = false;
68
+ isToolCallRunning = true;
69
+ spinner.stop();
70
+ //console.log("TC START", type, "agent", agentName, "/", from);
71
+ const icon = agentName == from ? toolIcon + " " : " " + toolIcon + " ";
72
+ console.log(icon, color.bold(from), "=>", type, `${color.yellowBright(tc.name)}`, tc.arguments);
73
+ };
74
+ const onToolCallEnd = (tc, tr, type, from) => {
75
+ isToolCallRunning = false;
76
+ if (options?.debug) {
77
+ console.log(tc.name, type, "from", from + ":\n", tr);
78
+ }
79
+ };
80
+ return {
81
+ onToken,
82
+ onStartThinking,
83
+ onEndThinking,
84
+ onThinkingToken,
85
+ onToolCallInProgress,
86
+ onToolCall,
87
+ onToolCallEnd,
88
+ };
89
+ };
90
+ export { useInferenceCallbacks, };
@@ -1,9 +1,8 @@
1
- import { InferenceOptions } from "@locallm/types/dist/inference.js";
2
- import { Command } from "commander";
3
- import type { McpClient } from "../main.js";
4
- import type { Agent } from "@agent-smith/agent";
5
- declare const program: Command;
6
- declare function chat(program: Command, options: InferenceOptions, agent: Agent, mcpServers: Array<McpClient>): Promise<void>;
7
- declare function buildCmds(): Promise<Command>;
8
- declare function parseCmd(program: Command): Promise<void>;
9
- export { buildCmds, chat, parseCmd, program };
1
+ import { Command } from 'commander';
2
+ import type { FeatureSpec } from '@agent-smith/types';
3
+ declare function initUserCmds(cmdFeats: Record<string, FeatureSpec>, program: Command): Promise<Array<Command>>;
4
+ declare function resetDbCmd(): Promise<any>;
5
+ declare function recreateDbCmd(): Promise<any>;
6
+ declare function processAgentsCmd(args: Array<string>, options: Record<string, any>): Promise<void>;
7
+ declare function processAgentCmd(args: Array<string>, options: Record<string, any>): Promise<any>;
8
+ export { initUserCmds, processAgentCmd, processAgentsCmd, resetDbCmd, recreateDbCmd, };
package/dist/cmd/cmds.js CHANGED
@@ -1,111 +1,142 @@
1
- import { input } from "@inquirer/prompts";
2
- import { Command } from "commander";
3
- import { query } from "../cli.js";
4
- import { readAliases, readFeatures } from "../db/read.js";
5
- import { chatInferenceParams, chatTemplate } from "../state/chat.js";
6
- import { isChatMode, runMode } from "../state/state.js";
7
- import { initCommandsFromAliases } from "./clicmds/aliases.js";
8
- import { initBaseCommands } from "./clicmds/base.js";
9
- import { initUserCmds } from "./clicmds/cmds.js";
10
- //import { usePerfTimer } from "../main.js";
11
- const program = new Command();
12
- async function chat(program, options, agent, mcpServers) {
13
- //console.log("CHAT OPTS", options);
14
- const data = { message: '>', default: "" };
15
- const prompt = await input(data);
16
- if (prompt == "/q") {
17
- isChatMode.value = false;
18
- if (runMode.value == "cmd") {
19
- process.exit(0);
1
+ import colors from "ansi-colors";
2
+ import { Option } from 'commander';
3
+ import path from "path";
4
+ import YAML from 'yaml';
5
+ import { db, conf, utils, state, getFeatureSpec } from "@agent-smith/core";
6
+ import { parseCommandArgs } from "../utils.js";
7
+ import { readCmd } from "./read_cmds.js";
8
+ import { runtimeDataError } from "../user_msgs.js";
9
+ import { allOptions, displayOptions, inferenceOptions, ioOptions } from "../options.js";
10
+ import { runMode } from "../state.js";
11
+ async function initUserCmds(cmdFeats, program) {
12
+ const features = Object.values(cmdFeats);
13
+ const usrCmds = [];
14
+ for (const feat of features) {
15
+ //console.log("Init cmd", feat);
16
+ const hasVariables = feat?.variables ? true : false;
17
+ const vars = hasVariables ? feat.variables : {};
18
+ let desc = "";
19
+ let fullName = "";
20
+ if (hasVariables) {
21
+ desc = vars.description;
22
+ fullName = vars.name;
20
23
  }
21
24
  else {
22
- mcpServers.forEach(async (s) => await s.stop());
23
- await query(program);
25
+ throw new Error(`user command ${feat.name}: provide a name and description`);
24
26
  }
27
+ //console.log("F", feat);
28
+ // @ts-ignore
29
+ const cmd = program.command(fullName)
30
+ .description(desc)
31
+ .action(async (...args) => {
32
+ const ca = parseCommandArgs(args);
33
+ const cmdPath = path.join(feat.path, feat.name + "." + feat.ext);
34
+ const c = await readCmd(feat.name, cmdPath);
35
+ if (!c) {
36
+ runtimeDataError(`can not import command ${feat.name}`);
37
+ throw new Error();
38
+ }
39
+ await c.run(ca.args, ca.options);
40
+ });
41
+ if (hasVariables) {
42
+ if (vars?.options) {
43
+ for (const opt of vars.options) {
44
+ if (Array.isArray(opt)) {
45
+ cmd.addOption(new Option(opt[0], opt[1]));
46
+ }
47
+ else {
48
+ // predefined option
49
+ switch (opt) {
50
+ case "all":
51
+ allOptions.forEach(o => cmd.addOption(o));
52
+ break;
53
+ case "display":
54
+ displayOptions.forEach(o => cmd.addOption(o));
55
+ break;
56
+ case "inference":
57
+ inferenceOptions.forEach(o => cmd.addOption(o));
58
+ break;
59
+ case "io":
60
+ ioOptions.forEach(o => cmd.addOption(o));
61
+ default:
62
+ break;
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ usrCmds.push(cmd);
69
+ }
70
+ //console.log("USRCMDS", usrCmds.map(c => c.name()))
71
+ return usrCmds;
72
+ }
73
+ async function resetDbCmd() {
74
+ if (runMode.value == "cli") {
75
+ console.log("This command can not be run in cli mode");
76
+ return;
25
77
  }
26
- //console.log("CHAT HIST", agent.history);
27
- //options.history = undefined;
28
- //console.log("RUN W PROMPT", prompt);
29
- await agent.run(prompt, chatInferenceParams, options, chatTemplate ? chatTemplate : undefined);
30
- console.log();
31
- await chat(program, options, agent, mcpServers);
78
+ utils.deleteFileIfExists(conf.dbPath);
79
+ console.log("Config database reset ok. Run the conf command to recreate it");
32
80
  }
33
- async function buildCmds() {
34
- //program.allowUnknownOption(true);
35
- //const perf = usePerfTimer();
36
- initBaseCommands(program);
37
- //perf.measure("initBaseCommands");
38
- const aliases = readAliases();
39
- //perf.measure("readAliases");
40
- const feats = readFeatures();
41
- //perf.measure("readFeatures");
42
- initCommandsFromAliases(program, aliases, feats);
43
- //perf.measure("initCommandsFromAliases");
44
- await initUserCmds(feats.cmd, program);
45
- //perf.measure("initUserCmds");
46
- //perf.measure("cmds for each");
47
- //perf.final("buildCmds");
48
- return program;
81
+ async function recreateDbCmd() {
82
+ if (runMode.value == "cli") {
83
+ console.log("This command can not be run in cli mode");
84
+ return;
85
+ }
86
+ await conf.recreateDbFromConf();
87
+ }
88
+ async function processAgentsCmd(args, options) {
89
+ if (options?.conf) {
90
+ if (!state.isAgentSettingsInitialized.value) {
91
+ state.initAgentSettings();
92
+ }
93
+ //console.log("PTS", tasksSettings);
94
+ console.log(YAML.stringify({ "agents": state.agentSettings }));
95
+ }
96
+ else {
97
+ const ts = Object.keys(db.readFeaturesType("agent")).sort();
98
+ console.table(ts);
99
+ }
49
100
  }
50
- /*async function buildCmds(): Promise<Command> {
51
- // Performance measurement start
52
- const startTime = process.hrtime.bigint();
53
- const measurements: { name: string; time: number; percentage: number }[] = [];
54
- let lastTime = startTime;
55
-
56
- function measureFunction(name: string) {
57
- const currentTime = process.hrtime.bigint();
58
- const elapsedNs = Number(currentTime - lastTime);
59
- const elapsedSec = elapsedNs / 1_000_000_000;
60
- measurements.push({ name, time: elapsedSec, percentage: 0 });
61
- lastTime = currentTime;
101
+ async function processAgentCmd(args, options) {
102
+ //console.log("TASK OPTS", options);
103
+ if (args.length == 0) {
104
+ console.warn("Provide an agent name");
105
+ return;
106
+ }
107
+ const { found, path } = getFeatureSpec(args[0], "agent");
108
+ if (!found) {
109
+ console.warn(`Agent ${args[0]} not found`);
110
+ return;
111
+ }
112
+ if (options?.reset) {
113
+ db.deleteAgentSetting(args[0]);
114
+ console.log("Agent", args[0], "reset ok");
115
+ return;
116
+ }
117
+ //console.log("RT", path)
118
+ const res = utils.readAgent(path);
119
+ if (!res.found) {
120
+ throw new Error(`Agent ${args[0]}, ${path} not found`);
121
+ }
122
+ //const ts = JSON.parse(res.ymlAgent);
123
+ console.log(res.ymlAgent);
124
+ if (Object.keys(options).length > 0) {
125
+ db.upsertAgentSettings(args[0], options);
126
+ }
127
+ const s = db.readAgentSetting(args[0]);
128
+ if (s.found) {
129
+ const sts = s.settings;
130
+ delete sts.id;
131
+ delete sts.name;
132
+ const display = {};
133
+ for (const [k, v] of Object.entries(sts)) {
134
+ if (v) {
135
+ display[k] = v;
136
+ }
137
+ }
138
+ console.log(colors.dim("Settings") + ":", display);
62
139
  }
63
-
64
- //program.allowUnknownOption(true);
65
- measureFunction("start");
66
- initBaseCommands(program);
67
-
68
- measureFunction("initBaseCommands");
69
- const aliases = readAliases();
70
-
71
- measureFunction("readAliases");
72
- const feats = readFeatures();
73
-
74
- measureFunction("readFeatures");
75
- initCommandsFromAliases(program, aliases, feats);
76
-
77
- measureFunction("initCommandsFromAliases");
78
- const cmds = await initUserCmds(feats.cmd);
79
-
80
- measureFunction("initUserCmds");
81
- cmds.forEach(c => {
82
- //console.log("Add cmd", c.name());
83
- program.addCommand(c)
84
- });
85
- measureFunction("cmds.forEach");
86
-
87
- // Calculate percentages and display results
88
- const totalTime = Number(process.hrtime.bigint() - startTime) / 1_000_000_000;
89
- measurements.forEach(m => {
90
- m.percentage = (m.time / totalTime) * 100;
91
- });
92
-
93
- console.log("\nPerformance Measurements for buildCmds:");
94
- measurements.forEach(m => {
95
- console.log(`${m.name}: ${m.time.toFixed(6)}s (${m.percentage.toFixed(2)}%)`);
96
- });
97
- console.log(`Total time: ${totalTime.toFixed(6)}s\n`);
98
-
99
- return program
100
- }*/
101
- async function parseCmd(program) {
102
- program.name('Agent Smith terminal client');
103
- program.description('Terminal agents toolkit');
104
- await program.parseAsync();
105
- //console.log("CMD END");
106
- //exit(0)
107
- /*if (isChatMode.value) {
108
- await chat(program)
109
- }*/
140
+ //console.log(JSON.stringify(ts, null, " "));
110
141
  }
111
- export { buildCmds, chat, parseCmd, program };
142
+ export { initUserCmds, processAgentCmd, processAgentsCmd, resetDbCmd, recreateDbCmd, };
@@ -0,0 +1,6 @@
1
+ import type { InferenceResult } from "@agent-smith/types";
2
+ declare function executeWorkflowCmd(name: string, wargs: Array<any>): Promise<any>;
3
+ declare function executeTaskCmd(name: string, targs?: Array<any>): Promise<InferenceResult>;
4
+ declare function executeAgentCmd(name: string, targs?: Array<any>): Promise<InferenceResult>;
5
+ declare function executeActionCmd(name: string, aargs: Array<any>, quiet?: boolean): Promise<any>;
6
+ export { executeWorkflowCmd, executeTaskCmd, executeActionCmd, executeAgentCmd, };
@@ -0,0 +1,57 @@
1
+ import { executeAction, executeWorkflow, getAgentPrompt, getInputFromOptions, useAgentExecutor } from "@agent-smith/core";
2
+ import { confirmToolUsage, parseCommandArgs } from "../utils.js";
3
+ import { useInferenceCallbacks } from "./callbacks.js";
4
+ import { chat } from "./build.js";
5
+ async function executeWorkflowCmd(name, wargs) {
6
+ //console.log("WF INITIAL ARGS", typeof wargs, wargs.slice(0, -1));
7
+ const { args, options } = parseCommandArgs(wargs);
8
+ //console.log("WF ARGS", typeof args, args);
9
+ //console.log("WF OPTS", options);
10
+ return await executeWorkflow(name, args, options);
11
+ }
12
+ async function executeTaskCmd(name, targs = []) {
13
+ const ca = parseCommandArgs(targs);
14
+ //console.log("ARGS", ca);
15
+ const inferenceCallbacks = useInferenceCallbacks(name, ca.options);
16
+ const options = { ...ca.options, ...inferenceCallbacks };
17
+ const prompt = await getAgentPrompt(name, ca.args, options);
18
+ const tsk = await useAgentExecutor(name, { prompt: prompt }, options);
19
+ const tr = await tsk.execute();
20
+ //console.log("TR", tr);
21
+ if (ca?.options.chat) {
22
+ await chat(options, tsk.agent, tsk.mcpServers);
23
+ }
24
+ return tr;
25
+ }
26
+ async function executeAgentCmd(name, targs = []) {
27
+ //console.log("EXEC AGENT", name);
28
+ const ca = parseCommandArgs(targs);
29
+ ca.options.isAgent = true;
30
+ ca.options.confirmToolUsage = confirmToolUsage;
31
+ const inferenceCallbacks = useInferenceCallbacks(name, ca.options);
32
+ const options = { ...ca.options, ...inferenceCallbacks };
33
+ const prompt = await getAgentPrompt(name, ca.args, options);
34
+ const tsk = await useAgentExecutor(name, { prompt: prompt }, options);
35
+ //console.log("CA", ca);
36
+ const tr = await tsk.execute();
37
+ //console.dir(tsk.agent.history, { depth: 6 });
38
+ if (ca?.options.chat) {
39
+ await chat(options, tsk.agent, tsk.mcpServers);
40
+ }
41
+ return tr;
42
+ }
43
+ async function executeActionCmd(name, aargs, quiet = false) {
44
+ //console.log("AARGs", aargs)
45
+ const { args, options } = parseCommandArgs(aargs);
46
+ //console.log("CMDA", args)
47
+ const params = args;
48
+ const ip = await getInputFromOptions(options);
49
+ if (ip !== null) {
50
+ params.push(ip);
51
+ }
52
+ if (options?.debug) {
53
+ console.log("Action", name, "params", params);
54
+ }
55
+ return await executeAction(name, params, options, quiet);
56
+ }
57
+ export { executeWorkflowCmd, executeTaskCmd, executeActionCmd, executeAgentCmd, };
@@ -1,4 +1,4 @@
1
- import type { UserCmdDef } from "../../interfaces.js";
1
+ import type { UserCmdDef } from "@agent-smith/types";
2
2
  declare function readCmd(name: string, cmdPath: string): Promise<UserCmdDef | null>;
3
3
  declare function readUserCmd(name: string, cmdPath: string): Promise<{
4
4
  found: boolean;
@@ -1,5 +1,5 @@
1
1
  import { pathToFileURL } from 'url';
2
- import { runtimeWarning } from "../lib/user_msgs.js";
2
+ import { runtimeWarning } from "../user_msgs.js";
3
3
  async function readCmd(name, cmdPath) {
4
4
  const url = pathToFileURL(cmdPath).href;
5
5
  let _cmd;
@@ -0,0 +1,3 @@
1
+ import type { Features } from "@agent-smith/types";
2
+ declare function getUserCmdsData(feats: Features): Promise<Features>;
3
+ export { getUserCmdsData, };
@@ -0,0 +1,23 @@
1
+ import path from "path";
2
+ import { readUserCmd } from "./read_cmds.js";
3
+ async function getUserCmdsData(feats) {
4
+ for (const feat of feats.cmd) {
5
+ const cmdPath = path.join(feat.path, feat.name + "." + feat.ext);
6
+ const { found, userCmd } = await readUserCmd(feat.name, cmdPath);
7
+ console.log("USR CMD", userCmd);
8
+ if (found) {
9
+ feat.variables = {
10
+ description: userCmd.description,
11
+ name: userCmd.name,
12
+ };
13
+ if (userCmd?.options) {
14
+ feat.variables.options = userCmd.options;
15
+ }
16
+ }
17
+ else {
18
+ throw new Error(`user command ${feat.name} not found at ${cmdPath}`);
19
+ }
20
+ }
21
+ return feats;
22
+ }
23
+ export { getUserCmdsData, };
package/dist/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import { argv } from 'process';
3
3
  import { query } from "./cli.js";
4
- import { resetDbCmd } from './cmd/clicmds/cmds.js';
5
- import { updateConfCmd } from './cmd/clicmds/updateconf.js';
6
- import { buildCmds, parseCmd } from './cmd/cmds.js';
7
- import { formatMode, init, inputMode, isChatMode, outputMode, runMode } from './state/state.js';
8
- //import { usePerfTimer } from './main.js';
4
+ import { resetDbCmd } from './cmd/cmds.js';
5
+ import { state, conf } from "@agent-smith/core";
6
+ import { isChatMode, runMode } from './state.js';
7
+ import { buildCmds, parseCmd } from './cmd/build.js';
9
8
  async function main() {
10
9
  //const perf = usePerfTimer();
11
10
  const nargs = argv.length;
@@ -14,7 +13,7 @@ async function main() {
14
13
  }
15
14
  else if (nargs >= 3) {
16
15
  if (argv[2] == "conf") {
17
- await updateConfCmd(argv.slice(-1));
16
+ await conf.updateConfCmd(argv.slice(-1));
18
17
  return;
19
18
  }
20
19
  else if (argv[2] == "reset") {
@@ -23,11 +22,12 @@ async function main() {
23
22
  }
24
23
  }
25
24
  //perf.measure("base");
26
- await init();
25
+ await state.init();
27
26
  //perf.measure("init");
28
27
  const program = await buildCmds();
29
28
  //perf.measure("buildCmds");
30
29
  //perf.final("index start");
30
+ // @ts-ignore
31
31
  program.hook('preAction', async (thisCommand, actionCommand) => {
32
32
  const options = actionCommand.opts();
33
33
  //console.log("POPTS", options)
@@ -36,16 +36,16 @@ async function main() {
36
36
  isChatMode.value = true;
37
37
  }
38
38
  if (options?.clipboardInput !== undefined) {
39
- inputMode.value = "clipboard";
39
+ state.inputMode.value = "clipboard";
40
40
  }
41
41
  if (options?.inputFile !== undefined) {
42
- inputMode.value = "promptfile";
42
+ state.inputMode.value = "promptfile";
43
43
  }
44
44
  if (options?.markdownOutput !== undefined) {
45
- formatMode.value = "markdown";
45
+ state.formatMode.value = "markdown";
46
46
  }
47
47
  if (options?.clipboardOutput !== undefined) {
48
- outputMode.value = "clipboard";
48
+ state.outputMode.value = "clipboard";
49
49
  }
50
50
  });
51
51
  switch (runMode.value) {
package/dist/main.d.ts CHANGED
@@ -1,38 +1,3 @@
1
- import { updateConfCmd } from "./cmd/clicmds/updateconf.js";
2
- import { executeAction } from "./cmd/lib/actions/cmd.js";
3
- import { McpClient } from "./cmd/lib/mcp.js";
4
- import { parseCommandArgs } from "./cmd/lib/options_parsers.js";
5
- import { executeTask } from "./cmd/lib/tasks/cmd.js";
6
- import { readTask } from "./cmd/lib/tasks/read.js";
7
- import { openTaskSpec } from "./cmd/lib/tasks/utils.js";
8
- import { extractToolDoc } from "./cmd/lib/tools.js";
9
- import { executeWorkflow } from "./cmd/lib/workflows/cmd.js";
10
- import { readWorkflow } from "./cmd/lib/workflows/read.js";
11
- import { allOptions, displayOptions, inferenceOptions, ioOptions } from "./cmd/options.js";
12
- import { writeToClipboard } from "./cmd/sys/clipboard.js";
13
- import { execute, run } from "./cmd/sys/execute.js";
14
- import { readConf } from "./cmd/sys/read_conf.js";
15
- import { createConfigFile, getConfigPath, processConfPath, updateConfigFile } from "./conf.js";
16
- import { initDb } from "./db/db.js";
17
- import { readBackends, readFeaturesType, readFilePaths, readTool } from "./db/read.js";
18
- import { upsertTaskSettings } from "./db/write.js";
19
- import { FeatureType, TaskSettings } from "./interfaces.js";
20
- import { backend, setBackend } from "./state/backends.js";
21
- import { init, initState, isStateReady, pluginDataDir } from "./state/state.js";
22
- import { getTaskSettings } from "./state/tasks.js";
23
- import { usePerfTimer } from "./utils/perf.js";
24
- import { extractBetweenTags, splitThinking } from "./utils/text.js";
25
- declare const db: {
26
- init: typeof initDb;
27
- readFilePaths: typeof readFilePaths;
28
- readFeaturesType: typeof readFeaturesType;
29
- readTool: typeof readTool;
30
- getTaskSettings: typeof getTaskSettings;
31
- upsertTaskSettings: typeof upsertTaskSettings;
32
- readBackends: typeof readBackends;
33
- };
34
- declare const fs: {
35
- openTaskSpec: typeof openTaskSpec;
36
- readWorkflow: typeof readWorkflow;
37
- };
38
- export { allOptions, backend, createConfigFile, db, displayOptions, execute, executeAction, executeTask, executeWorkflow, extractBetweenTags, extractToolDoc, FeatureType, fs, getConfigPath, inferenceOptions, init, initState, ioOptions, isStateReady, McpClient, openTaskSpec, parseCommandArgs, pluginDataDir, processConfPath, readConf, readTask, run, setBackend, splitThinking, TaskSettings, updateConfCmd, updateConfigFile, usePerfTimer, writeToClipboard, };
1
+ import { displayOptions, ioOptions, inferenceOptions, allOptions } from "./options.js";
2
+ import { parseCommandArgs } from "./utils.js";
3
+ export { displayOptions, ioOptions, inferenceOptions, allOptions, parseCommandArgs, };
package/dist/main.js CHANGED
@@ -1,37 +1,3 @@
1
- import { updateConfCmd } from "./cmd/clicmds/updateconf.js";
2
- import { executeAction } from "./cmd/lib/actions/cmd.js";
3
- import { McpClient } from "./cmd/lib/mcp.js";
4
- import { parseCommandArgs } from "./cmd/lib/options_parsers.js";
5
- import { executeTask } from "./cmd/lib/tasks/cmd.js";
6
- import { readTask } from "./cmd/lib/tasks/read.js";
7
- import { openTaskSpec } from "./cmd/lib/tasks/utils.js";
8
- import { extractToolDoc } from "./cmd/lib/tools.js";
9
- import { executeWorkflow } from "./cmd/lib/workflows/cmd.js";
10
- import { readWorkflow } from "./cmd/lib/workflows/read.js";
11
- import { allOptions, displayOptions, inferenceOptions, ioOptions } from "./cmd/options.js";
12
- import { writeToClipboard } from "./cmd/sys/clipboard.js";
13
- import { execute, run } from "./cmd/sys/execute.js";
14
- import { readConf } from "./cmd/sys/read_conf.js";
15
- import { createConfigFile, getConfigPath, processConfPath, updateConfigFile } from "./conf.js";
16
- import { initDb } from "./db/db.js";
17
- import { readBackends, readFeaturesType, readFilePaths, readTool } from "./db/read.js";
18
- import { upsertTaskSettings } from "./db/write.js";
19
- import { backend, setBackend } from "./state/backends.js";
20
- import { init, initState, isStateReady, pluginDataDir } from "./state/state.js";
21
- import { getTaskSettings } from "./state/tasks.js";
22
- import { usePerfTimer } from "./utils/perf.js";
23
- import { extractBetweenTags, splitThinking } from "./utils/text.js";
24
- const db = {
25
- init: initDb,
26
- readFilePaths,
27
- readFeaturesType,
28
- readTool,
29
- getTaskSettings,
30
- upsertTaskSettings,
31
- readBackends,
32
- };
33
- const fs = {
34
- openTaskSpec,
35
- readWorkflow,
36
- };
37
- export { allOptions, backend, createConfigFile, db, displayOptions, execute, executeAction, executeTask, executeWorkflow, extractBetweenTags, extractToolDoc, fs, getConfigPath, inferenceOptions, init, initState, ioOptions, isStateReady, McpClient, openTaskSpec, parseCommandArgs, pluginDataDir, processConfPath, readConf, readTask, run, setBackend, splitThinking, updateConfCmd, updateConfigFile, usePerfTimer, writeToClipboard, };
1
+ import { displayOptions, ioOptions, inferenceOptions, allOptions, } from "./options.js";
2
+ import { parseCommandArgs } from "./utils.js";
3
+ export { displayOptions, ioOptions, inferenceOptions, allOptions, parseCommandArgs, };
@@ -0,0 +1,6 @@
1
+ import type { InferenceParams, RunMode } from "@agent-smith/types";
2
+ declare let chatInferenceParams: InferenceParams;
3
+ declare const isChatMode: import("@vue/reactivity").Ref<boolean, boolean>;
4
+ declare const runMode: import("@vue/reactivity").Ref<RunMode, RunMode>;
5
+ declare function setChatInferenceParams(ip: InferenceParams): void;
6
+ export { runMode, isChatMode, chatInferenceParams, setChatInferenceParams, };
package/dist/state.js ADDED
@@ -0,0 +1,8 @@
1
+ import { ref } from "@vue/reactivity";
2
+ let chatInferenceParams = { temperature: 0.2, min_p: 0.05, max_tokens: 2048 };
3
+ const isChatMode = ref(false);
4
+ const runMode = ref("cmd");
5
+ function setChatInferenceParams(ip) {
6
+ chatInferenceParams = ip;
7
+ }
8
+ export { runMode, isChatMode, chatInferenceParams, setChatInferenceParams, };
@@ -0,0 +1,8 @@
1
+ import type { ToolCallSpec } from '@agent-smith/types';
2
+ declare function parseCommandArgs(args: Array<any>): {
3
+ args: Array<string>;
4
+ options: Record<string, any>;
5
+ };
6
+ declare function confirmToolUsage(toolCall: ToolCallSpec): Promise<boolean>;
7
+ declare const printToken: (t: string, showTokens?: boolean, dim?: boolean) => void;
8
+ export { parseCommandArgs, confirmToolUsage, printToken, };