mocode-ai 0.4.0 → 0.4.2
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.
- package/dist/agent/core.js +81 -16
- package/dist/agent/index.js +18 -2
- package/dist/agent/spawn.js +18 -9
- package/dist/config/index.js +106 -24
- package/dist/context/budget.js +225 -0
- package/dist/context/index.js +5 -2
- package/dist/context/lifecycle.js +384 -0
- package/dist/context/relevance.js +284 -0
- package/dist/llm/index.js +6 -3
- package/dist/memory/index.js +8 -1
- package/dist/memory/store.js +8 -1
- package/dist/repl/index.js +167 -22
- package/dist/session/compact.js +120 -12
- package/dist/session/index.js +5 -0
- package/dist/session/scheduler.js +172 -0
- package/dist/tools/builtins/ask-human.js +79 -3
- package/dist/tools/builtins/grep.js +52 -15
- package/dist/tools/builtins/index.js +20 -5
- package/dist/tools/builtins/read-file.js +15 -5
- package/dist/tools/constants.js +33 -0
- package/dist/ui/layout.js +30 -13
- package/package.json +1 -1
package/dist/tools/constants.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** 工具共享的截断 / 上限 / 忽略规则。 */
|
|
2
|
+
import { isMemoryEnabled } from '../config/index.js';
|
|
2
3
|
export const MAX_FILE_LINES = 2000;
|
|
3
4
|
export const MAX_OUTPUT = 20000;
|
|
4
5
|
export const MAX_RESULTS = 100;
|
|
@@ -22,6 +23,23 @@ export const GC_DAYS = 90;
|
|
|
22
23
|
/** memory_search 结果(召回的记忆正文)的放宽上限:指令性内容,中截破坏语义,对齐 use_skill。 */
|
|
23
24
|
export const MAX_MEMORY_RESULT = 64000;
|
|
24
25
|
export const IGNORE = ['**/node_modules/**', '**/.git/**'];
|
|
26
|
+
// ── Context Budget Scheduler(五区分账)────────────────────────────────────
|
|
27
|
+
/** Hot/Cold 划分:当前 step 起往前 N 个 user turn 之内的工具结果视为 Hot(绝对不压),
|
|
28
|
+
* 之外的视为 Cold(可调度器压)。默认 4 = 跨过 4 个用户问题仍生效。 */
|
|
29
|
+
export const HOT_TURN_WINDOW = 4;
|
|
30
|
+
/** Cold 区内可被就地 stub 的 tool 消息最低 age(经过的消费者 push 数)。默认 2,
|
|
31
|
+
* 与 lifecycle.ts DEFAULT_AGE_THRESHOLD 对齐。 */
|
|
32
|
+
export const TOOL_OLD_AGE = 2;
|
|
33
|
+
/** 五区预算占比(总和 0.95,留 5% 给 Reserve)。对齐 user 修正版:
|
|
34
|
+
* System 15 / History 20 / Hot Tool 25 / Cold Tool 25 / Summary 10。 */
|
|
35
|
+
export const BUDGET_RATIO = {
|
|
36
|
+
system: 0.15,
|
|
37
|
+
history: 0.20,
|
|
38
|
+
toolRecent: 0.25,
|
|
39
|
+
toolOld: 0.25,
|
|
40
|
+
summary: 0.10,
|
|
41
|
+
reserve: 0.05,
|
|
42
|
+
};
|
|
25
43
|
// ── plan 模式(只读规划,不执行)──────────────────────────────────────────────
|
|
26
44
|
/**
|
|
27
45
|
* plan 模式下从工具 schema 里剔除的工具(模型根本看不到 → 调不到):
|
|
@@ -38,3 +56,18 @@ export const PLAN_DISABLED_TOOLS = new Set([
|
|
|
38
56
|
'memory_forget',
|
|
39
57
|
'task',
|
|
40
58
|
]);
|
|
59
|
+
/**
|
|
60
|
+
* 按当前 isMemoryEnabled() 现算 plan 模式应屏蔽的工具。
|
|
61
|
+
* memoryEnabled=false 时记忆工具整体不在 builtinTools 里,plan 屏蔽集里也无须再列 ——
|
|
62
|
+
* 反之留着只是死名字。统一过滤,避免 Set 里残留与已下架工具不一致的概念性冗余。
|
|
63
|
+
* 调用方(agent/core 串行分支、llm/planChatTools)每次 chat 时调本函数拿当前值。
|
|
64
|
+
*/
|
|
65
|
+
export function getPlanDisabledTools() {
|
|
66
|
+
if (isMemoryEnabled())
|
|
67
|
+
return PLAN_DISABLED_TOOLS;
|
|
68
|
+
const next = new Set(PLAN_DISABLED_TOOLS);
|
|
69
|
+
next.delete('memory_save');
|
|
70
|
+
next.delete('memory_update');
|
|
71
|
+
next.delete('memory_forget');
|
|
72
|
+
return next;
|
|
73
|
+
}
|
package/dist/ui/layout.js
CHANGED
|
@@ -742,29 +742,46 @@ function composeSpinnerLine(status, cols) {
|
|
|
742
742
|
const rightStr = tail ? `${ui.yellow}${tail}${ui.reset}` : '';
|
|
743
743
|
return twoColumn(lead, leadW, rightStr, tailW, cols);
|
|
744
744
|
}
|
|
745
|
-
/** 下线之下那行(model 行):左 =
|
|
745
|
+
/** 下线之下那行(model 行):左 = 模式标识 + 本轮 token chip;右 = context + cwd,右端对齐。
|
|
746
746
|
* 活跃 plan chip 不再放这里,改放 spinner 行上方的「虚拟空行」(contentBottom+1,见 drawStatusBar),
|
|
747
747
|
* 既不挤 model 行,又给输入区上方留出可视分隔带。 */
|
|
748
748
|
function composeModelLine(status, cols) {
|
|
749
749
|
const ctx = status.contextBar; // 已带色
|
|
750
750
|
const ctxW = ansiDisplayWidth(ctx);
|
|
751
|
-
//
|
|
751
|
+
// 左段:模式标识 + 本轮 token chip。token chip 仅展示总量,用 mid 灰,不抢主色。
|
|
752
752
|
const modeTag = status.modeTag ?? '';
|
|
753
753
|
const modeColor = modeTag === 'plan' ? ui.yellow : ui.brightCyan;
|
|
754
|
-
const modePart = modeTag
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
const
|
|
758
|
-
|
|
754
|
+
const modePart = modeTag ? `${modeColor}${modeTag}${ui.reset}` : '';
|
|
755
|
+
const modeW = modeTag ? displayWidth(modeTag) : 0;
|
|
756
|
+
const tokChip = formatTurnTokenChip(status.lastTurnUsage);
|
|
757
|
+
const tokW = displayWidth(stripAnsi(tokChip));
|
|
758
|
+
// 合并左段:chip 前留 2 空格分隔,无 modeTag 也允许仅显示 chip(兜底边角)。
|
|
759
|
+
const sep = modePart && tokChip ? ' ' : '';
|
|
760
|
+
const leftStr = `${modePart}${sep}${tokChip}`;
|
|
761
|
+
const leftW = modeW + (modePart && tokChip ? sep.length : 0) + tokW;
|
|
759
762
|
// 右段:ctx + sep + cwd,右端对齐。cwd 按预算截断,极窄(<6)隐藏。
|
|
763
|
+
// 任一 chip 极宽时收紧 cwd(toolbar 列挤压场景),先从 cwd 砍、再隐藏 cwd、再隐藏 token chip。
|
|
760
764
|
const minGap = 2;
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
765
|
+
let cwdBudget = cols - leftW - minGap - ctxW - STATUS_SEP_W - 1;
|
|
766
|
+
let cwd = cwdBudget >= 6 ? truncateDisplay(status.cwd, cwdBudget) : '';
|
|
767
|
+
let cwdW = displayWidth(cwd);
|
|
768
|
+
let rightStr = `${ctx}${STATUS_SEP}${ui.dim}${cwd}${ui.reset}`;
|
|
769
|
+
let rightW = ctxW + STATUS_SEP_W + cwdW;
|
|
770
|
+
// 极窄(<24 列含 ctx):藏 token chip
|
|
771
|
+
if (modePart && tokChip && rightW + minGap + leftW > cols) {
|
|
772
|
+
return twoColumn(modePart, modeW, rightStr, rightW, cols);
|
|
773
|
+
}
|
|
766
774
|
return twoColumn(leftStr, leftW, rightStr, rightW, cols);
|
|
767
775
|
}
|
|
776
|
+
/** 把本轮 token 总量格式化成 chip 文本(纯字符串,带 ANSI 色)。无 usage 返空串。 */
|
|
777
|
+
function formatTurnTokenChip(usage) {
|
|
778
|
+
if (!usage || !usage.totalTokens)
|
|
779
|
+
return '';
|
|
780
|
+
const n = usage.totalTokens;
|
|
781
|
+
const text = n < 1000 ? `${n}` : `${(n / 1000).toFixed(n >= 10000 ? 0 : 1)}k`;
|
|
782
|
+
// 单段:量足够稳定时不显分项,避免无谓视觉负担。chip 用 mid 灰(降优先级)— 模式仍是主色。
|
|
783
|
+
return `${ui.dim}${text} tokens${ui.reset}`;
|
|
784
|
+
}
|
|
768
785
|
/** spinner 行上方的「虚拟空行」(contentBottom+1)。
|
|
769
786
|
* - 有活跃 plan:显「plan: <summary> ▸ N. step」整行左对齐(yellow + dim)
|
|
770
787
|
* - 无活跃 plan:空(保留原分隔视觉,避免内容贴输入区)
|
|
@@ -929,7 +946,7 @@ export function clearLiveAtCursor() {
|
|
|
929
946
|
frameRow = 0;
|
|
930
947
|
frameCol = 0;
|
|
931
948
|
}
|
|
932
|
-
/** 更新状态行基线(模型 / context / cwd / 模式标识 / 活跃 plan chip)。repl 在轮次边界与切模式时调。 */
|
|
949
|
+
/** 更新状态行基线(模型 / context / cwd / 模式标识 / 活跃 plan chip / 本轮 token chip)。repl 在轮次边界与切模式时调。 */
|
|
933
950
|
export function setStatusBase(b) {
|
|
934
951
|
base = b;
|
|
935
952
|
}
|