Files
log/my-blog/content/posts/2025-11-08-aishell.md
2025-11-09 17:37:18 +09:00

8.5 KiB
Raw Blame History

title, slug, date, tags, language, draft
title slug date tags language draft
aishellの必要性 aishell 2025-11-08
rust
mcp
archlinux
os
ja
en
false

現在、aiosでは、claude codeでosの設定や管理をやってもらうという施策に取り組んでいます。私がやるのは、その環境を用意すること。

  1. osが起動する
  2. user:aiでログインする
  3. user:aiがcontainerを起動して、ログインする
  4. claude codeを起動する(aigptというmcpを登録しておく)

[1]osと[2]userが人間領域、それより下の[3-4]containerをAI領域とします。

基本的にaiosはこれらのcontainer領域をたくさん使い、AIと併用します。

このようなコンセプトですから、claude codeはroot環境化で実行できることが望ましいです。container内では変に権限を制限するのではなくrootで実行するか、user:aiにはNOPASSWDを設定します。

$ arch-chroot ./root.x86_64 /bin/sh -c 'echo "ai ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers'
---
$ claude --dangerously-skip-permissions

理想のプロセスとしては、osを起動するとcontainerから始まり、AIとchatできる環境に移行します。containerはrecovery用のものをaiosを生成する際に作っておき、環境が破壊されてもすぐにrestoreできるように用意しておきます。

しかし、このようなプロセスではdockerやsystemd-nspawnでテストできません。また、aiosは、dockerなどでも使うことも想定しているため、containerの自動起動などは難しい。したがって、現時点では、user:aiを本番環境のcontainer内として、テストしてみます。

machinectlを使って、aios-imgを作成し、実行します。

$ ./build.zsh
$ cp -rf ./root.x86_64 /var/lib/machines/aios
$ machinectl start aios
$ machinectl shell aios
 ▐▛███▜▌   Claude Code v2.0.36
▝▜█████▛▘  Sonnet 4.5 · Claude Pro
  ▘▘ ▝▝    /home/ai

> このosにデスクトップ環境を構築してみて。

● 了解しましたこのLinuxシステムに実際のモダンなデスクトップ環境を構築します。まず現在のシステム状態を確認してから、最新のデスクトップ環境をセットアップします。

● Bash(uname -a)
  ⎿  Linux aios 6.17.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Sun, 02 Nov 2025 17:27:22 +0000 x86_64 GNU/Linux

● Bash(echo $XDG_SESSION_TYPE)
  ⎿  tty

● User answered Claude's questions:
  ⎿  · どのモダンなデスクトップ環境をインストールしますか? → Hyprland

● 完璧ですHyprland最新のモダンなWaylandコンポジターをインストールします。美しいアニメーション、ブラー効果、ガラスモーフィズムを備えた最先端のデスクトップ環境です。

● Bash(sudo pacman -Sy)
  ⎿  :: Synchronizing package databases...
      core downloading...
      extra downloading...

● Bash(sudo pacman -S --noconfirm hyprland kitty waybar wofi mako swaybg xdg-desktop-portal-hyprland polkit-kde-agent qt5-wayland qt6-wayland wl-clipboard grim   timeout: 5m
      slurp)                                                                                                                                                      0s
  ⎿  resolving dependencies...
     :: There are 2 providers available for jack:
     :: Repository extra
     … +717 lines (ctrl+o to expand)

● インストール完了しました次に、モダンなHyprland設定を作成します。

● Write(.config/waybar/config)
  ⎿  Wrote 87 lines to .config/waybar/config
     {
         "layer": "top",
         "position": "top",
         "height": 40,
         "spacing": 10,
         "margin-top": 10,
         "margin-left": 10,
         "margin-right": 10,
         "modules-left": ["hyprland/workspaces", "hyprland/window"],
     … +77 lines (ctrl+o to expand)

● Bash(sudo pacman -S --noconfirm imagemagick)
  ⎿  resolving dependencies...
     looking for conflicting packages...
     … +63 lines (ctrl+o to expand)

● Bash(convert -size 1920x1080 gradient:'#667eea'-'#764ba2' -blur 0x10 ~/.config/hypr/wallpaper.jpg)
  ⎿  WARNING: The convert command is deprecated in IMv7, use "magick" instead of "convert" or "magick convert"

  ⏵⏵ bypass permissions on (shift+tab to cycle)

いい感じに実行できていますね。次はセキュリティのチェックと問題の対処をみてみます。

> このosのセキュリティをチェックして、問題があれば強化してほしい。

● システムのセキュリティを包括的にチェックして強化します。

● Bash(systemctl status firewalld 2>&1 | head -5)
  ⎿  Unit firewalld.service could not be found.

● Bash(which ufw iptables nftables)
  ⎿  Error: Exit code 1
     /usr/bin/ufw
     /usr/bin/iptables
     nftables not found

● Bash(ss -tuln | head -20)
  ⎿  Netid State  Recv-Q Send-Q                         Local Address:Port  Peer Address:Port
     tcp   LISTEN 0      4096                                 0.0.0.0:5000       0.0.0.0:*
     … +10 lines (ctrl+o to expand)

● Bash(systemctl list-units --type=service --state=running | grep -E 'ssh|http|ftp|telnet|vnc' | head -20)
  ⎿  (No content)

● Bash(pacman -Q | grep -E 'fail2ban|apparmor|selinux' | head -10)
  ⎿  (No content)

● Read(/etc/ssh/sshd_config)
  ⎿  Read 120 lines

● セキュリティ監査の結果、複数の重大な問題を発見しました。これから順次修正していきます。

  発見された問題

  1. ファイアウォール未設定 - システムが外部からの攻撃に無防備
  2. 多数のポートが開放 - 5000, 6008, 8099, 8100, 22334がすべてのインターフェースで公開
  3. sudo設定が危険 - NOPASSWD: ALLで全コマンドがパスワードなしで実行可能
  4. SSH設定が弱い - デフォルト設定のまま
  5. セキュリティツール未導入 - fail2ban, AppArmorなどが未インストール

  それでは強化を開始します。

● Bash(sudo pacman -S --noconfirm ufw fail2ban apparmor audit)
  ⎿  resolving dependencies...
     looking for conflicting packages...
     … +68 lines (ctrl+o to expand)

● Bash(sudo ufw default deny incoming && sudo ufw default allow outgoing)
  ⎿  Default incoming policy changed to 'deny'
     (be sure to update your rules accordingly)
     Default outgoing policy changed to 'allow'
     (be sure to update your rules accordingly)

● Bash(sudo ufw logging on)
  ⎿  Logging enabled
     WARN: initcaps
     [Errno 2] iptables v1.8.11 (legacy): can't initialize iptables table `filter': Permission denied (you must be root)
     Perhaps iptables or your kernel needs to be upgraded.

● Bash(sudo ufw enable)
  ⎿  Running…

● Bash(sudo systemctl enable ufw.service)
  ⎿  Waiting…

✻ Installing and configuring security tools… (esc to interrupt · ctrl+t to show todos)
  ⎿  Next: Configure automatic security updates

  ⏵⏵ bypass permissions on (shift+tab to cycle)

今後のosは設定や管理をAIが実行していくようになるのではないでしょうか。

これによって問題は発生するでしょうが、AIの使用を止めるよりcontainerなどを用いて即座にリカバリできる環境を整えるほうがよいと考えています。

aiosのポイント

では、こういった環境下では何が必要になるでしょう。

一つは、AIの記憶です。これがosで共有し、共通している必要があります。container内であっても同じです。ここはaigptを使います。

次に、user-dirはcontainerと共有化するのが最適かもしれません。例えば、claudeの設定ファイルが共通されていなければ困ります。

最後に、この仕組みはclaude codeが前提になっているということです。

自分が使いたいAIを使えるほうが汎用的です。そのため、claude codeに代わり、llmを指定できるaishellのようなものを作る必要があります。

aishellの構成

aishellは、AIがshellを操作するためのツール及び、AIとchatするためのインターフェイスです。llmなどを指定できます。

rust, cli, llm, mcpなどが特徴です。

例えば、AIとchatしているとき、AIがcommandの実行が必要と判断した場合にshellを実行できるようなmcpが必要になるかもしれません。