@codebakers/cli 1.1.0 → 1.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/index.js +495 -15
- package/package.json +7 -2
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
10
|
import { Command } from "commander";
|
|
11
|
-
import
|
|
11
|
+
import chalk4 from "chalk";
|
|
12
12
|
|
|
13
13
|
// src/commands/setup.ts
|
|
14
14
|
import inquirer from "inquirer";
|
|
@@ -93,13 +93,26 @@ async function fetchPatterns(patterns) {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
// src/commands/setup.ts
|
|
96
|
+
var CODEBAKERS_MARKER = "# CODEBAKERS SMART ROUTER";
|
|
97
|
+
var USER_CONTENT_SEPARATOR = `
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
# USER CUSTOM INSTRUCTIONS
|
|
102
|
+
|
|
103
|
+
The following instructions were preserved from your original CLAUDE.md file.
|
|
104
|
+
CodeBakers patterns will be applied first, then these instructions.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
`;
|
|
96
109
|
var IDE_CONFIGS = {
|
|
97
110
|
cursor: {
|
|
98
111
|
file: ".cursor/mcp.json",
|
|
99
112
|
description: "Cursor AI IDE"
|
|
100
113
|
},
|
|
101
114
|
"claude-code": {
|
|
102
|
-
file: ".
|
|
115
|
+
file: ".mcp.json",
|
|
103
116
|
description: "Claude Code"
|
|
104
117
|
}
|
|
105
118
|
};
|
|
@@ -180,6 +193,7 @@ Validation failed: ${validation.error || "Unknown error"}`));
|
|
|
180
193
|
if (ide) {
|
|
181
194
|
await configureIDE(ide, options.force);
|
|
182
195
|
}
|
|
196
|
+
await installClaudeMd(apiKey, options.force);
|
|
183
197
|
const firstName = userName?.split(" ")[0];
|
|
184
198
|
const greeting = firstName ? `${firstName}, you're` : "You're";
|
|
185
199
|
console.log(chalk.bold.green("\n\u{1F389} Setup complete!\n"));
|
|
@@ -222,10 +236,12 @@ Error: ${message}`));
|
|
|
222
236
|
}
|
|
223
237
|
async function configureMCP(ide, force, spinner) {
|
|
224
238
|
const config = IDE_CONFIGS[ide];
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
239
|
+
const targetPath = ide === "cursor" ? join(process.cwd(), ".cursor", "mcp.json") : join(process.cwd(), ".mcp.json");
|
|
240
|
+
if (ide === "cursor") {
|
|
241
|
+
const targetDir = join(process.cwd(), ".cursor");
|
|
242
|
+
if (!existsSync(targetDir)) {
|
|
243
|
+
await mkdir(targetDir, { recursive: true });
|
|
244
|
+
}
|
|
229
245
|
}
|
|
230
246
|
let existingConfig = {};
|
|
231
247
|
if (existsSync(targetPath)) {
|
|
@@ -274,6 +290,78 @@ async function configureMCP(ide, force, spinner) {
|
|
|
274
290
|
console.log(chalk.yellow("Restart your IDE to activate the MCP server.\n"));
|
|
275
291
|
}
|
|
276
292
|
}
|
|
293
|
+
async function fetchClaudeMdFromApi(apiKey) {
|
|
294
|
+
try {
|
|
295
|
+
const apiUrl = getApiUrl();
|
|
296
|
+
const response = await fetch(`${apiUrl}/api/cli/claude-md`, {
|
|
297
|
+
headers: {
|
|
298
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
299
|
+
"Content-Type": "application/json"
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
if (!response.ok) {
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
const data = await response.json();
|
|
306
|
+
return data.content || null;
|
|
307
|
+
} catch {
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async function installClaudeMd(apiKey, force) {
|
|
312
|
+
const spinner = ora("Setting up CLAUDE.md...").start();
|
|
313
|
+
const claudeMdPath = join(process.cwd(), "CLAUDE.md");
|
|
314
|
+
try {
|
|
315
|
+
spinner.text = "Fetching CLAUDE.md from CodeBakers...";
|
|
316
|
+
const codebakersContent = await fetchClaudeMdFromApi(apiKey);
|
|
317
|
+
if (!codebakersContent) {
|
|
318
|
+
spinner.warn("Could not fetch CLAUDE.md from API. Skipping...");
|
|
319
|
+
console.log(chalk.dim(" You can manually add CLAUDE.md later.\n"));
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (existsSync(claudeMdPath)) {
|
|
323
|
+
const existingContent = await readFile(claudeMdPath, "utf-8");
|
|
324
|
+
const isCodeBakersFile = existingContent.trim().startsWith(CODEBAKERS_MARKER);
|
|
325
|
+
if (isCodeBakersFile) {
|
|
326
|
+
await writeFile(claudeMdPath, codebakersContent, "utf-8");
|
|
327
|
+
spinner.succeed("Updated CLAUDE.md to latest version");
|
|
328
|
+
} else {
|
|
329
|
+
if (!force) {
|
|
330
|
+
spinner.stop();
|
|
331
|
+
console.log(chalk.cyan("\n \u2139\uFE0F Your custom instructions will be preserved at the end of the file."));
|
|
332
|
+
console.log(chalk.dim(" CodeBakers patterns load first, then your rules apply on top."));
|
|
333
|
+
console.log(chalk.dim(" Your original content remains intact and can still override patterns.\n"));
|
|
334
|
+
const { shouldMerge } = await inquirer.prompt([
|
|
335
|
+
{
|
|
336
|
+
type: "confirm",
|
|
337
|
+
name: "shouldMerge",
|
|
338
|
+
message: "Merge with CodeBakers?",
|
|
339
|
+
default: true
|
|
340
|
+
}
|
|
341
|
+
]);
|
|
342
|
+
if (!shouldMerge) {
|
|
343
|
+
console.log(chalk.yellow(" Skipping CLAUDE.md installation.\n"));
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
spinner.start("Merging CLAUDE.md...");
|
|
347
|
+
}
|
|
348
|
+
const mergedContent = codebakersContent + USER_CONTENT_SEPARATOR + existingContent;
|
|
349
|
+
await writeFile(claudeMdPath, mergedContent, "utf-8");
|
|
350
|
+
spinner.succeed("Merged CLAUDE.md (your custom instructions preserved at the end)");
|
|
351
|
+
}
|
|
352
|
+
} else {
|
|
353
|
+
await writeFile(claudeMdPath, codebakersContent, "utf-8");
|
|
354
|
+
spinner.succeed("Created CLAUDE.md");
|
|
355
|
+
}
|
|
356
|
+
console.log(chalk.green("\u2713 CLAUDE.md installed"));
|
|
357
|
+
console.log(chalk.dim(" This file tells your AI to use CodeBakers patterns.\n"));
|
|
358
|
+
} catch (error) {
|
|
359
|
+
spinner.fail("Failed to install CLAUDE.md");
|
|
360
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
361
|
+
console.log(chalk.dim(` Error: ${message}
|
|
362
|
+
`));
|
|
363
|
+
}
|
|
364
|
+
}
|
|
277
365
|
|
|
278
366
|
// src/commands/serve.ts
|
|
279
367
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
@@ -474,34 +562,426 @@ ${text}`).join("\n\n---\n\n");
|
|
|
474
562
|
});
|
|
475
563
|
}
|
|
476
564
|
|
|
565
|
+
// src/commands/validate.ts
|
|
566
|
+
import chalk2 from "chalk";
|
|
567
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
568
|
+
import { join as join2 } from "path";
|
|
569
|
+
function validateStateFile(projectRoot) {
|
|
570
|
+
const result = { valid: true, errors: [], warnings: [] };
|
|
571
|
+
const statePath = join2(projectRoot, ".codebakers.json");
|
|
572
|
+
if (!existsSync2(statePath)) {
|
|
573
|
+
result.warnings.push("No .codebakers.json found");
|
|
574
|
+
return result;
|
|
575
|
+
}
|
|
576
|
+
try {
|
|
577
|
+
const content = readFileSync(statePath, "utf-8");
|
|
578
|
+
JSON.parse(content);
|
|
579
|
+
} catch (error) {
|
|
580
|
+
result.valid = false;
|
|
581
|
+
result.errors.push(`Invalid JSON in .codebakers.json: ${error}`);
|
|
582
|
+
}
|
|
583
|
+
return result;
|
|
584
|
+
}
|
|
585
|
+
function validateContextSummaries(projectRoot) {
|
|
586
|
+
const result = { valid: true, errors: [], warnings: [] };
|
|
587
|
+
const statePath = join2(projectRoot, ".codebakers.json");
|
|
588
|
+
if (!existsSync2(statePath)) return result;
|
|
589
|
+
const state = JSON.parse(readFileSync(statePath, "utf-8"));
|
|
590
|
+
if (!state.build?.fileToTaskMap) return result;
|
|
591
|
+
const trackedFiles = Object.keys(state.build.fileToTaskMap);
|
|
592
|
+
const contextFiles = state.context ? Object.keys(state.context) : [];
|
|
593
|
+
const missingContext = [];
|
|
594
|
+
for (const file of trackedFiles) {
|
|
595
|
+
if (file.endsWith(".json") || file.endsWith(".config.ts") || file.endsWith(".config.js")) {
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
if (file.startsWith("src/") && !contextFiles.includes(file)) {
|
|
599
|
+
missingContext.push(file);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
if (missingContext.length > 0) {
|
|
603
|
+
result.warnings.push(`Missing context summaries: ${missingContext.length} files`);
|
|
604
|
+
}
|
|
605
|
+
return result;
|
|
606
|
+
}
|
|
607
|
+
function validateContracts(projectRoot) {
|
|
608
|
+
const result = { valid: true, errors: [], warnings: [] };
|
|
609
|
+
const statePath = join2(projectRoot, ".codebakers.json");
|
|
610
|
+
if (!existsSync2(statePath)) return result;
|
|
611
|
+
const state = JSON.parse(readFileSync(statePath, "utf-8"));
|
|
612
|
+
if (!state.contracts) return result;
|
|
613
|
+
for (const [featureName, contract] of Object.entries(state.contracts)) {
|
|
614
|
+
if (!contract.expects) continue;
|
|
615
|
+
for (const depName of Object.keys(contract.expects)) {
|
|
616
|
+
if (depName === "environment" || depName === "database") continue;
|
|
617
|
+
if (typeof contract.expects[depName] === "object" && !state.contracts[depName]) {
|
|
618
|
+
result.warnings.push(`'${featureName}' expects '${depName}' but no contract found`);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return result;
|
|
623
|
+
}
|
|
624
|
+
function validateBuildState(projectRoot) {
|
|
625
|
+
const result = { valid: true, errors: [], warnings: [] };
|
|
626
|
+
const statePath = join2(projectRoot, ".codebakers.json");
|
|
627
|
+
if (!existsSync2(statePath)) return result;
|
|
628
|
+
const state = JSON.parse(readFileSync(statePath, "utf-8"));
|
|
629
|
+
if (!state.build) return result;
|
|
630
|
+
let inProgressCount = 0;
|
|
631
|
+
for (const phase of state.build.phases || []) {
|
|
632
|
+
for (const task of phase.tasks || []) {
|
|
633
|
+
if (task.status === "in_progress") {
|
|
634
|
+
inProgressCount++;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (inProgressCount > 1) {
|
|
639
|
+
result.warnings.push(`${inProgressCount} tasks marked in_progress (should be 1)`);
|
|
640
|
+
}
|
|
641
|
+
return result;
|
|
642
|
+
}
|
|
643
|
+
function validateFileExistence(projectRoot) {
|
|
644
|
+
const result = { valid: true, errors: [], warnings: [] };
|
|
645
|
+
const statePath = join2(projectRoot, ".codebakers.json");
|
|
646
|
+
if (!existsSync2(statePath)) return result;
|
|
647
|
+
const state = JSON.parse(readFileSync(statePath, "utf-8"));
|
|
648
|
+
if (!state.build?.fileToTaskMap) return result;
|
|
649
|
+
const missingFiles = [];
|
|
650
|
+
for (const file of Object.keys(state.build.fileToTaskMap)) {
|
|
651
|
+
const filePath = join2(projectRoot, file);
|
|
652
|
+
if (!existsSync2(filePath)) {
|
|
653
|
+
missingFiles.push(file);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (missingFiles.length > 0) {
|
|
657
|
+
result.errors.push(`${missingFiles.length} tracked files don't exist`);
|
|
658
|
+
result.valid = false;
|
|
659
|
+
}
|
|
660
|
+
return result;
|
|
661
|
+
}
|
|
662
|
+
function showBuildStatus(projectRoot) {
|
|
663
|
+
const statePath = join2(projectRoot, ".codebakers.json");
|
|
664
|
+
if (!existsSync2(statePath)) {
|
|
665
|
+
console.log(chalk2.dim("\nNo active build found."));
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
const state = JSON.parse(readFileSync(statePath, "utf-8"));
|
|
669
|
+
if (!state.build) {
|
|
670
|
+
console.log(chalk2.dim("\nNo active build found."));
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
console.log(chalk2.bold(`
|
|
674
|
+
\u{1F4CA} Build: ${state.build.projectName || "Unnamed Project"}`));
|
|
675
|
+
console.log("");
|
|
676
|
+
for (const phase of state.build.phases || []) {
|
|
677
|
+
const tasks = phase.tasks || [];
|
|
678
|
+
const completed = tasks.filter((t) => t.status === "completed").length;
|
|
679
|
+
const total = tasks.length;
|
|
680
|
+
const pct = total > 0 ? Math.round(completed / total * 100) : 0;
|
|
681
|
+
const bar = "\u2588".repeat(Math.round(pct / 10)) + "\u2591".repeat(10 - Math.round(pct / 10));
|
|
682
|
+
let status = "";
|
|
683
|
+
if (phase.status === "complete") {
|
|
684
|
+
status = chalk2.green("\u2705");
|
|
685
|
+
} else if (phase.status === "in_progress") {
|
|
686
|
+
status = chalk2.yellow("\u{1F504}");
|
|
687
|
+
} else {
|
|
688
|
+
status = chalk2.dim("\u23F3");
|
|
689
|
+
}
|
|
690
|
+
console.log(`${status} Phase ${phase.id}: ${phase.name} [${bar}] ${pct}%`);
|
|
691
|
+
}
|
|
692
|
+
if (state.build.stats) {
|
|
693
|
+
console.log("");
|
|
694
|
+
console.log(chalk2.dim(`Tasks: ${state.build.stats.completedTasks}/${state.build.stats.totalTasks} completed`));
|
|
695
|
+
}
|
|
696
|
+
if (state.build.currentTaskId) {
|
|
697
|
+
for (const phase of state.build.phases || []) {
|
|
698
|
+
const task = phase.tasks?.find((t) => t.id === state.build.currentTaskId);
|
|
699
|
+
if (task) {
|
|
700
|
+
console.log("");
|
|
701
|
+
console.log(chalk2.bold("Current Task:"));
|
|
702
|
+
console.log(` ${task.id}: ${task.title}`);
|
|
703
|
+
break;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (state.context) {
|
|
708
|
+
const contextCount = Object.keys(state.context).length;
|
|
709
|
+
console.log("");
|
|
710
|
+
console.log(chalk2.dim(`Context summaries: ${contextCount} files`));
|
|
711
|
+
}
|
|
712
|
+
if (state.contracts) {
|
|
713
|
+
const contractCount = Object.keys(state.contracts).length;
|
|
714
|
+
console.log(chalk2.dim(`Feature contracts: ${contractCount} defined`));
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
function validateCommand(program2) {
|
|
718
|
+
const cmd = program2.command("validate").description("Validate architectural coherence of the project").option("-v, --verbose", "Show detailed output").option("--status", "Show build status summary").action(async (options) => {
|
|
719
|
+
const projectRoot = process.cwd();
|
|
720
|
+
console.log(chalk2.bold("\n\u{1F50D} CodeBakers Coherence Validator\n"));
|
|
721
|
+
if (options.status) {
|
|
722
|
+
showBuildStatus(projectRoot);
|
|
723
|
+
console.log("");
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
const validators = [
|
|
727
|
+
{ name: "State File", fn: validateStateFile },
|
|
728
|
+
{ name: "Context Summaries", fn: validateContextSummaries },
|
|
729
|
+
{ name: "Contracts", fn: validateContracts },
|
|
730
|
+
{ name: "Build State", fn: validateBuildState },
|
|
731
|
+
{ name: "File Existence", fn: validateFileExistence }
|
|
732
|
+
];
|
|
733
|
+
let hasErrors = false;
|
|
734
|
+
let hasWarnings = false;
|
|
735
|
+
for (const { name, fn } of validators) {
|
|
736
|
+
const result = fn(projectRoot);
|
|
737
|
+
if (result.errors.length > 0) {
|
|
738
|
+
hasErrors = true;
|
|
739
|
+
console.log(chalk2.red(`\u274C ${name}:`));
|
|
740
|
+
for (const error of result.errors) {
|
|
741
|
+
console.log(chalk2.red(` ${error}`));
|
|
742
|
+
}
|
|
743
|
+
} else if (result.warnings.length > 0) {
|
|
744
|
+
hasWarnings = true;
|
|
745
|
+
console.log(chalk2.yellow(`\u26A0\uFE0F ${name}:`));
|
|
746
|
+
for (const warning of result.warnings) {
|
|
747
|
+
console.log(chalk2.yellow(` ${warning}`));
|
|
748
|
+
}
|
|
749
|
+
} else {
|
|
750
|
+
console.log(chalk2.green(`\u2705 ${name}`));
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
console.log("");
|
|
754
|
+
if (hasErrors) {
|
|
755
|
+
console.log(chalk2.red("Validation FAILED"));
|
|
756
|
+
process.exit(1);
|
|
757
|
+
} else if (hasWarnings) {
|
|
758
|
+
console.log(chalk2.yellow("Validation passed with warnings"));
|
|
759
|
+
} else {
|
|
760
|
+
console.log(chalk2.green("All validations passed"));
|
|
761
|
+
}
|
|
762
|
+
showBuildStatus(projectRoot);
|
|
763
|
+
console.log("");
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// src/commands/summarize.ts
|
|
768
|
+
import chalk3 from "chalk";
|
|
769
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
770
|
+
import { join as join3, relative, extname } from "path";
|
|
771
|
+
function detectFileType(filePath) {
|
|
772
|
+
const ext = extname(filePath);
|
|
773
|
+
const name = filePath.toLowerCase();
|
|
774
|
+
if (name.includes("schema") || name.includes("/db/")) return "schema";
|
|
775
|
+
if (name.includes("/api/") || name.includes("route.ts")) return "api";
|
|
776
|
+
if (name.includes("middleware")) return "middleware";
|
|
777
|
+
if (name.includes("/components/")) return "component";
|
|
778
|
+
if (name.includes("/hooks/") || name.startsWith("use")) return "hook";
|
|
779
|
+
if (name.includes("/lib/") || name.includes("/utils/")) return "utility";
|
|
780
|
+
if (name.includes(".test.") || name.includes(".spec.")) return "test";
|
|
781
|
+
return "unknown";
|
|
782
|
+
}
|
|
783
|
+
function generateSummaryTemplate(filePath, content) {
|
|
784
|
+
const fileType = detectFileType(filePath);
|
|
785
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
786
|
+
const exportMatches = content.match(/export\s+(const|function|class|type|interface|enum)\s+(\w+)/g) || [];
|
|
787
|
+
const exports = exportMatches.map((m) => {
|
|
788
|
+
const match = m.match(/export\s+(?:const|function|class|type|interface|enum)\s+(\w+)/);
|
|
789
|
+
return match ? match[1] : "";
|
|
790
|
+
}).filter(Boolean);
|
|
791
|
+
const base = {
|
|
792
|
+
purpose: `[TODO: Describe what this ${fileType} does]`,
|
|
793
|
+
exports: exports.length > 0 ? exports : void 0,
|
|
794
|
+
createdAt: now
|
|
795
|
+
};
|
|
796
|
+
switch (fileType) {
|
|
797
|
+
case "schema":
|
|
798
|
+
return {
|
|
799
|
+
...base,
|
|
800
|
+
purpose: "[TODO: Describe this database schema]",
|
|
801
|
+
schema: {},
|
|
802
|
+
relations: []
|
|
803
|
+
};
|
|
804
|
+
case "api":
|
|
805
|
+
return {
|
|
806
|
+
...base,
|
|
807
|
+
purpose: "[TODO: Describe this API endpoint]",
|
|
808
|
+
method: content.includes("POST") ? "POST" : content.includes("PUT") ? "PUT" : content.includes("DELETE") ? "DELETE" : "GET",
|
|
809
|
+
input: {},
|
|
810
|
+
output: {},
|
|
811
|
+
sideEffects: []
|
|
812
|
+
};
|
|
813
|
+
case "middleware":
|
|
814
|
+
return {
|
|
815
|
+
...base,
|
|
816
|
+
purpose: "[TODO: Describe this middleware]",
|
|
817
|
+
behavior: {},
|
|
818
|
+
protectedRoutes: [],
|
|
819
|
+
publicRoutes: []
|
|
820
|
+
};
|
|
821
|
+
case "component":
|
|
822
|
+
return {
|
|
823
|
+
...base,
|
|
824
|
+
purpose: "[TODO: Describe this component]",
|
|
825
|
+
props: [],
|
|
826
|
+
state: [],
|
|
827
|
+
events: []
|
|
828
|
+
};
|
|
829
|
+
case "hook":
|
|
830
|
+
return {
|
|
831
|
+
...base,
|
|
832
|
+
purpose: "[TODO: Describe this hook]",
|
|
833
|
+
params: [],
|
|
834
|
+
returns: "[TODO]",
|
|
835
|
+
sideEffects: []
|
|
836
|
+
};
|
|
837
|
+
case "utility":
|
|
838
|
+
return {
|
|
839
|
+
...base,
|
|
840
|
+
purpose: "[TODO: Describe this utility]",
|
|
841
|
+
dependencies: [],
|
|
842
|
+
patterns: {}
|
|
843
|
+
};
|
|
844
|
+
default:
|
|
845
|
+
return base;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
function ensureStateFile(projectRoot) {
|
|
849
|
+
const statePath = join3(projectRoot, ".codebakers.json");
|
|
850
|
+
if (existsSync3(statePath)) {
|
|
851
|
+
return JSON.parse(readFileSync2(statePath, "utf-8"));
|
|
852
|
+
}
|
|
853
|
+
const initial = {
|
|
854
|
+
version: "2.0",
|
|
855
|
+
context: {}
|
|
856
|
+
};
|
|
857
|
+
writeFileSync(statePath, JSON.stringify(initial, null, 2));
|
|
858
|
+
return initial;
|
|
859
|
+
}
|
|
860
|
+
function summarizeCommand(program2) {
|
|
861
|
+
program2.command("summarize [file]").description("Generate or update context summary for a file").option("-a, --all", "Generate summaries for all tracked files").option("--show", "Show existing summary without modifying").action(async (file, options) => {
|
|
862
|
+
const projectRoot = process.cwd();
|
|
863
|
+
const statePath = join3(projectRoot, ".codebakers.json");
|
|
864
|
+
console.log(chalk3.bold("\n\u{1F4DD} CodeBakers Context Summarizer\n"));
|
|
865
|
+
const state = ensureStateFile(projectRoot);
|
|
866
|
+
if (!state.context) {
|
|
867
|
+
state.context = {};
|
|
868
|
+
}
|
|
869
|
+
if (options.all) {
|
|
870
|
+
if (!state.build?.fileToTaskMap) {
|
|
871
|
+
console.log(chalk3.yellow("No tracked files found in build."));
|
|
872
|
+
console.log(chalk3.dim("Run /build command first to start tracking files."));
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
const files = Object.keys(state.build.fileToTaskMap);
|
|
876
|
+
let generated = 0;
|
|
877
|
+
let skipped = 0;
|
|
878
|
+
for (const f of files) {
|
|
879
|
+
if (f.endsWith(".json") || f.endsWith(".config.ts")) {
|
|
880
|
+
skipped++;
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
const filePath = join3(projectRoot, f);
|
|
884
|
+
if (!existsSync3(filePath)) {
|
|
885
|
+
console.log(chalk3.yellow(`\u26A0\uFE0F ${f} - file not found`));
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
if (state.context[f]) {
|
|
889
|
+
console.log(chalk3.dim(` ${f} - already has summary`));
|
|
890
|
+
skipped++;
|
|
891
|
+
continue;
|
|
892
|
+
}
|
|
893
|
+
const content = readFileSync2(filePath, "utf-8");
|
|
894
|
+
const summary = generateSummaryTemplate(f, content);
|
|
895
|
+
state.context[f] = summary;
|
|
896
|
+
generated++;
|
|
897
|
+
console.log(chalk3.green(`\u2705 ${f}`));
|
|
898
|
+
}
|
|
899
|
+
writeFileSync(statePath, JSON.stringify(state, null, 2));
|
|
900
|
+
console.log("");
|
|
901
|
+
console.log(chalk3.bold(`Generated: ${generated} | Skipped: ${skipped}`));
|
|
902
|
+
console.log(chalk3.dim("\nEdit .codebakers.json to fill in [TODO] placeholders."));
|
|
903
|
+
} else if (file) {
|
|
904
|
+
const relativePath = relative(projectRoot, join3(projectRoot, file));
|
|
905
|
+
const filePath = join3(projectRoot, file);
|
|
906
|
+
if (!existsSync3(filePath)) {
|
|
907
|
+
console.log(chalk3.red(`File not found: ${file}`));
|
|
908
|
+
process.exit(1);
|
|
909
|
+
}
|
|
910
|
+
if (options.show && state.context[relativePath]) {
|
|
911
|
+
console.log(chalk3.bold(`Summary for ${relativePath}:
|
|
912
|
+
`));
|
|
913
|
+
console.log(JSON.stringify(state.context[relativePath], null, 2));
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
const content = readFileSync2(filePath, "utf-8");
|
|
917
|
+
const summary = generateSummaryTemplate(relativePath, content);
|
|
918
|
+
if (state.context[relativePath]) {
|
|
919
|
+
console.log(chalk3.yellow(`Updating existing summary for ${relativePath}`));
|
|
920
|
+
state.context[relativePath] = {
|
|
921
|
+
...summary,
|
|
922
|
+
...state.context[relativePath],
|
|
923
|
+
exports: summary.exports
|
|
924
|
+
// Always update exports
|
|
925
|
+
};
|
|
926
|
+
} else {
|
|
927
|
+
state.context[relativePath] = summary;
|
|
928
|
+
console.log(chalk3.green(`Created summary for ${relativePath}`));
|
|
929
|
+
}
|
|
930
|
+
writeFileSync(statePath, JSON.stringify(state, null, 2));
|
|
931
|
+
console.log("");
|
|
932
|
+
console.log(chalk3.bold("Summary:"));
|
|
933
|
+
console.log(JSON.stringify(state.context[relativePath], null, 2));
|
|
934
|
+
console.log("");
|
|
935
|
+
console.log(chalk3.dim("Edit .codebakers.json to fill in [TODO] placeholders."));
|
|
936
|
+
} else {
|
|
937
|
+
console.log("Usage:");
|
|
938
|
+
console.log(" codebakers summarize <file> Generate summary for a specific file");
|
|
939
|
+
console.log(" codebakers summarize --all Generate summaries for all tracked files");
|
|
940
|
+
console.log(" codebakers summarize <file> --show Show existing summary");
|
|
941
|
+
console.log("");
|
|
942
|
+
const contextCount = Object.keys(state.context).length;
|
|
943
|
+
const todoCount = Object.values(state.context).filter(
|
|
944
|
+
(c) => JSON.stringify(c).includes("[TODO]")
|
|
945
|
+
).length;
|
|
946
|
+
console.log(chalk3.bold("Current Status:"));
|
|
947
|
+
console.log(` Summaries: ${contextCount}`);
|
|
948
|
+
if (todoCount > 0) {
|
|
949
|
+
console.log(chalk3.yellow(` Need attention: ${todoCount} with [TODO] placeholders`));
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
|
|
477
955
|
// src/index.ts
|
|
478
956
|
var program = new Command();
|
|
479
957
|
program.name("codebakers").description("CodeBakers CLI - AI prompt patterns for production-ready code").version("1.0.0");
|
|
480
958
|
setupCommand(program);
|
|
481
959
|
serveCommand(program);
|
|
960
|
+
validateCommand(program);
|
|
961
|
+
summarizeCommand(program);
|
|
482
962
|
program.command("status").description("Check CodeBakers configuration status").action(() => {
|
|
483
|
-
console.log(
|
|
963
|
+
console.log(chalk4.bold("\n\u{1F36A} CodeBakers Status\n"));
|
|
484
964
|
const apiKey = getApiKey();
|
|
485
965
|
if (apiKey) {
|
|
486
966
|
const maskedKey = apiKey.substring(0, 10) + "..." + apiKey.slice(-4);
|
|
487
|
-
console.log(
|
|
488
|
-
console.log(
|
|
967
|
+
console.log(chalk4.green("\u2713 API key configured"));
|
|
968
|
+
console.log(chalk4.dim(` Key: ${maskedKey}`));
|
|
489
969
|
} else {
|
|
490
|
-
console.log(
|
|
491
|
-
console.log(
|
|
970
|
+
console.log(chalk4.red("\u2717 No API key configured"));
|
|
971
|
+
console.log(chalk4.dim(" Run: codebakers setup"));
|
|
492
972
|
}
|
|
493
973
|
const apiUrl = getApiUrl();
|
|
494
|
-
console.log(
|
|
974
|
+
console.log(chalk4.dim(`
|
|
495
975
|
API URL: ${apiUrl}`));
|
|
496
976
|
if (apiUrl !== "https://codebakers.ai") {
|
|
497
|
-
console.log(
|
|
977
|
+
console.log(chalk4.yellow("\u26A0 Warning: API URL is not the default. Run `codebakers logout` to reset."));
|
|
498
978
|
}
|
|
499
|
-
console.log(
|
|
979
|
+
console.log(chalk4.dim(`Config path: ${getConfigPath()}
|
|
500
980
|
`));
|
|
501
981
|
});
|
|
502
982
|
program.command("logout").description("Remove stored API key").action(async () => {
|
|
503
983
|
const { clearConfig } = await import("./config-R2H6JKGW.js");
|
|
504
984
|
clearConfig();
|
|
505
|
-
console.log(
|
|
985
|
+
console.log(chalk4.green("\n\u2713 API key removed\n"));
|
|
506
986
|
});
|
|
507
987
|
program.parse();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebakers/cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "CodeBakers CLI - AI prompt patterns for production-ready code",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
12
12
|
"dev": "tsup src/index.ts --format esm --watch",
|
|
13
13
|
"prepublishOnly": "npm run build",
|
|
14
|
-
"test": "vitest run"
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:watch": "vitest",
|
|
16
|
+
"test:coverage": "vitest run --coverage",
|
|
17
|
+
"test:unit": "vitest run tests/unit",
|
|
18
|
+
"test:integration": "vitest run tests/integration"
|
|
15
19
|
},
|
|
16
20
|
"files": [
|
|
17
21
|
"dist"
|
|
@@ -46,6 +50,7 @@
|
|
|
46
50
|
"devDependencies": {
|
|
47
51
|
"@types/inquirer": "^9.0.7",
|
|
48
52
|
"@types/node": "^20.11.0",
|
|
53
|
+
"@vitest/coverage-v8": "^1.2.0",
|
|
49
54
|
"tsup": "^8.0.2",
|
|
50
55
|
"typescript": "^5.3.3",
|
|
51
56
|
"vitest": "^1.2.0"
|