Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): address predict-prompt review — placeholder fallback, output validation, log redaction

Shinku30dd8329770a
diff --git a/apps/desktop/src/main/maker-host/provider-one-shot.ts b/apps/desktop/src/main/maker-host/provider-one-shot.ts
index a559254ca0..f324760d3d 100644
--- a/apps/desktop/src/main/maker-host/provider-one-shot.ts
+++ b/apps/desktop/src/main/maker-host/provider-one-shot.ts
@@ -222,7 +222,7 @@ export function buildOneShotTarget(providerId: string): ProviderOneShotTarget |
if (!base) return null;
const model = pickXdTitleModel(provider);
if (!model) {
- log.debug('title oneShot skipped: no usable chat model in xd gateway catalog', {
+ log.debug('oneShot skipped: no usable chat model in xd gateway catalog', {
providerId,
});
return null;
@@ -436,7 +436,11 @@ export async function runProviderOneShot(
sessionId: args.sessionId,
agentKind: args.agentKind,
promptLen: args.prompt.length,
- opts,
+ maxTokens: opts?.maxTokens,
+ maxOutputChars: opts?.maxOutputChars,
+ maxVisualChars: opts?.maxVisualChars,
+ hasCodexInstructions: opts?.codexInstructions != null,
+ hasSystemPrompt: opts?.systemPrompt != null,
});
// 默认走吃系统代理的 undici fetch:上游可能是境外端点(catalog routing.upstream)。
@@ -467,13 +471,13 @@ export async function runProviderOneShot(
}
if (!providerId) {
- log.debug('title oneShot skipped: no connected provider', { agentKind: args.agentKind });
+ log.debug('oneShot skipped: no connected provider', { agentKind: args.agentKind });
return null;
}
const target = buildOneShotTarget(providerId);
if (!target) {
- log.debug('title oneShot skipped: no title target', { providerId, agentKind: args.agentKind });
+ log.debug('oneShot skipped: no one-shot target', { providerId, agentKind: args.agentKind });
return null;
}
// 标题模型这份拷贝被用户停用 → 跳过(回落启发式起名)。rail 条目带 buildRegistry
@@ -487,7 +491,7 @@ export async function runProviderOneShot(
? titleRouteUnavailableReason(titleCatalogModel, railProvider?.source === 'user')
: null;
if (initialUnavailableReason) {
- log.debug('title oneShot skipped: title model unavailable for new route', {
+ log.debug('oneShot skipped: title model unavailable for new route', {
providerId,
model: target.model,
reason: initialUnavailableReason,
@@ -533,7 +537,7 @@ export async function runProviderOneShot(
const canDispatchNow = (stage: string): boolean => {
const reason = routeUnavailableNow();
if (!reason) return true;
- log.debug('title oneShot skipped: route unavailable before dispatch', {
+ log.debug('oneShot skipped: route unavailable before dispatch', {
providerId,
model: target.model,
reason,
@@ -553,7 +557,7 @@ export async function runProviderOneShot(
case 'anthropic-messages': {
const oauth = await readAnthropicOAuth();
if (!oauth?.accessToken) {
- log.debug('title oneShot skipped: no anthropic OAuth', { providerId });
+ log.debug('oneShot skipped: no anthropic OAuth', { providerId });
return null;
}
if (!canDispatchNow('after-credential-refresh')) return null;
@@ -577,14 +581,14 @@ export async function runProviderOneShot(
case 'codex-responses': {
const creds = readCodexCreds();
if (!creds) {
- log.debug('title oneShot skipped: no codex creds', { providerId });
+ log.debug('oneShot skipped: no codex creds', { providerId });
return null;
}
if (!canDispatchNow('after-credential-read')) return null;
log.debug('oneShot request body (codex)', {
model: target.model,
effort: target.effort,
- instructions: codexInstructions,
+ instructionsLen: codexInstructions.length,
promptLen: args.prompt.length,
});
text = await fetchCodexTitle(
@@ -603,7 +607,7 @@ export async function runProviderOneShot(
case 'gateway-chat': {
const key = readGatewayKey();
if (!key) {
- log.debug('title oneShot skipped: no gateway key', { providerId });
+ log.debug('oneShot skipped: no gateway key', { providerId });
return null;
}
if (!canDispatchNow('after-credential-read')) return null;
@@ -641,7 +645,7 @@ export async function runProviderOneShot(
? Array.from(normalized).slice(0, maxVisualChars).join('')
: normalized;
if (!result) {
- log.warn('title oneShot rejected invalid model output', {
+ log.warn('oneShot rejected invalid model output', {
providerId,
model: target.model,
wire: target.wire,
@@ -649,7 +653,7 @@ export async function runProviderOneShot(
});
return null;
}
- log.info('title oneShot done', {
+ log.info('oneShot done', {
providerId,
model: target.model,
wire: target.wire,
@@ -658,7 +662,7 @@ export async function runProviderOneShot(
});
return result;
} catch (err) {
- log.warn('title oneShot failed (swallowed)', {
+ log.warn('oneShot failed (swallowed)', {
providerId,
model: target.model,
wire: target.wire,
diff --git a/apps/desktop/src/main/maker-ipc/promptPrediction.ts b/apps/desktop/src/main/maker-ipc/promptPrediction.ts
index ff85fe69f6..ef19dda661 100644
--- a/apps/desktop/src/main/maker-ipc/promptPrediction.ts
+++ b/apps/desktop/src/main/maker-ipc/promptPrediction.ts
@@ -79,7 +79,7 @@ function buildPredictionPrompt(
ja: "Match the user's language. The user types in Japanese.",
ko: "Match the user's language. The user types in Korean.",
};
- const wdLine = workingDir ? `Current working directory: ${workingDir}` : null;
+ const wdLine = workingDir ? `Current working directory: ${escapeReferenceData(workingDir)}` : null;
// 系统指令写入 Anthropic Messages API 顶层 system 字段(非 Anthropic wire 忽略),
// 不混入 user message,避免被 Anthropic API 拒绝。
@@ -181,7 +181,7 @@ export async function generatePromptPrediction(
// - maxTokens=96: 标题仅需 32 token,预测 ≤140 chars 需要更多
// - codexInstructions: 告诉模型这是预测而非标题
// - systemPrompt: Anthropic Messages API 顶层 system 字段(非 Anthropic wire 忽略)
- // - maxOutputChars=0: 跳过 validateTitleOutput(该函数面向单行标题,拒绝多行/长文本)
+ // - maxOutputChars=512: 恢复 validateTitleOutput 输出校验(拦截多行/Markdown/role label),再交给 maxVisualChars=140 做展示截断
// - maxVisualChars=140: 截断到推荐提示词上限
return runProviderOneShot(
{
@@ -198,7 +198,7 @@ export async function generatePromptPrediction(
codexInstructions:
'Output only the predicted next user message — no quotes, markdown, or commentary.',
systemPrompt,
- maxOutputChars: 0,
+ maxOutputChars: 512,
maxVisualChars: 140,
},
);
diff --git a/apps/desktop/src/renderer/__tests__/composerPlaceholderCss.test.ts b/apps/desktop/src/renderer/__tests__/composerPlaceholderCss.test.ts
index 5dffa2a64d..1e8d885549 100644
--- a/apps/desktop/src/renderer/__tests__/composerPlaceholderCss.test.ts
+++ b/apps/desktop/src/renderer/__tests__/composerPlaceholderCss.test.ts
@@ -16,4 +16,10 @@ describe('composer placeholder CSS', () => {
"[data-voice-draft-active='true'] .ProseMirror > p.is-empty:first-child:only-child::before {",
);
});
+
+ it('keeps the native placeholder hidden while a recommendation overlay is active (is-empty fallback included)', () => {
+ expect(globalsSource).toContain(
+ "[data-recommendation-active='true'] .ProseMirror > p.is-empty:first-child:only-child::before {",
+ );
+ });
});
diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
index d2883c9670..9a9192b8ad 100644
--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
@@ -6394,8 +6394,9 @@ export function ChatInput({
const hasMessage = !isEditorEmpty(editor);
renderSnapshotRef.current = composerRenderSnapshot(trigger, hasMessage);
const canSend = hasMessage || hasAttachments || browserComments.length > 0;
- // 推荐 overlay 的唯一可见判据:有推荐词 + 输入框空 + 不在语音态。
- const showRecommendationOverlay = !!recommendedPrompt && !hasMessage && !voiceInput.isBusy;
+ // 推荐 overlay 的唯一可见判据:开关开启 + 有推荐词 + 输入框空 + 不在语音态。
+ const showRecommendationOverlay =
+ recommendationEnabled && !!recommendedPrompt && !hasMessage && !voiceInput.isBusy;
const hasVoiceDraftText = voiceInput.draftText.trim().length > 0;
const [voiceReleaseToSendActive, setVoiceReleaseToSendActive] = useState(false);
const sendButtonDisabled = Boolean(
@@ -7109,7 +7110,12 @@ export function ChatInput({
<span
ref={sendButtonRef}
className="inline-flex rounded-full"
- onMouseDown={(event) => event.preventDefault()}
+ onMouseDown={(event) => {
+ // 只在编辑器已聚焦时压默认聚焦:点发送会先把焦点从
+ // contenteditable 挪到 button 上,发完光标就没了;
+ // 编辑器未聚焦时保留按钮正常聚焦行为(可访问性)。
+ if (editor?.isFocused) event.preventDefault();
+ }}
>
{mainSlotIsStop ? (
<SendButton
diff --git a/apps/desktop/src/renderer/components/settings/TipsSection.tsx b/apps/desktop/src/renderer/components/settings/TipsSection.tsx
index e1c33d5d9b..9882e5f94b 100644
--- a/apps/desktop/src/renderer/components/settings/TipsSection.tsx
+++ b/apps/desktop/src/renderer/components/settings/TipsSection.tsx
@@ -60,7 +60,7 @@ export function TipsSection() {
'[&>*+*]:border-t [&>*+*]:border-[var(--settings-theme-card-border)]',
)}
>
- {/* 输入框推荐提示词:任务结束后自动预测用户下一步输入 */}
+ {/* 输入框推荐提示词:turn 结束后自动预测用户下一步输入 */}
<div className="flex items-center justify-between gap-3 px-4 py-[14px]">
<div className="flex items-center gap-3">
<div
diff --git a/apps/desktop/src/renderer/styles/globals.css b/apps/desktop/src/renderer/styles/globals.css
index 4cd36aa52b..7932eccc3b 100644
--- a/apps/desktop/src/renderer/styles/globals.css
+++ b/apps/desktop/src/renderer/styles/globals.css
@@ -405,7 +405,8 @@ html:lang(ko) {
content: none;
}
/* 输入框推荐提示词生效时,推荐词由 ChatInput 的 overlay 承载,关掉原生 placeholder。 */
-[data-recommendation-active='true'] .ProseMirror > p.is-editor-empty:first-child::before {
+[data-recommendation-active='true'] .ProseMirror > p.is-editor-empty:first-child::before,
+[data-recommendation-active='true'] .ProseMirror > p.is-empty:first-child:only-child::before {
content: none;
}
.ProseMirror {