Skip to content

Commit 97af1a5

Browse files
authored
Merge pull request cli#13165 from cli/sm/add-skills-command
Add agent skills command
2 parents ebe0631 + a69a5fb commit 97af1a5

55 files changed

Lines changed: 15303 additions & 2 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@
3838
*~
3939

4040
vendor/
41+
gh

acceptance/acceptance_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414

1515
"math/rand"
1616

17+
"github.com/MakeNowJust/heredoc"
1718
"github.com/cli/cli/v2/internal/ghcmd"
1819
"github.com/cli/go-internal/testscript"
19-
"github.com/MakeNowJust/heredoc"
2020
)
2121

2222
func ghMain() int {
@@ -434,3 +434,11 @@ func (e *testScriptEnv) fromEnv() error {
434434

435435
return nil
436436
}
437+
438+
func TestSkills(t *testing.T) {
439+
var tsEnv testScriptEnv
440+
if err := tsEnv.fromEnv(); err != nil {
441+
t.Fatal(err)
442+
}
443+
testscript.Run(t, testScriptParamsFor(tsEnv, "skills"))
444+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Install with --force should overwrite an existing skill without error
2+
exec gh skill install github/awesome-copilot git-commit --force --dir $WORK/force-test
3+
stdout 'Installed git-commit'
4+
5+
# Install again with --force — should succeed (overwrite)
6+
exec gh skill install github/awesome-copilot git-commit --force --dir $WORK/force-test
7+
stdout 'Installed git-commit'
8+
9+
# Without --force, non-interactive should fail when skill exists
10+
! exec gh skill install github/awesome-copilot git-commit --dir $WORK/force-test
11+
stderr 'already installed'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Install from a local directory using --from-local
2+
exec gh skill install --from-local $WORK/local-repo git-commit --dir $WORK/output --force
3+
stdout 'Installed git-commit'
4+
5+
# Verify the skill was copied
6+
exists $WORK/output/git-commit/SKILL.md
7+
grep 'local-path' $WORK/output/git-commit/SKILL.md
8+
9+
-- local-repo/skills/git-commit/SKILL.md --
10+
---
11+
name: git-commit
12+
description: Write good git commits
13+
---
14+
# Git Commit
15+
Body content.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Invalid agent ID should error with valid options
2+
! exec gh skill install github/awesome-copilot git-commit --agent bogus-agent --force
3+
stderr 'invalid argument'
4+
stderr 'github-copilot'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Nonexistent repo should error
2+
! exec gh skill install nonexistent-owner-xyz/nonexistent-repo-abc --force --dir $WORK/tmp
3+
stderr 'Not Found'
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Two namespaced skills with the same base name in the same repo should
2+
# be independently installable using path-based disambiguation.
3+
4+
# Use gh as a credential helper
5+
exec gh auth setup-git
6+
7+
# Create a repo with two namespaced skills that share the name "deploy"
8+
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --public --add-readme
9+
defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING
10+
11+
exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING
12+
cd $SCRIPT_NAME-$RANDOM_STRING
13+
14+
mkdir -p skills/alice/deploy
15+
mkdir -p skills/bob/deploy
16+
cp $WORK/alice-skill.md skills/alice/deploy/SKILL.md
17+
cp $WORK/bob-skill.md skills/bob/deploy/SKILL.md
18+
19+
exec git add -A
20+
exec git commit -m 'Add namespaced skills'
21+
exec git push origin main
22+
23+
# Publish so the skills are discoverable
24+
exec gh skill publish --tag v1.0.0
25+
26+
# Install alice's deploy skill using the full path to disambiguate
27+
exec gh skill install $ORG/$SCRIPT_NAME-$RANDOM_STRING skills/alice/deploy --scope user --force
28+
stdout 'Installed alice/deploy'
29+
30+
# Install bob's deploy skill using the full path
31+
exec gh skill install $ORG/$SCRIPT_NAME-$RANDOM_STRING skills/bob/deploy --scope user --force
32+
stdout 'Installed bob/deploy'
33+
34+
# Verify both were installed to separate directories
35+
exists $HOME/.copilot/skills/alice/deploy/SKILL.md
36+
exists $HOME/.copilot/skills/bob/deploy/SKILL.md
37+
38+
# Verify each has the correct content
39+
grep 'Alice' $HOME/.copilot/skills/alice/deploy/SKILL.md
40+
grep 'Bob' $HOME/.copilot/skills/bob/deploy/SKILL.md
41+
42+
-- alice-skill.md --
43+
---
44+
name: deploy
45+
description: Alice's deployment skill
46+
---
47+
48+
# Deploy by Alice
49+
50+
Deploys infrastructure using Alice's conventions.
51+
52+
-- bob-skill.md --
53+
---
54+
name: deploy
55+
description: Bob's deployment skill
56+
---
57+
58+
# Deploy by Bob
59+
60+
Deploys infrastructure using Bob's conventions.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Install a skill that has nested subdirectories and verify file tree
2+
exec gh skill install github/awesome-copilot git-commit --force --dir $WORK/nested-test
3+
exists $WORK/nested-test/git-commit/SKILL.md
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Installing a skill that doesn't exist in a valid repo should error
2+
! exec gh skill install github/awesome-copilot nonexistent-skill-xyz --force --dir $WORK/tmp
3+
stderr 'not found'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Install with --pin to a specific ref
2+
exec gh skill install github/awesome-copilot git-commit --scope user --force --pin main
3+
stdout 'Installed git-commit'
4+
5+
# Install without --pin should resolve latest version
6+
exec gh skill install github/awesome-copilot git-commit --scope user --force
7+
stdout 'Installed git-commit'

0 commit comments

Comments
 (0)