@agent-smith/core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +378 -0
  2. package/dist/actions/cmd.d.ts +5 -0
  3. package/dist/actions/cmd.js +135 -0
  4. package/dist/actions/read.d.ts +3 -0
  5. package/dist/actions/read.js +17 -0
  6. package/dist/adaptaters/cmd.d.ts +2 -0
  7. package/dist/adaptaters/cmd.js +39 -0
  8. package/dist/agents/cmd.d.ts +3 -0
  9. package/dist/agents/cmd.js +10 -0
  10. package/dist/agents/conf.d.ts +3 -0
  11. package/dist/agents/conf.js +9 -0
  12. package/dist/agents/files.d.ts +3 -0
  13. package/dist/agents/files.js +40 -0
  14. package/dist/agents/read.d.ts +11 -0
  15. package/dist/agents/read.js +241 -0
  16. package/dist/agents/useagent.d.ts +13 -0
  17. package/dist/agents/useagent.js +395 -0
  18. package/dist/conf.d.ts +14 -0
  19. package/dist/conf.js +160 -0
  20. package/dist/const.d.ts +3 -0
  21. package/dist/const.js +10 -0
  22. package/dist/db/db.d.ts +3 -0
  23. package/dist/db/db.js +24 -0
  24. package/dist/db/read.d.ts +45 -0
  25. package/dist/db/read.js +280 -0
  26. package/dist/db/schemas.d.ts +2 -0
  27. package/dist/db/schemas.js +141 -0
  28. package/dist/db/write.d.ts +23 -0
  29. package/dist/db/write.js +570 -0
  30. package/dist/features/actions/load-skill.d.ts +2 -0
  31. package/dist/features/actions/load-skill.js +37 -0
  32. package/dist/features/actions/notify-user.d.ts +2 -0
  33. package/dist/features/actions/notify-user.js +25 -0
  34. package/dist/features/actions/read-feature.d.ts +2 -0
  35. package/dist/features/actions/read-feature.js +25 -0
  36. package/dist/features/actions/run-agent.d.ts +2 -0
  37. package/dist/features/actions/run-agent.js +34 -0
  38. package/dist/features/actions/run-collaborator.d.ts +1 -0
  39. package/dist/features/actions/run-collaborator.js +42 -0
  40. package/dist/features/actions/run-worker.d.ts +2 -0
  41. package/dist/features/actions/run-worker.js +34 -0
  42. package/dist/features/adaptaters/agent-smith-db-getschema.d.ts +4 -0
  43. package/dist/features/adaptaters/agent-smith-db-getschema.js +62 -0
  44. package/dist/features/adaptaters/imgs2base64.d.ts +1 -0
  45. package/dist/features/adaptaters/imgs2base64.js +13 -0
  46. package/dist/features/adaptaters/prequery.d.ts +4 -0
  47. package/dist/features/adaptaters/prequery.js +5 -0
  48. package/dist/features/agents/agent-smith-colab.yml +37 -0
  49. package/dist/features/agents/agent-smith-doc.yml +50 -0
  50. package/dist/features/agents/agent-smith-help.yml +35 -0
  51. package/dist/features/agents/agent-smith-search.yml +41 -0
  52. package/dist/features/agents/agent-smith-sql.yml +31 -0
  53. package/dist/features/agents/agent-smith.yml +37 -0
  54. package/dist/features/agents/collaborator.yml +15 -0
  55. package/dist/features/agents/infer.yml +12 -0
  56. package/dist/features/fragments/ctx-helper-files.md +4 -0
  57. package/dist/features/fragments/workspace.txt +6 -0
  58. package/dist/features/skills/create-package-readme/SKILL.md +66 -0
  59. package/dist/features/skills/document-package/SKILL.md +83 -0
  60. package/dist/features/skills/t/SKILL.md +26 -0
  61. package/dist/features/skills/update-codebase-summary/SKILL.md +45 -0
  62. package/dist/features/skills/update-doc-map/SKILL.md +8 -0
  63. package/dist/features/skills/update-doc-map/scripts/generate-doc-map.mjs +196 -0
  64. package/dist/features/workflows/agent-smith-db.yml +9 -0
  65. package/dist/features/workflows/q.yml +3 -0
  66. package/dist/features/workflows/vision.yml +3 -0
  67. package/dist/main.d.ts +127 -0
  68. package/dist/main.js +80 -0
  69. package/dist/mcp.d.ts +16 -0
  70. package/dist/mcp.js +110 -0
  71. package/dist/state/backends.d.ts +7 -0
  72. package/dist/state/backends.js +96 -0
  73. package/dist/state/features.d.ts +10 -0
  74. package/dist/state/features.js +42 -0
  75. package/dist/state/plugins.d.ts +6 -0
  76. package/dist/state/plugins.js +27 -0
  77. package/dist/state/state.d.ts +18 -0
  78. package/dist/state/state.js +79 -0
  79. package/dist/state/tasks.d.ts +6 -0
  80. package/dist/state/tasks.js +33 -0
  81. package/dist/tools.d.ts +15 -0
  82. package/dist/tools.js +149 -0
  83. package/dist/updateconf.d.ts +5 -0
  84. package/dist/updateconf.js +124 -0
  85. package/dist/utils/io.d.ts +10 -0
  86. package/dist/utils/io.js +98 -0
  87. package/dist/utils/perf.d.ts +9 -0
  88. package/dist/utils/perf.js +63 -0
  89. package/dist/utils/sys/clipboard.d.ts +3 -0
  90. package/dist/utils/sys/clipboard.js +33 -0
  91. package/dist/utils/sys/delete_file.d.ts +2 -0
  92. package/dist/utils/sys/delete_file.js +10 -0
  93. package/dist/utils/sys/dirs.d.ts +2 -0
  94. package/dist/utils/sys/dirs.js +9 -0
  95. package/dist/utils/sys/execute.d.ts +13 -0
  96. package/dist/utils/sys/execute.js +48 -0
  97. package/dist/utils/sys/read.d.ts +3 -0
  98. package/dist/utils/sys/read.js +21 -0
  99. package/dist/utils/sys/read_agent.d.ts +6 -0
  100. package/dist/utils/sys/read_agent.js +23 -0
  101. package/dist/utils/sys/read_cmds.d.ts +7 -0
  102. package/dist/utils/sys/read_cmds.js +37 -0
  103. package/dist/utils/sys/read_conf.d.ts +6 -0
  104. package/dist/utils/sys/read_conf.js +12 -0
  105. package/dist/utils/sys/read_features.d.ts +3 -0
  106. package/dist/utils/sys/read_features.js +134 -0
  107. package/dist/utils/sys/read_yml_file.d.ts +5 -0
  108. package/dist/utils/sys/read_yml_file.js +11 -0
  109. package/dist/utils/sys/run_python.d.ts +6 -0
  110. package/dist/utils/sys/run_python.js +39 -0
  111. package/dist/utils/text.d.ts +2 -0
  112. package/dist/utils/text.js +28 -0
  113. package/dist/utils/user_msgs.d.ts +5 -0
  114. package/dist/utils/user_msgs.js +19 -0
  115. package/dist/workflows/cmd.d.ts +3 -0
  116. package/dist/workflows/cmd.js +189 -0
  117. package/dist/workflows/read.d.ts +6 -0
  118. package/dist/workflows/read.js +61 -0
  119. package/package.json +45 -0
@@ -0,0 +1,124 @@
1
+ import path from "path";
2
+ import { confDir, createConfigFileIfNotExists, dbPath, processConfPath } from "./conf.js";
3
+ import { initDb } from "./db/db.js";
4
+ import { readFeaturePaths, readFilePath } from "./db/read.js";
5
+ import { cleanupFeaturePaths, updateAliases, updateDataDirPath, updateFeatures, updatePromptfilePath, upsertFilePath } from "./db/write.js";
6
+ import { getBuiltinFeaturesDirPath, readFeaturesDirs } from "./state/features.js";
7
+ import { readPluginsPaths } from "./state/plugins.js";
8
+ import { dataDirPath, promptfilePath } from "./state/state.js";
9
+ //import { runtimeDataError, runtimeInfo } from './user_msgs.js';
10
+ import { readUserCmd } from "./utils/sys/read_cmds.js";
11
+ import { deleteFileIfExists } from "./utils/sys/delete_file.js";
12
+ async function getUserCmdsData(feats) {
13
+ for (const feat of feats.cmd) {
14
+ const cmdPath = path.join(feat.path, feat.name + "." + feat.ext);
15
+ const { found, userCmd } = await readUserCmd(feat.name, cmdPath);
16
+ //console.log("READ CMD", userCmd);
17
+ if (!userCmd?.name) {
18
+ throw new Error(`provide a name for the ${feat.path} command`);
19
+ }
20
+ if (!userCmd?.description) {
21
+ throw new Error(`provide a description for the ${feat.path} command`);
22
+ }
23
+ if (found) {
24
+ feat.variables = {
25
+ description: userCmd.description,
26
+ name: userCmd.name,
27
+ };
28
+ if (userCmd?.options) {
29
+ feat.variables.options = userCmd.options;
30
+ }
31
+ }
32
+ }
33
+ return feats;
34
+ }
35
+ async function updateAllFeatures(paths, userFeats) {
36
+ //console.log("updateAllFeatures", paths);
37
+ const p = [getBuiltinFeaturesDirPath(), ...paths];
38
+ let feats = readFeaturesDirs(p, true);
39
+ feats = await getUserCmdsData(feats);
40
+ if (userFeats?.action) {
41
+ feats.action.push(...userFeats.action);
42
+ }
43
+ if (userFeats?.adaptater) {
44
+ feats.adaptater.push(...userFeats.adaptater);
45
+ }
46
+ if (userFeats?.agent) {
47
+ feats.agent.push(...userFeats.agent);
48
+ }
49
+ if (userFeats?.cmd) {
50
+ feats.cmd.push(...userFeats.cmd);
51
+ }
52
+ if (userFeats?.workflow) {
53
+ feats.workflow.push(...userFeats.workflow);
54
+ }
55
+ if (userFeats?.skill) {
56
+ feats.skill.push(...userFeats.skill);
57
+ }
58
+ updateFeatures(feats);
59
+ updateAliases(feats);
60
+ const deleted = cleanupFeaturePaths(paths);
61
+ for (const el of deleted) {
62
+ console.log("- [feature path]", el);
63
+ }
64
+ }
65
+ async function updateFeaturesCmd(options, userFeats) {
66
+ const fp = readFeaturePaths();
67
+ const pp = await readPluginsPaths();
68
+ const paths = [...fp, ...pp];
69
+ updateAllFeatures(paths, userFeats);
70
+ }
71
+ async function recreateDbFromConf() {
72
+ // try to find a conf path in db
73
+ let confPath;
74
+ const cf = readFilePath("conf");
75
+ if (cf.found) {
76
+ confPath = cf.path;
77
+ }
78
+ else {
79
+ // use default conf path
80
+ confPath = path.join(confDir, "config.yml");
81
+ }
82
+ console.log("Deleting db");
83
+ deleteFileIfExists(dbPath);
84
+ console.log("Using", confPath, "to recreate the db");
85
+ await updateConfCmd([confPath]);
86
+ console.log(`Config recreated db ${dbPath} from ${confPath} ok`);
87
+ }
88
+ async function updateConfCmd(args) {
89
+ initDb(false, true);
90
+ let confPath;
91
+ const userProvidedConfPath = (args[0] != "conf") ? args[0] : null;
92
+ if (userProvidedConfPath) {
93
+ confPath = userProvidedConfPath;
94
+ const isu = upsertFilePath("conf", confPath);
95
+ if (isu) {
96
+ console.log("Config path", confPath, "updated");
97
+ }
98
+ }
99
+ else {
100
+ // try to find a conf path in db
101
+ const cf = readFilePath("conf");
102
+ if (cf.found) {
103
+ confPath = cf.path;
104
+ }
105
+ else {
106
+ // use default conf path
107
+ confPath = path.join(confDir, "config.yml");
108
+ upsertFilePath("conf", confPath);
109
+ }
110
+ }
111
+ createConfigFileIfNotExists(confPath);
112
+ const { paths, pf, dd } = await processConfPath(confPath);
113
+ console.log("Using", confPath, "to update features");
114
+ if (pf.length > 0) {
115
+ updatePromptfilePath(pf);
116
+ promptfilePath.value = pf;
117
+ }
118
+ if (dd.length > 0) {
119
+ updateDataDirPath(dd);
120
+ dataDirPath.value = dd;
121
+ }
122
+ updateAllFeatures(paths);
123
+ }
124
+ export { updateConfCmd, updateFeaturesCmd, recreateDbFromConf, };
@@ -0,0 +1,10 @@
1
+ import type { InferenceResult, AgentSpec } from "@agent-smith/types";
2
+ declare function readPromptFile(): string;
3
+ declare function processOutput(res: InferenceResult): Promise<void>;
4
+ declare function openAgentSpec(name: string): {
5
+ agentSpec: AgentSpec;
6
+ agentPath: string;
7
+ };
8
+ declare function getInputFromOptions(options: Record<string, any>): Promise<string | null>;
9
+ declare function getAgentPrompt(name: string, args: Array<any> | Record<string, any>, options: Record<string, any>): Promise<string>;
10
+ export { getAgentPrompt, getInputFromOptions, openAgentSpec, readPromptFile, processOutput, };
@@ -0,0 +1,98 @@
1
+ import YAML from 'yaml';
2
+ import { readClipboard } from '../utils/sys/clipboard.js';
3
+ import { readAgent } from "../utils/sys/read_agent.js";
4
+ import { getFeatureSpec } from "../state/features.js";
5
+ import { runtimeWarning } from '../utils/user_msgs.js';
6
+ import { initFilepaths, promptfilePath, outputMode, formatMode } from "../state/state.js";
7
+ import { readFile } from "../utils/sys/read.js";
8
+ import { runtimeError } from '../utils/user_msgs.js';
9
+ import { writeToClipboard } from '../utils/sys/clipboard.js';
10
+ import { marked } from 'marked';
11
+ // @ts-ignore
12
+ import { markedTerminal } from "marked-terminal";
13
+ marked.use(markedTerminal());
14
+ function readPromptFile() {
15
+ initFilepaths();
16
+ return readFile(promptfilePath.value);
17
+ }
18
+ async function processOutput(res) {
19
+ //if (!(outputMode.value == "clipboard")) { return }
20
+ let data = "";
21
+ //console.log("Process OUTPUT", typeof res);
22
+ let hasTextData = false;
23
+ if (typeof res == "object") {
24
+ if (res?.text) {
25
+ data = res.text;
26
+ hasTextData = true;
27
+ }
28
+ else {
29
+ try {
30
+ data = JSON.stringify(res);
31
+ }
32
+ catch (e) {
33
+ runtimeError("Unable to parse json result");
34
+ }
35
+ }
36
+ }
37
+ else {
38
+ data = res;
39
+ }
40
+ //onsole.log("OUTPUT", typeof res, data);
41
+ if (outputMode.value == "clipboard") {
42
+ //console.log("Writing to kb", data)
43
+ await writeToClipboard(data);
44
+ }
45
+ if (hasTextData) {
46
+ if (formatMode.value == "markdown") {
47
+ console.log("\n------------------\n");
48
+ console.log(marked.parse(data).trim());
49
+ }
50
+ }
51
+ }
52
+ function openAgentSpec(name) {
53
+ const { found, path } = getFeatureSpec(name, "agent");
54
+ if (!found) {
55
+ throw new Error(`agent ${name} not found`);
56
+ }
57
+ const res = readAgent(path);
58
+ if (!res.found) {
59
+ throw new Error(`agent ${name}, ${path} not found`);
60
+ }
61
+ const agentSpec = YAML.parse(res.ymlAgent);
62
+ agentSpec.name = name;
63
+ return { agentSpec: agentSpec, agentPath: path };
64
+ }
65
+ async function getInputFromOptions(options) {
66
+ let out = null;
67
+ if (options?.clipboardInput === true) {
68
+ out = await readClipboard();
69
+ options.clipboardInput = false;
70
+ }
71
+ else if (options?.inputFile === true) {
72
+ out = readPromptFile();
73
+ options.inputFile = false;
74
+ }
75
+ return out;
76
+ }
77
+ async function getAgentPrompt(name, args, options) {
78
+ const ic = await getInputFromOptions(options);
79
+ if (ic) {
80
+ return ic;
81
+ }
82
+ let pr = "";
83
+ if (Array.isArray(args)) {
84
+ if (args[0] !== undefined) {
85
+ pr = args[0];
86
+ }
87
+ }
88
+ else {
89
+ if (args?.prompt) {
90
+ pr = args.prompt;
91
+ }
92
+ }
93
+ if (pr.length == 0) {
94
+ runtimeWarning("empty prompt provided to agent", name);
95
+ }
96
+ return pr;
97
+ }
98
+ export { getAgentPrompt, getInputFromOptions, openAgentSpec, readPromptFile, processOutput, };
@@ -0,0 +1,9 @@
1
+ declare const usePerfTimer: (startTimer?: boolean) => {
2
+ start: () => void;
3
+ time: () => string;
4
+ timeRaw: () => string | number;
5
+ printTime: () => void;
6
+ measure: (name: string) => void;
7
+ final: (name?: string) => void;
8
+ };
9
+ export { usePerfTimer };
@@ -0,0 +1,63 @@
1
+ const usePerfTimer = (startTimer = true) => {
2
+ let startTime;
3
+ const measurements = [];
4
+ let lastTime;
5
+ if (startTimer) {
6
+ startTime = performance.now();
7
+ lastTime = startTime;
8
+ }
9
+ const measure = (name) => {
10
+ const currentTime = performance.now();
11
+ const elapsedNs = Number(currentTime - lastTime);
12
+ const elapsedSec = elapsedNs / 1000;
13
+ measurements.push({ name, time: elapsedSec, percentage: 0 });
14
+ lastTime = currentTime;
15
+ console.log(name, elapsedSec);
16
+ };
17
+ const final = (name = "") => {
18
+ const totalTime = Number(performance.now() - startTime) / 1000;
19
+ console.log("\n*** Performance", name.length > 0 ? `for ${name}` : "", " ***");
20
+ measurements.forEach(m => {
21
+ m.percentage = (m.time / totalTime) * 100;
22
+ console.log(` - ${m.name}: ${m.time.toFixed(6)}s (${m.percentage.toFixed(2)}%)`);
23
+ });
24
+ console.log(`Total time: ${totalTime.toFixed(6)}s\n`);
25
+ };
26
+ const start = () => {
27
+ startTime = performance.now();
28
+ lastTime = startTime;
29
+ };
30
+ const _end = (raw) => {
31
+ if (!startTime) {
32
+ throw new Error("the timer has not started, can not end it");
33
+ }
34
+ const endTime = performance.now();
35
+ const duration = endTime - startTime;
36
+ if (raw) {
37
+ return duration;
38
+ }
39
+ const humanizedTime = _formatDuration(duration);
40
+ return humanizedTime;
41
+ };
42
+ const time = () => _end(false).toString();
43
+ const printTime = () => console.log(_end(false));
44
+ const timeRaw = () => _end(true);
45
+ const _formatDuration = (ms) => {
46
+ const seconds = ms / 1000;
47
+ const minutes = seconds / 60;
48
+ if (ms < 1000)
49
+ return `${ms.toFixed(2)} milliseconds`;
50
+ if (seconds < 60)
51
+ return `${seconds.toFixed(1)} seconds`;
52
+ return `${minutes.toFixed()} minutes ${(seconds % 60).toFixed()} seconds`;
53
+ };
54
+ return {
55
+ start,
56
+ time,
57
+ timeRaw,
58
+ printTime,
59
+ measure,
60
+ final,
61
+ };
62
+ };
63
+ export { usePerfTimer };
@@ -0,0 +1,3 @@
1
+ declare function readClipboard(): Promise<string>;
2
+ declare function writeToClipboard(data: string): Promise<void>;
3
+ export { readClipboard, writeToClipboard, };
@@ -0,0 +1,33 @@
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, };
@@ -0,0 +1,2 @@
1
+ declare function deleteFileIfExists(filePath: string): void;
2
+ export { deleteFileIfExists };
@@ -0,0 +1,10 @@
1
+ import * as fs from 'fs';
2
+ function deleteFileIfExists(filePath) {
3
+ if (fs.existsSync(filePath)) {
4
+ fs.unlinkSync(filePath);
5
+ }
6
+ else {
7
+ throw new Error(`File ${filePath} does not exist.`);
8
+ }
9
+ }
10
+ export { deleteFileIfExists };
@@ -0,0 +1,2 @@
1
+ declare function createDirectoryIfNotExists(dirPath: string, recursive?: boolean): void;
2
+ export { createDirectoryIfNotExists };
@@ -0,0 +1,9 @@
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 };
@@ -0,0 +1,13 @@
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 runShellCmd(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, runShellCmd };
@@ -0,0 +1,48 @@
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 runShellCmd(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, runShellCmd };
@@ -0,0 +1,3 @@
1
+ declare function readFile(fp: string): string;
2
+ declare function checkIfFileExists(filePath: string): Promise<boolean>;
3
+ export { readFile, checkIfFileExists, };
@@ -0,0 +1,21 @@
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, };
@@ -0,0 +1,6 @@
1
+ declare function readAgent(taskpath: string): {
2
+ found: boolean;
3
+ ymlAgent: string;
4
+ };
5
+ declare function readAgentsDir(dir: string): Array<string>;
6
+ export { readAgent, readAgentsDir, };
@@ -0,0 +1,23 @@
1
+ import { default as fs } from "fs";
2
+ import { default as path } from "path";
3
+ function readAgent(taskpath) {
4
+ if (!fs.existsSync(taskpath)) {
5
+ return { ymlAgent: "", found: false };
6
+ }
7
+ const data = fs.readFileSync(taskpath, 'utf8');
8
+ return { ymlAgent: data, found: true };
9
+ }
10
+ function readAgentsDir(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 { readAgent, readAgentsDir, };
@@ -0,0 +1,7 @@
1
+ import type { UserCmdDef } from "@agent-smith/types";
2
+ declare function readCmd(name: string, cmdPath: string): Promise<UserCmdDef | null>;
3
+ declare function readUserCmd(name: string, cmdPath: string): Promise<{
4
+ found: boolean;
5
+ userCmd: UserCmdDef;
6
+ }>;
7
+ export { readCmd, readUserCmd, };
@@ -0,0 +1,37 @@
1
+ import { pathToFileURL } from 'url';
2
+ import { runtimeWarning } from "../user_msgs.js";
3
+ async function readCmd(name, cmdPath) {
4
+ const url = pathToFileURL(cmdPath).href;
5
+ let _cmd;
6
+ try {
7
+ const mod = await import(/* @vite-ignore */ url);
8
+ _cmd = mod.cmd;
9
+ }
10
+ catch (e) {
11
+ runtimeWarning(`command ${name} not found at ${cmdPath}, ${e}`);
12
+ return null;
13
+ }
14
+ if (!_cmd) {
15
+ throw new Error("no cmd");
16
+ }
17
+ return _cmd;
18
+ }
19
+ async function readUserCmd(name, cmdPath) {
20
+ const url = pathToFileURL(cmdPath).href;
21
+ try {
22
+ const mod = await import(/* @vite-ignore */ url);
23
+ const cmdMod = mod.cmd;
24
+ const uc = {
25
+ name: cmdMod.name,
26
+ description: cmdMod.description,
27
+ run: cmdMod.run,
28
+ options: cmdMod?.options ? cmdMod.options : undefined,
29
+ };
30
+ return { found: true, userCmd: uc };
31
+ }
32
+ catch (e) {
33
+ runtimeWarning(`command ${name} not found at ${cmdPath}, ${e}`);
34
+ return { found: false, userCmd: { name: "", description: "", run: async (a, b) => null } };
35
+ }
36
+ }
37
+ export { readCmd, readUserCmd, };
@@ -0,0 +1,6 @@
1
+ import { ConfigFile } from "@agent-smith/types";
2
+ declare function readConf(confPath: string): {
3
+ found: boolean;
4
+ data: ConfigFile;
5
+ };
6
+ export { readConf };
@@ -0,0 +1,12 @@
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 };
@@ -0,0 +1,3 @@
1
+ import { Features } from "@agent-smith/types";
2
+ declare function readFeaturesDir(dir: string): Features;
3
+ export { readFeaturesDir };