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。

CR10: 远程 autonomy.set 对指定伙伴做可见性校验

nanabfe43b08e191
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/botRemoteSettingsHost.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/botRemoteSettingsHost.test.ts
index 57375656a9..9a3236582b 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/botRemoteSettingsHost.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botRemoteSettingsHost.test.ts
@@ -195,3 +195,15 @@ it('limits messaging-platform operations to this teammate and keeps the WeChat f
// There is no operation that takes credentials.
expect(await call('channels.im.add', { token: 'x' })).toMatchObject({ ok: false, code: 'INVALID_PARAMS' });
});
+
+it('holds the teammate a host-wide autonomy change names to the same visibility as a teammate-scoped call', async () => {
+ const hidden = setup({ visible: false });
+ expect(await hidden.call('autonomy.set', { schedulerBotId: 'bot-2' }, null)).toMatchObject({ ok: false, code: 'NOT_FOUND' });
+ expect(hidden.deps.autonomy.set).not.toHaveBeenCalled();
+ // Turning it off names nobody.
+ expect(await hidden.call('autonomy.set', { schedulerBotId: null }, null)).toMatchObject({ ok: true });
+ expect(hidden.deps.autonomy.set).toHaveBeenCalledWith(null);
+ const visible = setup();
+ expect(await visible.call('autonomy.set', { schedulerBotId: 'bot-2' }, null)).toMatchObject({ ok: true });
+ expect(visible.deps.autonomy.set).toHaveBeenCalledWith('bot-2');
+});
diff --git a/apps/desktop/src/main/localDb/ipc/botRemoteSettingsHost.ts b/apps/desktop/src/main/localDb/ipc/botRemoteSettingsHost.ts
index 5cbaeb99bf..7a3f02452e 100644
--- a/apps/desktop/src/main/localDb/ipc/botRemoteSettingsHost.ts
+++ b/apps/desktop/src/main/localDb/ipc/botRemoteSettingsHost.ts
@@ -34,6 +34,12 @@ export interface BotSettingsHostDeps {
/** Codes whose message is written for the user's page and is safe to hand to the controller. */
const FORWARDED_CODES = new Set(['PRECONDITION_FAILED', 'INVALID_PARAMS', 'NOT_FOUND', 'ALREADY_EXISTS', 'UNSUPPORTED_CAPABILITY']);
const BOT_ID = /^[A-Za-z0-9_-]{1,128}$/;
+/**
+ * Host-wide operations that still name a teammate in their arguments. The named teammate is held to
+ * the same visibility as a teammate-scoped call, so a controller cannot reach a hidden or archived one
+ * through them (e.g. make it the follow-up teammate).
+ */
+const HOST_OP_BOT_ARGS: Partial<Record<BotSettingsOp, string>> = { 'autonomy.set': 'schedulerBotId' };
const MAX_MESSAGE = 300;
const failure = (code: string, message: string): BotSettingsResult => ({ ok: false, code, message: message.slice(0, MAX_MESSAGE) });
@@ -74,6 +80,12 @@ export function createBotRemoteSettingsHost(deps: BotSettingsHostDeps) {
assertCurrent();
return failure('NOT_FOUND', 'Teammate unavailable');
}
+ const namedArg = HOST_OP_BOT_ARGS[op];
+ const named = namedArg ? (args as Record<string, unknown>)[namedArg] : null;
+ if (typeof named === 'string' && !(BOT_ID.test(named) && await deps.botVisible(named))) {
+ assertCurrent();
+ return failure('NOT_FOUND', 'Teammate unavailable');
+ }
assertCurrent();
const value = await handler({ controllerDeviceId: context.controllerDeviceId, botId, args: args as Record<string, unknown>, assertCurrent });
// A result produced for another account or after a revoke must never be delivered.
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index ed830b67ad..36e8fe5ed9 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -808,7 +808,7 @@ Session 任务遵守同一套机制与呈现契约:
- 已纳入观察范围但没有可用跟进者时为 null:不叫醒任何伙伴;范围内的本机任务「等你」超过阈值时宿主直接发系统提醒
(桌面通知 + 手机推送,主窗口在前台时不弹桌面通知),同一事件只提醒一次。跟进者的内置规则被主人暂停时同样处理。
- 设置「自动跟进所有任务」:账号级、只存 override(`bot-autonomy-settings.json` 的 `schedulerBotId`,显式 null = 关掉);
- 恢复默认 = 删除 override。目标伙伴必须存在且未归档;它被归档后关闭,不擅自转交其他伙伴。本机 IPC 仅可信界面使用;远程和手机经同账号的伙伴设置资源、绑定 owner/controller/revision 的动作修改。
+ 恢复默认 = 删除 override。目标伙伴必须存在且未归档;它被归档后关闭,不擅自转交其他伙伴。远程控制端设置时,目标还要对远程可见(未隐藏、未归档,与伙伴设置页其他操作同一判据;`autonomy.set` 虽是整机操作,宿主入口仍按它的 `schedulerBotId` 校验),否则按「伙伴不可用」拒绝,关闭(null)不受限。本机 IPC 仅可信界面使用;远程和手机经同账号的伙伴设置资源、绑定 owner/controller/revision 的动作修改。
override 文件存在但读不出(损坏 / 超限 / 无权限)时失败关闭:按关掉处理并记一条警告,保持关闭且不再显示首次邀请;
恢复默认会删掉坏文件。设置变化、伙伴新建 / 资料保存 / 暂停 / 恢复 / 归档都立即重算跟进者(不等 60 秒的定时重读)。