Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/commands/install-skill.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { homedir } from 'os';
import { join, dirname } from 'path';
import { join } from 'path';
import { existsSync } from 'fs';
import { mkdir, copyFile, readdir } from 'fs/promises';
import { fileURLToPath } from 'url';
import chalk from 'chalk';
import { getPackageRoot } from '../utils/paths.js';

export interface AgentConfig {
name: string;
Expand Down Expand Up @@ -48,9 +48,7 @@ export interface InstallSkillOptions {
}

export function getSkillsDir(): string {
const currentFile = fileURLToPath(import.meta.url);
// From dist/src/commands/install-skill.js -> skills/
return join(dirname(currentFile), '..', '..', '..', 'skills');
return join(getPackageRoot(import.meta.url), 'skills');
}

export async function discoverSkills(skillsDir: string): Promise<string[]> {
Expand Down
7 changes: 2 additions & 5 deletions src/lib/agent-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import path from 'path';
import { fileURLToPath } from 'url';
import { getPackageRoot } from '../utils/paths.js';
import { debug, logInfo, logWarn, logError, initLogFile, getLogFilePath } from '../utils/debug.js';
import type { InstallerOptions } from '../utils/types.js';
import { analytics } from '../utils/analytics.js';
Expand Down Expand Up @@ -577,10 +577,7 @@ export async function runAgent(
};

// Load plugin with bundled skills
// Path from dist/lib/ back to package root
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const pluginPath = path.join(__dirname, '../..');
const pluginPath = getPackageRoot(import.meta.url);
logInfo('Loading plugin from:', pluginPath);

const response = query({
Expand Down
18 changes: 18 additions & 0 deletions src/utils/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { dirname, join } from 'path';
import { existsSync } from 'fs';
import { fileURLToPath } from 'url';

/**
* Resolve the package root by walking up from a compiled file until we find package.json.
* Immune to changes in tsconfig outDir/rootDir structure.
*/
export function getPackageRoot(metaUrl: string): string {
let dir = dirname(fileURLToPath(metaUrl));
while (dir !== dirname(dir)) {
if (existsSync(join(dir, 'package.json'))) {
return dir;
}
dir = dirname(dir);
}
throw new Error('Could not find package root (no package.json found in parent directories)');
}