@amaster.ai/cli 1.1.31 → 1.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -139,10 +139,17 @@ Addon 可在 `addon.json` 中声明安装后的运行配置要求:
139
139
 
140
140
  `install.requirements` 会写入 `meta.json`,并在安装/升级结果中返回 `requirements` 和 `missingRequirements`。`secrets` 只保存键名和说明,不保存密钥值。
141
141
 
142
- 页面注册方式:
142
+ 页面接入方式:
143
143
 
144
- - `web`:生成 `src/routes-addon.ts`,并 patch `src/routes.tsx`
145
- - `mini`:生成 `src/app-addon.config.ts`,并 patch `src/app.config.ts`
144
+ - CLI 只复制页面文件并写入 `src/addons/{addonName}/meta.json`
145
+ - CLI 不自动修改 `src/routes.tsx` 或 `src/app.config.ts`
146
+ - 安装/升级结果会返回 `llmGuidance`,由大模型按当前应用结构接入 web routes、mini pages 和 tabBar
147
+
148
+ 显式接入指导:
149
+
150
+ - Addon 包根目录可以放 `SKILL.md`
151
+ - `SKILL.md` 不会安装到应用工程,只会在安装/升级结果的 `llmGuidance.skill` 中返回给大模型
152
+ - 如果 Addon 本身就是一个 skill 资源,应在 `addon.json.members` 中显式声明 `type: "skill"`;普通 Addon 的根 `SKILL.md` 只作为模型指导
146
153
 
147
154
  升级策略:
148
155
 
@@ -178,7 +185,7 @@ Addon 可在 `addon.json` 中声明安装后的运行配置要求:
178
185
  }
179
186
  ```
180
187
 
181
- MCP 接入时可按 `conflicts[].path` 读取应用里的当前文件,并按 `memberName` / `sourcePath` 获取 Addon 原始内容,再交给 AI 合并后重试安装或升级。
188
+ MCP 接入时可按 `conflicts[].path` 读取应用里的当前文件,并按 `memberName` / `sourcePath` 获取 Addon 原始内容,再交给 AI 或人工合并处理。
182
189
 
183
190
  ## 模板检查
184
191
 
package/dist/cli.cjs CHANGED
@@ -765,14 +765,6 @@ async function tryDetectNearestApplicationType(startDir = process.cwd()) {
765
765
 
766
766
  // src/marketplace/install.ts
767
767
  var execFileAsync = util.promisify(child_process.execFile);
768
- var ADDON_ROUTES_FILE = "src/routes-addon.ts";
769
- var ADDON_ROUTES_IMPORT = 'import { addonRoutes } from "./routes-addon";';
770
- var LEGACY_ADDON_ROUTES_IMPORT = 'import { addonRoutes } from "./amaster/registry/addon-routes.generated";';
771
- var LEGACY_ADDON_ROUTES_FILE = "src/amaster/registry/addon-routes.generated.ts";
772
- var ADDON_PAGES_FILE = "src/app-addon.config.ts";
773
- var ADDON_PAGES_IMPORT = 'import { addonPages, addonTabBarItems } from "./app-addon.config";';
774
- var LEGACY_ADDON_PAGES_IMPORT = 'import { addonPages, addonTabBarItems } from "./amaster/registry/addon-pages.generated";';
775
- var LEGACY_ADDON_PAGES_FILE = "src/amaster/registry/addon-pages.generated.ts";
776
768
  var AddonInstallConflictError = class extends Error {
777
769
  constructor(input) {
778
770
  super(`Addon ${input.operation} has ${input.conflicts.length} conflict(s)`);
@@ -821,13 +813,6 @@ function ensurePathInsideTarget(targetDir, relativePath) {
821
813
  }
822
814
  return absolute;
823
815
  }
824
- function removeFileExtension(input) {
825
- const extension = path.extname(input);
826
- return extension ? input.slice(0, -extension.length) : input;
827
- }
828
- function toPascalCase(input) {
829
- return input.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((part) => part[0].toUpperCase() + part.slice(1)).join("");
830
- }
831
816
  function parseScalarValue(rawValue, expectedType, enumValues) {
832
817
  const primaryType = Array.isArray(expectedType) ? expectedType[0] : expectedType;
833
818
  if (enumValues?.length) {
@@ -919,6 +904,83 @@ function buildMissingRequirements(requirements) {
919
904
  secrets: requirements.secrets?.filter((item) => item.required !== false).map((item) => ({ ...item }))
920
905
  };
921
906
  }
907
+ function hasInstallRequirements(requirements) {
908
+ return Boolean(requirements.envs?.length || requirements.secrets?.length);
909
+ }
910
+ function hasNpmDependencies(npm) {
911
+ return Boolean(Object.keys(npm.dependencies ?? {}).length);
912
+ }
913
+ function buildAddonLlmGuidance(input) {
914
+ const pageMembers = input.meta.members.filter((member) => member.type === "page");
915
+ const componentMembers = input.meta.members.filter((member) => member.type === "component");
916
+ const settingsMembers = input.meta.members.filter((member) => member.type === "settings");
917
+ const webRoutes = input.meta.members.filter((member) => member.type === "page" && member.page?.web).map((member) => ({
918
+ route: member.page.web.route,
919
+ entry: member.page.web.entry.startsWith("src/") ? member.page.web.entry : `src/${member.page.web.entry}`,
920
+ title: member.page.web.title,
921
+ visible: member.page.web.visible,
922
+ suggestedFile: "src/routes.tsx"
923
+ }));
924
+ const miniPages = input.meta.members.filter((member) => member.type === "page" && member.page?.mini).map((member) => ({
925
+ pagePath: member.page.mini.pagePath,
926
+ suggestedFile: "src/app.config.ts",
927
+ tabBar: member.page.mini.tabBar
928
+ }));
929
+ const components = componentMembers.map((member) => ({
930
+ name: member.name,
931
+ importFrom: member.targetPaths[0] || "",
932
+ targetPaths: member.targetPaths
933
+ }));
934
+ const settings = settingsMembers.map((member) => ({
935
+ targetPath: member.settings?.targetPath || member.targetPaths[0] || "",
936
+ paths: member.settings?.paths.map((item) => item.path) || []
937
+ }));
938
+ const instructions = [
939
+ `Addon ${input.meta.name}@${input.meta.version} has been ${input.operation === "install" ? "installed" : "upgraded"} into the application files.`,
940
+ "Do not run the install command again to apply integration steps; edit the application source files directly."
941
+ ];
942
+ if (pageMembers.length > 0) {
943
+ instructions.push("Wire the installed page members into the application's existing routing/configuration style.");
944
+ }
945
+ if (componentMembers.length > 0) {
946
+ instructions.push("Use installed component members from their target paths where the application needs them.");
947
+ }
948
+ if (hasInstallRequirements(input.requirements)) {
949
+ instructions.push("Configure the declared env/secret requirements before running or deploying the application.");
950
+ }
951
+ if (hasNpmDependencies(input.npm)) {
952
+ instructions.push("NPM dependencies have been written to package.json; avoid adding duplicate dependency entries.");
953
+ }
954
+ return {
955
+ summary: input.meta.manifest.description || input.meta.manifest.title || `Installed addon ${input.meta.name}@${input.meta.version}.`,
956
+ instructions,
957
+ skill: input.skillContent ? { path: "SKILL.md", content: input.skillContent } : void 0,
958
+ webRoutes: webRoutes.length ? webRoutes : void 0,
959
+ miniPages: miniPages.length ? miniPages : void 0,
960
+ components: components.length ? components : void 0,
961
+ settings: settings.length ? settings : void 0,
962
+ requirements: hasInstallRequirements(input.requirements) ? input.requirements : void 0,
963
+ npm: hasNpmDependencies(input.npm) ? input.npm : void 0
964
+ };
965
+ }
966
+ async function readAddonSkillGuidance(extractedDir, manifest) {
967
+ const hasSkillMemberAtRoot = manifest.members.some((member) => {
968
+ if (member.type !== "skill") {
969
+ return false;
970
+ }
971
+ const sourcePath = resolveMemberSourcePath(member);
972
+ return sourcePath === "SKILL.md";
973
+ });
974
+ if (hasSkillMemberAtRoot) {
975
+ return void 0;
976
+ }
977
+ const skillPath = path.join(extractedDir, "SKILL.md");
978
+ if (!fs.existsSync(skillPath)) {
979
+ return void 0;
980
+ }
981
+ const content = (await promises$1.readFile(skillPath, "utf8")).trim();
982
+ return content || void 0;
983
+ }
922
984
  function getAddonMetaPath(targetDir, addonName) {
923
985
  return path.join(targetDir, "src", "addons", addonName, "meta.json");
924
986
  }
@@ -1677,136 +1739,6 @@ async function validateUpgradeConflicts(targetDir, plan, existingMetas, previous
1677
1739
  });
1678
1740
  }
1679
1741
  }
1680
- async function ensureWebRoutesPatched(targetDir) {
1681
- const routesFile = path.join(targetDir, "src", "routes.tsx");
1682
- const original = await promises$1.readFile(routesFile, "utf8");
1683
- let next = original;
1684
- if (next.includes(LEGACY_ADDON_ROUTES_IMPORT)) {
1685
- next = next.replace(LEGACY_ADDON_ROUTES_IMPORT, ADDON_ROUTES_IMPORT);
1686
- }
1687
- if (!next.includes(ADDON_ROUTES_IMPORT)) {
1688
- next = next.replace(
1689
- 'import type { ComponentType } from "react";',
1690
- `import type { ComponentType } from "react";
1691
- ${ADDON_ROUTES_IMPORT}`
1692
- );
1693
- }
1694
- if (!next.includes("...addonRoutes")) {
1695
- const routeArrayPattern = /const routes:\s*RouteConfig\[\]\s*=\s*\[([\s\S]*?)\];/;
1696
- const match = next.match(routeArrayPattern);
1697
- if (!match) {
1698
- throw new Error("Unable to patch src/routes.tsx for addon route registration");
1699
- }
1700
- const inner = match[1]?.trim() ?? "";
1701
- const replacement = inner ? `const routes: RouteConfig[] = [
1702
- ...addonRoutes,
1703
- ${match[1]}
1704
- ];` : "const routes: RouteConfig[] = [\n ...addonRoutes,\n];";
1705
- next = next.replace(routeArrayPattern, replacement);
1706
- }
1707
- if (next !== original) {
1708
- await promises$1.writeFile(routesFile, next);
1709
- }
1710
- }
1711
- async function ensureMiniAppConfigPatched(targetDir, needsTabBarItems) {
1712
- const configFile = path.join(targetDir, "src", "app.config.ts");
1713
- const original = await promises$1.readFile(configFile, "utf8");
1714
- let next = original;
1715
- if (next.includes(LEGACY_ADDON_PAGES_IMPORT)) {
1716
- next = next.replace(LEGACY_ADDON_PAGES_IMPORT, ADDON_PAGES_IMPORT);
1717
- }
1718
- if (!next.includes(ADDON_PAGES_IMPORT)) {
1719
- next = `${ADDON_PAGES_IMPORT}
1720
- ${next}`;
1721
- }
1722
- if (!next.includes("...addonPages")) {
1723
- next = next.replace(/const pages\s*=\s*\[([\s\S]*?)\]/, (_full, inner) => {
1724
- const trimmed = inner.trim();
1725
- if (!trimmed) {
1726
- return "const pages = [...addonPages]";
1727
- }
1728
- return `const pages = [${inner}, ...addonPages]`;
1729
- });
1730
- }
1731
- if (needsTabBarItems && !next.includes("...addonTabBarItems")) {
1732
- const listPattern = /list:\s*\[([\s\S]*?)\]/;
1733
- const match = next.match(listPattern);
1734
- if (!match) {
1735
- throw new Error("Unable to patch src/app.config.ts for addon tabBar registration");
1736
- }
1737
- next = next.replace(listPattern, (_full, inner) => `list: [${inner}, ...addonTabBarItems]`);
1738
- }
1739
- if (next !== original) {
1740
- await promises$1.writeFile(configFile, next);
1741
- }
1742
- }
1743
- async function rebuildRegistryFiles(targetDir, applicationType, metas) {
1744
- if (applicationType === "web") {
1745
- const pageMembers2 = metas.flatMap(
1746
- (meta) => meta.members.filter((member) => member.type === "page" && member.page?.web).map((member) => ({ addonName: meta.name, member }))
1747
- ).sort((left, right) => `${left.addonName}:${left.member.name}`.localeCompare(`${right.addonName}:${right.member.name}`));
1748
- const imports = pageMembers2.map(({ addonName, member }) => {
1749
- const identifier = toPascalCase(`${addonName}-${member.name}-page`);
1750
- const entry = member.page.web.entry;
1751
- return {
1752
- identifier,
1753
- importPath: `./${removeFileExtension(entry).replace(/\\/g, "/")}`,
1754
- route: member.page.web.route,
1755
- visible: member.page.web.visible,
1756
- name: member.name
1757
- };
1758
- });
1759
- const routesFile = path.join(targetDir, "src", "routes.tsx");
1760
- const routesContent = fs.existsSync(routesFile) ? await promises$1.readFile(routesFile, "utf8") : "";
1761
- const alreadyPatched2 = routesContent.includes(ADDON_ROUTES_IMPORT) || routesContent.includes(LEGACY_ADDON_ROUTES_IMPORT) || routesContent.includes("...addonRoutes");
1762
- await promises$1.unlink(path.join(targetDir, LEGACY_ADDON_ROUTES_FILE)).catch(() => void 0);
1763
- if (imports.length > 0 || alreadyPatched2) {
1764
- const fileContent = [
1765
- 'import type { ComponentType } from "react";',
1766
- ...imports.map((item) => `import ${item.identifier} from "${item.importPath}";`),
1767
- "",
1768
- "type AddonRouteConfig = {",
1769
- " name: string;",
1770
- " path: string;",
1771
- " Component: ComponentType<Record<string, unknown>>;",
1772
- " visible?: boolean;",
1773
- "};",
1774
- "",
1775
- "export const addonRoutes: AddonRouteConfig[] = [",
1776
- ...imports.map(
1777
- (item) => ` { name: ${JSON.stringify(item.name)}, path: ${JSON.stringify(item.route)}, Component: ${item.identifier},${item.visible === void 0 ? "" : ` visible: ${item.visible},`} },`
1778
- ),
1779
- "];",
1780
- ""
1781
- ].join("\n");
1782
- await promises$1.writeFile(path.join(targetDir, ADDON_ROUTES_FILE), fileContent);
1783
- await ensureWebRoutesPatched(targetDir);
1784
- }
1785
- return;
1786
- }
1787
- const pageMembers = metas.flatMap(
1788
- (meta) => meta.members.filter((member) => member.type === "page" && member.page?.mini).map((member) => member.page.mini)
1789
- ).sort((left, right) => left.pagePath.localeCompare(right.pagePath));
1790
- const addonPages = pageMembers.map((page) => page.pagePath);
1791
- const addonTabBarItems = pageMembers.filter((page) => page.tabBar).map((page) => ({
1792
- pagePath: page.pagePath,
1793
- ...page.tabBar
1794
- }));
1795
- const appConfigFile = path.join(targetDir, "src", "app.config.ts");
1796
- const appConfigContent = fs.existsSync(appConfigFile) ? await promises$1.readFile(appConfigFile, "utf8") : "";
1797
- const alreadyPatched = appConfigContent.includes(ADDON_PAGES_IMPORT) || appConfigContent.includes(LEGACY_ADDON_PAGES_IMPORT) || appConfigContent.includes("...addonPages") || appConfigContent.includes("...addonTabBarItems");
1798
- await promises$1.unlink(path.join(targetDir, LEGACY_ADDON_PAGES_FILE)).catch(() => void 0);
1799
- if (addonPages.length > 0 || alreadyPatched) {
1800
- const fileContent = [
1801
- `export const addonPages = ${JSON.stringify(addonPages, null, 2)};`,
1802
- "",
1803
- `export const addonTabBarItems = ${JSON.stringify(addonTabBarItems, null, 2)};`,
1804
- ""
1805
- ].join("\n");
1806
- await promises$1.writeFile(path.join(targetDir, ADDON_PAGES_FILE), fileContent);
1807
- await ensureMiniAppConfigPatched(targetDir, addonTabBarItems.length > 0);
1808
- }
1809
- }
1810
1742
  async function materializeAddon(options) {
1811
1743
  const targetDir = path.resolve(options.targetDir);
1812
1744
  const existingMetas = await listInstalledAddons(targetDir);
@@ -1850,19 +1782,26 @@ async function materializeAddon(options) {
1850
1782
  });
1851
1783
  await ensureParentDirectory(plan.metaPath);
1852
1784
  await promises$1.writeFile(plan.metaPath, JSON.stringify(meta, null, 2));
1853
- const nextMetas = existingMetas.filter((item) => item.name !== meta.name).concat(meta);
1854
- await rebuildRegistryFiles(targetDir, plan.applicationType, nextMetas.filter((item) => item.applicationType === plan.applicationType));
1855
1785
  if (options.installPackageDependencies && packageJsonFiles.length) {
1856
1786
  await installPackageDependencies(targetDir);
1857
1787
  }
1858
1788
  const requirements = resolveInstallRequirements(plan.manifest);
1789
+ const skillContent = await readAddonSkillGuidance(options.extractedDir, plan.manifest);
1790
+ const llmGuidance = buildAddonLlmGuidance({
1791
+ operation: options.mode,
1792
+ meta,
1793
+ requirements,
1794
+ npm,
1795
+ skillContent
1796
+ });
1859
1797
  return {
1860
1798
  meta,
1861
1799
  writtenFiles: installedFiles.map((file) => file.path).concat(packageJsonFiles, restoredSettingsFiles, settingsResult.writtenFiles),
1862
1800
  removedFiles,
1863
1801
  requirements,
1864
1802
  missingRequirements: buildMissingRequirements(requirements),
1865
- npm
1803
+ npm,
1804
+ llmGuidance
1866
1805
  };
1867
1806
  }
1868
1807
  async function installAddonFromExtractedDirectory(options) {
@@ -3496,6 +3435,47 @@ function formatLoginIdentity(user) {
3496
3435
  function resolveAddonTargetDir(target) {
3497
3436
  return target ? target : resolveNearestPackageRoot();
3498
3437
  }
3438
+ function renderAddonInstallResult(result, operation, options) {
3439
+ const output = {
3440
+ success: true,
3441
+ operation,
3442
+ addon: {
3443
+ name: result.meta.name,
3444
+ version: result.meta.version,
3445
+ applicationType: result.meta.applicationType
3446
+ },
3447
+ files: {
3448
+ written: result.writtenFiles,
3449
+ removed: result.removedFiles
3450
+ },
3451
+ npm: Object.keys(result.npm.dependencies ?? {}).length ? result.npm : void 0,
3452
+ missingRequirements: result.missingRequirements.envs?.length || result.missingRequirements.secrets?.length ? result.missingRequirements : void 0,
3453
+ llmGuidance: result.llmGuidance
3454
+ };
3455
+ if (options.json) {
3456
+ renderOutput(output, options);
3457
+ return;
3458
+ }
3459
+ const lines = [
3460
+ `Addon ${operation === "install" ? "installed" : "upgraded"}: ${result.meta.name}@${result.meta.version}`,
3461
+ `Application type: ${result.meta.applicationType}`,
3462
+ `Written files: ${result.writtenFiles.length}`
3463
+ ];
3464
+ if (result.removedFiles.length) {
3465
+ lines.push(`Removed files: ${result.removedFiles.length}`);
3466
+ }
3467
+ if (result.llmGuidance.webRoutes?.length) {
3468
+ lines.push("Next: wire web routes from llmGuidance.webRoutes.");
3469
+ }
3470
+ if (result.llmGuidance.miniPages?.length) {
3471
+ lines.push("Next: wire mini pages from llmGuidance.miniPages.");
3472
+ }
3473
+ if (output.missingRequirements) {
3474
+ lines.push("Next: configure missing env/secrets from llmGuidance.requirements.");
3475
+ }
3476
+ lines.push("Use --json for LLM-readable integration guidance.");
3477
+ renderOutput(lines.join("\n"), options);
3478
+ }
3499
3479
  function requireStack(value) {
3500
3480
  if (value === "react-vite" || value === "taro") {
3501
3481
  return value;
@@ -3658,7 +3638,7 @@ addJsonOption(addOrganizationOption(addRegistryOption(addon.command("install <sp
3658
3638
  organizationCode: options.organizationCode,
3659
3639
  installParameters: parseKeyValuePairs(options.set)
3660
3640
  });
3661
- renderOutput(result, options);
3641
+ renderAddonInstallResult(result, "install", options);
3662
3642
  });
3663
3643
  addJsonOption(addOrganizationOption(addRegistryOption(addon.command("upgrade <specifier>").description("Upgrade an installed addon")))).option("--target <path>", "Application root directory, defaults to nearest package.json directory").addOption(new commander.Option("--application-type <type>", "Application type").choices(["web", "mini"])).option("--set <key=value>", "Install parameter", (value, previous = []) => previous.concat(value), []).action(async (specifier, options) => {
3664
3644
  const registry = resolveRegistryFromOptions(options);
@@ -3670,7 +3650,7 @@ addJsonOption(addOrganizationOption(addRegistryOption(addon.command("upgrade <sp
3670
3650
  organizationCode: options.organizationCode,
3671
3651
  installParameters: parseKeyValuePairs(options.set)
3672
3652
  });
3673
- renderOutput(result, options);
3653
+ renderAddonInstallResult(result, "upgrade", options);
3674
3654
  });
3675
3655
  addJsonOption(addon.command("list").description("List installed addons in an application")).option("--target <path>", "Application root directory, defaults to nearest package.json directory").action(async (options) => {
3676
3656
  const installed = await listInstalledAddons(resolveAddonTargetDir(options.target));