@agent-smith/cli 0.0.3 → 0.0.4

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.
@@ -0,0 +1,5 @@
1
+ import { Cmd } from "../../interfaces.js";
2
+ declare let cmds: Record<string, Cmd>;
3
+ declare function initCmds(): Promise<Record<string, Cmd>>;
4
+ declare function pingCmd(args: Array<string> | undefined, options: any): Promise<boolean>;
5
+ export { cmds, initCmds, pingCmd };
@@ -0,0 +1,138 @@
1
+ import { formatMode, initFeatures, runMode } from "../../state/state.js";
2
+ import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
3
+ import { readFeatures } from "../../db/read.js";
4
+ import { updateFeatures } from "../../db/write.js";
5
+ import { updateConf } from "../../conf.js";
6
+ import { executeActionCmd } from "../lib/execute_action.js";
7
+ import { clearOutput, initAgent, marked, taskReader } from "../../agent.js";
8
+ import { executeJobCmd, readJob } from "../lib/execute_job.js";
9
+ import { executeTaskCmd } from "../lib/execute_task.js";
10
+ import { readCmds } from "../sys/read_cmds.js";
11
+ let cmds = {
12
+ q: {
13
+ cmd: async () => process.exit(0),
14
+ description: "exit the cli"
15
+ },
16
+ ping: {
17
+ cmd: async () => pingCmd(["verbose"], undefined),
18
+ description: "ping inference servers",
19
+ },
20
+ lt: {
21
+ cmd: _listTasksCmd,
22
+ description: "list all the tasks"
23
+ },
24
+ rt: {
25
+ cmd: _readTaskCmd,
26
+ description: "read a task",
27
+ args: "arguments: \n-task (required): the task name"
28
+ },
29
+ rj: {
30
+ cmd: _readJobCmd,
31
+ description: "read a job",
32
+ args: "arguments: \n-job (required): the job name"
33
+ },
34
+ t: {
35
+ cmd: _executeTaskCmd,
36
+ description: "execute a task",
37
+ args: "arguments: \n-task (required): the task name\n-args: prompt and other arguments if any for the task"
38
+ },
39
+ j: {
40
+ cmd: _executeJobCmd,
41
+ description: "execute a job",
42
+ args: "arguments: \n-job (required): the job name\n-args: arguments if any for the job"
43
+ },
44
+ a: {
45
+ cmd: executeActionCmd,
46
+ description: "execute an action",
47
+ args: "arguments: \n-action (required): the task name\n-args: other arguments if any for the action"
48
+ },
49
+ conf: {
50
+ cmd: _updateConfCmd,
51
+ description: "process config file",
52
+ args: "arguments: \n-path (required): the path to the config.yml file"
53
+ },
54
+ update: {
55
+ cmd: _updateFeaturesCmd,
56
+ description: "reparse the features dirs and update the list",
57
+ }
58
+ };
59
+ async function initCmds() {
60
+ for (const dirpath of new Set(Object.values(readFeatures().cmd))) {
61
+ const c = await readCmds(`${dirpath}`);
62
+ cmds = { ...cmds, ...c };
63
+ }
64
+ return cmds;
65
+ }
66
+ async function pingCmd(args = [], options) {
67
+ let _isVerbose = false;
68
+ if (args.length > 0) {
69
+ _isVerbose = args[0] == "verbose";
70
+ }
71
+ const isUp = await initAgent(runMode.value, _isVerbose);
72
+ return isUp;
73
+ }
74
+ async function _updateFeaturesCmd(args = [], options) {
75
+ await initFeatures();
76
+ console.log("Features updated");
77
+ }
78
+ async function _updateConfCmd(args = [], options) {
79
+ if (args.length == 0) {
80
+ console.warn("Provide a config.yml file path");
81
+ return;
82
+ }
83
+ const allPaths = await updateConf(args[0]);
84
+ const feats = readFeaturesDirs(allPaths);
85
+ updateFeatures(feats);
86
+ }
87
+ async function _readJobCmd(args = [], options) {
88
+ if (args.length == 0) {
89
+ console.warn("Provide a job name");
90
+ return;
91
+ }
92
+ const t = await readJob(args[0]);
93
+ console.log(t.data);
94
+ }
95
+ async function _executeTaskCmd(args = [], options) {
96
+ if (args.length == 0) {
97
+ console.warn("Provide a task name");
98
+ return;
99
+ }
100
+ const { ok, data, error } = await executeTaskCmd(args);
101
+ if (!ok) {
102
+ console.warn(error);
103
+ }
104
+ clearOutput();
105
+ if (formatMode.value == "markdown") {
106
+ console.log(marked.parse(data).trim());
107
+ }
108
+ else {
109
+ console.log(data);
110
+ }
111
+ return data;
112
+ }
113
+ async function _executeJobCmd(args = [], options) {
114
+ if (args.length == 0) {
115
+ console.warn("Provide a job name");
116
+ return;
117
+ }
118
+ const name = args.shift();
119
+ const res = await executeJobCmd(name, args);
120
+ return res;
121
+ }
122
+ async function _readTaskCmd(args = [], options) {
123
+ if (args.length == 0) {
124
+ console.warn("Provide a task name");
125
+ return;
126
+ }
127
+ const { found, path } = getFeatureSpec(args[0], "task");
128
+ if (!found) {
129
+ console.warn(`FeatureType ${args[0]} not found`);
130
+ return;
131
+ }
132
+ const r = taskReader.read(path);
133
+ console.log(r.task);
134
+ }
135
+ async function _listTasksCmd(args = [], options) {
136
+ Object.keys(readFeatures().task).forEach((t) => console.log("-", t));
137
+ }
138
+ export { cmds, initCmds, pingCmd };
@@ -1,7 +1,6 @@
1
1
  import { Command } from "commander";
2
- declare function initCmds(): Promise<void>;
2
+ declare function initCliCmds(): Promise<void>;
3
3
  declare function runCmd(cmdName: string, args?: Array<string>): Promise<void>;
4
- declare function pingCmd(args: Array<string> | undefined, options: any): Promise<boolean>;
5
4
  declare function buildCmds(): Promise<Command>;
6
5
  declare function parseCmd(): Promise<void>;
7
- export { initCmds, runCmd, buildCmds, parseCmd, pingCmd };
6
+ export { runCmd, buildCmds, parseCmd, initCliCmds };
package/dist/cmd/cmds.js CHANGED
@@ -1,157 +1,11 @@
1
1
  import { Command } from "commander";
2
- import { formatMode, initFeatures, lastCmd, runMode } from "../state/state.js";
3
- import { modes } from "./options/modes.js";
4
- import { executeTaskCmd } from "./lib/execute_task.js";
5
- import { clearOutput, initAgent, marked, taskReader } from "../agent.js";
6
- import { executeActionCmd } from "./lib/execute_action.js";
7
- import { executeJobCmd, readJob } from "./lib/execute_job.js";
8
- import { readCmds } from "./sys/read_cmds.js";
2
+ import { lastCmd } from "../state/state.js";
3
+ import { modes } from "./clicmds/modes.js";
9
4
  import { processOutput, setOptions } from "./lib/utils.js";
10
- import { getFeatureSpec, readFeaturesDirs } from "../state/features.js";
11
- import { readFeatures } from "../db/read.js";
12
- import { insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures } from "../db/write.js";
13
- import { readConf } from "./sys/read_conf.js";
14
- import { buildPluginsPaths } from "../state/plugins.js";
15
- let cmds = {
16
- q: {
17
- cmd: async () => process.exit(0),
18
- description: "exit the cli"
19
- },
20
- ping: {
21
- cmd: async () => pingCmd(["verbose"], undefined),
22
- description: "ping inference servers",
23
- },
24
- lt: {
25
- cmd: _listTasksCmd,
26
- description: "list all the tasks"
27
- },
28
- rt: {
29
- cmd: _readTaskCmd,
30
- description: "read a task",
31
- args: "arguments: \n-task (required): the task name"
32
- },
33
- rj: {
34
- cmd: _readJobCmd,
35
- description: "read a job",
36
- args: "arguments: \n-job (required): the job name"
37
- },
38
- t: {
39
- cmd: _executeTaskCmd,
40
- description: "execute a task",
41
- args: "arguments: \n-task (required): the task name\n-args: prompt and other arguments if any for the task"
42
- },
43
- j: {
44
- cmd: _executeJobCmd,
45
- description: "execute a job",
46
- args: "arguments: \n-job (required): the job name\n-args: arguments if any for the job"
47
- },
48
- a: {
49
- cmd: executeActionCmd,
50
- description: "execute an action",
51
- args: "arguments: \n-action (required): the task name\n-args: other arguments if any for the action"
52
- },
53
- conf: {
54
- cmd: _updateConfCmd,
55
- description: "process config file",
56
- args: "arguments: \n-path (required): the path to the config.yml file"
57
- },
58
- update: {
59
- cmd: _updateFeaturesCmd,
60
- description: "reparse the features dirs and update the list",
61
- }
62
- };
63
- let cliCmds = { ...cmds, ...modes };
64
- async function initCmds() {
65
- for (const dirpath of new Set(Object.values(readFeatures().cmd))) {
66
- const c = await readCmds(`${dirpath}`);
67
- cmds = { ...cmds, ...c };
68
- }
69
- cliCmds = { ...cmds, ...modes };
70
- }
71
- async function _updateFeaturesCmd(args = [], options) {
72
- await initFeatures();
73
- console.log("Features updated");
74
- }
75
- async function _updateConfCmd(args = [], options) {
76
- if (args.length == 0) {
77
- console.warn("Provide a config.yml file path");
78
- return;
79
- }
80
- const { found, data } = readConf(args[0]);
81
- if (!found) {
82
- console.warn(`Config file ${args[0]} not found`);
83
- }
84
- const p = new Array();
85
- if ("features" in data) {
86
- p.push(...data.features);
87
- const fts = new Array();
88
- data.features.forEach((f) => {
89
- if (!fts.includes(f)) {
90
- insertFeaturesPathIfNotExists(f);
91
- fts.push(f);
92
- }
93
- });
94
- }
95
- if ("plugins" in data) {
96
- const plugins = await buildPluginsPaths(data.plugins);
97
- plugins.forEach((_pl) => {
98
- p.push(_pl.path);
99
- insertPluginIfNotExists(_pl.name, _pl.path);
100
- });
101
- }
102
- const feats = readFeaturesDirs(p);
103
- updateFeatures(feats);
104
- }
105
- async function _readJobCmd(args = [], options) {
106
- if (args.length == 0) {
107
- console.warn("Provide a job name");
108
- return;
109
- }
110
- const t = await readJob(args[0]);
111
- console.log(t.data);
112
- }
113
- async function _executeTaskCmd(args = [], options) {
114
- if (args.length == 0) {
115
- console.warn("Provide a task name");
116
- return;
117
- }
118
- const { ok, data, error } = await executeTaskCmd(args);
119
- if (!ok) {
120
- console.warn(error);
121
- }
122
- clearOutput();
123
- if (formatMode.value == "markdown") {
124
- console.log(marked.parse(data).trim());
125
- }
126
- else {
127
- console.log(data);
128
- }
129
- return data;
130
- }
131
- async function _executeJobCmd(args = [], options) {
132
- if (args.length == 0) {
133
- console.warn("Provide a job name");
134
- return;
135
- }
136
- const name = args.shift();
137
- const res = await executeJobCmd(name, args);
138
- return res;
139
- }
140
- async function _readTaskCmd(args = [], options) {
141
- if (args.length == 0) {
142
- console.warn("Provide a task name");
143
- return;
144
- }
145
- const { found, path } = getFeatureSpec(args[0], "task");
146
- if (!found) {
147
- console.warn(`FeatureType ${args[0]} not found`);
148
- return;
149
- }
150
- const r = taskReader.read(path);
151
- console.log(r.task);
152
- }
153
- async function _listTasksCmd(args = [], options) {
154
- Object.keys(readFeatures().task).forEach((t) => console.log("-", t));
5
+ import { cmds, initCmds } from "./clicmds/cmds.js";
6
+ let cliCmds = {};
7
+ async function initCliCmds() {
8
+ cliCmds = await initCmds();
155
9
  }
156
10
  async function runCmd(cmdName, args = []) {
157
11
  if (!(cmdName in cliCmds)) {
@@ -163,14 +17,6 @@ async function runCmd(cmdName, args = []) {
163
17
  lastCmd.name = cmdName;
164
18
  lastCmd.args = args;
165
19
  }
166
- async function pingCmd(args = [], options) {
167
- let _isVerbose = false;
168
- if (args.length > 0) {
169
- _isVerbose = args[0] == "verbose";
170
- }
171
- const isUp = await initAgent(runMode.value, _isVerbose);
172
- return isUp;
173
- }
174
20
  async function buildCmds() {
175
21
  const program = new Command();
176
22
  for (const [name, spec] of Object.entries(cmds)) {
@@ -203,4 +49,4 @@ async function parseCmd() {
203
49
  const program = await buildCmds();
204
50
  await program.parseAsync();
205
51
  }
206
- export { initCmds, runCmd, buildCmds, parseCmd, pingCmd };
52
+ export { runCmd, buildCmds, parseCmd, initCliCmds };
@@ -2,7 +2,7 @@ import { default as fs } from "fs";
2
2
  import { outputMode, promptfile } from "../../state/state.js";
3
3
  import { inputMode, runMode } from "../../state/state.js";
4
4
  import { readClipboard, writeToClipboard } from "../sys/clipboard.js";
5
- import { modes } from "../options/modes.js";
5
+ import { modes } from "../clicmds/modes.js";
6
6
  async function setOptions(options, args = []) {
7
7
  if (runMode.value == "cli") {
8
8
  return args;
package/dist/conf.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  declare const confDir: string;
2
2
  declare const dbPath: string;
3
3
  declare function createConfDirIfNotExists(): boolean;
4
- export { confDir, dbPath, createConfDirIfNotExists, };
4
+ declare function updateConf(confPath: string): Promise<Array<string>>;
5
+ export { confDir, dbPath, createConfDirIfNotExists, updateConf, };
package/dist/conf.js CHANGED
@@ -1,5 +1,8 @@
1
1
  import path from "path";
2
2
  import { default as fs } from "fs";
3
+ import { readConf } from "./cmd/sys/read_conf.js";
4
+ import { insertFeaturesPathIfNotExists, insertPluginIfNotExists } from "./db/write.js";
5
+ import { buildPluginsPaths } from "./state/plugins.js";
3
6
  const confDir = path.join(process.env.HOME, ".config/agent-smith/cli");
4
7
  const dbPath = path.join(confDir, "config.db");
5
8
  function createConfDirIfNotExists() {
@@ -9,4 +12,29 @@ function createConfDirIfNotExists() {
9
12
  }
10
13
  return true;
11
14
  }
12
- export { confDir, dbPath, createConfDirIfNotExists, };
15
+ async function updateConf(confPath) {
16
+ const { found, data } = readConf(confPath);
17
+ if (!found) {
18
+ console.warn(`Config file ${confPath} not found`);
19
+ }
20
+ const allPaths = new Array();
21
+ if ("features" in data) {
22
+ allPaths.push(...data.features);
23
+ const fts = new Array();
24
+ data.features.forEach((f) => {
25
+ if (!fts.includes(f)) {
26
+ insertFeaturesPathIfNotExists(f);
27
+ fts.push(f);
28
+ }
29
+ });
30
+ }
31
+ if ("plugins" in data) {
32
+ const plugins = await buildPluginsPaths(data.plugins);
33
+ plugins.forEach((_pl) => {
34
+ allPaths.push(_pl.path);
35
+ insertPluginIfNotExists(_pl.name, _pl.path);
36
+ });
37
+ }
38
+ return allPaths;
39
+ }
40
+ export { confDir, dbPath, createConfDirIfNotExists, updateConf, };
package/dist/db/db.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Database } from "better-sqlite3";
2
2
  declare let db: Database;
3
3
  declare function initDb(isVerbose?: boolean): void;
4
- declare function dbPopulateDefaults(): void;
5
- export { db, initDb, dbPopulateDefaults, };
4
+ export { db, initDb, };
package/dist/db/db.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import DatabaseConstructor from "better-sqlite3";
2
2
  import { schemas } from "./schemas.js";
3
- import { createConfDirIfNotExists, dbPath } from "../conf.js";
4
- createConfDirIfNotExists();
5
- let db = new DatabaseConstructor(dbPath);
3
+ import { dbPath } from "../conf.js";
4
+ let db;
6
5
  function initDb(isVerbose = false) {
6
+ db = new DatabaseConstructor(dbPath);
7
7
  schemas.forEach((s) => {
8
8
  db.exec(s);
9
9
  if (isVerbose) {
@@ -11,6 +11,4 @@ function initDb(isVerbose = false) {
11
11
  }
12
12
  });
13
13
  }
14
- function dbPopulateDefaults() {
15
- }
16
- export { db, initDb, dbPopulateDefaults, };
14
+ export { db, initDb, };
package/dist/index.js CHANGED
@@ -3,13 +3,13 @@ import { argv } from 'process';
3
3
  import { query } from "./cli.js";
4
4
  import { initState, runMode } from './state/state.js';
5
5
  import { initAgent } from './agent.js';
6
- import { initCmds, parseCmd } from './cmd/cmds.js';
6
+ import { initCliCmds, parseCmd } from './cmd/cmds.js';
7
7
  async function main() {
8
8
  if (argv.length == 2) {
9
9
  runMode.value = "cli";
10
10
  }
11
11
  await initState();
12
- await initCmds();
12
+ await initCliCmds();
13
13
  await initAgent(runMode.value);
14
14
  switch (runMode.value) {
15
15
  case "cli":
package/dist/main.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { execute, run } from "./cmd/sys/execute.js";
2
2
  import { executeJobCmd } from "./cmd/lib/execute_job.js";
3
3
  import { writeToClipboard } from "./cmd/sys/clipboard.js";
4
- import { pingCmd } from "./cmd/cmds.js";
4
+ import { pingCmd } from "./cmd/clicmds/cmds.js";
5
5
  export { execute, run, pingCmd, executeJobCmd, writeToClipboard, };
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { execute, run } from "./cmd/sys/execute.js";
2
2
  import { executeJobCmd } from "./cmd/lib/execute_job.js";
3
3
  import { writeToClipboard } from "./cmd/sys/clipboard.js";
4
- import { pingCmd } from "./cmd/cmds.js";
4
+ import { pingCmd } from "./cmd/clicmds/cmds.js";
5
5
  export { execute, run, pingCmd, executeJobCmd, writeToClipboard, };
@@ -1,6 +1,6 @@
1
1
  import { reactive, ref } from "@vue/reactivity";
2
2
  import { createConfDirIfNotExists, confDir } from "../conf.js";
3
- import { initDb, dbPopulateDefaults } from "../db/db.js";
3
+ import { initDb } from "../db/db.js";
4
4
  import { readFeaturePaths } from "../db/read.js";
5
5
  import { updateFeatures } from "../db/write.js";
6
6
  import { readFeaturesDirs } from "./features.js";
@@ -19,12 +19,8 @@ function initConf() {
19
19
  const exists = createConfDirIfNotExists();
20
20
  if (!exists) {
21
21
  console.log("Created configuration directory", confDir);
22
- initDb();
23
- dbPopulateDefaults();
24
- }
25
- else {
26
- initDb();
27
22
  }
23
+ initDb();
28
24
  }
29
25
  async function initFeatures() {
30
26
  const fp = readFeaturePaths();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@agent-smith/cli",
3
3
  "description": "Agent Smith: terminal client for language model agents",
4
4
  "repository": "https://github.com/synw/agent-smith",
5
- "version": "0.0.3",
5
+ "version": "0.0.4",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",
@@ -11,8 +11,8 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@agent-smith/brain": "^0.0.18",
14
- "@agent-smith/jobs": "^0.0.7",
15
- "@agent-smith/lmtask": "^0.0.10",
14
+ "@agent-smith/jobs": "^0.0.8",
15
+ "@agent-smith/lmtask": "^0.0.12",
16
16
  "@inquirer/prompts": "^5.3.8",
17
17
  "@inquirer/select": "^2.4.7",
18
18
  "@vue/reactivity": "^3.4.38",
@@ -21,7 +21,7 @@
21
21
  "commander": "^12.1.0",
22
22
  "log-update": "^6.1.0",
23
23
  "marked-terminal": "^7.1.0",
24
- "modprompt": "^0.7.6",
24
+ "modprompt": "^0.7.7",
25
25
  "python-shell": "^5.0.0",
26
26
  "yaml": "^2.5.0"
27
27
  },
@@ -33,7 +33,7 @@
33
33
  "@rollup/plugin-typescript": "^11.1.6",
34
34
  "@types/better-sqlite3": "^7.6.11",
35
35
  "@types/marked-terminal": "^6.1.1",
36
- "@types/node": "^22.5.0",
36
+ "@types/node": "^22.5.1",
37
37
  "rollup": "^4.21.1",
38
38
  "ts-node": "^10.9.2",
39
39
  "tslib": "2.7.0",
File without changes
File without changes