@kernel.chat/kbot 2.22.1 → 2.22.3
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/README.md +135 -132
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +183 -8
- package/dist/agent.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +3 -2
- package/dist/auth.js.map +1 -1
- package/dist/emergent-swarm.d.ts.map +1 -1
- package/dist/emergent-swarm.js +3 -1
- package/dist/emergent-swarm.js.map +1 -1
- package/dist/error-correction.js +2 -2
- package/dist/error-correction.js.map +1 -1
- package/dist/ide/acp-server.js +2 -2
- package/dist/ide/mcp-server.js +1 -1
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +4 -1
- package/dist/serve.js.map +1 -1
- package/dist/share.js +1 -1
- package/dist/tools/audit.js +1 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +18 -6
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/containers.d.ts.map +1 -1
- package/dist/tools/containers.js +11 -14
- package/dist/tools/containers.js.map +1 -1
- package/dist/tools/contribute.d.ts.map +1 -1
- package/dist/tools/contribute.js +6 -4
- package/dist/tools/contribute.js.map +1 -1
- package/dist/tools/quality.d.ts.map +1 -1
- package/dist/tools/quality.js +2 -1
- package/dist/tools/quality.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<strong>K:BOT</strong><br>
|
|
3
|
-
|
|
3
|
+
<em>Terminal AI agent that learns your patterns.</em>
|
|
4
4
|
</p>
|
|
5
5
|
|
|
6
6
|
<p align="center">
|
|
@@ -8,21 +8,30 @@
|
|
|
8
8
|
<a href="https://www.npmjs.com/package/@kernel.chat/kbot"><img src="https://img.shields.io/npm/dw/@kernel.chat/kbot?color=6B5B95" alt="npm downloads"></a>
|
|
9
9
|
<a href="https://github.com/isaacsight/kernel/blob/main/LICENSE"><img src="https://img.shields.io/github/license/isaacsight/kernel?color=6B5B95" alt="MIT License"></a>
|
|
10
10
|
<a href="https://github.com/isaacsight/kernel"><img src="https://img.shields.io/github/stars/isaacsight/kernel?color=6B5B95&style=flat" alt="GitHub stars"></a>
|
|
11
|
-
<a href="https://kernel.chat"><img src="https://img.shields.io/badge/web-kernel.chat-6B5B95" alt="kernel.chat"></a>
|
|
12
|
-
<a href="https://hub.docker.com/r/isaacsight/kbot"><img src="https://img.shields.io/badge/docker-kbot-6B5B95" alt="Docker"></a>
|
|
13
11
|
<a href="https://discord.gg/pYJn3hBqnz"><img src="https://img.shields.io/badge/discord-join-6B5B95?logo=discord&logoColor=white" alt="Discord"></a>
|
|
14
|
-
<a href="https://github.com/isaacsight/kernel/blob/main/packages/kbot/CONTRIBUTING.md"><img src="https://img.shields.io/badge/PRs-welcome-6B5B95" alt="PRs Welcome"></a>
|
|
15
12
|
</p>
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
<!-- TODO: Replace with actual demo GIF after recording -->
|
|
15
|
+
<!-- <p align="center"><img src="https://raw.githubusercontent.com/isaacsight/kernel/main/packages/kbot/demo.gif" alt="kbot demo" width="600"></p> -->
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g @kernel.chat/kbot
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**22 specialist agents. 223 tools. 20 providers. Runs offline. MIT licensed.**
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Why kbot?
|
|
26
|
+
|
|
27
|
+
Most AI coding tools lock you into one provider and forget everything between sessions. kbot is different:
|
|
28
|
+
|
|
29
|
+
- **20 providers, zero lock-in** — Claude, GPT, Gemini, Grok, DeepSeek, Groq, Mistral, and 13 more. Switch anytime.
|
|
30
|
+
- **Runs fully offline** — Embedded llama.cpp runs GGUF models directly. No Ollama needed. $0, fully private.
|
|
31
|
+
- **Learns your patterns** — Extracts what works from every conversation. Gets faster and smarter over time.
|
|
32
|
+
- **22 specialist agents** — Say "fix the auth bug" and it picks the coder. Say "research JWT tokens" and it picks the researcher. Auto-routed.
|
|
33
|
+
- **Self-evaluating** — Every response scored on quality. Low score? Auto-retries with feedback.
|
|
34
|
+
- **Works in your IDE** — Built-in MCP server for VS Code, Cursor, Zed, Neovim. ACP for JetBrains.
|
|
26
35
|
|
|
27
36
|
## Install
|
|
28
37
|
|
|
@@ -40,96 +49,97 @@ curl -fsSL https://raw.githubusercontent.com/isaacsight/kernel/main/packages/kbo
|
|
|
40
49
|
## Quick Start
|
|
41
50
|
|
|
42
51
|
```bash
|
|
43
|
-
#
|
|
52
|
+
# One-shot — ask anything
|
|
53
|
+
kbot "explain what this project does"
|
|
54
|
+
|
|
55
|
+
# Interactive REPL
|
|
56
|
+
kbot
|
|
57
|
+
|
|
58
|
+
# Use your own API key (auto-detects provider)
|
|
44
59
|
kbot auth
|
|
45
60
|
|
|
46
|
-
# Or
|
|
61
|
+
# Or go fully local — no API key, no data leaves your machine
|
|
47
62
|
kbot local
|
|
48
63
|
|
|
49
|
-
#
|
|
50
|
-
kbot
|
|
51
|
-
kbot local --embedded
|
|
52
|
-
|
|
53
|
-
# Start chatting
|
|
54
|
-
kbot
|
|
64
|
+
# Pipe mode — compose with Unix tools
|
|
65
|
+
kbot -p "generate a user roles migration" > migration.sql
|
|
55
66
|
```
|
|
56
67
|
|
|
57
|
-
##
|
|
68
|
+
## Specialists
|
|
58
69
|
|
|
59
|
-
-
|
|
60
|
-
- **`kbot models`** — Download, list, and manage GGUF models from HuggingFace
|
|
61
|
-
- **20 providers** — Embedded llama.cpp joins Anthropic, OpenAI, Google, Ollama, and 15 more
|
|
62
|
-
- **Auto-fallback** — If Ollama isn't running, kbot automatically uses embedded models
|
|
63
|
-
- **GPU-accelerated** — Metal (Mac), CUDA (Linux/Windows), Vulkan
|
|
70
|
+
Auto-routed by intent, or pick one with `kbot --agent <name>`:
|
|
64
71
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
| | Agents |
|
|
73
|
+
|---|---|
|
|
74
|
+
| **Core** | kernel, researcher, coder, writer, analyst |
|
|
75
|
+
| **Extended** | aesthete, guardian, curator, strategist |
|
|
76
|
+
| **Domain** | infrastructure, quant, investigator, oracle, chronist, sage, communicator, adapter |
|
|
77
|
+
| **Presets** | claude-code, cursor, copilot, creative, developer |
|
|
68
78
|
|
|
69
|
-
|
|
70
|
-
kbot
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
kbot
|
|
79
|
+
```bash
|
|
80
|
+
kbot --agent researcher "what papers cite Friston's Free Energy Principle?"
|
|
81
|
+
kbot --agent guardian "review src/auth.ts for security issues"
|
|
82
|
+
kbot --agent coder "refactor this into smaller functions"
|
|
74
83
|
```
|
|
75
84
|
|
|
76
|
-
##
|
|
85
|
+
## 223 Tools
|
|
86
|
+
|
|
87
|
+
| Category | Examples |
|
|
88
|
+
|----------|---------|
|
|
89
|
+
| **Files & Code** | read, write, glob, grep, lint, test |
|
|
90
|
+
| **Shell** | bash, parallel execute, background tasks |
|
|
91
|
+
| **Git & GitHub** | commit, diff, PR, issues, code search |
|
|
92
|
+
| **Web** | search, fetch, browser automation |
|
|
93
|
+
| **Research** | arXiv, Semantic Scholar, HuggingFace, NASA, DOI |
|
|
94
|
+
| **Data** | CSV read/query/write, transforms, reports, invoices |
|
|
95
|
+
| **Containers** | Docker build/run/compose, Terraform |
|
|
96
|
+
| **VFX** | GLSL shaders, FFmpeg, ImageMagick, Blender, procedural textures |
|
|
97
|
+
| **IDE** | MCP server, ACP server, LSP bridge |
|
|
98
|
+
| **Meta** | subagents, worktrees, planner, memory, sessions |
|
|
99
|
+
|
|
100
|
+
## 20 Providers
|
|
101
|
+
|
|
102
|
+
| Provider | Cost | Local? |
|
|
103
|
+
|----------|------|--------|
|
|
104
|
+
| **Embedded (llama.cpp)** | **Free** | Yes |
|
|
105
|
+
| **Ollama** | **Free** | Yes |
|
|
106
|
+
| **LM Studio** | **Free** | Yes |
|
|
107
|
+
| **Jan** | **Free** | Yes |
|
|
108
|
+
| DeepSeek | $0.27/M in | Cloud |
|
|
109
|
+
| SambaNova | $0.50/M in | Cloud |
|
|
110
|
+
| Cerebras | $0.60/M in | Cloud |
|
|
111
|
+
| Groq | $0.59/M in | Cloud |
|
|
112
|
+
| NVIDIA NIM | $0.80/M in | Cloud |
|
|
113
|
+
| Together AI | $0.88/M in | Cloud |
|
|
114
|
+
| Fireworks AI | $0.90/M in | Cloud |
|
|
115
|
+
| Google (Gemini) | $1.25/M in | Cloud |
|
|
116
|
+
| Mistral | $2.00/M in | Cloud |
|
|
117
|
+
| OpenAI (GPT) | $2.00/M in | Cloud |
|
|
118
|
+
| Cohere | $2.50/M in | Cloud |
|
|
119
|
+
| Anthropic (Claude) | $3.00/M in | Cloud |
|
|
120
|
+
| xAI (Grok) | $3.00/M in | Cloud |
|
|
121
|
+
| Perplexity | $3.00/M in | Cloud |
|
|
122
|
+
| OpenRouter | varies | Cloud |
|
|
123
|
+
| K:BOT Local | **Free** | Yes |
|
|
124
|
+
|
|
125
|
+
All auto-detected via environment variables. Or run `kbot auth` for interactive setup.
|
|
126
|
+
|
|
127
|
+
## Local Mode
|
|
128
|
+
|
|
129
|
+
No API key needed. No data leaves your machine.
|
|
77
130
|
|
|
78
131
|
```bash
|
|
79
|
-
|
|
80
|
-
kbot
|
|
81
|
-
|
|
82
|
-
|
|
132
|
+
# Use Ollama (if installed)
|
|
133
|
+
kbot local
|
|
134
|
+
|
|
135
|
+
# Or run models directly — embedded llama.cpp, no external service
|
|
136
|
+
kbot models pull llama3.1-8b
|
|
137
|
+
kbot local --embedded
|
|
138
|
+
|
|
139
|
+
# GPU-accelerated: Metal (Mac), CUDA (Linux/Windows), Vulkan
|
|
83
140
|
```
|
|
84
141
|
|
|
85
|
-
##
|
|
86
|
-
|
|
87
|
-
Auto-routed or manual with `kbot --agent <name>`:
|
|
88
|
-
|
|
89
|
-
**Core**: kernel, researcher, coder, writer, analyst
|
|
90
|
-
**Extended**: aesthete, guardian, curator, strategist, infrastructure, quant, investigator, oracle, chronist, sage, communicator, adapter
|
|
91
|
-
**Domain**: physicist, mathematician, biologist, economist, psychologist, engineer, medic, linguist, ethicist, educator, diplomat
|
|
92
|
-
**Creative**: creative, developer, hacker, operator, dreamer
|
|
93
|
-
**Systems**: session, scholar, auditor, benchmarker, synthesizer, debugger
|
|
94
|
-
|
|
95
|
-
## Features
|
|
96
|
-
|
|
97
|
-
- **214 Tools** — File ops, bash, git, GitHub, web search, Jupyter, Docker, browser, MCP, PyPI, CRAN, Cargo, arXiv, HuggingFace, NASA, API testing, data queries, math, LaTeX, Terraform
|
|
98
|
-
- **Local-First** — File reads, git, grep run instantly without an API call
|
|
99
|
-
- **Learning Engine** — Patterns, solutions, and user preferences cached across sessions
|
|
100
|
-
- **Mimic Matrix** — Code like Claude Code, Cursor, Copilot, Next.js, React, Rust, Python
|
|
101
|
-
- **Autonomous Planner** — Complex tasks get broken into steps, executed, and verified
|
|
102
|
-
- **Subagent System** — Parallel workers for research, coding, and analysis
|
|
103
|
-
- **Hooks & Plugins** — Pre/post tool hooks and custom plugins
|
|
104
|
-
- **Sessions** — Save, resume, and share conversations
|
|
105
|
-
|
|
106
|
-
## Providers
|
|
107
|
-
|
|
108
|
-
| Provider | Cost | Setup |
|
|
109
|
-
|----------|------|-------|
|
|
110
|
-
| Anthropic (Claude) | $3-15/M tokens | `ANTHROPIC_API_KEY` |
|
|
111
|
-
| OpenAI (GPT) | $2-8/M tokens | `OPENAI_API_KEY` |
|
|
112
|
-
| Google (Gemini) | $1.25-10/M tokens | `GOOGLE_API_KEY` |
|
|
113
|
-
| Mistral | $2-6/M tokens | `MISTRAL_API_KEY` |
|
|
114
|
-
| xAI (Grok) | $3-15/M tokens | `XAI_API_KEY` |
|
|
115
|
-
| DeepSeek | $0.27-1.10/M tokens | `DEEPSEEK_API_KEY` |
|
|
116
|
-
| Groq | $0.59-0.79/M tokens | `GROQ_API_KEY` |
|
|
117
|
-
| Together AI | $0.88/M tokens | `TOGETHER_API_KEY` |
|
|
118
|
-
| Fireworks AI | $0.90/M tokens | `FIREWORKS_API_KEY` |
|
|
119
|
-
| Perplexity | $3-15/M tokens | `PERPLEXITY_API_KEY` |
|
|
120
|
-
| Cohere | $2.5-10/M tokens | `COHERE_API_KEY` |
|
|
121
|
-
| NVIDIA NIM | $0.80-1.20/M tokens | `NVIDIA_API_KEY` |
|
|
122
|
-
| SambaNova | $0.50-1/M tokens | `SAMBANOVA_API_KEY` |
|
|
123
|
-
| Cerebras | $0.60/M tokens | `CEREBRAS_API_KEY` |
|
|
124
|
-
| OpenRouter | varies by model | `OPENROUTER_API_KEY` |
|
|
125
|
-
| Ollama (Local) | **Free** | `ollama serve` |
|
|
126
|
-
| LM Studio (Local) | **Free** | Open LM Studio → Start Server |
|
|
127
|
-
| Jan (Local) | **Free** | Open Jan → Enable API Server |
|
|
128
|
-
| K:BOT Local | **Free** | `kbot gateway start` |
|
|
129
|
-
|
|
130
|
-
All 19 providers auto-detected via env vars. Or run `kbot auth` for interactive setup.
|
|
131
|
-
|
|
132
|
-
## MCP Server (IDE Integration)
|
|
142
|
+
## IDE Integration
|
|
133
143
|
|
|
134
144
|
```json
|
|
135
145
|
{
|
|
@@ -141,72 +151,65 @@ All 19 providers auto-detected via env vars. Or run `kbot auth` for interactive
|
|
|
141
151
|
}
|
|
142
152
|
```
|
|
143
153
|
|
|
144
|
-
Works with Claude Code, Cursor, VS Code, Windsurf, Zed, Neovim. Exposes
|
|
145
|
-
|
|
146
|
-
## HTTP Server
|
|
147
|
-
|
|
148
|
-
```bash
|
|
149
|
-
kbot serve --port 7437 --token mysecret
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
REST API exposing all 214 tools for any LLM or automation pipeline.
|
|
153
|
-
|
|
154
|
-
## Use Everywhere
|
|
155
|
-
|
|
156
|
-
| Environment | How |
|
|
157
|
-
|-------------|-----|
|
|
158
|
-
| **Terminal** | `npm install -g @kernel.chat/kbot` |
|
|
159
|
-
| **Docker** | `docker run -it isaacsight/kbot` |
|
|
160
|
-
| **VS Code / Cursor** | MCP server: `kbot ide mcp` |
|
|
161
|
-
| **JetBrains IDEs** | ACP server: `kbot ide acp` |
|
|
162
|
-
| **Neovim / Zed** | MCP server config |
|
|
163
|
-
| **GitHub Actions** | See `action.yml` in repo |
|
|
164
|
-
| **REST API** | `kbot serve --port 7437` |
|
|
165
|
-
| **Railway** | One-click deploy with `railway.toml` |
|
|
166
|
-
| **Replit** | Import repo, auto-configured |
|
|
167
|
-
| **CI/CD** | `npx @kernel.chat/kbot "review this diff"` |
|
|
154
|
+
Works with Claude Code, Cursor, VS Code, Windsurf, Zed, Neovim. Exposes file ops, bash, git, search, planning, and more.
|
|
168
155
|
|
|
169
156
|
## Commands
|
|
170
157
|
|
|
171
|
-
| Command |
|
|
158
|
+
| Command | What it does |
|
|
172
159
|
|---------|-------------|
|
|
173
160
|
| `kbot` | Interactive REPL |
|
|
174
161
|
| `kbot "prompt"` | One-shot execution |
|
|
175
162
|
| `kbot auth` | Configure API key |
|
|
176
|
-
| `kbot local` | Use local AI
|
|
177
|
-
| `kbot
|
|
178
|
-
| `kbot
|
|
163
|
+
| `kbot local` | Use local AI (Ollama, embedded, LM Studio, Jan) |
|
|
164
|
+
| `kbot audit <repo>` | Security + quality audit of any GitHub repo |
|
|
165
|
+
| `kbot contribute <repo>` | Find good-first-issues and quick wins |
|
|
166
|
+
| `kbot serve` | Start HTTP REST server |
|
|
167
|
+
| `kbot ide mcp` | Start MCP server for IDEs |
|
|
168
|
+
| `kbot doctor` | 10-point health check |
|
|
179
169
|
| `/agent <name>` | Switch specialist |
|
|
180
|
-
| `/
|
|
181
|
-
| `/plan <task>` | Autonomous plan + execute |
|
|
170
|
+
| `/plan <task>` | Autonomous multi-step execution |
|
|
182
171
|
| `/save` / `/resume` | Session management |
|
|
172
|
+
| `/share` | Share conversation as GitHub Gist |
|
|
173
|
+
| `/tutorial` | Guided walkthrough |
|
|
174
|
+
|
|
175
|
+
## Under the Hood
|
|
176
|
+
|
|
177
|
+
kbot's agent loop runs 10 always-on cognition modules based on peer-reviewed research:
|
|
178
|
+
|
|
179
|
+
| Module | Paper | What it does |
|
|
180
|
+
|--------|-------|-------------|
|
|
181
|
+
| Free Energy | Friston, 2010 | Explore vs exploit decisions |
|
|
182
|
+
| Integrated Information | Tononi, 2004 | Multi-agent synthesis quality (phi) |
|
|
183
|
+
| Predictive Processing | Clark, 2013 | Anticipates your next action |
|
|
184
|
+
| Autopoiesis | Maturana & Varela, 1972 | Self-healing component monitoring |
|
|
185
|
+
| Strange Loops | Hofstadter, 1979 | Meta-cognition depth tracking |
|
|
186
|
+
| Error Correction | Gates, 2023 | Targeted error classification + fix |
|
|
187
|
+
| Entropy Context | Vopson, 2022 | Information decay detection |
|
|
188
|
+
| Godel Limits | Godel/UBC | Stuck-loop detection |
|
|
189
|
+
| Simulation | Wolpert, 2008 | Change impact prediction |
|
|
190
|
+
| Emergent Swarm | Project Sid, 2024 | Dynamic role discovery |
|
|
191
|
+
|
|
192
|
+
These aren't metaphors. They're TypeScript modules with paper citations in the headers. See `packages/kbot/src/`.
|
|
183
193
|
|
|
184
194
|
## Security
|
|
185
195
|
|
|
186
196
|
- API keys encrypted at rest (AES-256-CBC)
|
|
187
197
|
- Destructive operations require confirmation
|
|
188
|
-
-
|
|
198
|
+
- Shell commands sandboxed with blocklist
|
|
189
199
|
- Tool execution timeout (5 min)
|
|
190
|
-
- Config restricted to owner (chmod 600)
|
|
191
|
-
|
|
192
|
-
## Web Companion
|
|
193
|
-
|
|
194
|
-
[kernel.chat](https://kernel.chat) — visual interface with 39 agents. Free (20 msgs/day).
|
|
200
|
+
- Config files restricted to owner (chmod 600)
|
|
195
201
|
|
|
196
202
|
## Contributing
|
|
197
203
|
|
|
198
|
-
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, adding tools, and
|
|
204
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, adding tools, and creating specialist agents.
|
|
199
205
|
|
|
200
206
|
## Links
|
|
201
207
|
|
|
202
|
-
-
|
|
203
|
-
-
|
|
204
|
-
-
|
|
205
|
-
-
|
|
206
|
-
-
|
|
207
|
-
- **Issues**: [Report a bug](https://github.com/isaacsight/kernel/issues)
|
|
208
|
-
- **Email**: [support@kernel.chat](mailto:support@kernel.chat)
|
|
209
|
-
- **X/Twitter**: [@isaacsight](https://x.com/isaacsight)
|
|
208
|
+
- [kernel.chat](https://kernel.chat) — Web companion
|
|
209
|
+
- [npm](https://www.npmjs.com/package/@kernel.chat/kbot)
|
|
210
|
+
- [Docker Hub](https://hub.docker.com/r/isaacsight/kbot)
|
|
211
|
+
- [Discord](https://discord.gg/pYJn3hBqnz)
|
|
212
|
+
- [Issues](https://github.com/isaacsight/kernel/issues)
|
|
210
213
|
|
|
211
214
|
## License
|
|
212
215
|
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAwBA,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAc1E,OAAO,EAA8E,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAkEhI,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,uDAAuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,iDAAiD;IACjD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,sDAAsD;IACtD,UAAU,CAAC,EAAE,aAAa,CAAA;IAC1B,iFAAiF;IACjF,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAGD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CAC1E;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAwBA,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAc1E,OAAO,EAA8E,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAkEhI,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,uDAAuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,iDAAiD;IACjD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,sDAAsD;IACtD,UAAU,CAAC,EAAE,aAAa,CAAA;IAC1B,iFAAiF;IACjF,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAGD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CAC1E;AA8pBD,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,aAAa,CAAC,CAuhBxB;AAGD,6CAA6C;AAC7C,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAkEf"}
|
package/dist/agent.js
CHANGED
|
@@ -232,15 +232,20 @@ async function callOpenAICompat(apiKey, apiUrl, model, systemContext, messages,
|
|
|
232
232
|
: tc.function.arguments || {},
|
|
233
233
|
}));
|
|
234
234
|
}
|
|
235
|
-
// Fallback:
|
|
236
|
-
// instead of structured tool_calls.
|
|
235
|
+
// Fallback: Local models sometimes emit tool calls as raw JSON, tool_code blocks,
|
|
236
|
+
// or natural language descriptions instead of structured tool_calls.
|
|
237
|
+
// Parse these so tools still work with Ollama and other local providers.
|
|
237
238
|
if (!result.tool_calls && content && tools && tools.length > 0) {
|
|
238
239
|
const toolNames = tools.map(t => t.function?.name || t.name).filter(Boolean);
|
|
239
240
|
const parsed = tryParseInlineToolCalls(content, toolNames);
|
|
240
241
|
if (parsed.length > 0) {
|
|
241
242
|
result.tool_calls = parsed;
|
|
242
|
-
// Remove
|
|
243
|
-
result.content = content
|
|
243
|
+
// Remove parsed tool invocations from displayed content
|
|
244
|
+
result.content = content
|
|
245
|
+
.replace(/```(?:json)?\s*\{[\s\S]*?\}\s*```/g, '')
|
|
246
|
+
.replace(/```(?:tool_code|tool_call)\s*\n[\s\S]*?```/g, '')
|
|
247
|
+
.replace(/\{[\s\S]*?"name"\s*:\s*"[a-z_]+[\s\S]*?\}/g, '')
|
|
248
|
+
.trim();
|
|
244
249
|
}
|
|
245
250
|
}
|
|
246
251
|
return result;
|
|
@@ -267,8 +272,143 @@ function tryParseInlineToolCalls(content, knownTools) {
|
|
|
267
272
|
calls.push(parsed);
|
|
268
273
|
}
|
|
269
274
|
}
|
|
275
|
+
if (calls.length > 0)
|
|
276
|
+
return calls;
|
|
277
|
+
// Pattern 3: tool_code / tool_call blocks — Ollama models sometimes emit these
|
|
278
|
+
// ```tool_code\nbash -c "echo hello"\n``` or ```tool_call\nread_file path.ts\n```
|
|
279
|
+
const toolCodePattern = /```(?:tool_code|tool_call)\s*\n([\s\S]*?)```/g;
|
|
280
|
+
while ((match = toolCodePattern.exec(content)) !== null) {
|
|
281
|
+
const block = match[1].trim();
|
|
282
|
+
const parsed = parseToolCodeBlock(block, knownTools);
|
|
283
|
+
if (parsed)
|
|
284
|
+
calls.push(parsed);
|
|
285
|
+
}
|
|
286
|
+
if (calls.length > 0)
|
|
287
|
+
return calls;
|
|
288
|
+
// Pattern 4: Natural language tool invocations — "I'll use write_file to create..."
|
|
289
|
+
// followed by arguments like paths and content in code blocks
|
|
290
|
+
for (const toolName of knownTools) {
|
|
291
|
+
const nlPattern = new RegExp(`(?:use|call|invoke|execute|run)\\s+(?:the\\s+)?(?:\`)?${toolName}(?:\`)?`, 'i');
|
|
292
|
+
if (nlPattern.test(content)) {
|
|
293
|
+
const parsed = parseNaturalLanguageTool(content, toolName, knownTools);
|
|
294
|
+
if (parsed)
|
|
295
|
+
calls.push(parsed);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
270
298
|
return calls;
|
|
271
299
|
}
|
|
300
|
+
/** Parse a tool_code block into a tool call (e.g. `bash -c "echo hello"` or `write_file path content`) */
|
|
301
|
+
function parseToolCodeBlock(block, knownTools) {
|
|
302
|
+
const lines = block.split('\n');
|
|
303
|
+
const firstLine = lines[0].trim();
|
|
304
|
+
// Direct tool name at start: "read_file src/index.ts"
|
|
305
|
+
for (const tool of knownTools) {
|
|
306
|
+
if (firstLine.startsWith(tool + ' ') || firstLine === tool) {
|
|
307
|
+
const args = firstLine.slice(tool.length).trim();
|
|
308
|
+
return {
|
|
309
|
+
id: `inline_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`,
|
|
310
|
+
name: tool,
|
|
311
|
+
arguments: buildArgsFromToolCode(tool, args, lines.slice(1).join('\n')),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
// Bare shell commands → route to bash tool
|
|
316
|
+
if (knownTools.includes('bash')) {
|
|
317
|
+
// Common shell patterns: command at start of line
|
|
318
|
+
const shellPattern = /^(?:cd|ls|cat|mkdir|cp|mv|rm|echo|git|npm|npx|node|python|pip|cargo|go|make|curl|wget|find|grep|sed|awk|chmod|chown|touch|tar|unzip)\b/;
|
|
319
|
+
if (shellPattern.test(firstLine)) {
|
|
320
|
+
return {
|
|
321
|
+
id: `inline_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`,
|
|
322
|
+
name: 'bash',
|
|
323
|
+
arguments: { command: block },
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
/** Build structured args from a tool_code invocation */
|
|
330
|
+
function buildArgsFromToolCode(tool, argStr, restContent) {
|
|
331
|
+
switch (tool) {
|
|
332
|
+
case 'read_file':
|
|
333
|
+
case 'list_directory':
|
|
334
|
+
return { path: argStr || '.' };
|
|
335
|
+
case 'write_file':
|
|
336
|
+
return { path: argStr, content: restContent };
|
|
337
|
+
case 'bash':
|
|
338
|
+
return { command: argStr || restContent };
|
|
339
|
+
case 'grep':
|
|
340
|
+
// "grep pattern path"
|
|
341
|
+
const gparts = argStr.split(/\s+/, 2);
|
|
342
|
+
return { pattern: gparts[0] || argStr, path: gparts[1] || '.' };
|
|
343
|
+
case 'git_status':
|
|
344
|
+
case 'git_diff':
|
|
345
|
+
case 'git_log':
|
|
346
|
+
return {};
|
|
347
|
+
case 'git_commit':
|
|
348
|
+
return { message: argStr || restContent };
|
|
349
|
+
case 'web_search':
|
|
350
|
+
return { query: argStr || restContent };
|
|
351
|
+
default:
|
|
352
|
+
return argStr ? { input: argStr } : {};
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/** Extract tool arguments from natural language descriptions */
|
|
356
|
+
function parseNaturalLanguageTool(content, toolName, _knownTools) {
|
|
357
|
+
// Look for file paths and code blocks following the tool mention
|
|
358
|
+
const pathMatch = content.match(/(?:file|path)\s*[:=]?\s*[`"']([^`"'\n]+)[`"']/i)
|
|
359
|
+
|| content.match(/(?:to|at|in)\s+[`"']([^`"'\n]+\.\w+)[`"']/i)
|
|
360
|
+
|| content.match(/[`"']((?:\.\/|\/|src\/|packages\/)[^`"'\n]+)[`"']/i);
|
|
361
|
+
const codeMatch = content.match(/```\w*\n([\s\S]*?)```/);
|
|
362
|
+
const path = pathMatch?.[1];
|
|
363
|
+
const code = codeMatch?.[1];
|
|
364
|
+
const args = {};
|
|
365
|
+
switch (toolName) {
|
|
366
|
+
case 'write_file':
|
|
367
|
+
if (path)
|
|
368
|
+
args.path = path;
|
|
369
|
+
if (code)
|
|
370
|
+
args.content = code;
|
|
371
|
+
if (!path)
|
|
372
|
+
return null; // need at least a path
|
|
373
|
+
break;
|
|
374
|
+
case 'read_file':
|
|
375
|
+
case 'list_directory':
|
|
376
|
+
if (path)
|
|
377
|
+
args.path = path;
|
|
378
|
+
else
|
|
379
|
+
return null;
|
|
380
|
+
break;
|
|
381
|
+
case 'bash':
|
|
382
|
+
if (code)
|
|
383
|
+
args.command = code.trim();
|
|
384
|
+
else
|
|
385
|
+
return null;
|
|
386
|
+
break;
|
|
387
|
+
case 'grep':
|
|
388
|
+
if (path)
|
|
389
|
+
args.path = path;
|
|
390
|
+
const patternMatch = content.match(/(?:for|pattern)\s*[:=]?\s*[`"']([^`"'\n]+)[`"']/i);
|
|
391
|
+
if (patternMatch)
|
|
392
|
+
args.pattern = patternMatch[1];
|
|
393
|
+
else
|
|
394
|
+
return null;
|
|
395
|
+
break;
|
|
396
|
+
case 'web_search':
|
|
397
|
+
const queryMatch = content.match(/(?:search|query|look up)\s+(?:for\s+)?[`"']([^`"'\n]+)[`"']/i);
|
|
398
|
+
if (queryMatch)
|
|
399
|
+
args.query = queryMatch[1];
|
|
400
|
+
else
|
|
401
|
+
return null;
|
|
402
|
+
break;
|
|
403
|
+
default:
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
id: `inline_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`,
|
|
408
|
+
name: toolName,
|
|
409
|
+
arguments: args,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
272
412
|
function tryParseToolJson(json, knownTools) {
|
|
273
413
|
try {
|
|
274
414
|
const obj = JSON.parse(json);
|
|
@@ -594,9 +734,39 @@ export async function runAgent(message, options = {}) {
|
|
|
594
734
|
const contextSnippet = options.context ? formatContextForPrompt(options.context) : '';
|
|
595
735
|
const memorySnippet = getMemoryPrompt();
|
|
596
736
|
const learningContext = buildFullLearningContext(message, process.cwd());
|
|
597
|
-
const PERSONA = `You are K:BOT
|
|
737
|
+
const PERSONA = `You are K:BOT — an AI that lives in the user's terminal. You are also an autonomous Agentic Software Engineer. Your goal is to solve complex engineering problems by interacting directly with the user's system, codebase, and toolchain.
|
|
738
|
+
|
|
739
|
+
## CORE PHILOSOPHY
|
|
740
|
+
|
|
741
|
+
1. **Act, Don't Just Advise.** Do not give the user snippets to copy-paste. Write complete files, run terminal commands, execute tests, and verify your own work.
|
|
742
|
+
2. **Read Before You Write.** Never blindly assume the state of the codebase. Always use tools to search directories, read existing file contents, and check git status before proposing changes.
|
|
743
|
+
3. **Surgical Precision.** When modifying existing code, do not rewrite the entire file unless necessary. Use targeted edits. Understand existing abstractions and adhere to the project's style.
|
|
744
|
+
4. **Autonomous Verification.** After writing code, run the build, linter, or test suite to prove it works. If it fails, read the error logs and fix it autonomously.
|
|
745
|
+
|
|
746
|
+
## THE AGENTIC WORKFLOW
|
|
747
|
+
|
|
748
|
+
For complex tasks, follow this strict workflow:
|
|
749
|
+
|
|
750
|
+
### Phase 1: Planning & Discovery
|
|
751
|
+
- Search the filesystem to understand the existing architecture.
|
|
752
|
+
- Identify all files that need to be created or modified.
|
|
753
|
+
- Present a clear, bulleted implementation plan and ask for approval.
|
|
754
|
+
|
|
755
|
+
### Phase 2: Execution
|
|
756
|
+
- Execute the approved plan step-by-step.
|
|
757
|
+
- Generate full, complete files for new components.
|
|
758
|
+
- Make targeted replacements in existing files.
|
|
759
|
+
- If you encounter unexpected complexity, STOP, write down the issue, and revise the plan.
|
|
760
|
+
|
|
761
|
+
### Phase 3: Verification
|
|
762
|
+
- Run the compiler, linter, or test suite.
|
|
763
|
+
- If errors occur, diagnose and fix them iteratively.
|
|
764
|
+
- Summarize the changes made and verification steps taken.
|
|
765
|
+
|
|
766
|
+
## COMMUNICATION STYLE
|
|
767
|
+
|
|
768
|
+
Talk naturally — be direct, concise, and conversational. You're a skilled colleague, not a corporate chatbot.
|
|
598
769
|
|
|
599
|
-
Conversation style:
|
|
600
770
|
- Be casual and natural. Use short sentences. Don't over-explain.
|
|
601
771
|
- When the user asks a question, answer it directly. Lead with the answer, not the reasoning.
|
|
602
772
|
- When chatting casually, just chat. Not everything needs tools or code.
|
|
@@ -604,6 +774,7 @@ Conversation style:
|
|
|
604
774
|
- Match the user's energy. Short question → short answer. Detailed question → detailed response.
|
|
605
775
|
- Never say "I'd be happy to help with that" or "Certainly!" or "Great question!" — just do it.
|
|
606
776
|
- Don't repeat back what the user said. Don't restate the problem before solving it.
|
|
777
|
+
- Be proactive but never reckless. Always ask for permission before running destructive commands.
|
|
607
778
|
|
|
608
779
|
How you work with tools:
|
|
609
780
|
- When asked to create, fix, or build something — do it directly with your tools. Don't describe what you would do, just do it.
|
|
@@ -612,6 +783,8 @@ How you work with tools:
|
|
|
612
783
|
- After completing a task, briefly say what you did and where the output is.
|
|
613
784
|
- You run commands yourself. You never tell the user to run something.
|
|
614
785
|
|
|
786
|
+
Your primary directive: **Do the work for the user, verify it works, and report back when finished.**
|
|
787
|
+
|
|
615
788
|
Always quote file paths that contain spaces. Never reference internal system names.`;
|
|
616
789
|
// Inject repo map for code-related tasks (helps AI navigate the codebase)
|
|
617
790
|
let repoMapSnippet = '';
|
|
@@ -702,8 +875,10 @@ Always quote file paths that contain spaces. Never reference internal system nam
|
|
|
702
875
|
const isExplicitModel = options.model && !['auto', 'haiku', 'fast', 'sonnet', 'default'].includes(options.model);
|
|
703
876
|
const speed = options.model === 'haiku' || options.model === 'fast' ? 'fast' : 'default';
|
|
704
877
|
const model = isExplicitModel ? options.model : getProviderModel(provider, speed, originalMessage);
|
|
705
|
-
//
|
|
706
|
-
|
|
878
|
+
// Send tool definitions to ALL providers — including Ollama.
|
|
879
|
+
// Modern Ollama models (llama3.1+, qwen2.5, gemma3) support function calling.
|
|
880
|
+
// For models that don't, the inline tool-call parser catches JSON/text patterns.
|
|
881
|
+
const byokTools = tools.map(t => ({
|
|
707
882
|
name: t.name,
|
|
708
883
|
description: t.description,
|
|
709
884
|
input_schema: t.input_schema,
|