SuperAPI AI Directory

apifox-cli

Testing & quality

View repository

Updated 10-15 12:07

About this skill

Apifox CLI

Use the Apifox CLI to complete the user's request; do not assemble the payload from memory, and prioritize letting the CLI's --help、cli-schema、cli-schema validate、agentHints.nextSteps drive the next step.

New session check

  • When handling an Apifox CLI task for the first time, lightly confirm that the CLI is available:apifox --version、apifox --help。
  • If apifox does not exist or cannot output a version, install the CLI first:npm i -g apifox-cli@latest --registry=https://registry.npmmirror.com/。
  • After installation, run apifox login --with-token <TOKEN> to log in. An API access token can be created in the Apifox client or web app under "User avatar → Account settings → API access token".
  • Do not upgrade by default every time; only suggest an upgrade when a command returns a version-too-low/unknown command/missing parameter that is suspected to be caused by an old version, or when the user's task depends on new capabilities.

Basic usage

apifox --help
apifox <command> --help
apifox <command> <subcommand> --help

Common global parameters:

--project <projectId>     项目 ID
--branch <branchName>     分支名;纯数字值兼容旧 branchId
--access-token <token>    覆盖当前登录 token
--api-base-url <url>      私有部署地址

Login and projects

  • When not logged in, ask the user to provide an API access token and run:apifox login --with-token <TOKEN>。
  • Apifox CLI authentication credentials are stored in ~/.apifox/config.toml; do not print the token to logs, commit it to a repository, or write it into ordinary chat summaries.
  • If the user does not specify a project, first check whether .apifox/settings.jsonexists in the current workspace; if it contains a commonly used default projectId, prioritize using that project.
  • For the project ID, you can recommend that the user obtain it from "Project settings - Basic settings - Project ID"; or first run apifox project listand ask the user to confirm the target project for the command to be executed.
  • Ask the user before writing any local configuration file.

Standard write workflow

Mandatory: before executing create or update commands, you must first obtain the complete resource definition and data format, and before actually executing, use cli-schema validate to verify that the write is accurate. The specific workflow:

  1. Query the JSON schema of the execution command for the corresponding resource:apifox cli-schema get <schemaKey>
  2. Generate the JSON data file for the resource.
  3. Validate:apifox cli-schema validate <schemaKey> --file <path>
  4. Only after validate is correct, execute the actual create or update command.

After the command outputs results, prioritize reading the agentHints.nextSteps in the JSON output to continue execution or recovery.

CLI facts take precedence

  • Specific commands, parameters, and schema keys are subject to the current CLI output:apifox <command> --help、apifox cli-schema list、agentHints.nextSteps。
  • If this skill is inconsistent with the current CLI output, execute according to the current CLI output and synchronously correct the factual descriptions in this skill.

CLI write permission statement

  • When executing writes is restricted by AI (CLI source) permissions, if the user has not declared it, do not choose for the user; prioritize asking about the write method: enable direct edit permission for the target branch, or edit the target branch data on an AI branch.
  • If the user needs to directly edit data in the main branch, iteration branch, or common branch, ask the user to enable the switch for direct edit permission in the Apifox client version 2.8.32+ under "Project settings - Feature settings - AI feature settings - External AI edit permission".
  • If the user chooses the AI branch, the process is: step1: Create an AI branch and specify the source branch; step2: Import (pick-to) resources from the source branch as actually needed; step3: Edit the AI branch according to the user's needs; step4: Once done, remind the user to confirm whether to initiate a merge request or merge.
  • When executing merge/merge request directly from the CLI, the direct edit permission switches for both the source branch and the target branch are required to be enabled; otherwise, remind the user to first enable the permission switch for the corresponding branch type, or trigger the merge manually directly in the client.

AI Branch Description

  • An AI branch is an isolated branch for AI/automation to modify project resources, avoiding directly polluting the source branch.
  • If an AI branch has no difference from its source branch within 24 hours, it will be automatically archived.
  • An AI branch is initially empty and will not automatically clone the source branch resources; before editing/deleting existing resources in the source branch, first import them into the AI branch.
  • Newly created resources in the AI branch do not need to be imported first.
  • Changes in the AI branch will not be automatically written back to the source branch; after completion, the user must be asked to confirm whether to merge immediately or initiate a merge request.
  • When the target main branch is protected (isProtected), prioritize merge-request, do not directly merge。

Must ask the user

  • Login token, local configuration writing, private deployment address.
  • Create/switch AI branch, import source branch resources into the AI branch.
  • Destructive operations such as delete, archive, overwrite import, batch update.
  • Merge / merge-request AI branch changes back to the source branch.
  • Whether to upgrade the CLI.

Fault Recovery

Symptom Handling
Not logged in apifox login --with-token <TOKEN>
Don't know the project apifox project list
Don't know the command parameters apifox <command> --help
Parameter or schema error Run first cli-schema get / cli-schema validate
AI write restricted Explain the AI branch/permission switch and let the user choose
Private deployment Add --api-base-url https://your-server