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(desktop): remove agent-triggered app installation

Cindybd85a5926c43
diff --git a/apps/desktop/src/main/__tests__/updateService.test.ts b/apps/desktop/src/main/__tests__/updateService.test.ts
index fdcf877c13..89177da553 100644
--- a/apps/desktop/src/main/__tests__/updateService.test.ts
+++ b/apps/desktop/src/main/__tests__/updateService.test.ts
@@ -326,8 +326,8 @@ describe('installation version repair scope', () => {
});
});
-describe('agent-triggered managed app update', () => {
- it('only schedules a single native relaunch for a downloaded newer version', async () => {
+describe('agent-facing managed app update check', () => {
+ it('reports a downloaded newer version without restarting the app', async () => {
readAutoUpdateSettings.mockReturnValue({ autoRelaunchOnIdle: false });
fetchManifest.mockResolvedValue(updateManifest());
download.mockImplementation(async ({ targetPath }: { targetPath: string }) => {
@@ -336,24 +336,14 @@ describe('agent-triggered managed app update', () => {
return { path: targetPath, size: 123 };
});
const service = await freshUpdateService('darwin');
- const exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined) as never);
try {
- expect(service.installAppUpdateForAgent()).toMatchObject({ accepted: false });
expect(await service.checkAppUpdateForAgent()).toMatchObject({
status: 'ready', currentVersion: '0.0.64', targetVersion: '0.0.65',
});
- expect(service.installAppUpdateForAgent()).toMatchObject({
- accepted: true, currentVersion: '0.0.64', targetVersion: '0.0.65',
- });
- expect(service.installAppUpdateForAgent()).toMatchObject({ accepted: false });
- expect(spawnProcess).not.toHaveBeenCalled();
await vi.advanceTimersByTimeAsync(5_000);
- await vi.waitFor(() => expect(spawnProcess).toHaveBeenCalledOnce());
- expect(JSON.stringify(spawnProcess.mock.calls)).toContain('/bin/bash');
- expect(JSON.stringify(spawnProcess.mock.calls)).not.toContain('launchctl');
+ expect(spawnProcess).not.toHaveBeenCalled();
} finally {
service.stopUpdateService();
- exitSpy.mockRestore();
}
});
@@ -368,7 +358,6 @@ describe('agent-triggered managed app update', () => {
const service = await freshUpdateService('darwin');
expect(await service.checkAppUpdateForAgent()).toMatchObject({ status: 'ready' });
appIsInApplicationsFolder.mockReturnValue(false);
- expect(service.installAppUpdateForAgent()).toMatchObject({ accepted: false });
expect(await service.checkAppUpdateForAgent()).toMatchObject({ status: 'unsupported' });
await vi.advanceTimersByTimeAsync(5_000);
expect(spawnProcess).not.toHaveBeenCalled();
@@ -378,7 +367,6 @@ describe('agent-triggered managed app update', () => {
it('reports an unsupported Linux installation before fetching an update', async () => {
const service = await freshUpdateService('linux');
expect(await service.checkAppUpdateForAgent()).toMatchObject({ status: 'unsupported' });
- expect(service.installAppUpdateForAgent()).toMatchObject({ accepted: false });
expect(fetchManifest).not.toHaveBeenCalled();
checkDebianManagedInstallation.mockReturnValue({ status: 'managed' });
expect(await service.checkAppUpdateForAgent()).not.toMatchObject({ status: 'unsupported' });
@@ -389,20 +377,17 @@ describe('agent-triggered managed app update', () => {
const service = await freshUpdateService('win32');
checkWindowsUpdaterPrerequisites.mockReturnValue({ satisfied: false, missingFiles: ['vcruntime140.dll'] });
expect(await service.checkAppUpdateForAgent()).toMatchObject({ status: 'unsupported' });
- expect(service.installAppUpdateForAgent()).toMatchObject({ accepted: false });
expect(fetchManifest).not.toHaveBeenCalled();
service.stopUpdateService();
});
- it('does not schedule an update from a development build or a current version', async () => {
+ it('reports an unsupported development build and an up-to-date release', async () => {
const service = await freshUpdateService('darwin');
isDev.mockReturnValue(true);
expect(await service.checkAppUpdateForAgent()).toMatchObject({ status: 'unsupported' });
- expect(service.installAppUpdateForAgent()).toMatchObject({ accepted: false });
isDev.mockReturnValue(false);
fetchManifest.mockResolvedValue(updateManifest('0.0.64'));
expect(await service.checkAppUpdateForAgent()).toMatchObject({ status: 'no_installable_update' });
- expect(service.installAppUpdateForAgent()).toMatchObject({ accepted: false });
expect(spawnProcess).not.toHaveBeenCalled();
});
});
diff --git a/apps/desktop/src/main/maker-host/host-system-prompt.md b/apps/desktop/src/main/maker-host/host-system-prompt.md
index efdc65bec1..e350573753 100644
--- a/apps/desktop/src/main/maker-host/host-system-prompt.md
+++ b/apps/desktop/src/main/maker-host/host-system-prompt.md
@@ -1,4 +1,4 @@
You are Cindy, an open-source AI assistant.
Source: https://github.com/makecindy/cindy
-When asked to update the Cindy application hosting this task, use the cindy_helper app_update tools to check and install the update. Never replace the running Cindy application through shell commands or create a persistent restart job (including launchctl submit). If a release exists but the current update channel has no installable update, say so; do not sideload it. If the managed tools are unavailable, direct the user to Cindy's built-in Check for Updates action; do not improvise an installer. Installing restarts Cindy and may end this task; an accepted request is not proof that the new version started successfully.
+When asked to update the Cindy application hosting this task, use cindy_helper check_app_update to check the current update channel. If an installable update is ready, direct the user to Cindy's built-in Check for Updates action for manual installation; do not install or restart the application yourself. Never replace the running Cindy application through shell commands or create a persistent restart job (including launchctl submit). If a release exists but the current update channel has no installable update, say so; do not sideload it. If the managed tool is unavailable, direct the user to the same built-in action; do not improvise an installer.
diff --git a/apps/desktop/src/main/mcp-integrations/mcp-providers.ts b/apps/desktop/src/main/mcp-integrations/mcp-providers.ts
index 58321d457d..0443a75e5e 100644
--- a/apps/desktop/src/main/mcp-integrations/mcp-providers.ts
+++ b/apps/desktop/src/main/mcp-integrations/mcp-providers.ts
@@ -42,7 +42,7 @@ import { feishuIm, wechatIm } from '../im';
import { sendFeishuSessionNotification } from '../im/feishu/notificationOrigin';
import { getSlackToolBridge } from '../hook-control/slackToolBridge.js';
import { createLogger } from '../logger.js';
-import { checkAppUpdateForAgent, installAppUpdateForAgent } from '../updateService.js';
+import { checkAppUpdateForAgent } from '../updateService.js';
import { getScheduler } from '../scheduler-host/index.js';
import { stabilizeHookCommand } from '../scheduler-host/hook-script-generator.js';
import { searchSessionsFn } from '../maker-host/session-search.js';
@@ -392,7 +392,6 @@ export function createDesktopMcpProviders(deps: DesktopMcpProvidersDeps): LiziMc
isCurrentSession: (sessionId, sessionInstanceId) =>
deps.isCurrentLocalSessionInstance?.(sessionId, sessionInstanceId) === true,
check: checkAppUpdateForAgent,
- install: async () => installAppUpdateForAgent(),
},
logger: createLogger('mcp/cindy_helper'),
grokLogin: {
diff --git a/apps/desktop/src/main/updateService.ts b/apps/desktop/src/main/updateService.ts
index 7333125f2f..042333a334 100644
--- a/apps/desktop/src/main/updateService.ts
+++ b/apps/desktop/src/main/updateService.ts
@@ -210,8 +210,6 @@ let lastResumeAtMs: number | null = null;
let startupUpdateCheckInProgress = false;
let resolvedRelaunchTheme: 'light' | 'dark' = 'dark';
let busyProbe: () => boolean | Promise<boolean> = () => false;
-let agentRelaunchScheduled = false;
-let agentRelaunchTimer: ReturnType<typeof setTimeout> | null = null;
// ── Helpers ────────────────────────────────────────────────────────────────
@@ -2073,7 +2071,7 @@ async function executeRelaunchUnguarded(theme: 'light' | 'dark'): Promise<void>
// ── Public API ─────────────────────────────────────────────────────────────
-/** Report known platform apply blockers before telling the agent an update can be scheduled. */
+/** Report known platform apply blockers before suggesting the built-in update action. */
function agentUpdateApplyBlockReason(): string | null {
if (process.platform !== 'win32' && process.platform !== 'darwin' && process.platform !== 'linux') {
return '当前平台不支持应用内更新。';
@@ -2127,37 +2125,6 @@ export async function checkAppUpdateForAgent(): Promise<{
return { status: result, currentVersion, reason: `应用内更新检查结果:${result}` };
}
-export function installAppUpdateForAgent(): {
- accepted: boolean;
- currentVersion: string;
- targetVersion?: string;
- reason?: string;
-} {
- const currentVersion = app.getVersion();
- if (!app.isPackaged || isDev() || isCindyPersonalRuntime() || isVersionlessAppVersion(currentVersion)) {
- return { accepted: false, currentVersion, reason: '此构建不支持应用内更新。' };
- }
- const platformBlock = agentUpdateApplyBlockReason();
- if (platformBlock) return { accepted: false, currentVersion, reason: platformBlock };
- if (agentRelaunchScheduled || isRelaunching || autoRelaunchInProgress) {
- return { accepted: false, currentVersion, reason: '更新重启已在进行中。' };
- }
- if (currentStatus !== 'ready' || !readyVersion || !readyFilePath || !fs.existsSync(readyFilePath)
- || compareAppUpdateVersions(readyVersion, currentVersion) !== 'newer') {
- return { accepted: false, currentVersion, reason: '没有已下载且版本更新的应用内补丁;请先检查更新。' };
- }
- const targetVersion = readyVersion;
- agentRelaunchScheduled = true;
- // Let the MCP tool result reach the agent before the host exits. The existing
- // executor revalidates the staged patch and channel at the actual apply boundary.
- agentRelaunchTimer = setTimeout(() => {
- agentRelaunchTimer = null;
- agentRelaunchScheduled = false;
- void executeRelaunch(resolvedRelaunchTheme);
- }, 5_000);
- return { accepted: true, currentVersion, targetVersion };
-}
-
export function initUpdateService(): void {
// Observe the successful old-updater receipt before existing cleanup removes
// it. Async and metadata-only; no effect on download/apply/rollback decisions.
@@ -2595,11 +2562,6 @@ export async function enableUncustomizedBetaChannel(
}
export function stopUpdateService(): void {
- if (agentRelaunchTimer) {
- clearTimeout(agentRelaunchTimer);
- agentRelaunchTimer = null;
- agentRelaunchScheduled = false;
- }
if (firstCheckTimer) {
clearTimeout(firstCheckTimer);
firstCheckTimer = null;
diff --git a/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts b/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts
index 4362f9bca9..556e4eb670 100644
--- a/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts
+++ b/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts
@@ -18,19 +18,18 @@ function parsePayload(result: unknown): Record<string, unknown> {
}
describe("cindy_helper MCP server", () => {
- it('offers app updates only to a live local task and delegates installation once to the host', async () => {
+ it('offers update checks without installation only to a live local task', async () => {
let context = {
agentKind: 'codex' as const, workingDir: '/repo', sessionId: 'local-task',
sessionInstanceId: 'instance-1', remoteHostId: undefined as string | undefined,
};
let current = true;
const check = vi.fn(async () => ({ status: 'ready', currentVersion: '0.1.86', targetVersion: '0.1.90' }));
- const install = vi.fn(async () => ({ accepted: true, currentVersion: '0.1.86', targetVersion: '0.1.90' }));
const server = createXdtHelperMcpServer({
resolveSurface: async () => 'default',
appUpdate: {
isCurrentSession: (sessionId, instanceId) => current && sessionId === 'local-task' && instanceId === 'instance-1',
- check, install,
+ check,
},
}, {
...context, getSessionContext: () => context,
@@ -44,17 +43,16 @@ describe("cindy_helper MCP server", () => {
try {
const tools = parsePayload(await client.callTool({ name: 'list_tools', arguments: { category: 'app_update' } }));
expect((tools.tools as Array<{ name: string }>).map((tool) => tool.name)).toEqual([
- 'check_app_update', 'install_app_update',
+ 'check_app_update',
]);
expect(await call('check_app_update')).toMatchObject({ status: 'ready', targetVersion: '0.1.90' });
- expect(await call('install_app_update')).toMatchObject({ accepted: true, targetVersion: '0.1.90' });
+ expect(await call('install_app_update')).toMatchObject({ ok: false, errorCode: 'UNKNOWN_TOOL' });
expect(check).toHaveBeenCalledOnce();
- expect(install).toHaveBeenCalledOnce();
current = false;
- expect(await call('install_app_update')).toMatchObject({ ok: false, errorCode: 'STALE_SESSION' });
+ expect(await call('check_app_update')).toMatchObject({ ok: false, errorCode: 'STALE_SESSION' });
context = { ...context, remoteHostId: 'remote-machine' };
- expect(await call('install_app_update')).toMatchObject({ ok: false, errorCode: 'CAPABILITY_NOT_AVAILABLE' });
- expect(install).toHaveBeenCalledOnce();
+ expect(await call('check_app_update')).toMatchObject({ ok: false, errorCode: 'CAPABILITY_NOT_AVAILABLE' });
+ expect(check).toHaveBeenCalledOnce();
} finally {
await client.close();
await server.close();
diff --git a/packages/lizi-mcps/src/xdt-helper/app_update.ts b/packages/lizi-mcps/src/xdt-helper/app_update.ts
index 094ccd4c15..e285d12b99 100644
--- a/packages/lizi-mcps/src/xdt-helper/app_update.ts
+++ b/packages/lizi-mcps/src/xdt-helper/app_update.ts
@@ -5,7 +5,6 @@ import { errorPayload, okPayload } from './_payload.js';
export interface AppUpdateCallbacks {
isCurrentSession(sessionId: string, sessionInstanceId: string): boolean;
check(): Promise<{ status: string; currentVersion: string; targetVersion?: string; reason?: string }>;
- install(): Promise<{ accepted: boolean; currentVersion: string; targetVersion?: string; reason?: string }>;
}
export function registerAppUpdateTools(
@@ -28,7 +27,7 @@ export function registerAppUpdateTools(
registry.register({
name: 'check_app_update',
category: 'app_update',
- description: `检查当前运行的 ${BRAND_NAME} 是否有可通过应用内更新器安装的新版本。不要用 GitHub Release 文件替换正在运行的应用。`,
+ description: `检查当前运行的 ${BRAND_NAME} 是否有可通过应用内更新器安装的新版本。本工具不能安装或重启应用;如需手动安装,请用户使用内置「检查更新」界面。不要用 GitHub Release 文件替换正在运行的应用。`,
inputShape: {},
handler: async () => {
const error = callerError();
@@ -40,23 +39,4 @@ export function registerAppUpdateTools(
}
},
});
-
- registry.register({
- name: 'install_app_update',
- category: 'app_update',
- description: `仅当用户明确要求安装/更新当前运行的 ${BRAND_NAME} 时使用。仅安装应用内更新器已下载的新版本;成功表示已安排重启,不代表新版本已启动。本工具会结束正在运行的 Cindy 和当前任务。不要另写重启脚本或使用 launchctl。`,
- inputShape: {},
- handler: async () => {
- const error = callerError();
- if (error) return error;
- try {
- const result = await deps.callbacks.install();
- return result.accepted
- ? okPayload(result)
- : errorPayload('UPDATE_NOT_READY', result.reason ?? '没有可安装的应用内更新;请先调用 check_app_update。', result);
- } catch (cause) {
- return errorPayload('UPDATE_INSTALL_FAILED', String(cause));
- }
- },
- });
}