-
Notifications
You must be signed in to change notification settings - Fork 54
Golemv2 #1390
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
Merged
Golemv2 #1390
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a60b661
Add asset backend, fix imix to use them
nullmonk 43e0aa7
Add golem v2
nullmonk 99435f9
cargo fmt
nullmonk 82f540f
FIx test and cleanup a filename
nullmonk 550811b
fix, deps, remove the agent for FakeAgent
nullmonk 47dcdf8
cleanup warning in test file
nullmonk 735dae3
Format issue
nullmonk 1e5466b
Clean up Kyles nits
nullmonk 07b283d
Add empty input params for the tomes
nullmonk 883961f
Update to support changes in main
nullmonk 1671f0a
Fix to support the split of impls
nullmonk 318529a
windows newlines
nullmonk 967f524
more windows strings
nullmonk 72582db
Clean up tests
nullmonk 179e43b
cargo fmt
nullmonk 4709fdd
fix tests in mock environment
nullmonk bbb7bea
Export changes
nullmonk 1aa61f4
fix import
nullmonk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| def download_stuff_test(): | ||
| content = http.get("https://raw.githubusercontent.com/spellshift/realm/refs/heads/main/README.md") | ||
| # Allow this to work in both v1 and v2 | ||
| if type(content) != "string": | ||
| content = str(content["body"]) | ||
|
|
||
| # Mock is needed for tests | ||
| if not "# Realm" in content and not "Mock GET" in content: | ||
| print("failed to download readme") | ||
| return -1 | ||
|
|
||
| print("OKAY!") | ||
| return 0 | ||
|
|
||
| download_stuff_test() |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| def test(): | ||
| res = "" | ||
| for i in ["H", "E", "L", "L", "O"]: | ||
| res = res + i | ||
| return res | ||
|
|
||
| print("hello from an asset directory") | ||
| print(test()) | ||
| print(dir(file)) |
2 changes: 1 addition & 1 deletion
2
bin/golem_cli_test/syntax_fail.eldritch → ...cli_test_shadow/syntax_fail/main.eldritch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| def test(): | ||
| retorn "win" | ||
|
|
||
| print(test()) | ||
| print(test()) |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| [package] | ||
| name = "golemv2" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
|
|
||
| [dependencies] | ||
| clap = { workspace = true } | ||
| anyhow = { workspace = true } | ||
| pb = { workspace = true } | ||
| crossterm = { workspace = true } | ||
| walkdir = {workspace = true} | ||
| rust-embed = { workspace = true } | ||
| eldritch-core = { workspace = true } | ||
| eldritch-macros = { workspace = true } | ||
| eldritchv2 = { workspace = true, features = ["std", "stdlib"] } | ||
| eldritch-repl = { workspace = true } | ||
| eldritch-libagent = { workspace = true, features = ["fake_bindings"] } | ||
nullmonk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| eldritch-libassets = { workspace = true, features = ["stdlib"] } | ||
| eldritch-libpivot = { workspace = true, features = ["stdlib"] } | ||
| eldritch-libreport = { workspace = true, features = ["stdlib"] } | ||
| tokio.workspace = true | ||
| futures.workspace = true | ||
|
|
||
| [dev-dependencies] | ||
| assert_cmd = { workspace = true } | ||
| predicates = { workspace = true } | ||
| tempfile = { workspace = true } | ||
|
|
||
| [target.'cfg(target_os = "windows")'.build-dependencies] | ||
| static_vcruntime = { workspace = true } | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // This file defines DirectoryAssetBackend which is compatible with StdAssetLibrary | ||
| use alloc::borrow::Cow; | ||
| use alloc::vec::Vec; | ||
| use anyhow::anyhow; | ||
| use core::fmt::Debug; | ||
| use eldritchv2::assets::std::AssetBackend; | ||
| use std::fs; | ||
| use std::path::PathBuf; | ||
|
|
||
| const MAX_RECURSION_DEPTH: usize = 64; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct DirectoryAssetBackend { | ||
| root: PathBuf, | ||
| } | ||
|
|
||
| // An asset backend that reads from the local filesystem | ||
| impl DirectoryAssetBackend { | ||
| /// Creates a new asset backend rooted at the given directory path. | ||
| /// | ||
| /// # Errors | ||
| /// Returns a String error if the path does not exist or is not a directory. | ||
| pub fn new(directory_name: &str) -> anyhow::Result<Self> { | ||
| let root = PathBuf::from(directory_name); | ||
| if !root.exists() { | ||
| return Err(anyhow!("Directory not found: {}", directory_name)); | ||
| } | ||
| if !root.is_dir() { | ||
| return Err(anyhow!("Path is not a directory: {}", directory_name)); | ||
| } | ||
|
|
||
| // Canonicalize the path to resolve symlinks and '..' segments, | ||
| // which helps in later path checks. | ||
| let canonical_root = root | ||
| .canonicalize() | ||
| .map_err(|e| anyhow!("Failed to canonicalize path {}: {}", directory_name, e))?; | ||
|
|
||
| Ok(DirectoryAssetBackend { | ||
| root: canonical_root, | ||
| }) | ||
| } | ||
|
|
||
| /// Safely constructs the full, canonical path to the requested file. | ||
| /// Returns `None` if the path attempts to leave the root directory. | ||
| fn get_safe_path(&self, file_path: &str) -> Option<PathBuf> { | ||
| // 1. Join the root and the relative file path. | ||
| let mut path = self.root.clone(); | ||
| path.push(file_path); | ||
|
|
||
| let canonical_path = match path.canonicalize() { | ||
| Ok(p) => p, | ||
| // If canonicalize fails (e.g., file doesn't exist), we treat it as not found. | ||
| Err(_) => return None, | ||
| }; | ||
|
|
||
| // Ensure the canonical path starts with the canonical root. | ||
| // If it doesn't, the path contained '..' segments that successfully escaped the root. | ||
| if !canonical_path.starts_with(&self.root) { | ||
| // Path traversal attempt detected | ||
| return None; | ||
| } | ||
|
|
||
| Some(canonical_path) | ||
| } | ||
| } | ||
|
|
||
| // Implementing AssetBackend for DirectoryAssetBackend | ||
| impl AssetBackend for DirectoryAssetBackend { | ||
| fn get(&self, file_path: &str) -> anyhow::Result<Vec<u8>> { | ||
| let safe_path = self | ||
| .get_safe_path(file_path) | ||
| .ok_or(anyhow::anyhow!("invalid file path"))?; | ||
| // The path is safe and exists. Read the contents. | ||
| let data = fs::read(&safe_path)?; | ||
| Ok(data) | ||
| } | ||
|
|
||
| fn assets(&self) -> Vec<Cow<'static, str>> { | ||
| walkdir::WalkDir::new(&self.root) | ||
| .max_depth(MAX_RECURSION_DEPTH) | ||
| .into_iter() | ||
| .filter_map(|e| e.ok()) | ||
| .filter(|entry| entry.file_type().is_file()) | ||
| .filter_map(|entry| { | ||
| entry | ||
| .path() | ||
| .strip_prefix(&self.root) | ||
| .ok() // Get Ok(RelPath), discard Err | ||
| .and_then(|rel_path| rel_path.to_str()) // Get Some(str), discard None | ||
| .map(|s| Cow::Owned(s.to_string())) | ||
| }) | ||
| .collect() | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.