@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/README.md +2 -0
- package/dist/cli.cjs +229 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +230 -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;
|
|
@@ -560,12 +560,33 @@ async function getCurrentUser(registry) {
|
|
|
560
560
|
function logout(registry) {
|
|
561
561
|
clearStoredSession(registry);
|
|
562
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]);
|
|
563
583
|
async function loadAddonManifestFromDirectory(directory) {
|
|
564
584
|
const manifestPath = path.join(directory, "addon.json");
|
|
565
585
|
const manifestText = await promises$1.readFile(manifestPath, "utf8");
|
|
566
586
|
const manifest = JSON.parse(manifestText);
|
|
567
587
|
validateAddonManifest(manifest);
|
|
568
588
|
await assertDisplayAssetPathsExist(directory, manifest);
|
|
589
|
+
await assertSkillMemberContracts(directory, manifest);
|
|
569
590
|
return manifest;
|
|
570
591
|
}
|
|
571
592
|
function validateAddonManifest(manifest) {
|
|
@@ -585,9 +606,27 @@ function validateAddonManifest(manifest) {
|
|
|
585
606
|
throw new Error("addon.json missing members");
|
|
586
607
|
}
|
|
587
608
|
validateDisplayAssets(manifest);
|
|
609
|
+
validateMembers(manifest);
|
|
588
610
|
validateInstallRequirements(manifest);
|
|
589
611
|
validateInstallNpm(manifest);
|
|
590
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
|
+
}
|
|
591
630
|
function validateDisplayAssets(manifest) {
|
|
592
631
|
const image = manifest.display.image;
|
|
593
632
|
if (image !== void 0) {
|
|
@@ -618,6 +657,128 @@ async function assertDisplayAssetPathsExist(directory, manifest) {
|
|
|
618
657
|
await assertPathExists(directory, normalizeRelativePath(assetPath, "display asset path"));
|
|
619
658
|
}
|
|
620
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
|
+
}
|
|
621
782
|
function validateInstallRequirements(manifest) {
|
|
622
783
|
const requirements = manifest.install?.requirements;
|
|
623
784
|
if (!requirements) {
|
|
@@ -696,15 +857,63 @@ function resolveMemberSourcePath(member) {
|
|
|
696
857
|
return null;
|
|
697
858
|
}
|
|
698
859
|
function normalizeRelativePath(value, fieldName = "path") {
|
|
860
|
+
if (path.isAbsolute(value)) {
|
|
861
|
+
throw new Error(`Invalid addon.json ${fieldName}: ${value}`);
|
|
862
|
+
}
|
|
699
863
|
const normalized = value.replace(/^\.?\//, "").replace(/\\/g, "/");
|
|
700
864
|
if (!normalized || normalized.startsWith("../") || normalized.includes("/../")) {
|
|
701
865
|
throw new Error(`Invalid addon.json ${fieldName}: ${value}`);
|
|
702
866
|
}
|
|
703
867
|
return normalized;
|
|
704
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
|
+
}
|
|
705
879
|
async function assertPathExists(rootDir, relativePath) {
|
|
706
880
|
await promises$1.access(path.join(rootDir, relativePath), fs.constants.F_OK);
|
|
707
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
|
+
}
|
|
708
917
|
function resolveNearestPackageRoot(startDir = process.cwd()) {
|
|
709
918
|
let current = path.resolve(startDir);
|
|
710
919
|
const root = path.parse(current).root;
|
|
@@ -2437,8 +2646,8 @@ async function runAstCheck(options) {
|
|
|
2437
2646
|
}
|
|
2438
2647
|
const full = path.join(dir, entry);
|
|
2439
2648
|
try {
|
|
2440
|
-
const
|
|
2441
|
-
if (
|
|
2649
|
+
const stat4 = fs.statSync(full);
|
|
2650
|
+
if (stat4.isDirectory()) {
|
|
2442
2651
|
files2.push(...findFiles(full, extensions));
|
|
2443
2652
|
} else if (extensions.includes(path.extname(full))) {
|
|
2444
2653
|
files2.push(full);
|
|
@@ -3384,6 +3593,22 @@ function renderOutput(data, options = {}) {
|
|
|
3384
3593
|
}
|
|
3385
3594
|
console.dir(data, { depth: null, colors: true });
|
|
3386
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
|
+
}
|
|
3387
3612
|
function shouldRenderJsonError(argv) {
|
|
3388
3613
|
return argv.includes("--json");
|
|
3389
3614
|
}
|
|
@@ -3638,7 +3863,7 @@ addJsonOption(addOrganizationOption(addRegistryOption(addon.command("publish [so
|
|
|
3638
3863
|
scope: options.scope,
|
|
3639
3864
|
organizationCode: options.organizationCode
|
|
3640
3865
|
});
|
|
3641
|
-
renderOutput(result, options);
|
|
3866
|
+
renderOutput(options.json ? result : formatAddonPublishResult(result, options.organizationCode), options);
|
|
3642
3867
|
});
|
|
3643
3868
|
addJsonOption(addOrganizationOption(addRegistryOption(addon.command("activate <name>").description("Activate an addon")))).action(async (name, options) => {
|
|
3644
3869
|
const registry = resolveRegistryFromOptions(options);
|