saarthiclaw 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +287 -2
- package/dist/chunks/chunk-2GDAWRT7.js +339 -0
- package/dist/chunks/chunk-2OOG5CBM.js +12 -0
- package/dist/chunks/chunk-3UTSY2MH.js +138 -0
- package/dist/chunks/chunk-4MPWZPGX.js +720 -0
- package/dist/chunks/chunk-BTFIQWAE.js +185 -0
- package/dist/chunks/chunk-DORYMXNC.js +93 -0
- package/dist/chunks/chunk-EWADWZYM.js +315 -0
- package/dist/chunks/chunk-G6GCAEKE.js +64 -0
- package/dist/chunks/chunk-GNAQO3JX.js +385 -0
- package/dist/chunks/chunk-GVDXGKLD.js +82 -0
- package/dist/chunks/chunk-HGBZ55ND.js +80 -0
- package/dist/chunks/chunk-HNAZBEDV.js +354 -0
- package/dist/chunks/chunk-IT46XDPQ.js +100 -0
- package/dist/chunks/chunk-LLHZUSMZ.js +146 -0
- package/dist/chunks/chunk-MMIJKDOU.js +35 -0
- package/dist/chunks/chunk-SANS45ER.js +41 -0
- package/dist/chunks/chunk-XTVJWMUH.js +143 -0
- package/dist/chunks/config-PA5NJ37O.js +27 -0
- package/dist/chunks/doctor-333IEMCL.js +149 -0
- package/dist/chunks/errors-ZXTAHCZI.js +13 -0
- package/dist/chunks/history-IWDIOWLB.js +53 -0
- package/dist/chunks/init-Z4YC3G7V.js +232 -0
- package/dist/chunks/orchestrator-QCIY6FLH.js +17 -0
- package/dist/chunks/orchestrator-SDAA5TOH.js +18 -0
- package/dist/chunks/orchestrator-WXGJJEJW.js +26 -0
- package/dist/chunks/prompter-AAH4A3BG.js +14 -0
- package/dist/chunks/session-UUHCIT66.js +19 -0
- package/dist/chunks/signals-ZO4DZ4OK.js +18 -0
- package/dist/chunks/telegram-X36RUESQ.js +470 -0
- package/dist/chunks/wakeup-I7FQO5BS.js +126 -0
- package/dist/chunks/workspace-PFJUEHAB.js +10 -0
- package/dist/index.js +166 -0
- package/package.json +66 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. This project follows [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
## 0.1.0 — 2026-11-17
|
|
6
|
+
|
|
7
|
+
First public release on npm.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- `saarthiclaw` binary for Node.js ≥ 22.12 (no Bun required); `saarthiclaw-build` kept as an alias.
|
|
11
|
+
- Commands: `wakeup` (aliases `wake`, `start`; also the default in a terminal), `init`, `doctor`, `ask`, `plan`, `agent`, `telegram`, `history`.
|
|
12
|
+
- Global options: `--cwd`, `--model`, `--allow-shell`, `--debug`, `--no-banner`, `--version`, `--help`.
|
|
13
|
+
- Configuration resolution: flags → env → project `.env` → `.saarthiclaw/config.json` → `~/.saarthiclaw/config.json`, validated with zod.
|
|
14
|
+
- Guided, idempotent `init` that writes secrets to `.env`, settings to `.saarthiclaw/config.json`, updates `.gitignore` and can add an npm script.
|
|
15
|
+
- Project brief (package.json summary, stack hints, shallow file tree, README excerpt) and mode-specific instructions injected into every agent.
|
|
16
|
+
- Approval flow with risk labels, colourised diffs, deletion warnings, verbatim shell commands, extra confirmation for high-risk items and a final "Apply N changes?" step.
|
|
17
|
+
- Transactional apply with rollback of file changes on failure.
|
|
18
|
+
- Audit trail in `.saarthiclaw/logs/actions.jsonl` and `saarthiclaw history`.
|
|
19
|
+
- Friendly error messages for missing/invalid keys, credits, rate limits (with automatic retries), unknown models, network failures and timeouts.
|
|
20
|
+
- Ctrl+C cancels a running AI task cleanly and discards staged changes.
|
|
21
|
+
|
|
22
|
+
### Reliability
|
|
23
|
+
- Planning always produces a plan, even when a model loops on tools; repeated identical tool calls are short-circuited and every run's final step must produce an answer.
|
|
24
|
+
- Ask mode reads the real code instead of relying on the README.
|
|
25
|
+
|
|
26
|
+
### Security
|
|
27
|
+
- Shell execution is off by default everywhere; destructive commands are flagged.
|
|
28
|
+
- Workspace jail (no `..`, outside absolute paths or escaping symlinks) and a fixed secret blocklist (`.env*`, keys, `.npmrc`, `.saarthiclaw/`).
|
|
29
|
+
- Telegram: every update from a non-owner is dropped by a global guard.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hritik Vishnoi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,288 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SaarthiClaw
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**An AI developer assistant that lives in your project's terminal — the AI proposes, you approve.**
|
|
4
|
+
|
|
5
|
+
SaarthiClaw is like a very capable intern who always asks the senior first.
|
|
6
|
+
It reads your codebase, answers questions, drafts plans and stages code changes — but nothing touches your disk until you have reviewed the diff and said yes.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install --save-dev saarthiclaw
|
|
10
|
+
npx saarthiclaw init # one-time setup
|
|
11
|
+
npx saarthiclaw # wake it up
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Contents
|
|
17
|
+
|
|
18
|
+
- [Install](#install)
|
|
19
|
+
- [60-second quick start](#60-second-quick-start)
|
|
20
|
+
- [The modes](#the-modes)
|
|
21
|
+
- [How approval works](#how-approval-works)
|
|
22
|
+
- [Safety model](#safety-model)
|
|
23
|
+
- [Configuration](#configuration)
|
|
24
|
+
- [Command reference](#command-reference)
|
|
25
|
+
- [Telegram setup](#telegram-setup)
|
|
26
|
+
- [Free models and rate limits](#free-models-and-rate-limits)
|
|
27
|
+
- [Troubleshooting](#troubleshooting)
|
|
28
|
+
- [FAQ](#faq)
|
|
29
|
+
- [Roadmap](#roadmap)
|
|
30
|
+
- [Contributing](#contributing)
|
|
31
|
+
- [Publishing (maintainers)](#publishing-maintainers)
|
|
32
|
+
- [License](#license)
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
Requires **Node.js 22.12 or newer** (no Bun needed). Works on macOS, Linux and Windows.
|
|
37
|
+
|
|
38
|
+
As a dev dependency of the project you want help with (recommended — it becomes that project's "plugin"):
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
cd my-project
|
|
42
|
+
npm install --save-dev saarthiclaw
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Or globally:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install -g saarthiclaw
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
You also need an [OpenRouter API key](https://openrouter.ai/keys) (free models are available).
|
|
52
|
+
|
|
53
|
+
## 60-second quick start
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npx saarthiclaw init # paste your OpenRouter key, pick a model, choose safety options
|
|
57
|
+
npx saarthiclaw wakeup # banner → pick CLI (Ask / Plan / Agent) or Telegram
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`init` writes your key to the project's `.env`, settings to `.saarthiclaw/config.json`, makes sure both are git-ignored, and (optionally) adds an npm script so `npm run saarthiclaw` opens the menu.
|
|
61
|
+
|
|
62
|
+
Check everything is wired up with:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npx saarthiclaw doctor
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## The modes
|
|
69
|
+
|
|
70
|
+
### 💬 Ask — questions about your codebase (read-only)
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npx saarthiclaw ask "Where is the JWT verified and what happens when it expires?"
|
|
74
|
+
npx saarthiclaw ask "Summarise the database layer" --save notes.md
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Ask uses read-only tools (read / list / search files, analyse structure) and cites the file paths it relied on.
|
|
78
|
+
With `--save`, the answer is staged as a Markdown file and goes through the normal approval flow.
|
|
79
|
+
Web search is added automatically when a `FIRECRAWL_API_KEY` is configured.
|
|
80
|
+
|
|
81
|
+
### ✍️ Plan — a step-by-step plan, then execution
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
npx saarthiclaw plan "Add rate limiting to the public API routes"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
1. SaarthiClaw researches the code (read-only) and prints a numbered plan with complexity labels.
|
|
88
|
+
2. Optionally save it as `PLAN.md`.
|
|
89
|
+
3. Tick the steps you want (space toggles), confirm.
|
|
90
|
+
4. Each selected step runs with the agent (`Step 2/5 — Add middleware`), all sharing one staging area.
|
|
91
|
+
5. One approval screen at the end shows every staged change from every step.
|
|
92
|
+
|
|
93
|
+
### 🕵️ Agent — make changes with your sign-off
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx saarthiclaw agent "Add a /health route that returns the package version"
|
|
97
|
+
npx saarthiclaw agent "Upgrade zod usage to the new API and run the tests" --allow-shell
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The agent reads files, then **stages** creates, modifications, deletions, new folders and (only if you allowed it) shell commands.
|
|
101
|
+
You see progress (`✓ read_file {"path":"src/server.ts"}`), a summary table of staged actions with risk labels, and then the approval flow.
|
|
102
|
+
Press **Ctrl+C** during a run to cancel cleanly: staging is discarded and nothing is written.
|
|
103
|
+
|
|
104
|
+
### 📱 Telegram — the same engine from your phone
|
|
105
|
+
|
|
106
|
+
Pick **Telegram** in the menu (or run `npx saarthiclaw telegram`). Commands: `/ask`, `/agent`, `/plan`, `/help`. Only the configured owner can use the bot. See [Telegram setup](#telegram-setup).
|
|
107
|
+
|
|
108
|
+
## How approval works
|
|
109
|
+
|
|
110
|
+
After a run you get a table like:
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
Type Path / command Risk
|
|
114
|
+
────── ──────────────────────── ──────
|
|
115
|
+
create src/routes/health.ts LOW
|
|
116
|
+
modify src/server.ts MEDIUM
|
|
117
|
+
delete src/old-health.ts HIGH
|
|
118
|
+
shell npm test HIGH
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Then choose **Review one by one**, **Approve all** or **Reject all**:
|
|
122
|
+
|
|
123
|
+
- **Modifications** show a colourised unified diff (you can re-show it).
|
|
124
|
+
- **Deletions** show a clear red warning.
|
|
125
|
+
- **Shell commands** are shown verbatim, with warnings if they look destructive.
|
|
126
|
+
- **High-risk** items (deletions, shell commands) need a second, explicit "Really approve this?" — even after "Approve all".
|
|
127
|
+
- Every per-change prompt starts on **Reject**, so pressing Enter never approves by accident. Very fast repeated keypresses are ignored.
|
|
128
|
+
- Several edits to the same file are reviewed together as one item (labelled "N edits combined").
|
|
129
|
+
- You see a list of what will be applied and what will be skipped, then a final **"Apply 3 changes (skip 1)?"** confirmation, which defaults to **No**. Saying no writes nothing.
|
|
130
|
+
|
|
131
|
+
Risk levels: **low** = new file / new folder, **medium** = modify, **high** = delete or shell.
|
|
132
|
+
|
|
133
|
+
If applying a file change fails half-way, every file change from that batch is **rolled back** and shell commands are skipped.
|
|
134
|
+
|
|
135
|
+
## Safety model
|
|
136
|
+
|
|
137
|
+
| Guard | What it does |
|
|
138
|
+
| --- | --- |
|
|
139
|
+
| Shell **off** by default | The shell tool is not even offered to the model unless you pass `--allow-shell`, set `allowShellExecution: true`, or say yes to "Allow shell commands in this session?" at the start of Agent mode. Every command still needs per-command approval. |
|
|
140
|
+
| Destructive-command detection | `rm -rf`, `sudo`, `curl … \| sh`, `chmod -R`, `git push --force`, `git reset --hard`, `del /s`, paths outside the workspace, etc. are flagged in red. |
|
|
141
|
+
| Workspace jail | Every path from the model is resolved against the project root. `..` escapes, absolute paths outside the root, Windows drive/UNC paths and symlinks that point outside are rejected. |
|
|
142
|
+
| Secrets are invisible | `.env*`, `*.pem`, `*.key`, `id_rsa*`, `.npmrc`, `.ssh/`, `.aws/` and `.saarthiclaw/` can never be read, listed, written or deleted by tools. They are also never included in the project brief. |
|
|
143
|
+
| Size limits | Reads are capped (`maxFileSizeToRead`, 1 MiB) and tool output sent to the model is truncated (`maxToolOutputChars`, 20 000). |
|
|
144
|
+
| Audit log | Every staged / approved / rejected / applied / failed event is appended to `.saarthiclaw/logs/actions.jsonl` (timestamp, mode, type, path, risk, status — never file contents or commands). View it with `saarthiclaw history`. |
|
|
145
|
+
| Keys never logged | API keys are masked in `init`, `doctor` and `--debug` output. |
|
|
146
|
+
|
|
147
|
+
## Configuration
|
|
148
|
+
|
|
149
|
+
Resolution order, first match wins per key:
|
|
150
|
+
|
|
151
|
+
**CLI flags → environment variables → project `.env` → `.saarthiclaw/config.json` (project) → `~/.saarthiclaw/config.json` (user) → defaults**
|
|
152
|
+
|
|
153
|
+
### Environment variables (put secrets in the project `.env`)
|
|
154
|
+
|
|
155
|
+
| Variable | Required | Default | Purpose |
|
|
156
|
+
| --- | --- | --- | --- |
|
|
157
|
+
| `OPENROUTER_API_KEY` | yes | — | Your OpenRouter key |
|
|
158
|
+
| `OPENROUTER_DEFAULT_MODEL` | no | `qwen/qwen3-coder:free` | Model id |
|
|
159
|
+
| `FIRECRAWL_API_KEY` | no | — | Enables `web_search`, `web_crawl`, `fetch_url` tools |
|
|
160
|
+
| `TELEGRAM_BOT_TOKEN` | Telegram only | — | Bot token from @BotFather |
|
|
161
|
+
| `TELEGRAM_OWNER_ID` | Telegram only | — | Your numeric Telegram user id (legacy `TELEGRAM_BOT_ID` still works, with a deprecation note) |
|
|
162
|
+
| `SKILLS_DIRS` | no | — | Extra folders containing `SKILL.md` files (`:` or `;` separated) |
|
|
163
|
+
| `SAARTHICLAW_HOME` | no | `~/.saarthiclaw` | Location of the user config folder |
|
|
164
|
+
|
|
165
|
+
### Config file keys (`.saarthiclaw/config.json` or `~/.saarthiclaw/config.json`)
|
|
166
|
+
|
|
167
|
+
| Key | Default | Notes |
|
|
168
|
+
| --- | --- | --- |
|
|
169
|
+
| `model` | `qwen/qwen3-coder:free` | Same as `OPENROUTER_DEFAULT_MODEL` |
|
|
170
|
+
| `allowShellExecution` | `false` | Offer the shell tool by default |
|
|
171
|
+
| `maxSteps.ask` / `.plan` / `.agent` | `20` / `30` / `40` | Max tool-loop steps per run (plan = per step) |
|
|
172
|
+
| `excludePatterns` | `[]` | **Added** to the defaults `node_modules .git dist build .next .cache coverage *.log` |
|
|
173
|
+
| `maxFileSizeToRead` | `1048576` | Bytes |
|
|
174
|
+
| `maxToolOutputChars` | `20000` | Characters returned to the model per tool call |
|
|
175
|
+
| `context.maxReadmeChars` | `1500` | README excerpt in the project brief |
|
|
176
|
+
| `context.maxTreeLines` / `.maxTreeDepth` | `150` / `3` | File tree in the project brief |
|
|
177
|
+
| `context.maxBriefChars` | `8000` | Hard cap on the whole project brief |
|
|
178
|
+
| `skillsDirs` | `[]` | Same as `SKILLS_DIRS` |
|
|
179
|
+
|
|
180
|
+
Example:
|
|
181
|
+
|
|
182
|
+
```json
|
|
183
|
+
{
|
|
184
|
+
"model": "openai/gpt-oss-120b:free",
|
|
185
|
+
"allowShellExecution": false,
|
|
186
|
+
"maxSteps": { "agent": 30 },
|
|
187
|
+
"excludePatterns": ["fixtures", "*.snap"]
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Command reference
|
|
192
|
+
|
|
193
|
+
| Command | Behaviour |
|
|
194
|
+
| --- | --- |
|
|
195
|
+
| `saarthiclaw` | Same as `wakeup` in a terminal; prints help (exit 1) when not a TTY |
|
|
196
|
+
| `saarthiclaw wakeup` (aliases `wake`, `start`) | Banner → CLI / Telegram / Exit → Ask / Plan / Agent / Back. Ctrl+C or Esc at a prompt exits with a goodbye (exit 0) |
|
|
197
|
+
| `saarthiclaw init` | Interactive, idempotent setup |
|
|
198
|
+
| `saarthiclaw doctor [--offline]` | Checklist: Node, OS, root, config sources, key, model, live test call, Firecrawl, Telegram, shell setting, writable `.saarthiclaw/`. Exit 1 if a required check fails |
|
|
199
|
+
| `saarthiclaw ask "<question>" [--save file.md]` | Non-interactive answer (no prompts unless `--save`) |
|
|
200
|
+
| `saarthiclaw plan "<goal>"` | Plan mode with the goal pre-filled |
|
|
201
|
+
| `saarthiclaw agent "<task>"` | Agent mode with the task pre-filled |
|
|
202
|
+
| `saarthiclaw telegram` | Run the Telegram bot until Ctrl+C |
|
|
203
|
+
| `saarthiclaw history [--last N]` | Pretty-print the audit log (default 20) |
|
|
204
|
+
|
|
205
|
+
Global options: `--cwd <path>`, `--model <id>`, `--allow-shell`, `--debug`, `--no-banner`, `-v/--version`, `-h/--help`.
|
|
206
|
+
|
|
207
|
+
**Workspace root:** SaarthiClaw walks up from the current folder to the nearest directory containing `package.json` or `.git` and prints it once at startup. Override with `--cwd`.
|
|
208
|
+
|
|
209
|
+
`saarthiclaw-build` is kept as an alias binary for backwards compatibility.
|
|
210
|
+
|
|
211
|
+
## Telegram setup
|
|
212
|
+
|
|
213
|
+
1. Talk to [@BotFather](https://t.me/BotFather) → `/newbot` → copy the token.
|
|
214
|
+
2. Get your numeric user id from [@userinfobot](https://t.me/userinfobot).
|
|
215
|
+
3. Run `npx saarthiclaw init` and answer yes to Telegram (or add `TELEGRAM_BOT_TOKEN` and `TELEGRAM_OWNER_ID` to `.env`).
|
|
216
|
+
4. Run `npx saarthiclaw telegram`, open your bot and press **Start**.
|
|
217
|
+
|
|
218
|
+
Every update from anyone other than the owner is dropped before any handler runs. Changes from `/agent` and `/plan` are staged and shown with **Show Diff / Accept All / Reject All** buttons; high-risk batches need a second confirmation. Shell commands follow your `allowShellExecution` setting (off by default). Stop the bot with Ctrl+C.
|
|
219
|
+
|
|
220
|
+
## Free models and rate limits
|
|
221
|
+
|
|
222
|
+
- Free OpenRouter models are limited to roughly **20 requests per minute and 200 per day**. One agent run can use many requests (one per tool-loop step).
|
|
223
|
+
- SaarthiClaw retries 429 / 5xx responses automatically (3 retries with exponential backoff) and then explains the limit.
|
|
224
|
+
- The free lineup **rotates**. If you see "That model is not available", pick another in `saarthiclaw init` or pass `--model`. Good starting points: `qwen/qwen3-coder:free`, `openai/gpt-oss-120b:free`, `openai/gpt-oss-20b:free`.
|
|
225
|
+
|
|
226
|
+
## Troubleshooting
|
|
227
|
+
|
|
228
|
+
| Symptom | Fix |
|
|
229
|
+
| --- | --- |
|
|
230
|
+
| "No OpenRouter API key configured" | Run `npx saarthiclaw init`, or add `OPENROUTER_API_KEY=…` to the project `.env` |
|
|
231
|
+
| "Rate limited by OpenRouter (429)" | Wait a minute, use a different free model, or add credits |
|
|
232
|
+
| "OpenRouter rejected the API key (401)" | The key is wrong or revoked — create a new one and re-run `init` |
|
|
233
|
+
| "needs an interactive terminal (TTY)" | Run in a real terminal, or use `saarthiclaw ask "<question>"` in scripts/CI |
|
|
234
|
+
| Windows: arrow keys or colours look odd | Use Windows Terminal or PowerShell 7; set `NO_COLOR=1` to disable colours |
|
|
235
|
+
| Windows: shell commands | Commands run through the platform shell (`cmd.exe` on Windows), so write them for that shell |
|
|
236
|
+
| Anything else | `npx saarthiclaw doctor`, then re-run with `--debug` for a stack trace |
|
|
237
|
+
|
|
238
|
+
## FAQ
|
|
239
|
+
|
|
240
|
+
**Is this DevOps?**
|
|
241
|
+
It borrows DevOps ideas — approval gates, risk levels, audit logs — but it is an AI-assisted *development* tool that works inside one project on your machine.
|
|
242
|
+
|
|
243
|
+
**Does anything get sent besides my question?**
|
|
244
|
+
The model receives its instructions, a compact project brief (package.json summary, a shallow file tree, a README excerpt) and the content of files the tools read. Secret files are never readable.
|
|
245
|
+
|
|
246
|
+
**Can it run without approval?**
|
|
247
|
+
No. That is the whole point.
|
|
248
|
+
|
|
249
|
+
## Roadmap
|
|
250
|
+
|
|
251
|
+
- Web dashboard with Admin/Member keys and role-based access
|
|
252
|
+
- WhatsApp remote mode
|
|
253
|
+
- Database-backed history (the audit trail is already an event subscriber, so it can be swapped)
|
|
254
|
+
|
|
255
|
+
## Contributing
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
git clone https://github.com/hritik0447/SaarthiClaw.git
|
|
259
|
+
cd SaarthiClaw
|
|
260
|
+
npm install
|
|
261
|
+
npm run typecheck && npm test && npm run build
|
|
262
|
+
node dist/index.js --help
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Source layout: `index.ts` (entry) · `cli/` (commands: init, doctor, history) · `config/` (env/.env/config files) · `context/` (project brief + instructions) · `ai/` (model + error mapping) · `modes/ask|plan|agent|telegram` · `tui/` (menu, prompts, spinner, markdown) · `tests/`.
|
|
266
|
+
|
|
267
|
+
Tests use Node's built-in test runner with the AI SDK's mock model — no network, no real LLM. Issues and PRs welcome at <https://github.com/hritik0447/SaarthiClaw/issues>.
|
|
268
|
+
|
|
269
|
+
## Publishing (maintainers)
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
npm login # use an account with 2FA enabled (npm profile enable-2fa auth-and-writes)
|
|
273
|
+
npm view saarthiclaw name # "404 Not Found" means the name is free
|
|
274
|
+
npm run typecheck && npm test && npm run build
|
|
275
|
+
npm pack --dry-run # should list only dist/, README.md, LICENSE, CHANGELOG.md, package.json
|
|
276
|
+
npm publish # prepublishOnly re-runs typecheck + tests + build
|
|
277
|
+
npm i -g saarthiclaw && saarthiclaw --version # verify on a clean machine
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
If the unscoped name is taken: set `"name": "@hritik0447/saarthiclaw"` and `"publishConfig": { "access": "public" }`, then `npm publish --access public`. The binary is still called `saarthiclaw`.
|
|
281
|
+
|
|
282
|
+
Releases follow semver: `npm version patch` (bug fix, 0.1.0 → 0.1.1), `npm version minor` (new feature), `npm version major` (breaking). `npm version` bumps `package.json`, commits and tags; then `git push --follow-tags && npm publish`. Add an entry to `CHANGELOG.md` first.
|
|
283
|
+
|
|
284
|
+
Pulling a bad release: prefer `npm deprecate saarthiclaw@0.1.1 "Broken, use 0.1.2"` and ship a fixed patch. `npm unpublish saarthiclaw@0.1.1` only works within 72 hours and the version number can never be reused.
|
|
285
|
+
|
|
286
|
+
## License
|
|
287
|
+
|
|
288
|
+
[MIT](LICENSE) © Hritik Vishnoi
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import {
|
|
2
|
+
projectStateDir
|
|
3
|
+
} from "./chunk-MMIJKDOU.js";
|
|
4
|
+
|
|
5
|
+
// config/index.ts
|
|
6
|
+
import fs2 from "node:fs";
|
|
7
|
+
import os from "node:os";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
|
|
11
|
+
// config/dotenv.ts
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
function parseDotenv(source) {
|
|
14
|
+
const out = {};
|
|
15
|
+
const lines = source.replace(/\r\n?/g, "\n").split("\n");
|
|
16
|
+
for (const raw of lines) {
|
|
17
|
+
const line = raw.trim();
|
|
18
|
+
if (!line || line.startsWith("#")) continue;
|
|
19
|
+
const m = /^(?:export\s+)?([A-Za-z_][A-Za-z0-9_.-]*)\s*=\s*(.*)$/.exec(line);
|
|
20
|
+
if (!m) continue;
|
|
21
|
+
const key = m[1];
|
|
22
|
+
let value = m[2] ?? "";
|
|
23
|
+
if (value.startsWith('"')) {
|
|
24
|
+
const end = findClosingQuote(value, '"');
|
|
25
|
+
value = end === -1 ? value.slice(1) : value.slice(1, end);
|
|
26
|
+
value = value.replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\t/g, " ").replace(/\\"/g, '"').replace(/\\\\/g, "\\");
|
|
27
|
+
} else if (value.startsWith("'")) {
|
|
28
|
+
const end = value.indexOf("'", 1);
|
|
29
|
+
value = end === -1 ? value.slice(1) : value.slice(1, end);
|
|
30
|
+
} else {
|
|
31
|
+
const hash = value.search(/\s#/);
|
|
32
|
+
if (hash !== -1) value = value.slice(0, hash);
|
|
33
|
+
value = value.trim();
|
|
34
|
+
}
|
|
35
|
+
out[key] = value;
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
function findClosingQuote(value, quote) {
|
|
40
|
+
for (let i = 1; i < value.length; i++) {
|
|
41
|
+
if (value[i] === "\\") {
|
|
42
|
+
i++;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (value[i] === quote) return i;
|
|
46
|
+
}
|
|
47
|
+
return -1;
|
|
48
|
+
}
|
|
49
|
+
function readDotenvFile(file) {
|
|
50
|
+
if (!fs.existsSync(file)) return void 0;
|
|
51
|
+
return parseDotenv(fs.readFileSync(file, "utf8"));
|
|
52
|
+
}
|
|
53
|
+
function formatValue(value) {
|
|
54
|
+
if (value === "") return "";
|
|
55
|
+
if (/^[A-Za-z0-9_./:@+-]+$/.test(value)) return value;
|
|
56
|
+
return JSON.stringify(value);
|
|
57
|
+
}
|
|
58
|
+
function upsertDotenv(source, updates) {
|
|
59
|
+
const eol = source.includes("\r\n") ? "\r\n" : "\n";
|
|
60
|
+
const lines = source === "" ? [] : source.replace(/\r\n?/g, "\n").split("\n");
|
|
61
|
+
if (lines.length && lines[lines.length - 1] === "") lines.pop();
|
|
62
|
+
const pending = new Map(
|
|
63
|
+
Object.entries(updates).filter(
|
|
64
|
+
(e) => typeof e[1] === "string"
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
const result = lines.map((line) => {
|
|
68
|
+
const m = /^(\s*(?:export\s+)?)([A-Za-z_][A-Za-z0-9_.-]*)\s*=/.exec(line);
|
|
69
|
+
if (!m) return line;
|
|
70
|
+
const key = m[2];
|
|
71
|
+
if (!pending.has(key)) return line;
|
|
72
|
+
const value = pending.get(key);
|
|
73
|
+
pending.delete(key);
|
|
74
|
+
return `${m[1]}${key}=${formatValue(value)}`;
|
|
75
|
+
});
|
|
76
|
+
for (const [key, value] of pending) {
|
|
77
|
+
result.push(`${key}=${formatValue(value)}`);
|
|
78
|
+
}
|
|
79
|
+
return result.join(eol) + (result.length ? eol : "");
|
|
80
|
+
}
|
|
81
|
+
function writeDotenvFile(file, updates) {
|
|
82
|
+
const current = fs.existsSync(file) ? fs.readFileSync(file, "utf8") : "";
|
|
83
|
+
const next = upsertDotenv(current, updates);
|
|
84
|
+
if (next !== current) fs.writeFileSync(file, next, "utf8");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// config/index.ts
|
|
88
|
+
var DEFAULT_MODEL = "qwen/qwen3-coder:free";
|
|
89
|
+
var MODEL_PRESETS = [
|
|
90
|
+
"qwen/qwen3-coder:free",
|
|
91
|
+
"openai/gpt-oss-120b:free",
|
|
92
|
+
"openai/gpt-oss-20b:free"
|
|
93
|
+
];
|
|
94
|
+
var DEFAULT_EXCLUDE_PATTERNS = [
|
|
95
|
+
"node_modules",
|
|
96
|
+
".git",
|
|
97
|
+
"dist",
|
|
98
|
+
"build",
|
|
99
|
+
".next",
|
|
100
|
+
".cache",
|
|
101
|
+
"coverage",
|
|
102
|
+
"*.log"
|
|
103
|
+
];
|
|
104
|
+
var DEFAULTS = {
|
|
105
|
+
model: DEFAULT_MODEL,
|
|
106
|
+
allowShellExecution: false,
|
|
107
|
+
maxSteps: { ask: 20, plan: 30, agent: 40 },
|
|
108
|
+
maxFileSizeToRead: 1024 * 1024,
|
|
109
|
+
maxToolOutputChars: 2e4,
|
|
110
|
+
context: {
|
|
111
|
+
maxReadmeChars: 1500,
|
|
112
|
+
maxTreeLines: 150,
|
|
113
|
+
maxTreeDepth: 3,
|
|
114
|
+
maxBriefChars: 8e3
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var configFileSchema = z.object({
|
|
118
|
+
model: z.string().min(1),
|
|
119
|
+
openrouterApiKey: z.string().min(1),
|
|
120
|
+
firecrawlApiKey: z.string().min(1),
|
|
121
|
+
telegramBotToken: z.string().min(1),
|
|
122
|
+
telegramOwnerId: z.union([z.string().min(1), z.number().int()]),
|
|
123
|
+
skillsDirs: z.array(z.string()),
|
|
124
|
+
allowShellExecution: z.boolean(),
|
|
125
|
+
maxSteps: z.object({
|
|
126
|
+
ask: z.number().int().min(1).max(200),
|
|
127
|
+
plan: z.number().int().min(1).max(200),
|
|
128
|
+
agent: z.number().int().min(1).max(200)
|
|
129
|
+
}).partial(),
|
|
130
|
+
excludePatterns: z.array(z.string().min(1)),
|
|
131
|
+
maxFileSizeToRead: z.number().int().min(1024),
|
|
132
|
+
maxToolOutputChars: z.number().int().min(500),
|
|
133
|
+
context: z.object({
|
|
134
|
+
maxReadmeChars: z.number().int().min(0),
|
|
135
|
+
maxTreeLines: z.number().int().min(0),
|
|
136
|
+
maxTreeDepth: z.number().int().min(0).max(10),
|
|
137
|
+
maxBriefChars: z.number().int().min(500)
|
|
138
|
+
}).partial()
|
|
139
|
+
}).partial();
|
|
140
|
+
var ConfigError = class extends Error {
|
|
141
|
+
constructor(message) {
|
|
142
|
+
super(message);
|
|
143
|
+
this.name = "ConfigError";
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
function userConfigDir(env = process.env) {
|
|
147
|
+
const override = env.SAARTHICLAW_HOME?.trim();
|
|
148
|
+
return override ? path.resolve(override) : path.join(os.homedir(), ".saarthiclaw");
|
|
149
|
+
}
|
|
150
|
+
function projectConfigPath(root) {
|
|
151
|
+
return path.join(projectStateDir(root), "config.json");
|
|
152
|
+
}
|
|
153
|
+
function readConfigFile(file) {
|
|
154
|
+
if (!fs2.existsSync(file)) return void 0;
|
|
155
|
+
let raw;
|
|
156
|
+
try {
|
|
157
|
+
raw = JSON.parse(fs2.readFileSync(file, "utf8"));
|
|
158
|
+
} catch (e) {
|
|
159
|
+
throw new ConfigError(`Invalid JSON in ${file}: ${e.message}`);
|
|
160
|
+
}
|
|
161
|
+
const parsed = configFileSchema.safeParse(raw);
|
|
162
|
+
if (!parsed.success) {
|
|
163
|
+
const issues = parsed.error.issues.map((i) => ` • ${i.path.join(".") || "(root)"}: ${i.message}`).join("\n");
|
|
164
|
+
throw new ConfigError(`Invalid settings in ${file}:
|
|
165
|
+
${issues}`);
|
|
166
|
+
}
|
|
167
|
+
return parsed.data;
|
|
168
|
+
}
|
|
169
|
+
var ENV_KEYS = {
|
|
170
|
+
openrouterApiKey: ["OPENROUTER_API_KEY"],
|
|
171
|
+
model: ["OPENROUTER_DEFAULT_MODEL"],
|
|
172
|
+
firecrawlApiKey: ["FIRECRAWL_API_KEY"],
|
|
173
|
+
telegramBotToken: ["TELEGRAM_BOT_TOKEN"],
|
|
174
|
+
telegramOwnerId: ["TELEGRAM_OWNER_ID", "TELEGRAM_BOT_ID"],
|
|
175
|
+
skillsDirs: ["SKILLS_DIRS"]
|
|
176
|
+
};
|
|
177
|
+
function nonEmpty(v) {
|
|
178
|
+
if (v === void 0) return void 0;
|
|
179
|
+
const t = v.trim();
|
|
180
|
+
return t ? t : void 0;
|
|
181
|
+
}
|
|
182
|
+
function splitDirs(v) {
|
|
183
|
+
return v.split(/[;:](?![\\/])/).map((s) => s.trim()).filter(Boolean);
|
|
184
|
+
}
|
|
185
|
+
function loadConfig(opts) {
|
|
186
|
+
const root = path.resolve(opts.root);
|
|
187
|
+
const env = opts.env ?? process.env;
|
|
188
|
+
const flags = opts.flags ?? {};
|
|
189
|
+
const warnings = [];
|
|
190
|
+
const sources = {};
|
|
191
|
+
const dotenvPath = path.join(root, ".env");
|
|
192
|
+
const dotenv = readDotenvFile(dotenvPath);
|
|
193
|
+
const projectPath = projectConfigPath(root);
|
|
194
|
+
const project = readConfigFile(projectPath);
|
|
195
|
+
const userPath = path.join(opts.userDir ?? userConfigDir(env), "config.json");
|
|
196
|
+
const user = readConfigFile(userPath);
|
|
197
|
+
const files = {};
|
|
198
|
+
if (dotenv) files.dotenv = dotenvPath;
|
|
199
|
+
if (project) files.project = projectPath;
|
|
200
|
+
if (user) files.user = userPath;
|
|
201
|
+
const fromEnvLike = (key, bag, label) => {
|
|
202
|
+
if (!bag) return void 0;
|
|
203
|
+
const names = ENV_KEYS[key];
|
|
204
|
+
for (const name of names) {
|
|
205
|
+
const v = nonEmpty(bag[name]);
|
|
206
|
+
if (v !== void 0) {
|
|
207
|
+
if (name === "TELEGRAM_BOT_ID") {
|
|
208
|
+
warnings.push(
|
|
209
|
+
`TELEGRAM_BOT_ID (from ${label}) is deprecated — rename it to TELEGRAM_OWNER_ID.`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
return v;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return void 0;
|
|
216
|
+
};
|
|
217
|
+
const pickString = (key, flagValue) => {
|
|
218
|
+
const f = nonEmpty(flagValue);
|
|
219
|
+
if (f !== void 0) {
|
|
220
|
+
sources[key] = "flag";
|
|
221
|
+
return f;
|
|
222
|
+
}
|
|
223
|
+
const e = fromEnvLike(key, env, "env");
|
|
224
|
+
if (e !== void 0) {
|
|
225
|
+
sources[key] = "env";
|
|
226
|
+
return e;
|
|
227
|
+
}
|
|
228
|
+
const d = fromEnvLike(key, dotenv, ".env");
|
|
229
|
+
if (d !== void 0) {
|
|
230
|
+
sources[key] = ".env";
|
|
231
|
+
return d;
|
|
232
|
+
}
|
|
233
|
+
const fileKey = key;
|
|
234
|
+
const p = project?.[fileKey];
|
|
235
|
+
if (p !== void 0 && key !== "skillsDirs") {
|
|
236
|
+
sources[key] = "project";
|
|
237
|
+
return String(p);
|
|
238
|
+
}
|
|
239
|
+
const u = user?.[fileKey];
|
|
240
|
+
if (u !== void 0 && key !== "skillsDirs") {
|
|
241
|
+
sources[key] = "user";
|
|
242
|
+
return String(u);
|
|
243
|
+
}
|
|
244
|
+
return void 0;
|
|
245
|
+
};
|
|
246
|
+
const openrouterApiKey = pickString("openrouterApiKey");
|
|
247
|
+
let model = pickString("model", flags.model);
|
|
248
|
+
if (!model) {
|
|
249
|
+
model = DEFAULTS.model;
|
|
250
|
+
sources.model = "default";
|
|
251
|
+
}
|
|
252
|
+
const firecrawlApiKey = pickString("firecrawlApiKey");
|
|
253
|
+
const telegramBotToken = pickString("telegramBotToken");
|
|
254
|
+
const telegramOwnerId = pickString("telegramOwnerId");
|
|
255
|
+
let skillsDirs = [];
|
|
256
|
+
const skillsEnv = fromEnvLike("skillsDirs", env, "env") ?? fromEnvLike("skillsDirs", dotenv, ".env");
|
|
257
|
+
if (skillsEnv) {
|
|
258
|
+
skillsDirs = splitDirs(skillsEnv);
|
|
259
|
+
sources.skillsDirs = env.SKILLS_DIRS ? "env" : ".env";
|
|
260
|
+
} else if (project?.skillsDirs) {
|
|
261
|
+
skillsDirs = project.skillsDirs;
|
|
262
|
+
sources.skillsDirs = "project";
|
|
263
|
+
} else if (user?.skillsDirs) {
|
|
264
|
+
skillsDirs = user.skillsDirs;
|
|
265
|
+
sources.skillsDirs = "user";
|
|
266
|
+
}
|
|
267
|
+
let allowShellExecution = DEFAULTS.allowShellExecution;
|
|
268
|
+
sources.allowShellExecution = "default";
|
|
269
|
+
if (flags.allowShell) {
|
|
270
|
+
allowShellExecution = true;
|
|
271
|
+
sources.allowShellExecution = "flag";
|
|
272
|
+
} else if (project?.allowShellExecution !== void 0) {
|
|
273
|
+
allowShellExecution = project.allowShellExecution;
|
|
274
|
+
sources.allowShellExecution = "project";
|
|
275
|
+
} else if (user?.allowShellExecution !== void 0) {
|
|
276
|
+
allowShellExecution = user.allowShellExecution;
|
|
277
|
+
sources.allowShellExecution = "user";
|
|
278
|
+
}
|
|
279
|
+
const layered = (pick, fallback) => (project && pick(project)) ?? (user && pick(user)) ?? fallback;
|
|
280
|
+
const maxSteps = {
|
|
281
|
+
ask: layered((c) => c.maxSteps?.ask, DEFAULTS.maxSteps.ask),
|
|
282
|
+
plan: layered((c) => c.maxSteps?.plan, DEFAULTS.maxSteps.plan),
|
|
283
|
+
agent: layered((c) => c.maxSteps?.agent, DEFAULTS.maxSteps.agent)
|
|
284
|
+
};
|
|
285
|
+
const context = {
|
|
286
|
+
maxReadmeChars: layered((c) => c.context?.maxReadmeChars, DEFAULTS.context.maxReadmeChars),
|
|
287
|
+
maxTreeLines: layered((c) => c.context?.maxTreeLines, DEFAULTS.context.maxTreeLines),
|
|
288
|
+
maxTreeDepth: layered((c) => c.context?.maxTreeDepth, DEFAULTS.context.maxTreeDepth),
|
|
289
|
+
maxBriefChars: layered((c) => c.context?.maxBriefChars, DEFAULTS.context.maxBriefChars)
|
|
290
|
+
};
|
|
291
|
+
const excludePatterns = [
|
|
292
|
+
.../* @__PURE__ */ new Set([
|
|
293
|
+
...DEFAULT_EXCLUDE_PATTERNS,
|
|
294
|
+
...project?.excludePatterns ?? [],
|
|
295
|
+
...user?.excludePatterns ?? []
|
|
296
|
+
])
|
|
297
|
+
];
|
|
298
|
+
return {
|
|
299
|
+
root,
|
|
300
|
+
openrouterApiKey,
|
|
301
|
+
model,
|
|
302
|
+
firecrawlApiKey,
|
|
303
|
+
telegramBotToken,
|
|
304
|
+
telegramOwnerId,
|
|
305
|
+
skillsDirs,
|
|
306
|
+
allowShellExecution,
|
|
307
|
+
maxSteps,
|
|
308
|
+
excludePatterns,
|
|
309
|
+
maxFileSizeToRead: layered((c) => c.maxFileSizeToRead, DEFAULTS.maxFileSizeToRead),
|
|
310
|
+
maxToolOutputChars: layered((c) => c.maxToolOutputChars, DEFAULTS.maxToolOutputChars),
|
|
311
|
+
context,
|
|
312
|
+
sources,
|
|
313
|
+
files,
|
|
314
|
+
warnings
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
function writeProjectConfig(root, patch) {
|
|
318
|
+
const file = projectConfigPath(root);
|
|
319
|
+
fs2.mkdirSync(path.dirname(file), { recursive: true });
|
|
320
|
+
const current = fs2.existsSync(file) ? readConfigFile(file) ?? {} : {};
|
|
321
|
+
const next = configFileSchema.parse({ ...current, ...patch });
|
|
322
|
+
fs2.writeFileSync(file, JSON.stringify(next, null, 2) + "\n", "utf8");
|
|
323
|
+
return file;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export {
|
|
327
|
+
writeDotenvFile,
|
|
328
|
+
DEFAULT_MODEL,
|
|
329
|
+
MODEL_PRESETS,
|
|
330
|
+
DEFAULT_EXCLUDE_PATTERNS,
|
|
331
|
+
DEFAULTS,
|
|
332
|
+
configFileSchema,
|
|
333
|
+
ConfigError,
|
|
334
|
+
userConfigDir,
|
|
335
|
+
projectConfigPath,
|
|
336
|
+
readConfigFile,
|
|
337
|
+
loadConfig,
|
|
338
|
+
writeProjectConfig
|
|
339
|
+
};
|