@ai-setting/roy-agent-cli 1.6.16 → 1.6.18

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.
@@ -904,7 +904,7 @@ var init_status_bar = __esm(() => {
904
904
  var require_package = __commonJS((exports, module) => {
905
905
  module.exports = {
906
906
  name: "@ai-setting/roy-agent-cli",
907
- version: "1.6.16",
907
+ version: "1.6.18",
908
908
  type: "module",
909
909
  description: "CLI for roy-agent - Non-interactive command execution",
910
910
  main: "./dist/index.js",
@@ -1278,6 +1278,26 @@ function parseInline(text, keyPrefix) {
1278
1278
  }
1279
1279
  return nodes;
1280
1280
  }
1281
+ function tableCacheKey(header) {
1282
+ return header.join("\x01");
1283
+ }
1284
+ function lockColumnWidths(header, currentWidths) {
1285
+ const key = tableCacheKey(header);
1286
+ const prev = tableMaxWidthsCache.get(key);
1287
+ if (!prev) {
1288
+ tableMaxWidthsCache.set(key, currentWidths);
1289
+ return currentWidths;
1290
+ }
1291
+ const maxLen = Math.max(prev.length, currentWidths.length);
1292
+ const merged = [];
1293
+ for (let i = 0;i < maxLen; i++) {
1294
+ const a = prev[i] ?? 0;
1295
+ const b = currentWidths[i] ?? 0;
1296
+ merged.push(Math.max(a, b));
1297
+ }
1298
+ tableMaxWidthsCache.set(key, merged);
1299
+ return merged;
1300
+ }
1281
1301
  function splitTableRow(rawLine) {
1282
1302
  let s = rawLine.trim();
1283
1303
  if (s.startsWith("|"))
@@ -1354,7 +1374,7 @@ function parseTableBlock(lines, startIndex) {
1354
1374
  }
1355
1375
  function renderTableBlock(tbl, key) {
1356
1376
  const colCount = Math.max(tbl.header.length, ...tbl.rows.map((r) => r.length));
1357
- const widths = [];
1377
+ const rawWidths = [];
1358
1378
  for (let c = 0;c < colCount; c++) {
1359
1379
  const headerW = (tbl.header[c] ?? "").length;
1360
1380
  let dataW = 0;
@@ -1363,8 +1383,9 @@ function renderTableBlock(tbl, key) {
1363
1383
  if (cell.length > dataW)
1364
1384
  dataW = cell.length;
1365
1385
  }
1366
- widths.push(Math.max(headerW, dataW));
1386
+ rawWidths.push(Math.max(headerW, dataW));
1367
1387
  }
1388
+ const widths = lockColumnWidths(tbl.header, rawWidths);
1368
1389
  const alignments = [];
1369
1390
  for (let c = 0;c < colCount; c++) {
1370
1391
  alignments.push(tbl.alignments[c] ?? "left");
@@ -1508,9 +1529,26 @@ function renderMarkdownLegacyImpl(content) {
1508
1529
  }
1509
1530
  return blocks;
1510
1531
  }
1511
- var renderMarkdown;
1532
+ var tableMaxWidthsCache, MARKDOWN_CACHE_MAX = 16, markdownParseCache, renderMarkdownWithCache = (content) => {
1533
+ const cached = markdownParseCache.get(content);
1534
+ if (cached !== undefined) {
1535
+ markdownParseCache.delete(content);
1536
+ markdownParseCache.set(content, cached);
1537
+ return cached;
1538
+ }
1539
+ const parsed = renderMarkdownLegacyImpl(content);
1540
+ if (markdownParseCache.size >= MARKDOWN_CACHE_MAX) {
1541
+ const firstKey = markdownParseCache.keys().next().value;
1542
+ if (firstKey !== undefined)
1543
+ markdownParseCache.delete(firstKey);
1544
+ }
1545
+ markdownParseCache.set(content, parsed);
1546
+ return parsed;
1547
+ }, renderMarkdown;
1512
1548
  var init_markdown_renderer2 = __esm(() => {
1513
- renderMarkdown = wrapFunction(renderMarkdownLegacyImpl, "markdown.render", {
1549
+ tableMaxWidthsCache = new Map;
1550
+ markdownParseCache = new Map;
1551
+ renderMarkdown = wrapFunction(renderMarkdownWithCache, "markdown.render", {
1514
1552
  recordParams: true,
1515
1553
  recordResult: false,
1516
1554
  paramFilter: (args) => ({
@@ -1865,8 +1903,10 @@ var init_repl_ink = __esm(() => {
1865
1903
  const [buffer, setBuffer] = React3.useState("");
1866
1904
  const [cursor, setCursor] = React3.useState(0);
1867
1905
  React3.useEffect(() => {
1868
- onChange?.(buffer);
1869
- }, [buffer, onChange]);
1906
+ if (popupActive || buffer.startsWith("/")) {
1907
+ onChange?.(buffer);
1908
+ }
1909
+ }, [buffer, onChange, popupActive]);
1870
1910
  React3.useImperativeHandle(ref, () => ({
1871
1911
  clearBuffer: () => {
1872
1912
  setBuffer("");
@@ -11594,6 +11634,9 @@ function createAskUserTimeoutSentinel(errorInfo, timeoutMs, extra) {
11594
11634
  }
11595
11635
  function withAskUserTimeoutRace(opts) {
11596
11636
  const { rl, timeoutMs, onLine, onTimeout } = opts;
11637
+ if (!rl) {
11638
+ return { cancel: () => {} };
11639
+ }
11597
11640
  let resolved = false;
11598
11641
  let timer = null;
11599
11642
  const handleLine = (input) => {
@@ -11974,14 +12017,18 @@ class REPL {
11974
12017
  console.clear();
11975
12018
  this.printHeader();
11976
12019
  this.redrawInputArea();
11977
- this.rl.prompt(true);
12020
+ if (this.rl) {
12021
+ this.rl.prompt(true);
12022
+ }
11978
12023
  this.sessionManager?.clearAttachments();
11979
12024
  });
11980
12025
  this.commandRegistry.set("cls", async () => {
11981
12026
  console.clear();
11982
12027
  this.printHeader();
11983
12028
  this.redrawInputArea();
11984
- this.rl.prompt(true);
12029
+ if (this.rl) {
12030
+ this.rl.prompt(true);
12031
+ }
11985
12032
  this.sessionManager?.clearAttachments();
11986
12033
  });
11987
12034
  this.commandRegistry.set("sessions", async () => {
@@ -12211,7 +12258,9 @@ ${COLORS.system("[没有正在执行的请求]")}`);
12211
12258
  }
12212
12259
  this.printHeader();
12213
12260
  this.redrawInputArea();
12214
- this.rl.prompt(true);
12261
+ if (this.rl) {
12262
+ this.rl.prompt(true);
12263
+ }
12215
12264
  readline2.emitKeypressEvents(process.stdin);
12216
12265
  if (process.stdin.isTTY) {
12217
12266
  process.stdin.setRawMode?.(true);
@@ -12295,9 +12344,13 @@ ${COLORS.system("[没有正在执行的请求]")}`);
12295
12344
  printSlotBottomBorder();
12296
12345
  }
12297
12346
  updatePrompt() {
12298
- this.rl.setPrompt(COLORS.accent("❯ "));
12299
- this.redrawInputArea();
12300
- this.rl.prompt(true);
12347
+ if (this.rl) {
12348
+ this.rl.setPrompt(COLORS.accent("❯ "));
12349
+ this.redrawInputArea();
12350
+ this.rl.prompt(true);
12351
+ } else {
12352
+ this.redrawInputArea();
12353
+ }
12301
12354
  }
12302
12355
  async handleCommand(input) {
12303
12356
  const [cmd] = input.split(/\s+/);
@@ -12445,7 +12498,9 @@ ${COLORS.error("❌ 执行失败: " + error)}
12445
12498
  this.setMode("ready");
12446
12499
  if (options.showPrompt) {
12447
12500
  this.redrawInputArea();
12448
- this.rl.prompt(true);
12501
+ if (this.rl) {
12502
+ this.rl.prompt(true);
12503
+ }
12449
12504
  }
12450
12505
  }
12451
12506
  }
@@ -12504,9 +12559,13 @@ ${COLORS.error("❌ 执行失败: " + error)}
12504
12559
  promptUser(question, options, errorInfo, opts) {
12505
12560
  const timeoutMs = opts?.timeoutMs ?? this.askUserTimeoutMs ?? ASK_USER_TIMEOUT_MS;
12506
12561
  return new Promise((resolve) => {
12507
- this.rl.setPrompt(COLORS.accent("❯ "));
12508
- this.redrawInputArea();
12509
- this.rl.prompt(true);
12562
+ if (this.rl) {
12563
+ this.rl.setPrompt(COLORS.accent("❯ "));
12564
+ this.redrawInputArea();
12565
+ this.rl.prompt(true);
12566
+ } else {
12567
+ this.redrawInputArea();
12568
+ }
12510
12569
  const finishWithUserInput = (input) => {
12511
12570
  const trimmedInput = input.trim();
12512
12571
  if (!trimmedInput) {
@@ -12527,21 +12586,28 @@ ${COLORS.error("❌ 执行失败: " + error)}
12527
12586
  resolve(parsed.value);
12528
12587
  }
12529
12588
  };
12530
- withAskUserTimeoutRace({
12531
- rl: this.rl,
12532
- timeoutMs,
12533
- onLine: (input) => {
12534
- finishWithUserInput(input);
12535
- },
12536
- onTimeout: () => {
12537
- console.log(chalk7.yellow(`
12589
+ if (this.rl) {
12590
+ withAskUserTimeoutRace({
12591
+ rl: this.rl,
12592
+ timeoutMs,
12593
+ onLine: (input) => {
12594
+ finishWithUserInput(input);
12595
+ },
12596
+ onTimeout: () => {
12597
+ console.log(chalk7.yellow(`
12538
12598
  ⏱ ask_user 超时:${timeoutMs}ms 内未收到回应,已自动解除等待。`));
12539
- resolve(createAskUserTimeoutSentinel(errorInfo, timeoutMs, {
12540
- source: "repl",
12541
- question
12542
- }));
12543
- }
12544
- });
12599
+ resolve(createAskUserTimeoutSentinel(errorInfo, timeoutMs, {
12600
+ source: "repl",
12601
+ question
12602
+ }));
12603
+ }
12604
+ });
12605
+ } else {
12606
+ resolve(createAskUserTimeoutSentinel(errorInfo, timeoutMs, {
12607
+ source: "repl",
12608
+ question
12609
+ }));
12610
+ }
12545
12611
  });
12546
12612
  }
12547
12613
  handleSigint() {
@@ -12628,10 +12694,12 @@ ${COLORS.error("❌ 执行失败: " + error)}
12628
12694
  this.isExecuting = false;
12629
12695
  }
12630
12696
  this.setMode("ready");
12631
- try {
12632
- this.redrawInputArea();
12633
- this.rl.prompt(true);
12634
- } catch {}
12697
+ if (this.rl) {
12698
+ try {
12699
+ this.redrawInputArea();
12700
+ this.rl.prompt(true);
12701
+ } catch {}
12702
+ }
12635
12703
  }
12636
12704
  printHeader() {
12637
12705
  if (process.stdout.isTTY) {
package/dist/index.js CHANGED
@@ -903,7 +903,7 @@ var init_status_bar = __esm(() => {
903
903
  var require_package = __commonJS((exports, module) => {
904
904
  module.exports = {
905
905
  name: "@ai-setting/roy-agent-cli",
906
- version: "1.6.16",
906
+ version: "1.6.18",
907
907
  type: "module",
908
908
  description: "CLI for roy-agent - Non-interactive command execution",
909
909
  main: "./dist/index.js",
@@ -1277,6 +1277,26 @@ function parseInline(text, keyPrefix) {
1277
1277
  }
1278
1278
  return nodes;
1279
1279
  }
1280
+ function tableCacheKey(header) {
1281
+ return header.join("\x01");
1282
+ }
1283
+ function lockColumnWidths(header, currentWidths) {
1284
+ const key = tableCacheKey(header);
1285
+ const prev = tableMaxWidthsCache.get(key);
1286
+ if (!prev) {
1287
+ tableMaxWidthsCache.set(key, currentWidths);
1288
+ return currentWidths;
1289
+ }
1290
+ const maxLen = Math.max(prev.length, currentWidths.length);
1291
+ const merged = [];
1292
+ for (let i = 0;i < maxLen; i++) {
1293
+ const a = prev[i] ?? 0;
1294
+ const b = currentWidths[i] ?? 0;
1295
+ merged.push(Math.max(a, b));
1296
+ }
1297
+ tableMaxWidthsCache.set(key, merged);
1298
+ return merged;
1299
+ }
1280
1300
  function splitTableRow(rawLine) {
1281
1301
  let s = rawLine.trim();
1282
1302
  if (s.startsWith("|"))
@@ -1353,7 +1373,7 @@ function parseTableBlock(lines, startIndex) {
1353
1373
  }
1354
1374
  function renderTableBlock(tbl, key) {
1355
1375
  const colCount = Math.max(tbl.header.length, ...tbl.rows.map((r) => r.length));
1356
- const widths = [];
1376
+ const rawWidths = [];
1357
1377
  for (let c = 0;c < colCount; c++) {
1358
1378
  const headerW = (tbl.header[c] ?? "").length;
1359
1379
  let dataW = 0;
@@ -1362,8 +1382,9 @@ function renderTableBlock(tbl, key) {
1362
1382
  if (cell.length > dataW)
1363
1383
  dataW = cell.length;
1364
1384
  }
1365
- widths.push(Math.max(headerW, dataW));
1385
+ rawWidths.push(Math.max(headerW, dataW));
1366
1386
  }
1387
+ const widths = lockColumnWidths(tbl.header, rawWidths);
1367
1388
  const alignments = [];
1368
1389
  for (let c = 0;c < colCount; c++) {
1369
1390
  alignments.push(tbl.alignments[c] ?? "left");
@@ -1507,9 +1528,26 @@ function renderMarkdownLegacyImpl(content) {
1507
1528
  }
1508
1529
  return blocks;
1509
1530
  }
1510
- var renderMarkdown;
1531
+ var tableMaxWidthsCache, MARKDOWN_CACHE_MAX = 16, markdownParseCache, renderMarkdownWithCache = (content) => {
1532
+ const cached = markdownParseCache.get(content);
1533
+ if (cached !== undefined) {
1534
+ markdownParseCache.delete(content);
1535
+ markdownParseCache.set(content, cached);
1536
+ return cached;
1537
+ }
1538
+ const parsed = renderMarkdownLegacyImpl(content);
1539
+ if (markdownParseCache.size >= MARKDOWN_CACHE_MAX) {
1540
+ const firstKey = markdownParseCache.keys().next().value;
1541
+ if (firstKey !== undefined)
1542
+ markdownParseCache.delete(firstKey);
1543
+ }
1544
+ markdownParseCache.set(content, parsed);
1545
+ return parsed;
1546
+ }, renderMarkdown;
1511
1547
  var init_markdown_renderer2 = __esm(() => {
1512
- renderMarkdown = wrapFunction(renderMarkdownLegacyImpl, "markdown.render", {
1548
+ tableMaxWidthsCache = new Map;
1549
+ markdownParseCache = new Map;
1550
+ renderMarkdown = wrapFunction(renderMarkdownWithCache, "markdown.render", {
1513
1551
  recordParams: true,
1514
1552
  recordResult: false,
1515
1553
  paramFilter: (args) => ({
@@ -1864,8 +1902,10 @@ var init_repl_ink = __esm(() => {
1864
1902
  const [buffer, setBuffer] = React3.useState("");
1865
1903
  const [cursor, setCursor] = React3.useState(0);
1866
1904
  React3.useEffect(() => {
1867
- onChange?.(buffer);
1868
- }, [buffer, onChange]);
1905
+ if (popupActive || buffer.startsWith("/")) {
1906
+ onChange?.(buffer);
1907
+ }
1908
+ }, [buffer, onChange, popupActive]);
1869
1909
  React3.useImperativeHandle(ref, () => ({
1870
1910
  clearBuffer: () => {
1871
1911
  setBuffer("");
@@ -11593,6 +11633,9 @@ function createAskUserTimeoutSentinel(errorInfo, timeoutMs, extra) {
11593
11633
  }
11594
11634
  function withAskUserTimeoutRace(opts) {
11595
11635
  const { rl, timeoutMs, onLine, onTimeout } = opts;
11636
+ if (!rl) {
11637
+ return { cancel: () => {} };
11638
+ }
11596
11639
  let resolved = false;
11597
11640
  let timer = null;
11598
11641
  const handleLine = (input) => {
@@ -11973,14 +12016,18 @@ class REPL {
11973
12016
  console.clear();
11974
12017
  this.printHeader();
11975
12018
  this.redrawInputArea();
11976
- this.rl.prompt(true);
12019
+ if (this.rl) {
12020
+ this.rl.prompt(true);
12021
+ }
11977
12022
  this.sessionManager?.clearAttachments();
11978
12023
  });
11979
12024
  this.commandRegistry.set("cls", async () => {
11980
12025
  console.clear();
11981
12026
  this.printHeader();
11982
12027
  this.redrawInputArea();
11983
- this.rl.prompt(true);
12028
+ if (this.rl) {
12029
+ this.rl.prompt(true);
12030
+ }
11984
12031
  this.sessionManager?.clearAttachments();
11985
12032
  });
11986
12033
  this.commandRegistry.set("sessions", async () => {
@@ -12210,7 +12257,9 @@ ${COLORS.system("[没有正在执行的请求]")}`);
12210
12257
  }
12211
12258
  this.printHeader();
12212
12259
  this.redrawInputArea();
12213
- this.rl.prompt(true);
12260
+ if (this.rl) {
12261
+ this.rl.prompt(true);
12262
+ }
12214
12263
  readline2.emitKeypressEvents(process.stdin);
12215
12264
  if (process.stdin.isTTY) {
12216
12265
  process.stdin.setRawMode?.(true);
@@ -12294,9 +12343,13 @@ ${COLORS.system("[没有正在执行的请求]")}`);
12294
12343
  printSlotBottomBorder();
12295
12344
  }
12296
12345
  updatePrompt() {
12297
- this.rl.setPrompt(COLORS.accent("❯ "));
12298
- this.redrawInputArea();
12299
- this.rl.prompt(true);
12346
+ if (this.rl) {
12347
+ this.rl.setPrompt(COLORS.accent("❯ "));
12348
+ this.redrawInputArea();
12349
+ this.rl.prompt(true);
12350
+ } else {
12351
+ this.redrawInputArea();
12352
+ }
12300
12353
  }
12301
12354
  async handleCommand(input) {
12302
12355
  const [cmd] = input.split(/\s+/);
@@ -12444,7 +12497,9 @@ ${COLORS.error("❌ 执行失败: " + error)}
12444
12497
  this.setMode("ready");
12445
12498
  if (options.showPrompt) {
12446
12499
  this.redrawInputArea();
12447
- this.rl.prompt(true);
12500
+ if (this.rl) {
12501
+ this.rl.prompt(true);
12502
+ }
12448
12503
  }
12449
12504
  }
12450
12505
  }
@@ -12503,9 +12558,13 @@ ${COLORS.error("❌ 执行失败: " + error)}
12503
12558
  promptUser(question, options, errorInfo, opts) {
12504
12559
  const timeoutMs = opts?.timeoutMs ?? this.askUserTimeoutMs ?? ASK_USER_TIMEOUT_MS;
12505
12560
  return new Promise((resolve) => {
12506
- this.rl.setPrompt(COLORS.accent("❯ "));
12507
- this.redrawInputArea();
12508
- this.rl.prompt(true);
12561
+ if (this.rl) {
12562
+ this.rl.setPrompt(COLORS.accent("❯ "));
12563
+ this.redrawInputArea();
12564
+ this.rl.prompt(true);
12565
+ } else {
12566
+ this.redrawInputArea();
12567
+ }
12509
12568
  const finishWithUserInput = (input) => {
12510
12569
  const trimmedInput = input.trim();
12511
12570
  if (!trimmedInput) {
@@ -12526,21 +12585,28 @@ ${COLORS.error("❌ 执行失败: " + error)}
12526
12585
  resolve(parsed.value);
12527
12586
  }
12528
12587
  };
12529
- withAskUserTimeoutRace({
12530
- rl: this.rl,
12531
- timeoutMs,
12532
- onLine: (input) => {
12533
- finishWithUserInput(input);
12534
- },
12535
- onTimeout: () => {
12536
- console.log(chalk7.yellow(`
12588
+ if (this.rl) {
12589
+ withAskUserTimeoutRace({
12590
+ rl: this.rl,
12591
+ timeoutMs,
12592
+ onLine: (input) => {
12593
+ finishWithUserInput(input);
12594
+ },
12595
+ onTimeout: () => {
12596
+ console.log(chalk7.yellow(`
12537
12597
  ⏱ ask_user 超时:${timeoutMs}ms 内未收到回应,已自动解除等待。`));
12538
- resolve(createAskUserTimeoutSentinel(errorInfo, timeoutMs, {
12539
- source: "repl",
12540
- question
12541
- }));
12542
- }
12543
- });
12598
+ resolve(createAskUserTimeoutSentinel(errorInfo, timeoutMs, {
12599
+ source: "repl",
12600
+ question
12601
+ }));
12602
+ }
12603
+ });
12604
+ } else {
12605
+ resolve(createAskUserTimeoutSentinel(errorInfo, timeoutMs, {
12606
+ source: "repl",
12607
+ question
12608
+ }));
12609
+ }
12544
12610
  });
12545
12611
  }
12546
12612
  handleSigint() {
@@ -12627,10 +12693,12 @@ ${COLORS.error("❌ 执行失败: " + error)}
12627
12693
  this.isExecuting = false;
12628
12694
  }
12629
12695
  this.setMode("ready");
12630
- try {
12631
- this.redrawInputArea();
12632
- this.rl.prompt(true);
12633
- } catch {}
12696
+ if (this.rl) {
12697
+ try {
12698
+ this.redrawInputArea();
12699
+ this.rl.prompt(true);
12700
+ } catch {}
12701
+ }
12634
12702
  }
12635
12703
  printHeader() {
12636
12704
  if (process.stdout.isTTY) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-cli",
3
- "version": "1.6.16",
3
+ "version": "1.6.18",
4
4
  "type": "module",
5
5
  "description": "CLI for roy-agent - Non-interactive command execution",
6
6
  "main": "./dist/index.js",