akm-cli 0.0.0 → 0.0.16

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.
@@ -0,0 +1,70 @@
1
+ import path from "node:path";
2
+ import { toPosix } from "./common";
3
+ export const SCRIPT_EXTENSIONS = new Set([".sh", ".ts", ".js", ".ps1", ".cmd", ".bat"]);
4
+ const markdownSpec = {
5
+ isRelevantFile: (fileName) => path.extname(fileName).toLowerCase() === ".md",
6
+ toCanonicalName: (typeRoot, filePath) => {
7
+ const rel = toPosix(path.relative(typeRoot, filePath));
8
+ // Strip .md extension from canonical names (agent:code-reviewer, not agent:code-reviewer.md)
9
+ return rel.endsWith(".md") ? rel.slice(0, -3) : rel;
10
+ },
11
+ toAssetPath: (typeRoot, name) => {
12
+ // Accept both with and without .md extension
13
+ const withExt = name.endsWith(".md") ? name : `${name}.md`;
14
+ return path.join(typeRoot, withExt);
15
+ },
16
+ };
17
+ /** Extended set of script extensions for the script asset type */
18
+ export const SCRIPT_EXTENSIONS_BROAD = new Set([
19
+ ...SCRIPT_EXTENSIONS,
20
+ ".py",
21
+ ".rb",
22
+ ".go",
23
+ ".pl",
24
+ ".php",
25
+ ".lua",
26
+ ".r",
27
+ ".swift",
28
+ ".kt",
29
+ ".kts",
30
+ ]);
31
+ const scriptSpec = {
32
+ isRelevantFile: (fileName) => SCRIPT_EXTENSIONS_BROAD.has(path.extname(fileName).toLowerCase()),
33
+ toCanonicalName: (typeRoot, filePath) => toPosix(path.relative(typeRoot, filePath)),
34
+ toAssetPath: (typeRoot, name) => path.join(typeRoot, name),
35
+ };
36
+ export const ASSET_SPECS = {
37
+ // "tool" is a transparent alias for "script". It uses the same spec
38
+ // (broad script extensions) but retains its own stashDir ("tools") so
39
+ // files in tools/ are still discovered.
40
+ tool: { stashDir: "tools", ...scriptSpec },
41
+ skill: {
42
+ stashDir: "skills",
43
+ isRelevantFile: (fileName) => fileName === "SKILL.md",
44
+ toCanonicalName: (typeRoot, filePath) => {
45
+ const relDir = toPosix(path.dirname(path.relative(typeRoot, filePath)));
46
+ if (!relDir || relDir === ".")
47
+ return undefined;
48
+ return relDir;
49
+ },
50
+ toAssetPath: (typeRoot, name) => path.join(typeRoot, name, "SKILL.md"),
51
+ },
52
+ command: { stashDir: "commands", ...markdownSpec },
53
+ agent: { stashDir: "agents", ...markdownSpec },
54
+ knowledge: { stashDir: "knowledge", ...markdownSpec },
55
+ script: { stashDir: "scripts", ...scriptSpec },
56
+ };
57
+ export const ASSET_TYPES = Object.keys(ASSET_SPECS);
58
+ export const TYPE_DIRS = ASSET_TYPES.reduce((acc, type) => {
59
+ acc[type] = ASSET_SPECS[type].stashDir;
60
+ return acc;
61
+ }, {});
62
+ export function isRelevantAssetFile(assetType, fileName) {
63
+ return ASSET_SPECS[assetType].isRelevantFile(fileName);
64
+ }
65
+ export function deriveCanonicalAssetName(assetType, typeRoot, filePath) {
66
+ return ASSET_SPECS[assetType].toCanonicalName(typeRoot, filePath);
67
+ }
68
+ export function resolveAssetPathFromName(assetType, typeRoot, name) {
69
+ return ASSET_SPECS[assetType].toAssetPath(typeRoot, name);
70
+ }