@agent-smith/cli 0.0.20 → 0.0.22

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.
@@ -1,7 +1,7 @@
1
- import { formatMode, isChatMode } from "../../state/state.js";
1
+ import { formatMode, isChatMode, promptfile } from "../../state/state.js";
2
2
  import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
3
3
  import { readAliases, readFeatures } from "../../db/read.js";
4
- import { cleanupFeaturePaths, updateAliases, updateFeatures } from "../../db/write.js";
4
+ import { cleanupFeaturePaths, updateAliases, updateFeatures, updatePromptfilePath } from "../../db/write.js";
5
5
  import { processConfPath } from "../../conf.js";
6
6
  import { executeActionCmd } from "../lib/execute_action.js";
7
7
  import { initAgent, marked, taskBuilder } from "../../agent.js";
@@ -94,11 +94,15 @@ async function _updateConfCmd(args = [], options) {
94
94
  console.warn("Provide a config.yml file path");
95
95
  return;
96
96
  }
97
- const allPaths = await processConfPath(args[0]);
98
- const feats = readFeaturesDirs(allPaths);
97
+ const { paths, pf } = await processConfPath(args[0]);
98
+ if (pf.length > 0) {
99
+ updatePromptfilePath(pf);
100
+ promptfile.value = pf;
101
+ }
102
+ const feats = readFeaturesDirs(paths);
99
103
  updateFeatures(feats);
100
104
  updateAliases(feats);
101
- const deleted = cleanupFeaturePaths(allPaths);
105
+ const deleted = cleanupFeaturePaths(paths);
102
106
  for (const el of deleted) {
103
107
  console.log("- [feature path]", el);
104
108
  }
@@ -121,7 +125,7 @@ async function _executeTaskCmd(args = [], options) {
121
125
  console.warn(error);
122
126
  }
123
127
  if (formatMode.value == "markdown") {
124
- console.log("\n\n------------------\n");
128
+ console.log("\n------------------\n");
125
129
  console.log(marked.parse(data).trim());
126
130
  }
127
131
  else {
@@ -4,7 +4,7 @@ import { readYmlAction } from "../sys/read_yml_action.js";
4
4
  import { execute } from "../sys/execute.js";
5
5
  import { runPyScript } from "../sys/run_python.js";
6
6
  import { pyShell } from "../../state/state.js";
7
- import { processOutput } from "./utils.js";
7
+ import { parseInputOptions, processOutput } from "./utils.js";
8
8
  function _systemAction(path) {
9
9
  const action = useAgentTask({
10
10
  id: "system_action",
@@ -32,7 +32,7 @@ async function executeActionCmd(args = [], options = {}, quiet = false) {
32
32
  const name = args.shift();
33
33
  const { found, path, ext } = getFeatureSpec(name, "action");
34
34
  if (!found) {
35
- return { ok: false, data: {}, error: "FeatureType not found" };
35
+ return { ok: false, data: {}, error: "Action not found" };
36
36
  }
37
37
  let act;
38
38
  switch (ext) {
@@ -49,7 +49,11 @@ async function executeActionCmd(args = [], options = {}, quiet = false) {
49
49
  default:
50
50
  throw new Error(`Action ext ${ext} not implemented`);
51
51
  }
52
- const res = await act.run(args, options);
52
+ const input = await parseInputOptions(options);
53
+ if (input) {
54
+ args.push(input);
55
+ }
56
+ const res = await act.run(args, {});
53
57
  if (!quiet) {
54
58
  console.log(res.data);
55
59
  }
@@ -1,8 +1,7 @@
1
1
  import { brain, initAgent, taskBuilder } from "../../agent.js";
2
2
  import { getFeatureSpec } from "../../state/features.js";
3
- import { inputMode, isChatMode, isDebug } from "../../state/state.js";
4
- import { initTaskVars, readPromptFile, readTask } from "./utils.js";
5
- import { readClipboard } from "../sys/clipboard.js";
3
+ import { isChatMode, isDebug } from "../../state/state.js";
4
+ import { initTaskVars, parseInputOptions, readTask } from "./utils.js";
6
5
  async function executeTaskCmd(args = [], options = {}) {
7
6
  await initAgent();
8
7
  if (isDebug.value) {
@@ -11,17 +10,14 @@ async function executeTaskCmd(args = [], options = {}) {
11
10
  }
12
11
  const name = args.shift();
13
12
  const params = args.filter((x) => x.length > 0);
14
- let pr;
15
- if (options?.Ic == true || inputMode.value == "clipboard") {
16
- pr = await readClipboard();
17
- }
18
- else if (options.Pf || inputMode.value == "promptfile") {
19
- pr = readPromptFile();
20
- }
21
- else if (params.length > 0) {
22
- pr = params.shift();
13
+ let pr = await parseInputOptions(options);
14
+ if (!pr) {
15
+ const p = params.shift();
16
+ if (p) {
17
+ pr = p;
18
+ }
23
19
  }
24
- else {
20
+ if (!pr) {
25
21
  throw new Error("Please provide a prompt");
26
22
  }
27
23
  const { found, path } = getFeatureSpec(name, "task");
@@ -52,7 +48,14 @@ async function executeTaskCmd(args = [], options = {}) {
52
48
  throw new Error("No expert found for model " + m);
53
49
  }
54
50
  ex.checkStatus();
51
+ let i = 0;
55
52
  ex.backend.setOnToken((t) => {
53
+ if (i == 0) {
54
+ if (t == "\n\n") {
55
+ return;
56
+ }
57
+ }
58
+ ++i;
56
59
  process.stdout.write(t);
57
60
  });
58
61
  conf.expert = ex;
@@ -10,4 +10,5 @@ declare function initTaskVars(args: Array<any>): {
10
10
  conf: Record<string, any>;
11
11
  vars: Record<string, any>;
12
12
  };
13
- export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, initTaskVars, };
13
+ declare function parseInputOptions(options: any): Promise<string | null>;
14
+ export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, initTaskVars, parseInputOptions, };
@@ -20,8 +20,12 @@ async function setOptions(args = [], options) {
20
20
  return args;
21
21
  }
22
22
  function readPromptFile() {
23
- const res = fs.readFileSync(promptfile.value, 'utf8');
24
- return res;
23
+ try {
24
+ return fs.readFileSync(promptfile.value, 'utf8');
25
+ }
26
+ catch (e) {
27
+ return "";
28
+ }
25
29
  }
26
30
  async function processOutput(res) {
27
31
  if (!(outputMode.value == "clipboard")) {
@@ -102,4 +106,14 @@ function initTaskVars(args) {
102
106
  });
103
107
  return { conf, vars };
104
108
  }
105
- export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, initTaskVars, };
109
+ async function parseInputOptions(options) {
110
+ let out = null;
111
+ if (options?.Ic == true || inputMode.value == "clipboard") {
112
+ out = await readClipboard();
113
+ }
114
+ else if (options.Pf || inputMode.value == "promptfile") {
115
+ out = readPromptFile();
116
+ }
117
+ return out;
118
+ }
119
+ export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, initTaskVars, parseInputOptions, };
package/dist/conf.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  declare const confDir: string;
2
2
  declare const dbPath: string;
3
3
  declare function createConfDirIfNotExists(): boolean;
4
- declare function processConfPath(confPath: string): Promise<Array<string>>;
4
+ declare function processConfPath(confPath: string): Promise<{
5
+ paths: Array<string>;
6
+ pf: string;
7
+ }>;
5
8
  export { confDir, dbPath, createConfDirIfNotExists, processConfPath, };
package/dist/conf.js CHANGED
@@ -18,7 +18,7 @@ async function processConfPath(confPath) {
18
18
  console.warn(`Config file ${confPath} not found`);
19
19
  }
20
20
  const allPaths = new Array();
21
- if ("features" in data) {
21
+ if (data?.features) {
22
22
  allPaths.push(...data.features);
23
23
  const fts = new Array();
24
24
  data.features.forEach((f) => {
@@ -28,13 +28,17 @@ async function processConfPath(confPath) {
28
28
  }
29
29
  });
30
30
  }
31
- if ("plugins" in data) {
31
+ if (data?.plugins) {
32
32
  const plugins = await buildPluginsPaths(data.plugins);
33
33
  plugins.forEach((_pl) => {
34
34
  allPaths.push(_pl.path);
35
35
  insertPluginIfNotExists(_pl.name, _pl.path);
36
36
  });
37
37
  }
38
- return allPaths;
38
+ let pf = "";
39
+ if (data.promptfile) {
40
+ pf = data.promptfile;
41
+ }
42
+ return { paths: allPaths, pf: pf };
39
43
  }
40
44
  export { confDir, dbPath, createConfDirIfNotExists, processConfPath, };
package/dist/db/read.d.ts CHANGED
@@ -10,4 +10,5 @@ declare function readFeature(name: string, type: FeatureType): {
10
10
  found: boolean;
11
11
  feature: FeatureSpec;
12
12
  };
13
- export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases };
13
+ declare function readPromptFile(): string;
14
+ export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readPromptFile };
package/dist/db/read.js CHANGED
@@ -17,7 +17,7 @@ function readPlugins() {
17
17
  });
18
18
  return f;
19
19
  }
20
- function readFeaturesType(type) {
20
+ function _readFeaturesType(type) {
21
21
  const stmt = db.prepare(`SELECT name, path FROM ${type}`);
22
22
  const data = stmt.all();
23
23
  let f = {};
@@ -28,10 +28,10 @@ function readFeaturesType(type) {
28
28
  }
29
29
  function readFeatures() {
30
30
  const feats = { task: {}, job: {}, action: {}, cmd: {} };
31
- feats.task = readFeaturesType("task");
32
- feats.job = readFeaturesType("job");
33
- feats.action = readFeaturesType("action");
34
- feats.cmd = readFeaturesType("cmd");
31
+ feats.task = _readFeaturesType("task");
32
+ feats.job = _readFeaturesType("job");
33
+ feats.action = _readFeaturesType("action");
34
+ feats.cmd = _readFeaturesType("cmd");
35
35
  return feats;
36
36
  }
37
37
  function readAliases() {
@@ -59,4 +59,13 @@ function readFeature(name, type) {
59
59
  }
60
60
  return { found: false, feature: {} };
61
61
  }
62
- export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases };
62
+ function readPromptFile() {
63
+ const stmt1 = db.prepare("SELECT * FROM filepath WHERE name = ?");
64
+ const result = stmt1.get("promptfile");
65
+ let res = "";
66
+ if (result?.id) {
67
+ res = result.path;
68
+ }
69
+ return res;
70
+ }
71
+ export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readPromptFile };
@@ -1,8 +1,8 @@
1
1
  import { Features } from "../interfaces.js";
2
- declare function insertDefaultFilepaths(): void;
2
+ declare function updatePromptfilePath(pf: string): void;
3
3
  declare function insertFeaturesPathIfNotExists(path: string): boolean;
4
4
  declare function insertPluginIfNotExists(n: string, p: string): boolean;
5
5
  declare function cleanupFeaturePaths(paths: Array<string>): Array<string>;
6
6
  declare function updateAliases(feats: Features): void;
7
7
  declare function updateFeatures(feats: Features): void;
8
- export { insertDefaultFilepaths, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, };
8
+ export { updatePromptfilePath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, };
package/dist/db/write.js CHANGED
@@ -1,13 +1,9 @@
1
1
  import { db } from "./db.js";
2
- const defaultFilepaths = {
3
- prompt: "",
4
- override: "",
5
- };
6
- function insertDefaultFilepaths() {
7
- for (const [k, v] of Object.entries(defaultFilepaths)) {
8
- const stmt = db.prepare("INSERT INTO filepath (name, path) VALUES (?, ?)");
9
- stmt.run(k, v);
10
- }
2
+ function updatePromptfilePath(pf) {
3
+ const deleteStmt = db.prepare("DELETE FROM featurespath WHERE path = ?");
4
+ deleteStmt.run("promptfile");
5
+ const stmt = db.prepare("INSERT INTO filepath (name, path) VALUES (?, ?)");
6
+ stmt.run("promptfile", pf);
11
7
  }
12
8
  function insertFeaturesPathIfNotExists(path) {
13
9
  const stmt1 = db.prepare("SELECT * FROM featurespath WHERE path = ?");
@@ -93,4 +89,4 @@ function updateFeatures(feats) {
93
89
  upsertAndCleanFeatures(feats.action, "action");
94
90
  upsertAndCleanFeatures(feats.cmd, "cmd");
95
91
  }
96
- export { insertDefaultFilepaths, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, };
92
+ export { updatePromptfilePath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, };
@@ -31,9 +31,9 @@ interface Features {
31
31
  }>;
32
32
  }
33
33
  interface ConfigFile {
34
- promptfile: string;
35
- features: Array<string>;
36
- plugins: Array<string>;
34
+ promptfile?: string;
35
+ features?: Array<string>;
36
+ plugins?: Array<string>;
37
37
  }
38
38
  type CmdExecutor = (args: Array<string>, options: any) => Promise<any>;
39
39
  type InputMode = "manual" | "promptfile" | "clipboard";
@@ -1,7 +1,7 @@
1
1
  import { reactive, ref } from "@vue/reactivity";
2
2
  import { createConfDirIfNotExists, confDir } from "../conf.js";
3
3
  import { initDb } from "../db/db.js";
4
- import { readFeaturePaths } from "../db/read.js";
4
+ import { readFeaturePaths, readPromptFile } from "../db/read.js";
5
5
  import { updateAliases, updateFeatures } from "../db/write.js";
6
6
  import { readFeaturesDirs } from "./features.js";
7
7
  import { readPluginsPaths } from "./plugins.js";
@@ -31,6 +31,7 @@ async function initFeatures() {
31
31
  const feats = readFeaturesDirs(p);
32
32
  updateFeatures(feats);
33
33
  updateAliases(feats);
34
+ promptfile.value = readPromptFile();
34
35
  }
35
36
  async function initState() {
36
37
  initConf();
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.20",
5
+ "version": "0.0.22",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",
@@ -19,7 +19,6 @@
19
19
  "better-sqlite3": "^11.5.0",
20
20
  "clipboardy": "^4.0.0",
21
21
  "commander": "^12.1.0",
22
- "draftlog": "^1.0.13",
23
22
  "marked-terminal": "^7.2.1",
24
23
  "modprompt": "^0.9.1",
25
24
  "python-shell": "^5.0.0",