-
Notifications
You must be signed in to change notification settings - Fork 2
Add safe embedded manage-tink refresh #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4c8f7c6
76fd1a5
1156d02
11cabec
e970a8d
9678fe1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,14 +3,25 @@ | |
| use std::path::Path; | ||
|
|
||
| use crate::add; | ||
| use crate::catalog; | ||
| use crate::check; | ||
| use crate::error::Error; | ||
| use crate::paths::map_io; | ||
| use crate::library; | ||
| use crate::paths::{map_io, refuse_symlink}; | ||
| use crate::provenance; | ||
| use crate::skills::{self, Skill}; | ||
|
|
||
| const SKILL_MD: &str = include_str!("../skills/manage-tink/SKILL.md"); | ||
| const OPENAI_YAML: &str = include_str!("../skills/manage-tink/agents/openai.yaml"); | ||
| const COMMANDS_MD: &str = include_str!("../skills/manage-tink/references/commands.md"); | ||
|
|
||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub(crate) enum RefreshOutcome { | ||
| Installed, | ||
| Unchanged, | ||
| Refreshed, | ||
| } | ||
|
|
||
| /// Materialize the embedded tree for read-only validation or later publication. | ||
| /// The returned guard owns the bytes referenced by `Skill`. | ||
| pub(crate) fn prepare_manage_tink() -> Result<(tempfile::TempDir, Skill), Error> { | ||
|
|
@@ -33,6 +44,84 @@ pub(crate) fn prepare_manage_tink() -> Result<(tempfile::TempDir, Skill), Error> | |
| Ok((staging, skill)) | ||
| } | ||
|
|
||
| pub(crate) fn is_current(installed: &Skill) -> Result<bool, Error> { | ||
| let (_staging, embedded) = prepare_manage_tink()?; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Whenever a receipt-free Useful? React with 👍 / 👎. |
||
| skills::skill_contents_equal(&installed.path, &embedded.path) | ||
| } | ||
|
|
||
| /// Require an installed embedded copy to match the payload in this binary. | ||
| pub(crate) fn require_current(installed: &Skill) -> Result<(), Error> { | ||
| if is_current(installed)? { | ||
| return Ok(()); | ||
| } | ||
| Err(Error::msg( | ||
| "manage-tink differs from this Tink binary; run `tink skill refresh manage-tink`", | ||
| )) | ||
| } | ||
|
|
||
| fn refuse_remote_library_collision() -> Result<(), Error> { | ||
| let Some(home) = crate::home::existing_inventory_root(None)? else { | ||
| return Ok(()); | ||
| }; | ||
| let target = crate::home::skills_library_path(&home).join("manage-tink"); | ||
| refuse_symlink(&target)?; | ||
| if !target.is_dir() { | ||
| return Ok(()); | ||
| } | ||
| let library_skill = skills::read_skill(&target, true)?; | ||
| if provenance::read(&library_skill)?.is_some() { | ||
| return Err(Error::msg( | ||
| "Refusing to replace library manage-tink with remote provenance", | ||
| )); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub(crate) fn refresh_manage_tink(project_root: &Path) -> Result<RefreshOutcome, Error> { | ||
| check::check_zen_coupling(project_root)?; | ||
| let agents = crate::home::project_agents_path(project_root); | ||
| let skills_root = crate::home::project_skills_path(project_root); | ||
| let target = skills_root.join("manage-tink"); | ||
| refuse_symlink(&agents)?; | ||
| refuse_symlink(&skills_root)?; | ||
| refuse_symlink(&target)?; | ||
| refuse_remote_library_collision()?; | ||
|
|
||
| if !target.exists() { | ||
| install_manage_tink(project_root)?; | ||
| return Ok(RefreshOutcome::Installed); | ||
| } | ||
| if !target.is_dir() { | ||
| return Err(Error::msg("Installed manage-tink is not a directory")); | ||
| } | ||
|
|
||
| let installed = skills::read_skill(&target, true)?; | ||
| skills::validate_skill_tree(&target)?; | ||
| if provenance::read(&installed)?.is_some() { | ||
| return Err(Error::msg( | ||
| "Refusing to replace manage-tink with remote provenance", | ||
| )); | ||
| } | ||
| let (_staging, embedded) = prepare_manage_tink()?; | ||
| if !skills::skill_contents_equal(&installed.path, &embedded.path)? { | ||
| library::preflight_deposit(&embedded, None)?; | ||
| catalog::preflight_deposit_skill(project_root)?; | ||
| skills::replace_embedded_verified(&embedded, &skills_root)?; | ||
| library::deposit(&embedded, None)?; | ||
| catalog::deposit_skill(project_root, "manage-tink")?; | ||
|
|
||
| let refreshed = skills::read_skill(&target, true)?; | ||
| require_current(&refreshed)?; | ||
| return Ok(RefreshOutcome::Refreshed); | ||
| } | ||
|
|
||
| library::preflight_deposit(&installed, None)?; | ||
| catalog::preflight_deposit_skill(project_root)?; | ||
| library::sync_from_installed(&installed)?; | ||
| catalog::deposit_skill(project_root, "manage-tink")?; | ||
| Ok(RefreshOutcome::Unchanged) | ||
| } | ||
|
|
||
| /// Stage the embedded skill and install it into the project via `add`. | ||
| /// | ||
| /// Uses the quiet add path so init can own the closing narrative. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After upgrading the binary while a project still has the previous receipt-free
manage-tink, putting this validation inload_project_skillsblocks every caller of the generic loader, not just the C8check/lockboundaries. In particular, project listing, verification, synchronization, and refreshing an unrelated imported skill all fail onmanage-tinkdrift before performing their requested operation; keep the currentness gate in the check and lock command paths so unrelated project operations remain usable while the explicit repair is pending.Useful? React with 👍 / 👎.