@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/dist/cli.js CHANGED
@@ -738,14 +738,6 @@ async function tryDetectNearestApplicationType(startDir = process.cwd()) {
738
738
 
739
739
  // src/marketplace/install.ts
740
740
  var execFileAsync = promisify(execFile);
741
- var ADDON_ROUTES_FILE = "src/routes-addon.ts";
742
- var ADDON_ROUTES_IMPORT = 'import { addonRoutes } from "./routes-addon";';
743
- var LEGACY_ADDON_ROUTES_IMPORT = 'import { addonRoutes } from "./amaster/registry/addon-routes.generated";';
744
- var LEGACY_ADDON_ROUTES_FILE = "src/amaster/registry/addon-routes.generated.ts";
745
- var ADDON_PAGES_FILE = "src/app-addon.config.ts";
746
- var ADDON_PAGES_IMPORT = 'import { addonPages, addonTabBarItems } from "./app-addon.config";';
747
- var LEGACY_ADDON_PAGES_IMPORT = 'import { addonPages, addonTabBarItems } from "./amaster/registry/addon-pages.generated";';
748
- var LEGACY_ADDON_PAGES_FILE = "src/amaster/registry/addon-pages.generated.ts";
749
741
  var AddonInstallConflictError = class extends Error {
750
742
  constructor(input) {
751
743
  super(`Addon ${input.operation} has ${input.conflicts.length} conflict(s)`);
@@ -794,13 +786,6 @@ function ensurePathInsideTarget(targetDir, relativePath) {
794
786
  }
795
787
  return absolute;
796
788
  }
797
- function removeFileExtension(input) {
798
- const extension = extname(input);
799
- return extension ? input.slice(0, -extension.length) : input;
800
- }
801
- function toPascalCase(input) {
802
- return input.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((part) => part[0].toUpperCase() + part.slice(1)).join("");
803
- }
804
789
  function parseScalarValue(rawValue, expectedType, enumValues) {
805
790
  const primaryType = Array.isArray(expectedType) ? expectedType[0] : expectedType;
806
791
  if (enumValues?.length) {
@@ -892,6 +877,83 @@ function buildMissingRequirements(requirements) {
892
877
  secrets: requirements.secrets?.filter((item) => item.required !== false).map((item) => ({ ...item }))
893
878
  };
894
879
  }
880
+ function hasInstallRequirements(requirements) {
881
+ return Boolean(requirements.envs?.length || requirements.secrets?.length);
882
+ }
883
+ function hasNpmDependencies(npm) {
884
+ return Boolean(Object.keys(npm.dependencies ?? {}).length);
885
+ }
886
+ function buildAddonLlmGuidance(input) {
887
+ const pageMembers = input.meta.members.filter((member) => member.type === "page");
888
+ const componentMembers = input.meta.members.filter((member) => member.type === "component");
889
+ const settingsMembers = input.meta.members.filter((member) => member.type === "settings");
890
+ const webRoutes = input.meta.members.filter((member) => member.type === "page" && member.page?.web).map((member) => ({
891
+ route: member.page.web.route,
892
+ entry: member.page.web.entry.startsWith("src/") ? member.page.web.entry : `src/${member.page.web.entry}`,
893
+ title: member.page.web.title,
894
+ visible: member.page.web.visible,
895
+ suggestedFile: "src/routes.tsx"
896
+ }));
897
+ const miniPages = input.meta.members.filter((member) => member.type === "page" && member.page?.mini).map((member) => ({
898
+ pagePath: member.page.mini.pagePath,
899
+ suggestedFile: "src/app.config.ts",
900
+ tabBar: member.page.mini.tabBar
901
+ }));
902
+ const components = componentMembers.map((member) => ({
903
+ name: member.name,
904
+ importFrom: member.targetPaths[0] || "",
905
+ targetPaths: member.targetPaths
906
+ }));
907
+ const settings = settingsMembers.map((member) => ({
908
+ targetPath: member.settings?.targetPath || member.targetPaths[0] || "",
909
+ paths: member.settings?.paths.map((item) => item.path) || []
910
+ }));
911
+ const instructions = [
912
+ `Addon ${input.meta.name}@${input.meta.version} has been ${input.operation === "install" ? "installed" : "upgraded"} into the application files.`,
913
+ "Do not run the install command again to apply integration steps; edit the application source files directly."
914
+ ];
915
+ if (pageMembers.length > 0) {
916
+ instructions.push("Wire the installed page members into the application's existing routing/configuration style.");
917
+ }
918
+ if (componentMembers.length > 0) {
919
+ instructions.push("Use installed component members from their target paths where the application needs them.");
920
+ }
921
+ if (hasInstallRequirements(input.requirements)) {
922
+ instructions.push("Configure the declared env/secret requirements before running or deploying the application.");
923
+ }
924
+ if (hasNpmDependencies(input.npm)) {
925
+ instructions.push("NPM dependencies have been written to package.json; avoid adding duplicate dependency entries.");
926
+ }
927
+ return {
928
+ summary: input.meta.manifest.description || input.meta.manifest.title || `Installed addon ${input.meta.name}@${input.meta.version}.`,
929
+ instructions,
930
+ skill: input.skillContent ? { path: "SKILL.md", content: input.skillContent } : void 0,
931
+ webRoutes: webRoutes.length ? webRoutes : void 0,
932
+ miniPages: miniPages.length ? miniPages : void 0,
933
+ components: components.length ? components : void 0,
934
+ settings: settings.length ? settings : void 0,
935
+ requirements: hasInstallRequirements(input.requirements) ? input.requirements : void 0,
936
+ npm: hasNpmDependencies(input.npm) ? input.npm : void 0
937
+ };
938
+ }
939
+ async function readAddonSkillGuidance(extractedDir, manifest) {
940
+ const hasSkillMemberAtRoot = manifest.members.some((member) => {
941
+ if (member.type !== "skill") {
942
+ return false;
943
+ }
944
+ const sourcePath = resolveMemberSourcePath(member);
945
+ return sourcePath === "SKILL.md";
946
+ });
947
+ if (hasSkillMemberAtRoot) {
948
+ return void 0;
949
+ }
950
+ const skillPath = join(extractedDir, "SKILL.md");
951
+ if (!existsSync(skillPath)) {
952
+ return void 0;
953
+ }
954
+ const content = (await readFile(skillPath, "utf8")).trim();
955
+ return content || void 0;
956
+ }
895
957
  function getAddonMetaPath(targetDir, addonName) {
896
958
  return join(targetDir, "src", "addons", addonName, "meta.json");
897
959
  }
@@ -1650,136 +1712,6 @@ async function validateUpgradeConflicts(targetDir, plan, existingMetas, previous
1650
1712
  });
1651
1713
  }
1652
1714
  }
1653
- async function ensureWebRoutesPatched(targetDir) {
1654
- const routesFile = join(targetDir, "src", "routes.tsx");
1655
- const original = await readFile(routesFile, "utf8");
1656
- let next = original;
1657
- if (next.includes(LEGACY_ADDON_ROUTES_IMPORT)) {
1658
- next = next.replace(LEGACY_ADDON_ROUTES_IMPORT, ADDON_ROUTES_IMPORT);
1659
- }
1660
- if (!next.includes(ADDON_ROUTES_IMPORT)) {
1661
- next = next.replace(
1662
- 'import type { ComponentType } from "react";',
1663
- `import type { ComponentType } from "react";
1664
- ${ADDON_ROUTES_IMPORT}`
1665
- );
1666
- }
1667
- if (!next.includes("...addonRoutes")) {
1668
- const routeArrayPattern = /const routes:\s*RouteConfig\[\]\s*=\s*\[([\s\S]*?)\];/;
1669
- const match = next.match(routeArrayPattern);
1670
- if (!match) {
1671
- throw new Error("Unable to patch src/routes.tsx for addon route registration");
1672
- }
1673
- const inner = match[1]?.trim() ?? "";
1674
- const replacement = inner ? `const routes: RouteConfig[] = [
1675
- ...addonRoutes,
1676
- ${match[1]}
1677
- ];` : "const routes: RouteConfig[] = [\n ...addonRoutes,\n];";
1678
- next = next.replace(routeArrayPattern, replacement);
1679
- }
1680
- if (next !== original) {
1681
- await writeFile(routesFile, next);
1682
- }
1683
- }
1684
- async function ensureMiniAppConfigPatched(targetDir, needsTabBarItems) {
1685
- const configFile = join(targetDir, "src", "app.config.ts");
1686
- const original = await readFile(configFile, "utf8");
1687
- let next = original;
1688
- if (next.includes(LEGACY_ADDON_PAGES_IMPORT)) {
1689
- next = next.replace(LEGACY_ADDON_PAGES_IMPORT, ADDON_PAGES_IMPORT);
1690
- }
1691
- if (!next.includes(ADDON_PAGES_IMPORT)) {
1692
- next = `${ADDON_PAGES_IMPORT}
1693
- ${next}`;
1694
- }
1695
- if (!next.includes("...addonPages")) {
1696
- next = next.replace(/const pages\s*=\s*\[([\s\S]*?)\]/, (_full, inner) => {
1697
- const trimmed = inner.trim();
1698
- if (!trimmed) {
1699
- return "const pages = [...addonPages]";
1700
- }
1701
- return `const pages = [${inner}, ...addonPages]`;
1702
- });
1703
- }
1704
- if (needsTabBarItems && !next.includes("...addonTabBarItems")) {
1705
- const listPattern = /list:\s*\[([\s\S]*?)\]/;
1706
- const match = next.match(listPattern);
1707
- if (!match) {
1708
- throw new Error("Unable to patch src/app.config.ts for addon tabBar registration");
1709
- }
1710
- next = next.replace(listPattern, (_full, inner) => `list: [${inner}, ...addonTabBarItems]`);
1711
- }
1712
- if (next !== original) {
1713
- await writeFile(configFile, next);
1714
- }
1715
- }
1716
- async function rebuildRegistryFiles(targetDir, applicationType, metas) {
1717
- if (applicationType === "web") {
1718
- const pageMembers2 = metas.flatMap(
1719
- (meta) => meta.members.filter((member) => member.type === "page" && member.page?.web).map((member) => ({ addonName: meta.name, member }))
1720
- ).sort((left, right) => `${left.addonName}:${left.member.name}`.localeCompare(`${right.addonName}:${right.member.name}`));
1721
- const imports = pageMembers2.map(({ addonName, member }) => {
1722
- const identifier = toPascalCase(`${addonName}-${member.name}-page`);
1723
- const entry = member.page.web.entry;
1724
- return {
1725
- identifier,
1726
- importPath: `./${removeFileExtension(entry).replace(/\\/g, "/")}`,
1727
- route: member.page.web.route,
1728
- visible: member.page.web.visible,
1729
- name: member.name
1730
- };
1731
- });
1732
- const routesFile = join(targetDir, "src", "routes.tsx");
1733
- const routesContent = existsSync(routesFile) ? await readFile(routesFile, "utf8") : "";
1734
- const alreadyPatched2 = routesContent.includes(ADDON_ROUTES_IMPORT) || routesContent.includes(LEGACY_ADDON_ROUTES_IMPORT) || routesContent.includes("...addonRoutes");
1735
- await unlink(join(targetDir, LEGACY_ADDON_ROUTES_FILE)).catch(() => void 0);
1736
- if (imports.length > 0 || alreadyPatched2) {
1737
- const fileContent = [
1738
- 'import type { ComponentType } from "react";',
1739
- ...imports.map((item) => `import ${item.identifier} from "${item.importPath}";`),
1740
- "",
1741
- "type AddonRouteConfig = {",
1742
- " name: string;",
1743
- " path: string;",
1744
- " Component: ComponentType<Record<string, unknown>>;",
1745
- " visible?: boolean;",
1746
- "};",
1747
- "",
1748
- "export const addonRoutes: AddonRouteConfig[] = [",
1749
- ...imports.map(
1750
- (item) => ` { name: ${JSON.stringify(item.name)}, path: ${JSON.stringify(item.route)}, Component: ${item.identifier},${item.visible === void 0 ? "" : ` visible: ${item.visible},`} },`
1751
- ),
1752
- "];",
1753
- ""
1754
- ].join("\n");
1755
- await writeFile(join(targetDir, ADDON_ROUTES_FILE), fileContent);
1756
- await ensureWebRoutesPatched(targetDir);
1757
- }
1758
- return;
1759
- }
1760
- const pageMembers = metas.flatMap(
1761
- (meta) => meta.members.filter((member) => member.type === "page" && member.page?.mini).map((member) => member.page.mini)
1762
- ).sort((left, right) => left.pagePath.localeCompare(right.pagePath));
1763
- const addonPages = pageMembers.map((page) => page.pagePath);
1764
- const addonTabBarItems = pageMembers.filter((page) => page.tabBar).map((page) => ({
1765
- pagePath: page.pagePath,
1766
- ...page.tabBar
1767
- }));
1768
- const appConfigFile = join(targetDir, "src", "app.config.ts");
1769
- const appConfigContent = existsSync(appConfigFile) ? await readFile(appConfigFile, "utf8") : "";
1770
- const alreadyPatched = appConfigContent.includes(ADDON_PAGES_IMPORT) || appConfigContent.includes(LEGACY_ADDON_PAGES_IMPORT) || appConfigContent.includes("...addonPages") || appConfigContent.includes("...addonTabBarItems");
1771
- await unlink(join(targetDir, LEGACY_ADDON_PAGES_FILE)).catch(() => void 0);
1772
- if (addonPages.length > 0 || alreadyPatched) {
1773
- const fileContent = [
1774
- `export const addonPages = ${JSON.stringify(addonPages, null, 2)};`,
1775
- "",
1776
- `export const addonTabBarItems = ${JSON.stringify(addonTabBarItems, null, 2)};`,
1777
- ""
1778
- ].join("\n");
1779
- await writeFile(join(targetDir, ADDON_PAGES_FILE), fileContent);
1780
- await ensureMiniAppConfigPatched(targetDir, addonTabBarItems.length > 0);
1781
- }
1782
- }
1783
1715
  async function materializeAddon(options) {
1784
1716
  const targetDir = resolve(options.targetDir);
1785
1717
  const existingMetas = await listInstalledAddons(targetDir);
@@ -1823,19 +1755,26 @@ async function materializeAddon(options) {
1823
1755
  });
1824
1756
  await ensureParentDirectory(plan.metaPath);
1825
1757
  await writeFile(plan.metaPath, JSON.stringify(meta, null, 2));
1826
- const nextMetas = existingMetas.filter((item) => item.name !== meta.name).concat(meta);
1827
- await rebuildRegistryFiles(targetDir, plan.applicationType, nextMetas.filter((item) => item.applicationType === plan.applicationType));
1828
1758
  if (options.installPackageDependencies && packageJsonFiles.length) {
1829
1759
  await installPackageDependencies(targetDir);
1830
1760
  }
1831
1761
  const requirements = resolveInstallRequirements(plan.manifest);
1762
+ const skillContent = await readAddonSkillGuidance(options.extractedDir, plan.manifest);
1763
+ const llmGuidance = buildAddonLlmGuidance({
1764
+ operation: options.mode,
1765
+ meta,
1766
+ requirements,
1767
+ npm,
1768
+ skillContent
1769
+ });
1832
1770
  return {
1833
1771
  meta,
1834
1772
  writtenFiles: installedFiles.map((file) => file.path).concat(packageJsonFiles, restoredSettingsFiles, settingsResult.writtenFiles),
1835
1773
  removedFiles,
1836
1774
  requirements,
1837
1775
  missingRequirements: buildMissingRequirements(requirements),
1838
- npm
1776
+ npm,
1777
+ llmGuidance
1839
1778
  };
1840
1779
  }
1841
1780
  async function installAddonFromExtractedDirectory(options) {
@@ -3469,6 +3408,47 @@ function formatLoginIdentity(user) {
3469
3408
  function resolveAddonTargetDir(target) {
3470
3409
  return target ? target : resolveNearestPackageRoot();
3471
3410
  }
3411
+ function renderAddonInstallResult(result, operation, options) {
3412
+ const output = {
3413
+ success: true,
3414
+ operation,
3415
+ addon: {
3416
+ name: result.meta.name,
3417
+ version: result.meta.version,
3418
+ applicationType: result.meta.applicationType
3419
+ },
3420
+ files: {
3421
+ written: result.writtenFiles,
3422
+ removed: result.removedFiles
3423
+ },
3424
+ npm: Object.keys(result.npm.dependencies ?? {}).length ? result.npm : void 0,
3425
+ missingRequirements: result.missingRequirements.envs?.length || result.missingRequirements.secrets?.length ? result.missingRequirements : void 0,
3426
+ llmGuidance: result.llmGuidance
3427
+ };
3428
+ if (options.json) {
3429
+ renderOutput(output, options);
3430
+ return;
3431
+ }
3432
+ const lines = [
3433
+ `Addon ${operation === "install" ? "installed" : "upgraded"}: ${result.meta.name}@${result.meta.version}`,
3434
+ `Application type: ${result.meta.applicationType}`,
3435
+ `Written files: ${result.writtenFiles.length}`
3436
+ ];
3437
+ if (result.removedFiles.length) {
3438
+ lines.push(`Removed files: ${result.removedFiles.length}`);
3439
+ }
3440
+ if (result.llmGuidance.webRoutes?.length) {
3441
+ lines.push("Next: wire web routes from llmGuidance.webRoutes.");
3442
+ }
3443
+ if (result.llmGuidance.miniPages?.length) {
3444
+ lines.push("Next: wire mini pages from llmGuidance.miniPages.");
3445
+ }
3446
+ if (output.missingRequirements) {
3447
+ lines.push("Next: configure missing env/secrets from llmGuidance.requirements.");
3448
+ }
3449
+ lines.push("Use --json for LLM-readable integration guidance.");
3450
+ renderOutput(lines.join("\n"), options);
3451
+ }
3472
3452
  function requireStack(value) {
3473
3453
  if (value === "react-vite" || value === "taro") {
3474
3454
  return value;
@@ -3631,7 +3611,7 @@ addJsonOption(addOrganizationOption(addRegistryOption(addon.command("install <sp
3631
3611
  organizationCode: options.organizationCode,
3632
3612
  installParameters: parseKeyValuePairs(options.set)
3633
3613
  });
3634
- renderOutput(result, options);
3614
+ renderAddonInstallResult(result, "install", options);
3635
3615
  });
3636
3616
  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 Option("--application-type <type>", "Application type").choices(["web", "mini"])).option("--set <key=value>", "Install parameter", (value, previous = []) => previous.concat(value), []).action(async (specifier, options) => {
3637
3617
  const registry = resolveRegistryFromOptions(options);
@@ -3643,7 +3623,7 @@ addJsonOption(addOrganizationOption(addRegistryOption(addon.command("upgrade <sp
3643
3623
  organizationCode: options.organizationCode,
3644
3624
  installParameters: parseKeyValuePairs(options.set)
3645
3625
  });
3646
- renderOutput(result, options);
3626
+ renderAddonInstallResult(result, "upgrade", options);
3647
3627
  });
3648
3628
  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) => {
3649
3629
  const installed = await listInstalledAddons(resolveAddonTargetDir(options.target));