@42ailab/42plugin 0.1.0-beta.0

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,114 @@
1
+ export enum TargetType {
2
+ Capability = 'capability', // Full name: owner/repo:plugin:type:name
3
+ CapabilitySlug = 'capability_slug', // Short slug: author/slug
4
+ Plugin = 'plugin',
5
+ List = 'list',
6
+ }
7
+
8
+ export interface ParsedTarget {
9
+ type: TargetType;
10
+ fullName: string;
11
+ owner: string;
12
+ repo: string;
13
+ plugin?: string;
14
+ capType?: string;
15
+ capName?: string;
16
+ // For slug format
17
+ author?: string;
18
+ slug?: string;
19
+ }
20
+
21
+ /**
22
+ * Parse install target
23
+ *
24
+ * Formats:
25
+ * - Capability (full): owner/repo:plugin:type:name
26
+ * - Capability (slug): author/slug (e.g., alice/smart-reviewer)
27
+ * - Plugin: owner/repo:plugin
28
+ * - List: owner/list/slug
29
+ */
30
+ export function parseTarget(target: string): ParsedTarget {
31
+ // List format: owner/list/slug
32
+ if (target.includes('/list/')) {
33
+ const [owner, , slug] = target.split('/');
34
+ return {
35
+ type: TargetType.List,
36
+ fullName: target,
37
+ owner,
38
+ repo: 'list',
39
+ };
40
+ }
41
+
42
+ // Parse owner/repo:...
43
+ const [ownerRepo, ...rest] = target.split(':');
44
+ const slashParts = ownerRepo.split('/');
45
+
46
+ if (slashParts.length < 2) {
47
+ throw new Error(`Invalid target format: ${target}`);
48
+ }
49
+
50
+ const owner = slashParts[0];
51
+ const repo = slashParts[1];
52
+
53
+ if (!owner || !repo) {
54
+ throw new Error(`Invalid target format: ${target}`);
55
+ }
56
+
57
+ // Capability full format: owner/repo:plugin:type:name
58
+ if (rest.length === 3) {
59
+ const [plugin, capType, capName] = rest;
60
+ return {
61
+ type: TargetType.Capability,
62
+ fullName: target,
63
+ owner,
64
+ repo,
65
+ plugin,
66
+ capType,
67
+ capName,
68
+ };
69
+ }
70
+
71
+ // Plugin format: owner/repo:plugin
72
+ if (rest.length === 1) {
73
+ return {
74
+ type: TargetType.Plugin,
75
+ fullName: target,
76
+ owner,
77
+ repo,
78
+ plugin: rest[0],
79
+ };
80
+ }
81
+
82
+ // Simple format: author/slug (no colon, just two parts)
83
+ // This is the new short slug format for capabilities
84
+ if (rest.length === 0 && slashParts.length === 2) {
85
+ return {
86
+ type: TargetType.CapabilitySlug,
87
+ fullName: target,
88
+ owner,
89
+ repo,
90
+ author: owner,
91
+ slug: repo,
92
+ };
93
+ }
94
+
95
+ throw new Error(`Invalid target format: ${target}`);
96
+ }
97
+
98
+ /**
99
+ * Get install path for a capability type
100
+ */
101
+ export function getInstallPath(type: string, name: string): string {
102
+ switch (type) {
103
+ case 'skill':
104
+ return `.claude/skills/${name}/`;
105
+ case 'agent':
106
+ return `.claude/agents/${name}.md`;
107
+ case 'command':
108
+ return `.claude/commands/${name}.md`;
109
+ case 'hook':
110
+ return `.claude/hooks/${name}`;
111
+ default:
112
+ return `.claude/${type}/${name}/`;
113
+ }
114
+ }