AgentKit
Tài liệuBộ kitTham chiếu CLIỨng dụng Desktop
BetaBạn đang đọc tài liệu kênh beta (3.4.0-beta.1). Tính năng có thể thay đổi trước bản stable tiếp theo.Chuyển sang stable →

secrets

ak secrets import-env

Nhập hàng loạt bí mật từ một tệp dotenv hoặc một thư mục project.

Nhập hàng loạt bí mật từ một tệp dotenv hoặc một thư mục project.

Lệnh đọc file dotenv nhưng không sửa file đó. Mỗi key mới được ghi vào backend; --force mới ghi đè value đã có.

Khi <path> là một thư mục, lệnh tìm các file .env và .env.* trong đó (tối đa ba cấp), bỏ qua file mẫu, file sao lưu, symlink và thư mục ẩn hoặc thư mục dependency, rồi gộp thành một plan. Key xuất hiện ở nhiều file là xung đột và bị bỏ qua ở mọi nơi. --dry-run in plan mà không ghi gì; --project ghi một project chung cho mọi key thay vì lấy theo thư mục của từng file.

Dùng ak secrets import-env với đối số và tùy chọn dưới đây. Phần help nguyên bản giữ nguyên thuật ngữ, cú pháp, tác động và điều kiện thực thi của CLI để đối chiếu chính xác.

Khi bật đồng bộ vault, lần ghi cục bộ thành công sẽ khởi động push nền cho vault dùng backend hệ điều hành. Lệnh trả kết quả ngay. Dùng --no-push cho lần ghi này hoặc đặt AGENTKIT_SECRETS_AUTO_PUSH=0 để tắt push nền. Backend file đồng bộ khi bạn chạy ak secrets sync now.

Contract và help của lệnh

Bulk-import secrets from a dotenv file or a project directory

Synopsis

Parse <path> as a minimal dotenv file (KEY=value, KEY="quoted", KEY='quoted', # comments, blank lines) and store one secret per key. <path> must be at most 1 MiB. Values are never printed, logged, or included in --json output — only the imported/skipped counts and (with --verbose) a safe per-line reason are shown. Without --force, a key that already has a stored value is skipped rather than overwritten; --force overwrites instead. Use it when onboarding an existing .env-based project onto the secrets vault.

When <path> is a directory, import-env finds its dotenv files (.env and .env.*, up to three levels down, in path order) and imports them as one plan. It skips example, template and backup files (.env.example, .env.template, .env.bak, ...), dotenv-vault files, symbolic links, hidden and dependency directories, and lists each skipped file. A key defined in more than one file is a conflict: it is skipped everywhere and every place is named, so no file silently wins; a replace keeps an environment or project typed with annotate. The whole plan is printed, and --dry-run prints it without storing anything. Each imported key records its file as its source, the environment from the file name (.env.production: production) and the directory as its project, as imported profile text; --project names the project instead. Directory names and file names are only ever stored as text, never followed as instructions.

Effects: Writes one value per imported key to the active backend and updates each key's metadata, including its value hint (--no-hint records none), in ~/.agentkit/secrets/index.json. Never modifies <path> or any file under it. --dry-run writes nothing. With sync on, it then starts a background ak secrets sync now that pushes the change without waiting for it; --no-push or AGENTKIT_SECRETS_AUTO_PUSH=0 turns that off, and the file backend is never pushed in the background.

Exit status: 0 success 2 invalid flags or arguments, an unreadable path, a file over the 1 MiB import limit, or a directory with too many dotenv files 5 backend or index failure

ak secrets import-env <path> [flags]

Examples

  ak secrets import-env ${PATH}                    # skip keys that already exist
  ak secrets import-env ${PATH} --force             # overwrite existing keys too
  ak secrets import-env ${PATH} --verbose --json    # machine-readable per-line detail
  ak secrets import-env ${DIR} --dry-run           # preview a project directory import

Options

      --backend string                Storage backend: keychain (default), file (age-encrypted vault), or memory (dev/test; values and its index are throwaway)
      --dry-run                       Directory import: print the plan without storing anything
      --force                         Overwrite keys that already have a stored value
  -h, --help                          help for import-env
      --json                          Emit machine-readable JSON (implies --no-interactive)
      --no-hint                       Record no value hint for any imported key
      --no-interactive                Disable interactive prompts (CI-safe)
      --no-push ak secrets sync now   Do not push this change to the sync vault in the background (it syncs at the next ak secrets sync now)
      --project string                Directory import: record this project for every key instead of each file's directory
  -q, --quiet                         Suppress non-error output on stderr
      --unlock-with-recovery          Open the file backend's vault with a recovery private key and set a new passphrase
  -V, --verbose                       Extra diagnostic output on stderr (loses to --quiet)
  -y, --yes                           Assume yes for all prompts

SEE ALSO

  • ak secrets - Manage named secret values (API keys, tokens)