saarthiclaw 0.2.1 → 0.2.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +2 -0
  3. package/dist/chunks/{chunk-QFVMJJQY.js → chunk-44LLGJXH.js} +7 -7
  4. package/dist/chunks/{chunk-GSBUJPPF.js → chunk-BBQ26JQA.js} +5 -5
  5. package/dist/chunks/{chunk-OS5GVLKA.js → chunk-CGJ4VEUD.js} +1 -1
  6. package/dist/chunks/{chunk-4CNBITFA.js → chunk-CGTA77EE.js} +27 -7
  7. package/dist/chunks/{chunk-ZXVP7JFV.js → chunk-CUC6MUW7.js} +11 -13
  8. package/dist/chunks/{chunk-E4DRW4AW.js → chunk-H2FAKNUI.js} +10 -2
  9. package/dist/chunks/{chunk-OICPXSO2.js → chunk-HFMRQTXE.js} +1 -1
  10. package/dist/chunks/{chunk-4YYY2YOT.js → chunk-KAWTUWO2.js} +25 -7
  11. package/dist/chunks/{chunk-EG5A2Q6X.js → chunk-OJCC4JH2.js} +1 -1
  12. package/dist/chunks/{chunk-SKYTL7AH.js → chunk-OLL2WJVK.js} +17 -8
  13. package/dist/chunks/chunk-R4PMMMD5.js +407 -0
  14. package/dist/chunks/{chunk-VAP6FVF5.js → chunk-XNIFO3FV.js} +6 -6
  15. package/dist/chunks/{client-5WRI2PBK.js → client-O4UP5DCM.js} +3 -5
  16. package/dist/chunks/{context-AP3U34DQ.js → context-OL7JU4XA.js} +5 -7
  17. package/dist/chunks/{doctor-O3R2YTRO.js → doctor-OBO4MCDY.js} +11 -6
  18. package/dist/chunks/{errors-ZXTAHCZI.js → errors-OJZTUG74.js} +2 -4
  19. package/dist/chunks/orchestrator-HUHXYUUM.js +23 -0
  20. package/dist/chunks/{orchestrator-CYIGQH74.js → orchestrator-IKYROOM5.js} +10 -12
  21. package/dist/chunks/orchestrator-QAFNDXD2.js +22 -0
  22. package/dist/chunks/{session-FPFJMS7Y.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-LTPGXMRU.js} +7 -9
  25. package/dist/chunks/{team-OFNBRXVP.js → team-AOMHCEDT.js} +25 -20
  26. package/dist/chunks/{telegram-LPSIQBQX.js → telegram-KO7VH46G.js} +14 -16
  27. package/dist/chunks/{wakeup-M5EIP54K.js → wakeup-YZNEVSVH.js} +16 -18
  28. package/dist/index.js +20 -19
  29. package/package.json +1 -1
  30. package/dist/chunks/chunk-BTFIQWAE.js +0 -185
  31. package/dist/chunks/chunk-G6GCAEKE.js +0 -64
  32. package/dist/chunks/chunk-XTVJWMUH.js +0 -143
  33. package/dist/chunks/orchestrator-4SMA442I.js +0 -24
  34. package/dist/chunks/orchestrator-L4TOOHXY.js +0 -23
package/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  All notable changes to this project are documented here. This project follows [Semantic Versioning](https://semver.org/).
4
4
 
5
+ ## 0.2.3 — 2026-11-19
6
+
7
+ ### Added
8
+ - **Team AI.** The Admin adds one OpenRouter key on the dashboard (Settings → Team AI). Every team member's AI requests then go through the dashboard, which adds that key and uses the Admin's chosen model, so nobody else needs an AI key. Only the team access key is sent from the terminal; the AI key never leaves the dashboard.
9
+ - `team connect` and `team status` say which AI is used, and `doctor` accepts Team AI in place of a local key.
10
+ - The model is picked without a network call, using `teamAi` stored in `.saarthiclaw/team.json`; it is refreshed on every dashboard check.
11
+ - Set `SAARTHICLAW_OWN_AI_KEY=1` to use your own key instead.
12
+
13
+ ## 0.2.2 — 2026-11-19
14
+
15
+ ### Fixed
16
+ - Agent mode: some models described the change (or pasted the code) and asked "Would you like me to create the file?" instead of calling a tool, so nothing was staged. The instructions now say plainly to stage changes with the tools and never ask permission (approval happens afterwards). If a model still only describes the change, the agent tells it once to go ahead and stage it.
17
+
5
18
  ## 0.2.1 — 2026-11-18
6
19
 
7
20
  ### Changed
package/README.md CHANGED
@@ -175,6 +175,8 @@ npx saarthiclaw agent "validate todo text"
175
175
  ```
176
176
  Closed the terminal before the Admin decided? `npx saarthiclaw team sync` applies whatever was approved since.
177
177
 
178
+ **AI for the whole team (one key):** the Admin adds an OpenRouter key on the dashboard under **Settings → Team AI**. From then on every teammate's `ask`, `plan` and `agent` use it through the dashboard, so teammates need **no AI key of their own**. The key never leaves the dashboard, and everyone uses the model the Admin chose. (`SAARTHICLAW_OWN_AI_KEY=1` makes a terminal use its own key instead.)
179
+
178
180
  How it stays safe:
179
181
  - **The dashboard never touches files.** It stores the proposal and the decision; your own terminal applies it.
180
182
  - **No overwriting newer work.** Each proposal carries a hash of the file it was based on. If the file changed since, `team sync` does not apply it and reports it as failed; ask the agent again.
@@ -8,17 +8,17 @@ import {
8
8
  } from "./chunk-QRAFFI5V.js";
9
9
  import {
10
10
  getTeamContext
11
- } from "./chunk-SKYTL7AH.js";
12
- import {
13
- sha256Hex
14
- } from "./chunk-E4DRW4AW.js";
11
+ } from "./chunk-OLL2WJVK.js";
15
12
  import {
16
13
  RunCancelledError,
17
14
  runCancellable
18
15
  } from "./chunk-HGBZ55ND.js";
16
+ import {
17
+ sha256Hex
18
+ } from "./chunk-H2FAKNUI.js";
19
19
  import {
20
20
  resolveInsideRoot
21
- } from "./chunk-XTVJWMUH.js";
21
+ } from "./chunk-R4PMMMD5.js";
22
22
 
23
23
  // modes/agent/agent-tools.ts
24
24
  import { tool } from "ai";
@@ -135,7 +135,7 @@ async function generateWithProgress(agent, prompt, label) {
135
135
  try {
136
136
  const result = await runCancellable(
137
137
  (signal) => agent.generate({
138
- prompt,
138
+ ...typeof prompt === "string" ? { prompt } : { messages: prompt },
139
139
  abortSignal: signal,
140
140
  onStepFinish: (step) => {
141
141
  const parts = step.content ?? [];
@@ -361,7 +361,7 @@ async function sendForApproval(session, tracker, info, team) {
361
361
  📨 Sent ${res.ids.length} change${res.ids.length === 1 ? "" : "s"} to the Admin for approval.`) + chalk2.dim(" Nothing was written yet.\n"));
362
362
  const wait = session.prompter.interactive ? await session.prompter.confirm({ message: "Wait here for the Admin's decision? (approved changes are applied here right after)", initialValue: true }) : false;
363
363
  if (wait) {
364
- const { runTeamSync } = await import("./sync-S2A65FIE.js");
364
+ const { runTeamSync } = await import("./sync-LTPGXMRU.js");
365
365
  const summary = await runTeamSync(session, { wait: true });
366
366
  return { approved: summary.applied > 0, sent: res.ids.length };
367
367
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createWebTools
3
- } from "./chunk-OICPXSO2.js";
3
+ } from "./chunk-HFMRQTXE.js";
4
4
  import {
5
5
  createReadOnlyTools,
6
6
  dedupeReadOnlyTools,
@@ -8,19 +8,19 @@ import {
8
8
  finishOnLastStep,
9
9
  generateWithProgress,
10
10
  renderTerminalMarkdown
11
- } from "./chunk-QFVMJJQY.js";
11
+ } from "./chunk-44LLGJXH.js";
12
12
  import {
13
13
  ToolExecutor
14
- } from "./chunk-OS5GVLKA.js";
14
+ } from "./chunk-CGJ4VEUD.js";
15
15
  import {
16
16
  agentConfigFrom,
17
17
  createTracker,
18
18
  instructionsFor,
19
19
  readOnlyAgentConfig
20
- } from "./chunk-4YYY2YOT.js";
20
+ } from "./chunk-KAWTUWO2.js";
21
21
  import {
22
22
  AI_MAX_RETRIES
23
- } from "./chunk-BTFIQWAE.js";
23
+ } from "./chunk-R4PMMMD5.js";
24
24
 
25
25
  // modes/ask/orchestrator.ts
26
26
  import fs from "node:fs";
@@ -6,7 +6,7 @@ import {
6
6
  relativePosix,
7
7
  resolveInsideRoot,
8
8
  toPosix
9
- } from "./chunk-XTVJWMUH.js";
9
+ } from "./chunk-R4PMMMD5.js";
10
10
 
11
11
  // modes/agent/tool-executor.ts
12
12
  import fs from "node:fs";
@@ -4,15 +4,15 @@ import {
4
4
  finishOnLastStep,
5
5
  generateWithProgress,
6
6
  renderTerminalMarkdown
7
- } from "./chunk-QFVMJJQY.js";
7
+ } from "./chunk-44LLGJXH.js";
8
8
  import {
9
9
  ToolExecutor
10
- } from "./chunk-OS5GVLKA.js";
10
+ } from "./chunk-CGJ4VEUD.js";
11
11
  import {
12
12
  assertProjectOpen,
13
13
  describeTeamMode,
14
14
  getTeamContext
15
- } from "./chunk-SKYTL7AH.js";
15
+ } from "./chunk-OLL2WJVK.js";
16
16
  import {
17
17
  RunCancelledError
18
18
  } from "./chunk-HGBZ55ND.js";
@@ -20,10 +20,10 @@ import {
20
20
  agentConfigFrom,
21
21
  createTracker,
22
22
  instructionsFor
23
- } from "./chunk-4YYY2YOT.js";
23
+ } from "./chunk-KAWTUWO2.js";
24
24
  import {
25
25
  AI_MAX_RETRIES
26
- } from "./chunk-BTFIQWAE.js";
26
+ } from "./chunk-R4PMMMD5.js";
27
27
 
28
28
  // modes/agent/orchestrator.ts
29
29
  import chalk from "chalk";
@@ -85,7 +85,20 @@ async function runAgentTask(session, task, opts) {
85
85
  maxOutputTokens: 4e3,
86
86
  maxRetries: AI_MAX_RETRIES
87
87
  });
88
- const { text } = await generateWithProgress(agent, task, "Agent is thinking…");
88
+ let { text } = await generateWithProgress(agent, task, "Agent is thinking…");
89
+ if (tracker.PendingMutation().length === 0 && onlyDescribedTheChange(text)) {
90
+ console.log(chalk.dim("\nThe AI described the change instead of staging it; asking it to stage it now…"));
91
+ const followUp = await generateWithProgress(
92
+ agent,
93
+ [
94
+ { role: "user", content: task },
95
+ { role: "assistant", content: text },
96
+ { role: "user", content: "Yes, go ahead. Stage it now with the file tools (create_file / modify_file). Do not ask again; I will review the diff before anything is written." }
97
+ ],
98
+ "Staging the change…"
99
+ );
100
+ text = followUp.text || text;
101
+ }
89
102
  if (text.trim()) console.log("\n" + renderTerminalMarkdown(text) + "\n");
90
103
  const outcome = await finalizeStaged(session, tracker, executor, { task, summary: text, autoSend: opts.autoSend });
91
104
  return { text, ...outcome };
@@ -99,8 +112,15 @@ async function runAgentTask(session, task, opts) {
99
112
  executor.clearStaging();
100
113
  }
101
114
  }
115
+ function onlyDescribedTheChange(text) {
116
+ const t = text.trim();
117
+ if (!t) return false;
118
+ if (/```|^ {4}\S/m.test(t)) return true;
119
+ return /(would you like|shall i|should i|do you want|want me to|let me know if you('d| would)? like|can i go ahead|proceed\?)/i.test(t);
120
+ }
102
121
 
103
122
  export {
104
123
  runAgentMode,
105
- runAgentTask
124
+ runAgentTask,
125
+ onlyDescribedTheChange
106
126
  };
@@ -1,18 +1,13 @@
1
1
  import {
2
2
  clipOutput
3
- } from "./chunk-OS5GVLKA.js";
3
+ } from "./chunk-CGJ4VEUD.js";
4
4
  import {
5
5
  colorizePatch,
6
6
  riskBadge
7
7
  } from "./chunk-QRAFFI5V.js";
8
8
  import {
9
9
  getTeamContext
10
- } from "./chunk-SKYTL7AH.js";
11
- import {
12
- readSyncState,
13
- sha256Hex,
14
- writeSyncState
15
- } from "./chunk-E4DRW4AW.js";
10
+ } from "./chunk-OLL2WJVK.js";
16
11
  import {
17
12
  RunCancelledError,
18
13
  runCancellable
@@ -21,16 +16,19 @@ import {
21
16
  createAuditLogger
22
17
  } from "./chunk-5WH3FNFK.js";
23
18
  import {
24
- UserFacingError
25
- } from "./chunk-G6GCAEKE.js";
26
- import {
27
- NonInteractiveError
28
- } from "./chunk-IT46XDPQ.js";
19
+ readSyncState,
20
+ sha256Hex,
21
+ writeSyncState
22
+ } from "./chunk-H2FAKNUI.js";
29
23
  import {
24
+ UserFacingError,
30
25
  isSecretPath,
31
26
  relativePosix,
32
27
  resolveInsideRoot
33
- } from "./chunk-XTVJWMUH.js";
28
+ } from "./chunk-R4PMMMD5.js";
29
+ import {
30
+ NonInteractiveError
31
+ } from "./chunk-IT46XDPQ.js";
34
32
 
35
33
  // team/sync.ts
36
34
  import { spawnSync } from "node:child_process";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  UserFacingError
3
- } from "./chunk-G6GCAEKE.js";
3
+ } from "./chunk-R4PMMMD5.js";
4
4
  import {
5
5
  userConfigDir
6
6
  } from "./chunk-2GDAWRT7.js";
@@ -106,6 +106,13 @@ function readSyncState(root) {
106
106
  function writeSyncState(root, state) {
107
107
  writeJson(syncStateFile(root), { seen: state.seen.slice(-2e3), lastSyncAt: state.lastSyncAt });
108
108
  }
109
+ function teamAiFor(root, env = process.env) {
110
+ if (env.SAARTHICLAW_OWN_AI_KEY === "1") return void 0;
111
+ const link = readTeamLink(root, env);
112
+ if (!link?.teamAi) return void 0;
113
+ const key = readKey(link.server, root, env);
114
+ return key ? { server: link.server, key } : void 0;
115
+ }
109
116
 
110
117
  export {
111
118
  KEY_PATTERN,
@@ -122,5 +129,6 @@ export {
122
129
  saveKey,
123
130
  removeKey,
124
131
  readSyncState,
125
- writeSyncState
132
+ writeSyncState,
133
+ teamAiFor
126
134
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  clipOutput
3
- } from "./chunk-OS5GVLKA.js";
3
+ } from "./chunk-CGJ4VEUD.js";
4
4
 
5
5
  // modes/plan/web-tools.ts
6
6
  import { tool } from "ai";
@@ -2,12 +2,14 @@ import {
2
2
  attachAuditLog
3
3
  } from "./chunk-5WH3FNFK.js";
4
4
  import {
5
- isSecretPath
6
- } from "./chunk-XTVJWMUH.js";
5
+ teamAiFor
6
+ } from "./chunk-H2FAKNUI.js";
7
7
  import {
8
8
  getAgentModel,
9
+ getTeamModel,
10
+ isSecretPath,
9
11
  mapAiError
10
- } from "./chunk-BTFIQWAE.js";
12
+ } from "./chunk-R4PMMMD5.js";
11
13
 
12
14
  // modes/session.ts
13
15
  import chalk from "chalk";
@@ -175,7 +177,12 @@ function buildProjectBrief(root, budgets = {}) {
175
177
  }
176
178
 
177
179
  // context/instructions.ts
178
- var PERSONA = "You are SaarthiClaw, a careful coding assistant that lives in the developer's terminal. You behave like a very capable intern: you investigate first, explain your intent, and always let the senior developer (the human) approve changes.";
180
+ var PERSONA = "You are SaarthiClaw, a careful coding assistant that lives in the developer's terminal. You behave like a very capable intern: you investigate first, then do the work. The senior developer (the human) reviews and approves every staged change afterwards.";
181
+ var ACT_RULES = [
182
+ 'Do NOT ask for permission or confirmation before making a change, and do not end with a question like "Would you like me to create the file?" — staging IS the safe step; the human approves afterwards.',
183
+ "Never paste the code into your reply instead of staging it. If the task asks for code, a file, a fix or a feature, call create_file / modify_file / create_folder (or delete_file) so the change is staged.",
184
+ "If the request is ambiguous, pick the most reasonable interpretation, stage it, and mention the assumption in your summary."
185
+ ];
179
186
  var MODE_RULES = {
180
187
  ask: [
181
188
  "Mode: ASK (read-only). Answer the question about this codebase.",
@@ -199,18 +206,21 @@ var MODE_RULES = {
199
206
  ],
200
207
  "plan-step": [
201
208
  "Mode: AGENT executing ONE step of an approved plan.",
209
+ ...ACT_RULES,
202
210
  "Only do the work for the current step; earlier steps' staged changes are visible to read_file.",
203
211
  "Stage changes with the file tools; prefer minimal, focused diffs.",
204
212
  "Finish with a short summary of what you staged and why."
205
213
  ],
206
214
  agent: [
207
215
  "Mode: AGENT. Complete the user's task by staging changes with the tools.",
216
+ ...ACT_RULES,
208
217
  "Read the relevant files first, then stage the smallest correct change (minimal diffs, keep the existing style).",
209
- "Explain your intent briefly before and after making changes.",
218
+ "Only answer without staging anything when the user clearly asked a question rather than for a change.",
210
219
  "Finish with a short summary listing every staged change."
211
220
  ],
212
221
  "telegram-agent": [
213
222
  "Mode: AGENT via Telegram. Complete the task by staging changes with the tools.",
223
+ ...ACT_RULES,
214
224
  "Read relevant files first; stage minimal diffs; finish with a short summary of staged changes."
215
225
  ]
216
226
  };
@@ -344,7 +354,11 @@ function createSession(opts) {
344
354
  config,
345
355
  prompter: opts.prompter,
346
356
  debug: Boolean(opts.debug),
347
- model: opts.model ?? (() => getAgentModel({ apiKey: config.openrouterApiKey, model: config.model })),
357
+ model: opts.model ?? (() => {
358
+ const team = teamAiFor(config.root, opts.env ?? process.env);
359
+ if (team) return getTeamModel(team.server, team.key, config.model);
360
+ return getAgentModel({ apiKey: config.openrouterApiKey, model: config.model });
361
+ }),
348
362
  teamFetch: opts.teamFetch,
349
363
  env: opts.env,
350
364
  teamPollMs: opts.teamPollMs
@@ -377,6 +391,9 @@ ${chalk.red("✖")} ${chalk.bold(f.title)}`);
377
391
  if (debug && error instanceof Error && error.stack) console.error(chalk.dim(error.stack));
378
392
  console.error("");
379
393
  }
394
+ function hasAiAccess(session) {
395
+ return Boolean(session.config.openrouterApiKey) || Boolean(teamAiFor(session.root, session.env ?? process.env));
396
+ }
380
397
 
381
398
  export {
382
399
  agentConfigFrom,
@@ -385,5 +402,6 @@ export {
385
402
  hasWebTools,
386
403
  instructionsFor,
387
404
  createTracker,
388
- reportAiError
405
+ reportAiError,
406
+ hasAiAccess
389
407
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  UserFacingError
3
- } from "./chunk-G6GCAEKE.js";
3
+ } from "./chunk-R4PMMMD5.js";
4
4
 
5
5
  // team/client.ts
6
6
  var LEVEL_LABEL = {
@@ -1,15 +1,16 @@
1
- import {
2
- readKey,
3
- readTeamLink
4
- } from "./chunk-E4DRW4AW.js";
5
1
  import {
6
2
  LEVEL_LABEL,
7
3
  TeamClient,
8
4
  TeamNetworkError
9
- } from "./chunk-EG5A2Q6X.js";
5
+ } from "./chunk-OJCC4JH2.js";
6
+ import {
7
+ readKey,
8
+ readTeamLink,
9
+ writeTeamLink
10
+ } from "./chunk-H2FAKNUI.js";
10
11
  import {
11
12
  UserFacingError
12
- } from "./chunk-G6GCAEKE.js";
13
+ } from "./chunk-R4PMMMD5.js";
13
14
 
14
15
  // team/context.ts
15
16
  import chalk from "chalk";
@@ -36,7 +37,14 @@ async function resolve(session) {
36
37
  const { client, link } = found;
37
38
  try {
38
39
  const me = await client.whoami();
39
- return { mode: me.permissionLevel, client, me, link };
40
+ const teamAi = Boolean(me.policy?.teamAi);
41
+ if (link.teamAi !== teamAi && !envOf(session).SAARTHICLAW_TEAM_SERVER) {
42
+ try {
43
+ writeTeamLink(session.root, { ...link, teamAi });
44
+ } catch {
45
+ }
46
+ }
47
+ return { mode: me.permissionLevel, client, me, link: { ...link, teamAi } };
40
48
  } catch (e) {
41
49
  if (e instanceof TeamNetworkError && link.role === "admin") {
42
50
  console.log(chalk.yellow(`⚠ Team dashboard unreachable (${link.server}). Working as Admin; changes won't be logged there this time.`));
@@ -63,7 +71,8 @@ function describeTeamMode(ctx) {
63
71
  needs_approval: "your changes are sent to the Admin; nothing is written until they approve.",
64
72
  suggest_only: "you can ask and plan, and send suggestions; code changes are not allowed."
65
73
  };
66
- return `👥 Team${project}: ${who} — ${how[ctx.mode]}`;
74
+ const ai = ctx.me?.policy?.teamAi ? " AI: the team's key (from the dashboard)." : "";
75
+ return `👥 Team${project}: ${who} — ${how[ctx.mode]}${ai}`;
67
76
  }
68
77
  function assertProjectOpen(ctx) {
69
78
  const status = ctx.me?.project?.status;