diff --git a/.agents/skillctrl/lock.json b/.agents/skillctrl/lock.json index de12772..7328f69 100644 --- a/.agents/skillctrl/lock.json +++ b/.agents/skillctrl/lock.json @@ -1,6 +1,6 @@ { "acceptedHashes": { - "skillctrl": "7c4e07ebe7af33683bce91e381fcfb494e86bdbb" + "skillctrl": "4053fa0c4f206733210723bf5fa31d85adcf1c5d" }, "upstreams": { "skillctrl": { diff --git a/.agents/skills/skillctrl/SKILL.md b/.agents/skills/skillctrl/SKILL.md index 477912c..8f39d8d 100644 --- a/.agents/skills/skillctrl/SKILL.md +++ b/.agents/skills/skillctrl/SKILL.md @@ -97,11 +97,12 @@ Important behavior: - `update` without names refreshes all registered skills; use it only when the requested scope is all skills. An unchanged upstream original is skipped. - A changed single-input original is three-way merged into the local skill, - using the previous original stored in `.agents/skillctrl/originals//`. + using the registered tree hash to recover the previous original from repository + Git objects or upstream history, for every adapter without a recorded commit. Local edits survive unless the upstream changed the same lines. Each changed skill appears in the JSON `updates` with `merged`, `conflicted` (resolve the reported diff3 regions), or `replaced` (no previous original was available: - re-adapt from the intent once). Commit the stored original with the skill; + re-adapt from the intent once). Legacy base snapshots are ignored; `record` refuses content that still has conflict markers. - `remove` deletes the skill, its saved intent document, and registrations. - `--dry-run` checks basic arguments and reports command metadata without making diff --git a/.agents/skills/skillctrl/evals/evals.json b/.agents/skills/skillctrl/evals/evals.json index 24bc89d..9dded27 100644 --- a/.agents/skills/skillctrl/evals/evals.json +++ b/.agents/skills/skillctrl/evals/evals.json @@ -15,7 +15,7 @@ }, { "id": 2, - "prompt": "I ran skillctrl update browser from /tmp/project. It succeeded and reported {\"repo\":\"/tmp/project\",\"skills\":[\"browser\"],\"updates\":[{\"name\":\"browser\",\"path\":\".agents/skills/browser\",\"layout\":\"single\",\"status\":\"conflicted\",\"base\":\"snapshot\",\"original\":\".agents/skillctrl/originals/browser\",\"conflicts\":[{\"path\":\"SKILL.md\",\"kind\":\"content\",\"lines\":[[12,20]]}]}]}. check reports local.lock_changed=true. What should I inspect and do next? This is a read-only planning exercise; do not execute commands or change files.", + "prompt": "I ran skillctrl update browser from /tmp/project. It succeeded and reported {\"repo\":\"/tmp/project\",\"skills\":[\"browser\"],\"updates\":[{\"name\":\"browser\",\"path\":\".agents/skills/browser\",\"layout\":\"single\",\"status\":\"conflicted\",\"base\":\"upstream-history\",\"conflicts\":[{\"path\":\"SKILL.md\",\"kind\":\"content\",\"lines\":[[12,20]]}]}]}. check reports local.lock_changed=true. What should I inspect and do next? This is a read-only planning exercise; do not execute commands or change files.", "expected_output": "Starts from the update report, the skill diff and the saved intent in the selected repository, resolves the reported conflict by direct verified editing, and uses record only after the content meets the intent.", "files": [], "expectations": [ diff --git a/.agents/skills/skillctrl/references/ci.md b/.agents/skills/skillctrl/references/ci.md index 7e8c64a..f65d2d6 100644 --- a/.agents/skills/skillctrl/references/ci.md +++ b/.agents/skills/skillctrl/references/ci.md @@ -111,12 +111,14 @@ give it the whole patch of every skill: | `status` | Give the agent | Agent task | | --- | --- | --- | | `merged` | Intent and `git diff -- ` | Check the applied upstream change against the intent; edit only where it violates the intent | -| `conflicted` | Intent, `conflicts`, and `git diff -- ` | Resolve each reported region following the intent; for binary or deleted-file conflicts, compare with the new original under `original` | -| `replaced` | Intent and the whole skill directory | No previous original was available: adapt the new original from the intent once; later updates merge | +| `conflicted` | Intent, `conflicts`, and `git diff -- ` | Resolve each reported region following the intent; for binary or deleted-file conflicts, inspect the new original at the registered upstream source and skill path | +| `replaced` | Intent and the whole skill directory | Base recovery failed (see `reason`): inspect lost local-only files and adapt the replacement; later updates can merge if the tree remains reachable | | `refreshed` | Integration intent, root `SKILL.md`, and `git diff` of each changed input path | Check that routing still fits the refreshed originals | -`path` is the skill directory and `original` its stored new original; the diff -of `original` is the pure upstream difference when the merged diff is unclear. +`path` is the skill directory; `changes` lists upstream file changes. Base trees +come from repository objects, upstream history, or a recorded Git source commit. +History recovery works with every adapter and needs no recorded commit. +Updates require upstream access; PR `check` remains offline. Read beyond the diff only when needed: follow resources from changed text, and check whole-skill intent requirements with a search over the skill. Before recording, confirm that no conflict markers remain, for example with @@ -126,8 +128,7 @@ intent-free skills. Run the hash gate and repository checks before publication. If adaptation is unresolved, report the problem and leave it unaccepted. When there are verified changes, open a draft PR containing the skill changes, -stored originals under `.agents/skillctrl/originals/`, registrations, accepted -hashes, and evidence. When there are no changes, finish without creating a PR. +registrations, accepted hashes, and evidence. When there are no changes, finish without creating a PR. The PR uses the ordinary PR check above; a new upstream release alone never makes an unrelated PR fail. diff --git a/README.md b/README.md index a6cbecb..6463feb 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ skillctrl lets you install agent skills and customize them for your project. Shorten instructions, add your own checks, or combine skills into one workflow. -It keeps upstream originals and the intent behind your edits so your existing +It tracks upstream originals and the intent behind your edits so your existing agent can preserve those customizations when adapting upstream updates. https://github.com/user-attachments/assets/48394b56-6be3-47a5-b21a-4e3b3c851d72 diff --git a/docs/adr/2026-10-15-three-way-update.md b/docs/adr/2026-10-15-three-way-update.md index bd8ce09..606bcac 100644 --- a/docs/adr/2026-10-15-three-way-update.md +++ b/docs/adr/2026-10-15-three-way-update.md @@ -1,5 +1,8 @@ # Merge upstream changes into adapted skills with a stored base +Status: superseded for base storage and resolution by [2026-10-23: Recover three-way bases from upstream tree history](2026-10-23-base-from-upstream-tree.md). The snapshot procedures below are historical, not current instructions. + + - Status: Accepted - Date: 2026-10-15 diff --git a/docs/adr/2026-10-23-base-from-upstream-tree.md b/docs/adr/2026-10-23-base-from-upstream-tree.md new file mode 100644 index 0000000..5fd8ab1 --- /dev/null +++ b/docs/adr/2026-10-23-base-from-upstream-tree.md @@ -0,0 +1,96 @@ +# Recover three-way bases from upstream tree history + +Status: accepted. Supersedes [2026-10-15: Three-way update](2026-10-15-three-way-update.md) +for base storage and resolution. File reconciliation and merged-reference behavior +remain unchanged. + +## Context + +Native skills and gh registrations record an original skill tree hash but no +source commit. A missing local base previously forced replacement even when the +registered tree was reachable in upstream history. Replacement deletes local-only +files, including tests. Keeping a second complete original in the consumer +repository also duplicates content and enlarges checkouts and review diffs. + +The earlier ADR considered fetching a recorded commit, but did not consider +looking up the recorded tree directly after fetching upstream history. + +## Decision + +Resolve the previous original only for a changed single-input update, in order: + +1. Read the registered `skillFolderHash` from the consumer's Git objects. +2. Fetch upstream history into disposable bare storage with `--filter=blob:none`, + then read that tree identifier directly. This works with skills, gh, and git + acquisition adapters and does not require a recorded commit or skill path. +3. Retain the direct Git adapter's recorded source commit fetch as a last resort, + including its commit/path identity check. + +Verify recovered files against the registered tree hash before reconciliation. +Use the existing source validator: `sourceUrl`, when present, must identify the +same GitHub repository as `source`; otherwise derive the URL from `source`. +Do not broaden supported protocols, execute upstream scripts, or change the +chosen acquisition adapter. A missing tree/hash retains the reasoned `replaced` +fallback, which can delete +local-only files and requires review before acceptance. Fetch failures, invalid +source URLs, unreadable trees, or verification errors abort preparation if the +recorded-commit fallback cannot recover a verified base. A transient failure must +not cause destructive replacement. + +Fetch all advertised branch and tag histories without a depth limit. A default +branch fetch can miss a tree retained on another branch or release tag; shallow +fetches can miss arbitrarily old imports. Private pull-request refs and unreachable +objects are outside the search. Fetch commits and trees first; a promisor remote +loads blobs only for the requested tree. Missing blob IDs are prefetched in one +batch per tree to avoid a separate network round trip for each file. Servers that ignore filtering can send +all blobs; correctness is preserved but transfer savings are not guaranteed. +Share one history fetch per validated source within preparation, and discard it +afterward. Do not add persistent caches, private refs, or history to consumer +repositories. The fresh bare repository has no inherited shallow boundary; +existing shallow acquisition clones are not reused for this step. + +Do not create, refresh, read, or automatically delete +`.agents/skillctrl/originals/`. Existing copies are ignored and left byte-for-byte +untouched, even by remove or merge. Keep the legacy discovery exclusion so stale +manifests cannot become skills. After upgrading all callers, users can inspect +and manually remove the directory (`git rm -r -- .agents/skillctrl/originals` +for tracked copies). Automatic deletion would discard pending edits and would +make a routine update perform an unrelated repository cleanup. Removing files +from the current tree does not shrink existing Git history. + +Merged routing skills keep their registered originals under `references/`, +including the existing numeric-layout compatibility. They are part of the skill's +content, not single-input merge bases. + +JSON keeps the existing statuses and adds `base: upstream-history`; `repository` +and `upstream` continue to identify local objects and recorded-commit recovery. +The obsolete snapshot `original` path is omitted. `changes` reports upstream file +changes; conflict reports retain paths and line ranges. To resolve binary or +deletion conflicts, inspect the new original at the registered upstream source +and skill path rather than a stored local duplicate. + +## Tradeoffs and alternatives + +- Each changed source whose base is absent locally needs a full history fetch on + each update invocation. This costs network time and commit/tree bandwidth, + but removes duplicated originals and persistent cache lifecycle concerns. + Unchanged originals do not trigger base fetches. Explicit update already needs + upstream access; `check`, record, remove, and dry runs stay offline. +- Keeping snapshots would improve offline base availability, but preserves the + repository growth and double management the user chose to remove. No snapshot + compatibility fallback is retained. +- Fetching a tree hash directly is smaller but servers need not allow arbitrary + tree wants. Fetching advertised history provides a portable reachability path. +- A rewritten upstream can remove the only base. The recorded-commit fallback + may still recover it; otherwise replacement reports why. A network or + verification error aborts preparation if commit recovery also fails, preserving + the installed skills rather than replacing them. +- Fetching only one branch or a bounded depth is faster but silently loses valid + bases. No such optimization is included without a separate decision and tests. + +## Verification + +CLI tests use local Git fixture repositories through URL rewriting, without +network access. They cover commit-free skills/gh registrations, history recovery, +local-object priority, unavailable trees and rewritten history, ignored legacy +copies, local-only files, conflicts, and unchanged merged routing behavior. diff --git a/docs/adr/README.md b/docs/adr/README.md index 180ff2a..a55195e 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -25,3 +25,4 @@ one decision or milestone; filenames are `-.md`. | 2026-10-05 | [Consolidate upstream tracking and accepted hashes in one private lock](2026-10-05-unified-private-lock.md) | | 2026-10-06 | [Ship v0.3.1 and announce it publicly](2026-10-06-v0-3-1-release.md) | | 2026-10-15 | [Merge upstream changes into adapted skills with a stored base](2026-10-15-three-way-update.md) | +| 2026-10-23 | [Recover three-way bases from upstream tree history](2026-10-23-base-from-upstream-tree.md) | diff --git a/docs/ja/skills/skillctrl/SKILL.md b/docs/ja/skills/skillctrl/SKILL.md index f4af679..025ab5f 100644 --- a/docs/ja/skills/skillctrl/SKILL.md +++ b/docs/ja/skills/skillctrl/SKILL.md @@ -102,11 +102,12 @@ native 形式の root `skills-lock.json` と、`.agents/skillctrl/lock.json` に - 名前なしの `update` は登録済み skill をすべて更新する。 全 skill が依頼の対象である場合だけ使う。上流の原本が変わっていなければ更新を省略する。 -- 単一の原本が変わると、`.agents/skillctrl/originals//` に保存した前回の原本を base に、 +- 単一の原本が変わると、登録済み tree hash で repo の Git object または upstream の履歴から + 復元した前回の原本を base に、 手元の skill へ 3-way merge する。upstream が同じ行を変えない限りローカルの編集は残る。 変わった skill は JSON の `updates` に `merged`、`conflicted`(報告された diff3 の箇所を解消する)、 `replaced`(前回の原本がなかったため、intent に沿って一度だけ調整し直す)のいずれかで現れる。 - 保存した原本は skill と一緒に commit する。`record` は衝突マーカーが残った skill ディレクトリを拒否する。 + adapter や commit の記録の有無には依存しない。旧 base snapshot は参照しない。`record` は衝突マーカーが残った skill ディレクトリを拒否する。 - `remove` は skill、対応する intent ファイル、登録を削除する。 - `--dry-run` は基本的な引数を確認し、変更せずに操作の概要を表示する。 取得元の fetch・内容の確認、指定 skill が上流にあるかの確認、未コミットの編集との diff --git a/docs/ja/skills/skillctrl/evals/evals.json b/docs/ja/skills/skillctrl/evals/evals.json index 717957c..57800e7 100644 --- a/docs/ja/skills/skillctrl/evals/evals.json +++ b/docs/ja/skills/skillctrl/evals/evals.json @@ -15,7 +15,7 @@ }, { "id": 2, - "prompt": "/tmp/project で skillctrl update browser を実行しました。成功し、{\"repo\":\"/tmp/project\",\"skills\":[\"browser\"],\"updates\":[{\"name\":\"browser\",\"path\":\".agents/skills/browser\",\"layout\":\"single\",\"status\":\"conflicted\",\"base\":\"snapshot\",\"original\":\".agents/skillctrl/originals/browser\",\"conflicts\":[{\"path\":\"SKILL.md\",\"kind\":\"content\",\"lines\":[[12,20]]}]}]} と報告されました。check は local.lock_changed=true を報告しています。次に何を確認し、何をすべきですか。これは読み取り専用の計画を立てる課題なので、コマンドを実行したりファイルを変更したりしないでください。", + "prompt": "/tmp/project で skillctrl update browser を実行しました。成功し、{\"repo\":\"/tmp/project\",\"skills\":[\"browser\"],\"updates\":[{\"name\":\"browser\",\"path\":\".agents/skills/browser\",\"layout\":\"single\",\"status\":\"conflicted\",\"base\":\"upstream-history\",\"conflicts\":[{\"path\":\"SKILL.md\",\"kind\":\"content\",\"lines\":[[12,20]]}]}]} と報告されました。check は local.lock_changed=true を報告しています。次に何を確認し、何をすべきですか。これは読み取り専用の計画を立てる課題なので、コマンドを実行したりファイルを変更したりしないでください。", "expected_output": "選んだリポジトリで update の報告・skill の差分・保存した intent から確認を始め、報告された衝突を直接編集して解消・検証する。内容が intent を満たしてから record を使う。", "files": [], "expectations": [ diff --git a/docs/ja/skills/skillctrl/references/ci.md b/docs/ja/skills/skillctrl/references/ci.md index d187115..01fbbe5 100644 --- a/docs/ja/skills/skillctrl/references/ci.md +++ b/docs/ja/skills/skillctrl/references/ci.md @@ -104,12 +104,14 @@ jq -e '.updates | type == "array"' skillctrl-update.json | `status` | agent に渡すもの | agent の作業 | | --- | --- | --- | | `merged` | intent と `git diff -- ` | 適用された upstream の変更を intent と照合し、intent に反する箇所だけ編集する | -| `conflicted` | intent・`conflicts`・`git diff -- ` | 報告された箇所を intent に沿って解消する。バイナリや削除の衝突は `original` の新しい原本と比べる | -| `replaced` | intent と skill のディレクトリ全体 | 旧原本がなかったため、新しい原本を intent に沿って一度だけ調整する。次回以降は merge される | +| `conflicted` | intent・`conflicts`・`git diff -- ` | 報告された箇所を intent に沿って解消する。バイナリや削除の衝突では、登録済み upstream の source と skill path で新しい原本を確認する | +| `replaced` | intent と skill のディレクトリ全体 | `reason` で復元失敗を確認し、消えたローカル専用ファイルと置き換え後の内容を見直す。tree が到達可能なら次回以降は merge できる | | `refreshed` | 統合の intent・ルートの `SKILL.md`・変わった入力パスの `git diff` | 更新された原本に routing が合っているか確認する | -`path` は skill のディレクトリ、`original` は保存した新しい原本である。merge 後の差分が -分かりにくいときは、`original` の差分で upstream だけの変更を確認できる。差分以外は +`path` は skill のディレクトリ、`changes` は upstream のファイル変更を示す。 +base は repo の Git object、upstream 履歴、記録済み Git source commit から探す。 +履歴からの復元は全 adapter に対応し、commit の記録は不要である。 +update はネットワークを必要とするが、PR の `check` はオフラインのままである。差分以外は 必要なときだけ読む。変更箇所が参照する resource をたどり、skill 全体に関わる intent の要件は skill 内の検索で確認する。record の前に、 `git grep -n -e '^<<<<<<< local' -- .agents/skills/chosen-skill` などで衝突マーカーが @@ -117,8 +119,7 @@ skill 内の検索で確認する。record の前に、 intent がない skill は記録しない。公開前に hash の判定と repo のチェックを実行し、 調整が未解決なら問題を報告して受理しない。 -確認済みの変更があれば、skill の変更・`.agents/skillctrl/originals/` に保存した原本・ -登録・受理済み hash・根拠を含む draft PR を作る。 +確認済みの変更があれば、skill の変更・登録・受理済み hash・根拠を含む draft PR を作る。 変更がなければ PR を作らず終了する。その PR は通常の変更チェックを通す。 upstream の新しい release だけを理由に、無関係な PR を失敗にしない。 diff --git a/docs/ja/usage.md b/docs/ja/usage.md index bcf70dd..15688fe 100644 --- a/docs/ja/usage.md +++ b/docs/ja/usage.md @@ -151,25 +151,22 @@ jq '.updates' update.json git diff -- .agents/skills/chosen-skill # Resolve conflicts and check the upstream change against the saved intent skillctrl record chosen-skill -git diff -- .agents/skills/chosen-skill .agents/skillctrl/originals/chosen-skill .agents/skillctrl/lock.json +git diff -- .agents/skills/chosen-skill .agents/skillctrl/lock.json ``` -単体 skill の原本が変わると、update は新しい原本を現在の skill へファイル単位で -3-way merge します。base は前回取り込んだ原本で、`.agents/skillctrl/originals/chosen-skill/` -に未編集の snapshot として残ります。snapshot は `add` が作り、以後の update が更新します。 -upstream が変えていないファイルは手元の内容をそのまま残すため、upstream が同じ行を -変えない限りローカル調整は消えません。merge は upstream の変更だけを適用するので、 -`git diff -- .agents/skills/chosen-skill` に現れるのは upstream の変更(と衝突マーカー) -であり、失われた調整ではありません。旧原本と新原本だけの差分は -`git diff -- .agents/skillctrl/originals/chosen-skill` で確認できます。snapshot は skill と一緒に commit します。 +単体 skill の原本が変わると、update は現在の skill へファイル単位で 3-way merge します。 +base は登録済みの `skillFolderHash` で Git object または upstream の履歴から復元します。 +upstream が変えていないファイルとローカル専用ファイルは、手元の内容と実行権限を保持します。 +同じ箇所のテキスト編集は diff3 マーカーで示します。 +`git diff -- .agents/skills/chosen-skill` で適用した変更と衝突を確認し、 +`updates[].changes` で upstream のファイル変更を確認します。 update は、変更のあった skill ごとの結果を `updates` に出力します。 ```json {"repo": "/path/to/repo", "skills": ["chosen-skill"], "updates": [{ "name": "chosen-skill", "path": ".agents/skills/chosen-skill", "layout": "single", - "status": "conflicted", "base": "snapshot", - "original": ".agents/skillctrl/originals/chosen-skill", + "status": "conflicted", "base": "upstream-history", "changes": [{"path": "SKILL.md", "upstream": "modified", "result": "conflict"}, {"path": "references/new.md", "upstream": "added", "result": "applied"}], "conflicts": [{"path": "SKILL.md", "kind": "content", "lines": [[12, 20]]}] @@ -179,18 +176,25 @@ update は、変更のあった skill ごとの結果を `updates` に出力し | `status` | 意味 | | --- | --- | | `merged` | upstream の変更をすべて適用し、ローカルの編集も残っています。 | -| `conflicted` | 衝突しない変更は適用済みで、列挙したファイルの解消が必要です。テキストの衝突には `local`・`previous original`・`new original` のラベルが付いた diff3 マーカーを、報告した行範囲(1 始まり、両端を含む)に書き込みます。バイナリと変更/削除の衝突はローカル側を残すので、新しい原本は snapshot から取得します。 | +| `conflicted` | 衝突しない変更は適用済みで、列挙したファイルの解消が必要です。テキストの衝突には `local`・`previous original`・`new original` のラベルが付いた diff3 マーカーを、報告した行範囲(1 始まり、両端を含む)に書き込みます。バイナリと変更/削除の衝突はローカル側を残すので、新しい原本は登録済み upstream の source と skill path から確認します。 | | `replaced` | 検証できる旧原本がなく、従来どおり新しい原本で skill を置き換えました。理由は `reason` に出ます。 | | `refreshed` | merged skill の references を更新しました。変わった入力は `inputs` に出ます。ルート本文は保持します。 | -`base` は旧原本の取得元です。検証済みの `snapshot`、repo の Git object(`repository`)、 -`git` adapter の場合は記録済みの source commit の再取得(`upstream`)の順に探します。 -snapshot は登録済みの原本 tree hash と一致するときだけ使うため、snapshot を編集しても -merge の結果は変わりません。どれも使えないときは置き換えになります。たとえば、snapshot -導入前に取り込み、すでに upstream が変わった skill の初回 update、source commit を -記録しない command adapter、force push で消えた source commit などです。置き換え後は -snapshot が残るので、次回の update から merge できます。衝突があっても exit 0 です。 -衝突は hash の差分と同じく結果として扱います。 +`base` は検証できた最初の取得元です。repo の Git object(`repository`)、 +`blob:none` で取得した upstream の全 branch・tag の履歴(`upstream-history`、全 adapter 共通)、 +従来の `git` adapter による記録済み source commit の再取得(`upstream`)の順に探します。 +取得した tree は登録済み tree hash と照合します。履歴からの復元に source commit は不要です。 +shallow な取得はせず、サーバーが filter に対応していれば必要な tree の blob だけを取得します。 +同一 update 内では source ごとに履歴を共有し、終了後に破棄します。update はネットワークを +必要としますが、`check` は引き続きオフラインです。履歴の書き換えで tree が消えるなど、 +復元できない場合は `replaced` と理由を報告し、ローカル専用ファイルを含む skill 全体を +置き換えます。履歴の通信・読み取り・検証に失敗した場合は、記録済み commit でも復元 +できなければ更新全体を中止します。衝突があっても exit 0 です。 + +旧 `.agents/skillctrl/originals/` は参照も更新もせず、そのまま残します。 +すべての呼び出し元を更新した後、内容を確認して手動で削除してください。 +追跡済みなら `git rm -r -- .agents/skillctrl/originals` で削除し、commit します。 +新たな作成は行いません。merged skill の登録済み `references/` は従来どおりです。 保存した intent に沿って skill を直接編集して衝突を解消し、確認後に `record chosen-skill` で明示的に受理します。`record` は衝突マーカーが残った skill ディレクトリを拒否するので、先に解消してください。 diff --git a/docs/parity.md b/docs/parity.md index a2e05f2..9df35bc 100644 --- a/docs/parity.md +++ b/docs/parity.md @@ -17,9 +17,12 @@ throwaway Git repositories and fake upstreams reached through Git's | Unchanged original is not re-imported, so an adaptation is never discarded | `internal/install.Import` fingerprint comparison | `TestInstallerLifecycle/unchanged_original_is_not_re-imported` | | Binary content and executable modes survive an import | `internal/upstream.Export` | `TestInstallerLifecycle/changed_original_imports_bytes_and_modes` | | Unrelated upstream commits are ignored | `internal/upstream.Export` original-hash comparison | `TestInstallerLifecycle/unrelated_upstream_change_is_ignored` | -| A changed original is three-way merged: non-overlapping local edits survive and the diff holds only the upstream change | `internal/upstream.reconcile`, `threeWay` | `TestUpdateMergesUpstreamChangesIntoLocalAdaptation`, `TestCommandAdapterUpdatesMergeFromTheSnapshot` | +| A changed original is three-way merged: non-overlapping local edits survive and the diff holds only the upstream change | `internal/upstream.reconcile`, `threeWay` | `TestUpdateMergesUpstreamChangesIntoLocalAdaptation`, `TestCommandAdapterUpdatesMergeFromUpstreamHistory` | | Overlapping edits are reported with file paths and diff3 line ranges | `internal/upstream.mergeText` | `TestUpdateReportsConflictsWithLocations` | -| The base comes from a verified snapshot, repository objects, or the recorded source commit; otherwise the skill is replaced and the reason reported | `internal/upstream.previousOriginal`, `gitAdapter.Original` | `TestUpdateRecoversTheBaseWithoutASnapshot`, `TestUpdateFallsBackToReplacementWithoutAVerifiedOriginal` | +| The base comes from repository objects, upstream history for every adapter without a recorded commit, or the recorded Git source commit; otherwise replacement reports the reason | `internal/upstream.previousOriginal`, `historyOriginal`, `gitAdapter.Original` | `TestUpdateResolvesBaseFromGitObjectsAndHistory`, `TestUpdateFallsBackToReplacementWithoutAVerifiedOriginal`, `TestCommandAdapterUpdatesMergeFromUpstreamHistory` | +| A failed history fetch aborts without deleting local-only files or modifying registrations | `internal/upstream.previousOriginal` | `TestUpdateDoesNotReplaceSkillsWhenHistoryFetchFails` | +| Blobless history recovery loads required skill blobs without unrelated blobs or a shallow boundary | `internal/upstream.historyOriginal` | `TestUpdateHistoryFetchLoadsOnlyRequiredBlobs` | +| Legacy single-input base copies are ignored and remain untouched across add, update, remove, and merge | `internal/upstream.install` | `TestLegacyBaseSnapshotsAreLeftUntouched` | | Merged updates report refreshed inputs and keep no separate base | `internal/upstream.refreshed` | `TestUpdateReportsRefreshedMergedInputs` | | Unknown skill in a selection is rejected atomically | `internal/upstream.Install` | `TestInstallerLifecycle/rejected_imports_are_atomic/unknown_skill` | | Upstream symlink is refused | `internal/upstream.Export` mode and kind checks | `TestInstallerLifecycle/rejected_imports_are_atomic/symlink`, `TestRejectedUpstreamContent/symlink` | diff --git a/docs/requirements.md b/docs/requirements.md index 303f382..2271981 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -28,10 +28,10 @@ The existing implementation is in the dotfiles checkout used to start this task: User request (2026-10-15): a scheduled update must not make an agent re-read and re-adapt a whole skill whenever its upstream changes slightly; the upstream difference alone should drive the work. This supersedes the earlier single-input behavior in which update replaced a changed original's skill content. -- Keep the most recently imported original of each single-input skill as a base snapshot in `.agents/skillctrl/originals//`. add writes it, update refreshes it, and remove and merge delete it. Snapshots are excluded from skillctrl's skill discovery and from accepted hashes. Before a snapshot is used it must match the registration's original tree hash (or legacy content hash); an edited snapshot is never trusted. +- Do not create, update, read, or delete single-input base snapshots. Ignore existing `.agents/skillctrl/originals/` directories, retain their exclusion from discovery, and document manual removal after all callers upgrade. Registered merged references remain unchanged. - update merges a changed original into the current skill file by file, with the previous original as base, the current skill as local side and the new original as upstream side. Files the upstream did not change keep their local bytes and modes. Text conflicts are written with diff3 markers; binary, modify/delete and delete/modify conflicts keep the local side. Conflicts do not fail the command. -- Find the base, in order, from the verified snapshot, the destination's Git objects containing the registered original tree, and, for the direct Git adapter only, the recorded source commit fetched again from the same upstream with its tree hash verified. Never switch acquisition backends to find a base. When no base is available (no snapshot, no commit, a force-pushed upstream), replace the skill with the new original as before and report why. -- An update with an unchanged original leaves the skill untouched; a missing or invalid snapshot is restored from that same acquisition so the next upstream change merges. +- Find the base, in order, from the destination's Git objects containing the registered original tree, full upstream branch and tag history fetched into disposable bare storage with `blob:none`, and the direct Git adapter's existing recorded source commit fetch. History recovery works with every adapter using validated `sourceUrl` or `source`, without a source commit. Verify every recovered base with its registered tree hash. Share history per source within preparation; do not persist caches or shallow boundaries. Download only required blobs when the server supports filtering. This is Git base recovery, not a change of acquisition adapter. If the registered tree is unavailable, replace the whole skill and report reasons. Abort preparation on history fetch/read/verification failures unless the recorded-commit fallback succeeds. Explicit update requires upstream access; check remains offline. +- An update with an unchanged original leaves the skill untouched and does not fetch base history. - update reports `updates` in its JSON: for each changed single-input skill its status (`merged`, `conflicted`, `replaced`), the base source or the reason none was available, the upstream file changes with their result, and conflict paths and line ranges; for each changed merged skill its refreshed inputs. Reports name repository paths so automation can pass only the upstream diff, the conflicts and the saved intent to an agent. - Merged skills keep their originals under `references/` and refresh them wholesale; their routing is preserved as before. diff --git a/docs/usage.md b/docs/usage.md index 292b8c3..7d16740 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -180,26 +180,22 @@ jq '.updates' update.json git diff -- .agents/skills/chosen-skill # Resolve conflicts and check the upstream change against the saved intent skillctrl record chosen-skill -git diff -- .agents/skills/chosen-skill .agents/skillctrl/originals/chosen-skill .agents/skillctrl/lock.json +git diff -- .agents/skills/chosen-skill .agents/skillctrl/lock.json ``` A single-input update merges the changed original into the current skill, file -by file. The base is the previous original, kept as a pristine snapshot in -`.agents/skillctrl/originals/chosen-skill/`; `add` creates it and later updates -refresh it. Files the upstream left alone keep their local content, so local -adaptations survive unless the upstream changed the same lines. Because the -merge applies only the upstream change, `git diff -- .agents/skills/chosen-skill` -shows the upstream change (plus any conflict markers), not lost adaptations. -`git diff -- .agents/skillctrl/originals/chosen-skill` shows the pure -upstream-to-upstream difference. Commit the snapshot with the skill. +by file. The base is recovered by its registered `skillFolderHash` from Git +objects or upstream history. Files unchanged upstream and local-only files keep +their local bytes and modes. Overlapping text edits produce diff3 markers. +`git diff -- .agents/skills/chosen-skill` shows the applied upstream change and +any conflicts; `updates[].changes` lists the upstream file changes. `update` reports each changed skill in `updates`: ```json {"repo": "/path/to/repo", "skills": ["chosen-skill"], "updates": [{ "name": "chosen-skill", "path": ".agents/skills/chosen-skill", "layout": "single", - "status": "conflicted", "base": "snapshot", - "original": ".agents/skillctrl/originals/chosen-skill", + "status": "conflicted", "base": "upstream-history", "changes": [{"path": "SKILL.md", "upstream": "modified", "result": "conflict"}, {"path": "references/new.md", "upstream": "added", "result": "applied"}], "conflicts": [{"path": "SKILL.md", "kind": "content", "lines": [[12, 20]]}] @@ -209,20 +205,27 @@ upstream-to-upstream difference. Commit the snapshot with the skill. | `status` | Meaning | | --- | --- | | `merged` | Every upstream change applied; local edits are preserved. | -| `conflicted` | Clean changes applied; listed files need resolution. Text conflicts carry diff3 markers labelled `local`, `previous original`, and `new original` at the reported 1-based, inclusive line ranges. Binary and modify/delete conflicts keep the local side; take the new original from the snapshot. | +| `conflicted` | Clean changes applied; listed files need resolution. Text conflicts carry diff3 markers labelled `local`, `previous original`, and `new original` at the reported 1-based, inclusive line ranges. Binary and modify/delete conflicts keep the local side; inspect the new original at the registered upstream source and skill path. | | `replaced` | No verified previous original was available; the new original replaced the skill as in earlier releases. `reason` says why. | | `refreshed` | A merged skill's registered references were replaced; `inputs` lists which changed. Its routing body is preserved. | -`base` names where the previous original came from: the verified `snapshot`, the -repository's Git objects (`repository`), or, for the direct Git adapter, the -recorded source commit fetched again (`upstream`). The snapshot is trusted only -when it matches the registered original tree hash, so editing it does not -change a merge. A replacement happens when none of them is available: for -example, the first update of a skill imported before snapshots existed whose -upstream has already changed, a command adapter (which records no source -commit), or a source commit removed by a force push. The replacement stores a -snapshot, so the next update merges. A conflicting update exits `0`; conflicts -are results, like hash drift. +`base` names the first verified source: the repository's Git objects +(`repository`), upstream branch and tag history fetched with `blob:none` +(`upstream-history`, for every adapter), or the recorded source commit fetched +again by the direct Git adapter (`upstream`). Each recovered tree must match the +registered tree hash. Source commits are optional for history recovery. History +fetches have no shallow boundary; blobs are downloaded only when reading the +required tree, if the server supports filtering. History is shared per source +within an update and discarded afterward. Updates require upstream access; +`check` stays offline. If recovery fails, for example after rewritten history +removes the tree, `replaced` reports the reasons and replaces the whole skill, +including local-only files. History fetch/read/verification failures abort the +update unless recorded-commit recovery succeeds. A conflicting update exits `0`. + +Legacy `.agents/skillctrl/originals/` directories are ignored and left untouched. +After upgrading all callers, inspect and remove that directory manually (for +tracked copies, `git rm -r -- .agents/skillctrl/originals`) and commit the removal. +No command creates or refreshes it. Merged skills retain registered `references/`. Edit the skill directly to resolve conflicts and keep its saved intent, verify the result, then run `record chosen-skill` to accept it. `record` refuses a diff --git a/internal/cli/update_merge_test.go b/internal/cli/update_merge_test.go index 98efdc9..187655b 100644 --- a/internal/cli/update_merge_test.go +++ b/internal/cli/update_merge_test.go @@ -4,6 +4,7 @@ import ( "crypto/sha256" "fmt" "os" + "os/exec" "path/filepath" "strings" "testing" @@ -53,9 +54,10 @@ func TestUpdateMergesUpstreamChangesIntoLocalAdaptation(t *testing.T) { h := newHarness(t) h.publishDemo(t, demoV1, nil) h.run(0, "add", "fixture/source:demo") - if string(h.read(originals+"/demo/SKILL.md")) != string(h.read(".agents/skills/demo/SKILL.md")) { - t.Fatal("add did not keep the imported original as the next update's base") + if _, err := os.Stat(filepath.Join(h.root, originals)); !os.IsNotExist(err) { + t.Fatal("add created a legacy base snapshot") } + h.write(".agents/skills/demo/scripts/am.test.mjs", "local test\n") h.adapt(t, "line two", "line two adapted locally") h.commitAll() @@ -64,8 +66,8 @@ func TestUpdateMergesUpstreamChangesIntoLocalAdaptation(t *testing.T) { result := h.run(0, "update", "demo") update := onlyUpdate(t, result) - if update["status"] != "merged" || update["base"] != "snapshot" || update["conflicts"] != nil { - t.Fatalf("non-conflicting update was not merged from the snapshot: %v", update) + if update["status"] != "merged" || update["base"] != "upstream-history" || update["conflicts"] != nil { + t.Fatalf("non-conflicting update was not merged from upstream history: %v", update) } body := string(h.read(".agents/skills/demo/SKILL.md")) if !strings.Contains(body, "line two adapted locally") || !strings.Contains(body, "line five from upstream v2") { @@ -98,9 +100,8 @@ func TestUpdateMergesUpstreamChangesIntoLocalAdaptation(t *testing.T) { if strings.Contains(diff, "\n-line two adapted locally") || !strings.Contains(diff, "\n+line five from upstream v2") { t.Fatalf("skill diff is not limited to the upstream change:\n%s", diff) } - if !strings.Contains(string(h.read(originals+"/demo/SKILL.md")), "line five from upstream v2") || - strings.Contains(string(h.read(originals+"/demo/SKILL.md")), "adapted") { - t.Fatal("the snapshot does not hold the new pristine original") + if string(h.read(".agents/skills/demo/scripts/am.test.mjs")) != "local test\n" { + t.Fatal("merge removed a local-only test file") } if h.log() != "" { t.Fatal("update invoked a reviewer") @@ -153,8 +154,11 @@ func TestUpdateReportsConflictsWithLocations(t *testing.T) { func TestUpdateFallsBackToReplacementWithoutAVerifiedOriginal(t *testing.T) { h := newHarness(t) - // The fixture's manual skill predates base snapshots: its registration has no - // source commit, and its pristine tree was never committed locally. + // A registration whose tree is no longer reachable cannot supply a base. + registrations := h.upstreamSkills() + registrations["manual"].(map[string]any)["skillFolderHash"] = strings.Repeat("1", 40) + h.write("skills-lock.json", mustJSON(map[string]any{"version": 3, "skills": registrations})) + h.commitAll() h.publishSecondVersion(t) result := h.run(0, "update", "manual") @@ -163,7 +167,7 @@ func TestUpdateFallsBackToReplacementWithoutAVerifiedOriginal(t *testing.T) { t.Fatalf("missing base was not reported as a replacement: %v", update) } reason := str(update["reason"]) - for _, part := range []string{"no verified snapshot", "not in the repository's Git objects", "no recorded source commit"} { + for _, part := range []string{"not in the repository's Git objects", "unavailable in upstream history", "no recorded source commit"} { if !strings.Contains(reason, part) { t.Fatalf("reason %q lacks %q", reason, part) } @@ -171,14 +175,14 @@ func TestUpdateFallsBackToReplacementWithoutAVerifiedOriginal(t *testing.T) { if body := string(h.read(".agents/skills/manual/SKILL.md")); !strings.Contains(body, "upstream v2; generic browser") { t.Fatalf("fallback did not install the new original:\n%s", body) } - // The replacement leaves a verified base, so the next update merges. + // The replacement registers a reachable tree, so the next update merges. h.write(".agents/skills/manual/SKILL.md", manifest("canonical-manual", "upstream v2; default browser")) h.commitAll() h.writeOrigin("skills/manual/notes.md", "upstream v3 notes\n") h.originGit("add", "-A", "--", "skills") h.originGit("-c", "commit.gpgsign=false", "commit", "-qm", "original v3") update = onlyUpdate(t, h.run(0, "update", "manual")) - if update["status"] != "merged" || update["base"] != "snapshot" { + if update["status"] != "merged" || update["base"] != "upstream-history" { t.Fatalf("update after the fallback did not merge: %v", update) } if body := string(h.read(".agents/skills/manual/SKILL.md")); !strings.Contains(body, "default browser") { @@ -186,20 +190,24 @@ func TestUpdateFallsBackToReplacementWithoutAVerifiedOriginal(t *testing.T) { } } -func TestUpdateRecoversTheBaseWithoutASnapshot(t *testing.T) { +func TestUpdateResolvesBaseFromGitObjectsAndHistory(t *testing.T) { cases := []struct { name string // pristine commits the imported original before adapting it. pristine bool // rewrite removes the recorded source commit from the upstream history. rewrite bool + retain string tamper bool base string }{ {name: "repository objects", pristine: true, base: "repository"}, - {name: "recorded source commit", base: "upstream"}, - {name: "tampered snapshot", tamper: true, base: "upstream"}, + {name: "upstream history", base: "upstream-history"}, + {name: "ignored legacy snapshot", tamper: true, base: "upstream-history"}, {name: "force-pushed upstream", rewrite: true}, + {name: "tree retained on another branch", rewrite: true, retain: "branch", base: "upstream-history"}, + {name: "tree retained by a tag", rewrite: true, retain: "tag", base: "upstream-history"}, + {name: "recorded commit outside advertised histories", rewrite: true, retain: "custom", base: "upstream"}, } for _, test := range cases { t.Run(test.name, func(t *testing.T) { @@ -211,14 +219,21 @@ func TestUpdateRecoversTheBaseWithoutASnapshot(t *testing.T) { } if test.tamper { h.write(originals+"/demo/SKILL.md", manifest("demo", "tampered base")) - } else if err := os.RemoveAll(filepath.Join(h.root, originals)); err != nil { - t.Fatal(err) } h.adapt(t, "line two", "line two adapted locally") h.commitAll() if test.rewrite { branch := h.originGit("rev-parse", "--abbrev-ref", "HEAD") + if test.retain == "custom" { + h.originGit("update-ref", "refs/keep/original", "HEAD") + } else if test.retain == "tag" { + h.originGit("-c", "tag.gpgsign=false", "tag", "retained-original") + } else if test.retain != "" { + h.originGit(test.retain, "retained-original") + } h.originGit("checkout", "-q", "--orphan", "rewritten") + h.writeOrigin("skills/demo/SKILL.md", manifest("demo", "rewritten base")) + h.originGit("add", "-A", "--", "skills") h.originGit("-c", "commit.gpgsign=false", "commit", "-qm", "rewritten history") h.originGit("branch", "-D", branch) h.originGit("branch", "-m", branch) @@ -228,6 +243,9 @@ func TestUpdateRecoversTheBaseWithoutASnapshot(t *testing.T) { h.publishDemo(t, strings.Replace(demoV1, "line five", "line five from upstream v2", 1), nil) update := onlyUpdate(t, h.run(0, "update", "demo")) body := string(h.read(".agents/skills/demo/SKILL.md")) + if test.tamper && string(h.read(originals+"/demo/SKILL.md")) != manifest("demo", "tampered base") { + t.Fatal("update modified a legacy snapshot") + } if test.base == "" { if update["status"] != "replaced" || !strings.Contains(str(update["reason"]), "unavailable upstream") { t.Fatalf("lost source commit was not reported: %v", update) @@ -271,7 +289,7 @@ func TestUpdateReportsRefreshedMergedInputs(t *testing.T) { } } -func TestCommandAdapterUpdatesMergeFromTheSnapshot(t *testing.T) { +func TestCommandAdapterUpdatesMergeFromUpstreamHistory(t *testing.T) { for _, backend := range []string{"skills", "gh"} { t.Run(backend, func(t *testing.T) { h := newHarness(t) @@ -279,6 +297,9 @@ func TestCommandAdapterUpdatesMergeFromTheSnapshot(t *testing.T) { serve := func(body string) { t.Helper() content := manifest("new-skill", body) + h.writeOrigin("skills/new-skill/SKILL.md", content) + h.originGit("add", "--", "skills/new-skill") + h.originGit("-c", "commit.gpgsign=false", "commit", "-qm", "served original") h.writeFile(filepath.Join(served, "SKILL.md"), content) h.writeFile(filepath.Join(h.base, "served-lock.json"), mustJSON(map[string]any{"version": 1, "skills": map[string]any{"new-skill": map[string]any{ "source": "fixture/source", "sourceType": "github", "skillPath": "skills/new-skill/SKILL.md", @@ -304,12 +325,16 @@ func TestCommandAdapterUpdatesMergeFromTheSnapshot(t *testing.T) { } body := string(h.read(".agents/skills/new-skill/SKILL.md")) h.write(".agents/skills/new-skill/SKILL.md", strings.Replace(body, "line two", "line two adapted locally", 1)) + h.write(".agents/skills/new-skill/scripts/am.test.mjs", "local test\n") h.commitAll() serve(strings.Replace(demoV1, "line five", "line five from upstream v2", 1)) update := onlyUpdate(t, h.run(0, "--adapter", backend, "update", "new-skill")) - if update["status"] != "merged" || update["base"] != "snapshot" { - t.Fatalf("command adapter update did not merge from the snapshot: %v", update) + if update["status"] != "merged" || update["base"] != "upstream-history" { + t.Fatalf("command adapter update did not merge from upstream history: %v", update) + } + if string(h.read(".agents/skills/new-skill/scripts/am.test.mjs")) != "local test\n" { + t.Fatal("command adapter merge removed local-only files") } body = string(h.read(".agents/skills/new-skill/SKILL.md")) if !strings.Contains(body, "line two adapted locally") || !strings.Contains(body, "line five from upstream v2") { @@ -363,9 +388,7 @@ func TestUpdateReportsBinaryAndDeletionConflictsKeepingLocalFiles(t *testing.T) if _, err := os.Stat(filepath.Join(h.root, ".agents/skills/demo/keep.md")); !os.IsNotExist(err) { t.Fatal("a locally deleted file was restored") } - if string(h.read(originals+"/demo/keep.md")) != "keep v2\n" || string(h.read(originals+"/demo/asset.bin")) != "\x00upstream" { - t.Fatal("the new original is not available beside the kept local files") - } + } func TestUpdateIgnoresMarkerShapedTextInCleanMerges(t *testing.T) { @@ -388,3 +411,60 @@ func TestUpdateIgnoresMarkerShapedTextInCleanMerges(t *testing.T) { t.Fatalf("merge lost content:\n%s", body) } } + +func TestLegacyBaseSnapshotsAreLeftUntouched(t *testing.T) { + h := newHarness(t) + h.publishDemo(t, demoV1, nil) + legacy := originals + "/demo/SKILL.md" + h.write(legacy, "legacy user-edited copy\n") + h.commitAll() + check := func() { + t.Helper() + if string(h.read(legacy)) != "legacy user-edited copy\n" { + t.Fatal("command changed a legacy base snapshot") + } + } + h.run(0, "add", "fixture/source:demo") + check() + h.adapt(t, "line two", "local adaptation") + h.commitAll() + h.publishDemo(t, strings.Replace(demoV1, "line five", "upstream change", 1), nil) + h.run(0, "update", "demo") + check() + h.commitAll() + h.run(0, "remove", "demo") + check() + h.commitAll() + h.run(0, "merge", "--name", "demo", "fixture/source:new-skill") + check() +} + +func TestUpdateDoesNotReplaceSkillsWhenHistoryFetchFails(t *testing.T) { + h := newHarness(t) + h.publishDemo(t, demoV1, nil) + h.run(0, "add", "fixture/source:demo") + registrations := h.upstreamSkills() + delete(registrations["demo"].(map[string]any), "sourceCommit") + h.write("skills-lock.json", mustJSON(map[string]any{"version": 3, "skills": registrations})) + h.adapt(t, "line two", "local adaptation") + h.write(".agents/skills/demo/scripts/am.test.mjs", "local test\n") + h.commitAll() + before := h.git("status", "--porcelain") + h.publishDemo(t, strings.Replace(demoV1, "line five", "upstream change", 1), nil) + realGit, err := exec.LookPath("git") + if err != nil { + t.Fatal(err) + } + script := "#!/bin/sh\ncase \"$*\" in *--filter=blob:none*) exit 44 ;; esac\nexec '" + realGit + "' \"$@\"\n" + h.writeFile(filepath.Join(h.binDir, "git"), script) + if err := os.Chmod(filepath.Join(h.binDir, "git"), 0o755); err != nil { + t.Fatal(err) + } + _, stderr, code := h.try("update", "demo") + if code != 1 || !strings.Contains(stderr, "upstream history fetch failed") { + t.Fatalf("history failure: exit %d %s", code, stderr) + } + if h.git("status", "--porcelain") != before || string(h.read(".agents/skills/demo/scripts/am.test.mjs")) != "local test\n" { + t.Fatal("failed history fetch changed the repository") + } +} diff --git a/internal/gitx/gitx.go b/internal/gitx/gitx.go index 392fca3..d90d7ec 100644 --- a/internal/gitx/gitx.go +++ b/internal/gitx/gitx.go @@ -184,6 +184,11 @@ func SafeStdin(dir string, stdin []byte, args ...string) ([]byte, error) { return run(dir, nil, stdin, true, args) } +// SafeStdinEnv runs a hardened Git command with explicit stdin and environment. +func SafeStdinEnv(dir string, env []string, stdin []byte, args ...string) ([]byte, error) { + return run(dir, env, stdin, true, args) +} + // Trimmed returns stdout without surrounding whitespace, matching the previous // text-mode subprocess calls. func Trimmed(out []byte) string { return strings.TrimSpace(string(out)) } diff --git a/internal/install/install.go b/internal/install/install.go index 0c5a248..6b62302 100644 --- a/internal/install/install.go +++ b/internal/install/install.go @@ -307,10 +307,6 @@ func Import(repo, target, upstreamLock string) error { } intentRemovals = append(intentRemovals, path) } - originals, err := prepareOriginals(repo, filepath.Join(filepath.Dir(upstreamLock), upstream.PreparedOriginals)) - if err != nil { - return err - } claude := filepath.Join(repo, filepath.FromSlash(ClaudeDir)) if err := os.MkdirAll(claude, 0o755); err != nil { return err @@ -359,9 +355,6 @@ func Import(repo, target, upstreamLock string) error { return err } } - if err := originals(); err != nil { - return err - } if trackingErr == nil { if err := skillstate.Write(repo, private); err != nil { return err @@ -394,76 +387,6 @@ func Import(repo, target, upstreamLock string) error { return nil } -// prepareOriginals validates the staged base snapshots and the destination -// before any skill is replaced, and returns the step that publishes them. -// Snapshots are skillctrl-owned copies of upstream originals, so they are -// replaced without the pending-edit protection that guards skill content. -func prepareOriginals(repo, prepared string) (func() error, error) { - if _, err := os.Stat(prepared); os.IsNotExist(err) { - return func() error { return nil }, nil - } else if err != nil { - return nil, err - } - if err := CheckSkills(prepared); err != nil { - return nil, err - } - existing := filepath.Join(repo, filepath.FromSlash(upstream.Originals)) - for _, relative := range []string{".agents", ".agents/skillctrl", upstream.Originals} { - info, err := os.Lstat(filepath.Join(repo, filepath.FromSlash(relative))) - if os.IsNotExist(err) { - break - } - if err != nil { - return nil, err - } - if !info.IsDir() { - return nil, fmt.Errorf("original snapshots require a real directory: %s", relative) - } - } - if _, err := os.Stat(existing); err == nil { - if err := CheckSkills(existing); err != nil { - return nil, err - } - } - return func() error { - names := map[string]bool{} - for _, directory := range []string{existing, prepared} { - entries, err := os.ReadDir(directory) - if err != nil && !os.IsNotExist(err) { - return err - } - for _, entry := range entries { - names[entry.Name()] = true - } - } - for _, name := range slices.Sorted(maps.Keys(names)) { - current, err := fingerprint(filepath.Join(existing, name)) - if err != nil { - return err - } - replacement, err := fingerprint(filepath.Join(prepared, name)) - if err != nil { - return err - } - if current != nil && sameFingerprint(current, replacement) { - continue - } - if err := os.RemoveAll(filepath.Join(existing, name)); err != nil { - return err - } - if replacement != nil { - if err := copyDirectory(filepath.Join(prepared, name), filepath.Join(existing, name)); err != nil { - return err - } - } - } - if entries, err := os.ReadDir(existing); err == nil && len(entries) == 0 { - return os.Remove(existing) - } - return nil - }, nil -} - // protectPendingSkills allows unrelated edits and unchanged originals, but a // directory replacement must not silently discard an uncommitted customization. func protectPendingSkills(repo, target string, names map[string]bool) (map[string]bool, error) { diff --git a/internal/upstream/adapter.go b/internal/upstream/adapter.go index 798602f..f55e6bb 100644 --- a/internal/upstream/adapter.go +++ b/internal/upstream/adapter.go @@ -26,10 +26,6 @@ type ExportRequest struct { Target string Directory string Previous map[string]any - // Always writes the original to Target even when it matches Previous, whose - // registration is then returned unchanged. Update uses it to restore a - // missing base snapshot without re-importing the skill. - Always bool } // Adapter prepares originals in isolation; import protection and intent review @@ -70,7 +66,7 @@ func (adapter *gitAdapter) Export(request ExportRequest) (map[string]any, error) if err != nil { return nil, err } - return repository.export(request.Destination, request.Skill, request.Name, request.Target, request.Previous, request.Always) + return repository.export(request.Destination, request.Skill, request.Name, request.Target, request.Previous) } func (adapter *gitAdapter) repository(request ExportRequest) (*Repository, error) { @@ -352,15 +348,12 @@ func (adapter *commandAdapter) Export(request ExportRequest) (map[string]any, er unchanged := strings.EqualFold(priorSource, source) && (field(previous, "skillPath") == "" || field(previous, "skillPath") == field(result, "skillPath")) && ((field(previous, "skillFolderHash") != "" && field(previous, "skillFolderHash") == field(result, "skillFolderHash")) || (field(previous, "skillFolderHash") == "" && field(previous, "computedHash") != "" && field(previous, "computedHash") == field(result, "computedHash"))) - if unchanged && !request.Always { + if unchanged { return previous, nil } if err := writeExport(target, files, contents); err != nil { return nil, err } - if unchanged { - return previous, nil - } result["nativeExport"] = maps.Clone(metadata) if installed != destinationName { result["nativeName"] = installed diff --git a/internal/upstream/history.go b/internal/upstream/history.go new file mode 100644 index 0000000..d722250 --- /dev/null +++ b/internal/upstream/history.go @@ -0,0 +1,98 @@ +package upstream + +import ( + "crypto/sha256" + "errors" + "fmt" + "os" + "path/filepath" + "strings" + + "github.com/wwwyo/skillctrl/internal/gitx" +) + +var errHistoryUnavailable = errors.New("upstream history base unavailable") + +// historyOriginal resolves a registered tree independently of the acquisition +// adapter. Full history is necessary because native locks need not name a commit. +func historyOriginal(request ExportRequest) (map[string]file, error) { + tree := field(request.Previous, "skillFolderHash") + if !commitPattern.MatchString(tree) { + return nil, fmt.Errorf("%w: registration has no valid original tree hash", errHistoryUnavailable) + } + identifier := field(request.Previous, "sourceUrl") + if identifier == "" { + identifier = field(request.Previous, "source") + } + source, err := Source(identifier) + if err != nil { + return nil, fmt.Errorf("registration has no supported upstream URL") + } + if !strings.EqualFold(source, request.Source) { + return nil, fmt.Errorf("registered source URL changed source identity") + } + // Share one disposable fetch per source in this preparation, without storing + // upstream history or copies of originals in the destination repository. + directory := filepath.Join(request.Directory, fmt.Sprintf("history-%x", sha256.Sum256([]byte(strings.ToLower(source))))) + if _, err := os.Stat(filepath.Join(directory, "skillctrl-history-ready")); os.IsNotExist(err) { + if err := os.MkdirAll(directory, 0o700); err != nil { + return nil, err + } + if err := gitx.SafeRun(directory, "init", "--bare", "--quiet", "--template="); err != nil { + return nil, err + } + url := "https://github.com/" + source + ".git" + for _, setting := range [][2]string{ + {"remote.origin.url", url}, + {"remote.origin.promisor", "true"}, + {"remote.origin.partialclonefilter", "blob:none"}, + } { + if err := gitx.SafeRun(directory, "config", setting[0], setting[1]); err != nil { + return nil, err + } + } + env := removeEnv(gitx.Environment("GIT_TERMINAL_PROMPT=0"), "OPENCODE_API_KEY") + // No depth limit: the registered tree may be arbitrarily old or reachable + // only through a non-default branch or tag. Blobs are fetched on demand. + if err := gitx.SafeEnv(directory, env, "fetch", "--quiet", "--filter=blob:none", "--no-tags", "origin", + "+refs/heads/*:refs/heads/*", "+refs/tags/*:refs/tags/*"); err != nil { + return nil, fmt.Errorf("upstream history fetch failed") + } + if err := os.WriteFile(filepath.Join(directory, "skillctrl-history-ready"), nil, 0o600); err != nil { + return nil, err + } + } else if err != nil { + return nil, err + } + // Object reads stay local; only the explicit fetches above and below hit the network. + offline := removeEnv(gitx.Environment("GIT_NO_LAZY_FETCH=1"), "OPENCODE_API_KEY") + if err := gitx.SafeEnv(directory, offline, "cat-file", "-e", tree+"^{tree}"); err != nil { + return nil, fmt.Errorf("%w: registered original tree %s is unavailable in upstream history", errHistoryUnavailable, shortHash(tree)) + } + // cat-file lazily fetches one missing blob at a time. Batch the missing + // objects of this tree first to avoid a network round trip per skill file. + missing, err := gitx.SafeStdinEnv(directory, offline, nil, "rev-list", "--objects", "--missing=print", tree) + if err != nil { + return nil, fmt.Errorf("cannot list registered original tree") + } + var wants strings.Builder + for _, line := range strings.Split(string(missing), "\n") { + if oid, missing := strings.CutPrefix(line, "?"); missing { + wants.WriteString(oid + "\n") + } + } + if wants.Len() > 0 { + env := removeEnv(gitx.Environment("GIT_TERMINAL_PROMPT=0"), "OPENCODE_API_KEY") + if _, err := gitx.SafeStdinEnv(directory, env, []byte(wants.String()), "fetch", "--quiet", "--no-tags", "--no-write-fetch-head", "--filter=blob:none", "--stdin", "origin"); err != nil { + return nil, fmt.Errorf("cannot fetch registered original blobs from upstream history") + } + } + files, err := objectTree(directory, tree) + if err != nil { + return nil, fmt.Errorf("cannot read registered original from upstream history: %w", err) + } + if treeHash(files) != tree { + return nil, fmt.Errorf("upstream history original does not match the registered tree hash") + } + return files, nil +} diff --git a/internal/upstream/history_test.go b/internal/upstream/history_test.go new file mode 100644 index 0000000..2b59414 --- /dev/null +++ b/internal/upstream/history_test.go @@ -0,0 +1,74 @@ +package upstream + +import ( + "encoding/json" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/wwwyo/skillctrl/internal/gitx" +) + +func TestUpdateHistoryFetchLoadsOnlyRequiredBlobs(t *testing.T) { + o := newOrigin(t) + o.git("config", "uploadpack.allowFilter", "true") + o.git("config", "uploadpack.allowAnySHA1InWant", "true") + o.write("skills/demo/SKILL.md", manifest("demo", "old original")) + o.write("skills/demo/guide.md", "base guide\n") + o.write("unrelated.bin", "unrelated repository content\n") + o.commit("old original") + tree := o.git("rev-parse", "HEAD:skills/demo") + unrelated := o.git("rev-parse", "HEAD:unrelated.bin") + o.withRepository("fixture/source", o.dir) + withGitConfig(t, o.gitConfig) + dir := newDestination(t, "") + if err := os.MkdirAll(filepath.Join(dir, ".agents/skills/demo"), 0o755); err != nil { + t.Fatal(err) + } + for name, data := range map[string]string{"SKILL.md": manifest("demo", "adapted original"), "guide.md": "base guide\n", "local.txt": "local only\n"} { + if err := os.WriteFile(filepath.Join(dir, ".agents/skills/demo", name), []byte(data), 0o644); err != nil { + t.Fatal(err) + } + } + registration, err := json.Marshal(map[string]any{"version": 1, "skills": map[string]any{"demo": map[string]any{ + "source": "fixture/source", "sourceType": "github", "skillPath": "skills/demo/SKILL.md", "skillFolderHash": tree, + }}}) + if err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(dir, Lock), registration, 0o644); err != nil { + t.Fatal(err) + } + o.write("skills/demo/new.md", "new upstream file\n") + o.commit("new original") + stage := t.TempDir() + target, _, err := Install(dir, "update", []string{"demo"}, "", stage) + if err != nil { + t.Fatal(err) + } + reports, err := ReadUpdates(stage) + if err != nil || len(reports) != 1 || reports[0].Status != "merged" || reports[0].Base != "upstream-history" { + t.Fatalf("history recovery: %v %v", reports, err) + } + for name, want := range map[string]string{"SKILL.md": manifest("demo", "adapted original"), "local.txt": "local only\n", "new.md": "new upstream file\n"} { + got, err := os.ReadFile(filepath.Join(target, "demo", name)) + if err != nil || string(got) != want { + t.Fatalf("%s: %q %v", name, got, err) + } + } + histories, err := filepath.Glob(filepath.Join(stage, "history-*")) + if err != nil || len(histories) != 1 { + t.Fatalf("history storage: %v %v", histories, err) + } + objects, err := gitx.Safe(histories[0], "cat-file", "--batch-all-objects", "--batch-check=%(objectname)") + if err != nil { + t.Fatal(err) + } + if strings.Contains(string(objects), unrelated) { + t.Fatal("partial history fetch downloaded an unrelated blob") + } + if _, err := os.Stat(filepath.Join(histories[0], "shallow")); !os.IsNotExist(err) { + t.Fatal("history recovery retained a shallow boundary") + } +} diff --git a/internal/upstream/reconcile.go b/internal/upstream/reconcile.go index a2b5604..3cca31f 100644 --- a/internal/upstream/reconcile.go +++ b/internal/upstream/reconcile.go @@ -18,15 +18,6 @@ import ( "github.com/wwwyo/skillctrl/internal/jsonfmt" ) -// Originals is the repository-relative directory holding the most recently -// imported original of each single-input skill. It is the base of the next -// update's three-way merge and is verified against the registered tree hash -// before use, so a locally edited snapshot is never trusted as a base. -const Originals = ".agents/skillctrl/originals" - -// PreparedOriginals is the staged copy of Originals beside import results. -const PreparedOriginals = "originals" - // PreparedUpdates is the staged reconciliation report beside import results. const PreparedUpdates = "updates.json" @@ -38,7 +29,6 @@ type Update struct { Status string `json:"status"` Base string `json:"base,omitempty"` Reason string `json:"reason,omitempty"` - Original string `json:"original,omitempty"` Changes []Change `json:"changes,omitempty"` Conflicts []Conflict `json:"conflicts,omitempty"` Inputs []InputUpdate `json:"inputs,omitempty"` @@ -209,7 +199,7 @@ func objectTree(repository, tree string) (map[string]file, error) { // treeHash computes the SHA-1 Git tree identifier of files, the identity // recorded as skillFolderHash. Computing it in-process avoids staging the -// snapshot through an index that the caller's Git configuration could filter. +// original through an index that the caller's Git configuration could filter. func treeHash(files map[string]file) string { type node struct { blobs map[string]file @@ -261,65 +251,44 @@ func treeHash(files map[string]file) string { return hex.EncodeToString(hashNode(root)) } -// matchesRegistration reports whether files are exactly the registered original. -func matchesRegistration(files map[string]file, registration map[string]any) bool { - if len(files) == 0 { - return false - } - if recorded := field(registration, "skillFolderHash"); recorded != "" { - return treeHash(files) == recorded - } - recorded := field(registration, "computedHash") - if recorded == "" { - return false - } - entries := map[string]treeFile{} - contents := map[string][]byte{} - for name, entry := range files { - entries[name] = treeFile{oid: name} - contents[name] = entry.data - } - return contentHash(entries, contents) == recorded -} - -// snapshot returns the stored original when it still matches the registration. -func snapshot(directory string, registration map[string]any) (map[string]file, bool) { - files, err := readTree(directory) - if err != nil || !matchesRegistration(files, registration) { - return nil, false - } - return files, true -} - // previousOriginal finds the base of a three-way update. Every source is // verified against the registered identity; a missing base is reported with // the reasons each source failed instead of guessing. -func previousOriginal(dir, snapshotDir string, request ExportRequest, adapter Adapter) (map[string]file, string, string) { +func previousOriginal(dir string, request ExportRequest, adapter Adapter) (map[string]file, string, string, error) { previous := request.Previous - if files, ok := snapshot(snapshotDir, previous); ok { - return files, "snapshot", "" - } - reasons := []string{"no verified snapshot in " + Originals} - if tree := field(previous, "skillFolderHash"); tree != "" { + var reasons []string + if tree := field(previous, "skillFolderHash"); commitPattern.MatchString(tree) { if gitx.SafeRun(dir, "cat-file", "-e", tree+"^{tree}") == nil { if files, err := objectTree(dir, tree); err == nil && treeHash(files) == tree { - return files, "repository", "" + return files, "repository", "", nil } } reasons = append(reasons, "original tree is not in the repository's Git objects") } else { reasons = append(reasons, "registration has no original tree hash") } + files, historyErr := historyOriginal(request) + if historyErr == nil { + return files, "upstream-history", "", nil + } + reasons = append(reasons, historyErr.Error()) if source, ok := adapter.(originalSource); ok { files, err := source.Original(request) - if err == nil { - return files, "upstream", "" + if err == nil && treeHash(files) == field(previous, "skillFolderHash") { + return files, "upstream", "", nil + } + if err != nil { + reasons = append(reasons, err.Error()) + } else { + reasons = append(reasons, "recorded source original does not match the registered tree hash") } - reasons = append(reasons, err.Error()) } else { reasons = append(reasons, "the acquisition adapter cannot fetch a recorded original") } - return nil, "", strings.Join(reasons, "; ") + if !errors.Is(historyErr, errHistoryUnavailable) { + return nil, "", "", fmt.Errorf("cannot recover previous original: %s", strings.Join(reasons, "; ")) + } + return nil, "", strings.Join(reasons, "; "), nil } // originalSource is implemented by adapters able to fetch a previously @@ -392,7 +361,7 @@ func threeWay(scratch string, base, ours, theirs map[string]file) (map[string]fi merged.data = t.data case binary(o.data) || binary(t.data) || binary(b.data): // A binary file cannot carry conflict markers. Keep the local - // bytes; the new original remains available in the snapshot. + // bytes; resolve these conflicts against the upstream source. merged.data = o.data change.Result = "conflict" conflicts = append(conflicts, Conflict{Path: name, Kind: conflictBinary}) @@ -485,8 +454,8 @@ func conflictLines(data []byte) [][2]int { // reconcile merges a changed original into the prepared skill directory and // describes the result. Without a verified base, the new original replaces // the skill as before three-way updates existed, and the report says why. -func reconcile(dir, directory, name, skillDir, snapshotDir, staged string, request ExportRequest, adapter Adapter) (Update, error) { - update := Update{Name: name, Path: ".agents/skills/" + name, Layout: "single", Original: Originals + "/" + name} +func reconcile(dir, directory, name, skillDir, staged string, request ExportRequest, adapter Adapter) (Update, error) { + update := Update{Name: name, Path: ".agents/skills/" + name, Layout: "single"} theirs, err := readTree(staged) if err != nil { return update, err @@ -502,7 +471,10 @@ func reconcile(dir, directory, name, skillDir, snapshotDir, staged string, reque if err != nil { return update, err } - base, source, reason := previousOriginal(dir, snapshotDir, request, adapter) + base, source, reason, err := previousOriginal(dir, request, adapter) + if err != nil { + return update, err + } if base == nil { update.Status, update.Reason = StatusReplaced, reason return update, writeTree(skillDir, theirs) diff --git a/internal/upstream/upstream.go b/internal/upstream/upstream.go index bc42e25..8306de6 100644 --- a/internal/upstream/upstream.go +++ b/internal/upstream/upstream.go @@ -299,8 +299,8 @@ func (r *Repository) Path() string { return r.path } func (r *Repository) indexSkills() error { manifests := map[string]string{} for name, entry := range r.files { - // Base snapshots duplicate installed skills; they are never separate skills. - if containsSourceDirectory(name) || strings.HasPrefix(name, Originals+"/") { + // Ignore legacy base copies and registered merged references during discovery. + if containsSourceDirectory(name) || strings.HasPrefix(name, ".agents/skillctrl/originals/") { continue } if path.Base(name) != "SKILL.md" || entry.kind != "blob" { @@ -368,19 +368,12 @@ func (r *Repository) Select(name, previous string) (string, error) { // Export copies tracked files only, rejecting links and filesystem escapes. func (r *Repository) Export(destination, name, target string, previous map[string]any) (map[string]any, error) { - return r.export(destination, name, name, target, previous, false) + return r.export(destination, name, name, target, previous) } -// export writes a changed original to target. With always, an unchanged -// original is written too, and previous is still returned as its registration. -func (r *Repository) export(destination, name, destinationName, target string, previous map[string]any, always bool) (map[string]any, error) { - inspected := previous - if always { - inspected = maps.Clone(previous) - delete(inspected, "skillFolderHash") - delete(inspected, "computedHash") - } - result, files, contents, err := r.inspectExport(destination, name, destinationName, inspected) +// export writes a changed original to target. +func (r *Repository) export(destination, name, destinationName, target string, previous map[string]any) (map[string]any, error) { + result, files, contents, err := r.inspectExport(destination, name, destinationName, previous) if err != nil { return nil, err } @@ -389,25 +382,9 @@ func (r *Repository) export(destination, name, destinationName, target string, p return nil, err } } - if always && sameOriginal(previous, result) { - return previous, nil - } return result, nil } -// sameOriginal applies the same-original rule of inspectExport to a fresh result. -func sameOriginal(previous, result map[string]any) bool { - previousSource, _ := Source(field(previous, "source")) - if !strings.EqualFold(previousSource, field(result, "source")) { - return false - } - if field(previous, "skillFolderHash") != "" { - return field(previous, "skillPath") == field(result, "skillPath") && field(previous, "skillFolderHash") == field(result, "skillFolderHash") - } - return (field(previous, "skillPath") == "" || field(previous, "skillPath") == field(result, "skillPath")) && - field(previous, "computedHash") != "" && field(previous, "computedHash") == field(result, "computedHash") -} - func (r *Repository) inspectExport(destination, name, destinationName string, previous map[string]any) (map[string]any, map[string]treeFile, map[string][]byte, error) { manifest, err := r.Select(name, field(previous, "skillPath")) if err != nil { @@ -544,16 +521,6 @@ func rejectIgnored(destination, name string, files map[string]treeFile) error { return rejectIgnoredPaths(destination, ".agents/skills/"+name, name, paths) } -// rejectIgnoredAt applies the same rule to a staged directory written elsewhere -// in the destination, such as the base snapshot of a single-input skill. -func rejectIgnoredAt(destination, prefix, staged string) error { - files, err := readTree(staged) - if err != nil { - return err - } - return rejectIgnoredPaths(destination, prefix, path.Base(prefix), slices.Collect(maps.Keys(files))) -} - func rejectIgnoredPaths(destination, prefix, name string, paths []string) error { var request strings.Builder for _, path := range paths { @@ -601,17 +568,6 @@ func install(dir, directory string, request importRequest, adapter Adapter) (tar if err := copyTree(filepath.Join(dir, filepath.FromSlash(".agents/skills")), target); err != nil { return "", "", err } - originals := filepath.Join(directory, PreparedOriginals) - if err := os.MkdirAll(originals, 0o755); err != nil { - return "", "", err - } - if _, err := os.Lstat(filepath.Join(dir, filepath.FromSlash(Originals))); err == nil { - if err := copyTree(filepath.Join(dir, filepath.FromSlash(Originals)), originals); err != nil { - return "", "", err - } - } else if !os.IsNotExist(err) { - return "", "", err - } updates := []Update{} if len(selected) == 0 { selected = slices.Sorted(maps.Keys(value.ManagedSkills())) @@ -642,10 +598,6 @@ func install(dir, directory string, request importRequest, adapter Adapter) (tar updates = append(updates, update) } } - // Merged originals live under references/ and need no separate base. - if err := os.RemoveAll(filepath.Join(originals, name)); err != nil { - return "", "", err - } value.Skills[name] = exported continue } @@ -657,9 +609,6 @@ func install(dir, directory string, request importRequest, adapter Adapter) (tar if err := os.RemoveAll(filepath.Join(target, name)); err != nil { return "", "", err } - if err := os.RemoveAll(filepath.Join(originals, name)); err != nil { - return "", "", err - } delete(value.Skills, name) continue case "add": @@ -694,9 +643,7 @@ func install(dir, directory string, request importRequest, adapter Adapter) (tar // The original is staged apart from the skill: an add installs it, and an // update merges it into the current skill using the previous original. staged := filepath.Join(directory, "exports", name) - snapshotDir := filepath.Join(originals, name) - _, snapshotValid := snapshot(snapshotDir, previous) - request := ExportRequest{Destination: dir, Source: source, Skill: skill, Name: name, Target: staged, Directory: directory, Previous: previous, Always: !snapshotValid} + request := ExportRequest{Destination: dir, Source: source, Skill: skill, Name: name, Target: staged, Directory: directory, Previous: previous} exported, err := adapter.Export(request) if err != nil { return "", "", err @@ -710,13 +657,10 @@ func install(dir, directory string, request importRequest, adapter Adapter) (tar } else if err != nil { return "", "", err } - if err := rejectIgnoredAt(dir, Originals+"/"+name, staged); err != nil { - return "", "", err - } if !sameRegistration(exported, previous) { skillDir := filepath.Join(target, name) if command == "update" { - update, err := reconcile(dir, directory, name, skillDir, snapshotDir, staged, request, adapter) + update, err := reconcile(dir, directory, name, skillDir, staged, request, adapter) if err != nil { return "", "", err } @@ -730,12 +674,6 @@ func install(dir, directory string, request importRequest, adapter Adapter) (tar } } } - if err := os.RemoveAll(snapshotDir); err != nil { - return "", "", err - } - if err := os.Rename(staged, snapshotDir); err != nil { - return "", "", err - } } lock = filepath.Join(directory, "upstream.json") if err := value.writePrepared(directory, lock); err != nil {