Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 避免误报跨 Agent 工作区迁移提示 (#633)
jinguochen-dev3248db7ac06d
diff --git a/apps/desktop/src/main/cross-agent-convert/__tests__/detector.test.ts b/apps/desktop/src/main/cross-agent-convert/__tests__/detector.test.tsindex a32b221617..1e64613272 100644--- a/apps/desktop/src/main/cross-agent-convert/__tests__/detector.test.ts+++ b/apps/desktop/src/main/cross-agent-convert/__tests__/detector.test.ts@@ -132,6 +132,66 @@ describe('detect — agents', () => {expect(agents!.subItems).toHaveLength(1);expect(agents!.subItems![0].targetPath).toMatch(/\.codex[\\/]agents[\\/]foo\.toml$/);});++ it('to-codex: 普通 Markdown 不应被误报为可迁移 agent', async () => {+ await fs.mkdir(path.join(tmpDir, '.claude', 'agents'), { recursive: true });+ await fs.writeFile(+ path.join(tmpDir, '.claude', 'agents', 'codebase-explorer.md'),+ '# 代码库探索代理',+ );++ const r = await detect({ workingDir: tmpDir, agentKind: 'codex' });++ expect(r.items.find((i) => i.kind === 'agents')).toBeUndefined();+ });++ it('to-codex: 缺少 name 元数据的 Claude agent 不应被误报', async () => {+ await fs.mkdir(path.join(tmpDir, '.claude', 'agents'), { recursive: true });+ await fs.writeFile(+ path.join(tmpDir, '.claude', 'agents', 'without-name.md'),+ '---\ndescription: only description\n---\nbody',+ );++ const r = await detect({ workingDir: tmpDir, agentKind: 'codex' });++ expect(r.items.find((i) => i.kind === 'agents')).toBeUndefined();+ });++ it('to-codex: name 不是字符串的 Claude agent 不应被误报', async () => {+ await fs.mkdir(path.join(tmpDir, '.claude', 'agents'), { recursive: true });+ await fs.writeFile(+ path.join(tmpDir, '.claude', 'agents', 'numeric-name.md'),+ '---\nname: 1\n---\nbody',+ );++ const r = await detect({ workingDir: tmpDir, agentKind: 'codex' });++ expect(r.items.find((i) => i.kind === 'agents')).toBeUndefined();+ });++ it('to-codex: name 只有空白的 Claude agent 不应被误报', async () => {+ await fs.mkdir(path.join(tmpDir, '.claude', 'agents'), { recursive: true });+ await fs.writeFile(+ path.join(tmpDir, '.claude', 'agents', 'blank-name.md'),+ '---\nname: " "\n---\nbody',+ );++ const r = await detect({ workingDir: tmpDir, agentKind: 'codex' });++ expect(r.items.find((i) => i.kind === 'agents')).toBeUndefined();+ });++ it('to-codex: frontmatter YAML 无法解析的 Claude agent 不应被误报', async () => {+ await fs.mkdir(path.join(tmpDir, '.claude', 'agents'), { recursive: true });+ await fs.writeFile(+ path.join(tmpDir, '.claude', 'agents', 'invalid-frontmatter.md'),+ '---\nname: [unterminated\n---\nbody',+ );++ const r = await detect({ workingDir: tmpDir, agentKind: 'codex' });++ expect(r.items.find((i) => i.kind === 'agents')).toBeUndefined();+ });});describe('detect — mcp', () => {diff --git a/apps/desktop/src/main/cross-agent-convert/detector.ts b/apps/desktop/src/main/cross-agent-convert/detector.tsindex 911f0e5808..62a5149645 100644--- a/apps/desktop/src/main/cross-agent-convert/detector.ts+++ b/apps/desktop/src/main/cross-agent-convert/detector.ts@@ -12,6 +12,7 @@import fs from 'node:fs/promises';import path from 'node:path';+import yaml from 'js-yaml';import type {AgentKind,@@ -69,6 +70,27 @@ async function listFilesByExt(p: string, ext: string): Promise<string[]> {}}+/**+ * 检测阶段要求 Claude agent 文件包含可解析 YAML 中的非空字符串 `name`,+ * 避免把普通 Markdown 误报为可迁移代理。转换器对缺少或假值 `name` 的源文件+ * 会跳过,但不在这里重复执行转换。+ */+async function isConvertibleClaudeAgentFile(p: string): Promise<boolean> {+ try {+ const raw = await fs.readFile(p, 'utf8');+ const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);+ if (!match) return false;+ const parsed = yaml.load(match[1]);+ const name =+ parsed && typeof parsed === 'object' && !Array.isArray(parsed)+ ? (parsed as { name?: unknown }).name+ : undefined;+ return typeof name === 'string' && name.trim().length > 0;+ } catch {+ return false;+ }+}+export async function detect(input: DetectInput): Promise<DetectResult> {const wd = input.workingDir;if (!wd) return { items: [] };@@ -150,8 +172,17 @@ async function detectAgents(wd: string, direction: MigrationDirection, items: Miif (!(await isDir(claudeAgents))) return;const sourceFiles = await listFilesByExt(claudeAgents, '.md');if (sourceFiles.length === 0) return;- const targetExisting = new Set((await listFilesByExt(codexAgents, '.toml')).map((n) => n.replace(/\.toml$/i, '')));- const baseNames = sourceFiles.map((f) => f.replace(/\.md$/i, ''));+ const convertibleSourceFiles: string[] = [];+ for (const file of sourceFiles) {+ if (await isConvertibleClaudeAgentFile(path.join(claudeAgents, file))) {+ convertibleSourceFiles.push(file);+ }+ }+ if (convertibleSourceFiles.length === 0) return;+ const targetExisting = new Set(+ (await listFilesByExt(codexAgents, '.toml')).map((n) => n.replace(/\.toml$/i, '')),+ );+ const baseNames = convertibleSourceFiles.map((f) => f.replace(/\.md$/i, ''));const missing = baseNames.filter((n) => !targetExisting.has(n));if (missing.length === 0) return;items.push({