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。

chore: 同步 main 并解决 Hook 装配冲突

liugaoweifa2464c2bd5b
diff --cc apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
index 137f1c83dc,caf945d596..2e07b204dd
--- a/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
+++ b/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
@@@ -1252,9 -1264,10 +1265,11 @@@ export function readLegacyInstallTrust(
}
export function createGhostInstallReceipt(input: {
+ simulatorPreviousRelId?: string;
+ simulatorMarketRelease?: GhostInstallReceipt['simulatorMarketRelease'];
taskCapabilityApproved?: true;
targetCapabilityApproved?: true;
+ harnessCapabilityApproved?: string[];
manifest: GhostManifest;
localeResources: Record<string, GhostManifestLocaleResource>;
enabled: boolean;
diff --cc apps/desktop/src/main/cindy-brain/index.ts
index 0e3e68fddf,5c5bc94804..d5d3e41411
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@@ -7646,9 -7636,10 +7667,11 @@@ async function installOrUpdateMarketGho
manager.update(cindyFilePath, {
taskCapabilityApproved: confirmedTaskCapability(expected.consent, installed, inspected.manifest),
targetCapabilityApproved: confirmedTaskCapability(expected.consent, installed, inspected.manifest, 'targets'),
+ harnessCapabilityApproved: confirmedHarnessCapabilities(expected.consent, installed, inspected.manifest),
expectedPackageSha256: inspected.packageSha256,
expectedInstalledApproval: expected.expectedInstalledApproval!,
+ ...(previousRelId ? { simulatorPreviousRelId: previousRelId } : {}),
+ ...(previousRelId ? { simulatorMarketRelease: expected.simulatorMarketRelease } : {}),
...(expected.sourceChanged ? { sourceStateArchiveId: ghostSourceStateArchiveId(installed) } : {}),
...(trustOverride ? { trustOverride } : {}),
namespace: marketNamespace,
diff --cc apps/desktop/src/main/maker-host/built-in-skills.ts
index 1944bc81b9,1944bc81b9..3f6abe8cb4
--- a/apps/desktop/src/main/maker-host/built-in-skills.ts
+++ b/apps/desktop/src/main/maker-host/built-in-skills.ts
@@@ -25,7 -25,7 +25,7 @@@ const VERSIONS_DIRECTORY = '.versions'
const ACTIVE_BUNDLE_LINK = '.active';
const BUILT_IN_SKILL_MUTATION_WAIT_MS = 5_000;
/** Increment whenever shipped built-in Skill bytes change between releases. */
--export const BUILT_IN_SKILLS_BUNDLE_VERSION = 19;
++export const BUILT_IN_SKILLS_BUNDLE_VERSION = 20;
const PLUGIN_CREATOR_FIRST_BUNDLE_VERSION = 13;
export interface BuiltInSkillDescriptor {
diff --cc packages/maker-core/src/agents/claude-code/__tests__/auto-review-wiring.test.ts
index ef490fb3d5,eb273f58bf..f06a896410
--- 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
@@@ -273,33 -303,7 +303,33 @@@ describe('Auto-review wiring: native fi
await handle.close();
});
- it('downgrades native OAuth Auto after SDK init reveals a settings MCP', async () => {
- const { handle, fakeQuery, queryPermissionMode } = await startSession('auto', {
++ // Unit merge regression: actual SDK hook registration must retain native Auto
++ // handback and plugin decisions together; plugin continue must never grant permission.
++ it.each(['continue', 'block'] as const)('preserves native Auto handback with plugin %s', async (action) => {
++ const { handle, preToolUse, queryPermissionMode, reviewAutoPermissionAction } = await startSession('auto', {
+ providerId: 'anthropic',
+ authSource: 'oauth',
- initMcpServerNames: ['settings_prompt_mcp'],
- blockMcpServerStatus: true,
- });
-
- // Settings MCPs are not host-injected, so startup legitimately begins native Auto.
- expect(queryPermissionMode).toBe('auto');
- await vi.waitFor(() => expect(fakeQuery.setPermissionMode).toHaveBeenCalledWith('default'));
- await handle.close();
- });
-
- it('closes instead of leaving settings MCPs in native Auto when downgrade fails', async () => {
- const { handle, fakeQuery } = await startSession('auto', {
- providerId: 'anthropic',
- authSource: 'oauth',
- initMcpServerNames: ['settings_prompt_mcp'],
- rejectPermissionModeChange: true,
++ mcpProviderNames: ['cindy_orca'],
++ mcpToolApprovalPolicy: () => 'auto-approve',
+ });
-
- await vi.waitFor(() => expect(fakeQuery.close).toHaveBeenCalledTimes(1));
- await handle.close();
++ const plugin = vi.fn(async () => ({ action }));
++ try {
++ expect(queryPermissionMode).toBe('auto');
++ expect(handle.setHarnessHookHandler).toBeTypeOf('function');
++ handle.setHarnessHookHandler!(plugin);
++ expect(await preToolUse('mcp__cindy_orca__create_workers', { workers: [] }))
++ .toEqual(action === 'block' ? ['ask', 'deny'] : ['ask']);
++ expect(plugin).toHaveBeenCalledWith({
++ name: 'tool.before', toolName: 'mcp__cindy_orca__create_workers',
++ toolUseId: 'tu', input: { workers: [] },
++ });
++ expect(reviewAutoPermissionAction).not.toHaveBeenCalled();
++ } finally {
++ await handle.close();
++ }
+ });
+
- it('does not close an already-default host-MCP session when SDK init reports settings MCPs', async () => {
+ it('keeps native Claude Auto when the SDK init reveals settings MCPs', async () => {
const { handle, fakeQuery, queryPermissionMode } = await startSession('auto', {
providerId: 'anthropic',
authSource: 'oauth',
diff --cc packages/maker-core/src/agents/claude-code/index.ts
index 90b39150b6,d049651285..96938322d6
--- a/packages/maker-core/src/agents/claude-code/index.ts
+++ b/packages/maker-core/src/agents/claude-code/index.ts
@@@ -2200,9 -2208,32 +2210,34 @@@ export class ClaudeCodeAgent extends Ba
})],
}],
};
+ // Native Claude Auto skips canUseTool. Hand back only the calls Cindy itself must decide;
+ // everything else stays with the native classifier so no call is reviewed twice.
+ const nativeAutoPolicyHook: HookCallback = async (input) => {
+ if (input.hook_event_name !== 'PreToolUse') return { continue: true };
+ if (
+ mutablePermissionMode !== 'auto' || mutablePlanMode || planTurnActive
+ || !usesNativeClaudeAutoReview()
+ ) return { continue: true };
+ const pre = input as PreToolUseHookInput;
+ const toolName = pre.tool_name;
+ const decide = (permissionDecision: 'allow' | 'ask', reason: string) => ({
+ continue: true,
+ hookSpecificOutput: { hookEventName: 'PreToolUse' as const, permissionDecision, permissionDecisionReason: reason },
+ });
+ const isMcp = resolveMcpToolTarget(toolName, registeredMcpServerNames) !== null;
+ const mcpPolicy = isMcp ? classifyMcpApprovalPolicy(toolName, pre.tool_input) : null;
+ // Requester authority (owner / group guest) and forceConfirmToolCall are only known to
+ // Cindy, and a channel policy outranks trusted-MCP approval: route every call to canUseTool.
+ if (activeTurnPermissionPolicy) return decide('ask', 'Cindy reviews tool calls in channel turns.');
+ // Trusted MCP still goes through canUseTool: the Host shortcut allows it without a model call,
+ // but a plugin-delegated task must be re-checked against its live delegation scope first.
+ if (mcpPolicy === 'auto-approve') return decide('ask', 'Trusted Cindy tool: Host shortcut and delegation check.');
+ if (mcpPolicy === 'prompt-each-time') return decide('ask', 'This tool requires Cindy confirmation.');
+ return { continue: true };
+ };
- const localClaudeHooks = reviewMode
+ const harnessHookBridge = createHarnessHookBridge();
+ const harnessHooksEnabled = !reviewMode && !hosted && !opts.remoteHostId;
+ const baseLocalClaudeHooks = reviewMode
? mergeClaudeHookSets(
{ PreToolUse: [{ hooks: [reviewReadOnlyHook] }] },
nativeCliAuth ? workspaceSettingsConfigChangeHooks : undefined,
@@@ -2242,9 -2273,9 +2277,11 @@@
buildClaudeAskUserQuestionCallerProvenanceHooks(),
nativeCliAuth ? workspaceSettingsConfigChangeHooks : undefined,
this.deps.claudeHooks,
+ // Last: earlier guards may deny; this only routes what remains.
+ { PreToolUse: [{ hooks: [nativeAutoPolicyHook] }] },
);
+ const localClaudeHooks = mergeClaudeHookSets(baseLocalClaudeHooks,
+ harnessHooksEnabled ? buildClaudeHarnessHooks(request => harnessHookBridge.run(request)) : undefined);
const deniedCapabilityRoute = (toolName: string) => {
const route = findClaudeMcpCapabilityRoute(
this.deps.capabilityRouting,
@@@ -6398,42 -6414,9 +6454,43 @@@
});
};
const handle: AgentSessionHandle = {
+ harnessHooks: harnessHooksEnabled ? ['tool.before', 'compaction.before'] : [],
+ setHarnessHookHandler: handler => harnessHookBridge.setHandler(handler),
+ ...(harnessHooksEnabled ? {
+ requestHarnessCompaction: () => {
+ if (closed || turnInFlight || harnessCompaction || pendingRewindTo ||
+ idleResumeRebuildGate || cancellationRebuildGate || runningBackgroundTasks.size > 0) {
+ return Promise.reject(new Error('SESSION_RUNNING: Claude is not idle for compaction'));
+ }
+ return new Promise<{ noop?: boolean }>((resolve, reject) => {
+ harnessCompaction = { boundary: false, result: false, failed: false, resolve, reject };
+ // Reserve the existing query lane synchronously. Both host automatic
+ // compaction and all user sends honor turnInFlight; Claude owns the
+ // command, native PreCompact hooks, transcript and context adoption.
+ turnInFlight = true;
+ let dispatched = false;
+ try {
+ beginNewTurn(mutableFastMode ? 'priority' : 'standard');
+ resetToolLoopGuards();
+ dispatched = inputQueue.push({ type: 'user', message: { role: 'user', content: '/compact' }, parent_tool_use_id: null });
+ if (!dispatched) throw new Error('Claude compaction input queue is closed');
+ armUpstreamResponseIdle();
+ } catch (error) {
+ // Only a rejected dispatch can release the lane without a native
+ // terminal. Once queued, a lost acknowledgement is not replayable.
+ if (!dispatched) {
+ harnessCompaction = undefined;
+ turnInFlight = false;
+ clearUpstreamResponseIdle();
+ }
+ reject(error instanceof Error ? error : new Error('Claude compaction dispatch failed'));
+ }
+ });
+ },
+ } : {}),
disabledSkillPaths: disabledSkillSnapshot,
- getAutoReviewOwner: () => usesNativeClaudeAutoReview() ? 'native' : 'cindy',
+ // IM turn policies carry requester authority the native classifier cannot see.
+ getAutoReviewOwner: () => usesNativeClaudeAutoReview() && !activeTurnPermissionPolicy ? 'native' : 'cindy',
reviewAutoPermissionAction: async (action) => {
const decision = await reviewAutoAction(
action,
diff --cc packages/maker-core/src/agents/codex/index.ts
index cf24f05769,b91bd91e7e..22eb8aed23
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@@ -12956,16 -12907,13 +12978,22 @@@ assertRouteCurrent()
// warning for diagnostics to avoid rendering a duplicate error card.
log.warn('Codex Guardian warning', { threadId: params.threadId, message: params.message });
},
+ warning: (params) => {
+ if (params.message.startsWith(CODEX_HTTPS_FALLBACK_WARNING_PREFIX)) {
+ log.info('codex fell back to HTTPS transport; reconnect deadline cleared', { threadId });
+ clearReconnectStall();
+ }
+ },
error: (params) => {
+ if (harnessCompaction && params.scope !== 'transport') {
+ if ((!params.turnId || params.turnId === harnessCompaction.turnId) && params.willRetry !== true)
+ harnessCompaction.failed = true;
+ return;
+ }
+ if (params.scope === 'transport') {
+ nativeHarnessHooks?.invalidate();
+ finishHarnessCompaction(new Error('Codex compaction connection lost'));
+ }
// buffered turn 的 error (含终态) 同样进队列等对账 (greptile R11 P1 +
// codex R12 P1): 合法 → 激活后重放走正常终端路径收口 send; 孤儿 →
// 丢弃, 不得让孤儿 error 终结合法 send。