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): preserve verified skill fallbacks

xd-bobo96da2921f857
diff --git a/apps/desktop/src/main/commands/__tests__/builtinsRemoteRouting.test.ts b/apps/desktop/src/main/commands/__tests__/builtinsRemoteRouting.test.ts
index c47cfb751e..b3b2dd0dce 100644
--- a/apps/desktop/src/main/commands/__tests__/builtinsRemoteRouting.test.ts
+++ b/apps/desktop/src/main/commands/__tests__/builtinsRemoteRouting.test.ts
@@ -101,6 +101,29 @@ describe('/learn SSH fallback', () => {
'unknown command "/learn"',
);
});
+
+ it('keeps the remote fallback when only the controlling host disabled Learn', async () => {
+ const { registry, learnController, remoteInvoke } = makeHarness({
+ isLearnEnabled: () => false,
+ remoteInvoke: async () => ({ runId: 'remote-run' }),
+ });
+
+ expect(registry.list({ deviceId: 'dev-1' })).toContainEqual(
+ expect.objectContaining({ name: 'learn' }),
+ );
+ await registry.execute('learn', {
+ sessionId: 'remote-session',
+ deviceId: 'dev-1',
+ args: '学习远程流程',
+ });
+
+ expect(remoteInvoke).toHaveBeenCalledWith('dev-1', 'learn:start', [{
+ input: '学习远程流程',
+ sourceKind: 'freetext',
+ originSessionId: 'remote-session',
+ }]);
+ expect(learnController.startLearn).not.toHaveBeenCalled();
+ });
});
describe('/goal 远程路由', () => {
diff --git a/apps/desktop/src/main/commands/builtins.ts b/apps/desktop/src/main/commands/builtins.ts
index abc590b715..00aa05f103 100644
--- a/apps/desktop/src/main/commands/builtins.ts
+++ b/apps/desktop/src/main/commands/builtins.ts
@@ -699,7 +699,10 @@ export function registerBuiltinDesktopCommands(
name: 'learn',
description:
'Distill a reusable skill from anything you describe (a workflow, a repo, a URL, how you usually do X) — grounded in your usage history and profile, reviewed as a diff before saving. Bare /learn distills the current conversation; /learn hub:<slug> learns from a SkillHub skill. Usage: /learn [hub:<slug>] [what to learn]',
- isVisible: deps.isLearnEnabled,
+ // Remote visibility cannot be inferred from this controller's local
+ // preference. Keep the compatibility route and let remote learn:start
+ // enforce the controlled host's effective setting.
+ isVisible: (ctx) => Boolean(ctx?.deviceId) || deps.isLearnEnabled(),
execute: async (ctx) => {
const arg = (ctx.args ?? '').trim();
if (!arg && !ctx.sessionId) {
diff --git a/apps/desktop/src/main/commands/registry.ts b/apps/desktop/src/main/commands/registry.ts
index 682ace6339..b72a2f4dab 100644
--- a/apps/desktop/src/main/commands/registry.ts
+++ b/apps/desktop/src/main/commands/registry.ts
@@ -57,7 +57,7 @@ export interface DesktopCommandDefinition {
name: string;
description: string;
/** Optional dynamic gate for commands backed by a user-toggleable capability. */
- isVisible?: () => boolean;
+ isVisible?: (ctx?: Pick<DesktopCommandContext, 'deviceId'>) => boolean;
/**
* 主入口 —— 命中此命令时由 main 执行。
* 同步/异步皆可; 抛错由调用方 catch + 上报, 不会自动 swallow。
@@ -80,9 +80,9 @@ export class DesktopCommandRegistry {
* 暴露给 renderer 的视图: 只含 kind/name/description, 不含 execute 函数。
* 与 maker-core 的 DesktopCommandMeta 形状一致, palette 直接消费。
*/
- list(): DesktopCommandMeta[] {
+ list(ctx?: Pick<DesktopCommandContext, 'deviceId'>): DesktopCommandMeta[] {
return Array.from(this.commands.values())
- .filter((c) => c.isVisible?.() !== false)
+ .filter((c) => c.isVisible?.(ctx) !== false)
.map((c) => ({
kind: 'desktop' as const,
name: c.name,
@@ -96,7 +96,7 @@ export class DesktopCommandRegistry {
*/
async execute(name: string, ctx: DesktopCommandContext): Promise<unknown> {
const cmd = this.commands.get(name);
- if (!cmd || cmd.isVisible?.() === false) {
+ if (!cmd || cmd.isVisible?.(ctx) === false) {
throw new Error(`DesktopCommandRegistry: unknown command "/${name}"`);
}
return cmd.execute(ctx);
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.ts
index 2cd6c72a45..572bf6af86 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
@@ -46,20 +46,24 @@ async function prepareAndProjectBuiltInSkills(
input: ReturnType<typeof fixture> & { bundleVersion?: number },
) {
const prepared = await prepareBuiltInSkills(input);
- const shared = await refreshBuiltInSharedSkillLinks({
- userDataDir: input.userDataDir,
- appDataDir: input.appDataDir,
- homeDir: input.homeDir,
- descriptors: prepared.descriptors,
- withSharedMutation: input.withSharedMutation,
- });
- const claude = await refreshBuiltInClaudeSkillLinks({
- userDataDir: input.userDataDir,
- appDataDir: input.appDataDir,
- homeDir: input.homeDir,
- descriptors: prepared.descriptors,
- withSharedMutation: input.withSharedMutation,
- });
+ const shared = prepared.projectionSafe
+ ? await refreshBuiltInSharedSkillLinks({
+ userDataDir: input.userDataDir,
+ appDataDir: input.appDataDir,
+ homeDir: input.homeDir,
+ descriptors: prepared.descriptors,
+ withSharedMutation: input.withSharedMutation,
+ })
+ : { changed: false, warnings: [] };
+ const claude = prepared.projectionSafe
+ ? await refreshBuiltInClaudeSkillLinks({
+ userDataDir: input.userDataDir,
+ appDataDir: input.appDataDir,
+ homeDir: input.homeDir,
+ descriptors: prepared.descriptors,
+ withSharedMutation: input.withSharedMutation,
+ })
+ : { changed: false, warnings: [] };
return {
...prepared,
changed: prepared.changed || shared.changed || claude.changed,
@@ -166,9 +170,38 @@ describe('built-in Skills', () => {
expect(fs.readFileSync(path.join(descriptor.absolutePath, 'SKILL.md'), 'utf8')).toBe(installed);
expect(older.changed).toBe(false);
+ expect(older.projectionSafe).toBe(false);
expect(older.warnings.join('\n')).toContain('manifest is unavailable');
});
+ it('preserves existing projections when a manifest has a corrupt shape', async () => {
+ const input = fixture();
+ await prepareAndProjectBuiltInSkills(input);
+ const sharedLink = path.join(input.homeDir, '.agents', 'skills', 'cindy-skill-creator');
+ const claudeLink = path.join(input.userDataDir, 'claude-home', 'skills', 'cindy-skill-creator');
+ const sharedTarget = fs.realpathSync(sharedLink);
+ const claudeTarget = fs.realpathSync(claudeLink);
+ const manifestPath = path.join(
+ input.appDataDir,
+ 'Cindy',
+ 'shared-system-skills',
+ '.cindy-system-skills.json',
+ );
+ fs.writeFileSync(manifestPath, JSON.stringify({
+ schemaVersion: 3,
+ bundleVersion: 7,
+ fingerprints: {},
+ activeBundle: 'damaged',
+ }));
+
+ const failed = await prepareAndProjectBuiltInSkills(input);
+
+ expect(failed.projectionSafe).toBe(false);
+ expect(failed.warnings.join('\n')).toContain('manifest is unavailable');
+ expect(fs.realpathSync(sharedLink)).toBe(sharedTarget);
+ expect(fs.realpathSync(claudeLink)).toBe(claudeTarget);
+ });
+
it('does not infer a first install when the manifest is missing beside existing Skills', async () => {
const input = fixture();
const newer = await prepareBuiltInSkills({ ...input, bundleVersion: 5 });
diff --git a/apps/desktop/src/main/maker-host/__tests__/claudeAuthAdapterOAuthEnv.test.ts b/apps/desktop/src/main/maker-host/__tests__/claudeAuthAdapterOAuthEnv.test.ts
index 657523d725..a167d1f723 100644
--- a/apps/desktop/src/main/maker-host/__tests__/claudeAuthAdapterOAuthEnv.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/claudeAuthAdapterOAuthEnv.test.ts
@@ -110,7 +110,7 @@ vi.mock('../shared-global-skills.js', () => ({
}));
vi.mock('../built-in-skills.js', () => ({
- prepareBuiltInSkills: async () => ({ descriptors: [], warnings: [] }),
+ prepareBuiltInSkills: async () => ({ descriptors: [], projectionSafe: true, warnings: [] }),
refreshBuiltInSharedSkillLinks: async () => ({ warnings: [] }),
refreshBuiltInClaudeSkillLinks: async () => ({ warnings: [] }),
resolveBundledSystemSkillsRoot: () => '/tmp/cindy-bundled-system-skills',
diff --git a/apps/desktop/src/main/maker-host/auth-adapters.ts b/apps/desktop/src/main/maker-host/auth-adapters.ts
index a633cba61a..92247e178c 100644
--- a/apps/desktop/src/main/maker-host/auth-adapters.ts
+++ b/apps/desktop/src/main/maker-host/auth-adapters.ts
@@ -618,19 +618,23 @@ export class DesktopClaudeAuthAdapter implements AuthAdapter {
userDataDir: app.getPath('userData'),
appDataDir: app.getPath('appData'),
});
- const builtInSharedProjection = await refreshBuiltInSharedSkillLinks({
- userDataDir: app.getPath('userData'),
- appDataDir: app.getPath('appData'),
- descriptors: preparedBuiltIns.descriptors,
- });
+ const builtInSharedProjection = preparedBuiltIns.projectionSafe
+ ? await refreshBuiltInSharedSkillLinks({
+ userDataDir: app.getPath('userData'),
+ appDataDir: app.getPath('appData'),
+ descriptors: preparedBuiltIns.descriptors,
+ })
+ : { warnings: ['skipped built-in Skill projection because the active bundle could not be verified'] };
const sharedProjection = await prepareSharedGlobalSkillLinks({
assertOwnerStable: () => assertGhostSkillProjectionBoundaryStableForOwner(ownerId),
});
- const isolatedClaudeProjection = await refreshBuiltInClaudeSkillLinks({
- userDataDir: app.getPath('userData'),
- appDataDir: app.getPath('appData'),
- descriptors: preparedBuiltIns.descriptors,
- });
+ const isolatedClaudeProjection = preparedBuiltIns.projectionSafe
+ ? await refreshBuiltInClaudeSkillLinks({
+ userDataDir: app.getPath('userData'),
+ appDataDir: app.getPath('appData'),
+ descriptors: preparedBuiltIns.descriptors,
+ })
+ : { warnings: [] };
return {
warnings: [
...preparedBuiltIns.warnings,
diff --git a/apps/desktop/src/main/maker-host/built-in-skills.ts b/apps/desktop/src/main/maker-host/built-in-skills.ts
index 532800041d..7495075642 100644
--- a/apps/desktop/src/main/maker-host/built-in-skills.ts
+++ b/apps/desktop/src/main/maker-host/built-in-skills.ts
@@ -37,6 +37,8 @@ export interface PrepareBuiltInSkillsOptions {
export interface PrepareBuiltInSkillsResult {
descriptors: BuiltInSkillDescriptor[];
+ /** True only when every descriptor is backed by the active manifest's recorded bytes. */
+ projectionSafe: boolean;
changed: boolean;
warnings: string[];
}
@@ -636,6 +638,7 @@ export async function prepareBuiltInSkills(
: builtInSkillsRoot(options.userDataDir);
const warnings: string[] = [];
let changed = false;
+ let projectionSafe = false;
const bundleVersion = options.bundleVersion ?? BUILT_IN_SKILLS_BUNDLE_VERSION;
if (!Number.isSafeInteger(bundleVersion) || bundleVersion < 1) {
throw new Error(`invalid built-in Skill bundle version: ${bundleVersion}`);
@@ -659,6 +662,17 @@ export async function prepareBuiltInSkills(
);
return true;
}
+ const installedFingerprints = new Map<string, string | null>();
+ for (const descriptor of descriptors) {
+ installedFingerprints.set(
+ descriptor.name,
+ await hashDirectory(descriptor.absolutePath).catch(() => null),
+ );
+ }
+ projectionSafe = !isEmptyManifest(manifest) && descriptors.every((descriptor) => (
+ typeof manifest.fingerprints[descriptor.name] === 'string'
+ && installedFingerprints.get(descriptor.name) === manifest.fingerprints[descriptor.name]
+ ));
const newerBundleIsInstalled = manifest.bundleVersion > bundleVersion;
if (newerBundleIsInstalled) {
warnings.push(
@@ -680,9 +694,7 @@ export async function prepareBuiltInSkills(
throw new Error(`bundled Skill is missing SKILL.md: ${source}`);
}
const fingerprint = await hashDirectory(source);
- const installedFingerprint = await hashDirectory(descriptor.absolutePath).catch(
- () => null,
- );
+ const installedFingerprint = installedFingerprints.get(descriptor.name) ?? null;
const recordedFingerprint = manifest.fingerprints[descriptor.name];
const sameVersionConflict =
manifest.bundleVersion === bundleVersion &&
@@ -741,6 +753,7 @@ export async function prepareBuiltInSkills(
publishedDirectory = true;
await writeManifest(root, nextManifest);
changed = true;
+ projectionSafe = true;
} catch (error) {
await fsp.rm(pending, { recursive: true, force: true }).catch(() => undefined);
if (publishedDirectory) {
@@ -758,6 +771,7 @@ export async function prepareBuiltInSkills(
return {
descriptors: builtInSkillDescriptors(options.userDataDir, options.appDataDir),
+ projectionSafe,
changed,
warnings,
};
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 94b014c76a..b756c19611 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -5892,8 +5892,16 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
// Desktop / agent-builtin / agent-skill 各一条 list 接口 + desktop 自家的
// execute 接口。renderer 通过 mergeCommands 把三路 list 合并展示, dispatch
// 时按 kind 分流: desktop → executeDesktopCommand IPC; agent-* → 当 prompt 前缀 send。
- ipcMain.handle(MAKER_INVOKE.LIST_DESKTOP_COMMANDS, () => {
- return { success: true, commands: getDesktopCommandRegistry().list() };
+ ipcMain.handle(MAKER_INVOKE.LIST_DESKTOP_COMMANDS, (_event, ctx?: unknown) => {
+ const deviceId = ctx && typeof ctx === 'object' && !Array.isArray(ctx)
+ && typeof (ctx as { deviceId?: unknown }).deviceId === 'string'
+ && (ctx as { deviceId: string }).deviceId.length > 0
+ ? (ctx as { deviceId: string }).deviceId
+ : undefined;
+ return {
+ success: true,
+ commands: getDesktopCommandRegistry().list(deviceId ? { deviceId } : undefined),
+ };
});
ipcMain.handle(MAKER_INVOKE.EXECUTE_DESKTOP_COMMAND, async (e, name: unknown, ctx: unknown) => {
diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.ts
index c34b91bf39..39fbab5b6c 100644
--- a/apps/desktop/src/preload/preload.ts
+++ b/apps/desktop/src/preload/preload.ts
@@ -6061,11 +6061,11 @@ contextBridge.exposeInMainWorld('electronAPI', {
// Renderer 通过这四个调用合并三路数据 + 触发 desktop 命令 execute。
// 老 scanSlashCommands 已下线 —— 数据等价于 listAgentSkills, 改名是为了和
// listAgentCommands / listDesktopCommands 形成清晰的 "三源 + execute" 命名族。
- listDesktopCommands: (): Promise<{
+ listDesktopCommands: (ctx?: { deviceId?: string }): Promise<{
success: boolean;
error?: string;
commands?: Array<{ kind: 'desktop'; name: string; description: string }>;
- }> => ipcRenderer.invoke('maker:list-desktop-commands'),
+ }> => ipcRenderer.invoke('maker:list-desktop-commands', ctx),
executeDesktopCommand: (
name: string,
diff --git a/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts b/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts
index cc0574e988..ea725abe66 100644
--- a/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts
+++ b/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts
@@ -142,7 +142,7 @@ describe('loadAllCommands deviceId', () => {
'dev-1',
);
// desktop 始终本地
- expect(s.listDesktopCommands).toHaveBeenCalled();
+ expect(s.listDesktopCommands).toHaveBeenCalledWith({ deviceId: 'dev-1' });
// agent-builtin / agent-skill 不走本地、走隧道
expect(s.listAgentCommands).not.toHaveBeenCalled();
expect(s.listAgentSkills).not.toHaveBeenCalled();
diff --git a/apps/desktop/src/renderer/lib/slashCommands.ts b/apps/desktop/src/renderer/lib/slashCommands.ts
index 1587e5dfe7..01222510c8 100644
--- a/apps/desktop/src/renderer/lib/slashCommands.ts
+++ b/apps/desktop/src/renderer/lib/slashCommands.ts
@@ -344,7 +344,9 @@ export async function loadAllCommands(
// device-link「以被控端为准」:agent-builtin / agent-skill 是被控端**该会话**的能力,远程时经隧道
// 从被控端读(channel 已 allowlist,workingDir 是被控端路径,扫描在被控端跑正确)。
// desktop 命令**始终本地** —— 它是控制端 app 的 UI 动作(execute-desktop-command 不可隧道,见 D2)。
- const desktopP: Promise<CmdRes> = api.listDesktopCommands().catch(() => ({ success: false }));
+ const desktopP: Promise<CmdRes> = api.listDesktopCommands(
+ deviceId ? { deviceId } : undefined,
+ ).catch(() => ({ success: false }));
const builtinP: Promise<CmdRes> = (
deviceId
? (window.electronAPI.deviceLink.invoke(deviceId, 'maker:list-agent-commands', [
diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.ts
index 2481e3af13..d5fd648d99 100644
--- a/apps/desktop/src/renderer/vite-env.d.ts
+++ b/apps/desktop/src/renderer/vite-env.d.ts
@@ -5462,7 +5462,7 @@ interface ElectronAPI {
endSessionDragPreview: (dragEndAtMs?: number) => void;
// ── Palette `/` 命令三源 (palette refactor) ───────────────────────
- listDesktopCommands: () => Promise<{
+ listDesktopCommands: (ctx?: { deviceId?: string }) => Promise<{
success: boolean;
error?: string;
commands?: Array<{ kind: 'desktop'; name: string; description: string }>;