ys-code-agent 2.0.2 → 3.0.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.
@@ -14023,16 +14023,13 @@ var init_CommandPopup = __esm({
14023
14023
  }
14024
14024
  getCategorizedCommands() {
14025
14025
  const cats = [];
14026
- const seen = /* @__PURE__ */ new Set();
14027
- for (const cmd of this.filteredCommands) {
14028
- if (seen.has(cmd.command)) continue;
14029
- seen.add(cmd.command);
14030
- }
14026
+ const added = /* @__PURE__ */ new Set();
14031
14027
  const order = ["system", "files", "git", "agents", "code", "memory", "settings"];
14032
14028
  for (const cat of order) {
14033
- const cmds = this.filteredCommands.filter((c) => c.category === cat && !seen.has(c.command));
14029
+ const cmds = this.filteredCommands.filter((c) => c.category === cat && !added.has(c.command));
14034
14030
  if (cmds.length > 0) {
14035
14031
  cats.push({ category: cat, commands: cmds });
14032
+ cmds.forEach((c) => added.add(c.command));
14036
14033
  }
14037
14034
  }
14038
14035
  return cats;
@@ -14072,13 +14069,62 @@ init_config();
14072
14069
  init_logger();
14073
14070
 
14074
14071
  // src/providers/base.ts
14075
- var BaseProvider = class {
14072
+ var BaseProvider = class _BaseProvider {
14076
14073
  config;
14077
14074
  modelConfig;
14078
14075
  constructor(config, modelConfig) {
14079
14076
  this.config = config;
14080
14077
  this.modelConfig = modelConfig;
14081
14078
  }
14079
+ static convertToOpenAITools(tools) {
14080
+ return tools.map((schema) => {
14081
+ const properties = {};
14082
+ for (const [key, param] of Object.entries(schema.parameters)) {
14083
+ const prop = {
14084
+ type: param.type,
14085
+ description: param.description
14086
+ };
14087
+ if (param.enum) prop.enum = param.enum;
14088
+ if (param.minimum !== void 0) prop.minimum = param.minimum;
14089
+ if (param.maximum !== void 0) prop.maximum = param.maximum;
14090
+ properties[key] = prop;
14091
+ }
14092
+ return {
14093
+ type: "function",
14094
+ function: {
14095
+ name: schema.name,
14096
+ description: schema.description,
14097
+ parameters: {
14098
+ type: "object",
14099
+ properties,
14100
+ required: schema.required
14101
+ }
14102
+ }
14103
+ };
14104
+ });
14105
+ }
14106
+ static convertToAnthropicTools(tools) {
14107
+ return tools.map((schema) => {
14108
+ const properties = {};
14109
+ for (const [key, param] of Object.entries(schema.parameters)) {
14110
+ const prop = {
14111
+ type: param.type,
14112
+ description: param.description
14113
+ };
14114
+ if (param.enum) prop.enum = param.enum;
14115
+ properties[key] = prop;
14116
+ }
14117
+ return {
14118
+ name: schema.name,
14119
+ description: schema.description,
14120
+ input_schema: {
14121
+ type: "object",
14122
+ properties,
14123
+ required: schema.required
14124
+ }
14125
+ };
14126
+ });
14127
+ }
14082
14128
  getApiKey() {
14083
14129
  return this.config.apiKey || process.env[`${this.config.type.toUpperCase()}_API_KEY`] || "";
14084
14130
  }
@@ -14106,7 +14152,7 @@ var BaseProvider = class {
14106
14152
  body.stop = this.modelConfig.stop;
14107
14153
  }
14108
14154
  if (tools && tools.length > 0) {
14109
- body.tools = tools;
14155
+ body.tools = _BaseProvider.convertToOpenAITools(tools);
14110
14156
  body.tool_choice = "auto";
14111
14157
  }
14112
14158
  return body;
@@ -14315,28 +14361,6 @@ var AnthropicProvider = class extends BaseProvider {
14315
14361
  "anthropic-version": "2023-06-01"
14316
14362
  };
14317
14363
  }
14318
- buildRequestBody(messages, tools) {
14319
- const systemMessages = messages.filter((m) => m.role === "system");
14320
- const chatMessages = messages.filter((m) => m.role !== "system");
14321
- const body = {
14322
- model: this.modelConfig.model,
14323
- messages: chatMessages.map((m) => ({
14324
- role: m.role === "assistant" ? "assistant" : "user",
14325
- content: m.content
14326
- })),
14327
- max_tokens: this.modelConfig.maxTokens,
14328
- temperature: this.modelConfig.temperature,
14329
- top_p: this.modelConfig.topP,
14330
- stream: false
14331
- };
14332
- if (systemMessages.length > 0) {
14333
- body.system = systemMessages.map((m) => ({ type: "text", text: m.content }));
14334
- }
14335
- if (tools && tools.length > 0) {
14336
- body.tools = tools;
14337
- }
14338
- return body;
14339
- }
14340
14364
  convertMessages(messages) {
14341
14365
  const systemMessages = [];
14342
14366
  const chatMessages = [];
@@ -14367,7 +14391,7 @@ var AnthropicProvider = class extends BaseProvider {
14367
14391
  body.system = systemMessages;
14368
14392
  }
14369
14393
  if (tools && tools.length > 0) {
14370
- body.tools = tools;
14394
+ body.tools = BaseProvider.convertToAnthropicTools(tools);
14371
14395
  }
14372
14396
  const response = await this.fetchWithRetry(url, {
14373
14397
  method: "POST",
@@ -14417,7 +14441,7 @@ var AnthropicProvider = class extends BaseProvider {
14417
14441
  body.system = systemMessages;
14418
14442
  }
14419
14443
  if (tools && tools.length > 0) {
14420
- body.tools = tools;
14444
+ body.tools = BaseProvider.convertToAnthropicTools(tools);
14421
14445
  }
14422
14446
  const response = await this.fetchWithRetry(url, {
14423
14447
  method: "POST",
@@ -15126,27 +15150,35 @@ init_session();
15126
15150
  init_project();
15127
15151
  init_utils();
15128
15152
  var logger13 = getLogger("agent");
15129
- var SYSTEM_PROMPT = `You are YS Code Agent, an advanced AI coding assistant that helps users write, debug, and understand code.
15153
+ var SYSTEM_PROMPT = `You are YS Code Agent \u2014 a production-grade terminal AI coding assistant.
15154
+ You have DIRECT access to the filesystem and terminal through tool calls.
15130
15155
 
15131
- You have access to a set of tools that let you read, write, and edit files, search code, execute commands, and more.
15156
+ ## CRITICAL RULE \u2014 USE TOOLS, DON'T JUST TALK
15157
+ When the user asks you to make, create, write, or build something \u2014 USE the write_file tool to actually create the file on disk.
15158
+ When the user asks to read, show, or check something \u2014 USE the read_file tool.
15159
+ When the user asks to run, execute, or test something \u2014 USE the run_command tool.
15160
+ When the user asks to search or find something \u2014 USE the search_files tool.
15161
+ NEVER just show code in chat without writing it to disk when the user asks to create something.
15132
15162
 
15133
- When working on tasks:
15134
- 1. First understand the request thoroughly
15135
- 2. Make a plan before executing
15136
- 3. Read relevant files to understand existing code
15137
- 4. Write or edit code as needed
15138
- 5. Run tests or commands to verify
15139
- 6. Fix any issues that arise
15140
- 7. Report results clearly
15163
+ ## Available Tools
15164
+ - write_file: Write content to a file (creates/overwrites)
15165
+ - read_file: Read file contents from disk
15166
+ - edit_file: Edit specific parts of a file
15167
+ - delete_file: Delete a file
15168
+ - run_command: Execute a shell command
15169
+ - search_files: Search for text in files
15170
+ - glob: Find files matching a pattern
15171
+ - list_directory: List directory contents
15172
+ - git: Execute git commands
15173
+ - web_fetch: Fetch content from a URL
15174
+ - memory: Read/write project memory
15141
15175
 
15142
- Always follow these rules:
15143
- - Write clean, maintainable code following existing patterns
15144
- - Make minimal changes to achieve the goal
15145
- - Verify changes work correctly
15146
- - Be concise in explanations
15147
- - Use the tools available to you effectively
15148
- - Ask for clarification when needed
15149
- - Never execute dangerous commands without confirmation`;
15176
+ ## Response Format
15177
+ - Use clear section headers for complex responses
15178
+ - Show file paths when referencing code
15179
+ - Keep responses concise but complete
15180
+ - After writing files, confirm with a summary of what was created
15181
+ - Use markdown formatting in your responses`;
15150
15182
  var Agent = class {
15151
15183
  state;
15152
15184
  provider = null;
@@ -15799,6 +15831,26 @@ function getSessionId() {
15799
15831
  }
15800
15832
  }
15801
15833
 
15834
+ // src/utils/renderMarkdown.ts
15835
+ init_source();
15836
+ function renderMarkdown(text) {
15837
+ let result = text;
15838
+ result = result.replace(/^### (.+)$/gm, (_, m) => source_default.cyan.bold(m));
15839
+ result = result.replace(/^## (.+)$/gm, (_, m) => source_default.yellow.bold(m));
15840
+ result = result.replace(/^# (.+)$/gm, (_, m) => source_default.white.bold.underline(m));
15841
+ result = result.replace(/\*\*(.+?)\*\*/g, (_, m) => source_default.bold(m));
15842
+ result = result.replace(/\*(.+?)\*/g, (_, m) => source_default.italic(m));
15843
+ result = result.replace(/`([^`]+)`/g, (_, m) => source_default.bgGray.white(` ${m} `));
15844
+ result = result.replace(
15845
+ /```[\w]*\n([\s\S]+?)```/g,
15846
+ (_, code) => code.split("\n").map((l) => source_default.gray("\u2502 ") + source_default.green(l)).join("\n")
15847
+ );
15848
+ result = result.replace(/^[-*] (.+)$/gm, (_, m) => source_default.cyan(" \u25C6 ") + m);
15849
+ result = result.replace(/^(\d+)\. (.+)$/gm, (_, n, m) => source_default.yellow(` ${n}. `) + m);
15850
+ result = result.replace(/^---+$/gm, source_default.gray("\u2500".repeat(60)));
15851
+ return result;
15852
+ }
15853
+
15802
15854
  // src/ui/index.ts
15803
15855
  var import_readline = require("readline");
15804
15856
  var logger15 = getLogger("ui");
@@ -15832,7 +15884,10 @@ var TUI = class {
15832
15884
  historyIndex = -1;
15833
15885
  popupActive = false;
15834
15886
  cancelRequested = false;
15835
- rl = null;
15887
+ inputBuffer = "";
15888
+ cursorPos = 0;
15889
+ popupLineCount = 0;
15890
+ prevInput = null;
15836
15891
  constructor() {
15837
15892
  this.commandPopup = new CommandPopup();
15838
15893
  this.loadHistory();
@@ -15870,55 +15925,301 @@ var TUI = class {
15870
15925
  }
15871
15926
  this.startTTYMode();
15872
15927
  }
15873
- startTTYMode() {
15874
- const self = this;
15875
- this.rl = (0, import_readline.createInterface)({
15876
- input: process.stdin,
15877
- output: process.stdout,
15878
- prompt: "",
15879
- historySize: 0,
15880
- removeHistoryDuplicates: true
15881
- });
15882
- this.rl.on("line", async (line) => {
15928
+ startLineMode() {
15929
+ const { createInterface } = require("readline");
15930
+ const rl = createInterface({ input: process.stdin, output: process.stdout, prompt: "" });
15931
+ rl.on("line", (line) => {
15883
15932
  const trimmed = line.trim();
15884
- if (trimmed) {
15933
+ if (trimmed && this.onInput) {
15885
15934
  this.addHistory(trimmed);
15935
+ this.onInput(trimmed);
15936
+ }
15937
+ rl.prompt();
15938
+ });
15939
+ rl.on("SIGINT", () => process.exit(0));
15940
+ rl.prompt();
15941
+ }
15942
+ startTTYMode() {
15943
+ try {
15944
+ process.stdin.setRawMode?.(true);
15945
+ } catch {
15946
+ }
15947
+ (0, import_readline.emitKeypressEvents)(process.stdin);
15948
+ this.inputBuffer = "";
15949
+ this.cursorPos = 0;
15950
+ this.popupLineCount = 0;
15951
+ process.stdin.on("keypress", this.handleKeypress.bind(this));
15952
+ this.renderScreen();
15953
+ }
15954
+ async handleKeypress(str, key) {
15955
+ if (!this.running) return;
15956
+ if (!key) key = {};
15957
+ const k = key.name || "";
15958
+ const c = key.ctrl || false;
15959
+ if (this.popupActive) {
15960
+ await this.handlePopupKeypress(str, key);
15961
+ return;
15962
+ }
15963
+ if (k === "escape") {
15964
+ if (this.inputBuffer.length > 0) {
15965
+ this.inputBuffer = "";
15966
+ this.cursorPos = 0;
15967
+ }
15968
+ this.renderScreen();
15969
+ return;
15970
+ }
15971
+ if (k === "return" || k === "enter") {
15972
+ const input = this.inputBuffer.trim();
15973
+ this.inputBuffer = "";
15974
+ this.cursorPos = 0;
15975
+ if (input) {
15976
+ this.addHistory(input);
15886
15977
  if (this.onInput) {
15887
- await this.onInput(trimmed);
15978
+ await this.onInput(input);
15888
15979
  }
15889
15980
  }
15890
- this.showPrompt();
15891
- });
15892
- this.rl.on("SIGINT", () => {
15981
+ this.renderScreen();
15982
+ return;
15983
+ }
15984
+ if (k === "backspace") {
15985
+ if (this.cursorPos > 0) {
15986
+ this.inputBuffer = this.inputBuffer.slice(0, this.cursorPos - 1) + this.inputBuffer.slice(this.cursorPos);
15987
+ this.cursorPos--;
15988
+ }
15989
+ this.renderScreen();
15990
+ return;
15991
+ }
15992
+ if (k === "up") {
15993
+ if (this.inputHistory.length > 0) {
15994
+ if (this.historyIndex === -1) {
15995
+ this.historyIndex = this.inputHistory.length - 1;
15996
+ } else if (this.historyIndex > 0) {
15997
+ this.historyIndex--;
15998
+ }
15999
+ this.inputBuffer = this.inputHistory[this.historyIndex];
16000
+ this.cursorPos = this.inputBuffer.length;
16001
+ }
16002
+ this.renderScreen();
16003
+ return;
16004
+ }
16005
+ if (k === "down") {
16006
+ if (this.historyIndex >= 0) {
16007
+ this.historyIndex++;
16008
+ if (this.historyIndex >= this.inputHistory.length) {
16009
+ this.historyIndex = -1;
16010
+ this.inputBuffer = "";
16011
+ } else {
16012
+ this.inputBuffer = this.inputHistory[this.historyIndex];
16013
+ }
16014
+ this.cursorPos = this.inputBuffer.length;
16015
+ }
16016
+ this.renderScreen();
16017
+ return;
16018
+ }
16019
+ if (k === "left") {
16020
+ if (this.cursorPos > 0) this.cursorPos--;
16021
+ this.renderScreen();
16022
+ return;
16023
+ }
16024
+ if (k === "right") {
16025
+ if (this.cursorPos < this.inputBuffer.length) this.cursorPos++;
16026
+ this.renderScreen();
16027
+ return;
16028
+ }
16029
+ if (k === "tab") {
16030
+ this.handleTab();
16031
+ this.renderScreen();
16032
+ return;
16033
+ }
16034
+ if (c && k === "c") {
15893
16035
  if (this.cancelRequested || this.status === "thinking" || this.status === "executing") {
15894
16036
  if (this.onCancelRequest) this.onCancelRequest();
15895
16037
  } else {
15896
- process.stdout.write("\n");
16038
+ this.printLine("");
15897
16039
  this.printLine(source_default.yellow("Use /exit to quit, or press Ctrl+C again to force quit"));
15898
16040
  this.cancelRequested = true;
15899
16041
  setTimeout(() => {
15900
16042
  this.cancelRequested = false;
15901
16043
  }, 2e3);
15902
16044
  }
15903
- this.showPrompt();
15904
- });
15905
- this.rl.on("close", () => {
15906
- process.exit(0);
15907
- });
15908
- this.showPrompt();
16045
+ this.renderScreen();
16046
+ return;
16047
+ }
16048
+ if (c && k === "l") {
16049
+ this.clear();
16050
+ this.renderScreen();
16051
+ return;
16052
+ }
16053
+ if (c && k === "x") {
16054
+ await this.openExternalEditor();
16055
+ return;
16056
+ }
16057
+ if (c && k === "a") {
16058
+ this.cursorPos = 0;
16059
+ this.renderScreen();
16060
+ return;
16061
+ }
16062
+ if (c && k === "e") {
16063
+ this.cursorPos = this.inputBuffer.length;
16064
+ this.renderScreen();
16065
+ return;
16066
+ }
16067
+ if (str && str.length === 1 && str.charCodeAt(0) >= 32) {
16068
+ this.inputBuffer = this.inputBuffer.slice(0, this.cursorPos) + str + this.inputBuffer.slice(this.cursorPos);
16069
+ this.cursorPos++;
16070
+ if (str === "/") {
16071
+ this.popupActive = true;
16072
+ this.commandPopup.open();
16073
+ this.commandPopup.setFilter("");
16074
+ this.renderScreen();
16075
+ return;
16076
+ }
16077
+ if (this.inputBuffer.startsWith("/") && this.inputBuffer.length > 1) {
16078
+ this.popupActive = true;
16079
+ this.commandPopup.open();
16080
+ this.commandPopup.setFilter(this.inputBuffer.slice(1));
16081
+ this.renderScreen();
16082
+ return;
16083
+ }
16084
+ }
16085
+ this.renderScreen();
15909
16086
  }
15910
- startLineMode() {
15911
- const rl = (0, import_readline.createInterface)({ input: process.stdin, output: process.stdout, prompt: "" });
15912
- rl.on("line", (line) => {
15913
- const trimmed = line.trim();
15914
- if (trimmed && this.onInput) {
15915
- this.addHistory(trimmed);
15916
- this.onInput(trimmed);
16087
+ clearPopupLines() {
16088
+ if (this.popupLineCount > 0) {
16089
+ try {
16090
+ (0, import_readline.moveCursor)(process.stdout, 0, -(this.popupLineCount + 1));
16091
+ } catch {
15917
16092
  }
15918
- rl.prompt();
15919
- });
15920
- rl.on("SIGINT", () => process.exit(0));
15921
- rl.prompt();
16093
+ for (let i = 0; i <= this.popupLineCount; i++) {
16094
+ try {
16095
+ (0, import_readline.cursorTo)(process.stdout, 0);
16096
+ (0, import_readline.clearLine)(process.stdout, 1);
16097
+ process.stdout.write("\n");
16098
+ } catch {
16099
+ }
16100
+ }
16101
+ this.popupLineCount = 0;
16102
+ }
16103
+ }
16104
+ async handlePopupKeypress(str, key) {
16105
+ const k = key.name || "";
16106
+ if (k === "escape") {
16107
+ this.clearPopupLines();
16108
+ this.popupActive = false;
16109
+ this.commandPopup.close();
16110
+ this.inputBuffer = "";
16111
+ this.cursorPos = 0;
16112
+ this.renderScreen();
16113
+ return;
16114
+ }
16115
+ if (k === "up") {
16116
+ this.commandPopup.moveUp();
16117
+ this.renderScreen();
16118
+ return;
16119
+ }
16120
+ if (k === "down") {
16121
+ this.commandPopup.moveDown();
16122
+ this.renderScreen();
16123
+ return;
16124
+ }
16125
+ if (k === "return" || k === "enter") {
16126
+ const cmd = this.commandPopup.getSelectedCommand();
16127
+ this.popupActive = false;
16128
+ this.commandPopup.close();
16129
+ this.clearPopupLines();
16130
+ if (cmd) {
16131
+ const fullInput = `/${cmd} `;
16132
+ if (this.onInput) {
16133
+ await this.onInput(fullInput.trim());
16134
+ }
16135
+ }
16136
+ this.renderScreen();
16137
+ return;
16138
+ }
16139
+ if (k === "backspace") {
16140
+ this.commandPopup.deleteChar();
16141
+ const filter = this.commandPopup.getFilterText();
16142
+ if (filter.length === 0) {
16143
+ this.clearPopupLines();
16144
+ this.popupActive = false;
16145
+ this.commandPopup.close();
16146
+ this.inputBuffer = "/";
16147
+ this.cursorPos = 1;
16148
+ }
16149
+ this.renderScreen();
16150
+ return;
16151
+ }
16152
+ if (str && str.length === 1 && str.charCodeAt(0) >= 32) {
16153
+ this.commandPopup.appendChar(str);
16154
+ this.renderScreen();
16155
+ return;
16156
+ }
16157
+ }
16158
+ handleTab() {
16159
+ const match = this.inputBuffer.match(/^\/?(\w*)$/);
16160
+ if (match) {
16161
+ const partial = match[1].toLowerCase();
16162
+ const { ALL_COMMANDS: ALL_COMMANDS2 } = (init_CommandPopup(), __toCommonJS(CommandPopup_exports));
16163
+ const cmds = ALL_COMMANDS2.map((c) => c.command).filter((c) => c.startsWith(partial));
16164
+ if (cmds.length === 1) {
16165
+ this.inputBuffer = `/${cmds[0]} `;
16166
+ this.cursorPos = this.inputBuffer.length;
16167
+ }
16168
+ }
16169
+ }
16170
+ async openExternalEditor() {
16171
+ const editor = process.env.EDITOR || "nano";
16172
+ const { writeFileSync: writeFileSync7, unlinkSync: unlinkSync4, existsSync: existsSync11, mkdirSync: mkdirSync7, readFileSync: readFileSync11 } = await import("fs");
16173
+ const tmpDir = "/tmp/ys-agent";
16174
+ if (!existsSync11(tmpDir)) mkdirSync7(tmpDir, { recursive: true });
16175
+ const tmpFile = `/tmp/ys-agent/input-${Date.now()}.md`;
16176
+ writeFileSync7(tmpFile, this.inputBuffer, "utf-8");
16177
+ const { execSync: execSync4 } = await import("child_process");
16178
+ try {
16179
+ execSync4(`${editor} "${tmpFile}"`, { stdio: "inherit" });
16180
+ const content = readFileSync11(tmpFile, "utf-8").trim();
16181
+ if (content) {
16182
+ this.inputBuffer = content;
16183
+ this.cursorPos = content.length;
16184
+ }
16185
+ } catch {
16186
+ }
16187
+ try {
16188
+ unlinkSync4(tmpFile);
16189
+ } catch {
16190
+ }
16191
+ this.renderScreen();
16192
+ }
16193
+ renderScreen() {
16194
+ if (!process.stdout.isTTY) return;
16195
+ const promptLine2 = this.buildPromptLine();
16196
+ if (this.popupLineCount > 0) {
16197
+ try {
16198
+ (0, import_readline.moveCursor)(process.stdout, 0, -(this.popupLineCount + 1));
16199
+ } catch {
16200
+ }
16201
+ }
16202
+ if (this.popupActive && this.commandPopup.isVisible()) {
16203
+ const popup = this.commandPopup.render();
16204
+ const popupLines = popup.split("\n");
16205
+ this.popupLineCount = popupLines.length;
16206
+ for (const l of popupLines) {
16207
+ try {
16208
+ (0, import_readline.cursorTo)(process.stdout, 0);
16209
+ (0, import_readline.clearLine)(process.stdout, 1);
16210
+ process.stdout.write(l + "\n");
16211
+ } catch {
16212
+ }
16213
+ }
16214
+ } else {
16215
+ this.popupLineCount = 0;
16216
+ }
16217
+ try {
16218
+ (0, import_readline.cursorTo)(process.stdout, 0);
16219
+ (0, import_readline.clearLine)(process.stdout, 1);
16220
+ process.stdout.write(promptLine2);
16221
+ } catch {
16222
+ }
15922
16223
  }
15923
16224
  buildPromptPrefix() {
15924
16225
  const statusIndicator = STATUS_COLORS[this.status](INDICATORS[this.status]);
@@ -15934,10 +16235,22 @@ var TUI = class {
15934
16235
  else if (this.approvalMode === "yolo") approvalBadge2 = source_default.red(" [yolo]");
15935
16236
  return `${statusIndicator} ${source_default.cyan("ys")} ${source_default.yellow(`[${modelShort}]`)}${modeBadge2}${approvalBadge2} ${source_default.gray("\u203A")} `;
15936
16237
  }
16238
+ buildPromptLine() {
16239
+ const prefix = this.buildPromptPrefix();
16240
+ const input = this.inputBuffer || "";
16241
+ const cursor = source_default.gray("\u2588");
16242
+ let line;
16243
+ if (this.cursorPos >= input.length) {
16244
+ line = prefix + input + cursor;
16245
+ } else {
16246
+ const before = input.slice(0, this.cursorPos);
16247
+ const after = input.slice(this.cursorPos);
16248
+ line = prefix + before + cursor + after;
16249
+ }
16250
+ return line;
16251
+ }
15937
16252
  showPrompt() {
15938
- if (!this.running || !this.rl) return;
15939
- this.rl.setPrompt(this.buildPromptPrefix());
15940
- this.rl.prompt(true);
16253
+ if (this.running) this.renderScreen();
15941
16254
  }
15942
16255
  addHistory(input) {
15943
16256
  if (this.inputHistory[this.inputHistory.length - 1] !== input) {
@@ -15951,9 +16264,6 @@ var TUI = class {
15951
16264
  }
15952
16265
  setStatus(status) {
15953
16266
  this.status = status;
15954
- if (this.rl) {
15955
- this.rl.setPrompt(this.buildPromptPrefix());
15956
- }
15957
16267
  }
15958
16268
  setApprovalMode(mode) {
15959
16269
  this.approvalMode = mode;
@@ -15981,7 +16291,10 @@ var TUI = class {
15981
16291
  }
15982
16292
  }
15983
16293
  printAssistant(message) {
15984
- this.printLine(source_default.green(message));
16294
+ const rendered = renderMarkdown(message);
16295
+ for (const line of rendered.split("\n")) {
16296
+ this.printLine(line);
16297
+ }
15985
16298
  }
15986
16299
  printWarning(message) {
15987
16300
  this.printLine(source_default.yellow(`\u26A0 ${message}`));
@@ -16073,11 +16386,11 @@ var TUI = class {
16073
16386
  }
16074
16387
  stop() {
16075
16388
  this.running = false;
16076
- if (this.rl) {
16077
- this.rl.close();
16078
- this.rl = null;
16389
+ process.stdin.removeAllListeners("keypress");
16390
+ try {
16391
+ process.stdin.setRawMode?.(false);
16392
+ } catch {
16079
16393
  }
16080
- process.stdin.removeAllListeners("data");
16081
16394
  }
16082
16395
  destroy() {
16083
16396
  this.stop();
@@ -16459,8 +16772,8 @@ function getTemplate(ext) {
16459
16772
  }
16460
16773
  function promptConfirm(defaultYes) {
16461
16774
  return new Promise((resolve6) => {
16462
- const { createInterface: createInterface2 } = require("readline");
16463
- const rl = createInterface2({ input: process.stdin, output: process.stdout });
16775
+ const { createInterface } = require("readline");
16776
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
16464
16777
  const prompt = defaultYes ? "[Y/n] " : "[y/N] ";
16465
16778
  rl.question(prompt, (answer) => {
16466
16779
  rl.close();
@@ -16756,8 +17069,8 @@ function showGitHelp() {
16756
17069
  }
16757
17070
  function promptWithOptions() {
16758
17071
  return new Promise((resolve6) => {
16759
- const { createInterface: createInterface2 } = require("readline");
16760
- const rl = createInterface2({ input: process.stdin, output: process.stdout });
17072
+ const { createInterface } = require("readline");
17073
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
16761
17074
  rl.question("", (answer) => {
16762
17075
  rl.close();
16763
17076
  const a = answer.trim().toLowerCase();
@@ -16769,8 +17082,8 @@ function promptWithOptions() {
16769
17082
  }
16770
17083
  function promptLine() {
16771
17084
  return new Promise((resolve6) => {
16772
- const { createInterface: createInterface2 } = require("readline");
16773
- const rl = createInterface2({ input: process.stdin, output: process.stdout });
17085
+ const { createInterface } = require("readline");
17086
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
16774
17087
  rl.question("> ", (answer) => {
16775
17088
  rl.close();
16776
17089
  resolve6(answer.trim());
@@ -18245,8 +18558,8 @@ reg({
18245
18558
  tui.printLine(source_default.gray(" 1. Build the project"));
18246
18559
  tui.printLine(source_default.gray(" 2. Publish to npm registry"));
18247
18560
  tui.printLine(source_default.yellow("\n Continue? [y/N]"));
18248
- const { createInterface: createInterface2 } = await import("readline");
18249
- const rl = createInterface2({ input: process.stdin, output: process.stdout });
18561
+ const { createInterface } = await import("readline");
18562
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
18250
18563
  rl.question("", async (answer) => {
18251
18564
  rl.close();
18252
18565
  if (answer.trim().toLowerCase() !== "y") {
@@ -18495,7 +18808,7 @@ var InteractiveMode = class {
18495
18808
  // src/cli/index.ts
18496
18809
  var import_fs10 = require("fs");
18497
18810
  var logger18 = getLogger("cli");
18498
- var APP_VERSION = true ? "2.0.2" : "1.0.0";
18811
+ var APP_VERSION = true ? "3.0.0" : "1.0.0";
18499
18812
  var program2 = new Command();
18500
18813
  program2.name("ys").description("YS Code Agent - AI-Powered Terminal Coding Agent").version(APP_VERSION).option("-c, --config <path>", "Path to config file").option("-m, --model <model>", "Model to use").option("-p, --provider <provider>", "Provider to use").option("-d, --directory <path>", "Working directory").option("--read-only", "Enable read-only mode").option("--sandbox", "Enable sandbox mode").option("--verbose", "Enable verbose logging").option("--non-interactive", "Run in non-interactive mode").hook("preAction", () => {
18501
18814
  initializeTools();
@@ -18778,6 +19091,7 @@ async function main() {
18778
19091
  return;
18779
19092
  }
18780
19093
  applyGlobalOptions(rawArgs);
19094
+ initializeTools();
18781
19095
  showBanner();
18782
19096
  const interactive = new InteractiveMode();
18783
19097
  await interactive.start();