-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.go
More file actions
564 lines (455 loc) · 14.2 KB
/
Copy pathtypes.go
File metadata and controls
564 lines (455 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
package skills
import (
"encoding/json"
"time"
)
type InstallMode string
const (
InstallModeSymlink InstallMode = "symlink"
InstallModeCopy InstallMode = "copy"
)
type AgentType string
type AgentConfig struct {
Name AgentType
DisplayName string
ProjectSkillsDir string
GlobalSkillsDir string
ShowInUniversal bool
DetectProjectPath string
DetectGlobalPath string
}
type Skill struct {
Name string
Description string
Compatibility string
AllowedTools []string
Dir string
Content string
Metadata map[string]any
}
type SkillSourceType string
const (
SkillSourceTypeLocal SkillSourceType = "local"
SkillSourceTypeGitHub SkillSourceType = "github"
SkillSourceTypeGitLab SkillSourceType = "gitlab"
SkillSourceTypeGit SkillSourceType = "git"
SkillSourceTypeDirectURL SkillSourceType = "direct-url"
SkillSourceTypeWellKnown SkillSourceType = "well-known"
SkillSourceTypeSearchHint SkillSourceType = "search-hint"
)
type SkillSource struct {
Type SkillSourceType `json:"type"`
SourceURL string `json:"source_url,omitempty"`
Owner string `json:"owner,omitempty"`
Repo string `json:"repo,omitempty"`
Ref string `json:"ref,omitempty"`
Subpath string `json:"subpath,omitempty"`
SkillFilter string `json:"skill_filter,omitempty"`
ProviderID string `json:"provider_id,omitempty"`
InstallName string `json:"install_name,omitempty"`
WellKnownURL string `json:"well_known_url,omitempty"`
}
type SearchResult struct {
ID string `json:"id"`
SkillID string `json:"skill_id"`
Name string `json:"name"`
Installs int `json:"installs"`
Source string `json:"source"`
}
type AddOptions struct {
// Source is the install source string (local dir, git repo reference, direct URL,
// or a well-known index URL).
Source string
// Dirs are explicit target directories to install into. When provided, agent discovery is
// bypassed and Add installs directly to these directories.
Dirs []string
// Global installs into the global skills locations rather than project-local ones.
// When agent discovery is enabled, global installs may also be tracked in the lock file
// for future update checks.
Global bool
// Agents is an optional allowlist of agent types to install for. When empty and agent
// discovery is enabled, installed agents may be auto-detected.
Agents []AgentType
// Skills selects which skills to install from a multi-skill source. Entries may match
// either the skill folder name or the parsed skill name. "*" selects all discovered skills.
Skills []string
// ListOnly discovers and returns available skills without installing anything.
ListOnly bool
// Yes enables non-interactive defaults when a choice is required (for example, when a
// source contains multiple skills and no explicit selection was provided).
Yes bool
// All installs all discovered skills. In Add, this implies Yes and sets Skills to "*".
All bool
// FullDepth enables deep scanning for SKILL.md files within the source directory tree.
FullDepth bool
// Mode controls how skill files are installed (for example, via symlinks or copying).
Mode InstallMode
// EnableAgentDiscovery enables deriving target directories from the canonical skills dir
// and agent-specific skills dirs when Dirs is not provided.
EnableAgentDiscovery bool
}
type InstalledSkill struct {
InstallName string
Name string
Description string
Source SkillSource
Agents []AgentType
Global bool
}
type AddResult struct {
Available []Skill
Installed []InstalledSkill
}
type RemoveOptions struct {
// Dirs are explicit target directories to remove from. When provided, agent discovery is
// bypassed and Remove deletes directly from these directories.
Dirs []string
// Global removes from the global install locations rather than project-local ones.
Global bool
// Agents is an optional allowlist of agent types to remove from. When empty and agent
// discovery is enabled, installed agents may be auto-detected.
Agents []AgentType
// Skills is the list of install names to remove. When empty, All must be set.
Skills []string
// All removes all installed skills found in the resolved target directories.
All bool
// Yes is reserved for non-interactive defaults. It is currently unused by Remove.
Yes bool
// EnableAgentDiscovery enables deriving target directories from the canonical skills dir
// and agent-specific skills dirs when Dirs is not provided.
EnableAgentDiscovery bool
}
type RemoveResult struct {
Removed []InstalledSkill
}
type ListOptions struct {
// Dirs are explicit directories to list install names from. When provided, agent discovery
// is bypassed and List reads only these directories.
Dirs []string
// BundledSkills are fallback skills injected directly from code. Skill.Name is used as the
// install name. When the same install name exists in both BundledSkills and Dirs, entries
// from Dirs take precedence.
BundledSkills []Skill
// Global lists from the global install locations rather than project-local ones.
Global bool
// Agents is an optional allowlist of agent types to list for. When empty and agent
// discovery is enabled, installed agents may be auto-detected.
Agents []AgentType
// EnableAgentDiscovery enables deriving target directories from the canonical skills dir
// and agent-specific skills dirs when Dirs is not provided.
EnableAgentDiscovery bool
}
type ListedSkill struct {
InstallName string
Name string
Description string
Global bool
Agents []AgentType
}
type GetOptions struct {
// Dirs are explicit directories to search. When provided, agent discovery is bypassed and
// Get searches only these directories.
Dirs []string
// BundledSkills are fallback skills injected directly from code. Skill.Name is used as the
// install name. When the same install name exists in both BundledSkills and Dirs, entries
// from Dirs take precedence.
BundledSkills []Skill
// Skill is the install name of the skill to load.
Skill string
// Global searches the global install locations rather than project-local ones.
Global bool
// Agents is an optional allowlist of agent types to search. When empty and agent discovery
// is enabled, installed agents may be auto-detected.
Agents []AgentType
// EnableAgentDiscovery enables deriving target directories from the canonical skills dir
// and agent-specific skills dirs when Dirs is not provided.
EnableAgentDiscovery bool
}
type GetResult struct {
InstallName string
Skill Skill
}
type InitOptions struct {
// Name is an optional folder name used to place the template under "<dir>/<name>/SKILL.md".
Name string
// Dir is the base directory to write into. When empty, the current working directory is used.
Dir string
}
type LockEntry struct {
Source SkillSource `json:"source"`
SourceType string `json:"source_type"`
SourceURL string `json:"source_url"`
SkillPath string `json:"skill_path,omitempty"`
SkillFolderHash string `json:"skill_folder_hash,omitempty"`
InstalledAt time.Time `json:"installed_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type SkillLock struct {
Skills map[string]LockEntry `json:"skills"`
LastSelectedAgents []AgentType `json:"last_selected_agents,omitempty"`
Dismissed map[string]bool `json:"dismissed,omitempty"`
}
func (s *SkillSource) UnmarshalJSON(b []byte) error {
var obj map[string]json.RawMessage
if err := json.Unmarshal(b, &obj); err != nil {
return err
}
type snake struct {
Type SkillSourceType `json:"type"`
SourceURL string `json:"source_url,omitempty"`
Owner string `json:"owner,omitempty"`
Repo string `json:"repo,omitempty"`
Ref string `json:"ref,omitempty"`
Subpath string `json:"subpath,omitempty"`
SkillFilter string `json:"skill_filter,omitempty"`
ProviderID string `json:"provider_id,omitempty"`
InstallName string `json:"install_name,omitempty"`
WellKnownURL string `json:"well_known_url,omitempty"`
}
type camel struct {
Type SkillSourceType `json:"type"`
SourceURL string `json:"sourceUrl,omitempty"`
Owner string `json:"owner,omitempty"`
Repo string `json:"repo,omitempty"`
Ref string `json:"ref,omitempty"`
Subpath string `json:"subpath,omitempty"`
SkillFilter string `json:"skillFilter,omitempty"`
ProviderID string `json:"providerId,omitempty"`
InstallName string `json:"installName,omitempty"`
WellKnownURL string `json:"wellKnownUrl,omitempty"`
}
if _, ok := obj["source_url"]; ok {
var v snake
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*s = SkillSource(v)
return nil
}
if _, ok := obj["skill_filter"]; ok {
var v snake
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*s = SkillSource(v)
return nil
}
if _, ok := obj["provider_id"]; ok {
var v snake
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*s = SkillSource(v)
return nil
}
if _, ok := obj["install_name"]; ok {
var v snake
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*s = SkillSource(v)
return nil
}
if _, ok := obj["well_known_url"]; ok {
var v snake
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*s = SkillSource(v)
return nil
}
if _, ok := obj["sourceUrl"]; ok {
var v camel
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*s = SkillSource(v)
return nil
}
if _, ok := obj["skillFilter"]; ok {
var v camel
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*s = SkillSource(v)
return nil
}
if _, ok := obj["providerId"]; ok {
var v camel
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*s = SkillSource(v)
return nil
}
if _, ok := obj["installName"]; ok {
var v camel
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*s = SkillSource(v)
return nil
}
if _, ok := obj["wellKnownUrl"]; ok {
var v camel
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*s = SkillSource(v)
return nil
}
var v snake
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*s = SkillSource(v)
return nil
}
func (r *SearchResult) UnmarshalJSON(b []byte) error {
var obj map[string]json.RawMessage
if err := json.Unmarshal(b, &obj); err != nil {
return err
}
type snake struct {
ID string `json:"id"`
SkillID string `json:"skill_id"`
Name string `json:"name"`
Installs int `json:"installs"`
Source string `json:"source"`
}
type camel struct {
ID string `json:"id"`
SkillID string `json:"skillId"`
Name string `json:"name"`
Installs int `json:"installs"`
Source string `json:"source"`
}
if _, ok := obj["skill_id"]; ok {
var v snake
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*r = SearchResult(v)
return nil
}
if _, ok := obj["skillId"]; ok {
var v camel
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*r = SearchResult(v)
return nil
}
var v snake
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*r = SearchResult(v)
return nil
}
func (e *LockEntry) UnmarshalJSON(b []byte) error {
var obj map[string]json.RawMessage
if err := json.Unmarshal(b, &obj); err != nil {
return err
}
type snake struct {
Source SkillSource `json:"source"`
SourceType string `json:"source_type"`
SourceURL string `json:"source_url"`
SkillPath string `json:"skill_path,omitempty"`
SkillFolderHash string `json:"skill_folder_hash,omitempty"`
InstalledAt time.Time `json:"installed_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type camel struct {
Source SkillSource `json:"source"`
SourceType string `json:"sourceType"`
SourceURL string `json:"sourceUrl"`
SkillPath string `json:"skillPath,omitempty"`
SkillFolderHash string `json:"skillFolderHash,omitempty"`
InstalledAt time.Time `json:"installedAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
if _, ok := obj["source_type"]; ok {
var v snake
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*e = LockEntry(v)
return nil
}
if _, ok := obj["installed_at"]; ok {
var v snake
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*e = LockEntry(v)
return nil
}
if _, ok := obj["sourceType"]; ok {
var v camel
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*e = LockEntry(v)
return nil
}
if _, ok := obj["installedAt"]; ok {
var v camel
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*e = LockEntry(v)
return nil
}
var v snake
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*e = LockEntry(v)
return nil
}
func (l *SkillLock) UnmarshalJSON(b []byte) error {
var obj map[string]json.RawMessage
if err := json.Unmarshal(b, &obj); err != nil {
return err
}
type snake struct {
Skills map[string]LockEntry `json:"skills"`
LastSelectedAgents []AgentType `json:"last_selected_agents,omitempty"`
Dismissed map[string]bool `json:"dismissed,omitempty"`
}
type camel struct {
Skills map[string]LockEntry `json:"skills"`
LastSelectedAgents []AgentType `json:"lastSelectedAgents,omitempty"`
Dismissed map[string]bool `json:"dismissed,omitempty"`
}
if _, ok := obj["last_selected_agents"]; ok {
var v snake
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*l = SkillLock(v)
return nil
}
if _, ok := obj["lastSelectedAgents"]; ok {
var v camel
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*l = SkillLock(v)
return nil
}
var v snake
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*l = SkillLock(v)
return nil
}
type UpdateCheck struct {
InstallName string
Entry LockEntry
CurrentHash string
RemoteHash string
}