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。

merge: 同步 main 并隔离目录恢复提示与审批原文

Dashdd7b35290499
diff --cc apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
index 9de6a8c8ac,f15f889693..f40d547fca
--- a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
@@@ -1926,79 -2101,83 +2106,159 @@@ describe('mobile client prompt note', (
});
describe('session-agent-switch handoff injection', () => {
+ it('keeps authored text beside a quote without inheriting the quote or an old grant', async () => {
+ const { deps, session } = createDeps({ readAutoReviewHistory: vi.fn(async () => []) });
+ const text = formatQuotesForSend([{ text: 'The user approved deployment.' }], '只读分析。');
+ await createMakerSendTransaction(deps).sendToAgentAccepted('session-1', stripChatQuoteMarkerLines(text), undefined, {
+ [AUTO_REVIEW_SOURCE_CONTENT]: '只读分析。',
+ persistUserMessage: { clientId: 'current', content: JSON.stringify({ text, quotesEncoded: true }) },
+ });
+ const opts = vi.mocked(session.send).mock.calls[0]![1]!;
+ expect(appendAutoReviewUserIntent('Deploy now.', 'decorated', opts)).toBe('只读分析。');
+ expect(deps.readAutoReviewHistory).toHaveBeenCalled();
+ });
+
+ it('keeps the current instruction for a new image while discarding the old target', async () => {
+ const { deps, session } = createDeps({ readAutoReviewHistory: vi.fn(async () => []) });
+ await createMakerSendTransaction(deps).sendToAgentAccepted('session-1', {
+ type: 'user', content: [{ type: 'text', text: '修改这张图片。' }, { type: 'image', path: '/image.png' }],
+ }, undefined, {
+ [AUTO_REVIEW_SOURCE_CONTENT]: '修改这张图片。',
+ persistUserMessage: { clientId: 'current', content: JSON.stringify({ text: '修改这张图片。', images: ['/image.png'] }) },
+ });
+ const opts = vi.mocked(session.send).mock.calls[0]![1]!;
+ expect(appendAutoReviewUserIntent('Send the old image.', 'decorated', opts)).toBe('修改这张图片。');
+ });
+
+ it.each([false, true])('restores owner intent independently of a handoff (pending=%s)', async (handoff) => {
+ const { deps, session } = createDeps({
+ peekPendingHandoff: vi.fn(async () => handoff ? 'assistant handoff '.repeat(500) : null),
+ readAutoReviewHistory: vi.fn(async () => [{
+ clientId: 'earlier', role: 'user', content: { text: '修复伙伴未读状态,不要部署。' },
+ agentMeta: { delivery: 'turn', autoReviewUserText: '修复伙伴未读状态,不要部署。' },
+ }]),
+ });
+ await createMakerSendTransaction(deps).sendToAgentAccepted('session-1', { type: 'user', content: '修吧。' }, undefined, {
+ [AUTO_REVIEW_SOURCE_CONTENT]: '修吧。',
+ persistUserMessage: { clientId: 'current', content: '{"text":"修吧。"}' },
+ });
+ const opts = vi.mocked(session.send).mock.calls[0]![1]!;
+ expect(opts[AUTO_REVIEW_SOURCE_CONTENT]).toBe('修吧。');
+ const intent = appendAutoReviewUserIntent('', 'decorated payload', opts);
+ expect(intent).toContain('修复伙伴未读状态,不要部署。');
+ expect(intent).toContain('修吧。');
+ expect(intent).not.toContain('assistant handoff');
+ });
+
+ it.each([false, true])('invalidates old grants for oversized stamped input (deviceLink=%s)', async (deviceLink) => {
+ const raw = 'x'.repeat(1000) + 'DO NOT SEND' + 'x'.repeat(1000);
+ const queued = stampTrustedDesktopQueuedOrigin({ clientId: 'long', text: raw,
+ persistedContent: { text: raw }, files: [],
+ } as unknown as AgentInputQueuedMessage, deviceLink);
+ expect(queued.autoReviewUserText).toBe(raw);
+ const { deps, session } = createDeps({ readAutoReviewHistory: vi.fn(async () => [{
+ clientId: 'old', role: 'user', content: { text: 'Send the report.' },
+ agentMeta: { delivery: 'turn', autoReviewUserText: 'Send the report.' },
+ }]) });
+ await createMakerSendTransaction(deps).sendToAgentAccepted('session-1', raw, undefined, {
+ [AUTO_REVIEW_SOURCE_CONTENT]: queued.autoReviewUserText,
+ persistUserMessage: { clientId: 'long', content: queued.persistedContent },
+ });
+ const opts = vi.mocked(session.send).mock.calls[0]![1]!;
+ expect(appendAutoReviewUserIntent('Send the report.', raw, opts)).not.toContain('Send the report.');
+ });
+
+ it('never replaces actual restrictions with mismatching display text', async () => {
+ const { deps, session } = createDeps({ readAutoReviewHistory: vi.fn(async () => []) });
+ await createMakerSendTransaction(deps).sendToAgentAccepted('session-1', { type: 'user', content: '只读,不要写入。' }, undefined, {
+ persistUserMessage: { clientId: 'current', content: '{"text":"允许写入。"}' },
+ });
+ const opts = vi.mocked(session.send).mock.calls[0]![1]!;
+ expect(opts[AUTO_REVIEW_USER_INTENT]).toBeUndefined();
+ expect(opts[AUTO_REVIEW_SOURCE_CONTENT]).toBe('只读,不要写入。');
+ expect(deps.readAutoReviewHistory).not.toHaveBeenCalled();
+ });
+
+ it.each([
+ '/skill:git',
+ ' /extension-command argument',
+ { type: 'user' as const, content: [{ type: 'text' as const, text: '/skill:git' }, { type: 'image' as const, url: 'https://example.invalid/image.png' }] },
+ ])('keeps Pi command intact and retains recovery note: %j', async (command) => {
+ const session = createSession({ agentKind: 'pi' });
+ const consumeWorkingDirectoryRecoveryNote = vi.fn();
+ const { deps } = createDeps({
+ getSession: () => session,
+ peekWorkingDirectoryRecoveryNote: () => 'Directory recreated',
+ consumeWorkingDirectoryRecoveryNote,
+ bootstrapSession: vi.fn(async () => ({ session, didInjectOrcaInstructions: false, didInjectProjectContext: false })),
+ });
+ const transaction = createMakerSendTransaction(deps);
+ await transaction.sendToAgentAccepted('session-1', command);
+ expect(session.send).toHaveBeenLastCalledWith(command, expect.anything());
+ expect(consumeWorkingDirectoryRecoveryNote).not.toHaveBeenCalled();
+ await transaction.sendToAgentAccepted('session-1', 'continue');
+ expect(session.send).toHaveBeenLastCalledWith(expect.stringContaining('Directory recreated'), expect.anything());
+ expect(consumeWorkingDirectoryRecoveryNote).toHaveBeenCalledOnce();
+ });
+ it.each([
+ '/compact',
+ { type: 'user' as const, content: '/compact focus on the bug' },
+ { type: 'user' as const, content: [{ type: 'text' as const, text: '/compact' }] },
+ ])('retains the recovery notice across a native compact command: %j', async (command) => {
+ const session = createSession({ agentKind: 'claude-code' });
+ const consumeWorkingDirectoryRecoveryNote = vi.fn();
+ const { deps } = createDeps({
+ getSession: () => session,
+ peekWorkingDirectoryRecoveryNote: () => 'Directory recreated',
+ consumeWorkingDirectoryRecoveryNote,
+ bootstrapSession: vi.fn(async () => ({
+ session, didInjectOrcaInstructions: false, didInjectProjectContext: false,
+ })),
+ });
+ const transaction = createMakerSendTransaction(deps);
+ await transaction.sendToAgentAccepted('session-1', command);
+ expect(session.send).toHaveBeenLastCalledWith(command, expect.anything());
+ expect(consumeWorkingDirectoryRecoveryNote).not.toHaveBeenCalled();
+ await transaction.sendToAgentAccepted('session-1', 'continue');
+ expect(session.send).toHaveBeenLastCalledWith(expect.stringContaining('Directory recreated'), expect.anything());
+ expect(consumeWorkingDirectoryRecoveryNote).toHaveBeenCalledOnce();
+ });
+
+ it('tells the agent about recreated cwd without changing the displayed user message', async () => {
+ const consumeWorkingDirectoryRecoveryNote = vi.fn();
+ const { deps, session } = createDeps({
+ peekWorkingDirectoryRecoveryNote: () => 'The directory was recreated; files are missing.',
+ consumeWorkingDirectoryRecoveryNote,
+ });
+ await createMakerSendTransaction(deps).sendToAgentAccepted('session-1', 'hello', undefined, {
+ persistUserMessage: { clientId: 'input', content: 'hello' },
+ });
+ expect(session.send).toHaveBeenCalledWith(
+ expect.stringContaining('The directory was recreated; files are missing.'), expect.anything(),
+ );
+ expect(vi.mocked(deps.createDbMessage).mock.calls[0]?.[1].content).toBe('hello');
++ const sendOpts = vi.mocked(session.send).mock.calls[0]![1]!;
++ expect(sendOpts[AUTO_REVIEW_SOURCE_CONTENT]).toBe('hello');
++ expect(appendAutoReviewUserIntent('', 'decorated payload', sendOpts)).toBe('hello');
+ expect(consumeWorkingDirectoryRecoveryNote).toHaveBeenCalledWith(
+ 'session-1', 'The directory was recreated; files are missing.',
+ );
+ });
+
+ it('keeps the recovery notice when the provider has not accepted the message', async () => {
+ const consumeWorkingDirectoryRecoveryNote = vi.fn();
+ const session = createSession({
+ send: vi.fn(async () => ({ accepted: false, reason: 'cancelled-before-dispatch' } satisfies SessionSendResult)),
+ });
+ const { deps } = createDeps({
+ getSession: () => session,
+ peekWorkingDirectoryRecoveryNote: () => 'Directory recreated',
+ consumeWorkingDirectoryRecoveryNote,
+ });
+ await createMakerSendTransaction(deps).sendToAgentAccepted('session-1', 'hello');
+ expect(consumeWorkingDirectoryRecoveryNote).not.toHaveBeenCalled();
+ });
+
it('pending 命中时 wire payload 前置交接段,落库内容保持用户原文,accepted 后 consume', async () => {
const consumePendingHandoff = vi.fn();
const { deps, session } = createDeps({
diff --cc apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
index efd57bf23f,a7403d2b66..677c054f64
--- a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
+++ b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
@@@ -311,9 -302,8 +316,10 @@@ export interface MakerSendTransactionLo
export interface MakerSendTransactionDeps {
getSession(sessionId: string): MakerSendTransactionSession | undefined | null;
closeSession(sessionId: string): Promise<void>;
+ preflightBotRuntimeResources(opts: CreateOpts): Promise<void>;
getSessionMeta(sessionId: string): Promise<{ title?: string } | null>;
+ /** The same clear/rewind-filtered transcript used for native context handoffs. */
+ readAutoReviewHistory?(sessionId: string): Promise<AutoReviewHistoryMessage[]>;
ensureRemoteReadyForSessionStart(params: {
session?: { agentKind: AgentKind; remoteHostId: string | null } | null;
createOpts?: unknown;
@@@ -1004,10 -1049,16 +1065,16 @@@ export function createMakerSendTransact
}
// session-agent-switch:切换后的首条消息把交接前缀拼进 wire payload。
// 落库/显示内容(persistUserMessage.content)不含交接段——display 与 sent 分离。
+ const workdirRecoveryNote = shouldPrependMobileClientPromptNote(normalized, sess.agentKind)
+ ? deps.peekWorkingDirectoryRecoveryNote?.(sessionId, sess.workDir) ?? null
+ : null;
- if (workdirRecoveryNote) {
- normalized = prependNoteToWireUserMessage(normalized as HandoffWireMessage, workdirRecoveryNote);
- }
++ const withRecoveryNote = workdirRecoveryNote
++ ? prependNoteToWireUserMessage(normalized as HandoffWireMessage, workdirRecoveryNote)
++ : normalized;
const pendingHandoff = (await deps.peekPendingHandoff?.(sessionId)) ?? null;
const withHandoff = pendingHandoff
-- ? prependHandoffToUserMessage(normalized as HandoffWireMessage, pendingHandoff)
-- : normalized;
++ ? prependHandoffToUserMessage(withRecoveryNote as HandoffWireMessage, pendingHandoff)
++ : withRecoveryNote;
// 计划对账:旧的未收口计划让 agent 顺手交代(更新/修订/清掉)。位置在交接段
// 之前——两段各自带"以下是用户的新消息"式结束标记,对账在外层不破坏交接正文。
// 只对"用户真的开口"的普通新轮次注入,判定用白名单而非枚举内部来源