Commit graph

5657 commits

Author SHA1 Message Date
Fredric Silberberg
a656271f26 Print gh auth refresh for 401 returns
`gh auth refresh` exists to make it simpler for users to refresh their tokens on expiration/scope mismatch, but help messages only suggest using it in limited scenarios, and not in a common case of a token expiring and the user receiving a 401 error. Now, the auth flow will detect this case, and for refreshable tokens (namely, tokens created by logging in with `gh auth login` in the first place), it will suggest using `gh auth refresh` for these cases.
2026-04-20 12:07:14 -06:00
Sam Morrow
49d4747a81
Merge pull request #13237 from cli/sammorrowdrums/fix-skill-publish-fix-flag 2026-04-20 19:23:09 +02:00
Sam Morrow
f88a2a671c
fix(skills): make --fix and --dry-run mutually exclusive, suppress publish prompt
- --fix and --dry-run now error when combined
- "Ready to publish!" is suppressed when --fix is set since user must
  commit first

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-20 12:36:57 +02:00
Sam Morrow
c703294fbe
fix(skills): use canonical 'gh skill' not 'gh skills' alias
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-20 12:34:59 +02:00
Sam Morrow
2e64043d55
fix(skills): stop publish --fix from publishing
When --fix is used, return early after applying fixes instead of
continuing to the publish flow. The fixed files need to be committed
before publishing, so proceeding would fail anyway since the repo
would not be in sync.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-20 12:22:55 +02:00
William Martin
78f1ad537c Include CI context in telemetry 2026-04-20 12:02:56 +02:00
Sam Morrow
eaa018545a
refactor: decouple hidden-dir filtering from discovery layer
Move --allow-hidden-dirs filtering logic from the discovery package to
the install command, addressing review feedback. Discovery functions now
always return all skills (including hidden-dir), and callers decide how
to handle them.

Changes:
- DiscoverSkillsWithOptions/DiscoverLocalSkillsWithOptions always return
  hidden-dir skills; callers filter using IsHiddenDirConvention()
- DiscoverSkills/DiscoverLocalSkills (convenience wrappers) auto-filter
  hidden-dir skills for backward compatibility with preview/update/publish
- Remove --allow-hidden-dirs reference from discovery error messages
- Add filterHiddenDirSkills in install.go with caller-side flag logic
- Inline warning using heredoc.Docf, remove printHiddenDirWarning
- Add inline comments in matchHiddenDirConventions (babakks nitpicks)
- Add non-hidden-namespaced dir and no-skills-at-all test cases
- Add --allow-hidden-dirs tests in TestNewCmdInstall, TestInstallRun,
  and TestRunLocalInstall

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-20 11:14:39 +02:00
Tommaso Moro
082f15a8fd
Add support for installation in multiple agent hosts in gh skills install (#13209)
* add support for installation in multiple agent host

* print correct dir in warning

* remove dir as it depends on user vs project installation scope

* Move comment closer to assertion in registry test

Move the explanatory comment from above the map initialization to
directly above the assertions it describes, per review feedback.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* List supported agent names and IDs in help text

Replace the self-referencing "run --help" sentence with an inline list
of all supported --agent values showing Name (id) pairs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Use heredoc.Docf for Kiro CLI post-install hint

Replace individual fmt.Fprintln calls with a single heredoc.Docf block
for the Kiro CLI post-install guidance, per review feedback. Also
shorten the --agent flag usage line by overriding the auto-generated
enum list with a reference to the supported values in the help text.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Kynan Ware <47394200+BagToad@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-18 15:22:09 -06:00
William Martin
998b6212b3
Add skills specific telemetry
* Add skills specific telemetry

* Remove VisibilityFuture, inline goroutine at call sites

The VisibilityFuture/FetchRepoVisibilityAsync/Wait wrapper was an
unidiomatic async abstraction built for a single pattern used in
exactly two call sites. In Go the channel is already the future;
wrapping it in a struct with a Wait(timeout) method adds no value.

Delete the abstraction and inline a local visResult struct,
buffered channel, goroutine, and select at each call site. Behavior
is preserved exactly: err -> "unknown", timeout -> "unknown",
success+public -> include skill_names.

FetchRepoVisibility (synchronous) is kept as-is.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix nonsense copilot tests

* Update telemetry tests for public-only dims and search event removal

Production telemetry emission changed:
- preview: skill_owner/skill_repo/skill_name (renamed from skill_names)
  are now emitted only when repo_visibility=public.
- install: skill_owner/skill_repo/skill_names are now emitted only
  when repo_visibility=public.
- search: the initial skill_search event was removed entirely; the
  skill_search_install event no longer carries query/owner dims.

Update tests to match: rename skill_names -> skill_name in preview,
make owner/repo assertions conditional on public visibility in both
preview and install, and reduce the search test to a single event
with explicit Empty assertions for the removed query/owner dims so a
privacy regression cannot pass silently.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Test CategorizeHost and switch telemetry to skill_host_type

Add TestCategorizeHost covering all four classification branches
(github.com, ghes, tenancy, uncategorized) with cases verified
against the real ghauth implementation rather than guessed.

Update install and preview unit tests to assert the new
skill_host_type dimension name, and fix a typo in the preview
acceptance txtar (skill_hos_type -> skill_host_type).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Shrink visibility wait and test unknown visibility

The 2s visibilityWaitTimeout was wildly overprovisioned: by the time
telemetry emission reaches the select, the command has already done
several serial GitHub REST calls (and for install, a git sparse-checkout
plus possibly interactive prompts), so the one-call visibility fetch
has almost always completed. Drop the timeout to 200ms — a short safety
net for a stalled REST call, not a wait budget for a healthy one.

Also adds a table-driven case to TestFetchRepoVisibility covering an
unknown/future visibility value from the API, addressing @babakks'
review nitpick.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-17 19:58:59 +02:00
William Martin
6709e315df Do not send telemetry for aliases 2026-04-17 14:28:49 +02:00
William Martin
73f390073c
Merge pull request #13191 from cli/wm/add-telemetry-to-cli
Add sampled command telemetry
2026-04-17 14:28:46 +02:00
William Martin
17776cafc1 Apply review feedback
- Harden SpawnSendTelemetry against relative executable paths
- Use io.Copy for telemetry subprocess stdin write
- Clean up GH_TELEMETRY/DO_NOT_TRACK help text
- Fall back to built-in defaults (NoOp telemetry) on config load failure

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-17 12:28:52 +02:00
William Martin
3ed389d664 Disable telemetry for GHES 2026-04-17 11:50:24 +02:00
tommaso-moro
d333093efd remove misleading text 2026-04-17 10:26:03 +01:00
William Martin
18dc5e77f0 Add sampled command telemetry 2026-04-16 21:42:46 +02:00
Sam Morrow
c5c7d790c5
Update publish_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-04-16 19:21:35 +02:00
Sam Morrow
bce04e3245
Merge branch 'trunk' into sammorrowdrums/skills-replace-git-in-publish-tests 2026-04-16 19:06:38 +02:00
Copilot
5ae5d1db7f refactor: replace real git with run.CommandStubber in publish tests
Replace all exec.Command("git", ...), initGitRepo, runGitInDir, and
newTestGitClientWithUpstream with run.Stub()/run.CommandStubber stubs.

Changes:
- Remove os/exec and strings imports; add fmt, regexp, internal/run
- Add newTestGitClient(), stubGitRemote(), stubEnsurePushed() helpers
- Remove initGitRepo, runGitInDir, newTestGitClientWithUpstream helpers
- Add cmdStubs field to TestPublishRun table struct
- Convert all test cases to use stub-based git interactions
- Use regexp.QuoteMeta for remote name patterns
- Use %[1]s/%[2]s format args in stubGitRemote
- Initialize git.Client with explicit GitPath to avoid real git resolution
- Rewrite TestEnsurePushed with stub-based tests
- Update TestDetectGitHubRemote_UsesDir and TestPublishRun_DirArgUsesTargetRemote

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-16 19:02:53 +02:00
Sam Morrow
d7961f1393
Merge pull request #13185 from cli/sammorrowdrums/skills-post-merge-review-followups
Address post-merge review feedback for skills commands
2026-04-16 18:59:21 +02:00
Sam Morrow
de204f8518
fix: apply review feedback — nil HttpClient, local dedup type
- Return nil instead of real http.Client in unsupported host test
- Move skillResultKey type inside deduplicateResults function scope

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-16 18:49:54 +02:00
Kynan Ware
3265170df9
Merge pull request #13175 from cli/kw/first-party-extension-suggestions
Suggest and install official extensions for unknown commands
2026-04-16 10:48:28 -06:00
Kynan Ware
32b8af1017 Remove dispatch after install, install only
Removes post-install extension dispatch to keep the stub focused on
installation. Also removes unused args parameter from the run function.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-16 10:38:33 -06:00
Kynan Ware
b8d504cbd9 Rename official extension files and types to stubs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-16 10:34:48 -06:00
Kynan Ware
1d59334964 Replace em-dashes with regular dashes
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-16 10:32:00 -06:00
William Martin
abc2a50b4c Address PR review feedback
- Use cmdutil.DisableAuthCheck instead of raw annotation map
- Convert tests to table-driven format
- Use generic extension name in tests (gh-cool)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-16 18:11:28 +02:00
William Martin
7ad1d7c0a1 Suggest and install official extensions via stub commands
Register hidden stub commands for official GitHub extensions (gh-aw,
gh-stack) that offer to install the extension when invoked. This
replaces the error-string-matching approach from the original PR with
proper cobra commands that:

- Avoid false-positive matches on flag values or post-'--' args
- Eliminate conflicting cobra 'Did you mean?' suggestions
- Properly propagate prompt/install errors for correct exit codes
- Are hidden from help output and shell completions
- Use GroupID "extension" so checkValidExtension allows installing over them
- Are registered after extensions and aliases so both take priority

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-16 17:58:37 +02:00
Sam Morrow
9d00ecc248
style: fix gofmt alignment in publish tests
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-16 17:04:12 +02:00
Sam Morrow
8b115d2c23
fix: address post-merge review feedback for skills commands
- Remove direct opts.client injection in publish; use HttpClient factory
  pattern (PR #13168 feedback)
- Rename testName to name in discovery test struct (PR #13170 feedback)
- Use typed struct keys for dedup map with case-insensitive comparison
  in deduplicateResults (PR #13170 feedback)
- Simplify remote selection to use Remotes() ordering instead of manual
  origin-first logic (PR #13171 feedback)
- Fix push icon timing: show no icon before push, SuccessIcon after
  success (PR #13171 feedback)

Closes #13184

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-16 16:19:59 +02:00
Sam Morrow
1aa19846d4
Merge branch 'trunk' into sm/add-skills-command 2026-04-16 15:56:48 +02:00
Sam Morrow
963a1438a9
Merge pull request #13170 from cli/sammorrowdrums/fix-skills-namespace-dedup
fix: preserve namespace in skills search deduplication
2026-04-16 15:55:41 +02:00
Sam Morrow
29e55fe5b9
refactor: remove redundant nil-client fallback in skills publish (#13168)
Remove the dead code block that silently swallowed errors from
opts.HttpClient() and opts.Config() when creating an API client.
Instead, create the client with proper error propagation inside the
remote-checks block where it is actually needed.

Changes:
- Remove the error-swallowing client == nil fallback (lines 363-376)
- Create the API client inside the remote repo checks block with
  proper error returns from HttpClient() and Config()
- Resolve host from repoInfo first, then fall back to config
- Remove the now-unreachable 'client == nil' early exit before publish

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-16 15:52:53 +02:00
Sam Morrow
cf1afc9b88
Merge pull request #13167 from cli/sammorrowdrums/publish-use-shared-discovery
Publish: use shared discovery logic instead of requiring skills/ directory
2026-04-16 15:48:20 +02:00
Sam Morrow
e559a7cd5b
feat(skills): auto-push unpushed commits before publish
Like gh pr create, skill publish now automatically pushes unpushed
local commits before creating a release. This prevents the footgun
where a release is created against stale remote state when the user
has local commits that haven't been pushed yet.

The ensurePushed function checks for unpushed commits using
git rev-list @{push}..HEAD. If commits exist or the branch has
never been pushed, it pushes automatically and prints a status
message. This matches the CLI's opinionated-defaults philosophy
of doing the right thing by default.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-16 15:43:10 +02:00
Sam Morrow
b63f5bfd9a
refactor: use shared discovery logic in publish command
Replace the hardcoded skills/ directory requirement in the publish
command with the shared DiscoverLocalSkills() function used by install
and other commands. This removes the opinionated restriction that skills
must live under a skills/ directory and supports all discovery
conventions:

- skills/*/SKILL.md
- skills/{scope}/*/SKILL.md
- */SKILL.md (root-level)
- plugins/{scope}/skills/*/SKILL.md

All per-skill validation (frontmatter, spec-compliant naming, metadata
stripping, etc.) is preserved.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-16 15:38:36 +02:00
Babak K. Shandiz
a1eb707e26
fix(skill publish): remove misleading validate alias
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2026-04-16 14:04:29 +01:00
Babak K. Shandiz
3dce81a0d6
docs(skill): improve help docs
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2026-04-16 14:03:54 +01:00
tommaso-moro
a6e9722ec1 fix skills names in examples 2026-04-16 10:20:24 +01:00
Kynan Ware
3e0305d941 Disable auth check for gh extension install
Allow installing extensions without being authenticated. The install
command can work with public repositories and local directories without
requiring a login, so the auth gate is unnecessary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-15 17:55:45 -06:00
Kynan Ware
75909ed2ba Suggest and install official extensions for unknown commands
When a user runs an unknown command that matches a known official
extension (e.g. `gh stack` or `gh aw`), show an install suggestion.
In interactive TTY sessions, prompt the user to install it on the spot.

The official extension registry is hard-coded in pkg/extensions/.
Current entries are github/gh-aw and github/gh-stack. Teams can add
their extensions via PR. Install suggestions use an explicit github.com
host prefix for GHES compatibility.

Refs github/cli#220

Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-15 17:50:31 -06:00
Sam Morrow
980428c304
Merge pull request #13169 from cli/sammorrowdrums/fix-skills-publish-remote-detection 2026-04-16 01:17:06 +02:00
Sam Morrow
f2d978d960
Disable auth check for local-only skill flags
Add cmdutil.DisableAuthCheckFlag for --from-local on install so that
installing from a local directory does not require authentication.
This follows the same pattern used by attestation verify for its
--bundle flag.

The --dry-run flag on publish is intentionally left with auth enabled
because dry-run validation includes remote repository checks (security
settings, tag protection, topics).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-15 23:49:28 +02:00
Sam Morrow
e04dceb3b5
fix: address review feedback on namespace changes
- Keep skillName as bare name in JSON output for backward compat;
  namespace is available as a separate --json field
- Fix Namespace field comment to cover plugin namespaces too
- Trim /SKILL.md from install path arg to match comment
- Rename acceptance test to skills-install-namespaced since it
  tests install disambiguation, not search

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-15 23:39:11 +02:00
Sam Morrow
013d531101
chore: remove unused newTestGitClient function
Remove the now-unused newTestGitClient helper that was left behind
after refactoring tests to use initGitRepo directly. This fixes the
golangci-lint 'unused' error in CI.

Co-authored-by: BagToad <47394200+BagToad@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-15 23:36:25 +02:00
Sam Morrow
92e40eabea
fix: preserve namespace in skills search deduplication
Skills with the same name but different namespaces (e.g.
skills/kynan/commit and skills/will/commit) were being collapsed
into a single search result because extractSkillName discarded the
namespace. This also caused deduplicateByName to cap results
across different namespaces as if they were the same skill.

Changes:
- Add MatchSkillPath to discovery package returning both name and
  namespace (the existing MatchesSkillPath is kept for compat)
- Add Namespace field to skillResult in search
- Fix deduplicateResults to use repo/namespace/name as the dedup key
- Fix deduplicateByName to cap by namespace-qualified name
- Update table, prompt, and JSON output to show qualified names
- Use skill path for install subprocess when namespace is present,
  ensuring unambiguous install of namespaced skills
- Add namespace to --json fields and relevance scoring/filtering
- Add unit tests for namespace dedup, qualified names, and filtering
- Add acceptance test for namespaced skill search and install

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-15 23:01:09 +02:00
Sam Morrow
1d5c74a838
fix: use target directory remotes in skills publish
When a directory argument is provided to `gh skill publish`, the remote
detection now correctly uses the target directory's git remotes instead
of the current working directory's remotes.

Previously, `detectGitHubRemote` used the factory-provided git client
which pointed to the CWD. This meant that running
`gh skill publish /path/to/repo-bar` from inside repo-foo would detect
repo-foo's remotes and potentially create the release on the wrong repo.

The fix copies the git client and sets `RepoDir` to the target directory,
matching the pattern already used by `detectMissingRepoDiagnostic` and
`checkInstalledSkillDirs`.

Co-authored-by: BagToad <47394200+BagToad@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-15 22:56:06 +02:00
Sam Morrow
a6f6ab330f
fix: enforce size cap on first preview file, surface corrupted skills, fail on path traversal
- preview: remove 'fetched > 0' guard so the 512KB size cap applies
  uniformly to all files including the first
- update: return skills with corrupted YAML frontmatter with metadataErr
  set instead of silently dropping them from scan results
- installer: fail installation when a path traversal is detected in
  remote or local skill files instead of silently skipping

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-15 16:53:27 +02:00
Sam Morrow
6c7743eaf1
fix: align relevanceScore comments with implementation and fix typo
- Update comment in relevanceScore() from '10 000 points' to '3 000 points'
  to match the actual implementation value of 3_000
- Update corresponding test comment for consistency
- Fix typo: 'swaped' → 'swapped' in formatStars comment

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-15 16:41:09 +02:00
tommaso-moro
45d0ec0b51
address review comments
Co-authored-by: Sam Morrow <info@sam-morrow.com>
2026-04-15 16:01:26 +02:00
tommaso-moro
1f5a6b8396
clean up interface and fix a few bugs
support specifying a sha in gh skills preview command
2026-04-15 15:50:53 +02:00
tommaso-moro
663df07fcf
cleanup frontmatter fields
remove git sha because we only need git tree sha

remove github-owner from frontmatter, and make github-repo support full url. Only support github.com as host, error out otherwise
2026-04-15 15:47:34 +02:00