@amaster.ai/cli 1.1.35 → 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/README.md +2 -0
- package/dist/cli.cjs +230 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +231 -5
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,6 +99,8 @@ marketplace/screenshots/preview.png
|
|
|
99
99
|
- `datasource`
|
|
100
100
|
- `settings`
|
|
101
101
|
|
|
102
|
+
`skill` member 可以发布到 Marketplace,供 Agent 通过 Server API 下载并安装到自己的 skill cache;普通设计态 `addon install` 不会把 `skill` 写入应用工程。Skill member 的 `source.path` 必须指向一个目录,目录内必须包含带 `name` 和 `description` frontmatter 的 `SKILL.md`,可选包含 `references/`、`assets/` 和 `scripts/`。如果存在 `scripts/`,必须提供 `scripts/scripts.json` 声明可执行入口的名称、路径、用途和确认策略;脚本依赖的辅助文件可放在 `scripts/` 下,不需要逐个声明为入口。
|
|
103
|
+
|
|
102
104
|
安装结果会写入:
|
|
103
105
|
|
|
104
106
|
- `src/addons/<addon-name>/meta.json`
|
package/dist/cli.cjs
CHANGED
|
@@ -12,8 +12,8 @@ var os = require('os');
|
|
|
12
12
|
var tar = require('tar');
|
|
13
13
|
var http = require('http');
|
|
14
14
|
var child_process = require('child_process');
|
|
15
|
-
var util = require('util');
|
|
16
15
|
var YAML2 = require('yaml');
|
|
16
|
+
var util = require('util');
|
|
17
17
|
var ts = require('typescript');
|
|
18
18
|
|
|
19
19
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -78,6 +78,7 @@ async function packageAddonDirectory(sourceDir) {
|
|
|
78
78
|
cwd: absoluteSourceDir,
|
|
79
79
|
gzip: true,
|
|
80
80
|
file: archivePath,
|
|
81
|
+
noMtime: true,
|
|
81
82
|
portable: true
|
|
82
83
|
},
|
|
83
84
|
files
|
|
@@ -559,12 +560,33 @@ async function getCurrentUser(registry) {
|
|
|
559
560
|
function logout(registry) {
|
|
560
561
|
clearStoredSession(registry);
|
|
561
562
|
}
|
|
563
|
+
var SKILL_RESOURCE_MAX_FILE_SIZE_BYTES = 1024 * 1024;
|
|
564
|
+
var SKILL_REFERENCE_EXTENSIONS = /* @__PURE__ */ new Set([".md", ".mdx", ".txt", ".json", ".yml", ".yaml", ".ts", ".tsx", ".js", ".mjs"]);
|
|
565
|
+
var SKILL_ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
566
|
+
...SKILL_REFERENCE_EXTENSIONS,
|
|
567
|
+
".bpmn",
|
|
568
|
+
".csv",
|
|
569
|
+
".html",
|
|
570
|
+
".jsonl",
|
|
571
|
+
".toml",
|
|
572
|
+
".xml",
|
|
573
|
+
".css",
|
|
574
|
+
".scss",
|
|
575
|
+
".svg",
|
|
576
|
+
".png",
|
|
577
|
+
".jpg",
|
|
578
|
+
".jpeg",
|
|
579
|
+
".webp"
|
|
580
|
+
]);
|
|
581
|
+
var SKILL_SCRIPT_EXTENSIONS = /* @__PURE__ */ new Set([".sh", ".ts", ".tsx", ".js", ".mjs", ".cjs"]);
|
|
582
|
+
var SKILL_SCRIPT_RESOURCE_EXTENSIONS = /* @__PURE__ */ new Set([...SKILL_ASSET_EXTENSIONS, ...SKILL_SCRIPT_EXTENSIONS]);
|
|
562
583
|
async function loadAddonManifestFromDirectory(directory) {
|
|
563
584
|
const manifestPath = path.join(directory, "addon.json");
|
|
564
585
|
const manifestText = await promises$1.readFile(manifestPath, "utf8");
|
|
565
586
|
const manifest = JSON.parse(manifestText);
|
|
566
587
|
validateAddonManifest(manifest);
|
|
567
588
|
await assertDisplayAssetPathsExist(directory, manifest);
|
|
589
|
+
await assertSkillMemberContracts(directory, manifest);
|
|
568
590
|
return manifest;
|
|
569
591
|
}
|
|
570
592
|
function validateAddonManifest(manifest) {
|
|
@@ -584,9 +606,27 @@ function validateAddonManifest(manifest) {
|
|
|
584
606
|
throw new Error("addon.json missing members");
|
|
585
607
|
}
|
|
586
608
|
validateDisplayAssets(manifest);
|
|
609
|
+
validateMembers(manifest);
|
|
587
610
|
validateInstallRequirements(manifest);
|
|
588
611
|
validateInstallNpm(manifest);
|
|
589
612
|
}
|
|
613
|
+
function validateMembers(manifest) {
|
|
614
|
+
const allowedTypes = /* @__PURE__ */ new Set(["component", "page", "function", "skill", "theme", "settings", "workflow", "bpmn", "entity", "datasource"]);
|
|
615
|
+
for (const member of manifest.members) {
|
|
616
|
+
if (!member.name || typeof member.name !== "string") {
|
|
617
|
+
throw new Error("addon.json member missing name");
|
|
618
|
+
}
|
|
619
|
+
if (!member.type || typeof member.type !== "string") {
|
|
620
|
+
throw new Error(`addon.json member ${member.name} missing type`);
|
|
621
|
+
}
|
|
622
|
+
if (!allowedTypes.has(member.type)) {
|
|
623
|
+
throw new Error(`Unsupported addon member type: ${member.type}`);
|
|
624
|
+
}
|
|
625
|
+
if (!resolveMemberSourcePath(member)) {
|
|
626
|
+
throw new Error(`addon.json member ${member.name} missing source.path`);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
590
630
|
function validateDisplayAssets(manifest) {
|
|
591
631
|
const image = manifest.display.image;
|
|
592
632
|
if (image !== void 0) {
|
|
@@ -617,6 +657,128 @@ async function assertDisplayAssetPathsExist(directory, manifest) {
|
|
|
617
657
|
await assertPathExists(directory, normalizeRelativePath(assetPath, "display asset path"));
|
|
618
658
|
}
|
|
619
659
|
}
|
|
660
|
+
async function assertSkillMemberContracts(directory, manifest) {
|
|
661
|
+
for (const member of manifest.members) {
|
|
662
|
+
if (member.type !== "skill") {
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
const sourcePath = resolveMemberSourcePath(member);
|
|
666
|
+
if (!sourcePath) {
|
|
667
|
+
throw new Error(`Skill member ${member.name} is missing source.path`);
|
|
668
|
+
}
|
|
669
|
+
const sourceStat = await promises$1.stat(path.join(directory, sourcePath));
|
|
670
|
+
if (!sourceStat.isDirectory()) {
|
|
671
|
+
throw new Error(`Skill member ${member.name} source.path must be a directory`);
|
|
672
|
+
}
|
|
673
|
+
await assertSkillMarkdown(directory, member, sourcePath);
|
|
674
|
+
await assertOptionalSkillResourceDirectory(directory, member, sourcePath, "references", SKILL_REFERENCE_EXTENSIONS);
|
|
675
|
+
await assertOptionalSkillResourceDirectory(directory, member, sourcePath, "assets", SKILL_ASSET_EXTENSIONS);
|
|
676
|
+
await assertSkillScripts(directory, member, sourcePath);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
async function assertSkillMarkdown(directory, member, sourcePath) {
|
|
680
|
+
const skillPath = path.join(sourcePath, "SKILL.md");
|
|
681
|
+
await assertPathExists(directory, skillPath);
|
|
682
|
+
const content = await promises$1.readFile(path.join(directory, skillPath), "utf8");
|
|
683
|
+
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
|
|
684
|
+
if (!match) {
|
|
685
|
+
throw new Error(`Skill member ${member.name} SKILL.md missing YAML frontmatter`);
|
|
686
|
+
}
|
|
687
|
+
let frontmatter;
|
|
688
|
+
try {
|
|
689
|
+
frontmatter = YAML2.parse(match[1] ?? "");
|
|
690
|
+
} catch (error) {
|
|
691
|
+
throw new Error(`Skill member ${member.name} SKILL.md frontmatter is invalid YAML: ${error instanceof Error ? error.message : String(error)}`);
|
|
692
|
+
}
|
|
693
|
+
if (!frontmatter || typeof frontmatter !== "object" || Array.isArray(frontmatter)) {
|
|
694
|
+
throw new Error(`Skill member ${member.name} SKILL.md frontmatter must be a YAML object`);
|
|
695
|
+
}
|
|
696
|
+
const record = frontmatter;
|
|
697
|
+
if (typeof record.name !== "string" || !record.name.trim()) {
|
|
698
|
+
throw new Error(`Skill member ${member.name} SKILL.md frontmatter missing name`);
|
|
699
|
+
}
|
|
700
|
+
if (!/^[a-z0-9-]+$/.test(record.name.trim())) {
|
|
701
|
+
throw new Error(`Skill member ${member.name} SKILL.md frontmatter name must be hyphen-case`);
|
|
702
|
+
}
|
|
703
|
+
if (typeof record.description !== "string" || !record.description.trim()) {
|
|
704
|
+
throw new Error(`Skill member ${member.name} SKILL.md frontmatter missing description`);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
async function assertOptionalSkillResourceDirectory(directory, member, sourcePath, directoryName, allowedExtensions) {
|
|
708
|
+
const relativePath = path.join(sourcePath, directoryName);
|
|
709
|
+
if (!await pathExists(directory, relativePath)) {
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
const resourceStat = await promises$1.stat(path.join(directory, relativePath));
|
|
713
|
+
if (!resourceStat.isDirectory()) {
|
|
714
|
+
throw new Error(`Skill member ${member.name} ${directoryName}/ must be a directory`);
|
|
715
|
+
}
|
|
716
|
+
for (const file of await collectRelativeFiles(directory, relativePath)) {
|
|
717
|
+
if (!allowedExtensions.has(path.extname(file).toLowerCase())) {
|
|
718
|
+
throw new Error(`Skill member ${member.name} has unsupported ${directoryName} file type: ${file}`);
|
|
719
|
+
}
|
|
720
|
+
const fileStat = await promises$1.stat(path.join(directory, file));
|
|
721
|
+
if (fileStat.size > SKILL_RESOURCE_MAX_FILE_SIZE_BYTES) {
|
|
722
|
+
throw new Error(`Skill member ${member.name} ${directoryName} file is too large: ${file}`);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
async function assertSkillScripts(directory, member, sourcePath) {
|
|
727
|
+
const scriptsPath = path.join(sourcePath, "scripts");
|
|
728
|
+
if (!await pathExists(directory, scriptsPath)) {
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
const scriptsStat = await promises$1.stat(path.join(directory, scriptsPath));
|
|
732
|
+
if (!scriptsStat.isDirectory()) {
|
|
733
|
+
throw new Error(`Skill member ${member.name} scripts/ must be a directory`);
|
|
734
|
+
}
|
|
735
|
+
await assertSkillResourceFiles(directory, member, scriptsPath, "scripts", SKILL_SCRIPT_RESOURCE_EXTENSIONS);
|
|
736
|
+
const manifestPath = path.join(scriptsPath, "scripts.json");
|
|
737
|
+
await assertPathExists(directory, manifestPath);
|
|
738
|
+
const scriptsManifest = JSON.parse(await promises$1.readFile(path.join(directory, manifestPath), "utf8"));
|
|
739
|
+
if (!scriptsManifest || typeof scriptsManifest !== "object" || Array.isArray(scriptsManifest)) {
|
|
740
|
+
throw new Error(`Skill member ${member.name} scripts.json must contain a JSON object`);
|
|
741
|
+
}
|
|
742
|
+
const scripts = scriptsManifest.scripts;
|
|
743
|
+
if (!Array.isArray(scripts)) {
|
|
744
|
+
throw new Error(`Skill member ${member.name} scripts.json missing scripts array`);
|
|
745
|
+
}
|
|
746
|
+
if (!scripts.length) {
|
|
747
|
+
throw new Error(`Skill member ${member.name} scripts.json must declare at least one script entrypoint`);
|
|
748
|
+
}
|
|
749
|
+
const declaredPaths = /* @__PURE__ */ new Set();
|
|
750
|
+
for (const script of scripts) {
|
|
751
|
+
if (!script || typeof script !== "object" || Array.isArray(script)) {
|
|
752
|
+
throw new Error(`Skill member ${member.name} scripts.json contains an invalid script entry`);
|
|
753
|
+
}
|
|
754
|
+
const scriptRecord = script;
|
|
755
|
+
if (typeof scriptRecord.name !== "string" || !scriptRecord.name.trim()) {
|
|
756
|
+
throw new Error(`Skill member ${member.name} scripts.json script missing name`);
|
|
757
|
+
}
|
|
758
|
+
if (typeof scriptRecord.path !== "string" || !scriptRecord.path.trim()) {
|
|
759
|
+
throw new Error(`Skill member ${member.name} scripts.json script ${scriptRecord.name} missing path`);
|
|
760
|
+
}
|
|
761
|
+
if (typeof scriptRecord.description !== "string" || !scriptRecord.description.trim()) {
|
|
762
|
+
throw new Error(`Skill member ${member.name} scripts.json script ${scriptRecord.name} missing description`);
|
|
763
|
+
}
|
|
764
|
+
if (typeof scriptRecord.requiresConfirmation !== "boolean") {
|
|
765
|
+
throw new Error(`Skill member ${member.name} scripts.json script ${scriptRecord.name} missing requiresConfirmation`);
|
|
766
|
+
}
|
|
767
|
+
if (typeof scriptRecord.writesProjectFiles !== "boolean") {
|
|
768
|
+
throw new Error(`Skill member ${member.name} scripts.json script ${scriptRecord.name} missing writesProjectFiles`);
|
|
769
|
+
}
|
|
770
|
+
const scriptPath = normalizeSkillScriptPath(scriptRecord.path, member.name);
|
|
771
|
+
if (!SKILL_SCRIPT_EXTENSIONS.has(path.extname(scriptPath).toLowerCase())) {
|
|
772
|
+
throw new Error(`Skill member ${member.name} has unsupported script file type: ${scriptPath}`);
|
|
773
|
+
}
|
|
774
|
+
await assertPathExists(directory, path.join(scriptsPath, scriptPath));
|
|
775
|
+
const normalizedScriptPath = path.join(scriptsPath, scriptPath).replace(/\\/g, "/");
|
|
776
|
+
if (declaredPaths.has(normalizedScriptPath)) {
|
|
777
|
+
throw new Error(`Skill member ${member.name} scripts.json declares duplicate script path: ${scriptPath}`);
|
|
778
|
+
}
|
|
779
|
+
declaredPaths.add(normalizedScriptPath);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
620
782
|
function validateInstallRequirements(manifest) {
|
|
621
783
|
const requirements = manifest.install?.requirements;
|
|
622
784
|
if (!requirements) {
|
|
@@ -695,15 +857,63 @@ function resolveMemberSourcePath(member) {
|
|
|
695
857
|
return null;
|
|
696
858
|
}
|
|
697
859
|
function normalizeRelativePath(value, fieldName = "path") {
|
|
860
|
+
if (path.isAbsolute(value)) {
|
|
861
|
+
throw new Error(`Invalid addon.json ${fieldName}: ${value}`);
|
|
862
|
+
}
|
|
698
863
|
const normalized = value.replace(/^\.?\//, "").replace(/\\/g, "/");
|
|
699
864
|
if (!normalized || normalized.startsWith("../") || normalized.includes("/../")) {
|
|
700
865
|
throw new Error(`Invalid addon.json ${fieldName}: ${value}`);
|
|
701
866
|
}
|
|
702
867
|
return normalized;
|
|
703
868
|
}
|
|
869
|
+
function normalizeSkillScriptPath(value, memberName) {
|
|
870
|
+
if (path.isAbsolute(value)) {
|
|
871
|
+
throw new Error(`Skill member ${memberName} script path must be relative: ${value}`);
|
|
872
|
+
}
|
|
873
|
+
const normalized = value.replace(/^\.?\//, "").replace(/\\/g, "/");
|
|
874
|
+
if (!normalized || normalized.startsWith("../") || normalized.includes("/../")) {
|
|
875
|
+
throw new Error(`Skill member ${memberName} script path cannot escape scripts/: ${value}`);
|
|
876
|
+
}
|
|
877
|
+
return normalized;
|
|
878
|
+
}
|
|
704
879
|
async function assertPathExists(rootDir, relativePath) {
|
|
705
880
|
await promises$1.access(path.join(rootDir, relativePath), fs.constants.F_OK);
|
|
706
881
|
}
|
|
882
|
+
async function pathExists(rootDir, relativePath) {
|
|
883
|
+
try {
|
|
884
|
+
await assertPathExists(rootDir, relativePath);
|
|
885
|
+
return true;
|
|
886
|
+
} catch {
|
|
887
|
+
return false;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
async function collectRelativeFiles(rootDir, relativeDir) {
|
|
891
|
+
const entries = await promises$1.readdir(path.join(rootDir, relativeDir), { withFileTypes: true });
|
|
892
|
+
const files = [];
|
|
893
|
+
for (const entry of entries) {
|
|
894
|
+
if (entry.name.startsWith(".")) {
|
|
895
|
+
throw new Error(`Skill resources cannot contain hidden files or directories: ${path.join(relativeDir, entry.name)}`);
|
|
896
|
+
}
|
|
897
|
+
const relativePath = path.join(relativeDir, entry.name).replace(/\\/g, "/");
|
|
898
|
+
if (entry.isDirectory()) {
|
|
899
|
+
files.push(...await collectRelativeFiles(rootDir, relativePath));
|
|
900
|
+
continue;
|
|
901
|
+
}
|
|
902
|
+
files.push(relativePath);
|
|
903
|
+
}
|
|
904
|
+
return files.sort();
|
|
905
|
+
}
|
|
906
|
+
async function assertSkillResourceFiles(rootDir, member, relativeDir, label, allowedExtensions) {
|
|
907
|
+
for (const file of await collectRelativeFiles(rootDir, relativeDir)) {
|
|
908
|
+
if (!allowedExtensions.has(path.extname(file).toLowerCase())) {
|
|
909
|
+
throw new Error(`Skill member ${member.name} has unsupported ${label} file type: ${file}`);
|
|
910
|
+
}
|
|
911
|
+
const fileStat = await promises$1.stat(path.join(rootDir, file));
|
|
912
|
+
if (fileStat.size > SKILL_RESOURCE_MAX_FILE_SIZE_BYTES) {
|
|
913
|
+
throw new Error(`Skill member ${member.name} ${label} file is too large: ${file}`);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
707
917
|
function resolveNearestPackageRoot(startDir = process.cwd()) {
|
|
708
918
|
let current = path.resolve(startDir);
|
|
709
919
|
const root = path.parse(current).root;
|
|
@@ -2436,8 +2646,8 @@ async function runAstCheck(options) {
|
|
|
2436
2646
|
}
|
|
2437
2647
|
const full = path.join(dir, entry);
|
|
2438
2648
|
try {
|
|
2439
|
-
const
|
|
2440
|
-
if (
|
|
2649
|
+
const stat4 = fs.statSync(full);
|
|
2650
|
+
if (stat4.isDirectory()) {
|
|
2441
2651
|
files2.push(...findFiles(full, extensions));
|
|
2442
2652
|
} else if (extensions.includes(path.extname(full))) {
|
|
2443
2653
|
files2.push(full);
|
|
@@ -3383,6 +3593,22 @@ function renderOutput(data, options = {}) {
|
|
|
3383
3593
|
}
|
|
3384
3594
|
console.dir(data, { depth: null, colors: true });
|
|
3385
3595
|
}
|
|
3596
|
+
function formatAddonPublishResult(result, organizationCode) {
|
|
3597
|
+
const lines = [
|
|
3598
|
+
`Addon published: ${result.addon.name}@${result.version.version}`,
|
|
3599
|
+
`Scope: ${result.addon.scope}`,
|
|
3600
|
+
`Status: ${result.addon.status}`
|
|
3601
|
+
];
|
|
3602
|
+
if (result.addon.scope === "organization") {
|
|
3603
|
+
lines.push(`Organization: ${organizationCode || result.addon.ownerOrganization?.code || "-"}`);
|
|
3604
|
+
if (result.addon.status !== "active") {
|
|
3605
|
+
lines.push("");
|
|
3606
|
+
lines.push("Next step:");
|
|
3607
|
+
lines.push(` amaster addon activate ${result.addon.name} --organization-code ${organizationCode || "<code>"}`);
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
return lines.join("\n");
|
|
3611
|
+
}
|
|
3386
3612
|
function shouldRenderJsonError(argv) {
|
|
3387
3613
|
return argv.includes("--json");
|
|
3388
3614
|
}
|
|
@@ -3637,7 +3863,7 @@ addJsonOption(addOrganizationOption(addRegistryOption(addon.command("publish [so
|
|
|
3637
3863
|
scope: options.scope,
|
|
3638
3864
|
organizationCode: options.organizationCode
|
|
3639
3865
|
});
|
|
3640
|
-
renderOutput(result, options);
|
|
3866
|
+
renderOutput(options.json ? result : formatAddonPublishResult(result, options.organizationCode), options);
|
|
3641
3867
|
});
|
|
3642
3868
|
addJsonOption(addOrganizationOption(addRegistryOption(addon.command("activate <name>").description("Activate an addon")))).action(async (name, options) => {
|
|
3643
3869
|
const registry = resolveRegistryFromOptions(options);
|