mocode-ai 1.7.7 → 1.7.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.
@@ -161,6 +161,7 @@ const zhCN = {
161
161
  'intervention.emptyInput': '自动返回空输入',
162
162
  'intervention.nonInteractive': '[介入] {title}(非交互环境,{kind})',
163
163
  'repl.idle': '空闲',
164
+ 'repl.queuedCommandHeld': '排队的是斜杠命令,已填入输入框,请确认后手动发送',
164
165
  'repl.loadFailed': '(加载失败)',
165
166
  'repl.resumeAnchor': '已恢复会话 {id} · {count} 条消息 · 当前模型 {model}(/model switch 可切换)',
166
167
  'repl.noSessions': '(没有已保存的会话)',
@@ -208,6 +209,8 @@ const zhCN = {
208
209
  'banner.disabled': '关闭',
209
210
  'status.modeSwitch': 'Shift+Tab 切换',
210
211
  'status.history': '历史 ↑{count}(PgDn 回底)',
212
+ 'status.queued': '排队 ·',
213
+ 'status.queuePlanTag': '(Plan)',
211
214
  'status.measured': '实测',
212
215
  'status.estimated': '估算',
213
216
  'status.messages': '{count} 条消息',
@@ -548,6 +551,7 @@ const en = {
548
551
  'intervention.emptyInput': 'automatically returned empty input',
549
552
  'intervention.nonInteractive': '[intervention] {title} (non-interactive; {kind})',
550
553
  'repl.idle': 'Idle',
554
+ 'repl.queuedCommandHeld': 'Queued text is a slash command; filled into the input for you to send manually',
551
555
  'repl.loadFailed': '(load failed)',
552
556
  'repl.resumeAnchor': 'Resumed session {id} · {count} messages · model {model} (/model switch to change)',
553
557
  'repl.noSessions': '(no saved sessions)',
@@ -595,6 +599,8 @@ const en = {
595
599
  'banner.disabled': 'Disabled',
596
600
  'status.modeSwitch': 'Shift+Tab Switch',
597
601
  'status.history': 'History ↑{count} (PgDn to bottom)',
602
+ 'status.queued': 'queued ·',
603
+ 'status.queuePlanTag': ' (Plan)',
598
604
  'status.measured': 'measured',
599
605
  'status.estimated': 'estimated',
600
606
  'status.messages': '{count} messages',
@@ -4,6 +4,7 @@ import * as layout from '../ui/layout.js';
4
4
  import * as mouse from '../ui/mouse.js';
5
5
  import { promptComposer } from '../ui/composer.js';
6
6
  import { appendCurrentSessionRuntimeEvent } from '../session/index.js';
7
+ import { getAgentMode } from '../agent/mode.js';
7
8
  const emitter = stdin;
8
9
  // ── 运行态交互(typeahead 输入 + 滚动回看 + Ctrl+C 中断 + Ctrl+G 输入面板)──
9
10
  // 只在 await runAgent() 期间挂载;/resume /rollback /compact 等走 askLine(cooked readline)的分支不挂(避免抢 stdin)。
@@ -12,6 +13,12 @@ let runningCursor = 0; // 缓冲内光标字符索引(0..len);运行态支持任
12
13
  let runningPlaceholder = '';
13
14
  let currentAbort = null;
14
15
  let listening = false; // onRunningKey 是否处于挂载期(start → stop 之间)
16
+ /**
17
+ * 运行态「预加载/排队」消息:运行中打字后按 Enter 入队(单条,再次入队即替换),
18
+ * 当前 agent 结束后由主循环自动发送,无需用户在 INPUT 态再按一次 Enter。
19
+ * null = 没有排队。mode 快照入队那一刻的模式,自动执行时沿用(用户选「沿用当前模式」)。
20
+ */
21
+ let queuedTurn = null;
15
22
  /** 运行态打开的输入面板(Ctrl+G);非 null = 面板仍开着。主循环进 INPUT 态前须等它关闭,否则两个 keypress 监听抢键。 */
16
23
  let composerPending = null;
17
24
  /** 获取运行中输入缓冲(agent 结束后预填下一轮 INPUT 态)。 */
@@ -23,6 +30,20 @@ export function clearRunningInput() {
23
30
  runningInput = '';
24
31
  runningCursor = 0;
25
32
  }
33
+ /** 当前排队消息(运行中按 Enter 预加载);无则 null。主循环在 agent 结束后取走并自动发送。 */
34
+ export function getQueuedTurn() {
35
+ return queuedTurn;
36
+ }
37
+ /** 取走并清空排队消息(消费一次)。 */
38
+ export function consumeQueuedTurn() {
39
+ const queued = queuedTurn;
40
+ queuedTurn = null;
41
+ return queued;
42
+ }
43
+ /** 取消排队(运行态 Esc 在已有排队时优先取消排队,而不是只清 typeahead)。 */
44
+ export function clearQueuedTurn() {
45
+ queuedTurn = null;
46
+ }
26
47
  /**
27
48
  * 等待运行态打开的输入面板关闭(无则立即返回)。
28
49
  * agent 可能在面板打开期间结束:主循环在进入 INPUT 态(promptWithSlashMenu 挂自己的 keypress)前必须 await,
@@ -99,6 +120,11 @@ function onRunningKey(_str, key) {
99
120
  paint();
100
121
  }
101
122
  else if (currentAbort && !currentAbort.signal.aborted) {
123
+ // 中断当前任务 = 明确要停下,排队的下一跳也一并取消,避免 agent 一停又自动发新需求。
124
+ if (queuedTurn) {
125
+ queuedTurn = null;
126
+ layout.setQueuedTurn(undefined); // 只撤状态行 chip,不在内容区写提示
127
+ }
102
128
  appendCurrentSessionRuntimeEvent('abort', { phase: 'requested', source: 'keyboard' });
103
129
  currentAbort.abort();
104
130
  }
@@ -153,13 +179,32 @@ function onRunningKey(_str, key) {
153
179
  return;
154
180
  }
155
181
  if (key.name === 'escape') {
156
- runningInput = '';
157
- runningCursor = 0;
158
- paint();
182
+ // 有排队消息时 Esc 只取消排队,不清空 typeahead 草稿(避免误删正在打的字);
183
+ // 无排队时维持原语义:清空 typeahead。
184
+ if (queuedTurn) {
185
+ queuedTurn = null;
186
+ layout.setQueuedTurn(undefined); // 只撤状态行 chip,不在内容区写提示
187
+ paint();
188
+ }
189
+ else {
190
+ runningInput = '';
191
+ runningCursor = 0;
192
+ paint();
193
+ }
159
194
  return;
160
195
  }
161
- // Enter / Ctrl+J:运行中 no-op(单行 typeahead;agent 结束后预填,用户在 INPUT 态按 Enter 提交)
196
+ // Enter / Ctrl+J:把 typeahead 内容入队(单条,再次入队即替换)。当前 agent 结束后
197
+ // 主循环经 consumeQueuedTurn 自动发送,无需在 INPUT 态再按一次 Enter。空内容 no-op。
162
198
  if (key.name === 'return' || key.name === 'enter' || (key.ctrl && key.name === 'j')) {
199
+ const text = runningInput.trim();
200
+ if (!text)
201
+ return;
202
+ queuedTurn = { text: runningInput, mode: getAgentMode() }; // 单条:再次入队即替换
203
+ runningInput = '';
204
+ runningCursor = 0;
205
+ // 入队只反映在状态行 `● 状态` 右侧的常驻 chip(含预览/模式),不往 agent 输出区写行。
206
+ layout.setQueuedTurn(queuedTurn.text, queuedTurn.mode);
207
+ paint(); // 清空底部 typeahead 回显
163
208
  return;
164
209
  }
165
210
  // 可打印字符(>= 空格,非 ctrl/meta)→ 光标处插入 + 非 dim 回显(与空闲态一致)
@@ -32,7 +32,7 @@ import { PROMPT, buildSlashCommands, LLM_ERROR_HINT_KEYS, isCommandShape, sugges
32
32
  import { dispatchCommand } from './commands/registry.js';
33
33
  import { settlePlanStatus, refreshStatusBase, runningStateFor } from './status-bar.js';
34
34
  import { messageAttachments, formatUserMessage, textOf, queryHistoryFromMessages, renderHistory, } from './message-format.js';
35
- import { startRunningListener, stopRunningListener, getRunningInput, clearRunningInput, waitForRunningComposer, } from './running-input.js';
35
+ import { startRunningListener, stopRunningListener, getRunningInput, clearRunningInput, waitForRunningComposer, consumeQueuedTurn, } from './running-input.js';
36
36
  const emitter = stdin;
37
37
  // ── 运行态交互已移到 ./running-input.ts ──
38
38
  // ── pendingPrefill / pendingTimer / pendingAttachments 保留在此(awaitPendingRecall / echoInput 用)
@@ -676,7 +676,19 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
676
676
  // 运行态 Ctrl+G 打开的输入面板可能在 agent 结束时仍开着:等它关闭再进 INPUT 态,
677
677
  // 否则面板与 promptWithSlashMenu 两个 keypress 监听抢键;面板确认的内容随后经 getRunningInput 预填。
678
678
  await waitForRunningComposer();
679
- // INPUT 态:画底栏输入框 + 状态行,光标入输入框
679
+ // 消息预加载:上一轮运行中用户按 Enter 排了队(consumeQueuedTurn),agent 一结束就自动发送,
680
+ // 跳过 INPUT 态输入框与撤回窗口(入队那一刻即已确认)。非空才自动发;排队时正在打的 typeahead
681
+ // 草稿经 pendingPrefill 保住,留到下一轮输入框。
682
+ const queued = consumeQueuedTurn();
683
+ const autoSend = !!queued && queued.text.trim().length > 0;
684
+ if (queued)
685
+ layout.setQueuedTurn(undefined); // chip 已被消费(或为空丢弃),从状态行撤下
686
+ if (autoSend && queued) {
687
+ // 排队时仍在输入框草稿里的字(typeahead)不能丢:回填为下一轮预填。
688
+ if (getRunningInput().trim())
689
+ pendingPrefill = [getRunningInput()];
690
+ clearRunningInput();
691
+ }
680
692
  refreshStatusBase(history);
681
693
  // 后台反思若已完成(上轮 fire-and-forget),在安全点 flush 一行 dim 摘要:
682
694
  // 不在 RUNNING 态写——防与正在跑的 agent 争屏(contentWrite / 状态行)。
@@ -685,39 +697,54 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
685
697
  layout.contentWrite(` ${ui.gray}↳ ${formatReflectResult(reflectRes)}${ui.reset}\n`);
686
698
  clearLastReflectResult();
687
699
  }
688
- // 所有斜杠命令和 Agent 轮次共用同一个输出→输入边界,避免某条命令漏写第二个 \n
689
- // 后下一条 ❯ 气泡紧贴确认文案;已有多余空行也会收敛为恰好一行。
690
- if (hasSubmittedInput)
691
- layout.normalizeInputBoundary();
692
- layout.enterInputMode(t('repl.idle'));
693
- let input = null;
694
- try {
695
- input = await promptWithSlashMenu({
696
- prompt: PROMPT,
697
- commands: buildSlashCommands(),
698
- onCycleMode: cycleMode,
699
- // Ctrl+R / Ctrl+P 历史搜索候选源:惰性工厂——当前会话内存 queryHistory + 最近落盘会话,
700
- // 聚合要读盘,只有面板真正打开(Ctrl+R/P)才求值,平常轮次零开销
701
- history: () => collectQueryHistory(queryHistory).map((e) => e.text),
702
- // /rollback 预填优先;否则上一轮运行中 typeahead 打的字 → 预填进输入框,用户可改可发
703
- ...(pendingPrefill
704
- ? { initialLines: pendingPrefill }
705
- : getRunningInput()
706
- ? { initialLines: [getRunningInput()] }
707
- : {}),
708
- });
700
+ let input;
701
+ let queuedMode = null;
702
+ if (autoSend && queued) {
703
+ input = queued.text.split('\n');
704
+ queuedMode = queued.mode;
709
705
  }
710
- catch {
711
- break; // Ctrl+C(SIGINT)/ 异常 → 退出
706
+ else {
707
+ // 所有斜杠命令和 Agent 轮次共用同一个输出→输入边界,避免某条命令漏写第二个 \n
708
+ // 后下一条 ❯ 气泡紧贴确认文案;已有多余空行也会收敛为恰好一行。
709
+ if (hasSubmittedInput)
710
+ layout.normalizeInputBoundary();
711
+ layout.enterInputMode(t('repl.idle'));
712
+ try {
713
+ const picked = await promptWithSlashMenu({
714
+ prompt: PROMPT,
715
+ commands: buildSlashCommands(),
716
+ onCycleMode: cycleMode,
717
+ // Ctrl+R / Ctrl+P 历史搜索候选源:惰性工厂——当前会话内存 queryHistory + 最近落盘会话,
718
+ // 聚合要读盘,只有面板真正打开(Ctrl+R/P)才求值,平常轮次零开销
719
+ history: () => collectQueryHistory(queryHistory).map((e) => e.text),
720
+ // /rollback 预填优先;否则上一轮运行中 typeahead 打的字 → 预填进输入框,用户可改可发
721
+ ...(pendingPrefill
722
+ ? { initialLines: pendingPrefill }
723
+ : getRunningInput()
724
+ ? { initialLines: [getRunningInput()] }
725
+ : {}),
726
+ });
727
+ if (picked === null)
728
+ break; // 空 prompt Ctrl+D
729
+ input = picked;
730
+ }
731
+ catch {
732
+ break; // Ctrl+C(SIGINT)/ 异常 → 退出
733
+ }
734
+ pendingPrefill = null; // 预填已消费,清空
735
+ clearRunningInput(); // 预填已消费,清空(下轮运行态从空开始)
712
736
  }
713
- pendingPrefill = null; // 预填已消费,清空
714
- clearRunningInput(); // 预填已消费,清空(下轮运行态从空开始)
715
- if (input === null)
716
- break; // 空 prompt Ctrl+D
717
737
  let joined = input.join('\n');
718
738
  const line = joined.trim();
719
739
  if (!line)
720
740
  continue;
741
+ // 排队预加载只对「发给 agent 的需求」自动执行;斜杠命令不静默自动跑
742
+ // (否则排队 /clear、/exit、/rollback 会在用户没看着时触发),改为填回输入框由用户显式确认。
743
+ if (autoSend && isCommandShape(line.split(/\s+/)[0] ?? '')) {
744
+ pendingPrefill = input;
745
+ layout.contentWrite(`${ui.dim} ↳ ${t('repl.queuedCommandHeld')}${ui.reset}\n`);
746
+ continue;
747
+ }
721
748
  hasSubmittedInput = true;
722
749
  if (line === '/exit' || line === '/quit')
723
750
  break;
@@ -830,7 +857,8 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
830
857
  continue; // 与其他命令一致:回 INPUT 态由循环顶部的 normalizeInputBoundary + enterInputMode 负责
831
858
  }
832
859
  const bubbleRows = input.length + 2 + pendingAttachments.length; // N 行 message + 2 行尾随空(含 \n\n 留下的 open current 行) + 每附件 1 行
833
- const shouldCommit = await awaitPendingRecall(input);
860
+ // 排队消息入队时即已确认 → 跳过 500ms 撤回窗口,直接发送。
861
+ const shouldCommit = autoSend || (await awaitPendingRecall(input));
834
862
  if (!shouldCommit) {
835
863
  // 撤回:气泡从内容区擦掉 + 行放回输入框(下轮 promptWithSlashMenu 经 initialLines 消费)+ 切回 INPUT 视觉。
836
864
  // pendingAttachments **保留** —— 撤回的是输入文本不是意图,再发时随消息一起带走
@@ -842,7 +870,8 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
842
870
  }
843
871
  // 只记录已过撤回窗口的真实用户 query;slash 命令和合成执行轮不会走到这里。
844
872
  queryHistory.push(joined);
845
- const initialPlan = getAgentMode() === 'plan'; // 轮首模式(在 runTurn 之前读)
873
+ // 排队消息沿用「入队那一刻」的模式(用户在运行中预加载时选的模式);普通消息读当前模式。
874
+ const initialPlan = (queuedMode ?? getAgentMode()) === 'plan';
846
875
  const turn = await runTurn(joined, initialPlan, placeholder);
847
876
  if (turn.routedCancel) {
848
877
  // 路由阶段 Ctrl+C 撤回:与 500ms 撤回窗口同语义——气泡擦掉 + 行回填输入框
@@ -30,7 +30,7 @@ import { paintInput, repaint } from './input-paint.js';
30
30
  import { WHEEL_LINES, screenRowToAbsLine, repaintViewport, scrollBy, scrollWheel, resetScroll, lockScrollToBottom, } from './scroll.js';
31
31
  import { contentWrite, contentInsertAfter, contentDeleteFrom, contentReplaceLine, reflowContentForResize, flushMdSegment, } from './content-write.js';
32
32
  export { isTuiActive, getGeo, setRegion, contentMode, isStreamingPaused } from './screen.js';
33
- export { drawStatusBar, setStatus, stopTurnTimer, startTurnTimerIfRunning, paintLiveAtCursor, clearLiveAtCursor, setLiveUsage, setStatusBase, } from './statusbar.js';
33
+ export { drawStatusBar, setStatus, stopTurnTimer, startTurnTimerIfRunning, paintLiveAtCursor, clearLiveAtCursor, setLiveUsage, setQueuedTurn, setStatusBase, } from './statusbar.js';
34
34
  export { paintInput, paintRunningInput, repaint } from './input-paint.js';
35
35
  export { isScrolled, repaintViewport, repaintContentLine, scrollBy, scrollWheel, resetScroll, lockScrollToBottom, unlockScroll, isScrollLocked, } from './scroll.js';
36
36
  export { contentWrite, writeBanner, rewriteBanner, bannerHeight, contentWriteMd, contentWriteMdOnce, clearContent, rewindContent, writeWelcomeBlock, dismissWelcomeBlock, contentInsertAfter, contentDeleteFrom, totalRows, isLastContentRowBlank, normalizeMutationBoundary, normalizeInputBoundary, contentReplaceLine, notifyContentReset, } from './content-write.js';
@@ -61,6 +61,10 @@ export const state = {
61
61
  * composeModelLine 在 RUNNING 态把它画成 chip 放 context 进度条左侧;
62
62
  * 不主动触发重画——RUNNING 态 turnTimer 80ms 心跳重画自然取最新值。 */
63
63
  liveUsage: undefined,
64
+ /** 运行态已排队、当前任务结束后自动发送的下一条消息(纯文本摘要,无=undefined)。 */
65
+ queuedText: undefined,
66
+ /** 排队消息入队时的模式,用于在 chip 上标注 Plan/Auto。 */
67
+ queuedMode: undefined,
64
68
  statusText: '',
65
69
  spinnerFrame: undefined,
66
70
  turnStart: null, // RUNNING 态起点(Date.now());INPUT 态为 null。composeStatus 据此拼走时。
@@ -64,6 +64,12 @@ export function composeSpinnerLine(status, cols) {
64
64
  lead = `${ui.accent}●${ui.reset} ${ui.dim}${status.status}${ui.reset}`;
65
65
  leadW = 1 + 1 + displayWidth(status.status);
66
66
  }
67
+ // 排队下一跳:紧跟「● 状态(+走时)」右侧显示,运行中持续可见,当前任务结束即自动发送。
68
+ const queued = queuedChip();
69
+ if (queued) {
70
+ lead += ` ${queued.str}`;
71
+ leadW += 2 + queued.w;
72
+ }
67
73
  // ── 右段:仅滚动回看时显历史指示 ──
68
74
  let tail = '';
69
75
  let tailW = 0;
@@ -371,6 +377,28 @@ export function clearLiveAtCursor() {
371
377
  export function setLiveUsage(u) {
372
378
  state.liveUsage = u;
373
379
  }
380
+ /**
381
+ * 设置/清除运行态已排队的下一条消息 chip(显示在 `● 状态` 右侧)。
382
+ * 立即重画一次保证入队瞬间可见;之后 RUNNING 态 80ms 心跳会自然带上。
383
+ */
384
+ export function setQueuedTurn(text, mode) {
385
+ state.queuedText = text;
386
+ state.queuedMode = mode;
387
+ drawStatusBar();
388
+ }
389
+ /** 排队 chip:▸ 排队: <首行…>(Plan)。只拼左段,宽度另计(不含 ANSI)。 */
390
+ function queuedChip() {
391
+ const raw = state.queuedText;
392
+ if (!raw)
393
+ return null;
394
+ const firstLine = raw.split('\n')[0] ?? '';
395
+ const preview = truncateDisplay(firstLine.trim(), 32);
396
+ const modeTag = state.queuedMode === 'plan' ? t('status.queuePlanTag') : '';
397
+ const label = t('status.queued');
398
+ const plain = `${label} ${preview}${modeTag}`;
399
+ const str = `${ui.yellow}▸ ${plain}${ui.reset}`;
400
+ return { str, w: 2 + displayWidth(plain) };
401
+ }
374
402
  /** 更新状态行基线(模型 / context / cwd / 模式标识 / 活跃 plan chip / 本轮 token chip)。repl 在轮次边界与切模式时调。 */
375
403
  export function setStatusBase(b) {
376
404
  state.base = b;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocode-ai",
3
- "version": "1.7.7",
3
+ "version": "1.7.8",
4
4
  "description": "终端编码 agent:LLM + tool-call 循环 + 流式输出(含思考)+ 27 个工具,接任意 OpenAI 兼容后端。",
5
5
  "type": "module",
6
6
  "bin": {