Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(auto-review): preserve pasted user authorization
321sssrt-bitdaa0eafd00fd
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.tsindex b6485006ed..f6dff5b40c 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts@@ -4,12 +4,38 @@ import {AUTO_REVIEW_DELEGATED_CONTINUATION,restoreAutoReviewUserIntent,restoreAutoReviewSteerIntent,+ readAutoReviewUserText,currentAutoReviewResourceIntent,type AutoReviewHistoryMessage,} from '../autoReviewUserIntent';import { projectPersistedAgentFacingUserText } from '@cindy/maker-shared/agent-input-projection';import { formatQuoteForSend, formatQuotesForSend } from '@cindy/maker-shared/chat-quotes';+describe('pasted authored text', () => {+ // #7424 / unit: production readText/resource projection must preserve exact owner authorization.+ // Existing negatives cover structured resources, not paste-only or mixed input; the minimal old+ // failure is any non-empty pastedTextRanges returning null/''. Long paste and restrictions are observable auth evidence.+ const longPaste = Array.from({ length: 24 }, (_, index) => `第 ${index + 1} 行:允许本地修改和测试。`).join('\n');+ it.each([+ { name: 'full paste', prefix: '', pasted: `${longPaste}\n不要 push、不要发布。`, suffix: '' },+ { name: 'mixed input', prefix: '先检查现状。\n', pasted: longPaste,+ suffix: '\n允许本地修改和测试,但不要 push、不要发布。' },+ ])('preserves the complete authorization for $name', ({ prefix, pasted, suffix }) => {+ const text = `${prefix}${pasted}${suffix}`;+ const content = { text, pastedTextRanges: [{ start: prefix.length, end: prefix.length + pasted.length }] };+ expect(readAutoReviewUserText(content)).toBe(text);+ expect(currentAutoReviewResourceIntent(content, text)).toBe(text);+ expect(currentAutoReviewResourceIntent(content, projectPersistedAgentFacingUserText(content)!)).toBe(text);+ });++ it('restores a persisted pasted message once on retry', () => {+ const text = '允许本地修改和测试,但不要 push、不要发布。';+ const content = { text, pastedTextRanges: [{ start: 0, end: text.length }] };+ const message = { ...user(text, 'pasted'), content };+ expect(restoreAutoReviewUserIntent([message], { clientId: 'pasted', content })).toBe(text);+ });+});+describe('authored text beside structured references', () => {// unit: Composer list markers are structure, not an owner's new request.it.each(['- ', '2) ', '3、', '+ \n • '])('discards reference-only list scaffolding %j without discarding real words', prefix => {@@ -35,7 +61,7 @@ describe('authored text beside structured references', () => {expect(currentAutoReviewResourceIntent(content, text).trim()).toBe(request);expect(currentAutoReviewResourceIntent(content, wire).trim()).toBe(request);expect(currentAutoReviewResourceIntent(content, `${wire} changed`)).toBe('');- expect(currentAutoReviewResourceIntent({ ...content, pastedTextRanges: [{}] }, wire)).toBe('');+ expect(currentAutoReviewResourceIntent({ ...content, pastedTextRanges: [{}] }, wire).trim()).toBe(request);const invalid = { ...content, agentReferences: [{ ...content.agentReferences[0], end: href.length + 1 }] };expect(currentAutoReviewResourceIntent(invalid, projectPersistedAgentFacingUserText(invalid)!)).toBe('');});@@ -271,7 +297,6 @@ describe('restored Auto authorization', () => {it.each([{ quotesEncoded: true },{ sessionReferences: [{}] },- { pastedTextRanges: [{}] },{ images: [{}] },{ files: [{}] },])(diff --git a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.tsindex 873c035a16..ca947065dd 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts@@ -3553,6 +3553,34 @@ describe('session-agent-switch handoff injection', () => {agentMeta: stored!.agentMeta as Record<string, unknown> }])).toBe(request);});+ // #7424 / unit: the trusted queue and accepted transaction must persist the exact pasted owner request.+ // Adjacent reference tests did not cover paste ranges; the minimal old failure stamps '' for text + ranges.+ it.each([false, true])('preserves pasted authorization through queue and persistence (deviceLink=%s)', async deviceLink => {+ const text = '允许本地修改和测试,但不要 push、不要发布。';+ const content = { text, pastedTextRanges: [{ start: 0, end: text.length }] };+ const queued = stampTrustedDesktopQueuedOrigin({ clientId: 'pasted-request', text,+ persistedContent: content, files: [],+ } as unknown as AgentInputQueuedMessage, deviceLink);+ expect(queued.autoReviewUserText).toBe(text);+ const { deps, session } = createDeps();+ await createMakerSendTransaction(deps).sendToAgentAccepted('session-1', text, undefined, {+ [AUTO_REVIEW_SOURCE_CONTENT]: queued.autoReviewUserText,+ persistUserMessage: { clientId: queued.clientId, content, delivery: 'turn' },+ });+ expect(vi.mocked(session.send).mock.lastCall?.[1]?.[AUTO_REVIEW_USER_INTENT]).toBe(text);+ expect(vi.mocked(deps.createDbMessage).mock.lastCall?.[1].agentMeta?.autoReviewUserText).toBe(text);+ });++ it.each([false, true])('rejects pasted authorization when persisted and wire text diverge (deviceLink=%s)', deviceLink => {+ const persisted = { text: '允许 push。', pastedTextRanges: [{ start: 0, end: 6 }] };+ for (const persistedContent of [persisted, JSON.stringify(persisted)]) {+ const queued = stampTrustedDesktopQueuedOrigin({ clientId: 'pasted-mismatch', text: '不要 push。',+ persistedContent, files: [],+ } as unknown as AgentInputQueuedMessage, deviceLink);+ expect(queued.autoReviewUserText).toBe('');+ }+ });+// unit: a forwarded quote must survive persistence without becoming permission.it('persists host request evidence without restoring the target previous grant', async () => {const { deps, session } = createDeps({ readAutoReviewHistory: async () => [{diff --git a/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts b/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.tsindex b2a5e93744..d4a427d049 100644--- a/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts+++ b/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts@@ -64,10 +64,8 @@ export function currentAutoReviewResourceIntent(// Queue admission carries Composer text; direct consumers may already carry// its agent-facing projection. Both must match this same persisted envelope.if (value.text !== wireText && projectPersistedAgentFacingUserText(content) !== wireText) return '';- // Pasted text still lacks a verified authored projection. Structured references,- // however, have validated spans: discard those spans, not the owner's adjacent- // request. Attached session transcripts are separate from value.text entirely.- if (Array.isArray(value.pastedTextRanges) && value.pastedTextRanges.length > 0) return '';+ // Structured references have validated spans: discard those spans, not the+ // owner's adjacent request. Attached session transcripts are separate from value.text entirely.const references = readAgentInputReferences(value.agentReferences, value.text);if (Array.isArray(value.agentReferences) && references.length !== value.agentReferences.length) return '';const parts: string[] = [];diff --git a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts b/apps/desktop/src/main/maker-ipc/makerSendTransaction.tsindex fec0962454..813dbd27ff 100644--- a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts+++ b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts@@ -187,7 +187,7 @@ export function stampTrustedDesktopQueuedOrigin(// Keep the complete input until the shared atomic history budget is applied.// Pre-compacting a revocation would leave older grants beside an omission marker.if (ordinary) explicitUserItem.autoReviewUserText =- readAutoReviewUserText(item.persistedContent) ?? currentAutoReviewResourceIntent(item.persistedContent, item.text);+ readAutoReviewUserText(item.persistedContent, item.text) ?? currentAutoReviewResourceIntent(item.persistedContent, item.text);if (deviceLinkInvoke || !canTrustDesktopPiCommand(item)) return explicitUserItem;const receipt: TrustedDesktopPiCommandSnapshot = {version: 1,diff --git a/packages/maker-shared/src/autoReviewIntent.ts b/packages/maker-shared/src/autoReviewIntent.tsindex b40472acbb..204a20b685 100644--- a/packages/maker-shared/src/autoReviewIntent.ts+++ b/packages/maker-shared/src/autoReviewIntent.ts@@ -255,7 +255,7 @@ export function createAutoReviewIntentProjection() {: null;}- function readAutoReviewUserText(content: unknown): string | null {+ function readAutoReviewUserText(content: unknown, wireText?: string): string | null {if (typeof content === "string") {try {content = JSON.parse(content);@@ -276,10 +276,10 @@ export function createAutoReviewIntentProjection() {"sessionReferences","agentReferences","references",- "pastedTextRanges",].some((key) => Array.isArray(value[key]) && value[key].length > 0))return null;+ if (wireText !== undefined && value.text !== wireText) return null;return value.text;}