Bỏ qua để đến nội dung

CLI output và automation

Bestie CLI có hai kiểu output: output thân thiện cho terminal và output máy đọc được cho scripts. Dùng các tùy chọn trong trang này khi chạy Bestie trong CI, shell scripts, cron jobs hoặc automation khác.

Các lệnh human-facing in Bestie ASCII banner trước nội dung lệnh. Trong terminal interactive, banner có thể animate ngắn. Trong output non-interactive, Bestie in banner tĩnh.

Tắt banner cho một command:

Terminal window
BESTIE_NO_BANNER=1 bestie status

Giữ banner nhưng tắt animation:

Terminal window
BESTIE_BANNER=static bestie status

Ép animation khi stdout là TTY:

Terminal window
BESTIE_BANNER=animate bestie status

Các command máy đọc được tự suppress banner khi CLI entrypoint nhận diện được.

Bestie dùng badge, table và progress indicator có màu cho human output khi stdout là TTY.

Tắt ANSI color:

Terminal window
NO_COLOR=1 bestie doctor

Dùng cách này khi capture command output vào script hoặc log không nên chứa terminal escape sequences.

Ưu tiên command có JSON hoặc raw output khi automation cần parse kết quả.

Doctor JSON:

Terminal window
bestie doctor --json

Channel Doctor JSON:

Terminal window
bestie channels doctor --channel all --json
bestie channels doctor --channel telegram --connect --json
bestie channels doctor --channel zalo --connect --json

MCP tool call JSON:

Terminal window
bestie mcp call dry-run read_file --read --json '{"path":"README.md"}'

Memory JSON và export commands:

Terminal window
bestie memory export
bestie memory analyze --json
bestie memory cleanup --dry-run --json
bestie memory cleanup --apply --yes --json

Những command này được thiết kế để tránh decorative output. Với command chưa có JSON mode, set BESTIE_NO_BANNER=1NO_COLOR=1 trước khi parse human output.

Bestie có thể in update notice nhẹ khi npm có bản mới hơn. Notice cho biết version hiện tại, version mới nhất và command để update:

Có bản Bestie mới: <current> -> <latest>
Chạy `bestie update --apply` để cài bản npm mới nhất.

Update notice dùng cache 24 giờ trong runtime data directory. Chat và daemon start hoặc restart path có thể kích hoạt notice này.

Chạy npm version check rõ ràng:

Terminal window
bestie update

Bestie đọc package name và version hiện tại từ package.json đã cài, hỏi npm registry version mới nhất, ghi update-check.json trong runtime data directory, rồi in current/latest version.

Nếu không kết nối được npm, Bestie vẫn in local version, báo npm check failed, gợi ý command cài thủ công và exit non-zero.

Apply update nếu có:

Terminal window
bestie update --apply

--apply chạy:

Terminal window
npm install -g bestie-agent@latest

Nếu install command thành công, mở terminal mới nếu shell của bạn vẫn cache binary bestie cũ. Nếu npm exit non-zero, Bestie báo exit code đó.

Chỉ dùng --apply khi môi trường cho phép sửa global npm installation. Trong CI hoặc host bị khóa, ưu tiên bestie update rồi để deployment process quyết định cách cài version mới.

Doctor exit non-zero khi phát hiện lỗi:

Terminal window
bestie doctor --json > doctor-report.json

Dùng exit code để fail CI hoặc setup scripts, và dùng JSON report để hiển thị các check bị fail.

Command arguments không hợp lệ cũng set hoặc trả về exit status non-zero. Với command destructive hoặc thay đổi state, chỉ dùng confirmation flag như --yes, --apply hoặc --confirm sau khi dry run đã ổn.

  • Ưu tiên --json hoặc raw export command khi có.
  • Set BESTIE_NO_BANNER=1 cho human-facing command được dùng trong scripts.
  • Set NO_COLOR=1 khi logs không nên chứa ANSI escape sequences.
  • Xem update notice là human output, không phải dữ liệu máy đọc được.
  • Giữ secrets trong .bestie/.env hoặc environment variables, không để trong command arguments hoặc logs.
  • Tránh parse decorative human table khi đã có JSON command.