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。

Merge remote-tracking branch 'upstream/main' into feat/issue-397-ios-simulator-native-framebuffer

JiangJiahaoee17ee94c3a1
diff --cc apps/desktop/scripts/ci/lib.mjs
index 80d424f0de,f31f965413..6ea593bdef
--- a/apps/desktop/scripts/ci/lib.mjs
+++ b/apps/desktop/scripts/ci/lib.mjs
@@@ -551,132 -740,18 +740,140 @@@ export function verifyMacContactsPermis
if (hasAppleEventsEntitlement(readCodesignEntitlements(helperApp))) {
throw new Error(`helper app must not receive Apple Events entitlement: ${helperApp}`);
}
+ if (
+ keychainAccessGroup &&
+ hasKeychainAccessGroup(readCodesignEntitlements(helperApp), keychainAccessGroup)
+ ) {
+ throw new Error(`helper app must not receive WebAuthn keychain access group: ${helperApp}`);
+ }
}
- console.log('==> Verified macOS Contacts usage descriptions and main-only Apple Events entitlement');
+ console.log(
+ `==> Verified macOS Contacts usage descriptions and main-only Apple Events${keychainAccessGroup ? ' / WebAuthn' : ''} entitlements`,
+ );
}
+const IOS_SIMULATOR_HELPER_RELATIVE_PATH = path.join(
+ 'Contents',
+ 'Helpers',
+ 'Cindy iOS Simulator Helper.app',
+);
+const IOS_SIMULATOR_HELPER_EXECUTABLE = 'ios-simulator-sidecar';
+const IOS_SIMULATOR_SIDECAR_MANIFEST_RELATIVE_PATH = path.join(
+ 'Contents',
+ 'Resources',
+ 'ios-simulator',
+ 'native-sidecar-manifest.json',
+);
+
+function runSigningCommand(command, args, label) {
+ const result = spawnSync(command, args, { encoding: 'utf8' });
+ if (result.error) {
+ throw new Error(`${label} could not execute: ${result.error.message}`);
+ }
+ if (result.status !== 0) {
+ throw new Error(`${label} failed: ${result.stderr || result.stdout}`);
+ }
+ return {
+ stdout: result.stdout ?? '',
+ stderr: result.stderr ?? '',
+ };
+}
+
+function inspectDesignatedRequirement(bundlePath) {
+ const result = runSigningCommand(
+ '/usr/bin/codesign',
+ ['-d', '-r', '-', bundlePath],
+ 'iOS Simulator helper designated requirement inspection',
+ );
+ const output = `${result.stdout}\n${result.stderr}`;
+ const requirement = output.match(/designated\s*=>\s*(.+)/)?.[1]?.trim();
+ if (!requirement) {
+ throw new Error('iOS Simulator helper designated requirement is unavailable');
+ }
+ return requirement;
+}
+
+function inspectMachOArchitectures(executablePath) {
+ const { stdout } = runSigningCommand(
+ '/usr/bin/lipo',
+ ['-archs', executablePath],
+ 'iOS Simulator helper architecture inspection',
+ );
+ const architectures = stdout
+ .trim()
+ .split(/\s+/)
+ .filter((architecture) => architecture === 'arm64' || architecture === 'x86_64');
+ if (architectures.length === 0) {
+ throw new Error('iOS Simulator helper has no supported architecture');
+ }
+ return [...new Set(architectures)].sort();
+}
+
+/**
+ * Writes the Host-private identity record after the nested Helper is signed.
+ * The main app is signed afterwards, sealing this resource into its code signature.
+ */
+export function writeIOSSimulatorSidecarManifest(appPath, signing) {
+ const helperPath = path.join(appPath, IOS_SIMULATOR_HELPER_RELATIVE_PATH);
+ const executablePath = path.join(
+ helperPath,
+ 'Contents',
+ 'MacOS',
+ IOS_SIMULATOR_HELPER_EXECUTABLE,
+ );
+ const infoPlistPath = path.join(helperPath, 'Contents', 'Info.plist');
+ if (!fs.existsSync(executablePath) || !fs.existsSync(infoPlistPath)) {
+ throw new Error('packaged iOS Simulator helper is incomplete');
+ }
+
+ const manifestPath = path.join(appPath, IOS_SIMULATOR_SIDECAR_MANIFEST_RELATIVE_PATH);
+ const manifest = {
+ schemaVersion: 1,
+ artifactId: 'cindy.ios-simulator-sidecar',
+ bundleIdentifier: readPlistString(infoPlistPath, 'CFBundleIdentifier'),
+ version: readPlistString(infoPlistPath, 'CFBundleShortVersionString'),
+ architectures: inspectMachOArchitectures(executablePath),
+ sha256: sha256(executablePath),
+ signing: {
+ mode: signing.mode,
+ teamIdentifier: signing.teamIdentifier ?? null,
+ designatedRequirement: inspectDesignatedRequirement(helperPath),
+ hardenedRuntime: true,
+ },
+ };
+ fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
+ fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, {
+ mode: 0o644,
+ });
+ return manifestPath;
+}
+
+function signIOSSimulatorHelper(appPath, signArgs, signing) {
+ const helperPath = path.join(appPath, IOS_SIMULATOR_HELPER_RELATIVE_PATH);
+ const executablePath = path.join(
+ helperPath,
+ 'Contents',
+ 'MacOS',
+ IOS_SIMULATOR_HELPER_EXECUTABLE,
+ );
+ if (!fs.existsSync(executablePath)) {
+ throw new Error(`packaged iOS Simulator helper is missing: ${executablePath}`);
+ }
+ console.log(' Signing iOS Simulator helper executable...');
+ runSigningCommand(
+ '/usr/bin/codesign',
+ [...signArgs, executablePath],
+ 'iOS Simulator helper signing',
+ );
+ console.log(' Signing iOS Simulator helper bundle...');
+ runSigningCommand(
+ '/usr/bin/codesign',
+ [...signArgs, helperPath],
+ 'iOS Simulator helper bundle signing',
+ );
+ writeIOSSimulatorSidecarManifest(appPath, signing);
+}
+
export function adhocSignMacApp(appPath, helperEntitlementsPath, mainEntitlementsPath) {
console.log('==> Ad-hoc signing macOS app for local packaged testing...');
const signBase = '/usr/bin/codesign --force --options runtime --sign -';
@@@ -711,9 -782,15 +908,15 @@@
/**
* Developer ID 由内向外逐层签名(Electron app 不能依赖 --deep)。
- * @param {{ signIdentity: string }} identity
+ * @param {{ signIdentity: string, teamId: string }} identity
*/
- export function signMacAppWithIdentity(appPath, helperEntitlementsPath, mainEntitlementsPath, identity) {
+ export function signMacAppWithIdentity(
+ appPath,
+ helperEntitlementsPath,
+ mainEntitlementsPath,
+ identity,
+ { keychainAccessGroup } = {},
+ ) {
console.log(' Removing provenance attributes...');
exec(`/usr/bin/xattr -dr com.apple.provenance "${appPath}" 2>/dev/null || true`);
diff --cc apps/desktop/scripts/package-desktop.mjs
index c670125385,019ddbc6a7..57f0c2bcce
--- a/apps/desktop/scripts/package-desktop.mjs
+++ b/apps/desktop/scripts/package-desktop.mjs
@@@ -376,19 -405,9 +408,21 @@@ async function finishDarwin(
files.push(fileEntry('hotfix', hotfixZipPath));
} else {
// 版本无关(或显式放行)→ ad-hoc 签名,产出 .app 的 zip 供本机/内部试用。
+ writeMacEntitlements(helperEntitlementsPath);
+ writeMacEntitlements(mainEntitlementsPath, { appleEvents: true });
adhocSignMacApp(appPath, helperEntitlementsPath, mainEntitlementsPath);
+ if (requireNativeReleaseGate) {
+ throw new Error(
+ 'CINDY_IOS_SIMULATOR_RELEASE_NATIVE_SMOKE=1 requires a Developer ID signed and notarized package',
+ );
+ }
+ if (arch === 'arm64' && !isPhysicalArm64Mac()) {
+ console.log(
+ '==> Skipping iOS Simulator release gate: arm64 app is not runnable on this Intel host',
+ );
+ } else {
+ runIOSSimulatorReleaseGate(appPath, arch, 'untrusted');
+ }
const appZipPath = path.join(artifactDir, `${baseName}-${arch}.zip`);
console.log('==> Creating app ZIP (ad-hoc signed)...');
if (fs.existsSync(appZipPath)) fs.unlinkSync(appZipPath);
diff --cc apps/desktop/src/main/maker-host/index.ts
index e710c4d493,807502b693..30c206f078
--- a/apps/desktop/src/main/maker-host/index.ts
+++ b/apps/desktop/src/main/maker-host/index.ts
@@@ -990,14 -992,40 +1002,46 @@@ export function getMaker(): Maker
// codex 子进程没法消费 in-process JS instance, prepareCodexExtraSpawnConfig
// 起 streamable-HTTP bridge 把 instance 通过 -c 'mcp_servers...=...' 注入。
mcpProviders: codexMcpProviders,
- capabilityRouting: DESKTOP_CAPABILITY_ROUTING_POLICY,
+ // Evaluate after app-server startup prepared (or reused) the MCP bridge.
+ // The bridge snapshot is the applied capability surface; the preference
+ // alone can be ahead of it while a busy Codex turn defers refresh.
+ get capabilityRouting() {
+ return buildDesktopCapabilityRoutingPolicy({
+ cindyComputerAvailable:
+ getActiveCodexBridgeServerNames()?.includes('cindy_computer') === true,
+ });
+ },
+ resolveCapabilityRouting: async ({
+ workingDir,
+ remoteHostId,
+ vendorOptions,
+ codexBrowserUseProvisioned,
+ ensureCodexBrowserUseReady,
+ }) => {
+ const disabledPluginIds =
+ readDisabledBuiltinPluginIds(vendorOptions)
+ ?? getPluginRegistry().getDisabledRuntimePluginIds(workingDir);
+ const cindyBrowserEnabled = !disabledPluginIds.includes('browser');
+ let connectedCodexBrowserUse = codexBrowserUseProvisioned;
+ if (!remoteHostId && !cindyBrowserEnabled && connectedCodexBrowserUse) {
+ connectedCodexBrowserUse = await ensureCodexBrowserUseReady();
+ }
+ return buildDesktopCapabilityRoutingPolicy({
+ cindyComputerAvailable:
+ getActiveCodexBridgeServerNames()?.includes('cindy_computer') === true,
+ cindyBrowserEnabled,
+ codexBrowserUseAvailable: connectedCodexBrowserUse,
+ codexBrowserUseProvisioned,
+ remoteHostId,
+ });
+ },
makerMemory: makerMemoryManager,
+ codexHostDynamicToolProvider: createIOSSimulatorCodexDynamicToolProvider({
+ deps: getIOSSimulatorMcpDeps(),
+ isEnabled: (workingDir) =>
+ getPluginRegistry().isEnabled('ios-simulator', workingDir),
+ }),
+ getShellCommandPolicy: ({ command }) => getDesktopShellCommandPolicy(command),
// 通讯录 prompt 段有效状态(codex 版): 在 claude 的判定链之上再与「实际应用
// 到 running app-server 的 spawn 快照」对齐 —— 开关切换后失效失败(busy,
// contacts-ipc 折成 codexMcpRefreshed:false)时 stale 桥里没有新工具面,
@@@ -1082,12 -1120,22 +1136,28 @@@
// bridge 整体缺席 = cindy_contacts 必然不可达
codexAppliedContactsEnabled = false;
}
+ const shellGuardDir = ensureAgentShellGuards();
+ if (shellGuardDir) {
+ mcpExtraEnv.PATH = [shellGuardDir, mcpExtraEnv.PATH ?? process.env.PATH]
+ .filter((value): value is string => Boolean(value))
+ .join(path.delimiter);
+ }
+ const isControlPlane = ctx.hostPurpose === 'control-plane';
+ const browserCompanion = isControlPlane
+ ? null
+ : await prepareCodexBrowserCompanion({ codexHome: getCodexHome() });
+ const browserCompanionSpawnConfig =
+ resolveCodexBrowserCompanionSpawnConfig(browserCompanion);
+ mcpExtraArgs.push(...browserCompanionSpawnConfig.extraArgs);
+ if (
+ browserCompanion?.status === 'unavailable' &&
+ browserCompanion.reason !== 'platform_unsupported'
+ ) {
+ desktopMakerLogger.warn('Codex Browser companion unavailable', {
+ reason: browserCompanion.reason,
+ detail: browserCompanion.detail,
+ });
+ }
// API 模式: 追加 model_provider override, 让 codex app-server 走 AI Gateway
// 而非 OAuth 订阅后端。每次 createHost 都现读 mode, 切模式后重建即生效。
// 关掉 API 模式则不带这些 flag —— 天然可逆 (见 codex-gateway-config.ts)。
diff --cc apps/desktop/src/main/maker-ipc/register.ts
index f44e8f26ca,57ed2a95bb..765091578e
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@@ -361,12 -431,8 +431,10 @@@ import
resolveSessionReferences,
} from './sessionReferenceResolver.js';
import { registerAndroidAutomationHandlers } from './androidHandlers.js';
+import { registerIOSSimulatorHandlers } from './iosSimulatorHandlers.js';
+import { reconcileIOSSimulatorOwnership } from '../mcp-integrations/ios-simulator.js';
import { MAKER_INVOKE, MAKER_PUSH, MAKER_SEND } from './channels.js';
- import type {
- CollabDispatchOutcome,
- } from './collabSendOutcome.js';
+ import type { CollabDispatchOutcome } from './collabSendOutcome.js';
import { runAcceptedCallback } from './acceptedCallbackRunner.js';
import { createElectronIpcHandlerRegistry } from './electronIpcRegistry.js';
import { refreshCodexMcpEnvironment } from './codexMcpRefresh.js';
diff --cc apps/desktop/src/preload/preload.ts
index df3b869175,b9175b482a..f7fd77c6c6
--- a/apps/desktop/src/preload/preload.ts
+++ b/apps/desktop/src/preload/preload.ts
@@@ -526,16 -558,20 +572,22 @@@ const fanOutMakerProviderUpstreamError
const fanOutMakerAutoPermissionFallback = createIpcFanOut('maker:auto-permission:fallback');
const fanOutMakerCodexRuntimeRouteChanged = createIpcFanOut('maker:codex-runtime-route-changed');
// 延迟凭证切换在 turn 结束兑现的广播(payload = { sessionId, model, providerId })。
- const fanOutMakerSessionCredentialSwitchApplied = createIpcFanOut('maker:session-credential-switch-applied');
+ const fanOutMakerSessionCredentialSwitchApplied = createIpcFanOut(
+ 'maker:session-credential-switch-applied',
+ );
const fanOutMakerClaudeSessionRouteChanged = createIpcFanOut('maker:claude-session-route-changed');
+const fanOutIOSSimulatorFocusRequest = createIpcFanOut('maker:ios-simulator:focus-request');
+const fanOutIOSSimulatorH264Frame = createIpcFanOut('maker:ios-simulator:h264-frame');
// 会话后台活动翻转广播(payload = { sessionId, active }):turn 已结束但 CC 子进程仍在调模型。
- const fanOutMakerSessionBackgroundActivityChanged = createIpcFanOut('maker:session-background-activity-changed');
- const fanOutMakerUsageTodaySpend = createIpcFanOut('usage:today-spend-changed'); // Claude USD
- const fanOutMakerUsageTodayTokens = createIpcFanOut('usage:today-tokens-changed'); // Codex token
+ const fanOutMakerSessionBackgroundActivityChanged = createIpcFanOut(
+ 'maker:session-background-activity-changed',
+ );
+ const fanOutMakerUsageTodaySpend = createIpcFanOut('usage:today-spend-changed'); // Claude USD
+ const fanOutMakerUsageTodayTokens = createIpcFanOut('usage:today-tokens-changed'); // Codex token
const fanOutMakerUsageModelPricing = createIpcFanOut('usage:model-pricing-changed');
- const fanOutMakerUsageReferenceModelPricing = createIpcFanOut('usage:reference-model-pricing-changed');
+ const fanOutMakerUsageReferenceModelPricing = createIpcFanOut(
+ 'usage:reference-model-pricing-changed',
+ );
const fanOutMakerUsageClaudeAccount = createIpcFanOut('usage:claude-account-changed'); // Claude 月度配额
const fanOutMakerUsageCodexAccount = createIpcFanOut('usage:codex-account-changed'); // Codex 订阅用量
const fanOutMakerUsageXaiRateLimit = createIpcFanOut('usage:xai-rate-limit-changed'); // xAI bridge 限流快照
diff --cc apps/desktop/src/renderer/vite-env.d.ts
index 55ee215683,2a264b62ab..c4fb99c61b
--- a/apps/desktop/src/renderer/vite-env.d.ts
+++ b/apps/desktop/src/renderer/vite-env.d.ts
@@@ -24,28 -24,9 +24,27 @@@ type VoiceInputConnectionTestResult
type DesktopLoginAction = import('../shared/authIpc').DesktopLoginAction;
type DesktopLoginActionResult = import('../shared/authIpc').DesktopLoginActionResult;
type UtilityTextFailure = import('../shared/utilityTextResult').UtilityTextFailure;
+type IOSSimulatorSessionStatus = import('../shared/iosSimulatorIpc').IOSSimulatorSessionStatus;
+type IOSSimulatorStatusRequest = import('../shared/iosSimulatorIpc').IOSSimulatorStatusRequest;
+type IOSSimulatorToolRequest = import('../shared/iosSimulatorIpc').IOSSimulatorToolRequest;
+type IOSSimulatorToolResponse = import('../shared/iosSimulatorIpc').IOSSimulatorToolResponse;
+type IOSSimulatorAgentControlRequest =
+ import('../shared/iosSimulatorIpc').IOSSimulatorAgentControlRequest;
+type IOSSimulatorFocusRequest = import('../shared/iosSimulatorIpc').IOSSimulatorFocusRequest;
+type IOSSimulatorH264FramePush = import('../shared/iosSimulatorIpc').IOSSimulatorH264FramePush;
+type IOSSimulatorLiveTouchRequest =
+ import('../shared/iosSimulatorIpc').IOSSimulatorLiveTouchRequest;
+type IOSSimulatorMutationControlRequest =
+ import('../shared/iosSimulatorIpc').IOSSimulatorMutationControlRequest;
+type IOSSimulatorViewerRouteRequest =
+ import('../shared/iosSimulatorIpc').IOSSimulatorViewerRouteRequest;
+type IOSSimulatorViewerVisibilityRequest =
+ import('../shared/iosSimulatorIpc').IOSSimulatorViewerVisibilityRequest;
+type IOSSimulatorStreamProfileRequest =
+ import('../shared/iosSimulatorIpc').IOSSimulatorStreamProfileRequest;
type MakerSessionTreeSnapshot = import('@cindy/maker-core').SessionTreeSnapshot;
type BrowserBackendHealth = import('../shared/browserBackend').BrowserBackendHealth;
- type BrowserBackendRecoveryResult =
- import('../shared/browserBackend').BrowserBackendRecoveryResult;
+ type BrowserBackendRecoveryResult = import('../shared/browserBackend').BrowserBackendRecoveryResult;
type DesktopAccountDeletionConfirmInput =
import('../shared/authIpc').DesktopAccountDeletionConfirmInput;
type DesktopAccountDeletionAvailabilityResult =