mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
fix(init): name the agent files the first sync kept (#943)
init syncs agents quietly, and an agent file a tool already had under an agent's name was kept without a word: init said "Synced" while the tool went on loading its own file. A plain sync shows this only as a count. The quiet agent run now returns a line per tool that names the kept files and the command that replaces them, and init prints it with the skill warnings. In symlink mode what is kept is the whole agents folder, so the line says that instead. Closes #938
This commit is contained in:
@@ -264,7 +264,8 @@ func printInitDone(p *initPlan, res *initResult) {
|
||||
// firstSync replaces target copies identical to the source with links, then
|
||||
// syncs skills (and agents, if any) quietly. warnings are what a plain sync
|
||||
// would have printed under each tool, such as the entries it kept because
|
||||
// skillshare did not create them, plus the copies the trash could not take.
|
||||
// skillshare did not create them, plus the copies the trash could not take
|
||||
// and the agent files each tool kept.
|
||||
func firstSync(cfg *config.Config) (skills int, warnings []string, err error) {
|
||||
cfg.Targets = config.WithSharedSkillsTargets(cfg.Targets, cfg.Mode)
|
||||
start := time.Now()
|
||||
@@ -283,7 +284,8 @@ func firstSync(cfg *config.Config) (skills int, warnings []string, err error) {
|
||||
entries = append(entries, syncTargetEntry{name: name, target: target, mode: getTargetMode(target.SkillsConfig().Mode, cfg.Mode)})
|
||||
}
|
||||
results, failed := runParallelSyncQuiet(entries, cfg.EffectiveSkillsSource(), discovered, ssync.EffectiveFileIgnorePatterns(cfg.Ignore), false, false, "")
|
||||
if _, agentErr := syncAgentsGlobal(cfg, false, false, true, start); agentErr != nil && err == nil {
|
||||
agentStats, agentErr := syncAgentsGlobal(cfg, false, false, true, start)
|
||||
if agentErr != nil && err == nil {
|
||||
err = agentErr
|
||||
}
|
||||
spinner.Stop()
|
||||
@@ -301,6 +303,7 @@ func firstSync(cfg *config.Config) (skills int, warnings []string, err error) {
|
||||
warnings = append(warnings, w)
|
||||
}
|
||||
}
|
||||
warnings = append(warnings, agentStats.warnings...)
|
||||
return counts.Skills, warnings, err
|
||||
}
|
||||
|
||||
|
||||
@@ -98,3 +98,32 @@ func TestFirstSyncReportsLinkKeptFromAnotherTool(t *testing.T) {
|
||||
t.Fatalf("want the kept link reported, got %v", warnings)
|
||||
}
|
||||
}
|
||||
|
||||
// The first sync keeps an agent file a tool already has under an agent's
|
||||
// name. init must name it, with the command that replaces it.
|
||||
func TestFirstSyncReportsAgentFileKeptInTool(t *testing.T) {
|
||||
t.Setenv("XDG_DATA_HOME", t.TempDir())
|
||||
agents, agentsTgt := t.TempDir(), t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(agents, "helper.md"), []byte("---\nname: helper\ndescription: x\n---\nours"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(agentsTgt, "helper.md"), []byte("theirs"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := &config.Config{Source: t.TempDir(), AgentsSource: agents, Mode: "merge", Targets: map[string]config.TargetConfig{
|
||||
"claude": {Path: t.TempDir(), Agents: &config.ResourceTargetConfig{Path: agentsTgt}},
|
||||
}}
|
||||
|
||||
var warnings []string
|
||||
captureStdout(t, func() {
|
||||
var err error
|
||||
if _, warnings, err = firstSync(cfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
want := "claude: kept local agents: helper.md (sync agents --force replaces them)"
|
||||
if len(warnings) != 1 || warnings[0] != want {
|
||||
t.Fatalf("warnings = %v, want %q", warnings, want)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,20 @@ import (
|
||||
type agentSyncStats struct {
|
||||
linked, local, updated, pruned int
|
||||
failed []string // targets whose agent sync failed
|
||||
// warnings are the lines a quiet run did not print: each target's own
|
||||
// warnings, and the agent files it kept because they are not skillshare's.
|
||||
warnings []string
|
||||
}
|
||||
|
||||
// keptLocalAgentsWarning names the agent files a target kept, and the flag
|
||||
// that replaces them. Like the skills line, it lists only the first few.
|
||||
func keptLocalAgentsWarning(target string, names []string) string {
|
||||
const maxListed = 5
|
||||
msg := target + ": kept local agents: " + strings.Join(names[:min(len(names), maxListed)], ", ")
|
||||
if n := len(names) - maxListed; n > 0 {
|
||||
msg += fmt.Sprintf(" ... and %d more", n)
|
||||
}
|
||||
return msg + " (sync agents --force replaces them)"
|
||||
}
|
||||
|
||||
// syncAgentsGlobal discovers agents and syncs them to all agent-capable targets.
|
||||
@@ -302,6 +316,14 @@ func renderAgentRun(results []sync.AgentTargetResult, agentCount int, dryRun, js
|
||||
fmt.Printf(" %s %s\n", theme.Warning().Render(ui.MarkWarn), w)
|
||||
}
|
||||
}
|
||||
totals.warnings = append(totals.warnings, r.Warnings...)
|
||||
switch {
|
||||
case r.Mode == "symlink" && len(r.Skipped) > 0:
|
||||
// Symlink mode links the whole folder, so what it kept is the folder.
|
||||
totals.warnings = append(totals.warnings, r.Name+": kept the agents folder as it is (sync agents --force replaces it with a link to the source)")
|
||||
case len(r.Skipped) > 0:
|
||||
totals.warnings = append(totals.warnings, keptLocalAgentsWarning(r.Name, r.Skipped))
|
||||
}
|
||||
totals.linked += stats.linked
|
||||
totals.local += stats.local
|
||||
totals.updated += stats.updated
|
||||
|
||||
@@ -51,7 +51,7 @@ Each answer has a default, so pressing <kbd>Enter</kbd> through every question g
|
||||
|
||||
**Connect my existing repo** is for a second machine. It checks the repo first, without writing anything, and works out its layout: a repo pushed with `--git-root root` becomes the whole skillshare folder, and a repo whose skills sit in a `skills/` folder uses it as the source. Skills that exist both on this machine and in the repo use the repo version. Skills only on this machine are offered to keep, and are added to the repo on your next `skillshare push`.
|
||||
|
||||
During the first sync, a skill folder in a tool that is byte-for-byte identical to the source copy is replaced with a link. The folder is moved to the trash first, and `skillshare trash list` shows it under `replaced-by-init/<tool>/` until trash cleanup removes it (7 days). `trash restore` refuses these entries, because it restores into the source, which already holds the same skill; copy the folder back from the trash by hand if you need it. Folders that differ, and links another tool put on a skill's name, are kept and listed; run `skillshare sync --force` to replace them.
|
||||
During the first sync, a skill folder in a tool that is byte-for-byte identical to the source copy is replaced with a link. The folder is moved to the trash first, and `skillshare trash list` shows it under `replaced-by-init/<tool>/` until trash cleanup removes it (7 days). `trash restore` refuses these entries, because it restores into the source, which already holds the same skill; copy the folder back from the trash by hand if you need it. Folders that differ, and links another tool put on a skill's name, are kept and listed; run `skillshare sync --force` to replace them. An agent file a tool already has under an agent's name is kept and listed the same way; `skillshare sync agents --force` replaces it.
|
||||
|
||||
### Without a terminal
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ flowchart TD
|
||||
|
||||
**Connect my existing repo** は 2 台目のマシン向けです。何も書き込まずに先にリポジトリを確認し、構成を判断します。`--git-root root` で push したリポジトリは skillshare フォルダ全体になり、Skill が `skills/` フォルダにあるリポジトリはそのフォルダを source にします。このマシンとリポジトリの両方にある同名の Skill はリポジトリ版を使います。このマシンにしかない Skill は残すかどうかを尋ね、次の `skillshare push` でリポジトリに追加されます。
|
||||
|
||||
初回の sync では、source とバイト単位で同一のツール側 Skill フォルダはリンクに置き換えられます。フォルダは先に trash へ移され、trash のクリーンアップで削除されるまで(7 日間)`skillshare trash list` の `replaced-by-init/<tool>/` 以下に表示されます。`trash restore` は source に復元するコマンドで、source には同じ Skill がすでにあるため、これらのエントリは復元できません。必要な場合は trash のフォルダから手動でコピーしてください。内容が異なるフォルダや、他のツールが Skill と同じ名前で置いたリンクは、残して一覧表示します。`skillshare sync --force` で置き換えられます。
|
||||
初回の sync では、source とバイト単位で同一のツール側 Skill フォルダはリンクに置き換えられます。フォルダは先に trash へ移され、trash のクリーンアップで削除されるまで(7 日間)`skillshare trash list` の `replaced-by-init/<tool>/` 以下に表示されます。`trash restore` は source に復元するコマンドで、source には同じ Skill がすでにあるため、これらのエントリは復元できません。必要な場合は trash のフォルダから手動でコピーしてください。内容が異なるフォルダや、他のツールが Skill と同じ名前で置いたリンクは、残して一覧表示します。`skillshare sync --force` で置き換えられます。ツール側に Agent と同じ名前のファイルがすでにある場合も、同じように残して一覧表示します。`skillshare sync agents --force` で置き換えられます。
|
||||
|
||||
### ターミナルがない場合
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ flowchart TD
|
||||
|
||||
**Connect my existing repo**는 두 번째 머신용입니다. 아무것도 쓰지 않고 먼저 저장소를 확인해 구조를 판단합니다. `--git-root root`로 push한 저장소는 skillshare 폴더 전체가 되고, skill이 `skills/` 폴더에 있는 저장소는 그 폴더를 source로 사용합니다. 이 머신과 저장소 양쪽에 있는 같은 이름의 skill은 저장소 버전을 사용합니다. 이 머신에만 있는 skill은 유지할지 묻고, 다음 `skillshare push` 때 저장소에 추가됩니다.
|
||||
|
||||
첫 sync에서 source와 바이트 단위로 같은 도구 쪽 skill 폴더는 링크로 바뀝니다. 폴더는 먼저 trash로 옮겨지며, trash 정리로 삭제될 때까지(7일) `skillshare trash list`의 `replaced-by-init/<tool>/` 아래에 표시됩니다. `trash restore`는 source로 복원하는데 source에는 같은 skill이 이미 있으므로, 이 항목은 복원할 수 없습니다. 필요하면 trash 폴더에서 직접 복사하세요. 내용이 다른 폴더와 다른 도구가 skill과 같은 이름으로 둔 링크는 유지하고 목록으로 보여 주며, `skillshare sync --force`로 바꿀 수 있습니다.
|
||||
첫 sync에서 source와 바이트 단위로 같은 도구 쪽 skill 폴더는 링크로 바뀝니다. 폴더는 먼저 trash로 옮겨지며, trash 정리로 삭제될 때까지(7일) `skillshare trash list`의 `replaced-by-init/<tool>/` 아래에 표시됩니다. `trash restore`는 source로 복원하는데 source에는 같은 skill이 이미 있으므로, 이 항목은 복원할 수 없습니다. 필요하면 trash 폴더에서 직접 복사하세요. 내용이 다른 폴더와 다른 도구가 skill과 같은 이름으로 둔 링크는 유지하고 목록으로 보여 주며, `skillshare sync --force`로 바꿀 수 있습니다. 도구에 agent와 같은 이름의 파일이 이미 있으면 같은 방식으로 유지하고 목록으로 보여 주며, `skillshare sync agents --force`로 바꿀 수 있습니다.
|
||||
|
||||
### 터미널이 없을 때
|
||||
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ flowchart TD
|
||||
|
||||
**Connect my existing repo** 用于第二台机器。它会先检查 repo(不写入任何东西)并判断结构:用 `--git-root root` 推送的 repo 会成为整个 skillshare 文件夹;skills 放在 `skills/` 文件夹的 repo 会以该文件夹作为 source。这台机器和 repo 都有的同名 skill 使用 repo 版本。只存在于这台机器的 skills 会询问是否保留,并在下次 `skillshare push` 时加入 repo。
|
||||
|
||||
第一次 sync 时,工具中与 source 逐字节相同的 skill 文件夹会替换为链接。文件夹会先移到 trash,在 trash 清理将其删除之前(7 天),`skillshare trash list` 会把它列在 `replaced-by-init/<tool>/` 之下。`trash restore` 会恢复到 source,而 source 中已有相同的 skill,所以它拒绝恢复这些条目;需要时请从 trash 文件夹手动复制回去。内容不同的文件夹,以及其他工具以同名放置的链接,会保留并列出;运行 `skillshare sync --force` 可以替换它们。
|
||||
第一次 sync 时,工具中与 source 逐字节相同的 skill 文件夹会替换为链接。文件夹会先移到 trash,在 trash 清理将其删除之前(7 天),`skillshare trash list` 会把它列在 `replaced-by-init/<tool>/` 之下。`trash restore` 会恢复到 source,而 source 中已有相同的 skill,所以它拒绝恢复这些条目;需要时请从 trash 文件夹手动复制回去。内容不同的文件夹,以及其他工具以同名放置的链接,会保留并列出;运行 `skillshare sync --force` 可以替换它们。工具里已有与 agent 同名的文件时,也会同样保留并列出;运行 `skillshare sync agents --force` 可以替换它。
|
||||
|
||||
### 没有终端时
|
||||
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ flowchart TD
|
||||
|
||||
**Connect my existing repo** 用於第二台機器。它會先檢查 repo(不寫入任何東西)並判斷結構:用 `--git-root root` 推上去的 repo 會成為整個 skillshare 資料夾;skills 放在 `skills/` 資料夾的 repo 會以該資料夾作為 source。這台機器和 repo 都有的同名 skill 使用 repo 版本。只存在於這台機器的 skills 會詢問是否保留,並在下次 `skillshare push` 時加入 repo。
|
||||
|
||||
第一次 sync 時,工具裡與 source 逐位元組相同的 skill 資料夾會換成連結。資料夾會先移到 trash,在 trash 清理把它刪除之前(7 天),`skillshare trash list` 會把它列在 `replaced-by-init/<tool>/` 之下。`trash restore` 會還原到 source,而 source 已經有相同的 skill,所以它拒絕還原這些項目;需要時請從 trash 資料夾手動複製回去。內容不同的資料夾,以及其他工具以同名放置的連結,會保留並列出;執行 `skillshare sync --force` 可以把它們換掉。
|
||||
第一次 sync 時,工具裡與 source 逐位元組相同的 skill 資料夾會換成連結。資料夾會先移到 trash,在 trash 清理把它刪除之前(7 天),`skillshare trash list` 會把它列在 `replaced-by-init/<tool>/` 之下。`trash restore` 會還原到 source,而 source 已經有相同的 skill,所以它拒絕還原這些項目;需要時請從 trash 資料夾手動複製回去。內容不同的資料夾,以及其他工具以同名放置的連結,會保留並列出;執行 `skillshare sync --force` 可以把它們換掉。工具裡已有與 agent 同名的檔案時,也會同樣保留並列出;執行 `skillshare sync agents --force` 可以把它換掉。
|
||||
|
||||
### 沒有終端機時
|
||||
|
||||
|
||||
Reference in New Issue
Block a user