@caliber-ai/cli 0.14.1 → 0.15.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.
package/dist/bin.js CHANGED
@@ -85,6 +85,7 @@ import ora2 from "ora";
85
85
  import readline from "readline";
86
86
  import select from "@inquirer/select";
87
87
  import fs16 from "fs";
88
+ import { createTwoFilesPatch } from "diff";
88
89
 
89
90
  // src/auth/token-store.ts
90
91
  init_constants();
@@ -2066,26 +2067,38 @@ function collectSetupFiles(setup) {
2066
2067
  }
2067
2068
  return files;
2068
2069
  }
2069
- function previewFileContent(filePath, content, maxLines = 25) {
2070
+ function previewNewFile(filePath, content, maxLines = 40) {
2070
2071
  const lines = content.split("\n");
2071
2072
  const displayLines = lines.slice(0, maxLines);
2072
- const maxWidth = Math.max(60, ...displayLines.map((l) => l.length + 4));
2073
- const width = Math.min(maxWidth, 80);
2074
2073
  console.log("");
2075
- console.log(` ${chalk3.dim("\u250C\u2500")} ${chalk3.bold(filePath)} ${chalk3.dim("\u2500".repeat(Math.max(0, width - filePath.length - 5)) + "\u2510")}`);
2076
- console.log(` ${chalk3.dim("\u2502")}${" ".repeat(width - 1)}${chalk3.dim("\u2502")}`);
2074
+ console.log(` ${chalk3.green("+ new")} ${chalk3.bold(filePath)}`);
2075
+ console.log(chalk3.dim(" \u2500".repeat(30)));
2077
2076
  for (const line of displayLines) {
2078
- const truncated = line.length > width - 5 ? line.slice(0, width - 8) + "..." : line;
2079
- const padding = " ".repeat(Math.max(0, width - truncated.length - 3));
2080
- console.log(` ${chalk3.dim("\u2502")} ${truncated}${padding}${chalk3.dim("\u2502")}`);
2077
+ console.log(` ${chalk3.green("+")} ${line}`);
2081
2078
  }
2082
2079
  if (lines.length > maxLines) {
2083
- console.log(` ${chalk3.dim("\u2502")}${" ".repeat(width - 1)}${chalk3.dim("\u2502")}`);
2084
- const note = `(showing first ${maxLines} lines, full file is ${lines.length} lines)`;
2085
- const notePadding = " ".repeat(Math.max(0, width - note.length - 3));
2086
- console.log(` ${chalk3.dim("\u2502")} ${chalk3.dim(note)}${notePadding}${chalk3.dim("\u2502")}`);
2080
+ console.log("");
2081
+ console.log(chalk3.dim(` ... ${lines.length - maxLines} more lines (${lines.length} total)`));
2082
+ }
2083
+ console.log("");
2084
+ }
2085
+ function previewDiff(filePath, oldContent, newContent) {
2086
+ const patch = createTwoFilesPatch(filePath, filePath, oldContent, newContent, "current", "proposed", { context: 3 });
2087
+ const patchLines = patch.split("\n").slice(2);
2088
+ console.log("");
2089
+ console.log(` ${chalk3.yellow("~ modified")} ${chalk3.bold(filePath)}`);
2090
+ console.log(chalk3.dim(" \u2500".repeat(30)));
2091
+ for (const line of patchLines) {
2092
+ if (line.startsWith("@@")) {
2093
+ console.log(` ${chalk3.cyan(line)}`);
2094
+ } else if (line.startsWith("+")) {
2095
+ console.log(` ${chalk3.green(line)}`);
2096
+ } else if (line.startsWith("-")) {
2097
+ console.log(` ${chalk3.red(line)}`);
2098
+ } else {
2099
+ console.log(` ${chalk3.dim(line)}`);
2100
+ }
2087
2101
  }
2088
- console.log(` ${chalk3.dim("\u2514" + "\u2500".repeat(width - 1) + "\u2518")}`);
2089
2102
  console.log("");
2090
2103
  }
2091
2104
  async function promptFilePreview(setup) {
@@ -2094,11 +2107,19 @@ async function promptFilePreview(setup) {
2094
2107
  console.log(chalk3.dim("\n No files to preview.\n"));
2095
2108
  return;
2096
2109
  }
2097
- const choice = await select({
2098
- message: "Which file to preview?",
2099
- choices: files.map((f, i) => ({ name: f.path, value: i }))
2110
+ const choices = files.map((f, i) => {
2111
+ const exists = fs16.existsSync(f.path);
2112
+ const icon = exists ? chalk3.yellow("~") : chalk3.green("+");
2113
+ return { name: `${icon} ${f.path}`, value: i };
2100
2114
  });
2101
- previewFileContent(files[choice].path, files[choice].content);
2115
+ const choice = await select({ message: "Which file to preview?", choices });
2116
+ const file = files[choice];
2117
+ if (fs16.existsSync(file.path)) {
2118
+ const existing = fs16.readFileSync(file.path, "utf-8");
2119
+ previewDiff(file.path, existing, file.content);
2120
+ } else {
2121
+ previewNewFile(file.path, file.content);
2122
+ }
2102
2123
  }
2103
2124
 
2104
2125
  // src/commands/undo.ts