@amaster.ai/cli 1.1.36 → 1.1.37

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
@@ -4,14 +4,14 @@ import { createInterface } from 'readline/promises';
4
4
  import { stdin, stdout } from 'process';
5
5
  import { Command, Option } from 'commander';
6
6
  import { readFile, mkdtemp, stat, rm, writeFile, readdir, access, unlink, copyFile, mkdir } from 'fs/promises';
7
- import { join, resolve, basename, dirname, relative, parse, extname } from 'path';
7
+ import { join, resolve, basename, dirname, relative, parse, extname, isAbsolute } from 'path';
8
8
  import { randomBytes, createHash, randomUUID } from 'crypto';
9
9
  import { tmpdir, homedir } from 'os';
10
10
  import * as tar from 'tar';
11
11
  import { createServer } from 'http';
12
12
  import { execFile, spawn, spawnSync } from 'child_process';
13
+ import YAML2, { parse as parse$1 } from 'yaml';
13
14
  import { promisify } from 'util';
14
- import YAML2 from 'yaml';
15
15
  import ts from 'typescript';
16
16
 
17
17
  var EXCLUDED_NAMES = /* @__PURE__ */ new Set([".git", "node_modules", ".DS_Store", "PROMPT.md"]);
@@ -533,12 +533,33 @@ async function getCurrentUser(registry) {
533
533
  function logout(registry) {
534
534
  clearStoredSession(registry);
535
535
  }
536
+ var SKILL_RESOURCE_MAX_FILE_SIZE_BYTES = 1024 * 1024;
537
+ var SKILL_REFERENCE_EXTENSIONS = /* @__PURE__ */ new Set([".md", ".mdx", ".txt", ".json", ".yml", ".yaml", ".ts", ".tsx", ".js", ".mjs"]);
538
+ var SKILL_ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
539
+ ...SKILL_REFERENCE_EXTENSIONS,
540
+ ".bpmn",
541
+ ".csv",
542
+ ".html",
543
+ ".jsonl",
544
+ ".toml",
545
+ ".xml",
546
+ ".css",
547
+ ".scss",
548
+ ".svg",
549
+ ".png",
550
+ ".jpg",
551
+ ".jpeg",
552
+ ".webp"
553
+ ]);
554
+ var SKILL_SCRIPT_EXTENSIONS = /* @__PURE__ */ new Set([".sh", ".ts", ".tsx", ".js", ".mjs", ".cjs"]);
555
+ var SKILL_SCRIPT_RESOURCE_EXTENSIONS = /* @__PURE__ */ new Set([...SKILL_ASSET_EXTENSIONS, ...SKILL_SCRIPT_EXTENSIONS]);
536
556
  async function loadAddonManifestFromDirectory(directory) {
537
557
  const manifestPath = join(directory, "addon.json");
538
558
  const manifestText = await readFile(manifestPath, "utf8");
539
559
  const manifest = JSON.parse(manifestText);
540
560
  validateAddonManifest(manifest);
541
561
  await assertDisplayAssetPathsExist(directory, manifest);
562
+ await assertSkillMemberContracts(directory, manifest);
542
563
  return manifest;
543
564
  }
544
565
  function validateAddonManifest(manifest) {
@@ -558,9 +579,27 @@ function validateAddonManifest(manifest) {
558
579
  throw new Error("addon.json missing members");
559
580
  }
560
581
  validateDisplayAssets(manifest);
582
+ validateMembers(manifest);
561
583
  validateInstallRequirements(manifest);
562
584
  validateInstallNpm(manifest);
563
585
  }
586
+ function validateMembers(manifest) {
587
+ const allowedTypes = /* @__PURE__ */ new Set(["component", "page", "function", "skill", "theme", "settings", "workflow", "bpmn", "entity", "datasource"]);
588
+ for (const member of manifest.members) {
589
+ if (!member.name || typeof member.name !== "string") {
590
+ throw new Error("addon.json member missing name");
591
+ }
592
+ if (!member.type || typeof member.type !== "string") {
593
+ throw new Error(`addon.json member ${member.name} missing type`);
594
+ }
595
+ if (!allowedTypes.has(member.type)) {
596
+ throw new Error(`Unsupported addon member type: ${member.type}`);
597
+ }
598
+ if (!resolveMemberSourcePath(member)) {
599
+ throw new Error(`addon.json member ${member.name} missing source.path`);
600
+ }
601
+ }
602
+ }
564
603
  function validateDisplayAssets(manifest) {
565
604
  const image = manifest.display.image;
566
605
  if (image !== void 0) {
@@ -591,6 +630,128 @@ async function assertDisplayAssetPathsExist(directory, manifest) {
591
630
  await assertPathExists(directory, normalizeRelativePath(assetPath, "display asset path"));
592
631
  }
593
632
  }
633
+ async function assertSkillMemberContracts(directory, manifest) {
634
+ for (const member of manifest.members) {
635
+ if (member.type !== "skill") {
636
+ continue;
637
+ }
638
+ const sourcePath = resolveMemberSourcePath(member);
639
+ if (!sourcePath) {
640
+ throw new Error(`Skill member ${member.name} is missing source.path`);
641
+ }
642
+ const sourceStat = await stat(join(directory, sourcePath));
643
+ if (!sourceStat.isDirectory()) {
644
+ throw new Error(`Skill member ${member.name} source.path must be a directory`);
645
+ }
646
+ await assertSkillMarkdown(directory, member, sourcePath);
647
+ await assertOptionalSkillResourceDirectory(directory, member, sourcePath, "references", SKILL_REFERENCE_EXTENSIONS);
648
+ await assertOptionalSkillResourceDirectory(directory, member, sourcePath, "assets", SKILL_ASSET_EXTENSIONS);
649
+ await assertSkillScripts(directory, member, sourcePath);
650
+ }
651
+ }
652
+ async function assertSkillMarkdown(directory, member, sourcePath) {
653
+ const skillPath = join(sourcePath, "SKILL.md");
654
+ await assertPathExists(directory, skillPath);
655
+ const content = await readFile(join(directory, skillPath), "utf8");
656
+ const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
657
+ if (!match) {
658
+ throw new Error(`Skill member ${member.name} SKILL.md missing YAML frontmatter`);
659
+ }
660
+ let frontmatter;
661
+ try {
662
+ frontmatter = parse$1(match[1] ?? "");
663
+ } catch (error) {
664
+ throw new Error(`Skill member ${member.name} SKILL.md frontmatter is invalid YAML: ${error instanceof Error ? error.message : String(error)}`);
665
+ }
666
+ if (!frontmatter || typeof frontmatter !== "object" || Array.isArray(frontmatter)) {
667
+ throw new Error(`Skill member ${member.name} SKILL.md frontmatter must be a YAML object`);
668
+ }
669
+ const record = frontmatter;
670
+ if (typeof record.name !== "string" || !record.name.trim()) {
671
+ throw new Error(`Skill member ${member.name} SKILL.md frontmatter missing name`);
672
+ }
673
+ if (!/^[a-z0-9-]+$/.test(record.name.trim())) {
674
+ throw new Error(`Skill member ${member.name} SKILL.md frontmatter name must be hyphen-case`);
675
+ }
676
+ if (typeof record.description !== "string" || !record.description.trim()) {
677
+ throw new Error(`Skill member ${member.name} SKILL.md frontmatter missing description`);
678
+ }
679
+ }
680
+ async function assertOptionalSkillResourceDirectory(directory, member, sourcePath, directoryName, allowedExtensions) {
681
+ const relativePath = join(sourcePath, directoryName);
682
+ if (!await pathExists(directory, relativePath)) {
683
+ return;
684
+ }
685
+ const resourceStat = await stat(join(directory, relativePath));
686
+ if (!resourceStat.isDirectory()) {
687
+ throw new Error(`Skill member ${member.name} ${directoryName}/ must be a directory`);
688
+ }
689
+ for (const file of await collectRelativeFiles(directory, relativePath)) {
690
+ if (!allowedExtensions.has(extname(file).toLowerCase())) {
691
+ throw new Error(`Skill member ${member.name} has unsupported ${directoryName} file type: ${file}`);
692
+ }
693
+ const fileStat = await stat(join(directory, file));
694
+ if (fileStat.size > SKILL_RESOURCE_MAX_FILE_SIZE_BYTES) {
695
+ throw new Error(`Skill member ${member.name} ${directoryName} file is too large: ${file}`);
696
+ }
697
+ }
698
+ }
699
+ async function assertSkillScripts(directory, member, sourcePath) {
700
+ const scriptsPath = join(sourcePath, "scripts");
701
+ if (!await pathExists(directory, scriptsPath)) {
702
+ return;
703
+ }
704
+ const scriptsStat = await stat(join(directory, scriptsPath));
705
+ if (!scriptsStat.isDirectory()) {
706
+ throw new Error(`Skill member ${member.name} scripts/ must be a directory`);
707
+ }
708
+ await assertSkillResourceFiles(directory, member, scriptsPath, "scripts", SKILL_SCRIPT_RESOURCE_EXTENSIONS);
709
+ const manifestPath = join(scriptsPath, "scripts.json");
710
+ await assertPathExists(directory, manifestPath);
711
+ const scriptsManifest = JSON.parse(await readFile(join(directory, manifestPath), "utf8"));
712
+ if (!scriptsManifest || typeof scriptsManifest !== "object" || Array.isArray(scriptsManifest)) {
713
+ throw new Error(`Skill member ${member.name} scripts.json must contain a JSON object`);
714
+ }
715
+ const scripts = scriptsManifest.scripts;
716
+ if (!Array.isArray(scripts)) {
717
+ throw new Error(`Skill member ${member.name} scripts.json missing scripts array`);
718
+ }
719
+ if (!scripts.length) {
720
+ throw new Error(`Skill member ${member.name} scripts.json must declare at least one script entrypoint`);
721
+ }
722
+ const declaredPaths = /* @__PURE__ */ new Set();
723
+ for (const script of scripts) {
724
+ if (!script || typeof script !== "object" || Array.isArray(script)) {
725
+ throw new Error(`Skill member ${member.name} scripts.json contains an invalid script entry`);
726
+ }
727
+ const scriptRecord = script;
728
+ if (typeof scriptRecord.name !== "string" || !scriptRecord.name.trim()) {
729
+ throw new Error(`Skill member ${member.name} scripts.json script missing name`);
730
+ }
731
+ if (typeof scriptRecord.path !== "string" || !scriptRecord.path.trim()) {
732
+ throw new Error(`Skill member ${member.name} scripts.json script ${scriptRecord.name} missing path`);
733
+ }
734
+ if (typeof scriptRecord.description !== "string" || !scriptRecord.description.trim()) {
735
+ throw new Error(`Skill member ${member.name} scripts.json script ${scriptRecord.name} missing description`);
736
+ }
737
+ if (typeof scriptRecord.requiresConfirmation !== "boolean") {
738
+ throw new Error(`Skill member ${member.name} scripts.json script ${scriptRecord.name} missing requiresConfirmation`);
739
+ }
740
+ if (typeof scriptRecord.writesProjectFiles !== "boolean") {
741
+ throw new Error(`Skill member ${member.name} scripts.json script ${scriptRecord.name} missing writesProjectFiles`);
742
+ }
743
+ const scriptPath = normalizeSkillScriptPath(scriptRecord.path, member.name);
744
+ if (!SKILL_SCRIPT_EXTENSIONS.has(extname(scriptPath).toLowerCase())) {
745
+ throw new Error(`Skill member ${member.name} has unsupported script file type: ${scriptPath}`);
746
+ }
747
+ await assertPathExists(directory, join(scriptsPath, scriptPath));
748
+ const normalizedScriptPath = join(scriptsPath, scriptPath).replace(/\\/g, "/");
749
+ if (declaredPaths.has(normalizedScriptPath)) {
750
+ throw new Error(`Skill member ${member.name} scripts.json declares duplicate script path: ${scriptPath}`);
751
+ }
752
+ declaredPaths.add(normalizedScriptPath);
753
+ }
754
+ }
594
755
  function validateInstallRequirements(manifest) {
595
756
  const requirements = manifest.install?.requirements;
596
757
  if (!requirements) {
@@ -669,15 +830,63 @@ function resolveMemberSourcePath(member) {
669
830
  return null;
670
831
  }
671
832
  function normalizeRelativePath(value, fieldName = "path") {
833
+ if (isAbsolute(value)) {
834
+ throw new Error(`Invalid addon.json ${fieldName}: ${value}`);
835
+ }
672
836
  const normalized = value.replace(/^\.?\//, "").replace(/\\/g, "/");
673
837
  if (!normalized || normalized.startsWith("../") || normalized.includes("/../")) {
674
838
  throw new Error(`Invalid addon.json ${fieldName}: ${value}`);
675
839
  }
676
840
  return normalized;
677
841
  }
842
+ function normalizeSkillScriptPath(value, memberName) {
843
+ if (isAbsolute(value)) {
844
+ throw new Error(`Skill member ${memberName} script path must be relative: ${value}`);
845
+ }
846
+ const normalized = value.replace(/^\.?\//, "").replace(/\\/g, "/");
847
+ if (!normalized || normalized.startsWith("../") || normalized.includes("/../")) {
848
+ throw new Error(`Skill member ${memberName} script path cannot escape scripts/: ${value}`);
849
+ }
850
+ return normalized;
851
+ }
678
852
  async function assertPathExists(rootDir, relativePath) {
679
853
  await access(join(rootDir, relativePath), constants.F_OK);
680
854
  }
855
+ async function pathExists(rootDir, relativePath) {
856
+ try {
857
+ await assertPathExists(rootDir, relativePath);
858
+ return true;
859
+ } catch {
860
+ return false;
861
+ }
862
+ }
863
+ async function collectRelativeFiles(rootDir, relativeDir) {
864
+ const entries = await readdir(join(rootDir, relativeDir), { withFileTypes: true });
865
+ const files = [];
866
+ for (const entry of entries) {
867
+ if (entry.name.startsWith(".")) {
868
+ throw new Error(`Skill resources cannot contain hidden files or directories: ${join(relativeDir, entry.name)}`);
869
+ }
870
+ const relativePath = join(relativeDir, entry.name).replace(/\\/g, "/");
871
+ if (entry.isDirectory()) {
872
+ files.push(...await collectRelativeFiles(rootDir, relativePath));
873
+ continue;
874
+ }
875
+ files.push(relativePath);
876
+ }
877
+ return files.sort();
878
+ }
879
+ async function assertSkillResourceFiles(rootDir, member, relativeDir, label, allowedExtensions) {
880
+ for (const file of await collectRelativeFiles(rootDir, relativeDir)) {
881
+ if (!allowedExtensions.has(extname(file).toLowerCase())) {
882
+ throw new Error(`Skill member ${member.name} has unsupported ${label} file type: ${file}`);
883
+ }
884
+ const fileStat = await stat(join(rootDir, file));
885
+ if (fileStat.size > SKILL_RESOURCE_MAX_FILE_SIZE_BYTES) {
886
+ throw new Error(`Skill member ${member.name} ${label} file is too large: ${file}`);
887
+ }
888
+ }
889
+ }
681
890
  function resolveNearestPackageRoot(startDir = process.cwd()) {
682
891
  let current = resolve(startDir);
683
892
  const root = parse(current).root;
@@ -2410,8 +2619,8 @@ async function runAstCheck(options) {
2410
2619
  }
2411
2620
  const full = join(dir, entry);
2412
2621
  try {
2413
- const stat3 = statSync(full);
2414
- if (stat3.isDirectory()) {
2622
+ const stat4 = statSync(full);
2623
+ if (stat4.isDirectory()) {
2415
2624
  files2.push(...findFiles(full, extensions));
2416
2625
  } else if (extensions.includes(extname(full))) {
2417
2626
  files2.push(full);
@@ -3357,6 +3566,22 @@ function renderOutput(data, options = {}) {
3357
3566
  }
3358
3567
  console.dir(data, { depth: null, colors: true });
3359
3568
  }
3569
+ function formatAddonPublishResult(result, organizationCode) {
3570
+ const lines = [
3571
+ `Addon published: ${result.addon.name}@${result.version.version}`,
3572
+ `Scope: ${result.addon.scope}`,
3573
+ `Status: ${result.addon.status}`
3574
+ ];
3575
+ if (result.addon.scope === "organization") {
3576
+ lines.push(`Organization: ${organizationCode || result.addon.ownerOrganization?.code || "-"}`);
3577
+ if (result.addon.status !== "active") {
3578
+ lines.push("");
3579
+ lines.push("Next step:");
3580
+ lines.push(` amaster addon activate ${result.addon.name} --organization-code ${organizationCode || "<code>"}`);
3581
+ }
3582
+ }
3583
+ return lines.join("\n");
3584
+ }
3360
3585
  function shouldRenderJsonError(argv) {
3361
3586
  return argv.includes("--json");
3362
3587
  }
@@ -3611,7 +3836,7 @@ addJsonOption(addOrganizationOption(addRegistryOption(addon.command("publish [so
3611
3836
  scope: options.scope,
3612
3837
  organizationCode: options.organizationCode
3613
3838
  });
3614
- renderOutput(result, options);
3839
+ renderOutput(options.json ? result : formatAddonPublishResult(result, options.organizationCode), options);
3615
3840
  });
3616
3841
  addJsonOption(addOrganizationOption(addRegistryOption(addon.command("activate <name>").description("Activate an addon")))).action(async (name, options) => {
3617
3842
  const registry = resolveRegistryFromOptions(options);