From 0eeb17342eb31ec53e8df44d725bc6693251d733 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Fri, 1 Aug 2025 16:22:02 -0700 Subject: [PATCH] **chore(archive): remove obsolete scripts and encoded assets** - Removed the following obsolete and unused scripts/assets: - `check-database.js`: Legacy debugging script for database checks, statistics, and example queries, no longer relevant to the current architecture. - `cli-wrapper.js`: Outdated CLI wrapper script, replaced by direct build workflows and updated CLI tools under `dist/`. - `encoded-image.html`: Placeholder file, no longer utilized or referenced in the repository. - **Purpose**: - Streamline the repository by removing outdated and unused assets to enhance maintainability and reduce clutter. - Align the codebase with current workflows and standards. --- check-database.js | 83 --------------- cli-wrapper.js | 85 ---------------- encoded-image.html | 1 - fix-dimension-mismatch.js | 163 ------------------------------ index.html | 17 ---- test-browser-cache-detection.html | 78 -------------- test-worker-cache-detection.html | 130 ------------------------ 7 files changed, 557 deletions(-) delete mode 100644 check-database.js delete mode 100755 cli-wrapper.js delete mode 100644 encoded-image.html delete mode 100644 fix-dimension-mismatch.js delete mode 100644 index.html delete mode 100644 test-browser-cache-detection.html delete mode 100644 test-worker-cache-detection.html diff --git a/check-database.js b/check-database.js deleted file mode 100644 index 14170bee..00000000 --- a/check-database.js +++ /dev/null @@ -1,83 +0,0 @@ -// Script to check if there's any data in the database -import { BrainyData } from './dist/brainyData.js'; - -async function checkDatabase() { - try { - console.log('Initializing BrainyData...'); - const db = new BrainyData(); - await db.init(); - - console.log('Getting database status...'); - const status = await db.status(); - console.log('Database status:', JSON.stringify(status, null, 2)); - - console.log('Getting statistics...'); - const stats = await db.getStatistics(); - console.log('Statistics:', JSON.stringify(stats, null, 2)); - - console.log('Getting all nouns...'); - const nouns = await db.getAllNouns(); - console.log(`Found ${nouns.length} nouns in the database.`); - - if (nouns.length > 0) { - console.log('Sample of nouns:'); - for (let i = 0; i < Math.min(5, nouns.length); i++) { - console.log(`Noun ${i + 1}:`, JSON.stringify(nouns[i], null, 2)); - } - } - - console.log('Getting all verbs...'); - const verbs = await db.getAllVerbs(); - console.log(`Found ${verbs.length} verbs in the database.`); - - if (verbs.length > 0) { - console.log('Sample of verbs:'); - for (let i = 0; i < Math.min(5, verbs.length); i++) { - console.log(`Verb ${i + 1}:`, JSON.stringify(verbs[i], null, 2)); - } - } - - // Try a simple search to see if it returns any results - console.log('Trying a simple search...'); - const searchResults = await db.searchText('test', 10); - console.log(`Search returned ${searchResults.length} results.`); - - if (searchResults.length > 0) { - console.log('Sample of search results:'); - for (let i = 0; i < Math.min(5, searchResults.length); i++) { - console.log(`Result ${i + 1}:`, JSON.stringify({ - id: searchResults[i].id, - score: searchResults[i].score, - metadata: searchResults[i].metadata - }, null, 2)); - } - } - - // If no results, try adding a test item and searching again - if (searchResults.length === 0 && nouns.length === 0) { - console.log('No data found. Adding a test item...'); - const id = await db.add('This is a test item for searching', { noun: 'Thing', category: 'test' }); - console.log(`Added test item with ID: ${id}`); - - console.log('Trying search again...'); - const newSearchResults = await db.searchText('test', 10); - console.log(`Search returned ${newSearchResults.length} results.`); - - if (newSearchResults.length > 0) { - console.log('Sample of search results:'); - for (let i = 0; i < Math.min(5, newSearchResults.length); i++) { - console.log(`Result ${i + 1}:`, JSON.stringify({ - id: newSearchResults[i].id, - score: newSearchResults[i].score, - metadata: newSearchResults[i].metadata - }, null, 2)); - } - } - } - - } catch (error) { - console.error('Error checking database:', error); - } -} - -checkDatabase().catch(console.error); \ No newline at end of file diff --git a/cli-wrapper.js b/cli-wrapper.js deleted file mode 100755 index 648d64e9..00000000 --- a/cli-wrapper.js +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env node - -/** - * CLI Wrapper Script - * - * This script serves as a wrapper for the Brainy CLI, ensuring that command-line arguments - * are properly passed to the CLI when invoked through npm scripts. - */ - -import { spawn, execSync } from 'child_process' -import { fileURLToPath } from 'url' -import { dirname, join } from 'path' -import fs from 'fs' - - -// Get the directory of the current module -const __filename = fileURLToPath(import.meta.url) -const __dirname = dirname(__filename) - -// Path to the actual CLI script -const cliPath = join(__dirname, 'dist', 'cli.js') - -// Check if the CLI script exists -if (!fs.existsSync(cliPath)) { - // Check if we're running in a global installation context - const isGlobalInstall = __dirname.includes('node_modules') && !__dirname.includes('node_modules/.') - - if (isGlobalInstall) { - console.error(`Error: CLI script not found at ${cliPath}`) - console.error('This is likely because the CLI was not built during package installation.') - console.error('Please reinstall the package with:') - console.error('npm uninstall -g @soulcraft/brainy') - console.error('npm install -g @soulcraft/brainy --legacy-peer-deps') - process.exit(1) - } else { - // In a local development context, try to build the CLI - console.log(`CLI script not found at ${cliPath}. Building CLI...`) - - try { - // Run the build:cli script - execSync('npm run build:cli', { stdio: 'inherit' }) - - // Check again if the CLI script exists after building - if (!fs.existsSync(cliPath)) { - console.error(`Error: Failed to build CLI script at ${cliPath}`) - process.exit(1) - } - - console.log('CLI built successfully.') - } catch (error) { - console.error(`Error building CLI: ${error.message}`) - console.error('Make sure you have the necessary dependencies installed.') - process.exit(1) - } - } -} - -// Special handling for version flags -if (process.argv.includes('--version') || process.argv.includes('-V')) { - // Read version directly from package.json to ensure it's always correct - try { - const packageJsonPath = join(__dirname, 'package.json') - const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) - console.log(packageJson.version) - process.exit(0) - } catch (error) { - console.error('Error loading version information:', error.message) - process.exit(1) - } -} - -// Forward all arguments to the CLI script -const args = process.argv.slice(2) - -// Check if npm is passing --force flag -// When npm runs with --force, it sets the npm_config_force environment variable -if (process.env.npm_config_force === 'true' && args.includes('clear') && !args.includes('--force') && !args.includes('-f')) { - args.push('--force') -} - -const cli = spawn('node', [cliPath, ...args], { stdio: 'inherit' }) - -cli.on('close', (code) => { - process.exit(code) -}) diff --git a/encoded-image.html b/encoded-image.html deleted file mode 100644 index cfc1a5e2..00000000 --- a/encoded-image.html +++ /dev/null @@ -1 +0,0 @@ -Brainy Logo \ No newline at end of file diff --git a/fix-dimension-mismatch.js b/fix-dimension-mismatch.js deleted file mode 100644 index f19d997e..00000000 --- a/fix-dimension-mismatch.js +++ /dev/null @@ -1,163 +0,0 @@ -// Script to fix dimension mismatch by re-embedding existing data -import { BrainyData } from './dist/brainyData.js'; -import fs from 'fs'; -import path from 'path'; - -async function fixDimensionMismatch() { - try { - console.log('Starting dimension mismatch fix...'); - - // Create a backup of the existing data - const backupDir = './brainy-data-backup-' + Date.now(); - console.log(`Creating backup of existing data in ${backupDir}...`); - - // Copy the entire brainy-data directory to the backup directory - await fs.promises.mkdir(backupDir, { recursive: true }); - await copyDirectory('./brainy-data', backupDir); - console.log('Backup created successfully.'); - - // Initialize BrainyData with the current embedding function - console.log('Initializing BrainyData...'); - const db = new BrainyData(); - await db.init(); - - // Get database status to check if there's any data - const status = await db.status(); - console.log('Database status:', JSON.stringify(status, null, 2)); - - // Read all noun files directly from the filesystem - console.log('Reading noun files directly from filesystem...'); - const nounsDir = './brainy-data/nouns'; - const files = await fs.promises.readdir(nounsDir); - - // Process each noun file - const processedNouns = []; - for (const file of files) { - if (file.endsWith('.json')) { - const filePath = path.join(nounsDir, file); - const data = await fs.promises.readFile(filePath, 'utf-8'); - const parsedNoun = JSON.parse(data); - - // Get the metadata for this noun - const metadataPath = path.join('./brainy-data/metadata', `${parsedNoun.id}.json`); - let metadata = {}; - try { - const metadataData = await fs.promises.readFile(metadataPath, 'utf-8'); - metadata = JSON.parse(metadataData); - } catch (error) { - console.warn(`No metadata found for noun ${parsedNoun.id}`); - } - - // Extract text from metadata if available - let text = ''; - if (metadata.text) { - text = metadata.text; - } else if (metadata.description) { - text = metadata.description; - } else { - // If no text is available, use a placeholder - text = `Noun ${parsedNoun.id}`; - console.warn(`No text found for noun ${parsedNoun.id}, using placeholder`); - } - - // Re-embed the text using the current embedding function - console.log(`Re-embedding noun ${parsedNoun.id}...`); - try { - // Delete the existing noun first - await db.delete(parsedNoun.id); - - // Add the noun with the same ID but new vector - const newId = await db.add(text, metadata, { id: parsedNoun.id }); - processedNouns.push({ id: newId, originalId: parsedNoun.id }); - console.log(`Successfully re-embedded noun ${parsedNoun.id}`); - } catch (error) { - console.error(`Error re-embedding noun ${parsedNoun.id}:`, error); - } - } - } - - console.log(`Processed ${processedNouns.length} nouns.`); - - // Recreate verbs - console.log('Reading verb files directly from filesystem...'); - const verbsDir = './brainy-data/verbs'; - const verbFiles = await fs.promises.readdir(verbsDir); - - // Process each verb file - const processedVerbs = []; - for (const file of verbFiles) { - if (file.endsWith('.json')) { - const filePath = path.join(verbsDir, file); - const data = await fs.promises.readFile(filePath, 'utf-8'); - const parsedVerb = JSON.parse(data); - - // Check if both source and target nouns exist - const sourceExists = processedNouns.some(n => n.originalId === parsedVerb.sourceId); - const targetExists = processedNouns.some(n => n.originalId === parsedVerb.targetId); - - if (sourceExists && targetExists) { - console.log(`Re-creating verb ${parsedVerb.id} between ${parsedVerb.sourceId} and ${parsedVerb.targetId}...`); - try { - // Delete the existing verb first - await db.deleteVerb(parsedVerb.id); - - // Add the verb with the same relationship - await db.addVerb(parsedVerb.sourceId, parsedVerb.targetId, { - verb: parsedVerb.type || 'RelatedTo', - ...parsedVerb.metadata - }); - - processedVerbs.push(parsedVerb.id); - console.log(`Successfully re-created verb ${parsedVerb.id}`); - } catch (error) { - console.error(`Error re-creating verb ${parsedVerb.id}:`, error); - } - } else { - console.warn(`Skipping verb ${parsedVerb.id} because source or target noun doesn't exist`); - } - } - } - - console.log(`Processed ${processedVerbs.length} verbs.`); - - // Try a search to verify it works - console.log('Trying a search to verify it works...'); - const searchResults = await db.searchText('test', 10); - console.log(`Search returned ${searchResults.length} results.`); - - if (searchResults.length > 0) { - console.log('Sample of search results:'); - for (let i = 0; i < Math.min(5, searchResults.length); i++) { - console.log(`Result ${i + 1}:`, JSON.stringify({ - id: searchResults[i].id, - score: searchResults[i].score, - metadata: searchResults[i].metadata - }, null, 2)); - } - } - - console.log('Dimension mismatch fix completed successfully.'); - } catch (error) { - console.error('Error fixing dimension mismatch:', error); - } -} - -// Helper function to copy a directory recursively -async function copyDirectory(source, destination) { - const entries = await fs.promises.readdir(source, { withFileTypes: true }); - - await fs.promises.mkdir(destination, { recursive: true }); - - for (const entry of entries) { - const srcPath = path.join(source, entry.name); - const destPath = path.join(destination, entry.name); - - if (entry.isDirectory()) { - await copyDirectory(srcPath, destPath); - } else { - await fs.promises.copyFile(srcPath, destPath); - } - } -} - -fixDimensionMismatch().catch(console.error); \ No newline at end of file diff --git a/index.html b/index.html deleted file mode 100644 index 1018e443..00000000 --- a/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - Brainy Interactive Demo - Redirecting... - - - - - -

Redirecting to Brainy Interactive Demo...

-

If you are not redirected automatically, please click the link above.

- - diff --git a/test-browser-cache-detection.html b/test-browser-cache-detection.html deleted file mode 100644 index f1da7637..00000000 --- a/test-browser-cache-detection.html +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - Brainy Cache Detection Browser Test - - - -

Brainy Cache Detection Browser Test

-

This page tests if Brainy's cache detection works properly in browser environments.

- - - -
-

Test results will appear here...

-
- - - - diff --git a/test-worker-cache-detection.html b/test-worker-cache-detection.html deleted file mode 100644 index a2c66f91..00000000 --- a/test-worker-cache-detection.html +++ /dev/null @@ -1,130 +0,0 @@ - - - - - - Brainy Cache Detection Worker Test - - - -

Brainy Cache Detection Worker Test

-

This page tests if Brainy's cache detection works properly in Web Worker environments.

- - - -
-

Test results will appear here...

-
- - - -