@agent-smith/cli 0.0.108 → 0.0.110
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/cli.js +1 -0
- package/dist/cmd/clicmds/aliases.js +8 -6
- package/dist/cmd/clicmds/base.js +5 -2
- package/dist/cmd/clicmds/cmds.d.ts +2 -3
- package/dist/cmd/clicmds/cmds.js +63 -23
- package/dist/cmd/clicmds/updateconf.d.ts +2 -1
- package/dist/cmd/clicmds/updateconf.js +39 -9
- package/dist/cmd/cmds.js +70 -3
- package/dist/cmd/lib/actions/cmd.js +21 -1
- package/dist/cmd/lib/actions/read.js +4 -0
- package/dist/cmd/lib/adaptaters/cmd.js +8 -1
- package/dist/cmd/lib/agents/cmd.js +2 -1
- package/dist/cmd/lib/mcp.js +6 -0
- package/dist/cmd/lib/options_parsers.js +5 -0
- package/dist/cmd/lib/tasks/cmd.js +90 -5
- package/dist/cmd/lib/tasks/conf.js +35 -0
- package/dist/cmd/lib/tasks/read.js +30 -1
- package/dist/cmd/lib/tools.js +10 -4
- package/dist/cmd/lib/user_msgs.js +4 -3
- package/dist/cmd/lib/utils.js +5 -0
- package/dist/cmd/lib/workflows/cmd.js +24 -1
- package/dist/cmd/lib/workflows/read.js +5 -0
- package/dist/cmd/options.js +1 -0
- package/dist/cmd/sys/clipboard.js +25 -0
- package/dist/cmd/sys/execute.js +1 -0
- package/dist/cmd/sys/read_cmds.d.ts +7 -3
- package/dist/cmd/sys/read_cmds.js +21 -3
- package/dist/cmd/sys/read_conf.js +1 -0
- package/dist/cmd/sys/read_features.js +1 -0
- package/dist/cmd/sys/run_python.js +4 -0
- package/dist/conf.d.ts +5 -2
- package/dist/conf.js +6 -3
- package/dist/db/db.js +1 -0
- package/dist/db/read.js +1 -0
- package/dist/db/write.js +50 -2
- package/dist/index.js +8 -0
- package/dist/interfaces.d.ts +13 -2
- package/dist/main.d.ts +18 -3
- package/dist/main.js +17 -2
- package/dist/state/backends.js +14 -0
- package/dist/state/plugins.js +3 -0
- package/dist/state/state.js +21 -2
- package/dist/state/tasks.d.ts +2 -1
- package/dist/state/tasks.js +8 -1
- package/dist/utils/text.js +4 -0
- package/dist/utils/user_msgs.js +2 -0
- package/package.json +15 -15
- package/dist/state/auto/usercmds.d.ts +0 -4
- package/dist/state/auto/usercmds.js +0 -3
package/dist/cli.js
CHANGED
|
@@ -6,6 +6,7 @@ import { backend } from './state/backends.js';
|
|
|
6
6
|
async function query(program) {
|
|
7
7
|
const data = { message: "$", default: "" };
|
|
8
8
|
const q = await input(data);
|
|
9
|
+
//console.log("QUERY", q);
|
|
9
10
|
const args = q.split(" ");
|
|
10
11
|
await program.parseAsync(args, { from: "user" });
|
|
11
12
|
if (isChatMode.value) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { allOptions } from "../options.js";
|
|
2
2
|
import { executeTaskCmd } from "../lib/tasks/cmd.js";
|
|
3
|
-
import { executeActionCmd } from "../lib/actions/cmd.js";
|
|
4
3
|
import { executeWorkflowCmd } from "../lib/workflows/cmd.js";
|
|
5
4
|
import { executeAgentCmd } from "../lib/agents/cmd.js";
|
|
6
5
|
function initCommandsFromAliases(program, aliases, features) {
|
|
7
6
|
aliases.forEach((alias) => {
|
|
7
|
+
//console.log("A", alias)
|
|
8
8
|
switch (alias.type) {
|
|
9
9
|
case "agent":
|
|
10
10
|
const agcmd = program.command(`${alias.name} [prompt_and_vars...]`)
|
|
@@ -13,6 +13,7 @@ function initCommandsFromAliases(program, aliases, features) {
|
|
|
13
13
|
await executeAgentCmd(alias.name, args);
|
|
14
14
|
});
|
|
15
15
|
allOptions.forEach(o => agcmd.addOption(o));
|
|
16
|
+
//console.log("TVARS", alias.name, features.task[alias.name]?.variables)
|
|
16
17
|
if (features.agent[alias.name]?.variables) {
|
|
17
18
|
const rtv = features.agent[alias.name].variables?.required;
|
|
18
19
|
if (rtv) {
|
|
@@ -35,6 +36,7 @@ function initCommandsFromAliases(program, aliases, features) {
|
|
|
35
36
|
await executeTaskCmd(alias.name, args);
|
|
36
37
|
});
|
|
37
38
|
allOptions.forEach(o => tcmd.addOption(o));
|
|
39
|
+
//console.log("TVARS", alias.name, features.task[alias.name]?.variables)
|
|
38
40
|
if (features.task[alias.name]?.variables) {
|
|
39
41
|
const rtv = features.task[alias.name].variables?.required;
|
|
40
42
|
if (rtv) {
|
|
@@ -50,14 +52,14 @@ function initCommandsFromAliases(program, aliases, features) {
|
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
break;
|
|
53
|
-
case "action":
|
|
55
|
+
/*case "action":
|
|
54
56
|
const acmd = program.command(`${alias.name} [args...]`)
|
|
55
57
|
.description("action: " + alias.name)
|
|
56
|
-
.action(async (...args) => {
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
.action(async (...args: Array<any>) => {
|
|
59
|
+
await executeActionCmd(alias.name, args)
|
|
60
|
+
});
|
|
59
61
|
allOptions.forEach(o => acmd.addOption(o));
|
|
60
|
-
break
|
|
62
|
+
break;*/
|
|
61
63
|
case "workflow":
|
|
62
64
|
const wcmd = program.command(`${alias.name} [args...]`)
|
|
63
65
|
.description("workflow: " + alias.name)
|
package/dist/cmd/clicmds/base.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Option } from "commander";
|
|
2
2
|
import { listBackends, setBackend } from "../../state/backends.js";
|
|
3
3
|
import { parseCommandArgs } from "../lib/options_parsers.js";
|
|
4
|
-
import { processTaskCmd, processTasksCmd, resetDbCmd
|
|
5
|
-
import { updateConfCmd } from "./updateconf.js";
|
|
4
|
+
import { processTaskCmd, processTasksCmd, resetDbCmd } from "./cmds.js";
|
|
5
|
+
import { updateConfCmd, updateFeaturesCmd } from "./updateconf.js";
|
|
6
6
|
import { displayOptions, inferenceOptions } from "../options.js";
|
|
7
7
|
function initBaseCommands(program) {
|
|
8
|
+
/*program.command("ping")
|
|
9
|
+
.description("ping inference servers")
|
|
10
|
+
.action(async (...args: Array<any>) => { console.log("Found working inference server(s):", await initAgent(initRemoteBackends())) });*/
|
|
8
11
|
program.command("exit")
|
|
9
12
|
.description("exit the cli")
|
|
10
13
|
.action(() => process.exit(0));
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { FeatureSpec } from '../../interfaces.js';
|
|
3
|
-
declare function initUserCmds(cmdFeats: Record<string, FeatureSpec
|
|
3
|
+
declare function initUserCmds(cmdFeats: Record<string, FeatureSpec>, program: Command): Promise<Array<Command>>;
|
|
4
4
|
declare function resetDbCmd(): Promise<any>;
|
|
5
|
-
declare function updateFeaturesCmd(options: Record<string, any>): Promise<any>;
|
|
6
5
|
declare function processTasksCmd(args: Array<string>, options: Record<string, any>): Promise<void>;
|
|
7
6
|
declare function processTaskCmd(args: Array<string>, options: Record<string, any>): Promise<any>;
|
|
8
|
-
export { initUserCmds, processTaskCmd, processTasksCmd, resetDbCmd,
|
|
7
|
+
export { initUserCmds, processTaskCmd, processTasksCmd, resetDbCmd, };
|
package/dist/cmd/clicmds/cmds.js
CHANGED
|
@@ -1,26 +1,73 @@
|
|
|
1
1
|
import colors from "ansi-colors";
|
|
2
|
+
import { Option } from 'commander';
|
|
2
3
|
import path from "path";
|
|
3
4
|
import YAML from 'yaml';
|
|
4
5
|
import { dbPath } from "../../conf.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { getFeatureSpec
|
|
8
|
-
import { readPluginsPaths } from "../../state/plugins.js";
|
|
6
|
+
import { readFeaturesType, readTaskSetting } from "../../db/read.js";
|
|
7
|
+
import { deleteTaskSetting, upsertTaskSettings } from "../../db/write.js";
|
|
8
|
+
import { getFeatureSpec } from "../../state/features.js";
|
|
9
9
|
import { runMode } from "../../state/state.js";
|
|
10
10
|
import { initTaskSettings, isTaskSettingsInitialized, tasksSettings } from '../../state/tasks.js';
|
|
11
11
|
import { deleteFileIfExists } from "../sys/delete_file.js";
|
|
12
|
-
import { readCmd } from "../sys/read_cmds.js";
|
|
13
12
|
import { readTask } from "../sys/read_task.js";
|
|
14
|
-
|
|
13
|
+
import { parseCommandArgs } from "../lib/options_parsers.js";
|
|
14
|
+
import { readCmd } from "../sys/read_cmds.js";
|
|
15
|
+
import { runtimeDataError } from "../lib/user_msgs.js";
|
|
16
|
+
import { allOptions, displayOptions, inferenceOptions, ioOptions } from "../options.js";
|
|
17
|
+
async function initUserCmds(cmdFeats, program) {
|
|
15
18
|
const features = Object.values(cmdFeats);
|
|
16
19
|
const usrCmds = [];
|
|
17
20
|
for (const feat of features) {
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
//console.log("Init cmd", feat);
|
|
22
|
+
const hasVariables = feat?.variables ? true : false;
|
|
23
|
+
const vars = hasVariables ? feat.variables : {};
|
|
24
|
+
let desc = "";
|
|
25
|
+
if (hasVariables) {
|
|
26
|
+
desc = vars.description;
|
|
22
27
|
}
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
const cmd = program.command(feat.variables.name)
|
|
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);
|
|
23
69
|
}
|
|
70
|
+
//console.log("USRCMDS", usrCmds.map(c => c.name()))
|
|
24
71
|
return usrCmds;
|
|
25
72
|
}
|
|
26
73
|
async function resetDbCmd() {
|
|
@@ -31,23 +78,12 @@ async function resetDbCmd() {
|
|
|
31
78
|
deleteFileIfExists(dbPath);
|
|
32
79
|
console.log("Config database reset ok. Run the conf command to recreate it");
|
|
33
80
|
}
|
|
34
|
-
async function updateFeaturesCmd(options) {
|
|
35
|
-
const fp = readFeaturePaths();
|
|
36
|
-
const pp = await readPluginsPaths();
|
|
37
|
-
const paths = [...fp, ...pp];
|
|
38
|
-
const feats = readFeaturesDirs(paths, options?.debug ?? false);
|
|
39
|
-
updateFeatures(feats);
|
|
40
|
-
updateAliases(feats);
|
|
41
|
-
const deleted = cleanupFeaturePaths(paths);
|
|
42
|
-
for (const el of deleted) {
|
|
43
|
-
console.log("- [feature path]", el);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
81
|
async function processTasksCmd(args, options) {
|
|
47
82
|
if (options?.conf) {
|
|
48
83
|
if (!isTaskSettingsInitialized.value) {
|
|
49
84
|
initTaskSettings();
|
|
50
85
|
}
|
|
86
|
+
//console.log("PTS", tasksSettings);
|
|
51
87
|
console.log(YAML.stringify({ "tasks": tasksSettings }));
|
|
52
88
|
}
|
|
53
89
|
else {
|
|
@@ -56,6 +92,7 @@ async function processTasksCmd(args, options) {
|
|
|
56
92
|
}
|
|
57
93
|
}
|
|
58
94
|
async function processTaskCmd(args, options) {
|
|
95
|
+
//console.log("TASK OPTS", options);
|
|
59
96
|
if (args.length == 0) {
|
|
60
97
|
console.warn("Provide a task name");
|
|
61
98
|
return;
|
|
@@ -70,10 +107,12 @@ async function processTaskCmd(args, options) {
|
|
|
70
107
|
console.log("Task", args[0], "reset ok");
|
|
71
108
|
return;
|
|
72
109
|
}
|
|
110
|
+
//console.log("RT", path)
|
|
73
111
|
const res = readTask(path);
|
|
74
112
|
if (!res.found) {
|
|
75
113
|
throw new Error(`Task ${args[0]}, ${path} not found`);
|
|
76
114
|
}
|
|
115
|
+
//const ts = JSON.parse(res.ymlTask);
|
|
77
116
|
console.log(res.ymlTask);
|
|
78
117
|
if (Object.keys(options).length > 0) {
|
|
79
118
|
upsertTaskSettings(args[0], options);
|
|
@@ -91,5 +130,6 @@ async function processTaskCmd(args, options) {
|
|
|
91
130
|
}
|
|
92
131
|
console.log(colors.dim("Settings") + ":", display);
|
|
93
132
|
}
|
|
133
|
+
//console.log(JSON.stringify(ts, null, " "));
|
|
94
134
|
}
|
|
95
|
-
export { initUserCmds, processTaskCmd, processTasksCmd, resetDbCmd,
|
|
135
|
+
export { initUserCmds, processTaskCmd, processTasksCmd, resetDbCmd, };
|
|
@@ -1,12 +1,48 @@
|
|
|
1
|
+
import path from "path";
|
|
1
2
|
import { processConfPath } from "../../conf.js";
|
|
2
3
|
import { initDb } from "../../db/db.js";
|
|
3
|
-
import { readFilePath } from "../../db/read.js";
|
|
4
|
+
import { readFeaturePaths, readFilePath } from "../../db/read.js";
|
|
4
5
|
import { cleanupFeaturePaths, updateAliases, updateDataDirPath, updateFeatures, updatePromptfilePath, upsertFilePath } from "../../db/write.js";
|
|
5
6
|
import { readFeaturesDirs } from "../../state/features.js";
|
|
7
|
+
import { readPluginsPaths } from "../../state/plugins.js";
|
|
6
8
|
import { dataDirPath, promptfilePath } from "../../state/state.js";
|
|
7
9
|
import { runtimeDataError, runtimeInfo } from '../lib/user_msgs.js';
|
|
10
|
+
import { readUserCmd } from "../sys/read_cmds.js";
|
|
11
|
+
async function getUserCmdsData(feats) {
|
|
12
|
+
for (const feat of feats.cmd) {
|
|
13
|
+
const cmdPath = path.join(feat.path, feat.name + "." + feat.ext);
|
|
14
|
+
const { found, userCmd } = await readUserCmd(feat.name, cmdPath);
|
|
15
|
+
if (found) {
|
|
16
|
+
feat.variables = {
|
|
17
|
+
description: userCmd.description,
|
|
18
|
+
name: userCmd.name,
|
|
19
|
+
};
|
|
20
|
+
if (userCmd?.options) {
|
|
21
|
+
feat.variables.options = userCmd.options;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return feats;
|
|
26
|
+
}
|
|
27
|
+
async function updateAllFeatures(paths) {
|
|
28
|
+
let feats = readFeaturesDirs(paths, true);
|
|
29
|
+
feats = await getUserCmdsData(feats);
|
|
30
|
+
updateFeatures(feats);
|
|
31
|
+
updateAliases(feats);
|
|
32
|
+
const deleted = cleanupFeaturePaths(paths);
|
|
33
|
+
for (const el of deleted) {
|
|
34
|
+
console.log("- [feature path]", el);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function updateFeaturesCmd(options) {
|
|
38
|
+
const fp = readFeaturePaths();
|
|
39
|
+
const pp = await readPluginsPaths();
|
|
40
|
+
const paths = [...fp, ...pp];
|
|
41
|
+
updateAllFeatures(paths);
|
|
42
|
+
}
|
|
8
43
|
async function updateConfCmd(args) {
|
|
9
44
|
initDb(false, true);
|
|
45
|
+
// try to find a conf path in db
|
|
10
46
|
const { found, path } = readFilePath("conf");
|
|
11
47
|
const userProvidedConfPath = (args[0] != "conf") ? args[0] : null;
|
|
12
48
|
if (!found && !userProvidedConfPath) {
|
|
@@ -33,12 +69,6 @@ async function updateConfCmd(args) {
|
|
|
33
69
|
updateDataDirPath(dd);
|
|
34
70
|
dataDirPath.value = dd;
|
|
35
71
|
}
|
|
36
|
-
|
|
37
|
-
updateFeatures(feats);
|
|
38
|
-
updateAliases(feats);
|
|
39
|
-
const deleted = cleanupFeaturePaths(paths);
|
|
40
|
-
for (const el of deleted) {
|
|
41
|
-
console.log("- [feature path]", el);
|
|
42
|
-
}
|
|
72
|
+
updateAllFeatures(paths);
|
|
43
73
|
}
|
|
44
|
-
export { updateConfCmd, };
|
|
74
|
+
export { updateConfCmd, updateFeaturesCmd, };
|
package/dist/cmd/cmds.js
CHANGED
|
@@ -7,8 +7,11 @@ import { isChatMode, runMode } from "../state/state.js";
|
|
|
7
7
|
import { initCommandsFromAliases } from "./clicmds/aliases.js";
|
|
8
8
|
import { initBaseCommands } from "./clicmds/base.js";
|
|
9
9
|
import { initUserCmds } from "./clicmds/cmds.js";
|
|
10
|
+
import { exit } from "node:process";
|
|
11
|
+
//import { usePerfTimer } from "../main.js";
|
|
10
12
|
const program = new Command();
|
|
11
13
|
async function chat(program, options, agent, mcpServers) {
|
|
14
|
+
//console.log("CHAT OPTS", options);
|
|
12
15
|
const data = { message: '>', default: "" };
|
|
13
16
|
const prompt = await input(data);
|
|
14
17
|
if (prompt == "/q") {
|
|
@@ -21,24 +24,88 @@ async function chat(program, options, agent, mcpServers) {
|
|
|
21
24
|
await query(program);
|
|
22
25
|
}
|
|
23
26
|
}
|
|
27
|
+
//console.log("CHAT HIST", agent.history);
|
|
28
|
+
//options.history = undefined;
|
|
29
|
+
//console.log("RUN W PROMPT", prompt);
|
|
24
30
|
await agent.run(prompt, chatInferenceParams, options, chatTemplate ? chatTemplate : undefined);
|
|
25
31
|
console.log();
|
|
26
32
|
await chat(program, options, agent, mcpServers);
|
|
27
33
|
}
|
|
28
34
|
async function buildCmds() {
|
|
35
|
+
//program.allowUnknownOption(true);
|
|
36
|
+
//const perf = usePerfTimer();
|
|
29
37
|
initBaseCommands(program);
|
|
38
|
+
//perf.measure("initBaseCommands");
|
|
30
39
|
const aliases = readAliases();
|
|
40
|
+
//perf.measure("readAliases");
|
|
31
41
|
const feats = readFeatures();
|
|
42
|
+
//perf.measure("readFeatures");
|
|
32
43
|
initCommandsFromAliases(program, aliases, feats);
|
|
44
|
+
//perf.measure("initCommandsFromAliases");
|
|
45
|
+
await initUserCmds(feats.cmd, program);
|
|
46
|
+
//perf.measure("initUserCmds");
|
|
47
|
+
//perf.measure("cmds for each");
|
|
48
|
+
//perf.final("buildCmds");
|
|
49
|
+
return program;
|
|
50
|
+
}
|
|
51
|
+
/*async function buildCmds(): Promise<Command> {
|
|
52
|
+
// Performance measurement start
|
|
53
|
+
const startTime = process.hrtime.bigint();
|
|
54
|
+
const measurements: { name: string; time: number; percentage: number }[] = [];
|
|
55
|
+
let lastTime = startTime;
|
|
56
|
+
|
|
57
|
+
function measureFunction(name: string) {
|
|
58
|
+
const currentTime = process.hrtime.bigint();
|
|
59
|
+
const elapsedNs = Number(currentTime - lastTime);
|
|
60
|
+
const elapsedSec = elapsedNs / 1_000_000_000;
|
|
61
|
+
measurements.push({ name, time: elapsedSec, percentage: 0 });
|
|
62
|
+
lastTime = currentTime;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//program.allowUnknownOption(true);
|
|
66
|
+
measureFunction("start");
|
|
67
|
+
initBaseCommands(program);
|
|
68
|
+
|
|
69
|
+
measureFunction("initBaseCommands");
|
|
70
|
+
const aliases = readAliases();
|
|
71
|
+
|
|
72
|
+
measureFunction("readAliases");
|
|
73
|
+
const feats = readFeatures();
|
|
74
|
+
|
|
75
|
+
measureFunction("readFeatures");
|
|
76
|
+
initCommandsFromAliases(program, aliases, feats);
|
|
77
|
+
|
|
78
|
+
measureFunction("initCommandsFromAliases");
|
|
33
79
|
const cmds = await initUserCmds(feats.cmd);
|
|
80
|
+
|
|
81
|
+
measureFunction("initUserCmds");
|
|
34
82
|
cmds.forEach(c => {
|
|
35
|
-
|
|
83
|
+
//console.log("Add cmd", c.name());
|
|
84
|
+
program.addCommand(c)
|
|
36
85
|
});
|
|
37
|
-
|
|
38
|
-
|
|
86
|
+
measureFunction("cmds.forEach");
|
|
87
|
+
|
|
88
|
+
// Calculate percentages and display results
|
|
89
|
+
const totalTime = Number(process.hrtime.bigint() - startTime) / 1_000_000_000;
|
|
90
|
+
measurements.forEach(m => {
|
|
91
|
+
m.percentage = (m.time / totalTime) * 100;
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
console.log("\nPerformance Measurements for buildCmds:");
|
|
95
|
+
measurements.forEach(m => {
|
|
96
|
+
console.log(`${m.name}: ${m.time.toFixed(6)}s (${m.percentage.toFixed(2)}%)`);
|
|
97
|
+
});
|
|
98
|
+
console.log(`Total time: ${totalTime.toFixed(6)}s\n`);
|
|
99
|
+
|
|
100
|
+
return program
|
|
101
|
+
}*/
|
|
39
102
|
async function parseCmd(program) {
|
|
40
103
|
program.name('Agent Smith terminal client');
|
|
41
104
|
program.description('Terminal agents toolkit');
|
|
42
105
|
await program.parseAsync();
|
|
106
|
+
exit(0);
|
|
107
|
+
/*if (isChatMode.value) {
|
|
108
|
+
await chat(program)
|
|
109
|
+
}*/
|
|
43
110
|
}
|
|
44
111
|
export { buildCmds, chat, parseCmd, program };
|
|
@@ -12,6 +12,7 @@ import { pathToFileURL } from 'url';
|
|
|
12
12
|
import { getInputFromOptions } from '../tasks/utils.js';
|
|
13
13
|
async function executeAction(name, payload, options, quiet = false) {
|
|
14
14
|
let run;
|
|
15
|
+
//console.log("GET ACTION", name, payload);
|
|
15
16
|
const inputData = await getInputFromOptions(options);
|
|
16
17
|
if (inputData) {
|
|
17
18
|
if (Array.isArray(payload)) {
|
|
@@ -22,11 +23,14 @@ async function executeAction(name, payload, options, quiet = false) {
|
|
|
22
23
|
if (!found) {
|
|
23
24
|
throw new Error(`Action ${name} not found at ${path}`);
|
|
24
25
|
}
|
|
26
|
+
//console.log("CREATE ACTION", name, ext, path);
|
|
25
27
|
switch (ext) {
|
|
26
28
|
case "js":
|
|
27
29
|
const url = pathToFileURL(path).href;
|
|
28
|
-
|
|
30
|
+
//console.log("CR JSA", url);
|
|
31
|
+
const mjsa = await import(/* @vite-ignore */ url);
|
|
29
32
|
run = createJsAction(mjsa.action);
|
|
33
|
+
//console.log("END CR JSA")
|
|
30
34
|
break;
|
|
31
35
|
case "yml":
|
|
32
36
|
run = systemAction(path);
|
|
@@ -37,6 +41,7 @@ async function executeAction(name, payload, options, quiet = false) {
|
|
|
37
41
|
default:
|
|
38
42
|
throw new Error(`Action ext ${ext} not implemented`);
|
|
39
43
|
}
|
|
44
|
+
//console.log("RUN", payload);
|
|
40
45
|
const res = await run(payload, options);
|
|
41
46
|
if (!quiet) {
|
|
42
47
|
if (res) {
|
|
@@ -47,7 +52,9 @@ async function executeAction(name, payload, options, quiet = false) {
|
|
|
47
52
|
return res;
|
|
48
53
|
}
|
|
49
54
|
async function executeActionCmd(name, aargs, quiet = false) {
|
|
55
|
+
//console.log("AARGs", aargs)
|
|
50
56
|
const { args, options } = parseCommandArgs(aargs);
|
|
57
|
+
//console.log("CMDA", args)
|
|
51
58
|
const params = args;
|
|
52
59
|
if (options?.clipBoardInput) {
|
|
53
60
|
params.push(await readClipboard());
|
|
@@ -62,9 +69,12 @@ async function executeActionCmd(name, aargs, quiet = false) {
|
|
|
62
69
|
}
|
|
63
70
|
function systemAction(path) {
|
|
64
71
|
const run = async (params) => {
|
|
72
|
+
//console.log("SYS ACTION PARAMS", params);
|
|
65
73
|
let runArgs = new Array();
|
|
74
|
+
// convert args for tool calls
|
|
66
75
|
if (!Array.isArray(params)) {
|
|
67
76
|
try {
|
|
77
|
+
// obviously a tool call
|
|
68
78
|
if (typeof params == "string") {
|
|
69
79
|
runArgs.push(params);
|
|
70
80
|
}
|
|
@@ -83,9 +93,12 @@ function systemAction(path) {
|
|
|
83
93
|
if (!actionSpec.found) {
|
|
84
94
|
runtimeError("System action yml file", path, "not found");
|
|
85
95
|
}
|
|
96
|
+
//console.log("Yml action", JSON.stringify(actionSpec.data, null, " "));
|
|
97
|
+
//console.log("Args", args)
|
|
86
98
|
if (!actionSpec.data?.args) {
|
|
87
99
|
actionSpec.data.args = [];
|
|
88
100
|
}
|
|
101
|
+
//console.log("EXEC", actionSpec.data.cmd, [...actionSpec.data.args, ...runArgs]);
|
|
89
102
|
const out = await execute(actionSpec.data.cmd, [...actionSpec.data.args, ...runArgs]);
|
|
90
103
|
return out.trim();
|
|
91
104
|
};
|
|
@@ -93,9 +106,11 @@ function systemAction(path) {
|
|
|
93
106
|
}
|
|
94
107
|
function pythonAction(path) {
|
|
95
108
|
const run = async (params) => {
|
|
109
|
+
//console.log("PY ACTION PARAMS", params);
|
|
96
110
|
let runArgs = new Array();
|
|
97
111
|
if (!Array.isArray(params)) {
|
|
98
112
|
try {
|
|
113
|
+
// obviously a tool call
|
|
99
114
|
if (typeof params == "string") {
|
|
100
115
|
runArgs.push(params);
|
|
101
116
|
}
|
|
@@ -110,7 +125,11 @@ function pythonAction(path) {
|
|
|
110
125
|
else {
|
|
111
126
|
runArgs = params;
|
|
112
127
|
}
|
|
128
|
+
//console.log("Py action", path);
|
|
113
129
|
const { data, error } = await runPyScript(pyShell, "python3", path, runArgs);
|
|
130
|
+
/*console.log("----------------");
|
|
131
|
+
console.log("PYOUT", data);
|
|
132
|
+
console.log("----------------");*/
|
|
114
133
|
if (error) {
|
|
115
134
|
throw new Error(`python error: ${error}`);
|
|
116
135
|
}
|
|
@@ -125,6 +144,7 @@ function pythonAction(path) {
|
|
|
125
144
|
}
|
|
126
145
|
catch (e) {
|
|
127
146
|
console.warn("Can not parse json from python action", path, e);
|
|
147
|
+
//throw new Error(`python error: ${error}`)
|
|
128
148
|
}
|
|
129
149
|
}
|
|
130
150
|
return final;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
function createJsAction(action) {
|
|
2
2
|
const run = async (args, options) => {
|
|
3
|
+
//console.log("JS ACTION PARAMS", args);
|
|
3
4
|
try {
|
|
4
5
|
const res = await action(args, options);
|
|
5
6
|
return res;
|
|
6
7
|
}
|
|
7
8
|
catch (e) {
|
|
9
|
+
/*if (e?.text) {
|
|
10
|
+
throw new Error(`executing action:${e.text()}. Args: ${args}`);
|
|
11
|
+
}*/
|
|
8
12
|
throw new Error(`executing action:${e}. Args: ${args}`);
|
|
9
13
|
}
|
|
10
14
|
};
|
|
@@ -3,6 +3,9 @@ import { createJsAction } from "../actions/read.js";
|
|
|
3
3
|
import { pathToFileURL } from 'url';
|
|
4
4
|
import { getInputFromOptions } from "../tasks/utils.js";
|
|
5
5
|
async function executeAdaptater(name, params, options) {
|
|
6
|
+
/*if (params?.args) {
|
|
7
|
+
params = params.args;
|
|
8
|
+
}*/
|
|
6
9
|
const { found, path } = getFeatureSpec(name, "adaptater");
|
|
7
10
|
if (!found) {
|
|
8
11
|
throw new Error(`adaptater ${name} not found`);
|
|
@@ -15,11 +18,13 @@ async function executeAdaptater(name, params, options) {
|
|
|
15
18
|
}
|
|
16
19
|
let run;
|
|
17
20
|
const url = pathToFileURL(path).href;
|
|
18
|
-
const jsa = await import(url);
|
|
21
|
+
const jsa = await import(/* @vite-ignore */ url);
|
|
19
22
|
run = createJsAction(jsa.action);
|
|
20
23
|
let res;
|
|
21
24
|
try {
|
|
25
|
+
//console.log("ADAPT RUN PARAMS", params);
|
|
22
26
|
res = await run(params, options);
|
|
27
|
+
//console.log("ADAPT RES", res);
|
|
23
28
|
}
|
|
24
29
|
catch (e) {
|
|
25
30
|
throw new Error(`adaptater ${name}: ${e}`);
|
|
@@ -27,6 +32,8 @@ async function executeAdaptater(name, params, options) {
|
|
|
27
32
|
if (res?.error) {
|
|
28
33
|
throw res.error;
|
|
29
34
|
}
|
|
35
|
+
//await processOutput(res);
|
|
36
|
+
//console.log("ADRES", res);
|
|
30
37
|
return res;
|
|
31
38
|
}
|
|
32
39
|
export { executeAdaptater, };
|
|
@@ -5,6 +5,7 @@ async function executeAgentCmd(name, targs = []) {
|
|
|
5
5
|
const ca = parseCommandArgs(targs);
|
|
6
6
|
const prompt = await getTaskPrompt(name, ca.args, ca.options);
|
|
7
7
|
ca.options.isAgent = true;
|
|
8
|
-
|
|
8
|
+
const res = await executeTask(name, { prompt: prompt }, ca.options);
|
|
9
|
+
return res;
|
|
9
10
|
}
|
|
10
11
|
export { executeAgentCmd, };
|
package/dist/cmd/lib/mcp.js
CHANGED
|
@@ -9,6 +9,9 @@ class McpClient {
|
|
|
9
9
|
askUserTools = null;
|
|
10
10
|
tools = {};
|
|
11
11
|
constructor(servername, command, args, authorizedTools = null, askUserTools = null) {
|
|
12
|
+
//console.log("MCP servername", servername);
|
|
13
|
+
//console.log("MCP command", command);
|
|
14
|
+
//console.log("MCP ARGS", typeof args, args);
|
|
12
15
|
this.name = servername;
|
|
13
16
|
const okargs = new Array();
|
|
14
17
|
for (const arg of args) {
|
|
@@ -59,7 +62,9 @@ class McpClient {
|
|
|
59
62
|
argsTypes[k] = vv.type;
|
|
60
63
|
}
|
|
61
64
|
}
|
|
65
|
+
//console.log("MCP ARGS TYPES", argsTypes);
|
|
62
66
|
const exec = async (args) => {
|
|
67
|
+
//console.log("MCP EXEC ARGS", args);
|
|
63
68
|
const _iargs = args;
|
|
64
69
|
for (const [k, v] of Object.entries(_iargs)) {
|
|
65
70
|
if (argsTypes[k] == "array") {
|
|
@@ -76,6 +81,7 @@ class McpClient {
|
|
|
76
81
|
name: tool.name,
|
|
77
82
|
arguments: _iargs,
|
|
78
83
|
};
|
|
84
|
+
//console.log("PAY", payload);
|
|
79
85
|
const res = await this.client.callTool(payload);
|
|
80
86
|
return res;
|
|
81
87
|
};
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
function parseCommandArgs(args) {
|
|
2
|
+
//return { args: program.args, options: program.opts() }
|
|
3
|
+
//discard the command (last arg)
|
|
2
4
|
args.pop();
|
|
5
|
+
//console.log("Raw command args:", args);
|
|
3
6
|
const res = {
|
|
4
7
|
args: new Array(),
|
|
5
8
|
options: {},
|
|
6
9
|
};
|
|
7
10
|
res.options = args.pop();
|
|
8
11
|
res.args = Array.isArray(args[0]) ? args[0] : args;
|
|
12
|
+
//console.log("PARSE ARGS RES", res.args);
|
|
13
|
+
//console.log("PARSE OPTS RES", res.options);
|
|
9
14
|
return res;
|
|
10
15
|
}
|
|
11
16
|
function parseTaskConfigOptions(options) {
|