Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): align Learn activation sources
xd-bobo2cb0cf892653
diff --git a/apps/desktop/src/main/learn-host/__tests__/controller.test.ts b/apps/desktop/src/main/learn-host/__tests__/controller.test.tsindex a410a487c9..6357bc1a39 100644--- a/apps/desktop/src/main/learn-host/__tests__/controller.test.ts+++ b/apps/desktop/src/main/learn-host/__tests__/controller.test.ts@@ -1511,6 +1511,20 @@ describe('LearnController 状态机', () => {});});+ it('session 源在创建 run 前拒绝没有可蒸馏消息的空任务', async () => {+ const h = makeHarness({ getConversationBlock: async () => '' });++ await expect(h.controller.startLearn({+ input: '',+ sourceKind: 'session',+ originSessionId: 'empty-origin',+ })).rejects.toMatchObject({+ code: 'INVALID_PARAMS',+ message: 'the origin conversation has no distillable content',+ });+ expect(h.store.list()).toEqual([]);+ });+it('证据检索抛错 → 无证据继续(不整轮失败)', async () => {const h = makeHarness({search: async () => {diff --git a/apps/desktop/src/main/learn-host/__tests__/conversationBlock.test.ts b/apps/desktop/src/main/learn-host/__tests__/conversationBlock.test.tsindex 6ee7815363..9e45e07666 100644--- a/apps/desktop/src/main/learn-host/__tests__/conversationBlock.test.ts+++ b/apps/desktop/src/main/learn-host/__tests__/conversationBlock.test.ts@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';import {CONVERSATION_TOTAL_CHAR_BUDGET,formatConversationBlock,+ isBareLearnInvocationText,} from '../evidence.pure';describe('formatConversationBlock', () => {@@ -28,3 +29,12 @@ describe('formatConversationBlock', () => {expect(block).not.toContain('msg-0 ');});});++describe('isBareLearnInvocationText', () => {+ it('recognizes only bare Learn triggers regardless of later history rows', () => {+ expect(isBareLearnInvocationText('/learn')).toBe(true);+ expect(isBareLearnInvocationText(' /SKILL:Learn ')).toBe(true);+ expect(isBareLearnInvocationText('/learn preserve the release flow')).toBe(false);+ expect(isBareLearnInvocationText('please run /learn')).toBe(false);+ });+});diff --git a/apps/desktop/src/main/learn-host/controller.ts b/apps/desktop/src/main/learn-host/controller.tsindex 5bec10112c..ca38084a07 100644--- a/apps/desktop/src/main/learn-host/controller.ts+++ b/apps/desktop/src/main/learn-host/controller.ts@@ -329,6 +329,16 @@ export class LearnController {if (req.sourceKind === 'session' && !req.originSessionId) {throw new LearnError('INVALID_PARAMS', 'session source requires the origin session');}+ if (+ req.sourceKind === 'session'+ && req.originSessionId+ && !(await this.deps.getConversationBlock(req.originSessionId))+ ) {+ throw new LearnError(+ 'INVALID_PARAMS',+ 'the origin conversation has no distillable content',+ );+ }if (req.sourceKind === 'hub' && !req.hubSlug) {throw new LearnError('INVALID_PARAMS', 'hubSlug is required for hub source');}diff --git a/apps/desktop/src/main/learn-host/evidence.pure.ts b/apps/desktop/src/main/learn-host/evidence.pure.tsindex af8a865bbf..6fa24d82b3 100644--- a/apps/desktop/src/main/learn-host/evidence.pure.ts+++ b/apps/desktop/src/main/learn-host/evidence.pure.ts@@ -31,6 +31,11 @@ export interface ConversationItem {text: string;}+/** A bare Learn invocation triggers collection but is never itself evidence. */+export function isBareLearnInvocationText(text: string): boolean {+ return /^\/(?:skill:)?learn\s*$/i.test(text.trim());+}+/*** 把当前会话消息渲染成 prompt 块(时间正序;超预算从**最早**的开始丢 ——* 提炼工作流时近期消息价值更高)。空输入返回空串。diff --git a/apps/desktop/src/main/learn-host/index.ts b/apps/desktop/src/main/learn-host/index.tsindex 428a228948..55d0209494 100644--- a/apps/desktop/src/main/learn-host/index.ts+++ b/apps/desktop/src/main/learn-host/index.ts@@ -40,7 +40,11 @@ import { LearnRunStore } from './runStore';import { applyProposal, resolveInstalledSkillDir } from './apply';import { collectUserProfile } from './profile';import { formatSkillsIndexBlock, listInstalledSkills } from './skillsIndex';-import { CONVERSATION_MESSAGE_LIMIT, formatConversationBlock } from './evidence.pure';+import {+ CONVERSATION_MESSAGE_LIMIT,+ formatConversationBlock,+ isBareLearnInvocationText,+} from './evidence.pure';import { redactSensitive } from './redaction';import {cleanupStaging,@@ -208,17 +212,13 @@ export function startLearnHost(deps: StartLearnHostDeps): LearnController {.limit(CONVERSATION_MESSAGE_LIMIT);const items: Array<{ role: string; text: string }> = [];const chronologicalRows = rows.reverse();- for (const [index, r] of chronologicalRows.entries()) {+ for (const r of chronologicalRows) {const text = visibleMessageTextForConversationSearch(r.role, r.content);if (!text) continue;// The built-in Learn Skill reaches the host after its invocation has- // entered chat history. Keep the trigger itself out of the evidence;- // the former Desktop command was intercepted before persistence.- if (- index === chronologicalRows.length - 1- && r.role === 'user'- && /^\/(?:skill:)?learn\s*$/i.test(text.trim())- ) {+ // entered chat history. Keep every bare trigger out of the evidence,+ // including when an assistant/tool row was persisted after it.+ if (r.role === 'user' && isBareLearnInvocationText(text)) {continue;}items.push({ role: r.role, text: redactSensitive(text).text });diff --git a/apps/desktop/src/main/maker-host/__tests__/built-in-skills.test.ts b/apps/desktop/src/main/maker-host/__tests__/built-in-skills.test.tsindex 80d3559f51..249a75e89a 100644--- a/apps/desktop/src/main/maker-host/__tests__/built-in-skills.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/built-in-skills.test.ts@@ -239,6 +239,26 @@ describe('built-in Skills', () => {expect(result.warnings.join('\n')).toContain('already owned by the user');});+ it('keeps the isolated Claude runtime aligned with the user-owned palette winner', async () => {+ const input = fixture();+ const first = await prepareBuiltInSkills(input);+ const descriptor = first.descriptors.find((item) => item.name === 'learn')!;+ const sharedSkill = path.join(input.homeDir, '.agents', 'skills', 'learn');+ expect(fs.realpathSync(descriptor.nativeClaudePath)).toBe(fs.realpathSync(sharedSkill));++ const claudePaletteSkill = path.join(input.homeDir, '.claude', 'skills', 'learn');+ fs.mkdirSync(claudePaletteSkill, { recursive: true });+ fs.writeFileSync(path.join(claudePaletteSkill, 'SKILL.md'), '# User Claude Learn\n');++ const updated = await prepareBuiltInSkills(input);++ expect(updated.warnings).toEqual([]);+ expect(fs.realpathSync(sharedSkill)).toBe(fs.realpathSync(descriptor.absolutePath));+ expect(fs.realpathSync(descriptor.nativeClaudePath)).toBe(+ fs.realpathSync(claudePaletteSkill),+ );+ });+it('attests only commands backed by the materialized Cindy copy', async () => {const input = fixture();const { descriptors } = await prepareBuiltInSkills(input);diff --git a/apps/desktop/src/main/maker-host/built-in-skills.ts b/apps/desktop/src/main/maker-host/built-in-skills.tsindex b2fd1003c7..b7d892f0c2 100644--- a/apps/desktop/src/main/maker-host/built-in-skills.ts+++ b/apps/desktop/src/main/maker-host/built-in-skills.ts@@ -170,6 +170,8 @@ async function ensureSkillEntry(replaceStaleCindyLink = false,legacyUserDataDir?: string,appDataDir?: string,+ desiredTarget = descriptor.absolutePath,+ additionalManagedTargets: readonly string[] = [],): Promise<{ changed: boolean; warning?: string; targetPath?: string }> {await fsp.mkdir(path.dirname(linkPath), { recursive: true });@@ -177,7 +179,7 @@ async function ensureSkillEntry(try {const current = await fsp.realpath(linkPath);currentTarget = current;- const expected = await fsp.realpath(descriptor.absolutePath);+ const expected = await fsp.realpath(desiredTarget);if (samePath(current, expected)) return { changed: false };} catch {// Inspect the lexical entry below; a missing entry may be created.@@ -193,11 +195,12 @@ async function ensureSkillEntry(descriptor,legacyUserDataDir,appDataDir,+ additionalManagedTargets,)) {await fsp.unlink(linkPath);await fsp.symlink(- descriptor.absolutePath,+ desiredTarget,linkPath,process.platform === 'win32' ? 'junction' : 'dir',);@@ -213,11 +216,11 @@ async function ensureSkillEntry(}await fsp.symlink(- descriptor.absolutePath,+ desiredTarget,linkPath,process.platform === 'win32' ? 'junction' : 'dir',);- return { changed: true, targetPath: descriptor.absolutePath };+ return { changed: true, targetPath: desiredTarget };}async function isCindyManagedSystemSkillTarget(@@ -225,6 +228,7 @@ async function isCindyManagedSystemSkillTarget(descriptor: BuiltInSkillDescriptor,legacyUserDataDir?: string,appDataDir?: string,+ additionalManagedTargets: readonly string[] = [],): Promise<boolean> {try {const rawTarget = await fsp.readlink(linkPath);@@ -232,6 +236,9 @@ async function isCindyManagedSystemSkillTarget(? rawTarget: path.resolve(path.dirname(linkPath), rawTarget);if (samePath(target, descriptor.absolutePath)) return true;+ if (additionalManagedTargets.some((managedTarget) => samePath(target, managedTarget))) {+ return true;+ }if (legacyUserDataDir &&samePath(target, path.join(builtInSkillsRoot(legacyUserDataDir), descriptor.name))@@ -295,6 +302,15 @@ function realPathOrNormalized(value: string): string {catch { return normalizeForCompare(value); }}+async function hasSkillFile(skillDir: string): Promise<boolean> {+ for (const fileName of ['SKILL.md', 'skill.md']) {+ if ((await fsp.stat(path.join(skillDir, fileName)).catch(() => null))?.isFile()) {+ return true;+ }+ }+ return false;+}+/** Main-owned attestation used by the renderer; names and descriptions are not trusted. */export function markCindyBuiltInAgentSkills(skills: readonly AgentSkillCommand[],@@ -403,14 +419,27 @@ export async function prepareBuiltInSkills(continue;}try {- // Point at the shared name instead of a profile copy. If a user owns- // that name, Claude, Codex, and Pi all execute the same winner.+ // Claude's palette scans ~/.claude while its isolated runtime reads+ // <userData>/claude-home. Mirror the palette winner so a user-owned+ // Claude Skill keeps precedence even when ~/.agents has Cindy's copy.+ const homeDir = options.homeDir ?? os.homedir();+ const claudePalettePath = path.join(+ homeDir,+ '.claude',+ 'skills',+ descriptor.name,+ );+ const claudeRuntimeTarget = await hasSkillFile(claudePalettePath)+ ? claudePalettePath+ : sharedPath;const linked = await ensureSkillEntry(- { ...descriptor, absolutePath: sharedPath },+ descriptor,descriptor.nativeClaudePath,true,options.userDataDir,options.appDataDir,+ claudeRuntimeTarget,+ [sharedPath],);changed = linked.changed || changed;if (linked.warning) warnings.push(linked.warning);