@agenticmail/enterprise 0.5.4 → 0.5.6

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.
Files changed (50) hide show
  1. package/dist/chunk-2AHKTK2N.js +819 -0
  2. package/dist/chunk-2ESYSVXG.js +48 -0
  3. package/dist/chunk-6CVIA5YL.js +808 -0
  4. package/dist/chunk-FVXEXRP2.js +12666 -0
  5. package/dist/chunk-OZZ65RAG.js +9040 -0
  6. package/dist/chunk-P2FILRUE.js +591 -0
  7. package/dist/chunk-Q3ZHFVGV.js +48 -0
  8. package/dist/chunk-TCIGK4HQ.js +1943 -0
  9. package/dist/chunk-WI62KTVK.js +3455 -0
  10. package/dist/cidr-O6T7HDUD.js +17 -0
  11. package/dist/cli-build-skill-AE7QC5C5.js +235 -0
  12. package/dist/cli-build-skill-MP6K4ZXO.js +235 -0
  13. package/dist/cli-recover-5M74V7V4.js +97 -0
  14. package/dist/cli-recover-5VWKSBTE.js +97 -0
  15. package/dist/cli-submit-skill-6AAQWZWW.js +162 -0
  16. package/dist/cli-submit-skill-LDFJGSKO.js +162 -0
  17. package/dist/cli-validate-DHESCL7V.js +148 -0
  18. package/dist/cli-validate-QTV6662P.js +148 -0
  19. package/dist/cli-verify-G27G44PM.js +98 -0
  20. package/dist/cli.js +13 -13
  21. package/dist/config-store-YW6BMVSU.js +58 -0
  22. package/dist/db-adapter-WPKXQDEY.js +7 -0
  23. package/dist/domain-lock-XXXJIX7D.js +7 -0
  24. package/dist/dynamodb-33B2BXRN.js +426 -0
  25. package/dist/esm-BZF7GNJD.js +5090 -0
  26. package/dist/factory-X6SKUEDX.js +9 -0
  27. package/dist/firewall-ZGR2AGAP.js +10 -0
  28. package/dist/index.js +35 -35
  29. package/dist/managed-J3QQMQQJ.js +16 -0
  30. package/dist/mongodb-KTICSLUI.js +319 -0
  31. package/dist/mysql-VIFJFM4A.js +574 -0
  32. package/dist/postgres-A67RQTZX.js +575 -0
  33. package/dist/registry/cli.js +1 -1
  34. package/dist/routes-F22OJNEY.js +5674 -0
  35. package/dist/runtime-TCAE7QSD.js +47 -0
  36. package/dist/server-B27VUUU6.js +11 -0
  37. package/dist/setup-HJ4PTUSA.js +20 -0
  38. package/dist/setup-UIQKEGIG.js +20 -0
  39. package/dist/skills-NJKTYIGZ.js +14 -0
  40. package/dist/sqlite-Y6GS6AE3.js +490 -0
  41. package/dist/turso-A7AO3JDH.js +495 -0
  42. package/package.json +1 -1
  43. package/src/cli.ts +13 -13
  44. package/src/domain-lock/cli-recover.ts +4 -4
  45. package/src/domain-lock/cli-verify.ts +3 -3
  46. package/src/engine/cli-build-skill.ts +2 -2
  47. package/src/engine/cli-submit-skill.ts +3 -3
  48. package/src/engine/cli-validate.ts +3 -3
  49. package/src/setup/index.ts +19 -3
  50. package/src/setup/registration.ts +4 -4
@@ -0,0 +1,162 @@
1
+ import {
2
+ validateSkillManifest
3
+ } from "./chunk-TY7NVD4U.js";
4
+ import "./chunk-2ESYSVXG.js";
5
+
6
+ // src/engine/cli-submit-skill.ts
7
+ var UPSTREAM_REPO = "agenticmail/enterprise";
8
+ async function runSubmitSkill(args) {
9
+ const chalk = (await import("chalk")).default;
10
+ const ora = (await import("ora")).default;
11
+ const { execSync } = await import("child_process");
12
+ const fs = await import("fs/promises");
13
+ const path = await import("path");
14
+ const target = args.filter((a) => !a.startsWith("--"))[0];
15
+ if (!target) {
16
+ console.log(`${chalk.bold("Usage:")} npx @agenticmail/enterprise submit-skill <path-to-skill-dir>`);
17
+ process.exit(1);
18
+ return;
19
+ }
20
+ const skillDir = path.resolve(target);
21
+ console.log("");
22
+ console.log(chalk.bold("\u{1F680} Submit Community Skill"));
23
+ console.log("");
24
+ const spinner = ora("Checking prerequisites...").start();
25
+ try {
26
+ execSync("gh --version", { stdio: "pipe" });
27
+ } catch {
28
+ spinner.fail("GitHub CLI (gh) is not installed");
29
+ console.log("");
30
+ console.log(chalk.dim(" Install it from: https://cli.github.com/"));
31
+ console.log(chalk.dim(" Then run: gh auth login"));
32
+ process.exit(1);
33
+ return;
34
+ }
35
+ try {
36
+ execSync("gh auth status", { stdio: "pipe" });
37
+ } catch {
38
+ spinner.fail("Not authenticated with GitHub CLI");
39
+ console.log(chalk.dim(" Run: gh auth login"));
40
+ process.exit(1);
41
+ return;
42
+ }
43
+ spinner.succeed("GitHub CLI authenticated");
44
+ const validateSpinner = ora("Validating skill manifest...").start();
45
+ const manifestPath = path.join(skillDir, "agenticmail-skill.json");
46
+ let manifest;
47
+ try {
48
+ const raw = await fs.readFile(manifestPath, "utf-8");
49
+ manifest = JSON.parse(raw);
50
+ } catch (err) {
51
+ validateSpinner.fail(`Cannot read manifest: ${err.message}`);
52
+ process.exit(1);
53
+ return;
54
+ }
55
+ const validation = validateSkillManifest(manifest);
56
+ if (!validation.valid) {
57
+ validateSpinner.fail("Manifest validation failed");
58
+ for (const err of validation.errors) {
59
+ console.log(chalk.red(" \u2502 " + err));
60
+ }
61
+ console.log(chalk.dim("\n Fix the errors above and try again."));
62
+ process.exit(1);
63
+ return;
64
+ }
65
+ validateSpinner.succeed(`Manifest valid: ${manifest.name} v${manifest.version}`);
66
+ const skillId = manifest.id;
67
+ const branchName = `community/add-${skillId}`;
68
+ const forkSpinner = ora("Forking repository...").start();
69
+ try {
70
+ execSync(`gh repo fork ${UPSTREAM_REPO} --clone=false 2>&1 || true`, { stdio: "pipe" });
71
+ forkSpinner.succeed("Repository forked (or already exists)");
72
+ } catch {
73
+ forkSpinner.succeed("Fork exists");
74
+ }
75
+ let forkUrl;
76
+ try {
77
+ const ghUser = execSync("gh api user --jq .login", { encoding: "utf-8" }).trim();
78
+ forkUrl = `https://github.com/${ghUser}/enterprise.git`;
79
+ } catch {
80
+ forkSpinner.fail("Cannot determine GitHub username");
81
+ process.exit(1);
82
+ return;
83
+ }
84
+ const tmpDir = path.join(process.env.TMPDIR || "/tmp", `agenticmail-submit-${Date.now()}`);
85
+ const pushSpinner = ora("Cloning fork...").start();
86
+ try {
87
+ execSync(`git clone --depth 1 ${forkUrl} "${tmpDir}"`, { stdio: "pipe" });
88
+ pushSpinner.text = "Creating branch...";
89
+ const run = (cmd) => execSync(cmd, { cwd: tmpDir, stdio: "pipe", encoding: "utf-8" });
90
+ run(`git remote add upstream https://github.com/${UPSTREAM_REPO}.git`);
91
+ run("git fetch upstream main --depth 1");
92
+ run(`git checkout -b ${branchName} upstream/main`);
93
+ pushSpinner.text = "Copying skill files...";
94
+ const destDir = path.join(tmpDir, "community-skills", skillId);
95
+ await fs.mkdir(destDir, { recursive: true });
96
+ const files = await fs.readdir(skillDir);
97
+ for (const file of files) {
98
+ await fs.copyFile(path.join(skillDir, file), path.join(destDir, file));
99
+ }
100
+ pushSpinner.text = "Committing...";
101
+ run(`git add community-skills/${skillId}/`);
102
+ run(`git commit -m "Add community skill: ${manifest.name}"`);
103
+ pushSpinner.text = "Pushing to fork...";
104
+ run(`git push origin ${branchName} --force`);
105
+ pushSpinner.succeed("Pushed to fork");
106
+ } catch (err) {
107
+ pushSpinner.fail(`Git operation failed: ${err.message}`);
108
+ process.exit(1);
109
+ return;
110
+ }
111
+ const prSpinner = ora("Opening pull request...").start();
112
+ const toolsList = (manifest.tools || []).map(
113
+ (t) => `- \`${t.id}\` \u2014 ${t.name}: ${t.description}`
114
+ ).join("\n");
115
+ const prBody = `## Community Skill Submission
116
+
117
+ **Skill ID:** \`${manifest.id}\`
118
+ **Application:** ${manifest.name}
119
+ **Category:** ${manifest.category}
120
+ **Risk Level:** ${manifest.risk}
121
+ **Author:** @${manifest.author}
122
+ **License:** ${manifest.license}
123
+
124
+ ### Description
125
+
126
+ ${manifest.description}
127
+
128
+ ### Tools Provided
129
+
130
+ ${toolsList}
131
+
132
+ ### Validation
133
+
134
+ - [x] Manifest passes \`npx @agenticmail/enterprise validate\`
135
+ - [x] All required fields present
136
+ - [x] No duplicate tool IDs
137
+ ${manifest.tags ? `
138
+ **Tags:** ${manifest.tags.join(", ")}` : ""}`;
139
+ try {
140
+ const prUrl = execSync(
141
+ `gh pr create --repo ${UPSTREAM_REPO} --head ${branchName} --title "Add community skill: ${manifest.name}" --body "${prBody.replace(/"/g, '\\"')}"`,
142
+ { cwd: tmpDir, encoding: "utf-8", stdio: "pipe" }
143
+ ).trim();
144
+ prSpinner.succeed("Pull request opened!");
145
+ console.log(chalk.green(`
146
+ ${prUrl}
147
+ `));
148
+ } catch (err) {
149
+ if (err.stderr?.includes("already exists")) {
150
+ prSpinner.warn("A PR for this skill already exists");
151
+ } else {
152
+ prSpinner.fail(`Could not open PR: ${err.message}`);
153
+ }
154
+ }
155
+ try {
156
+ await fs.rm(tmpDir, { recursive: true, force: true });
157
+ } catch {
158
+ }
159
+ }
160
+ export {
161
+ runSubmitSkill
162
+ };
@@ -0,0 +1,162 @@
1
+ import {
2
+ validateSkillManifest
3
+ } from "./chunk-TY7NVD4U.js";
4
+ import "./chunk-KFQGP6VL.js";
5
+
6
+ // src/engine/cli-submit-skill.ts
7
+ var UPSTREAM_REPO = "agenticmail/enterprise";
8
+ async function runSubmitSkill(args) {
9
+ const chalk = (await import("chalk")).default;
10
+ const ora = (await import("ora")).default;
11
+ const { execSync } = await import("child_process");
12
+ const fs = await import("fs/promises");
13
+ const path = await import("path");
14
+ const target = args.filter((a) => !a.startsWith("--"))[0];
15
+ if (!target) {
16
+ console.log(`${chalk.bold("Usage:")} npx @agenticmail/enterprise submit-skill <path-to-skill-dir>`);
17
+ process.exit(1);
18
+ return;
19
+ }
20
+ const skillDir = path.resolve(target);
21
+ console.log("");
22
+ console.log(chalk.bold("\u{1F680} Submit Community Skill"));
23
+ console.log("");
24
+ const spinner = ora("Checking prerequisites...").start();
25
+ try {
26
+ execSync("gh --version", { stdio: "pipe" });
27
+ } catch {
28
+ spinner.fail("GitHub CLI (gh) is not installed");
29
+ console.log("");
30
+ console.log(chalk.dim(" Install it from: https://cli.github.com/"));
31
+ console.log(chalk.dim(" Then run: gh auth login"));
32
+ process.exit(1);
33
+ return;
34
+ }
35
+ try {
36
+ execSync("gh auth status", { stdio: "pipe" });
37
+ } catch {
38
+ spinner.fail("Not authenticated with GitHub CLI");
39
+ console.log(chalk.dim(" Run: gh auth login"));
40
+ process.exit(1);
41
+ return;
42
+ }
43
+ spinner.succeed("GitHub CLI authenticated");
44
+ const validateSpinner = ora("Validating skill manifest...").start();
45
+ const manifestPath = path.join(skillDir, "agenticmail-skill.json");
46
+ let manifest;
47
+ try {
48
+ const raw = await fs.readFile(manifestPath, "utf-8");
49
+ manifest = JSON.parse(raw);
50
+ } catch (err) {
51
+ validateSpinner.fail(`Cannot read manifest: ${err.message}`);
52
+ process.exit(1);
53
+ return;
54
+ }
55
+ const validation = validateSkillManifest(manifest);
56
+ if (!validation.valid) {
57
+ validateSpinner.fail("Manifest validation failed");
58
+ for (const err of validation.errors) {
59
+ console.log(chalk.red(" \u2502 " + err));
60
+ }
61
+ console.log(chalk.dim("\n Fix the errors above and try again."));
62
+ process.exit(1);
63
+ return;
64
+ }
65
+ validateSpinner.succeed(`Manifest valid: ${manifest.name} v${manifest.version}`);
66
+ const skillId = manifest.id;
67
+ const branchName = `community/add-${skillId}`;
68
+ const forkSpinner = ora("Forking repository...").start();
69
+ try {
70
+ execSync(`gh repo fork ${UPSTREAM_REPO} --clone=false 2>&1 || true`, { stdio: "pipe" });
71
+ forkSpinner.succeed("Repository forked (or already exists)");
72
+ } catch {
73
+ forkSpinner.succeed("Fork exists");
74
+ }
75
+ let forkUrl;
76
+ try {
77
+ const ghUser = execSync("gh api user --jq .login", { encoding: "utf-8" }).trim();
78
+ forkUrl = `https://github.com/${ghUser}/enterprise.git`;
79
+ } catch {
80
+ forkSpinner.fail("Cannot determine GitHub username");
81
+ process.exit(1);
82
+ return;
83
+ }
84
+ const tmpDir = path.join(process.env.TMPDIR || "/tmp", `agenticmail-submit-${Date.now()}`);
85
+ const pushSpinner = ora("Cloning fork...").start();
86
+ try {
87
+ execSync(`git clone --depth 1 ${forkUrl} "${tmpDir}"`, { stdio: "pipe" });
88
+ pushSpinner.text = "Creating branch...";
89
+ const run = (cmd) => execSync(cmd, { cwd: tmpDir, stdio: "pipe", encoding: "utf-8" });
90
+ run(`git remote add upstream https://github.com/${UPSTREAM_REPO}.git`);
91
+ run("git fetch upstream main --depth 1");
92
+ run(`git checkout -b ${branchName} upstream/main`);
93
+ pushSpinner.text = "Copying skill files...";
94
+ const destDir = path.join(tmpDir, "community-skills", skillId);
95
+ await fs.mkdir(destDir, { recursive: true });
96
+ const files = await fs.readdir(skillDir);
97
+ for (const file of files) {
98
+ await fs.copyFile(path.join(skillDir, file), path.join(destDir, file));
99
+ }
100
+ pushSpinner.text = "Committing...";
101
+ run(`git add community-skills/${skillId}/`);
102
+ run(`git commit -m "Add community skill: ${manifest.name}"`);
103
+ pushSpinner.text = "Pushing to fork...";
104
+ run(`git push origin ${branchName} --force`);
105
+ pushSpinner.succeed("Pushed to fork");
106
+ } catch (err) {
107
+ pushSpinner.fail(`Git operation failed: ${err.message}`);
108
+ process.exit(1);
109
+ return;
110
+ }
111
+ const prSpinner = ora("Opening pull request...").start();
112
+ const toolsList = (manifest.tools || []).map(
113
+ (t) => `- \`${t.id}\` \u2014 ${t.name}: ${t.description}`
114
+ ).join("\n");
115
+ const prBody = `## Community Skill Submission
116
+
117
+ **Skill ID:** \`${manifest.id}\`
118
+ **Application:** ${manifest.name}
119
+ **Category:** ${manifest.category}
120
+ **Risk Level:** ${manifest.risk}
121
+ **Author:** @${manifest.author}
122
+ **License:** ${manifest.license}
123
+
124
+ ### Description
125
+
126
+ ${manifest.description}
127
+
128
+ ### Tools Provided
129
+
130
+ ${toolsList}
131
+
132
+ ### Validation
133
+
134
+ - [x] Manifest passes \`npx @agenticmail/enterprise validate\`
135
+ - [x] All required fields present
136
+ - [x] No duplicate tool IDs
137
+ ${manifest.tags ? `
138
+ **Tags:** ${manifest.tags.join(", ")}` : ""}`;
139
+ try {
140
+ const prUrl = execSync(
141
+ `gh pr create --repo ${UPSTREAM_REPO} --head ${branchName} --title "Add community skill: ${manifest.name}" --body "${prBody.replace(/"/g, '\\"')}"`,
142
+ { cwd: tmpDir, encoding: "utf-8", stdio: "pipe" }
143
+ ).trim();
144
+ prSpinner.succeed("Pull request opened!");
145
+ console.log(chalk.green(`
146
+ ${prUrl}
147
+ `));
148
+ } catch (err) {
149
+ if (err.stderr?.includes("already exists")) {
150
+ prSpinner.warn("A PR for this skill already exists");
151
+ } else {
152
+ prSpinner.fail(`Could not open PR: ${err.message}`);
153
+ }
154
+ }
155
+ try {
156
+ await fs.rm(tmpDir, { recursive: true, force: true });
157
+ } catch {
158
+ }
159
+ }
160
+ export {
161
+ runSubmitSkill
162
+ };
@@ -0,0 +1,148 @@
1
+ import {
2
+ ALL_TOOLS,
3
+ init_tool_catalog
4
+ } from "./chunk-WI62KTVK.js";
5
+ import {
6
+ collectCommunityToolIds,
7
+ validateSkillManifest
8
+ } from "./chunk-TY7NVD4U.js";
9
+ import "./chunk-2ESYSVXG.js";
10
+
11
+ // src/engine/cli-validate.ts
12
+ init_tool_catalog();
13
+ async function runValidate(args) {
14
+ const chalk = (await import("chalk")).default;
15
+ const fs = await import("fs/promises");
16
+ const path = await import("path");
17
+ const jsonMode = args.includes("--json");
18
+ const allMode = args.includes("--all");
19
+ const pathArgs = args.filter((a) => !a.startsWith("--"));
20
+ const builtinIds = new Set(ALL_TOOLS.map((t) => t.id));
21
+ const communityDir = path.resolve(process.cwd(), "community-skills");
22
+ const reports = [];
23
+ if (allMode) {
24
+ let entries;
25
+ try {
26
+ entries = await fs.readdir(communityDir, { withFileTypes: true });
27
+ } catch {
28
+ if (jsonMode) {
29
+ console.log(JSON.stringify({ error: "community-skills/ directory not found" }));
30
+ } else {
31
+ console.error(chalk.red("Error: community-skills/ directory not found"));
32
+ }
33
+ process.exit(1);
34
+ return;
35
+ }
36
+ for (const entry of entries) {
37
+ if (!entry.isDirectory() || entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
38
+ const skillDir = path.join(communityDir, entry.name);
39
+ const report = await validatePath(skillDir, builtinIds, communityDir);
40
+ reports.push(report);
41
+ }
42
+ } else {
43
+ const target = pathArgs[0];
44
+ if (!target) {
45
+ if (jsonMode) {
46
+ console.log(JSON.stringify({ error: "No path specified. Usage: npx @agenticmail/enterprise validate <path> [--all] [--json]" }));
47
+ } else {
48
+ console.log(`${chalk.bold("Usage:")} npx @agenticmail/enterprise validate <path>`);
49
+ console.log("");
50
+ console.log(" <path> Path to a skill directory or agenticmail-skill.json file");
51
+ console.log(" --all Validate all skills in community-skills/");
52
+ console.log(" --json Machine-readable JSON output");
53
+ }
54
+ process.exit(1);
55
+ return;
56
+ }
57
+ const report = await validatePath(path.resolve(target), builtinIds, communityDir);
58
+ reports.push(report);
59
+ }
60
+ if (jsonMode) {
61
+ console.log(JSON.stringify({ results: reports, totalErrors: reports.reduce((s, r) => s + r.errors.length, 0) }, null, 2));
62
+ } else {
63
+ console.log("");
64
+ for (const report of reports) {
65
+ if (report.valid) {
66
+ console.log(chalk.green(" \u2714") + " " + chalk.bold(report.skillId) + chalk.dim(` (${report.path})`));
67
+ } else {
68
+ console.log(chalk.red(" \u2718") + " " + chalk.bold(report.skillId) + chalk.dim(` (${report.path})`));
69
+ for (const err of report.errors) {
70
+ console.log(chalk.red(" \u2502 ") + err);
71
+ }
72
+ }
73
+ for (const warn of report.warnings) {
74
+ console.log(chalk.yellow(" \u26A0 ") + warn);
75
+ }
76
+ }
77
+ console.log("");
78
+ const passed = reports.filter((r) => r.valid).length;
79
+ const failed = reports.filter((r) => !r.valid).length;
80
+ if (failed > 0) {
81
+ console.log(chalk.red(` ${failed} failed`) + chalk.dim(`, ${passed} passed, ${reports.length} total`));
82
+ } else {
83
+ console.log(chalk.green(` ${passed} passed`) + chalk.dim(`, ${reports.length} total`));
84
+ }
85
+ console.log("");
86
+ }
87
+ if (reports.some((r) => !r.valid)) {
88
+ process.exit(1);
89
+ }
90
+ }
91
+ async function validatePath(targetPath, builtinIds, communityDir) {
92
+ const fs = await import("fs/promises");
93
+ const path = await import("path");
94
+ let manifestPath;
95
+ try {
96
+ const stat = await fs.stat(targetPath);
97
+ if (stat.isDirectory()) {
98
+ manifestPath = path.join(targetPath, "agenticmail-skill.json");
99
+ } else {
100
+ manifestPath = targetPath;
101
+ }
102
+ } catch {
103
+ return {
104
+ path: targetPath,
105
+ skillId: path.basename(targetPath),
106
+ valid: false,
107
+ errors: [`Path not found: ${targetPath}`],
108
+ warnings: []
109
+ };
110
+ }
111
+ let raw;
112
+ try {
113
+ raw = await fs.readFile(manifestPath, "utf-8");
114
+ } catch {
115
+ return {
116
+ path: manifestPath,
117
+ skillId: path.basename(path.dirname(manifestPath)),
118
+ valid: false,
119
+ errors: [`Cannot read: ${manifestPath}`],
120
+ warnings: []
121
+ };
122
+ }
123
+ let manifest;
124
+ try {
125
+ manifest = JSON.parse(raw);
126
+ } catch (err) {
127
+ return {
128
+ path: manifestPath,
129
+ skillId: path.basename(path.dirname(manifestPath)),
130
+ valid: false,
131
+ errors: [`Invalid JSON: ${err.message}`],
132
+ warnings: []
133
+ };
134
+ }
135
+ const communityIds = await collectCommunityToolIds(communityDir, manifest.id);
136
+ const allExistingIds = /* @__PURE__ */ new Set([...builtinIds, ...communityIds]);
137
+ const result = validateSkillManifest(manifest, { existingToolIds: allExistingIds });
138
+ return {
139
+ path: manifestPath,
140
+ skillId: manifest.id || path.basename(path.dirname(manifestPath)),
141
+ valid: result.valid,
142
+ errors: result.errors,
143
+ warnings: result.warnings
144
+ };
145
+ }
146
+ export {
147
+ runValidate
148
+ };
@@ -0,0 +1,148 @@
1
+ import {
2
+ ALL_TOOLS,
3
+ init_tool_catalog
4
+ } from "./chunk-X6UVWFHW.js";
5
+ import {
6
+ collectCommunityToolIds,
7
+ validateSkillManifest
8
+ } from "./chunk-TY7NVD4U.js";
9
+ import "./chunk-KFQGP6VL.js";
10
+
11
+ // src/engine/cli-validate.ts
12
+ init_tool_catalog();
13
+ async function runValidate(args) {
14
+ const chalk = (await import("chalk")).default;
15
+ const fs = await import("fs/promises");
16
+ const path = await import("path");
17
+ const jsonMode = args.includes("--json");
18
+ const allMode = args.includes("--all");
19
+ const pathArgs = args.filter((a) => !a.startsWith("--"));
20
+ const builtinIds = new Set(ALL_TOOLS.map((t) => t.id));
21
+ const communityDir = path.resolve(process.cwd(), "community-skills");
22
+ const reports = [];
23
+ if (allMode) {
24
+ let entries;
25
+ try {
26
+ entries = await fs.readdir(communityDir, { withFileTypes: true });
27
+ } catch {
28
+ if (jsonMode) {
29
+ console.log(JSON.stringify({ error: "community-skills/ directory not found" }));
30
+ } else {
31
+ console.error(chalk.red("Error: community-skills/ directory not found"));
32
+ }
33
+ process.exit(1);
34
+ return;
35
+ }
36
+ for (const entry of entries) {
37
+ if (!entry.isDirectory() || entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
38
+ const skillDir = path.join(communityDir, entry.name);
39
+ const report = await validatePath(skillDir, builtinIds, communityDir);
40
+ reports.push(report);
41
+ }
42
+ } else {
43
+ const target = pathArgs[0];
44
+ if (!target) {
45
+ if (jsonMode) {
46
+ console.log(JSON.stringify({ error: "No path specified. Usage: npx @agenticmail/enterprise validate <path> [--all] [--json]" }));
47
+ } else {
48
+ console.log(`${chalk.bold("Usage:")} npx @agenticmail/enterprise validate <path>`);
49
+ console.log("");
50
+ console.log(" <path> Path to a skill directory or agenticmail-skill.json file");
51
+ console.log(" --all Validate all skills in community-skills/");
52
+ console.log(" --json Machine-readable JSON output");
53
+ }
54
+ process.exit(1);
55
+ return;
56
+ }
57
+ const report = await validatePath(path.resolve(target), builtinIds, communityDir);
58
+ reports.push(report);
59
+ }
60
+ if (jsonMode) {
61
+ console.log(JSON.stringify({ results: reports, totalErrors: reports.reduce((s, r) => s + r.errors.length, 0) }, null, 2));
62
+ } else {
63
+ console.log("");
64
+ for (const report of reports) {
65
+ if (report.valid) {
66
+ console.log(chalk.green(" \u2714") + " " + chalk.bold(report.skillId) + chalk.dim(` (${report.path})`));
67
+ } else {
68
+ console.log(chalk.red(" \u2718") + " " + chalk.bold(report.skillId) + chalk.dim(` (${report.path})`));
69
+ for (const err of report.errors) {
70
+ console.log(chalk.red(" \u2502 ") + err);
71
+ }
72
+ }
73
+ for (const warn of report.warnings) {
74
+ console.log(chalk.yellow(" \u26A0 ") + warn);
75
+ }
76
+ }
77
+ console.log("");
78
+ const passed = reports.filter((r) => r.valid).length;
79
+ const failed = reports.filter((r) => !r.valid).length;
80
+ if (failed > 0) {
81
+ console.log(chalk.red(` ${failed} failed`) + chalk.dim(`, ${passed} passed, ${reports.length} total`));
82
+ } else {
83
+ console.log(chalk.green(` ${passed} passed`) + chalk.dim(`, ${reports.length} total`));
84
+ }
85
+ console.log("");
86
+ }
87
+ if (reports.some((r) => !r.valid)) {
88
+ process.exit(1);
89
+ }
90
+ }
91
+ async function validatePath(targetPath, builtinIds, communityDir) {
92
+ const fs = await import("fs/promises");
93
+ const path = await import("path");
94
+ let manifestPath;
95
+ try {
96
+ const stat = await fs.stat(targetPath);
97
+ if (stat.isDirectory()) {
98
+ manifestPath = path.join(targetPath, "agenticmail-skill.json");
99
+ } else {
100
+ manifestPath = targetPath;
101
+ }
102
+ } catch {
103
+ return {
104
+ path: targetPath,
105
+ skillId: path.basename(targetPath),
106
+ valid: false,
107
+ errors: [`Path not found: ${targetPath}`],
108
+ warnings: []
109
+ };
110
+ }
111
+ let raw;
112
+ try {
113
+ raw = await fs.readFile(manifestPath, "utf-8");
114
+ } catch {
115
+ return {
116
+ path: manifestPath,
117
+ skillId: path.basename(path.dirname(manifestPath)),
118
+ valid: false,
119
+ errors: [`Cannot read: ${manifestPath}`],
120
+ warnings: []
121
+ };
122
+ }
123
+ let manifest;
124
+ try {
125
+ manifest = JSON.parse(raw);
126
+ } catch (err) {
127
+ return {
128
+ path: manifestPath,
129
+ skillId: path.basename(path.dirname(manifestPath)),
130
+ valid: false,
131
+ errors: [`Invalid JSON: ${err.message}`],
132
+ warnings: []
133
+ };
134
+ }
135
+ const communityIds = await collectCommunityToolIds(communityDir, manifest.id);
136
+ const allExistingIds = /* @__PURE__ */ new Set([...builtinIds, ...communityIds]);
137
+ const result = validateSkillManifest(manifest, { existingToolIds: allExistingIds });
138
+ return {
139
+ path: manifestPath,
140
+ skillId: manifest.id || path.basename(path.dirname(manifestPath)),
141
+ valid: result.valid,
142
+ errors: result.errors,
143
+ warnings: result.warnings
144
+ };
145
+ }
146
+ export {
147
+ runValidate
148
+ };