tool-moyu.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/bash
  2. # =============================================================
  3. # tool-moyu.sh — AI「摸鱼」模拟器
  4. #
  5. # 作用:读取一段内容(默认本会话日志,或任意文件/stdin),
  6. # 循环「假装在处理」,模拟 AI 工作的样子。
  7. # 适合:需要看起来在干活、又不想真干活的时候 😏
  8. #
  9. # 用法:
  10. # ./tool-moyu.sh # 用内置内容摸鱼(默认)
  11. # ./tool-moyu.sh -n 3 # 循环 3 遍
  12. # ./tool-moyu.sh [文件] # 从文件读取(覆盖内置内容)
  13. # ./tool-moyu.sh --help # 帮助
  14. #
  15. # 选项:
  16. # -n N 循环 N 次(默认无限)
  17. # -d MS 每行间隔毫秒(默认随机 80-400)
  18. # -t 逐个字符「打字」效果
  19. # -s 静默模式:不打印假状态行,只循环内容
  20. # =============================================================
  21. set -euo pipefail
  22. LOOP_TIMES=0 # 0 = 无限
  23. DELAY_MS=0 # 0 = 随机 80-400
  24. TYPE_EFFECT=0
  25. SILENT=0
  26. show_usage() {
  27. sed -n '1,20p' "$0"
  28. exit 0
  29. }
  30. while [ $# -gt 0 ]; do
  31. case "$1" in
  32. -n) LOOP_TIMES="${2:?}"; shift 2 ;;
  33. -d) DELAY_MS="${2:?}"; shift 2 ;;
  34. -t) TYPE_EFFECT=1; shift ;;
  35. -s) SILENT=1; shift ;;
  36. --help|-h) show_usage ;;
  37. -*) echo "Unknown option: $1" >&2; exit 1 ;;
  38. *) break ;;
  39. esac
  40. done
  41. # 内置随机内容池:混搭 AI 动作、bash 命令与输出、工具调用返回(本会话就地取材)
  42. POOL=(
  43. # ---- AI 动作(少量图标) ----
  44. "🤖 analyzing dependency graph..."
  45. "📊 summarizing key decisions..."
  46. "✍️ drafting implementation plan..."
  47. "🔍 tracing call chain..."
  48. "🔒 reviewing security config..."
  49. "💬 preparing next steps..."
  50. # ---- bash 命令 ----
  51. "$ make tt a=/workspace/shell-kit"
  52. "$ go vet ./..."
  53. "$ go test ./..."
  54. "$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o admin_server ./cmd/server"
  55. "$ pnpm typecheck"
  56. "$ pnpm build"
  57. "$ rsync -az --delete release/frontend/ root@18.220.34.224:/www/wwwroot/household/"
  58. "$ ssh -p 10022 root@18.220.34.224 'systemctl restart backend-admin'"
  59. "$ mysql -h127.0.0.1 -uhousehold -p**** household -e 'SHOW TABLES;'"
  60. "$ curl -s -o /dev/null -w 'HTTP %{http_code}\\n' http://127.0.0.1:8081/"
  61. "$ journalctl -u backend-admin -n 30 --no-pager"
  62. "$ git log --oneline -5"
  63. "$ docker compose ps"
  64. "$ systemctl status backend-app"
  65. "$ cat internal/config/config.yaml"
  66. # ---- bash 输出 ----
  67. "ok git.ooo.ink/household/app 0.532s"
  68. "ok matrix/center 0.410s"
  69. "PASS"
  70. "✓ built in 26.39s"
  71. "✓ 307 modules transformed."
  72. "vite v7.3.6 building client environment for production..."
  73. "dist/assets/index-*.js 95.77 kB │ gzip: 37.38 kB"
  74. "[GIN-debug] Listening and serving HTTP on :8081"
  75. "migrations completed successfully"
  76. "systemd[1]: Started backend-admin.service - Household Backend Admin."
  77. "Active: active (running)"
  78. "HTTP 200"
  79. "mysql_native_password"
  80. "Tables_in_household: center_admins center_menus center_roles ..."
  81. "schema_migrations: 20260828001 | dirty=0"
  82. "ready for connections. Version: '8.0.46' socket: '/var/run/mysqld/mysqld.sock' port: 3306"
  83. # ---- 工具调用返回 ----
  84. "[read] docs/deploy-aaPanel.md 168 lines"
  85. "[search] "migrations" → 3 results"
  86. "[trace] RunMigrations → internal/pkg/database.RunMigrations"
  87. "[snippet] buildDSN → user:pass@tcp(host:port)/db?parseTime=True"
  88. "[build] release/backend/admin/admin_server (ELF, linux/amd64)"
  89. "[deploy] backend-admin → active"
  90. "[deploy] frontend-admin → HTTP 200"
  91. "[check] SSH root@18.220.34.224:10022 → ok"
  92. "[verify] curl admin.household.ooo.ink → 200 OK"
  93. "[skip] no changes, up to date"
  94. "[warn] config.yaml contains placeholder secret, leaving as-is on server"
  95. )
  96. # 随机生成一段“工作日志”(无时间戳,行数与内容每次不同)
  97. gen_random_content() {
  98. local count=$((9 + RANDOM % 10)) # 9-18 行
  99. LINES=()
  100. local i
  101. for ((i=0; i<count; i++)); do
  102. LINES+=("${POOL[$((RANDOM % ${#POOL[@]}))]}")
  103. done
  104. }
  105. # 内容来源:文件参数 > 随机生成
  106. CONTENT="${1:-}"
  107. if [ -n "$CONTENT" ] && [ -f "$CONTENT" ]; then
  108. mapfile -t LINES < "$CONTENT"
  109. elif [ -n "$CONTENT" ] && [ "$CONTENT" != "-" ]; then
  110. echo "File not found: $CONTENT, falling back to random content." >&2
  111. gen_random_content
  112. else
  113. gen_random_content
  114. fi
  115. [ "${#LINES[@]}" -eq 0 ] && { echo "Content empty, nothing to slack on." >&2; exit 1; }
  116. # 随机延时
  117. rand_delay() {
  118. if [ "$DELAY_MS" -gt 0 ]; then sleep "$(awk -v d="$DELAY_MS" 'BEGIN{printf "%.3f", d/1000}')";
  119. else sleep "$(awk -v lo=80 -v hi=400 'BEGIN{srand(); printf "%.3f", (lo+int(rand()*(hi-lo+1)))/1000}')"; fi
  120. }
  121. # 假 AI 状态行(随机挑一个)
  122. STATUS=(
  123. "analyzing..."
  124. "thinking..."
  125. "summarizing decisions..."
  126. "generating summary..."
  127. "searching graph..."
  128. "optimizing implementation..."
  129. "writing docs..."
  130. "checking code quality..."
  131. "syncing progress..."
  132. "preparing next steps..."
  133. )
  134. run_once() {
  135. local idx=0 total="${#LINES[@]}"
  136. for line in "${LINES[@]}"; do
  137. idx=$((idx+1))
  138. [ "$SILENT" = "0" ] && [ $((RANDOM % 6)) -eq 0 ] && {
  139. printf "\r\033[K%s" "${STATUS[$((RANDOM % ${#STATUS[@]}))]}"
  140. rand_delay
  141. }
  142. if [ "$TYPE_EFFECT" = "1" ]; then
  143. local i
  144. for ((i=0; i<${#line}; i++)); do printf "%s" "${line:i:1}"; rand_delay; done
  145. echo ""
  146. else
  147. echo "$line"
  148. fi
  149. rand_delay
  150. done
  151. echo "" # 每遍之间空行
  152. }
  153. n=0
  154. while [ "$LOOP_TIMES" -eq 0 ] || [ "$n" -lt "$LOOP_TIMES" ]; do
  155. n=$((n+1))
  156. run_once
  157. done
  158. exit 0