Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(auto): preserve literal trigger restrictions and reject ambiguous provenance
Dash5238b358542c
diff --git a/apps/desktop/src/main/localDb/__tests__/autoReviewProjection.test.ts b/apps/desktop/src/main/localDb/__tests__/autoReviewProjection.test.tsindex 11d75ff106..63a85cb150 100644--- a/apps/desktop/src/main/localDb/__tests__/autoReviewProjection.test.ts+++ b/apps/desktop/src/main/localDb/__tests__/autoReviewProjection.test.ts@@ -68,10 +68,28 @@ function stored(db: Database.Database) {}describe('durable Auto authority projection', () => {+ it.each(['lead', 'worker'])('keeps literal trigger restrictions and rejects ambiguous provenance in %s', session => {+ const dir=fs.mkdtempSync(path.join(os.tmpdir(),'cindy-authority-literal-'));+ directories.push(dir);const filename=path.join(dir,'test.sqlite');const db=open(filename);+ add(db,'grant','worker',1,'publish');read(db);+ const text='[UI_ACTION_TRIGGER] do not publish';+ add(db,'restriction',session,2,text);+ add(db,'followup','worker',3,'continue');+ const incremental=read(db);+ expect(JSON.stringify(incremental.reviewIntent)).toContain(text);+ expect(incremental.reviewIntent).toMatchObject({historyOmitted:true});+ if(session==='worker') expect(JSON.stringify(incremental.sessionIntent)).toContain(text);+ const old=JSON.parse(stored(db).payload);+ db.prepare('UPDATE auto_review_projections SET version=2,payload=?').run(JSON.stringify({...old,sessionIntent:'publish',reviewIntent:'publish',reviewUnverified:false}));+ const restarted=open(filename,false);+ const rebuilt=read(restarted);+ expect(rebuilt.sessionIntent).toEqual(incremental.sessionIntent);+ expect(rebuilt.reviewIntent).toEqual(incremental.reviewIntent);+ expect(restarted.prepare('SELECT version FROM auto_review_projections').get()).toEqual({version:3});+ });it.each([{ autoResume: true, autoReviewUserText: 'allow' },{ contextRebuild: { reason: 'recovery' }, autoReviewUserText: 'allow' },- { autoReviewUserText: '[UI_ACTION_TRIGGER] allow' },{ autoReviewUserText: { kind: 'delegated-continuation' } },{ autoReviewUserText: { kind: 'scheduled-continuation' } },])('ignores synthetic recovery through incremental writes, restart and v1 upgrade: %j', (meta) => {@@ -92,7 +110,7 @@ describe('durable Auto authority projection', () => {}));const restarted = open(filename, false);expect(read(restarted)).toMatchObject({ sessionIntent: before.sessionIntent, reviewIntent: before.reviewIntent });- expect(restarted.prepare('SELECT version FROM auto_review_projections').get()).toEqual({ version: 2 });+ expect(restarted.prepare('SELECT version FROM auto_review_projections').get()).toEqual({ version: 3 });add(restarted, 'reset', 'worker', 4, '');add(restarted, 'resume-again', 'worker', 5, 'allow', 'user', { delivery: 'steer', ...meta });expect(read(restarted)).toMatchObject({ sessionIntent: '', reviewIntent: '' });diff --git a/apps/desktop/src/main/localDb/autoReviewProjection.ts b/apps/desktop/src/main/localDb/autoReviewProjection.tsindex 9b3db0e655..2d0a6f36cc 100644--- a/apps/desktop/src/main/localDb/autoReviewProjection.ts+++ b/apps/desktop/src/main/localDb/autoReviewProjection.ts@@ -67,7 +67,7 @@ export function readAutoReviewProjection(}const review = projector.reviewState([row]);if (review.unverified) state.reviewUnverified = true;- else+ if (!review.unverified || review.intent !== '')state.reviewIntent = projector.append(reset ? '' : state.reviewIntent,review.intent as string,@@ -119,7 +119,7 @@ export function readAutoReviewProjection(CREATE TEMP TRIGGER auto_review_project AFTER UPDATE OF revision ON main.auto_review_projectionsWHEN (SELECT depth FROM auto_review_projection_batch) = 0BEGIN- UPDATE auto_review_projections SET payload = cindy_authority_projection_v1(CASE WHEN OLD.projected_revision = OLD.revision AND OLD.version = 2+ UPDATE auto_review_projections SET payload = cindy_authority_projection_v1(CASE WHEN OLD.projected_revision = OLD.revision AND OLD.version = 3AND json_extract(NEW.payload, '$.appendEvent.role') = 'user'AND json_extract(NEW.payload, '$.appendEvent.visible') = 1AND json_extract(NEW.payload, '$.appendEvent.createdAt') > json_extract(OLD.payload, '$.lastEventAt')@@ -136,7 +136,7 @@ export function readAutoReviewProjection(THEN json_extract(m.agent_meta,'$.autoReviewUserText.acceptedAt') ELSE m.created_at ENDELSE m.created_at END,CASE WHEN m.session_id = NEW.lead_id THEN 0 ELSE 1 END, m.rowid)- ) END, NEW.session_id, OLD.payload, json_extract(NEW.payload, '$.appendEvent')), projected_revision = NEW.revision, version = 2+ ) END, NEW.session_id, OLD.payload, json_extract(NEW.payload, '$.appendEvent')), projected_revision = NEW.revision, version = 3WHERE session_id = NEW.session_id AND lead_id = NEW.lead_id;END`);}@@ -156,13 +156,13 @@ export function readAutoReviewProjection(let row = select.get(sessionId, leadId) as Row;// First use after upgrade or a legacy writer rebuilds from current evidence// inside this transaction. Never fall back to the previous payload.- if (row.version !== 2 || row.projected_revision !== row.revision || row.payload === null) {+ if (row.version !== 3 || row.projected_revision !== row.revision || row.payload === null) {db.prepare("UPDATE auto_review_projections SET revision = revision + 1, payload = json_remove(payload, '$.appendEvent') WHERE session_id = ? AND lead_id = ?",).run(sessionId, leadId);row = select.get(sessionId, leadId) as Row;}- if (row.version !== 2 || row.projected_revision !== row.revision || !row.payload)+ if (row.version !== 3 || row.projected_revision !== row.revision || !row.payload)throw new Error('Authorization projection is not synchronized');const value = JSON.parse(row.payload) as StoredAutoReviewProjection & {reviewUnverified: boolean;diff --git a/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.tsindex 862e286067..c15b4a87b6 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts@@ -27,7 +27,6 @@ describe('steer authorization restoration', () => {it.each([{ autoResume: true, autoReviewUserText: 'Send now.' },{ contextRebuild: {}, autoReviewUserText: 'Send now.' },- { autoReviewUserText: '[UI_ACTION_TRIGGER] Send now.' },])('preserves human revocations across synthetic recovery: %j', (meta) => {const history = [user('Send now.'), user('Do not send.'), {...user('Send now.', 'recovery'), agentMeta: { delivery: 'turn', ...meta },@@ -107,6 +106,10 @@ describe('steer authorization restoration', () => {});describe('restored Auto authorization', () => {+ it('retains literal UI trigger text as a user restriction', () => {+ expect(restoreAutoReviewUserIntent([user('Publish now.'), user('[UI_ACTION_TRIGGER] do not publish')]))+ .toEqual({earlierUserMessages:['Publish now.'],currentUserMessage:'[UI_ACTION_TRIGGER] do not publish'});+ });it('restores the writing-test → new search → natural authorization sequence without assistant claims', async () => {const exercise = 'Only for this writing test, use no tools and modify no data.';const search = 'Now search for the latest portable chargers.';diff --git a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskReviewContext.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskReviewContext.test.tsindex 73f1b9010b..faa96f4b25 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskReviewContext.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskReviewContext.test.ts@@ -67,6 +67,15 @@ describe('plugin delegated Auto context', () => {expect(result.authorizationError).toContain('size');expect(result.delegatedTask).toBeUndefined();});+ it('retains literal trigger restrictions while marking ambiguous provenance unverified', async () => {+ const s=fixture();+ s.history=['Publish now.','[UI_ACTION_TRIGGER] do not publish','continue'].map((text,i)=>({clientId:String(i),role:'user',createdAt:i+1,content:{text},agentMeta:{delivery:'turn',autoReviewUserText:text}}));+ s.sessionHistory=s.history;+ const live=restoreAutoReviewUserIntent(s.history);+ const result=await createPluginTaskReviewResolver(async()=>s)({...request,userIntent:live});+ expect(JSON.stringify(result.userIntent)).toContain('[UI_ACTION_TRIGGER] do not publish');+ expect(result.userIntent).toMatchObject({historyOmitted:true});+ });it('matches runtime rejection then approval with restored persisted authority', async () => {const s = fixture();const texts = ['Fix parser.', 'Do not publish.', 'Only change parser files.', 'Approved plan:\nRun tests.'];diff --git a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.tsindex 43723893f3..d08d7bd431 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.ts@@ -413,7 +413,7 @@ it.each(['validation', 'archive', 'settlement', 'alreadyArchived', 'failure'] asconst record = {id:'worker',sessionId:'child',label:'one',status:phase === 'alreadyArchived' ? 'archived' : 'done'};const query = {from:()=>query,innerJoin:()=>query,where:()=>query,limit:async()=>[record]};const epoch = {client:{drizzle:{select:()=>query}}};- const deps = {service, getCurrentDbClientSnapshot:()=>epoch,PluginTaskError,assertPluginTaskResult,+ const deps = {service, getCurrentDbClientSnapshot:()=>epoch,PluginTaskError,assertPluginTaskResult,readPluginTaskPlanReceipt,orcaWorkers:{},orcaTeams:{},sessions:{},eq:()=>true,and:()=>true,createPluginTaskStore:()=>({get:async()=>({payload:JSON.stringify({teamPlan:{items:[{label:'one'}]}})})}),readPluginWorkerCompletion:async()=>({row:record,completedAt:1}),orcaTeamService:{archiveWorker}};diff --git a/packages/maker-shared/src/autoReviewIntent.ts b/packages/maker-shared/src/autoReviewIntent.tsindex 34ca8a6e7e..e5f16d8857 100644--- a/packages/maker-shared/src/autoReviewIntent.ts+++ b/packages/maker-shared/src/autoReviewIntent.ts@@ -141,7 +141,6 @@ export function createAutoReviewIntentProjection() {const meta = message.agentMeta;const receipt = meta?.autoReviewUserText;return !!(meta?.autoResume || meta?.contextRebuild ||- (typeof receipt === "string" && receipt.startsWith("[UI_ACTION_TRIGGER]")) ||(receipt && typeof receipt === "object" && "kind" in receipt &&(receipt.kind === "scheduled-continuation" || receipt.kind === "delegated-continuation")));}@@ -257,6 +256,10 @@ export function createAutoReviewIntentProjection() {omitted = true;}} else if (m.role === "user") {+ // Legacy UI triggers and literal user text share this string receipt.+ // Keep restrictions, but do not let ambiguous provenance establish Auto consent.+ if (typeof receipt === "string" && receipt.startsWith("[UI_ACTION_TRIGGER]"))+ omitted = true;if (typeof receipt === "string" &&["turn", "steer"].includes(String(m.agentMeta?.delivery))