@ai-setting/roy-agent-cli 1.6.17 → 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.17",
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) => ({
@@ -11596,6 +11634,9 @@ function createAskUserTimeoutSentinel(errorInfo, timeoutMs, extra) {
11596
11634
  }
11597
11635
  function withAskUserTimeoutRace(opts) {
11598
11636
  const { rl, timeoutMs, onLine, onTimeout } = opts;
11637
+ if (!rl) {
11638
+ return { cancel: () => {} };
11639
+ }
11599
11640
  let resolved = false;
11600
11641
  let timer = null;
11601
11642
  const handleLine = (input) => {
@@ -12545,21 +12586,28 @@ ${COLORS.error("❌ 执行失败: " + error)}
12545
12586
  resolve(parsed.value);
12546
12587
  }
12547
12588
  };
12548
- withAskUserTimeoutRace({
12549
- rl: this.rl,
12550
- timeoutMs,
12551
- onLine: (input) => {
12552
- finishWithUserInput(input);
12553
- },
12554
- onTimeout: () => {
12555
- 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(`
12556
12598
  ⏱ ask_user 超时:${timeoutMs}ms 内未收到回应,已自动解除等待。`));
12557
- resolve(createAskUserTimeoutSentinel(errorInfo, timeoutMs, {
12558
- source: "repl",
12559
- question
12560
- }));
12561
- }
12562
- });
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
+ }
12563
12611
  });
12564
12612
  }
12565
12613
  handleSigint() {
@@ -12646,10 +12694,12 @@ ${COLORS.error("❌ 执行失败: " + error)}
12646
12694
  this.isExecuting = false;
12647
12695
  }
12648
12696
  this.setMode("ready");
12649
- try {
12650
- this.redrawInputArea();
12651
- this.rl.prompt(true);
12652
- } catch {}
12697
+ if (this.rl) {
12698
+ try {
12699
+ this.redrawInputArea();
12700
+ this.rl.prompt(true);
12701
+ } catch {}
12702
+ }
12653
12703
  }
12654
12704
  printHeader() {
12655
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.17",
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) => ({
@@ -11595,6 +11633,9 @@ function createAskUserTimeoutSentinel(errorInfo, timeoutMs, extra) {
11595
11633
  }
11596
11634
  function withAskUserTimeoutRace(opts) {
11597
11635
  const { rl, timeoutMs, onLine, onTimeout } = opts;
11636
+ if (!rl) {
11637
+ return { cancel: () => {} };
11638
+ }
11598
11639
  let resolved = false;
11599
11640
  let timer = null;
11600
11641
  const handleLine = (input) => {
@@ -12544,21 +12585,28 @@ ${COLORS.error("❌ 执行失败: " + error)}
12544
12585
  resolve(parsed.value);
12545
12586
  }
12546
12587
  };
12547
- withAskUserTimeoutRace({
12548
- rl: this.rl,
12549
- timeoutMs,
12550
- onLine: (input) => {
12551
- finishWithUserInput(input);
12552
- },
12553
- onTimeout: () => {
12554
- 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(`
12555
12597
  ⏱ ask_user 超时:${timeoutMs}ms 内未收到回应,已自动解除等待。`));
12556
- resolve(createAskUserTimeoutSentinel(errorInfo, timeoutMs, {
12557
- source: "repl",
12558
- question
12559
- }));
12560
- }
12561
- });
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
+ }
12562
12610
  });
12563
12611
  }
12564
12612
  handleSigint() {
@@ -12645,10 +12693,12 @@ ${COLORS.error("❌ 执行失败: " + error)}
12645
12693
  this.isExecuting = false;
12646
12694
  }
12647
12695
  this.setMode("ready");
12648
- try {
12649
- this.redrawInputArea();
12650
- this.rl.prompt(true);
12651
- } catch {}
12696
+ if (this.rl) {
12697
+ try {
12698
+ this.redrawInputArea();
12699
+ this.rl.prompt(true);
12700
+ } catch {}
12701
+ }
12652
12702
  }
12653
12703
  printHeader() {
12654
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.17",
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",