Lifecycle stable ownership-aware

Cài lại clean AgentKit

Gỡ kit có ownership → (tuỳ chọn) reset state → cài CLI stable → login + kit init. Không xóa ~/.codex hay ~/.claude.

Ranh giới lệnh

ak uninstall ≠ gỡ kit global

Nhầm lệnh này là nguyên nhân hay gặp khi “gỡ AgentKit” thất bại hoặc gỡ nhầm scope.

ak uninstall

Gỡ project do AgentKit quản lý (ak new / project bootstrap). Cần AK project tại hoặc phía trên thư mục hiện tại. Không phải lệnh gỡ kit cài global trên máy.

  • Cần project AK
  • Preview mặc định
  • Không thay kit uninstall

ak kit uninstall <kit>

Gỡ nội dung do kit sở hữu (AgentKit-owned) theo scope/mode bạn chọn. Dùng khi muốn gỡ engineer/marketing (global, project, native, plugin).

  • Theo từng kit
  • Theo từng scope/mode
  • Cần ownership records

Uninstall là preview-first

Chạy không có --yes có thể kết thúc bằng thông báo kiểu kit uninstall dry-run complete; re-run with --yes to execute . Đó là hành vi mong đợi — chưa gỡ, không phải uninstall fail.

--force không phải delete-all

ak kit uninstall không có flag --force. Trên ak update / ak kit init / project ak uninstall, --force chỉ nới collision/overwrite có kiểm soát — không phải “xóa sạch mọi thứ”, không bypass snapshot recovery.

Tách lớp

Gỡ kit · reset state · thay binary · cài lại kit

Bốn việc khác nhau. Làm đúng thứ tự: gỡ kit (còn ownership) → (tuỳ chọn) dời state AgentKit → cài CLI stable → login + kit init.

1. Gỡ kit

ak kit uninstall … theo scope thật đã cài

2. Reset state AK

logout + mv ~/.agentkit (sau khi gỡ kit)

3. Thay CLI

self-update hoặc install.sh kênh stable

4. Cài lại kit

login + kit init --channel stable

Binary channel và kit channel tách nhau. Ghi rõ --channel stable khi muốn chắc cài/cập nhật từ stable.

Cài lại clean

Cài lại clean AgentKit stable

Quy trình macOS/Linux khuyến nghị. Giữ ownership đến khi gỡ kit xong; ưu tiên move/quarantine hơn delete; giữ state cũ đến khi audit/doctor pass.

  1. 1

    Dừng tiến trình đang ghi

    Đóng Codex, Claude Code và mọi lệnh lifecycle AgentKit đang chạy trước khi đụng file tạm hoặc gỡ kit.

  2. 2

    Xác nhận CLI ak + kênh stable

    type -a ak, ak --version, ak self-update --check --channel stable. Nâng CLI nếu cần — nhưng chưa xóa ~/.agentkit.

  3. 3

    Workaround file ..* (2.7.0)

    Nếu gặp lỗi snapshot outside scope: đóng Codex, list rồi move (không xóa) file tạm khớp pattern hẹp sang quarantine.

  4. 4

    Audit + gỡ kit đã sở hữu

    Chỉ gỡ scope/mode thật sự đã cài: global native, user plugin, project native, project plugin. Preview (--dry-run) rồi --yes.

  5. 5

    Xác minh bằng chứng gỡ

    ak audit --json và ak backups list --json. Snapshot recovery còn lại là bằng chứng — giữ đến khi cài lại xong.

  6. 6

    Reset state AgentKit (tùy chọn)

    Chỉ sau khi gỡ kit xong: ak logout, rồi mv ~/.agentkit sang tên phục hồi — không xóa ngay.

  7. 7

    Cài lại CLI stable

    Installer stable, hash -r, type -a ak, ak --version, ak doctor --json. Giải quyết trùng binary trên PATH.

  8. 8

    Login + cài lại kit

    ak login, ak licenses, ak kit init … --channel stable --yes, rồi audit/doctor trước khi restart Codex.

01

Phase 1: dừng tiến trình đang ghi

Đóng Codex, Claude Code, và mọi lệnh lifecycle AgentKit đang chạy trước khi đụng file tạm trong ~/.codex hoặc chạy uninstall. Không chồng lifecycle, không kill giữa chừng pha mutation.

02

Phase 2: CLI đã cài + kênh stable

shell
type -a ak
ak --version
ak self-update --check --channel stable

# Nâng CLI (không xóa ~/.agentkit — ownership vẫn cần cho uninstall)
ak self-update --channel stable --yes

# Hoặc cài lại binary từ installer stable
# curl -fsSL https://agentkit.best/install.sh | AK_CHANNEL=stable sh
# hash -r
# ak --version

03

Phase 3: workaround file ..* (2.7.0)

Chỉ khi bạn thấy backups: walk produced path outside scope (hoặc list thấy file khớp). Move, không xóa.

Trước hết list file khớp pattern hẹp (maxdepth 1, type file):

shell
find "$HOME/.codex" -maxdepth 1 -type f \
  -name '..codex-global-state.json.bak.tmp-*' -print

Sau khi Codex đã đóng, move các file khớp sang quarantine có thể phục hồi ngoài cây ~/.codex (nhưng vẫn trong ~/.agentkit để dễ tìm):

shell
quarantine="$HOME/.agentkit/manual-quarantine/codex-temp-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$quarantine"

find "$HOME/.codex" -maxdepth 1 -type f \
  -name '..codex-global-state.json.bak.tmp-*' \
  -exec mv -n {} "$quarantine"/ \;
Move; không delete.
Chỉ pattern hẹp ..codex-global-state.json.bak.tmp-*
Không đụng config.toml, skills, hooks, credentials, session state, dotfile khác.
Giữ quarantine đến khi reinstall verify pass.
File xuất hiện lại khi Codex đã đóng, hoặc không phải regular file → dừng, escalate — không nới cleanup.
Không bypass tạo backup của AgentKit; không --no-backup.

Sau quarantine, chạy lại dry-run rồi uninstall có --yes (đúng scope bạn dùng — xem Phase 4).

04

Phase 4: audit và gỡ kit đã sở hữu

Chỉ chạy mode bạn thật sự đã cài. Xem dry-run trước mỗi --yes. Lặp cho từng kit (engineer, marketing, …).

Global native

shell
# Global native (ví dụ Engineer Kit)
ak audit --json

ak kit uninstall engineer --global --dry-run
ak kit uninstall engineer --global --yes

# Lặp cho kit khác đã cài (ví dụ marketing) — cùng scope
# ak kit uninstall marketing --global --dry-run
# ak kit uninstall marketing --global --yes

Claude Code user plugin

shell
# Claude Code user plugin
ak kit uninstall engineer --global --plugin-mode --dry-run
ak kit uninstall engineer --global --plugin-mode --yes

Native project

shell
# Native project — dùng đường dẫn tuyệt đối
ak kit uninstall engineer \
  --project-dir /absolute/path/to/project \
  --dry-run

ak kit uninstall engineer \
  --project-dir /absolute/path/to/project \
  --yes

Project plugin

shell
# Project plugin
ak kit uninstall engineer \
  --plugin-mode \
  --project-dir /absolute/path/to/project \
  --dry-run

ak kit uninstall engineer \
  --plugin-mode \
  --project-dir /absolute/path/to/project \
  --yes

05

Phase 5: xác minh bằng chứng gỡ

shell
ak audit --json
ak backups list --json

Recovery snapshot còn lại là bằng chứng mong đợi — không xóa cho đến khi lifecycle và cài lại đã verify. Chỉ mô tả uninstall “đã gỡ” khi lệnh confirmed (--yes) thành công.

06

Phase 6: reset state nội bộ AgentKit (cố ý)

Chỉ khi bạn thật sự muốn state AgentKit sạch. Sau khi ownership-aware kit uninstall xong.

shell
# Chỉ sau khi ownership-aware kit uninstall đã xong
ak logout

stamp=$(date +%Y%m%d-%H%M%S)
mv "$HOME/.agentkit" "$HOME/.agentkit.pre-stable-$stamp"

# Giữ thư mục đổi tên cho đến khi cài stable + audit/doctor pass
# Không xóa ngay — trong đó có backup, quarantine, registry, auth state
  • Reset state AgentKit nhưng vẫn giữ bản phục hồi (mv, không rm).
  • Cũng dời backups và quarantine file tạm đã tạo ở Phase 3 (nằm trong ~/.agentkit).
  • Không xóa thư mục đổi tên cho đến khi cài stable + kit audit pass.

07

Phase 7: cài stable

shell
curl -fsSL https://agentkit.best/install.sh | AK_CHANNEL=stable sh
hash -r

type -a ak
ak --version
ak doctor --json

# Nếu type -a ak hiện nhiều binary: sửa PATH trước khi tiếp tục

08

Phase 8: authenticate và cài lại kit

shell
ak login
ak licenses

# Ví dụ: Engineer Kit trên Codex global, kênh stable
ak kit init engineer \
  --target codex \
  --global \
  --channel stable \
  --yes

ak audit engineer --strict --json
ak doctor --adapter codex --json

# Chỉ restart Codex sau khi các check trên xong

Giữ quarantine và ~/.agentkit.pre-stable-* cho đến khi ak audit / ak doctor pass. Sau đó mới cân nhắc dọn bản phục hồi.

Windows

Windows (PowerShell) — nguyên tắc an toàn

Không dịch máy lệnh Unix sang Remove-Item -Recurse trên cả runtime home. Giữ ownership-aware uninstall trước khi reset state.

Inspect mọi ak.exe trên PATH (Get-Command ak -All) trước khi replace.
Chỉ gỡ/thay executable AgentKit đã xác minh — không xóa cả thư mục PATH nếu có thể chứa tool khác.
Không xóa %USERPROFILE%\.codex hoặc %USERPROFILE%\.claude.
Quarantine state (Move-Item) thay vì xóa rộng.
ak kit uninstall ownership-aware trước khi dời %USERPROFILE%\.agentkit.

Quarantine file tạm ..* (tương đương Phase 3)

powershell
# PowerShell — đóng Codex trước. Chỉ file tạm khớp pattern hẹp.
$codex = Join-Path $env:USERPROFILE '.codex'
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$quarantine = Join-Path $env:USERPROFILE ".agentkit\manual-quarantine\codex-temp-$stamp"
New-Item -ItemType Directory -Force -Path $quarantine | Out-Null

Get-ChildItem -LiteralPath $codex -File -Force |
  Where-Object { $_.Name -like '..codex-global-state.json.bak.tmp-*' } |
  ForEach-Object {
    Move-Item -LiteralPath $_.FullName -Destination $quarantine -ErrorAction Stop
  }

Get-ChildItem -LiteralPath $quarantine -Force

Dời state AgentKit (tương đương Phase 6)

powershell
# PowerShell — chỉ sau kit uninstall ownership-aware
ak logout
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$homeAk = Join-Path $env:USERPROFILE '.agentkit'
$dest = Join-Path $env:USERPROFILE ".agentkit.pre-stable-$stamp"
Move-Item -LiteralPath $homeAk -Destination $dest

Cài lại CLI (installer Windows)

powershell
# PowerShell
irm https://agentkit.best/install.ps1 | iex
# Mở terminal mới, rồi:
Get-Command ak -All
ak --version
ak doctor --json

Các lệnh ak kit uninstall / audit / kit init giống Unix (cùng flags). Thay $HOME bằng %USERPROFILE% khi nói path; dùng đường dẫn project tuyệt đối cho --project-dir.

Tài liệu liên quan