mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
hook trust metadata and enforcement (#20321)
# Why We want shared hook trust that both the app and the TUI can build on, but the metadata is only useful if runtime behavior agrees with it. This PR adds a single backend trust model for hooks so unmanaged hooks cannot run until the current definition has been reviewed, while managed hooks remain runnable and non-configurable. # What - persist `trusted_hash` alongside hook state in `config.toml` - expose `currentHash` and derived `trustStatus` through `hooks/list` - derive trust from normalized hook definitions so equivalent hooks from `config.toml` and `hooks.json` share the same trust identity - gate unmanaged hooks on trust before they enter the runnable handler set # Reviewer Notes - key file to review is `codex-rs/hooks/src/engine/discovery.rs` - the only **core** change is schema related
This commit is contained in:
committed by
GitHub
Unverified
parent
78421face0
commit
0452dca986
@@ -1559,19 +1559,13 @@ pub enum HookSource {
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl HookSource {
|
||||
/// Returns whether hooks from this source are managed and therefore not
|
||||
/// user-configurable.
|
||||
pub fn is_managed(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Self::System
|
||||
| Self::Mdm
|
||||
| Self::CloudRequirements
|
||||
| Self::LegacyManagedConfigFile
|
||||
| Self::LegacyManagedConfigMdm
|
||||
)
|
||||
}
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum HookTrustStatus {
|
||||
Managed,
|
||||
Untrusted,
|
||||
Trusted,
|
||||
Modified,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
|
||||
@@ -3996,20 +3990,6 @@ mod tests {
|
||||
use tempfile::NamedTempFile;
|
||||
use tempfile::TempDir;
|
||||
|
||||
#[test]
|
||||
fn hook_source_managedness_is_source_derived() {
|
||||
assert_eq!(HookSource::System.is_managed(), true);
|
||||
assert_eq!(HookSource::Mdm.is_managed(), true);
|
||||
assert_eq!(HookSource::CloudRequirements.is_managed(), true);
|
||||
assert_eq!(HookSource::LegacyManagedConfigFile.is_managed(), true);
|
||||
assert_eq!(HookSource::LegacyManagedConfigMdm.is_managed(), true);
|
||||
assert_eq!(HookSource::User.is_managed(), false);
|
||||
assert_eq!(HookSource::Project.is_managed(), false);
|
||||
assert_eq!(HookSource::SessionFlags.is_managed(), false);
|
||||
assert_eq!(HookSource::Plugin.is_managed(), false);
|
||||
assert_eq!(HookSource::Unknown.is_managed(), false);
|
||||
}
|
||||
|
||||
fn sorted_writable_roots(roots: Vec<WritableRoot>) -> Vec<(PathBuf, Vec<PathBuf>)> {
|
||||
let mut sorted_roots: Vec<(PathBuf, Vec<PathBuf>)> = roots
|
||||
.into_iter()
|
||||
|
||||
Reference in New Issue
Block a user