@agent-smith/cli 0.0.108 → 0.0.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/cli.js +1 -0
  2. package/dist/cmd/clicmds/aliases.js +8 -6
  3. package/dist/cmd/clicmds/base.js +5 -2
  4. package/dist/cmd/clicmds/cmds.d.ts +2 -3
  5. package/dist/cmd/clicmds/cmds.js +63 -23
  6. package/dist/cmd/clicmds/updateconf.d.ts +2 -1
  7. package/dist/cmd/clicmds/updateconf.js +39 -9
  8. package/dist/cmd/cmds.js +70 -3
  9. package/dist/cmd/lib/actions/cmd.js +21 -1
  10. package/dist/cmd/lib/actions/read.js +4 -0
  11. package/dist/cmd/lib/adaptaters/cmd.js +8 -1
  12. package/dist/cmd/lib/agents/cmd.js +2 -1
  13. package/dist/cmd/lib/mcp.js +6 -0
  14. package/dist/cmd/lib/options_parsers.js +5 -0
  15. package/dist/cmd/lib/tasks/cmd.js +90 -5
  16. package/dist/cmd/lib/tasks/conf.js +35 -0
  17. package/dist/cmd/lib/tasks/read.js +30 -1
  18. package/dist/cmd/lib/tools.js +10 -4
  19. package/dist/cmd/lib/user_msgs.js +4 -3
  20. package/dist/cmd/lib/utils.js +5 -0
  21. package/dist/cmd/lib/workflows/cmd.js +24 -1
  22. package/dist/cmd/lib/workflows/read.js +5 -0
  23. package/dist/cmd/options.js +1 -0
  24. package/dist/cmd/sys/clipboard.js +25 -0
  25. package/dist/cmd/sys/execute.js +1 -0
  26. package/dist/cmd/sys/read_cmds.d.ts +7 -3
  27. package/dist/cmd/sys/read_cmds.js +21 -3
  28. package/dist/cmd/sys/read_conf.js +1 -0
  29. package/dist/cmd/sys/read_features.js +1 -0
  30. package/dist/cmd/sys/run_python.js +4 -0
  31. package/dist/conf.d.ts +5 -2
  32. package/dist/conf.js +6 -3
  33. package/dist/db/db.js +1 -0
  34. package/dist/db/read.js +1 -0
  35. package/dist/db/write.js +50 -2
  36. package/dist/index.js +8 -0
  37. package/dist/interfaces.d.ts +13 -2
  38. package/dist/main.d.ts +18 -3
  39. package/dist/main.js +17 -2
  40. package/dist/state/backends.js +14 -0
  41. package/dist/state/plugins.js +3 -0
  42. package/dist/state/state.js +21 -2
  43. package/dist/state/tasks.d.ts +2 -1
  44. package/dist/state/tasks.js +8 -1
  45. package/dist/utils/text.js +4 -0
  46. package/dist/utils/user_msgs.js +2 -0
  47. package/package.json +15 -15
  48. package/dist/state/auto/usercmds.d.ts +0 -4
  49. package/dist/state/auto/usercmds.js +0 -3
@@ -3,6 +3,7 @@ import YAML from 'yaml';
3
3
  import { getFeatureSpec } from '../../../state/features.js';
4
4
  async function _createWorkflowFromSpec(spec) {
5
5
  const steps = [];
6
+ //console.log("Create WF. Steps:", spec);
6
7
  for (const step of spec.steps) {
7
8
  const type = Object.keys(step)[0];
8
9
  const sval = step[type];
@@ -13,9 +14,11 @@ async function _createWorkflowFromSpec(spec) {
13
14
  };
14
15
  steps.push(wf);
15
16
  }
17
+ //console.log("STEPS", Object.keys(steps).length, steps);
16
18
  return steps;
17
19
  }
18
20
  async function _readWorkflowFromDisk(name) {
21
+ //const fp = path.join(jobsPath, `${name}.yml`);
19
22
  const { found, path } = getFeatureSpec(name, "workflow");
20
23
  if (!found) {
21
24
  return { found: false, data: {} };
@@ -37,8 +40,10 @@ async function readWorkflow(name) {
37
40
  switch (ext) {
38
41
  case "yml":
39
42
  const { data } = await _readWorkflowFromDisk(name);
43
+ //console.log("WF DATA", data);
40
44
  try {
41
45
  const workflow = await _createWorkflowFromSpec(data);
46
+ //console.log("WF END", found, workflow);
42
47
  if (!found) {
43
48
  return { found: false, workflow: [] };
44
49
  }
@@ -4,6 +4,7 @@ const displayOptions = [
4
4
  new Option("-d, --debug", "use the debug mode"),
5
5
  ];
6
6
  const inferenceOptions = [
7
+ //new Option("-s, --stream", "use the stream mode"),
7
8
  new Option("-m, --model <name>", "the model name").argParser(parseString),
8
9
  new Option("-x, --ctx", "context window size").argParser(parseIntValue),
9
10
  new Option("--tpl, --template <template>", "the template to use"),
@@ -1,8 +1,33 @@
1
1
  import clipboard from 'clipboardy';
2
+ //import { execute } from "./execute.js";
3
+ //const { platform } = process;
2
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*/
3
12
  return await clipboard.read();
4
13
  }
5
14
  async function writeToClipboard(data) {
6
15
  await clipboard.write(data);
7
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
+ }*/
8
33
  export { readClipboard, writeToClipboard, };
@@ -6,6 +6,7 @@ async function execute(command, args = [], { onStdout = (data) => { }, onStderr
6
6
  throw err; },
7
7
  }) {
8
8
  let buffer = new Array();
9
+ //console.log("Cmd args:", args)
9
10
  const useShell = platform() === 'win32';
10
11
  const child = spawn(command, args, { shell: useShell });
11
12
  child.stdout.setEncoding('utf8');
@@ -1,3 +1,7 @@
1
- import { Command } from "commander";
2
- declare function readCmd(name: string, cmdPath: string): Promise<Command | null>;
3
- export { readCmd };
1
+ import type { UserCmdDef } from "../../interfaces.js";
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, };
@@ -2,9 +2,9 @@ import { pathToFileURL } from 'url';
2
2
  import { runtimeWarning } from "../lib/user_msgs.js";
3
3
  async function readCmd(name, cmdPath) {
4
4
  const url = pathToFileURL(cmdPath).href;
5
- let _cmd = null;
5
+ let _cmd;
6
6
  try {
7
- const mod = await import(url);
7
+ const mod = await import(/* @vite-ignore */ url);
8
8
  _cmd = mod.cmd;
9
9
  }
10
10
  catch (e) {
@@ -16,4 +16,22 @@ async function readCmd(name, cmdPath) {
16
16
  }
17
17
  return _cmd;
18
18
  }
19
- export { readCmd };
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, };
@@ -6,6 +6,7 @@ function readConf(confPath) {
6
6
  }
7
7
  const file = fs.readFileSync(confPath, 'utf8');
8
8
  const data = YAML.parse(file);
9
+ //console.log("READ CONF", data);
9
10
  return { data: data, found: true };
10
11
  }
11
12
  export { readConf };
@@ -4,6 +4,7 @@ function _readDir(dir, ext) {
4
4
  const fileNames = new Array;
5
5
  fs.readdirSync(dir).forEach((filename) => {
6
6
  const filepath = path.join(dir, filename);
7
+ //console.log("F", filepath);
7
8
  const isDir = fs.statSync(filepath).isDirectory();
8
9
  if (!isDir) {
9
10
  if (ext.includes(path.extname(filename))) {
@@ -17,16 +17,20 @@ async function runPyScript(rsShell, pythonPath, scriptPath, scriptArgs, onEmitLi
17
17
  res.data.push(msg);
18
18
  }
19
19
  rsShell.on('message', function (message) {
20
+ //console.log("MSG", message);
20
21
  handleLine(message);
21
22
  });
22
23
  rsShell.on('stderr', function (err) {
23
24
  console.log("STDERR", err);
24
25
  });
25
26
  rsShell.on('pythonError', function (err) {
27
+ //console.log("PYERR", `${err.message}, ${err.traceback}`);
26
28
  res.error = new Error(`${err.traceback} ${err.message}`);
27
29
  promiseResolve(true);
28
30
  });
29
31
  rsShell.end(function (err, code, signal) {
32
+ //console.log("END", code, signal);
33
+ //console.log("DATA", res);
30
34
  promiseResolve(true);
31
35
  });
32
36
  await promise;
package/dist/conf.d.ts CHANGED
@@ -1,8 +1,11 @@
1
+ declare function getConfigPath(appName: string, filename: string): {
2
+ confDir: string;
3
+ dbPath: string;
4
+ };
1
5
  declare const confDir: string, dbPath: string;
2
- declare const cacheFilePath: string;
3
6
  declare function processConfPath(confPath: string): Promise<{
4
7
  paths: Array<string>;
5
8
  pf: string;
6
9
  dd: string;
7
10
  }>;
8
- export { confDir, dbPath, cacheFilePath, processConfPath, };
11
+ export { confDir, dbPath, processConfPath, getConfigPath, };
package/dist/conf.js CHANGED
@@ -18,21 +18,22 @@ function getConfigPath(appName, filename) {
18
18
  confDir = join(homedir(), 'Library', 'Application Support', appName);
19
19
  dbPath = join(homedir(), 'Library', 'Application Support', appName, filename);
20
20
  }
21
- else {
21
+ else { // Linux, BSD, etc.
22
22
  confDir = join(homedir(), '.config', appName);
23
23
  dbPath = join(homedir(), '.config', appName, filename);
24
24
  }
25
25
  return { confDir: confDir, dbPath: dbPath };
26
26
  }
27
27
  const { confDir, dbPath } = getConfigPath("agent-smith", "config.db");
28
- const cacheFilePath = join(import.meta.dirname, "state/auto/usercmds.js");
29
28
  async function processConfPath(confPath) {
30
29
  createDirectoryIfNotExists(confDir);
31
30
  const { found, data } = readConf(confPath);
32
31
  if (!found) {
33
32
  runtimeError(`Config file ${confPath} not found`);
34
33
  }
34
+ //console.log(data)
35
35
  const allPaths = new Array();
36
+ // backends
36
37
  const backends = {};
37
38
  let defaultBackendName = "";
38
39
  if (data?.backends) {
@@ -73,11 +74,13 @@ async function processConfPath(confPath) {
73
74
  }
74
75
  }
75
76
  console.log("Default backend:", defaultBackendName);
77
+ //console.dir(backends, { depth: 4 });
76
78
  if (!Object.keys(backends).includes(defaultBackendName)) {
77
79
  throw new Error(`Undeclared default backend: ${defaultBackendName}`);
78
80
  }
79
81
  backends[defaultBackendName].isDefault = true;
80
82
  upsertBackends(Object.values(backends));
83
+ // features and plugins from conf
81
84
  if (data?.features) {
82
85
  allPaths.push(...data.features);
83
86
  const fts = new Array();
@@ -115,4 +118,4 @@ async function processConfPath(confPath) {
115
118
  }
116
119
  return { paths: allPaths, pf: pf, dd: dd };
117
120
  }
118
- export { confDir, dbPath, cacheFilePath, processConfPath, };
121
+ export { confDir, dbPath, processConfPath, getConfigPath, };
package/dist/db/db.js CHANGED
@@ -5,6 +5,7 @@ import { confDir, dbPath } from "../conf.js";
5
5
  let db;
6
6
  const debugDb = false;
7
7
  function initDb(isVerbose, execSchema) {
8
+ //console.log("DBP", dbPath);
8
9
  if (execSchema) {
9
10
  createDirectoryIfNotExists(confDir, true);
10
11
  db = new DatabaseConstructor(dbPath, { fileMustExist: false, verbose: debugDb ? console.log : undefined });
package/dist/db/read.js CHANGED
@@ -27,6 +27,7 @@ function readPlugins() {
27
27
  return f;
28
28
  }
29
29
  function readFeaturesType(type) {
30
+ //console.log(`SELECT name, path, ext, variables FROM ${type}`)
30
31
  const stmt = db.prepare(`SELECT name, path, ext, variables FROM ${type}`);
31
32
  const data = stmt.all();
32
33
  const res = {};
package/dist/db/write.js CHANGED
@@ -20,10 +20,13 @@ function setDefaultBackend(name) {
20
20
  }
21
21
  function upsertBackends(bdata) {
22
22
  let hasUpdates = false;
23
+ // Get all existing backend names
23
24
  const existingStmt = db.prepare("SELECT name FROM backend");
24
25
  const existingBackends = existingStmt.all();
25
26
  const existingNames = new Set(existingBackends.map(b => b.name));
27
+ // Create a set of new backend names for comparison
26
28
  const newNames = new Set(bdata.map(b => b.name));
29
+ // Delete backends that are not in the new list
27
30
  const toDelete = Array.from(existingNames).filter(name => !newNames.has(name));
28
31
  if (toDelete.length > 0) {
29
32
  const deleteStmt = db.prepare("DELETE FROM backend WHERE name = ?");
@@ -32,6 +35,7 @@ function upsertBackends(bdata) {
32
35
  }
33
36
  hasUpdates = true;
34
37
  }
38
+ // Upsert the new backends
35
39
  for (const backend of bdata) {
36
40
  const stmt1 = db.prepare("SELECT * FROM backend WHERE name = ?");
37
41
  const result = stmt1.get(backend.name);
@@ -113,13 +117,19 @@ function upsertAndCleanFeatures(feats, type) {
113
117
  const stmt = db.prepare(`SELECT name FROM ${type}`);
114
118
  const rows = stmt.all();
115
119
  const names = rows.map(row => row.name);
120
+ // cleanup removed features
116
121
  const availableFeatsNames = feats.map((f) => f.name);
122
+ //console.log("NAMES", names);
123
+ //console.log("AVAILABLE", availableFeatsNames);
117
124
  const newFeatures = new Array();
118
125
  names.forEach((name) => {
126
+ //console.log(name, !availableFeatsNames.includes(name));
119
127
  if (!availableFeatsNames.includes(name)) {
128
+ //console.log("DELETE", name);
120
129
  const deleteStmt = db.prepare(`DELETE FROM ${type} WHERE name = ?`);
121
130
  deleteStmt.run(name);
122
131
  console.log("-", "[" + type + "]", name);
132
+ // check if the feature has a tool and delete if if so
123
133
  const stmt1 = db.prepare("SELECT * FROM tool WHERE name = ?");
124
134
  const result = stmt1.get(name);
125
135
  if (result?.id) {
@@ -131,8 +141,15 @@ function upsertAndCleanFeatures(feats, type) {
131
141
  });
132
142
  feats.forEach((feat) => {
133
143
  if (!names.includes(feat.name)) {
134
- const insertStmt = db.prepare(`INSERT INTO ${type} (name, path, ext) VALUES (?, ?, ?)`);
135
- insertStmt.run(feat.name, feat.path, feat.ext);
144
+ //console.log("ADD", type, feat);
145
+ if (feat?.variables) {
146
+ const insertStmt = db.prepare(`INSERT INTO ${type} (name, path, ext, variables) VALUES (?, ?, ?, ?)`);
147
+ insertStmt.run(feat.name, feat.path, feat.ext, JSON.stringify(feat.variables, null, 2));
148
+ }
149
+ else {
150
+ const insertStmt2 = db.prepare(`INSERT INTO ${type} (name, path, ext) VALUES (?, ?, ?)`);
151
+ insertStmt2.run(feat.name, feat.path, feat.ext);
152
+ }
136
153
  console.log("+", "[" + type + "]", feat.name, feat.path);
137
154
  newFeatures.push(feat);
138
155
  }
@@ -142,48 +159,72 @@ function upsertAndCleanFeatures(feats, type) {
142
159
  function updateVariables(name, variableDoc) {
143
160
  const stmt1 = db.prepare("SELECT id FROM task WHERE name = ?");
144
161
  const result = stmt1.get(name);
162
+ //console.log("UV res", result);
145
163
  if (!result?.id) {
146
164
  return;
147
165
  }
148
166
  const updateStmt = db.prepare("UPDATE task SET variables = ? WHERE id = ?");
149
167
  updateStmt.run(variableDoc, result.id);
168
+ //console.log("~", "[task variables] updated for", name);
169
+ }
170
+ function updateUserCmd(feat) {
171
+ const stmt1 = db.prepare("SELECT id FROM cmd WHERE name = ?");
172
+ const result = stmt1.get(feat.name);
173
+ //console.log("UV res", result);
174
+ if (!result?.id) {
175
+ return;
176
+ }
177
+ const updateStmt = db.prepare("UPDATE cmd SET variables = ? WHERE id = ?");
178
+ updateStmt.run(JSON.stringify(feat.variables, null, 2), result.id);
150
179
  }
151
180
  function upsertTool(name, type, toolDoc) {
152
181
  const stmt1 = db.prepare("SELECT * FROM tool WHERE name = ?");
153
182
  const result = stmt1.get(name);
154
183
  if (result?.id) {
184
+ // Update the existing tool
155
185
  const updateStmt = db.prepare("UPDATE tool SET spec = ?, type = ? WHERE id = ?");
156
186
  updateStmt.run(toolDoc, type, result.id);
187
+ //console.log("~", "[tool] updated from", type, ":", name);
157
188
  }
158
189
  else {
190
+ // Insert a new tool
159
191
  const stmt = db.prepare("INSERT INTO tool (name, spec, type) VALUES (?,?,?)");
160
192
  stmt.run(name, toolDoc, type);
193
+ //console.log("+", "[tool] added from", type, ":", name);
161
194
  }
162
195
  }
163
196
  function updateFeatures(feats) {
197
+ //console.log("FEATS", feats);
164
198
  upsertAndCleanFeatures(feats.agent, "agent");
165
199
  feats.agent.forEach((feat) => {
166
200
  const { toolDoc, variables } = extractTaskToolDocAndVariables(feat.name, feat.ext, feat.path);
201
+ //const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
202
+ //console.log(`TASK ${feat.name} TOOL DOC`, toolDoc);
167
203
  if (toolDoc.length > 0) {
168
204
  upsertTool(feat.name, "agent", toolDoc);
169
205
  }
170
206
  if (Object.keys(variables.required).length > 0 || Object.keys(variables.optional).length > 0) {
207
+ //console.log("UPDATE VARS", feat.name, ":", variables)
171
208
  updateVariables(feat.name, JSON.stringify(variables, null, " "));
172
209
  }
173
210
  });
174
211
  upsertAndCleanFeatures(feats.task, "task");
175
212
  feats.task.forEach((feat) => {
176
213
  const { toolDoc, variables } = extractTaskToolDocAndVariables(feat.name, feat.ext, feat.path);
214
+ //const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
215
+ //console.log(`TASK ${feat.name} TOOL DOC`, toolDoc);
177
216
  if (toolDoc.length > 0) {
178
217
  upsertTool(feat.name, "task", toolDoc);
179
218
  }
180
219
  if (Object.keys(variables.required).length > 0 || Object.keys(variables.optional).length > 0) {
220
+ //console.log("UPDATE VARS", feat.name, ":", variables)
181
221
  updateVariables(feat.name, JSON.stringify(variables, null, " "));
182
222
  }
183
223
  });
184
224
  upsertAndCleanFeatures(feats.action, "action");
185
225
  feats.action.forEach((feat) => {
186
226
  const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
227
+ //console.log(`ACTION ${feat.name} TOOL DOC`, found, toolDoc);
187
228
  if (found) {
188
229
  upsertTool(feat.name, "action", toolDoc);
189
230
  }
@@ -191,23 +232,27 @@ function updateFeatures(feats) {
191
232
  upsertAndCleanFeatures(feats.workflow, "workflow");
192
233
  feats.workflow.forEach((feat) => {
193
234
  const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
235
+ //console.log(`WORKFLOW ${feat.name} TOOL DOC`, toolDoc);
194
236
  if (found) {
195
237
  upsertTool(feat.name, "workflow", toolDoc);
196
238
  }
197
239
  });
198
240
  upsertAndCleanFeatures(feats.adaptater, "adaptater");
199
241
  upsertAndCleanFeatures(feats.cmd, "cmd");
242
+ feats.cmd.forEach(c => updateUserCmd(c));
200
243
  }
201
244
  function upsertFilePath(name, newPath) {
202
245
  const selectStmt = db.prepare("SELECT * FROM filepath WHERE name = ?");
203
246
  const result = selectStmt.get(name);
204
247
  if (result?.id) {
248
+ // If the filepath exists, update it
205
249
  const q = `UPDATE filepath SET path = ? WHERE name = ?`;
206
250
  const stmt = db.prepare(q);
207
251
  const updateResult = stmt.run(newPath, name);
208
252
  return updateResult.changes > 0;
209
253
  }
210
254
  else {
255
+ // If the filepath does not exist, insert it
211
256
  const insertStmt = db.prepare("INSERT INTO filepath (name, path) VALUES (?, ?)");
212
257
  insertStmt.run(name, newPath);
213
258
  return true;
@@ -260,6 +305,7 @@ function upsertTaskSettings(taskName, settings) {
260
305
  qvalues.push(settings.backend);
261
306
  }
262
307
  const q = `UPDATE tasksettings SET ${qparams.join(", ")} WHERE name = ?`;
308
+ //console.log("Q", q);
263
309
  const stmt = db.prepare(q);
264
310
  const updateResult = stmt.run(...qvalues, taskName);
265
311
  return updateResult.changes > 0;
@@ -310,6 +356,8 @@ function upsertTaskSettings(taskName, settings) {
310
356
  const nq = new Array("?");
311
357
  qnames.forEach(n => nq.push("?"));
312
358
  const q = `INSERT INTO tasksettings (name, ${qnames.join(", ")}) VALUES (${nq.join(", ")})`;
359
+ //console.log(q);
360
+ //console.log("VALs", qvalues);
313
361
  const insertStmt = db.prepare(q);
314
362
  insertStmt.run(taskName, ...qvalues);
315
363
  return true;
package/dist/index.js CHANGED
@@ -5,7 +5,9 @@ import { resetDbCmd } from './cmd/clicmds/cmds.js';
5
5
  import { updateConfCmd } from './cmd/clicmds/updateconf.js';
6
6
  import { buildCmds, parseCmd } from './cmd/cmds.js';
7
7
  import { formatMode, init, inputMode, isChatMode, outputMode, runMode } from './state/state.js';
8
+ //import { usePerfTimer } from './main.js';
8
9
  async function main() {
10
+ //const perf = usePerfTimer();
9
11
  const nargs = argv.length;
10
12
  if (nargs == 2) {
11
13
  runMode.value = "cli";
@@ -20,10 +22,16 @@ async function main() {
20
22
  return;
21
23
  }
22
24
  }
25
+ //perf.measure("base");
23
26
  await init();
27
+ //perf.measure("init");
24
28
  const program = await buildCmds();
29
+ //perf.measure("buildCmds");
30
+ //perf.final("index start");
25
31
  program.hook('preAction', async (thisCommand, actionCommand) => {
26
32
  const options = actionCommand.opts();
33
+ //console.log("POPTS", options)
34
+ //const v = options?.clipboardOutput !== undefined;
27
35
  if (options?.chat === true) {
28
36
  isChatMode.value = true;
29
37
  }
@@ -5,7 +5,7 @@ interface FeatureSpec {
5
5
  name: string;
6
6
  path: string;
7
7
  ext: FeatureExtension;
8
- variables?: TaskVariables;
8
+ variables?: TaskVariables | Record<string, any>;
9
9
  }
10
10
  interface Features {
11
11
  agent: Array<{
@@ -22,6 +22,11 @@ interface Features {
22
22
  name: string;
23
23
  path: string;
24
24
  ext: CmdExtension;
25
+ variables?: {
26
+ name: string;
27
+ options?: Array<Array<string> | string>;
28
+ description: string;
29
+ };
25
30
  }>;
26
31
  action: Array<{
27
32
  name: string;
@@ -39,6 +44,12 @@ interface Features {
39
44
  ext: AdaptaterExtension;
40
45
  }>;
41
46
  }
47
+ interface UserCmdDef {
48
+ name: string;
49
+ description: string;
50
+ run: (args: any, options: Record<string, any>) => Promise<any>;
51
+ options?: Array<Array<string> | string>;
52
+ }
42
53
  interface ConfInferenceBackend {
43
54
  type: LmProviderType;
44
55
  url: string;
@@ -151,4 +162,4 @@ type CmdExtension = "js";
151
162
  type FeatureExtension = TaskExtension | AgentExtension | CmdExtension | ActionExtension | WorkflowExtension;
152
163
  type AliasType = "task" | "agent" | "action" | "workflow";
153
164
  type FeatureExecutor<I = any, O = any> = (params: I, options: Record<string, any>) => Promise<O>;
154
- export { InputMode, VerbosityMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, AgentExtension, WorkflowExtension, AdaptaterExtension, CmdExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, ToolType, Settings, DbModelDef, ModelSpec, ModelfileSpec, ModelPack, LmTaskFileSpec, LmTaskConfig, FinalLmTaskConfig, McpServerSpec, McpServerTool, InferenceBackend, ConfInferenceBackend, FeatureExecutor, WorkflowStep, TaskSettings, };
165
+ export { InputMode, VerbosityMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, AgentExtension, WorkflowExtension, AdaptaterExtension, CmdExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, ToolType, Settings, DbModelDef, ModelSpec, ModelfileSpec, ModelPack, LmTaskFileSpec, LmTaskConfig, FinalLmTaskConfig, McpServerSpec, McpServerTool, InferenceBackend, ConfInferenceBackend, FeatureExecutor, WorkflowStep, TaskSettings, UserCmdDef, };
package/dist/main.d.ts CHANGED
@@ -3,7 +3,7 @@ import { executeTask } from "./cmd/lib/tasks/cmd.js";
3
3
  import { executeAction } from "./cmd/lib/actions/cmd.js";
4
4
  import { executeWorkflow } from "./cmd/lib/workflows/cmd.js";
5
5
  import { writeToClipboard } from "./cmd/sys/clipboard.js";
6
- import { initState, pluginDataDir, init } from "./state/state.js";
6
+ import { initState, pluginDataDir, init, isStateReady } from "./state/state.js";
7
7
  import { usePerfTimer } from "./utils/perf.js";
8
8
  import { parseCommandArgs } from "./cmd/lib/options_parsers.js";
9
9
  import { extractToolDoc } from "./cmd/lib/tools.js";
@@ -12,5 +12,20 @@ import { extractBetweenTags, splitThinking } from "./utils/text.js";
12
12
  import { displayOptions, ioOptions, inferenceOptions, allOptions } from "./cmd/options.js";
13
13
  import { McpClient } from "./cmd/lib/mcp.js";
14
14
  import { readTask } from "./cmd/lib/tasks/read.js";
15
- import { FeatureType } from "./interfaces.js";
16
- export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initState, init, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, allOptions, McpClient, readTask, FeatureType, };
15
+ import { FeatureType, TaskSettings } from "./interfaces.js";
16
+ import { getConfigPath } from "./conf.js";
17
+ import { readFeaturesType, readFilePaths } from "./db/read.js";
18
+ import { readConf } from "./cmd/sys/read_conf.js";
19
+ import { backend } from "./state/backends.js";
20
+ import { getTaskSettings } from "./state/tasks.js";
21
+ import { upsertTaskSettings } from "./db/write.js";
22
+ declare const db: {
23
+ readFilePaths: typeof readFilePaths;
24
+ readFeaturesType: typeof readFeaturesType;
25
+ getTaskSettings: typeof getTaskSettings;
26
+ upsertTaskSettings: typeof upsertTaskSettings;
27
+ };
28
+ declare const fs: {
29
+ openTaskSpec: typeof openTaskSpec;
30
+ };
31
+ export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initState, init, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, allOptions, isStateReady, backend, McpClient, readTask, FeatureType, getConfigPath, readConf, TaskSettings, db, fs, };
package/dist/main.js CHANGED
@@ -3,7 +3,7 @@ import { executeTask } from "./cmd/lib/tasks/cmd.js";
3
3
  import { executeAction } from "./cmd/lib/actions/cmd.js";
4
4
  import { executeWorkflow } from "./cmd/lib/workflows/cmd.js";
5
5
  import { writeToClipboard } from "./cmd/sys/clipboard.js";
6
- import { initState, pluginDataDir, init } from "./state/state.js";
6
+ import { initState, pluginDataDir, init, isStateReady } from "./state/state.js";
7
7
  import { usePerfTimer } from "./utils/perf.js";
8
8
  import { parseCommandArgs } from "./cmd/lib/options_parsers.js";
9
9
  import { extractToolDoc } from "./cmd/lib/tools.js";
@@ -12,4 +12,19 @@ import { extractBetweenTags, splitThinking } from "./utils/text.js";
12
12
  import { displayOptions, ioOptions, inferenceOptions, allOptions } from "./cmd/options.js";
13
13
  import { McpClient } from "./cmd/lib/mcp.js";
14
14
  import { readTask } from "./cmd/lib/tasks/read.js";
15
- export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initState, init, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, allOptions, McpClient, readTask, };
15
+ import { getConfigPath } from "./conf.js";
16
+ import { readFeaturesType, readFilePaths } from "./db/read.js";
17
+ import { readConf } from "./cmd/sys/read_conf.js";
18
+ import { backend } from "./state/backends.js";
19
+ import { getTaskSettings } from "./state/tasks.js";
20
+ import { upsertTaskSettings } from "./db/write.js";
21
+ const db = {
22
+ readFilePaths,
23
+ readFeaturesType,
24
+ getTaskSettings,
25
+ upsertTaskSettings,
26
+ };
27
+ const fs = {
28
+ openTaskSpec,
29
+ };
30
+ export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initState, init, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, allOptions, isStateReady, backend, McpClient, readTask, getConfigPath, readConf, db, fs, };
@@ -9,8 +9,10 @@ const backends = {};
9
9
  const isBackendUp = ref(false);
10
10
  async function initBackends() {
11
11
  const rmb = readBackends();
12
+ //console.log("Backends:", rmb)
12
13
  let defaultBackendName = null;
13
14
  for (const bk of Object.values(rmb)) {
15
+ //console.log("BK", bk.name);
14
16
  let name = bk.name;
15
17
  let apiKey = "";
16
18
  if (bk?.apiKey) {
@@ -39,6 +41,12 @@ async function initBackends() {
39
41
  }
40
42
  if (defaultBackendName !== null) {
41
43
  backend.value = backends[defaultBackendName];
44
+ //console.log("Setting default backend", defaultBackendName, "/", backend.value.name)
45
+ /*isBackendUp.value = await probeBackend(backend.value, isVerbose);
46
+
47
+ if (isBackendUp.value && backend.value.providerType == "ollama") {
48
+ await backend.value.modelsInfo();
49
+ }*/
42
50
  }
43
51
  }
44
52
  async function setBackend(name, isVerbose = false) {
@@ -52,9 +60,11 @@ async function setBackend(name, isVerbose = false) {
52
60
  isBackendUp.value = await probeBackend(backend.value, isVerbose);
53
61
  }
54
62
  async function listBackends(printResult = true) {
63
+ //console.log("DEFB", backend.value?.name);
55
64
  const allBk = new Array();
56
65
  for (const [name, lm] of Object.entries(backends)) {
57
66
  const bcn = name == backend.value?.name ? colors.bold(name) : name;
67
+ //const isUp = await probeBackend(lm, false);
58
68
  const buf = new Array("-", bcn, colors.dim("(" + lm.providerType + ") " + lm.serverUrl));
59
69
  const str = buf.join(" ");
60
70
  if (printResult) {
@@ -103,6 +113,8 @@ const probeBackend = async (lm, isVerbose) => {
103
113
  }
104
114
  break;
105
115
  case "ollama":
116
+ //console.warn("The Ollama provider is not yet supported");
117
+ //break;
106
118
  try {
107
119
  await lm.modelsInfo();
108
120
  if (isVerbose) {
@@ -117,6 +129,8 @@ const probeBackend = async (lm, isVerbose) => {
117
129
  }
118
130
  break;
119
131
  case "openai":
132
+ //console.warn("The Ollama provider is not yet supported");
133
+ //break;
120
134
  try {
121
135
  await lm.modelsInfo();
122
136
  if (isVerbose) {
@@ -5,12 +5,14 @@ async function buildPluginsPaths(names) {
5
5
  const plugins = new Array();
6
6
  const root = await execute("npm", ["root", "-g"]);
7
7
  const rootPath = root.trim();
8
+ //console.log("PLUGINS", packs);
8
9
  names.forEach((p) => {
9
10
  plugins.push({
10
11
  name: p,
11
12
  path: path.join(rootPath, p, "dist")
12
13
  });
13
14
  });
15
+ //console.log("PLUGINS PATHS", paths);
14
16
  return plugins;
15
17
  }
16
18
  async function readPluginsPaths() {
@@ -19,6 +21,7 @@ async function readPluginsPaths() {
19
21
  plugins.forEach((p) => {
20
22
  paths.push(p.path);
21
23
  });
24
+ //console.log("PLUGINS PATHS", paths);
22
25
  return paths;
23
26
  }
24
27
  export { buildPluginsPaths, readPluginsPaths };