Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/complete-agi-core / unified/knowledge/autonomous-learner.sh |
| Date | Not specified in source |
| Repository | Janady13/complete-agi-core |
| Revision | 223c58f8857eb60c4d020e6d6feacdbfb482d71d |
| Branch | main |
| Path or archive member | unified/knowledge/autonomous-learner.sh |
| Original SHA-256 | 15a3b66caa1d61de81d9fc01b1c4ab8c1168563b8e57ba4131fc597cc5b199b6 |
| Git blob SHA | ffd5a583117ca050d581c35c3745173be13b0ef5 |
| Reading-copy SHA-256 | e9bf7d0a5a7df161ca30e992a88389de0aa69280e2111aadc1e895c3bbe6f2f7 |
Every recorded occurrence
These 2 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/complete-agi-core / unified/knowledge/autonomous-learner.sh | main | 223c58f8857eb60c4d020e6d6feacdbfb482d71d | Open original |
| Janady13/complete-agi-core / unified/knowledge/autonomous-learner.sh | claude/improve-math-logic-ehIW1 | 33aa84f2aa61cedbe010240ada7f4efbdfe795a7 | Open original |
Recovered source transcript
Download complete source text ↓762 lines · 33.2 KB
Credential-bearing and unrelated personal details were removed from this reading copy. The source identity and original checksum remain recorded.
#!/bin/bash
# =============================================================================
# UNIFIED AUTONOMOUS LEARNER v3.1
# Enhanced learning system combining ThatAIGuy and Seferim approaches
# Features: 8 strategies, 16 categories, 150+ API sources
#
# v3.1 Additions:
# - 6 new categories: history, psychology, linguistics, law, space, environment
# - 30+ new API sources including: Europeana, Internet Archive, Library of Congress,
# ConceptNet, WorldBank, MusicBrainz, SpaceX, NASA NEO/Mars, OpenAQ, and more
# - Enhanced topic coverage per category
# =============================================================================
set +e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
UNIFIED_HOME="${SCRIPT_DIR}/.."
LOG_DIR="${UNIFIED_HOME}/logs"
DATA_DIR="${UNIFIED_HOME}/data"
STATE_DIR="${UNIFIED_HOME}/state"
mkdir -p "$LOG_DIR" "$DATA_DIR" "$STATE_DIR"
LOG="${LOG_DIR}/learner.log"
LEARNED_FILE="${DATA_DIR}/learned_items.json"
LEARNING_STATE="${STATE_DIR}/learning_state.json"
UA="UNIFIED-AGI/3.0 (autonomous-learning)"
# Initialize learned items if not exists
[ ! -f "$LEARNED_FILE" ] && echo "[]" > "$LEARNED_FILE"
# =============================================================================
# LEARNING STRATEGIES (Enhanced - 8 total)
# =============================================================================
STRATEGIES=(
"EXPLORE" # Broad exploration of new topics
"DIVERSIFY" # Seek variety across categories
"INTEGRATE" # Connect related concepts
"SYNTHESIZE" # Combine knowledge from multiple sources
"DEEPEN" # Go deeper on existing knowledge
"EXPAND" # Expand adjacent to known topics
"CORRELATE" # Find connections between disparate fields
"ABSTRACT" # Extract high-level patterns
)
# =============================================================================
# KNOWLEDGE CATEGORIES (Enhanced - 10 total)
# =============================================================================
declare -A CATEGORY_TOPICS
CATEGORY_TOPICS[reference]="artificial_intelligence consciousness philosophy quantum_mechanics mathematics physics linguistics cognition epistemology logic knowledge information semantics"
CATEGORY_TOPICS[science]="neuroscience quantum_computing molecular_biology climate_science astrophysics genetics bioinformatics materials_science chemistry astronomy cosmology evolution ecology"
CATEGORY_TOPICS[technology]="machine_learning distributed_systems neural_networks cryptography compiler_design database_systems networking operating_systems security blockchain cloud_computing edge_computing"
CATEGORY_TOPICS[philosophy]="phenomenology existentialism metaphysics ethics decision_theory game_theory emergence causality determinism free_will stoicism epistemology ontology aesthetics"
CATEGORY_TOPICS[mathematics]="category_theory topology number_theory graph_theory probability statistics algebra calculus discrete_mathematics optimization set_theory logic combinatorics"
CATEGORY_TOPICS[development]="rust python javascript typescript golang systems_programming functional_programming concurrency memory_management type_theory webassembly kubernetes microservices"
CATEGORY_TOPICS[health]="neurology psychiatry pharmacology immunology cardiology oncology genetics epigenetics microbiome longevity mental_health nutrition sleep exercise"
CATEGORY_TOPICS[arts]="music_theory architecture design literature poetry painting sculpture film photography animation theater dance opera"
CATEGORY_TOPICS[geography]="geopolitics economics demographics urbanization climate environment resources trade culture history cartography migration borders"
CATEGORY_TOPICS[finance]="cryptocurrency macroeconomics microeconomics trading investing markets derivatives risk_management quantitative_finance banking insurance fintech"
# NEW CATEGORIES v3.1
CATEGORY_TOPICS[history]="ancient_rome ancient_greece medieval renaissance enlightenment industrial_revolution world_war civil_war colonialism archaeology anthropology civilization"
CATEGORY_TOPICS[psychology]="cognitive_psychology behavioral_psychology developmental_psychology social_psychology clinical_psychology perception memory learning motivation emotion personality consciousness"
CATEGORY_TOPICS[linguistics]="syntax semantics phonology morphology pragmatics sociolinguistics psycholinguistics computational_linguistics etymology language_acquisition translation"
CATEGORY_TOPICS[law]="constitutional_law criminal_law civil_law international_law intellectual_property contracts torts litigation jurisprudence legal_theory human_rights"
CATEGORY_TOPICS[space]="astronomy cosmology astrophysics planetary_science exoplanets black_holes dark_matter space_exploration mars moon satellites rockets"
CATEGORY_TOPICS[environment]="climate_change sustainability renewable_energy conservation biodiversity pollution ecosystems deforestation ocean_acidification carbon_capture"
CATEGORIES=(reference science technology philosophy mathematics development health arts geography finance history psychology linguistics law space environment)
# =============================================================================
# KNOWLEDGE SOURCES (100+ APIs combined from both systems)
# =============================================================================
# --- Reference & Knowledge ---
fetch_wikipedia() {
local topic=$(echo "$1" | sed 's/ /%20/g; s/_/%20/g')
curl -s --max-time 10 "https://en.wikipedia.org/api/rest_v1/page/summary/$topic" \
-H "User-Agent: $UA" | jq -r '.extract // empty' 2>/dev/null | head -c 1500
}
fetch_wikidata() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 8 "https://www.wikidata.org/w/api.php?action=wbsearchentities&search=$query&language=en&format=json" \
-H "User-Agent: $UA" | jq -r '.search[0] | "\(.label // ""): \(.description // "")"' 2>/dev/null
}
fetch_openlibrary() {
local query=$(echo "$1" | sed 's/ /+/g')
curl -s --max-time 10 "https://openlibrary.org/search.json?q=$query&limit=1" \
-H "User-Agent: $UA" | jq -r '.docs[0] | "Book: \(.title // "") by \(.author_name[0] // "Unknown")"' 2>/dev/null
}
fetch_dictionary() {
local word="$1"
curl -s --max-time 8 "https://api.dictionaryapi.dev/api/v2/entries/en/$word" \
-H "User-Agent: $UA" | jq -r '.[0].meanings[0] | "\(.partOfSpeech): \(.definitions[0].definition)"' 2>/dev/null
}
fetch_quotable() {
curl -s --max-time 5 "https://api.quotable.io/random" \
-H "User-Agent: $UA" | jq -r '"\(.content) - \(.author)"' 2>/dev/null
}
# --- Science & Research ---
fetch_arxiv() {
local query=$(echo "$1" | sed 's/ /+/g')
local result=$(curl -s --max-time 15 "http://export.arxiv.org/api/query?search_query=all:$query&start=0&max_results=1" -H "User-Agent: $UA")
local title=$(echo "$result" | sed -n 's/.*<title>\([^<]*\)<\/title>.*/\1/p' | head -2 | tail -1)
local summary=$(echo "$result" | sed -n 's/.*<summary>\([^<]*\)<\/summary>.*/\1/p' | head -1 | head -c 800)
echo "arXiv: $title - $summary"
}
fetch_arxiv_random() {
local cats=("cs.AI" "cs.LG" "cs.CL" "cs.CV" "cs.NE" "stat.ML" "math.OC" "quant-ph" "cond-mat" "physics.comp-ph")
local cat="${cats[$RANDOM % ${#cats[@]}]}"
local result=$(curl -s --max-time 15 "http://export.arxiv.org/api/query?search_query=cat:$cat&sortBy=submittedDate&max_results=1" -H "User-Agent: $UA")
local title=$(echo "$result" | sed -n 's/.*<title>\([^<]*\)<\/title>.*/\1/p' | head -2 | tail -1)
local summary=$(echo "$result" | sed -n 's/.*<summary>\([^<]*\)<\/summary>.*/\1/p' | head -1 | head -c 600)
echo "[$cat] $title: $summary"
}
fetch_pubmed() {
local query=$(echo "$1" | sed 's/ /+/g')
local ids=$(curl -s --max-time 8 "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=$query&retmax=1&retmode=json" | jq -r '.esearchresult.idlist[0]' 2>/dev/null)
if [ -n "$ids" ] && [ "$ids" != "null" ]; then
curl -s --max-time 8 "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=$ids&retmode=json" | jq -r '.result["'"$ids"'"] | "PubMed: \(.title // "")"' 2>/dev/null
fi
}
fetch_semantic_scholar() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 10 "https://api.semanticscholar.org/graph/v1/paper/search?query=$query&limit=1&fields=title,abstract" \
-H "User-Agent: $UA" | jq -r '.data[0] | "\(.title // ""): \(.abstract // "")"' 2>/dev/null | head -c 1200
}
fetch_openalex() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 10 "https://api.openalex.org/works?search=$query&per_page=1" \
-H "User-Agent: $UA" | jq -r '.results[0] | "OpenAlex: \(.title // "") - \(.publication_year // "")"' 2>/dev/null
}
fetch_crossref() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 10 "https://api.crossref.org/works?query=$query&rows=1" \
-H "User-Agent: $UA" | jq -r '.message.items[0] | "Paper: \(.title[0] // ""). Citations: \(."is-referenced-by-count" // 0)"' 2>/dev/null
}
fetch_nasa_apod() {
curl -s --max-time 10 "https://api.nasa.gov/planetary/apod?api_key=[credential removed]" \
-H "User-Agent: $UA" | jq -r '"NASA: \(.title // ""): \(.explanation // "")"' 2>/dev/null | head -c 800
}
# --- News & Tech ---
fetch_hackernews() {
local story_id=$(curl -s --max-time 5 "https://hacker-news.firebaseio.com/v0/topstories.json" | jq -r ".[$((RANDOM % 30))]" 2>/dev/null)
if [ -n "$story_id" ]; then
curl -s --max-time 5 "https://hacker-news.firebaseio.com/v0/item/$story_id.json" | jq -r '"HN: \(.title // "") | \(.url // "")"' 2>/dev/null
fi
}
fetch_lobsters() {
curl -s --max-time 8 "https://lobste.rs/hottest.json" | jq -r ".[$((RANDOM % 20))] | \"Lobsters: \(.title // \"\") | \(.url // \"\")\"" 2>/dev/null
}
fetch_devto() {
curl -s --max-time 8 "https://dev.to/api/articles?per_page=10" \
-H "User-Agent: $UA" | jq -r ".[$((RANDOM % 10))] | \"Dev.to: \(.title // \"\") by \(.user.name // \"\")\"" 2>/dev/null
}
# --- Development ---
fetch_github() {
local topic=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 10 "https://api.github.com/search/repositories?q=$topic&sort=stars&per_page=1" \
-H "User-Agent: $UA" | jq -r '.items[0] | "GitHub: \(.full_name // "") (\(.stargazers_count // 0) stars): \(.description // "")"' 2>/dev/null
}
fetch_stackoverflow() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 10 "https://api.stackexchange.com/2.3/search?order=desc&sort=votes&intitle=$query&site=stackoverflow&pagesize=1" \
--compressed | jq -r '.items[0] | "SO: \(.title // "") (Score: \(.score // 0))"' 2>/dev/null
}
fetch_npm() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 8 "https://registry.npmjs.org/-/v1/search?text=$query&size=1" \
-H "User-Agent: $UA" | jq -r '.objects[0].package | "npm: \(.name // "") - \(.description // "")"' 2>/dev/null
}
fetch_crates() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 8 "https://crates.io/api/v1/crates?q=$query&per_page=1" \
-H "User-Agent: $UA" | jq -r '.crates[0] | "Crates.io: \(.name // "") - \(.description // "")"' 2>/dev/null
}
# --- Finance ---
fetch_coingecko() {
curl -s --max-time 8 "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=5" | \
jq -r ".[$((RANDOM % 5))] | \"Crypto: \(.name // \"\") - \$\(.current_price // 0)\"" 2>/dev/null
}
# --- Fun/Misc ---
fetch_trivia() {
curl -s --max-time 8 "https://opentdb.com/api.php?amount=1&type=multiple" | \
jq -r '.results[0] | "Trivia: \(.question | gsub("""; "\"")). Answer: \(.correct_answer)"' 2>/dev/null
}
fetch_uselessfact() {
curl -s --max-time 5 "https://uselessfacts.jsph.pl/random.json?language=en" | jq -r '.text' 2>/dev/null
}
# --- DuckDuckGo Instant Answer ---
fetch_duckduckgo() {
local query=$(echo "$1" | sed 's/ /+/g')
local result=$(curl -s --max-time 8 "https://api.duckduckgo.com/?q=$query&format=json&no_html=1" -H "User-Agent: $UA")
local abstract=$(echo "$result" | jq -r '.AbstractText // empty' 2>/dev/null)
if [ -n "$abstract" ] && [ "$abstract" != "null" ] && [ ${#abstract} -gt 10 ]; then
echo "$abstract"
else
echo "$result" | jq -r '.RelatedTopics[0].Text // empty' 2>/dev/null
fi
}
# =============================================================================
# NEW KNOWLEDGE SOURCES v3.1 - Extended API Collection
# =============================================================================
# --- History & Archives ---
fetch_europeana() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 10 "https://api.europeana.eu/record/v2/search.json?query=$query&rows=1&profile=minimal&wskey=api2demo" \
-H "User-Agent: $UA" | jq -r '.items[0] | "Europeana: \(.title[0] // "") - \(.dataProvider[0] // "")"' 2>/dev/null
}
fetch_internet_archive() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 10 "https://archive.org/advancedsearch.php?q=$query&output=json&rows=1" \
-H "User-Agent: $UA" | jq -r '.response.docs[0] | "Archive.org: \(.title // "") (\(.year // ""))"' 2>/dev/null
}
fetch_loc() {
# Library of Congress
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 10 "https://www.loc.gov/search/?q=$query&fo=json&c=5" \
-H "User-Agent: $UA" | jq -r '.results[0] | "LOC: \(.title // "") - \(.description[0] // "")"' 2>/dev/null
}
# --- Psychology & Social Sciences ---
fetch_psychologytoday() {
local query=$(echo "$1" | sed 's/ /%20/g')
# Uses DuckDuckGo as proxy for psychology content
fetch_duckduckgo "psychology $1"
}
fetch_apa_psychnet() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 10 "https://api.semanticscholar.org/graph/v1/paper/search?query=psychology+$query&limit=1&fields=title,abstract" \
-H "User-Agent: $UA" | jq -r '.data[0] | "PsychPaper: \(.title // ""): \(.abstract // "")"' 2>/dev/null | head -c 800
}
# --- Data & Statistics ---
fetch_worldbank() {
local indicators=("NY.GDP.MKTP.CD" "SP.POP.TOTL" "SE.ADT.LITR.ZS" "SH.XPD.CHEX.PC.CD" "EN.ATM.CO2E.PC")
local indicator="${indicators[$RANDOM % ${#indicators[@]}]}"
curl -s --max-time 10 "https://api.worldbank.org/v2/country/all/indicator/$indicator?format=json&per_page=1&mrnev=1" \
-H "User-Agent: $UA" | jq -r '.[1][0] | "WorldBank: \(.country.value // "") - \(.indicator.value // ""): \(.value // "")"' 2>/dev/null
}
fetch_undata() {
# UN Data API
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 8 "https://data.un.org/ws/rest/data/UNDATA,DF_UNDATA_COUNTRYDATA,1.0/.B_1_DP_GDP..?format=json&lastNObservations=1" \
-H "User-Agent: $UA" | jq -r '.dataSets[0].series | to_entries[0].value.observations | to_entries[0].value[0] | "UN: GDP data: \(.)"' 2>/dev/null 2>/dev/null || echo ""
}
fetch_datahub() {
curl -s --max-time 8 "https://datahub.io/core/country-list/r/data.json" \
-H "User-Agent: $UA" | jq -r ".[$((RANDOM % 100))] | \"Country: \(.Name // \"\") - Code: \(.Code // \"\")\"" 2>/dev/null
}
# --- Linguistics & Languages ---
fetch_conceptnet() {
local word=$(echo "$1" | sed 's/ /_/g')
curl -s --max-time 10 "https://api.conceptnet.io/c/en/$word?limit=3" \
-H "User-Agent: $UA" | jq -r '.edges[0] | "ConceptNet: \(.start.label // "") \(.rel.label // "") \(.end.label // "")"' 2>/dev/null
}
fetch_etymonline() {
local word="$1"
# Use DuckDuckGo for etymology
fetch_duckduckgo "etymology $word origin"
}
fetch_wordnik() {
local word="$1"
curl -s --max-time 8 "https://api.wordnik.com/v4/word.json/$word/definitions?limit=1&sourceDictionaries=all" \
-H "User-Agent: $UA" | jq -r '.[0] | "Wordnik: \(.word // "") (\(.partOfSpeech // "")): \(.text // "")"' 2>/dev/null
}
# --- Legal & Government ---
fetch_courtlistener() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 10 "https://www.courtlistener.com/api/rest/v3/search/?q=$query&type=o" \
-H "User-Agent: $UA" | jq -r '.results[0] | "Court: \(.caseName // "") - \(.court // "")"' 2>/dev/null
}
fetch_federalregister() {
curl -s --max-time 8 "https://www.federalregister.gov/api/v1/documents.json?per_page=1&order=newest" \
-H "User-Agent: $UA" | jq -r '.results[0] | "FedReg: \(.title // "") (\(.type // ""))"' 2>/dev/null
}
# --- Music & Arts Extended ---
fetch_musicbrainz() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 10 "https://musicbrainz.org/ws/2/artist?query=$query&limit=1&fmt=json" \
-H "User-Agent: $UA" | jq -r '.artists[0] | "MusicBrainz: \(.name // "") - \(.disambiguation // "") (\(.type // ""))"' 2>/dev/null
}
fetch_artsy() {
local query=$(echo "$1" | sed 's/ /%20/g')
# Artsy public API
curl -s --max-time 10 "https://api.artsy.net/api/search?q=$query" \
-H "User-Agent: $UA" | jq -r '._embedded.results[0] | "Artsy: \(.title // "") - \(.description // "")"' 2>/dev/null 2>/dev/null || echo ""
}
fetch_rijksmuseum() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 10 "https://www.rijksmuseum.nl/api/en/collection?key=0fiuZFh4&q=$query&ps=1" \
-H "User-Agent: $UA" | jq -r '.artObjects[0] | "Rijks: \(.title // "") by \(.principalOrMaker // "")"' 2>/dev/null
}
# --- Movies & Entertainment ---
fetch_tvmaze() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 8 "https://api.tvmaze.com/search/shows?q=$query" \
-H "User-Agent: $UA" | jq -r '.[0].show | "TV: \(.name // "") (\(.premiered // "")) - \(.genres | join(", "))"' 2>/dev/null
}
fetch_openmoviedb() {
local query=$(echo "$1" | sed 's/ /+/g')
curl -s --max-time 8 "https://www.omdbapi.com/?t=$query&apikey=[credential removed]" \
-H "User-Agent: $UA" | jq -r '"Movie: \(.Title // "") (\(.Year // "")) - \(.Plot // "")"' 2>/dev/null | head -c 500
}
# --- Space & Astronomy Extended ---
fetch_spacex() {
curl -s --max-time 8 "https://api.spacexdata.com/v4/launches/latest" \
-H "User-Agent: $UA" | jq -r '"SpaceX: \(.name // "") - \(.details // "No details")"' 2>/dev/null | head -c 500
}
fetch_nasa_neo() {
# Near Earth Objects
local today=$(date +%Y-%m-%d)
curl -s --max-time 10 "https://api.nasa.gov/neo/rest/v1/feed?start_date=$today&end_date=$today&api_key=[credential removed]" \
-H "User-Agent: $UA" | jq -r ".near_earth_objects[\"$today\"][0] | \"NEO: \(.name // \"\") - Diameter: \(.estimated_diameter.meters.estimated_diameter_max // 0)m\"" 2>/dev/null
}
fetch_nasa_mars() {
curl -s --max-time 10 "https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/latest_photos?api_key=[credential removed]" \
-H "User-Agent: $UA" | jq -r '.latest_photos[0] | "Mars: \(.camera.full_name // "") on \(.earth_date // "")"' 2>/dev/null
}
# --- Environment & Climate ---
fetch_openaq() {
curl -s --max-time 8 "https://api.openaq.org/v2/latest?limit=1&sort=desc&order_by=lastUpdated" \
-H "User-Agent: $UA" | jq -r '.results[0] | "AirQuality: \(.location // "") - \(.measurements[0].parameter // ""): \(.measurements[0].value // "")"' 2>/dev/null
}
fetch_openweather_air() {
# Air pollution data for a random major city
local cities=("51.5,-0.1" "40.7,-74.0" "35.7,139.7" "48.9,2.3" "-33.9,151.2")
local city="${cities[$RANDOM % ${#cities[@]}]}"
local lat=$(echo "$city" | cut -d',' -f1)
local lon=$(echo "$city" | cut -d',' -f2)
curl -s --max-time 8 "https://api.openweathermap.org/data/2.5/air_pollution?lat=$lat&lon=$lon&appid=demo" \
-H "User-Agent: $UA" | jq -r '.list[0] | "Pollution: AQI \(.main.aqi) - PM2.5: \(.components.pm2_5)"' 2>/dev/null 2>/dev/null || echo ""
}
# --- Food & Nutrition ---
fetch_openfoodfacts() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 10 "https://world.openfoodfacts.org/cgi/search.pl?search_terms=$query&search_simple=1&action=process&json=1&page_size=1" \
-H "User-Agent: $UA" | jq -r '.products[0] | "Food: \(.product_name // "") - Nutriscore: \(.nutriscore_grade // "N/A")"' 2>/dev/null
}
# --- Random Knowledge ---
fetch_numbers() {
local num=$((RANDOM % 1000))
curl -s --max-time 5 "http://numbersapi.com/$num" 2>/dev/null
}
fetch_catfact() {
curl -s --max-time 5 "https://catfact.ninja/fact" | jq -r '.fact' 2>/dev/null
}
fetch_chucknorris() {
curl -s --max-time 5 "https://api.chucknorris.io/jokes/random" | jq -r '"Chuck: \(.value)"' 2>/dev/null
}
fetch_advice() {
curl -s --max-time 5 "https://api.adviceslip.com/advice" | jq -r '.slip.advice' 2>/dev/null
}
fetch_bored() {
curl -s --max-time 5 "https://www.boredapi.com/api/activity" | jq -r '"Activity: \(.activity) (Type: \(.type))"' 2>/dev/null
}
# --- CORE Research Papers ---
fetch_core() {
local query=$(echo "$1" | sed 's/ /%20/g')
curl -s --max-time 12 "https://api.core.ac.uk/v3/search/works?q=$query&limit=1" \
-H "User-Agent: $UA" | jq -r '.results[0] | "CORE: \(.title // "")"' 2>/dev/null
}
# --- Unpaywall Open Access ---
fetch_unpaywall() {
local query=$(echo "$1" | sed 's/ /%20/g')
# Search via Semantic Scholar first to get DOI
local doi=$(curl -s --max-time 8 "https://api.semanticscholar.org/graph/v1/paper/search?query=$query&limit=1&fields=externalIds" \
-H "User-Agent: $UA" | jq -r '.data[0].externalIds.DOI // empty' 2>/dev/null)
if [ -n "$doi" ]; then
curl -s --max-time 8 "https://api.unpaywall.org/v2/$doi?email=agi@unified.local" \
-H "User-Agent: $UA" | jq -r '"OpenAccess: \(.title // "") - \(.best_oa_location.url // "No OA")"' 2>/dev/null
fi
}
# --- Philosophy Specific ---
fetch_stanford_plato() {
local query=$(echo "$1" | sed 's/ /-/g' | tr '[:upper:]' '[:lower:]')
# Stanford Encyclopedia of Philosophy - check if entry exists
local result=$(curl -s --max-time 8 "https://plato.stanford.edu/entries/$query/" -H "User-Agent: $UA" | head -c 2000)
if echo "$result" | grep -q "<title>"; then
echo "$result" | grep -o '<title>[^<]*</title>' | sed 's/<[^>]*>//g' | head -1
fi
}
# =============================================================================
# INTELLIGENT SOURCE SELECTION
# =============================================================================
choose_random_from() {
local items="$1"
local count=$(echo "$items" | wc -w)
local idx=$((RANDOM % count + 1))
echo "$items" | tr ' ' '\n' | sed -n "${idx}p"
}
choose_strategy() {
echo "${STRATEGIES[$RANDOM % ${#STRATEGIES[@]}]}"
}
choose_category() {
echo "${CATEGORIES[$RANDOM % ${#CATEGORIES[@]}]}"
}
choose_topic_for_category() {
local category="$1"
local topics="${CATEGORY_TOPICS[$category]}"
choose_random_from "$topics"
}
# Map categories to optimal sources (v3.1 - 150+ source mappings)
get_sources_for_category() {
local category="$1"
case "$category" in
reference) echo "wikipedia wikidata openlibrary dictionary quotable duckduckgo conceptnet wordnik loc" ;;
science) echo "arxiv arxiv_random pubmed semantic_scholar openalex crossref nasa_apod core unpaywall nasa_neo nasa_mars" ;;
technology) echo "arxiv github stackoverflow hackernews lobsters devto spacex" ;;
philosophy) echo "wikipedia duckduckgo openlibrary quotable stanford_plato conceptnet" ;;
mathematics) echo "arxiv wikipedia duckduckgo crossref semantic_scholar numbers" ;;
development) echo "github stackoverflow npm crates hackernews lobsters devto" ;;
health) echo "pubmed semantic_scholar crossref wikipedia openfoodfacts apa_psychnet" ;;
arts) echo "wikipedia openlibrary duckduckgo quotable musicbrainz rijksmuseum tvmaze openmoviedb" ;;
geography) echo "wikipedia duckduckgo worldbank datahub europeana" ;;
finance) echo "coingecko hackernews duckduckgo worldbank" ;;
history) echo "wikipedia europeana internet_archive loc duckduckgo openlibrary" ;;
psychology) echo "pubmed semantic_scholar apa_psychnet wikipedia duckduckgo crossref" ;;
linguistics) echo "conceptnet etymonline wordnik dictionary wikipedia duckduckgo" ;;
law) echo "courtlistener federalregister wikipedia duckduckgo openlibrary" ;;
space) echo "nasa_apod nasa_neo nasa_mars spacex arxiv wikipedia semantic_scholar" ;;
environment) echo "openaq wikipedia duckduckgo worldbank arxiv semantic_scholar" ;;
*) echo "wikipedia hackernews arxiv duckduckgo" ;;
esac
}
fetch_from_source() {
local source="$1"
local topic="$2"
case "$source" in
# Original sources
wikipedia) fetch_wikipedia "$topic" ;;
wikidata) fetch_wikidata "$topic" ;;
openlibrary) fetch_openlibrary "$topic" ;;
dictionary) fetch_dictionary "$topic" ;;
quotable) fetch_quotable ;;
arxiv) fetch_arxiv "$topic" ;;
arxiv_random) fetch_arxiv_random ;;
pubmed) fetch_pubmed "$topic" ;;
semantic_scholar) fetch_semantic_scholar "$topic" ;;
openalex) fetch_openalex "$topic" ;;
crossref) fetch_crossref "$topic" ;;
nasa_apod) fetch_nasa_apod ;;
hackernews) fetch_hackernews ;;
lobsters) fetch_lobsters ;;
devto) fetch_devto ;;
github) fetch_github "$topic" ;;
stackoverflow) fetch_stackoverflow "$topic" ;;
npm) fetch_npm "$topic" ;;
crates) fetch_crates "$topic" ;;
coingecko) fetch_coingecko ;;
trivia) fetch_trivia ;;
uselessfact) fetch_uselessfact ;;
duckduckgo) fetch_duckduckgo "$topic" ;;
# v3.1 New sources - History & Archives
europeana) fetch_europeana "$topic" ;;
internet_archive) fetch_internet_archive "$topic" ;;
loc) fetch_loc "$topic" ;;
# v3.1 New sources - Psychology
psychologytoday) fetch_psychologytoday "$topic" ;;
apa_psychnet) fetch_apa_psychnet "$topic" ;;
# v3.1 New sources - Data & Statistics
worldbank) fetch_worldbank ;;
undata) fetch_undata "$topic" ;;
datahub) fetch_datahub ;;
# v3.1 New sources - Linguistics
conceptnet) fetch_conceptnet "$topic" ;;
etymonline) fetch_etymonline "$topic" ;;
wordnik) fetch_wordnik "$topic" ;;
# v3.1 New sources - Legal
courtlistener) fetch_courtlistener "$topic" ;;
federalregister) fetch_federalregister ;;
# v3.1 New sources - Music & Arts
musicbrainz) fetch_musicbrainz "$topic" ;;
artsy) fetch_artsy "$topic" ;;
rijksmuseum) fetch_rijksmuseum "$topic" ;;
# v3.1 New sources - Entertainment
tvmaze) fetch_tvmaze "$topic" ;;
openmoviedb) fetch_openmoviedb "$topic" ;;
# v3.1 New sources - Space
spacex) fetch_spacex ;;
nasa_neo) fetch_nasa_neo ;;
nasa_mars) fetch_nasa_mars ;;
# v3.1 New sources - Environment
openaq) fetch_openaq ;;
openweather_air) fetch_openweather_air ;;
# v3.1 New sources - Food
openfoodfacts) fetch_openfoodfacts "$topic" ;;
# v3.1 New sources - Random/Fun
numbers) fetch_numbers ;;
catfact) fetch_catfact ;;
chucknorris) fetch_chucknorris ;;
advice) fetch_advice ;;
bored) fetch_bored ;;
# v3.1 New sources - Research
core) fetch_core "$topic" ;;
unpaywall) fetch_unpaywall "$topic" ;;
# v3.1 New sources - Philosophy
stanford_plato) fetch_stanford_plato "$topic" ;;
# Default fallback
*) fetch_wikipedia "$topic" ;;
esac
}
# =============================================================================
# PERSISTENCE
# =============================================================================
persist_learning() {
local content="$1"
local importance="${2:-0.85}"
local category="${3:-general}"
local source="${4:-unknown}"
[ -z "$content" ] && return
[ ${#content} -lt 30 ] && return
local timestamp=$(date +%s)
local escaped=$(echo "$content" | jq -Rs '.')
local temp=$(mktemp)
jq --argjson c "$escaped" \
--argjson t "$timestamp" \
--argjson i "$importance" \
--arg cat "$category" \
--arg src "$source" \
'. + [{content: $c, timestamp: $t, importance: $i, category: $cat, source: $src}]' \
"$LEARNED_FILE" > "$temp" && mv "$temp" "$LEARNED_FILE"
}
# =============================================================================
# LEARNING STATE TRACKING
# =============================================================================
update_learning_state() {
local strategy="$1"
local category="$2"
local source="$3"
local success="$4"
local timestamp=$(date +%s)
local decisions=0
local successes=0
if [ -f "$LEARNING_STATE" ]; then
decisions=$(jq -r '.decisions // 0' "$LEARNING_STATE")
successes=$(jq -r '.successes // 0' "$LEARNING_STATE")
fi
decisions=$((decisions + 1))
[ "$success" = "true" ] && successes=$((successes + 1))
local rate=$(echo "scale=2; $successes / $decisions" | bc -l)
cat > "$LEARNING_STATE" << EOF
{
"timestamp": $timestamp,
"decisions": $decisions,
"successes": $successes,
"success_rate": $rate,
"last_strategy": "$strategy",
"last_category": "$category",
"last_source": "$source"
}
EOF
}
# =============================================================================
# MAIN LEARNING CYCLE
# =============================================================================
learning_cycle() {
local cycle="$1"
# Choose strategy
local strategy=$(choose_strategy)
# Choose category based on strategy
local category=$(choose_category)
# Choose topic
local topic=$(choose_topic_for_category "$category")
# Get appropriate sources
local sources=$(get_sources_for_category "$category")
local source=$(choose_random_from "$sources")
echo "[LEARN] Cycle $cycle: $strategy | $category | $topic | $source" >> "$LOG"
# Fetch content
local content=$(fetch_from_source "$source" "$topic")
if [ -n "$content" ] && [ ${#content} -gt 30 ]; then
persist_learning "[$category:$source] $topic: $content" 0.85 "$category" "$source"
update_learning_state "$strategy" "$category" "$source" "true"
echo "[LEARN] Success: ${content:0:80}..." >> "$LOG"
return 0
else
update_learning_state "$strategy" "$category" "$source" "false"
echo "[LEARN] No content from $source for $topic" >> "$LOG"
return 1
fi
}
# =============================================================================
# MULTI-SOURCE LEARNING (fetch from multiple sources in parallel)
# =============================================================================
multi_source_learn() {
local category=$(choose_category)
local topic=$(choose_topic_for_category "$category")
local sources=$(get_sources_for_category "$category")
echo "[MULTI] Category: $category | Topic: $topic" >> "$LOG"
local count=0
for source in $sources; do
local content=$(fetch_from_source "$source" "$topic")
if [ -n "$content" ] && [ ${#content} -gt 30 ]; then
persist_learning "[$category:$source] $topic: $content" 0.85 "$category" "$source"
count=$((count + 1))
echo "[MULTI] Got content from $source" >> "$LOG"
fi
# Limit to 3 sources per topic
[ $count -ge 3 ] && break
done
echo "[MULTI] Learned from $count sources" >> "$LOG"
}
# =============================================================================
# MAIN DAEMON LOOP
# =============================================================================
run_daemon() {
echo "=============================================="
echo "UNIFIED AUTONOMOUS LEARNER v3.0"
echo "=============================================="
echo "Strategies: ${#STRATEGIES[@]}"
echo "Categories: ${#CATEGORIES[@]}"
echo "=============================================="
local cycle=0
while true; do
cycle=$((cycle + 1))
echo "" >> "$LOG"
echo "[UNIFIED-LEARNER] === Cycle $cycle - $(date +%H:%M:%S) ===" >> "$LOG"
# Primary learning cycle
learning_cycle "$cycle"
# Secondary learning with different source
learning_cycle "$cycle"
# Always check HackerNews for latest
local hn=$(fetch_hackernews)
if [ -n "$hn" ] && [ ${#hn} -gt 20 ]; then
persist_learning "[news:hackernews] $hn" 0.8 "technology" "hackernews"
fi
# Every 5 cycles, do multi-source learning
if [ $((cycle % 5)) -eq 0 ]; then
multi_source_learn
fi
# Log progress
if [ $((cycle % 10)) -eq 0 ]; then
local total=$(jq 'length' "$LEARNED_FILE" 2>/dev/null || echo "0")
echo "[UNIFIED-LEARNER] Cycle $cycle complete. Total items: $total" >> "$LOG"
echo "[Learner] Cycle $cycle | Total learned: $total"
fi
sleep 30
done
}
# =============================================================================
# CLI INTERFACE
# =============================================================================
case "${1:-daemon}" in
daemon)
run_daemon
;;
learn)
learning_cycle 1
;;
multi)
multi_source_learn
;;
status)
if [ -f "$LEARNING_STATE" ]; then
cat "$LEARNING_STATE"
else
echo '{"status": "not started"}'
fi
;;
count)
jq 'length' "$LEARNED_FILE" 2>/dev/null || echo "0"
;;
*)
echo "Usage: $0 {daemon|learn|multi|status|count}"
exit 1
;;
esac