@agent-smith/cli 0.0.63 → 0.0.65
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.d.ts +2 -1
- package/dist/cli.js +7 -48
- package/dist/cmd/clicmds/aliases.d.ts +7 -0
- package/dist/cmd/clicmds/aliases.js +43 -0
- package/dist/cmd/clicmds/base.d.ts +3 -0
- package/dist/cmd/clicmds/base.js +94 -0
- package/dist/cmd/clicmds/cmds.d.ts +4 -7
- package/dist/cmd/clicmds/cmds.js +6 -184
- package/dist/cmd/clicmds/update.d.ts +2 -0
- package/dist/cmd/clicmds/update.js +46 -0
- package/dist/cmd/cmds.d.ts +3 -5
- package/dist/cmd/cmds.js +19 -53
- package/dist/cmd/lib/actions/cmd.d.ts +3 -2
- package/dist/cmd/lib/actions/cmd.js +67 -50
- package/dist/cmd/lib/actions/read.js +2 -2
- package/dist/cmd/lib/adaptaters/cmd.d.ts +2 -2
- package/dist/cmd/lib/adaptaters/cmd.js +3 -15
- package/dist/cmd/lib/models.d.ts +1 -1
- package/dist/cmd/lib/models.js +8 -6
- package/dist/cmd/lib/options_parsers.d.ts +7 -0
- package/dist/cmd/lib/options_parsers.js +41 -0
- package/dist/cmd/lib/tasks/cmd.d.ts +3 -2
- package/dist/cmd/lib/tasks/cmd.js +105 -63
- package/dist/cmd/lib/tasks/mcp.d.ts +13 -0
- package/dist/cmd/lib/tasks/mcp.js +57 -0
- package/dist/cmd/lib/tools.d.ts +8 -1
- package/dist/cmd/lib/tools.js +31 -1
- package/dist/cmd/lib/utils.d.ts +1 -2
- package/dist/cmd/lib/utils.js +1 -23
- package/dist/cmd/lib/workflows/cmd.d.ts +3 -2
- package/dist/cmd/lib/workflows/cmd.js +21 -27
- package/dist/cmd/options.d.ts +8 -0
- package/dist/cmd/options.js +62 -0
- package/dist/cmd/sys/read_cmds.d.ts +2 -2
- package/dist/cmd/sys/read_cmds.js +2 -2
- package/dist/db/db.d.ts +1 -1
- package/dist/db/db.js +3 -2
- package/dist/db/read.d.ts +3 -2
- package/dist/db/read.js +18 -12
- package/dist/db/schemas.js +12 -6
- package/dist/db/write.js +30 -13
- package/dist/index.js +14 -8
- package/dist/interfaces.d.ts +23 -6
- package/dist/main.d.ts +6 -6
- package/dist/main.js +6 -6
- package/dist/state/state.d.ts +2 -7
- package/dist/state/state.js +3 -11
- package/dist/utils/perf.d.ts +1 -1
- package/dist/utils/perf.js +6 -6
- package/package.json +10 -11
- package/dist/cmd/clicmds/modes.d.ts +0 -3
- package/dist/cmd/clicmds/modes.js +0 -95
- package/dist/utils/args.d.ts +0 -7
- package/dist/utils/args.js +0 -85
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,55 +1,14 @@
|
|
|
1
1
|
import { input } from '@inquirer/prompts';
|
|
2
|
-
import { chat
|
|
2
|
+
import { chat } from './cmd/cmds.js';
|
|
3
3
|
import { isChatMode } from './state/state.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function parseParams(params) {
|
|
7
|
-
const regex = /"([^"]*)"|(\S+)/g;
|
|
8
|
-
let match;
|
|
9
|
-
const result = new Array();
|
|
10
|
-
while ((match = regex.exec(params)) !== null) {
|
|
11
|
-
if (match[1]) {
|
|
12
|
-
result.push(match[1]);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
result.push(match[2]);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
async function dispatch(input) {
|
|
21
|
-
if (input.startsWith("-")) {
|
|
22
|
-
try {
|
|
23
|
-
const _cmd = modes[input].cmd;
|
|
24
|
-
await _cmd([], {});
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
throw new Error(`Option error ${e}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const buf = new Array();
|
|
32
|
-
let params = parseParams(input);
|
|
33
|
-
const cmd = params.shift();
|
|
34
|
-
const opts = {};
|
|
35
|
-
params.forEach((p) => {
|
|
36
|
-
if (p.startsWith("-")) {
|
|
37
|
-
opts[p.substring(1)] = true;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
buf.push(p);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
const args = await setOptions(buf, opts);
|
|
44
|
-
await runCmd(cmd, args);
|
|
45
|
-
}
|
|
46
|
-
async function query(sign = "$") {
|
|
47
|
-
const data = { message: sign, default: "" };
|
|
4
|
+
async function query(program) {
|
|
5
|
+
const data = { message: "$", default: "" };
|
|
48
6
|
const q = await input(data);
|
|
49
|
-
|
|
7
|
+
const args = q.split(" ");
|
|
8
|
+
await program.parseAsync(args, { from: "user" });
|
|
50
9
|
if (isChatMode.value) {
|
|
51
|
-
await chat();
|
|
10
|
+
await chat(program);
|
|
52
11
|
}
|
|
53
|
-
await query(
|
|
12
|
+
await query(program);
|
|
54
13
|
}
|
|
55
14
|
export { query };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { AliasType, FeatureSpec, FeatureType } from "../../interfaces.js";
|
|
3
|
+
declare function initCommandsFromAliases(program: Command, aliases: {
|
|
4
|
+
name: string;
|
|
5
|
+
type: AliasType;
|
|
6
|
+
}[], features: Record<FeatureType, Record<string, FeatureSpec>>): Command;
|
|
7
|
+
export { initCommandsFromAliases, };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { actionOptions, taskOptions, workflowOptions } from "../options.js";
|
|
2
|
+
import { executeTaskCmd } from "../lib/tasks/cmd.js";
|
|
3
|
+
import { executeActionCmd } from "../lib/actions/cmd.js";
|
|
4
|
+
import { executeWorkflowCmd } from "../lib/workflows/cmd.js";
|
|
5
|
+
function initCommandsFromAliases(program, aliases, features) {
|
|
6
|
+
aliases.forEach((alias) => {
|
|
7
|
+
switch (alias.type) {
|
|
8
|
+
case "task":
|
|
9
|
+
const tcmd = program.command(`${alias.name} [prompt_and_vars...]`)
|
|
10
|
+
.description("task: " + alias.name)
|
|
11
|
+
.action(async (...args) => {
|
|
12
|
+
await executeTaskCmd(alias.name, args);
|
|
13
|
+
});
|
|
14
|
+
taskOptions.forEach(o => tcmd.addOption(o));
|
|
15
|
+
if (features.task[alias.name]?.variables) {
|
|
16
|
+
features.task[alias.name].variables?.optional.forEach(v => {
|
|
17
|
+
tcmd.option(`--${v} <value>`);
|
|
18
|
+
});
|
|
19
|
+
features.task[alias.name].variables?.required.forEach(v => {
|
|
20
|
+
tcmd.requiredOption(`--${v} <value>`);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
break;
|
|
24
|
+
case "action":
|
|
25
|
+
const acmd = program.command(`${alias.name} [args...]`)
|
|
26
|
+
.description("action: " + alias.name)
|
|
27
|
+
.action(async (...args) => {
|
|
28
|
+
await executeActionCmd(alias.name, args);
|
|
29
|
+
});
|
|
30
|
+
actionOptions.forEach(o => acmd.addOption(o));
|
|
31
|
+
break;
|
|
32
|
+
case "workflow":
|
|
33
|
+
const wcmd = program.command(`${alias.name} [args...]`)
|
|
34
|
+
.description("workflow: " + alias.name)
|
|
35
|
+
.action(async (...args) => {
|
|
36
|
+
executeWorkflowCmd(alias.name, args);
|
|
37
|
+
});
|
|
38
|
+
workflowOptions.forEach(o => wcmd.addOption(o));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return program;
|
|
42
|
+
}
|
|
43
|
+
export { initCommandsFromAliases, };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import YAML from 'yaml';
|
|
2
|
+
import { initAgent, taskBuilder } from "../../agent.js";
|
|
3
|
+
import { dbPath } from "../../conf.js";
|
|
4
|
+
import { readFeaturePaths, readFeaturesType } from "../../db/read.js";
|
|
5
|
+
import { cleanupFeaturePaths, updateAliases, updateFeatures } from "../../db/write.js";
|
|
6
|
+
import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
|
|
7
|
+
import { readPluginsPaths } from "../../state/plugins.js";
|
|
8
|
+
import { runMode } from "../../state/state.js";
|
|
9
|
+
import { showModelsCmd } from "../lib/models.js";
|
|
10
|
+
import { parseCommandArgs } from "../lib/options_parsers.js";
|
|
11
|
+
import { deleteFileIfExists } from "../sys/delete_file.js";
|
|
12
|
+
import { readTask } from "../sys/read_task.js";
|
|
13
|
+
import { updateConfCmd } from "./update.js";
|
|
14
|
+
function initBaseCommands(program) {
|
|
15
|
+
program.command("ping")
|
|
16
|
+
.description("ping inference servers")
|
|
17
|
+
.action(async (...args) => { console.log("Found working inference server(s):", await initAgent()); });
|
|
18
|
+
program.command("exit")
|
|
19
|
+
.description("exit the cli")
|
|
20
|
+
.action(() => process.exit(0));
|
|
21
|
+
program.command("tasks")
|
|
22
|
+
.description("list all the tasks")
|
|
23
|
+
.action(async (...args) => {
|
|
24
|
+
const ts = Object.keys(readFeaturesType("task")).sort();
|
|
25
|
+
console.table(ts);
|
|
26
|
+
});
|
|
27
|
+
program.command("task <task>")
|
|
28
|
+
.description("read a task")
|
|
29
|
+
.action(async (...args) => {
|
|
30
|
+
const ca = parseCommandArgs(args);
|
|
31
|
+
await _readTaskCmd(ca.args);
|
|
32
|
+
});
|
|
33
|
+
program.command("models [filters...]")
|
|
34
|
+
.description("list the available models")
|
|
35
|
+
.action(async (...args) => {
|
|
36
|
+
const ca = parseCommandArgs(args);
|
|
37
|
+
await showModelsCmd(ca.args);
|
|
38
|
+
});
|
|
39
|
+
program.command("update")
|
|
40
|
+
.description("update the available features: run this after adding a new feature")
|
|
41
|
+
.action(async (...args) => {
|
|
42
|
+
await _updateFeatures();
|
|
43
|
+
});
|
|
44
|
+
program.command("conf <path>")
|
|
45
|
+
.description("process config file")
|
|
46
|
+
.action(async (...args) => {
|
|
47
|
+
const ca = parseCommandArgs(args);
|
|
48
|
+
await updateConfCmd(ca.args);
|
|
49
|
+
});
|
|
50
|
+
program.command("reset")
|
|
51
|
+
.description("reset the config database")
|
|
52
|
+
.action(async (...args) => {
|
|
53
|
+
await _resetDbCmd();
|
|
54
|
+
});
|
|
55
|
+
return program;
|
|
56
|
+
}
|
|
57
|
+
async function _resetDbCmd() {
|
|
58
|
+
if (runMode.value == "cli") {
|
|
59
|
+
console.log("This command can not be run in cli mode");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
deleteFileIfExists(dbPath);
|
|
63
|
+
console.log("Config database reset ok. Run the conf command to recreate it");
|
|
64
|
+
}
|
|
65
|
+
async function _updateFeatures() {
|
|
66
|
+
const fp = readFeaturePaths();
|
|
67
|
+
const pp = await readPluginsPaths();
|
|
68
|
+
const paths = [...fp, ...pp];
|
|
69
|
+
const feats = readFeaturesDirs(paths);
|
|
70
|
+
updateFeatures(feats);
|
|
71
|
+
updateAliases(feats);
|
|
72
|
+
const deleted = cleanupFeaturePaths(paths);
|
|
73
|
+
for (const el of deleted) {
|
|
74
|
+
console.log("- [feature path]", el);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function _readTaskCmd(args) {
|
|
78
|
+
if (args.length == 0) {
|
|
79
|
+
console.warn("Provide a task name");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const { found, path } = getFeatureSpec(args[0], "task");
|
|
83
|
+
if (!found) {
|
|
84
|
+
console.warn(`FeatureType ${args[0]} not found`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const res = readTask(path);
|
|
88
|
+
if (!res.found) {
|
|
89
|
+
throw new Error(`Task ${args[0]}, ${path} not found`);
|
|
90
|
+
}
|
|
91
|
+
const ts = taskBuilder.readFromYaml(res.ymlTask);
|
|
92
|
+
console.log(YAML.stringify(ts));
|
|
93
|
+
}
|
|
94
|
+
export { initBaseCommands };
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function
|
|
4
|
-
|
|
5
|
-
declare function pingCmd(args: Array<string> | undefined, options: any): Promise<boolean>;
|
|
6
|
-
declare function updateConfCmd(args: Array<string> | undefined, options: any): Promise<any>;
|
|
7
|
-
export { cmds, initCmds, pingCmd, initAliases, updateConfCmd };
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { FeatureSpec } from '../../interfaces.js';
|
|
3
|
+
declare function initUserCmds(cmdFeats: Record<string, FeatureSpec>): Promise<Array<Command>>;
|
|
4
|
+
export { initUserCmds };
|
package/dist/cmd/clicmds/cmds.js
CHANGED
|
@@ -1,188 +1,10 @@
|
|
|
1
|
-
import YAML from 'yaml';
|
|
2
|
-
import { dataDirPath, isChatMode, isDebug, promptfilePath, runMode } from "../../state/state.js";
|
|
3
|
-
import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
|
|
4
|
-
import { readAliases, readFeaturePaths, readFeatures, readFilePath } from "../../db/read.js";
|
|
5
|
-
import { cleanupFeaturePaths, updateAliases, updateDataDirPath, updateFeatures, upsertFilePath, updatePromptfilePath } from "../../db/write.js";
|
|
6
|
-
import { processConfPath } from "../../conf.js";
|
|
7
|
-
import { executeActionCmd } from "../lib/actions/cmd.js";
|
|
8
|
-
import { initAgent, taskBuilder } from "../../agent.js";
|
|
9
|
-
import { executeTaskCmd } from "../lib/tasks/cmd.js";
|
|
10
1
|
import { readCmds } from "../sys/read_cmds.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import { readPluginsPaths } from '../../state/plugins.js';
|
|
17
|
-
import { runtimeDataError, runtimeInfo } from '../lib/user_msgs.js';
|
|
18
|
-
let cmds = {
|
|
19
|
-
exit: {
|
|
20
|
-
cmd: async () => process.exit(0),
|
|
21
|
-
description: "exit the cli"
|
|
22
|
-
},
|
|
23
|
-
ping: {
|
|
24
|
-
cmd: async () => pingCmd(["verbose"], undefined),
|
|
25
|
-
description: "ping inference servers",
|
|
26
|
-
},
|
|
27
|
-
tasks: {
|
|
28
|
-
cmd: _listTasksCmd,
|
|
29
|
-
description: "list all the tasks"
|
|
30
|
-
},
|
|
31
|
-
task: {
|
|
32
|
-
cmd: _readTaskCmd,
|
|
33
|
-
description: "read a task",
|
|
34
|
-
args: "arguments: \n-task (required): the task name"
|
|
35
|
-
},
|
|
36
|
-
models: {
|
|
37
|
-
cmd: showModelsCmd,
|
|
38
|
-
description: "list the available models",
|
|
39
|
-
},
|
|
40
|
-
update: {
|
|
41
|
-
cmd: _updateFeatures,
|
|
42
|
-
description: "update the available features: run this after adding a new feature",
|
|
43
|
-
},
|
|
44
|
-
conf: {
|
|
45
|
-
cmd: updateConfCmd,
|
|
46
|
-
description: "process config file",
|
|
47
|
-
args: "arguments: \n-path (required): the path to the config.yml file"
|
|
48
|
-
},
|
|
49
|
-
reset: {
|
|
50
|
-
cmd: _resetDbCmd,
|
|
51
|
-
description: "reset the config database",
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
function initAliases() {
|
|
55
|
-
const aliases = readAliases();
|
|
56
|
-
const _cmds = {};
|
|
57
|
-
aliases.forEach((alias) => {
|
|
58
|
-
switch (alias.type) {
|
|
59
|
-
case "task":
|
|
60
|
-
_cmds[alias.name] = {
|
|
61
|
-
cmd: (args = [], options) => _executeTaskCmd([alias.name, ...args], options),
|
|
62
|
-
description: "task: " + alias.name,
|
|
63
|
-
};
|
|
64
|
-
break;
|
|
65
|
-
case "action":
|
|
66
|
-
_cmds[alias.name] = {
|
|
67
|
-
cmd: (args = [], options = {}, quiet = false) => executeActionCmd([alias.name, ...args], options, quiet),
|
|
68
|
-
description: "action: " + alias.name,
|
|
69
|
-
};
|
|
70
|
-
break;
|
|
71
|
-
case "workflow":
|
|
72
|
-
_cmds[alias.name] = {
|
|
73
|
-
cmd: (args = [], options) => _executeWorkflowCmd([alias.name, ...args], options),
|
|
74
|
-
description: "wokflow: " + alias.name,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
return _cmds;
|
|
79
|
-
}
|
|
80
|
-
async function initCmds() {
|
|
81
|
-
for (const dirpath of new Set(Object.values(readFeatures().cmd))) {
|
|
82
|
-
const c = await readCmds(`${dirpath}`);
|
|
83
|
-
cmds = { ...cmds, ...c };
|
|
2
|
+
async function initUserCmds(cmdFeats) {
|
|
3
|
+
const cmds = new Array();
|
|
4
|
+
for (const feat of Object.values(cmdFeats)) {
|
|
5
|
+
const c = await readCmds(`${feat.path}`);
|
|
6
|
+
cmds.push(...c);
|
|
84
7
|
}
|
|
85
8
|
return cmds;
|
|
86
9
|
}
|
|
87
|
-
|
|
88
|
-
const isUp = await initAgent();
|
|
89
|
-
return isUp;
|
|
90
|
-
}
|
|
91
|
-
async function _updateFeatures(args = [], options) {
|
|
92
|
-
const fp = readFeaturePaths();
|
|
93
|
-
const pp = await readPluginsPaths();
|
|
94
|
-
const paths = [...fp, ...pp];
|
|
95
|
-
const feats = readFeaturesDirs(paths);
|
|
96
|
-
updateFeatures(feats);
|
|
97
|
-
updateAliases(feats);
|
|
98
|
-
const deleted = cleanupFeaturePaths(paths);
|
|
99
|
-
for (const el of deleted) {
|
|
100
|
-
console.log("- [feature path]", el);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
async function updateConfCmd(args = [], options) {
|
|
104
|
-
initDb(isDebug.value, true);
|
|
105
|
-
const { found, path } = readFilePath("conf");
|
|
106
|
-
const userProvidedConfPath = (args[0] != "conf") ? args[0] : null;
|
|
107
|
-
if (!found && !userProvidedConfPath) {
|
|
108
|
-
runtimeDataError("conf file path not found in db: please provide a conf path parameter to the command");
|
|
109
|
-
}
|
|
110
|
-
let confPath;
|
|
111
|
-
if (userProvidedConfPath) {
|
|
112
|
-
confPath = userProvidedConfPath;
|
|
113
|
-
const isu = upsertFilePath("conf", confPath);
|
|
114
|
-
if (isu) {
|
|
115
|
-
runtimeInfo("Config path", confPath, "updated");
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
confPath = path;
|
|
120
|
-
}
|
|
121
|
-
console.log("Using", confPath, "to update features");
|
|
122
|
-
const { paths, pf, dd } = await processConfPath(confPath);
|
|
123
|
-
if (pf.length > 0) {
|
|
124
|
-
updatePromptfilePath(pf);
|
|
125
|
-
promptfilePath.value = pf;
|
|
126
|
-
}
|
|
127
|
-
if (dd.length > 0) {
|
|
128
|
-
updateDataDirPath(dd);
|
|
129
|
-
dataDirPath.value = dd;
|
|
130
|
-
}
|
|
131
|
-
const feats = readFeaturesDirs(paths);
|
|
132
|
-
updateFeatures(feats);
|
|
133
|
-
updateAliases(feats);
|
|
134
|
-
updateAllModels();
|
|
135
|
-
const deleted = cleanupFeaturePaths(paths);
|
|
136
|
-
for (const el of deleted) {
|
|
137
|
-
console.log("- [feature path]", el);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
async function _resetDbCmd(args = [], options) {
|
|
141
|
-
if (runMode.value == "cli") {
|
|
142
|
-
console.log("This command can not be run in cli mode");
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
deleteFileIfExists(dbPath);
|
|
146
|
-
console.log("Config database reset ok. Run the conf command to recreate it");
|
|
147
|
-
}
|
|
148
|
-
async function _executeTaskCmd(args = [], options) {
|
|
149
|
-
if (args.length == 0) {
|
|
150
|
-
console.warn("Provide a task name");
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
const res = await executeTaskCmd(args, options);
|
|
154
|
-
if (isChatMode.value) {
|
|
155
|
-
}
|
|
156
|
-
return res;
|
|
157
|
-
}
|
|
158
|
-
async function _executeWorkflowCmd(args = [], options) {
|
|
159
|
-
if (args.length == 0) {
|
|
160
|
-
console.warn("Provide a workflow name");
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const name = args.shift();
|
|
164
|
-
const res = await executeWorkflowCmd(name, args, options);
|
|
165
|
-
return res;
|
|
166
|
-
}
|
|
167
|
-
async function _readTaskCmd(args = [], options) {
|
|
168
|
-
if (args.length == 0) {
|
|
169
|
-
console.warn("Provide a task name");
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
const { found, path } = getFeatureSpec(args[0], "task");
|
|
173
|
-
if (!found) {
|
|
174
|
-
console.warn(`FeatureType ${args[0]} not found`);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const res = readTask(path);
|
|
178
|
-
if (!res.found) {
|
|
179
|
-
throw new Error(`Task ${args[0]}, ${path} not found`);
|
|
180
|
-
}
|
|
181
|
-
const ts = taskBuilder.readFromYaml(res.ymlTask);
|
|
182
|
-
console.log(YAML.stringify(ts));
|
|
183
|
-
}
|
|
184
|
-
async function _listTasksCmd(args = [], options) {
|
|
185
|
-
const ts = Object.keys(readFeatures().task).sort();
|
|
186
|
-
console.table(ts);
|
|
187
|
-
}
|
|
188
|
-
export { cmds, initCmds, pingCmd, initAliases, updateConfCmd };
|
|
10
|
+
export { initUserCmds };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { processConfPath } from "../../conf.js";
|
|
2
|
+
import { initDb } from "../../db/db.js";
|
|
3
|
+
import { readFilePath } from "../../db/read.js";
|
|
4
|
+
import { cleanupFeaturePaths, updateAliases, updateDataDirPath, updateFeatures, updatePromptfilePath, upsertFilePath } from "../../db/write.js";
|
|
5
|
+
import { readFeaturesDirs } from "../../state/features.js";
|
|
6
|
+
import { dataDirPath, promptfilePath } from "../../state/state.js";
|
|
7
|
+
import { updateAllModels } from '../lib/models.js';
|
|
8
|
+
import { runtimeDataError, runtimeInfo } from '../lib/user_msgs.js';
|
|
9
|
+
async function updateConfCmd(args) {
|
|
10
|
+
initDb(false, true);
|
|
11
|
+
const { found, path } = readFilePath("conf");
|
|
12
|
+
const userProvidedConfPath = (args[0] != "conf") ? args[0] : null;
|
|
13
|
+
if (!found && !userProvidedConfPath) {
|
|
14
|
+
runtimeDataError("conf file path not found in db: please provide a conf path parameter to the command");
|
|
15
|
+
}
|
|
16
|
+
let confPath;
|
|
17
|
+
if (userProvidedConfPath) {
|
|
18
|
+
confPath = userProvidedConfPath;
|
|
19
|
+
const isu = upsertFilePath("conf", confPath);
|
|
20
|
+
if (isu) {
|
|
21
|
+
runtimeInfo("Config path", confPath, "updated");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
confPath = path;
|
|
26
|
+
}
|
|
27
|
+
console.log("Using", confPath, "to update features");
|
|
28
|
+
const { paths, pf, dd } = await processConfPath(confPath);
|
|
29
|
+
if (pf.length > 0) {
|
|
30
|
+
updatePromptfilePath(pf);
|
|
31
|
+
promptfilePath.value = pf;
|
|
32
|
+
}
|
|
33
|
+
if (dd.length > 0) {
|
|
34
|
+
updateDataDirPath(dd);
|
|
35
|
+
dataDirPath.value = dd;
|
|
36
|
+
}
|
|
37
|
+
const feats = readFeaturesDirs(paths);
|
|
38
|
+
updateFeatures(feats);
|
|
39
|
+
updateAliases(feats);
|
|
40
|
+
updateAllModels();
|
|
41
|
+
const deleted = cleanupFeaturePaths(paths);
|
|
42
|
+
for (const el of deleted) {
|
|
43
|
+
console.log("- [feature path]", el);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export { updateConfCmd, };
|
package/dist/cmd/cmds.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
declare function chat(): Promise<void>;
|
|
3
|
-
declare function initCliCmds(): Promise<void>;
|
|
4
|
-
declare function runCmd(cmdName: string, args?: Array<string>, options?: any): Promise<void>;
|
|
2
|
+
declare function chat(program: Command): Promise<void>;
|
|
5
3
|
declare function buildCmds(): Promise<Command>;
|
|
6
|
-
declare function parseCmd(): Promise<void>;
|
|
7
|
-
export { buildCmds, chat,
|
|
4
|
+
declare function parseCmd(program: Command): Promise<void>;
|
|
5
|
+
export { buildCmds, chat, parseCmd, };
|
package/dist/cmd/cmds.js
CHANGED
|
@@ -3,13 +3,13 @@ import { toRaw } from "@vue/reactivity";
|
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import { brain } from "../agent.js";
|
|
5
5
|
import { query } from "../cli.js";
|
|
6
|
+
import { readAliases, readFeatures } from "../db/read.js";
|
|
6
7
|
import { chatInferenceParams } from "../state/chat.js";
|
|
7
|
-
import { isChatMode,
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
async function chat() {
|
|
8
|
+
import { isChatMode, runMode } from "../state/state.js";
|
|
9
|
+
import { initCommandsFromAliases } from "./clicmds/aliases.js";
|
|
10
|
+
import { initBaseCommands } from "./clicmds/base.js";
|
|
11
|
+
import { initUserCmds } from "./clicmds/cmds.js";
|
|
12
|
+
async function chat(program) {
|
|
13
13
|
const data = { message: '>', default: "" };
|
|
14
14
|
const prompt = await input(data);
|
|
15
15
|
if (prompt == "/q") {
|
|
@@ -18,63 +18,29 @@ async function chat() {
|
|
|
18
18
|
process.exit(0);
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
|
-
await query();
|
|
21
|
+
await query(program);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
await brain.ex.think(prompt, toRaw(chatInferenceParams));
|
|
25
25
|
console.log();
|
|
26
|
-
await chat();
|
|
27
|
-
}
|
|
28
|
-
async function initCliCmds() {
|
|
29
|
-
const _cmds = await initCmds();
|
|
30
|
-
const _alias = initAliases();
|
|
31
|
-
cliCmds = { ..._cmds, ..._alias };
|
|
32
|
-
}
|
|
33
|
-
async function runCmd(cmdName, args = [], options = {}) {
|
|
34
|
-
if (!(cmdName in cliCmds)) {
|
|
35
|
-
console.log(`Command ${cmdName} not found`);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const cmd = cliCmds[cmdName].cmd;
|
|
39
|
-
await cmd(args, options);
|
|
40
|
-
lastCmd.name = cmdName;
|
|
41
|
-
lastCmd.args = args;
|
|
26
|
+
await chat(program);
|
|
42
27
|
}
|
|
43
28
|
async function buildCmds() {
|
|
44
29
|
const program = new Command();
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return res;
|
|
54
|
-
};
|
|
55
|
-
if ("args" in spec) {
|
|
56
|
-
cmd
|
|
57
|
-
.argument("<args...>", spec.args)
|
|
58
|
-
.description(spec.description)
|
|
59
|
-
.action(_cmd);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
cmd
|
|
63
|
-
.argument("[args...]", "No arguments")
|
|
64
|
-
.description(spec.description)
|
|
65
|
-
.action(_cmd);
|
|
66
|
-
}
|
|
67
|
-
for (const [_name, _spec] of Object.entries(modes)) {
|
|
68
|
-
cmd.option(_name, _spec.description);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
30
|
+
initBaseCommands(program);
|
|
31
|
+
const aliases = readAliases();
|
|
32
|
+
const feats = readFeatures();
|
|
33
|
+
initCommandsFromAliases(program, aliases, feats);
|
|
34
|
+
const cmds = await initUserCmds(feats.cmd);
|
|
35
|
+
cmds.forEach(c => {
|
|
36
|
+
program.addCommand(c);
|
|
37
|
+
});
|
|
71
38
|
return program;
|
|
72
39
|
}
|
|
73
|
-
async function parseCmd() {
|
|
74
|
-
const program = await buildCmds();
|
|
40
|
+
async function parseCmd(program) {
|
|
75
41
|
await program.parseAsync();
|
|
76
42
|
if (isChatMode.value) {
|
|
77
|
-
await chat();
|
|
43
|
+
await chat(program);
|
|
78
44
|
}
|
|
79
45
|
}
|
|
80
|
-
export { buildCmds, chat,
|
|
46
|
+
export { buildCmds, chat, parseCmd, };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AgentTask } from "@agent-smith/jobs";
|
|
2
2
|
import { FeatureType } from "../../../interfaces.js";
|
|
3
|
+
declare function executeAction(name: string, payload: Record<string, any>, options: Record<string, any>, quiet?: boolean): Promise<any>;
|
|
4
|
+
declare function executeActionCmd(name: string, aargs: Array<any>, quiet?: boolean): Promise<any>;
|
|
3
5
|
declare function systemAction(path: string): AgentTask<FeatureType, Array<string>, any>;
|
|
4
6
|
declare function pythonAction(path: string): AgentTask<FeatureType, Array<string>>;
|
|
5
|
-
|
|
6
|
-
export { executeActionCmd, systemAction, pythonAction };
|
|
7
|
+
export { executeAction, executeActionCmd, systemAction, pythonAction, };
|