@autifyhq/muon
Version:
Muon - AI-Powered Playwright Test Coding Agent with Advanced Test Fixing Capabilities
66 lines (65 loc) • 2.31 kB
JavaScript
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { homedir } from 'node:os';
import { join } from 'node:path';
const CONFIG_VERSION = '1.0.0';
function getGlobalMuonDir() {
return join(homedir(), '.muon');
}
function getTrustConfigPath() {
return join(getGlobalMuonDir(), 'trust-config.json');
}
export function isTrusted(projectPath) {
const configPath = getTrustConfigPath();
if (!existsSync(configPath)) {
return false;
}
try {
const configContent = readFileSync(configPath, 'utf-8');
const config = JSON.parse(configContent);
// Check if current directory is in trusted directories
return config.trustedDirectories.includes(projectPath);
}
catch (error) {
// If there's an error reading the config, treat as not trusted
console.warn('Warning: Could not read trust config:', error);
return false;
}
}
export function saveTrustConfig(projectPath) {
try {
const muonDir = getGlobalMuonDir();
const configPath = getTrustConfigPath();
// Create global .muon directory if it doesn't exist
if (!existsSync(muonDir)) {
mkdirSync(muonDir, { recursive: true });
}
let config = {
trustedDirectories: [],
version: CONFIG_VERSION,
};
// Load existing config if it exists
if (existsSync(configPath)) {
try {
const existingContent = readFileSync(configPath, 'utf-8');
config = JSON.parse(existingContent);
}
catch (_error) {
// If existing config is corrupted, start fresh
console.warn('Warning: Existing trust config corrupted, creating new one');
}
}
// Add current directory to trusted list if not already present
if (!config.trustedDirectories.includes(projectPath)) {
config.trustedDirectories.push(projectPath);
}
// Update version
config.version = CONFIG_VERSION;
// Save config
writeFileSync(configPath, JSON.stringify(config, null, 2));
return true;
}
catch (error) {
console.error('Error saving trust config:', error);
return false;
}
}