Skip to content

feat: generate protected path policy - #18

Merged
furedea merged 1 commit into
mainfrom
feat/generate-protected-paths
May 19, 2026
Merged

furedea merged 1 commit into
mainfrom
feat/generate-protected-paths

Conversation

@furedea

@furedea furedea commented May 19, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings May 19, 2026 00:54
@furedea
furedea merged commit 725c04c into main May 19, 2026
13 checks passed
@furedea
furedea deleted the feat/generate-protected-paths branch May 19, 2026 00:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new protection module and a corresponding generate-codex-config-fragment CLI subcommand that emits a TOML fragment describing the Codex "guarded filesystem" policy. The policy enumerates harness hook files (under agents/hooks and codex/hooks) plus a fixed list of home-directory configuration files, and assigns them all "read" permission alongside a glob_scan_max_depth setting.

Changes:

  • Introduce src/protection.rs with protected_paths, codex_config_fragment, and write_codex_config_fragment, plus two unit tests.
  • Wire the new module into lib.rs and add a GenerateCodexConfigFragment CLI subcommand in cli.rs.
  • Document the new subcommand in the README usage example.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
src/protection.rs New module that discovers harness files and renders the guarded-filesystem TOML fragment.
src/lib.rs Registers the new protection module.
src/cli.rs Adds the GenerateCodexConfigFragment subcommand and dispatch wiring.
README.md Documents the new generate-codex-config-fragment CLI invocation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/protection.rs
Comment on lines +30 to +32
pub fn protected_paths(source: &Path) -> Result<Vec<String>> {
let agent_hooks = relative_files(&source.join("agents/hooks"))?;
let codex_hooks = relative_files(&source.join("codex/hooks"))?;
Comment thread src/protection.rs
Comment on lines +64 to +90
fn home_agent_hook_paths(paths: &[String]) -> Vec<String> {
paths
.iter()
.map(|path| format!("~/.claude/hooks/{path}"))
.collect()
}

fn home_codex_hook_paths(paths: &[String]) -> Vec<String> {
paths
.iter()
.map(|path| format!("~/.codex/hooks/{path}"))
.collect()
}

fn source_agent_hook_paths(source: &Path, paths: &[String]) -> Vec<String> {
paths
.iter()
.map(|path| source.join("agents/hooks").join(path).display().to_string())
.collect()
}

fn source_codex_hook_paths(source: &Path, paths: &[String]) -> Vec<String> {
paths
.iter()
.map(|path| source.join("codex/hooks").join(path).display().to_string())
.collect()
}
Comment thread src/protection.rs
Comment on lines +20 to +25
let mut content = String::from("[permissions.guarded.filesystem]\n");

for path in protected_paths(source)? {
content.push_str(&format!("\"{}\" = \"read\"\n", toml_escape(&path)));
}
content.push_str(&format!("glob_scan_max_depth = {GLOB_SCAN_MAX_DEPTH}\n"));
Comment thread src/protection.rs
Comment on lines +52 to +62
fn relative_files(root: &Path) -> Result<Vec<String>> {
fs_ops::regular_files(root)?
.into_iter()
.map(|path| {
let relative = path
.strip_prefix(root)
.with_context(|| format!("failed to strip prefix {}", root.display()))?;
Ok(relative.to_string_lossy().replace('\\', "/"))
})
.collect()
}
Comment thread src/protection.rs
}

fn toml_escape(value: &str) -> String {
value.replace('\\', "\\\\").replace('"', "\\\"")
Comment thread src/protection.rs
Comment on lines +37 to +47
paths.extend([
"~/.claude/CLAUDE.md".to_string(),
"~/.claude/rules/forbidden_commands.json".to_string(),
"~/.claude/settings.json".to_string(),
"~/.codex/AGENTS.md".to_string(),
"~/.codex/hooks.json".to_string(),
"~/.codex/rules/default.rules".to_string(),
]);
paths.extend(source_agent_hook_paths(source, &agent_hooks));
paths.extend(source_codex_hook_paths(source, &codex_hooks));
paths.push(source.join("agents/AGENTS.md").display().to_string());
Comment thread src/protection.rs
Comment on lines +130 to +142
fn codex_config_fragment_writes_guarded_filesystem_toml() -> Result<()> {
let root = test_root("codex_config_fragment_writes_guarded_filesystem_toml")?;
write_minimal_source(&root)?;

let content = codex_config_fragment(&root)?;

assert!(content.contains("[permissions.guarded.filesystem]"));
assert!(content.contains("\"~/.claude/hooks/guard.sh\" = \"read\""));
assert!(content.contains("glob_scan_max_depth = 5"));

std::fs::remove_dir_all(root)?;
Ok(())
}
furedea added a commit that referenced this pull request May 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.2.0](agent-harness-v0.1.0...agent-harness-v0.2.0)
(2026-05-28)


### Features

* add agent harness CLI
([#6](#6))
([7f3c775](7f3c775))
* expose Nix package and Home Manager module
([#7](#7))
([137a5da](137a5da))
* generate command policy files
([#14](#14))
([9a3c7d0](9a3c7d0))
* generate hook configurations
([#17](#17))
([b5ec4d8](b5ec4d8))
* generate protected path policy
([#18](#18))
([725c04c](725c04c))
* refine agent harness command layout
([#12](#12))
([ca57421](ca57421))
* render provider skills
([#20](#20))
([e7e4a21](e7e4a21))
* **skills:** add ADR operation skill
([#30](#30))
([3d89283](3d89283))
* **skills:** add git workflow skill
([#28](#28))
([9764417](9764417))
* standardize CLI option names
([#13](#13))
([110c284](110c284))
* synthesize provider configs
([#19](#19))
([41dfb40](41dfb40))
* use file-level generated outputs
([#11](#11))
([64cf683](64cf683))
* use packaged source by default
([#32](#32))
([6c44f34](6c44f34))


### Bug Fixes

* avoid git in json syntax test
([#26](#26))
([d64b992](d64b992))
* install generated codex guarded config
([#25](#25))
([1647802](1647802))
* keep user tools visible in dev shell
([#23](#23))
([9a572e6](9a572e6))
* protect installed harness paths only
([#27](#27))
([9911632](9911632))
* **release:** use token for release PRs
([#38](#38))
([31c010e](31c010e))
* validate skill patch descriptions
([#33](#33))
([519a9ad](519a9ad))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: Kaito Shigyo / 執行凱斗 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants