@amaster.ai/cli 1.1.47 → 1.1.49

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
@@ -585,7 +585,7 @@ function validateAddonManifest(manifest) {
585
585
  validateInstallNpm(manifest);
586
586
  }
587
587
  function validateMembers(manifest) {
588
- const allowedTypes = /* @__PURE__ */ new Set(["component", "page", "function", "skill", "theme", "settings", "workflow", "bpmn", "entity", "datasource"]);
588
+ const allowedTypes = /* @__PURE__ */ new Set(["component", "page", "function", "skill", "theme", "settings", "workflow", "bpmn", "entity", "datasource", "assets"]);
589
589
  for (const member of manifest.members) {
590
590
  if (!member.name || typeof member.name !== "string") {
591
591
  throw new Error("addon.json member missing name");
@@ -965,6 +965,7 @@ async function tryDetectNearestApplicationType(startDir = process.cwd()) {
965
965
 
966
966
  // src/marketplace/install.ts
967
967
  var execFileAsync = promisify(execFile);
968
+ var ADDON_PROMPT_FILE_NAME = "PROMPT.md";
968
969
  var AddonInstallConflictError = class extends Error {
969
970
  constructor(input) {
970
971
  super(`Addon ${input.operation} has ${input.conflicts.length} conflict(s)`);
@@ -1163,6 +1164,9 @@ function toImportSpecifier(targetPath) {
1163
1164
  const normalized = targetPath.replace(/\\/g, "/").replace(/^src\//, "@/");
1164
1165
  return removePathExtension(normalized).replace(/\/index$/, "");
1165
1166
  }
1167
+ function toAssetImportSpecifier(targetPath) {
1168
+ return targetPath.replace(/\\/g, "/").replace(/^src\//, "@/");
1169
+ }
1166
1170
  function resolveInstalledAddonDisplay(meta) {
1167
1171
  const legacyMeta = meta;
1168
1172
  return {
@@ -1174,6 +1178,7 @@ function buildAddonLlmGuidance(input) {
1174
1178
  const pageMembers = input.meta.members.filter((member) => member.type === "page");
1175
1179
  const componentMembers = input.meta.members.filter((member) => member.type === "component");
1176
1180
  const functionMembers = input.meta.members.filter((member) => member.type === "function");
1181
+ const assetMembers = input.meta.members.filter((member) => member.type === "assets");
1177
1182
  const settingsMembers = input.meta.members.filter((member) => member.type === "settings");
1178
1183
  const webRoutes = input.meta.members.filter((member) => member.type === "page" && member.page?.web).map((member) => ({
1179
1184
  route: member.page.web.route,
@@ -1195,11 +1200,17 @@ function buildAddonLlmGuidance(input) {
1195
1200
  name: member.name,
1196
1201
  targetPaths: member.targetPaths
1197
1202
  }));
1203
+ const assets = assetMembers.map((member) => ({
1204
+ name: member.name,
1205
+ targetPaths: member.targetPaths,
1206
+ importFrom: member.targetPaths[0] ? toAssetImportSpecifier(member.targetPaths[0]) : void 0
1207
+ }));
1198
1208
  const settings = settingsMembers.map((member) => ({
1199
1209
  targetPath: member.settings?.targetPath || member.targetPaths[0] || "",
1200
1210
  paths: member.settings?.paths.map((item) => item.path) || []
1201
1211
  }));
1202
1212
  const display = resolveInstalledAddonDisplay(input.meta);
1213
+ const promptContent = input.meta.guidance?.prompt?.content ?? input.promptContent;
1203
1214
  const instructions = [
1204
1215
  "Use the installed Addon files in the host application's existing pages, components, routes, dialogs, or preview areas.",
1205
1216
  "Do not reinstall to complete integration; edit application source files directly."
@@ -1213,6 +1224,9 @@ function buildAddonLlmGuidance(input) {
1213
1224
  if (functionMembers.length > 0) {
1214
1225
  instructions.push("Use installed function members by invoking their function names from the host application.");
1215
1226
  }
1227
+ if (assetMembers.length > 0) {
1228
+ instructions.push("Import installed asset members from their @/assets paths instead of hardcoding external URLs.");
1229
+ }
1216
1230
  if (hasInstallRequirements(input.requirements)) {
1217
1231
  instructions.push(
1218
1232
  "Configure the declared env/secret requirements before running or deploying the application. Use the app_secret_env tool instead of writing secret values into source files or .env examples."
@@ -1224,11 +1238,12 @@ function buildAddonLlmGuidance(input) {
1224
1238
  return {
1225
1239
  summary: display.description || display.title || `Installed addon ${input.meta.name}@${input.meta.version}.`,
1226
1240
  instructions,
1227
- prompt: input.promptContent ? { path: "PROMPT.md", content: input.promptContent } : void 0,
1241
+ prompt: promptContent ? { path: getAddonPromptTargetPath(input.meta.name), content: promptContent } : void 0,
1228
1242
  webRoutes: webRoutes.length ? webRoutes : void 0,
1229
1243
  miniPages: miniPages.length ? miniPages : void 0,
1230
1244
  components: components.length ? components : void 0,
1231
1245
  functions: functions.length ? functions : void 0,
1246
+ assets: assets.length ? assets : void 0,
1232
1247
  settings: settings.length ? settings : void 0,
1233
1248
  requirements: hasInstallRequirements(input.requirements) ? input.requirements : void 0,
1234
1249
  npm: hasNpmDependencies(input.npm) ? input.npm : void 0
@@ -1237,11 +1252,35 @@ function buildAddonLlmGuidance(input) {
1237
1252
  function getAddonMetaPath(targetDir, addonName) {
1238
1253
  return join(targetDir, "src", "addons", addonName, "meta.json");
1239
1254
  }
1255
+ function getAddonPromptTargetPath(addonName) {
1256
+ return `src/addons/${addonName}/${ADDON_PROMPT_FILE_NAME}`;
1257
+ }
1258
+ async function hydrateInstalledAddonPrompt(metaPath, meta) {
1259
+ const prompt = meta.guidance?.prompt;
1260
+ if (!prompt?.path || prompt.content) {
1261
+ return meta;
1262
+ }
1263
+ const promptPath = ensurePathInsideTarget(dirname(metaPath), prompt.path);
1264
+ if (!existsSync(promptPath)) {
1265
+ return meta;
1266
+ }
1267
+ return {
1268
+ ...meta,
1269
+ guidance: {
1270
+ ...meta.guidance,
1271
+ prompt: {
1272
+ ...prompt,
1273
+ content: (await readFile(promptPath, "utf8")).trim()
1274
+ }
1275
+ }
1276
+ };
1277
+ }
1240
1278
  async function readInstalledAddonMeta(metaPath) {
1241
1279
  if (!existsSync(metaPath)) {
1242
1280
  return null;
1243
1281
  }
1244
- return JSON.parse(await readFile(metaPath, "utf8"));
1282
+ const meta = JSON.parse(await readFile(metaPath, "utf8"));
1283
+ return await hydrateInstalledAddonPrompt(metaPath, meta);
1245
1284
  }
1246
1285
  async function listAddonMetaPaths(targetDir) {
1247
1286
  const addonsDir = join(targetDir, "src", "addons");
@@ -1345,12 +1384,12 @@ async function collectDirectoryFiles(sourceDir) {
1345
1384
  }
1346
1385
  return files.sort();
1347
1386
  }
1348
- async function planCopyMember(sourceRoot, sourceRelativePath, targetBaseRelativeDir, member, targetRelativePath) {
1387
+ async function planCopyMember(sourceRoot, sourceRelativePath, targetBaseRelativeDir, member, targetRelativePath, defaultTargetRelativePath) {
1349
1388
  const sourceAbsolutePath = join(sourceRoot, sourceRelativePath);
1350
1389
  const sourceStat = await stat(sourceAbsolutePath);
1351
1390
  const plannedFiles = [];
1352
1391
  const targetPaths = [];
1353
- const defaultTargetPath = join(targetBaseRelativeDir, basename(sourceRelativePath)).replace(/\\/g, "/");
1392
+ const defaultTargetPath = defaultTargetRelativePath ?? join(targetBaseRelativeDir, basename(sourceRelativePath)).replace(/\\/g, "/");
1354
1393
  const memberTargetPath = targetRelativePath ?? defaultTargetPath;
1355
1394
  if (sourceStat.isDirectory()) {
1356
1395
  const sourceFiles = await collectDirectoryFiles(sourceAbsolutePath);
@@ -1434,6 +1473,9 @@ async function buildInstallPlan(options) {
1434
1473
  case "theme":
1435
1474
  targetBaseRelativeDir = join("src", "assets", manifest.name);
1436
1475
  break;
1476
+ case "assets":
1477
+ targetBaseRelativeDir = join("src", "assets", manifest.name);
1478
+ break;
1437
1479
  case "workflow":
1438
1480
  targetBaseRelativeDir = join("src", "workflow");
1439
1481
  break;
@@ -1453,6 +1495,9 @@ async function buildInstallPlan(options) {
1453
1495
  throw new Error(`Unsupported addon member type: ${member.type}`);
1454
1496
  }
1455
1497
  const targetRelativePath = resolveMemberTargetPath(member);
1498
+ const sourceAbsolutePath = join(options.extractedDir, sourceRelativePath);
1499
+ const sourceStat = await stat(sourceAbsolutePath);
1500
+ const defaultTargetPath = member.type === "assets" && sourceStat.isDirectory() ? targetBaseRelativeDir.replace(/\\/g, "/") : join(targetBaseRelativeDir, basename(sourceRelativePath)).replace(/\\/g, "/");
1456
1501
  if (targetRelativePath && !isSameOrInsidePath(targetRelativePath, targetBaseRelativeDir)) {
1457
1502
  throw new Error(
1458
1503
  `Member ${member.name} target.path must stay inside ${targetBaseRelativeDir}: ${targetRelativePath}`
@@ -1463,7 +1508,8 @@ async function buildInstallPlan(options) {
1463
1508
  sourceRelativePath,
1464
1509
  targetBaseRelativeDir,
1465
1510
  member,
1466
- targetRelativePath
1511
+ targetRelativePath,
1512
+ defaultTargetPath
1467
1513
  );
1468
1514
  files.push(...planned.files);
1469
1515
  const installedMember = {
@@ -1558,6 +1604,12 @@ function buildInstalledAddonMeta(options) {
1558
1604
  installParameters: options.installParameters,
1559
1605
  requirements: resolveInstallRequirements(options.manifest),
1560
1606
  npm: resolveInstallNpm(options.manifest),
1607
+ guidance: options.promptContent ? {
1608
+ prompt: {
1609
+ path: ADDON_PROMPT_FILE_NAME,
1610
+ contentHash: sha256Buffer(Buffer.from(options.promptContent))
1611
+ }
1612
+ } : void 0,
1561
1613
  members: options.members,
1562
1614
  files: options.files
1563
1615
  };
@@ -1572,6 +1624,20 @@ async function writePlannedFiles(targetDir, planFiles) {
1572
1624
  await copyFile(file.sourcePath, absoluteTargetPath);
1573
1625
  }
1574
1626
  }
1627
+ async function writeAddonPromptFile(targetDir, addonName, promptContent) {
1628
+ const promptTargetPath = getAddonPromptTargetPath(addonName);
1629
+ const absolutePromptPath = ensurePathInsideTarget(targetDir, promptTargetPath);
1630
+ if (promptContent) {
1631
+ await ensureParentDirectory(absolutePromptPath);
1632
+ await writeFile(absolutePromptPath, promptContent);
1633
+ return { writtenFiles: [promptTargetPath], removedFiles: [] };
1634
+ }
1635
+ if (existsSync(absolutePromptPath)) {
1636
+ await unlink(absolutePromptPath);
1637
+ return { writtenFiles: [], removedFiles: [promptTargetPath] };
1638
+ }
1639
+ return { writtenFiles: [], removedFiles: [] };
1640
+ }
1575
1641
  function isPlainObject(value) {
1576
1642
  return value !== null && typeof value === "object" && !Array.isArray(value);
1577
1643
  }
@@ -2075,6 +2141,8 @@ async function materializeAddon(options) {
2075
2141
  const packageJsonFiles = await applyNpmDependencies(targetDir, npm);
2076
2142
  await writePlannedFiles(targetDir, plan.files);
2077
2143
  const settingsResult = await applyPlannedSettings(targetDir, plan.settings);
2144
+ const promptContent = options.promptContent?.trim() || void 0;
2145
+ const promptFiles = await writeAddonPromptFile(targetDir, plan.manifest.name, promptContent);
2078
2146
  const installedFiles = [];
2079
2147
  for (const plannedFile of plan.files) {
2080
2148
  installedFiles.push(
@@ -2089,6 +2157,7 @@ async function materializeAddon(options) {
2089
2157
  installParameters: plan.installParameters,
2090
2158
  members: attachAppliedSettings(plan.members, settingsResult.appliedSettings),
2091
2159
  files: installedFiles,
2160
+ promptContent,
2092
2161
  installedAt: previousMeta?.installedAt
2093
2162
  });
2094
2163
  await ensureParentDirectory(plan.metaPath);
@@ -2098,7 +2167,6 @@ async function materializeAddon(options) {
2098
2167
  await installPackageDependencies(targetDir);
2099
2168
  }
2100
2169
  const requirements = resolveInstallRequirements(plan.manifest);
2101
- const promptContent = options.promptContent?.trim() || void 0;
2102
2170
  const llmGuidance = buildAddonLlmGuidance({
2103
2171
  operation: options.mode,
2104
2172
  meta,
@@ -2108,8 +2176,8 @@ async function materializeAddon(options) {
2108
2176
  });
2109
2177
  return {
2110
2178
  meta,
2111
- writtenFiles: installedFiles.map((file) => file.path).concat(packageJsonFiles, restoredSettingsFiles, settingsResult.writtenFiles),
2112
- removedFiles,
2179
+ writtenFiles: installedFiles.map((file) => file.path).concat(promptFiles.writtenFiles, packageJsonFiles, restoredSettingsFiles, settingsResult.writtenFiles),
2180
+ removedFiles: removedFiles.concat(promptFiles.removedFiles),
2113
2181
  requirements,
2114
2182
  missingRequirements: buildMissingRequirements(requirements),
2115
2183
  npm,
@@ -3897,9 +3965,9 @@ addJsonOption(addRegistryOption(program.command("whoami").description("Show the
3897
3965
  }
3898
3966
  );
3899
3967
  var addon = program.command("addon").description("Addon marketplace commands");
3900
- addJsonOption(addOrganizationOption(addRegistryOption(addon.command("search [query]").description("Search addons")))).option("--application-type <type>", "Application type").option("--phase <phase>", "Phase filter").option("--member-type <type>", "Member type filter").option("--scope <scope>", "Scope filter").option("--page <page>", "Page number", (value) => Number.parseInt(value, 10)).option("--page-size <pageSize>", "Page size", (value) => Number.parseInt(value, 10)).action(async (query, options) => {
3968
+ addJsonOption(addOrganizationOption(addRegistryOption(addon.command("search [query]").description("Search addons")))).option("--target <path>", "Application root directory used to detect application type").option("--application-type <type>", "Application type").option("--phase <phase>", "Phase filter").option("--member-type <type>", "Member type filter").option("--scope <scope>", "Scope filter").option("--page <page>", "Page number", (value) => Number.parseInt(value, 10)).option("--page-size <pageSize>", "Page size", (value) => Number.parseInt(value, 10)).action(async (query, options) => {
3901
3969
  const registry = resolveRegistryFromOptions(options);
3902
- const applicationType = options.applicationType ?? await tryDetectNearestApplicationType();
3970
+ const applicationType = options.applicationType ?? await tryDetectNearestApplicationType(options.target);
3903
3971
  const result = await searchAddons(registry, {
3904
3972
  query,
3905
3973
  applicationType,