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。

优化新对话技能加载

DavidShen8f3c91c50424
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 2688605cde..4a86b7dbab 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -3887,7 +3887,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
ipcMain.handle(MAKER_INVOKE.LIST_AGENT_SKILLS, async (_e, agentKind: unknown, params: unknown) => {
try {
const kind = requireAgentKind(agentKind);
- const skillParams = params as { workingDir: string; forceReload?: boolean };
+ const skillParams = (params ?? {}) as { workingDir?: string; forceReload?: boolean };
const linksChanged = await prepareProjectSkillLinksFailSoft(skillParams?.workingDir);
if (kind === 'codex' && linksChanged) {
skillParams.forceReload = true;
diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.ts
index 2a836ae89c..94f9b69009 100644
--- a/apps/desktop/src/preload/preload.ts
+++ b/apps/desktop/src/preload/preload.ts
@@ -3929,7 +3929,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
listAgentSkills: (
agentKind: 'claude-code' | 'codex',
- params: { workingDir: string; forceReload?: boolean },
+ params: { workingDir?: string; forceReload?: boolean },
): Promise<{
success: boolean;
error?: string;
diff --git a/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts b/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts
index a8a73a0ace..2190fb5e29 100644
--- a/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts
+++ b/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts
@@ -48,6 +48,36 @@ describe('loadAllCommands deviceId', () => {
expect(cmds.map((x) => x.name).sort()).toEqual(['compact', 'goal', 'help', 'localskill']);
});
+ it('本地 Claude 新对话无 workingDir 时仍加载全局 skills', async () => {
+ const s = stubElectron();
+ const cmds = await loadAllCommands('claude-code', undefined);
+
+ expect(s.invoke).not.toHaveBeenCalled();
+ expect(s.listAgentSkills).toHaveBeenCalledWith('claude-code', {});
+ expect(cmds.some((x) => x.name === 'localskill')).toBe(true);
+ });
+
+ it('SSH remote 用 null 显式关闭控制端本机 skill 扫描', async () => {
+ const s = stubElectron();
+ const cmds = await loadAllCommands('claude-code', null);
+
+ expect(s.listAgentSkills).not.toHaveBeenCalled();
+ expect(s.invoke).not.toHaveBeenCalledWith(
+ expect.anything(),
+ 'maker:list-agent-skills',
+ expect.anything(),
+ );
+ expect(cmds.some((x) => x.kind === 'agent-skill')).toBe(false);
+ });
+
+ it('本地 Codex 新对话无 workingDir 时保持不请求 skills/list', async () => {
+ const s = stubElectron();
+ const cmds = await loadAllCommands('codex', undefined);
+
+ expect(s.listAgentSkills).not.toHaveBeenCalled();
+ expect(cmds.some((x) => x.kind === 'agent-skill')).toBe(false);
+ });
+
it('远程会话:agent-builtin / agent-skill 走隧道,desktop 仍本地', async () => {
const s = stubElectron();
const cmds = await loadAllCommands('claude-code', '/host/path', undefined, 'dev-1');
@@ -59,11 +89,23 @@ describe('loadAllCommands deviceId', () => {
expect(s.invoke).toHaveBeenCalledWith('dev-1', 'maker:list-agent-commands', ['claude-code']);
expect(s.invoke).toHaveBeenCalledWith('dev-1', 'maker:list-agent-skills', [
'claude-code',
- { workingDir: '/host/path', forceReload: undefined },
+ { workingDir: '/host/path' },
]);
// 结果 = 本地 desktop(help + goal,远程会话不再剔除)+ 被控端 builtin(host-cmd)+ 被控端 skill(host-skill)
expect(cmds.map((x) => x.name).sort()).toEqual(['goal', 'help', 'host-cmd', 'host-skill']);
// device-link 下 /goal 保留:业务体经隧道到被控端 goal-host,palette 正常展示。
expect(cmds.some((x) => x.name === 'goal')).toBe(true);
});
+
+ it('device-link Claude 新对话无 workingDir 时从被控端加载全局 skills', async () => {
+ const s = stubElectron();
+ const cmds = await loadAllCommands('claude-code', undefined, undefined, 'dev-1');
+
+ expect(s.listAgentSkills).not.toHaveBeenCalled();
+ expect(s.invoke).toHaveBeenCalledWith('dev-1', 'maker:list-agent-skills', [
+ 'claude-code',
+ {},
+ ]);
+ expect(cmds.some((x) => x.name === 'host-skill')).toBe(true);
+ });
});
diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
index cec617008c..b716fe8a62 100644
--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
@@ -2962,7 +2962,7 @@ export function ChatInput({
// workingDir 是被控端路径(SSH remoteHostId 才置 null 关扫描)。desktop 命令始终本地。
loadAllCommands(
paletteAgentKind,
- isRemoteSession ? null : (workingDir ?? null),
+ isRemoteSession ? null : workingDir,
opts,
deviceLinkDeviceId,
)
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
index a45ffd69b7..74851b31d8 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
@@ -1081,8 +1081,9 @@ export function CCAgentSessionView({
useEffect(() => {
let cancelled = false;
const agentKind = session?.agentKind === 'codex' ? 'codex' : 'claude-code';
- // remote 传 null:loadAllCommands 退化为 desktop + agent-builtin,不扫本机项目 skills。
- const wd = isRemoteSession ? null : (session?.workingDir ?? null);
+ // SSH remote 传 null:loadAllCommands 退化为 desktop + agent-builtin,不扫控制端本机 skills。
+ // 本地无 workingDir 传 undefined:Claude 仍可扫描全局 skills。
+ const wd = isRemoteSession ? null : session?.workingDir;
// 先同步清空:切换会话(尤其 local→remote)时 loadAllCommands 是异步的,清空可避免
// 刷新完成前 getHelpCommandsSnapshot / desktop 命令识别复用上一个项目的本地 skills。
setAllCommands([]);
@@ -1563,7 +1564,7 @@ export function CCAgentSessionView({
// device-link 远程会话同源:传 remoteDeviceId,fallback 快照也从被控端读(见上方 cache effect 说明)。
return await loadAllCommands(
agentKind,
- isRemoteSession ? null : (session?.workingDir ?? null),
+ isRemoteSession ? null : session?.workingDir,
undefined,
remoteDeviceId,
);
diff --git a/apps/desktop/src/renderer/lib/slashCommands.ts b/apps/desktop/src/renderer/lib/slashCommands.ts
index 81c1126cb1..15d9978fd3 100644
--- a/apps/desktop/src/renderer/lib/slashCommands.ts
+++ b/apps/desktop/src/renderer/lib/slashCommands.ts
@@ -85,7 +85,8 @@ export function filterSlashCommands(
* 拉三路 IPC, 合并成 UnifiedCommand[]。
*
* - 任何一路失败按空列表处理(已在 main 端做 try/catch + 返回 success:false), 不阻塞 palette。
- * - workingDir 为空时不发起 agent-skill 扫描(没意义), 但 desktop / agent-builtin 仍然返回。
+ * - workingDir=undefined 表示本地无项目:Claude 仍扫描全局 skills。
+ * - workingDir=null 表示显式禁用扫描(SSH remote):避免读取控制端本机 skills。
*/
export async function loadAllCommands(
agentKind: AgentKind,
@@ -108,14 +109,19 @@ export async function loadAllCommands(
? (window.electronAPI.deviceLink.invoke(deviceId, 'maker:list-agent-commands', [agentKind]) as Promise<CmdRes>)
: api.listAgentCommands(agentKind)
).catch(() => ({ success: false }));
- const skillP: Promise<SkillRes> = workingDir
+ const shouldLoadSkills = workingDir !== null && (agentKind === 'claude-code' || Boolean(workingDir));
+ const skillParams = {
+ ...(workingDir ? { workingDir } : {}),
+ ...(opts?.forceReload !== undefined ? { forceReload: opts.forceReload } : {}),
+ };
+ const skillP: Promise<SkillRes> = shouldLoadSkills
? (
deviceId
? (window.electronAPI.deviceLink.invoke(deviceId, 'maker:list-agent-skills', [
agentKind,
- { workingDir, forceReload: opts?.forceReload },
+ skillParams,
]) as Promise<SkillRes>)
- : api.listAgentSkills(agentKind, { workingDir, forceReload: opts?.forceReload })
+ : api.listAgentSkills(agentKind, skillParams)
).catch(() => ({ success: false }))
: Promise.resolve({ success: true, skills: [] });
diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.ts
index 7bbd2b0c43..6242f060ea 100644
--- a/apps/desktop/src/renderer/vite-env.d.ts
+++ b/apps/desktop/src/renderer/vite-env.d.ts
@@ -3776,7 +3776,7 @@ interface ElectronAPI {
listAgentSkills: (
agentKind: 'claude-code' | 'codex',
- params: { workingDir: string; forceReload?: boolean },
+ params: { workingDir?: string; forceReload?: boolean },
) => Promise<{
success: boolean;
error?: string;
diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.ts
index cfafac0962..6bce253f42 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -1160,6 +1160,8 @@ export class CodexAgent extends BaseAgent {
* 只是包成新的 AgentSkillCommand 形状(kind='agent-skill')。
*/
override async listAgentSkills(opts: ListAgentSkillsOptions): Promise<ListAgentSkillsResult> {
+ // Codex app-server 的 skills/list 需要 cwd;无项目的新对话保持原先的空列表语义。
+ if (!opts.workingDir) return { skills: [] };
try {
const { skills, errors } = await this.listSkillsForCwd(opts.workingDir, opts.forceReload ?? false);
const out: ListAgentSkillsResult = {
diff --git a/packages/maker-core/src/agents/shared/palette-scanner.test.ts b/packages/maker-core/src/agents/shared/palette-scanner.test.ts
index 9f04b9d40f..e937f9c4eb 100644
--- a/packages/maker-core/src/agents/shared/palette-scanner.test.ts
+++ b/packages/maker-core/src/agents/shared/palette-scanner.test.ts
@@ -30,6 +30,45 @@ describe('scanWorkspaceFileResources', () => {
});
describe('scanClaudeSlashCommands', () => {
+ it('lists global Claude commands and skills without a working directory', async () => {
+ const root = await mkdtemp(path.join(os.tmpdir(), 'xdt-palette-'));
+ const home = path.join(root, 'home');
+ const commandsDir = path.join(home, '.claude', 'commands');
+ const skillDir = path.join(home, '.claude', 'skills', 'global-only');
+
+ vi.stubEnv('HOME', home);
+ vi.stubEnv('USERPROFILE', home);
+ try {
+ await mkdir(commandsDir, { recursive: true });
+ await mkdir(skillDir, { recursive: true });
+ await writeFile(path.join(commandsDir, 'global-command.md'), '# Global command\n', 'utf8');
+ await writeFile(
+ path.join(skillDir, 'SKILL.md'),
+ '---\ndescription: available without a project\n---\n\nbody\n',
+ 'utf8',
+ );
+
+ const commands = await scanClaudeSlashCommands();
+
+ expect(commands).toEqual(expect.arrayContaining([
+ expect.objectContaining({
+ name: 'global-command',
+ source: 'user',
+ scope: 'global',
+ }),
+ expect.objectContaining({
+ name: 'global-only',
+ description: 'available without a project',
+ source: 'skill',
+ scope: 'global',
+ }),
+ ]));
+ } finally {
+ vi.unstubAllEnvs();
+ await rm(root, { recursive: true, force: true });
+ }
+ });
+
it('includes skill directories that are symlinked into the global Claude skills root', async () => {
const root = await mkdtemp(path.join(os.tmpdir(), 'xdt-palette-'));
const home = path.join(root, 'home');
diff --git a/packages/maker-core/src/agents/shared/palette-scanner.ts b/packages/maker-core/src/agents/shared/palette-scanner.ts
index 303be29764..abe5ec8540 100644
--- a/packages/maker-core/src/agents/shared/palette-scanner.ts
+++ b/packages/maker-core/src/agents/shared/palette-scanner.ts
@@ -303,19 +303,19 @@ async function scanClaudeSkillDirs(
return results;
}
-export async function scanClaudeSlashCommands(workingDir: string): Promise<AgentSlashCommand[]> {
- if (!workingDir || !path.isAbsolute(workingDir) || !(await isDirectory(workingDir))) {
- return [];
- }
-
+export async function scanClaudeSlashCommands(workingDir?: string): Promise<AgentSlashCommand[]> {
const home = os.homedir();
const merged = new Map<string, AgentSlashCommand>();
const discovered = [
...(await scanClaudeCommandFiles(path.join(home, '.claude', 'commands'), 'global')),
...(await scanClaudeSkillDirs(path.join(home, '.claude', 'skills'), 'global')),
- ...(await scanClaudeCommandFiles(path.join(workingDir, '.claude', 'commands'), 'project')),
- ...(await scanClaudeSkillDirs(path.join(workingDir, '.claude', 'skills'), 'project')),
];
+ if (workingDir && path.isAbsolute(workingDir) && await isDirectory(workingDir)) {
+ discovered.push(
+ ...(await scanClaudeCommandFiles(path.join(workingDir, '.claude', 'commands'), 'project')),
+ ...(await scanClaudeSkillDirs(path.join(workingDir, '.claude', 'skills'), 'project')),
+ );
+ }
for (const cmd of discovered) {
merged.set(cmd.name, cmd);
diff --git a/packages/maker-core/src/types/palette.ts b/packages/maker-core/src/types/palette.ts
index 12d2dbfd4d..5ce0742070 100644
--- a/packages/maker-core/src/types/palette.ts
+++ b/packages/maker-core/src/types/palette.ts
@@ -64,7 +64,8 @@ export interface AgentSkillCommand {
export type UnifiedCommand = DesktopCommandMeta | AgentBuiltinCommand | AgentSkillCommand;
export interface ListAgentSkillsOptions {
- workingDir: string;
+ /** Omit to list only agent-global skills without a project scope. */
+ workingDir?: string;
forceReload?: boolean;
}