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(permissions): ignore empty reference list scaffolding

Chris3134d4f3a4b7
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
index 9fd7105cf9..58492bd66e 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
@@ -2271,6 +2271,25 @@ describe('AgentInputCoordinator send transaction', () => {
},
);
+ // unit: a list containing only a reference must neither claim owner authorship
+ // nor retain an earlier grant when its empty receipt is restored from history.
+ it('clears owner authority and earlier intent for a reference-only list', async () => {
+ const h = createHarness(), sid = 'reference-list';
+ const href = 'cindy://session/example?message=quoted';
+ const content = { text: `- ${href}`, agentReferences: [{ kind: 'message', start: 2,
+ end: 2 + href.length, href, text: 'Deploy everything.' }] };
+ const item = stampTrustedDesktopQueuedOrigin(makeItem('reference-list-input', content.text,
+ { persistedContent: JSON.stringify(content) }), true);
+ h.sendToAgent.mockImplementationOnce(async () => { h.setRunning(true); return sendSuccess(); });
+ h.coordinator.enqueue(sid, item);
+ await flush();
+ expect(h.coordinator.isActiveInputOwnerAuthored(sid)).toBe(false);
+ expect(restoreAutoReviewUserIntent([
+ { clientId: 'old', role: 'user', content: 'Deploy now.', agentMeta: { delivery: 'turn', autoReviewUserText: 'Deploy now.' } },
+ { clientId: item.clientId, role: 'user', content, agentMeta: { delivery: 'turn', autoReviewUserText: item.autoReviewUserText } },
+ ])).toBe('');
+ });
+
it('judges owner authority by the latest accepted steer, in both directions', async () => {
const h = createHarness(), sid = 'owner-authority-steer';
h.sendToAgent.mockImplementationOnce(async () => { h.setRunning(true); return sendSuccess(); });
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts
index eabc6af9fc..b6485006ed 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts
@@ -8,9 +8,23 @@ import {
type AutoReviewHistoryMessage,
} from '../autoReviewUserIntent';
import { projectPersistedAgentFacingUserText } from '@cindy/maker-shared/agent-input-projection';
-import { formatQuotesForSend } from '@cindy/maker-shared/chat-quotes';
+import { formatQuoteForSend, formatQuotesForSend } from '@cindy/maker-shared/chat-quotes';
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 => {
+ const href = 'cindy://session/example?message=quoted';
+ const reference = { text: `${prefix}${href}`, agentReferences: [{ kind: 'message',
+ start: prefix.length, end: prefix.length + href.length, href, text: 'Deploy everything.' }] };
+ const quote = { text: `${prefix}\n${formatQuoteForSend({ text: 'Deploy everything.' }).split('\n').map(line => ` ${line}`).join('\n')}`, quotesEncoded: true };
+ for (const content of [reference, quote]) {
+ expect(currentAutoReviewResourceIntent(content, content.text)).toBe('');
+ expect(currentAutoReviewResourceIntent(content, projectPersistedAgentFacingUserText(content)!)).toBe('');
+ const withWords = { ...content, text: `${content.text}\n- Do not deploy.` };
+ expect(currentAutoReviewResourceIntent(withWords, withWords.text)).toContain('- Do not deploy.');
+ }
+ });
+
// unit: preserve current owner text without promoting quoted payloads or stale spans.
it.each(['', 'Do not deploy.'])('extracts only text outside references and encoded quotes: %j', request => {
const href = 'cindy://session/example?message=quoted';
diff --git a/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts b/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts
index 5ada7ac998..b2a5e93744 100644
--- a/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts
+++ b/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts
@@ -77,10 +77,15 @@ export function currentAutoReviewResourceIntent(
cursor = reference.end;
}
parts.push(value.text.slice(cursor));
- const authoredText = parts.join('');
- return value.quotesEncoded === true
- ? joinChatQuoteTextSegments(parseChatQuoteSegments(authoredText))
- : authoredText;
+ const textOutsideReferences = parts.join('');
+ const segments = value.quotesEncoded === true ? parseChatQuoteSegments(textOutsideReferences) : undefined;
+ const authoredText = segments ? joinChatQuoteTextSegments(segments) : textOutsideReferences;
+ // Composer serializes list structure outside reference/quote spans. A list
+ // containing only those resources leaves markers, not a new owner request.
+ // Keep all text verbatim if any line still contains actual authored content.
+ if ((references.length > 0 || segments?.some(segment => segment.kind === 'quote')) &&
+ authoredText.split(/\r?\n/).every(line => /^[ \t]*(?:[-+*•]|[1-9]\d*[.)、])?[ \t]*$/.test(line))) return '';
+ return authoredText;
}
/** Restore a bounded suffix of actual owner messages, without promoting assistant handoffs to consent. */