@agent-smith/cli 0.0.18 → 0.0.19

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,8 +1,7 @@
1
1
  import { LmTaskBuilder } from "@agent-smith/lmtask";
2
2
  import { marked } from 'marked';
3
- import { FeatureType, RunMode } from "./interfaces.js";
3
+ import { FeatureType } from "./interfaces.js";
4
4
  declare let brain: import("@agent-smith/brain").AgentBrain<Record<string, any>>;
5
- declare const modelsForExpert: Record<string, string>;
6
- declare const taskBuilder: LmTaskBuilder<FeatureType>;
7
- declare function initAgent(mode: RunMode, isVerbose?: boolean): Promise<boolean>;
8
- export { brain, initAgent, marked, modelsForExpert, taskBuilder };
5
+ declare const taskBuilder: LmTaskBuilder<FeatureType, Record<string, any>>;
6
+ declare function initAgent(isVerbose?: boolean): Promise<boolean>;
7
+ export { brain, initAgent, marked, taskBuilder };
package/dist/agent.js CHANGED
@@ -1,36 +1,40 @@
1
1
  import { useAgentBrain } from "@agent-smith/brain";
2
2
  import { LmTaskBuilder } from "@agent-smith/lmtask";
3
3
  import { marked } from 'marked';
4
- import { markedTerminal } from 'marked-terminal';
4
+ import { markedTerminal } from "marked-terminal";
5
5
  marked.use(markedTerminal());
6
6
  let brain = useAgentBrain();
7
- const modelsForExpert = {};
8
7
  const taskBuilder = new LmTaskBuilder(brain);
9
8
  async function initExperts() {
10
9
  brain.experts.forEach((ex) => {
11
- ex.backend.setOnStartEmit(() => console.log(""));
12
10
  ex.backend.setOnToken((t) => {
13
11
  process.stdout.write(t);
14
12
  });
15
13
  });
16
14
  }
17
- async function initAgent(mode, isVerbose = false) {
15
+ async function initAgent(isVerbose = false) {
18
16
  if (!brain.state.get().isOn) {
19
17
  brain.resetExperts();
20
- await brain.initLocal();
18
+ await brain.initLocal(true, isVerbose);
21
19
  await initExperts();
22
20
  }
23
21
  const brainUp = brain.state.get().isOn;
24
22
  if (isVerbose) {
25
23
  if (!brainUp) {
26
- console.log("❌ No experts found for inference");
24
+ console.log("❌ No backends found for inference");
27
25
  }
28
26
  else {
29
- brain.experts.forEach((ex) => {
30
- console.log(`✅ Expert ${ex.name} is up`);
27
+ brain.backends.forEach((b) => {
28
+ console.log(`✅ Backend ${b.name} is up`);
29
+ if (b.lm.providerType == "ollama") {
30
+ console.log(" Models:", b.lm.models.map(x => x.name));
31
+ }
32
+ else {
33
+ console.log(" Model:", b.lm.model.name);
34
+ }
31
35
  });
32
36
  }
33
37
  }
34
38
  return brainUp;
35
39
  }
36
- export { brain, initAgent, marked, modelsForExpert, taskBuilder };
40
+ export { brain, initAgent, marked, taskBuilder };
package/dist/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare function query(_default?: string): Promise<void>;
1
+ declare function query(sign?: string): Promise<void>;
2
2
  export { query };
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { input } from '@inquirer/prompts';
2
- import { runCmd } from './cmd/cmds.js';
3
- import { lastCmd, inputMode } from './state/state.js';
4
- import { readPromptFile } from './cmd/lib/utils.js';
5
- import { readClipboard } from './cmd/sys/clipboard.js';
2
+ import { chat, runCmd } from './cmd/cmds.js';
3
+ import { isChatMode } from './state/state.js';
4
+ import { setOptions } from './cmd/lib/utils.js';
5
+ import { modes } from './cmd/clicmds/modes.js';
6
6
  function parseParams(params) {
7
7
  const regex = /"([^"]*)"|(\S+)/g;
8
8
  let match;
@@ -18,27 +18,38 @@ function parseParams(params) {
18
18
  return result;
19
19
  }
20
20
  async function dispatch(input) {
21
- let buf = new Array();
22
- buf = parseParams(input);
23
- const cmd = buf.shift();
24
- if (inputMode.value == "promptfile") {
25
- const p = readPromptFile();
26
- buf.push(p);
27
- }
28
- else if (inputMode.value == "clipboard") {
29
- const p = await readClipboard();
30
- buf.push(p);
21
+ if (input.startsWith("-")) {
22
+ try {
23
+ const _cmd = modes[input].cmd;
24
+ await _cmd([], {});
25
+ return;
26
+ }
27
+ catch (e) {
28
+ throw new Error(`Option error ${e}`);
29
+ }
31
30
  }
32
- await runCmd(cmd, buf);
31
+ const buf = new Array();
32
+ let params = parseParams(input);
33
+ const cmd = params.shift();
34
+ const opts = {};
35
+ params.forEach((p) => {
36
+ if (p.startsWith("-")) {
37
+ opts[p.substring(1)] = true;
38
+ }
39
+ else {
40
+ buf.push(p);
41
+ }
42
+ });
43
+ const args = await setOptions(buf, opts);
44
+ await runCmd(cmd, args);
33
45
  }
34
- async function query(_default) {
35
- const data = { message: '>', default: "" };
36
- if (_default) {
37
- data.default = _default;
46
+ async function query(sign = "$") {
47
+ const data = { message: sign, default: "" };
48
+ const q = await input(data);
49
+ await dispatch(q);
50
+ if (isChatMode.value) {
51
+ await chat();
38
52
  }
39
- const answer = await input(data);
40
- await dispatch(answer);
41
- const lc = lastCmd.name + " " + lastCmd.args.join(" ");
42
- await query(lc);
53
+ await query(sign);
43
54
  }
44
55
  export { query };
@@ -1,4 +1,4 @@
1
- import { formatMode, runMode } from "../../state/state.js";
1
+ import { formatMode, isChatMode } from "../../state/state.js";
2
2
  import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
3
3
  import { readAliases, readFeatures } from "../../db/read.js";
4
4
  import { cleanupFeaturePaths, updateAliases, updateFeatures } from "../../db/write.js";
@@ -86,11 +86,7 @@ async function initCmds() {
86
86
  return cmds;
87
87
  }
88
88
  async function pingCmd(args = [], options) {
89
- let _isVerbose = false;
90
- if (args.length > 0) {
91
- _isVerbose = args[0] == "verbose";
92
- }
93
- const isUp = await initAgent(runMode.value, _isVerbose);
89
+ const isUp = await initAgent(true);
94
90
  return isUp;
95
91
  }
96
92
  async function _updateConfCmd(args = [], options) {
@@ -120,7 +116,7 @@ async function _executeTaskCmd(args = [], options) {
120
116
  console.warn("Provide a task name");
121
117
  return;
122
118
  }
123
- const { ok, data, error } = await executeTaskCmd(args, options);
119
+ const { ok, data, conf, error } = await executeTaskCmd(args, options);
124
120
  if (!ok) {
125
121
  console.warn(error);
126
122
  }
@@ -131,6 +127,8 @@ async function _executeTaskCmd(args = [], options) {
131
127
  else {
132
128
  console.log();
133
129
  }
130
+ if (isChatMode.value) {
131
+ }
134
132
  return data;
135
133
  }
136
134
  async function _executeJobCmd(args = [], options) {
@@ -156,8 +154,8 @@ async function _readTaskCmd(args = [], options) {
156
154
  if (!res.found) {
157
155
  throw new Error(`Task ${args[0]}, ${path} not found`);
158
156
  }
159
- const ts = taskBuilder.readFromYaml(path);
160
- console.log(ts);
157
+ const ts = taskBuilder.readFromYaml(res.ymlTask);
158
+ console.log(JSON.stringify(ts, null, " "));
161
159
  }
162
160
  async function _listTasksCmd(args = [], options) {
163
161
  Object.keys(readFeatures().task).forEach((t) => console.log("-", t));
@@ -1,11 +1,23 @@
1
- import { formatMode, inputMode, isDebug, outputMode, runMode } from "../../state/state.js";
1
+ import { formatMode, inputMode, isChatMode, isDebug, outputMode, runMode } from "../../state/state.js";
2
2
  const modes = {
3
3
  "-d": {
4
4
  cmd: async () => {
5
5
  isDebug.value = true;
6
+ if (runMode.value == "cli") {
7
+ console.log("Debug mode is on");
8
+ }
6
9
  },
7
10
  description: "use debug mode",
8
11
  },
12
+ "-c": {
13
+ cmd: async () => {
14
+ isChatMode.value = true;
15
+ if (runMode.value == "cli") {
16
+ console.log("Chat mode is on");
17
+ }
18
+ },
19
+ description: "use chat mode for tasks",
20
+ },
9
21
  "-if": {
10
22
  cmd: async () => {
11
23
  inputMode.value = "promptfile";
@@ -1,6 +1,7 @@
1
1
  import { Command } from "commander";
2
+ declare function chat(): Promise<void>;
2
3
  declare function initCliCmds(): Promise<void>;
3
4
  declare function runCmd(cmdName: string, args?: Array<string>): Promise<void>;
4
5
  declare function buildCmds(): Promise<Command>;
5
6
  declare function parseCmd(): Promise<void>;
6
- export { runCmd, buildCmds, parseCmd, initCliCmds };
7
+ export { buildCmds, initCliCmds, parseCmd, runCmd, chat };
package/dist/cmd/cmds.js CHANGED
@@ -1,11 +1,32 @@
1
+ import { input } from "@inquirer/prompts";
1
2
  import { Command } from "commander";
2
- import { lastCmd } from "../state/state.js";
3
+ import { brain } from "../agent.js";
4
+ import { isChatMode, lastCmd, runMode } from "../state/state.js";
5
+ import { cmds, initAliases, initCmds } from "./clicmds/cmds.js";
3
6
  import { modes } from "./clicmds/modes.js";
4
7
  import { processOutput, setOptions } from "./lib/utils.js";
5
- import { cmds, initAliases, initCmds } from "./clicmds/cmds.js";
8
+ import { query } from "../cli.js";
6
9
  let cliCmds = {};
10
+ async function chat() {
11
+ const data = { message: '>', default: "" };
12
+ const prompt = await input(data);
13
+ if (prompt == "/q") {
14
+ isChatMode.value = false;
15
+ if (runMode.value == "cmd") {
16
+ process.exit(0);
17
+ }
18
+ else {
19
+ await query();
20
+ }
21
+ }
22
+ await brain.ex.think(prompt);
23
+ console.log();
24
+ await chat();
25
+ }
7
26
  async function initCliCmds() {
8
- cliCmds = await initCmds();
27
+ const _cmds = await initCmds();
28
+ const _alias = initAliases();
29
+ cliCmds = { ..._cmds, ..._alias };
9
30
  }
10
31
  async function runCmd(cmdName, args = []) {
11
32
  if (!(cmdName in cliCmds)) {
@@ -23,7 +44,7 @@ async function buildCmds() {
23
44
  for (const [name, spec] of Object.entries({ ...cmds, ...aliases })) {
24
45
  const cmd = program.command(name);
25
46
  const _cmd = async (args = [], options = {}) => {
26
- const _args = await setOptions(options, args);
47
+ const _args = await setOptions(args, options);
27
48
  const res = await spec.cmd(_args, options);
28
49
  await processOutput(res);
29
50
  return res;
@@ -49,5 +70,9 @@ async function buildCmds() {
49
70
  async function parseCmd() {
50
71
  const program = await buildCmds();
51
72
  await program.parseAsync();
73
+ if (isChatMode.value) {
74
+ await chat();
75
+ }
52
76
  }
53
- export { runCmd, buildCmds, parseCmd, initCliCmds };
77
+ export { buildCmds, initCliCmds, parseCmd, runCmd, chat };
78
+ ;
@@ -4,6 +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
8
  function _systemAction(path) {
8
9
  const action = useAgentTask({
9
10
  id: "system_action",
@@ -47,12 +48,12 @@ async function executeActionCmd(args = [], options = {}, quiet = false) {
47
48
  break;
48
49
  default:
49
50
  throw new Error(`Action ext ${ext} not implemented`);
50
- break;
51
51
  }
52
52
  const res = await act.run(args, options);
53
53
  if (!quiet) {
54
54
  console.log(res.data);
55
55
  }
56
+ await processOutput(res);
56
57
  return { ok: true, data: res.data, error: "" };
57
58
  }
58
59
  export { executeActionCmd };
@@ -1,10 +1,10 @@
1
1
  import { brain, initAgent, taskBuilder } from "../../agent.js";
2
2
  import { getFeatureSpec } from "../../state/features.js";
3
- import { inputMode, isDebug, runMode } from "../../state/state.js";
3
+ import { inputMode, isChatMode, isDebug } from "../../state/state.js";
4
4
  import { initTaskVars, readPromptFile, readTask } from "./utils.js";
5
5
  import { readClipboard } from "../sys/clipboard.js";
6
6
  async function executeTaskCmd(args = [], options = {}) {
7
- await initAgent(runMode.value);
7
+ await initAgent();
8
8
  if (isDebug.value) {
9
9
  console.log("Task args:", args);
10
10
  console.log("Task options:", options);
@@ -26,7 +26,7 @@ async function executeTaskCmd(args = [], options = {}) {
26
26
  }
27
27
  const { found, path } = getFeatureSpec(name, "task");
28
28
  if (!found) {
29
- return { ok: false, data: {}, error: `Task ${name} not found` };
29
+ return { ok: false, data: "", conf: {}, error: `Task ${name} not found` };
30
30
  }
31
31
  const res = readTask(path);
32
32
  if (!res.found) {
@@ -64,8 +64,15 @@ async function executeTaskCmd(args = [], options = {}) {
64
64
  }
65
65
  const data = await task.run({ prompt: pr, ...vars }, conf);
66
66
  if (data?.error) {
67
- return { ok: false, data: {}, error: `Error executing task: ${data.error}` };
67
+ return { ok: false, data: "", conf: conf, error: `Error executing task: ${data.error}` };
68
68
  }
69
- return { ok: true, data: data.text, error: "" };
69
+ conf.prompt = pr;
70
+ if (isChatMode.value) {
71
+ if (brain.ex.name != ex.name) {
72
+ brain.setDefaultExpert(ex);
73
+ }
74
+ brain.ex.template.pushToHistory({ user: pr, assistant: data.text });
75
+ }
76
+ return { ok: true, data: data.text, conf: conf, error: "" };
70
77
  }
71
78
  export { executeTaskCmd };
@@ -1,4 +1,4 @@
1
- declare function setOptions(options: Record<string, any>, args?: Array<string>): Promise<Array<string>>;
1
+ declare function setOptions(args: Array<string> | undefined, options: Record<string, any>): Promise<Array<string>>;
2
2
  declare function readPromptFile(): string;
3
3
  declare function processOutput(res: any): Promise<void>;
4
4
  declare function readTask(taskpath: string): {
@@ -1,14 +1,10 @@
1
1
  import { default as fs } from "fs";
2
2
  import { default as path } from "path";
3
3
  import { outputMode, promptfile } from "../../state/state.js";
4
- import { inputMode, runMode } from "../../state/state.js";
4
+ import { inputMode } from "../../state/state.js";
5
5
  import { readClipboard, writeToClipboard } from "../sys/clipboard.js";
6
6
  import { modes } from "../clicmds/modes.js";
7
- async function setOptions(options, args = []) {
8
- if (runMode.value == "cli") {
9
- return args;
10
- }
11
- ;
7
+ async function setOptions(args = [], options) {
12
8
  for (const k of Object.keys(options)) {
13
9
  const opt = modes["-" + k.toLowerCase()];
14
10
  await opt.cmd([], undefined);
@@ -28,6 +24,9 @@ function readPromptFile() {
28
24
  return res;
29
25
  }
30
26
  async function processOutput(res) {
27
+ if (!(outputMode.value == "clipboard")) {
28
+ return;
29
+ }
31
30
  let data = "";
32
31
  if (typeof res == "object") {
33
32
  let hasOutput = false;
package/dist/index.js CHANGED
@@ -9,10 +9,10 @@ async function main() {
9
9
  runMode.value = "cli";
10
10
  }
11
11
  await initState();
12
- await initCliCmds();
13
- await initAgent(runMode.value);
12
+ await initAgent();
14
13
  switch (runMode.value) {
15
14
  case "cli":
15
+ await initCliCmds();
16
16
  await query();
17
17
  break;
18
18
  default:
@@ -5,6 +5,7 @@ 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
+ declare const isChatMode: import("@vue/reactivity").Ref<boolean, boolean>;
8
9
  declare const isDebug: import("@vue/reactivity").Ref<boolean, boolean>;
9
10
  declare const promptfile: import("@vue/reactivity").Ref<string, string>;
10
11
  declare const lastCmd: {
@@ -13,4 +14,4 @@ declare const lastCmd: {
13
14
  };
14
15
  declare function initFeatures(): Promise<void>;
15
16
  declare function initState(): Promise<void>;
16
- export { inputMode, outputMode, runMode, formatMode, lastCmd, isDebug, promptfile, initState, initFeatures, pyShell, };
17
+ export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, isDebug, promptfile, initState, initFeatures, pyShell, };
@@ -10,6 +10,7 @@ const inputMode = ref("manual");
10
10
  const outputMode = ref("txt");
11
11
  const runMode = ref("cmd");
12
12
  const formatMode = ref("text");
13
+ const isChatMode = ref(false);
13
14
  const isDebug = ref(false);
14
15
  const promptfile = ref("");
15
16
  const lastCmd = reactive({
@@ -35,4 +36,4 @@ async function initState() {
35
36
  initConf();
36
37
  await initFeatures();
37
38
  }
38
- export { inputMode, outputMode, runMode, formatMode, lastCmd, isDebug, promptfile, initState, initFeatures, pyShell, };
39
+ export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, isDebug, promptfile, initState, initFeatures, pyShell, };
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.18",
5
+ "version": "0.0.19",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",
@@ -10,18 +10,18 @@
10
10
  "watch": "tsc -p . -w"
11
11
  },
12
12
  "dependencies": {
13
- "@agent-smith/brain": "^0.0.32",
13
+ "@agent-smith/brain": "^0.0.33",
14
14
  "@agent-smith/jobs": "^0.0.11",
15
- "@agent-smith/lmtask": "^0.0.23",
16
- "@inquirer/prompts": "^7.0.0",
17
- "@inquirer/select": "^4.0.0",
15
+ "@agent-smith/lmtask": "^0.0.24",
16
+ "@inquirer/prompts": "^7.0.1",
17
+ "@inquirer/select": "^4.0.1",
18
18
  "@vue/reactivity": "^3.5.12",
19
19
  "better-sqlite3": "^11.5.0",
20
20
  "clipboardy": "^4.0.0",
21
21
  "commander": "^12.1.0",
22
22
  "draftlog": "^1.0.13",
23
- "marked-terminal": "^7.1.0",
24
- "modprompt": "^0.9.0",
23
+ "marked-terminal": "^7.2.1",
24
+ "modprompt": "^0.9.1",
25
25
  "python-shell": "^5.0.0",
26
26
  "yaml": "^2.6.0"
27
27
  },
@@ -33,9 +33,9 @@
33
33
  "@rollup/plugin-typescript": "^12.1.1",
34
34
  "@types/better-sqlite3": "^7.6.11",
35
35
  "@types/marked-terminal": "^6.1.1",
36
- "@types/node": "^22.7.9",
36
+ "@types/node": "^22.8.5",
37
37
  "restmix": "^0.5.0",
38
- "rollup": "^4.24.0",
38
+ "rollup": "^4.24.3",
39
39
  "ts-node": "^10.9.2",
40
40
  "tslib": "2.8.0",
41
41
  "typescript": "^5.6.3"