@agent-smith/cli 0.0.4 → 0.0.6

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.
package/dist/agent.d.ts CHANGED
@@ -1,15 +1,8 @@
1
+ import { LmTaskBuilder } from "@agent-smith/lmtask";
1
2
  import { marked } from 'marked';
2
3
  import { RunMode } from "./interfaces.js";
3
4
  declare let brain: import("@agent-smith/brain").AgentBrain;
4
5
  declare const modelsForExpert: Record<string, string>;
5
- declare const taskReader: {
6
- init: (taskPath: string) => import("@agent-smith/jobs").AgentTask;
7
- read: (taskPath: string) => {
8
- found: boolean;
9
- task: import("@agent-smith/lmtask").LmTask;
10
- };
11
- readDir: (dir: string) => Array<string>;
12
- };
13
- declare function clearOutput(): void;
6
+ declare const taskBuilder: LmTaskBuilder;
14
7
  declare function initAgent(mode: RunMode, isVerbose?: boolean): Promise<boolean>;
15
- export { brain, initAgent, clearOutput, marked, modelsForExpert, taskReader };
8
+ export { brain, initAgent, marked, modelsForExpert, taskBuilder };
package/dist/agent.js CHANGED
@@ -1,29 +1,20 @@
1
1
  import { useAgentBrain } from "@agent-smith/brain";
2
- import { useLmTask } from "@agent-smith/lmtask";
3
- import logUpdate from 'log-update';
2
+ import { LmTaskBuilder } from "@agent-smith/lmtask";
3
+ ;
4
4
  import { marked } from 'marked';
5
5
  import { markedTerminal } from 'marked-terminal';
6
- import { formatMode } from "./state/state.js";
7
6
  marked.use(markedTerminal());
8
7
  let brain = useAgentBrain();
9
8
  const modelsForExpert = {};
10
- const taskReader = useLmTask(brain);
9
+ const taskBuilder = new LmTaskBuilder(brain);
11
10
  async function initExperts() {
12
11
  brain.experts.forEach((ex) => {
13
12
  ex.setOnStartEmit(() => console.log(""));
14
13
  ex.setOnToken((t) => {
15
- if (formatMode.value == "markdown") {
16
- logUpdate(marked.parse(ex.stream.get() + t).trim());
17
- }
18
- else {
19
- logUpdate((ex.stream.get() + t).trim());
20
- }
14
+ process.stdout.write(t);
21
15
  });
22
16
  });
23
17
  }
24
- function clearOutput() {
25
- logUpdate.clear();
26
- }
27
18
  async function initAgent(mode, isVerbose = false) {
28
19
  if (!brain.state.get().isOn) {
29
20
  brain.resetExperts();
@@ -44,4 +35,4 @@ async function initAgent(mode, isVerbose = false) {
44
35
  }
45
36
  return brainUp;
46
37
  }
47
- export { brain, initAgent, clearOutput, marked, modelsForExpert, taskReader };
38
+ export { brain, initAgent, marked, modelsForExpert, taskBuilder };
@@ -4,10 +4,11 @@ import { readFeatures } from "../../db/read.js";
4
4
  import { updateFeatures } from "../../db/write.js";
5
5
  import { updateConf } from "../../conf.js";
6
6
  import { executeActionCmd } from "../lib/execute_action.js";
7
- import { clearOutput, initAgent, marked, taskReader } from "../../agent.js";
7
+ import { initAgent, marked, taskBuilder } from "../../agent.js";
8
8
  import { executeJobCmd, readJob } from "../lib/execute_job.js";
9
9
  import { executeTaskCmd } from "../lib/execute_task.js";
10
10
  import { readCmds } from "../sys/read_cmds.js";
11
+ import { readTask } from "../lib/utils.js";
11
12
  let cmds = {
12
13
  q: {
13
14
  cmd: async () => process.exit(0),
@@ -101,12 +102,12 @@ async function _executeTaskCmd(args = [], options) {
101
102
  if (!ok) {
102
103
  console.warn(error);
103
104
  }
104
- clearOutput();
105
105
  if (formatMode.value == "markdown") {
106
+ console.log("\n\n------------------\n");
106
107
  console.log(marked.parse(data).trim());
107
108
  }
108
109
  else {
109
- console.log(data);
110
+ console.log();
110
111
  }
111
112
  return data;
112
113
  }
@@ -129,8 +130,12 @@ async function _readTaskCmd(args = [], options) {
129
130
  console.warn(`FeatureType ${args[0]} not found`);
130
131
  return;
131
132
  }
132
- const r = taskReader.read(path);
133
- console.log(r.task);
133
+ const res = readTask(path);
134
+ if (!res.found) {
135
+ throw new Error(`Task ${args[0]}, ${path} not found`);
136
+ }
137
+ const ts = taskBuilder.readFromYaml(path);
138
+ console.log(ts);
134
139
  }
135
140
  async function _listTasksCmd(args = [], options) {
136
141
  Object.keys(readFeatures().task).forEach((t) => console.log("-", t));
@@ -43,13 +43,13 @@ const modes = {
43
43
  console.log("Markdown output mode");
44
44
  }
45
45
  },
46
- description: "use markdown output (default)"
46
+ description: "use markdown output"
47
47
  },
48
48
  "-otxt": {
49
49
  cmd: async () => {
50
50
  formatMode.value = "text";
51
51
  if (runMode.value == "cli") {
52
- console.log("Text output mode");
52
+ console.log("Text output mode (default)");
53
53
  }
54
54
  },
55
55
  description: "use text output "
@@ -1,8 +1,10 @@
1
1
  import YAML from 'yaml';
2
2
  import { default as fs } from "fs";
3
3
  import { useAgentJob } from "@agent-smith/jobs";
4
- import { brain, taskReader } from '../../agent.js';
4
+ import { brain, marked, taskBuilder } from '../../agent.js';
5
5
  import { getFeatureSpec } from '../../state/features.js';
6
+ import { formatMode } from '../../state/state.js';
7
+ import { readTask } from './utils.js';
6
8
  async function executeJobCmd(name, args = []) {
7
9
  const { job, found } = await _dispatchReadJob(name);
8
10
  if (!found) {
@@ -16,6 +18,12 @@ async function executeJobCmd(name, args = []) {
16
18
  brain.expertsForModelsInfo();
17
19
  try {
18
20
  res = await job.runTask(name, params);
21
+ if ("text" in res) {
22
+ if (formatMode.value == "markdown") {
23
+ console.log("\n\n------------------\n");
24
+ console.log(marked.parse(res.text).trim());
25
+ }
26
+ }
19
27
  }
20
28
  catch (err) {
21
29
  console.log("ERR", err);
@@ -69,7 +77,11 @@ async function _createJobFromSpec(spec) {
69
77
  if (!found) {
70
78
  return { found: false, job: {} };
71
79
  }
72
- const at = taskReader.init(path);
80
+ const res = readTask(path);
81
+ if (!res.found) {
82
+ throw new Error(`Task ${t.name}, ${path} not found`);
83
+ }
84
+ const at = taskBuilder.fromYaml(res.ymlTask);
73
85
  tasks[t.name] = at;
74
86
  }
75
87
  }
@@ -1,7 +1,7 @@
1
- import { initAgent, taskReader } from "../../agent.js";
2
- import logUpdate from "log-update";
1
+ import { initAgent, taskBuilder } from "../../agent.js";
3
2
  import { getFeatureSpec } from "../../state/features.js";
4
3
  import { runMode } from "../../state/state.js";
4
+ import { readTask } from "./utils.js";
5
5
  async function executeTaskCmd(args = [], options = {}) {
6
6
  await initAgent(runMode.value);
7
7
  const name = args.shift();
@@ -9,7 +9,11 @@ async function executeTaskCmd(args = [], options = {}) {
9
9
  if (!found) {
10
10
  return { ok: false, data: {}, error: `Task ${name} not found` };
11
11
  }
12
- const task = taskReader.init(path);
12
+ const res = readTask(path);
13
+ if (!res.found) {
14
+ throw new Error(`Task ${name}, ${path} not found`);
15
+ }
16
+ const task = taskBuilder.fromYaml(res.ymlTask);
13
17
  const pr = args.shift();
14
18
  const vars = {};
15
19
  args.forEach((a) => {
@@ -18,7 +22,7 @@ async function executeTaskCmd(args = [], options = {}) {
18
22
  vars[t[0]] = t[1];
19
23
  }
20
24
  });
21
- logUpdate("Ingesting prompt ...");
25
+ console.log("Ingesting prompt ...");
22
26
  const data = await task.run({ prompt: pr, ...vars });
23
27
  if (data?.error) {
24
28
  return { ok: false, data: {}, error: `Error executing task: ${data.error}` };
@@ -1,4 +1,9 @@
1
1
  declare function setOptions(options: Record<string, any>, args?: Array<string>): Promise<Array<string>>;
2
2
  declare function readPromptFile(): string;
3
3
  declare function processOutput(res: any): Promise<void>;
4
- export { readPromptFile, processOutput, setOptions, };
4
+ declare function readTask(taskpath: string): {
5
+ found: boolean;
6
+ ymlTask: string;
7
+ };
8
+ declare function readTasksDir(dir: string): Array<string>;
9
+ export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, };
@@ -1,4 +1,5 @@
1
1
  import { default as fs } from "fs";
2
+ import { default as path } from "path";
2
3
  import { outputMode, promptfile } from "../../state/state.js";
3
4
  import { inputMode, runMode } from "../../state/state.js";
4
5
  import { readClipboard, writeToClipboard } from "../sys/clipboard.js";
@@ -39,7 +40,7 @@ async function processOutput(res) {
39
40
  hasOutput = true;
40
41
  }
41
42
  if (!hasOutput) {
42
- throw new Error(`No data in res: ${res}`);
43
+ throw new Error(`No data in res: ${JSON.stringify(res, null, " ")}`);
43
44
  }
44
45
  }
45
46
  else {
@@ -49,4 +50,24 @@ async function processOutput(res) {
49
50
  await writeToClipboard(data);
50
51
  }
51
52
  }
52
- export { readPromptFile, processOutput, setOptions, };
53
+ function readTask(taskpath) {
54
+ if (!fs.existsSync(taskpath)) {
55
+ return { ymlTask: "", found: false };
56
+ }
57
+ const data = fs.readFileSync(taskpath, 'utf8');
58
+ return { ymlTask: data, found: true };
59
+ }
60
+ function readTasksDir(dir) {
61
+ const tasks = new Array();
62
+ fs.readdirSync(dir).forEach((filename) => {
63
+ const filepath = path.join(dir, filename);
64
+ const isDir = fs.statSync(filepath).isDirectory();
65
+ if (!isDir) {
66
+ if (filename.endsWith(".yml")) {
67
+ tasks.push(filename);
68
+ }
69
+ }
70
+ });
71
+ return tasks;
72
+ }
73
+ export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, };
package/dist/index.js CHANGED
File without changes
@@ -9,7 +9,7 @@ let pyShell;
9
9
  const inputMode = ref("manual");
10
10
  const outputMode = ref("txt");
11
11
  const runMode = ref("cmd");
12
- const formatMode = ref("markdown");
12
+ const formatMode = ref("text");
13
13
  const promptfile = ref("");
14
14
  const lastCmd = reactive({
15
15
  name: "",
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.4",
5
+ "version": "0.0.6",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",
@@ -12,14 +12,14 @@
12
12
  "dependencies": {
13
13
  "@agent-smith/brain": "^0.0.18",
14
14
  "@agent-smith/jobs": "^0.0.8",
15
- "@agent-smith/lmtask": "^0.0.12",
15
+ "@agent-smith/lmtask": "^0.0.13",
16
16
  "@inquirer/prompts": "^5.3.8",
17
17
  "@inquirer/select": "^2.4.7",
18
18
  "@vue/reactivity": "^3.4.38",
19
19
  "better-sqlite3": "^11.2.1",
20
20
  "clipboardy": "^4.0.0",
21
21
  "commander": "^12.1.0",
22
- "log-update": "^6.1.0",
22
+ "draftlog": "^1.0.13",
23
23
  "marked-terminal": "^7.1.0",
24
24
  "modprompt": "^0.7.7",
25
25
  "python-shell": "^5.0.0",
@@ -33,8 +33,8 @@
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.1",
37
- "rollup": "^4.21.1",
36
+ "@types/node": "^22.5.2",
37
+ "rollup": "^4.21.2",
38
38
  "ts-node": "^10.9.2",
39
39
  "tslib": "2.7.0",
40
40
  "typescript": "^5.5.4"