Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(skillhub): 修复停用扫描边界与安装卸载状态收口
xd-bobof43bee9e5b23
diff --git a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts b/apps/desktop/src/main/skillhub/__tests__/installService.test.tsindex ef07494de2..b07b496a3a 100644--- a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts+++ b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts@@ -478,6 +478,43 @@ describe('skillhub/installService', () => {}});+ it.each(['success', 'registry-failure', 'owner-before-registry', 'owner-during-registry', 'preference-failure'])(+ 'preserves a missing installation’s disabled override until commit (%s)', async (outcome) => {+ const skillName = 'stale-disabled';+ const finalDir = path.join(fs.realpathSync.native(TEST_ROOT), 'skills', skillName);+ const zipBuf = await makeZip({ 'SKILL.md': 'new content' });+ await setupInstallDownload(skillName, zipBuf);+ const activation = await import('../activationPreferences');+ await activation.setCindySkillEnabled(finalDir, false);+ const { getCurrentDataOwnerId } = await import('../../authManager');+ vi.mocked(getCurrentDataOwnerId).mockReturnValue('owner-1');+ const { registryService } = await import('../registry');+ vi.mocked(registryService.addInstall).mockImplementation(async () => {+ if (outcome === 'registry-failure') throw new Error('registry unavailable');+ if (outcome === 'owner-during-registry') vi.mocked(getCurrentDataOwnerId).mockReturnValue('owner-2');+ });+ const reset = outcome === 'preference-failure'+ ? vi.spyOn(activation, 'setCindySkillEnabled').mockRejectedValueOnce(new Error('settings unavailable'))+ : undefined;+ try {+ const { install } = await import('../installService');+ const result = await install({ name: skillName, installPath: finalDir, version: '1.0.0' }, (progress) => {+ if (outcome === 'owner-before-registry' && progress.phase === 'registering') {+ vi.mocked(getCurrentDataOwnerId).mockReturnValue('owner-2');+ }+ });+ expect(result.success).toBe(outcome === 'success');+ expect(fs.existsSync(finalDir)).toBe(outcome === 'success');+ expect(activation.isCindySkillEnabled(finalDir)).toBe(outcome === 'success');+ if (outcome === 'owner-during-registry' || outcome === 'preference-failure') {+ expect(registryService.removeInstall).toHaveBeenCalledWith(skillName, finalDir);+ }+ } finally {+ reset?.mockRestore();+ }+ },+ );+it('removes a fresh install directory when registry registration fails', async () => {const finalDir = path.join(TEST_ROOT, 'skills', 'registry-fail-skill');const zipBuf = await makeZip({ 'SKILL.md': 'new content' });@@ -1059,6 +1096,28 @@ describe('skillhub/installService', () => {);});+ it('refreshes the importing project when removing an external skill alias', async () => {+ const projectRoot = path.join(TEST_ROOT, 'importing-project');+ const alias = path.join(projectRoot, '.agents', 'skills', 'alias');+ const source = path.join(TEST_ROOT, 'external', 'source');+ fs.mkdirSync(source, { recursive: true });+ fs.writeFileSync(path.join(source, 'SKILL.md'), 'external content');+ makeDirectoryLink(alias, source);+ const { inspectLocalSkillTarget } = await import('../localSkillTarget');+ const target = inspectLocalSkillTarget(source, [alias])!;+ const sharedSkills = await import('../../maker-host/shared-global-skills.js');+ const { registryService } = await import('../registry');+ vi.mocked(registryService.getInstall).mockResolvedValue(null);+ vi.mocked(registryService.readManifest).mockResolvedValue(null);+ vi.mocked(sharedSkills.projectWorkingDirFromSkillPath).mockImplementation((entry) => entry === alias ? projectRoot : null);+ const { uninstall } = await import('../installService');+ const result = await uninstall(target.sourcePath, target);+ expect(result).toEqual({ success: true, projectWorkingDir: projectRoot });+ expect(sharedSkills.prepareSharedProjectSkillLinks).toHaveBeenCalledWith({ workingDir: projectRoot });+ expect(fs.existsSync(alias)).toBe(false);+ expect(fs.readFileSync(path.join(source, 'SKILL.md'), 'utf8')).toBe('external content');+ });+it('returns the project cwd after uninstalling a project skill', async () => {const projectRoot = path.join(TEST_ROOT, 'project-uninstall');const finalDir = path.join(projectRoot, '.agents', 'skills', 'project-skill');diff --git a/apps/desktop/src/main/skillhub/installService.ts b/apps/desktop/src/main/skillhub/installService.tsindex 7fd9481b89..f14720b4d5 100644--- a/apps/desktop/src/main/skillhub/installService.ts+++ b/apps/desktop/src/main/skillhub/installService.ts@@ -719,14 +719,6 @@ export async function install(return { success: false, errorCode: 'CANCELLED', message: '已取消' };}- if (!rollbackState.backupDir && !isCindySkillEnabled(finalDir)) {- try { await setCindySkillEnabled(finalDir, true, () => !checkAbort()); }- catch {- await rollbackFinalSwitch(finalDir, rollbackState);- return { success: false, errorCode: 'WRITE_FAILED', message: 'Could not reset Skill state' };- }- }-// 7) 同步 registryonProgress({ phase: 'registering', name: p.name });if (checkAbort()) {@@ -804,6 +796,12 @@ export async function install(for (const { installPath } of physicalRegistrySnapshots) {await registryService.removeInstall(p.name, installPath);}+ // Fresh installs reset a stale override only after registration succeeds.+ // A failed reset uses the same file/registry rollback; existing installs+ // keep their preference, including when a later backup step fails.+ if (!rollbackState.backupDir && !isCindySkillEnabled(finalDir)) {+ await setCindySkillEnabled(finalDir, true, () => !checkAbort());+ }} catch (err) {log.error('[skillInstall] registry sync failed:', err);const registryMessage = err instanceof Error ? err.message : String(err);@@ -1090,7 +1088,9 @@ async function uninstallLocked(const complete = await finishUninstallCleanup(cleanup, canMutate);const cleanupToken = complete ? undefined : crypto.randomUUID();if (cleanupToken) pendingUninstallCleanup.set(cleanupToken, cleanup);- const projectWorkingDir = await reconcileProjectSkillLinksForPaths(resolved, absolutePath);+ const projectWorkingDir = await reconcileProjectSkillLinksForPaths(+ target?.operationPath ?? absolutePath, resolved, absolutePath,+ );return { success: true, ...(cleanupToken ? { cleanupToken } : {}),...(projectWorkingDir ? { projectWorkingDir } : {}) };}diff --git a/docs/dev-rules/pi-harness.md b/docs/dev-rules/pi-harness.mdindex 21ee07e34b..21c88aa7bb 100644--- a/docs/dev-rules/pi-harness.md+++ b/docs/dev-rules/pi-harness.md@@ -77,6 +77,11 @@ provider/model/contextWindow,因为 Pi 会用进程初始 CLI route 重建未配置 Pi 百分比时不写 `reserveTokens`,沿用 Pi 默认 16384。+Skill 停用适配保留用户指定的物理路径,再尽力解析发现目录中的符号链接别名;该额外扫描+共享 2048 个条目、16 层深度和 100ms 的遍历预算,目录流逐项读取并在退出时关闭。+预算耗尽后保留已解析路径,不继续扫描;原生 Pi 仍负责资源加载,不能因 Cindy 的扫描+截断而拒绝加载其它资源。时间预算在文件系统调用之间检查,不是对单次系统调用的超时。+## 3. 设计原则(Chris 2026-07-30 裁决)- PI 是 Cindy 未来的基座 harness。diff --git a/packages/maker-core/src/agents/pi/__tests__/skill-activation.test.ts b/packages/maker-core/src/agents/pi/__tests__/skill-activation.test.tsnew file mode 100644index 0000000000..e5dc69df46--- /dev/null+++ b/packages/maker-core/src/agents/pi/__tests__/skill-activation.test.ts@@ -0,0 +1,67 @@+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { piDisabledDiscoveryPaths } from '../skill-activation.js';++let root: string;+beforeEach(() => { root = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-pi-alias-')); });+afterEach(() => {+ vi.restoreAllMocks();+ fs.rmSync(root, { recursive: true, force: true });+});++function link(source: string, destination: string): void {+ fs.mkdirSync(path.dirname(destination), { recursive: true });+ fs.symlinkSync(source, destination, process.platform === 'win32' ? 'junction' : 'dir');+}++function deepTree(): string {+ const deepest = path.join(root, ...Array<string>(32).fill('d'));+ fs.mkdirSync(deepest, { recursive: true });+ return deepest;+}++describe('bounded Pi disabled Skill alias discovery', () => {+ it('keeps native paths and resolves ordinary nested imports without following cycles', () => {+ const source = path.join(root, 'source');+ fs.mkdirSync(source);+ fs.writeFileSync(path.join(source, 'SKILL.md'), 'fixture');+ const discovery = path.join(root, 'skills');+ const alias = path.join(discovery, 'nested', 'alias');+ link(source, alias);+ link(discovery, path.join(discovery, 'cycle'));+ expect(piDisabledDiscoveryPaths([source], [discovery])).toEqual([source, alias]);+ const scan = vi.spyOn(fs, 'opendirSync');+ expect(piDisabledDiscoveryPaths([], [discovery])).toEqual([]);+ expect(scan).not.toHaveBeenCalled();+ });++ it('caps traversal through a linked deep directory while retaining the disabled source', () => {+ const deepest = deepTree();+ const alias = path.join(root, 'alias');+ link(path.join(root, 'd'), alias);+ vi.spyOn(performance, 'now').mockReturnValue(0);+ const stat = vi.spyOn(fs, 'statSync');+ expect(piDisabledDiscoveryPaths([deepest], [alias])).toEqual([deepest]);+ expect(stat.mock.calls.length).toBeLessThanOrEqual(17);+ });++ it('caps enumeration in a wide directory instead of inspecting every file', () => {+ for (let index = 0; index < 2200; index += 1) fs.writeFileSync(path.join(root, `f${index}`), '');+ vi.spyOn(performance, 'now').mockReturnValue(0);+ const stat = vi.spyOn(fs, 'statSync');+ const disabled = path.join(root, 'absent-skill');+ expect(piDisabledDiscoveryPaths([disabled], [root])).toEqual([disabled]);+ expect(stat.mock.calls.length).toBeLessThanOrEqual(2048);+ });++ it('stops further filesystem visits when the time budget expires', () => {+ const deepest = deepTree();+ let elapsed = 0;+ vi.spyOn(performance, 'now').mockImplementation(() => { elapsed += 25; return elapsed; });+ const stat = vi.spyOn(fs, 'statSync');+ expect(piDisabledDiscoveryPaths([deepest], [root])).toEqual([deepest]);+ expect(stat.mock.calls.length).toBeLessThan(3);+ });+});diff --git a/packages/maker-core/src/agents/pi/skill-activation.ts b/packages/maker-core/src/agents/pi/skill-activation.tsindex 7952fb8a09..b093412f95 100644--- a/packages/maker-core/src/agents/pi/skill-activation.ts+++ b/packages/maker-core/src/agents/pi/skill-activation.ts@@ -25,19 +25,39 @@ export function filterPiDisabledProjectSkills(*/export function piDisabledDiscoveryPaths(disabled: readonly string[], roots: readonly string[]): string[] {const result = new Set(disabled);- const visit = (entry: string, ancestors: Set<string>) => {+ if (disabled.length === 0) return [];+ // Alias resolution is best-effort and must not hold up native Pi startup.+ // Bound enumeration itself (including hidden entries), not just recursion.+ const deadline = performance.now() + 100;+ const disabledKeys = new Set(disabled.map(canonicalSkillPath));+ let remainingEntries = 2048;+ const exhausted = () => remainingEntries <= 0 || performance.now() >= deadline;+ const visit = (entry: string, ancestors: Set<string>, depth: number) => {+ if (depth > 16 || exhausted()) return;try {const key = canonicalSkillPath(entry);- if (isSkillDisabled(entry, disabled)) { result.add(entry); return; }+ if (disabledKeys.has(key)) { result.add(entry); return; }if (!fs.statSync(entry).isDirectory() || ancestors.has(key)) return;if (fs.existsSync(path.join(entry, 'SKILL.md')) || fs.existsSync(path.join(entry, 'skill.md'))) return;const next = new Set([...ancestors, key]);- for (const child of fs.readdirSync(entry)) {- if (!child.startsWith('.')) visit(path.join(entry, child), next);+ const directory = fs.opendirSync(entry);+ try {+ while (!exhausted()) {+ const child = directory.readSync();+ if (!child) break;+ remainingEntries -= 1;+ if (!child.name.startsWith('.')) visit(path.join(entry, child.name), next, depth + 1);+ }+ } finally {+ directory.closeSync();}} catch { /* Missing/unreadable discovery roots are handled by native Pi. */ }};- if (disabled.length > 0) for (const root of roots) visit(root, new Set());+ for (const root of roots) {+ if (exhausted()) break;+ remainingEntries -= 1;+ visit(root, new Set(), 0);+ }return [...result];}