keystone-cli 0.1.0 β†’ 0.2.0

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 (51) hide show
  1. package/README.md +326 -59
  2. package/package.json +1 -1
  3. package/src/cli.ts +90 -81
  4. package/src/db/workflow-db.ts +0 -7
  5. package/src/expression/evaluator.test.ts +42 -0
  6. package/src/expression/evaluator.ts +28 -0
  7. package/src/parser/agent-parser.test.ts +10 -0
  8. package/src/parser/agent-parser.ts +2 -1
  9. package/src/parser/config-schema.ts +13 -5
  10. package/src/parser/workflow-parser.ts +0 -5
  11. package/src/runner/llm-adapter.test.ts +0 -8
  12. package/src/runner/llm-adapter.ts +33 -10
  13. package/src/runner/llm-executor.test.ts +59 -18
  14. package/src/runner/llm-executor.ts +1 -1
  15. package/src/runner/mcp-client.test.ts +166 -88
  16. package/src/runner/mcp-client.ts +156 -22
  17. package/src/runner/mcp-manager.test.ts +73 -15
  18. package/src/runner/mcp-manager.ts +44 -18
  19. package/src/runner/mcp-server.test.ts +4 -1
  20. package/src/runner/mcp-server.ts +25 -11
  21. package/src/runner/shell-executor.ts +3 -3
  22. package/src/runner/step-executor.ts +10 -9
  23. package/src/runner/tool-integration.test.ts +21 -14
  24. package/src/runner/workflow-runner.ts +25 -5
  25. package/src/templates/agents/explore.md +54 -0
  26. package/src/templates/agents/general.md +8 -0
  27. package/src/templates/agents/keystone-architect.md +54 -0
  28. package/src/templates/agents/my-agent.md +3 -0
  29. package/src/templates/agents/summarizer.md +28 -0
  30. package/src/templates/agents/test-agent.md +10 -0
  31. package/src/templates/approval-process.yaml +36 -0
  32. package/src/templates/basic-inputs.yaml +19 -0
  33. package/src/templates/basic-shell.yaml +20 -0
  34. package/src/templates/batch-processor.yaml +43 -0
  35. package/src/templates/cleanup-finally.yaml +22 -0
  36. package/src/templates/composition-child.yaml +13 -0
  37. package/src/templates/composition-parent.yaml +14 -0
  38. package/src/templates/data-pipeline.yaml +38 -0
  39. package/src/templates/full-feature-demo.yaml +64 -0
  40. package/src/templates/human-interaction.yaml +12 -0
  41. package/src/templates/invalid.yaml +5 -0
  42. package/src/templates/llm-agent.yaml +8 -0
  43. package/src/templates/loop-parallel.yaml +37 -0
  44. package/src/templates/retry-policy.yaml +36 -0
  45. package/src/templates/scaffold-feature.yaml +48 -0
  46. package/src/templates/state.db +0 -0
  47. package/src/templates/state.db-shm +0 -0
  48. package/src/templates/state.db-wal +0 -0
  49. package/src/templates/stop-watch.yaml +17 -0
  50. package/src/templates/workflow.db +0 -0
  51. package/src/utils/config-loader.test.ts +2 -2
package/README.md CHANGED
@@ -1,136 +1,403 @@
1
+ <p align="center">
2
+ <img src="logo.png" width="250" alt="Keystone CLI Logo">
3
+ </p>
4
+
1
5
  # πŸ›οΈ Keystone CLI
2
6
 
3
7
  [![Bun](https://img.shields.io/badge/Bun-%23000000.svg?style=flat&logo=bun&logoColor=white)](https://bun.sh)
4
- [![NPM Version](https://img.shields.io/npm/v/keystone-cli.svg?style=flat)](https://www.npmjs.com/package/keystone-cli)
8
+ [![npm version](https://img.shields.io/npm/v/keystone-cli.svg?style=flat)](https://www.npmjs.com/package/keystone-cli)
5
9
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
10
 
7
- **Keystone** is a local-first, declarative, agentic workflow orchestrator built on **Bun**.
11
+ A local-first, declarative, agentic workflow orchestrator built on **Bun**.
8
12
 
9
- It allows you to define complex automation workflows using a simple YAML syntax, featuring first-class support for LLM agents, persistent state management via SQLite, and high-concurrency execution with built-in resilience.
13
+ Keystone allows you to define complex automation workflows using a simple YAML syntax, with first-class support for LLM agents, state persistence, and parallel execution.
10
14
 
11
15
  ---
12
16
 
13
- ## ✨ Key Features
17
+ ## ✨ Features
14
18
 
15
- - ⚑ **Local-First & Fast:** Powered by Bun with a local SQLite database. No external "cloud state" requiredβ€”your data and workflow history stay on your machine.
16
- - 🧩 **Declarative Workflows:** Define logic in YAML. Keystone automatically calculates the execution graph (DAG) and detects dependencies from your expressions.
17
- - πŸ€– **Agentic by Design:** Seamlessly integrate LLM agents defined in Markdown. Agents can use tools, which are just other workflow steps.
18
- - πŸ”Œ **Built-in MCP Server:** Expose your workflows as tools to other AI assistants (like Claude Desktop) using the Model Context Protocol.
19
- - πŸ”„ **Resilient Execution:** Built-in retries, exponential backoff, and timeouts. Interrupted workflows can be resumed exactly where they stopped.
20
- - πŸ§‘β€πŸ’» **Human-in-the-Loop:** Support for manual approval and text input steps for sensitive or creative operations.
21
- - πŸ“Š **Interactive TUI:** A beautiful terminal dashboard to monitor concurrent runs and history.
22
- - πŸ›‘οΈ **Security-First:** Automatic secret redaction from logs/database and AST-based safe expression evaluation.
19
+ - ⚑ **Local-First:** Built on Bun with a local SQLite database for state management.
20
+ - 🧩 **Declarative:** Define workflows in YAML with automatic dependency tracking (DAG).
21
+ - πŸ€– **Agentic:** First-class support for LLM agents defined in Markdown with YAML frontmatter.
22
+ - πŸ§‘β€πŸ’» **Human-in-the-Loop:** Support for manual approval and text input steps.
23
+ - πŸ”„ **Resilient:** Built-in retries, timeouts, and state persistence. Resume failed or paused runs exactly where they left off.
24
+ - πŸ“Š **TUI Dashboard:** Built-in interactive dashboard for monitoring and managing runs.
25
+ - πŸ› οΈ **Extensible:** Support for shell, file, HTTP request, LLM, and sub-workflow steps.
26
+ - πŸ”Œ **MCP Support:** Integrated Model Context Protocol server.
27
+ - πŸ›‘οΈ **Secret Redaction:** Automatically redacts environment variables and secrets from logs and outputs.
23
28
 
24
29
  ---
25
30
 
26
31
  ## πŸš€ Installation
27
32
 
28
- Ensure you have [Bun](https://bun.sh) installed (v1.0.0 or higher).
33
+ Ensure you have [Bun](https://bun.sh) installed.
34
+
35
+ ### Global Install (Recommended)
36
+ ```bash
37
+ bun install -g keystone-cli
38
+ ```
29
39
 
40
+ ### From Source
30
41
  ```bash
31
- # Install globally via Bun
32
- bun add -g keystone-cli
42
+ # Clone the repository
43
+ git clone https://github.com/mhingston/keystone-cli.git
44
+ cd keystone-cli
45
+
46
+ # Install dependencies
47
+ bun install
33
48
 
34
- # Or via NPM
35
- npm install -g keystone-cli
49
+ # Link CLI globally
50
+ bun link
36
51
  ```
37
52
 
38
53
  ### Shell Completion
39
54
 
40
- To enable tab completion for workflow names and commands:
55
+ To enable tab completion for your shell, add the following to your `.zshrc` or `.bashrc`:
41
56
 
42
- **Zsh:** Add `source <(keystone completion zsh)` to your `.zshrc`
43
- **Bash:** Add `source <(keystone completion bash)` to your `.bashrc`
57
+ **Zsh:**
58
+ ```bash
59
+ source <(keystone completion zsh)
60
+ ```
61
+
62
+ **Bash:**
63
+ ```bash
64
+ source <(keystone completion bash)
65
+ ```
44
66
 
45
67
  ---
46
68
 
47
- ## πŸš₯ Quick Start
69
+ ## 🚦 Quick Start
48
70
 
49
71
  ### 1. Initialize a Project
50
72
  ```bash
51
73
  keystone init
52
74
  ```
53
- This creates a `.keystone/` directory for configuration and a `workflows/` directory for your files.
75
+ This creates the `.keystone/` directory for configuration and seeds `.keystone/workflows/` with default automation files and agents (like `scaffold-feature` and `keystone-architect`).
54
76
 
55
- ### 2. Configure Environment
77
+ ### 2. Configure your Environment
56
78
  Add your API keys to the generated `.env` file:
57
79
  ```env
58
80
  OPENAI_API_KEY=sk-...
59
81
  ANTHROPIC_API_KEY=sk-ant-...
60
82
  ```
61
83
 
62
- ### 3. Run Your First Workflow
84
+ ### 3. Run a Workflow
63
85
  ```bash
64
86
  keystone run basic-shell
65
87
  ```
88
+ Keystone automatically looks in `.keystone/workflows/` (locally and in your home directory) for `.yaml` or `.yml` files.
89
+
90
+ ### 4. Monitor with the Dashboard
91
+ ```bash
92
+ keystone ui
93
+ ```
94
+
95
+ ---
96
+
97
+ ## βš™οΈ Configuration
98
+
99
+ Keystone uses a local configuration file at `.keystone/config.yaml` to manage model providers and model mappings.
100
+
101
+ ```yaml
102
+ default_provider: openai
103
+
104
+ providers:
105
+ openai:
106
+ type: openai
107
+ base_url: https://api.openai.com/v1
108
+ api_key_env: OPENAI_API_KEY
109
+ default_model: gpt-4o
110
+ anthropic:
111
+ type: anthropic
112
+ base_url: https://api.anthropic.com/v1
113
+ api_key_env: ANTHROPIC_API_KEY
114
+ default_model: claude-3-5-sonnet-20240620
115
+ groq:
116
+ type: openai
117
+ base_url: https://api.groq.com/openai/v1
118
+ api_key_env: GROQ_API_KEY
119
+ default_model: llama-3.3-70b-versatile
120
+
121
+ model_mappings:
122
+ "gpt-*": openai
123
+ "claude-*": anthropic
124
+ "o1-*": openai
125
+ "llama-*": groq
126
+
127
+ mcp_servers:
128
+ filesystem:
129
+ command: npx
130
+ args: ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/directory"]
131
+ github:
132
+ command: npx
133
+ args: ["-y", "@modelcontextprotocol/server-github"]
134
+ env:
135
+ GITHUB_PERSONAL_ACCESS_TOKEN: "your-github-pat" # Or omit if GITHUB_TOKEN is in your .env
136
+
137
+ storage:
138
+
139
+ retention_days: 30
140
+ ```
141
+
142
+ ### Model & Provider Resolution
143
+
144
+ Keystone resolves which provider to use for a model in the following order:
145
+
146
+ 1. **Explicit Provider:** Use the `provider` field in an agent or step definition.
147
+ 2. **Provider Prefix:** Use the `provider:model` syntax (e.g., `model: copilot:gpt-4o`).
148
+ 3. **Model Mappings:** Matches the model name against the `model_mappings` in your config (supports suffix `*` for prefix matching).
149
+ 4. **Default Provider:** Falls back to the `default_provider` defined in your config.
150
+
151
+ #### Example: Explicit Provider in Agent
152
+ **`.keystone/workflows/agents/summarizer.md`**
153
+ ```markdown
154
+ ---
155
+ name: summarizer
156
+ provider: anthropic
157
+ model: claude-3-5-sonnet-latest
158
+ ---
159
+ ```
160
+
161
+ #### Example: Provider Prefix in Step
162
+ ```yaml
163
+ - id: notify
164
+ type: llm
165
+ agent: summarizer
166
+ model: copilot:gpt-4o
167
+ prompt: ...
168
+ ```
169
+
170
+ ### OpenAI Compatible Providers
171
+ You can add any OpenAI-compatible provider (Groq, Together AI, Perplexity, Local Ollama, etc.) by setting the `type` to `openai` and providing the `base_url` and `api_key_env`.
172
+
173
+ ### GitHub Copilot Support
174
+
175
+ Keystone supports using your GitHub Copilot subscription directly. To authenticate (using the GitHub Device Flow):
176
+
177
+ ```bash
178
+ keystone auth login
179
+ ```
180
+
181
+ Then, you can use Copilot in your configuration:
182
+
183
+ ```yaml
184
+ providers:
185
+ copilot:
186
+ type: copilot
187
+ default_model: gpt-4o
188
+ ```
189
+
190
+ Authentication tokens for Copilot are managed automatically after the initial login. For other providers, API keys should be stored in a `.env` file in your project root:
191
+ - `OPENAI_API_KEY`
192
+ - `ANTHROPIC_API_KEY`
66
193
 
67
194
  ---
68
195
 
69
- ## βš™οΈ How it Works
196
+ ## πŸ“ Workflow Example
70
197
 
71
- ### Workflows (.yaml)
72
- Workflows are defined by steps. Steps run in **parallel** by default unless a dependency is defined via `needs` or detected in an expression like `${{ steps.previous_step.output }}`.
198
+ Workflows are defined in YAML. Dependencies are automatically resolved based on the `needs` field, and **Keystone also automatically detects implicit dependencies** from your `${{ }}` expressions.
73
199
 
74
200
  ```yaml
75
- name: analyze-repo
201
+ name: build-and-notify
202
+ description: Build the project and notify the team
203
+
204
+ inputs:
205
+ branch:
206
+ type: string
207
+ default: main
208
+
76
209
  steps:
77
- - id: list_files
210
+ - id: checkout
211
+ type: shell
212
+ run: git checkout ${{ inputs.branch }}
213
+
214
+ - id: install
215
+ type: shell
216
+ # Implicit dependency on 'checkout' detected from expression below
217
+ if: ${{ steps.checkout.status == 'success' }}
218
+ run: bun install
219
+
220
+ - id: build
78
221
  type: shell
79
- run: ls -R
80
- transform: stdout.split('\n')
222
+ needs: [install] # Explicit dependency
223
+ run: bun run build
224
+ retry:
225
+ count: 3
226
+ backoff: exponential
81
227
 
82
- - id: analyze
228
+ - id: notify
83
229
  type: llm
84
- foreach: ${{ steps.list_files.output }}
85
- concurrency: 5
86
- agent: code-reviewer
87
- prompt: "Analyze this file: ${{ item }}"
230
+ # Implicit dependency on 'build' detected from expression below
231
+ agent: summarizer
232
+ prompt: |
233
+ The build for branch "${{ inputs.branch }}" was successful.
234
+ Result: ${{ steps.build.output }}
235
+ Please write a concise 1-sentence summary for Slack.
236
+
237
+ outputs:
238
+ slack_message: ${{ steps.notify.output }}
239
+ ```
240
+
241
+ ---
242
+
243
+ ## πŸ—οΈ Step Types
244
+
245
+ Keystone supports several specialized step types:
246
+
247
+ - `shell`: Run arbitrary shell commands.
248
+ - `llm`: Prompt an agent and get structured or unstructured responses. Supports `schema` (JSON Schema) for structured output.
249
+ - `request`: Make HTTP requests (GET, POST, etc.).
250
+ - `file`: Read, write, or append to files.
251
+ - `human`: Pause execution for manual confirmation or text input.
252
+ - `inputType: confirm`: Simple Enter-to-continue prompt.
253
+ - `inputType: text`: Prompt for a string input, available via `${{ steps.id.output }}`.
254
+ - `workflow`: Trigger another workflow as a sub-step.
255
+ - `sleep`: Pause execution for a specified duration.
256
+
257
+ All steps support common features like `needs` (dependencies), `if` (conditionals), `retry`, `timeout`, `foreach` (parallel iteration), and `transform` (post-process output using expressions).
258
+
259
+ #### Example: Transform & Foreach Concurrency
260
+ ```yaml
261
+ - id: list_files
262
+ type: shell
263
+ run: ls *.txt
264
+ # Post-process stdout into an array of filenames
265
+ transform: ${{ stdout.trim().split('\n') }}
266
+
267
+ - id: process_files
268
+ type: shell
269
+ foreach: ${{ steps.list_files.output }}
270
+ concurrency: 5 # Process 5 files at a time
271
+ run: echo "Processing ${{ item }}"
88
272
  ```
89
273
 
90
- ### Agents (.md)
91
- Agents are defined in Markdown with YAML frontmatter. This keeps the "personality" and tools of the agent together in a human-readable format.
274
+ ---
275
+
276
+ ## πŸ€– Agent Definitions
92
277
 
278
+ Agents are defined in Markdown files with YAML frontmatter, making them easy to read and version control.
279
+
280
+ **`.keystone/workflows/agents/summarizer.md`**
93
281
  ```markdown
94
282
  ---
95
- name: code-reviewer
96
- model: claude-3-5-sonnet-latest
283
+ name: summarizer
284
+ provider: openai
285
+ model: gpt-4o
286
+ description: Summarizes technical logs into human-readable messages
287
+ ---
288
+
289
+ You are a technical communications expert. Your goal is to take technical output
290
+ (like build logs or test results) and provide a concise, professional summary.
291
+ ```
292
+
293
+ ### Agent Tools
294
+
295
+ Agents can be equipped with tools, which are essentially workflow steps they can choose to execute. You can define tools in the agent definition, or directly in an LLM step within a workflow.
296
+
297
+ **`.keystone/workflows/agents/developer.md`**
298
+ ```markdown
299
+ ---
300
+ name: developer
97
301
  tools:
98
- - name: read_file
302
+ - name: list_files
303
+ description: List files in the current directory
99
304
  execution:
100
- type: file
101
- op: read
102
- path: "${{ args.path }}"
305
+ id: list-files-tool
306
+ type: shell
307
+ run: ls -F
103
308
  ---
104
- You are an expert security researcher. Review the provided code for vulnerabilities.
309
+ You are a software developer. You can use tools to explore the codebase.
105
310
  ```
106
311
 
312
+ ### Keystone as an MCP Server
313
+
314
+ Keystone can itself act as an MCP server, allowing other agents (like Claude Desktop or GitHub Copilot) to discover and run your workflows as tools.
315
+
316
+ ```bash
317
+ keystone mcp
318
+ ```
319
+
320
+ > **Note:** Workflow execution via the Keystone MCP server is synchronous. This provides a better experience for agents as they receive the final results directly, though it means the connection remains open for the duration of the workflow run.
321
+
322
+ #### Global MCP Servers
323
+ Define shared MCP servers in `.keystone/config.yaml` to reuse them across different workflows. Keystone ensures that multiple steps using the same global server will share a single running process.
324
+
325
+ Keystone supports both local (stdio) and remote (SSE) MCP servers.
326
+
327
+ ```yaml
328
+ mcp_servers:
329
+ # Local server (stdio)
330
+ filesystem:
331
+ type: local # Default
332
+ command: npx
333
+ args: ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/directory"]
334
+
335
+ # Remote server (SSE)
336
+ atlassian:
337
+ type: remote
338
+ url: https://mcp.atlassian.com/v1/sse
339
+ ```
340
+
341
+ #### Using MCP in Steps
342
+ You can use global servers, define local ones, or include all global servers at once.
343
+
344
+ ```yaml
345
+ - id: analyze_code
346
+ type: llm
347
+ agent: developer
348
+ # Option 1: Explicitly include global servers by name
349
+ # Option 2: Define a local one-off server (standard object syntax)
350
+ mcpServers:
351
+ - filesystem
352
+ - name: custom-tool
353
+ command: node
354
+ args: ["./scripts/custom-mcp.js"]
355
+
356
+ # Option 3: Automatically include ALL global servers
357
+ useGlobalMcp: true
358
+
359
+ prompt: "Analyze the architecture of this project."
360
+ ```
361
+
362
+ In these examples, the agent will have access to all tools provided by the MCP servers (like `list_directory`, `read_file`, etc.) in addition to any tools defined in the agent or the step itself.
363
+
107
364
  ---
108
365
 
109
- ## πŸ› οΈ CLI Reference
366
+ ## πŸ› οΈ CLI Commands
110
367
 
111
368
  | Command | Description |
112
369
  | :--- | :--- |
113
370
  | `init` | Initialize a new Keystone project |
114
- | `run <workflow>` | Execute a workflow (supports `-i key=val` for inputs) |
115
- | `resume <run_id>` | Resume a paused or failed workflow run |
371
+ | `run <workflow>` | Execute a workflow (use `-i key=val` for inputs) |
372
+ | `resume <run_id>` | Resume a failed or paused workflow |
373
+ | `validate [path]` | Check workflow files for errors |
374
+ | `workflows` | List available workflows |
375
+ | `history` | Show recent workflow runs |
376
+ | `logs <run_id>` | View logs and step status for a specific run |
377
+ | `graph <workflow>` | Generate a Mermaid diagram of the workflow |
378
+ | `config` | Show current configuration and providers |
379
+ | `auth status` | Show authentication status |
380
+ | `auth login` | Login to an authentication provider (GitHub) |
381
+ | `auth logout` | Logout and clear authentication tokens |
116
382
  | `ui` | Open the interactive TUI dashboard |
117
- | `mcp` | Start the MCP server to use workflows in other tools |
118
- | `graph <workflow>` | Visualize the DAG as an ASCII or Mermaid diagram |
119
- | `history` | List recent runs and their status |
120
- | `auth login` | Authenticate with GitHub for Copilot support |
121
- | `validate` | Check workflow files for schema and logic errors |
383
+ | `mcp` | Start the Keystone MCP server |
384
+ | `completion [shell]` | Generate shell completion script (zsh, bash) |
385
+ | `prune [--days N]` | Cleanup old run data from the database |
122
386
 
123
387
  ---
124
388
 
125
- ## πŸ”’ Security & Privacy
389
+ ## πŸ“‚ Project Structure
126
390
 
127
- 1. **Local State:** All run history, logs, and outputs are stored in a local SQLite database (`.keystone/state.db`).
128
- 2. **Redaction:** Keystone automatically scans for your environment variables and masks them in all logs and database entries.
129
- 3. **AST Evaluation:** Expressions are parsed into an Abstract Syntax Tree and executed in a sandbox, preventing arbitrary code execution within `${{ }}` blocks.
130
- 4. **Shell Safety:** Use the built-in `escape()` function when passing user input to shell commands to prevent injection.
391
+ - `src/db/`: SQLite persistence layer.
392
+ - `src/runner/`: The core execution engine, handles parallelization and retries.
393
+ - `src/parser/`: Zod-powered validation for workflows and agents.
394
+ - `src/expression/`: `${{ }}` expression evaluator.
395
+ - `src/ui/`: Ink-powered TUI dashboard.
396
+ - `src/utils/`: Shared utilities (auth, redaction, config loading).
397
+ - `.keystone/workflows/`: Your YAML workflow definitions.
131
398
 
132
399
  ---
133
400
 
134
401
  ## πŸ“„ License
135
402
 
136
- MIT Β© [Mark Hingston](https://github.com/mhingston)
403
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keystone-cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "A local-first, declarative, agentic workflow orchestrator built on Bun",
5
5
  "type": "module",
6
6
  "bin": {