Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(auto): retain initialized live intent on delegated continuations
Dash23ca4fe4c333
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaInterAgentDispatcher.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaInterAgentDispatcher.test.tsindex 289aa1591d..69487557bc 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaInterAgentDispatcher.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaInterAgentDispatcher.test.ts@@ -1,5 +1,5 @@import type { SessionSendOptions, SessionSendResult, UserMessage } from '@cindy/maker-core';-import { AUTO_REVIEW_USER_INTENT } from '@cindy/maker-core';+import { AUTO_REVIEW_DELEGATED_CONTINUATION, appendAutoReviewUserIntent, AUTO_REVIEW_USER_INTENT } from '@cindy/maker-core';import { beforeEach, describe, expect, it, vi } from 'vitest';import type { AgentInputQueuedMessage } from '../../../shared/agentInputQueue.js';@@ -173,7 +173,7 @@ describe('Orca lead/worker dispatcher', () => {content:'[From Orca Lead]\nImplement feature\n\n---\n(Bridge note: your worker_id for tool calls is worker-1.)',},- expect.objectContaining({ throwOnStartFailure: true }),+ expect.objectContaining({ throwOnStartFailure: true, [AUTO_REVIEW_DELEGATED_CONTINUATION]: true }),);});@@ -781,3 +781,15 @@ describe('Orca lead/worker dispatcher', () => {expect(accepted).not.toHaveBeenCalled();});});++it.each(['Do not publish', ''])('ordinary live continuation retains the last accepted intent %j', async live => {+ const h = createHarness();+ h.liveSession.send.mockImplementation(async (message, opts) => {+ expect(opts?.[AUTO_REVIEW_DELEGATED_CONTINUATION]).toBe(true);+ expect(appendAutoReviewUserIntent(live, message.content, opts)).toBe(live);+ await opts?.onAccepted?.();+ return {accepted:true};+ });+ const result=await h.dispatcher.dispatchOrEnqueueOrcaInterAgentMessage({targetSessionId:'target-session',rawContent:'Publish now',source:'lead',senderLabel:'Lead',meta:{source:'orca',context:'ordinary-live'}});+ expect(result.ok).toBe(true);+});diff --git a/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts b/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.tsindex 3c834832a2..9ac3136a3e 100644--- a/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts+++ b/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts@@ -1,10 +1,10 @@-import { AUTO_REVIEW_SOURCE_CONTENT, AUTO_REVIEW_USER_INTENT, MAIN_OWNED_SEND_CONTEXT, appendAutoReviewUserIntent, extractAutoReviewUserIntent } from '@cindy/maker-core';+import { AUTO_REVIEW_DELEGATED_CONTINUATION, AUTO_REVIEW_SOURCE_CONTENT, AUTO_REVIEW_USER_INTENT, MAIN_OWNED_SEND_CONTEXT, appendAutoReviewUserIntent, extractAutoReviewUserIntent } from '@cindy/maker-core';import type { AutoReviewUserIntent, SendOptions, UserMessage } from '@cindy/maker-core';import { joinChatQuoteTextSegments, parseChatQuoteSegments } from '@cindy/maker-shared/chat-quotes';import { projectPersistedAgentFacingUserText } from '@cindy/maker-shared/agent-input-projection';/** Main-only projection of a protected delegated receipt; never accepted from wire input. */-export const AUTO_REVIEW_DELEGATED_CONTINUATION = Symbol('autoReviewDelegatedContinuation');+export { AUTO_REVIEW_DELEGATED_CONTINUATION };/** Existing transcript projection, already filtered by the database's clear/rewind boundary. */export interface AutoReviewHistoryMessage {diff --git a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts b/apps/desktop/src/main/maker-ipc/makerSendTransaction.tsindex cc8ad2af69..596742ee1c 100644--- a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts+++ b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts@@ -1465,6 +1465,7 @@ export function createMakerSendTransaction(deps: MakerSendTransactionDeps): Make...(retryTranscriptUserEntryId ? { retryTranscriptUserEntryId } : {}),...(resolveScheduledIntent ? { resolveAutoReviewUserIntent: resolveScheduledIntent } : {}),[AUTO_REVIEW_SOURCE_CONTENT]: autoReviewSourceContent,+ ...(so[AUTO_REVIEW_DELEGATED_CONTINUATION] ? { [AUTO_REVIEW_DELEGATED_CONTINUATION]: true as const } : {}),...(so[INHERITED_CAPABILITY_SELECTION] !== undefined? { [INHERITED_CAPABILITY_SELECTION]: so[INHERITED_CAPABILITY_SELECTION] }: {}),diff --git a/apps/desktop/src/main/maker-ipc/orcaInterAgentDispatcher.ts b/apps/desktop/src/main/maker-ipc/orcaInterAgentDispatcher.tsindex a2bba35187..f75c9ae5bd 100644--- a/apps/desktop/src/main/maker-ipc/orcaInterAgentDispatcher.ts+++ b/apps/desktop/src/main/maker-ipc/orcaInterAgentDispatcher.ts@@ -2,7 +2,7 @@ import {formatAgentMessage,formatOrcaCommunicationMessage,} from '@cindy/orca-workflow';-import { AUTO_REVIEW_SOURCE_CONTENT, AUTO_REVIEW_USER_INTENT } from '@cindy/maker-core';+import { AUTO_REVIEW_DELEGATED_CONTINUATION, AUTO_REVIEW_SOURCE_CONTENT, AUTO_REVIEW_USER_INTENT } from '@cindy/maker-core';import { restoreAutoReviewUserIntent, type AutoReviewHistoryMessage } from './autoReviewUserIntent.js';import type { AgentKind, SessionSendOptions, SessionSendResult, UserMessage } from '@cindy/maker-core';@@ -678,6 +678,7 @@ async function sendPersistedUserMessageToSession<TSessionMeta>(throwOnStartFailure: true,[AUTO_REVIEW_SOURCE_CONTENT]: '',[AUTO_REVIEW_USER_INTENT]: humanIntent,+ [AUTO_REVIEW_DELEGATED_CONTINUATION]: true,onAccepted: async () => {// maker-core 会在 vendor handle.send 前 await 此 hook;必须先落库,再运行 accepted 副作用。await deps.createDbMessage(session.id, {diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 67cb71bf4e..04bd3bfc11 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -9423,6 +9423,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)...(params.autoReviewUserText ? {[AUTO_REVIEW_SOURCE_CONTENT]: '',[AUTO_REVIEW_USER_INTENT]: restoreAutoReviewUserIntent(await readAutoReviewHistory(targetSessionId)),+ [AUTO_REVIEW_DELEGATED_CONTINUATION]: true as const,} : {}),planMode: false,onAccepted: persistUserMessage,@@ -9537,6 +9538,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)...(params.autoReviewUserText ? {[AUTO_REVIEW_SOURCE_CONTENT]: '',[AUTO_REVIEW_USER_INTENT]: restoreAutoReviewUserIntent(await readAutoReviewHistory(targetSessionId)),+ [AUTO_REVIEW_DELEGATED_CONTINUATION]: true as const,} : {}),planMode: false,onAccepted: persistUserMessage,diff --git a/packages/maker-core/src/agents/base-agent.ts b/packages/maker-core/src/agents/base-agent.tsindex 88abcfa89d..464f4726a6 100644--- a/packages/maker-core/src/agents/base-agent.ts+++ b/packages/maker-core/src/agents/base-agent.ts@@ -1948,6 +1948,9 @@ export const AUTO_REVIEW_SOURCE_CONTENT = Symbol('cindy.auto-review-source-conte/** Host-restored user authorization for this send; never accepted from wire options. */export const AUTO_REVIEW_USER_INTENT = Symbol('cindy.auto-review-user-intent');+/** Main-attested continuation: retain initialized live intent, including an explicit empty reset. */+export const AUTO_REVIEW_DELEGATED_CONTINUATION = Symbol('autoReviewDelegatedContinuation');+/** Main-only selection from the original input for a retained-history continuation. */export const INHERITED_CAPABILITY_SELECTION = Symbol('cindy.inherited-capability-selection');@@ -1975,6 +1978,7 @@ export interface MainOwnedSendContext {export interface SendOptions {readonly [AUTO_REVIEW_SOURCE_CONTENT]?: UserMessage['content'];readonly [AUTO_REVIEW_USER_INTENT]?: AutoReviewUserIntent;+ readonly [AUTO_REVIEW_DELEGATED_CONTINUATION]?: true;readonly [INHERITED_CAPABILITY_SELECTION]?: string;/** Exact Skill selected by a Host authorization check for this send. */readonly [PINNED_SKILL_INVOCATION]?: PinnedSkillInvocation;diff --git a/packages/maker-core/src/agents/claude-code/__tests__/auto-review-wiring.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/auto-review-wiring.test.tsindex 9640b763c8..2c0087e9b9 100644--- a/packages/maker-core/src/agents/claude-code/__tests__/auto-review-wiring.test.ts+++ b/packages/maker-core/src/agents/claude-code/__tests__/auto-review-wiring.test.ts@@ -1,3 +1,4 @@+import { AUTO_REVIEW_DELEGATED_CONTINUATION, AUTO_REVIEW_USER_INTENT } from '../../base-agent.js';/*** Auto-review 接线集成测试:官方 Claude OAuth 在没有 host MCP 时保留原生 Auto classifier;* 一旦有 host MCP 或使用第三方路由,映射到 SDK default,让 canUseTool 走 Cindy 当前模型轻量 fallback。@@ -1299,3 +1300,15 @@ describe('Auto review for progressive MCP operations', () => {}});});++it.each(['Do not publish.', ''])('keeps live Claude intent %j over stale continuation history', async restriction => {+ const {handle,canUseTool,reviewAutoPermissionAction}=await startSession('auto',{mcpProviderNames:['cindy'],mcpToolApprovalPolicy:()=> 'prompt',reviewVerdict:'block'});+ try {+ await handle.send({type:'user',content:'Publish the release.'});+ await handle.steer!({type:'user',content:restriction});+ await handle.steer!({type:'user',content:'Lead continuation'}, {[AUTO_REVIEW_DELEGATED_CONTINUATION]:true,[AUTO_REVIEW_USER_INTENT]:'Publish the release.'});+ await canUseTool('mcp__cindy__ghost_call',{action:'publish'},{toolUseID:'live-continuation'});+ const intent=reviewedRequest(reviewAutoPermissionAction).userIntent;+ if(restriction) expect(JSON.stringify(intent)).toContain(restriction); else expect(intent).toBe('');+ } finally {await handle.close();}+});diff --git a/packages/maker-core/src/agents/claude-code/index.ts b/packages/maker-core/src/agents/claude-code/index.tsindex 323b2e6c50..93767c49b7 100644--- a/packages/maker-core/src/agents/claude-code/index.ts+++ b/packages/maker-core/src/agents/claude-code/index.ts@@ -2648,6 +2648,7 @@ export class ClaudeCodeAgent extends BaseAgent {let mutableAutoReviewCredentialMode = effectiveCredentialMode;let nativeAutoReviewUnavailable = false;let currentAutoReviewIntent: AutoReviewUserIntent = '';+ let autoReviewIntentInitialized = false;const autoReviewActionContext = createAutoReviewActionContext();const autoReviewContext = () => activeTurnPermissionPolicy?.autoReviewContext?? (activeTurnPermissionPolicy?.origin.kind === 'im'@@ -2655,7 +2656,7 @@ export class ClaudeCodeAgent extends BaseAgent {: undefined);// Authorization belongs to the accepted input, not the foreground policy's lifetime.let currentAutoReviewAuthority: ReturnType<typeof autoReviewContext>;- const priorAutoReviewIntent = () => JSON.stringify(currentAutoReviewAuthority ?? null) === JSON.stringify(autoReviewContext() ?? null) ? currentAutoReviewIntent : '';+ const priorAutoReviewIntent = () => !autoReviewIntentInitialized ? undefined : JSON.stringify(currentAutoReviewAuthority ?? null) === JSON.stringify(autoReviewContext() ?? null) ? currentAutoReviewIntent : '';const autoReviewDecisionCache = new Map<string, Promise<AutoReviewDecision>>();// Claude's native OAuth Auto classifier bypasses canUseTool entirely. Once a host MCP// is registered, that would also bypass Cindy's trusted-server and prompt policies,@@ -2674,6 +2675,7 @@ export class ClaudeCodeAgent extends BaseAgent {const setAutoReviewIntent = (content: AutoReviewUserIntent, source = { authority: currentAutoReviewAuthority }): void => {autoReviewActionContext.advance(typeof content !== 'string' && JSON.stringify(currentAutoReviewAuthority ?? null) === JSON.stringify(source.authority ?? null));currentAutoReviewIntent = normalizeAutoReviewUserIntent(content);+ autoReviewIntentInitialized = true;currentAutoReviewAuthority = source.authority && { ...source.authority };autoReviewDecisionCache.clear();// 每条新用户消息 = 新一轮,提示重新武装。ErrorBanner 那份只活到下一条非 error 事件diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.tsindex 745cd86534..b0f3cd231c 100644--- a/packages/maker-core/src/agents/codex/index.ts+++ b/packages/maker-core/src/agents/codex/index.ts@@ -4775,6 +4775,7 @@ assertRouteCurrent();*/let mutableProviderId: string | null | undefined = opts.providerId;let currentAutoReviewIntent: AutoReviewUserIntent = '';+ let autoReviewIntentInitialized = false;const autoReviewActionContext = createAutoReviewActionContext();const autoReviewContext = () => activeTurnPermissionPolicy?.autoReviewContext?? (activeTurnPermissionPolicy?.origin.kind === 'im'@@ -4782,11 +4783,12 @@ assertRouteCurrent();: undefined);// Authorization belongs to the accepted input, not the foreground policy's lifetime.let currentAutoReviewAuthority: ReturnType<typeof autoReviewContext>;- const priorAutoReviewIntent = () => JSON.stringify(currentAutoReviewAuthority ?? null) === JSON.stringify(autoReviewContext() ?? null) ? currentAutoReviewIntent : '';+ const priorAutoReviewIntent = () => !autoReviewIntentInitialized ? undefined : JSON.stringify(currentAutoReviewAuthority ?? null) === JSON.stringify(autoReviewContext() ?? null) ? currentAutoReviewIntent : '';const autoReviewDecisionCache = new Map<string, Promise<AutoReviewDecision>>();const setAutoReviewIntent = (content: AutoReviewUserIntent, source = { authority: currentAutoReviewAuthority }): void => {autoReviewActionContext.advance(typeof content !== 'string' && JSON.stringify(currentAutoReviewAuthority ?? null) === JSON.stringify(source.authority ?? null));currentAutoReviewIntent = normalizeAutoReviewUserIntent(content);+ autoReviewIntentInitialized = true;currentAutoReviewAuthority = source.authority && { ...source.authority };autoReviewDecisionCache.clear();// 每条新用户消息 = 新一轮,提示重新武装。ErrorBanner 那份只活到下一条非 error 事件diff --git a/packages/maker-core/src/agents/pi/index.ts b/packages/maker-core/src/agents/pi/index.tsindex 8d12c0cf03..69370be0a7 100644--- a/packages/maker-core/src/agents/pi/index.ts+++ b/packages/maker-core/src/agents/pi/index.ts@@ -3821,6 +3821,7 @@ export class PiAgent extends BaseAgent {let activeEffortSnapshot = initialEffortSnapshot;let mutableEffort: Effort | null = startupEffort ?? null;let currentAutoReviewIntent: AutoReviewUserIntent = '';+ let autoReviewIntentInitialized = false;const autoReviewActionContext = createAutoReviewActionContext();const autoReviewContext = () => activeTurnPermissionPolicy?.autoReviewContext?? (activeTurnPermissionPolicy?.origin.kind === 'im'@@ -3828,11 +3829,12 @@ export class PiAgent extends BaseAgent {: undefined);// Authorization belongs to the accepted input, not the foreground policy's lifetime.let currentAutoReviewAuthority: ReturnType<typeof autoReviewContext> | null;- const priorAutoReviewIntent = () => JSON.stringify(currentAutoReviewAuthority ?? null) === JSON.stringify(autoReviewContext() ?? null) ? currentAutoReviewIntent : '';+ const priorAutoReviewIntent = () => !autoReviewIntentInitialized ? undefined : JSON.stringify(currentAutoReviewAuthority ?? null) === JSON.stringify(autoReviewContext() ?? null) ? currentAutoReviewIntent : '';const autoReviewDecisionCache = new Map<string, Promise<AutoReviewDecision>>();const setAutoReviewIntent = (content: AutoReviewUserIntent, source = { authority: currentAutoReviewAuthority }): void => {autoReviewActionContext.advance(typeof content !== 'string' && JSON.stringify(currentAutoReviewAuthority ?? null) === JSON.stringify(source.authority ?? null));currentAutoReviewIntent = normalizeAutoReviewUserIntent(content);+ autoReviewIntentInitialized = true;currentAutoReviewAuthority = source.authority && { ...source.authority };autoReviewDecisionCache.clear();// 每条新用户消息 = 新一轮,提示重新武装。ErrorBanner 那份只活到下一条非 error 事件diff --git a/packages/maker-core/src/agents/shared/auto-review-decision.test.ts b/packages/maker-core/src/agents/shared/auto-review-decision.test.tsindex 584f7653ee..d8ce3c5292 100644--- a/packages/maker-core/src/agents/shared/auto-review-decision.test.ts+++ b/packages/maker-core/src/agents/shared/auto-review-decision.test.ts@@ -1,6 +1,6 @@import { afterEach, describe, expect, it, vi } from 'vitest';import * as staticReview from './auto-review.js';-import { AUTO_REVIEW_USER_INTENT, MAIN_OWNED_SEND_CONTEXT, type SendOptions } from '../base-agent.js';+import { AUTO_REVIEW_DELEGATED_CONTINUATION, AUTO_REVIEW_USER_INTENT, MAIN_OWNED_SEND_CONTEXT, type SendOptions } from '../base-agent.js';import {AUTO_REVIEW_CONFIRM_UNDELIVERED_CODE,@@ -756,3 +756,11 @@ describe('flat authorization and observed denied actions', () => {expect(context.precedingBlockedActions).toEqual([]);});});++it('retains live restrictions and empty revocations on continuations but restores cold handles', () => {+ const opts: SendOptions = { [AUTO_REVIEW_DELEGATED_CONTINUATION]: true, [AUTO_REVIEW_USER_INTENT]: 'Publish the release' };+ expect(appendAutoReviewUserIntent('Do not publish', 'Lead says publish', opts)).toBe('Do not publish');+ expect(appendAutoReviewUserIntent('', 'Lead says publish', opts)).toBe('');+ expect(appendAutoReviewUserIntent(undefined, 'Lead says publish', opts)).toBe('Publish the release');+ expect(appendAutoReviewUserIntent('Do not publish', '', {})).toBe('');+});diff --git a/packages/maker-core/src/agents/shared/auto-review-decision.ts b/packages/maker-core/src/agents/shared/auto-review-decision.tsindex a5c7b7a449..c7a8b84b8f 100644--- a/packages/maker-core/src/agents/shared/auto-review-decision.ts+++ b/packages/maker-core/src/agents/shared/auto-review-decision.ts@@ -1,5 +1,5 @@import type { AgentKind, UserMessage } from '../../types/common.js';-import { AUTO_REVIEW_SOURCE_CONTENT, AUTO_REVIEW_USER_INTENT, MAIN_OWNED_SEND_CONTEXT, type SendOptions } from '../base-agent.js';+import { AUTO_REVIEW_DELEGATED_CONTINUATION, AUTO_REVIEW_SOURCE_CONTENT, AUTO_REVIEW_USER_INTENT, MAIN_OWNED_SEND_CONTEXT, type SendOptions } from '../base-agent.js';import {MAX_AUTO_REVIEW_ACTION_TEXT_CHARS,@@ -587,7 +587,9 @@ export function normalizeAutoReviewUserIntent(intent: AutoReviewUserIntent): Aut}/** Preserve chronological user messages; scope is assessed, never assumed permanent. */-export function appendAutoReviewUserIntent(previous: AutoReviewUserIntent, content: UserMessage['content'], sendOpts?: SendOptions): AutoReviewUserIntent {+export function appendAutoReviewUserIntent(previous: AutoReviewUserIntent | undefined, content: UserMessage['content'], sendOpts?: SendOptions): AutoReviewUserIntent {+ // A continuation is not a new human input. A live empty reset is authoritative too.+ if (sendOpts?.[AUTO_REVIEW_DELEGATED_CONTINUATION] && previous !== undefined) return normalizeAutoReviewUserIntent(previous);// The authenticated Host snapshot already includes this input; never append it twice.if (sendOpts?.[AUTO_REVIEW_USER_INTENT] !== undefined) {return normalizeAutoReviewUserIntent(sendOpts[AUTO_REVIEW_USER_INTENT]);@@ -597,7 +599,7 @@ export function appendAutoReviewUserIntent(previous: AutoReviewUserIntent, conteconst latest = userIntentText(sendOpts?.[MAIN_OWNED_SEND_CONTEXT]?.rawChannelText ?? sourceContent);// A new attachment changes what "send this" refers to; it cannot renew an earlier grant.const hasAttachments = Array.isArray(sourceContent) && sourceContent.some((block) => block.type !== 'text');- if (!latest || hasAttachments || previous === '') return compactCurrentUserIntent(latest);+ if (!latest || hasAttachments || previous === undefined || previous === '') return compactCurrentUserIntent(latest);const earlierUserMessages = typeof previous === 'string'? [previous] : [...previous.earlierUserMessages, previous.currentUserMessage];return normalizeAutoReviewUserIntent({ earlierUserMessages, currentUserMessage: latest,diff --git a/packages/maker-core/src/session.origin.test.ts b/packages/maker-core/src/session.origin.test.tsindex 68ae4300ac..e71ab556cc 100644--- a/packages/maker-core/src/session.origin.test.ts+++ b/packages/maker-core/src/session.origin.test.ts@@ -12,6 +12,7 @@ import { Session } from './session.js';import {MAIN_OWNED_SEND_CONTEXT,AUTO_REVIEW_USER_INTENT,+ AUTO_REVIEW_DELEGATED_CONTINUATION,type AgentSessionHandle,type SendOptions,type TurnContinuationState,@@ -147,6 +148,14 @@ function createControllableHandle(opts?: {}describe('dispatch authorization refresh', () => {+ it('passes the protected continuation marker through acceptance to the harness', async () => {+ const h = createControllableHandle();+ const session = makeSession(h.handle);+ await session.send('Lead continuation', { [AUTO_REVIEW_DELEGATED_CONTINUATION]: true, [AUTO_REVIEW_USER_INTENT]: 'persisted fallback' });+ expect(h.lastSendOptions()?.[AUTO_REVIEW_DELEGATED_CONTINUATION]).toBe(true);+ await session.close();+ });+it('reads authorization after accepted preparation and overrides an earlier snapshot', async () => {const h = createControllableHandle();const session = makeSession(h.handle);