@agent-smith/cli 0.0.116 → 0.0.119

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 (114) hide show
  1. package/README.md +277 -34
  2. package/dist/cli.js +4 -8
  3. package/dist/cmd/{clicmds/aliases.d.ts → aliases.d.ts} +1 -1
  4. package/dist/cmd/{clicmds/aliases.js → aliases.js} +1 -26
  5. package/dist/cmd/{clicmds/base.js → base.js} +21 -17
  6. package/dist/cmd/build.d.ts +9 -0
  7. package/dist/cmd/build.js +64 -0
  8. package/dist/cmd/callbacks.d.ts +11 -0
  9. package/dist/cmd/callbacks.js +90 -0
  10. package/dist/cmd/cmds.d.ts +8 -9
  11. package/dist/cmd/cmds.js +134 -103
  12. package/dist/cmd/features.d.ts +5 -0
  13. package/dist/cmd/features.js +55 -0
  14. package/dist/cmd/{sys/read_cmds.d.ts → read_cmds.d.ts} +1 -1
  15. package/dist/cmd/{sys/read_cmds.js → read_cmds.js} +1 -1
  16. package/dist/cmd/user_cmds.d.ts +3 -0
  17. package/dist/cmd/user_cmds.js +23 -0
  18. package/dist/index.js +11 -11
  19. package/dist/main.d.ts +3 -38
  20. package/dist/main.js +3 -37
  21. package/dist/state.d.ts +6 -0
  22. package/dist/state.js +8 -0
  23. package/dist/utils.d.ts +8 -0
  24. package/dist/utils.js +50 -0
  25. package/package.json +14 -24
  26. package/dist/cmd/clicmds/cmds.d.ts +0 -7
  27. package/dist/cmd/clicmds/cmds.js +0 -135
  28. package/dist/cmd/clicmds/updateconf.d.ts +0 -3
  29. package/dist/cmd/clicmds/updateconf.js +0 -74
  30. package/dist/cmd/lib/actions/cmd.d.ts +0 -6
  31. package/dist/cmd/lib/actions/cmd.js +0 -154
  32. package/dist/cmd/lib/actions/read.d.ts +0 -3
  33. package/dist/cmd/lib/actions/read.js +0 -17
  34. package/dist/cmd/lib/adaptaters/cmd.d.ts +0 -2
  35. package/dist/cmd/lib/adaptaters/cmd.js +0 -39
  36. package/dist/cmd/lib/agents/cmd.d.ts +0 -3
  37. package/dist/cmd/lib/agents/cmd.js +0 -11
  38. package/dist/cmd/lib/mcp.d.ts +0 -16
  39. package/dist/cmd/lib/mcp.js +0 -108
  40. package/dist/cmd/lib/options_parsers.d.ts +0 -7
  41. package/dist/cmd/lib/options_parsers.js +0 -52
  42. package/dist/cmd/lib/tasks/cmd.d.ts +0 -4
  43. package/dist/cmd/lib/tasks/cmd.js +0 -419
  44. package/dist/cmd/lib/tasks/conf.d.ts +0 -6
  45. package/dist/cmd/lib/tasks/conf.js +0 -131
  46. package/dist/cmd/lib/tasks/read.d.ts +0 -14
  47. package/dist/cmd/lib/tasks/read.js +0 -186
  48. package/dist/cmd/lib/tasks/utils.d.ts +0 -8
  49. package/dist/cmd/lib/tasks/utils.js +0 -48
  50. package/dist/cmd/lib/tools.d.ts +0 -15
  51. package/dist/cmd/lib/tools.js +0 -147
  52. package/dist/cmd/lib/utils.d.ts +0 -3
  53. package/dist/cmd/lib/utils.js +0 -54
  54. package/dist/cmd/lib/workflows/cmd.d.ts +0 -3
  55. package/dist/cmd/lib/workflows/cmd.js +0 -230
  56. package/dist/cmd/lib/workflows/read.d.ts +0 -6
  57. package/dist/cmd/lib/workflows/read.js +0 -61
  58. package/dist/cmd/sys/clipboard.d.ts +0 -3
  59. package/dist/cmd/sys/clipboard.js +0 -33
  60. package/dist/cmd/sys/delete_file.d.ts +0 -2
  61. package/dist/cmd/sys/delete_file.js +0 -10
  62. package/dist/cmd/sys/dirs.d.ts +0 -2
  63. package/dist/cmd/sys/dirs.js +0 -9
  64. package/dist/cmd/sys/execute.d.ts +0 -13
  65. package/dist/cmd/sys/execute.js +0 -48
  66. package/dist/cmd/sys/read.d.ts +0 -3
  67. package/dist/cmd/sys/read.js +0 -21
  68. package/dist/cmd/sys/read_conf.d.ts +0 -6
  69. package/dist/cmd/sys/read_conf.js +0 -12
  70. package/dist/cmd/sys/read_features.d.ts +0 -3
  71. package/dist/cmd/sys/read_features.js +0 -112
  72. package/dist/cmd/sys/read_task.d.ts +0 -6
  73. package/dist/cmd/sys/read_task.js +0 -23
  74. package/dist/cmd/sys/read_yml_file.d.ts +0 -5
  75. package/dist/cmd/sys/read_yml_file.js +0 -11
  76. package/dist/cmd/sys/run_python.d.ts +0 -6
  77. package/dist/cmd/sys/run_python.js +0 -39
  78. package/dist/conf.d.ts +0 -14
  79. package/dist/conf.js +0 -166
  80. package/dist/const.d.ts +0 -3
  81. package/dist/const.js +0 -24
  82. package/dist/db/db.d.ts +0 -4
  83. package/dist/db/db.js +0 -23
  84. package/dist/db/read.d.ts +0 -34
  85. package/dist/db/read.js +0 -128
  86. package/dist/db/schemas.d.ts +0 -2
  87. package/dist/db/schemas.js +0 -105
  88. package/dist/db/write.d.ts +0 -15
  89. package/dist/db/write.js +0 -376
  90. package/dist/interfaces.d.ts +0 -165
  91. package/dist/interfaces.js +0 -1
  92. package/dist/state/backends.d.ts +0 -7
  93. package/dist/state/backends.js +0 -159
  94. package/dist/state/chat.d.ts +0 -7
  95. package/dist/state/chat.js +0 -10
  96. package/dist/state/features.d.ts +0 -8
  97. package/dist/state/features.js +0 -35
  98. package/dist/state/plugins.d.ts +0 -6
  99. package/dist/state/plugins.js +0 -27
  100. package/dist/state/state.d.ts +0 -20
  101. package/dist/state/state.js +0 -80
  102. package/dist/state/tasks.d.ts +0 -6
  103. package/dist/state/tasks.js +0 -28
  104. package/dist/utils/perf.d.ts +0 -9
  105. package/dist/utils/perf.js +0 -63
  106. package/dist/utils/text.d.ts +0 -6
  107. package/dist/utils/text.js +0 -41
  108. package/dist/utils/user_msgs.d.ts +0 -5
  109. package/dist/utils/user_msgs.js +0 -19
  110. /package/dist/cmd/{clicmds/base.d.ts → base.d.ts} +0 -0
  111. /package/dist/{cmd/options.d.ts → options.d.ts} +0 -0
  112. /package/dist/{cmd/options.js → options.js} +0 -0
  113. /package/dist/{cmd/lib/user_msgs.d.ts → user_msgs.d.ts} +0 -0
  114. /package/dist/{cmd/lib/user_msgs.js → user_msgs.js} +0 -0
package/README.md CHANGED
@@ -1,82 +1,325 @@
1
- # Agent Smith terminal client
1
+ [![npm version](https://img.shields.io/npm/v/@agent-smith/cli)](https://www.npmjs.com/package/@agent-smith/cli)
2
2
 
3
- A terminal client to use language models
3
+ # @agent-smith/cli Terminal REPL for Agent Smith
4
4
 
5
- :books: Read the [documentation](https://synw.github.io/agent-smith/terminal_client/install)
5
+ A command-line interface built with Commander.js for interacting with AI agents, executing workflows and actions, managing configuration, and running inference. Part of the [Agent Smith toolkit](https://github.com/lynxai-team/agent-smith).
6
6
 
7
- ## Install
7
+ ## Features
8
8
 
9
- Install the Agent Smith terminal client globally:
9
+ - 🚀 **Interactive REPL** Chat mode for conversational agent interaction
10
+ - ⚡ **One-shot Commands** — Run agents, workflows, and actions from the terminal
11
+ - 🔧 **Dynamic Commands** — Auto-generated commands from database features (agents, actions, workflows, aliases)
12
+ - 🎛️ **Configuration Management** — YAML-based config with SQLite backend for backends, plugins, and feature paths
13
+ - 🌐 **Multi-Backend Support** — Llama.cpp, Koboldcpp, Ollama, OpenRouter, and any OpenAI-compatible API
14
+ - 📋 **I/O Flexibility** — Clipboard input/output, file input, markdown output modes
15
+ - 🔍 **Inference Control** — Fine-grained control over model parameters (temperature, top_k, top_p, min_p, etc.)
16
+ - 🔄 **Hot-Reloadable Features** — Add agents and tools without restarting the CLI
17
+
18
+ ## Documentation
19
+
20
+ ### For AI Agents
21
+
22
+ - [Codebase Summary](.agents/documentation/codebase-summary.md) — Architecture, key files, and patterns for the CLI package
23
+ - [Overview](https://raw.githubusercontent.com/lynxai-team/agent-smith/refs/heads/main/docsite/public/doc/terminal_client/2.overview.md) — Terminal client principles and feature types
24
+ - [Install](https://raw.githubusercontent.com/lynxai-team/agent-smith/refs/heads/main/docsite/public/doc/terminal_client/1.install.md) — Installation and quickstart
25
+ - [Config](https://raw.githubusercontent.com/lynxai-team/agent-smith/refs/heads/main/docsite/public/doc/terminal_client/3.config.md) — Configuration file format and backend setup
26
+ - [Agents](https://raw.githubusercontent.com/lynxai-team/agent-smith/refs/heads/main/docsite/public/doc/terminal_client/agents/1.overview.md) — Agent YAML definitions and tool calling
27
+ - [Tasks](https://raw.githubusercontent.com/lynxai-team/agent-smith/refs/heads/main/docsite/public/doc/terminal_client/4.tasks.md) — Running agents with variables and parameters
28
+ - [Actions](https://raw.githubusercontent.com/lynxai-team/agent-smith/refs/heads/main/docsite/public/doc/terminal_client/6.actions.md) — Custom tool scripts (JS, Python, YAML)
29
+ - [Workflows](https://raw.githubusercontent.com/lynxai-team/agent-smith/refs/heads/main/docsite/public/doc/terminal_client/7.workflows.md) — Chaining actions and agents in pipelines
30
+ - [Commands](https://raw.githubusercontent.com/lynxai-team/agent-smith/refs/heads/main/docsite/public/doc/terminal_client/8.commands.md) — Custom terminal commands
31
+
32
+ ### For Humans
33
+
34
+ - [Quickstart Guide](https://lynxai-team.github.io/agent-smith/terminal_client/quickstart) — Get up and running in minutes
35
+ - [Terminal Client Overview](https://lynxai-team.github.io/agent-smith/terminal_client/overview) — Principles and feature types
36
+ - [Installation](https://lynxai-team.github.io/agent-smith/terminal_client/install) — Install and initial configuration
37
+ - [Configuration](https://lynxai-team.github.io/agent-smith/terminal_client/config) — Config file format, backends, and plugins
38
+ - [Agent Definitions](https://lynxai-team.github.io/agent-smith/terminal_client/agents/overview) — Declaring agents with YAML
39
+ - [Tasks & Variables](https://lynxai-team.github.io/agent-smith/terminal_client/tasks) — Parameterized agent execution
40
+ - [Actions](https://lynxai-team.github.io/agent-smith/terminal_client/actions) — Writing custom tools
41
+ - [Workflows](https://lynxai-team.github.io/agent-smith/terminal_client/workflows) — Building multi-step pipelines
42
+
43
+ ## Installation
10
44
 
11
45
  ```bash
12
46
  npm i -g @agent-smith/cli
13
47
  ```
14
48
 
15
- A global `lm` command is available once installed.
49
+ This installs the `lm` command globally.
50
+
51
+ ## Quick Start
52
+
53
+ ### 1. Initialize a config file
54
+
55
+ Run `lm conf` to initialize. A basic config file will be created (`~/.config/agent-smith/config.yml` on Linux):
56
+
57
+ ```yaml
58
+ backends:
59
+ default: llamacpp
60
+ llamacpp:
61
+ url: http://localhost:8080/v1
62
+ ```
63
+
64
+ ### 2. Configure your backend
65
+
66
+ Customize your config:
67
+
68
+ ```yaml
69
+ backends:
70
+ default: "llamacpp"
71
+ llamacpp:
72
+ url: "http://localhost:8080/v1"
73
+ openrouter:
74
+ type: "openai"
75
+ url: "https://openrouter.ai/api/v1"
76
+ apiKey: "$OPENROUTER_API_KEY" # env variable
77
+ ```
78
+
79
+ Run `lm conf` again to synchronize. This processes the YAML config and populates the SQLite database (at `~/.config/agent-smith/config.db` on Linux).
80
+
81
+ ### 3. Run a Quick Query
82
+
83
+ ```bash
84
+ lm q list the planets of the solar system
85
+ ```
86
+
87
+ With a specific model:
88
+
89
+ ```bash
90
+ lm q list the planets of the solar system -m gemma4b
91
+ ```
92
+
93
+ ### 4. Enter Interactive Chat Mode
94
+
95
+ ```bash
96
+ lm
97
+ ```
98
+
99
+ Then type your queries interactively. Use `exit` to quit.
100
+
101
+ ## Usage
102
+
103
+ ### Listing Agents
104
+
105
+ List all registered agents:
106
+
107
+ ```bash
108
+ lm agents
109
+ ```
110
+
111
+ View an agent definition:
112
+
113
+ ```bash
114
+ lm agent myagent
115
+ ```
116
+
117
+ ### Running Agents
118
+
119
+ Run a specific agent with a prompt:
120
+
121
+ ```bash
122
+ lm myagent "Explain quantum computing"
123
+ ```
124
+
125
+ With variables (if the agent requires them):
126
+
127
+ ```bash
128
+ lm myagent "Analyze this code" --workspace /path/to/project
129
+ ```
16
130
 
17
- ## Quickstart
131
+ ### Using Different Backends
18
132
 
19
- Install the inference and the vision plugin:
133
+ Change the default backend:
20
134
 
21
135
  ```bash
22
- npm i -g @agent-smith/feat-inference @agent-smith/feat-vision
136
+ lm backend openrouter
23
137
  ```
24
138
 
25
- Create a `config.yml` file with this content:
139
+ Use a specific backend for one execution:
26
140
 
27
- ```yml
28
- plugins:
29
- - "@agent-smith/feat-inference"
30
- - "@agent-smith/feat-vision"
31
- - "@agent-smith/feat-models"
141
+ ```bash
142
+ lm myagent "Hello" -b llamacpp
32
143
  ```
33
144
 
34
- Run the conf command to initialize:
145
+ List available backends:
35
146
 
36
147
  ```bash
37
- lm conf ~/path/to/config.yml
148
+ lm backends
38
149
  ```
39
150
 
40
- ### Inference
151
+ ### Inference Parameters
41
152
 
42
- Run an inference query with the <kbd>q</kbd> command, using an Ollama model that you already have:
153
+ Control model behavior with command-line options:
43
154
 
44
155
  ```bash
45
- lm q list the planets of the solar system m="llama3.1:latest"
156
+ lm q "Write a poem" \
157
+ --model qwen4b \
158
+ --temperature 0.7 \
159
+ --top_k 20 \
160
+ --top_p 0.95 \
161
+ --max_tokens 1024
46
162
  ```
47
163
 
48
- ### Vision
164
+ ### Input/Output Modes
49
165
 
50
- Run a vision query: pull `minicpm-v:8b-2.6-q8_0` from Ollama and run:
166
+ **Clipboard input:**
167
+ ```bash
168
+ lm q "Summarize this" --ic
169
+ ```
51
170
 
171
+ **File input:**
52
172
  ```bash
53
- lm vision imgs/img1.jpeg imgs/img2.jpeg "Compare the images"
173
+ lm q "Analyze" --if
54
174
  ```
55
175
 
56
- ### Tasks
176
+ **Markdown output:**
177
+ ```bash
178
+ lm q "Generate a report" --markdown-output
179
+ ```
57
180
 
58
- List the available tasks:
181
+ **Clipboard output:**
182
+ ```bash
183
+ lm q "Generate code" --oc
184
+ ```
185
+
186
+ ### Chat Mode for Tasks
187
+
188
+ Enable chat mode for multi-turn task execution:
59
189
 
60
190
  ```bash
61
- lm tasks
191
+ lm myagent "Start a project" -c
62
192
  ```
63
193
 
64
- Show a task:
194
+ ### Verbose and Debug Modes
65
195
 
66
196
  ```bash
67
- lm task think
197
+ lm q "Hello" --verbose # Show detailed execution info
198
+ lm q "Hello" --debug # Show debug-level output
68
199
  ```
69
200
 
70
- ### Models
201
+ ## Complete Example
202
+
203
+ Here's a full workflow: configuring backends, creating an agent, and running it with custom parameters.
71
204
 
72
- Show available models:
205
+ ### Step 1: Create Features Directory
73
206
 
74
207
  ```bash
75
- lm models
208
+ mkdir -p ~/my-agents/features/agents
209
+ mkdir -p ~/my-agents/features/actions
210
+ ```
211
+
212
+ ### Step 2: Configure Features Path
213
+
214
+ Update `~/.config/agent-smith/config.yml`:
215
+
216
+ ```yaml
217
+ features:
218
+ - ~/my-agents/features
219
+ backends:
220
+ default: "llamacpp"
221
+ llamacpp:
222
+ type: "openai"
223
+ url: "http://localhost:8080/v1"
224
+ ```
225
+
226
+ Run `lm conf` to synchronize the conf db
227
+
228
+ ### Step 3: Create an Agent
229
+
230
+ Create `~/my-agents/features/agents/shell-demo.yml`:
231
+
232
+ ```yaml
233
+ description: A demo agent
234
+ prompt: |-
235
+ Custom prompt here.
236
+ User input: {prompt}
237
+ template:
238
+ system: |-
239
+ Custom system prompt here
240
+ model: qwen4b
241
+ inferParams:
242
+ min_p: 0
243
+ top_k: 20
244
+ top_p: 0.95
245
+ temperature: 0.4
76
246
  ```
77
247
 
78
- Search for a model:
248
+ ### Step 4: Register and Run
79
249
 
80
250
  ```bash
81
- lm model qwen
82
- ```
251
+ # Register the new agent
252
+ lm update
253
+
254
+ # Run with a prompt and variable
255
+ lm demo "user prompt here" -v # -v is to see thinking tokens
256
+ ```
257
+
258
+ ## API Reference
259
+
260
+ ### CLI Entry Point
261
+
262
+ The package exports utility functions for integration:
263
+
264
+ ```typescript
265
+ import {
266
+ displayOptions,
267
+ ioOptions,
268
+ inferenceOptions,
269
+ allOptions,
270
+ parseCommandArgs
271
+ } from "@agent-smith/cli";
272
+ ```
273
+
274
+ ### Options
275
+
276
+ | Export | Type | Description |
277
+ |--------|------|-------------|
278
+ | `displayOptions` | `Option[]` | CLI display options (`--verbose`, `--debug`) |
279
+ | `ioOptions` | `Option[]` | I/O mode options (clipboard, file, markdown) |
280
+ | `inferenceOptions` | `Option[]` | Inference parameter options (model, temperature, etc.) |
281
+ | `allOptions` | `Option[]` | Combined options array |
282
+ | `parseCommandArgs` | `Function` | Parse command-line arguments for Commander.js |
283
+
284
+ ### Inference Options
285
+
286
+ | Option | Short | Description |
287
+ |--------|-------|-------------|
288
+ | `--model <name>` | `-m` | Model name to use |
289
+ | `--ctx` | `-x` | Context window size |
290
+ | `--template <template>` | `--tpl` | Template to use |
291
+ | `--max_tokens <number>` | `--mt` | Maximum tokens to generate |
292
+ | `--top_k <number>` | `-k` | Limit results to top K |
293
+ | `--top_p <number>` | `-p` | Cumulative probability filter |
294
+ | `--min_p <number>` | `--mp` | Minimum token probability |
295
+ | `--temperature <number>` | `-t` | Sampling randomness |
296
+ | `--repeat_penalty <number>` | `-r` | Penalty for repeated tokens |
297
+ | `--backend <name>` | `-b` | Backend to use (must be registered) |
298
+ | `--mcp [args...]` | — | MCP server arguments |
299
+
300
+ ### I/O Options
301
+
302
+ | Option | Short | Description |
303
+ |--------|-------|-------------|
304
+ | `--input-file` | `--if` | Use promptfile input mode |
305
+ | `--clipboard-input` | `--ic` | Use clipboard input mode |
306
+ | `--manual-input` | `--im` | Manual input (default) |
307
+ | `--clipboard-output` | `--oc` | Output to clipboard |
308
+ | `--markdown-output` | `--omd` | Markdown output format |
309
+ | `--text-output` | `--otxt` | Text output (default) |
310
+
311
+ ## Important Notes
312
+
313
+ - **Node.js Required**: This package runs in Node.js environments only — it is not a browser library.
314
+ - **Global Installation**: Designed for global installation via `npm i -g`. The `lm` binary is available system-wide.
315
+ - **SQLite Database**: Configuration and features are stored in SQLite at `~/.config/agent-smith/config.db`.
316
+ - **Dependencies**: Requires `@agent-smith/core` for feature execution and database operations.
317
+ - **Backend Compatibility**: Supports any server with an OpenAI-compatible API (Llama.cpp, Ollama, Koboldcpp, OpenRouter, etc.).
318
+ - **Related Packages**:
319
+ - `@agent-smith/core` — Runtime engine for feature execution
320
+ - `@agent-smith/agent` — Agent inference loop
321
+ - `@agent-smith/wscli` — WebSocket client for server communication
322
+
323
+ ## License
324
+
325
+ MIT
package/dist/cli.js CHANGED
@@ -1,18 +1,14 @@
1
1
  import { input } from '@inquirer/prompts';
2
- import { chat } from './cmd/cmds.js';
3
- import { isChatMode } from './state/state.js';
4
- import { Agent } from '@agent-smith/agent';
5
- import { backend } from './state/backends.js';
6
2
  async function query(program) {
7
3
  const data = { message: "$", default: "" };
8
4
  const q = await input(data);
9
5
  //console.log("QUERY", q);
10
6
  const args = q.split(" ");
11
7
  await program.parseAsync(args, { from: "user" });
12
- if (isChatMode.value) {
13
- const agent = new Agent(backend.value, "chat");
14
- await chat(program, {}, agent, []);
15
- }
8
+ /*if (isChatMode.value) {
9
+ const agent = new Agent({ lm: state.backend.value!, name: "chat" })
10
+ await chat({}, agent, [])
11
+ }*/
16
12
  await query(program);
17
13
  }
18
14
  export { query };
@@ -1,5 +1,5 @@
1
1
  import { Command } from "commander";
2
- import { AliasType, FeatureSpec, FeatureType } from "../../interfaces.js";
2
+ import type { AliasType, FeatureSpec, FeatureType } from "@agent-smith/types";
3
3
  declare function initCommandsFromAliases(program: Command, aliases: {
4
4
  name: string;
5
5
  type: AliasType;
@@ -1,7 +1,5 @@
1
1
  import { allOptions } from "../options.js";
2
- import { executeTaskCmd } from "../lib/tasks/cmd.js";
3
- import { executeWorkflowCmd } from "../lib/workflows/cmd.js";
4
- import { executeAgentCmd } from "../lib/agents/cmd.js";
2
+ import { executeWorkflowCmd, executeAgentCmd } from "./features.js";
5
3
  function initCommandsFromAliases(program, aliases, features) {
6
4
  aliases.forEach((alias) => {
7
5
  //console.log("A", alias)
@@ -29,29 +27,6 @@ function initCommandsFromAliases(program, aliases, features) {
29
27
  }
30
28
  }
31
29
  break;
32
- case "task":
33
- const tcmd = program.command(`${alias.name} [prompt_and_vars...]`)
34
- .description("task: " + alias.name)
35
- .action(async (...args) => {
36
- await executeTaskCmd(alias.name, args);
37
- });
38
- allOptions.forEach(o => tcmd.addOption(o));
39
- //console.log("TVARS", alias.name, features.task[alias.name]?.variables)
40
- if (features.task[alias.name]?.variables) {
41
- const rtv = features.task[alias.name].variables?.required;
42
- if (rtv) {
43
- for (const name of Object.keys(rtv)) {
44
- tcmd.option(`--${name} <value>`);
45
- }
46
- }
47
- const otv = features.task[alias.name].variables?.optional;
48
- if (otv) {
49
- for (const name of Object.keys(otv)) {
50
- tcmd.option(`--${name} <value>`);
51
- }
52
- }
53
- }
54
- break;
55
30
  /*case "action":
56
31
  const acmd = program.command(`${alias.name} [args...]`)
57
32
  .description("action: " + alias.name)
@@ -1,8 +1,7 @@
1
1
  import { Option } from "commander";
2
- import { listBackends, setBackend } from "../../state/backends.js";
3
- import { parseCommandArgs } from "../lib/options_parsers.js";
4
- import { processTaskCmd, processTasksCmd, resetDbCmd } from "./cmds.js";
5
- import { updateConfCmd, updateFeaturesCmd } from "./updateconf.js";
2
+ import { conf, state } from "@agent-smith/core";
3
+ import { parseCommandArgs } from "../utils.js";
4
+ import { processAgentCmd, processAgentsCmd, recreateDbCmd, resetDbCmd } from "./cmds.js";
6
5
  import { displayOptions, inferenceOptions } from "../options.js";
7
6
  function initBaseCommands(program) {
8
7
  /*program.command("ping")
@@ -11,50 +10,55 @@ function initBaseCommands(program) {
11
10
  program.command("exit")
12
11
  .description("exit the cli")
13
12
  .action(() => process.exit(0));
14
- const tasksCmd = program.command("tasks")
15
- .description("list all the tasks")
13
+ const agentsCmd = program.command("agents")
14
+ .description("list all the agents")
16
15
  .action(async (...args) => {
17
16
  const ca = parseCommandArgs(args);
18
- await processTasksCmd(ca.args, ca.options);
17
+ await processAgentsCmd(ca.args, ca.options);
19
18
  });
20
- tasksCmd.addOption(new Option("-c, --conf", "output the tasks config"));
21
- const taskCmd = program.command("task <task>")
22
- .description("read a task")
19
+ agentsCmd.addOption(new Option("-c, --conf", "output the agents config"));
20
+ const agentCmd = program.command("agent <agent>")
21
+ .description("view an agent")
23
22
  .action(async (...args) => {
24
23
  const ca = parseCommandArgs(args);
25
- await processTaskCmd(ca.args, ca.options);
24
+ await processAgentCmd(ca.args, ca.options);
26
25
  });
27
- inferenceOptions.forEach(o => taskCmd.addOption(o));
28
- taskCmd.addOption(new Option("--reset", "reset the task config to the original"));
26
+ inferenceOptions.forEach(o => agentCmd.addOption(o));
27
+ agentCmd.addOption(new Option("--reset", "reset the task config to the original"));
29
28
  program.command("backend <name>")
30
29
  .description("set the default backend")
31
30
  .action(async (...args) => {
32
31
  const ca = parseCommandArgs(args);
33
- await setBackend(ca.args[0]);
32
+ await state.setBackend(ca.args[0]);
34
33
  });
35
34
  program.command("backends")
36
35
  .description("list the available backends")
37
36
  .action(async (...args) => {
38
- await listBackends();
37
+ await state.listBackends();
39
38
  });
40
39
  const updateCmd = program.command("update")
41
40
  .description("update the available features: run this after adding a new feature")
42
41
  .action(async (...args) => {
43
42
  const ca = parseCommandArgs(args);
44
- await updateFeaturesCmd(ca.options);
43
+ await conf.updateFeaturesCmd(ca.options);
45
44
  });
46
45
  displayOptions.forEach(o => updateCmd.addOption(o));
47
46
  program.command("conf <path>")
48
47
  .description("process config file")
49
48
  .action(async (...args) => {
50
49
  const ca = parseCommandArgs(args);
51
- await updateConfCmd(ca.args);
50
+ await conf.updateConfCmd(ca.args);
52
51
  });
53
52
  program.command("reset")
54
53
  .description("reset the config database")
55
54
  .action(async (...args) => {
56
55
  await resetDbCmd();
57
56
  });
57
+ program.command("regendb")
58
+ .description("regenerate the database from the current registered config file")
59
+ .action(async (...args) => {
60
+ await recreateDbCmd();
61
+ });
58
62
  return program;
59
63
  }
60
64
  export { initBaseCommands };
@@ -0,0 +1,9 @@
1
+ import type { AgentInferenceOptions } from "@agent-smith/types";
2
+ import { Command } from "commander";
3
+ import { type McpClient } from "@agent-smith/core";
4
+ import type { Agent } from "@agent-smith/agent";
5
+ declare const program: Command;
6
+ declare function chat(options: AgentInferenceOptions, agent: Agent, mcpServers: Array<McpClient>): Promise<void>;
7
+ declare function buildCmds(): Promise<Command>;
8
+ declare function parseCmd(program: Command): Promise<void>;
9
+ export { buildCmds, chat, parseCmd, program };
@@ -0,0 +1,64 @@
1
+ import { input } from "@inquirer/prompts";
2
+ import { Command } from "commander";
3
+ import { query } from "../cli.js";
4
+ import { db } from "@agent-smith/core";
5
+ import { isChatMode, runMode, chatInferenceParams } from "../state.js";
6
+ import { initBaseCommands } from "./base.js";
7
+ import { initCommandsFromAliases } from "./aliases.js";
8
+ import { initUserCmds } from "./cmds.js";
9
+ const program = new Command();
10
+ async function chat(options, agent, mcpServers) {
11
+ //console.log("CHAT AGENT", agent);
12
+ const data = { message: '>', default: "" };
13
+ const prompt = await input(data);
14
+ if (prompt == "/q") {
15
+ isChatMode.value = false;
16
+ if (runMode.value == "cmd") {
17
+ process.exit(0);
18
+ }
19
+ else {
20
+ mcpServers.forEach(async (s) => await s.stop());
21
+ await query(program);
22
+ }
23
+ }
24
+ /* console.log("CHAT HISTORY", agent.history.length);
25
+ agent.history.forEach(t => {
26
+ const turn = { ...t };
27
+ delete turn.stats;
28
+ console.log(turn)
29
+ });*/
30
+ //options.history = undefined;
31
+ //console.log("RUN W PROMPT", prompt);
32
+ options.params = chatInferenceParams;
33
+ await agent.run(prompt, options);
34
+ console.log();
35
+ await chat(options, agent, mcpServers);
36
+ }
37
+ async function buildCmds() {
38
+ //program.allowUnknownOption(true);
39
+ //const perf = usePerfTimer();
40
+ initBaseCommands(program);
41
+ //perf.measure("initBaseCommands");
42
+ const aliases = db.readAliases();
43
+ //perf.measure("readAliases");
44
+ const feats = db.readFeatures();
45
+ //perf.measure("readFeatures");
46
+ initCommandsFromAliases(program, aliases, feats);
47
+ //perf.measure("initCommandsFromAliases");
48
+ await initUserCmds(feats.cmd, program);
49
+ //perf.measure("initUserCmds");
50
+ //perf.measure("cmds for each");
51
+ //perf.final("buildCmds");
52
+ return program;
53
+ }
54
+ async function parseCmd(program) {
55
+ program.name('Agent Smith terminal client');
56
+ program.description('Terminal agents toolkit');
57
+ await program.parseAsync();
58
+ //console.log("CMD END");
59
+ //exit(0)
60
+ /*if (isChatMode.value) {
61
+ await chat(program)
62
+ }*/
63
+ }
64
+ export { buildCmds, chat, parseCmd, program };
@@ -0,0 +1,11 @@
1
+ import type { AgentInferenceOptions, ToolCallSpec } from "@agent-smith/types";
2
+ declare const useInferenceCallbacks: (agentName: string, options: AgentInferenceOptions) => {
3
+ onToken: (t: string, from: string) => void;
4
+ onStartThinking: (from: string) => void;
5
+ onEndThinking: (from: string) => void;
6
+ onThinkingToken: (t: string, from: string) => void;
7
+ onToolCallInProgress: (tc: Array<ToolCallSpec>, from: string) => void;
8
+ onToolCall: (tc: ToolCallSpec, type: string, from: string) => void;
9
+ onToolCallEnd: (tc: ToolCallSpec, tr: any, type: string, from: string) => void;
10
+ };
11
+ export { useInferenceCallbacks, };