@gemdoq/codi 0.1.5 → 0.1.8

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.js CHANGED
@@ -337,7 +337,7 @@ import * as readline from "readline/promises";
337
337
  import { stdin as input, stdout as output } from "process";
338
338
  var isWindows = os.platform() === "win32";
339
339
  var SETTINGS_DIR = path2.join(
340
- process.env["HOME"] || process.env["USERPROFILE"] || "~",
340
+ process.env["HOME"] || process.env["USERPROFILE"] || os.homedir(),
341
341
  ".codi"
342
342
  );
343
343
  var SETTINGS_PATH = path2.join(SETTINGS_DIR, "settings.json");
@@ -503,6 +503,7 @@ async function runSetupWizard() {
503
503
  // src/config/config.ts
504
504
  init_esm_shims();
505
505
  import * as fs2 from "fs";
506
+ import * as os2 from "os";
506
507
  import * as path3 from "path";
507
508
  var DEFAULT_CONFIG = {
508
509
  provider: "openai",
@@ -532,7 +533,7 @@ var ConfigManager = class {
532
533
  this.loadAll();
533
534
  }
534
535
  loadAll() {
535
- const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
536
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || os2.homedir();
536
537
  this.loadFile(path3.join(home, ".codi", "settings.json"));
537
538
  this.loadFile(path3.join(process.cwd(), ".codi", "settings.json"));
538
539
  this.loadFile(path3.join(process.cwd(), ".codi", "settings.local.json"));
@@ -609,7 +610,7 @@ var ConfigManager = class {
609
610
  return this.configPaths;
610
611
  }
611
612
  save(scope) {
612
- const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
613
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || os2.homedir();
613
614
  let filePath;
614
615
  switch (scope) {
615
616
  case "user":
@@ -635,7 +636,7 @@ var configManager = new ConfigManager();
635
636
  init_esm_shims();
636
637
  import * as readline2 from "readline/promises";
637
638
  import { stdin as input2, stdout as output2 } from "process";
638
- import * as os2 from "os";
639
+ import * as os3 from "os";
639
640
  import chalk4 from "chalk";
640
641
  import { execSync } from "child_process";
641
642
  import { edit } from "external-editor";
@@ -823,9 +824,30 @@ var Repl = class {
823
824
  completer: (line) => completer(line),
824
825
  terminal: true
825
826
  });
826
- if (process.stdin.isTTY && os2.platform() !== "win32") {
827
+ if (process.stdin.isTTY && os3.platform() !== "win32") {
827
828
  process.stdout.write("\x1B[?2004h");
828
829
  }
830
+ if (os3.platform() === "win32" && process.stdin.isTTY) {
831
+ process.stdin.on("keypress", (_str, key) => {
832
+ if (key && key.sequence === "") {
833
+ try {
834
+ const clip = execSync(
835
+ 'powershell -NoProfile -command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-Clipboard"',
836
+ { encoding: "utf-8", timeout: 5e3, env: { ...process.env } }
837
+ ).replace(/\r\n/g, "\n").replace(/\n$/, "");
838
+ if (clip && this.rl) {
839
+ const firstNewline = clip.indexOf("\n");
840
+ if (firstNewline === -1) {
841
+ this.rl.write(clip);
842
+ } else {
843
+ this.rl.write(clip.replace(/\n/g, "\\"));
844
+ }
845
+ }
846
+ } catch {
847
+ }
848
+ }
849
+ });
850
+ }
829
851
  this.printWelcome();
830
852
  while (this.running) {
831
853
  try {
@@ -890,7 +912,7 @@ var Repl = class {
890
912
  }
891
913
  }
892
914
  }
893
- if (process.stdin.isTTY && os2.platform() !== "win32") {
915
+ if (process.stdin.isTTY && os3.platform() !== "win32") {
894
916
  process.stdout.write("\x1B[?2004l");
895
917
  }
896
918
  }
@@ -913,8 +935,10 @@ var Repl = class {
913
935
  const cmd = input3.slice(1).trim();
914
936
  if (!cmd) return;
915
937
  try {
916
- const shell = os2.platform() === "win32" ? "powershell.exe" : void 0;
917
- const result = execSync(cmd, {
938
+ const isWin = os3.platform() === "win32";
939
+ const shell = isWin ? "powershell.exe" : void 0;
940
+ const finalCmd = isWin ? `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ${cmd}` : cmd;
941
+ const result = execSync(finalCmd, {
918
942
  encoding: "utf-8",
919
943
  stdio: ["inherit", "pipe", "pipe"],
920
944
  timeout: 3e4,
@@ -1487,7 +1511,7 @@ function sleep(ms) {
1487
1511
 
1488
1512
  // src/agent/system-prompt.ts
1489
1513
  init_esm_shims();
1490
- import * as os3 from "os";
1514
+ import * as os4 from "os";
1491
1515
  import { execSync as execSync2 } from "child_process";
1492
1516
  var ROLE_DEFINITION = `You are Codi (\uCF54\uB514), a terminal-based AI coding agent. You help users with software engineering tasks including writing code, debugging, refactoring, and explaining code. You have access to tools for file manipulation, code search, shell execution, and more.
1493
1517
 
@@ -1599,7 +1623,7 @@ function buildSystemPrompt(context) {
1599
1623
  fragments.push(buildEnvironmentInfo(context));
1600
1624
  fragments.push(CONVERSATION_RULES);
1601
1625
  fragments.push(TOOL_HIERARCHY);
1602
- if (os3.platform() === "win32") {
1626
+ if (os4.platform() === "win32") {
1603
1627
  fragments.push(WINDOWS_RULES);
1604
1628
  }
1605
1629
  fragments.push(CODE_RULES);
@@ -1630,8 +1654,8 @@ function buildEnvironmentInfo(context) {
1630
1654
  const lines = [
1631
1655
  "# Environment",
1632
1656
  `- Date: ${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}`,
1633
- `- OS: ${os3.platform()} ${os3.release()}`,
1634
- `- Shell: ${process.env["SHELL"] || process.env["COMSPEC"] || "unknown"}`,
1657
+ `- OS: ${os4.platform()} ${os4.release()}`,
1658
+ `- Shell: ${os4.platform() === "win32" ? "PowerShell" : process.env["SHELL"] || "/bin/bash"}`,
1635
1659
  `- Working Directory: ${context.cwd}`,
1636
1660
  `- Model: ${context.model}`,
1637
1661
  `- Provider: ${context.provider}`
@@ -1702,12 +1726,13 @@ ${summaryContent}`;
1702
1726
  // src/agent/memory.ts
1703
1727
  init_esm_shims();
1704
1728
  import * as fs4 from "fs";
1729
+ import * as os5 from "os";
1705
1730
  import * as path6 from "path";
1706
1731
  import * as crypto from "crypto";
1707
1732
  var MemoryManager = class {
1708
1733
  memoryDir;
1709
1734
  constructor() {
1710
- const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
1735
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || os5.homedir();
1711
1736
  const projectHash = crypto.createHash("md5").update(process.cwd()).digest("hex").slice(0, 8);
1712
1737
  const projectName = path6.basename(process.cwd());
1713
1738
  this.memoryDir = path6.join(home, ".codi", "projects", `${projectName}-${projectHash}`, "memory");
@@ -1764,12 +1789,13 @@ var memoryManager = new MemoryManager();
1764
1789
  // src/agent/session.ts
1765
1790
  init_esm_shims();
1766
1791
  import * as fs5 from "fs";
1792
+ import * as os6 from "os";
1767
1793
  import * as path7 from "path";
1768
1794
  import * as crypto2 from "crypto";
1769
1795
  var SessionManager = class {
1770
1796
  sessionsDir;
1771
1797
  constructor() {
1772
- const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
1798
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || os6.homedir();
1773
1799
  this.sessionsDir = path7.join(home, ".codi", "sessions");
1774
1800
  }
1775
1801
  ensureDir() {
@@ -2192,9 +2218,9 @@ async function promptUser(tool, input3) {
2192
2218
  // src/hooks/hook-manager.ts
2193
2219
  init_esm_shims();
2194
2220
  import { exec } from "child_process";
2195
- import * as os4 from "os";
2221
+ import * as os7 from "os";
2196
2222
  function getDefaultShell() {
2197
- if (os4.platform() === "win32") {
2223
+ if (os7.platform() === "win32") {
2198
2224
  return "powershell.exe";
2199
2225
  }
2200
2226
  return void 0;
@@ -2231,7 +2257,9 @@ var HookManager = class {
2231
2257
  session_id: context["sessionId"],
2232
2258
  cwd: context["cwd"] || process.cwd()
2233
2259
  });
2234
- const proc = exec(command, {
2260
+ const isWin = os7.platform() === "win32";
2261
+ const finalCommand = isWin ? `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ${command}` : command;
2262
+ const proc = exec(finalCommand, {
2235
2263
  timeout: timeout || 5e3,
2236
2264
  cwd: process.cwd(),
2237
2265
  env: { ...process.env },
@@ -2272,6 +2300,7 @@ var hookManager = new HookManager();
2272
2300
  init_esm_shims();
2273
2301
  init_tool();
2274
2302
  import * as fs7 from "fs";
2303
+ import * as os8 from "os";
2275
2304
  import * as path9 from "path";
2276
2305
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2277
2306
  import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
@@ -2292,7 +2321,7 @@ var McpManager = class {
2292
2321
  }
2293
2322
  loadMcpConfigs() {
2294
2323
  const configs = {};
2295
- const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
2324
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || os8.homedir();
2296
2325
  const paths = [
2297
2326
  path9.join(home, ".codi", "mcp.json"),
2298
2327
  path9.join(process.cwd(), ".codi", "mcp.json")
@@ -2496,7 +2525,7 @@ var subAgentTool = {
2496
2525
  // src/config/slash-commands.ts
2497
2526
  init_esm_shims();
2498
2527
  import * as fs8 from "fs";
2499
- import * as os5 from "os";
2528
+ import * as os9 from "os";
2500
2529
  import * as path10 from "path";
2501
2530
  import chalk11 from "chalk";
2502
2531
  function createBuiltinCommands() {
@@ -2907,7 +2936,7 @@ ${diff}
2907
2936
  console.log(chalk11.yellow("Usage: /search <keyword>"));
2908
2937
  return true;
2909
2938
  }
2910
- const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
2939
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || os9.homedir();
2911
2940
  const sessionsDir = path10.join(home, ".codi", "sessions");
2912
2941
  if (!fs8.existsSync(sessionsDir)) {
2913
2942
  console.log(chalk11.dim("\nNo sessions found.\n"));
@@ -2959,8 +2988,10 @@ Search results for "${args}":
2959
2988
  }
2960
2989
  const { execSync: execSync5 } = await import("child_process");
2961
2990
  try {
2962
- const shell = os5.platform() === "win32" ? "powershell.exe" : void 0;
2963
- const output3 = execSync5(args, { encoding: "utf-8", cwd: process.cwd(), stdio: "pipe", shell });
2991
+ const isWin = os9.platform() === "win32";
2992
+ const shell = isWin ? "powershell.exe" : void 0;
2993
+ const fixCmd = isWin ? `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ${args}` : args;
2994
+ const output3 = execSync5(fixCmd, { encoding: "utf-8", cwd: process.cwd(), stdio: "pipe", shell });
2964
2995
  console.log(chalk11.green(`
2965
2996
  \u2713 Command succeeded. No errors to fix.
2966
2997
  `));
@@ -3010,7 +3041,7 @@ ${errorOutput}
3010
3041
  }
3011
3042
  function loadCustomCommands() {
3012
3043
  const commands = [];
3013
- const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
3044
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || os9.homedir();
3014
3045
  const dirs = [
3015
3046
  path10.join(home, ".codi", "commands"),
3016
3047
  path10.join(process.cwd(), ".codi", "commands")
@@ -3573,6 +3604,7 @@ async function builtinSearch(pattern, searchPath, input3, outputMode, headLimit)
3573
3604
  } catch {
3574
3605
  continue;
3575
3606
  }
3607
+ content = content.replace(/\r\n/g, "\n");
3576
3608
  const lines = content.split("\n");
3577
3609
  const matchedLineIndices = /* @__PURE__ */ new Set();
3578
3610
  let fileMatchCount = 0;
@@ -3667,9 +3699,9 @@ function collectFiles(dirPath, typeFilter, globFilter) {
3667
3699
  init_esm_shims();
3668
3700
  init_tool();
3669
3701
  import { exec as exec2, spawn } from "child_process";
3670
- import * as os6 from "os";
3702
+ import * as os10 from "os";
3671
3703
  function getDefaultShell2() {
3672
- if (os6.platform() === "win32") {
3704
+ if (os10.platform() === "win32") {
3673
3705
  return "powershell.exe";
3674
3706
  }
3675
3707
  return process.env["SHELL"] || "/bin/bash";
@@ -3678,7 +3710,7 @@ var backgroundTasks = /* @__PURE__ */ new Map();
3678
3710
  var taskCounter = 0;
3679
3711
  var bashTool = {
3680
3712
  name: "bash",
3681
- description: `Execute a shell command. Supports timeout (max 600s, default 120s) and background execution. The working directory persists between calls. Uses the platform default shell (bash on Unix, cmd.exe on Windows).`,
3713
+ description: `Execute a shell command. Supports timeout (max 600s, default 120s) and background execution. The working directory persists between calls. Uses the platform default shell (bash on Unix, PowerShell on Windows).`,
3682
3714
  inputSchema: {
3683
3715
  type: "object",
3684
3716
  properties: {
@@ -3702,7 +3734,8 @@ var bashTool = {
3702
3734
  return runBackgroundTask(command);
3703
3735
  }
3704
3736
  return new Promise((resolve10) => {
3705
- exec2(command, {
3737
+ const finalCommand = os10.platform() === "win32" ? `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ${command}` : command;
3738
+ exec2(finalCommand, {
3706
3739
  timeout,
3707
3740
  maxBuffer: 10 * 1024 * 1024,
3708
3741
  shell: getDefaultShell2(),
@@ -3738,7 +3771,8 @@ ${stderr}` : ""
3738
3771
  };
3739
3772
  function runBackgroundTask(command) {
3740
3773
  const taskId = `bg_${++taskCounter}`;
3741
- const proc = spawn(command, {
3774
+ const bgCommand = os10.platform() === "win32" ? `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ${command}` : command;
3775
+ const proc = spawn(bgCommand, {
3742
3776
  shell: getDefaultShell2(),
3743
3777
  cwd: process.cwd(),
3744
3778
  env: { ...process.env },
@@ -4816,7 +4850,16 @@ async function main() {
4816
4850
  process.exit(0);
4817
4851
  }
4818
4852
  if (args.version) {
4819
- console.log("codi v0.1.0");
4853
+ try {
4854
+ const { readFileSync: readFileSync14 } = await import("fs");
4855
+ const { fileURLToPath: fileURLToPath3 } = await import("url");
4856
+ const p = await import("path");
4857
+ const dir = p.dirname(fileURLToPath3(import.meta.url));
4858
+ const pkg = JSON.parse(readFileSync14(p.join(dir, "..", "package.json"), "utf-8"));
4859
+ console.log(`codi v${pkg.version}`);
4860
+ } catch {
4861
+ console.log("codi v0.1.8");
4862
+ }
4820
4863
  process.exit(0);
4821
4864
  }
4822
4865
  if (await needsSetup()) {