fix(install): report why an install failed in --json output (#831)

install --json printed empty skills and failed lists with exit code 1
when the whole install failed, for example when the security audit
blocked a tracked repository or a single skill. Scripts and the herdr
mod could see that it failed but not why, and the mod already reads an
error field that was never set.

The install JSON now carries the command error in an omitempty error
field, in global and project mode. The install docs also stop saying
--json implies --force: it only permits overwriting, and the audit gate
still applies unless --force is given.
This commit is contained in:
Willie
2026-11-10 17:24:23 +08:00
committed by GitHub
parent 5da2b49bfb
commit 176a236249
8 changed files with 116 additions and 6 deletions
+4
View File
@@ -32,6 +32,7 @@ type installJSONOutput struct {
Skills []string `json:"skills"`
Failed []string `json:"failed"`
Duration string `json:"duration"`
Error string `json:"error,omitempty"`
}
type installLogSummary struct {
@@ -550,6 +551,9 @@ func installOutputJSON(summary installLogSummary, start time.Time, installErr er
Failed: summary.FailedSkills,
Duration: formatDuration(start),
}
if installErr != nil {
output.Error = installErr.Error()
}
return writeJSONResult(&output, installErr)
}
+1 -1
View File
@@ -131,7 +131,7 @@ or `--kind agent` to choose which resource to manage.
| `--exclude <name>` | Skip specific skills during multi-skill install (repeatable) |
| `--skip-audit` | Skip security audit for this install |
| `--audit-threshold <t>` / `--threshold <t>` / `-T <t>` | Override block threshold for this run (`critical\|high\|medium\|low\|info`; shorthand: `c\|h\|m\|l\|i`, plus `crit`, `med`) |
| `--json` | Noninteractive JSON; permits overwrite and selects all when no skill/agent filter is given; retains audit blocking |
| `--json` | Noninteractive JSON; permits overwrite and selects all when no skill/agent filter is given; retains audit blocking; a whole install that fails or is blocked exits non-zero with an `error` field, while blocked skills from a multi-skill source go to `failed` |
| `--dry-run, -n` | Preview |
**Fuzzy subdirectory resolution:** When a monorepo has nested skill directories, you can specify just the skill name — e.g., `user/repo/vue-best-practices` finds `skills/vue-best-practices/` automatically. Fails with an error if multiple matches exist.
@@ -6,6 +6,7 @@ import (
"encoding/binary"
"os"
"path/filepath"
"strings"
"testing"
"skillshare/internal/testutil"
@@ -72,6 +73,41 @@ func TestInstall_Track_BlocksCritical(t *testing.T) {
}
}
func TestInstall_JSONReportsAuditBlock(t *testing.T) {
for _, tc := range []struct {
name string
project bool
args []string
}{
{name: "global tracked", args: []string{"--track", "--name", "evil-repo"}},
{name: "global plain"},
{name: "project tracked", project: true, args: []string{"--track", "--name", "evil-repo"}},
{name: "project plain", project: true},
} {
t.Run(tc.name, func(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
setupGlobalConfig(sb)
repoURL := setupBareRepoWithCriticalContent(t, sb, "json-critical")
args := append([]string{"install", repoURL, "--json"}, tc.args...)
var result *testutil.Result
if tc.project {
result = sb.RunCLIInDir(sb.SetupProjectDir("claude"), append(args, "-p")...)
} else {
result = sb.RunCLI(args...)
}
result.AssertFailure(t)
assertPureJSON(t, strings.TrimSpace(result.Stdout))
msg, _ := parseJSON(t, result.Stdout)["error"].(string)
if !strings.Contains(msg, "blocked by security audit") {
t.Errorf("expected error field to report the audit block, got: %s", result.Stdout)
}
})
}
}
func TestInstall_Track_SkipAudit(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
+15 -1
View File
@@ -305,7 +305,7 @@ See [Project Setup](/docs/how-to/sharing/project-setup) for the full guide.
| `--project` | `-p` | Install into project `.skillshare/skills/` |
| `--global` | `-g` | Install into global `~/.config/skillshare/skills/` |
| `--dry-run` | `-n` | Preview only |
| `--json` | | Output as JSON (implies `--force`; also implies non-interactive selection when no `--skill`/`--agent` filter is given) |
| `--json` | | Output as JSON (permits overwriting existing skills like `--force`, but audit blocking still applies; also implies non-interactive selection when no `--skill`/`--agent` filter is given) |
## JSON Output
@@ -359,6 +359,20 @@ skillshare install github.com/user/agents --kind agent --json
}
```
When the install fails as a whole, for example when the security audit blocks a tracked repository or a single skill, the command exits non-zero and the `error` field says why. When a source has several skills, the ones that are blocked or fail are listed in `failed` instead, and the command still exits 0. Add `--force` to install despite audit findings.
```json
{
"source": "github.com/user/evil-skills",
"tracked": true,
"dry_run": false,
"skills": [],
"failed": [],
"duration": "0.412s",
"error": "blocked by security audit (use --force to override)"
}
```
## Duplicate Detection
skillshare automatically detects when you're about to install something that already exists:
@@ -299,7 +299,7 @@ skillshare sync
| `--project` | `-p` | プロジェクトの `.skillshare/skills/` へインストール |
| `--global` | `-g` | グローバルの `~/.config/skillshare/skills/` へインストール |
| `--dry-run` | `-n` | プレビューのみ |
| `--json` | | JSON として出力(`--force` を暗黙的に有効化。`--skill`/`--agent` フィルタが指定されない場合、非インタラクティブ選択も暗黙的に有効化) |
| `--json` | | JSON として出力(`--force` と同様に既存の skill を上書きできるが、監査によるブロックは引き続き適用。`--skill`/`--agent` フィルタが指定されない場合、非インタラクティブ選択も暗黙的に有効化) |
## JSON 出力
@@ -353,6 +353,20 @@ skillshare install github.com/user/agents --kind agent --json
}
```
tracked リポジトリや単一の skill がセキュリティ監査にブロックされた場合など、インストール全体が失敗すると、コマンドは 0 以外で終了し、`error` フィールドに理由が入ります。複数の skill を含むソースでは、ブロックまたは失敗した skill は `failed` に記録され、コマンドは 0 で終了します。監査の検出結果があってもインストールするには `--force` を付けます。
```json
{
"source": "github.com/user/evil-skills",
"tracked": true,
"dry_run": false,
"skills": [],
"failed": [],
"duration": "0.412s",
"error": "blocked by security audit (use --force to override)"
}
```
## 重複検出
skillshare は、すでに存在するものをインストールしようとしていることを自動的に検出します。
@@ -299,7 +299,7 @@ skillshare sync
| `--project` | `-p` | 프로젝트 `.skillshare/skills/`에 설치 |
| `--global` | `-g` | global `~/.config/skillshare/skills/`에 설치 |
| `--dry-run` | `-n` | 미리보기만 |
| `--json` | | JSON으로 출력 (`--force`를 암시함; `--skill`/`--agent` 필터가 없을 때는 비인터랙티브 선택도 암시함) |
| `--json` | | JSON으로 출력 (`--force`처럼 기존 skill 덮어쓰기를 허용하지만 보안 감사 차단은 그대로 적용됨; `--skill`/`--agent` 필터가 없을 때는 비인터랙티브 선택도 암시함) |
## JSON 출력
@@ -353,6 +353,20 @@ skillshare install github.com/user/agents --kind agent --json
}
```
tracked 저장소나 단일 skill이 보안 감사에 차단되는 등 설치 전체가 실패하면 명령은 0이 아닌 코드로 종료되고 `error` 필드에 이유가 담깁니다. 여러 skill이 있는 소스에서는 차단되거나 실패한 skill이 `failed`에 기록되고 명령은 0으로 종료됩니다. 감사 결과가 있어도 설치하려면 `--force`를 추가하세요.
```json
{
"source": "github.com/user/evil-skills",
"tracked": true,
"dry_run": false,
"skills": [],
"failed": [],
"duration": "0.412s",
"error": "blocked by security audit (use --force to override)"
}
```
## 중복 감지
skillshare는 이미 존재하는 것을 다시 설치하려는 시점을 자동으로 감지합니다.
@@ -299,7 +299,7 @@ skillshare sync
| `--project` | `-p` | 安装到 project 的 `.skillshare/skills/` |
| `--global` | `-g` | 安装到 global 的 `~/.config/skillshare/skills/` |
| `--dry-run` | `-n` | 仅预览 |
| `--json` | | 以 JSON 输出(隐含 `--force`;未指定 `--skill`/`--agent` 过滤条件时也隐含非交互式选择) |
| `--json` | | 以 JSON 输出(与 `--force` 一样允许覆盖已有 skill,但安全审计拦截仍然生效;未指定 `--skill`/`--agent` 过滤条件时也隐含非交互式选择) |
## JSON 输出
@@ -353,6 +353,20 @@ skillshare install github.com/user/agents --kind agent --json
}
```
整个安装失败时,例如 tracked 仓库或单个 skill 被安全审计拦截,命令以非零状态退出,`error` 字段说明原因。来源包含多个 skill 时,被拦截或失败的 skill 会列在 `failed` 中,命令仍以 0 退出。要在有审计发现的情况下仍然安装,请加上 `--force`。
```json
{
"source": "github.com/user/evil-skills",
"tracked": true,
"dry_run": false,
"skills": [],
"failed": [],
"duration": "0.412s",
"error": "blocked by security audit (use --force to override)"
}
```
## 重复检测
skillshare 会自动检测你是否正在安装某个已经存在的内容:
@@ -299,7 +299,7 @@ skillshare sync
| `--project` | `-p` | 安裝到專案的 `.skillshare/skills/` |
| `--global` | `-g` | 安裝到全域的 `~/.config/skillshare/skills/` |
| `--dry-run` | `-n` | 只預覽 |
| `--json` | | 以 JSON 輸出(隱含 `--force`;若未指定 `--skill`/`--agent` 篩選,也隱含非互動式選擇) |
| `--json` | | 以 JSON 輸出(和 `--force` 一樣允許覆寫既有 skill,但安全稽核的阻擋仍然有效;若未指定 `--skill`/`--agent` 篩選,也隱含非互動式選擇) |
## JSON 輸出
@@ -353,6 +353,20 @@ skillshare install github.com/user/agents --kind agent --json
}
```
整個安裝失敗時,例如 tracked repo 或單一 skill 被安全稽核擋下,指令會以非零狀態結束,`error` 欄位說明原因。來源有多個 skill 時,被擋下或失敗的 skill 會列在 `failed`,指令仍以 0 結束。若要在有稽核發現時仍然安裝,請加上 `--force`。
```json
{
"source": "github.com/user/evil-skills",
"tracked": true,
"dry_run": false,
"skills": [],
"failed": [],
"duration": "0.412s",
"error": "blocked by security audit (use --force to override)"
}
```
## 重複偵測
skillshare 會自動偵測你即將安裝的東西是否已經存在: