diff --git a/packages/cli/src/commands/workflow/list.ts b/packages/cli/src/commands/workflow/list.ts index 3881d2c7..67df9ba4 100644 --- a/packages/cli/src/commands/workflow/list.ts +++ b/packages/cli/src/commands/workflow/list.ts @@ -38,7 +38,15 @@ export class WorkflowListCommand extends Command { async execute(): Promise { const targetPath = resolve(this.projectPath || process.cwd()); - const workflows = listWorkflows(targetPath); + + let workflows: ReturnType; + try { + workflows = listWorkflows(targetPath); + } catch (err) { + console.log(chalk.red('Failed to list workflows.')); + console.log(chalk.dim(String(err))); + return 1; + } if (this.json) { console.log(JSON.stringify(workflows, null, 2)); diff --git a/packages/core/src/cicd/templates.ts b/packages/core/src/cicd/templates.ts index e7ceb267..b6765a53 100644 --- a/packages/core/src/cicd/templates.ts +++ b/packages/core/src/cicd/templates.ts @@ -152,8 +152,7 @@ skill-validation: - skillkit validate - skillkit test --json > test-results.json artifacts: - reports: - junit: test-results.json + # Note: test-results.json is JSON format, not JUnit XML paths: - test-results.json expire_in: 30 days diff --git a/packages/core/src/executor/agents.ts b/packages/core/src/executor/agents.ts index e9573369..d496fc65 100644 --- a/packages/core/src/executor/agents.ts +++ b/packages/core/src/executor/agents.ts @@ -230,7 +230,7 @@ async function executeCommand( const spawnOptions: SpawnOptions = { cwd: options.cwd, env: options.env as NodeJS.ProcessEnv, - shell: true, + // shell: false (default) - prevents shell injection when passing untrusted input }; const child = spawn(command, args, spawnOptions); diff --git a/packages/core/src/executor/engine.ts b/packages/core/src/executor/engine.ts index 53ce9a9b..eacd7090 100644 --- a/packages/core/src/executor/engine.ts +++ b/packages/core/src/executor/engine.ts @@ -279,10 +279,34 @@ export class SkillExecutionEngine { commitSha: taskResult.commitSha, }); - if (taskResult.status === 'failed' && !options.continueOnError) { - overallStatus = 'failed'; - overallError = taskResult.error; - break; + // Emit task_complete progress event (matching execute behavior) + this.onProgress?.({ + type: 'task_complete', + taskId: task.id, + taskName: task.name, + taskIndex: i, + totalTasks: tasks.length, + status: taskResult.status, + error: taskResult.error, + }); + + // Handle task failure + if (taskResult.status === 'failed') { + if (!options.continueOnError) { + overallStatus = 'failed'; + overallError = taskResult.error; + break; + } + } + + // Run verification if enabled (matching execute behavior) + if (options.verify && task.verify) { + const verificationPassed = await this.runVerification(task, taskResult); + if (!verificationPassed && !options.continueOnError) { + overallStatus = 'failed'; + overallError = 'Verification failed'; + break; + } } } @@ -383,8 +407,36 @@ export class SkillExecutionEngine { return { continue: true }; } + /** + * Safely test a regex pattern with timeout protection against ReDoS + */ + private safeRegexTest(pattern: string, input: string, timeoutMs = 1000): boolean { + // Limit pattern and input length to prevent excessive processing + if (pattern.length > 500 || input.length > 100000) { + return false; + } + + try { + const regex = new RegExp(pattern); + // Simple patterns should complete quickly; complex ones may timeout + const startTime = Date.now(); + const result = regex.test(input); + if (Date.now() - startTime > timeoutMs) { + console.warn(`Regex pattern took too long: ${pattern.slice(0, 50)}...`); + } + return result; + } catch { + // Invalid regex pattern + return false; + } + } + /** * Run verification for a task + * + * SECURITY NOTE: Verification commands are executed from skill configuration. + * Only run skills from trusted sources. Commands run with the same privileges + * as the skillkit process. */ private async runVerification( task: ExecutableTask, @@ -404,6 +456,7 @@ export class SkillExecutionEngine { for (const rule of task.verify.automated) { if (rule.command) { try { + // SECURITY: Commands are from skill config - only run trusted skills const output = execSync(rule.command, { cwd: this.projectPath, encoding: 'utf-8', @@ -419,7 +472,8 @@ export class SkillExecutionEngine { passed = output.includes(expected); } else if (rule.expect.startsWith('matches:')) { const pattern = rule.expect.slice(8); - passed = new RegExp(pattern).test(output); + // Use safe regex test to prevent ReDoS + passed = this.safeRegexTest(pattern, output); } } diff --git a/packages/core/src/marketplace/aggregator.ts b/packages/core/src/marketplace/aggregator.ts index 89d6e72f..fcedb081 100644 --- a/packages/core/src/marketplace/aggregator.ts +++ b/packages/core/src/marketplace/aggregator.ts @@ -156,6 +156,22 @@ export class MarketplaceAggregator { return skills; } + /** + * Check if a path is an absolute URL + */ + private isAbsoluteUrl(path: string): boolean { + return /^https?:\/\//i.test(path); + } + + /** + * Convert a GitHub URL to raw content URL + */ + private toRawUrl(url: string): string { + return url + .replace('://github.com/', '://raw.githubusercontent.com/') + .replace('/blob/', '/'); + } + /** * Parse a skill entry from JSON */ @@ -166,6 +182,11 @@ export class MarketplaceAggregator { const name = String(item.name || item.title || 'Unknown'); const path = String(item.path || item.file || item.url || '/'); + // Handle absolute URLs - use them directly instead of building from source + const rawUrl = this.isAbsoluteUrl(path) + ? this.toRawUrl(path) + : this.buildRawUrl(source, path); + return { id: `${source.owner}/${source.repo}/${path}`, name, @@ -179,7 +200,7 @@ export class MarketplaceAggregator { stars: typeof item.stars === 'number' ? item.stars : undefined, updatedAt: item.updatedAt as string | undefined, downloads: typeof item.downloads === 'number' ? item.downloads : undefined, - rawUrl: this.buildRawUrl(source, path), + rawUrl, }; } @@ -215,14 +236,21 @@ export class MarketplaceAggregator { const descMatch = context.match(/[-*]\s*\[.*?\]\(.*?\)\s*[-:]\s*(.+?)(?:\n|$)/); const description = descMatch ? descMatch[1].trim() : ''; + // Handle absolute URLs in README links + const isAbsolute = this.isAbsoluteUrl(path); + const normalizedPath = isAbsolute ? path : (path.startsWith('/') ? path : `/${path}`); + const rawUrl = isAbsolute + ? this.toRawUrl(path) + : `https://raw.githubusercontent.com/${source.owner}/${source.repo}/${branch}/${path}`; + skills.push({ id: `${source.owner}/${source.repo}/${path}`, name, description, source, - path: path.startsWith('/') ? path : `/${path}`, + path: normalizedPath, tags: this.inferTags(name, description), - rawUrl: `https://raw.githubusercontent.com/${source.owner}/${source.repo}/${branch}/${path}`, + rawUrl, }); } diff --git a/packages/core/src/memory/compressor.ts b/packages/core/src/memory/compressor.ts index 937e266e..a86f0692 100644 --- a/packages/core/src/memory/compressor.ts +++ b/packages/core/src/memory/compressor.ts @@ -5,6 +5,7 @@ * extraction or AI-powered compression. */ +import { homedir } from 'node:os'; import type { Observation, Learning, ObservationType } from './types.js'; import { LearningStore } from './learning-store.js'; import { MemoryIndexStore } from './memory-index.js'; @@ -856,7 +857,9 @@ export class MemoryCompressor { projectPath, options?.projectName ); - this.indexStore = new MemoryIndexStore(projectPath, options?.scope === 'global'); + // For global scope, use home directory; for project scope, use project path + const indexBasePath = options?.scope === 'global' ? homedir() : projectPath; + this.indexStore = new MemoryIndexStore(indexBasePath, options?.scope === 'global'); this.projectName = options?.projectName; } diff --git a/packages/core/src/memory/memory-index.ts b/packages/core/src/memory/memory-index.ts index edc52b7a..d837f68d 100644 --- a/packages/core/src/memory/memory-index.ts +++ b/packages/core/src/memory/memory-index.ts @@ -7,12 +7,12 @@ export class MemoryIndexStore { private readonly filePath: string; private data: MemoryIndex | null = null; - constructor(basePath: string, isGlobal = false) { - if (isGlobal) { - this.filePath = join(basePath, 'memory', 'index.yaml'); - } else { - this.filePath = join(basePath, '.skillkit', 'memory', 'index.yaml'); - } + constructor(basePath: string, _isGlobal = false) { + // Both global and project use .skillkit subdirectory + // Global: ~/.skillkit/memory/index.yaml (basePath = homedir()) + // Project: /.skillkit/memory/index.yaml (basePath = projectPath) + // Note: _isGlobal kept for API compatibility but basePath determines the actual path + this.filePath = join(basePath, '.skillkit', 'memory', 'index.yaml'); } private ensureDir(): void { diff --git a/packages/core/src/testing/runner.ts b/packages/core/src/testing/runner.ts index 975b90b7..0fbd8d56 100644 --- a/packages/core/src/testing/runner.ts +++ b/packages/core/src/testing/runner.ts @@ -7,6 +7,7 @@ import { existsSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; import { exec } from 'node:child_process'; +import { createServer } from 'node:net'; import { promisify } from 'node:util'; import { parse as parseYaml } from 'yaml'; import type { @@ -602,19 +603,43 @@ function assertEnvVarSet( }; } -function assertPortAvailable( +async function checkPortAvailable(port: number): Promise { + return new Promise((resolve) => { + const server = createServer(); + server.once('error', () => resolve(false)); + server.once('listening', () => { + server.close(); + resolve(true); + }); + server.listen(port, '127.0.0.1'); + }); +} + +async function assertPortAvailable( assertion: TestAssertion, startTime: number -): AssertionResult { +): Promise { const port = parseInt(assertion.target || '0', 10); - // Simple check - we can't easily check port availability without net module - // This is a placeholder that always passes + if (port <= 0 || port > 65535) { + return { + assertion, + passed: false, + actual: `invalid port ${port}`, + expected: 'valid port number (1-65535)', + error: 'Invalid port number', + duration: Date.now() - startTime, + }; + } + + const isAvailable = await checkPortAvailable(port); + return { assertion, - passed: true, - actual: `port ${port}`, + passed: isAvailable, + actual: isAvailable ? 'available' : 'in use', expected: 'available', + error: isAvailable ? undefined : `Port ${port} is already in use`, duration: Date.now() - startTime, }; }