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