saarthiclaw 0.2.2 → 0.3.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 (35) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +10 -0
  3. package/dist/chunks/{chunk-EG5A2Q6X.js → chunk-33MUQ6E5.js} +9 -1
  4. package/dist/chunks/{chunk-OS5GVLKA.js → chunk-CGJ4VEUD.js} +1 -1
  5. package/dist/chunks/{chunk-E4DRW4AW.js → chunk-H2FAKNUI.js} +10 -2
  6. package/dist/chunks/{chunk-OICPXSO2.js → chunk-HFMRQTXE.js} +1 -1
  7. package/dist/chunks/{chunk-GX2I7K4S.js → chunk-KAWTUWO2.js} +15 -5
  8. package/dist/chunks/{chunk-VDYO3QC7.js → chunk-N33J57DT.js} +6 -6
  9. package/dist/chunks/{chunk-DSQDVSZS.js → chunk-OF5PQQQ4.js} +6 -6
  10. package/dist/chunks/chunk-R4PMMMD5.js +407 -0
  11. package/dist/chunks/{chunk-SKYTL7AH.js → chunk-S6YZ2A73.js} +17 -8
  12. package/dist/chunks/{chunk-TTT3KK46.js → chunk-SYH37PL6.js} +5 -5
  13. package/dist/chunks/{chunk-ZXVP7JFV.js → chunk-XATEICDJ.js} +11 -13
  14. package/dist/chunks/{chunk-3UFD5346.js → chunk-XT5WAZRV.js} +5 -5
  15. package/dist/chunks/{client-5WRI2PBK.js → client-TI5W2YDP.js} +3 -5
  16. package/dist/chunks/{context-AP3U34DQ.js → context-RKFGCGP7.js} +5 -7
  17. package/dist/chunks/{doctor-O3R2YTRO.js → doctor-ZQICU2F4.js} +11 -6
  18. package/dist/chunks/{errors-ZXTAHCZI.js → errors-OJZTUG74.js} +2 -4
  19. package/dist/chunks/orchestrator-ATA2LHPJ.js +22 -0
  20. package/dist/chunks/{orchestrator-NIDJK4C3.js → orchestrator-NJ7US5XC.js} +9 -11
  21. package/dist/chunks/{orchestrator-KNCW4K57.js → orchestrator-XLVMKC4V.js} +10 -12
  22. package/dist/chunks/{session-CRFC3IEU.js → session-ZC5D2O77.js} +6 -3
  23. package/dist/chunks/{store-KW257WIV.js → store-JG5OKLEO.js} +5 -5
  24. package/dist/chunks/{sync-S2A65FIE.js → sync-ESB3YWI2.js} +7 -9
  25. package/dist/chunks/{team-RBSOK3HT.js → team-PFETXIEC.js} +123 -23
  26. package/dist/chunks/{telegram-JSGRYPIX.js → telegram-IMADPCKR.js} +14 -16
  27. package/dist/chunks/{wakeup-4IP4JXVF.js → wakeup-UX6AM7M6.js} +16 -18
  28. package/dist/chunks/workspace-XERWEYJB.js +281 -0
  29. package/dist/index.js +27 -20
  30. package/package.json +1 -1
  31. package/dist/chunks/chunk-BTFIQWAE.js +0 -185
  32. package/dist/chunks/chunk-G6GCAEKE.js +0 -64
  33. package/dist/chunks/chunk-XTVJWMUH.js +0 -143
  34. package/dist/chunks/orchestrator-JFJU4FGP.js +0 -24
  35. package/dist/chunks/{init-GCJNYE3Y.js → init-5ENYFSX2.js} +3 -3
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ async function bootstrap(cmd, opts = {}) {
17
17
  import("./chunks/workspace-PFJUEHAB.js"),
18
18
  import("./chunks/config-PA5NJ37O.js"),
19
19
  import("./chunks/prompter-AAH4A3BG.js"),
20
- import("./chunks/session-CRFC3IEU.js")
20
+ import("./chunks/session-ZC5D2O77.js")
21
21
  ]);
22
22
  if (opts.needsTty && !prompterMod.isInteractiveTerminal()) {
23
23
  throw new prompterMod.NonInteractiveError(opts.needsTty);
@@ -37,10 +37,11 @@ async function bootstrap(cmd, opts = {}) {
37
37
  async function startWakeup(cmd) {
38
38
  const session = await bootstrap(cmd, { needsTty: "`saarthiclaw wakeup`" });
39
39
  const g = cmd.optsWithGlobals();
40
- const { renderBanner, runWakeup } = await import("./chunks/wakeup-4IP4JXVF.js");
40
+ const { renderBanner, runWakeup } = await import("./chunks/wakeup-UX6AM7M6.js");
41
41
  if (g.banner !== false) console.log(renderBanner(getVersion()) + "\n");
42
- if (!session.config.openrouterApiKey) {
43
- console.log(chalk.yellow("⚠ No OpenRouter API key found. Run `saarthiclaw init` first (Ask/Plan/Agent need it).\n"));
42
+ const { hasAiAccess } = await import("./chunks/session-ZC5D2O77.js");
43
+ if (!hasAiAccess(session)) {
44
+ console.log(chalk.yellow("⚠ No AI key found. Run `saarthiclaw init` first, or ask your team Admin to add a Team AI key (Ask/Plan/Agent need one).\n"));
44
45
  }
45
46
  await runWakeup(session);
46
47
  goodbye();
@@ -65,36 +66,36 @@ function buildProgram() {
65
66
  program.command("wakeup").aliases(["wake", "start"]).description("open the interactive menu (CLI: Ask / Plan / Agent, or Telegram)").action(async (_opts, cmd) => startWakeup(cmd));
66
67
  program.command("init").description("guided one-time setup (API key, model, safety options)").action(async (_opts, cmd) => {
67
68
  const session = await bootstrap(cmd, { needsTty: "`saarthiclaw init`" });
68
- const { runInit } = await import("./chunks/init-GCJNYE3Y.js");
69
+ const { runInit } = await import("./chunks/init-5ENYFSX2.js");
69
70
  await runInit({ root: session.root, prompter: session.prompter, decorate: true });
70
71
  });
71
72
  program.command("doctor").description("check your setup (Node, config, API key, a live test call)").option("--offline", "skip the live model call").action(async (opts, cmd) => {
72
73
  const session = await bootstrap(cmd);
73
- const { runDoctor } = await import("./chunks/doctor-O3R2YTRO.js");
74
+ const { runDoctor } = await import("./chunks/doctor-ZQICU2F4.js");
74
75
  const code = await runDoctor(session, { live: !opts.offline });
75
76
  if (code !== 0) throw new CommanderError(code, "saarthiclaw.doctorFailed", "");
76
77
  });
77
78
  program.command("ask").argument("[question...]", "question about the codebase (omit for the interactive prompt)").option("--save <file.md>", "save the answer as Markdown (goes through the approval flow)").description("ask a question about this codebase (read-only)").action(async (words, opts, cmd) => {
78
79
  const question = joinWords(words);
79
80
  const session = await bootstrap(cmd, { needsTty: question && !opts.save ? void 0 : "`saarthiclaw ask` without a question or with --save" });
80
- const ask = await import("./chunks/orchestrator-KNCW4K57.js");
81
+ const ask = await import("./chunks/orchestrator-XLVMKC4V.js");
81
82
  if (question) await ask.runAskOnce(session, question, opts.save);
82
83
  else await ask.runAskMode(session);
83
84
  });
84
85
  program.command("plan").argument("[goal...]", "what you want to achieve").description("generate a step-by-step plan, pick steps, execute them with approval").action(async (words, _opts, cmd) => {
85
86
  const session = await bootstrap(cmd, { needsTty: "`saarthiclaw plan`" });
86
- const { runPlanMode } = await import("./chunks/orchestrator-JFJU4FGP.js");
87
+ const { runPlanMode } = await import("./chunks/orchestrator-ATA2LHPJ.js");
87
88
  await runPlanMode(session, joinWords(words));
88
89
  });
89
90
  program.command("agent").argument("[task...]", "task for the agent").description("let the agent stage changes; you review and approve every diff").option("--send", "team (Needs approval): send the changes to the Admin without asking; no shell commands").action(async (words, opts, cmd) => {
90
91
  const task = joinWords(words);
91
92
  const session = await bootstrap(cmd, { needsTty: opts.send && task ? void 0 : "`saarthiclaw agent`" });
92
- const { runAgentMode } = await import("./chunks/orchestrator-NIDJK4C3.js");
93
+ const { runAgentMode } = await import("./chunks/orchestrator-NJ7US5XC.js");
93
94
  await runAgentMode(session, task, { send: opts.send });
94
95
  });
95
96
  program.command("telegram").description("run the Telegram remote-control bot (owner only) until Ctrl+C").action(async (_opts, cmd) => {
96
97
  const session = await bootstrap(cmd);
97
- const { runTelegramMode } = await import("./chunks/telegram-JSGRYPIX.js");
98
+ const { runTelegramMode } = await import("./chunks/telegram-IMADPCKR.js");
98
99
  await runTelegramMode(session);
99
100
  });
100
101
  program.command("history").description("show the audit trail of staged / approved / applied actions").option("--last <n>", "number of events to show", "20").action(async (opts, cmd) => {
@@ -106,44 +107,49 @@ function buildProgram() {
106
107
  });
107
108
  const team = program.command("team").description("work with a team dashboard: connect, sync approved changes, suggest, invite").action(async (_opts, cmd) => {
108
109
  const session = await bootstrap(cmd);
109
- const { teamStatus } = await import("./chunks/team-RBSOK3HT.js");
110
+ const { teamStatus } = await import("./chunks/team-PFETXIEC.js");
110
111
  await teamStatus(session);
111
112
  });
112
113
  team.command("connect").alias("join").argument("[url]", "dashboard address, e.g. http://127.0.0.1:3000").description("link this project to a dashboard with your access key (Admin or member)").action(async (url, _opts, cmd) => {
113
114
  const session = await bootstrap(cmd, { needsTty: process.env.SAARTHICLAW_TEAM_KEY ? void 0 : "`saarthiclaw team connect` (or set SAARTHICLAW_TEAM_KEY)" });
114
- const { teamConnect } = await import("./chunks/team-RBSOK3HT.js");
115
+ const { teamConnect } = await import("./chunks/team-PFETXIEC.js");
115
116
  await teamConnect(session, url);
116
117
  });
117
118
  team.command("status").description("who you are, your level, and what is waiting").action(async (_opts, cmd) => {
118
119
  const session = await bootstrap(cmd);
119
- const { teamStatus } = await import("./chunks/team-RBSOK3HT.js");
120
+ const { teamStatus } = await import("./chunks/team-PFETXIEC.js");
120
121
  await teamStatus(session);
121
122
  });
122
123
  team.command("sync").description("apply your changes the Admin approved; show rejections").option("-y, --yes", "apply approved changes without asking").option("-w, --wait", "keep waiting until the Admin has decided on everything").action(async (opts, cmd) => {
123
124
  const session = await bootstrap(cmd);
124
125
  const g = cmd.optsWithGlobals();
125
- const { teamSync } = await import("./chunks/team-RBSOK3HT.js");
126
+ const { teamSync } = await import("./chunks/team-PFETXIEC.js");
126
127
  await teamSync(session, { yes: opts.yes, wait: opts.wait, allowShell: g.allowShell });
127
128
  });
129
+ team.command("watch").description("keep this folder and the team website in step (approved website changes come down here; Admin/Trusted edits go up)").option("--once", "sync one time and exit").option("--prefer <side>", "when both sides changed a file: website | laptop").option("--interval <seconds>", "how often to check (default 2)").action(async (opts, cmd) => {
130
+ const session = await bootstrap(cmd);
131
+ const { teamWatch } = await import("./chunks/team-PFETXIEC.js");
132
+ await teamWatch(session, opts);
133
+ });
128
134
  team.command("suggest").argument("[idea...]", "your idea for the Admin").description("send an idea to the Admin (any level, including Suggest only)").action(async (words, _opts, cmd) => {
129
135
  const idea = joinWords(words);
130
136
  const session = await bootstrap(cmd, { needsTty: idea ? void 0 : "`saarthiclaw team suggest` without text" });
131
- const { teamSuggest } = await import("./chunks/team-RBSOK3HT.js");
137
+ const { teamSuggest } = await import("./chunks/team-PFETXIEC.js");
132
138
  await teamSuggest(session, idea);
133
139
  });
134
140
  team.command("invite").argument("[name]", "developer's name").option("--level <level>", "trusted | needs-approval | suggest-only").description("(Admin) add a developer and print their one-time access key").action(async (name, opts, cmd) => {
135
141
  const session = await bootstrap(cmd, { needsTty: name ? void 0 : "`saarthiclaw team invite` without a name" });
136
- const { teamInvite } = await import("./chunks/team-RBSOK3HT.js");
142
+ const { teamInvite } = await import("./chunks/team-PFETXIEC.js");
137
143
  await teamInvite(session, name ?? "", opts.level);
138
144
  });
139
145
  team.command("inbox").description("(Admin) suggestions you forwarded to the agent; run the agent on one").action(async (_opts, cmd) => {
140
146
  const session = await bootstrap(cmd);
141
- const { teamInbox } = await import("./chunks/team-RBSOK3HT.js");
147
+ const { teamInbox } = await import("./chunks/team-PFETXIEC.js");
142
148
  await teamInbox(session);
143
149
  });
144
150
  team.command("disconnect").alias("leave").description("unlink this project from the dashboard (back to solo mode)").action(async (_opts, cmd) => {
145
151
  const session = await bootstrap(cmd, { needsTty: "`saarthiclaw team disconnect`" });
146
- const { teamDisconnect } = await import("./chunks/team-RBSOK3HT.js");
152
+ const { teamDisconnect } = await import("./chunks/team-PFETXIEC.js");
147
153
  await teamDisconnect(session);
148
154
  });
149
155
  program.addHelpText(
@@ -151,6 +157,7 @@ function buildProgram() {
151
157
  `
152
158
  Examples:
153
159
  $ npx saarthiclaw init one-time setup
160
+ $ npx saarthiclaw team watch keep this folder in step with the team website
154
161
  $ npx saarthiclaw open the menu (same as wakeup)
155
162
  $ npx saarthiclaw ask "where is auth handled?"
156
163
  $ npx saarthiclaw agent "add a /health route" --allow-shell
@@ -174,7 +181,7 @@ async function main(argv = process.argv) {
174
181
  });
175
182
  }
176
183
  process.on("unhandledRejection", async (reason) => {
177
- const { reportError } = await import("./chunks/errors-ZXTAHCZI.js");
184
+ const { reportError } = await import("./chunks/errors-OJZTUG74.js");
178
185
  reportError(reason, debug);
179
186
  process.exit(1);
180
187
  });
@@ -196,7 +203,7 @@ async function main(argv = process.argv) {
196
203
  console.log(chalk.yellow("\nRun cancelled. Staged changes were discarded — nothing was written."));
197
204
  return 0;
198
205
  }
199
- const { reportError } = await import("./chunks/errors-ZXTAHCZI.js");
206
+ const { reportError } = await import("./chunks/errors-OJZTUG74.js");
200
207
  reportError(e, debug);
201
208
  return 1;
202
209
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saarthiclaw",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "An AI developer assistant that lives in your project's terminal. Ask, Plan and Agent modes — the AI proposes, you approve every change.",
5
5
  "keywords": [
6
6
  "ai",
@@ -1,185 +0,0 @@
1
- import {
2
- DEFAULT_MODEL,
3
- loadConfig
4
- } from "./chunk-2GDAWRT7.js";
5
- import {
6
- findWorkspaceRoot
7
- } from "./chunk-MMIJKDOU.js";
8
-
9
- // ai/errors.ts
10
- var MissingApiKeyError = class extends Error {
11
- constructor() {
12
- super("OPENROUTER_API_KEY is not set");
13
- this.name = "MissingApiKeyError";
14
- }
15
- };
16
- var FREE_TIER_NOTE = "Free OpenRouter models allow roughly 20 requests/minute and about 200 requests/day. Wait a minute, switch model with `--model <id>`, or add credits on openrouter.ai.";
17
- function asErrorLike(e) {
18
- return e && typeof e === "object" ? e : { message: String(e) };
19
- }
20
- function unwrap(e) {
21
- let cur = asErrorLike(e);
22
- for (let i = 0; i < 6; i++) {
23
- if (cur.name === "AI_RetryError" && cur.lastError) {
24
- cur = asErrorLike(cur.lastError);
25
- continue;
26
- }
27
- if (cur.statusCode === void 0 && cur.status === void 0 && cur.cause) {
28
- const c = asErrorLike(cur.cause);
29
- if (c.statusCode !== void 0 || c.status !== void 0 || c.name === "AI_RetryError") {
30
- cur = c;
31
- continue;
32
- }
33
- }
34
- break;
35
- }
36
- return cur;
37
- }
38
- var NETWORK_CODES = /* @__PURE__ */ new Set([
39
- "ECONNREFUSED",
40
- "ECONNRESET",
41
- "ENOTFOUND",
42
- "EAI_AGAIN",
43
- "ETIMEDOUT",
44
- "ENETUNREACH",
45
- "EHOSTUNREACH",
46
- "UND_ERR_CONNECT_TIMEOUT",
47
- "UND_ERR_SOCKET"
48
- ]);
49
- function findCode(e) {
50
- let cur = e;
51
- for (let i = 0; i < 6 && cur && typeof cur === "object"; i++) {
52
- const c = cur.code;
53
- if (typeof c === "string") return c;
54
- cur = cur.cause;
55
- }
56
- return void 0;
57
- }
58
- function mapAiError(error) {
59
- const outer = asErrorLike(error);
60
- if (error instanceof MissingApiKeyError || outer.name === "MissingApiKeyError" || outer.name === "AI_LoadAPIKeyError") {
61
- return {
62
- kind: "missing_key",
63
- title: "No OpenRouter API key configured.",
64
- hint: "Run `saarthiclaw init` (or set OPENROUTER_API_KEY in your project .env). Get a key at https://openrouter.ai/keys"
65
- };
66
- }
67
- if (outer.name === "AI_NoOutputGeneratedError") {
68
- return {
69
- kind: "no_output",
70
- title: "The model finished without giving an answer.",
71
- hint: "This happens when a model keeps calling tools until it runs out of steps. Try again, ask a more specific question, or use a stronger model with `--model <id>`."
72
- };
73
- }
74
- if (outer.name === "AI_NoObjectGeneratedError") {
75
- return {
76
- kind: "no_output",
77
- title: "The model did not return a valid plan.",
78
- hint: "Try again, or use a model that is better at structured output (e.g. `--model openai/gpt-4o-mini`)."
79
- };
80
- }
81
- if (outer.name === "AbortError" || outer.name === "RunCancelledError") {
82
- return { kind: "cancelled", title: "Cancelled.", hint: "Nothing was written." };
83
- }
84
- const e = unwrap(error);
85
- const status = e.statusCode ?? e.status;
86
- const body = `${e.message ?? ""} ${e.responseBody ?? ""}`.toLowerCase();
87
- if (e.name === "TimeoutError" || /timed? ?out/.test(body) && status === void 0) {
88
- return {
89
- kind: "timeout",
90
- title: "The AI request timed out.",
91
- hint: "The model may be overloaded. Try again, or pick a faster model with `--model <id>`."
92
- };
93
- }
94
- if (status === 401) {
95
- return {
96
- kind: "invalid_key",
97
- title: "OpenRouter rejected the API key (401).",
98
- hint: "Check OPENROUTER_API_KEY or run `saarthiclaw init` to replace it. Keys: https://openrouter.ai/keys",
99
- status
100
- };
101
- }
102
- if (status === 402) {
103
- return {
104
- kind: "payment",
105
- title: "OpenRouter says this request needs credits (402).",
106
- hint: "Use a `:free` model (e.g. qwen/qwen3-coder:free) or add credits at https://openrouter.ai/credits",
107
- status
108
- };
109
- }
110
- if (status === 403) {
111
- return {
112
- kind: "forbidden",
113
- title: "OpenRouter refused the request (403).",
114
- hint: "Your key may lack permission for this model, or the input was flagged by moderation. Try another model.",
115
- status
116
- };
117
- }
118
- if (status === 429) {
119
- return {
120
- kind: "rate_limit",
121
- title: "Rate limited by OpenRouter (429), even after retrying with backoff.",
122
- hint: FREE_TIER_NOTE,
123
- status
124
- };
125
- }
126
- if (status === 404 || status === 400 && /(not a valid model|no endpoints found|model .*not (found|exist)|unknown model)/.test(body)) {
127
- return {
128
- kind: "model_not_found",
129
- title: "That model is not available on OpenRouter.",
130
- hint: "Free model lineups rotate. Pick another with `saarthiclaw init` or `--model <id>` (see https://openrouter.ai/models?q=free).",
131
- status
132
- };
133
- }
134
- const code = findCode(error);
135
- if (code && NETWORK_CODES.has(code) || /fetch failed|network|socket hang up|getaddrinfo/.test(body)) {
136
- return {
137
- kind: "network",
138
- title: "Could not reach OpenRouter (network error).",
139
- hint: "Check your internet connection, proxy or firewall, then try again."
140
- };
141
- }
142
- if (status !== void 0 && status >= 500) {
143
- return {
144
- kind: "unknown",
145
- title: `OpenRouter had a server error (${status}).`,
146
- hint: "This is usually temporary — try again in a moment or switch model.",
147
- status
148
- };
149
- }
150
- return {
151
- kind: "unknown",
152
- title: e.message?.split("\n")[0] || "Unexpected AI error.",
153
- hint: "Run with --debug for details, or `saarthiclaw doctor` to check your setup.",
154
- status
155
- };
156
- }
157
- var AI_MAX_RETRIES = 3;
158
-
159
- // ai/ai.config.ts
160
- import { createOpenRouter } from "@openrouter/ai-sdk-provider";
161
- function getAgentModel(options = {}) {
162
- let apiKey = options.apiKey?.trim();
163
- let modelId = options.model?.trim();
164
- if (!apiKey || !modelId) {
165
- const cfg = loadConfig({ root: findWorkspaceRoot() });
166
- apiKey ||= cfg.openrouterApiKey;
167
- modelId ||= cfg.model;
168
- }
169
- if (!apiKey) throw new MissingApiKeyError();
170
- const provider = createOpenRouter({
171
- apiKey,
172
- headers: {
173
- "HTTP-Referer": "https://github.com/hritik0447/SaarthiClaw",
174
- "X-Title": "SaarthiClaw"
175
- }
176
- });
177
- return provider(modelId || DEFAULT_MODEL);
178
- }
179
-
180
- export {
181
- MissingApiKeyError,
182
- mapAiError,
183
- AI_MAX_RETRIES,
184
- getAgentModel
185
- };
@@ -1,64 +0,0 @@
1
- import {
2
- NonInteractiveError
3
- } from "./chunk-IT46XDPQ.js";
4
- import {
5
- PathSafetyError
6
- } from "./chunk-XTVJWMUH.js";
7
- import {
8
- mapAiError
9
- } from "./chunk-BTFIQWAE.js";
10
- import {
11
- ConfigError
12
- } from "./chunk-2GDAWRT7.js";
13
-
14
- // cli/errors.ts
15
- import chalk from "chalk";
16
- var UserFacingError = class extends Error {
17
- constructor(message, hint) {
18
- super(message);
19
- this.hint = hint;
20
- this.name = "UserFacingError";
21
- }
22
- hint;
23
- };
24
- function looksLikeAiError(e) {
25
- if (!e || typeof e !== "object") return false;
26
- const name = e.name ?? "";
27
- return name.startsWith("AI_") || name === "MissingApiKeyError" || "statusCode" in e;
28
- }
29
- function reportError(error, debug) {
30
- let title;
31
- let hint;
32
- if (error instanceof UserFacingError) {
33
- title = error.message;
34
- hint = error.hint;
35
- } else if (error instanceof ConfigError) {
36
- title = "Configuration problem";
37
- hint = `${error.message}
38
- Fix the file above or re-run \`saarthiclaw init\`.`;
39
- } else if (error instanceof NonInteractiveError || error instanceof PathSafetyError) {
40
- title = error.message;
41
- } else if (looksLikeAiError(error)) {
42
- const f = mapAiError(error);
43
- title = f.title;
44
- hint = f.hint;
45
- } else {
46
- title = error instanceof Error ? error.message : String(error);
47
- hint = debug ? void 0 : "Run again with --debug for details, or `saarthiclaw doctor` to check your setup.";
48
- }
49
- console.error(`
50
- ${chalk.red("✖")} ${chalk.bold(title)}`);
51
- if (hint) for (const line of hint.split("\n")) console.error(chalk.dim(` ${line}`));
52
- if (debug && error instanceof Error && error.stack) {
53
- console.error(chalk.dim(`
54
- ${error.stack}`));
55
- const cause = error.cause;
56
- if (cause) console.error(chalk.dim(`Caused by: ${cause instanceof Error ? cause.stack : String(cause)}`));
57
- }
58
- console.error("");
59
- }
60
-
61
- export {
62
- UserFacingError,
63
- reportError
64
- };
@@ -1,143 +0,0 @@
1
-
2
- // modes/agent/path-safety.ts
3
- import fs from "node:fs";
4
- import path from "node:path";
5
- var PathSafetyError = class extends Error {
6
- constructor(message) {
7
- super(message);
8
- this.name = "PathSafetyError";
9
- }
10
- };
11
- var SECRET_PATTERNS = [
12
- ".env",
13
- ".env.*",
14
- "*.pem",
15
- "*.key",
16
- "*.p12",
17
- "*.pfx",
18
- "id_rsa*",
19
- "id_dsa*",
20
- "id_ecdsa*",
21
- "id_ed25519*",
22
- ".npmrc",
23
- ".yarnrc.yml",
24
- ".pypirc",
25
- ".netrc",
26
- ".pgpass",
27
- ".ssh",
28
- ".aws",
29
- ".saarthiclaw"
30
- ];
31
- function toPosix(p) {
32
- return p.replace(/\\/g, "/");
33
- }
34
- var regexCache = /* @__PURE__ */ new Map();
35
- function globToRegExp(glob) {
36
- const cached = regexCache.get(glob);
37
- if (cached) return cached;
38
- let re = "";
39
- for (let i = 0; i < glob.length; i++) {
40
- const c = glob[i];
41
- if (c === "*") {
42
- if (glob[i + 1] === "*") {
43
- re += ".*";
44
- i++;
45
- if (glob[i + 1] === "/") i++;
46
- } else {
47
- re += "[^/]*";
48
- }
49
- } else if (c === "?") {
50
- re += "[^/]";
51
- } else {
52
- re += c.replace(/[.+^${}()|[\]\\]/g, "\\$&");
53
- }
54
- }
55
- const out = new RegExp(`^${re}$`, "i");
56
- regexCache.set(glob, out);
57
- return out;
58
- }
59
- function matchesPattern(relPosix, pattern) {
60
- const p = toPosix(pattern).replace(/^\.\//, "").replace(/\/$/, "");
61
- if (!p) return false;
62
- const norm = relPosix.replace(/^\.\//, "");
63
- const segments = norm.split("/").filter((s) => s && s !== ".");
64
- if (!p.includes("/")) {
65
- const re2 = globToRegExp(p);
66
- return segments.some((s) => re2.test(s));
67
- }
68
- const re = globToRegExp(p);
69
- for (let i = 1; i <= segments.length; i++) {
70
- if (re.test(segments.slice(0, i).join("/"))) return true;
71
- }
72
- return false;
73
- }
74
- function isSecretPath(relPosix) {
75
- return SECRET_PATTERNS.some((p) => matchesPattern(relPosix, p));
76
- }
77
- function isExcludedPath(relPosix, patterns) {
78
- return patterns.some((p) => matchesPattern(relPosix, p));
79
- }
80
- function lexists(p) {
81
- try {
82
- fs.lstatSync(p);
83
- return true;
84
- } catch {
85
- return false;
86
- }
87
- }
88
- function isInside(root, target) {
89
- const rel = path.relative(root, target);
90
- return rel === "" || !rel.startsWith(`..${path.sep}`) && rel !== ".." && !path.isAbsolute(rel);
91
- }
92
- var realRootCache;
93
- function realRootOf(rootAbs) {
94
- if (realRootCache?.root === rootAbs) return realRootCache.real;
95
- const real = fs.realpathSync(rootAbs);
96
- realRootCache = { root: rootAbs, real };
97
- return real;
98
- }
99
- function resolveInsideRoot(root, input) {
100
- if (typeof input !== "string") throw new PathSafetyError("Path must be a string");
101
- if (input.includes("\0")) throw new PathSafetyError("Path contains a NUL byte");
102
- let p = toPosix(input.trim());
103
- if (!p) p = ".";
104
- const rootAbs = path.resolve(root);
105
- if (process.platform !== "win32" && (/^[a-zA-Z]:\//.test(p) || p.startsWith("//"))) {
106
- throw new PathSafetyError(`Path escapes workspace: ${input}`);
107
- }
108
- const abs = path.resolve(rootAbs, p);
109
- if (!isInside(rootAbs, abs)) {
110
- throw new PathSafetyError(`Path escapes workspace: ${input}`);
111
- }
112
- const realRoot = realRootOf(rootAbs);
113
- let probe = abs;
114
- while (!lexists(probe)) {
115
- const parent = path.dirname(probe);
116
- if (parent === probe) break;
117
- probe = parent;
118
- }
119
- let realProbe;
120
- try {
121
- realProbe = fs.realpathSync(probe);
122
- } catch {
123
- throw new PathSafetyError(`Path is a dangling symlink: ${input}`);
124
- }
125
- if (!isInside(realRoot, realProbe)) {
126
- throw new PathSafetyError(`Path resolves outside workspace via symlink: ${input}`);
127
- }
128
- return abs;
129
- }
130
- function relativePosix(root, abs) {
131
- const rel = path.relative(path.resolve(root), abs);
132
- return rel ? toPosix(rel) : ".";
133
- }
134
-
135
- export {
136
- PathSafetyError,
137
- toPosix,
138
- globToRegExp,
139
- isSecretPath,
140
- isExcludedPath,
141
- resolveInsideRoot,
142
- relativePosix
143
- };
@@ -1,24 +0,0 @@
1
- import {
2
- runPlanMode,
3
- stepPrompt
4
- } from "./chunk-VDYO3QC7.js";
5
- import "./chunk-OICPXSO2.js";
6
- import "./chunk-DSQDVSZS.js";
7
- import "./chunk-OS5GVLKA.js";
8
- import "./chunk-QRAFFI5V.js";
9
- import "./chunk-SKYTL7AH.js";
10
- import "./chunk-E4DRW4AW.js";
11
- import "./chunk-HGBZ55ND.js";
12
- import "./chunk-GX2I7K4S.js";
13
- import "./chunk-5WH3FNFK.js";
14
- import "./chunk-EG5A2Q6X.js";
15
- import "./chunk-G6GCAEKE.js";
16
- import "./chunk-IT46XDPQ.js";
17
- import "./chunk-XTVJWMUH.js";
18
- import "./chunk-BTFIQWAE.js";
19
- import "./chunk-2GDAWRT7.js";
20
- import "./chunk-MMIJKDOU.js";
21
- export {
22
- runPlanMode,
23
- stepPrompt
24
- };
@@ -1,9 +1,9 @@
1
- import {
2
- maskSecret
3
- } from "./chunk-2OOG5CBM.js";
4
1
  import {
5
2
  ensureGitignore
6
3
  } from "./chunk-R7ID2QVW.js";
4
+ import {
5
+ maskSecret
6
+ } from "./chunk-2OOG5CBM.js";
7
7
  import {
8
8
  DEFAULT_MODEL,
9
9
  MODEL_PRESETS,