manage-api-version

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

manage-api-version

管理API版本

Read and change the version of one or more API dependencies in a Mule project — the same values the Anypoint Studio Project Properties → API Specs tab sets. Each API dependency in the project gets its own version property in
pom.xml
, named by combining the dependency's
artifactId
with
.version
:
xml
<properties>
  <order-api.version>1.0.0</order-api.version>
  <customer-api.version>2.1.0</customer-api.version>
</properties>

读取并更改Mule项目中一个或多个API依赖的版本——这些版本与Anypoint Studio中项目属性→API规格标签设置的值一致。项目中的每个API依赖都会在
pom.xml
中拥有独立的版本属性,属性名称由依赖的
artifactId
加上
.version
组成:
xml
<properties>
  <order-api.version>1.0.0</order-api.version>
  <customer-api.version>2.1.0</customer-api.version>
</properties>

Overview

概述

This skill reads and updates
<{artifactId}.version>
properties in
pom.xml
. A Mule project can have one or more API dependencies, each with its own version property. The property name is always
{artifactId}.version
where
artifactId
is the Maven artifact ID of the API dependency.
What you'll do: Display all API versions or specific ones by name, check whether newer versions are available (for all APIs or specific ones), or update the version for one or more API dependencies in a single operation and rescaffold the project once all changes are applied.

本技能用于读取和更新
pom.xml
中的
<{artifactId}.version>
属性。一个Mule项目可以包含一个或多个API依赖,每个依赖都有自己的版本属性。属性名称始终为
{artifactId}.version
,其中
artifactId
是API依赖的Maven工件ID。
你可以执行的操作: 显示所有API版本或指定API的版本,检查是否有新版本可用(针对所有API或指定API),或者在单次操作中更新一个或多个API依赖的版本,并在所有更改应用后重新生成项目脚手架。

Prerequisites

前提条件

Before starting, verify these tools are available:
bash
anypoint-cli-v4 --version   # must be v4; needs exchange asset list
mvn --version               # Maven 3.6+ for rescaffold (CHANGE path only)
If
anypoint-cli-v4
is missing:
bash
npm install -g @mulesoft/anypoint-cli-v4
anypoint-cli-v4 conf username <username>
anypoint-cli-v4 conf password <password>
The CHECK and CHANGE paths query Exchange. If the CLI is not authenticated or network is unavailable, display-only operations (DISPLAY ALL, DISPLAY SPECIFIC) still work — they read from
pom.xml
only.

开始前,请确认以下工具已可用:
bash
anypoint-cli-v4 --version   # 必须为v4版本;需要exchange asset list功能
mvn --version               # 重新搭建项目需要Maven 3.6+(仅CHANGE流程需要)
如果缺少
anypoint-cli-v4
:
bash
npm install -g @mulesoft/anypoint-cli-v4
anypoint-cli-v4 conf username <用户名>
anypoint-cli-v4 conf password <密码>
CHECK和CHANGE流程会查询Exchange。如果CLI未认证或网络不可用,仅显示类操作(DISPLAY ALL、DISPLAY SPECIFIC)仍可正常工作——它们仅从
pom.xml
读取数据。

Bundled Scripts

内置脚本

This skill ships one shell helper in its own
scripts/
directory:
ScriptPurpose
scripts/fetch_versions.sh <groupId>:<artifactId>:<currentVersion> [...]
Resolves the full published-version list for one or more API dependencies in a single invocation, firing one Exchange lookup per API in parallel instead of the agent looping and calling
anypoint-cli-v4
once per API sequentially. See Version Discovery under Step 7b for full usage and output shape.
Invoke it with the
Bash
tool at the absolute path you were given in the "skill is now active" message (the directory containing this
SKILL.md
) — e.g.
<skill-dir>/scripts/fetch_versions.sh ...
. Do not construct a relative
../scripts/...
path; the working directory shifts across turns and relative paths break.

本技能在自身的
scripts/
目录中包含一个Shell辅助脚本:
脚本用途
scripts/fetch_versions.sh <groupId>:<artifactId>:<currentVersion> [...]
一次性解析一个或多个API依赖的完整已发布版本列表,针对每个API并行发起一次Exchange查询,而非由Agent循环逐个调用
anypoint-cli-v4
。有关完整用法和输出格式,请查看步骤7b下的「版本发现」部分。
使用
Bash
工具调用该脚本时,请使用「技能已激活」消息中提供的绝对路径(包含本
SKILL.md
的目录)——例如
<skill-dir>/scripts/fetch_versions.sh ...
。请勿使用相对路径
../scripts/...
;工作目录会在交互过程中切换,相对路径会失效。

Execution Paths

执行流程

User intentPath
display/check current version — all APIs or no specific one named→ DISPLAY ALL (Steps 1 → 2 → 3)
display/check current version — one or more specific APIs named→ DISPLAY SPECIFIC (Steps 1 → 2 → 4)
any new/updated versions available — no specific API named→ CHECK ALL (Steps 1 → 2 → 5)
any new/updated versions available — one or more specific APIs named→ CHECK SPECIFIC (Steps 1 → 2 → 6)
set, change, adjust, update, bump, switch version→ CHANGE (Steps 1 → 2 → 7 → 8 → 9)

用户意图流程
显示/检查当前版本——所有API或未指定具体API→ DISPLAY ALL(步骤1 → 2 → 3)
显示/检查当前版本——指定一个或多个API→ DISPLAY SPECIFIC(步骤1 → 2 → 4)
检查是否有新版本可用——未指定具体API→ CHECK ALL(步骤1 → 2 → 5)
检查是否有新版本可用——指定一个或多个API→ CHECK SPECIFIC(步骤1 → 2 → 6)
设置、更改、调整、更新、升级、切换版本→ CHANGE(步骤1 → 2 → 7 → 8 → 9)

Step 1: Resolve Project Directory

步骤1:确定项目目录

Resolve the project root using the best available signal, in this order:
  1. Exact path supplied — use it directly.
  2. Rough location or folder name given (e.g. "the order-api project", "in my documents", "the one in ~/projects") — use
    find
    to locate a
    pom.xml
    matching that hint and confirm with the user if more than one match is found.
  3. Multiple projects open/in scope and an API name was given, but no project hint (e.g. a multi-root workspace, or more than one
    pom.xml
    reachable from context) — before falling back to "current/active project," check whether the named API's
    <{artifactId}.version>
    property (or a matching hardcoded
    <dependency>
    artifactId) exists in only one of the open projects'
    pom.xml
    files:
    • Unique match — use that project silently. Do not ask; a name that only exists in one place is not actually ambiguous.
    • Matches multiple projects — ask which project, the same way as case 5 below.
    • Matches none of the open projects — do not ask "which project" (that implies the project is the problem, when it's more likely the API name). Instead say:
      I couldn't find an API named
      <name>
      in any of the open projects (
      <list the open project names/paths>
      ). Did you mean a different API name, or is it in a project that isn't open right now? This check only applies when 2+ projects are genuinely in scope. With a single open/reachable project, skip straight to case 4 — never ask when there's nothing to disambiguate.
  4. Current working directory implied (e.g. "this project", "the current one"), or only one project is in scope — check if
    pom.xml
    exists in the current directory and use it.
  5. Nothing given — no project hint AND no API name to disambiguate by — with multiple projects in scope — this includes fully generic requests like "update the API version" or "check for updates" when 2+ projects are open and no prior project has been established this conversation. Do not guess a "current directory" in this case, even if one happens to be technically active (e.g. whichever file tab last had focus) — a generic request with no name or path given is exactly the ambiguous case this step exists to catch. Ask:
What project do you want to work on? You can give me the full path, a folder name, or just tell me it's the current directory.
Confirm
pom.xml
exists at the resolved path before continuing.
Ask at most once per conversation. Once the user has stated or confirmed which project they mean, keep using it for subsequent requests in the same conversation — don't re-ask on every turn. If the user later names a different project or a different API that resolves elsewhere, switch silently and confirm the switch in the response (e.g. "Switching to
<project>
for this one.") rather than re-running the full disambiguation question.
STOP (only if the project cannot be resolved from context).

按以下优先级确定项目根目录:
  1. 提供了精确路径——直接使用该路径。
  2. 提供了大致位置或文件夹名称(例如「order-api项目」「在我的文档中」「~/projects下的那个项目」)——使用
    find
    命令定位符合提示的
    pom.xml
    ,如果找到多个匹配项,请与用户确认。
  3. 打开了多个项目/处于多项目范围,且指定了API名称但未提供项目提示(例如多根工作区,或从上下文可访问多个
    pom.xml
    )——在回退到「当前/活动项目」之前,检查指定API的
    <{artifactId}.version>
    属性(或匹配的硬编码
    <dependency>
    artifactId)是否仅存在于其中一个打开项目的
    pom.xml
    中:
    • 唯一匹配——静默使用该项目。无需询问;仅在一个项目中存在的名称不存在歧义。
    • 匹配多个项目——询问用户选择哪个项目,方式与下文第5种情况相同。
    • 未匹配任何打开的项目——请勿询问「哪个项目」(这暗示问题出在项目上,但更可能是API名称错误)。请改为提示:
      我在所有打开的项目(<列出打开的项目名称/路径>)中未找到名为
      <name>
      的API。你是否指其他API名称,或者该API所在项目未打开? 此检查仅适用于确实存在2个及以上项目的场景。如果只有一个打开/可访问的项目,请直接跳至第4种情况——无需询问,因为没有需要消除歧义的内容。
  4. 暗示使用当前工作目录(例如「这个项目」「当前项目」),或仅存在一个项目范围——检查当前目录是否存在
    pom.xml
    并使用它。
  5. 未提供任何信息——既无项目提示也无API名称用于消除歧义——且存在多个项目范围——这包括完全通用的请求,例如「更新API版本」或「检查更新」,且当前对话中未指定过项目。在这种情况下,请勿猜测「当前目录」,即使技术上存在活跃目录(例如最后获得焦点的文件标签所在目录)——无名称或路径的通用请求正是此步骤要处理的歧义场景。请询问:
你想操作哪个项目?你可以提供完整路径、文件夹名称,或者直接告诉我是当前目录。
继续操作前,请确认解析后的路径中存在
pom.xml
。
每次对话最多询问一次。一旦用户说明或确认了要操作的项目,在本次对话的后续请求中持续使用该项目——无需每次都重新询问。如果用户后续指定了不同项目或可解析到其他位置的API,请静默切换并在响应中确认切换(例如「本次操作将切换至
<project>
项目」),而非重新执行完整的消除歧义流程。
终止流程(仅当无法从上下文确定项目时)。

Step 2: Route Operation

步骤2:路由操作

Parse the user's request for intent keywords:
KeywordsOperation
get, show, find, display, what is, current — all / every / no specific API named→ DISPLAY ALL
get, show, find, display, what is, current — one or more specific APIs named→ DISPLAY SPECIFIC
any new, updates, newer, latest, upgrade — no specific API named→ CHECK ALL
any new, updates, newer, latest, upgrade — one or more specific APIs named→ CHECK SPECIFIC
set, change, adjust, update, bump, switch→ CHANGE
If intent is ambiguous, ask:
Do you want to display the current API version(s), or change one?
STOP (only if operation cannot be determined from the request).

解析用户请求中的意图关键词:
关键词操作
get、show、find、display、what is、current —— all / every / 未指定具体API→ DISPLAY ALL
get、show、find、display、what is、current —— 指定一个或多个API→ DISPLAY SPECIFIC
any new、updates、newer、latest、upgrade —— 未指定具体API→ CHECK ALL
any new、updates、newer、latest、upgrade —— 指定一个或多个API→ CHECK SPECIFIC
set、change、adjust、update、bump、switch→ CHANGE
如果意图不明确,请询问:
你想要显示当前API版本,还是更改某个API版本?
终止流程(仅当无法从请求中确定操作类型时)。

Step 3: Show All API Versions (Display All)

步骤3:显示所有API版本(Display All)

  1. Read
    pom.xml
    . Find all properties inside
    <properties>
    whose name ends in
    .version
    and corresponds to an API spec dependency. To identify API spec dependencies, check the matching
    <dependency>
    block:
    • Classifier check (preferred): API spec deps use one of these classifiers:
      raml
      ,
      oas
      ,
      graphql
      ,
      protobuf
      ,
      fat-protobuf
      ,
      evented-api
      . Connectors use
      mule-plugin
      . If a classifier is present and matches this list, it is an API spec.
    • artifactId fallback: If no classifier is set, check whether the
      artifactId
      contains the word
      api
      — this is the common naming convention for API spec artifacts. Skip any dependency whose classifier is
      mule-plugin
      or that matches neither signal.
  2. Print all matching ones:
API dependency versions (from pom.xml <properties>):

  order-api.version    → 1.0.0
  customer-api.version → 2.1.0
  1. If none are found, say so clearly and suggest the user check the Project Properties → API Specs tab in Anypoint Studio to confirm APIs are added to the project.
End the skill here for the DISPLAY ALL path.

  1. 读取
    pom.xml
    。找到
    <properties>
    中所有名称以
    .version
    结尾且对应API规格依赖的属性。要识别API规格依赖,请检查对应的
    <dependency>
    块:
    • 分类器检查(首选):API规格依赖使用以下分类器之一:
      raml
      、
      oas
      、
      graphql
      、
      protobuf
      、
      fat-protobuf
      、
      evented-api
      。连接器使用
      mule-plugin
      。如果存在分类器且符合此列表,则为API规格依赖。
    • artifactId回退:如果未设置分类器,请检查
      artifactId
      是否包含
      api
      一词——这是API规格工件的常见命名约定。 跳过分类器为
      mule-plugin
      或不符合上述任一条件的依赖。
  2. 打印所有匹配的版本信息:
API依赖版本(来自pom.xml <properties>):

  order-api.version    → 1.0.0
  customer-api.version → 2.1.0
  1. 如果未找到任何API依赖,请明确告知用户,并建议用户检查Anypoint Studio中的「项目属性→API规格」标签,确认已将API添加到项目中。
DISPLAY ALL流程至此结束。

Step 4: Show Versions for Named APIs (Display Specific)

步骤4:显示指定API的版本(Display Specific)

  1. Extract all API names the user specified. If none were named, fall back to DISPLAY ALL.
  2. Read
    pom.xml
    . For each named API, find its
    <{artifactId}.version>
    property.
  3. Print each result:
order-api.version    → 1.0.0
customer-api.version → 2.1.0
  1. If a named API's property is not found, flag it and list the available API version properties so the user can confirm the correct name.
End the skill here for the DISPLAY SPECIFIC path.

  1. 提取用户指定的所有API名称。如果未指定任何API,则回退到DISPLAY ALL流程。
  2. 读取
    pom.xml
    。对于每个指定的API,找到其
    <{artifactId}.version>
    属性。
  3. 打印每个结果:
order-api.version    → 1.0.0
customer-api.version → 2.1.0
  1. 如果未找到指定API的属性,请标记该API,并列出可用的API版本属性,以便用户确认正确名称。
DISPLAY SPECIFIC流程至此结束。

Step 5: Check All APIs for Newer Versions (Check All)

步骤5:检查所有API是否有新版本(Check All)

  1. Read
    pom.xml
    and identify all API spec dependencies (same classifier/artifactId logic as DISPLAY ALL).
  2. For each API, discover its full version list using the Version Discovery procedure below.
  3. Report results:
    If newer versions exist for any API:
    Newer versions available:
    
      order-api:    current 1.0.0 → latest 2.0.0
      customer-api: current 1.5.0 → latest 1.6.0
    
    No updates available:
      billing-api: 3.1.0 (already latest)
    
    Would you like to update any of these?
    STOP — if the user wants to update, transition to the CHANGE path starting at Step 7 for the APIs they name.
    If no newer versions exist for any API:
    All APIs are on their latest versions:
    
      order-api:    1.0.0
      customer-api: 2.1.0
      billing-api:  3.1.0
    
    Would you like to change any version anyway?
    STOP — if yes, transition to CHANGE path at Step 7.
End the skill here if the user does not want to make any changes.

  1. 读取
    pom.xml
    并识别所有API规格依赖(与DISPLAY ALL流程使用相同的分类器/artifactId逻辑)。
  2. 对于每个API,使用下文的版本发现流程获取其完整版本列表。
  3. 报告结果:
    如果任何API存在新版本:
    有新版本可用:
    
      order-api:    当前版本 1.0.0 → 最新版本 2.0.0
      customer-api: 当前版本 1.5.0 → 最新版本 1.6.0
    
    无可用更新:
      billing-api: 3.1.0(已是最新版本)
    
    是否要更新其中某些API?
    终止流程 —— 如果用户想要更新,则从步骤7开始进入CHANGE流程,处理用户指定的API。
    如果所有API都已是最新版本:
    所有API均为最新版本:
    
      order-api:    1.0.0
      customer-api: 2.1.0
      billing-api:  3.1.0
    
    是否仍要更改某些API的版本?
    终止流程 —— 如果是,则从步骤7开始进入CHANGE流程。
如果用户不想进行任何更改,流程至此结束。

Step 6: Check Named APIs for Newer Versions (Check Specific)

步骤6:检查指定API是否有新版本(Check Specific)

  1. Extract the API name(s) the user specified.
  2. For each named API, discover its full version list using the Version Discovery procedure below, and compare against the current version to determine if a newer one exists.
  3. Go through each named API one at a time in the order the user asked:
    If a newer version exists:
    order-api — current: 1.0.0
    A newer version is available: 2.0.0
    
    Would you like to update it?
    STOP — if yes, proceed with the CHANGE flow for this API (Step 7c onwards). If no, move to the next named API.
    If already on the latest version:
    order-api is already on the latest version: 1.0.0
    
    Would you like to change it to a different version anyway?
    STOP — if yes, proceed with the CHANGE flow for this API (Step 7c onwards). If no, move to the next named API.
  4. After all named APIs have been addressed, if any were queued for change, proceed to Step 8.

  1. 提取用户指定的API名称。
  2. 对于每个指定的API,使用下文的版本发现流程获取其完整版本列表,并与当前版本比较以确定是否存在新版本。
  3. 按照用户询问的顺序逐个处理每个指定的API:
    如果存在新版本:
    order-api — 当前版本:1.0.0
    有新版本可用:2.0.0
    
    是否要更新该API?
    终止流程 —— 如果是,则针对该API继续执行CHANGE流程(从步骤7c开始)。如果否,则处理下一个指定的API。
    如果已是最新版本:
    order-api已是最新版本:1.0.0
    
    是否仍要将其更改为其他版本?
    终止流程 —— 如果是,则针对该API继续执行CHANGE流程(从步骤7c开始)。如果否,则处理下一个指定的API。
  4. 处理完所有指定API后,如果有任何API需要更改,则继续执行步骤8。

Step 7: Identify Target APIs and Fetch Available Versions (Change)

步骤7:确定目标API并获取可用版本(Change)

7a — Identify which APIs to change

7a — 确定要更改的API

If the user named the API(s) to update, use those. Otherwise:
  1. Read
    pom.xml
    and list all API dependency version properties.
  2. Ask which API(s) they want to update.
STOP (only if target API(s) not pre-supplied).
如果用户已指定要更新的API,则使用这些API。否则:
  1. 读取
    pom.xml
    并列出所有API依赖版本属性。
  2. 询问用户要更新哪些API。
终止流程(仅当未提供目标API时)。

7b — Fetch available versions from Exchange

7b — 从Exchange获取可用版本

Before querying, back up the current pom.xml content in memory so it can be restored if anything fails later.
Read
groupId
and
artifactId
from the
<dependency>
block in
pom.xml
for every target API, then discover all of their version lists in a single call using the Version Discovery procedure below — pass all target APIs as separate arguments to the same script invocation, never one invocation per API.
If any row comes back with
"source": "error"
(both
list
and the
describe
fallback failed for that API):
  • If no pom.xml changes have been made yet, stop and tell the user, citing the row's
    error
    field:
    Failed to fetch versions from Exchange for
    <artifactId>
    . Check that
    anypoint-cli-v4
    is authenticated and you have network access, then try again.
  • If pom.xml was already partially modified in a prior step, restore it to the backed-up state before stopping with the same message.

查询前,请将当前pom.xml内容备份到内存中,以便在后续出现任何问题时恢复。
从
pom.xml
的
<dependency>
块中读取每个目标API的
groupId
和
artifactId
,然后使用下文的版本发现流程一次性获取所有目标API的版本列表——将所有目标API作为单独参数传递给同一个脚本调用,请勿逐个调用脚本。
如果任何返回行的
"source": "error"
(
list
和
describe
回退方式均对该API失败):
  • 如果尚未对pom.xml进行任何更改,请终止流程并告知用户,引用该行的
    error
    字段:
    无法从Exchange获取
    <artifactId>
    的版本列表。请确认
    anypoint-cli-v4
    已认证且网络可用,然后重试。
  • 如果pom.xml已在之前的步骤中被部分修改,请先将其恢复到备份状态,再终止流程并显示相同消息。

Version Discovery (shared procedure — used by Steps 5, 6, 7b)

版本发现(共享流程——用于步骤5、6、7b)

Discover versions for ALL target APIs in ONE call to the bundled script — never loop and invoke
anypoint-cli-v4
yourself, one API at a time.
Each direct
anypoint-cli-v4
invocation pays a full Node CLI cold start plus a network round trip; looping that per API serializes N round trips where one script call does them in parallel and returns once. This is the single biggest lever for making this skill feel fast, especially on projects with several API dependencies.
Invoke the script with the
Bash
tool at its absolute path —
<skill-dir>/scripts/fetch_versions.sh
, where
<skill-dir>
is the absolute path you were given in the "skill is now active" message (the directory containing this
SKILL.md
). Do not construct a relative
../scripts/...
path; the working directory shifts across turns and relative paths break.
Pass one
<groupId>:<artifactId>:<currentVersion>
argument per target API — for Steps 5 and 6 that's every API identified in that step; for Step 7b that's every API in the change set:
bash
<skill-dir>/scripts/fetch_versions.sh \
  "<groupId1>:<artifactId1>:<currentVersion1>" \
  "<groupId2>:<artifactId2>:<currentVersion2>"
The script prints one JSON array to stdout, one object per input API, in input order:
json
[
  {
    "groupId": "org.example", "artifactId": "order-api", "currentVersion": "1.0.0",
    "versions": ["2.0.0", "1.1.0", "1.0.0"],
    "source": "list"
  }
]
Read each row's
source
field:
  • "list"
    — the normal path. Internally this ran
    exchange asset list <artifactId> --output json
    , filtered to rows matching the exact
    groupId
    /
    assetId
    , sorted by semver (highest first). Trust this fully — it is not anchored to any single version, so it doesn't have the false-negative failure mode described below.
  • "describe-fallback"
    —
    list
    returned zero matching rows for this asset, so the script fell back to
    exchange asset describe <groupId>/<artifactId>/<currentVersion>
    and parsed its
    otherVersions
    field. Surface the row's
    warning
    field to the user verbatim —
    describe
    's version list is anchored to the version you query with and has been observed to come back empty when that anchor version is not the latest published one, even when newer versions genuinely exist. Since CHECK/CHANGE always query from whatever version is currently pinned in
    pom.xml
    (almost never the latest), treat this row's version list as possibly incomplete.
  • "error"
    — both
    list
    and the
    describe
    fallback failed for this asset. Surface the row's
    error
    field. For Step 7b (CHANGE), treat this the same as an Exchange-fetch failure (see below). For Steps 5/6 (CHECK), report the failure for that specific API and continue processing the others — don't abort the whole check over one API's lookup failure.
(This mirrors the pattern already used by two sibling skills in this repo —
build-mule-integration/scripts/search_templates.sh
and
manage-global-configurations/scripts/get_latest_connector.sh
— which fire multiple
exchange asset list
calls in parallel rather than looping sequentially, for the same latency reason.)
一次性调用内置脚本获取所有目标API的版本——请勿循环逐个调用
anypoint-cli-v4
。每次直接调用
anypoint-cli-v4
都会经历完整的Node CLI冷启动和网络往返;逐个API循环调用会导致N次串行往返,而一次脚本调用可并行处理所有API并一次性返回结果。这是提升本技能响应速度的关键,尤其是在包含多个API依赖的项目中。
使用
Bash
工具调用脚本时,请使用其绝对路径——
<skill-dir>/scripts/fetch_versions.sh
,其中
<skill-dir>
是「技能已激活」消息中提供的绝对路径(包含本
SKILL.md
的目录)。请勿使用相对路径
../scripts/...
;工作目录会在交互过程中切换,相对路径会失效。
为每个目标API传递一个
<groupId>:<artifactId>:<currentVersion>
参数——步骤5和6中为该步骤识别的所有API;步骤7b中为所有待更改的API:
bash
<skill-dir>/scripts/fetch_versions.sh \
  "<groupId1>:<artifactId1>:<currentVersion1>" \
  "<groupId2>:<artifactId2>:<currentVersion2>"
脚本会向标准输出打印一个JSON数组,每个输入API对应一个对象,按输入顺序排列:
json
[
  {
    "groupId": "org.example", "artifactId": "order-api", "currentVersion": "1.0.0",
    "versions": ["2.0.0", "1.1.0", "1.0.0"],
    "source": "list"
  }
]
读取每行的
source
字段:
  • "list"
    —— 正常流程。内部执行
    exchange asset list <artifactId> --output json
    ,过滤出匹配精确
    groupId
    /
    assetId
    的行,并按语义化版本排序(从高到低)。完全信任此结果——它不锚定到任何单个版本,因此不存在下文所述的假阴性失败模式。
  • "describe-fallback"
    ——
    list
    未返回该资产的匹配行,因此脚本回退到
    exchange asset describe <groupId>/<artifactId>/<currentVersion>
    并解析其
    otherVersions
    字段。将该行的
    warning
    字段原封不动地展示给用户——
    describe
    的版本列表锚定到查询时使用的版本,已观察到当锚定版本不是最新发布版本时,即使存在新版本,返回的版本列表也可能为空。由于CHECK/CHANGE流程始终从当前固定在
    pom.xml
    中的版本(几乎从未是最新版本)进行查询,请将该行的版本列表视为可能不完整。
  • "error"
    ——
    list
    和
    describe
    回退方式均对该资产失败。展示该行的
    error
    字段。对于步骤7b(CHANGE),处理方式与Exchange获取失败相同(见下文)。对于步骤5/6(CHECK),报告该API的查询失败并继续处理其他API——请勿因一个API的查询失败而终止整个检查流程。
(这与本仓库中两个同类技能使用的模式一致——
build-mule-integration/scripts/search_templates.sh
和
manage-global-configurations/scripts/get_latest_connector.sh
——它们并行发起多个
exchange asset list
调用而非串行循环,以减少延迟。)

7c — Present available versions and handle selection

7c — 展示可用版本并处理选择

For each target API, present the available versions as a single
AskUserQuestion
tool call
— do not narrate the version list as plain chat text first and then also call the tool; that produces two renderings of the same question. The tool call itself is the only presentation. If a newer version than the current one exists, mention it in the question text; list every available version as an option (current version included, labeled), plus a "Keep current version" style option is not needed since the current version already appears in the list:
question: "order-api — current: 1.0.0. A newer version is available: 2.0.0. Which version would you like to use?"
options:
  - "2.0.0"
  - "1.1.0"
  - "1.0.0 (current, no change)"
  - "0.9.0"
If the current version is already the latest, drop the "newer version available" sentence from the question text but still call the tool the same way:
question: "order-api — current: 2.0.0. Which version would you like to use?"
options:
  - "2.0.0 (current, no change)"
  - "1.1.0"
  - "1.0.0"
When changing multiple APIs, handle them one at a time: issue one
AskUserQuestion
call for the first API, STOP, get the selection, then move to the next API and repeat with a new
AskUserQuestion
call.
STOP — wait for the tool's response for the current API before presenting the next. Never restate the question or option list as a separate chat message before or after the tool call.
对于每个目标API,通过单次
AskUserQuestion
工具调用展示可用版本——请勿先以普通聊天文本叙述版本列表,再调用工具;这会导致同一问题被重复展示。工具调用本身就是唯一的展示方式。如果存在比当前版本更新的版本,请在问题文本中提及;将所有可用版本作为选项列出(包含当前版本并标注),无需额外添加「保留当前版本」选项,因为当前版本已在列表中:
question: "order-api — 当前版本: 1.0.0。有新版本可用: 2.0.0。你想要使用哪个版本?"
options:
  - "2.0.0"
  - "1.1.0"
  - "1.0.0 (当前版本,无更改)"
  - "0.9.0"
如果当前版本已是最新版本,请从问题文本中删除「有新版本可用」语句,但仍以相同方式调用工具:
question: "order-api — 当前版本: 2.0.0。你想要使用哪个版本?"
options:
  - "2.0.0 (当前版本,无更改)"
  - "1.1.0"
  - "1.0.0"
当更改多个API时,请逐个处理:为第一个API发起一次
AskUserQuestion
调用,终止流程,获取选择结果,然后处理下一个API并重复调用
AskUserQuestion
。
终止流程 —— 等待当前API的工具响应后再展示下一个API的选项。请勿在工具调用前后以单独的聊天消息重述问题或选项列表。

7d — Handle same-version selection

7d — 处理选择相同版本的情况

If the user selects the version already applied for a given API, respond:
order-api
is already on version
1.0.0
— no changes made.
Remove that API from the change set. If all APIs in the request were no-ops, end the skill here. Otherwise continue with the remaining APIs that do have a version change.

如果用户选择了某个API已应用的版本,请响应:
order-api
当前已是
1.0.0
版本——未进行任何更改。
将该API从更改集中移除。如果请求中的所有API均无需更改,则流程至此结束。否则继续处理剩余需要更改版本的API。

Step 8: Apply the New Version (Change)

步骤8:应用新版本(Change)

8a — Update
pom.xml

8a — 更新
pom.xml

For each API in the change set, determine which case applies:
Case 1 — Property placeholder already exists (
<{artifactId}.version>
is in
<properties>
): Update the value in the
<properties>
block. The dependency itself (
<version>${order-api.version}</version>
) does not need to change.
bash
ARTIFACT_ID="order-api"
NEW_VERSION="1.1.0"

awk -v key="${ARTIFACT_ID}.version" -v val="$NEW_VERSION" '
  $0 ~ "<" key ">" { sub(/>.*</, ">" val "<") }
  { print }
' pom.xml > pom.xml.tmp && mv pom.xml.tmp pom.xml
Case 2 — Version is hardcoded directly in the dependency (no
<{artifactId}.version>
property exists, dependency has a literal
<version>1.0.0</version>
): This means the project is not yet using the placeholder pattern. Do both:
  1. Add
    <{artifactId}.version>NEW</{artifactId}.version>
    to the
    <properties>
    block.
  2. Replace the hardcoded
    <version>1.0.0</version>
    inside that dependency's block with
    <version>${order-api.version}</version>
    .
Repeat for each API in the change set, applying all edits before writing the file.
对于更改集中的每个API,确定适用的情况:
情况1 — 属性占位符已存在(
<{artifactId}.version>
在
<properties>
中): 更新
<properties>
块中的值。无需更改依赖本身(
<version>${order-api.version}</version>
)。
bash
ARTIFACT_ID="order-api"
NEW_VERSION="1.1.0"

awk -v key="${ARTIFACT_ID}.version" -v val="$NEW_VERSION" '
  $0 ~ "<" key ">" { sub(/>.*</, ">" val "<") }
  { print }
' pom.xml > pom.xml.tmp && mv pom.xml.tmp pom.xml
情况2 — 版本硬编码在依赖中(不存在
<{artifactId}.version>
属性,依赖中包含字面量
<version>1.0.0</version>
): 这意味着项目尚未使用占位符模式。请执行以下两项操作:
  1. 在
    <properties>
    块中添加
    <{artifactId}.version>NEW</{artifactId}.version>
    。
  2. 将该依赖块中的硬编码
    <version>1.0.0</version>
    替换为
    <version>${order-api.version}</version>
    。
对更改集中的每个API重复上述操作,在写入文件前应用所有编辑。

8b — Confirm

8b — 确认更改

Print a summary of all changes made:
Updated in pom.xml:
  order-api.version:    1.0.0 → 1.1.0
  customer-api.version: 1.5.0 → 2.0.0

打印所有已执行更改的摘要:
已在pom.xml中更新:
  order-api.version:    1.0.0 → 1.1.0
  customer-api.version: 1.5.0 → 2.0.0

Step 9: Rescaffold the Project (Change)

步骤9:重新生成项目脚手架(Change)

After all version properties are updated, trigger APIkit to regenerate flows from the new API spec versions — the same operation Anypoint Studio runs when you save changes in the Project Properties → API Specs tab. If multiple APIs were changed in the same operation, flows for all of them are regenerated in this single pass.
Run the following from the project root, exactly as shown — two commands only, joined with
&&
, nothing else appended:
bash
cd <projectDir> && mvn clean package -DskipTests
  • Never append
    2>&1
    ,
    >
    ,
    >>
    , or any other redirection to this command, and never pipe it into anything.
    The tool invocation already captures stdout and stderr in full, so redirection adds nothing — and it has a real side effect: the host IDE's command layer treats stream-redirection operators as unsafe and forces a manual approval prompt even for an otherwise-trusted command, which is exactly what this step must avoid.
  • Do not add flags or bundle it with anything else — only the exact
    cd <projectDir> && mvn clean package -DskipTests
    shape above.
  • Do not pause for user confirmation before running this. Rescaffolding after a version change is automatic in the real product — Anypoint Studio runs it the instant
    pom.xml
    changes, or the instant the user touches the Project Properties → API Specs tab — with no click-through step for the human. This skill mirrors that: run the command as soon as Step 8's edits are written, without asking.
  • Wait for the full output before continuing.
  • BUILD SUCCESS
    means APIkit has pulled in the updated spec versions and regenerated the corresponding flows. The project is now consistent with all changed API versions.
  • If
    BUILD FAILURE
    occurs: automatically restore
    pom.xml
    to its pre-change state, then report the Maven error output verbatim so the user can investigate:
    Build failed — pom.xml has been restored to its previous state. Maven error: [output here]
One
mvn
invocation per response.
Do not bundle it with any other tool call.

更新所有版本属性后,触发APIkit从新的API规格版本重新生成流——这与Anypoint Studio中保存「项目属性→API规格」标签更改时执行的操作相同。如果在单次操作中更改了多个API,则所有API的流会在本次流程中重新生成。
从项目根目录运行以下命令,完全按照所示格式——仅两个命令,用
&&
连接,无其他附加内容:
bash
cd <projectDir> && mvn clean package -DskipTests
  • 请勿为该命令添加
    2>&1
    、
    >
    、
    >>
    或任何其他重定向操作,也请勿将其管道输出到其他命令
    。工具调用已完整捕获标准输出和标准错误,重定向毫无意义——且会产生实际副作用:主机IDE的命令层会将流重定向运算符视为不安全操作,即使是其他受信任的命令也会强制要求手动确认,而本步骤必须避免这种情况。
  • 请勿添加任何标志或与其他命令捆绑——仅使用上述精确格式
    cd <projectDir> && mvn clean package -DskipTests
    。
  • 运行前请勿暂停等待用户确认。在实际产品中,版本更改后重新生成脚手架是自动的——Anypoint Studio会在
    pom.xml
    更改或用户修改「项目属性→API规格」标签时立即执行该操作,无需人工点击确认步骤。本技能与此保持一致:步骤8的编辑完成后立即运行该命令,无需询问。
  • 等待命令执行完成后再继续。
  • BUILD SUCCESS
    表示APIkit已拉取更新后的规格版本并重新生成了对应的流。项目现在与所有已更改的API版本保持一致。
  • 如果出现
    BUILD FAILURE
    :自动将
    pom.xml
    恢复到更改前的状态,然后原封不动地报告Maven错误输出,以便用户排查:
    构建失败——pom.xml已恢复到之前的状态。Maven错误:[此处输出错误信息]
每次响应仅执行一次
mvn
调用
。请勿将其与文件编辑或其他命令捆绑。

Rules

规则

  • Property name is always
    {artifactId}.version
    — derived from the Maven
    artifactId
    of the API dependency, not a hardcoded tag like
    <apiVersion>
    .
  • Never touch
    <version>
    (the Maven artifact version at the top of
    pom.xml
    ). That is a different field entirely.
  • Always show available versions before applying a change. Never ask the user to type a version string — always fetch from Exchange and present the list first.
  • Newer version callout only when one exists. Only show the "a newer version is available" message if the current version is not already the latest. Never show it otherwise.
  • Same version is a no-op, not an error. If the user picks the already-applied version, say so and exclude that API from the change set. If all selections are no-ops, end without writing any files or running
    mvn
    .
  • Batch all changes, then rescaffold once. Apply all pom.xml edits before running
    mvn
    . Never rescaffold between individual API updates — one
    mvn
    pass at the end covers all of them.
  • Always back up pom.xml before writing. Hold the original content in memory at the start of every CHANGE operation. Restore it automatically on any failure — Exchange fetch error, mvn failure, or anything else that prevents successful completion.
  • Rescaffold is mandatory after every CHANGE, and it is automatic — never a user prompt. Never declare the version updated without running
    mvn clean package -DskipTests
    and confirming
    BUILD SUCCESS
    . A version change without rescaffolding leaves the project inconsistent. Run it immediately after Step 8's edits with no confirmation question, matching how Anypoint Studio itself rescaffolds automatically on a pom.xml change or an API Specs tab edit.
  • Never redirect the
    mvn
    command's output.
    No
    2>&1
    ,
    >
    ,
    >>
    , or pipes — the tool call already captures full stdout/stderr, and redirection operators can trip the host IDE's unsafe-command check and force an unwanted manual approval.
  • One
    mvn
    invocation per response.
    Do not bundle it with file edits or other commands.
  • No Anypoint CLI needed for pom.xml edits — use bash + Read/Edit tools only.
  • jq
    is required
    by
    scripts/fetch_versions.sh
    for parsing Exchange JSON responses. If
    jq
    is not available on the machine running the script, it will fail — there is no separate manual fallback path; install
    jq
    rather than reimplementing the script's parsing inline.
  • Version discovery is always one call to
    scripts/fetch_versions.sh
    covering every target API, never a per-API loop of raw
    anypoint-cli-v4
    invocations.
    See the Version Discovery procedure under Step 7b. The script runs
    exchange asset list
    (not version-anchored) in parallel across all target APIs, falling back to
    exchange asset describe
    's
    otherVersions
    field only per-API when
    list
    finds no match for that asset —
    describe
    's version list is anchored to the version you query with and has been observed to return empty/incomplete results when that version isn't the latest, which is exactly the situation CHECK and CHANGE query from.
  • Multi-API version selection is one at a time. Show one API's version list, STOP, get the selection, then proceed to the next. Never show all lists simultaneously.
  • Multi-turn interactive. At every STOP marker: print only the question as plain text, end your response, and wait. Do not run any tools until all required values are in hand.
  • Skip-if-provided. Before the first STOP, extract any values the user already gave (project path, operation, target API, new version). At each STOP, skip it if the question is already answered.

  • 属性名称始终为
    {artifactId}.version
    ——由API依赖的Maven
    artifactId
    派生而来,而非
    <apiVersion>
    之类的硬编码标签。
  • 请勿修改
    <version>
    (
    pom.xml
    顶部的Maven工件版本)。这是完全不同的字段。
  • 应用更改前始终展示可用版本。请勿要求用户输入版本字符串——始终先从Exchange获取版本列表并展示。
  • 仅当存在新版本时才提示。仅当当前版本不是最新版本时,才显示「有新版本可用」消息。否则请勿显示。
  • 选择相同版本视为无操作,而非错误。如果用户选择了已应用的版本,请告知用户并将该API从更改集中移除。如果所有选择均为无操作,则无需写入任何文件或运行
    mvn
    ,直接结束流程。
  • 批量应用所有更改,然后重新生成一次脚手架。应用所有pom.xml编辑后再运行
    mvn
    。请勿在单个API更新之间重新生成脚手架——最后一次
    mvn
    执行即可覆盖所有更改。
  • 写入前始终备份pom.xml。在每次CHANGE操作开始时,将原始内容保存在内存中。任何失败时自动恢复——Exchange获取错误、mvn失败或任何其他导致无法成功完成的情况。
  • 每次CHANGE后必须自动重新生成脚手架——无需用户提示。未运行
    mvn clean package -DskipTests
    并确认
    BUILD SUCCESS
    前,请勿宣布版本已更新。未重新生成脚手架的版本更改会导致项目不一致。步骤8的编辑完成后立即运行该命令,无需确认,与Anypoint Studio在pom.xml更改或API规格标签编辑时自动重新生成脚手架的行为一致。
  • 请勿重定向
    mvn
    命令的输出
    。不要使用
    2>&1
    、
    >
    、
    >>
    或管道——工具调用已完整捕获标准输出和标准错误,重定向运算符可能触发主机IDE的不安全命令检查,强制要求不必要的手动确认。
  • 每次响应仅执行一次
    mvn
    调用
    。请勿将其与文件编辑或其他命令捆绑。
  • pom.xml编辑无需Anypoint CLI——仅使用bash + 读取/编辑工具。
  • **
    scripts/fetch_versions.sh
    需要
    jq
    **来解析Exchange的JSON响应。如果运行脚本的机器上未安装
    jq
    ,脚本会失败——无单独的手动回退流程;请安装
    jq
    ,而非重新实现脚本的解析逻辑。
  • 版本发现始终通过一次
    scripts/fetch_versions.sh
    调用覆盖所有目标API,而非逐个API循环调用原始
    anypoint-cli-v4
    。请查看步骤7b下的版本发现流程。脚本针对所有目标API并行运行
    exchange asset list
    (不锚定版本),仅当
    list
    未找到该资产的匹配项时,才针对单个API回退到
    exchange asset describe
    的
    otherVersions
    字段——
    describe
    的版本列表锚定到查询时使用的版本,已观察到当该版本不是最新版本时,会返回空/不完整的结果,而这正是CHECK和CHANGE流程的查询场景。
  • 多API版本选择需逐个处理。展示一个API的版本列表,终止流程,获取选择结果,然后处理下一个API。请勿同时展示所有版本列表。
  • 多轮交互式操作。在每个终止流程标记处:仅将问题打印为纯文本,结束响应并等待。在获取所有必要值前,请勿运行任何工具。
  • 已提供则跳过。在第一次终止流程前,提取用户已提供的所有值(项目路径、操作类型、目标API、新版本)。在每个终止流程处,如果问题已得到回答则跳过。

Troubleshooting

故障排除

  • No
    .version
    properties found:
    The APIs may not be added to the project yet. Use Anypoint Studio's Project Properties → API Specs tab to add the API dependency first, which will create the property in
    pom.xml
    .
  • mvn
    fails after version change:
    pom.xml is automatically restored. Check the Maven error for the root cause — the selected version may have an incompatible dependency or the Exchange asset may not be fully published.
  • Multiple properties for the same API: If the same artifactId appears more than once under
    <properties>
    , update all occurrences to keep the project consistent.
  • scripts/fetch_versions.sh
    rows come back with
    "source": "error"
    due to an auth error:
    Run
    anypoint-cli-v4 conf
    to verify credentials, or re-authenticate with
    anypoint-cli-v4 conf username <user>
    /
    anypoint-cli-v4 conf password <pass>
    . If
    ANYPOINT_BEARER
    is set in the environment alongside
    ANYPOINT_CLIENT_ID
    /
    ANYPOINT_CLIENT_SECRET
    , unset the client-credential vars — the CLI rejects calls when multiple auth methods are simultaneously active.
  • A row comes back with
    "source": "describe-fallback"
    and a
    versions
    list that looks too short:
    Expected —
    exchange asset list
    found zero rows for that
    groupId
    /
    assetId
    , so the script fell back to the version-anchored
    describe
    lookup, which can under-report versions newer than the current one (see Version Discovery). Confirm the artifactId matches the Exchange
    assetId
    exactly (case-sensitive) and that the account is authenticated against the correct organization — a private asset published under a different org than the CLI session's selected org will not appear via
    list
    . As a next step, try
    anypoint-cli-v4 exchange asset list <artifactId> --output json
    manually (unfiltered) to see whether the asset shows up under a different
    groupId
    than what's in
    pom.xml
    .
  • "source": "error"
    with no obvious auth/network cause:
    Both
    exchange asset list
    and the
    describe
    fallback failed for that specific asset. Re-run just that one API through
    scripts/fetch_versions.sh
    in isolation to see the underlying CLI error more clearly, or run the two
    anypoint-cli-v4
    commands by hand to inspect stderr directly.

  • 未找到
    .version
    属性
    :可能尚未将API添加到项目中。请使用Anypoint Studio的「项目属性→API规格」标签添加API依赖,这会在
    pom.xml
    中创建对应的属性。
  • 版本更改后
    mvn
    失败
    :pom.xml会自动恢复。请查看Maven错误以确定根本原因——所选版本可能存在不兼容依赖,或Exchange资产可能未完全发布。
  • 同一API存在多个属性:如果
    <properties>
    中多次出现相同的artifactId,请更新所有实例以保持项目一致性。
  • scripts/fetch_versions.sh
    返回行的
    "source": "error"
    且原因是认证错误
    :运行
    anypoint-cli-v4 conf
    验证凭据,或使用
    anypoint-cli-v4 conf username <用户>
    /
    anypoint-cli-v4 conf password <密码>
    重新认证。如果环境中同时设置了
    ANYPOINT_BEARER
    和
    ANYPOINT_CLIENT_ID
    /
    ANYPOINT_CLIENT_SECRET
    ,请取消设置客户端凭据变量——当同时存在多种认证方式时,CLI会拒绝调用。
  • 返回行的
    "source": "describe-fallback"
    且
    versions
    列表过短
    :这是预期情况——
    exchange asset list
    未找到该
    groupId
    /
    assetId
    的匹配行,因此脚本回退到锚定版本的
    describe
    查询,该查询可能会少报当前版本之后的新版本(见版本发现)。请确认artifactId与Exchange的
    assetId
    完全匹配(区分大小写),且账户已针对正确的组织进行认证——发布在与CLI会话所选组织不同的私有资产不会通过
    list
    显示。下一步,尝试手动运行
    anypoint-cli-v4 exchange asset list <artifactId> --output json
    (未过滤),查看该资产是否出现在与
    pom.xml
    中不同的
    groupId
    下。
  • "source": "error"
    且无明显认证/网络原因
    :
    exchange asset list
    和
    describe
    回退方式均对该特定资产失败。单独重新运行该API的
    scripts/fetch_versions.sh
    调用,以更清晰地查看底层CLI错误,或手动运行两个
    anypoint-cli-v4
    命令直接检查标准错误。

Related Skills

相关技能

  • manage-global-configurations — Set up API AutoDiscovery (
    api.id
    ) and other global elements that pair with these API versions
  • build-mule-integration — Build and package the Mule project after version changes
  • manage-global-configurations — 设置API AutoDiscovery(
    api.id
    )和其他与这些API版本配对的全局元素
  • build-mule-integration — 版本更改后构建并打包Mule项目