theclawbay 0.3.85 → 0.4.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 (86) hide show
  1. package/README.md +3 -2
  2. package/dist/commands/logout.js +82 -1466
  3. package/dist/commands/setup.js +151 -3593
  4. package/dist/lib/base-command.js +7 -5
  5. package/dist/lib/clients/aider-cleanup.d.ts +1 -0
  6. package/dist/lib/clients/aider-cleanup.js +15 -0
  7. package/dist/lib/clients/aider.d.ts +14 -0
  8. package/dist/lib/clients/aider.js +57 -0
  9. package/dist/lib/clients/claude-cleanup.d.ts +2 -0
  10. package/dist/lib/clients/claude-cleanup.js +88 -0
  11. package/dist/lib/clients/claude.d.ts +49 -0
  12. package/dist/lib/clients/claude.js +400 -0
  13. package/dist/lib/clients/cline-cleanup.d.ts +1 -0
  14. package/dist/lib/clients/cline-cleanup.js +80 -0
  15. package/dist/lib/clients/cline.d.ts +15 -0
  16. package/dist/lib/clients/cline.js +73 -0
  17. package/dist/lib/clients/codex-cleanup.d.ts +7 -0
  18. package/dist/lib/clients/codex-cleanup.js +145 -0
  19. package/dist/lib/clients/codex.d.ts +28 -0
  20. package/dist/lib/clients/codex.js +176 -0
  21. package/dist/lib/clients/continue-cleanup.d.ts +1 -0
  22. package/dist/lib/clients/continue-cleanup.js +40 -0
  23. package/dist/lib/clients/continue.d.ts +22 -0
  24. package/dist/lib/clients/continue.js +81 -0
  25. package/dist/lib/clients/gsd-cleanup.d.ts +4 -0
  26. package/dist/lib/clients/gsd-cleanup.js +168 -0
  27. package/dist/lib/clients/gsd.d.ts +30 -0
  28. package/dist/lib/clients/gsd.js +136 -0
  29. package/dist/lib/clients/hermes-cleanup.d.ts +2 -0
  30. package/dist/lib/clients/hermes-cleanup.js +112 -0
  31. package/dist/lib/clients/hermes.d.ts +18 -0
  32. package/dist/lib/clients/hermes.js +145 -0
  33. package/dist/lib/clients/openclaw-cleanup.d.ts +1 -0
  34. package/dist/lib/clients/openclaw-cleanup.js +52 -0
  35. package/dist/lib/clients/openclaw.d.ts +34 -0
  36. package/dist/lib/clients/openclaw.js +100 -0
  37. package/dist/lib/clients/opencode-family-cleanup.d.ts +12 -0
  38. package/dist/lib/clients/opencode-family-cleanup.js +201 -0
  39. package/dist/lib/clients/opencode-family.d.ts +86 -0
  40. package/dist/lib/clients/opencode-family.js +427 -0
  41. package/dist/lib/clients/roo-cleanup.d.ts +1 -0
  42. package/dist/lib/clients/roo-cleanup.js +48 -0
  43. package/dist/lib/clients/roo.d.ts +21 -0
  44. package/dist/lib/clients/roo.js +91 -0
  45. package/dist/lib/clients/trae-cleanup.d.ts +2 -0
  46. package/dist/lib/clients/trae-cleanup.js +40 -0
  47. package/dist/lib/clients/trae.d.ts +27 -0
  48. package/dist/lib/clients/trae.js +118 -0
  49. package/dist/lib/clients/zo.d.ts +39 -0
  50. package/dist/lib/clients/zo.js +210 -0
  51. package/dist/lib/shared/backend.d.ts +31 -0
  52. package/dist/lib/shared/backend.js +273 -0
  53. package/dist/lib/shared/client-registry.d.ts +23 -0
  54. package/dist/lib/shared/client-registry.js +68 -0
  55. package/dist/lib/shared/editor-env-cleanup.d.ts +2 -0
  56. package/dist/lib/shared/editor-env-cleanup.js +86 -0
  57. package/dist/lib/shared/editor-env.d.ts +27 -0
  58. package/dist/lib/shared/editor-env.js +224 -0
  59. package/dist/lib/shared/env-persist-cleanup.d.ts +4 -0
  60. package/dist/lib/shared/env-persist-cleanup.js +77 -0
  61. package/dist/lib/shared/env-persist.d.ts +26 -0
  62. package/dist/lib/shared/env-persist.js +179 -0
  63. package/dist/lib/shared/format.d.ts +5 -0
  64. package/dist/lib/shared/format.js +48 -0
  65. package/dist/lib/shared/fsx-cleanup.d.ts +3 -0
  66. package/dist/lib/shared/fsx-cleanup.js +36 -0
  67. package/dist/lib/shared/fsx.d.ts +9 -0
  68. package/dist/lib/shared/fsx.js +103 -0
  69. package/dist/lib/shared/models.d.ts +60 -0
  70. package/dist/lib/shared/models.js +124 -0
  71. package/dist/lib/shared/platform.d.ts +16 -0
  72. package/dist/lib/shared/platform.js +116 -0
  73. package/dist/lib/shared/prompts.d.ts +29 -0
  74. package/dist/lib/shared/prompts.js +504 -0
  75. package/dist/lib/shared/providers.d.ts +3 -0
  76. package/dist/lib/shared/providers.js +8 -0
  77. package/dist/lib/shared/toml.d.ts +7 -0
  78. package/dist/lib/shared/toml.js +157 -0
  79. package/dist/lib/shared/tui.d.ts +42 -0
  80. package/dist/lib/shared/tui.js +173 -0
  81. package/dist/lib/shared/urls.d.ts +18 -0
  82. package/dist/lib/shared/urls.js +149 -0
  83. package/dist/lib/supported-models.d.ts +1 -1
  84. package/dist/lib/supported-models.js +1 -1
  85. package/package.json +1 -6
  86. package/theclawbay-supported-models.json +202 -5
@@ -0,0 +1,400 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CLAUDE_DESKTOP_3P_STATE_PATH = exports.CLAUDE_EDITOR_SETTINGS_STATE_PATH = exports.MANAGED_CLAUDE_ENV_NAMES = exports.CLAUDE_CODE_EDITOR_DISABLE_LOGIN_PROMPT_SETTING = exports.CLAUDE_CODE_EDITOR_ENV_SETTING = exports.CLAUDE_ENV_ENABLE_TELEMETRY_NAME = exports.CLAUDE_ENV_DISABLE_NONESSENTIAL_TRAFFIC_NAME = exports.CLAUDE_ENV_SIMPLE_MODE_NAME = void 0;
7
+ exports.claudeDesktop3pConfigPath = claudeDesktop3pConfigPath;
8
+ exports.claudeDesktopLogCandidates = claudeDesktopLogCandidates;
9
+ exports.claudeDesktopAppCandidatePaths = claudeDesktopAppCandidatePaths;
10
+ exports.detectClaudeCodeClient = detectClaudeCodeClient;
11
+ exports.detectClaudeClient = detectClaudeClient;
12
+ exports.buildManagedClaudeEditorEnv = buildManagedClaudeEditorEnv;
13
+ exports.persistClaudeEditorSettings = persistClaudeEditorSettings;
14
+ exports.cleanupClaudeEditorSettings = cleanupClaudeEditorSettings;
15
+ exports.cleanupClaudeDesktop3pConfig = cleanupClaudeDesktop3pConfig;
16
+ exports.cleanupLegacyClaudeEditorTerminalEnvSettings = cleanupLegacyClaudeEditorTerminalEnvSettings;
17
+ exports.expandClaudeDesktopInferenceModels = expandClaudeDesktopInferenceModels;
18
+ exports.discoverClaudeDesktopDeploymentOrganizationUuid = discoverClaudeDesktopDeploymentOrganizationUuid;
19
+ exports.writeClaudeDesktop3pConfig = writeClaudeDesktop3pConfig;
20
+ const env_persist_1 = require("../shared/env-persist");
21
+ const node_path_1 = __importDefault(require("node:path"));
22
+ const paths_1 = require("../config/paths");
23
+ const node_os_1 = __importDefault(require("node:os"));
24
+ const fsx_1 = require("../shared/fsx");
25
+ const platform_1 = require("../shared/platform");
26
+ const node_fs_1 = require("node:fs");
27
+ const urls_1 = require("../shared/urls");
28
+ const editor_env_1 = require("../shared/editor-env");
29
+ const promises_1 = __importDefault(require("node:fs/promises"));
30
+ // Extracted from src/commands/setup.ts (theclawbay CLI restructure).
31
+ // Code motion only: bodies are verbatim from the original file.
32
+ exports.CLAUDE_ENV_SIMPLE_MODE_NAME = "CLAUDE_CODE_SIMPLE";
33
+ exports.CLAUDE_ENV_DISABLE_NONESSENTIAL_TRAFFIC_NAME = "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC";
34
+ exports.CLAUDE_ENV_ENABLE_TELEMETRY_NAME = "CLAUDE_CODE_ENABLE_TELEMETRY";
35
+ exports.CLAUDE_CODE_EDITOR_ENV_SETTING = "claudeCode.environmentVariables";
36
+ exports.CLAUDE_CODE_EDITOR_DISABLE_LOGIN_PROMPT_SETTING = "claudeCode.disableLoginPrompt";
37
+ exports.MANAGED_CLAUDE_ENV_NAMES = [
38
+ env_persist_1.CLAUDE_ENV_API_KEY_NAME,
39
+ env_persist_1.CLAUDE_ENV_BASE_URL_NAME,
40
+ exports.CLAUDE_ENV_SIMPLE_MODE_NAME,
41
+ exports.CLAUDE_ENV_DISABLE_NONESSENTIAL_TRAFFIC_NAME,
42
+ exports.CLAUDE_ENV_ENABLE_TELEMETRY_NAME,
43
+ ];
44
+ exports.CLAUDE_EDITOR_SETTINGS_STATE_PATH = node_path_1.default.join(paths_1.theclawbayStateDir, "claude-editor-settings.restore.json");
45
+ exports.CLAUDE_DESKTOP_3P_STATE_PATH = node_path_1.default.join(paths_1.theclawbayStateDir, "claude-desktop-3p.restore.json");
46
+ function claudeDesktop3pConfigPath() {
47
+ if (node_os_1.default.platform() !== "darwin")
48
+ return null;
49
+ return node_path_1.default.join(node_os_1.default.homedir(), "Library", "Application Support", "Claude-3p", "claude_desktop_config.json");
50
+ }
51
+ function claudeDesktopLogCandidates() {
52
+ if (node_os_1.default.platform() !== "darwin")
53
+ return [];
54
+ const home = node_os_1.default.homedir();
55
+ return [
56
+ node_path_1.default.join(home, "Library", "Logs", "Claude-3p", "main.log"),
57
+ node_path_1.default.join(home, "Library", "Logs", "Claude", "main.log"),
58
+ ];
59
+ }
60
+ function claudeDesktopAppCandidatePaths() {
61
+ if (node_os_1.default.platform() !== "darwin")
62
+ return [];
63
+ const home = node_os_1.default.homedir();
64
+ return (0, fsx_1.uniqueStrings)([
65
+ "/Applications/Claude.app",
66
+ node_path_1.default.join(home, "Applications", "Claude.app"),
67
+ ]);
68
+ }
69
+ async function detectClaudeCodeClient() {
70
+ if ((0, platform_1.hasCommand)("claude"))
71
+ return true;
72
+ const candidates = [
73
+ node_path_1.default.join(node_os_1.default.homedir(), ".claude"),
74
+ node_path_1.default.join(node_os_1.default.homedir(), ".claude.json"),
75
+ node_path_1.default.join(node_os_1.default.homedir(), ".config", "claude"),
76
+ ];
77
+ for (const candidate of candidates) {
78
+ if (await (0, fsx_1.pathExists)(candidate))
79
+ return true;
80
+ }
81
+ return false;
82
+ }
83
+ async function detectClaudeClient() {
84
+ if (await detectClaudeCodeClient())
85
+ return true;
86
+ if (claudeDesktopAppCandidatePaths().some((candidate) => (0, node_fs_1.existsSync)(candidate)))
87
+ return true;
88
+ const configPath = claudeDesktop3pConfigPath();
89
+ if (!configPath)
90
+ return false;
91
+ return (await (0, fsx_1.pathExists)(configPath)) || (await (0, fsx_1.pathExists)(node_path_1.default.dirname(configPath)));
92
+ }
93
+ function buildManagedClaudeEditorEnv(params) {
94
+ return {
95
+ [env_persist_1.CLAUDE_ENV_API_KEY_NAME]: params.apiKey,
96
+ [env_persist_1.CLAUDE_ENV_BASE_URL_NAME]: (0, urls_1.anthropicCompatibleProxyUrl)(params.backendUrl),
97
+ };
98
+ }
99
+ async function persistClaudeEditorSettings(params) {
100
+ const existingSnapshotRaw = await (0, fsx_1.readFileIfExists)(exports.CLAUDE_EDITOR_SETTINGS_STATE_PATH);
101
+ let existingSnapshot = [];
102
+ if (existingSnapshotRaw?.trim()) {
103
+ try {
104
+ existingSnapshot = JSON.parse(existingSnapshotRaw);
105
+ }
106
+ catch {
107
+ existingSnapshot = [];
108
+ }
109
+ }
110
+ const snapshotByPath = new Map(existingSnapshot.map((entry) => [entry.settingsPath, entry]));
111
+ const managedPaths = [];
112
+ const desiredEnv = params.claudeEnabled
113
+ ? buildManagedClaudeEditorEnv({ apiKey: params.apiKey, backendUrl: params.backendUrl })
114
+ : null;
115
+ for (const host of (0, editor_env_1.editorHosts)()) {
116
+ const settingsPath = host.userSettingsPath;
117
+ const hostPresent = (await (0, fsx_1.pathExists)(host.extensionDir)) ||
118
+ (await (0, fsx_1.pathExists)(settingsPath)) ||
119
+ (await (0, fsx_1.pathExists)(node_path_1.default.dirname(settingsPath)));
120
+ if (!hostPresent)
121
+ continue;
122
+ const existed = await (0, fsx_1.pathExists)(settingsPath);
123
+ const settings = await (0, fsx_1.readJsonObjectFile)(settingsPath);
124
+ const currentEnvValue = settings[exports.CLAUDE_CODE_EDITOR_ENV_SETTING];
125
+ const currentEnv = typeof currentEnvValue === "object" && currentEnvValue !== null && !Array.isArray(currentEnvValue)
126
+ ? { ...currentEnvValue }
127
+ : {};
128
+ let changed = false;
129
+ if (!snapshotByPath.has(settingsPath)) {
130
+ snapshotByPath.set(settingsPath, {
131
+ settingsPath,
132
+ existed,
133
+ envHadKey: Object.prototype.hasOwnProperty.call(settings, exports.CLAUDE_CODE_EDITOR_ENV_SETTING),
134
+ envPreviousValue: currentEnvValue ?? null,
135
+ disableLoginPromptHadKey: Object.prototype.hasOwnProperty.call(settings, exports.CLAUDE_CODE_EDITOR_DISABLE_LOGIN_PROMPT_SETTING),
136
+ disableLoginPromptPreviousValue: settings[exports.CLAUDE_CODE_EDITOR_DISABLE_LOGIN_PROMPT_SETTING] ?? null,
137
+ });
138
+ }
139
+ if (desiredEnv) {
140
+ const nextEnv = { ...currentEnv };
141
+ for (const [name, value] of Object.entries(desiredEnv)) {
142
+ if (nextEnv[name] === value)
143
+ continue;
144
+ nextEnv[name] = value;
145
+ changed = true;
146
+ }
147
+ for (const name of exports.MANAGED_CLAUDE_ENV_NAMES) {
148
+ if (name in desiredEnv || !(name in nextEnv))
149
+ continue;
150
+ delete nextEnv[name];
151
+ changed = true;
152
+ }
153
+ settings[exports.CLAUDE_CODE_EDITOR_ENV_SETTING] = nextEnv;
154
+ if (settings[exports.CLAUDE_CODE_EDITOR_DISABLE_LOGIN_PROMPT_SETTING] !== true) {
155
+ settings[exports.CLAUDE_CODE_EDITOR_DISABLE_LOGIN_PROMPT_SETTING] = true;
156
+ changed = true;
157
+ }
158
+ }
159
+ else {
160
+ if (Object.prototype.hasOwnProperty.call(settings, exports.CLAUDE_CODE_EDITOR_ENV_SETTING)) {
161
+ delete settings[exports.CLAUDE_CODE_EDITOR_ENV_SETTING];
162
+ changed = true;
163
+ }
164
+ if (Object.prototype.hasOwnProperty.call(settings, exports.CLAUDE_CODE_EDITOR_DISABLE_LOGIN_PROMPT_SETTING)) {
165
+ delete settings[exports.CLAUDE_CODE_EDITOR_DISABLE_LOGIN_PROMPT_SETTING];
166
+ changed = true;
167
+ }
168
+ }
169
+ if (!changed)
170
+ continue;
171
+ await (0, fsx_1.writeJsonObjectFile)(settingsPath, settings);
172
+ managedPaths.push(settingsPath);
173
+ }
174
+ await (0, fsx_1.writeJsonObjectFile)(exports.CLAUDE_EDITOR_SETTINGS_STATE_PATH, Array.from(snapshotByPath.values()), 0o600);
175
+ return managedPaths;
176
+ }
177
+ async function cleanupClaudeEditorSettings() {
178
+ const snapshotRaw = await (0, fsx_1.readFileIfExists)(exports.CLAUDE_EDITOR_SETTINGS_STATE_PATH);
179
+ if (snapshotRaw === null || !snapshotRaw.trim())
180
+ return [];
181
+ let entries = [];
182
+ try {
183
+ entries = JSON.parse(snapshotRaw);
184
+ }
185
+ catch {
186
+ return [];
187
+ }
188
+ const updated = [];
189
+ for (const entry of entries) {
190
+ const settings = await (0, fsx_1.readJsonObjectFile)(entry.settingsPath);
191
+ if (!entry.envHadKey) {
192
+ delete settings[exports.CLAUDE_CODE_EDITOR_ENV_SETTING];
193
+ }
194
+ else {
195
+ settings[exports.CLAUDE_CODE_EDITOR_ENV_SETTING] = entry.envPreviousValue;
196
+ }
197
+ if (!entry.disableLoginPromptHadKey) {
198
+ delete settings[exports.CLAUDE_CODE_EDITOR_DISABLE_LOGIN_PROMPT_SETTING];
199
+ }
200
+ else {
201
+ settings[exports.CLAUDE_CODE_EDITOR_DISABLE_LOGIN_PROMPT_SETTING] = entry.disableLoginPromptPreviousValue;
202
+ }
203
+ if (entry.existed || Object.keys(settings).length > 0) {
204
+ await (0, fsx_1.writeJsonObjectFile)(entry.settingsPath, settings);
205
+ updated.push(entry.settingsPath);
206
+ continue;
207
+ }
208
+ if (await (0, fsx_1.removeFileIfExists)(entry.settingsPath)) {
209
+ updated.push(entry.settingsPath);
210
+ }
211
+ }
212
+ await (0, fsx_1.removeFileIfExists)(exports.CLAUDE_EDITOR_SETTINGS_STATE_PATH);
213
+ return updated;
214
+ }
215
+ async function cleanupClaudeDesktop3pConfig() {
216
+ const snapshotRaw = await (0, fsx_1.readFileIfExists)(exports.CLAUDE_DESKTOP_3P_STATE_PATH);
217
+ if (snapshotRaw === null || !snapshotRaw.trim())
218
+ return false;
219
+ let snapshot = null;
220
+ try {
221
+ snapshot = JSON.parse(snapshotRaw);
222
+ }
223
+ catch {
224
+ snapshot = null;
225
+ }
226
+ if (!snapshot?.configPath) {
227
+ await (0, fsx_1.removeFileIfExists)(exports.CLAUDE_DESKTOP_3P_STATE_PATH);
228
+ return false;
229
+ }
230
+ if (!snapshot.existed) {
231
+ const removed = await (0, fsx_1.removeFileIfExists)(snapshot.configPath);
232
+ await (0, fsx_1.removeFileIfExists)(exports.CLAUDE_DESKTOP_3P_STATE_PATH);
233
+ return removed;
234
+ }
235
+ const previousRaw = snapshot.previousRaw ?? "";
236
+ const existingRaw = await (0, fsx_1.readFileIfExists)(snapshot.configPath);
237
+ if (existingRaw === previousRaw) {
238
+ await (0, fsx_1.removeFileIfExists)(exports.CLAUDE_DESKTOP_3P_STATE_PATH);
239
+ return false;
240
+ }
241
+ await promises_1.default.mkdir(node_path_1.default.dirname(snapshot.configPath), { recursive: true });
242
+ await promises_1.default.writeFile(snapshot.configPath, previousRaw, "utf8");
243
+ await (0, fsx_1.removeFileIfExists)(exports.CLAUDE_DESKTOP_3P_STATE_PATH);
244
+ return true;
245
+ }
246
+ async function cleanupLegacyClaudeEditorTerminalEnvSettings(params) {
247
+ const snapshotRaw = await (0, fsx_1.readFileIfExists)(editor_env_1.EDITOR_TERMINAL_ENV_STATE_PATH);
248
+ if (snapshotRaw === null || !snapshotRaw.trim())
249
+ return [];
250
+ let entries = [];
251
+ try {
252
+ entries = JSON.parse(snapshotRaw);
253
+ }
254
+ catch {
255
+ return [];
256
+ }
257
+ const settingsKey = (0, editor_env_1.terminalIntegratedEnvSettingsKey)();
258
+ const managedClaudeEnv = {
259
+ [env_persist_1.CLAUDE_ENV_API_KEY_NAME]: params.apiKey,
260
+ [env_persist_1.CLAUDE_ENV_BASE_URL_NAME]: (0, urls_1.anthropicCompatibleProxyUrl)(params.backendUrl),
261
+ };
262
+ const updated = [];
263
+ for (const entry of entries) {
264
+ const settings = await (0, fsx_1.readJsonObjectFile)(entry.settingsPath);
265
+ const currentValue = settings[settingsKey];
266
+ if (typeof currentValue !== "object" || currentValue === null || Array.isArray(currentValue))
267
+ continue;
268
+ const currentEnv = { ...currentValue };
269
+ const previousEnv = typeof entry.previousValue === "object" &&
270
+ entry.previousValue !== null &&
271
+ !Array.isArray(entry.previousValue)
272
+ ? { ...entry.previousValue }
273
+ : {};
274
+ let changed = false;
275
+ for (const name of exports.MANAGED_CLAUDE_ENV_NAMES) {
276
+ const expectedManagedValue = managedClaudeEnv[name];
277
+ const currentManagedValue = currentEnv[name];
278
+ const currentMatchesManaged = typeof expectedManagedValue === "string" ? currentManagedValue === expectedManagedValue : false;
279
+ if (!currentMatchesManaged)
280
+ continue;
281
+ if (Object.prototype.hasOwnProperty.call(previousEnv, name)) {
282
+ currentEnv[name] = previousEnv[name];
283
+ }
284
+ else {
285
+ delete currentEnv[name];
286
+ }
287
+ changed = true;
288
+ }
289
+ if (!changed)
290
+ continue;
291
+ settings[settingsKey] = currentEnv;
292
+ await (0, fsx_1.writeJsonObjectFile)(entry.settingsPath, settings);
293
+ updated.push(entry.settingsPath);
294
+ }
295
+ return updated;
296
+ }
297
+ function expandClaudeDesktopInferenceModels(modelIds) {
298
+ const expanded = [];
299
+ const add = (value) => {
300
+ const normalized = value.trim();
301
+ if (!normalized || expanded.includes(normalized))
302
+ return;
303
+ expanded.push(normalized);
304
+ };
305
+ for (const modelId of modelIds) {
306
+ add(modelId);
307
+ const datedMatch = modelId.match(/^(claude-[a-z]+-\d+(?:-\d+)?)-(\d{8})$/);
308
+ if (datedMatch?.[1])
309
+ add(datedMatch[1]);
310
+ const base = datedMatch?.[1] ?? modelId;
311
+ const dottedMatch = base.match(/^(claude-[a-z]+-\d+)-(\d+)$/);
312
+ if (dottedMatch?.[1] && dottedMatch?.[2]) {
313
+ add(`${dottedMatch[1]}.${dottedMatch[2]}`);
314
+ }
315
+ }
316
+ return expanded;
317
+ }
318
+ async function discoverClaudeDesktopDeploymentOrganizationUuid(existing) {
319
+ const enterpriseConfig = (0, fsx_1.objectRecordOr)(existing.enterpriseConfig, {});
320
+ const existingValue = enterpriseConfig.deploymentOrganizationUuid;
321
+ if (typeof existingValue === "string" && existingValue.trim()) {
322
+ return existingValue.trim();
323
+ }
324
+ const uuidPattern = /\b[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b/i;
325
+ const logPattern = /(deploymentOrganizationUuid|organizationUuid|organization uuid|org uuid)/i;
326
+ for (const logPath of claudeDesktopLogCandidates()) {
327
+ const logRaw = await (0, fsx_1.readFileIfExists)(logPath);
328
+ if (!logRaw)
329
+ continue;
330
+ const tail = logRaw.slice(-200000);
331
+ for (const line of tail.split(/\r?\n/).reverse()) {
332
+ if (!logPattern.test(line))
333
+ continue;
334
+ const match = line.match(uuidPattern);
335
+ if (match?.[0])
336
+ return match[0];
337
+ }
338
+ }
339
+ return null;
340
+ }
341
+ async function writeClaudeDesktop3pConfig(params) {
342
+ const configPath = claudeDesktop3pConfigPath();
343
+ if (!configPath || params.claudeModels.length === 0)
344
+ return null;
345
+ const desktopPresent = claudeDesktopAppCandidatePaths().some((candidate) => (0, node_fs_1.existsSync)(candidate)) ||
346
+ (await (0, fsx_1.pathExists)(configPath)) ||
347
+ (await (0, fsx_1.pathExists)(node_path_1.default.dirname(configPath))) ||
348
+ claudeDesktopLogCandidates().some((candidate) => (0, node_fs_1.existsSync)(candidate));
349
+ if (!desktopPresent)
350
+ return null;
351
+ let existed = true;
352
+ let existingRaw = "";
353
+ try {
354
+ existingRaw = await promises_1.default.readFile(configPath, "utf8");
355
+ }
356
+ catch (error) {
357
+ const err = error;
358
+ if (err.code !== "ENOENT")
359
+ throw error;
360
+ existed = false;
361
+ }
362
+ const existingSnapshotRaw = await (0, fsx_1.readFileIfExists)(exports.CLAUDE_DESKTOP_3P_STATE_PATH);
363
+ if (!existingSnapshotRaw?.trim()) {
364
+ const snapshot = {
365
+ version: 1,
366
+ configPath,
367
+ existed,
368
+ previousRaw: existed ? existingRaw : null,
369
+ };
370
+ await (0, fsx_1.writeJsonObjectFile)(exports.CLAUDE_DESKTOP_3P_STATE_PATH, snapshot, 0o600);
371
+ }
372
+ let doc = {};
373
+ if (existingRaw.trim()) {
374
+ try {
375
+ doc = (0, fsx_1.objectRecordOr)(JSON.parse(existingRaw), {});
376
+ }
377
+ catch {
378
+ throw new Error(`invalid JSON in Claude Desktop config: ${configPath}`);
379
+ }
380
+ }
381
+ const enterpriseConfig = (0, fsx_1.objectRecordOr)(doc.enterpriseConfig, {});
382
+ enterpriseConfig.inferenceProvider = "gateway";
383
+ enterpriseConfig.inferenceGatewayBaseUrl = (0, urls_1.anthropicCompatibleProxyUrl)(params.backendUrl);
384
+ enterpriseConfig.inferenceGatewayApiKey = params.apiKey;
385
+ enterpriseConfig.inferenceModels = expandClaudeDesktopInferenceModels(params.claudeModels);
386
+ enterpriseConfig.isDesktopExtensionEnabled = true;
387
+ enterpriseConfig.isDesktopExtensionDirectoryEnabled = true;
388
+ enterpriseConfig.isDesktopExtensionSignatureRequired = false;
389
+ enterpriseConfig.isLocalDevMcpEnabled = true;
390
+ enterpriseConfig.isClaudeCodeForDesktopEnabled = true;
391
+ const deploymentOrganizationUuid = await discoverClaudeDesktopDeploymentOrganizationUuid(doc);
392
+ if (deploymentOrganizationUuid) {
393
+ enterpriseConfig.deploymentOrganizationUuid = deploymentOrganizationUuid;
394
+ }
395
+ doc.enterpriseConfig = enterpriseConfig;
396
+ doc.isUsingBuiltInNodeForMcp = true;
397
+ doc.isDxtAutoUpdatesEnabled = true;
398
+ await (0, fsx_1.writeJsonObjectFile)(configPath, doc);
399
+ return configPath;
400
+ }
@@ -0,0 +1 @@
1
+ export declare function cleanupClineConfig(): Promise<boolean>;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanupClineConfig = cleanupClineConfig;
4
+ const fsx_cleanup_1 = require("../shared/fsx-cleanup");
5
+ const cline_1 = require("./cline");
6
+ const fsx_1 = require("../shared/fsx");
7
+ const providers_1 = require("../shared/providers");
8
+ const urls_1 = require("../shared/urls");
9
+ // Extracted from src/commands/logout.ts (theclawbay CLI restructure).
10
+ // Code motion only: bodies are verbatim from the original file.
11
+ async function cleanupClineConfig() {
12
+ const globalState = await (0, fsx_cleanup_1.readJsonObjectFile)(cline_1.CLINE_GLOBAL_STATE_PATH);
13
+ const secrets = await (0, fsx_cleanup_1.readJsonObjectFile)(cline_1.CLINE_SECRETS_PATH);
14
+ const snapshotRaw = await (0, fsx_1.readFileIfExists)(cline_1.CLINE_RESTORE_STATE_PATH);
15
+ let changed = false;
16
+ if (snapshotRaw?.trim()) {
17
+ try {
18
+ const snapshot = JSON.parse(snapshotRaw);
19
+ for (const [key, value] of Object.entries(snapshot.globalState ?? {})) {
20
+ if (value === null) {
21
+ if (key in globalState) {
22
+ delete globalState[key];
23
+ changed = true;
24
+ }
25
+ continue;
26
+ }
27
+ if (globalState[key] !== value) {
28
+ globalState[key] = value;
29
+ changed = true;
30
+ }
31
+ }
32
+ for (const [key, value] of Object.entries(snapshot.secrets ?? {})) {
33
+ if (value === null) {
34
+ if (key in secrets) {
35
+ delete secrets[key];
36
+ changed = true;
37
+ }
38
+ continue;
39
+ }
40
+ if (secrets[key] !== value) {
41
+ secrets[key] = value;
42
+ changed = true;
43
+ }
44
+ }
45
+ }
46
+ catch {
47
+ // Fall through to best-effort cleanup below.
48
+ }
49
+ }
50
+ else {
51
+ if (globalState.planModeApiProvider === providers_1.OPENAI_PROVIDER_ID) {
52
+ delete globalState.planModeApiProvider;
53
+ changed = true;
54
+ }
55
+ if (globalState.actModeApiProvider === providers_1.OPENAI_PROVIDER_ID) {
56
+ delete globalState.actModeApiProvider;
57
+ changed = true;
58
+ }
59
+ if ((0, urls_1.isTheClawBayOpenAiCompatibleBaseUrl)(globalState.openAiBaseUrl)) {
60
+ delete globalState.openAiBaseUrl;
61
+ changed = true;
62
+ }
63
+ for (const key of ["planModeOpenAiModelId", "actModeOpenAiModelId"]) {
64
+ if (typeof globalState[key] === "string") {
65
+ delete globalState[key];
66
+ changed = true;
67
+ }
68
+ }
69
+ if (typeof secrets.openAiApiKey === "string") {
70
+ delete secrets.openAiApiKey;
71
+ changed = true;
72
+ }
73
+ }
74
+ if (changed) {
75
+ await (0, fsx_cleanup_1.writeJsonFile)(cline_1.CLINE_GLOBAL_STATE_PATH, globalState);
76
+ await (0, fsx_cleanup_1.writeJsonFile)(cline_1.CLINE_SECRETS_PATH, secrets, 0o600);
77
+ }
78
+ await (0, fsx_1.removeFileIfExists)(cline_1.CLINE_RESTORE_STATE_PATH);
79
+ return changed;
80
+ }
@@ -0,0 +1,15 @@
1
+ export declare const DEFAULT_CLINE_MODEL: string;
2
+ export declare const CLINE_GLOBAL_STATE_PATH: string;
3
+ export declare const CLINE_SECRETS_PATH: string;
4
+ export declare const CLINE_RESTORE_STATE_PATH: string;
5
+ export type ClineRestoreSnapshot = {
6
+ globalState: Record<string, unknown>;
7
+ secrets: Record<string, string | null>;
8
+ };
9
+ export declare function detectClineClient(): Promise<boolean>;
10
+ export declare function isManagedClineState(doc: Record<string, unknown>): boolean;
11
+ export declare function writeClineConfig(params: {
12
+ backendUrl: string;
13
+ model: string;
14
+ apiKey: string;
15
+ }): Promise<string[]>;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CLINE_RESTORE_STATE_PATH = exports.CLINE_SECRETS_PATH = exports.CLINE_GLOBAL_STATE_PATH = exports.DEFAULT_CLINE_MODEL = void 0;
7
+ exports.detectClineClient = detectClineClient;
8
+ exports.isManagedClineState = isManagedClineState;
9
+ exports.writeClineConfig = writeClineConfig;
10
+ const models_1 = require("../shared/models");
11
+ const node_path_1 = __importDefault(require("node:path"));
12
+ const node_os_1 = __importDefault(require("node:os"));
13
+ const paths_1 = require("../config/paths");
14
+ const platform_1 = require("../shared/platform");
15
+ const fsx_1 = require("../shared/fsx");
16
+ const editor_env_1 = require("../shared/editor-env");
17
+ const urls_1 = require("../shared/urls");
18
+ // Extracted from src/commands/setup.ts (theclawbay CLI restructure).
19
+ // Code motion only: bodies are verbatim from the original file.
20
+ exports.DEFAULT_CLINE_MODEL = models_1.DEFAULT_CODEX_MODEL;
21
+ exports.CLINE_GLOBAL_STATE_PATH = node_path_1.default.join(node_os_1.default.homedir(), ".cline", "data", "globalState.json");
22
+ exports.CLINE_SECRETS_PATH = node_path_1.default.join(node_os_1.default.homedir(), ".cline", "data", "secrets.json");
23
+ exports.CLINE_RESTORE_STATE_PATH = node_path_1.default.join(paths_1.theclawbayStateDir, "cline.restore.json");
24
+ async function detectClineClient() {
25
+ if ((0, platform_1.hasCommand)("cline"))
26
+ return true;
27
+ const candidates = [
28
+ exports.CLINE_GLOBAL_STATE_PATH,
29
+ exports.CLINE_SECRETS_PATH,
30
+ node_path_1.default.join(node_os_1.default.homedir(), ".cline", "state", "taskHistory.json"),
31
+ node_path_1.default.join(node_os_1.default.homedir(), ".cline", "tasks"),
32
+ ];
33
+ for (const candidate of candidates) {
34
+ if (await (0, fsx_1.pathExists)(candidate))
35
+ return true;
36
+ }
37
+ return (await (0, editor_env_1.detectExtensionHosts)(["saoudrizwan.claude-dev-"])).length > 0;
38
+ }
39
+ function isManagedClineState(doc) {
40
+ return (doc.planModeApiProvider === "openai" &&
41
+ doc.actModeApiProvider === "openai" &&
42
+ (0, urls_1.isTheClawBayOpenAiCompatibleBaseUrl)(doc.openAiBaseUrl));
43
+ }
44
+ async function writeClineConfig(params) {
45
+ const proxyUrl = (0, urls_1.openAiCompatibleProxyUrl)(params.backendUrl);
46
+ const globalState = await (0, fsx_1.readJsonObjectFile)(exports.CLINE_GLOBAL_STATE_PATH);
47
+ const secrets = await (0, fsx_1.readJsonObjectFile)(exports.CLINE_SECRETS_PATH);
48
+ const alreadyManaged = isManagedClineState(globalState) && typeof secrets.openAiApiKey === "string";
49
+ if (!alreadyManaged) {
50
+ const snapshot = {
51
+ globalState: {
52
+ planModeApiProvider: "planModeApiProvider" in globalState ? globalState.planModeApiProvider : null,
53
+ actModeApiProvider: "actModeApiProvider" in globalState ? globalState.actModeApiProvider : null,
54
+ openAiBaseUrl: "openAiBaseUrl" in globalState ? globalState.openAiBaseUrl : null,
55
+ planModeOpenAiModelId: "planModeOpenAiModelId" in globalState ? globalState.planModeOpenAiModelId : null,
56
+ actModeOpenAiModelId: "actModeOpenAiModelId" in globalState ? globalState.actModeOpenAiModelId : null,
57
+ },
58
+ secrets: {
59
+ openAiApiKey: typeof secrets.openAiApiKey === "string" ? secrets.openAiApiKey : null,
60
+ },
61
+ };
62
+ await (0, fsx_1.writeJsonObjectFile)(exports.CLINE_RESTORE_STATE_PATH, snapshot, 0o600);
63
+ }
64
+ globalState.planModeApiProvider = "openai";
65
+ globalState.actModeApiProvider = "openai";
66
+ globalState.openAiBaseUrl = proxyUrl;
67
+ globalState.planModeOpenAiModelId = params.model.trim() || exports.DEFAULT_CLINE_MODEL;
68
+ globalState.actModeOpenAiModelId = params.model.trim() || exports.DEFAULT_CLINE_MODEL;
69
+ secrets.openAiApiKey = params.apiKey;
70
+ await (0, fsx_1.writeJsonObjectFile)(exports.CLINE_GLOBAL_STATE_PATH, globalState);
71
+ await (0, fsx_1.writeJsonObjectFile)(exports.CLINE_SECRETS_PATH, secrets, 0o600);
72
+ return [exports.CLINE_GLOBAL_STATE_PATH, exports.CLINE_SECRETS_PATH];
73
+ }
@@ -0,0 +1,7 @@
1
+ export declare const WAN_PROVIDER_ID = "theclawbay-wan";
2
+ export declare const HISTORY_PROVIDER_DB_MIGRATE_SOURCES: string[];
3
+ export declare function removeTopLevelProviderSelection(source: string): string;
4
+ export declare function setTopLevelTableKey(source: string, tableName: string, key: string, tomlValue: string): string;
5
+ export declare function isTheClawBayCodexNativeBaseUrl(value: unknown): value is string;
6
+ export declare function cleanupCodexConfig(): Promise<boolean>;
7
+ export declare function cleanupCodexFeatureFlags(): Promise<boolean>;