mocode-ai 0.5.1 → 0.5.3

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.
@@ -131,6 +131,11 @@ export function sliceFromEnd(offset, count) {
131
131
  export function totalRows() {
132
132
  return rows.length + (hasCurrent ? 1 : 0);
133
133
  }
134
+ /** 已提交行数(不含 hasCurrent 空行)。供续写位校正:breakRow 后 hasCurrent=true 时光标已在
135
+ * rows.length+1 位,若用 totalRows()+1 会多跳 1 行(2 空行 bug)。 */
136
+ export function committedRows() {
137
+ return rows.length;
138
+ }
134
139
  /** 取绝对行索引(0-based,含当前行)的原始自洽行;越界返 null。供鼠标选区文本提取。 */
135
140
  export function lineAt(abs) {
136
141
  const all = snapshot();
package/dist/ui/layout.js CHANGED
@@ -191,11 +191,15 @@ export function contentWrite(s) {
191
191
  const bottom = g.contentBottom;
192
192
  // resize 后 contentRow 可能过时(拖终端框):
193
193
  // - 缩小:contentRow > 新 bottom → 钳到新 bottom
194
- // - 放大:contentRow < 新 bottom 且回尾 → 推进到 min(total, bottom)
194
+ // - 放大:contentRow < 新 bottom 且回尾 → 推进到 min(committed+1, bottom)
195
+ // committed+1 是合法「待写位」(所有行已 breakRow 提交、光标在新空行);用 committed 会把续写位拉回到
196
+ // 最后一行 banner/content 上,首次 contentWrite 覆盖 banner(首条消息「插到 logo 下面」bug)。
197
+ // 注意:不能用 totalRows()+1——breakRow 后 hasCurrent=true,totalRows 已含当前空行,再 +1 会多跳一行,
198
+ // 导致 onDone 摘要行等写 \n 后的 contentWrite 入口多跳 1 行(2 空行 bug)。
195
199
  if (contentRow > bottom)
196
200
  contentRow = bottom;
197
201
  else if (scrollOffset === 0 && contentRow < bottom) {
198
- contentRow = Math.min(content.totalRows(), bottom);
202
+ contentRow = Math.min(content.committedRows() + 1, bottom);
199
203
  }
200
204
  const startRow = contentRow;
201
205
  const startCol = contentCol;
@@ -353,6 +357,11 @@ export function writeBanner(lines) {
353
357
  content.setLines(lines);
354
358
  bannerH = lines.length;
355
359
  bannerRows = lines;
360
+ // 续写位推进到 banner 之后:clearContent 把 contentRow 归到 1,writeBanner 灌入 bannerH 行
361
+ // 但不动 contentRow → 首次 contentWrite 会从屏行 1 写出(覆盖 banner)。这里同步修正,
362
+ // 让首条用户消息从 banner 下方开始(与 buffer 尾部对齐)。仅首次走这条,后续 rewriteBanner 不动续写位。
363
+ contentRow = Math.min(bannerH + 1, getGeo().contentBottom);
364
+ contentCol = 1;
356
365
  if (scrollOffset === 0)
357
366
  repaintViewport();
358
367
  return;
@@ -1410,15 +1419,18 @@ export function paintLiveAtCursor(text) {
1410
1419
  }
1411
1420
  // resize 后 contentRow 可能过时(拖终端框):
1412
1421
  // - 缩小:contentRow > 新 bottom → 钳到新 bottom
1413
- // - 放大:contentRow < 新 bottom 且回尾 → 推进到 min(total, bottom)(内容末尾或新区底)
1414
- // 内容够填满:推进到 bottom(最底部);内容不够:推进到 total(紧跟内容尾)
1422
+ // - 放大:contentRow < 新 bottom 且回尾 → 推进到 min(total+1, bottom)(内容末尾或新区底)
1423
+ // total+1 是合法「待写位」(breakRow 后光标在新空行);用 total 会把续写位拉回最后一行,
1424
+ // 首次 contentWrite 覆盖 banner(首条消息「插到 logo 下面」bug)。
1415
1425
  // 否则 cup 到旧行号→帧画在屏幕中间(旧 bottom 位置),而非内容末尾/最底部。
1416
1426
  const g = getGeo();
1417
- const total = content.totalRows();
1427
+ const committed = content.committedRows();
1418
1428
  if (contentRow > g.contentBottom)
1419
1429
  contentRow = g.contentBottom;
1420
1430
  if (scrollOffset === 0 && contentRow < g.contentBottom) {
1421
- contentRow = Math.min(total, g.contentBottom);
1431
+ // committed+1 而非 total+1:breakRow 后 hasCurrent=true,totalRows 已含当前空行,+1 会多跳一行
1432
+ // (contentWrite 入口的同类逻辑已同步修正,见上方注释)。
1433
+ contentRow = Math.min(committed + 1, g.contentBottom);
1422
1434
  }
1423
1435
  let out = '';
1424
1436
  if (frameRow && (frameRow !== contentRow || frameCol !== contentCol)) {
@@ -1851,12 +1863,14 @@ export function enterAltScreen() {
1851
1863
  // 重画 repaintViewport 防抖(下面 timer),避免连续拖动闪烁;但行号/区域必须立即正确。
1852
1864
  const g = getGeo(footerH);
1853
1865
  const total = content.totalRows();
1866
+ const committed = content.committedRows();
1854
1867
  // 缩小:contentRow > 新 bottom → 钳到新 bottom
1855
1868
  if (contentRow > g.contentBottom)
1856
1869
  contentRow = g.contentBottom;
1857
- // 放大:contentRow < 新 bottom 且回尾(offset=0)→ 推进到 min(total, bottom)
1870
+ // 放大:contentRow < 新 bottom 且回尾(offset=0)→ 推进到 min(committed+1, bottom)
1871
+ // committed+1 是合法「待写位」;用 total+1 在 hasCurrent=true(breakRow 后)时会多跳一行。
1858
1872
  if (scrollOffset === 0 && contentRow < g.contentBottom) {
1859
- contentRow = Math.min(total, g.contentBottom);
1873
+ contentRow = Math.min(committed + 1, g.contentBottom);
1860
1874
  }
1861
1875
  if (frameRow && frameRow > g.contentBottom)
1862
1876
  frameRow = g.contentBottom;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocode-ai",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "终端编码 agent:LLM + tool-call 循环 + 流式输出(含思考)+ 16 个工具,接任意 OpenAI 兼容后端。",
5
5
  "type": "module",
6
6
  "bin": {