@bobsworkshop/cli 0.1.0 → 0.1.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.
- package/dist/bin/{analyse-auto-WQUK5YPO.js → analyse-auto-KKWLMLHZ.js} +4 -5
- package/dist/bin/{analyse-results-FIDS4635.js → analyse-results-N5QLJNND.js} +2 -2
- package/dist/bin/bob.js +1 -0
- package/dist/bin/chunk-WEHSNZKO.js +880 -0
- package/package.json +11 -5
- package/bin/bob.ts +0 -74
- package/dist/bin/analyse-auto-AAWSETKY.js +0 -540
- package/dist/bin/analyse-auto-FQ62GYPV.js +0 -533
- package/dist/bin/analyse-auto-JAD24IQ5.js +0 -511
- package/dist/bin/analyse-auto-R4MZA7SX.js +0 -511
- package/dist/bin/analyse-auto-V3SH4MS7.js +0 -524
- package/dist/bin/analyse-auto-WVAY6467.js +0 -280
- package/dist/bin/analyse-results-3NSD6MAY.js +0 -363
- package/dist/bin/analyse-results-B7LONUXU.js +0 -265
- package/dist/bin/analyse-results-E6NBAVDB.js +0 -265
- package/dist/bin/analyse-results-LMGVKAUX.js +0 -342
- package/dist/bin/analyse-results-LSMLUEIB.js +0 -338
- package/dist/bin/analyse-results-MOCLBCD7.js +0 -326
- package/dist/bin/analyse-results-NLAEAOOP.js +0 -10
- package/dist/bin/analyse-results-PYQIKWYL.js +0 -9
- package/dist/bin/analyse-results-R3MG5H7G.js +0 -329
- package/dist/bin/analyse-results-UYZZSBHB.js +0 -9
- package/dist/bin/analyse-results-YYGHIK2Q.js +0 -9
- package/dist/bin/analysis-tracker-N5VANTLH.js +0 -12
- package/dist/bin/chunk-3RSDDQE2.js +0 -420
- package/dist/bin/chunk-6KWC4HDO.js +0 -97
- package/dist/bin/chunk-6W7WDF4Q.js +0 -589
- package/dist/bin/chunk-7CXM3RLM.js +0 -287
- package/dist/bin/chunk-FGYL6SWO.js +0 -465
- package/dist/bin/chunk-J4BSKFCW.js +0 -624
- package/dist/bin/chunk-KWOQFI6L.js +0 -287
- package/dist/bin/chunk-OOGLZ2QB.js +0 -322
- package/dist/bin/chunk-TEVQLSGD.js +0 -287
- package/dist/bin/chunk-VUS7R7SO.js +0 -479
|
@@ -1,465 +0,0 @@
|
|
|
1
|
-
// src/core/config-store.ts
|
|
2
|
-
import Conf from "conf";
|
|
3
|
-
|
|
4
|
-
// src/types/config.ts
|
|
5
|
-
var DEFAULT_CONFIG = {
|
|
6
|
-
tier: "local",
|
|
7
|
-
loggedIn: false,
|
|
8
|
-
email: null,
|
|
9
|
-
uid: null,
|
|
10
|
-
authToken: null,
|
|
11
|
-
refreshToken: null,
|
|
12
|
-
provider: null,
|
|
13
|
-
providerKey: null,
|
|
14
|
-
localEndpoint: null,
|
|
15
|
-
personalizationMode: false,
|
|
16
|
-
consultantMode: false,
|
|
17
|
-
autoMode: false,
|
|
18
|
-
idrp: false,
|
|
19
|
-
idrpFilter: "free",
|
|
20
|
-
activeProject: null,
|
|
21
|
-
conversationId: null,
|
|
22
|
-
activePersona: null,
|
|
23
|
-
hasSeenWelcome: false
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// src/core/config-store.ts
|
|
27
|
-
var store = new Conf({
|
|
28
|
-
projectName: "bob-cli",
|
|
29
|
-
defaults: DEFAULT_CONFIG
|
|
30
|
-
});
|
|
31
|
-
function getConfig() {
|
|
32
|
-
return {
|
|
33
|
-
tier: store.get("tier"),
|
|
34
|
-
loggedIn: store.get("loggedIn"),
|
|
35
|
-
email: store.get("email"),
|
|
36
|
-
uid: store.get("uid"),
|
|
37
|
-
authToken: store.get("authToken"),
|
|
38
|
-
refreshToken: store.get("refreshToken"),
|
|
39
|
-
provider: store.get("provider"),
|
|
40
|
-
providerKey: store.get("providerKey"),
|
|
41
|
-
localEndpoint: store.get("localEndpoint"),
|
|
42
|
-
personalizationMode: store.get("personalizationMode"),
|
|
43
|
-
consultantMode: store.get("consultantMode"),
|
|
44
|
-
idrp: store.get("idrp"),
|
|
45
|
-
idrpFilter: store.get("idrpFilter"),
|
|
46
|
-
activeProject: store.get("activeProject"),
|
|
47
|
-
conversationId: store.get("conversationId"),
|
|
48
|
-
activePersona: store.get("activePersona"),
|
|
49
|
-
hasSeenWelcome: store.get("hasSeenWelcome"),
|
|
50
|
-
autoMode: store.get("autoMode")
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function setConfigValue(key, value) {
|
|
54
|
-
store.set(key, value);
|
|
55
|
-
}
|
|
56
|
-
function getConfigPath() {
|
|
57
|
-
return store.path;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// src/commands/login.ts
|
|
61
|
-
import chalk from "chalk";
|
|
62
|
-
import http from "http";
|
|
63
|
-
import open from "open";
|
|
64
|
-
import axios from "axios";
|
|
65
|
-
import { URL } from "url";
|
|
66
|
-
import * as readline from "readline";
|
|
67
|
-
var CLI_AUTH_URL = "https://bobs-workshop.web.app/cli-auth";
|
|
68
|
-
var CALLBACK_PORT = 9876;
|
|
69
|
-
var FIREBASE_API_KEY = "AIzaSyB-hUZEonRIzbExVDwuneJaDjJZBvHdIps";
|
|
70
|
-
function registerLoginCommand(program) {
|
|
71
|
-
program.command("login").description("Authenticate with Bob's Workshop via browser").action(async () => {
|
|
72
|
-
console.log("");
|
|
73
|
-
console.log(chalk.bold.cyan(" \u{1F510} Bob CLI \u2014 Login"));
|
|
74
|
-
console.log(chalk.gray(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
75
|
-
console.log("");
|
|
76
|
-
console.log(chalk.yellow(" \u26A0\uFE0F Important:"));
|
|
77
|
-
console.log(chalk.gray(" \u2022 Local conversations (Tier 1) will NOT sync to the platform."));
|
|
78
|
-
console.log(chalk.gray(" \u2022 Only NEW conversations created after login will save to Firebase."));
|
|
79
|
-
console.log(chalk.gray(" \u2022 Your local history stays in ~/.bob/projects/ (backup via `bob backup`)."));
|
|
80
|
-
console.log(chalk.gray(" \u2022 Logging in upgrades you to Tier 3 (Platform) with full features."));
|
|
81
|
-
console.log("");
|
|
82
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
83
|
-
const answer = await new Promise((resolve2) => {
|
|
84
|
-
rl.question(chalk.cyan(" Continue with login? (y/n): "), resolve2);
|
|
85
|
-
});
|
|
86
|
-
rl.close();
|
|
87
|
-
if (answer.toLowerCase() !== "y" && answer.toLowerCase() !== "yes") {
|
|
88
|
-
console.log("");
|
|
89
|
-
console.log(chalk.gray(" Login cancelled."));
|
|
90
|
-
console.log("");
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
console.log("");
|
|
94
|
-
console.log(chalk.gray(" Opening browser for authentication..."));
|
|
95
|
-
console.log("");
|
|
96
|
-
try {
|
|
97
|
-
const result = await startAuthFlow();
|
|
98
|
-
if (result) {
|
|
99
|
-
const exchangeResult = await exchangeCustomToken(result.token);
|
|
100
|
-
setConfigValue("authToken", exchangeResult.idToken);
|
|
101
|
-
setConfigValue("refreshToken", exchangeResult.refreshToken);
|
|
102
|
-
setConfigValue("email", result.email);
|
|
103
|
-
setConfigValue("uid", result.uid);
|
|
104
|
-
setConfigValue("loggedIn", true);
|
|
105
|
-
setConfigValue("tier", "platform");
|
|
106
|
-
console.log("");
|
|
107
|
-
console.log(chalk.green(` \u2705 Logged in as ${result.email}`));
|
|
108
|
-
console.log(chalk.gray(" Tier: Platform (Tier 3)"));
|
|
109
|
-
console.log(chalk.gray(" All platform features are now available."));
|
|
110
|
-
console.log("");
|
|
111
|
-
}
|
|
112
|
-
} catch (error) {
|
|
113
|
-
console.log(chalk.red(` \u274C Login failed: ${error.message}`));
|
|
114
|
-
console.log("");
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
program.command("logout").description("Sign out and clear stored credentials").action(() => {
|
|
118
|
-
setConfigValue("authToken", null);
|
|
119
|
-
setConfigValue("refreshToken", null);
|
|
120
|
-
setConfigValue("email", null);
|
|
121
|
-
setConfigValue("uid", null);
|
|
122
|
-
setConfigValue("loggedIn", false);
|
|
123
|
-
setConfigValue("tier", "local");
|
|
124
|
-
console.log("");
|
|
125
|
-
console.log(chalk.gray(" \u{1F44B} Logged out. Switched to Tier 1 (local-first)."));
|
|
126
|
-
console.log("");
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
async function exchangeCustomToken(customToken) {
|
|
130
|
-
const url = `https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=${FIREBASE_API_KEY}`;
|
|
131
|
-
const response = await axios.post(url, {
|
|
132
|
-
token: customToken,
|
|
133
|
-
returnSecureToken: true
|
|
134
|
-
});
|
|
135
|
-
if (!response.data?.idToken || !response.data?.refreshToken) {
|
|
136
|
-
throw new Error("Token exchange failed \u2014 no ID token returned.");
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
idToken: response.data.idToken,
|
|
140
|
-
refreshToken: response.data.refreshToken
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
async function refreshAuthToken(refreshToken) {
|
|
144
|
-
const url = `https://securetoken.googleapis.com/v1/token?key=${FIREBASE_API_KEY}`;
|
|
145
|
-
const response = await axios.post(url, {
|
|
146
|
-
grant_type: "refresh_token",
|
|
147
|
-
refresh_token: refreshToken
|
|
148
|
-
});
|
|
149
|
-
if (!response.data?.id_token) {
|
|
150
|
-
throw new Error("Token refresh failed.");
|
|
151
|
-
}
|
|
152
|
-
setConfigValue("authToken", response.data.id_token);
|
|
153
|
-
return response.data.id_token;
|
|
154
|
-
}
|
|
155
|
-
function startAuthFlow() {
|
|
156
|
-
return new Promise((resolve2, reject) => {
|
|
157
|
-
const timeout = setTimeout(() => {
|
|
158
|
-
server.close();
|
|
159
|
-
reject(new Error("Login timed out after 120 seconds. Please try again."));
|
|
160
|
-
}, 12e4);
|
|
161
|
-
const server = http.createServer((req, res) => {
|
|
162
|
-
if (!req.url?.startsWith("/callback")) {
|
|
163
|
-
res.writeHead(404);
|
|
164
|
-
res.end("Not found");
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
try {
|
|
168
|
-
const url = new URL(req.url, `http://localhost:${CALLBACK_PORT}`);
|
|
169
|
-
const token = url.searchParams.get("token");
|
|
170
|
-
const email = url.searchParams.get("email");
|
|
171
|
-
const uid = url.searchParams.get("uid");
|
|
172
|
-
if (!token || !email || !uid) {
|
|
173
|
-
res.writeHead(400);
|
|
174
|
-
res.end("Missing parameters");
|
|
175
|
-
reject(new Error("Invalid callback \u2014 missing token, email, or uid."));
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
res.writeHead(200, { "Content-Type": "text/html" });
|
|
179
|
-
res.end(`
|
|
180
|
-
<html>
|
|
181
|
-
<body style="background: #0a0a0a; color: white; font-family: system-ui; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0;">
|
|
182
|
-
<div style="text-align: center;">
|
|
183
|
-
<h1>\u2705 Authenticated!</h1>
|
|
184
|
-
<p style="color: #888;">You can close this tab and return to your terminal.</p>
|
|
185
|
-
</div>
|
|
186
|
-
</body>
|
|
187
|
-
</html>
|
|
188
|
-
`);
|
|
189
|
-
clearTimeout(timeout);
|
|
190
|
-
server.close();
|
|
191
|
-
resolve2({ token, email, uid });
|
|
192
|
-
} catch (e) {
|
|
193
|
-
res.writeHead(500);
|
|
194
|
-
res.end("Error");
|
|
195
|
-
reject(e);
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
server.listen(CALLBACK_PORT, () => {
|
|
199
|
-
console.log(chalk.gray(` \u{1F310} Waiting for authentication (port ${CALLBACK_PORT})...`));
|
|
200
|
-
console.log(chalk.gray(" If your browser doesn't open, visit:"));
|
|
201
|
-
console.log(chalk.cyan(` ${CLI_AUTH_URL}`));
|
|
202
|
-
console.log("");
|
|
203
|
-
open(CLI_AUTH_URL).catch(() => {
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
server.on("error", (err) => {
|
|
207
|
-
clearTimeout(timeout);
|
|
208
|
-
if (err.code === "EADDRINUSE") {
|
|
209
|
-
reject(new Error("Port 9876 is already in use. Close other instances and try again."));
|
|
210
|
-
} else {
|
|
211
|
-
reject(err);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// src/core/api-client.ts
|
|
218
|
-
import axios2 from "axios";
|
|
219
|
-
var FUNCTIONS_BASE = "https://us-central1-seedlingapp.cloudfunctions.net";
|
|
220
|
-
async function callCloudFunction(functionName, data) {
|
|
221
|
-
const config = getConfig();
|
|
222
|
-
if (!config.authToken) {
|
|
223
|
-
throw new Error("Not authenticated. Run `bob login` first.");
|
|
224
|
-
}
|
|
225
|
-
try {
|
|
226
|
-
const response = await axios2.post(
|
|
227
|
-
`${FUNCTIONS_BASE}/${functionName}`,
|
|
228
|
-
{ data },
|
|
229
|
-
{
|
|
230
|
-
headers: {
|
|
231
|
-
"Content-Type": "application/json",
|
|
232
|
-
"Authorization": `Bearer ${config.authToken}`
|
|
233
|
-
},
|
|
234
|
-
timeout: 18e4
|
|
235
|
-
}
|
|
236
|
-
);
|
|
237
|
-
return response.data?.result || response.data;
|
|
238
|
-
} catch (error) {
|
|
239
|
-
const status = error.response?.status;
|
|
240
|
-
if (status === 401 && config.refreshToken) {
|
|
241
|
-
try {
|
|
242
|
-
const newToken = await refreshAuthToken(config.refreshToken);
|
|
243
|
-
const retryResponse = await axios2.post(
|
|
244
|
-
`${FUNCTIONS_BASE}/${functionName}`,
|
|
245
|
-
{ data },
|
|
246
|
-
{
|
|
247
|
-
headers: {
|
|
248
|
-
"Content-Type": "application/json",
|
|
249
|
-
"Authorization": `Bearer ${newToken}`
|
|
250
|
-
},
|
|
251
|
-
timeout: 18e4
|
|
252
|
-
}
|
|
253
|
-
);
|
|
254
|
-
return retryResponse.data?.result || retryResponse.data;
|
|
255
|
-
} catch (refreshError) {
|
|
256
|
-
setConfigValue("loggedIn", false);
|
|
257
|
-
throw new Error("Session expired. Run `bob login` again.");
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
if (status === 404) {
|
|
261
|
-
throw new Error(`Function "${functionName}" not found. Is it deployed?`);
|
|
262
|
-
}
|
|
263
|
-
if (status === 403) {
|
|
264
|
-
throw new Error("Permission denied. You may not have access to this feature.");
|
|
265
|
-
}
|
|
266
|
-
if (status === 500) {
|
|
267
|
-
const serverMsg = error.response?.data?.error?.message || error.response?.data?.error || "Internal server error";
|
|
268
|
-
throw new Error(`Server error: ${serverMsg}`);
|
|
269
|
-
}
|
|
270
|
-
if (status === 429) {
|
|
271
|
-
throw new Error("Rate limited. Please wait a moment and try again.");
|
|
272
|
-
}
|
|
273
|
-
const errorMsg = error.response?.data?.error?.message || error.message || `Request failed with status ${status}`;
|
|
274
|
-
throw new Error(errorMsg);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// src/ai/providers/local.ts
|
|
279
|
-
import axios3 from "axios";
|
|
280
|
-
async function callLocalModel(endpoint, messages) {
|
|
281
|
-
try {
|
|
282
|
-
const response = await axios3.post(
|
|
283
|
-
endpoint,
|
|
284
|
-
{
|
|
285
|
-
model: "bob-local-dna:latest",
|
|
286
|
-
messages,
|
|
287
|
-
stream: false
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
headers: { "Content-Type": "application/json" },
|
|
291
|
-
timeout: 18e4
|
|
292
|
-
}
|
|
293
|
-
);
|
|
294
|
-
if (response.data?.message?.content) {
|
|
295
|
-
return response.data.message.content;
|
|
296
|
-
}
|
|
297
|
-
const choice = response.data?.choices?.[0];
|
|
298
|
-
if (choice?.message?.content) {
|
|
299
|
-
return choice.message.content;
|
|
300
|
-
}
|
|
301
|
-
if (typeof response.data?.response === "string") {
|
|
302
|
-
return response.data.response;
|
|
303
|
-
}
|
|
304
|
-
return "No response received from local model.";
|
|
305
|
-
} catch (error) {
|
|
306
|
-
if (error.code === "ECONNREFUSED") {
|
|
307
|
-
throw new Error("Cannot connect to local model. Is Ollama running? Check your endpoint: " + endpoint);
|
|
308
|
-
}
|
|
309
|
-
throw new Error("Local model error: " + (error.response?.status ? `Status ${error.response.status}` : error.message));
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// src/core/context-builder.ts
|
|
314
|
-
import * as fs from "fs";
|
|
315
|
-
import * as path from "path";
|
|
316
|
-
var IGNORE_DIRS = ["node_modules", ".git", "dist", "build", ".dart_tool", ".idea", ".gradle", ".pub-cache", ".bob"];
|
|
317
|
-
var MAX_DEPTH = 3;
|
|
318
|
-
function buildLocalContext(rootDir) {
|
|
319
|
-
const tree = getDirectoryTree(rootDir, 0);
|
|
320
|
-
return `Working Directory: ${rootDir}
|
|
321
|
-
|
|
322
|
-
File Tree:
|
|
323
|
-
${tree}`;
|
|
324
|
-
}
|
|
325
|
-
function getDirectoryTree(dir, depth) {
|
|
326
|
-
if (depth >= MAX_DEPTH) return "";
|
|
327
|
-
let result = "";
|
|
328
|
-
try {
|
|
329
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
330
|
-
for (const entry of entries) {
|
|
331
|
-
if (IGNORE_DIRS.includes(entry.name)) continue;
|
|
332
|
-
if (entry.name.startsWith(".") && depth === 0) continue;
|
|
333
|
-
const indent = " ".repeat(depth);
|
|
334
|
-
if (entry.isDirectory()) {
|
|
335
|
-
result += `${indent}${entry.name}/
|
|
336
|
-
`;
|
|
337
|
-
result += getDirectoryTree(path.join(dir, entry.name), depth + 1);
|
|
338
|
-
} else {
|
|
339
|
-
result += `${indent}${entry.name}
|
|
340
|
-
`;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
} catch (e) {
|
|
344
|
-
}
|
|
345
|
-
return result;
|
|
346
|
-
}
|
|
347
|
-
function readFileContent(filePath) {
|
|
348
|
-
try {
|
|
349
|
-
return fs.readFileSync(path.resolve(filePath), "utf-8");
|
|
350
|
-
} catch (e) {
|
|
351
|
-
return null;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// src/core/file-writer.ts
|
|
356
|
-
import * as fs2 from "fs";
|
|
357
|
-
import * as path2 from "path";
|
|
358
|
-
import * as readline2 from "readline";
|
|
359
|
-
import chalk2 from "chalk";
|
|
360
|
-
function extractProposedFile(response) {
|
|
361
|
-
const codeBlockRegex = /```[\w]*\n([\s\S]*?)```/;
|
|
362
|
-
const match = response.match(codeBlockRegex);
|
|
363
|
-
if (!match) return null;
|
|
364
|
-
const codeContent = match[1].trim();
|
|
365
|
-
const lines = codeContent.split("\n");
|
|
366
|
-
if (lines.length === 0) return null;
|
|
367
|
-
const firstLine = lines[0].trim();
|
|
368
|
-
let filePathMatch = firstLine.match(/^\/\/\s*File:\s*(.+)$/);
|
|
369
|
-
if (!filePathMatch) {
|
|
370
|
-
filePathMatch = firstLine.match(/^\/\/\s*([\w\-\.\/\\]+\.\w+)\s*$/);
|
|
371
|
-
}
|
|
372
|
-
if (!filePathMatch) {
|
|
373
|
-
filePathMatch = firstLine.match(/^#\s*File:\s*(.+)$/);
|
|
374
|
-
}
|
|
375
|
-
if (!filePathMatch) {
|
|
376
|
-
filePathMatch = firstLine.match(/^#\s*([\w\-\.\/\\]+\.\w+)\s*$/);
|
|
377
|
-
}
|
|
378
|
-
if (!filePathMatch) return null;
|
|
379
|
-
const filePath = filePathMatch[1].trim();
|
|
380
|
-
if (!filePath.includes("/") && !filePath.includes("\\")) return null;
|
|
381
|
-
if (!filePath.includes(".")) return null;
|
|
382
|
-
const fileContent = lines.slice(1).join("\n").trim();
|
|
383
|
-
const absolutePath = path2.join(process.cwd(), filePath);
|
|
384
|
-
const isNew = !fs2.existsSync(absolutePath);
|
|
385
|
-
return {
|
|
386
|
-
filePath,
|
|
387
|
-
content: fileContent,
|
|
388
|
-
isNew
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
function stripCodeBlockFromResponse(response) {
|
|
392
|
-
return response.replace(/```[\w]*\n[\s\S]*?```/g, "").trim();
|
|
393
|
-
}
|
|
394
|
-
async function proposeAndWriteFile(proposed) {
|
|
395
|
-
const absolutePath = path2.join(process.cwd(), proposed.filePath);
|
|
396
|
-
const action = proposed.isNew ? "CREATE" : "UPDATE";
|
|
397
|
-
const icon = proposed.isNew ? "\u{1F4C4}" : "\u270F\uFE0F";
|
|
398
|
-
const color = proposed.isNew ? chalk2.green : chalk2.yellow;
|
|
399
|
-
const totalLines = proposed.content.split("\n").length;
|
|
400
|
-
console.log("");
|
|
401
|
-
console.log(color(` \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510`));
|
|
402
|
-
console.log(color(` \u2502 ${icon} ${action}: ${proposed.filePath} (${totalLines} lines)`));
|
|
403
|
-
console.log(color(` \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524`));
|
|
404
|
-
const previewLines = proposed.content.split("\n").slice(0, 6);
|
|
405
|
-
for (const line of previewLines) {
|
|
406
|
-
console.log(chalk2.gray(` \u2502 ${line}`));
|
|
407
|
-
}
|
|
408
|
-
if (totalLines > 6) {
|
|
409
|
-
console.log(chalk2.gray(` \u2502 ... (${totalLines - 6} more lines)`));
|
|
410
|
-
}
|
|
411
|
-
console.log(color(` \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518`));
|
|
412
|
-
console.log("");
|
|
413
|
-
const rl = readline2.createInterface({ input: process.stdin, output: process.stdout });
|
|
414
|
-
const answer = await new Promise((resolve2) => {
|
|
415
|
-
rl.question(chalk2.cyan(` \u{1F4BE} ${action === "CREATE" ? "Write this file" : "Apply changes"}? (y/n/path): `), resolve2);
|
|
416
|
-
});
|
|
417
|
-
rl.close();
|
|
418
|
-
const trimmed = answer.trim().toLowerCase();
|
|
419
|
-
if (trimmed === "n" || trimmed === "no") {
|
|
420
|
-
console.log(chalk2.gray(" \u23ED\uFE0F Skipped."));
|
|
421
|
-
return false;
|
|
422
|
-
}
|
|
423
|
-
let targetPath = absolutePath;
|
|
424
|
-
if (trimmed !== "y" && trimmed !== "yes" && trimmed.length > 0) {
|
|
425
|
-
targetPath = path2.join(process.cwd(), trimmed);
|
|
426
|
-
}
|
|
427
|
-
try {
|
|
428
|
-
const dir = path2.dirname(targetPath);
|
|
429
|
-
if (!fs2.existsSync(dir)) {
|
|
430
|
-
fs2.mkdirSync(dir, { recursive: true });
|
|
431
|
-
}
|
|
432
|
-
if (!proposed.isNew && fs2.existsSync(targetPath)) {
|
|
433
|
-
const backupDir = path2.join(process.cwd(), ".bob-backups");
|
|
434
|
-
if (!fs2.existsSync(backupDir)) fs2.mkdirSync(backupDir, { recursive: true });
|
|
435
|
-
const timestamp = Date.now();
|
|
436
|
-
const backupName = proposed.filePath.replace(/[\/\\]/g, "_") + `.${timestamp}.bak`;
|
|
437
|
-
fs2.copyFileSync(targetPath, path2.join(backupDir, backupName));
|
|
438
|
-
}
|
|
439
|
-
fs2.writeFileSync(targetPath, proposed.content, "utf-8");
|
|
440
|
-
const relativePath = path2.relative(process.cwd(), targetPath);
|
|
441
|
-
console.log(chalk2.green(` \u2705 Written: ${relativePath}`));
|
|
442
|
-
if (!proposed.isNew) {
|
|
443
|
-
console.log(chalk2.gray(` \u{1F4E6} Backup saved to .bob-backups/`));
|
|
444
|
-
}
|
|
445
|
-
console.log("");
|
|
446
|
-
return true;
|
|
447
|
-
} catch (error) {
|
|
448
|
-
console.log(chalk2.red(` \u274C Write failed: ${error.message}`));
|
|
449
|
-
return false;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
export {
|
|
454
|
-
getConfig,
|
|
455
|
-
setConfigValue,
|
|
456
|
-
getConfigPath,
|
|
457
|
-
registerLoginCommand,
|
|
458
|
-
callCloudFunction,
|
|
459
|
-
callLocalModel,
|
|
460
|
-
buildLocalContext,
|
|
461
|
-
readFileContent,
|
|
462
|
-
extractProposedFile,
|
|
463
|
-
stripCodeBlockFromResponse,
|
|
464
|
-
proposeAndWriteFile
|
|
465
|
-
};
|