@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.
- package/README.md +274 -34
- package/dist/cli.js +4 -8
- package/dist/cmd/{clicmds/aliases.d.ts → aliases.d.ts} +1 -1
- package/dist/cmd/{clicmds/aliases.js → aliases.js} +1 -26
- package/dist/cmd/{clicmds/base.js → base.js} +21 -17
- package/dist/cmd/build.d.ts +9 -0
- package/dist/cmd/build.js +59 -0
- package/dist/cmd/callbacks.d.ts +11 -0
- package/dist/cmd/callbacks.js +90 -0
- package/dist/cmd/cmds.d.ts +8 -9
- package/dist/cmd/cmds.js +134 -103
- package/dist/cmd/features.d.ts +6 -0
- package/dist/cmd/features.js +57 -0
- package/dist/cmd/{sys/read_cmds.d.ts → read_cmds.d.ts} +1 -1
- package/dist/cmd/{sys/read_cmds.js → read_cmds.js} +1 -1
- package/dist/cmd/user_cmds.d.ts +3 -0
- package/dist/cmd/user_cmds.js +23 -0
- package/dist/index.js +11 -11
- package/dist/main.d.ts +3 -38
- package/dist/main.js +3 -37
- package/dist/state.d.ts +6 -0
- package/dist/state.js +8 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +50 -0
- package/package.json +10 -20
- package/dist/cmd/clicmds/cmds.d.ts +0 -7
- package/dist/cmd/clicmds/cmds.js +0 -135
- package/dist/cmd/clicmds/updateconf.d.ts +0 -3
- package/dist/cmd/clicmds/updateconf.js +0 -74
- package/dist/cmd/lib/actions/cmd.d.ts +0 -6
- package/dist/cmd/lib/actions/cmd.js +0 -154
- package/dist/cmd/lib/actions/read.d.ts +0 -3
- package/dist/cmd/lib/actions/read.js +0 -17
- package/dist/cmd/lib/adaptaters/cmd.d.ts +0 -2
- package/dist/cmd/lib/adaptaters/cmd.js +0 -39
- package/dist/cmd/lib/agents/cmd.d.ts +0 -3
- package/dist/cmd/lib/agents/cmd.js +0 -11
- package/dist/cmd/lib/mcp.d.ts +0 -16
- package/dist/cmd/lib/mcp.js +0 -105
- package/dist/cmd/lib/options_parsers.d.ts +0 -7
- package/dist/cmd/lib/options_parsers.js +0 -52
- package/dist/cmd/lib/tasks/cmd.d.ts +0 -4
- package/dist/cmd/lib/tasks/cmd.js +0 -419
- package/dist/cmd/lib/tasks/conf.d.ts +0 -6
- package/dist/cmd/lib/tasks/conf.js +0 -131
- package/dist/cmd/lib/tasks/read.d.ts +0 -14
- package/dist/cmd/lib/tasks/read.js +0 -186
- package/dist/cmd/lib/tasks/utils.d.ts +0 -8
- package/dist/cmd/lib/tasks/utils.js +0 -48
- package/dist/cmd/lib/tools.d.ts +0 -15
- package/dist/cmd/lib/tools.js +0 -147
- package/dist/cmd/lib/utils.d.ts +0 -3
- package/dist/cmd/lib/utils.js +0 -54
- package/dist/cmd/lib/workflows/cmd.d.ts +0 -3
- package/dist/cmd/lib/workflows/cmd.js +0 -230
- package/dist/cmd/lib/workflows/read.d.ts +0 -6
- package/dist/cmd/lib/workflows/read.js +0 -61
- package/dist/cmd/sys/clipboard.d.ts +0 -3
- package/dist/cmd/sys/clipboard.js +0 -33
- package/dist/cmd/sys/delete_file.d.ts +0 -2
- package/dist/cmd/sys/delete_file.js +0 -10
- package/dist/cmd/sys/dirs.d.ts +0 -2
- package/dist/cmd/sys/dirs.js +0 -9
- package/dist/cmd/sys/execute.d.ts +0 -13
- package/dist/cmd/sys/execute.js +0 -48
- package/dist/cmd/sys/read.d.ts +0 -3
- package/dist/cmd/sys/read.js +0 -21
- package/dist/cmd/sys/read_conf.d.ts +0 -6
- package/dist/cmd/sys/read_conf.js +0 -12
- package/dist/cmd/sys/read_features.d.ts +0 -3
- package/dist/cmd/sys/read_features.js +0 -112
- package/dist/cmd/sys/read_task.d.ts +0 -6
- package/dist/cmd/sys/read_task.js +0 -23
- package/dist/cmd/sys/read_yml_file.d.ts +0 -5
- package/dist/cmd/sys/read_yml_file.js +0 -11
- package/dist/cmd/sys/run_python.d.ts +0 -6
- package/dist/cmd/sys/run_python.js +0 -39
- package/dist/conf.d.ts +0 -14
- package/dist/conf.js +0 -166
- package/dist/const.d.ts +0 -3
- package/dist/const.js +0 -24
- package/dist/db/db.d.ts +0 -4
- package/dist/db/db.js +0 -23
- package/dist/db/read.d.ts +0 -34
- package/dist/db/read.js +0 -128
- package/dist/db/schemas.d.ts +0 -2
- package/dist/db/schemas.js +0 -105
- package/dist/db/write.d.ts +0 -15
- package/dist/db/write.js +0 -376
- package/dist/interfaces.d.ts +0 -165
- package/dist/interfaces.js +0 -1
- package/dist/state/backends.d.ts +0 -7
- package/dist/state/backends.js +0 -159
- package/dist/state/chat.d.ts +0 -7
- package/dist/state/chat.js +0 -10
- package/dist/state/features.d.ts +0 -8
- package/dist/state/features.js +0 -35
- package/dist/state/plugins.d.ts +0 -6
- package/dist/state/plugins.js +0 -27
- package/dist/state/state.d.ts +0 -20
- package/dist/state/state.js +0 -80
- package/dist/state/tasks.d.ts +0 -6
- package/dist/state/tasks.js +0 -28
- package/dist/utils/perf.d.ts +0 -9
- package/dist/utils/perf.js +0 -63
- package/dist/utils/text.d.ts +0 -6
- package/dist/utils/text.js +0 -41
- package/dist/utils/user_msgs.d.ts +0 -5
- package/dist/utils/user_msgs.js +0 -19
- /package/dist/cmd/{clicmds/base.d.ts → base.d.ts} +0 -0
- /package/dist/{cmd/options.d.ts → options.d.ts} +0 -0
- /package/dist/{cmd/options.js → options.js} +0 -0
- /package/dist/{cmd/lib/user_msgs.d.ts → user_msgs.d.ts} +0 -0
- /package/dist/{cmd/lib/user_msgs.js → user_msgs.js} +0 -0
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import colors from "ansi-colors";
|
|
2
|
-
import { pathToFileURL } from "node:url";
|
|
3
|
-
import { getFeatureSpec } from "../../../state/features.js";
|
|
4
|
-
import { executeAction } from "../actions/cmd.js";
|
|
5
|
-
import { executeAdaptater } from "../adaptaters/cmd.js";
|
|
6
|
-
import { parseCommandArgs } from "../options_parsers.js";
|
|
7
|
-
import { executeTask } from "../tasks/cmd.js";
|
|
8
|
-
import { getInputFromOptions, getTaskPrompt } from "../tasks/utils.js";
|
|
9
|
-
import { runtimeError } from "../user_msgs.js";
|
|
10
|
-
import { readWorkflow } from "./read.js";
|
|
11
|
-
async function executeWorkflow(wname, args, options = {}) {
|
|
12
|
-
const { workflow, found } = await readWorkflow(wname);
|
|
13
|
-
if (!found) {
|
|
14
|
-
throw new Error(`Workflow ${wname} not found`);
|
|
15
|
-
}
|
|
16
|
-
const isDebug = options?.debug === true;
|
|
17
|
-
const isVerbose = options?.verbose === true;
|
|
18
|
-
const stepNames = Object.keys(workflow);
|
|
19
|
-
if (isDebug || isVerbose) {
|
|
20
|
-
console.log("Running workflow", wname, stepNames.length, "steps");
|
|
21
|
-
}
|
|
22
|
-
let i = 0;
|
|
23
|
-
const finalTaskIndex = stepNames.length - 1;
|
|
24
|
-
let taskRes = { cmdArgs: args };
|
|
25
|
-
//console.log("WPARAMS", taskRes);
|
|
26
|
-
let prevStepType = null;
|
|
27
|
-
for (const step of workflow) {
|
|
28
|
-
if (isDebug || isVerbose) {
|
|
29
|
-
console.log(i + 1, step.name, colors.dim(step.type));
|
|
30
|
-
}
|
|
31
|
-
switch (step.type) {
|
|
32
|
-
case "task":
|
|
33
|
-
try {
|
|
34
|
-
let tdata = taskRes;
|
|
35
|
-
if (i == 0) {
|
|
36
|
-
tdata.prompt = await getTaskPrompt(step.name, taskRes.cmdArgs, options);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
if (prevStepType) {
|
|
40
|
-
if (prevStepType == "task") {
|
|
41
|
-
tdata.prompt = taskRes.answer.text;
|
|
42
|
-
}
|
|
43
|
-
else if (prevStepType == "action") {
|
|
44
|
-
if (taskRes?.args) {
|
|
45
|
-
if (typeof taskRes.args == "string") {
|
|
46
|
-
tdata.prompt = taskRes.args;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (!tdata?.prompt) {
|
|
53
|
-
throw new Error(`Workflow ${wname} step ${i + 1}: provide a prompt for the task ${step.name}`);
|
|
54
|
-
}
|
|
55
|
-
options.isAgent = false;
|
|
56
|
-
const tr = await executeTask(step.name, tdata, options);
|
|
57
|
-
taskRes = { ...tr, ...taskRes };
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
throw new Error(`workflow task ${i + 1}: ${e}`);
|
|
61
|
-
}
|
|
62
|
-
break;
|
|
63
|
-
case "agent":
|
|
64
|
-
try {
|
|
65
|
-
let tdata = taskRes;
|
|
66
|
-
if (i == 0) {
|
|
67
|
-
tdata.prompt = await getTaskPrompt(step.name, taskRes.cmdArgs, options);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
if (prevStepType) {
|
|
71
|
-
if (prevStepType == "task") {
|
|
72
|
-
tdata.prompt = taskRes.answer.text;
|
|
73
|
-
}
|
|
74
|
-
else if (prevStepType == "action") {
|
|
75
|
-
if (taskRes?.args) {
|
|
76
|
-
if (typeof taskRes.args == "string") {
|
|
77
|
-
tdata.prompt = taskRes.args;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (!tdata?.prompt) {
|
|
84
|
-
throw new Error(`Workflow ${wname} step ${i + 1}: provide a prompt for the task ${step.name}`);
|
|
85
|
-
}
|
|
86
|
-
options.isAgent = true;
|
|
87
|
-
const tr = await executeTask(step.name, tdata, options);
|
|
88
|
-
options.isAgent = false;
|
|
89
|
-
taskRes = { ...tr, ...taskRes };
|
|
90
|
-
}
|
|
91
|
-
catch (e) {
|
|
92
|
-
throw new Error(`workflow task ${i + 1}: ${e}`);
|
|
93
|
-
}
|
|
94
|
-
break;
|
|
95
|
-
case "action":
|
|
96
|
-
try {
|
|
97
|
-
//console.log("EXEC ACTION ARGS", taskRes);
|
|
98
|
-
//const actArgs = i == 0 ? taskRes.cmdArgs : taskRes;
|
|
99
|
-
let actArgs;
|
|
100
|
-
if (i == 0) {
|
|
101
|
-
actArgs = taskRes.cmdArgs;
|
|
102
|
-
const inputData = await getInputFromOptions(options);
|
|
103
|
-
if (inputData) {
|
|
104
|
-
actArgs.push(inputData);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
actArgs = taskRes;
|
|
109
|
-
}
|
|
110
|
-
const ares = await executeAction(step.name, actArgs, options, true);
|
|
111
|
-
//console.log("WF ACTION RES", typeof ares, ares);
|
|
112
|
-
//console.log("LAST ACT", i, finalTaskIndex);
|
|
113
|
-
if (i == finalTaskIndex && !options?.isToolCall && !options?.quiet) {
|
|
114
|
-
console.log(ares);
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
if (typeof ares == "string" || Array.isArray(ares)) {
|
|
118
|
-
taskRes.args = ares;
|
|
119
|
-
//console.log("ARRAY ACTION RES", taskRes)
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
taskRes = { ...ares, ...taskRes };
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
throw new Error(`workflow action ${i + 1}: ${e}`);
|
|
127
|
-
}
|
|
128
|
-
//console.log("END ACTION", step.name)
|
|
129
|
-
break;
|
|
130
|
-
case "adaptater":
|
|
131
|
-
try {
|
|
132
|
-
//console.log("WF AD ARGS IN", taskRes);
|
|
133
|
-
//console.log("AD OPTS IN", options);
|
|
134
|
-
let actArgs;
|
|
135
|
-
if (i == 0) {
|
|
136
|
-
//console.log("TR", taskRes);
|
|
137
|
-
actArgs = taskRes.cmdArgs;
|
|
138
|
-
//console.log("ACT ARGS", actArgs);
|
|
139
|
-
const inputData = await getInputFromOptions(options);
|
|
140
|
-
if (inputData) {
|
|
141
|
-
actArgs.push(inputData);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
actArgs = taskRes;
|
|
146
|
-
}
|
|
147
|
-
const adres = await executeAdaptater(step.name, actArgs, options);
|
|
148
|
-
//console.log("WF AD FINAL RES", taskRes);
|
|
149
|
-
//console.log("LAST ACT", i, finalTaskIndex);
|
|
150
|
-
if (i == finalTaskIndex && !options?.isToolCall && !options?.quiet) {
|
|
151
|
-
console.log(adres);
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
//console.log("WF AD RES", typeof adres, adres);
|
|
155
|
-
if (typeof adres == "string" || Array.isArray(adres)) {
|
|
156
|
-
taskRes.args = adres;
|
|
157
|
-
//console.log("WF AD IT RES", taskRes);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
taskRes = { ...adres };
|
|
161
|
-
}
|
|
162
|
-
//console.log("WF ADAPT RES", typeof ares, Array.isArray(ares) ? ares.length : "NA");
|
|
163
|
-
}
|
|
164
|
-
catch (e) {
|
|
165
|
-
throw new Error(`workflow adaptater ${i + 1}: ${e}`);
|
|
166
|
-
}
|
|
167
|
-
break;
|
|
168
|
-
case "cmd":
|
|
169
|
-
try {
|
|
170
|
-
const { found, path } = getFeatureSpec(step.name, "cmd");
|
|
171
|
-
if (!found) {
|
|
172
|
-
throw new Error(`Command ${step.name} not found`);
|
|
173
|
-
}
|
|
174
|
-
const url = pathToFileURL(path).href;
|
|
175
|
-
let jsa;
|
|
176
|
-
try {
|
|
177
|
-
jsa = await import(/* @vite-ignore */ url);
|
|
178
|
-
}
|
|
179
|
-
catch (e) {
|
|
180
|
-
throw new Error(`cmd import error ${e}`);
|
|
181
|
-
}
|
|
182
|
-
if (!jsa?.runCmd) {
|
|
183
|
-
runtimeError(`workflow ${wname}: can not import the runCmd function from step ${i} for command ${step.name}: please add a runCmd function export`);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
let cArgs;
|
|
187
|
-
if (i == 0) {
|
|
188
|
-
cArgs = taskRes.cmdArgs;
|
|
189
|
-
const inputData = await getInputFromOptions(options);
|
|
190
|
-
if (inputData) {
|
|
191
|
-
cArgs.push(inputData);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
cArgs = taskRes;
|
|
196
|
-
}
|
|
197
|
-
const cres = await jsa.runCmd(cArgs, options);
|
|
198
|
-
if (typeof cres == "string" || Array.isArray(cres)) {
|
|
199
|
-
taskRes.args = cres;
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
taskRes = { ...cres, ...taskRes };
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
catch (e) {
|
|
206
|
-
throw new Error(`workflow command ${i + 1}: ${e}`);
|
|
207
|
-
}
|
|
208
|
-
break;
|
|
209
|
-
default:
|
|
210
|
-
throw new Error(`unknown workflow step type ${step.type} in workflow ${wname}`);
|
|
211
|
-
}
|
|
212
|
-
prevStepType = step.type;
|
|
213
|
-
//console.log("WF NODE RES", step.type, taskRes);
|
|
214
|
-
/*if (isDebug) {
|
|
215
|
-
console.log("->", params);
|
|
216
|
-
}*/
|
|
217
|
-
//console.log("WFR", taskRes)
|
|
218
|
-
++i;
|
|
219
|
-
}
|
|
220
|
-
//console.log("WF RES")
|
|
221
|
-
return taskRes;
|
|
222
|
-
}
|
|
223
|
-
async function executeWorkflowCmd(name, wargs) {
|
|
224
|
-
//console.log("WF INITIAL ARGS", typeof wargs, wargs.slice(0, -1));
|
|
225
|
-
const { args, options } = parseCommandArgs(wargs);
|
|
226
|
-
//console.log("WF ARGS", typeof args, args);
|
|
227
|
-
//console.log("WF OPTS", options);
|
|
228
|
-
return await executeWorkflow(name, args, options);
|
|
229
|
-
}
|
|
230
|
-
export { executeWorkflow, executeWorkflowCmd };
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { default as fs } from "fs";
|
|
2
|
-
import YAML from 'yaml';
|
|
3
|
-
import { getFeatureSpec } from '../../../state/features.js';
|
|
4
|
-
async function _createWorkflowFromSpec(spec) {
|
|
5
|
-
const steps = [];
|
|
6
|
-
//console.log("Create WF. Steps:", spec);
|
|
7
|
-
for (const step of spec.steps) {
|
|
8
|
-
const type = Object.keys(step)[0];
|
|
9
|
-
const sval = step[type];
|
|
10
|
-
const name = sval;
|
|
11
|
-
const wf = {
|
|
12
|
-
name: name,
|
|
13
|
-
type: type == "command" ? "cmd" : type,
|
|
14
|
-
};
|
|
15
|
-
steps.push(wf);
|
|
16
|
-
}
|
|
17
|
-
//console.log("STEPS", Object.keys(steps).length, steps);
|
|
18
|
-
return steps;
|
|
19
|
-
}
|
|
20
|
-
async function _readWorkflowFromDisk(name) {
|
|
21
|
-
//const fp = path.join(jobsPath, `${name}.yml`);
|
|
22
|
-
const { found, path } = getFeatureSpec(name, "workflow");
|
|
23
|
-
if (!found) {
|
|
24
|
-
return { found: false, data: {} };
|
|
25
|
-
}
|
|
26
|
-
if (!fs.existsSync(path)) {
|
|
27
|
-
return { data: {}, found: false };
|
|
28
|
-
}
|
|
29
|
-
const file = fs.readFileSync(path, 'utf8');
|
|
30
|
-
const data = YAML.parse(file);
|
|
31
|
-
data.name = name;
|
|
32
|
-
return { data: data, found: true };
|
|
33
|
-
}
|
|
34
|
-
async function readWorkflow(name) {
|
|
35
|
-
const { found, ext } = getFeatureSpec(name, "workflow");
|
|
36
|
-
if (!found) {
|
|
37
|
-
return { found: false, workflow: [] };
|
|
38
|
-
}
|
|
39
|
-
let wf = new Array();
|
|
40
|
-
switch (ext) {
|
|
41
|
-
case "yml":
|
|
42
|
-
const { data } = await _readWorkflowFromDisk(name);
|
|
43
|
-
//console.log("WF DATA", data);
|
|
44
|
-
try {
|
|
45
|
-
const workflow = await _createWorkflowFromSpec(data);
|
|
46
|
-
//console.log("WF END", found, workflow);
|
|
47
|
-
if (!found) {
|
|
48
|
-
return { found: false, workflow: [] };
|
|
49
|
-
}
|
|
50
|
-
wf = workflow;
|
|
51
|
-
}
|
|
52
|
-
catch (e) {
|
|
53
|
-
throw new Error(`Workflow ${name} create error: ${e}`);
|
|
54
|
-
}
|
|
55
|
-
break;
|
|
56
|
-
default:
|
|
57
|
-
throw new Error(`Workflow ${name} extension ${ext} not implemented`);
|
|
58
|
-
}
|
|
59
|
-
return { found: true, workflow: wf };
|
|
60
|
-
}
|
|
61
|
-
export { readWorkflow };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import clipboard from 'clipboardy';
|
|
2
|
-
//import { execute } from "./execute.js";
|
|
3
|
-
//const { platform } = process;
|
|
4
|
-
async function readClipboard() {
|
|
5
|
-
/*let res = "";
|
|
6
|
-
if (platform == "linux") {
|
|
7
|
-
res = await execute("xclip", ["-o", "-selection", "primary"]);
|
|
8
|
-
} else {
|
|
9
|
-
res = await clipboard.read();
|
|
10
|
-
}
|
|
11
|
-
return res*/
|
|
12
|
-
return await clipboard.read();
|
|
13
|
-
}
|
|
14
|
-
async function writeToClipboard(data) {
|
|
15
|
-
await clipboard.write(data);
|
|
16
|
-
}
|
|
17
|
-
/*import { platform } from "os";
|
|
18
|
-
|
|
19
|
-
async function getClipboard(): Promise<string> {
|
|
20
|
-
const currentPlatform = platform();
|
|
21
|
-
|
|
22
|
-
switch (currentPlatform) {
|
|
23
|
-
case 'darwin': // macOS
|
|
24
|
-
return await execute("pbpaste", []);
|
|
25
|
-
case 'win32': // Windows
|
|
26
|
-
return await execute("powershell", ["-command", "Get-Clipboard"]);
|
|
27
|
-
case 'linux': // Linux
|
|
28
|
-
return await execute("xclip", ["-o", "-selection", "clipboard"]);
|
|
29
|
-
default:
|
|
30
|
-
throw new Error(`Unsupported platform: ${currentPlatform}`);
|
|
31
|
-
}
|
|
32
|
-
}*/
|
|
33
|
-
export { readClipboard, writeToClipboard, };
|
package/dist/cmd/sys/dirs.d.ts
DELETED
package/dist/cmd/sys/dirs.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
function createDirectoryIfNotExists(dirPath, recursive = false) {
|
|
4
|
-
const resolvedDirPath = path.resolve(dirPath);
|
|
5
|
-
if (!fs.existsSync(resolvedDirPath)) {
|
|
6
|
-
fs.mkdirSync(resolvedDirPath, { recursive: recursive });
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export { createDirectoryIfNotExists };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
declare function execute(command: string, args?: Array<string>, { onStdout, onStderr, onError, stream, }?: {
|
|
2
|
-
onStderr?: (data: any) => void;
|
|
3
|
-
onError?: (err: any) => void;
|
|
4
|
-
onStdout?: ((data: any) => void) | undefined;
|
|
5
|
-
stream?: boolean | undefined;
|
|
6
|
-
}): Promise<string>;
|
|
7
|
-
declare function run(command: string, args?: Array<string>, { onStdout, onStderr, onError, onFinished, }?: {
|
|
8
|
-
onStdout?: (data: any) => void;
|
|
9
|
-
onStderr?: (data: any) => void;
|
|
10
|
-
onError?: (err: any) => void;
|
|
11
|
-
onFinished?: () => void;
|
|
12
|
-
}): () => boolean;
|
|
13
|
-
export { execute, run };
|
package/dist/cmd/sys/execute.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { spawn } from "child_process";
|
|
2
|
-
import { platform } from "os";
|
|
3
|
-
async function execute(command, args = [], { onStdout = (data) => { }, onStderr = (data) => { }, onError = (data) => { }, stream = false, } = {
|
|
4
|
-
onStderr: (data) => console.log("stderr:", data),
|
|
5
|
-
onError: (err) => { if (err)
|
|
6
|
-
throw err; },
|
|
7
|
-
}) {
|
|
8
|
-
let buffer = new Array();
|
|
9
|
-
//console.log("Cmd args:", args)
|
|
10
|
-
const useShell = platform() === 'win32';
|
|
11
|
-
const child = spawn(command, args, { shell: useShell });
|
|
12
|
-
child.stdout.setEncoding('utf8');
|
|
13
|
-
child.stdout.on('data', (data) => {
|
|
14
|
-
buffer.push(data);
|
|
15
|
-
onStdout(data);
|
|
16
|
-
});
|
|
17
|
-
child.stderr.setEncoding('utf8');
|
|
18
|
-
child.stderr.on('data', (data) => onStderr(data));
|
|
19
|
-
child.on("error", (data) => onError(data));
|
|
20
|
-
let finish;
|
|
21
|
-
let end = new Promise((r) => finish = r);
|
|
22
|
-
child.on('close', () => finish(true));
|
|
23
|
-
await end;
|
|
24
|
-
if (!stream) {
|
|
25
|
-
return buffer.join("\n");
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return buffer.join("");
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function run(command, args = [], { onStdout = (data) => { }, onStderr = (data) => { }, onError = (data) => { }, onFinished = () => { }, } = {
|
|
32
|
-
onStdout: (data) => console.log("stdout:", data),
|
|
33
|
-
onStderr: (data) => console.log("stderr:", data),
|
|
34
|
-
onError: (err) => { if (err)
|
|
35
|
-
throw err; },
|
|
36
|
-
onFinished: () => { },
|
|
37
|
-
}) {
|
|
38
|
-
const useShell = platform() === 'win32';
|
|
39
|
-
var child = spawn(command, args, { shell: useShell });
|
|
40
|
-
child.stdout.setEncoding('utf8');
|
|
41
|
-
child.stdout.on('data', (data) => onStdout(data));
|
|
42
|
-
child.stderr.setEncoding('utf8');
|
|
43
|
-
child.stderr.on('data', (data) => onStderr(data));
|
|
44
|
-
child.on("error", (data) => onError(data));
|
|
45
|
-
child.on('close', () => onFinished());
|
|
46
|
-
return () => child.kill();
|
|
47
|
-
}
|
|
48
|
-
export { execute, run };
|
package/dist/cmd/sys/read.d.ts
DELETED
package/dist/cmd/sys/read.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { default as fs } from "fs";
|
|
2
|
-
import { access, constants } from 'fs/promises';
|
|
3
|
-
import { resolve } from 'path';
|
|
4
|
-
function readFile(fp) {
|
|
5
|
-
try {
|
|
6
|
-
return fs.readFileSync(fp, 'utf8');
|
|
7
|
-
}
|
|
8
|
-
catch (e) {
|
|
9
|
-
throw new Error(`reading file ${e}}`);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
async function checkIfFileExists(filePath) {
|
|
13
|
-
try {
|
|
14
|
-
await access(resolve(filePath), constants.F_OK);
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export { readFile, checkIfFileExists, };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { default as fs } from "fs";
|
|
2
|
-
import YAML from 'yaml';
|
|
3
|
-
function readConf(confPath) {
|
|
4
|
-
if (!fs.existsSync(confPath)) {
|
|
5
|
-
return { data: {}, found: false };
|
|
6
|
-
}
|
|
7
|
-
const file = fs.readFileSync(confPath, 'utf8');
|
|
8
|
-
const data = YAML.parse(file);
|
|
9
|
-
//console.log("READ CONF", data);
|
|
10
|
-
return { data: data, found: true };
|
|
11
|
-
}
|
|
12
|
-
export { readConf };
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { default as fs } from "fs";
|
|
2
|
-
import { default as path } from "path";
|
|
3
|
-
function _readDir(dir, ext) {
|
|
4
|
-
const fileNames = new Array;
|
|
5
|
-
fs.readdirSync(dir).forEach((filename) => {
|
|
6
|
-
const filepath = path.join(dir, filename);
|
|
7
|
-
//console.log("F", filepath);
|
|
8
|
-
const isDir = fs.statSync(filepath).isDirectory();
|
|
9
|
-
if (!isDir) {
|
|
10
|
-
if (ext.includes(path.extname(filename))) {
|
|
11
|
-
fileNames.push(filename);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
return fileNames;
|
|
16
|
-
}
|
|
17
|
-
function readFeaturesDir(dir) {
|
|
18
|
-
const feats = {
|
|
19
|
-
task: [],
|
|
20
|
-
action: [],
|
|
21
|
-
cmd: [],
|
|
22
|
-
workflow: [],
|
|
23
|
-
adaptater: [],
|
|
24
|
-
agent: [],
|
|
25
|
-
};
|
|
26
|
-
let dirpath = path.join(dir, "tasks");
|
|
27
|
-
if (fs.existsSync(dirpath)) {
|
|
28
|
-
const data = _readDir(dirpath, [".yml"]);
|
|
29
|
-
data.forEach((filename) => {
|
|
30
|
-
const parts = filename.split(".");
|
|
31
|
-
const ext = parts.pop();
|
|
32
|
-
const name = parts.join("");
|
|
33
|
-
feats.task.push({
|
|
34
|
-
name: name,
|
|
35
|
-
path: path.join(dirpath),
|
|
36
|
-
ext: ext,
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
dirpath = path.join(dir, "agents");
|
|
41
|
-
if (fs.existsSync(dirpath)) {
|
|
42
|
-
const data = _readDir(dirpath, [".yml"]);
|
|
43
|
-
data.forEach((filename) => {
|
|
44
|
-
const parts = filename.split(".");
|
|
45
|
-
const ext = parts.pop();
|
|
46
|
-
const name = parts.join("");
|
|
47
|
-
feats.agent.push({
|
|
48
|
-
name: name,
|
|
49
|
-
path: path.join(dirpath),
|
|
50
|
-
ext: ext,
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
dirpath = path.join(dir, "workflows");
|
|
55
|
-
if (fs.existsSync(dirpath)) {
|
|
56
|
-
const data = _readDir(dirpath, [".yml"]);
|
|
57
|
-
data.forEach((filename) => {
|
|
58
|
-
const parts = filename.split(".");
|
|
59
|
-
const ext = parts.pop();
|
|
60
|
-
const name = parts.join("");
|
|
61
|
-
feats.workflow.push({
|
|
62
|
-
name: name,
|
|
63
|
-
path: path.join(dirpath),
|
|
64
|
-
ext: ext,
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
dirpath = path.join(dir, "actions");
|
|
69
|
-
if (fs.existsSync(dirpath)) {
|
|
70
|
-
const data = _readDir(dirpath, [".yml", ".js", ".py"]);
|
|
71
|
-
data.forEach((filename) => {
|
|
72
|
-
const parts = filename.split(".");
|
|
73
|
-
const ext = parts.pop();
|
|
74
|
-
const name = parts.join("");
|
|
75
|
-
feats.action.push({
|
|
76
|
-
name: name,
|
|
77
|
-
path: path.join(dirpath),
|
|
78
|
-
ext: ext,
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
dirpath = path.join(dir, "adaptaters");
|
|
83
|
-
if (fs.existsSync(dirpath)) {
|
|
84
|
-
const data = _readDir(dirpath, [".js"]);
|
|
85
|
-
data.forEach((filename) => {
|
|
86
|
-
const parts = filename.split(".");
|
|
87
|
-
const ext = parts.pop();
|
|
88
|
-
const name = parts.join("");
|
|
89
|
-
feats.adaptater.push({
|
|
90
|
-
name: name,
|
|
91
|
-
path: path.join(dirpath),
|
|
92
|
-
ext: ext,
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
dirpath = path.join(dir, "cmds");
|
|
97
|
-
if (fs.existsSync(dirpath)) {
|
|
98
|
-
const data = _readDir(dirpath, [".js"]);
|
|
99
|
-
data.forEach((filename) => {
|
|
100
|
-
const parts = filename.split(".");
|
|
101
|
-
const ext = parts.pop();
|
|
102
|
-
const name = parts.join("");
|
|
103
|
-
feats.cmd.push({
|
|
104
|
-
name: name,
|
|
105
|
-
path: path.join(dirpath),
|
|
106
|
-
ext: ext,
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
return feats;
|
|
111
|
-
}
|
|
112
|
-
export { readFeaturesDir };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { default as fs } from "fs";
|
|
2
|
-
import { default as path } from "path";
|
|
3
|
-
function readTask(taskpath) {
|
|
4
|
-
if (!fs.existsSync(taskpath)) {
|
|
5
|
-
return { ymlTask: "", found: false };
|
|
6
|
-
}
|
|
7
|
-
const data = fs.readFileSync(taskpath, 'utf8');
|
|
8
|
-
return { ymlTask: data, found: true };
|
|
9
|
-
}
|
|
10
|
-
function readTasksDir(dir) {
|
|
11
|
-
const tasks = new Array();
|
|
12
|
-
fs.readdirSync(dir).forEach((filename) => {
|
|
13
|
-
const filepath = path.join(dir, filename);
|
|
14
|
-
const isDir = fs.statSync(filepath).isDirectory();
|
|
15
|
-
if (!isDir) {
|
|
16
|
-
if (filename.endsWith(".yml")) {
|
|
17
|
-
tasks.push(filename);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
return tasks;
|
|
22
|
-
}
|
|
23
|
-
export { readTask, readTasksDir, };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { default as fs } from "fs";
|
|
2
|
-
import YAML from 'yaml';
|
|
3
|
-
function readYmlFile(path) {
|
|
4
|
-
if (!fs.existsSync(path)) {
|
|
5
|
-
return { data: {}, found: false };
|
|
6
|
-
}
|
|
7
|
-
const file = fs.readFileSync(path, 'utf8');
|
|
8
|
-
const data = YAML.parse(file);
|
|
9
|
-
return { data: data, found: true };
|
|
10
|
-
}
|
|
11
|
-
export { readYmlFile };
|