@gemdoq/codi 0.1.6 → 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 +62 -35
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
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
|
|
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,19 +824,24 @@ var Repl = class {
|
|
|
823
824
|
completer: (line) => completer(line),
|
|
824
825
|
terminal: true
|
|
825
826
|
});
|
|
826
|
-
if (process.stdin.isTTY &&
|
|
827
|
+
if (process.stdin.isTTY && os3.platform() !== "win32") {
|
|
827
828
|
process.stdout.write("\x1B[?2004h");
|
|
828
829
|
}
|
|
829
|
-
if (
|
|
830
|
+
if (os3.platform() === "win32" && process.stdin.isTTY) {
|
|
830
831
|
process.stdin.on("keypress", (_str, key) => {
|
|
831
832
|
if (key && key.sequence === "") {
|
|
832
833
|
try {
|
|
833
|
-
const clip = execSync(
|
|
834
|
-
|
|
835
|
-
timeout:
|
|
836
|
-
|
|
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$/, "");
|
|
837
838
|
if (clip && this.rl) {
|
|
838
|
-
|
|
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
|
+
}
|
|
839
845
|
}
|
|
840
846
|
} catch {
|
|
841
847
|
}
|
|
@@ -906,7 +912,7 @@ var Repl = class {
|
|
|
906
912
|
}
|
|
907
913
|
}
|
|
908
914
|
}
|
|
909
|
-
if (process.stdin.isTTY &&
|
|
915
|
+
if (process.stdin.isTTY && os3.platform() !== "win32") {
|
|
910
916
|
process.stdout.write("\x1B[?2004l");
|
|
911
917
|
}
|
|
912
918
|
}
|
|
@@ -929,8 +935,10 @@ var Repl = class {
|
|
|
929
935
|
const cmd = input3.slice(1).trim();
|
|
930
936
|
if (!cmd) return;
|
|
931
937
|
try {
|
|
932
|
-
const
|
|
933
|
-
const
|
|
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, {
|
|
934
942
|
encoding: "utf-8",
|
|
935
943
|
stdio: ["inherit", "pipe", "pipe"],
|
|
936
944
|
timeout: 3e4,
|
|
@@ -1503,7 +1511,7 @@ function sleep(ms) {
|
|
|
1503
1511
|
|
|
1504
1512
|
// src/agent/system-prompt.ts
|
|
1505
1513
|
init_esm_shims();
|
|
1506
|
-
import * as
|
|
1514
|
+
import * as os4 from "os";
|
|
1507
1515
|
import { execSync as execSync2 } from "child_process";
|
|
1508
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.
|
|
1509
1517
|
|
|
@@ -1615,7 +1623,7 @@ function buildSystemPrompt(context) {
|
|
|
1615
1623
|
fragments.push(buildEnvironmentInfo(context));
|
|
1616
1624
|
fragments.push(CONVERSATION_RULES);
|
|
1617
1625
|
fragments.push(TOOL_HIERARCHY);
|
|
1618
|
-
if (
|
|
1626
|
+
if (os4.platform() === "win32") {
|
|
1619
1627
|
fragments.push(WINDOWS_RULES);
|
|
1620
1628
|
}
|
|
1621
1629
|
fragments.push(CODE_RULES);
|
|
@@ -1646,8 +1654,8 @@ function buildEnvironmentInfo(context) {
|
|
|
1646
1654
|
const lines = [
|
|
1647
1655
|
"# Environment",
|
|
1648
1656
|
`- Date: ${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}`,
|
|
1649
|
-
`- OS: ${
|
|
1650
|
-
`- Shell: ${
|
|
1657
|
+
`- OS: ${os4.platform()} ${os4.release()}`,
|
|
1658
|
+
`- Shell: ${os4.platform() === "win32" ? "PowerShell" : process.env["SHELL"] || "/bin/bash"}`,
|
|
1651
1659
|
`- Working Directory: ${context.cwd}`,
|
|
1652
1660
|
`- Model: ${context.model}`,
|
|
1653
1661
|
`- Provider: ${context.provider}`
|
|
@@ -1718,12 +1726,13 @@ ${summaryContent}`;
|
|
|
1718
1726
|
// src/agent/memory.ts
|
|
1719
1727
|
init_esm_shims();
|
|
1720
1728
|
import * as fs4 from "fs";
|
|
1729
|
+
import * as os5 from "os";
|
|
1721
1730
|
import * as path6 from "path";
|
|
1722
1731
|
import * as crypto from "crypto";
|
|
1723
1732
|
var MemoryManager = class {
|
|
1724
1733
|
memoryDir;
|
|
1725
1734
|
constructor() {
|
|
1726
|
-
const home = process.env["HOME"] || process.env["USERPROFILE"] ||
|
|
1735
|
+
const home = process.env["HOME"] || process.env["USERPROFILE"] || os5.homedir();
|
|
1727
1736
|
const projectHash = crypto.createHash("md5").update(process.cwd()).digest("hex").slice(0, 8);
|
|
1728
1737
|
const projectName = path6.basename(process.cwd());
|
|
1729
1738
|
this.memoryDir = path6.join(home, ".codi", "projects", `${projectName}-${projectHash}`, "memory");
|
|
@@ -1780,12 +1789,13 @@ var memoryManager = new MemoryManager();
|
|
|
1780
1789
|
// src/agent/session.ts
|
|
1781
1790
|
init_esm_shims();
|
|
1782
1791
|
import * as fs5 from "fs";
|
|
1792
|
+
import * as os6 from "os";
|
|
1783
1793
|
import * as path7 from "path";
|
|
1784
1794
|
import * as crypto2 from "crypto";
|
|
1785
1795
|
var SessionManager = class {
|
|
1786
1796
|
sessionsDir;
|
|
1787
1797
|
constructor() {
|
|
1788
|
-
const home = process.env["HOME"] || process.env["USERPROFILE"] ||
|
|
1798
|
+
const home = process.env["HOME"] || process.env["USERPROFILE"] || os6.homedir();
|
|
1789
1799
|
this.sessionsDir = path7.join(home, ".codi", "sessions");
|
|
1790
1800
|
}
|
|
1791
1801
|
ensureDir() {
|
|
@@ -2208,9 +2218,9 @@ async function promptUser(tool, input3) {
|
|
|
2208
2218
|
// src/hooks/hook-manager.ts
|
|
2209
2219
|
init_esm_shims();
|
|
2210
2220
|
import { exec } from "child_process";
|
|
2211
|
-
import * as
|
|
2221
|
+
import * as os7 from "os";
|
|
2212
2222
|
function getDefaultShell() {
|
|
2213
|
-
if (
|
|
2223
|
+
if (os7.platform() === "win32") {
|
|
2214
2224
|
return "powershell.exe";
|
|
2215
2225
|
}
|
|
2216
2226
|
return void 0;
|
|
@@ -2247,7 +2257,9 @@ var HookManager = class {
|
|
|
2247
2257
|
session_id: context["sessionId"],
|
|
2248
2258
|
cwd: context["cwd"] || process.cwd()
|
|
2249
2259
|
});
|
|
2250
|
-
const
|
|
2260
|
+
const isWin = os7.platform() === "win32";
|
|
2261
|
+
const finalCommand = isWin ? `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ${command}` : command;
|
|
2262
|
+
const proc = exec(finalCommand, {
|
|
2251
2263
|
timeout: timeout || 5e3,
|
|
2252
2264
|
cwd: process.cwd(),
|
|
2253
2265
|
env: { ...process.env },
|
|
@@ -2288,6 +2300,7 @@ var hookManager = new HookManager();
|
|
|
2288
2300
|
init_esm_shims();
|
|
2289
2301
|
init_tool();
|
|
2290
2302
|
import * as fs7 from "fs";
|
|
2303
|
+
import * as os8 from "os";
|
|
2291
2304
|
import * as path9 from "path";
|
|
2292
2305
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2293
2306
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
@@ -2308,7 +2321,7 @@ var McpManager = class {
|
|
|
2308
2321
|
}
|
|
2309
2322
|
loadMcpConfigs() {
|
|
2310
2323
|
const configs = {};
|
|
2311
|
-
const home = process.env["HOME"] || process.env["USERPROFILE"] ||
|
|
2324
|
+
const home = process.env["HOME"] || process.env["USERPROFILE"] || os8.homedir();
|
|
2312
2325
|
const paths = [
|
|
2313
2326
|
path9.join(home, ".codi", "mcp.json"),
|
|
2314
2327
|
path9.join(process.cwd(), ".codi", "mcp.json")
|
|
@@ -2512,7 +2525,7 @@ var subAgentTool = {
|
|
|
2512
2525
|
// src/config/slash-commands.ts
|
|
2513
2526
|
init_esm_shims();
|
|
2514
2527
|
import * as fs8 from "fs";
|
|
2515
|
-
import * as
|
|
2528
|
+
import * as os9 from "os";
|
|
2516
2529
|
import * as path10 from "path";
|
|
2517
2530
|
import chalk11 from "chalk";
|
|
2518
2531
|
function createBuiltinCommands() {
|
|
@@ -2923,7 +2936,7 @@ ${diff}
|
|
|
2923
2936
|
console.log(chalk11.yellow("Usage: /search <keyword>"));
|
|
2924
2937
|
return true;
|
|
2925
2938
|
}
|
|
2926
|
-
const home = process.env["HOME"] || process.env["USERPROFILE"] ||
|
|
2939
|
+
const home = process.env["HOME"] || process.env["USERPROFILE"] || os9.homedir();
|
|
2927
2940
|
const sessionsDir = path10.join(home, ".codi", "sessions");
|
|
2928
2941
|
if (!fs8.existsSync(sessionsDir)) {
|
|
2929
2942
|
console.log(chalk11.dim("\nNo sessions found.\n"));
|
|
@@ -2975,8 +2988,10 @@ Search results for "${args}":
|
|
|
2975
2988
|
}
|
|
2976
2989
|
const { execSync: execSync5 } = await import("child_process");
|
|
2977
2990
|
try {
|
|
2978
|
-
const
|
|
2979
|
-
const
|
|
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 });
|
|
2980
2995
|
console.log(chalk11.green(`
|
|
2981
2996
|
\u2713 Command succeeded. No errors to fix.
|
|
2982
2997
|
`));
|
|
@@ -3026,7 +3041,7 @@ ${errorOutput}
|
|
|
3026
3041
|
}
|
|
3027
3042
|
function loadCustomCommands() {
|
|
3028
3043
|
const commands = [];
|
|
3029
|
-
const home = process.env["HOME"] || process.env["USERPROFILE"] ||
|
|
3044
|
+
const home = process.env["HOME"] || process.env["USERPROFILE"] || os9.homedir();
|
|
3030
3045
|
const dirs = [
|
|
3031
3046
|
path10.join(home, ".codi", "commands"),
|
|
3032
3047
|
path10.join(process.cwd(), ".codi", "commands")
|
|
@@ -3589,6 +3604,7 @@ async function builtinSearch(pattern, searchPath, input3, outputMode, headLimit)
|
|
|
3589
3604
|
} catch {
|
|
3590
3605
|
continue;
|
|
3591
3606
|
}
|
|
3607
|
+
content = content.replace(/\r\n/g, "\n");
|
|
3592
3608
|
const lines = content.split("\n");
|
|
3593
3609
|
const matchedLineIndices = /* @__PURE__ */ new Set();
|
|
3594
3610
|
let fileMatchCount = 0;
|
|
@@ -3683,9 +3699,9 @@ function collectFiles(dirPath, typeFilter, globFilter) {
|
|
|
3683
3699
|
init_esm_shims();
|
|
3684
3700
|
init_tool();
|
|
3685
3701
|
import { exec as exec2, spawn } from "child_process";
|
|
3686
|
-
import * as
|
|
3702
|
+
import * as os10 from "os";
|
|
3687
3703
|
function getDefaultShell2() {
|
|
3688
|
-
if (
|
|
3704
|
+
if (os10.platform() === "win32") {
|
|
3689
3705
|
return "powershell.exe";
|
|
3690
3706
|
}
|
|
3691
3707
|
return process.env["SHELL"] || "/bin/bash";
|
|
@@ -3694,7 +3710,7 @@ var backgroundTasks = /* @__PURE__ */ new Map();
|
|
|
3694
3710
|
var taskCounter = 0;
|
|
3695
3711
|
var bashTool = {
|
|
3696
3712
|
name: "bash",
|
|
3697
|
-
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,
|
|
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).`,
|
|
3698
3714
|
inputSchema: {
|
|
3699
3715
|
type: "object",
|
|
3700
3716
|
properties: {
|
|
@@ -3718,7 +3734,8 @@ var bashTool = {
|
|
|
3718
3734
|
return runBackgroundTask(command);
|
|
3719
3735
|
}
|
|
3720
3736
|
return new Promise((resolve10) => {
|
|
3721
|
-
|
|
3737
|
+
const finalCommand = os10.platform() === "win32" ? `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ${command}` : command;
|
|
3738
|
+
exec2(finalCommand, {
|
|
3722
3739
|
timeout,
|
|
3723
3740
|
maxBuffer: 10 * 1024 * 1024,
|
|
3724
3741
|
shell: getDefaultShell2(),
|
|
@@ -3754,7 +3771,8 @@ ${stderr}` : ""
|
|
|
3754
3771
|
};
|
|
3755
3772
|
function runBackgroundTask(command) {
|
|
3756
3773
|
const taskId = `bg_${++taskCounter}`;
|
|
3757
|
-
const
|
|
3774
|
+
const bgCommand = os10.platform() === "win32" ? `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ${command}` : command;
|
|
3775
|
+
const proc = spawn(bgCommand, {
|
|
3758
3776
|
shell: getDefaultShell2(),
|
|
3759
3777
|
cwd: process.cwd(),
|
|
3760
3778
|
env: { ...process.env },
|
|
@@ -4832,7 +4850,16 @@ async function main() {
|
|
|
4832
4850
|
process.exit(0);
|
|
4833
4851
|
}
|
|
4834
4852
|
if (args.version) {
|
|
4835
|
-
|
|
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
|
+
}
|
|
4836
4863
|
process.exit(0);
|
|
4837
4864
|
}
|
|
4838
4865
|
if (await needsSetup()) {
|