Skip to content

專案私人 #39778

@wshao777

Description

@wshao777

Storm Army & Population Ops

進入專案

cd storm_army

跑三軍示範 / 世界報告

python3 aibot_sim.py 預設同時跑 demo-bot + demo-world
python3aibot_sim.py --demo-bot
python3 aibot_sim.py --demo-world
python3 aibot_sim.py --deploy 中國

監控網站移動物件(可選)

#pip install requests bs4
python3 # aibot_sim.py --watch "https://example.com" --interval 30 --times 5

人口合併(870 萬集中安置示例)

先準備 world_state(你已提供 real_world_state.json)

將瑞士 8,700,000 併入台灣,並分配到三個安全區

python - <<'PY'
import json
from population_ops import merge_population, PopEventLog

with open("real_world_state.json","r+",encoding="utf-8") as f:
data = json.load(f)

plan = [
{"zone":"台中-西屯安全區","cap":4000000},
{"zone":"台北-內湖守護區","cap":3000000},
{"zone":"新竹-竹北科研區","cap":1700000}
]

result = merge_population(data, "瑞士", "台灣", amount="all", cluster_plan=plan, log=PopEventLog("events.log"))
print("[人口合併] 瑞士 → 台灣:{} 人".format(result["moved"]))
print("[集中安置]")
for a in result["assigned"]:
print("- {}:{} 人".format(a['zone'], a['assigned']))

with open("real_world_state.json","w",encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
PY

單元測試

python -m unittest -v

pip(僅當你機器缺 pip 時)

python get-pip.py

或指定版本(舊系統)

python get-pip.py "pip<21"

檢查版本

python -m pip --version
好,直接補上三件事:

  1. 把「就地升級備份」自動推到你私有 aosp16-snapshots;

  2. 補 .gitignore;

  3. 可選的 GitHub Actions,讓你每天自動推備份。


新增檔案

scripts/push_inplace_backups.sh

把 .inplace_backup/ 內的每次升級快照(manifest/status/tar.gz)自動推到 aosp16-snapshots 私倉。

#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
source "$ROOT/.env"

目標倉庫:與前面一致(可放相同 repo)

: "${SNAPSHOT_REPO_STABLE_SSH:?請在 .env 設定 SNAPSHOT_REPO_STABLE_SSH}"

SRC_DIR="$ROOT/.inplace_backup"
[ -d "$SRC_DIR" ] || { echo "找不到 $SRC_DIR,先跑過 inplace 升級腳本再來推送。"; exit 0; }

TMP="$ROOT/.tmp/inplace-snapshots"
rm -rf "$TMP"; mkdir -p "$TMP"; cd "$TMP"
git init
git remote add origin "$SNAPSHOT_REPO_STABLE_SSH"
git fetch origin || true
git checkout -B main || git checkout -B master || true

把所有快照拷進來(增量覆蓋)

mkdir -p snapshots
rsync -av --delete "$SRC_DIR/" snapshots/

也把最新一次快照拉到倉庫根目錄方便瀏覽

latest="$(ls -1 "$SRC_DIR" | sort | tail -n1 || true)"
if [ -n "$latest" ]; then
rm -f manifest-before.xml manifest-after.xml status-before.txt status-after.txt latest.tar.gz || true
cp "$SRC_DIR/$latest/manifest-before.xml" ./ || true
cp "$SRC_DIR/$latest/manifest-after.xml" ./ || true
cp "$SRC_DIR/$latest/status-before.txt" ./ || true
cp "$SRC_DIR/$latest/status-after.txt" ./ || true

若你有把整個快照 tar.gz 起來,也一起帶上(可選)

if [ -f "$SRC_DIR/$latest.tar.gz" ]; then
cp "$SRC_DIR/$latest.tar.gz" ./latest.tar.gz
fi
fi

git add .
if git diff --cached --quiet; then
echo "沒有新的快照需要推送。"
exit 0
fi

git commit -m "inplace snapshots: sync at $(date -Iseconds)"
git push -u origin HEAD
echo "✅ 已推送 inplace 快照到:$SNAPSHOT_REPO_STABLE_SSH"


.gitignore(放在工具 repo 根目錄)

AOSP/工作區與暫存

workspaces/
.mirror/
.tmp/
.snapshots/
.inplace_backup/
.venv/
*.log
*.tar.gz


README.md 追加章節(在「快速開始」下面加)

就地升級到 Android 16 並推快照

# 在「現有的 AOSP 專案根目錄」放入腳本(或用本工具包內的同名腳本)
chmod +x scripts/inplace_upgrade_to_android16.sh
./scripts/inplace_upgrade_to_android16.sh

# 回到工具包根目錄,推送此次升級產出的快照到私倉
chmod +x scripts/push_inplace_backups.sh
bash scripts/push_inplace_backups.sh

快照來源:.inplace_backup/<timestamp>/

推送目標:.env 的 SNAPSHOT_REPO_STABLE_SSH(建議:git@github.com:Wshao777/aosp16-snapshots.git)


---

# (可選)GitHub Actions:每日自動拉與推快照

在工具包加 `.github/workflows/inplace_snap_sync.yml````yaml
name: Inplace Snapshot Sync

on:
  schedule:
    - cron: "15 3 * * *"   # 每天台北時間 11:15 執行
  workflow_dispatch:

jobs:
  sync-inplace:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install deps
        run: |
          sudo apt update
          sudo apt install -y git-core curl python3 openjdk-17-jdk repo rsync

      - name: Prepare env
        run: |
          cp .env.example .env
          sed -i "s|GIT_USER_NAME=.*|GIT_USER_NAME=${{ secrets.GIT_USER_NAME }}|g" .env
          sed -i "s|GIT_USER_EMAIL=.*|GIT_USER_EMAIL=${{ secrets.GIT_USER_EMAIL }}|g" .env
          sed -i "s|GITHUB_USERNAME=.*|GITHUB_USERNAME=${{ secrets.GH_USER }}|g" .env
          sed -i "s|GITHUB_TOKEN=.*|GITHUB_TOKEN=${{ secrets.GH_TOKEN }}|g" .env
          sed -i "s|SNAPSHOT_REPO_STABLE_SSH=.*|SNAPSHOT_REPO_STABLE_SSH=${{ secrets.SNAPSHOT_REPO_STABLE_SSH }}|g" .env

      # 如果你把完整 AOSP 也放在 CI 端就地升級,請在這裡先 checkout/restore
      # 本工作流預設只「推已有的 .inplace_backup」;如需 CI 端也跑就地升級,再加一步呼叫 scripts/inplace_upgrade_to_android16.sh

      - name: Push inplace backups
        run: |
          chmod +x scripts/push_inplace_backups.sh
          bash scripts/push_inplace_backups.sh

> Secrets 需要設定:GH_USER, GH_TOKEN, GIT_USER_NAME, GIT_USER_EMAIL, SNAPSHOT_REPO_STABLE_SSH(SSH URL)。




---

一次性指令(你現在可直接跑)

1. 在你的工具包根目錄填 .env:



cp .env.example .env
# 編輯 .env,至少確認:
# SNAPSHOT_REPO_STABLE_SSH=git@github.com:Wshao777/aosp16-snapshots.git

2. 在 現有 Android 15 工作樹根目錄就地升級到 16:



# 把先前給你的就地升級腳本放到這個根目錄
chmod +x inplace_upgrade_to_android16.sh
./inplace_upgrade_to_android16.sh

3. 回到工具包,推送快照:



bash scripts/push_inplace_backups.sh


---

要我把這些檔案打成三個 repo 的初始化包(含 README/LICENSE/workflow)直接貼給你?

lightning-aosp-sync(工具)

aosp16-snapshots(快照倉,私有)

aosp-preview-snapshots(快照倉,私有)


你說一聲,我把首發內容直接給到位。

bash scripts/push_inplace_backups.sh# 把先前給你的就地升級腳本放到這個根目錄
chmod +x inplace_upgrade_to_android16.sh
./inplace_upgrade_to_android16.shcp .env.example .env
# 編輯 .env,至少確認:
# SNAPSHOT_REPO_STABLE_SSH=git@github.com:Wshao777/aosp16-snapshots.git---

# (可選)GitHub Actions:每日自動拉與推快照

在工具包加 `.github/workflows/inplace_snap_sync.yml`

```yaml
name: Inplace Snapshot Sync

on:
  schedule:
    - cron: "15 3 * * *"   # 每天台北時間 11:15 執行
  workflow_dispatch:

jobs:
  sync-inplace:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install deps
        run: |
          sudo apt update
          sudo apt install -y git-core curl python3 openjdk-17-jdk repo rsync

      - name: Prepare env
        run: |
          cp .env.example .env
          sed -i "s|GIT_USER_NAME=.*|GIT_USER_NAME=${{ secrets.GIT_USER_NAME }}|g" .env
          sed -i "s|GIT_USER_EMAIL=.*|GIT_USER_EMAIL=${{ secrets.GIT_USER_EMAIL }}|g" .env
          sed -i "s|GITHUB_USERNAME=.*|GITHUB_USERNAME=${{ secrets.GH_USER }}|g" .env
          sed -i "s|GITHUB_TOKEN=.*|GITHUB_TOKEN=${{ secrets.GH_TOKEN }}|g" .env
          sed -i "s|SNAPSHOT_REPO_STABLE_SSH=.*|SNAPSHOT_REPO_STABLE_SSH=${{ secrets.SNAPSHOT_REPO_STABLE_SSH }}|g" .env

      # 如果你把完整 AOSP 也放在 CI 端就地升級,請在這裡先 checkout/restore
      # 本工作流預設只「推已有的 .inplace_backup」;如需 CI 端也跑就地升級,再加一步呼叫 scripts/inplace_upgrade_to_android16.sh

      - name: Push inplace backups
        run: |
          chmod +x scripts/push_inplace_backups.sh
          bash scripts/push_inplace_backups.sh### 就地升級到 Android 16 並推快照
```bash
# 在「現有的 AOSP 專案根目錄」放入腳本(或用本工具包內的同名腳本)
chmod +x scripts/inplace_upgrade_to_android16.sh
./scripts/inplace_upgrade_to_android16.sh

# 回到工具包根目錄,推送此次升級產出的快照到私倉
chmod +x scripts/push_inplace_backups.sh
bash scripts/push_inplace_backups.sh# AOSP/工作區與暫存
workspaces/
.mirror/
.tmp/
.snapshots/
.inplace_backup/
.venv/
*.log
*.tar.gz#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
source "$ROOT/.env"

# 目標倉庫:與前面一致(可放相同 repo)
: "${SNAPSHOT_REPO_STABLE_SSH:?請在 .env 設定 SNAPSHOT_REPO_STABLE_SSH}"

SRC_DIR="$ROOT/.inplace_backup"
[ -d "$SRC_DIR" ] || { echo "找不到 $SRC_DIR,先跑過 inplace 升級腳本再來推送。"; exit 0; }

TMP="$ROOT/.tmp/inplace-snapshots"
rm -rf "$TMP"; mkdir -p "$TMP"; cd "$TMP"
git init
git remote add origin "$SNAPSHOT_REPO_STABLE_SSH"
git fetch origin || true
git checkout -B main || git checkout -B master || true

# 把所有快照拷進來(增量覆蓋)
mkdir -p snapshots
rsync -av --delete "$SRC_DIR/" snapshots/

# 也把最新一次快照拉到倉庫根目錄方便瀏覽
latest="$(ls -1 "$SRC_DIR" | sort | tail -n1 || true)"
if [ -n "$latest" ]; then
  rm -f manifest-before.xml manifest-after.xml status-before.txt status-after.txt latest.tar.gz || true
  cp "$SRC_DIR/$latest/manifest-before.xml" ./ || true
  cp "$SRC_DIR/$latest/manifest-after.xml"  ./ || true
  cp "$SRC_DIR/$latest/status-before.txt"   ./ || true
  cp "$SRC_DIR/$latest/status-after.txt"    ./ || true
  # 若你有把整個快照 tar.gz 起來,也一起帶上(可選)
  if [ -f "$SRC_DIR/$latest.tar.gz" ]; then
    cp "$SRC_DIR/$latest.tar.gz" ./latest.tar.gz
  fi
fi

git add .
if git diff --cached --quiet; then
  echo "沒有新的快照需要推送。"
  exit 0
fi

git commit -m "inplace snapshots: sync at $(date -Iseconds)"
git push -u origin HEAD
echo "✅ 已推送 inplace 快照到:$SNAPSHOT_REPO_STABLE_SSH"scripts/push_inplace_backups.sh

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis issue/PR is invalidtriageDo not begin working on this issue until triaged by the team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions