saarthiclaw 0.1.0 → 0.2.2

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 (36) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +49 -1
  3. package/dist/chunks/chunk-3UFD5346.js +126 -0
  4. package/dist/chunks/{chunk-LLHZUSMZ.js → chunk-5WH3FNFK.js} +1 -0
  5. package/dist/chunks/chunk-DSQDVSZS.js +411 -0
  6. package/dist/chunks/chunk-E4DRW4AW.js +126 -0
  7. package/dist/chunks/chunk-EG5A2Q6X.js +121 -0
  8. package/dist/chunks/{chunk-GNAQO3JX.js → chunk-GX2I7K4S.js} +19 -7
  9. package/dist/chunks/{chunk-DORYMXNC.js → chunk-OICPXSO2.js} +1 -1
  10. package/dist/chunks/{chunk-4MPWZPGX.js → chunk-OS5GVLKA.js} +1 -219
  11. package/dist/chunks/{chunk-HNAZBEDV.js → chunk-QRAFFI5V.js} +6 -4
  12. package/dist/chunks/chunk-R7ID2QVW.js +39 -0
  13. package/dist/chunks/chunk-SKYTL7AH.js +83 -0
  14. package/dist/chunks/{chunk-3UTSY2MH.js → chunk-TTT3KK46.js} +9 -12
  15. package/dist/chunks/{chunk-EWADWZYM.js → chunk-VDYO3QC7.js} +21 -17
  16. package/dist/chunks/chunk-ZXVP7JFV.js +232 -0
  17. package/dist/chunks/client-5WRI2PBK.js +18 -0
  18. package/dist/chunks/context-AP3U34DQ.js +20 -0
  19. package/dist/chunks/{doctor-333IEMCL.js → doctor-O3R2YTRO.js} +21 -0
  20. package/dist/chunks/{history-IWDIOWLB.js → history-FANJN33X.js} +4 -3
  21. package/dist/chunks/{init-Z4YC3G7V.js → init-GCJNYE3Y.js} +17 -50
  22. package/dist/chunks/orchestrator-JFJU4FGP.js +24 -0
  23. package/dist/chunks/orchestrator-KNCW4K57.js +32 -0
  24. package/dist/chunks/orchestrator-NIDJK4C3.js +25 -0
  25. package/dist/chunks/{session-UUHCIT66.js → session-CRFC3IEU.js} +2 -2
  26. package/dist/chunks/store-KW257WIV.js +40 -0
  27. package/dist/chunks/sync-S2A65FIE.js +21 -0
  28. package/dist/chunks/team-RBSOK3HT.js +378 -0
  29. package/dist/chunks/{telegram-X36RUESQ.js → telegram-JSGRYPIX.js} +24 -11
  30. package/dist/chunks/{wakeup-I7FQO5BS.js → wakeup-4IP4JXVF.js} +57 -16
  31. package/dist/index.js +62 -13
  32. package/package.json +4 -2
  33. package/dist/chunks/chunk-GVDXGKLD.js +0 -82
  34. package/dist/chunks/orchestrator-QCIY6FLH.js +0 -17
  35. package/dist/chunks/orchestrator-SDAA5TOH.js +0 -18
  36. package/dist/chunks/orchestrator-WXGJJEJW.js +0 -26
@@ -0,0 +1,24 @@
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
+ };
@@ -0,0 +1,32 @@
1
+ import {
2
+ asMd,
3
+ askQuestion,
4
+ runAskMode,
5
+ runAskOnce,
6
+ saveAnswer,
7
+ validateMdFilename
8
+ } from "./chunk-TTT3KK46.js";
9
+ import "./chunk-OICPXSO2.js";
10
+ import "./chunk-DSQDVSZS.js";
11
+ import "./chunk-OS5GVLKA.js";
12
+ import "./chunk-QRAFFI5V.js";
13
+ import "./chunk-SKYTL7AH.js";
14
+ import "./chunk-E4DRW4AW.js";
15
+ import "./chunk-HGBZ55ND.js";
16
+ import "./chunk-GX2I7K4S.js";
17
+ import "./chunk-5WH3FNFK.js";
18
+ import "./chunk-EG5A2Q6X.js";
19
+ import "./chunk-G6GCAEKE.js";
20
+ import "./chunk-IT46XDPQ.js";
21
+ import "./chunk-XTVJWMUH.js";
22
+ import "./chunk-BTFIQWAE.js";
23
+ import "./chunk-2GDAWRT7.js";
24
+ import "./chunk-MMIJKDOU.js";
25
+ export {
26
+ asMd,
27
+ askQuestion,
28
+ runAskMode,
29
+ runAskOnce,
30
+ saveAnswer,
31
+ validateMdFilename
32
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ onlyDescribedTheChange,
3
+ runAgentMode,
4
+ runAgentTask
5
+ } from "./chunk-3UFD5346.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
+ onlyDescribedTheChange,
23
+ runAgentMode,
24
+ runAgentTask
25
+ };
@@ -4,10 +4,10 @@ import {
4
4
  hasWebTools,
5
5
  instructionsFor,
6
6
  reportAiError
7
- } from "./chunk-GNAQO3JX.js";
7
+ } from "./chunk-GX2I7K4S.js";
8
+ import "./chunk-5WH3FNFK.js";
8
9
  import "./chunk-XTVJWMUH.js";
9
10
  import "./chunk-BTFIQWAE.js";
10
- import "./chunk-LLHZUSMZ.js";
11
11
  import "./chunk-2GDAWRT7.js";
12
12
  import "./chunk-MMIJKDOU.js";
13
13
  export {
@@ -0,0 +1,40 @@
1
+ import {
2
+ KEY_PATTERN,
3
+ credentialId,
4
+ credentialsFile,
5
+ normalizeServer,
6
+ readKey,
7
+ readSyncState,
8
+ readTeamLink,
9
+ removeKey,
10
+ removeTeamLink,
11
+ saveKey,
12
+ sha256Hex,
13
+ syncStateFile,
14
+ teamFile,
15
+ writeSyncState,
16
+ writeTeamLink
17
+ } from "./chunk-E4DRW4AW.js";
18
+ import "./chunk-G6GCAEKE.js";
19
+ import "./chunk-IT46XDPQ.js";
20
+ import "./chunk-XTVJWMUH.js";
21
+ import "./chunk-BTFIQWAE.js";
22
+ import "./chunk-2GDAWRT7.js";
23
+ import "./chunk-MMIJKDOU.js";
24
+ export {
25
+ KEY_PATTERN,
26
+ credentialId,
27
+ credentialsFile,
28
+ normalizeServer,
29
+ readKey,
30
+ readSyncState,
31
+ readTeamLink,
32
+ removeKey,
33
+ removeTeamLink,
34
+ saveKey,
35
+ sha256Hex,
36
+ syncStateFile,
37
+ teamFile,
38
+ writeSyncState,
39
+ writeTeamLink
40
+ };
@@ -0,0 +1,21 @@
1
+ import {
2
+ applyRemoteAction,
3
+ runTeamSync
4
+ } from "./chunk-ZXVP7JFV.js";
5
+ import "./chunk-OS5GVLKA.js";
6
+ import "./chunk-QRAFFI5V.js";
7
+ import "./chunk-SKYTL7AH.js";
8
+ import "./chunk-E4DRW4AW.js";
9
+ import "./chunk-HGBZ55ND.js";
10
+ import "./chunk-5WH3FNFK.js";
11
+ import "./chunk-EG5A2Q6X.js";
12
+ import "./chunk-G6GCAEKE.js";
13
+ import "./chunk-IT46XDPQ.js";
14
+ import "./chunk-XTVJWMUH.js";
15
+ import "./chunk-BTFIQWAE.js";
16
+ import "./chunk-2GDAWRT7.js";
17
+ import "./chunk-MMIJKDOU.js";
18
+ export {
19
+ applyRemoteAction,
20
+ runTeamSync
21
+ };
@@ -0,0 +1,378 @@
1
+ import {
2
+ ensureGitignore
3
+ } from "./chunk-R7ID2QVW.js";
4
+ import {
5
+ runTeamSync
6
+ } from "./chunk-ZXVP7JFV.js";
7
+ import "./chunk-OS5GVLKA.js";
8
+ import "./chunk-QRAFFI5V.js";
9
+ import {
10
+ describeTeamMode,
11
+ getTeamContext,
12
+ teamClientFor
13
+ } from "./chunk-SKYTL7AH.js";
14
+ import {
15
+ KEY_PATTERN,
16
+ normalizeServer,
17
+ readKey,
18
+ readTeamLink,
19
+ removeKey,
20
+ removeTeamLink,
21
+ saveKey,
22
+ writeTeamLink
23
+ } from "./chunk-E4DRW4AW.js";
24
+ import "./chunk-HGBZ55ND.js";
25
+ import "./chunk-5WH3FNFK.js";
26
+ import {
27
+ LEVEL_LABEL,
28
+ TeamApiError,
29
+ TeamClient
30
+ } from "./chunk-EG5A2Q6X.js";
31
+ import {
32
+ UserFacingError
33
+ } from "./chunk-G6GCAEKE.js";
34
+ import "./chunk-IT46XDPQ.js";
35
+ import {
36
+ isSecretPath
37
+ } from "./chunk-XTVJWMUH.js";
38
+ import "./chunk-BTFIQWAE.js";
39
+ import "./chunk-2GDAWRT7.js";
40
+ import "./chunk-MMIJKDOU.js";
41
+
42
+ // cli/team.ts
43
+ import chalk from "chalk";
44
+
45
+ // team/scan.ts
46
+ import fs from "node:fs";
47
+ import path from "node:path";
48
+ var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", "build", ".next", ".cache", "coverage", ".saarthiclaw", ".test-build"]);
49
+ function readText(root, name) {
50
+ try {
51
+ return fs.readFileSync(path.join(root, name), "utf8");
52
+ } catch {
53
+ return null;
54
+ }
55
+ }
56
+ function exists(root, name) {
57
+ try {
58
+ return fs.statSync(path.join(root, name)).isFile();
59
+ } catch {
60
+ return false;
61
+ }
62
+ }
63
+ function projectSnapshot(root) {
64
+ let pkg = {};
65
+ try {
66
+ pkg = JSON.parse(readText(root, "package.json") ?? "{}");
67
+ } catch {
68
+ pkg = {};
69
+ }
70
+ const readme = readText(root, "README.md") ?? readText(root, "readme.md") ?? "";
71
+ const dependencies = Object.keys(pkg.dependencies ?? {});
72
+ const devDependencies = Object.keys(pkg.devDependencies ?? {});
73
+ const scripts = {};
74
+ for (const [k, v] of Object.entries(pkg.scripts ?? {})) if (typeof v === "string") scripts[k] = v;
75
+ const lines = [];
76
+ const walk = (dir, depth, prefix, relDir) => {
77
+ if (depth > 3 || lines.length >= 300) return;
78
+ let entries;
79
+ try {
80
+ entries = fs.readdirSync(dir, { withFileTypes: true });
81
+ } catch {
82
+ return;
83
+ }
84
+ entries = entries.filter((e) => !SKIP_DIRS.has(e.name) && !(e.isDirectory() && e.name.startsWith(".")) && !isSecretPath(relDir ? `${relDir}/${e.name}` : e.name)).sort((a, b) => a.name.localeCompare(b.name));
85
+ for (const e of entries) {
86
+ if (lines.length >= 300) return;
87
+ lines.push(`${prefix}├─ ${e.name}${e.isDirectory() ? "/" : ""}`);
88
+ if (e.isDirectory() && !e.isSymbolicLink()) walk(path.join(dir, e.name), depth + 1, `${prefix}│ `, relDir ? `${relDir}/${e.name}` : e.name);
89
+ }
90
+ };
91
+ walk(root, 1, "", "");
92
+ return {
93
+ name: (pkg.name || path.basename(root)).slice(0, 120),
94
+ rootPath: root,
95
+ techStack: { version: pkg.version || "1.0.0", scripts, dependencies, devDependencies },
96
+ signals: {
97
+ hasReadme: Boolean(readme),
98
+ hasTestScript: Boolean(scripts.test),
99
+ hasBuildScript: Boolean(scripts.build),
100
+ hasTypeScript: exists(root, "tsconfig.json"),
101
+ hasLockfile: ["package-lock.json", "bun.lockb", "bun.lock", "yarn.lock", "pnpm-lock.yaml"].some((f) => exists(root, f)),
102
+ hasGitignore: exists(root, ".gitignore"),
103
+ hasEnvExample: exists(root, ".env.example"),
104
+ dependencyCount: dependencies.length + devDependencies.length
105
+ },
106
+ readmeExcerpt: readme.slice(0, 1500),
107
+ fileTree: lines.join("\n")
108
+ };
109
+ }
110
+
111
+ // cli/team.ts
112
+ var DEFAULT_SERVER = "http://127.0.0.1:3000";
113
+ var MEMBER_LEVELS = ["trusted", "needs_approval", "suggest_only"];
114
+ function envOf(session) {
115
+ return session.env ?? process.env;
116
+ }
117
+ function requireLinked(session) {
118
+ const found = teamClientFor(session);
119
+ if (!found) throw new UserFacingError("This project is not connected to a team dashboard.", "Run `saarthiclaw team connect <dashboard-url>` first.");
120
+ return found;
121
+ }
122
+ function explainLevel(me) {
123
+ switch (me.permissionLevel) {
124
+ case "admin":
125
+ return "You are the Admin: you approve your own changes here, and your team's changes on the dashboard (Approvals).";
126
+ case "trusted":
127
+ return "You are Trusted: you approve your own AI changes in this terminal. Everything you apply is logged on the dashboard.";
128
+ case "needs_approval":
129
+ return "Your level is Needs approval: the agent's changes are sent to the Admin. Once approved, `saarthiclaw team sync` applies them here.";
130
+ case "suggest_only":
131
+ return "Your level is Suggest only: you can use Ask and Plan, and send ideas with `saarthiclaw team suggest`. Code changes are not allowed.";
132
+ }
133
+ }
134
+ async function teamConnect(session, serverArg) {
135
+ const env = envOf(session);
136
+ const existing = readTeamLink(session.root, env);
137
+ console.log(chalk.bold("\n👥 Connect to your team dashboard\n"));
138
+ const server = normalizeServer(
139
+ serverArg?.trim() || await session.prompter.text({
140
+ message: "Dashboard address",
141
+ placeholder: DEFAULT_SERVER,
142
+ initialValue: existing?.server ?? DEFAULT_SERVER,
143
+ validate: (v) => v.trim() ? void 0 : "Enter the address the Admin gave you"
144
+ })
145
+ );
146
+ let key = env.SAARTHICLAW_TEAM_KEY?.trim();
147
+ if (!key) {
148
+ key = (await session.prompter.password({
149
+ message: "Your access key (from the Admin, or the Admin key from `npm run setup`)",
150
+ validate: (v) => KEY_PATTERN.test(v.trim()) ? void 0 : "Keys look like sc_m_1a2b3c4d_… or sc_a_…"
151
+ })).trim();
152
+ }
153
+ if (!KEY_PATTERN.test(key)) throw new UserFacingError("That does not look like a SaarthiClaw access key.", "Keys look like sc_m_1a2b3c4d_<32 characters> (members) or sc_a_… (Admin).");
154
+ const client = new TeamClient(server, key, session.teamFetch);
155
+ const me = await client.whoami();
156
+ const reallyConnected = existing ? Boolean(readKey(existing.server, session.root, { ...env, SAARTHICLAW_TEAM_KEY: "" })) : false;
157
+ if (reallyConnected && existing?.name && (existing.name !== me.name || existing.server !== server) && session.prompter.interactive) {
158
+ const was = `${existing.name}${existing.permissionLevel ? ` (${LEVEL_LABEL[existing.permissionLevel] ?? existing.permissionLevel})` : ""}`;
159
+ const switchIt = await session.prompter.confirm({
160
+ message: `This folder is connected as ${was}. The key you pasted belongs to ${me.name} (${LEVEL_LABEL[me.permissionLevel]}). Switch this folder to ${me.name}?`,
161
+ initialValue: false
162
+ });
163
+ if (!switchIt) {
164
+ console.log(chalk.yellow(`
165
+ Nothing changed. This folder is still ${was}.
166
+ `));
167
+ return;
168
+ }
169
+ }
170
+ const credFile = saveKey(server, session.root, key, env);
171
+ writeTeamLink(session.root, {
172
+ server,
173
+ name: me.name,
174
+ role: me.role,
175
+ permissionLevel: me.permissionLevel,
176
+ projectName: me.project?.name,
177
+ connectedAt: (/* @__PURE__ */ new Date()).toISOString()
178
+ });
179
+ const gitignoreChanged = ensureGitignore(session.root, [".saarthiclaw/"]);
180
+ await getTeamContext(session, { refresh: true });
181
+ console.log(chalk.green(`
182
+ ✓ Connected as ${chalk.bold(me.name)} (${LEVEL_LABEL[me.permissionLevel]})`) + chalk.dim(` to ${server}`));
183
+ console.log(chalk.dim(` Key saved in ${credFile} (outside the project, never committed).`));
184
+ if (gitignoreChanged) console.log(chalk.dim(" Added .saarthiclaw/ to .gitignore."));
185
+ console.log(`
186
+ ${explainLevel(me)}
187
+ `);
188
+ if (!session.config.openrouterApiKey && me.permissionLevel !== "suggest_only") {
189
+ console.log(chalk.yellow("One more thing: this folder has no AI key yet, so the agent can't run here.") + chalk.dim(" Add it with ") + chalk.bold("npx saarthiclaw init") + "\n");
190
+ }
191
+ if (me.role === "admin") {
192
+ const share = !session.prompter.interactive || await session.prompter.confirm({
193
+ message: me.project?.linked ? `Update the dashboard's project details from this folder? (name, README, file list, health checks — no code)` : `Link this folder as the team project? (shares name, README, file list, health checks — no code)`,
194
+ initialValue: true
195
+ });
196
+ if (share) {
197
+ const p = await client.pushProject(projectSnapshot(session.root));
198
+ const link = readTeamLink(session.root, env);
199
+ if (link) writeTeamLink(session.root, { ...link, projectName: p.name });
200
+ console.log(chalk.green(`✓ Dashboard project: ${p.name}`));
201
+ }
202
+ console.log(chalk.dim("\nNext: invite developers with ") + chalk.bold("saarthiclaw team invite <name>") + chalk.dim(" (or on the dashboard → Members).\n"));
203
+ } else {
204
+ if (!me.project?.linked) console.log(chalk.yellow("The Admin has not linked a project yet. You can still connect; changes are accepted once they do.\n"));
205
+ const next = {
206
+ trusted: 'npx saarthiclaw agent "describe the change"',
207
+ needs_approval: 'npx saarthiclaw agent "describe the change" (it waits for the Admin, then applies)',
208
+ suggest_only: 'npx saarthiclaw team suggest "your idea"'
209
+ };
210
+ console.log(chalk.dim("Next: ") + chalk.bold(next[me.permissionLevel] ?? "npx saarthiclaw") + "\n");
211
+ }
212
+ }
213
+ async function teamStatus(session) {
214
+ const link = readTeamLink(session.root, envOf(session));
215
+ console.log(chalk.bold("\n👥 Team status\n"));
216
+ if (!link) {
217
+ console.log("Solo mode — this project is not connected to a team dashboard.");
218
+ console.log(chalk.dim("Working alone needs no setup. To work with a team: ") + chalk.bold("saarthiclaw team connect <dashboard-url>") + "\n");
219
+ return;
220
+ }
221
+ const team = await getTeamContext(session, { refresh: true });
222
+ const me = team.me;
223
+ if (!me) return;
224
+ const rows = [
225
+ ["Dashboard", link.server],
226
+ ["You", `${me.name} (${LEVEL_LABEL[me.permissionLevel]})`],
227
+ ["Project", me.project ? `${me.project.name} · ${me.project.status}` : chalk.yellow("not linked yet")]
228
+ ];
229
+ if (me.role === "admin") {
230
+ rows.push(["Waiting for you", me.pendingApprovals ? chalk.yellow(`${me.pendingApprovals} change(s) on the dashboard → Approvals`) : "nothing"]);
231
+ rows.push(["Agent inbox", me.inbox ? chalk.cyan(`${me.inbox} forwarded suggestion(s) → saarthiclaw team inbox`) : "empty"]);
232
+ } else {
233
+ rows.push(["Your changes", `${me.myPending} waiting for the Admin · ${me.myApproved} approved, not applied yet`]);
234
+ }
235
+ rows.push(["Unread messages", me.unreadMessages ? chalk.cyan(String(me.unreadMessages)) + chalk.dim(" (open the dashboard → Messages)") : "0"]);
236
+ rows.push(["File changes", me.policy.allowFileModification ? "allowed by the Admin" : chalk.yellow("turned off by the Admin")]);
237
+ const width = Math.max(...rows.map(([k]) => k.length));
238
+ for (const [k, v] of rows) console.log(` ${chalk.dim(k.padEnd(width))} ${v}`);
239
+ console.log(`
240
+ ${chalk.cyan(describeTeamMode(team) ?? "")}
241
+ `);
242
+ if (me.role === "member" && me.myApproved) console.log(chalk.bold("→ Run `saarthiclaw team sync` to apply your approved changes.\n"));
243
+ }
244
+ async function teamSync(session, opts) {
245
+ await runTeamSync(session, opts);
246
+ }
247
+ async function teamSuggest(session, words) {
248
+ const { client } = requireLinked(session);
249
+ const message = words.trim() || (await session.prompter.text({
250
+ message: "Your suggestion for the Admin",
251
+ placeholder: "e.g. Add input validation to the signup form",
252
+ validate: (v) => v.trim().length >= 10 ? void 0 : "Please write at least 10 characters"
253
+ })).trim();
254
+ if (message.length < 10) throw new UserFacingError("Please write at least 10 characters.");
255
+ if (message.length > 500) throw new UserFacingError("Suggestions can be at most 500 characters.");
256
+ await client.suggest(message);
257
+ console.log(chalk.green("\n💡 Suggestion sent.") + chalk.dim(" The Admin sees it on the dashboard under Suggestions and can forward it to the agent.\n"));
258
+ }
259
+ async function teamInvite(session, nameArg, levelArg) {
260
+ const { client, link } = requireLinked(session);
261
+ const name = nameArg.trim() || (await session.prompter.text({
262
+ message: "Developer's name",
263
+ validate: (v) => v.trim().length >= 2 && v.trim().length <= 40 ? void 0 : "2–40 characters"
264
+ })).trim();
265
+ let level;
266
+ if (levelArg) {
267
+ const norm = levelArg.trim().toLowerCase().replace(/[-\s]/g, "_");
268
+ if (!MEMBER_LEVELS.includes(norm)) throw new UserFacingError(`Unknown level "${levelArg}".`, "Use trusted, needs-approval or suggest-only.");
269
+ level = norm;
270
+ } else if (session.prompter.interactive) {
271
+ level = await session.prompter.select({
272
+ message: `What may ${name} do?`,
273
+ options: [
274
+ { value: "needs_approval", label: "Needs approval", hint: "their AI changes wait for you (recommended)" },
275
+ { value: "trusted", label: "Trusted", hint: "they approve their own changes" },
276
+ { value: "suggest_only", label: "Suggest only", hint: "ask, plan and suggest; no code changes" }
277
+ ],
278
+ initialValue: "needs_approval"
279
+ });
280
+ }
281
+ let r;
282
+ try {
283
+ r = await client.invite(name, level);
284
+ } catch (e) {
285
+ if (!(e instanceof TeamApiError && e.code === "NAME_TAKEN")) throw e;
286
+ if (!session.prompter.interactive) throw new UserFacingError(`${name} is already on the team.`, "Run this in a terminal to give them a new key, or use the dashboard → Members → Regenerate key.");
287
+ const again = await session.prompter.confirm({ message: `${name} is already on the team. Give ${name} a NEW key? (their old key stops working)`, initialValue: true });
288
+ if (!again) {
289
+ console.log(chalk.dim("\nNothing changed.\n"));
290
+ return;
291
+ }
292
+ r = await client.invite(name, level, true);
293
+ }
294
+ const lvl = LEVEL_LABEL[r.member.permissionLevel] ?? r.member.permissionLevel;
295
+ console.log(chalk.green(`
296
+ ✓ ${r.member.name} ${r.regenerated ? "has a new key" : "added"} (${lvl}).`));
297
+ console.log(chalk.bold("\nTheir access key — shown only once, send it privately:\n"));
298
+ console.log(" " + chalk.inverse(` ${r.key} `) + "\n");
299
+ console.log(chalk.dim(`They install SaarthiClaw in their copy of the project and run:`));
300
+ console.log(` ${chalk.bold(`npx saarthiclaw team connect ${link.server}`)}
301
+ `);
302
+ if (/127\.0\.0\.1|localhost/.test(link.server)) {
303
+ console.log(chalk.yellow("Note: 127.0.0.1 only works on this computer. Friends on other computers need your LAN or hosted address (start the dashboard with HOST=0.0.0.0).\n"));
304
+ }
305
+ }
306
+ async function teamInbox(session) {
307
+ const team = await getTeamContext(session, { refresh: true });
308
+ if (team.mode !== "admin" || !team.client) throw new UserFacingError("The agent inbox is for the Admin.", team.mode === "solo" ? "Connect first: `saarthiclaw team connect <dashboard-url>`." : void 0);
309
+ const client = team.client;
310
+ while (true) {
311
+ const items = await client.inbox();
312
+ console.log(chalk.bold(`
313
+ 📥 Agent inbox (${items.length})`) + chalk.dim(" — suggestions you forwarded on the dashboard\n"));
314
+ if (items.length === 0) {
315
+ console.log(chalk.dim("Empty. On the dashboard, open Suggestions and press “Forward to agent” on an idea.\n"));
316
+ return;
317
+ }
318
+ for (const it of items) {
319
+ console.log(`${chalk.bold(`#${it.id}`)} ${it.message}`);
320
+ console.log(chalk.dim(` from ${it.authorName}${it.adminNote ? ` · your note: ${it.adminNote}` : ""}`));
321
+ }
322
+ console.log("");
323
+ if (!session.prompter.interactive) return;
324
+ const pick = await session.prompter.select({
325
+ message: "Pick a suggestion",
326
+ options: [...items.map((it) => ({ value: String(it.id), label: `#${it.id} ${it.message.slice(0, 60)}`, hint: it.authorName })), { value: "back", label: "↩ Back" }]
327
+ });
328
+ if (pick === "back") return;
329
+ const item = items.find((i) => String(i.id) === pick);
330
+ const what = await session.prompter.select({
331
+ message: `#${item.id}: what now?`,
332
+ options: [
333
+ { value: "run", label: "Run the agent on it", hint: "you review every change, as usual" },
334
+ { value: "done", label: "Mark as done", hint: "already handled" },
335
+ { value: "back", label: "↩ Back" }
336
+ ],
337
+ initialValue: "run"
338
+ });
339
+ if (what === "back") continue;
340
+ if (what === "run") {
341
+ const { runAgentTask } = await import("./orchestrator-NIDJK4C3.js");
342
+ const task = `${item.message}${item.adminNote ? `
343
+
344
+ Admin note: ${item.adminNote}` : ""}
345
+
346
+ (Suggested by ${item.authorName}.)`;
347
+ await runAgentTask(session, task, { allowShell: session.config.allowShellExecution });
348
+ const done = await session.prompter.confirm({ message: `Mark #${item.id} as done?`, initialValue: true });
349
+ if (!done) continue;
350
+ }
351
+ await client.inboxDone(item.id);
352
+ console.log(chalk.green(`✓ #${item.id} marked as done.`));
353
+ }
354
+ }
355
+ async function teamDisconnect(session) {
356
+ const env = envOf(session);
357
+ const link = readTeamLink(session.root, env);
358
+ if (!link) {
359
+ console.log(chalk.dim("\nNot connected — already in solo mode.\n"));
360
+ return;
361
+ }
362
+ const sure = await session.prompter.confirm({ message: `Disconnect this project from ${link.server}? (your saved key for it is removed from this computer)`, initialValue: false });
363
+ if (!sure) return;
364
+ removeTeamLink(session.root);
365
+ removeKey(link.server, session.root, env);
366
+ await getTeamContext(session, { refresh: true });
367
+ console.log(chalk.green("\n✓ Disconnected. SaarthiClaw now works solo in this project.\n"));
368
+ }
369
+ export {
370
+ DEFAULT_SERVER,
371
+ teamConnect,
372
+ teamDisconnect,
373
+ teamInbox,
374
+ teamInvite,
375
+ teamStatus,
376
+ teamSuggest,
377
+ teamSync
378
+ };
@@ -1,24 +1,24 @@
1
1
  import {
2
2
  generatePlan,
3
3
  stepPrompt
4
- } from "./chunk-EWADWZYM.js";
5
- import {
6
- UserFacingError
7
- } from "./chunk-G6GCAEKE.js";
8
- import "./chunk-IT46XDPQ.js";
4
+ } from "./chunk-VDYO3QC7.js";
9
5
  import {
10
6
  createWebTools
11
- } from "./chunk-DORYMXNC.js";
7
+ } from "./chunk-OICPXSO2.js";
12
8
  import {
13
- ToolExecutor,
14
9
  createAgentTools,
15
10
  createReadOnlyTools,
16
11
  dedupeReadOnlyTools,
17
12
  finishOnLastStep
18
- } from "./chunk-4MPWZPGX.js";
13
+ } from "./chunk-DSQDVSZS.js";
14
+ import {
15
+ ToolExecutor
16
+ } from "./chunk-OS5GVLKA.js";
19
17
  import {
20
18
  groupPending
21
- } from "./chunk-HNAZBEDV.js";
19
+ } from "./chunk-QRAFFI5V.js";
20
+ import "./chunk-SKYTL7AH.js";
21
+ import "./chunk-E4DRW4AW.js";
22
22
  import {
23
23
  waitForInterrupt
24
24
  } from "./chunk-HGBZ55ND.js";
@@ -27,14 +27,19 @@ import {
27
27
  createTracker,
28
28
  instructionsFor,
29
29
  readOnlyAgentConfig
30
- } from "./chunk-GNAQO3JX.js";
30
+ } from "./chunk-GX2I7K4S.js";
31
+ import "./chunk-5WH3FNFK.js";
32
+ import "./chunk-EG5A2Q6X.js";
33
+ import {
34
+ UserFacingError
35
+ } from "./chunk-G6GCAEKE.js";
36
+ import "./chunk-IT46XDPQ.js";
31
37
  import "./chunk-XTVJWMUH.js";
32
38
  import {
33
39
  AI_MAX_RETRIES,
34
40
  MissingApiKeyError,
35
41
  mapAiError
36
42
  } from "./chunk-BTFIQWAE.js";
37
- import "./chunk-LLHZUSMZ.js";
38
43
  import "./chunk-2GDAWRT7.js";
39
44
  import "./chunk-MMIJKDOU.js";
40
45
 
@@ -409,6 +414,14 @@ ${list}`);
409
414
 
410
415
  // modes/telegram/index.ts
411
416
  async function runTelegramMode(session) {
417
+ const { getTeamContext } = await import("./context-AP3U34DQ.js");
418
+ const team = await getTeamContext(session);
419
+ if (team.mode === "needs_approval" || team.mode === "suggest_only") {
420
+ throw new UserFacingError(
421
+ "Telegram remote control is for the Admin and Trusted members.",
422
+ "Your changes go through the dashboard instead: use `saarthiclaw agent`, then `saarthiclaw team sync`."
423
+ );
424
+ }
412
425
  const token = session.config.telegramBotToken;
413
426
  const ownerId = session.config.telegramOwnerId;
414
427
  if (!token || !ownerId) {