@corbat-tech/coco 2.25.8 → 2.25.9

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/cli/index.js CHANGED
@@ -2543,7 +2543,7 @@ function getDefaultModel(provider) {
2543
2543
  case "codex":
2544
2544
  return process.env["CODEX_MODEL"] ?? "codex-mini-latest";
2545
2545
  case "copilot":
2546
- return process.env["COPILOT_MODEL"] ?? "gpt-4o-copilot";
2546
+ return process.env["COPILOT_MODEL"] ?? "claude-sonnet-4.6";
2547
2547
  case "groq":
2548
2548
  return process.env["GROQ_MODEL"] ?? "llama-3.3-70b-versatile";
2549
2549
  case "openrouter":
@@ -2562,6 +2562,11 @@ function getDefaultModel(provider) {
2562
2562
  return "claude-sonnet-4-6";
2563
2563
  }
2564
2564
  }
2565
+ function normalizeConfiguredModel(model) {
2566
+ if (typeof model !== "string") return void 0;
2567
+ const trimmed = model.trim();
2568
+ return trimmed.length > 0 ? trimmed : void 0;
2569
+ }
2565
2570
  function getDefaultProvider() {
2566
2571
  const envProvider = process.env["COCO_PROVIDER"]?.toLowerCase();
2567
2572
  if (envProvider && VALID_PROVIDERS.includes(envProvider)) {
@@ -2584,7 +2589,7 @@ async function getLastUsedModel(provider) {
2584
2589
  try {
2585
2590
  const config = await loadConfig(CONFIG_PATHS.config);
2586
2591
  if (config.provider.type === provider) {
2587
- return config.provider.model;
2592
+ return normalizeConfiguredModel(config.provider.model);
2588
2593
  }
2589
2594
  } catch {
2590
2595
  }
@@ -2621,8 +2626,9 @@ async function saveProviderPreference(provider, model) {
2621
2626
  };
2622
2627
  }
2623
2628
  config.provider.type = provider;
2624
- if (model) {
2625
- config.provider.model = model;
2629
+ const normalizedModel = normalizeConfiguredModel(model);
2630
+ if (normalizedModel) {
2631
+ config.provider.model = normalizedModel;
2626
2632
  } else {
2627
2633
  config.provider.model = getDefaultModel(provider);
2628
2634
  }
@@ -5474,6 +5480,11 @@ var init_codex = __esm({
5474
5480
  };
5475
5481
  }
5476
5482
  });
5483
+ function normalizeModel(model) {
5484
+ if (typeof model !== "string") return void 0;
5485
+ const trimmed = model.trim();
5486
+ return trimmed.length > 0 ? trimmed : void 0;
5487
+ }
5477
5488
  function createCopilotProvider() {
5478
5489
  return new CopilotProvider();
5479
5490
  }
@@ -5528,7 +5539,7 @@ var init_copilot2 = __esm({
5528
5539
  async initialize(config) {
5529
5540
  this.config = {
5530
5541
  ...config,
5531
- model: config.model ?? DEFAULT_MODEL4
5542
+ model: normalizeModel(config.model) ?? DEFAULT_MODEL4
5532
5543
  };
5533
5544
  const tokenResult = await getValidCopilotToken();
5534
5545
  if (tokenResult) {
@@ -6855,12 +6866,17 @@ __export(providers_exports, {
6855
6866
  listProviders: () => listProviders,
6856
6867
  withRetry: () => withRetry
6857
6868
  });
6869
+ function normalizeProviderModel(model) {
6870
+ if (typeof model !== "string") return void 0;
6871
+ const trimmed = model.trim();
6872
+ return trimmed.length > 0 ? trimmed : void 0;
6873
+ }
6858
6874
  async function createProvider(type, config = {}) {
6859
6875
  let provider;
6860
6876
  const mergedConfig = {
6861
6877
  apiKey: config.apiKey ?? getApiKey(type),
6862
6878
  baseUrl: config.baseUrl ?? getBaseUrl(type),
6863
- model: config.model ?? getDefaultModel(type),
6879
+ model: normalizeProviderModel(config.model) ?? getDefaultModel(type),
6864
6880
  maxTokens: config.maxTokens,
6865
6881
  temperature: config.temperature,
6866
6882
  timeout: config.timeout
@@ -9783,7 +9799,7 @@ function generateToolCatalog(registry) {
9783
9799
  }
9784
9800
  async function createDefaultReplConfig() {
9785
9801
  const providerType = await getLastUsedProvider();
9786
- const model = await getLastUsedModel(providerType) ?? getDefaultModel(providerType);
9802
+ const model = await getLastUsedModel(providerType) || getDefaultModel(providerType);
9787
9803
  return {
9788
9804
  provider: {
9789
9805
  type: providerType,
@@ -40566,9 +40582,20 @@ function hasNullByte2(str) {
40566
40582
  }
40567
40583
  function normalizePath2(filePath) {
40568
40584
  let normalized = filePath.replace(/\0/g, "");
40585
+ const home = process.env.HOME || process.env.USERPROFILE;
40586
+ if (home && normalized.startsWith("~")) {
40587
+ if (normalized === "~") {
40588
+ normalized = home;
40589
+ } else if (normalized.startsWith("~/") || normalized.startsWith(`~${path39__default.sep}`)) {
40590
+ normalized = path39__default.join(home, normalized.slice(2));
40591
+ }
40592
+ }
40569
40593
  normalized = path39__default.normalize(normalized);
40570
40594
  return normalized;
40571
40595
  }
40596
+ function resolveUserPath(filePath) {
40597
+ return path39__default.resolve(normalizePath2(filePath));
40598
+ }
40572
40599
  function isWithinDirectory(targetPath, baseDir) {
40573
40600
  const normalizedTarget = path39__default.normalize(targetPath);
40574
40601
  const normalizedBase = path39__default.normalize(baseDir);
@@ -40601,7 +40628,7 @@ function isPathAllowed(filePath, operation) {
40601
40628
  return { allowed: false, reason: "Path contains invalid characters" };
40602
40629
  }
40603
40630
  const normalized = normalizePath2(filePath);
40604
- const absolute = path39__default.resolve(normalized);
40631
+ const absolute = resolveUserPath(normalized);
40605
40632
  const cwd = process.cwd();
40606
40633
  for (const blocked of BLOCKED_PATHS2) {
40607
40634
  const normalizedBlocked = path39__default.normalize(blocked);
@@ -40660,7 +40687,7 @@ function isENOENT(error) {
40660
40687
  return error.code === "ENOENT";
40661
40688
  }
40662
40689
  async function enrichENOENT(filePath, operation) {
40663
- const absPath = path39__default.resolve(filePath);
40690
+ const absPath = resolveUserPath(filePath);
40664
40691
  const suggestions = await suggestSimilarFilesDeep(absPath, process.cwd());
40665
40692
  const hint = formatSuggestions(suggestions, path39__default.dirname(absPath));
40666
40693
  const action = operation === "read" ? "Use glob or list_dir to find the correct path." : "Check that the parent directory exists.";
@@ -40668,7 +40695,7 @@ async function enrichENOENT(filePath, operation) {
40668
40695
  ${action}`;
40669
40696
  }
40670
40697
  async function enrichDirENOENT(dirPath) {
40671
- const absPath = path39__default.resolve(dirPath);
40698
+ const absPath = resolveUserPath(dirPath);
40672
40699
  const suggestions = await suggestSimilarDirsDeep(absPath, process.cwd());
40673
40700
  const hint = formatSuggestions(suggestions, path39__default.dirname(absPath));
40674
40701
  return `Directory not found: ${dirPath}${hint}
@@ -40691,7 +40718,7 @@ Examples:
40691
40718
  async execute({ path: filePath, encoding, maxSize }) {
40692
40719
  validatePath(filePath, "read");
40693
40720
  try {
40694
- const absolutePath = path39__default.resolve(filePath);
40721
+ const absolutePath = resolveUserPath(filePath);
40695
40722
  const stats = await fs35__default.stat(absolutePath);
40696
40723
  const maxBytes = maxSize ?? DEFAULT_MAX_FILE_SIZE;
40697
40724
  let truncated = false;
@@ -40750,7 +40777,7 @@ Examples:
40750
40777
  async execute({ path: filePath, content, createDirs, dryRun }) {
40751
40778
  validatePath(filePath, "write");
40752
40779
  try {
40753
- const absolutePath = path39__default.resolve(filePath);
40780
+ const absolutePath = resolveUserPath(filePath);
40754
40781
  let wouldCreate = false;
40755
40782
  try {
40756
40783
  await fs35__default.access(absolutePath);
@@ -40812,7 +40839,7 @@ Examples:
40812
40839
  async execute({ path: filePath, oldText, newText, all, dryRun }) {
40813
40840
  validatePath(filePath, "write");
40814
40841
  try {
40815
- const absolutePath = path39__default.resolve(filePath);
40842
+ const absolutePath = resolveUserPath(filePath);
40816
40843
  let content = await fs35__default.readFile(absolutePath, "utf-8");
40817
40844
  let replacements = 0;
40818
40845
  if (all) {
@@ -40933,7 +40960,7 @@ Examples:
40933
40960
  }),
40934
40961
  async execute({ path: filePath }) {
40935
40962
  try {
40936
- const absolutePath = path39__default.resolve(filePath);
40963
+ const absolutePath = resolveUserPath(filePath);
40937
40964
  const stats = await fs35__default.stat(absolutePath);
40938
40965
  return {
40939
40966
  exists: true,
@@ -40964,7 +40991,7 @@ Examples:
40964
40991
  }),
40965
40992
  async execute({ path: dirPath, recursive }) {
40966
40993
  try {
40967
- const absolutePath = path39__default.resolve(dirPath);
40994
+ const absolutePath = resolveUserPath(dirPath);
40968
40995
  const entries = [];
40969
40996
  async function listDir(dir, prefix = "") {
40970
40997
  const items = await fs35__default.readdir(dir, { withFileTypes: true });
@@ -41024,7 +41051,7 @@ Examples:
41024
41051
  }
41025
41052
  validatePath(filePath, "delete");
41026
41053
  try {
41027
- const absolutePath = path39__default.resolve(filePath);
41054
+ const absolutePath = resolveUserPath(filePath);
41028
41055
  const stats = await fs35__default.stat(absolutePath);
41029
41056
  if (stats.isDirectory()) {
41030
41057
  if (!recursive) {
@@ -41040,7 +41067,7 @@ Examples:
41040
41067
  } catch (error) {
41041
41068
  if (error instanceof ToolError) throw error;
41042
41069
  if (error.code === "ENOENT") {
41043
- return { deleted: false, path: path39__default.resolve(filePath) };
41070
+ return { deleted: false, path: resolveUserPath(filePath) };
41044
41071
  }
41045
41072
  throw new FileSystemError(`Failed to delete: ${filePath}`, {
41046
41073
  path: filePath,
@@ -41068,8 +41095,8 @@ Examples:
41068
41095
  validatePath(source, "read");
41069
41096
  validatePath(destination, "write");
41070
41097
  try {
41071
- const srcPath = path39__default.resolve(source);
41072
- const destPath = path39__default.resolve(destination);
41098
+ const srcPath = resolveUserPath(source);
41099
+ const destPath = resolveUserPath(destination);
41073
41100
  if (!overwrite) {
41074
41101
  try {
41075
41102
  await fs35__default.access(destPath);
@@ -41129,8 +41156,8 @@ Examples:
41129
41156
  validatePath(source, "delete");
41130
41157
  validatePath(destination, "write");
41131
41158
  try {
41132
- const srcPath = path39__default.resolve(source);
41133
- const destPath = path39__default.resolve(destination);
41159
+ const srcPath = resolveUserPath(source);
41160
+ const destPath = resolveUserPath(destination);
41134
41161
  if (!overwrite) {
41135
41162
  try {
41136
41163
  await fs35__default.access(destPath);
@@ -41216,7 +41243,7 @@ Examples:
41216
41243
  }),
41217
41244
  async execute({ path: dirPath, depth, showHidden, dirsOnly }) {
41218
41245
  try {
41219
- const absolutePath = path39__default.resolve(dirPath ?? ".");
41246
+ const absolutePath = resolveUserPath(dirPath ?? ".");
41220
41247
  let totalFiles = 0;
41221
41248
  let totalDirs = 0;
41222
41249
  const lines = [path39__default.basename(absolutePath) + "/"];
@@ -49682,6 +49709,43 @@ function getAllCommands() {
49682
49709
 
49683
49710
  // src/cli/repl/input/handler.ts
49684
49711
  var HISTORY_FILE = path39.join(os4.homedir(), ".coco", "history");
49712
+ function navigateHistory(direction, state) {
49713
+ const { currentLine, historyIndex, sessionHistory, tempLine } = state;
49714
+ if (direction === "up") {
49715
+ if (sessionHistory.length === 0) return null;
49716
+ let nextIndex = historyIndex;
49717
+ let nextTempLine = tempLine;
49718
+ if (nextIndex === -1) {
49719
+ nextTempLine = currentLine;
49720
+ nextIndex = sessionHistory.length - 1;
49721
+ } else if (nextIndex > 0) {
49722
+ nextIndex--;
49723
+ }
49724
+ return {
49725
+ currentLine: sessionHistory[nextIndex] ?? "",
49726
+ cursorPos: 0,
49727
+ historyIndex: nextIndex,
49728
+ tempLine: nextTempLine
49729
+ };
49730
+ }
49731
+ if (historyIndex === -1) return null;
49732
+ if (historyIndex < sessionHistory.length - 1) {
49733
+ const nextIndex = historyIndex + 1;
49734
+ const nextLine = sessionHistory[nextIndex] ?? "";
49735
+ return {
49736
+ currentLine: nextLine,
49737
+ cursorPos: nextLine.length,
49738
+ historyIndex: nextIndex,
49739
+ tempLine
49740
+ };
49741
+ }
49742
+ return {
49743
+ currentLine: tempLine,
49744
+ cursorPos: tempLine.length,
49745
+ historyIndex: -1,
49746
+ tempLine
49747
+ };
49748
+ }
49685
49749
  async function handleOptionC(copyFn = copyToClipboard, getLastBlockFn = getLastBlock) {
49686
49750
  const block = getLastBlockFn();
49687
49751
  if (!block) return null;
@@ -50255,14 +50319,18 @@ function createInputHandler(_session) {
50255
50319
  cursorPos = 0;
50256
50320
  render();
50257
50321
  } else if (sessionHistory.length > 0) {
50258
- if (historyIndex === -1) {
50259
- tempLine = currentLine;
50260
- historyIndex = sessionHistory.length - 1;
50261
- } else if (historyIndex > 0) {
50262
- historyIndex--;
50322
+ const nextState = navigateHistory("up", {
50323
+ currentLine,
50324
+ historyIndex,
50325
+ sessionHistory,
50326
+ tempLine
50327
+ });
50328
+ if (nextState) {
50329
+ currentLine = nextState.currentLine;
50330
+ cursorPos = nextState.cursorPos;
50331
+ historyIndex = nextState.historyIndex;
50332
+ tempLine = nextState.tempLine;
50263
50333
  }
50264
- currentLine = sessionHistory[historyIndex] ?? "";
50265
- cursorPos = currentLine.length;
50266
50334
  render();
50267
50335
  }
50268
50336
  return;
@@ -50284,14 +50352,18 @@ function createInputHandler(_session) {
50284
50352
  cursorPos = currentLine.length;
50285
50353
  render();
50286
50354
  } else if (historyIndex !== -1) {
50287
- if (historyIndex < sessionHistory.length - 1) {
50288
- historyIndex++;
50289
- currentLine = sessionHistory[historyIndex] ?? "";
50290
- } else {
50291
- historyIndex = -1;
50292
- currentLine = tempLine;
50355
+ const nextState = navigateHistory("down", {
50356
+ currentLine,
50357
+ historyIndex,
50358
+ sessionHistory,
50359
+ tempLine
50360
+ });
50361
+ if (nextState) {
50362
+ currentLine = nextState.currentLine;
50363
+ cursorPos = nextState.cursorPos;
50364
+ historyIndex = nextState.historyIndex;
50365
+ tempLine = nextState.tempLine;
50293
50366
  }
50294
- cursorPos = currentLine.length;
50295
50367
  render();
50296
50368
  }
50297
50369
  return;