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(plugins): preserve setup terminal steps

nanafc818160b7d0
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostSetupCoordinator.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostSetupCoordinator.test.ts
index d821dd6e2c..2d280cae78 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/ghostSetupCoordinator.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostSetupCoordinator.test.ts
@@ -16,6 +16,7 @@ import {
GhostSetupInteractionBridge,
type GhostSetupInteractionCommand,
type GhostSetupInteractionResponseTarget,
+ type GhostSetupInteractionSnapshot,
} from '../ghostSetupInteractionBridge';
function required(revision = 0): GhostSetupAssessment {
@@ -288,6 +289,40 @@ describe('GhostSetupCoordinator', () => {
expect(h.bridge.pendingSnapshots()).toEqual([]);
});
+ it('preserves non-empty satisfied steps in the ready terminal snapshot', async () => {
+ const h = harness(required());
+ const waiting = h.coordinator.ensureReady({
+ sessionId: 'session-1',
+ ghostId: 'gmail',
+ tool: 'search',
+ });
+ await vi.waitFor(() => expect(h.bridge.pendingSnapshots()).toHaveLength(1));
+ const initial = h.bridge.pendingSnapshots()[0].request;
+
+ h.setAssessment(ready(1));
+ h.changeBus.emit('gmail', { source: 'oauth', ref: 'google' });
+ await expect(waiting).resolves.toMatchObject({ ok: true });
+
+ const terminalSnapshots = h.broadcast.mock.calls
+ .filter(([channel]) => channel === MAKER_PUSH.INTERACTION_REQUEST)
+ .map(
+ ([, payload]) =>
+ (payload as { request: GhostSetupInteractionSnapshot }).request,
+ )
+ .filter((request) => request.terminal === true);
+ expect(terminalSnapshots).toHaveLength(1);
+ expect(terminalSnapshots[0].steps).toEqual([
+ {
+ id: initial.steps[0].id,
+ groupId: initial.steps[0].groupId,
+ groupMode: initial.steps[0].groupMode,
+ title: initial.steps[0].title,
+ description: initial.steps[0].description,
+ phase: 'satisfied',
+ },
+ ]);
+ });
+
it('run_action is single-flight and only a later ready assessment settles', async () => {
const h = harness(required());
let release!: () => void;
diff --git a/apps/desktop/src/main/cindy-brain/ghostSetupCoordinator.ts b/apps/desktop/src/main/cindy-brain/ghostSetupCoordinator.ts
index 01c8e0dc76..ae8da2a3c2 100644
--- a/apps/desktop/src/main/cindy-brain/ghostSetupCoordinator.ts
+++ b/apps/desktop/src/main/cindy-brain/ghostSetupCoordinator.ts
@@ -249,6 +249,28 @@ export class GhostSetupCoordinator {
this.deps.bridge.update(snapshot);
};
+ const publishSatisfied = (nextAssessment: GhostSetupAssessment): void => {
+ assessment = nextAssessment;
+ const nextRevision = Math.max(snapshot.revision + 1, assessment.revision);
+ // A ready assessment has no actionable plan, but Renderer still
+ // requires the terminal snapshot to retain the interaction's steps.
+ // Preserve the last authoritative presentation and strip every
+ // action/error while projecting the completed state.
+ snapshot = {
+ ...snapshot,
+ revision: nextRevision,
+ steps: snapshot.steps.map((step) => ({
+ id: step.id,
+ groupId: step.groupId,
+ groupMode: step.groupMode,
+ title: step.title,
+ description: step.description,
+ phase: 'satisfied',
+ })),
+ };
+ this.deps.bridge.update(snapshot);
+ };
+
const verify = (requiredPhase?: GhostSetupInteractionStep['phase']): Promise<void> => {
if (settled) return Promise.resolve();
if (verifying) return verifying;
@@ -275,7 +297,7 @@ export class GhostSetupCoordinator {
}
const next = current.assessment;
if (next.state === 'ready') {
- publish(next, 'satisfied');
+ publishSatisfied(next);
settle({ ok: true, assessment: next }, 'ready');
return;
}
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
index 51be00956a..9e34c182af 100644
--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
@@ -7,6 +7,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import type { AgentInputProjection, AgentInputQueuedMessage } from '../../shared/agentInputQueue';
+import { GHOST_SETUP_MAX_INTERACTION_STEPS } from '../../shared/ghost';
import type { Message } from '@/lib/ccAgent.types';
import type { AttachedFile, MentionedResource } from '@/lib/fileTypes';
@@ -827,23 +828,25 @@ describe('makerChatStore text delta batching', () => {
expect(makerChatStore.getSnapshot(SESSION_ID).pendingPluginSetup).toBeNull();
});
- it('accepts all 64 manifest-valid setup steps and rejects a 65th', () => {
+ it('accepts the full setup interaction capacity and rejects one extra step', () => {
const step = pluginSetupRequest(1).steps[0];
emitInteractionRequest({
...pluginSetupRequest(1),
- steps: Array.from({ length: 64 }, (_, index) => ({
+ steps: Array.from({ length: GHOST_SETUP_MAX_INTERACTION_STEPS }, (_, index) => ({
...step,
id: `setup-${index}`,
action: { ...step.action, id: `oauth:${index}` },
})),
});
- expect(makerChatStore.getSnapshot(SESSION_ID).pendingPluginSetup?.steps).toHaveLength(64);
+ expect(makerChatStore.getSnapshot(SESSION_ID).pendingPluginSetup?.steps).toHaveLength(
+ GHOST_SETUP_MAX_INTERACTION_STEPS,
+ );
makerChatStore.purgeSession(SESSION_ID);
emitInteractionRequest({
...pluginSetupRequest(1),
requestId: 'plugin-setup-oversized',
- steps: Array.from({ length: 65 }, (_, index) => ({
+ steps: Array.from({ length: GHOST_SETUP_MAX_INTERACTION_STEPS + 1 }, (_, index) => ({
...step,
id: `setup-${index}`,
action: { ...step.action, id: `oauth:${index}` },