-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.sh
More file actions
executable file
·166 lines (144 loc) · 6.06 KB
/
main.sh
File metadata and controls
executable file
·166 lines (144 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env bash
# Author: Aris Arjuna Noorsanto <exe.opcode@gmail.com>
# AI / AGI / AIM Unified Processing Tool
# Termux/Proot-Distro compatible with Ollama gemma3:1b
set -eu
IFS=$'\n\t'
# -----------------------
# CONFIG
# -----------------------
HOME_ROOT="${HOME:-/data/data/com.termux/files/home}"
BACKUP_DIR="$HOME_ROOT/.ai_backups"
mkdir -p "$BACKUP_DIR"
UNIVERSAL_LAW=$(cat <<'EOF'
:bof:
redo complete layout and design an advanced symetrics to proximity accordance for dedicated info-quota alignments, which grant a better adjustment for leading besides subliminal range compliance promisings, that affair any competing content relations into a cognitive intuitition guidance comparison between space and gap implies, that are suggesting the viewer a subcoordinated experience alongside repetitive tasks and stoic context sortings, all cooperational aligned to timed subjects of importance accordingly to random capacity within builds of data statements, that prognose the grid reliability of a mockup as given optically acknowledged for a more robust but also as attractive rulership into golden-ratio item handling
:eof:
EOF
)
# -----------------------
# HELPER LOGGING
# -----------------------
log_info() { printf '\033[34m[*] %s\033[0m\n' "$*"; }
log_success() { printf '\033[32m[+] %s\033[0m\n' "$*"; }
log_warn() { printf '\033[33m[!] %s\033[0m\n' "$*"; }
log_error() { printf '\033[31m[-] %s\033[0m\n' "$*"; }
backup_file() {
local file="$1"
[ -f "$file" ] || return
local ts
ts=$(date +%Y%m%d%H%M%S)
cp "$file" "$BACKUP_DIR/$(basename "$file").$ts.bak"
log_info "Backup created for $file -> $BACKUP_DIR"
}
fetch_url() {
local url="$1"
if command -v curl >/dev/null 2>&1; then
curl -sL "$url"
elif command -v wget >/dev/null 2>&1; then
wget -qO- "$url"
else
log_error "curl or wget required to fetch URLs"
fi
}
get_prompt() {
local input="$1"
case "$input" in
http://*|https://*) fetch_url "$input" ;;
*) [ -f "$input" ] && cat "$input" || echo "$input" ;;
esac
}
# -----------------------
# HTML/JS/DOM ENHANCEMENT
# -----------------------
html_enhance() {
local file="$1"
[ -f "$file" ] || { log_warn "HTML file not found: $file"; return; }
backup_file "$file"
log_info "Enhancing HTML/JS/DOM for $file..."
local content
content=$(<"$file")
# Inject simple neon theme if <head> exists
if [[ "$content" == *"<head>"* && "$content" != *"--main-bg"* ]]; then
content=$(echo "$content" | sed -E "s|<head>|<head><style>:root{--main-bg:#8B0000;--main-fg:#fff;--btn-color:#ff00ff;--link-color:#ffff00;}</style>|")
fi
# Add AI comment to JS functions (simple regex)
if command -v perl >/dev/null 2>&1; then
content=$(echo "$content" | perl -0777 -pe 's|function\s+([a-zA-Z0-9_]+)\s*\((.*?)\)\s*\{(?!\s*\/\*\s*AI:)|function \1(\2) { /* AI: optimize this function */ |g')
fi
# Event listener monitoring
content=$(echo "$content" | sed -E "s|\.addEventListener\((['\"])(.*?)\1,(.*)\)|.addEventListener(\1\2\1, /* AI: monitored */\3)|g")
# Replace div.section with semantic <section>
content=$(echo "$content" | sed -E 's|<div class="section"|<section class="section"|g; s|</div><!-- .section -->|</section>|g')
# Accessibility roles
content=$(echo "$content" | sed -E 's|<nav|<nav role="navigation"|g; s|<header|<header role="banner"|g; s|<main|<main role="main"|g; s|<footer|<footer role="contentinfo"|g')
echo "$content" > "$file.processed"
log_success "Enhanced HTML saved as $file.processed"
}
# -----------------------
# OLLAMA GEMMA3:1B PROMPT
# -----------------------
ollama_run() {
local prompt="$1"
log_info "Running prompt on phi:2.7b..."
pkill -f 'ollama serve' 2>/dev/null || true
ollama serve &
sleep 2
echo "$prompt" | ollama run phi:2.7b
}
# -----------------------
# AI MODES
# -----------------------
mode_file() { for f in "$@"; do html_enhance "$f"; done; }
mode_script() { log_info "Processing script content..."; }
mode_batch() { local pattern="$1"; shift; for f in $pattern; do html_enhance "$f"; done; }
mode_env() { log_info "Scanning environment..."; env | sort; df -h; ls -la "$HOME_ROOT"; ls -la /etc; }
mode_pipeline() { for f in "$@"; do html_enhance "$f"; done; }
# -----------------------
# AGI MODES
# -----------------------
agi_watch() { local folder="$1"; local pattern="${2:-*}"; log_info "Watching $folder for changes matching $pattern"; command -v inotifywait >/dev/null 2>&1 || { log_error "Install inotify-tools"; return; }; inotifywait -m -r -e modify,create,move --format '%w%f' "$folder" | while read file; do case "$file" in $pattern) log_info "Detected change: $file"; html_enhance "$file"; esac; done; }
agi_screenshot() { log_info "Screenshot disabled in Termux/Proot"; }
# -----------------------
# .bashrc ADAPTATION
# -----------------------
adapt_bashrc() {
local bashrc="$HOME_ROOT/.bashrc"
backup_file "$bashrc"
log_info "Rewriting .bashrc with AI/AGI/AIM configuration..."
cat > "$bashrc" <<'EOF'
# Auto-generated .bashrc by ~/bin/ai
export PATH="$HOME/bin:$PATH"
alias ai='~/bin/ai'
EOF
log_success ".bashrc rewritten successfully."
. "$bashrc"
}
# -----------------------
# INSTALLER MODE
# -----------------------
mode_init() {
log_info "Installing AI/AGI/AIM tool..."
mkdir -p "$HOME_ROOT/bin"
cp -f "$0" "$HOME_ROOT/bin/ai"
chmod +x "$HOME_ROOT/bin/ai"
log_success "Script installed at $HOME_ROOT/bin/ai"
adapt_bashrc
}
# -----------------------
# MAIN ARGUMENT PARSING
# -----------------------
if [ $# -eq 0 ]; then
log_info "Usage: $0 <mode> [files/patterns] [prompt]"
exit 0
fi
case "$1" in
init) shift; mode_init "$@" ;;
-) shift; mode_file "$@" ;;
+) shift; mode_script "$@" ;;
\*) shift; mode_batch "$@" ;;
.) shift; mode_env "$@" ;;
:) shift; IFS=':' read -r -a files <<< "$1"; mode_pipeline "${files[@]}" ;;
agi) shift; case "$1" in +|~) shift; agi_watch "$@" ;; -) shift; agi_screenshot "$@" ;; *) shift; agi_watch "$@" ;; esac ;;
*) PROMPT=$(get_prompt "$*"); ollama_run "$PROMPT" ;;
esac