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(plugin): 同步主干并解决目标接口冲突

liugaowei1bc9ee9f33d2
diff --cc apps/desktop/src/main/cindy-brain/index.ts
index c5debd949a,9388ba1302..8980785abe
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@@ -7037,97 -7045,101 +7058,102 @@@ async function updateLocalGhostPackageL
);
if (sourceChanged) assertGhostRelocationIdle(instanceId);
rejectUnauthorizedTokenBroker(inspected.canonicalManifest, authorizationOverrides);
- runtime.stop(instanceId);
- // 等待失败表示旧进程仍可能存活;此时不能恢复 resident,否则会产生
- // 两份后台进程。仅在确认退出后的更新阶段失败时恢复旧版本。
- await getGhostNodeRuntimeBroker().stopAndWait(instanceId);
- // 用户已明确选择了这份本地真实包:同 id 可以原位替换,市场来源不是永久所有权。
- // 替换前先切断旧市场更新路由;用户状态由安装事务隔离归档,落位失败再恢复。
- const detachMarketRecord = Boolean(marketRecord?.installed);
- const restoreMarketRecord = (): void => {
- if (!detachMarketRecord || !marketRecord) return;
- try {
- // 来源解绑不触碰 opt-out,失败恢复同样只恢复旧路由;用户过去的显式
- // 卸载决定因此既不会被新增,也不会被清除。
- marketLedger.restoreInstallation(marketRecord);
- } catch (error) {
- // 恢复失败时保持路由失效是安全降级:不能让旧市场自动覆盖用户明确选择的本地包。
- log.error('failed to restore Plugin market provenance after local update failure', {
- ghostId: inspected.manifest.id,
- error: error instanceof Error ? error.message : String(error),
- });
+ const releaseSync = pluginDeviceSync.beginMutation(instanceId);
+ try {
+ runtime.stop(instanceId);
+ // 等待失败表示旧进程仍可能存活;此时不能恢复 resident,否则会产生
+ // 两份后台进程。仅在确认退出后的更新阶段失败时恢复旧版本。
+ await getGhostNodeRuntimeBroker().stopAndWait(instanceId);
+ // 用户已明确选择了这份本地真实包:同 id 可以原位替换,市场来源不是永久所有权。
+ // 替换前先切断旧市场更新路由;用户状态由安装事务隔离归档,落位失败再恢复。
+ const detachMarketRecord = Boolean(marketRecord?.installed);
+ const restoreMarketRecord = (): void => {
+ if (!detachMarketRecord || !marketRecord) return;
+ try {
+ // 来源解绑不触碰 opt-out,失败恢复同样只恢复旧路由;用户过去的显式
+ // 卸载决定因此既不会被新增,也不会被清除。
+ marketLedger.restoreInstallation(marketRecord);
+ } catch (error) {
+ // 恢复失败时保持路由失效是安全降级:不能让旧市场自动覆盖用户明确选择的本地包。
+ log.error('failed to restore Plugin market provenance after local update failure', {
+ ghostId: inspected.manifest.id,
+ error: error instanceof Error ? error.message : String(error),
+ });
+ }
+ };
+ if (detachMarketRecord && marketRecord) {
+ try {
+ // 先持久化切断自动更新路由,再改真实包。普通本地/Forge 换源不是
+ // 用户显式卸载,不得产生 default-install opt-out。
+ marketLedger.markRemovedRecord(marketRecord, null);
+ } catch (error) {
+ restoreMarketRecord();
+ spawnIfResident(previousGhost);
+ log.warn('failed to detach Plugin market provenance before local update', {
+ ghostId: inspected.manifest.id,
+ error: error instanceof Error ? error.message : String(error),
+ });
+ throwIpcError('INTERNAL', 'Unable to detach the installed Plugin source');
+ }
}
- };
- if (detachMarketRecord && marketRecord) {
+ getGhostAgentSlot().clearGhost(instanceId);
+ getGhostErrandSlot().clearGhost(instanceId);
+ let result: Awaited<ReturnType<typeof manager.update>>;
+ let packagePlaced = false;
try {
- // 先持久化切断自动更新路由,再改真实包。普通本地/Forge 换源不是
- // 用户显式卸载,不得产生 default-install opt-out。
- marketLedger.markRemovedRecord(marketRecord, null);
- } catch (error) {
- restoreMarketRecord();
- spawnIfResident(previousGhost);
- log.warn('failed to detach Plugin market provenance before local update', {
+ result = await withActiveOwnerGhostOauthMutationLock(
+ instanceId,
+ () =>
+ manager.update(cindyFilePath, {
+ taskCapabilityApproved: confirmedTaskCapability(consent, previousGhost, inspected.manifest),
++ targetCapabilityApproved: confirmedTaskCapability(consent, previousGhost, inspected.manifest, 'targets'),
+ expectedPackageSha256,
+ expectedInstalledApproval,
+ installOrigin: installOrigin ?? 'manual',
+ ...(sourceChanged ? { sourceStateArchiveId: ghostSourceStateArchiveId(previousGhost) } : {}),
+ ...deliveryNamespaceFields(previousGhost),
+ beforePackageCommit: () => {
+ if (isCurrent?.() === false) throwIpcError('PRECONDITION_FAILED', 'Plugin operation is no longer current');
+ return getGhostOauthAccountManager().prepareAccountsForChangedClients(
+ previousGhost.manifest, inspected.canonicalManifest, instanceId,
+ );
+ },
+ onPackagePlaced: () => {
+ packagePlaced = true;
+ },
+ }),
+ );
+ } catch (err) {
+ if (!packagePlaced) {
+ restoreMarketRecord();
+ spawnIfResident(previousGhost);
+ throw err;
+ }
+ const placed = findInstalledGhostByInstanceId(manager.list(), instanceId) ??
+ manager.list().find((ghost) => ghost.dir === previousGhost.dir);
+ if (!placed) throw err;
+ log.warn('local ghost post-placement notification failed', {
ghostId: inspected.manifest.id,
- error: error instanceof Error ? error.message : String(error),
+ error: err instanceof Error ? err.message : String(err),
});
- throwIpcError('INTERNAL', 'Unable to detach the installed Plugin source');
- }
- }
- getGhostAgentSlot().clearGhost(instanceId);
- getGhostErrandSlot().clearGhost(instanceId);
- let result: Awaited<ReturnType<typeof manager.update>>;
- let packagePlaced = false;
- try {
- result = await withActiveOwnerGhostOauthMutationLock(
- instanceId,
- () =>
- manager.update(cindyFilePath, {
- taskCapabilityApproved: confirmedTaskCapability(consent, previousGhost, inspected.manifest),
- targetCapabilityApproved: confirmedTaskCapability(consent, previousGhost, inspected.manifest, 'targets'),
- expectedPackageSha256,
- expectedInstalledApproval,
- installOrigin: installOrigin ?? 'manual',
- ...(sourceChanged ? { sourceStateArchiveId: ghostSourceStateArchiveId(previousGhost) } : {}),
- ...deliveryNamespaceFields(previousGhost),
- beforePackageCommit: () => {
- if (isCurrent?.() === false) throwIpcError('PRECONDITION_FAILED', 'Plugin operation is no longer current');
- return getGhostOauthAccountManager().prepareAccountsForChangedClients(
- previousGhost.manifest, inspected.canonicalManifest, instanceId,
- );
- },
- onPackagePlaced: () => {
- packagePlaced = true;
- },
- }),
- );
- } catch (err) {
- if (!packagePlaced) {
- restoreMarketRecord();
- spawnIfResident(previousGhost);
- throw err;
+ result = { ghost: placed };
}
- const placed = findInstalledGhostByInstanceId(manager.list(), instanceId) ??
- manager.list().find((ghost) => ghost.dir === previousGhost.dir);
- if (!placed) throw err;
- log.warn('local ghost post-placement notification failed', {
- ghostId: inspected.manifest.id,
- error: err instanceof Error ? err.message : String(err),
- });
- result = { ghost: placed };
- }
- if ('rejection' in result) {
- // 回滚失败时安装目录可能已是新字节或缺失,不能恢复旧 runtime 或旧市场来源路由。
- if (!(result.rejection.code === 'io' && result.rejection.rollbackFailed)) {
- restoreMarketRecord();
- spawnIfResident(previousGhost);
+ if ('rejection' in result) {
+ // 回滚失败时安装目录可能已是新字节或缺失,不能恢复旧 runtime 或旧市场来源路由。
+ if (!(result.rejection.code === 'io' && result.rejection.rollbackFailed)) {
+ restoreMarketRecord();
+ spawnIfResident(previousGhost);
+ }
+ throwInstallError(result.rejection);
}
- throwInstallError(result.rejection);
+ runtime.resetFuse(instanceId);
+ await bindPluginUsage(result.ghost,
+ !detachMarketRecord && previousGhost?.approval.state === 'approved' ? previousGhost.approval.revision : undefined);
+ spawnIfResident(result.ghost);
+ return result.ghost;
+ } finally {
+ releaseSync();
}
- runtime.resetFuse(instanceId);
- await bindPluginUsage(result.ghost,
- !detachMarketRecord && previousGhost?.approval.state === 'approved' ? previousGhost.approval.revision : undefined);
- spawnIfResident(result.ghost);
- return result.ghost;
}
/**
diff --cc apps/desktop/src/main/maker-host/built-in-skills.ts
index 671bb841f6,671bb841f6..04af10afc5
--- 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 = 15;
++export const BUILT_IN_SKILLS_BUNDLE_VERSION = 16;
const PLUGIN_CREATOR_FIRST_BUNDLE_VERSION = 13;
export interface BuiltInSkillDescriptor {
diff --cc apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
index 70060098d8,b13bab5bd4..8830e369aa
--- a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
@@@ -1558,27 -1647,50 +1647,71 @@@ describe('agent-chosen control steering
function expected(h: ReturnType<typeof createHarness>) {
return { session: h.getTurnSessionIdentity(), turnGeneration: 0 };
}
+ // Production entry: steerControlInput. Plugin target grants must survive screening
+ // and provider preparation; existing turn-boundary cases do not revoke grants. In-memory unit tier.
+ it.each(['screening', 'provider-preparation'])('does not queue or accept input revoked during %s', async (stage) => {
+ const h = createHarness();
+ h.setRunning(true);
+ let revoked = false;
+ const beforeMutation = async () => { if (revoked) throw new Error('PERMISSION_DENIED'); };
+ if (stage === 'screening') h.setScreenUserMessage(async () => {
+ revoked = true;
+ return { action: 'allow' };
+ });
+ else h.steerToAgent.mockImplementationOnce(async (_id, _message, sendOpts) => {
+ revoked = true;
+ await sendOpts.beforeProviderStart?.();
+ });
+ await expect(h.coordinator.steerControlInput(sid, { item: makeItem('report', 'context') },
+ { ...expected(h), beforeMutation })).rejects.toThrow('PERMISSION_DENIED');
+ expect(h.coordinator.hasPendingQueueItem(sid, 'report')).toBe(false);
+ expect(h.onSteerAccepted).not.toHaveBeenCalled();
+ expect(h.sendToAgent).not.toHaveBeenCalled();
+ });
+ // #6399, unit: real coordinator + action admission. Existing tests covered turn
+ // changes, not a current tool's revoked authority over an otherwise valid row.
+ it.each([
+ ['new', 'screening'], ['queued', 'screening'],
+ ['new', 'provider'], ['queued', 'provider'],
+ ] as const)(
+ 'preserves input and never accepts a %s control steer revoked during %s',
+ async (source, boundary) => {
+ const h = createHarness();
+ h.setRunning(true);
+ await h.coordinator.ensureQueueRestored(sid);
+ const item = makeItem('report', 'worker result');
+ if (source === 'queued') h.coordinator.enqueue(sid, item);
+ let current = true;
+ const decision = await admitTaskAction(
+ { server: 'cindy_helper', sessionId: 'caller', tool: 'steer_session', args: {} },
+ {
+ key: 'input', ownerInput: true, delegated: false,
+ assertCurrent: async () => {
+ if (!current) throw new Error('TASK_ACTION_AUTHORIZATION_EXPIRED');
+ },
+ },
+ );
+ if (!decision.ok || !decision.run) throw new Error('missing action scope');
+ const accepted = vi.fn();
+ h.setScreenUserMessage(async () => {
+ if (boundary === 'screening') current = false;
+ return { action: 'allow' };
+ });
+ h.steerToAgent.mockImplementationOnce(async (_id, _message, sendOpts) => {
+ current = false;
+ await sendOpts?.[MCP_APP_MESSAGE_GUARD]?.();
+ accepted();
+ });
+ await expect(decision.run(() => h.coordinator.steerControlInput(
+ sid, source === 'queued' ? { queuedClientId: item.clientId } : { item }, expected(h),
+ ))).rejects.toThrow('TASK_ACTION_AUTHORIZATION_EXPIRED');
+ if (boundary === 'screening') expect(h.steerToAgent).not.toHaveBeenCalled();
+ expect(accepted).not.toHaveBeenCalled();
+ expect(h.sendToAgent).not.toHaveBeenCalled();
+ expect(h.onSteerAccepted).not.toHaveBeenCalled();
+ expect(h.coordinator.hasPendingQueueItem(sid, item.clientId)).toBe(source === 'queued');
+ },
+ );
it('joins a running turn even though ordinary new turns must queue', async () => {
const h = createHarness();
h.setRunning(true);
diff --cc apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
index 10a5871095,0a0f468528..e89373a69d
--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
@@@ -2553,12 -2568,12 +2571,16 @@@ export class AgentInputCoordinator
item.persistedContent,
referenceContexts,
);
- const appMessageGuard = queuedAppMessageGuard(item);
+ const appMessageGuard = combineInputGuards(
+ queuedAppMessageGuard(item),
+ taskActionInputGuard(sessionId, item),
+ beforeMutation ? assertSteerAuthority : undefined,
+ );
await this.deps.steerToAgent(sessionId, buildMakerUserMessage(item, referenceContexts), {
+ ...(opts?.beforeMutation ? { beforeProviderStart: async () => {
+ try { await opts.beforeMutation!(); }
+ catch (error) { authorizationFailed = true; throw error; }
+ } } : {}),
...(appMessageGuard ? { [MCP_APP_MESSAGE_GUARD]: appMessageGuard } : {}),
...(item.sharedTaskAuthor ? { sharedTaskAuthor: item.sharedTaskAuthor } : {}),
[AUTO_REVIEW_SOURCE_CONTENT]: queuedAutoReviewText(item),
diff --cc apps/desktop/src/main/maker-ipc/register.ts
index 0ee331ac5a,6e9b9ccc99..ad2eb06933
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@@ -11300,7 -11531,7 +11536,8 @@@ export function registerMakerIpc(maker
autoReviewUserText: params.autoReviewUserText,
botTaskCoordination: params.botTaskCoordination,
authorizationGuard: params.authorizationGuard,
+ files: params.files,
+ taskActionDeliveryGuard: params.taskActionDeliveryGuard,
});
return {
ok: true as const,
diff --cc apps/desktop/src/preload/ghostPreload.ts
index 41ef872366,0940b9ebdb..8e0118ea5b
--- a/apps/desktop/src/preload/ghostPreload.ts
+++ b/apps/desktop/src/preload/ghostPreload.ts
@@@ -65,15 -65,10 +65,17 @@@ contextBridge.exposeInMainWorld('cindy'
},
fs: (req: Record<string, unknown>): Promise<unknown> =>
ipcRenderer.invoke('ghost-pipe:send', { ...req, type: 'fs-request' }),
+ deviceSync: (req: Record<string, unknown>): Promise<unknown> =>
+ ipcRenderer.invoke('ghost-pipe:send', { ...req, type: 'device-sync-request' }),
library: (req: Record<string, unknown>): Promise<unknown> =>
ipcRenderer.invoke('ghost-pipe:send', { ...req, type: 'library-request' }),
+ targets: Object.fromEntries(['list', 'resolve', 'send', 'cancel'].map(kind => [kind,
+ async (req: Record<string, unknown> = {}): Promise<unknown> => {
+ const result = await ipcRenderer.invoke('ghost-pipe:send', { ...req, type: 'targets-request', kind });
+ if (result?.ok === true) return result.data;
+ throw Object.assign(new Error(result?.error?.message ?? 'Target request failed'), { code: result?.error?.code ?? 'HOST_NOT_READY' });
+ },
+ ])),
tasks: Object.fromEntries(
['capabilities', 'models', 'setModel', 'requestWriteAccess', 'startTeam', 'getTeam', 'setTeamPlan', 'releaseWorker', 'create', 'list', 'get', 'send', 'getRun', 'listRuns', 'cancel', 'readMessages', 'setHidden'].map(kind => [
kind, async (req: Record<string, unknown> = {}): Promise<unknown> => {