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(claude-code): 保留远程图片来源告警

DavidShen401c8b9ac0a2
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/normalizeAttachmentsTemp.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/normalizeAttachmentsTemp.test.ts
index e018dbdef5..8c3e5db797 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/normalizeAttachmentsTemp.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/normalizeAttachmentsTemp.test.ts
@@ -14,8 +14,13 @@ vi.mock('../../imageCacheStore.js', () => ({
}));
vi.mock('../../cindy-media/blobStore.js', () => ({
resolveSafe: vi.fn(),
+ supportedMime: vi.fn(),
+ mimeForExt: vi.fn(),
+}));
+vi.mock('../../cindy-media/ledger.js', () => ({
+ removeRefById: vi.fn(),
+ deleteZeroRefBlobRecord: vi.fn(),
}));
-vi.mock('../../cindy-media/ledger.js', () => ({}));
vi.mock('../../cindy-media/ingest.js', () => ({ ingestMedia: vi.fn() }));
vi.mock('../../device-link/mediaTransfer.js', () => ({
downloadToFile: vi.fn(),
@@ -29,12 +34,18 @@ import {
cleanupOrphanedTempAttachments,
cleanupSessionTempAttachments,
configureTempAttachmentOwner,
+ materializeDirectSendOssAttachments,
normalizeUserMessage,
} from '../normalizeAttachments.js';
+import * as cindyMediaBlobStore from '../../cindy-media/blobStore.js';
+import { ingestMedia } from '../../cindy-media/ingest.js';
+import { downloadToFile, removeRemote } from '../../device-link/mediaTransfer.js';
+import { buildAttachmentOssRef } from '../../../shared/attachmentOssRef.js';
const tempDirs: string[] = [];
beforeEach(async () => {
+ vi.clearAllMocks();
tempRoot.value = await fs.mkdtemp(path.join(os.tmpdir(), 'cindy-review-inline-test-'));
tempDirs.push(tempRoot.value);
configureTempAttachmentOwner({
@@ -48,6 +59,57 @@ afterEach(async () => {
});
describe('inline attachment temporary files', () => {
+ it('marks directly materialized OSS images as desktop-host attachments', async () => {
+ const hash = 'a'.repeat(64);
+ const mediaUrl = `cindy-media://blobs/${hash}.png`;
+ const absPath = path.join(tempRoot.value, 'materialized.png');
+ vi.mocked(downloadToFile).mockImplementationOnce(async (_ossKey, destination) => {
+ await fs.writeFile(destination, Buffer.from([0x89, 0x50, 0x4e, 0x47]));
+ });
+ vi.mocked(cindyMediaBlobStore.supportedMime).mockReturnValue(true);
+ vi.mocked(cindyMediaBlobStore.resolveSafe).mockReturnValue({
+ absPath,
+ mimeType: 'image/png',
+ hash,
+ });
+ vi.mocked(ingestMedia).mockResolvedValueOnce({
+ hash,
+ ext: '.png',
+ mimeType: 'image/png',
+ bytes: 4,
+ url: mediaUrl,
+ deduplicated: false,
+ refIds: ['ref-1'],
+ });
+ const ossRef = buildAttachmentOssRef({
+ ossKey: 'cindy/device-link/user/image.png',
+ mimeType: 'image/png',
+ originalName: 'image.png',
+ });
+
+ const materialized = await materializeDirectSendOssAttachments(
+ 'direct-oss-image',
+ {
+ type: 'user',
+ content: [{ type: 'image', path: ossRef, mimeType: 'image/png' }],
+ },
+ undefined,
+ );
+
+ expect(materialized.message).toEqual({
+ type: 'user',
+ content: [{
+ type: 'image',
+ path: absPath,
+ mimeType: 'image/png',
+ pathOrigin: 'desktop-host',
+ base64: undefined,
+ }],
+ });
+ materialized.cleanupAfterAcceptance?.();
+ expect(removeRemote).toHaveBeenCalledWith('cindy/device-link/user/image.png');
+ });
+
it('writes private bytes and removes them even before Maker owns the session', async () => {
const sessionId = 'reviewer-session';
const normalized = await normalizeUserMessage(sessionId, {
diff --git a/apps/desktop/src/main/maker-ipc/normalizeAttachments.ts b/apps/desktop/src/main/maker-ipc/normalizeAttachments.ts
index b7f4b4999d..e426e38af0 100644
--- a/apps/desktop/src/main/maker-ipc/normalizeAttachments.ts
+++ b/apps/desktop/src/main/maker-ipc/normalizeAttachments.ts
@@ -863,9 +863,11 @@ export async function materializeDirectSendOssAttachments(
typeof pathValue === 'string' &&
pathValue !== originalPath
) {
+ const isImage = (original as { type?: unknown }).type === 'image';
nextContent[attachmentIndexes[index]] = {
...(original as object),
path: pathValue,
+ ...(isImage ? { pathOrigin: 'desktop-host' as const } : {}),
base64: undefined,
};
}
diff --git a/packages/maker-core/src/agents/claude-code/__tests__/plan-mode.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/plan-mode.test.ts
index 6c85a1441c..de58ed8dca 100644
--- a/packages/maker-core/src/agents/claude-code/__tests__/plan-mode.test.ts
+++ b/packages/maker-core/src/agents/claude-code/__tests__/plan-mode.test.ts
@@ -625,6 +625,61 @@ describe('ClaudeCodeAgent plan mode', () => {
await handle.close();
});
+ it('warns when an active SSH session is steered with a desktop-local image', async () => {
+ const configDir = await makeTempDir();
+ process.env.CLAUDE_CONFIG_DIR = configDir;
+ const workingDir = await makeTempDir();
+ const imagePath = path.join(workingDir, 'desktop-steer.png');
+ const remoteSend = vi.fn(async () => {});
+ const fakeQuery = { ...createFakeQuery(), send: remoteSend };
+ const remoteCcQueryFactory: NonNullable<AgentDeps['remoteCcQueryFactory']> = async () =>
+ fakeQuery as never;
+ const logger = createNoopLogger();
+ const warn = vi.spyOn(logger, 'warn');
+ const agent = new ClaudeCodeAgent(createDeps({ logger, remoteCcQueryFactory }));
+ const handle = await agent.startSession({
+ sessionId: 'session-remote-desktop-steer-image',
+ model: 'claude-opus-4-6',
+ workingDir,
+ remoteHostId: 'remote-1',
+ permissionMode: 'auto',
+ });
+ const iterator = handle.events()[Symbol.asyncIterator]();
+
+ await handle.send({ type: 'user', content: 'Start the remote turn' });
+ await vi.waitFor(() => expect(remoteSend).toHaveBeenCalledTimes(1));
+ await handle.steer({
+ type: 'user',
+ content: [
+ {
+ type: 'image',
+ path: imagePath,
+ mimeType: 'image/png',
+ pathOrigin: 'desktop-host',
+ },
+ { type: 'text', text: 'Inspect this too' },
+ ],
+ });
+ await vi.waitFor(() => expect(remoteSend).toHaveBeenCalledTimes(2));
+
+ expect(warn).toHaveBeenCalledWith(
+ 'cc remote: local attachment not accessible on remote session',
+ expect.objectContaining({
+ sessionId: 'session-remote-desktop-steer-image',
+ hostId: 'remote-1',
+ }),
+ );
+ const events = [await nextEvent(iterator), await nextEvent(iterator)];
+ expect(events).toContainEqual(expect.objectContaining({
+ type: 'error',
+ data: expect.objectContaining({
+ message: expect.stringContaining('[REMOTE_LOCAL_ATTACHMENT_UNSUPPORTED]'),
+ isTerminal: false,
+ }),
+ }));
+ await handle.close();
+ });
+
it('overrides remote cc-manager env with a host-materialized Claude route', async () => {
const configDir = await makeTempDir();
process.env.CLAUDE_CONFIG_DIR = configDir;
diff --git a/packages/maker-core/src/agents/claude-code/index.ts b/packages/maker-core/src/agents/claude-code/index.ts
index 0cfd76580d..bb7382dcbf 100644
--- a/packages/maker-core/src/agents/claude-code/index.ts
+++ b/packages/maker-core/src/agents/claude-code/index.ts
@@ -4842,6 +4842,27 @@ export class ClaudeCodeAgent extends BaseAgent {
releaseCancellationRebuildGate?.();
}
}
+ const warnIfRemoteDesktopAttachment = (content: UserMessage['content']): void => {
+ if (!opts.remoteHostId || !Array.isArray(content)) return;
+ const hasDesktopLocalAttachment = content.some(
+ (block) => block.type === 'file'
+ || block.type === 'mention'
+ || (block.type === 'image' && block.pathOrigin === 'desktop-host'),
+ );
+ if (!hasDesktopLocalAttachment) return;
+ log.warn('cc remote: local attachment not accessible on remote session', {
+ sessionId: opts.sessionId,
+ hostId: opts.remoteHostId,
+ });
+ eventQueue.push({
+ type: 'error',
+ data: {
+ message: '[REMOTE_LOCAL_ATTACHMENT_UNSUPPORTED] Local file attachments are not accessible on remote sessions. Paste content directly instead.',
+ isTerminal: false,
+ },
+ source: 'claude-code',
+ });
+ };
const handle: AgentSessionHandle = {
get id() { return sdkSessionId ?? '<pending>'; },
agentKind: 'claude-code',
@@ -5163,27 +5184,7 @@ export class ClaudeCodeAgent extends BaseAgent {
// 模型看不见 → silent context loss。完整修法是 upload 文件到远端 (follow-up),
// 这里 MVP 检测到附件就 emit warn event 让用户知道,实际请求里把附件 ref 留着
// (daemon 端 SDK 读不到就跳过, 不会 crash)。
- if (opts.remoteHostId && Array.isArray(message.content)) {
- const hasDesktopLocalAttachment = message.content.some(
- (b) => b.type === 'file'
- || b.type === 'mention'
- || (b.type === 'image' && b.pathOrigin === 'desktop-host'),
- );
- if (hasDesktopLocalAttachment) {
- log.warn('cc remote: local attachment not accessible on remote session', {
- sessionId: opts.sessionId,
- hostId: opts.remoteHostId,
- });
- eventQueue.push({
- type: 'error',
- data: {
- message: '[REMOTE_LOCAL_ATTACHMENT_UNSUPPORTED] Local file attachments are not accessible on remote sessions. Paste content directly instead.',
- isTerminal: false,
- },
- source: 'claude-code',
- });
- }
- }
+ warnIfRemoteDesktopAttachment(message.content);
// Claude Code streaming-input 协议要求 message 包装层,漏掉会 exit code 1。
// sendOpts.messageUuid 注入到 SDK input.uuid — SDK 透传当作 file checkpoint
// snapshot 的 messageId, rewind preview 拿同款 uuid 调 rewindFiles dryRun。
@@ -5268,6 +5269,7 @@ export class ClaudeCodeAgent extends BaseAgent {
// keeps the original queue/composer content and lets the user retry.
throw new Error('No active Claude turn to steer');
}
+ warnIfRemoteDesktopAttachment(message.content);
// Same-turn steering deliberately does NOT call beginTurn(), reset the
// tool-loop guard, or emit a new running status. Those are turn-start
// side effects; doing them here would corrupt usage attribution and make