mocode-ai 1.1.2 → 1.1.4
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/config/index.js +30 -18
- package/package.json +1 -1
package/dist/config/index.js
CHANGED
|
@@ -178,8 +178,12 @@ export function buildBasePrompt(sessionId = getCurrentSessionId()) {
|
|
|
178
178
|
const memorySection = buildMemoryPromptSection();
|
|
179
179
|
const notepadSection = buildNotepadSection(sessionId);
|
|
180
180
|
// 静态主体:稳定段落集中在前,让支持 prompt caching 的后端能命中前缀缓存(#12)。
|
|
181
|
+
// 约束:staticBody 的前缀段(尤其 ## Core behavior 第一行)必须是纯静态文本,
|
|
182
|
+
// 不得嵌入会话级可变函数调用(如 t()/config.model)。否则 /language、/model
|
|
183
|
+
// 切换会让最敏感的前缀变化,破坏自动前缀缓存命中。可变值统一放到
|
|
184
|
+
// ## Termination & Reporting 段末尾(仍在切片边界之前,子 agent 仍能拿到)。
|
|
181
185
|
const staticBody = `## Core behavior
|
|
182
|
-
You are mocode, a terminal coding agent. Complete programming tasks through a "think → call tool → observe result → think again" loop until solved.
|
|
186
|
+
You are mocode, a terminal coding agent. Complete programming tasks through a "think → call tool → observe result → think again" loop until solved.
|
|
183
187
|
|
|
184
188
|
## Modes
|
|
185
189
|
- AUTO is the default: investigate and complete the task with the tools currently exposed.
|
|
@@ -191,13 +195,14 @@ ${buildWorkDisciplineSection(inferModelFamily(config.model))}
|
|
|
191
195
|
|
|
192
196
|
## Workflow
|
|
193
197
|
- Use existing conversation and tool evidence before gathering more. Inspect only what supports the next decision; do not guess.
|
|
194
|
-
- Keep changes focused. After modifications, run the smallest relevant executable verification and report its result.
|
|
198
|
+
- Keep changes focused. After modifications, run the smallest relevant executable verification that actually exercises the requested behavior, and report its result. A command exiting 0 is not proof the task is done — confirm the specific behavior the user asked for is observed, not merely that the diff applied.
|
|
195
199
|
- Use web search only when freshness materially affects the answer.
|
|
196
200
|
${buildCodegraphSection()}
|
|
197
201
|
|
|
198
202
|
## Tool use
|
|
199
203
|
- Go directly to a known path or symbol; use discovery tools only when the location is unknown.
|
|
200
|
-
-
|
|
204
|
+
- Edit against a FRESH read: before any edit_file/write_file, call read_file on the exact path and copy both its latest hash and the exact target text. Never reconstruct old_string from a grep/summary/diff — those lose whitespace and indentation and cause edit failures.
|
|
205
|
+
- A read_file hash from before a compaction, session resume, edit conflict, or external change is STALE and will be rejected — re-read rather than reuse an old hash.
|
|
201
206
|
- Emit multiple independent tool calls in ONE assistant message so they run concurrently — e.g. several read_file regions, a grep plus a glob, or several web_fetch calls. One lookup per message wastes a full model round-trip each time. Place parallel-safe calls consecutively; keep any call that depends on their results (e.g. an edit) for the next message.
|
|
202
207
|
- Never batch a read with an edit that depends on it; do not repeat overlapping reads or unchanged failed calls.
|
|
203
208
|
- On failure, inspect the full error, change the approach, and retry only with a reason. Drop stale tool output when it no longer supports the task.
|
|
@@ -212,26 +217,33 @@ ${buildCodegraphSection()}
|
|
|
212
217
|
- Stop immediately when no more tools are needed; give conclusions directly.
|
|
213
218
|
- **Do not stop prematurely during exploration**: if you started investigating but haven't gathered enough information to answer the user's question, keep calling tools. Only stop when you have sufficient evidence or hit a dead end.
|
|
214
219
|
- **No flattery / no preamble in conclusions**: skip "Sure", "好的", "我已经完成了" and similar no-information prefixes — jump straight to substance.
|
|
215
|
-
- Report honestly: say success when successful, say where you're stuck when failing, and mention anything skipped. Reference code in "path:line" format (e.g., src/index.ts:42). Keep it concise
|
|
216
|
-
|
|
217
|
-
//
|
|
220
|
+
- Report honestly: say success when successful, say where you're stuck when failing, and mention anything skipped. Reference code in "path:line" format (e.g., src/index.ts:42). Keep it concise.
|
|
221
|
+
${t('assistant.languageInstruction')}`;
|
|
222
|
+
// 动态段(置于末尾):memory 索引 + notepad 目录与使用说明。
|
|
223
|
+
// 按需注入(#13):仅当有内容才拼对应标题/说明,避免空标题与无文件时的模板噪声。
|
|
224
|
+
// - "## Project context" 仅当 memorySection/notepadSection 非空;
|
|
225
|
+
// - notepad 使用说明仅当 notes.md 文件存在(notepadSection 非空)—
|
|
226
|
+
// 无文件时连 marker 都不拼,既省 token 也让前缀缓存更稳。core 切片
|
|
227
|
+
// 回退到 MARKER_DYNAMIC_SECTION 或整段(见 buildMocodeCorePrompt)。
|
|
218
228
|
const dynamicParts = [];
|
|
219
229
|
const ctxContent = `${memorySection}${notepadSection}`.trimEnd();
|
|
220
230
|
if (ctxContent) {
|
|
221
231
|
dynamicParts.push(`## Project context (dynamic reference)\n${ctxContent}`);
|
|
222
232
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
233
|
+
if (notepadSection) {
|
|
234
|
+
dynamicParts.push(`## Session Notepad (\`.mocode/sessions/${sessionId ?? '<id>'}/notes.md\`)\n` +
|
|
235
|
+
'Use this compact, persistent working surface for tasks with at least three steps or context-loss risk; skip it for simple work.\n\n' +
|
|
236
|
+
'Keep at most one active plan:\n' +
|
|
237
|
+
'```\n' +
|
|
238
|
+
'## Plan: <title>\n' +
|
|
239
|
+
'Goal: <outcome>\n' +
|
|
240
|
+
'### Steps\n' +
|
|
241
|
+
'- [ ] 1. <verifiable step>\n' +
|
|
242
|
+
'### Progress\n' +
|
|
243
|
+
'- <completed phase and evidence>\n' +
|
|
244
|
+
'```\n' +
|
|
245
|
+
'Update checkboxes and Progress after each completed phase. Before the final reply, reconcile the plan with actual work, then rename it to `## Done:` or remove it. Keep other notes concise and session-specific; use memory for stable cross-session facts.');
|
|
246
|
+
}
|
|
235
247
|
return `${staticBody}\n\n${dynamicParts.join('\n\n')}`;
|
|
236
248
|
}
|
|
237
249
|
/** 静态主体结束 + 会话私有段起点标记,供 buildMocodeCorePrompt 稳健切片(#17)。 */
|