setclaw 1.3.0 → 1.3.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 (3) hide show
  1. package/README.md +29 -1
  2. package/bin/setclaw.js +21 -52
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -65,6 +65,23 @@ npm i -g setclaw
65
65
  setclaw <your-quatarly-api-key>
66
66
  ```
67
67
 
68
+ ### What it does
69
+
70
+ - ✔ Backs up your current env vars and Factory config to `~/.setclaw/backup.json`
71
+ - ✔ Adds all 11 models to Factory AI Droid
72
+ - ✔ Sets env vars **system-wide** (all users) — falls back to current user if no admin rights
73
+ - ✔ Works on Windows, macOS, and Linux
74
+
75
+ ### Restore Original Settings
76
+
77
+ Made a mistake or want to undo everything?
78
+
79
+ ```bash
80
+ setclaw --restore
81
+ ```
82
+
83
+ This removes all env vars setclaw set and restores your original Factory config from the backup.
84
+
68
85
  ---
69
86
 
70
87
  ## Using Claude Code
@@ -157,7 +174,18 @@ Then create an account at [app.factory.ai](https://app.factory.ai), run `droid`
157
174
  <details>
158
175
  <summary><b>Can I run it again with a different API key?</b></summary>
159
176
 
160
- Yes. Just run `npx setclaw@latest <new-key>` again — it updates existing models and env vars without creating duplicates. A backup of your Factory settings is saved before any changes.
177
+ Yes. Just run `npx setclaw@latest <new-key>` or `setclaw <new-key>` again — it updates existing models and env vars without creating duplicates. A fresh backup is saved before every run.
178
+
179
+ </details>
180
+
181
+ <details>
182
+ <summary><b>How do I restore my original settings?</b></summary>
183
+
184
+ ```bash
185
+ setclaw --restore
186
+ ```
187
+
188
+ This reverts all env vars to their pre-setclaw values and restores your original Factory config from `~/.setclaw/backup.json`.
161
189
 
162
190
  </details>
163
191
 
package/bin/setclaw.js CHANGED
@@ -56,7 +56,10 @@ out("");
56
56
 
57
57
  const args = process.argv.slice(2);
58
58
  const restore = args.includes("--restore");
59
- const apiKey = !restore ? (process.env.QUATARLY_API_KEY || args.find(a => !a.startsWith("--"))) : null;
59
+
60
+ // Only treat an arg as API key if it doesn't start with - and looks like a key
61
+ const keyArg = args.find(a => !a.startsWith("-") && a.length > 8);
62
+ const apiKey = !restore ? (process.env.QUATARLY_API_KEY || keyArg) : null;
60
63
 
61
64
  // ─── First-run detection ──────────────────────────────────────────────
62
65
 
@@ -68,36 +71,16 @@ const isFirstRun = !isNpx && existsSync(MARKER_FILE);
68
71
  // ════════════════════════════════════════════════════════════════════
69
72
 
70
73
  if (restore) {
71
- if (!existsSync(BACKUP_FILE)) {
72
- fail("No backup found. Nothing to restore.");
73
- process.exit(1);
74
- }
75
-
76
- const backup = JSON.parse(readFileSync(BACKUP_FILE, "utf-8"));
77
- log("Restoring original environment variables...");
74
+ log("Removing setclaw environment variables...");
78
75
 
79
76
  if (OS === "win32") {
80
77
  for (const key of VAR_KEYS) {
81
- if (backup.env[key] !== undefined) {
82
- // Restore to both user and system
83
- try {
84
- execSync(`reg add "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" /v "${key}" /t REG_SZ /d "${backup.env[key]}" /f`, { stdio: "ignore" });
85
- } catch {}
86
- execSync(`reg add "HKCU\\Environment" /v "${key}" /t REG_SZ /d "${backup.env[key]}" /f`, { stdio: "ignore" });
87
- ok(`Restored ${key} = ${backup.env[key] || "(empty)"}`);
88
- } else {
89
- // Was not set before — delete it
90
- try {
91
- execSync(`reg delete "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" /v "${key}" /f`, { stdio: "ignore" });
92
- } catch {}
93
- try {
94
- execSync(`reg delete "HKCU\\Environment" /v "${key}" /f`, { stdio: "ignore" });
95
- } catch {}
96
- ok(`Removed ${key} (was not set before)`);
97
- }
78
+ // Delete from both HKLM and HKCU — don't "restore", just remove
79
+ try { execSync(`reg delete "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" /v "${key}" /f`, { stdio: "ignore" }); } catch {}
80
+ try { execSync(`reg delete "HKCU\\Environment" /v "${key}" /f`, { stdio: "ignore" }); } catch {}
81
+ ok(`Removed ${key}`);
98
82
  }
99
83
  } else {
100
- // Remove setclaw block from all rc files
101
84
  const marker = "# --- Quatarly / Claude Code env ---";
102
85
  const endMarker = "# --- end Quatarly ---";
103
86
  const rcFiles = ["/etc/environment", "/etc/zshenv", "/etc/bash.bashrc",
@@ -114,12 +97,17 @@ if (restore) {
114
97
  }
115
98
  }
116
99
 
117
- // Restore Factory settings
100
+ // Restore Factory settings from backup if it exists
118
101
  const factoryPath = join(HOME, ".factory", "settings.json");
119
- if (backup.factory && existsSync(factoryPath)) {
120
- log("Restoring Factory settings...");
121
- writeFileSync(factoryPath, JSON.stringify(backup.factory, null, 2), "utf-8");
122
- ok("Factory settings restored.");
102
+ if (existsSync(BACKUP_FILE)) {
103
+ const backup = JSON.parse(readFileSync(BACKUP_FILE, "utf-8"));
104
+ if (backup.factory && existsSync(factoryPath)) {
105
+ log("Restoring Factory settings...");
106
+ writeFileSync(factoryPath, JSON.stringify(backup.factory, null, 2), "utf-8");
107
+ ok("Factory settings restored.");
108
+ }
109
+ } else {
110
+ warn("No backup found — env vars removed, Factory settings unchanged.");
123
111
  }
124
112
 
125
113
  // Clean up backup
@@ -155,30 +143,11 @@ if (!key) { fail("API key cannot be empty."); process.exit(1); }
155
143
 
156
144
  err("");
157
145
 
158
- // ─── Backup current state ─────────────────────────────────────────────
146
+ // ─── Backup current state (Factory config only) ───────────────────────
159
147
 
160
148
  mkdirSync(BACKUP_DIR, { recursive: true });
161
149
 
162
- const backup = { env: {}, factory: null };
163
-
164
- if (OS === "win32") {
165
- for (const k of VAR_KEYS) {
166
- try {
167
- const val = execSync(`reg query "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" /v "${k}" 2>nul`, { encoding: "utf-8" });
168
- const match = val.match(/REG_SZ\s+(.+)/);
169
- backup.env[k] = match ? match[1].trim() : "";
170
- } catch {
171
- // Also try HKCU
172
- try {
173
- const val = execSync(`reg query "HKCU\\Environment" /v "${k}" 2>nul`, { encoding: "utf-8" });
174
- const match = val.match(/REG_SZ\s+(.+)/);
175
- backup.env[k] = match ? match[1].trim() : "";
176
- } catch {
177
- backup.env[k] = undefined; // Was not set
178
- }
179
- }
180
- }
181
- }
150
+ const backup = { factory: null };
182
151
 
183
152
  // Backup Factory settings
184
153
  const factoryPath = join(HOME, ".factory", "settings.json");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "setclaw",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "BOA & Quatarly setup for Claude Code and Factory",
5
5
  "type": "module",
6
6
  "bin": {