Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test(companions): preserve native skill link import boundaries
Chris12a115215965
diff --git a/apps/desktop/src/main/bot-import/README.md b/apps/desktop/src/main/bot-import/README.mdindex 066beb0784..867d1641d9 100644--- a/apps/desktop/src/main/bot-import/README.md+++ b/apps/desktop/src/main/bot-import/README.md@@ -116,6 +116,15 @@ omitting it retains normal companion defaults, and a rejected request can be cornative directory links and disabled lists. OpenClaw discovery covers workspace,workspace `.agents`, personal/managed/workshop, installed bundled, extra andenabled plugin manifest roots, with native precedence and symlink trust rules.+ Hermes personal/external roots and OpenClaw managed/personal roots intentionally+ accept directory links outside their lexical root, as their native loaders do.+ Selecting such a source trusts that source's Skill catalog and link targets;+ this importer does not sandbox a compromised source home. Other OpenClaw roots+ retain canonical containment / configured target checks. Once a Skill is found,+ only its canonical subtree is captured (including ordinary hidden resources);+ unrelated resource-link escapes remain rejected. Adding a new folder-grant flow+ or disallowing native personal links would change the full-import contract and+ is not part of this fix.Nested archive/environment/support directories are excluded. Names and skillKeyoverrides are resolved before deduplication; skill-owned credential alternativesare selected separately so credential ambiguity cannot deselect a skill.diff --git a/apps/desktop/src/main/bot-import/__tests__/sources.test.ts b/apps/desktop/src/main/bot-import/__tests__/sources.test.tsindex 4c9fa8b1e3..b2de781992 100644--- a/apps/desktop/src/main/bot-import/__tests__/sources.test.ts+++ b/apps/desktop/src/main/bot-import/__tests__/sources.test.ts@@ -458,18 +458,55 @@ it('uses OpenClaw declared names, skillKey, grouped roots and plugin sources inexpect(snapshot.items.find(item => item.env?.SERVICE_TOKEN)?.view.selected).toBe(true);});-it('follows trusted skill directory links without following resource escapes or cycles', async () => {- await write('.hermes/config.yaml', 'name: Ada');+it.for([+ { kind: 'hermes', folder: '.hermes/skills' },+ { kind: 'openclaw', folder: '.openclaw/skills' },+ { kind: 'openclaw', folder: '.agents/skills' },+] as const)('preserves native $folder directory links but bounds their resource subtree', async ({ kind, folder }, ctx) => {+ await write(`.${kind}/${kind === 'hermes' ? 'config.yaml' : 'openclaw.json'}`, '{}');await write('shared/report/SKILL.md', '---\nname: report\n---\nRead report');- await fs.mkdir(path.join(home, '.hermes/skills'), { recursive: true });- try { await fs.symlink(path.join(home, 'shared/report'), path.join(home, '.hermes/skills/report'), 'junction'); }- catch (error) { if (['EPERM', 'ENOTSUP'].includes((error as NodeJS.ErrnoException).code ?? '')) return; throw error; }- await fs.symlink(path.join(home, '.hermes/skills'), path.join(home, '.hermes/skills/loop'), 'junction');+ await write('shared/report/scripts/report.py', '# Skill resource');+ await write('shared/report/.env', 'REPORT_MODE=fixture');+ await write('private/account.txt', 'Unrelated fixture');+ await fs.mkdir(path.join(home, folder), { recursive: true });+ try { await fs.symlink(path.join(home, 'shared/report'), path.join(home, folder, 'report'), 'junction'); }+ catch (error) { if (['EPERM', 'ENOTSUP'].includes((error as NodeJS.ErrnoException).code ?? '')) { ctx.skip(); return; } throw error; }+ await fs.symlink(path.join(home, folder), path.join(home, folder, 'loop'), 'junction');const reader = deps(); const [source] = await discoverImportSources(reader);const snapshot = await inspectImportSource(source!, reader);- expect(snapshot.items.filter(item => item.view.category === 'skills')).toHaveLength(1);- expect(snapshot.items[0]?.sourceDirectory).toBe(await fs.realpath(path.join(home, 'shared/report')));-});+ const skills = snapshot.items.filter(item => item.view.category === 'skills');+ expect(skills).toHaveLength(1);+ const directory = skills[0]!.sourceDirectory!;+ expect(directory).toBe(await fs.realpath(path.join(home, 'shared/report')));+ const resources = await readImportSkillTree(directory);+ expect(resources.map(file => file.name).sort()).toEqual(['.env', 'SKILL.md', 'scripts/report.py']);+ expect(resources.find(file => file.name === '.env')?.bytes.toString()).toBe('REPORT_MODE=fixture');+ // Trust in this Skill's canonical root does not grant its resources a second+ // escape into an unrelated directory, even when the Skill itself was linked.+ await fs.symlink(path.join(home, 'private'), path.join(directory, 'outside'), 'junction');+ await expect(readImportSkillTree(directory)).rejects.toThrow('SOURCE_LINK_OUTSIDE_FOLDER');+});++it.for(['workspace/skills', 'workspace/.agents/skills', '../extra-skills'])(+ 'requires native allowed targets for OpenClaw %s directory links', async (folder, ctx) => {+ await write('.openclaw/openclaw.json', '{}');+ await write('shared/report/SKILL.md', '---\nname: report\n---\nRead report');+ const sourceRoot = path.join(home, '.openclaw');+ const directory = path.resolve(sourceRoot, folder);+ await fs.mkdir(directory, { recursive: true });+ try { await fs.symlink(path.join(home, 'shared/report'), path.join(directory, 'report'), 'junction'); }+ catch (error) { if (['EPERM', 'ENOTSUP'].includes((error as NodeJS.ErrnoException).code ?? '')) { ctx.skip(); return; } throw error; }+ const [source] = await discoverImportSources(deps());+ const inspect = (allowed: string[]) => discoverImportSkills(source!, {+ skills: { load: { extraDirs: ['../extra-skills'], allowSymlinkTargets: allowed } },+ }, home, {}, createImportBudget());+ expect(await inspect([])).toEqual([]);+ expect(await inspect(['../unrelated'])).toEqual([]);+ const allowed = await inspect(['../shared']);+ expect(allowed.map(item => item.view.name)).toEqual(['report']);+ expect(allowed[0]?.sourceDirectory).toBe(await fs.realpath(path.join(home, 'shared/report')));+ },+);it('retains unmapped skill authentication privately without deselecting the skill', async () => {const secret = 'fixture-skill-key-without-env';diff --git a/apps/desktop/src/main/bot-import/skills.ts b/apps/desktop/src/main/bot-import/skills.tsindex 208c1618a8..114594ba85 100644--- a/apps/desktop/src/main/bot-import/skills.ts+++ b/apps/desktop/src/main/bot-import/skills.ts@@ -5,6 +5,10 @@ import { fingerprint, inside, readImportFile, readImportTree, type ImportReadBudimport { CompanionImportError, object, string, type ImportItem, type ImportSource } from './types.js';/** Discovery roots are derived on the host from the selected source, never from IPC paths. */+// `any` preserves native Hermes personal/external and OpenClaw managed/personal+// directory-link semantics. Selecting that source trusts its Skill catalog; it+// is not an arbitrary IPC folder grant. Once a Skill is found, resource capture+// is confined to its canonical directory by readImportSkillTree/readImportTree.interface SkillRoot { directory: string; links: 'any' | string[]; bundled?: boolean }const ignored = new Set(['.git', '.github', '.hub', '.archive', '_archive', '.venv', 'venv', 'node_modules', 'site-packages', '__pycache__', '.tox', '.nox', '.pytest_cache', '.mypy_cache', '.ruff_cache']);const strings = (value: unknown): string[] => Array.isArray(value) ? value.filter((v): v is string => typeof v === 'string' && !!v.trim()) : [];