Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

Use canonical native paths throughout Skill package imports

wyt47cb4874d3ad
diff --git a/src/main/features/skills.ts b/src/main/features/skills.ts
index f7dc9251..ba8fc80c 100644
--- a/src/main/features/skills.ts
+++ b/src/main/features/skills.ts
@@ -1397,7 +1397,7 @@ interface ImportPathPolicyOptions {
}
function _realPathForImportPolicy(value: string): string {
- try { return fs.realpathSync(value); }
+ try { return fs.realpathSync.native(value); }
catch { return value; }
}
@@ -2122,7 +2122,8 @@ async function _withSkillPackage<T extends ImportResult>(sourcePath: string, vis
let realSource: string;
let st: fs.Stats;
try {
- realSource = fs.realpathSync(trimmed);
+ // Match promises.realpath during discovery, including Windows short names.
+ realSource = fs.realpathSync.native(trimmed);
st = fs.statSync(realSource);
} catch {
return { ok: false, error: t('skills.errors.dir_inaccessible') };
@@ -2169,7 +2170,7 @@ async function _withSkillPackage<T extends ImportResult>(sourcePath: string, vis
extractDir = fs.mkdtempSync(path.join(os.tmpdir(), 'orkas-skill-package-'));
extractBundleSafely(zip, extractDir);
- return await visit(fs.realpathSync(extractDir), crypto.createHash('sha256').update(archiveBytes).digest('hex'));
+ return await visit(fs.realpathSync.native(extractDir), crypto.createHash('sha256').update(archiveBytes).digest('hex'));
} catch (err) {
log.warn('skill package archive import failed', {
source_type: 'zip',
@@ -2326,7 +2327,7 @@ export async function importSkillPackageFromPath(sourcePath: string, options: {
if (getActiveUserId() !== uid || options.signal?.aborted) throw new Error('Skill import cancelled.');
for (const file of item.files) {
const st = fs.lstatSync(file.src);
- if (!st.isFile() || fs.realpathSync(file.src) !== file.src
+ if (!st.isFile() || fs.realpathSync.native(file.src) !== file.src
|| JSON.stringify([st.size, st.mtimeMs, st.ctimeMs, st.ino]) !== file.stamp) {
throw new Error('The source changed before copying.');
}
diff --git a/test/main/features/skills.test.ts b/test/main/features/skills.test.ts
index 74725f87..6b207a54 100644
--- a/test/main/features/skills.test.ts
+++ b/test/main/features/skills.test.ts
@@ -1,5 +1,7 @@
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import * as fs from 'node:fs';
+import mutableFs from 'node:fs';
+import { syncBuiltinESMExports } from 'node:module';
import * as os from 'node:os';
import * as path from 'node:path';
import AdmZip from 'adm-zip';
@@ -1714,6 +1716,50 @@ describe('skills › selected batch package import', () => {
return dir;
}
+ it.each([false, true])('keeps native path identity across legacy aliases; source redirected=%s', async redirected => {
+ const dir = skill('selected', 'selected', 1);
+ const nativeRealpath = fs.realpathSync.native;
+ const legacyRealpath = fs.realpathSync;
+ const promiseRealpath = fs.promises.realpath;
+ const canonicalSource = nativeRealpath(source);
+ const alias = `${canonicalSource}-legacy-alias`;
+ fs.symlinkSync(source, alias, 'junction');
+ let redirectObserved = false;
+ // Windows legacy realpathSync preserves short names/casing that the
+ // native promise API expands. Both spellings still name the same source.
+ const legacy = vi.spyOn(mutableFs, 'realpathSync').mockImplementation(((value: fs.PathLike, options?: any) => {
+ const resolved = legacyRealpath(value, options);
+ return typeof resolved === 'string' && (resolved === canonicalSource || resolved.startsWith(canonicalSource + path.sep))
+ ? alias + resolved.slice(canonicalSource.length) : resolved;
+ }) as typeof fs.realpathSync);
+ Object.assign(legacy, { native: nativeRealpath });
+ syncBuiltinESMExports();
+ const canonical = vi.spyOn(fs.promises, 'realpath').mockImplementation((async (value: fs.PathLike, options?: any) => {
+ if (redirected && String(value) === nativeRealpath(dir)) {
+ redirectObserved = true;
+ return canonicalSource;
+ }
+ return promiseRealpath(value, options);
+ }) as typeof fs.promises.realpath);
+ syncBuiltinESMExports();
+ try {
+ const s = await loadSkills();
+ const result = await s.importSkillPackageFromPath(source, { all: true });
+ expect(result.ok, JSON.stringify(result)).toBe(!redirected);
+ if (redirected) {
+ expect(redirectObserved).toBe(true);
+ expect(fs.existsSync(path.join(customSkillsDir(), 'selected'))).toBe(false);
+ } else {
+ expect(fs.readFileSync(path.join(customSkillsDir(), 'selected', 'references', '0.md'), 'utf8')).toBe('Reference 0.\n');
+ }
+ } finally {
+ canonical.mockRestore();
+ legacy.mockRestore();
+ syncBuiltinESMExports();
+ fs.rmSync(alias, { recursive: true, force: true });
+ }
+ });
+
it('previews 265 Skills without writes, imports only selected roots and preserves nested references', async () => {
for (let i = 0; i < 265; i++) skill(`skills/item-${String(i).padStart(3, '0')}`);
const dir = skill('plugins/vendor/skills/large', 'large', 320);