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(desktop): honor built-in skill runtime state

xd-bobo3c428afc9344
diff --git a/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/_frontmatter.py b/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/_frontmatter.py
index 2f26434aca..f7dd2e2505 100644
--- a/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/_frontmatter.py
+++ b/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/_frontmatter.py
@@ -53,11 +53,15 @@ def _parse_scalar(raw):
return int(value)
if re.fullmatch(r"[-+]?(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)", value):
return float(value)
- if value.startswith(('[', '{')):
- try:
- return json.loads(value)
- except (TypeError, ValueError) as exc:
- raise FrontmatterError(f"Invalid flow value: {exc}") from exc
+ if value.startswith(("[", "{")):
+ closing = "]" if value.startswith("[") else "}"
+ if not value.endswith(closing):
+ raise FrontmatterError(f"Unterminated flow value, expected '{closing}'")
+ # The bundled tools only inspect scalar name/description values. Keep
+ # flow collection contents opaque while preserving the collection type,
+ # so valid YAML bare scalars such as [Read, Grep] and {owner: me} do not
+ # require PyYAML or JSON syntax.
+ return [] if value.startswith("[") else {}
return value
diff --git a/apps/desktop/src/main/bootstrap-electron.ts b/apps/desktop/src/main/bootstrap-electron.ts
index b54c5bf5c3..e72c5a3652 100644
--- a/apps/desktop/src/main/bootstrap-electron.ts
+++ b/apps/desktop/src/main/bootstrap-electron.ts
@@ -578,12 +578,11 @@ import { SkillhubMarketService } from './skillhub/marketService';
import { skillhubAutoSyncService } from './skillhub/autoSyncService';
import { rehydrateCloseSuppression } from './maker-host/rehydrateCloseSuppression.js';
import {
- BUILT_IN_LEARN_SKILL_NAME,
builtInSkillDescriptors,
prepareBuiltInSkills,
resolveBundledSystemSkillsRoot,
} from './maker-host/built-in-skills.js';
-import { isCindySkillEnabled } from './skillhub/activationPreferences';
+import { isCindyLearnSkillEnabled } from './skillhub/activationPreferences';
import { prepareSharedGlobalSkillLinks } from './maker-host/shared-global-skills.js';
// Maker Core 一阶段重构(新链路)—— 静态 import 避免 dynamic import 触发 vite chunking
// 让 imageProtocol 等需要 app.ready 前注册的模块跑在错误时机。getMaker() 是 lazy 的,
@@ -6099,13 +6098,7 @@ const registerIpcHandlers = () => {
registerBuiltinDesktopCommands(getDesktopCommandRegistry(), {
getGoalController,
getLearnController,
- isLearnEnabled: () => {
- const descriptor = builtInSkillDescriptors(
- app.getPath('userData'),
- app.getPath('appData'),
- ).find((skill) => skill.name === BUILT_IN_LEARN_SKILL_NAME);
- return descriptor ? isCindySkillEnabled(descriptor.absolutePath) : false;
- },
+ isLearnEnabled: isCindyLearnSkillEnabled,
remoteInvoke: (deviceId, channel, args) =>
deviceLinkHandleInvoke(deviceLinkIpcDeps(), deviceId, channel, args),
});
diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/collabSendOutcome.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/collabSendOutcome.test.ts
index b520237181..0dbf8a3e73 100644
--- a/apps/desktop/src/main/mcp-integrations/__tests__/collabSendOutcome.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/__tests__/collabSendOutcome.test.ts
@@ -14,6 +14,7 @@ const mockState = vi.hoisted(() => ({
collabService: null as null | {
[key: string]: ReturnType<typeof vi.fn>;
},
+ learnEnabled: true,
capturedProvidersConfig: null as null | Record<string, unknown>,
}));
@@ -89,6 +90,10 @@ vi.mock('../../maker-host/lsp-mode-store.js', () => ({
readLspModeSettings: () => ({ enabled: true }),
}));
+vi.mock('../../skillhub/activationPreferences.js', () => ({
+ isCindyLearnSkillEnabled: () => mockState.learnEnabled,
+}));
+
vi.mock('../../localDb/chatHistoryReader.js', () => ({
listWorkdirsForHistory: vi.fn(),
listSessionsForHistory: vi.fn(),
@@ -164,6 +169,7 @@ describe('collab send outcome semantics', () => {
mockState.logger.trace.mockClear();
mockState.logger.fatal.mockClear();
mockState.collabService = null;
+ mockState.learnEnabled = true;
mockState.capturedProvidersConfig = null;
vi.clearAllMocks();
});
@@ -198,6 +204,35 @@ describe('collab send outcome semantics', () => {
).toBe(true);
});
+ it('rejects start_skill_learning after the built-in Learn Skill is disabled', async () => {
+ mockState.learnEnabled = false;
+ createDesktopMcpProviders({
+ botCapabilities,
+ getMakerMemoryManager: vi.fn(),
+ lspPool: {} as never,
+ pluginRegistry: { isEnabled: () => true } as never,
+ resolveIOSSimulatorAccess: () => ({ allowed: true }),
+ invokeRemote: vi.fn(),
+ });
+ const xdtHelper = mockState.capturedProvidersConfig?.xdtHelper as {
+ skillLearning: (input: {
+ callerSessionId: string;
+ input: string;
+ sourceKind: 'session';
+ }) => Promise<Record<string, unknown>>;
+ };
+
+ await expect(xdtHelper.skillLearning({
+ callerSessionId: 'session-1',
+ input: '',
+ sourceKind: 'session',
+ })).resolves.toEqual({
+ ok: false,
+ errorCode: 'SKILL_DISABLED',
+ message: 'Cindy Learn is disabled in Local Skills.',
+ });
+ });
+
it('reports enable_collab_mode delegate_task created-and-dispatched distinctly', async () => {
const result = await resolveCollabDispatchResult(
() => Promise.resolve({ accepted: true } satisfies SessionSendResult),
diff --git a/apps/desktop/src/main/mcp-integrations/mcp-providers.ts b/apps/desktop/src/main/mcp-integrations/mcp-providers.ts
index 059a2f7cd3..e6eb47e5aa 100644
--- a/apps/desktop/src/main/mcp-integrations/mcp-providers.ts
+++ b/apps/desktop/src/main/mcp-integrations/mcp-providers.ts
@@ -86,6 +86,7 @@ import {
type ChatHistoryReaderDeps,
} from './remoteChatHistory.js';
import { botSessionLinks, sessions } from '../localDb/schema.js';
+import { isCindyLearnSkillEnabled } from '../skillhub/activationPreferences.js';
export interface DesktopMcpProvidersDeps {
botCapabilities: Pick<ReturnType<typeof createBotCapabilityService>, 'list' | 'select'>;
@@ -383,6 +384,13 @@ export function createDesktopMcpProviders(deps: DesktopMcpProvidersDeps): LiziMc
hubCatalogScope,
}) => {
try {
+ if (!isCindyLearnSkillEnabled()) {
+ return {
+ ok: false,
+ errorCode: 'SKILL_DISABLED',
+ message: 'Cindy Learn is disabled in Local Skills.',
+ };
+ }
// Lazy import avoids coupling provider construction to learn-host startup.
// The callback is invoked only after bootstrap has initialized the host.
const { getLearnController } = await import('../learn-host/index.js');
diff --git a/apps/desktop/src/main/skillhub/__tests__/activationPreferences.test.ts b/apps/desktop/src/main/skillhub/__tests__/activationPreferences.test.ts
index 70ddc77410..9a22e6f115 100644
--- a/apps/desktop/src/main/skillhub/__tests__/activationPreferences.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/activationPreferences.test.ts
@@ -45,6 +45,16 @@ describe('Skill activation preferences', () => {
await reloaded.setCindySkillEnabled(b, true);
expect(reloaded.readDisabledSkillPaths()).toEqual([]);
});
+ it('reports the built-in Learn Skill activation state from its stable physical path', async () => {
+ const prefs = await import('../activationPreferences');
+ const descriptors = (await import('../../maker-host/built-in-skills')).builtInSkillDescriptors(root, root);
+ const learn = descriptors.find((descriptor) => descriptor.name === 'learn')!;
+ expect(prefs.isCindyLearnSkillEnabled()).toBe(true);
+ await prefs.setCindySkillEnabled(learn.absolutePath, false);
+ expect(prefs.isCindyLearnSkillEnabled()).toBe(false);
+ await prefs.setCindySkillEnabled(learn.absolutePath, true);
+ expect(prefs.isCindyLearnSkillEnabled()).toBe(true);
+ });
it('also disables native runtime projections when the Cindy built-in Skill is disabled', async () => {
const prefs = await import('../activationPreferences');
const descriptor = (await import('../../maker-host/built-in-skills')).builtInSkillDescriptors(root, root)[0]!;
diff --git a/apps/desktop/src/main/skillhub/__tests__/scanner.test.ts b/apps/desktop/src/main/skillhub/__tests__/scanner.test.ts
index d7bed97fad..c84f68a73c 100644
--- a/apps/desktop/src/main/skillhub/__tests__/scanner.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/scanner.test.ts
@@ -115,11 +115,7 @@ describe('scanAllSkills', () => {
builtIn: true,
canUninstall: false,
cindyEnabled: true,
- linkedEngines: [
- { engine: 'claude-code', label: 'Claude' },
- { engine: 'codex', label: 'Codex' },
- { engine: 'pi', label: 'Pi' },
- ],
+ linkedEngines: [],
});
expect(result.skills.find((skill) => !skill.builtIn)).toMatchObject({
description: 'User copy',
@@ -127,6 +123,42 @@ describe('scanAllSkills', () => {
});
});
+ it('lists only engines that actually discover the bundled Skill path', async () => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'skillhub-built-in-engines-'));
+ tempRoots.push(root);
+ const builtIn = path.join(root, 'shared-system-skills', 'learn');
+ fs.mkdirSync(builtIn, { recursive: true });
+ fs.writeFileSync(path.join(builtIn, 'SKILL.md'), '---\nname: learn\ndescription: Learn\n---\nBody\n');
+ const items = (['codex', 'pi'] as const).map((engine) => ({
+ engine,
+ kind: 'skill' as const,
+ scope: 'user' as const,
+ name: 'learn',
+ description: 'Learn',
+ absolutePath: builtIn,
+ mdPath: path.join(builtIn, 'SKILL.md'),
+ files: [],
+ }));
+ const maker = {
+ listCustomizations: vi.fn(async () => ({ errors: [], items })),
+ } as unknown as Maker;
+
+ const result = await scanAllSkills({}, maker, [], [{
+ name: 'learn',
+ absolutePath: builtIn,
+ nativeClaudePath: path.join(root, 'claude-home', 'skills', 'learn'),
+ }]);
+
+ expect(result.skills).toHaveLength(1);
+ expect(result.skills[0]).toMatchObject({
+ builtIn: true,
+ linkedEngines: [
+ { engine: 'codex', label: 'Codex' },
+ { engine: 'pi', label: 'Pi' },
+ ],
+ });
+ });
+
it('projects the registry slug joined by physical path without replacing native directory names', async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'skillhub-registry-slug-'));
tempRoots.push(root);
diff --git a/apps/desktop/src/main/skillhub/activationPreferences.ts b/apps/desktop/src/main/skillhub/activationPreferences.ts
index 733912056f..e9571f30d2 100644
--- a/apps/desktop/src/main/skillhub/activationPreferences.ts
+++ b/apps/desktop/src/main/skillhub/activationPreferences.ts
@@ -4,7 +4,10 @@ import { randomUUID } from 'node:crypto';
import { app } from 'electron';
import { createLogger } from '../logger';
import { createOverrideSettingsFile } from '../maker-host/override-settings-file';
-import { builtInSkillDescriptors } from '../maker-host/built-in-skills';
+import {
+ BUILT_IN_LEARN_SKILL_NAME,
+ builtInSkillDescriptors,
+} from '../maker-host/built-in-skills';
/** Device/profile-local user intent; independent of cloud installs and account changes. */
interface SkillActivationPreferences {
@@ -76,6 +79,14 @@ export function isCindySkillEnabled(source: string): boolean {
return !readDisabledSkillPaths().includes(skillActivationKey(source));
}
+export function isCindyLearnSkillEnabled(): boolean {
+ const descriptor = builtInSkillDescriptors(
+ app.getPath('userData'),
+ app.getPath('appData'),
+ ).find((skill) => skill.name === BUILT_IN_LEARN_SKILL_NAME);
+ return descriptor ? isCindySkillEnabled(descriptor.absolutePath) : false;
+}
+
export interface SkillActivationSnapshot { key: string; revision?: string; aliases: string[] }
export function snapshotSkillActivation(source: string): SkillActivationSnapshot | null {
diff --git a/apps/desktop/src/main/skillhub/scanner.ts b/apps/desktop/src/main/skillhub/scanner.ts
index 87e8c6bc8d..7ee400753f 100644
--- a/apps/desktop/src/main/skillhub/scanner.ts
+++ b/apps/desktop/src/main/skillhub/scanner.ts
@@ -269,6 +269,24 @@ export async function scanAllSkills(
log.error('maker.listCustomizations failed', err);
listed = { items: [], errors: [{ message: err instanceof Error ? err.message : String(err) }] };
}
+ const discoveredEnginesByRealPath = new Map<
+ string,
+ Map<Skill['engine'], Skill['linkedEngines'][number]>
+ >();
+ for (const rawItem of listed.items) {
+ const item = normalizeSkillEntityPath(rawItem);
+ if (item.kind !== 'skill') continue;
+ const realPath = realPathOrNormalized(item.absolutePath);
+ const engines = discoveredEnginesByRealPath.get(realPath) ?? new Map();
+ if (!engines.has(item.engine)) {
+ engines.set(item.engine, {
+ engine: item.engine,
+ label: item.engine === 'claude-code' ? 'Claude' : item.engine === 'codex' ? 'Codex' : 'Pi',
+ ...(item.runtimeStatus ? { runtimeStatus: item.runtimeStatus } : {}),
+ });
+ }
+ discoveredEnginesByRealPath.set(realPath, engines);
+ }
const builtInRealPaths = new Set<string>();
for (const descriptor of builtInSkills) {
try {
@@ -368,11 +386,7 @@ export async function scanAllSkills(
}
}
const linkedEngines = builtIn
- ? [
- { engine: 'claude-code' as const, label: 'Claude' },
- { engine: 'codex' as const, label: 'Codex' },
- { engine: 'pi' as const, label: 'Pi' },
- ]
+ ? Array.from(discoveredEnginesByRealPath.get(realPath)?.values() ?? [])
: Array.from(engineSet.values());
const skill: Skill = {