@agent-smith/cli 0.0.62 → 0.0.64

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 (54) hide show
  1. package/dist/cli.d.ts +2 -1
  2. package/dist/cli.js +7 -48
  3. package/dist/cmd/clicmds/aliases.d.ts +7 -0
  4. package/dist/cmd/clicmds/aliases.js +43 -0
  5. package/dist/cmd/clicmds/base.d.ts +3 -0
  6. package/dist/cmd/clicmds/base.js +94 -0
  7. package/dist/cmd/clicmds/cmds.d.ts +4 -7
  8. package/dist/cmd/clicmds/cmds.js +6 -184
  9. package/dist/cmd/clicmds/update.d.ts +2 -0
  10. package/dist/cmd/clicmds/update.js +46 -0
  11. package/dist/cmd/cmds.d.ts +3 -5
  12. package/dist/cmd/cmds.js +19 -53
  13. package/dist/cmd/lib/actions/cmd.d.ts +3 -2
  14. package/dist/cmd/lib/actions/cmd.js +71 -49
  15. package/dist/cmd/lib/actions/read.js +2 -2
  16. package/dist/cmd/lib/adaptaters/cmd.d.ts +2 -2
  17. package/dist/cmd/lib/adaptaters/cmd.js +3 -15
  18. package/dist/cmd/lib/models.d.ts +1 -1
  19. package/dist/cmd/lib/models.js +8 -6
  20. package/dist/cmd/lib/options_parsers.d.ts +7 -0
  21. package/dist/cmd/lib/options_parsers.js +41 -0
  22. package/dist/cmd/lib/tasks/cmd.d.ts +3 -2
  23. package/dist/cmd/lib/tasks/cmd.js +83 -62
  24. package/dist/cmd/lib/tools.d.ts +8 -1
  25. package/dist/cmd/lib/tools.js +31 -1
  26. package/dist/cmd/lib/utils.d.ts +1 -2
  27. package/dist/cmd/lib/utils.js +1 -23
  28. package/dist/cmd/lib/workflows/cmd.d.ts +3 -2
  29. package/dist/cmd/lib/workflows/cmd.js +21 -27
  30. package/dist/cmd/options.d.ts +8 -0
  31. package/dist/cmd/options.js +62 -0
  32. package/dist/cmd/sys/read_cmds.d.ts +2 -2
  33. package/dist/cmd/sys/read_cmds.js +2 -2
  34. package/dist/db/db.d.ts +1 -1
  35. package/dist/db/db.js +3 -2
  36. package/dist/db/read.d.ts +3 -2
  37. package/dist/db/read.js +18 -12
  38. package/dist/db/schemas.js +12 -6
  39. package/dist/db/write.js +30 -13
  40. package/dist/index.js +14 -8
  41. package/dist/interfaces.d.ts +5 -6
  42. package/dist/main.d.ts +6 -6
  43. package/dist/main.js +6 -6
  44. package/dist/state/state.d.ts +2 -7
  45. package/dist/state/state.js +3 -11
  46. package/dist/utils/perf.d.ts +1 -1
  47. package/dist/utils/perf.js +6 -6
  48. package/dist/utils/user_msgs.d.ts +5 -0
  49. package/dist/utils/user_msgs.js +17 -0
  50. package/package.json +10 -11
  51. package/dist/cmd/clicmds/modes.d.ts +0 -3
  52. package/dist/cmd/clicmds/modes.js +0 -95
  53. package/dist/utils/args.d.ts +0 -7
  54. package/dist/utils/args.js +0 -85
@@ -1,41 +1,30 @@
1
- import { isDebug, isVerbose } from "../../../state/state.js";
1
+ import { executeAction } from "../actions/cmd.js";
2
+ import { executeAdaptater } from "../adaptaters/cmd.js";
3
+ import { parseCommandArgs } from "../options_parsers.js";
4
+ import { executeTask } from "../tasks/cmd.js";
2
5
  import { readWorkflow } from "./read.js";
3
- import { executeTaskCmd } from "../tasks/cmd.js";
4
- import { executeActionCmd } from "../actions/cmd.js";
5
- import { executeAdaptaterCmd } from "../adaptaters/cmd.js";
6
- async function executeWorkflowCmd(name, args = [], options = {}) {
6
+ async function executeWorkflow(name, params, options) {
7
7
  const { workflow, found } = await readWorkflow(name);
8
8
  if (!found) {
9
9
  throw new Error(`Workflow ${name} not found`);
10
10
  }
11
+ const isDebug = options?.debug === true;
12
+ const isVerbose = options?.verbose === true;
11
13
  const stepNames = Object.keys(workflow);
12
- if (isDebug.value || isVerbose.value) {
14
+ if (isDebug || isVerbose) {
13
15
  console.log("Running workflow", name, stepNames.length, "steps");
14
16
  }
15
- let params = Array.isArray(args) ? {} : args;
16
17
  let i = 0;
17
18
  const finalTaskIndex = stepNames.length + 1;
18
- let taskRes = {};
19
+ let taskRes = params;
19
20
  for (const [name, step] of Object.entries(workflow)) {
20
- if (isDebug.value || isVerbose.value) {
21
+ if (isDebug || isVerbose) {
21
22
  console.log(`${i + 1}: ${step.type} ${name}`);
22
23
  }
23
- let pval = new Array();
24
- if (i == 0) {
25
- pval = [name, ...args];
26
- }
27
- else {
28
- if (Array.isArray(params)) {
29
- pval = [name, ...params];
30
- }
31
- else {
32
- pval = { name: name, ...params };
33
- }
34
- }
35
24
  switch (step.type) {
36
25
  case "task":
37
26
  try {
38
- const tr = await executeTaskCmd(pval, options);
27
+ const tr = await executeTask(name, taskRes, options, true);
39
28
  taskRes = tr;
40
29
  }
41
30
  catch (e) {
@@ -44,9 +33,9 @@ async function executeWorkflowCmd(name, args = [], options = {}) {
44
33
  break;
45
34
  case "action":
46
35
  try {
47
- const ares = await executeActionCmd(pval, options, true);
36
+ const ares = await executeAction(name, taskRes, options, true);
48
37
  if (typeof ares == "string") {
49
- taskRes = [ares];
38
+ taskRes = { payload: ares };
50
39
  }
51
40
  else {
52
41
  taskRes = ares;
@@ -61,9 +50,9 @@ async function executeWorkflowCmd(name, args = [], options = {}) {
61
50
  break;
62
51
  case "adaptater":
63
52
  try {
64
- const ares = await executeAdaptaterCmd(pval, options);
53
+ const ares = await executeAdaptater(name, taskRes, options);
65
54
  if (typeof ares == "string") {
66
- taskRes = [ares];
55
+ taskRes = { payload: ares };
67
56
  }
68
57
  else {
69
58
  taskRes = ares;
@@ -81,4 +70,9 @@ async function executeWorkflowCmd(name, args = [], options = {}) {
81
70
  }
82
71
  return taskRes;
83
72
  }
84
- export { executeWorkflowCmd, };
73
+ async function executeWorkflowCmd(name, wargs) {
74
+ const { args, options } = parseCommandArgs(wargs);
75
+ const params = { args: args };
76
+ return await executeWorkflow(name, params, options);
77
+ }
78
+ export { executeWorkflow, executeWorkflowCmd, };
@@ -0,0 +1,8 @@
1
+ import { Option } from "commander";
2
+ declare const displayOptions: Array<Option>;
3
+ declare const inferenceOptions: Array<Option>;
4
+ declare const ioOptions: Array<Option>;
5
+ declare const taskOptions: Array<Option>;
6
+ declare const actionOptions: Array<Option>;
7
+ declare const workflowOptions: Array<Option>;
8
+ export { displayOptions, ioOptions, inferenceOptions, taskOptions, actionOptions, workflowOptions, };
@@ -0,0 +1,62 @@
1
+ import { InvalidArgumentError, Option } from "commander";
2
+ const displayOptions = [
3
+ new Option("-v, --verbose", "use the verbose mode"),
4
+ new Option("-d, --debug", "use the debug mode"),
5
+ ];
6
+ const inferenceOptions = [
7
+ new Option("-m, --model <name>", "the model name").argParser(parseString),
8
+ new Option("-x, --ctx", "context window size").argParser(parseIntValue),
9
+ new Option("--tpl, --template <template>", "the template to use"),
10
+ new Option("--mt, --max_tokens <number>", "the number of predictions to return").argParser(parseIntValue),
11
+ new Option("-k, --top_k <number>", "limits the result set to the top K results").argParser(parseIntValue),
12
+ new Option("-p, --top_p <number>", "filters results based on cumulative probability").argParser(parseFloatValue),
13
+ new Option("--mp, --min_p <number>", "the minimum probability for a token to be considered, relative to the probability of the most likely token").argParser(parseFloatValue),
14
+ new Option("-t, --temperature <number>", "adjusts randomness in sampling; higher values mean more randomness").argParser(parseFloatValue),
15
+ new Option("-r, --repeat_penalty <number>", "adjusts penalty for repeated tokens").argParser(parseFloatValue),
16
+ ];
17
+ const ioOptions = [
18
+ new Option("--if, --input-file", "use promptfile input mode"),
19
+ new Option("--ic, --clipboard-input", "use clipboard input mode"),
20
+ new Option("--im, --manual-input", "use manual input mode (default)"),
21
+ new Option("--oc, --clipboard-output", "use clipboard output mode"),
22
+ new Option("--omd, --markdown-output", "use markdown output"),
23
+ new Option("--otxt, --text-output", "use text output (default)"),
24
+ ];
25
+ const taskOptions = [
26
+ ...displayOptions,
27
+ ...ioOptions,
28
+ ...inferenceOptions,
29
+ new Option("--tokens", "toggle show tokens mode"),
30
+ new Option("-c, --chat", "toggle chat mode for tasks"),
31
+ ];
32
+ const actionOptions = [
33
+ ...displayOptions,
34
+ ...ioOptions,
35
+ ];
36
+ const workflowOptions = [
37
+ ...taskOptions
38
+ ];
39
+ function parseString(value) {
40
+ if (typeof value !== 'string')
41
+ throw new InvalidArgumentError('The value must be a string');
42
+ return value;
43
+ }
44
+ function parseIntValue(value) {
45
+ if (typeof value !== 'string')
46
+ throw new InvalidArgumentError('The value must be a string');
47
+ const num = parseInt(value);
48
+ if (!isNaN(num))
49
+ return num;
50
+ else
51
+ throw new InvalidArgumentError(`Invalid integer: ${value}`);
52
+ }
53
+ function parseFloatValue(value) {
54
+ if (typeof value !== 'string')
55
+ throw new InvalidArgumentError('The value must be a string');
56
+ const num = parseFloat(value);
57
+ if (!isNaN(num))
58
+ return num;
59
+ else
60
+ throw new InvalidArgumentError(`Invalid float: ${value}`);
61
+ }
62
+ export { displayOptions, ioOptions, inferenceOptions, taskOptions, actionOptions, workflowOptions, };
@@ -1,3 +1,3 @@
1
- import { Cmd } from "../../interfaces.js";
2
- declare function readCmds(dir: string): Promise<Record<string, Cmd>>;
1
+ import { Command } from "commander";
2
+ declare function readCmds(dir: string): Promise<Array<Command>>;
3
3
  export { readCmds };
@@ -15,14 +15,14 @@ function _readCmdsDir(dir) {
15
15
  return fileNames;
16
16
  }
17
17
  async function readCmds(dir) {
18
- const cmds = {};
18
+ const cmds = new Array();
19
19
  const fileNames = _readCmdsDir(dir);
20
20
  for (const name of fileNames) {
21
21
  const { cmd } = await import(path.join(dir, name + ".js"));
22
22
  if (!cmd) {
23
23
  throw new Error(`command ${name} not found in ${dir}`);
24
24
  }
25
- cmds[name] = cmd;
25
+ cmds.push(cmd);
26
26
  }
27
27
  return cmds;
28
28
  }
package/dist/db/db.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Database } from "better-sqlite3";
2
2
  declare const dbPath: string;
3
3
  declare let db: Database;
4
- declare function initDb(isVerbose: boolean, execSchema?: boolean): void;
4
+ declare function initDb(isVerbose: boolean, execSchema: boolean): void;
5
5
  export { db, dbPath, initDb, };
package/dist/db/db.js CHANGED
@@ -5,10 +5,11 @@ import { createDirectoryIfNotExists } from "../cmd/sys/dirs.js";
5
5
  const confDir = path.join(process.env.HOME ?? "~/", ".config/agent-smith/cli");
6
6
  const dbPath = path.join(confDir, "config.db");
7
7
  let db;
8
- function initDb(isVerbose, execSchema = false) {
8
+ const debugDb = true;
9
+ function initDb(isVerbose, execSchema) {
9
10
  if (execSchema) {
10
11
  createDirectoryIfNotExists(confDir, true);
11
- db = new DatabaseConstructor(dbPath, { fileMustExist: false });
12
+ db = new DatabaseConstructor(dbPath, { fileMustExist: false, verbose: debugDb ? console.log : undefined });
12
13
  schemas.forEach((s) => {
13
14
  db.exec(s);
14
15
  if (isVerbose) {
package/dist/db/read.d.ts CHANGED
@@ -2,7 +2,8 @@ import { ToolSpec } from "modprompt";
2
2
  import { AliasType, FeatureSpec, FeatureType, DbModelDef, ToolType } from "../interfaces.js";
3
3
  declare function readFeaturePaths(): Array<string>;
4
4
  declare function readPlugins(): Array<Record<string, string>>;
5
- declare function readFeatures(): Record<FeatureType, Record<string, string>>;
5
+ declare function readFeaturesType(type: FeatureType): Record<string, FeatureSpec>;
6
+ declare function readFeatures(): Record<FeatureType, Record<string, FeatureSpec>>;
6
7
  declare function readAliases(): Array<{
7
8
  name: string;
8
9
  type: AliasType;
@@ -30,4 +31,4 @@ declare function readModel(shortname: string): {
30
31
  found: boolean;
31
32
  modelData: Record<string, any>;
32
33
  };
33
- export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readModels, readModelfiles, readModel, };
34
+ export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readModels, readModelfiles, readModel, readFeaturesType, };
package/dist/db/read.js CHANGED
@@ -17,25 +17,31 @@ function readPlugins() {
17
17
  });
18
18
  return f;
19
19
  }
20
- function _readFeaturesType(type) {
21
- const stmt = db.prepare(`SELECT name, path FROM ${type}`);
20
+ function readFeaturesType(type) {
21
+ const stmt = db.prepare(`SELECT name, path, ext, variables FROM ${type}`);
22
22
  const data = stmt.all();
23
- let f = {};
23
+ const res = {};
24
24
  data.forEach((row) => {
25
- f[row.name] = row.path;
25
+ const vars = row?.variables ? JSON.parse(row.variables) : undefined;
26
+ res[row.name] = {
27
+ name: row.name,
28
+ path: row.path,
29
+ ext: row.ext,
30
+ variables: vars,
31
+ };
26
32
  });
27
- return f;
33
+ return res;
28
34
  }
29
35
  function readFeatures() {
30
36
  const feats = {
31
37
  task: {}, action: {}, cmd: {}, workflow: {}, adaptater: {}, modelfile: {}
32
38
  };
33
- feats.task = _readFeaturesType("task");
34
- feats.action = _readFeaturesType("action");
35
- feats.cmd = _readFeaturesType("cmd");
36
- feats.workflow = _readFeaturesType("workflow");
37
- feats.adaptater = _readFeaturesType("adaptater");
38
- feats.modelfile = _readFeaturesType("modelfile");
39
+ feats.task = readFeaturesType("task");
40
+ feats.action = readFeaturesType("action");
41
+ feats.cmd = readFeaturesType("cmd");
42
+ feats.workflow = readFeaturesType("workflow");
43
+ feats.adaptater = readFeaturesType("adaptater");
44
+ feats.modelfile = readFeaturesType("modelfile");
39
45
  return feats;
40
46
  }
41
47
  function readAliases() {
@@ -129,4 +135,4 @@ function readModel(shortname) {
129
135
  }
130
136
  return { found: false, modelData: {} };
131
137
  }
132
- export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readModels, readModelfiles, readModel, };
138
+ export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readModels, readModelfiles, readModel, readFeaturesType, };
@@ -16,38 +16,43 @@ const tasks = `CREATE TABLE IF NOT EXISTS task (
16
16
  id INTEGER PRIMARY KEY AUTOINCREMENT,
17
17
  name TEXT UNIQUE NOT NULL,
18
18
  path TEXT NOT NULL,
19
+ variables TEXT,
19
20
  ext TEXT NOT NULL CHECK ( ext IN ('yml') )
20
21
  );`;
21
22
  const workflow = `CREATE TABLE IF NOT EXISTS workflow (
22
23
  id INTEGER PRIMARY KEY AUTOINCREMENT,
23
24
  name TEXT UNIQUE NOT NULL,
24
25
  path TEXT NOT NULL,
26
+ variables TEXT,
25
27
  ext TEXT NOT NULL CHECK ( ext IN ('yml') )
26
28
  );`;
27
29
  const action = `CREATE TABLE IF NOT EXISTS action (
28
30
  id INTEGER PRIMARY KEY AUTOINCREMENT,
29
31
  name TEXT UNIQUE NOT NULL,
30
32
  path TEXT NOT NULL,
33
+ variables TEXT,
31
34
  ext TEXT NOT NULL CHECK ( ext IN ('yml', 'js', 'py') )
32
35
  );`;
33
36
  const adaptater = `CREATE TABLE IF NOT EXISTS adaptater (
34
37
  id INTEGER PRIMARY KEY AUTOINCREMENT,
35
38
  name TEXT UNIQUE NOT NULL,
36
39
  path TEXT NOT NULL,
40
+ variables TEXT,
37
41
  ext TEXT NOT NULL CHECK ( ext IN ('yml', 'js', 'py') )
38
42
  );`;
39
- const tool = `CREATE TABLE IF NOT EXISTS tool (
40
- id INTEGER PRIMARY KEY AUTOINCREMENT,
41
- name TEXT UNIQUE NOT NULL,
42
- spec TEXT NOT NULL,
43
- type TEXT NOT NULL CHECK ( type IN ('task', 'action', 'workflow') )
44
- );`;
45
43
  const cmd = `CREATE TABLE IF NOT EXISTS cmd (
46
44
  id INTEGER PRIMARY KEY AUTOINCREMENT,
47
45
  name TEXT UNIQUE NOT NULL,
48
46
  path TEXT NOT NULL,
47
+ variables TEXT,
49
48
  ext TEXT NOT NULL CHECK ( ext IN ('js') )
50
49
  );`;
50
+ const tool = `CREATE TABLE IF NOT EXISTS tool (
51
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
52
+ name TEXT UNIQUE NOT NULL,
53
+ spec TEXT NOT NULL,
54
+ type TEXT NOT NULL CHECK ( type IN ('task', 'action', 'workflow') )
55
+ );`;
51
56
  const alias = `CREATE TABLE IF NOT EXISTS aliases (
52
57
  id INTEGER PRIMARY KEY AUTOINCREMENT,
53
58
  name TEXT UNIQUE NOT NULL,
@@ -57,6 +62,7 @@ const modelfile = `CREATE TABLE IF NOT EXISTS modelfile (
57
62
  id INTEGER PRIMARY KEY AUTOINCREMENT,
58
63
  name TEXT UNIQUE NOT NULL,
59
64
  path TEXT NOT NULL,
65
+ variables TEXT,
60
66
  ext TEXT NOT NULL CHECK ( ext IN ('yml') )
61
67
  );`;
62
68
  const model = `CREATE TABLE IF NOT EXISTS model (
package/dist/db/write.js CHANGED
@@ -1,4 +1,4 @@
1
- import { extractToolDoc } from "../cmd/lib/tools.js";
1
+ import { extractTaskToolDocAndVariables, extractToolDoc } from "../cmd/lib/tools.js";
2
2
  import { db } from "./db.js";
3
3
  import { readModels } from "./read.js";
4
4
  function updatePromptfilePath(pf) {
@@ -101,15 +101,29 @@ function upsertAndCleanFeatures(feats, type) {
101
101
  });
102
102
  return newFeatures;
103
103
  }
104
+ function updateVariables(name, variableDoc) {
105
+ const stmt1 = db.prepare("SELECT id FROM task WHERE name = ?");
106
+ const result = stmt1.get(name);
107
+ if (!result?.id) {
108
+ return;
109
+ }
110
+ const updateStmt = db.prepare("UPDATE task SET variables = ? WHERE id = ?");
111
+ updateStmt.run(variableDoc, result.id);
112
+ console.log("~", "[task variables] updated for", name);
113
+ }
104
114
  function upsertTool(name, type, toolDoc) {
105
115
  const stmt1 = db.prepare("SELECT * FROM tool WHERE name = ?");
106
116
  const result = stmt1.get(name);
107
117
  if (result?.id) {
108
- return;
118
+ const updateStmt = db.prepare("UPDATE tool SET spec = ?, type = ? WHERE id = ?");
119
+ updateStmt.run(toolDoc, type, result.id);
120
+ console.log("~", "[tool] updated from", type, ":", name);
121
+ }
122
+ else {
123
+ const stmt = db.prepare("INSERT INTO tool (name, spec, type) VALUES (?,?,?)");
124
+ stmt.run(name, toolDoc, type);
125
+ console.log("+", "[tool] added from", type, ":", name);
109
126
  }
110
- const stmt = db.prepare("INSERT INTO tool (name, spec, type) VALUES (?,?,?)");
111
- stmt.run(name, toolDoc, type);
112
- console.log("+", "[tool] from", type, ":", name);
113
127
  }
114
128
  function updateModels(models) {
115
129
  const allDbModels = readModels();
@@ -137,22 +151,25 @@ function updateModels(models) {
137
151
  })();
138
152
  }
139
153
  function updateFeatures(feats) {
140
- const newTasks = upsertAndCleanFeatures(feats.task, "task");
141
- newTasks.forEach((feat) => {
142
- const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
143
- if (found) {
154
+ upsertAndCleanFeatures(feats.task, "task");
155
+ feats.task.forEach((feat) => {
156
+ const { toolDoc, variables } = extractTaskToolDocAndVariables(feat.name, feat.ext, feat.path);
157
+ if (toolDoc.length > 0) {
144
158
  upsertTool(feat.name, "task", toolDoc);
145
159
  }
160
+ if (variables.required.length > 0 || variables.optional.length > 0) {
161
+ updateVariables(feat.name, JSON.stringify(variables, null, " "));
162
+ }
146
163
  });
147
- const newActions = upsertAndCleanFeatures(feats.action, "action");
148
- newActions.forEach((feat) => {
164
+ upsertAndCleanFeatures(feats.action, "action");
165
+ feats.action.forEach((feat) => {
149
166
  const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
150
167
  if (found) {
151
168
  upsertTool(feat.name, "action", toolDoc);
152
169
  }
153
170
  });
154
- const newWorkflows = upsertAndCleanFeatures(feats.workflow, "workflow");
155
- newWorkflows.forEach((feat) => {
171
+ upsertAndCleanFeatures(feats.workflow, "workflow");
172
+ feats.workflow.forEach((feat) => {
156
173
  const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
157
174
  if (found) {
158
175
  upsertTool(feat.name, "workflow", toolDoc);
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import { argv } from 'process';
3
- import { query } from "./cli.js";
4
- import { initState, runMode } from './state/state.js';
5
3
  import { initAgent } from './agent.js';
6
- import { initCliCmds, parseCmd } from './cmd/cmds.js';
7
- import { updateConfCmd } from './cmd/clicmds/cmds.js';
4
+ import { query } from "./cli.js";
5
+ import { buildCmds, parseCmd } from './cmd/cmds.js';
6
+ import { initState, isChatMode, runMode } from './state/state.js';
7
+ import { updateConfCmd } from './cmd/clicmds/update.js';
8
8
  async function main() {
9
9
  const nargs = argv.length;
10
10
  if (nargs == 2) {
@@ -12,19 +12,25 @@ async function main() {
12
12
  }
13
13
  else if (nargs >= 3) {
14
14
  if (argv[2] == "conf") {
15
- await updateConfCmd(argv.slice(-1), {});
15
+ await updateConfCmd(argv.slice(-1));
16
16
  return;
17
17
  }
18
18
  }
19
19
  await initState();
20
20
  await initAgent();
21
+ const program = await buildCmds();
22
+ program.hook('preAction', async (thisCommand, actionCommand) => {
23
+ const options = actionCommand.opts();
24
+ if (options?.chat === true) {
25
+ isChatMode.value = true;
26
+ }
27
+ });
21
28
  switch (runMode.value) {
22
29
  case "cli":
23
- await initCliCmds();
24
- await query();
30
+ await query(program);
25
31
  break;
26
32
  default:
27
- await parseCmd();
33
+ await parseCmd(program);
28
34
  break;
29
35
  }
30
36
  }
@@ -1,15 +1,15 @@
1
1
  import { BaseLmTask, ModelSpec } from "@agent-smith/lmtask";
2
2
  import { InferenceParams } from "@locallm/types";
3
- interface Cmd {
4
- cmd: CmdExecutor;
5
- description: string;
6
- args?: string;
3
+ interface FeatureVariables {
4
+ required: Array<string>;
5
+ optional: Array<string>;
7
6
  }
8
7
  interface FeatureSpec {
9
8
  id?: number;
10
9
  name: string;
11
10
  path: string;
12
11
  ext: FeatureExtension;
12
+ variables?: FeatureVariables;
13
13
  }
14
14
  interface Features {
15
15
  task: Array<{
@@ -92,7 +92,6 @@ interface FinalLmTaskConfig {
92
92
  model?: ModelSpec;
93
93
  modelname?: string;
94
94
  }
95
- type CmdExecutor = (args: Array<string>, options: any) => Promise<any>;
96
95
  type InputMode = "manual" | "promptfile" | "clipboard";
97
96
  type OutputMode = "txt" | "clipboard";
98
97
  type RunMode = "cli" | "cmd";
@@ -108,4 +107,4 @@ type CmdExtension = "js";
108
107
  type ModelFileExtension = "yml";
109
108
  type FeatureExtension = TaskExtension | CmdExtension | ActionExtension | WorkflowExtension | ModelFileExtension;
110
109
  type AliasType = "task" | "action" | "workflow";
111
- export { Cmd, CmdExecutor, InputMode, VerbosityMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, WorkflowExtension, AdaptaterExtension, CmdExtension, ModelFileExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, ToolType, Settings, DbModelDef, ModelSpec, ModelfileSpec, ModelPack, LmTaskFileSpec, LmTaskConfig, FinalLmTaskConfig, };
110
+ export { InputMode, VerbosityMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, WorkflowExtension, AdaptaterExtension, CmdExtension, ModelFileExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, ToolType, Settings, DbModelDef, ModelSpec, ModelfileSpec, ModelPack, LmTaskFileSpec, LmTaskConfig, FinalLmTaskConfig, };
package/dist/main.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import { execute, run } from "./cmd/sys/execute.js";
2
- import { executeActionCmd } from "./cmd/lib/actions/cmd.js";
3
- import { executeTaskCmd } from "./cmd/lib/tasks/cmd.js";
4
- import { executeWorkflowCmd } from "./cmd/lib/workflows/cmd.js";
2
+ import { executeTask } from "./cmd/lib/tasks/cmd.js";
3
+ import { executeAction } from "./cmd/lib/actions/cmd.js";
4
+ import { executeWorkflow } from "./cmd/lib/workflows/cmd.js";
5
5
  import { writeToClipboard } from "./cmd/sys/clipboard.js";
6
- import { pingCmd } from "./cmd/clicmds/cmds.js";
7
6
  import { initAgent } from "./agent.js";
8
7
  import { initState, pluginDataDir } from "./state/state.js";
9
8
  import { usePerfTimer } from "./utils/perf.js";
10
- import { parseArgs } from "./utils/args.js";
9
+ import { parseCommandArgs } from "./cmd/lib/options_parsers.js";
11
10
  import { LmTaskConf } from "@agent-smith/lmtask/dist/interfaces.js";
12
11
  import { extractToolDoc } from "./cmd/lib/tools.js";
13
12
  import { openTaskSpec } from "./cmd/lib/tasks/utils.js";
14
13
  import { extractBetweenTags, splitThinking } from "./utils/text.js";
15
- export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseArgs, extractToolDoc, LmTaskConf, openTaskSpec, extractBetweenTags, splitThinking, };
14
+ import { displayOptions, ioOptions, inferenceOptions, taskOptions, actionOptions, workflowOptions } from "./cmd/options.js";
15
+ export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, LmTaskConf, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, taskOptions, actionOptions, workflowOptions, };
package/dist/main.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { execute, run } from "./cmd/sys/execute.js";
2
- import { executeActionCmd } from "./cmd/lib/actions/cmd.js";
3
- import { executeTaskCmd } from "./cmd/lib/tasks/cmd.js";
4
- import { executeWorkflowCmd } from "./cmd/lib/workflows/cmd.js";
2
+ import { executeTask } from "./cmd/lib/tasks/cmd.js";
3
+ import { executeAction } from "./cmd/lib/actions/cmd.js";
4
+ import { executeWorkflow } from "./cmd/lib/workflows/cmd.js";
5
5
  import { writeToClipboard } from "./cmd/sys/clipboard.js";
6
- import { pingCmd } from "./cmd/clicmds/cmds.js";
7
6
  import { initAgent } from "./agent.js";
8
7
  import { initState, pluginDataDir } from "./state/state.js";
9
8
  import { usePerfTimer } from "./utils/perf.js";
10
- import { parseArgs } from "./utils/args.js";
9
+ import { parseCommandArgs } from "./cmd/lib/options_parsers.js";
11
10
  import { extractToolDoc } from "./cmd/lib/tools.js";
12
11
  import { openTaskSpec } from "./cmd/lib/tasks/utils.js";
13
12
  import { extractBetweenTags, splitThinking } from "./utils/text.js";
14
- export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, };
13
+ import { displayOptions, ioOptions, inferenceOptions, taskOptions, actionOptions, workflowOptions } from "./cmd/options.js";
14
+ export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, taskOptions, actionOptions, workflowOptions, };
@@ -1,15 +1,11 @@
1
1
  import { PythonShell } from 'python-shell';
2
- import { InputMode, RunMode, FormatMode, OutputMode, VerbosityMode } from "../interfaces.js";
2
+ import { InputMode, RunMode, FormatMode, OutputMode } from "../interfaces.js";
3
3
  declare let pyShell: PythonShell;
4
4
  declare const inputMode: import("@vue/reactivity").Ref<InputMode, InputMode>;
5
5
  declare const outputMode: import("@vue/reactivity").Ref<OutputMode, OutputMode>;
6
6
  declare const runMode: import("@vue/reactivity").Ref<RunMode, RunMode>;
7
7
  declare const formatMode: import("@vue/reactivity").Ref<FormatMode, FormatMode>;
8
8
  declare const isChatMode: import("@vue/reactivity").Ref<boolean, boolean>;
9
- declare const isDebug: import("@vue/reactivity").ComputedRef<boolean>;
10
- declare const isVerbose: import("@vue/reactivity").ComputedRef<boolean>;
11
- declare const isQuiet: import("@vue/reactivity").ComputedRef<boolean>;
12
- declare const isShowTokens: import("@vue/reactivity").Ref<boolean, boolean>;
13
9
  declare const promptfilePath: import("@vue/reactivity").Ref<string, string>;
14
10
  declare const dataDirPath: import("@vue/reactivity").Ref<string, string>;
15
11
  declare const lastCmd: {
@@ -19,5 +15,4 @@ declare const lastCmd: {
19
15
  declare function initFilepaths(): void;
20
16
  declare function initState(): Promise<void>;
21
17
  declare function pluginDataDir(pluginName: string): string;
22
- declare function setVerbosity(mode: VerbosityMode): void;
23
- export { inputMode, outputMode, isChatMode, isShowTokens, runMode, formatMode, lastCmd, isDebug, isVerbose, isQuiet, promptfilePath, dataDirPath, pluginDataDir, initState, initFilepaths, setVerbosity, pyShell, };
18
+ export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, pluginDataDir, initState, initFilepaths, pyShell, };
@@ -1,4 +1,4 @@
1
- import { computed, reactive, ref } from "@vue/reactivity";
1
+ import { reactive, ref } from "@vue/reactivity";
2
2
  import { initDb } from "../db/db.js";
3
3
  import { readFilePaths } from "../db/read.js";
4
4
  import path from "path";
@@ -9,11 +9,6 @@ const outputMode = ref("txt");
9
9
  const runMode = ref("cmd");
10
10
  const formatMode = ref("text");
11
11
  const isChatMode = ref(false);
12
- const verbosity = ref("quiet");
13
- const isDebug = computed(() => verbosity.value == "debug");
14
- const isVerbose = computed(() => verbosity.value == "verbose");
15
- const isQuiet = computed(() => verbosity.value == "quiet");
16
- const isShowTokens = ref(false);
17
12
  const promptfilePath = ref("");
18
13
  const dataDirPath = ref("");
19
14
  const isStateReady = ref(false);
@@ -37,7 +32,7 @@ async function initState() {
37
32
  if (isStateReady.value) {
38
33
  return;
39
34
  }
40
- initDb(isDebug.value);
35
+ initDb(false, false);
41
36
  initFilepaths();
42
37
  isStateReady.value = true;
43
38
  }
@@ -53,7 +48,4 @@ function pluginDataDir(pluginName) {
53
48
  createDirectoryIfNotExists(pluginDatapath);
54
49
  return pluginDatapath;
55
50
  }
56
- function setVerbosity(mode) {
57
- verbosity.value = mode;
58
- }
59
- export { inputMode, outputMode, isChatMode, isShowTokens, runMode, formatMode, lastCmd, isDebug, isVerbose, isQuiet, promptfilePath, dataDirPath, pluginDataDir, initState, initFilepaths, setVerbosity, pyShell, };
51
+ export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, pluginDataDir, initState, initFilepaths, pyShell, };
@@ -1,6 +1,6 @@
1
1
  declare const usePerfTimer: (startTimer?: boolean) => {
2
2
  start: () => number;
3
- time: () => string | number;
3
+ time: () => string;
4
4
  timeRaw: () => string | number;
5
5
  printTime: () => void;
6
6
  };
@@ -16,17 +16,17 @@ const usePerfTimer = (startTimer = true) => {
16
16
  const humanizedTime = _formatDuration(duration);
17
17
  return humanizedTime;
18
18
  };
19
- const time = () => _end(false);
19
+ const time = () => _end(false).toString();
20
20
  const printTime = () => console.log(_end(false));
21
21
  const timeRaw = () => _end(true);
22
22
  const _formatDuration = (ms) => {
23
- const seconds = Math.floor(ms / 1000);
24
- const minutes = Math.floor(seconds / 60);
23
+ const seconds = ms / 1000;
24
+ const minutes = seconds / 60;
25
25
  if (ms < 1000)
26
- return `${ms.toFixed(2)}ms`;
26
+ return `${ms.toFixed(2)} milliseconds`;
27
27
  if (seconds < 60)
28
- return `${seconds.toFixed(2)}s`;
29
- return `${minutes}m ${seconds % 60}s`;
28
+ return `${seconds.toFixed(1)} seconds`;
29
+ return `${minutes.toFixed(1)} minutes ${seconds % 60} seconds`;
30
30
  };
31
31
  return {
32
32
  start,
@@ -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, };