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(maker-core): inherit origin capability and review intent on yield

Dashefea905f7fe0
diff --git a/docs/dev-rules/maker-core-and-agent-behavior.md b/docs/dev-rules/maker-core-and-agent-behavior.md
index a963d0f6a4..de5ed75d1b 100644
--- a/docs/dev-rules/maker-core-and-agent-behavior.md
+++ b/docs/dev-rules/maker-core-and-agent-behavior.md
@@ -102,8 +102,9 @@ timeout 不得触发自动换窗或 replay。Codex 当前没有与 Claude `AutoC
通用终态。continuation 的 `turn/start` 已被服务端接受后若本地 Stop,即使
`turnStarted` 已激活、随后 `interrupted` 被墓碑吞掉,也必须发出一条未认领的
cancelled `done`,避免 Session 仍握着 `currentTurnAttemptToken`。
- 续段必须继承铸造 claim 时的 `turnPermissionPolicy`,不得把无人值守只读边界
- 重置成普通 Auto。
+ 续段必须继承铸造 claim 时的 origin 上下文:`turnPermissionPolicy`、
+ capability selection 与 auto-review intent。不得把无人值守只读边界重置成普通
+ Auto,也不得用固定 wait 提示覆盖原请求的能力选择或审查意图。
Claude wake continuation 与 Codex yield continuation 先分账,不抽公共模块。
## 3. 守住四项核心数据指标
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.ts
index b647a3a1c7..f4dd11e462 100644
--- a/packages/maker-core/src/agents/codex/index.test.ts
+++ b/packages/maker-core/src/agents/codex/index.test.ts
@@ -17472,6 +17472,114 @@ describe('CodexAgent yield continuation', () => {
await handle.close();
});
+ it('inherits origin capability selection and auto-review intent on the yield continuation turn', async () => {
+ const seenIntents: string[] = [];
+ const reviewAutoPermissionAction = vi.fn<AutoReviewDelegate>(async (request) => {
+ seenIntents.push(request.userIntent);
+ return { verdict: 'allow' as const };
+ });
+ const agent = new CodexAgent(createDeps({}, {
+ capabilityRouting: {
+ overrides: [{
+ capabilityId: 'feishu',
+ source: {
+ kind: 'harness-plugin',
+ harness: 'codex',
+ surface: 'mcp',
+ id: 'cindy-routed-feishu-delegate',
+ artifactId: 'feishu-delegate',
+ containerId: 'feishu-delegate@personal',
+ },
+ invocation: 'explicit-only',
+ explicitSelectors: [
+ '$feishu-delegate:message-feishu-coworkers',
+ '/feishu-delegate:message-feishu-coworkers',
+ ],
+ replacement: { kind: 'cindy-plugin', id: 'xd-feishu' },
+ }],
+ },
+ getMcpToolApprovalPolicy: () => 'auto-approve',
+ reviewAutoPermissionAction,
+ }));
+ let turnSeq = 0;
+ const host = installFakeHost(agent, (method) => {
+ if (method === Method.TurnStart) {
+ turnSeq += 1;
+ return { turn: { id: `turn-${turnSeq}` } };
+ }
+ return undefined;
+ }, { userAgent: 'mock-codex/0.145.0' });
+ const handle = await agent.startSession({
+ sessionId: 'session-yield-origin-context',
+ model: 'gpt-5.4',
+ workingDir: '/repo',
+ permissionMode: 'auto',
+ });
+ const handlers = host.getThreadHandlers();
+ if (!handlers?.itemCompleted || !handlers.turnCompleted || !handlers.mcpServerElicitation || !handlers.commandExecutionApproval) {
+ throw new Error('expected item, turn, elicitation, and approval handlers');
+ }
+ await handle.send({
+ type: 'user',
+ content: '用 $feishu-delegate:message-feishu-coworkers 查消息并跑 typecheck',
+ });
+ handlers.itemCompleted({
+ threadId: 'start-thread-id',
+ turnId: 'turn-1',
+ item: {
+ id: 'item-exec-origin-context',
+ type: 'commandExecution',
+ command: 'pnpm --filter desktop run typecheck',
+ status: 'completed',
+ aggregatedOutput: 'Script running with cell ID 226',
+ },
+ });
+ handlers.turnCompleted({
+ threadId: 'start-thread-id',
+ turn: { id: 'turn-1', status: 'completed' },
+ });
+ await vi.waitFor(() => {
+ expect(yieldTurnStartCalls(host)).toHaveLength(1);
+ });
+ handlers.turnStarted?.({
+ threadId: 'start-thread-id',
+ turn: { id: 'turn-2', status: 'inProgress' },
+ });
+ handlers.itemStarted?.({
+ threadId: 'start-thread-id',
+ turnId: 'turn-2',
+ item: {
+ id: 'item-routed-feishu-yield',
+ type: 'mcpToolCall',
+ server: 'cindy-routed-feishu-delegate',
+ tool: 'feishu_read_messages',
+ pluginId: 'feishu-delegate@personal',
+ },
+ });
+ await expect(handlers.mcpServerElicitation({
+ threadId: 'start-thread-id',
+ turnId: 'turn-2',
+ serverName: 'cindy-routed-feishu-delegate',
+ mode: 'form',
+ _meta: {
+ codex_approval_kind: 'mcp_tool_call',
+ tool_name: 'feishu_read_messages',
+ },
+ message: 'Allow tool call',
+ requestedSchema: {},
+ })).resolves.toEqual({ action: 'accept', content: null, _meta: null });
+ await expect(handlers.commandExecutionApproval({
+ threadId: 'start-thread-id',
+ turnId: 'turn-2',
+ itemId: 'item-exec-origin-context-review',
+ command: 'pnpm --filter desktop run typecheck',
+ cwd: '/repo',
+ })).resolves.toEqual({ decision: 'accept' });
+ expect(seenIntents.some((intent) => intent.includes('查消息并跑 typecheck'))).toBe(true);
+ expect(seenIntents.some((intent) => intent.includes('foreground exec cell'))).toBe(false);
+ await handle.close();
+ });
+
it('detects Responses/proxy function_call(exec_command) yield output', async () => {
const agent = new CodexAgent(createDeps());
let turnSeq = 0;
diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.ts
index b070e38320..88aaabc1ef 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -1184,6 +1184,8 @@ type YieldContinuationClaim = {
originTurnId: string;
continuationTurnId: string | null;
permissionPolicy: TurnPermissionPolicy | null;
+ capabilitySelectionText: string;
+ autoReviewIntent: string;
deferredPlanText: string | null;
deferredPlanTurnId: string | null;
deferredPlanCapabilitySelectionText: string;
@@ -3264,6 +3266,8 @@ export class CodexAgent extends BaseAgent {
originTurnId,
continuationTurnId: null,
permissionPolicy: activeTurnPermissionPolicy,
+ capabilitySelectionText: '',
+ autoReviewIntent: '',
deferredPlanText: null,
deferredPlanTurnId: null,
deferredPlanCapabilitySelectionText: '',
@@ -3430,6 +3434,12 @@ export class CodexAgent extends BaseAgent {
...(claim.permissionPolicy
? { turnPermissionPolicy: claim.permissionPolicy }
: {}),
+ ...(claim.capabilitySelectionText
+ ? { [CODEX_INHERITED_CAPABILITY_SELECTION]: claim.capabilitySelectionText }
+ : {}),
+ ...(claim.autoReviewIntent
+ ? { [CODEX_AUTO_REVIEW_INTENT]: claim.autoReviewIntent }
+ : {}),
};
try {
await handle.send(
@@ -9061,6 +9071,12 @@ export class CodexAgent extends BaseAgent {
if (yieldedCells.length > 0) {
yieldClaim.cells = dedupeCells([...yieldClaim.cells, ...yieldedCells]);
}
+ if (!yieldClaim.capabilitySelectionText && completedCapabilitySelectionText) {
+ yieldClaim.capabilitySelectionText = completedCapabilitySelectionText;
+ }
+ if (!yieldClaim.autoReviewIntent && currentAutoReviewIntent) {
+ yieldClaim.autoReviewIntent = currentAutoReviewIntent;
+ }
} else if (existingYieldClaim?.state === 'active') {
existingYieldClaim.settled = true;
activeYieldContinuationId = null;
@@ -9083,6 +9099,9 @@ export class CodexAgent extends BaseAgent {
suppressSuccessfulYieldBoundary = true;
} else {
yieldClaim = mintYieldContinuationClaim(outstandingCells, turn.id, retryCount);
+ yieldClaim.permissionPolicy = existingYieldClaim.permissionPolicy;
+ yieldClaim.capabilitySelectionText = existingYieldClaim.capabilitySelectionText;
+ yieldClaim.autoReviewIntent = existingYieldClaim.autoReviewIntent;
yieldClaim.deferredPlanText = existingYieldClaim.deferredPlanText;
yieldClaim.deferredPlanTurnId = existingYieldClaim.deferredPlanTurnId;
yieldClaim.deferredPlanCapabilitySelectionText =
@@ -9090,6 +9109,10 @@ export class CodexAgent extends BaseAgent {
}
} else if (yieldedCells.length > 0) {
yieldClaim = mintYieldContinuationClaim(yieldedCells, turn.id, 0);
+ // turn/completed already deleted the origin turn's selection map. Use the
+ // snapshot taken before that delete, plus the still-live review intent.
+ yieldClaim.capabilitySelectionText = completedCapabilitySelectionText;
+ yieldClaim.autoReviewIntent = currentAutoReviewIntent;
}
if (!suppressSuccessfulYieldBoundary) {
const idleStatusEvent: AgentEvent = {