@amaster.ai/cli 1.1.31 → 1.1.33

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,89 @@ 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 removePathExtension(path) {
887
+ return path.replace(/\.[^/.]+$/, "");
888
+ }
889
+ function toImportSpecifier(targetPath) {
890
+ const normalized = targetPath.replace(/\\/g, "/").replace(/^src\//, "@/");
891
+ return removePathExtension(normalized).replace(/\/index$/, "");
892
+ }
893
+ function buildAddonLlmGuidance(input) {
894
+ const pageMembers = input.meta.members.filter((member) => member.type === "page");
895
+ const componentMembers = input.meta.members.filter((member) => member.type === "component");
896
+ const settingsMembers = input.meta.members.filter((member) => member.type === "settings");
897
+ const webRoutes = input.meta.members.filter((member) => member.type === "page" && member.page?.web).map((member) => ({
898
+ route: member.page.web.route,
899
+ entry: member.page.web.entry.startsWith("src/") ? member.page.web.entry : `src/${member.page.web.entry}`,
900
+ title: member.page.web.title,
901
+ visible: member.page.web.visible,
902
+ suggestedFile: "src/routes.tsx"
903
+ }));
904
+ const miniPages = input.meta.members.filter((member) => member.type === "page" && member.page?.mini).map((member) => ({
905
+ pagePath: member.page.mini.pagePath,
906
+ suggestedFile: "src/app.config.ts",
907
+ tabBar: member.page.mini.tabBar
908
+ }));
909
+ const components = componentMembers.map((member) => ({
910
+ name: member.name,
911
+ importFrom: member.targetPaths[0] ? toImportSpecifier(member.targetPaths[0]) : ""
912
+ }));
913
+ const settings = settingsMembers.map((member) => ({
914
+ targetPath: member.settings?.targetPath || member.targetPaths[0] || "",
915
+ paths: member.settings?.paths.map((item) => item.path) || []
916
+ }));
917
+ const instructions = [
918
+ "Use the installed Addon files in the host application's existing pages, components, routes, dialogs, or preview areas.",
919
+ "Do not reinstall to complete integration; edit application source files directly."
920
+ ];
921
+ if (pageMembers.length > 0) {
922
+ instructions.push("Wire the installed page members into the application's existing routing/configuration style.");
923
+ }
924
+ if (componentMembers.length > 0) {
925
+ instructions.push("Use installed component members from their target paths where the application needs them.");
926
+ }
927
+ if (hasInstallRequirements(input.requirements)) {
928
+ instructions.push("Configure the declared env/secret requirements before running or deploying the application.");
929
+ }
930
+ if (hasNpmDependencies(input.npm)) {
931
+ instructions.push("NPM dependencies have been written to package.json; avoid adding duplicate dependency entries.");
932
+ }
933
+ return {
934
+ summary: input.meta.manifest.description || input.meta.manifest.title || `Installed addon ${input.meta.name}@${input.meta.version}.`,
935
+ instructions,
936
+ prompt: input.promptContent ? { path: "PROMPT.md", content: input.promptContent } : void 0,
937
+ webRoutes: webRoutes.length ? webRoutes : void 0,
938
+ miniPages: miniPages.length ? miniPages : void 0,
939
+ components: components.length ? components : void 0,
940
+ settings: settings.length ? settings : void 0,
941
+ requirements: hasInstallRequirements(input.requirements) ? input.requirements : void 0,
942
+ npm: hasNpmDependencies(input.npm) ? input.npm : void 0
943
+ };
944
+ }
945
+ async function readAddonPrompt(extractedDir, manifest) {
946
+ const hasPromptMemberAtRoot = manifest.members.some((member) => {
947
+ if (member.type !== "skill") {
948
+ return false;
949
+ }
950
+ const sourcePath = resolveMemberSourcePath(member);
951
+ return sourcePath === "PROMPT.md";
952
+ });
953
+ if (hasPromptMemberAtRoot) {
954
+ return void 0;
955
+ }
956
+ const promptPath = join(extractedDir, "PROMPT.md");
957
+ if (!existsSync(promptPath)) {
958
+ return void 0;
959
+ }
960
+ const content = (await readFile(promptPath, "utf8")).trim();
961
+ return content || void 0;
962
+ }
895
963
  function getAddonMetaPath(targetDir, addonName) {
896
964
  return join(targetDir, "src", "addons", addonName, "meta.json");
897
965
  }
@@ -1650,136 +1718,6 @@ async function validateUpgradeConflicts(targetDir, plan, existingMetas, previous
1650
1718
  });
1651
1719
  }
1652
1720
  }
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
1721
  async function materializeAddon(options) {
1784
1722
  const targetDir = resolve(options.targetDir);
1785
1723
  const existingMetas = await listInstalledAddons(targetDir);
@@ -1823,19 +1761,26 @@ async function materializeAddon(options) {
1823
1761
  });
1824
1762
  await ensureParentDirectory(plan.metaPath);
1825
1763
  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
1764
  if (options.installPackageDependencies && packageJsonFiles.length) {
1829
1765
  await installPackageDependencies(targetDir);
1830
1766
  }
1831
1767
  const requirements = resolveInstallRequirements(plan.manifest);
1768
+ const promptContent = await readAddonPrompt(options.extractedDir, plan.manifest);
1769
+ const llmGuidance = buildAddonLlmGuidance({
1770
+ operation: options.mode,
1771
+ meta,
1772
+ requirements,
1773
+ npm,
1774
+ promptContent
1775
+ });
1832
1776
  return {
1833
1777
  meta,
1834
1778
  writtenFiles: installedFiles.map((file) => file.path).concat(packageJsonFiles, restoredSettingsFiles, settingsResult.writtenFiles),
1835
1779
  removedFiles,
1836
1780
  requirements,
1837
1781
  missingRequirements: buildMissingRequirements(requirements),
1838
- npm
1782
+ npm,
1783
+ llmGuidance
1839
1784
  };
1840
1785
  }
1841
1786
  async function installAddonFromExtractedDirectory(options) {
@@ -1860,6 +1805,33 @@ function createOrganizationHeaders(organizationCode) {
1860
1805
  "x-organization-code": organizationCode
1861
1806
  };
1862
1807
  }
1808
+ function toAddonSearchResponse(response) {
1809
+ return {
1810
+ items: response.items.flatMap((addon2) => {
1811
+ const version = addon2.latestVersion;
1812
+ if (!version) {
1813
+ return [];
1814
+ }
1815
+ return [
1816
+ {
1817
+ name: addon2.name,
1818
+ version: version.version,
1819
+ installSpecifier: `${addon2.name}@${version.version}`,
1820
+ title: version.title,
1821
+ description: version.description,
1822
+ category: version.category,
1823
+ applicationTypes: version.applicationTypes,
1824
+ phases: version.phases,
1825
+ memberTypes: version.memberTypes,
1826
+ ...addon2.imageUrl ? { imageUrl: addon2.imageUrl } : {}
1827
+ }
1828
+ ];
1829
+ }),
1830
+ page: response.page,
1831
+ pageSize: response.pageSize,
1832
+ total: response.total
1833
+ };
1834
+ }
1863
1835
  function parseAddonSpecifier(specifier) {
1864
1836
  const trimmed = specifier.trim();
1865
1837
  if (!trimmed) {
@@ -1885,11 +1857,12 @@ async function searchAddons(registry, options) {
1885
1857
  if (options.scope) query.set("scope", options.scope);
1886
1858
  if (options.page) query.set("page", String(options.page));
1887
1859
  if (options.pageSize) query.set("pageSize", String(options.pageSize));
1888
- return await requestJson(registry, `/api/addons?${query.toString()}`, {
1860
+ const response = await requestJson(registry, `/api/addons?${query.toString()}`, {
1889
1861
  method: "GET",
1890
1862
  headers: createOrganizationHeaders(options.organizationCode),
1891
1863
  unwrapData: true
1892
1864
  });
1865
+ return toAddonSearchResponse(response);
1893
1866
  }
1894
1867
  async function getAddon(registry, name, organizationCode) {
1895
1868
  return await requestJson(registry, `/api/addons/${encodeURIComponent(name)}`, {
@@ -3469,6 +3442,41 @@ function formatLoginIdentity(user) {
3469
3442
  function resolveAddonTargetDir(target) {
3470
3443
  return target ? target : resolveNearestPackageRoot();
3471
3444
  }
3445
+ function renderAddonInstallResult(result, operation, options) {
3446
+ const output = {
3447
+ success: true,
3448
+ operation,
3449
+ addon: {
3450
+ name: result.meta.name,
3451
+ version: result.meta.version,
3452
+ applicationType: result.meta.applicationType
3453
+ },
3454
+ llmGuidance: result.llmGuidance
3455
+ };
3456
+ if (options.json) {
3457
+ renderOutput(output, options);
3458
+ return;
3459
+ }
3460
+ const lines = [
3461
+ `Addon ${operation === "install" ? "installed" : "upgraded"}: ${result.meta.name}@${result.meta.version}`,
3462
+ `Application type: ${result.meta.applicationType}`,
3463
+ `Written files: ${result.writtenFiles.length}`
3464
+ ];
3465
+ if (result.removedFiles.length) {
3466
+ lines.push(`Removed files: ${result.removedFiles.length}`);
3467
+ }
3468
+ if (result.llmGuidance.webRoutes?.length) {
3469
+ lines.push("Next: wire web routes from llmGuidance.webRoutes.");
3470
+ }
3471
+ if (result.llmGuidance.miniPages?.length) {
3472
+ lines.push("Next: wire mini pages from llmGuidance.miniPages.");
3473
+ }
3474
+ if (result.missingRequirements.envs?.length || result.missingRequirements.secrets?.length) {
3475
+ lines.push("Next: configure missing env/secrets from llmGuidance.requirements.");
3476
+ }
3477
+ lines.push("Use --json for LLM-readable integration guidance.");
3478
+ renderOutput(lines.join("\n"), options);
3479
+ }
3472
3480
  function requireStack(value) {
3473
3481
  if (value === "react-vite" || value === "taro") {
3474
3482
  return value;
@@ -3631,7 +3639,7 @@ addJsonOption(addOrganizationOption(addRegistryOption(addon.command("install <sp
3631
3639
  organizationCode: options.organizationCode,
3632
3640
  installParameters: parseKeyValuePairs(options.set)
3633
3641
  });
3634
- renderOutput(result, options);
3642
+ renderAddonInstallResult(result, "install", options);
3635
3643
  });
3636
3644
  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
3645
  const registry = resolveRegistryFromOptions(options);
@@ -3643,7 +3651,7 @@ addJsonOption(addOrganizationOption(addRegistryOption(addon.command("upgrade <sp
3643
3651
  organizationCode: options.organizationCode,
3644
3652
  installParameters: parseKeyValuePairs(options.set)
3645
3653
  });
3646
- renderOutput(result, options);
3654
+ renderAddonInstallResult(result, "upgrade", options);
3647
3655
  });
3648
3656
  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
3657
  const installed = await listInstalledAddons(resolveAddonTargetDir(options.target));