@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,134 @@
1
+ import { default as fs } from "fs";
2
+ import { default as path } from "path";
3
+ import { default as fm } from "front-matter";
4
+ import { readFile } from "./read.js";
5
+ import { runtimeDataError } from "../user_msgs.js";
6
+ function _readDir(dir, ext) {
7
+ const fileNames = new Array;
8
+ fs.readdirSync(dir).forEach((filename) => {
9
+ const filepath = path.join(dir, filename);
10
+ //console.log("F", filepath);
11
+ const isDir = fs.statSync(filepath).isDirectory();
12
+ if (!isDir) {
13
+ if (ext.includes(path.extname(filename))) {
14
+ fileNames.push(filename);
15
+ }
16
+ }
17
+ });
18
+ return fileNames;
19
+ }
20
+ function _readSkills(dir) {
21
+ const dirs = new Array();
22
+ fs.readdirSync(dir).forEach((p) => {
23
+ const isDir = fs.statSync(path.join(dir, p)).isDirectory();
24
+ const skp = path.join(dir, p, "SKILL.md");
25
+ const fc = readFile(skp);
26
+ const data = fm(fc);
27
+ //console.log("FM DATA", data);
28
+ if (!data.attributes?.name) {
29
+ runtimeDataError(`error in skill ${p}: missing name`);
30
+ }
31
+ if (!data.attributes?.description) {
32
+ runtimeDataError(`error in skill ${p}: missing description`);
33
+ }
34
+ //console.log("SKP", skp);
35
+ if (isDir) {
36
+ dirs.push({ name: p, path: skp, info: { name: data.attributes.name, description: data.attributes.description } });
37
+ }
38
+ });
39
+ return dirs;
40
+ }
41
+ function readFeaturesDir(dir) {
42
+ const feats = {
43
+ action: [],
44
+ cmd: [],
45
+ workflow: [],
46
+ adaptater: [],
47
+ agent: [],
48
+ skill: [],
49
+ };
50
+ let dirpath = path.join(dir, "agents");
51
+ if (fs.existsSync(dirpath)) {
52
+ const data = _readDir(dirpath, [".yml"]);
53
+ data.forEach((filename) => {
54
+ const parts = filename.split(".");
55
+ const ext = parts.pop();
56
+ const name = parts.join("");
57
+ feats.agent.push({
58
+ name: name,
59
+ path: path.join(dirpath),
60
+ ext: ext,
61
+ });
62
+ });
63
+ }
64
+ dirpath = path.join(dir, "workflows");
65
+ if (fs.existsSync(dirpath)) {
66
+ const data = _readDir(dirpath, [".yml"]);
67
+ data.forEach((filename) => {
68
+ const parts = filename.split(".");
69
+ const ext = parts.pop();
70
+ const name = parts.join("");
71
+ feats.workflow.push({
72
+ name: name,
73
+ path: path.join(dirpath),
74
+ ext: ext,
75
+ });
76
+ });
77
+ }
78
+ dirpath = path.join(dir, "actions");
79
+ if (fs.existsSync(dirpath)) {
80
+ const data = _readDir(dirpath, [".yml", ".js", ".py"]);
81
+ data.forEach((filename) => {
82
+ const parts = filename.split(".");
83
+ const ext = parts.pop();
84
+ const name = parts.join("");
85
+ feats.action.push({
86
+ name: name,
87
+ path: path.join(dirpath),
88
+ ext: ext,
89
+ });
90
+ });
91
+ }
92
+ dirpath = path.join(dir, "adaptaters");
93
+ if (fs.existsSync(dirpath)) {
94
+ const data = _readDir(dirpath, [".js"]);
95
+ data.forEach((filename) => {
96
+ const parts = filename.split(".");
97
+ const ext = parts.pop();
98
+ const name = parts.join("");
99
+ feats.adaptater.push({
100
+ name: name,
101
+ path: path.join(dirpath),
102
+ ext: ext,
103
+ });
104
+ });
105
+ }
106
+ dirpath = path.join(dir, "cmds");
107
+ if (fs.existsSync(dirpath)) {
108
+ const data = _readDir(dirpath, [".js"]);
109
+ data.forEach((filename) => {
110
+ const parts = filename.split(".");
111
+ const ext = parts.pop();
112
+ const name = parts.join("");
113
+ feats.cmd.push({
114
+ name: name,
115
+ path: path.join(dirpath),
116
+ ext: ext,
117
+ });
118
+ });
119
+ }
120
+ dirpath = path.join(dir, "skills");
121
+ if (fs.existsSync(dirpath)) {
122
+ const data = _readSkills(dirpath);
123
+ data.forEach((s) => {
124
+ feats.skill.push({
125
+ name: s.name,
126
+ path: s.path,
127
+ ext: "md",
128
+ variables: s.info,
129
+ });
130
+ });
131
+ }
132
+ return feats;
133
+ }
134
+ export { readFeaturesDir };
@@ -0,0 +1,5 @@
1
+ declare function readYmlFile(path: string): {
2
+ found: boolean;
3
+ data: Record<string, any>;
4
+ };
5
+ export { readYmlFile };
@@ -0,0 +1,11 @@
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 };
@@ -0,0 +1,6 @@
1
+ import { PythonShell } from 'python-shell';
2
+ declare function runPyScript(rsShell: PythonShell, pythonPath: string, scriptPath: string, scriptArgs: Array<string>, onEmitLine?: CallableFunction): Promise<{
3
+ data: any;
4
+ error?: Error;
5
+ }>;
6
+ export { runPyScript };
@@ -0,0 +1,39 @@
1
+ import { PythonShell } from 'python-shell';
2
+ async function runPyScript(rsShell, pythonPath, scriptPath, scriptArgs, onEmitLine) {
3
+ const _options = {
4
+ mode: "text",
5
+ pythonPath: pythonPath,
6
+ pythonOptions: ['-u'],
7
+ args: scriptArgs,
8
+ };
9
+ let promiseResolve;
10
+ let promise = new Promise((resolve) => promiseResolve = resolve);
11
+ rsShell = new PythonShell(scriptPath, _options);
12
+ const res = { data: new Array() };
13
+ function handleLine(msg) {
14
+ if (onEmitLine) {
15
+ onEmitLine(msg);
16
+ }
17
+ res.data.push(msg);
18
+ }
19
+ rsShell.on('message', function (message) {
20
+ //console.log("MSG", message);
21
+ handleLine(message);
22
+ });
23
+ rsShell.on('stderr', function (err) {
24
+ console.log("STDERR", err);
25
+ });
26
+ rsShell.on('pythonError', function (err) {
27
+ //console.log("PYERR", `${err.message}, ${err.traceback}`);
28
+ res.error = new Error(`${err.traceback} ${err.message}`);
29
+ promiseResolve(true);
30
+ });
31
+ rsShell.end(function (err, code, signal) {
32
+ //console.log("END", code, signal);
33
+ //console.log("DATA", res);
34
+ promiseResolve(true);
35
+ });
36
+ await promise;
37
+ return res;
38
+ }
39
+ export { runPyScript };
@@ -0,0 +1,2 @@
1
+ declare function extractBetweenTags(text: string, startTag: string, endTag: string): string;
2
+ export { extractBetweenTags, };
@@ -0,0 +1,28 @@
1
+ function extractBetweenTags(text, startTag, endTag) {
2
+ try {
3
+ // Find start position
4
+ const startIndex = text.indexOf(startTag);
5
+ if (startIndex === -1)
6
+ return text;
7
+ // Calculate content boundaries
8
+ let contentStart = startIndex + startTag.length;
9
+ let contentEnd;
10
+ if (endTag) {
11
+ contentEnd = text.indexOf(endTag, contentStart);
12
+ if (contentEnd === -1)
13
+ return text;
14
+ }
15
+ else {
16
+ // Find next newline for self-closing tags
17
+ contentEnd = text.indexOf('\n', contentStart);
18
+ if (contentEnd === -1)
19
+ contentEnd = text.length;
20
+ }
21
+ // Extract content
22
+ return text.substring(contentStart, contentEnd).trim();
23
+ }
24
+ catch (error) {
25
+ throw new Error(`Error parsing content between tags ${startTag} ${endTag}: ${error}`);
26
+ }
27
+ }
28
+ export { extractBetweenTags, };
@@ -0,0 +1,5 @@
1
+ declare function runtimeError(...msg: string[]): void;
2
+ declare function runtimeWarning(...msg: string[]): void;
3
+ declare function runtimeDataError(...msg: string[]): void;
4
+ declare function runtimeInfo(...msg: string[]): void;
5
+ export { runtimeError, runtimeWarning, runtimeDataError, runtimeInfo, };
@@ -0,0 +1,19 @@
1
+ import { exit } from "process";
2
+ import colors from "ansi-colors";
3
+ function runtimeError(...msg) {
4
+ console.warn("💥", colors.dim("Runtime error:"), ...msg);
5
+ exit(1);
6
+ }
7
+ function runtimeWarning(...msg) {
8
+ console.warn("⚠️", colors.dim("Runtime warning:"), ...msg);
9
+ //exit(1)
10
+ }
11
+ function runtimeDataError(...msg) {
12
+ console.warn("❌", colors.dim("Runtime data error:"), ...msg);
13
+ exit(1);
14
+ }
15
+ function runtimeInfo(...msg) {
16
+ //console.log("ℹ️ ", colors.dim("Info:"), ...msg);
17
+ console.log("📫", colors.dim("Info:"), ...msg);
18
+ }
19
+ export { runtimeError, runtimeWarning, runtimeDataError, runtimeInfo, };
@@ -0,0 +1,3 @@
1
+ import type { AgentInferenceOptions } from "@agent-smith/types";
2
+ declare function executeWorkflow(wname: string, args: any, options: AgentInferenceOptions & Record<string, any>): Promise<any>;
3
+ export { executeWorkflow, };
@@ -0,0 +1,189 @@
1
+ import { pathToFileURL } from "node:url";
2
+ import { getFeatureSpec } from "../state/features.js";
3
+ import { executeAction } from "../actions/cmd.js";
4
+ import { executeAdaptater } from "../adaptaters/cmd.js";
5
+ import { executeAgent } from "../agents/cmd.js";
6
+ import { getInputFromOptions, getAgentPrompt } from "../utils/io.js";
7
+ import { runtimeError } from "../utils/user_msgs.js";
8
+ import { readWorkflow } from "./read.js";
9
+ async function executeWorkflow(wname, args, options) {
10
+ const { workflow, found } = await readWorkflow(wname);
11
+ if (!found) {
12
+ throw new Error(`Workflow ${wname} not found`);
13
+ }
14
+ const isDebug = options?.debug === true;
15
+ const isVerbose = options?.verbose === true;
16
+ const stepNames = Object.keys(workflow);
17
+ if (isDebug || isVerbose) {
18
+ console.log("Running workflow", wname, stepNames.length, "steps");
19
+ }
20
+ let i = 0;
21
+ const finalTaskIndex = stepNames.length - 1;
22
+ let taskRes = { cmdArgs: args };
23
+ //console.log("WPARAMS", taskRes);
24
+ let prevStepType = null;
25
+ //console.log("WF OPTS", options);
26
+ for (const step of workflow) {
27
+ if (isDebug || isVerbose) {
28
+ console.log(i + 1, step.name, `\x1b[2m${step.type}\x1b[0m`);
29
+ }
30
+ switch (step.type) {
31
+ case "agent":
32
+ try {
33
+ let tdata = { prompt: "", ...taskRes };
34
+ if (i == 0) {
35
+ tdata.prompt = await getAgentPrompt(step.name, taskRes.cmdArgs, options);
36
+ }
37
+ else {
38
+ if (prevStepType) {
39
+ if (prevStepType == "action") {
40
+ if (taskRes?.args) {
41
+ if (typeof taskRes.args == "string") {
42
+ tdata.prompt = taskRes.args;
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+ if (!tdata?.prompt) {
49
+ throw new Error(`Workflow ${wname} step ${i + 1}: provide a prompt for the task ${step.name}`);
50
+ }
51
+ options.isAgent = true;
52
+ //console.log("WF EXEC AGENT", step.name, tdata, options);
53
+ const tr = await executeAgent(step.name, tdata, options);
54
+ options.isAgent = false;
55
+ taskRes = { ...tr, ...taskRes };
56
+ }
57
+ catch (e) {
58
+ throw new Error(`workflow task ${i + 1}: ${e}`);
59
+ }
60
+ break;
61
+ case "action":
62
+ try {
63
+ //console.log("EXEC ACTION ARGS", taskRes);
64
+ //const actArgs = i == 0 ? taskRes.cmdArgs : taskRes;
65
+ let actArgs;
66
+ if (i == 0) {
67
+ actArgs = taskRes.cmdArgs;
68
+ const inputData = await getInputFromOptions(options);
69
+ if (inputData) {
70
+ actArgs.push(inputData);
71
+ }
72
+ }
73
+ else {
74
+ actArgs = taskRes;
75
+ }
76
+ const ares = await executeAction(step.name, actArgs, options, true);
77
+ //console.log("WF ACTION RES", typeof ares, ares);
78
+ //console.log("LAST ACT", i, finalTaskIndex);
79
+ if (i == finalTaskIndex && !options?.isToolCall) {
80
+ console.log(ares);
81
+ break;
82
+ }
83
+ if (typeof ares == "string" || Array.isArray(ares)) {
84
+ taskRes.args = ares;
85
+ //console.log("ARRAY ACTION RES", taskRes)
86
+ }
87
+ else {
88
+ taskRes = { ...ares, ...taskRes };
89
+ }
90
+ }
91
+ catch (e) {
92
+ throw new Error(`workflow action ${i + 1}: ${e}`);
93
+ }
94
+ //console.log("END ACTION", step.name)
95
+ break;
96
+ case "adaptater":
97
+ try {
98
+ //console.log("WF AD ARGS IN", taskRes);
99
+ //console.log("AD OPTS IN", options);
100
+ let actArgs;
101
+ if (i == 0) {
102
+ //console.log("TR", taskRes);
103
+ actArgs = taskRes.cmdArgs;
104
+ //console.log("ACT ARGS", actArgs);
105
+ const inputData = await getInputFromOptions(options);
106
+ if (inputData) {
107
+ actArgs.push(inputData);
108
+ }
109
+ }
110
+ else {
111
+ actArgs = taskRes;
112
+ }
113
+ const adres = await executeAdaptater(step.name, actArgs, options);
114
+ //console.log("WF AD FINAL RES", taskRes);
115
+ //console.log("LAST ACT", i, finalTaskIndex);
116
+ if (i == finalTaskIndex && !options?.isToolCall) {
117
+ console.log(adres);
118
+ break;
119
+ }
120
+ //console.log("WF AD RES", typeof adres, adres);
121
+ if (typeof adres == "string" || Array.isArray(adres)) {
122
+ taskRes.args = adres;
123
+ //console.log("WF AD IT RES", taskRes);
124
+ }
125
+ else {
126
+ taskRes = { ...adres };
127
+ }
128
+ //console.log("WF ADAPT RES", typeof ares, Array.isArray(ares) ? ares.length : "NA");
129
+ }
130
+ catch (e) {
131
+ throw new Error(`workflow adaptater ${i + 1}: ${e}`);
132
+ }
133
+ break;
134
+ case "cmd":
135
+ try {
136
+ const { found, path } = getFeatureSpec(step.name, "cmd");
137
+ if (!found) {
138
+ throw new Error(`Command ${step.name} not found`);
139
+ }
140
+ const url = pathToFileURL(path).href;
141
+ let jsa;
142
+ try {
143
+ jsa = await import(/* @vite-ignore */ url);
144
+ }
145
+ catch (e) {
146
+ throw new Error(`cmd import error ${e}`);
147
+ }
148
+ if (!jsa?.runCmd) {
149
+ runtimeError(`workflow ${wname}: can not import the runCmd function from step ${i} for command ${step.name}: please add a runCmd function export`);
150
+ return;
151
+ }
152
+ let cArgs;
153
+ if (i == 0) {
154
+ cArgs = taskRes.cmdArgs;
155
+ const inputData = await getInputFromOptions(options);
156
+ if (inputData) {
157
+ cArgs.push(inputData);
158
+ }
159
+ }
160
+ else {
161
+ cArgs = taskRes;
162
+ }
163
+ const cres = await jsa.runCmd(cArgs, options);
164
+ if (typeof cres == "string" || Array.isArray(cres)) {
165
+ taskRes.args = cres;
166
+ }
167
+ else {
168
+ taskRes = { ...cres, ...taskRes };
169
+ }
170
+ }
171
+ catch (e) {
172
+ throw new Error(`workflow command ${i + 1}: ${e}`);
173
+ }
174
+ break;
175
+ default:
176
+ throw new Error(`unknown workflow step type ${step.type} in workflow ${wname}`);
177
+ }
178
+ prevStepType = step.type;
179
+ //console.log("WF NODE RES", step.type, taskRes);
180
+ /*if (isDebug) {
181
+ console.log("->", params);
182
+ }*/
183
+ //console.log("WFR", taskRes)
184
+ ++i;
185
+ }
186
+ //console.log("WF RES")
187
+ return taskRes;
188
+ }
189
+ export { executeWorkflow, };
@@ -0,0 +1,6 @@
1
+ import type { WorkflowStep } from '@agent-smith/types';
2
+ declare function readWorkflow(name: string): Promise<{
3
+ found: boolean;
4
+ workflow: Array<WorkflowStep>;
5
+ }>;
6
+ export { readWorkflow };
@@ -0,0 +1,61 @@
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 };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@agent-smith/core",
3
+ "version": "0.0.1",
4
+ "description": "Agent Smith core",
5
+ "repository": "https://github.com/synw/agent-smith",
6
+ "scripts": {
7
+ "build": "rm -rf dist/* && tsc && cp -r src/features/agents dist/features && cp -r src/features/workflows dist/features && cp -r src/features/fragments dist/features && cp -r src/features/skills dist/features"
8
+ },
9
+ "dependencies": {
10
+ "@agent-smith/agent": "^0.5.0",
11
+ "@intrinsicai/gbnfgen": "^0.12.0",
12
+ "@modelcontextprotocol/sdk": "^1.29.0",
13
+ "@vue/reactivity": "^3.5.35",
14
+ "better-sqlite3": "^12.10.0",
15
+ "clipboardy": "^5.3.1",
16
+ "front-matter": "^4.0.2",
17
+ "node-notifier": "^10.0.1",
18
+ "python-shell": "^5.0.0",
19
+ "yaml": "^2.9.0"
20
+ },
21
+ "devDependencies": {
22
+ "@agent-smith/types": "^0.0.5",
23
+ "@types/better-sqlite3": "^7.6.13",
24
+ "@types/node": "^25.9.1",
25
+ "@types/node-notifier": "^8.0.5",
26
+ "tslib": "^2.8.1",
27
+ "typescript": "^6.0.3"
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "module": "./dist/main.js",
33
+ "types": "./dist/main.d.ts",
34
+ "type": "module",
35
+ "exports": {
36
+ ".": {
37
+ "import": "./dist/main.js"
38
+ }
39
+ },
40
+ "publishConfig": {
41
+ "access": "public",
42
+ "registry": "https://registry.npmjs.org/"
43
+ },
44
+ "license": "MIT"
45
+ }