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(cindy-make): reject forks of disabled sessions

MagicLizi8a3dcbd3d2e6
diff --git a/apps/desktop/src/main/__tests__/fork.test.ts b/apps/desktop/src/main/__tests__/fork.test.ts
index 41a688c6bd..d4417480a8 100644
--- a/apps/desktop/src/main/__tests__/fork.test.ts
+++ b/apps/desktop/src/main/__tests__/fork.test.ts
@@ -20,6 +20,7 @@ import { CodexResumePreparationBlockedError } from '@cindy/maker-core';
import { CODEX_RESUME_NOT_READY_WIRE_MESSAGE } from '@cindy/maker-shared/agent-input-projection';
import { projectSessionContextWindow } from '../../shared/sessionContextWindow';
import { computeForkSourceMessagesDigest } from '../localDb/forkRecoverySnapshot.js';
+import { MAKER_INVOKE } from '../maker-ipc/channels.js';
const UUID_V4_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
@@ -28,6 +29,24 @@ const UUID_V4_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9
// maker.forkSdkSession 内部已包含 SDK 调用 + uuidMap 构建; 业务测试只关心其入参
// (确认 fork 把对的 sourceSdkSessionId / upToMessageId / title / workingDir 传下去)
// 和返回值 (uuidMap 决定 messages.agentMeta remap 结果)。
+const { ipcHandlers, sessionCreatedMock } = vi.hoisted(() => ({
+ ipcHandlers: new Map<string, (event: unknown, ...args: unknown[]) => Promise<unknown>>(),
+ sessionCreatedMock: vi.fn(),
+}));
+vi.mock('electron', () => ({
+ ipcMain: {
+ handle: (
+ channel: string,
+ handler: (event: unknown, ...args: unknown[]) => Promise<unknown>,
+ ) => {
+ ipcHandlers.set(channel, handler);
+ },
+ },
+}));
+vi.mock('../localDb/ipc/sessionCreatedBroadcast.js', () => ({
+ emitSessionCreated: sessionCreatedMock,
+}));
+
const forkSdkSessionMock = vi.fn();
vi.mock('../maker-host/index.js', () => ({
getMaker: () => ({
@@ -95,6 +114,8 @@ const originalXdtUserDataDir = process.env.XDT_USER_DATA_DIR;
const tempDirs: string[] = [];
beforeEach(async () => {
+ ipcHandlers.clear();
+ sessionCreatedMock.mockClear();
if (originalClaudeConfigDir === undefined) delete process.env.CLAUDE_CONFIG_DIR;
else process.env.CLAUDE_CONFIG_DIR = originalClaudeConfigDir;
if (originalXdtUserDataDir === undefined) delete process.env.XDT_USER_DATA_DIR;
@@ -205,6 +226,49 @@ async function writeClaudeJsonlInConfigDir(
// ── tests ──────────────────────────────────────────────────────────────────
+describe('disabled Cindy Make fork boundaries', () => {
+ const cases = ['cindy-make', 'cindy-make-merge'].flatMap((source) =>
+ [MAKER_INVOKE.FORK, MAKER_INVOKE.FORK_STRIP_ENCRYPTED].flatMap((channel) =>
+ ['orchestration', 'legacy IPC'].map((entryPoint) => ({ source, channel, entryPoint })),
+ ),
+ );
+
+ it.each(cases)(
+ 'rejects $source through $entryPoint $channel before reading history or creating a child',
+ async ({ source, channel, entryPoint }) => {
+ selectQueue.push(
+ [makeSourceRow({ source, agentKind: 'codex' })],
+ [makeMessageRow({ clientId: 'legacy-message' })],
+ );
+ const args =
+ channel === MAKER_INVOKE.FORK
+ ? ['src-session', 'legacy-message']
+ : ['src-session'];
+ let operation: Promise<unknown>;
+ if (entryPoint === 'legacy IPC') {
+ const { registerMakerForkIpc } = await import('../maker-ipc/fork.js');
+ registerMakerForkIpc();
+ operation = ipcHandlers.get(channel)!({}, ...args);
+ } else {
+ operation =
+ channel === MAKER_INVOKE.FORK
+ ? forkSessionAtMessage('src-session', 'legacy-message')
+ : forkSessionStripEncrypted('src-session');
+ }
+
+ await expect(operation).rejects.toMatchObject({ code: 'UNSUPPORTED_CAPABILITY' });
+ expect(selectQueue).toHaveLength(1);
+ expect(forkSdkSessionMock).not.toHaveBeenCalled();
+ expect(txMock).not.toHaveBeenCalled();
+ expect(queryOneMock).not.toHaveBeenCalled();
+ expect(queryMock).not.toHaveBeenCalled();
+ expect(createMessageMock).not.toHaveBeenCalled();
+ expect(commitContextRebuildMock).not.toHaveBeenCalled();
+ expect(sessionCreatedMock).not.toHaveBeenCalled();
+ },
+ );
+});
+
describe('forkSessionAtMessage', () => {
it.each([
{ marker: 200000, projectedWindow: 200000 },
diff --git a/apps/desktop/src/main/maker-orchestration/fork.ts b/apps/desktop/src/main/maker-orchestration/fork.ts
index 06583bfd33..0a1af11e76 100644
--- a/apps/desktop/src/main/maker-orchestration/fork.ts
+++ b/apps/desktop/src/main/maker-orchestration/fork.ts
@@ -14,6 +14,7 @@ import { createId } from '@paralleldrive/cuid2';
import { CodexResumePreparationBlockedError, isCodexHistoryRecoveryRequired } from '@cindy/maker-core';
import { CODEX_RESUME_NOT_READY_WIRE_MESSAGE } from '@cindy/maker-shared/agent-input-projection';
+import { assertCindyMakeSessionAvailable } from '../cindy-make/featureGate.js';
import { getDbClient } from '../localDb/client/current';
import { sessions, messages } from '../localDb/schema';
import { sessionToCamel } from '../localDb/mapper';
@@ -784,6 +785,8 @@ export async function forkSessionAtMessage(
throw forkError('SOURCE_NOT_FOUND', `Source session ${sourceSessionId} 不存在`);
}
+ assertCindyMakeSessionAvailable(source.source);
+
// 轮 26 发现 5 防御深度:远端会话 fork 由 SDK 层拒绝(pi forkSdkSession 抛
// NotSupportedError remoteFork;cc/codex 由 daemon 远端执行)。host 层显式
// 守卫兜底 —— 若未来某 agent 的 SDK 守卫漏掉,这里阻止 DB 写入产生
@@ -1092,6 +1095,9 @@ export async function forkSessionStripEncrypted(sourceSessionId: string): Promis
if (!source) {
throw forkError('SOURCE_NOT_FOUND', `Source session ${sourceSessionId} 不存在`);
}
+
+ assertCindyMakeSessionAvailable(source.source);
+
// 先校验"类型"再校验"运行状态":non-codex 会话(可能 sdkSessionId 也为空)应拿到
// 更准确的 NOT_CODEX_SESSION 而不是 SOURCE_NEVER_RAN。
if (source.agentKind !== 'codex') {
diff --git a/docs/cindy-make-upstream.md b/docs/cindy-make-upstream.md
index cfa5195a37..ff00472b6a 100644
--- a/docs/cindy-make-upstream.md
+++ b/docs/cindy-make-upstream.md
@@ -18,6 +18,12 @@
[UsageTaskTable](../apps/desktop/src/renderer/components/settings/usage/UsageTaskTable.tsx) 与
[用量任务排名测试](../apps/desktop/src/renderer/components/settings/usage/__tests__/usageTaskTable.test.tsx)。
+历史制作与上游合并任务也不能通过普通分叉或剥离加密内容分叉转为可见普通任务。公共
+分叉函数在读取源任务的持久来源后、复制历史或原生线程及创建子任务前拒绝,旧控制端的
+既有 fork 通道同样受此门禁约束;普通任务流程不变。实现与回归见
+[fork](../apps/desktop/src/main/maker-orchestration/fork.ts) 与
+[fork.test](../apps/desktop/src/main/__tests__/fork.test.ts)。
+
共享开关见 [cindyMakeFeature](../packages/maker-shared/src/cindyMakeFeature.ts),
执行边界见 [featureGate](../apps/desktop/src/main/cindy-make/featureGate.ts) 与
[回归测试](../apps/desktop/src/main/maker-ipc/__tests__/cindyMakeFeatureGate.test.ts)。