diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..c424bdc --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1504 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "android_system_properties" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cc" +version = "1.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "005ec2760ca554fae18df7a11195552ec576cd665632a881bc011d5bb2fd4d80" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cpufeatures", + "rand_core", +] + +[[package]] +name = "chrono" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +dependencies = [ + "iana-time-zone", + "num-traits", + "serde", + "windows-link", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "rand_core", + "wasm-bindgen", +] + +[[package]] +name = "grokboy" +version = "0.1.0" +dependencies = [ + "anyhow", + "grokboy-core", + "serde_json", + "tokio", +] + +[[package]] +name = "grokboy-core" +version = "0.1.0" +dependencies = [ + "anyhow", + "chrono", + "futures-util", + "reqwest", + "serde", + "serde_json", + "thiserror", + "tokio", + "uuid", +] + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hyper" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b501faa50e7a26c3d3560ca625132f4078a17771f4810baf70475ae48cbe43" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" + +[[package]] +name = "icu_properties" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" + +[[package]] +name = "icu_provider" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "ipnet" +version = "2.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791930b43c0d5973160d90a8f3894509f2b273430f5c5c73b668636d0287c5c0" + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce57d20d1ea864ce2ac172ab472d409214f4fd359f0b2a2775abdf522e2af99e" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "log" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "mio" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quinn" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04759210543be93709136e28212294a659ef5001836ff4eab4d663e4529bba83" +dependencies = [ + "bytes", + "getrandom 0.4.3", + "lru-slab", + "rand", + "rand_pcg", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35a133f956daabe89a61a685c2649f13d82d5aa4bd5d12d1277e1072a21c0694" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.61.2", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_pcg" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a" +dependencies = [ + "rand_core", +] + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tokio-util", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "rustls" +version = "0.23.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6725596c3f2c3a0aef021139e145d4eafe314a6623e4680ca83852b2c67ab2ba" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "serde_json" +version = "1.0.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba467056f1b547ed52077911161fc86985becbc60e8e1857c8a144dab0def891" + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12df2e0110f65b775f769bb17ef989067a1d931b2eb822bd4346631eeada89f9" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "tinystr" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cf0ded5c4e56918d8f8a339e1bb67d038d3bc6d144ac407904015ba2e4cde9b" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c85f2c3ef0b1cd58b36682f4b17aaa995f0e5db534d85692b4903abce21f67" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494815d09bf52b5548659851081238f0ca39ff638363907596da739561c62c52" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "url", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "uuid" +version = "1.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ef6dac1e96601b4fb3acccccff2139741fcb757cb9a36089bf5be91cfb285ce" +dependencies = [ + "getrandom 0.4.3", + "js-sys", + "serde_core", + "wasm-bindgen", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aecb87a33d3b0c5e3b7aa46336eaf486cffafbd281b195e4c8b80d50df2351bf" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ef4c5d3d2cdf5c54f4231181768f5510842e350db025faf1f7163b1030ed928" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a690d511e3c1a8b3a55e33511e3c2c00c78415cd23650f32b808627f5696b9ed" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "411e4887f0071ef2d2164a9d5fdf2d20efbef78fccd3a78b0c10a1dc5295e48a" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.5", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81941cd78d0c92026c33e5e01312845a4cb1e9af3407f9134b100dd03144103e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-streams" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65" +dependencies = [ + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "web-sys" +version = "0.3.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fbddc4a036f00ec4f18c83445bd3115cb306a91da554919a099d9222fe4a7f8" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "yoke" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/Cargo.toml b/Cargo.toml index 134315d..5515574 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,11 @@ authors = ["Daniel Wang"] [workspace.dependencies] anyhow = "1" +chrono = { version = "0.4", default-features = false, features = ["clock", "std", "serde"] } futures-util = "0.3" reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls", "stream"] } serde = { version = "1", features = ["derive"] } serde_json = "1" -tokio = { version = "1", features = ["rt-multi-thread", "macros", "io-std", "io-util", "sync"] } thiserror = "2" +tokio = { version = "1", features = ["rt-multi-thread", "macros", "io-std", "io-util", "sync", "process", "time", "fs"] } +uuid = { version = "1", features = ["v4", "serde"] } diff --git a/README.md b/README.md index 94118ab..39bc051 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # GrokBoy -Minimal local **GrokBot-like** CLI agent. Phase **P0**: streaming chat only. +Minimal local **GrokBot-like** CLI agent. Phase **P1**: tools + ReAct + sessions. ## Status | Phase | Status | |-------|--------| | P0 streaming chat | done | -| P1 shell / files + ReAct | next | +| P1 shell / files + ReAct | done | | P2 completion / loop guard | planned | | P3 browser (Playwright) | later | @@ -19,7 +19,7 @@ No Docker desktop, no Codex/LazyBoy fork. export GROKBOY_API_KEY=your_key # or XAI_API_KEY # optional: # export GROKBOY_BASE_URL=https://api.x.ai/v1 -# export GROKBOY_MODEL=grok-4 +# export GROKBOY_MODEL=grok-4.6 cd ~/GrokBoy cargo run -p grokboy -- chat @@ -27,23 +27,30 @@ cargo run -p grokboy -- chat ## Commands -- `grokboy chat` — interactive streaming chat +- `grokboy chat` — interactive streaming chat (no tools) +- `grokboy run ""` — one-shot agent with tools (`shell`, `list_dir`, `read_file`, `write_file`) +- `grokboy run --session ""` — continue a saved session +- `grokboy smoke` — offline tool checks (no API key required) - `grokboy help` +Sessions are stored under `~/.grokboy/sessions/.json`. + ## 繁體中文 -本機終端機聊天 bot。P0 只能對話;P1 才會加讀寫檔與 shell。 +本機終端機 coding assistant。P1 已支援讀寫檔、列目錄、shell,以及多輪 tool-calling。 ```bash export GROKBOY_API_KEY=你的金鑰 cd ~/GrokBoy +cargo run -p grokboy -- smoke +cargo run -p grokboy -- run "列出目前目錄並讀 README.md" cargo run -p grokboy -- chat ``` ## Layout ``` -crates/grokboy-core/ # config + streaming client +crates/grokboy-core/ # config, model, tools, agent, session crates/grokboy/ # CLI binary docs/ACCEPTANCE.md ``` diff --git a/crates/grokboy-core/Cargo.toml b/crates/grokboy-core/Cargo.toml index 73064ad..39b9d32 100644 --- a/crates/grokboy-core/Cargo.toml +++ b/crates/grokboy-core/Cargo.toml @@ -3,13 +3,15 @@ name = "grokboy-core" version.workspace = true edition.workspace = true license.workspace = true -description = "Minimal GrokBot-like agent core (chat loop)" +description = "Minimal GrokBot-like agent core (chat + tools + ReAct)" [dependencies] anyhow.workspace = true +chrono.workspace = true futures-util.workspace = true reqwest.workspace = true serde.workspace = true serde_json.workspace = true thiserror.workspace = true tokio.workspace = true +uuid.workspace = true diff --git a/crates/grokboy-core/src/agent.rs b/crates/grokboy-core/src/agent.rs new file mode 100644 index 0000000..ca55370 --- /dev/null +++ b/crates/grokboy-core/src/agent.rs @@ -0,0 +1,68 @@ +//! Multi-step OpenAI-compatible tool-calling ReAct loop. + +use crate::config::Config; +use crate::model::{ChatMessage, chat_completion}; +use crate::tools::{ToolContext, execute_tool, tool_definitions}; +use anyhow::Result; + +pub const DEFAULT_MAX_ROUNDS: usize = 12; + +pub const AGENT_SYSTEM: &str = "\ +You are GrokBoy, a concise local coding assistant with tools. +Use tools when they help solve the task; otherwise answer directly. +Prefer short, clear answers. Traditional Chinese is welcome when the user writes in Chinese. +Available tools: shell, list_dir, read_file, write_file. +Do not invent tool results — call the tools. Stop when you can give a final answer."; + +/// Run the agent loop until the model returns text without tool_calls or max rounds. +/// Appends all intermediate messages (assistant tool_calls + tool results + final) to `messages`. +/// Returns the final assistant text (may be empty if stopped on round limit with only tools). +pub async fn run_agent( + config: &Config, + messages: &mut Vec, + tool_ctx: &ToolContext, + max_rounds: usize, +) -> Result { + let tools = tool_definitions(); + let mut last_text = String::new(); + + for _round in 0..max_rounds { + let reply = chat_completion(config, messages, Some(&tools)).await?; + let tool_calls = reply.tool_calls.clone().unwrap_or_default(); + + if tool_calls.is_empty() { + last_text = reply.text().to_string(); + messages.push(reply); + return Ok(last_text); + } + + // Keep any content the model sent alongside tool_calls. + if let Some(c) = reply.content.as_ref().filter(|s| !s.is_empty()) { + last_text = c.clone(); + } + messages.push(reply); + + for call in &tool_calls { + let result = execute_tool(tool_ctx, &call.function.name, &call.function.arguments).await; + messages.push(ChatMessage::tool(&call.id, result)); + } + } + + Ok(last_text) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn system_prompt_mentions_tools() { + assert!(AGENT_SYSTEM.contains("shell")); + assert!(AGENT_SYSTEM.contains("Traditional Chinese") || AGENT_SYSTEM.contains("Chinese")); + } + + #[test] + fn default_max_rounds_is_12() { + assert_eq!(DEFAULT_MAX_ROUNDS, 12); + } +} diff --git a/crates/grokboy-core/src/config.rs b/crates/grokboy-core/src/config.rs index c8000ed..7a4c242 100644 --- a/crates/grokboy-core/src/config.rs +++ b/crates/grokboy-core/src/config.rs @@ -22,7 +22,7 @@ impl Config { let base_url = env::var("GROKBOY_BASE_URL") .or_else(|_| env::var("OPENAI_BASE_URL")) .unwrap_or_else(|_| "https://api.x.ai/v1".into()); - let model = env::var("GROKBOY_MODEL").unwrap_or_else(|_| "grok-4".into()); + let model = env::var("GROKBOY_MODEL").unwrap_or_else(|_| "grok-4.6".into()); Ok(Self { api_key, base_url: base_url.trim_end_matches('/').to_string(), @@ -35,13 +35,22 @@ impl Config { mod tests { use super::*; + #[test] + fn default_model_is_grok_4_6() { + let cfg = Config { + api_key: "x".into(), + base_url: "https://api.x.ai/v1".into(), + model: "grok-4.6".into(), + }; + assert_eq!(cfg.model, "grok-4.6"); + } + #[test] fn rejects_missing_key() { - // Ensure we don't panic; actual env may have keys in CI — just type-check path. let _ = Config { api_key: "x".into(), base_url: "https://api.x.ai/v1".into(), - model: "grok-4".into(), + model: "grok-4.6".into(), }; } } diff --git a/crates/grokboy-core/src/lib.rs b/crates/grokboy-core/src/lib.rs index c8052b8..abe5fab 100644 --- a/crates/grokboy-core/src/lib.rs +++ b/crates/grokboy-core/src/lib.rs @@ -1,7 +1,13 @@ -//! GrokBoy core: config + OpenAI-compatible streaming chat. +//! GrokBoy core: config, streaming chat, tools, ReAct agent, sessions. +mod agent; mod config; mod model; +mod session; +mod tools; +pub use agent::{AGENT_SYSTEM, DEFAULT_MAX_ROUNDS, run_agent}; pub use config::Config; -pub use model::{ChatMessage, Role, stream_chat}; +pub use model::{ChatMessage, FunctionCall, Role, ToolCall, chat_completion, stream_chat}; +pub use session::{Session, load_or_create, load_session, save_session, sessions_dir}; +pub use tools::{ToolContext, execute_tool, tool_definitions}; diff --git a/crates/grokboy-core/src/model.rs b/crates/grokboy-core/src/model.rs index 1319a5c..fcef68e 100644 --- a/crates/grokboy-core/src/model.rs +++ b/crates/grokboy-core/src/model.rs @@ -2,7 +2,7 @@ use crate::config::Config; use anyhow::{Context, Result, anyhow}; use futures_util::StreamExt; use serde::{Deserialize, Serialize}; -use serde_json::json; +use serde_json::{Value, json}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] @@ -10,33 +10,91 @@ pub enum Role { System, User, Assistant, + Tool, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct FunctionCall { + pub name: String, + /// JSON-encoded argument object as a string (OpenAI-compatible). + pub arguments: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ToolCall { + pub id: String, + #[serde(rename = "type")] + pub kind: String, + pub function: FunctionCall, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ChatMessage { pub role: Role, - pub content: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub content: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub tool_calls: Option>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub tool_call_id: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub name: Option, } impl ChatMessage { pub fn system(content: impl Into) -> Self { Self { role: Role::System, - content: content.into(), + content: Some(content.into()), + tool_calls: None, + tool_call_id: None, + name: None, } } + pub fn user(content: impl Into) -> Self { Self { role: Role::User, - content: content.into(), + content: Some(content.into()), + tool_calls: None, + tool_call_id: None, + name: None, } } + pub fn assistant(content: impl Into) -> Self { Self { role: Role::Assistant, - content: content.into(), + content: Some(content.into()), + tool_calls: None, + tool_call_id: None, + name: None, } } + + pub fn assistant_tool_calls(content: Option, tool_calls: Vec) -> Self { + Self { + role: Role::Assistant, + content, + tool_calls: Some(tool_calls), + tool_call_id: None, + name: None, + } + } + + pub fn tool(tool_call_id: impl Into, content: impl Into) -> Self { + Self { + role: Role::Tool, + content: Some(content.into()), + tool_calls: None, + tool_call_id: Some(tool_call_id.into()), + name: None, + } + } + + pub fn text(&self) -> &str { + self.content.as_deref().unwrap_or("") + } } #[derive(Debug, Deserialize)] @@ -60,8 +118,20 @@ struct ApiErrorBody { message: Option, } +#[derive(Debug, Deserialize)] +struct CompletionResponse { + choices: Option>, + error: Option, +} + +#[derive(Debug, Deserialize)] +struct CompletionChoice { + message: Option, + finish_reason: Option, +} + /// Stream a chat completion; invoke `on_delta` for each text piece. -/// Returns the full assistant text. +/// Returns the full assistant text. (No tools — used by interactive `chat`.) pub async fn stream_chat( config: &Config, messages: &[ChatMessage], @@ -141,6 +211,71 @@ pub async fn stream_chat( Ok(full) } +/// Non-streaming chat completion, optionally with tool definitions. +/// Returns the assistant message (may include `tool_calls`). +pub async fn chat_completion( + config: &Config, + messages: &[ChatMessage], + tools: Option<&Value>, +) -> Result { + let client = reqwest::Client::new(); + let url = format!("{}/chat/completions", config.base_url); + + let mut body = json!({ + "model": config.model, + "messages": messages, + "stream": false, + }); + if let Some(tools) = tools { + body["tools"] = tools.clone(); + body["tool_choice"] = json!("auto"); + } + + let response = client + .post(&url) + .bearer_auth(&config.api_key) + .header("content-type", "application/json") + .json(&body) + .send() + .await + .context("request to chat completions failed")?; + + if !response.status().is_success() { + let status = response.status(); + let text = response.text().await.unwrap_or_default(); + return Err(anyhow!("chat completions HTTP {status}: {text}")); + } + + let parsed: CompletionResponse = response + .json() + .await + .context("parsing chat completions JSON")?; + + if let Some(err) = parsed.error { + return Err(anyhow!( + "provider error: {}", + err.message.unwrap_or_else(|| "unknown".into()) + )); + } + + let choice = parsed + .choices + .and_then(|mut c| c.pop()) + .ok_or_else(|| anyhow!("no choices in completion response"))?; + + let mut message = choice + .message + .ok_or_else(|| anyhow!("empty message in completion choice"))?; + + // Normalize: ensure assistant role even if provider omits it. + if message.role != Role::Assistant && message.role != Role::Tool { + message.role = Role::Assistant; + } + + let _ = choice.finish_reason; + Ok(message) +} + #[cfg(test)] mod tests { use super::*; @@ -151,5 +286,34 @@ mod tests { let v = serde_json::to_value(&msg).unwrap(); assert_eq!(v["role"], "user"); assert_eq!(v["content"], "hi"); + assert!(v.get("tool_calls").is_none()); + } + + #[test] + fn tool_message_serializes() { + let msg = ChatMessage::tool("call_1", r#"{"ok":true}"#); + let v = serde_json::to_value(&msg).unwrap(); + assert_eq!(v["role"], "tool"); + assert_eq!(v["tool_call_id"], "call_1"); + assert_eq!(v["content"], r#"{"ok":true}"#); + } + + #[test] + fn assistant_tool_calls_serialize() { + let msg = ChatMessage::assistant_tool_calls( + None, + vec![ToolCall { + id: "c1".into(), + kind: "function".into(), + function: FunctionCall { + name: "list_dir".into(), + arguments: r#"{"path":"."}"#.into(), + }, + }], + ); + let v = serde_json::to_value(&msg).unwrap(); + assert_eq!(v["role"], "assistant"); + assert_eq!(v["tool_calls"][0]["function"]["name"], "list_dir"); + assert!(v.get("content").is_none() || v["content"].is_null()); } } diff --git a/crates/grokboy-core/src/session.rs b/crates/grokboy-core/src/session.rs new file mode 100644 index 0000000..f09e90f --- /dev/null +++ b/crates/grokboy-core/src/session.rs @@ -0,0 +1,138 @@ +//! Persist agent sessions under ~/.grokboy/sessions/. + +use crate::model::ChatMessage; +use anyhow::{Context, Result, anyhow}; +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; +use std::fs; +use std::path::{Path, PathBuf}; +use uuid::Uuid; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Session { + pub id: String, + pub created_at: DateTime, + pub updated_at: DateTime, + pub cwd: PathBuf, + pub messages: Vec, +} + +impl Session { + pub fn new(cwd: impl Into) -> Self { + let now = Utc::now(); + Self { + id: Uuid::new_v4().to_string(), + created_at: now, + updated_at: now, + cwd: cwd.into(), + messages: Vec::new(), + } + } + + pub fn touch(&mut self) { + self.updated_at = Utc::now(); + } + + pub fn push(&mut self, msg: ChatMessage) { + self.messages.push(msg); + self.touch(); + } +} + +pub fn sessions_dir() -> Result { + let home = dirs_home().ok_or_else(|| anyhow!("cannot resolve home directory"))?; + Ok(home.join(".grokboy").join("sessions")) +} + +fn dirs_home() -> Option { + std::env::var_os("HOME") + .or_else(|| std::env::var_os("USERPROFILE")) + .map(PathBuf::from) +} + +pub fn ensure_sessions_dir() -> Result { + let dir = sessions_dir()?; + fs::create_dir_all(&dir).with_context(|| format!("create {}", dir.display()))?; + Ok(dir) +} + +pub fn session_path(id: &str) -> Result { + validate_session_id(id)?; + Ok(ensure_sessions_dir()?.join(format!("{id}.json"))) +} + +fn validate_session_id(id: &str) -> Result<()> { + if id.is_empty() || id.contains('/') || id.contains('\\') || id.contains("..") { + return Err(anyhow!("invalid session id")); + } + Ok(()) +} + +pub fn save_session(session: &Session) -> Result { + let path = session_path(&session.id)?; + save_session_to(session, &path)?; + Ok(path) +} + +pub fn save_session_to(session: &Session, path: &Path) -> Result<()> { + if let Some(parent) = path.parent() { + fs::create_dir_all(parent).with_context(|| format!("create {}", parent.display()))?; + } + let tmp = path.with_extension("json.tmp"); + let data = serde_json::to_vec_pretty(session).context("serialize session")?; + fs::write(&tmp, &data).with_context(|| format!("write {}", tmp.display()))?; + fs::rename(&tmp, path).with_context(|| format!("rename to {}", path.display()))?; + Ok(()) +} + +pub fn load_session(id: &str) -> Result { + let path = session_path(id)?; + load_session_from(&path) +} + +pub fn load_session_from(path: &Path) -> Result { + let data = fs::read(path).with_context(|| format!("read session {}", path.display()))?; + let session: Session = serde_json::from_slice(&data).context("parse session JSON")?; + Ok(session) +} + +pub fn load_or_create(session_id: Option<&str>, cwd: &Path) -> Result { + match session_id { + Some(id) => load_session(id), + None => Ok(Session::new(cwd)), + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::model::ChatMessage; + + #[test] + fn save_and_load_roundtrip() { + let stamp = Uuid::new_v4(); + let dir = std::env::temp_dir().join(format!("grokboy-sess-{stamp}")); + fs::create_dir_all(&dir).unwrap(); + let path = dir.join("sess.json"); + + let mut s = Session::new(dir.join("proj")); + s.push(ChatMessage::system("sys")); + s.push(ChatMessage::user("hi")); + save_session_to(&s, &path).unwrap(); + assert!(path.exists()); + + let loaded = load_session_from(&path).unwrap(); + assert_eq!(loaded.id, s.id); + assert_eq!(loaded.messages.len(), 2); + assert_eq!(loaded.messages[1].text(), "hi"); + + let _ = fs::remove_dir_all(&dir); + } + + #[test] + fn rejects_bad_session_id() { + assert!(validate_session_id("../x").is_err()); + assert!(validate_session_id("a/b").is_err()); + assert!(validate_session_id("ok-id").is_ok()); + } +} diff --git a/crates/grokboy-core/src/tools.rs b/crates/grokboy-core/src/tools.rs new file mode 100644 index 0000000..5ca459d --- /dev/null +++ b/crates/grokboy-core/src/tools.rs @@ -0,0 +1,406 @@ +//! Built-in tools: shell, list_dir, read_file, write_file. + +use anyhow::{Context, Result, anyhow}; +use serde_json::{Value, json}; +use std::path::{Component, Path, PathBuf}; +use std::process::Stdio; +use std::time::Duration; +use tokio::process::Command; + +pub const MAX_READ_BYTES: usize = 256 * 1024; +pub const SHELL_TIMEOUT_SECS: u64 = 30; + +/// Runtime context for tool execution. +#[derive(Debug, Clone)] +pub struct ToolContext { + /// Default working directory for relative paths / shell. + pub cwd: PathBuf, + /// Optional workspace root; paths outside it are rejected when set. + pub workspace_root: Option, +} + +impl ToolContext { + pub fn new(cwd: impl Into) -> Self { + let cwd = cwd.into(); + Self { + cwd: cwd.clone(), + workspace_root: Some(cwd), + } + } + + pub fn with_workspace(mut self, root: Option) -> Self { + self.workspace_root = root; + self + } +} + +/// OpenAI-compatible tool definitions for chat completions. +pub fn tool_definitions() -> Value { + json!([ + { + "type": "function", + "function": { + "name": "shell", + "description": "Run a shell command. Captures stdout, stderr, and exit code. Timeout 30s. cwd defaults to the session working directory.", + "parameters": { + "type": "object", + "properties": { + "command": { "type": "string", "description": "Shell command to run" }, + "cwd": { "type": "string", "description": "Optional working directory" } + }, + "required": ["command"] + } + } + }, + { + "type": "function", + "function": { + "name": "list_dir", + "description": "List entries in a directory (names only, sorted).", + "parameters": { + "type": "object", + "properties": { + "path": { "type": "string", "description": "Directory path (relative to cwd or absolute)" } + }, + "required": ["path"] + } + } + }, + { + "type": "function", + "function": { + "name": "read_file", + "description": "Read a text file (max 256KB). Returns contents as UTF-8 (lossy).", + "parameters": { + "type": "object", + "properties": { + "path": { "type": "string", "description": "File path" } + }, + "required": ["path"] + } + } + }, + { + "type": "function", + "function": { + "name": "write_file", + "description": "Write text to a file, creating parent directories as needed.", + "parameters": { + "type": "object", + "properties": { + "path": { "type": "string", "description": "File path" }, + "content": { "type": "string", "description": "File contents" } + }, + "required": ["path", "content"] + } + } + } + ]) +} + +/// Resolve a user-supplied path against cwd and optionally enforce workspace_root. +pub fn resolve_path(ctx: &ToolContext, path: &str) -> Result { + let raw = Path::new(path); + let joined = if raw.is_absolute() { + raw.to_path_buf() + } else { + ctx.cwd.join(raw) + }; + + // Normalize without requiring the path to exist (for write_file parents). + let resolved = normalize_path(&joined); + + if let Some(root) = &ctx.workspace_root { + let root_norm = normalize_path(root); + if !resolved.starts_with(&root_norm) { + return Err(anyhow!( + "path {:?} is outside workspace root {:?}", + resolved, + root_norm + )); + } + } + + Ok(resolved) +} + +fn normalize_path(path: &Path) -> PathBuf { + let mut out = PathBuf::new(); + for comp in path.components() { + match comp { + Component::Prefix(p) => out.push(p.as_os_str()), + Component::RootDir => out.push(Component::RootDir.as_os_str()), + Component::CurDir => {} + Component::ParentDir => { + out.pop(); + } + Component::Normal(c) => out.push(c), + } + } + out +} + +pub async fn execute_tool(ctx: &ToolContext, name: &str, arguments_json: &str) -> String { + match execute_tool_inner(ctx, name, arguments_json).await { + Ok(v) => v.to_string(), + Err(e) => json!({ "error": format!("{e:#}") }).to_string(), + } +} + +async fn execute_tool_inner(ctx: &ToolContext, name: &str, arguments_json: &str) -> Result { + let args: Value = serde_json::from_str(arguments_json) + .with_context(|| format!("invalid tool arguments JSON for {name}"))?; + + match name { + "shell" => tool_shell(ctx, &args).await, + "list_dir" => tool_list_dir(ctx, &args).await, + "read_file" => tool_read_file(ctx, &args).await, + "write_file" => tool_write_file(ctx, &args).await, + other => Err(anyhow!("unknown tool: {other}")), + } +} + +async fn tool_shell(ctx: &ToolContext, args: &Value) -> Result { + let command = args + .get("command") + .and_then(|v| v.as_str()) + .ok_or_else(|| anyhow!("shell: missing 'command'"))?; + + let cwd = if let Some(c) = args.get("cwd").and_then(|v| v.as_str()) { + resolve_path(ctx, c)? + } else { + ctx.cwd.clone() + }; + + if !cwd.is_dir() { + return Err(anyhow!("shell cwd is not a directory: {}", cwd.display())); + } + + let child = Command::new("sh") + .arg("-c") + .arg(command) + .current_dir(&cwd) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .kill_on_drop(true) + .spawn() + .with_context(|| format!("failed to spawn shell for: {command}"))?; + + let timeout = Duration::from_secs(SHELL_TIMEOUT_SECS); + let output = match tokio::time::timeout(timeout, child.wait_with_output()).await { + Ok(Ok(out)) => out, + Ok(Err(e)) => return Err(anyhow!("shell wait failed: {e}")), + Err(_) => { + return Ok(json!({ + "error": format!("command timed out after {SHELL_TIMEOUT_SECS}s"), + "timed_out": true, + "command": command, + })); + } + }; + + let stdout = String::from_utf8_lossy(&output.stdout).to_string(); + let stderr = String::from_utf8_lossy(&output.stderr).to_string(); + let exit_code = output.status.code().unwrap_or(-1); + + Ok(json!({ + "command": command, + "cwd": cwd.display().to_string(), + "exit_code": exit_code, + "stdout": truncate_output(&stdout, 64 * 1024), + "stderr": truncate_output(&stderr, 32 * 1024), + })) +} + +async fn tool_list_dir(ctx: &ToolContext, args: &Value) -> Result { + let path = args + .get("path") + .and_then(|v| v.as_str()) + .ok_or_else(|| anyhow!("list_dir: missing 'path'"))?; + let dir = resolve_path(ctx, path)?; + let mut rd = tokio::fs::read_dir(&dir) + .await + .with_context(|| format!("list_dir: {}", dir.display()))?; + + let mut entries = Vec::new(); + while let Some(ent) = rd.next_entry().await? { + let name = ent.file_name().to_string_lossy().to_string(); + let file_type = ent.file_type().await?; + let kind = if file_type.is_dir() { + "dir" + } else if file_type.is_symlink() { + "symlink" + } else { + "file" + }; + entries.push(json!({ "name": name, "kind": kind })); + } + entries.sort_by(|a, b| { + a["name"] + .as_str() + .unwrap_or("") + .cmp(b["name"].as_str().unwrap_or("")) + }); + + Ok(json!({ + "path": dir.display().to_string(), + "entries": entries, + })) +} + +async fn tool_read_file(ctx: &ToolContext, args: &Value) -> Result { + let path = args + .get("path") + .and_then(|v| v.as_str()) + .ok_or_else(|| anyhow!("read_file: missing 'path'"))?; + let file = resolve_path(ctx, path)?; + let meta = tokio::fs::metadata(&file) + .await + .with_context(|| format!("read_file: {}", file.display()))?; + if !meta.is_file() { + return Err(anyhow!("read_file: not a file: {}", file.display())); + } + if meta.len() as usize > MAX_READ_BYTES { + return Err(anyhow!( + "read_file: file too large ({} bytes > {} cap)", + meta.len(), + MAX_READ_BYTES + )); + } + let bytes = tokio::fs::read(&file) + .await + .with_context(|| format!("read_file: {}", file.display()))?; + let content = String::from_utf8_lossy(&bytes).to_string(); + Ok(json!({ + "path": file.display().to_string(), + "bytes": bytes.len(), + "content": content, + })) +} + +async fn tool_write_file(ctx: &ToolContext, args: &Value) -> Result { + let path = args + .get("path") + .and_then(|v| v.as_str()) + .ok_or_else(|| anyhow!("write_file: missing 'path'"))?; + let content = args + .get("content") + .and_then(|v| v.as_str()) + .ok_or_else(|| anyhow!("write_file: missing 'content'"))?; + let file = resolve_path(ctx, path)?; + if let Some(parent) = file.parent() { + tokio::fs::create_dir_all(parent) + .await + .with_context(|| format!("write_file create_dir_all: {}", parent.display()))?; + } + tokio::fs::write(&file, content.as_bytes()) + .await + .with_context(|| format!("write_file: {}", file.display()))?; + Ok(json!({ + "path": file.display().to_string(), + "bytes_written": content.len(), + })) +} + +fn truncate_output(s: &str, max: usize) -> String { + if s.len() <= max { + s.to_string() + } else { + format!( + "{}…\n[truncated {} bytes]", + &s[..max], + s.len().saturating_sub(max) + ) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use std::time::{SystemTime, UNIX_EPOCH}; + + fn temp_ctx() -> (ToolContext, PathBuf) { + let stamp = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_nanos(); + let dir = std::env::temp_dir().join(format!("grokboy-tools-{stamp}")); + std::fs::create_dir_all(&dir).unwrap(); + (ToolContext::new(dir.clone()), dir) + } + + #[tokio::test] + async fn write_read_list_shell() { + let (ctx, dir) = temp_ctx(); + + let w = execute_tool( + &ctx, + "write_file", + &json!({"path": "hello.txt", "content": "你好 GrokBoy"}).to_string(), + ) + .await; + let w: Value = serde_json::from_str(&w).unwrap(); + assert!(w.get("error").is_none(), "{w}"); + assert_eq!(w["bytes_written"], "你好 GrokBoy".len()); + + let r = execute_tool( + &ctx, + "read_file", + &json!({"path": "hello.txt"}).to_string(), + ) + .await; + let r: Value = serde_json::from_str(&r).unwrap(); + assert_eq!(r["content"], "你好 GrokBoy"); + + let l = execute_tool(&ctx, "list_dir", &json!({"path": "."}).to_string()).await; + let l: Value = serde_json::from_str(&l).unwrap(); + let names: Vec<&str> = l["entries"] + .as_array() + .unwrap() + .iter() + .map(|e| e["name"].as_str().unwrap()) + .collect(); + assert!(names.contains(&"hello.txt")); + + let s = execute_tool( + &ctx, + "shell", + &json!({"command": "echo hi && ls hello.txt"}).to_string(), + ) + .await; + let s: Value = serde_json::from_str(&s).unwrap(); + assert_eq!(s["exit_code"], 0); + assert!(s["stdout"].as_str().unwrap().contains("hi")); + + let _ = std::fs::remove_dir_all(&dir); + } + + #[tokio::test] + async fn rejects_path_traversal() { + let (ctx, dir) = temp_ctx(); + let out = execute_tool( + &ctx, + "read_file", + &json!({"path": "../outside.txt"}).to_string(), + ) + .await; + let v: Value = serde_json::from_str(&out).unwrap(); + assert!(v.get("error").is_some(), "{v}"); + let _ = std::fs::remove_dir_all(&dir); + } + + #[test] + fn tool_defs_include_four() { + let defs = tool_definitions(); + let arr = defs.as_array().unwrap(); + assert_eq!(arr.len(), 4); + let names: Vec<&str> = arr + .iter() + .map(|t| t["function"]["name"].as_str().unwrap()) + .collect(); + assert!(names.contains(&"shell")); + assert!(names.contains(&"list_dir")); + assert!(names.contains(&"read_file")); + assert!(names.contains(&"write_file")); + } +} diff --git a/crates/grokboy/Cargo.toml b/crates/grokboy/Cargo.toml index 03d6d89..1145329 100644 --- a/crates/grokboy/Cargo.toml +++ b/crates/grokboy/Cargo.toml @@ -3,7 +3,7 @@ name = "grokboy" version.workspace = true edition.workspace = true license.workspace = true -description = "GrokBoy CLI — local chat agent" +description = "GrokBoy CLI — local chat + tool agent" [[bin]] name = "grokboy" @@ -12,4 +12,5 @@ path = "src/main.rs" [dependencies] anyhow.workspace = true grokboy-core = { path = "../grokboy-core" } +serde_json.workspace = true tokio.workspace = true diff --git a/crates/grokboy/src/main.rs b/crates/grokboy/src/main.rs index 7081163..c7c6380 100644 --- a/crates/grokboy/src/main.rs +++ b/crates/grokboy/src/main.rs @@ -1,9 +1,13 @@ -use anyhow::{Context, Result}; -use grokboy_core::{ChatMessage, Config, stream_chat}; +use anyhow::{Context, Result, anyhow}; +use grokboy_core::{ + AGENT_SYSTEM, ChatMessage, Config, DEFAULT_MAX_ROUNDS, Session, ToolContext, execute_tool, + load_or_create, run_agent, save_session, stream_chat, tool_definitions, +}; +use serde_json::json; use std::io::{self, Write}; use std::process::ExitCode; -const SYSTEM: &str = "You are GrokBoy, a concise local coding assistant. Prefer clear, short answers. Traditional Chinese is welcome when the user writes in Chinese."; +const CHAT_SYSTEM: &str = "You are GrokBoy, a concise local coding assistant. Prefer clear, short answers. Traditional Chinese is welcome when the user writes in Chinese."; #[tokio::main] async fn main() -> ExitCode { @@ -15,37 +19,51 @@ async fn main() -> ExitCode { } async fn run() -> Result<()> { - let mut args = std::env::args().skip(1); - let cmd = args.next().unwrap_or_else(|| "help".into()); + let mut args = std::env::args().skip(1).collect::>(); + if args.is_empty() { + print_help(); + return Ok(()); + } + let cmd = args.remove(0); match cmd.as_str() { "chat" => cmd_chat().await, + "run" => cmd_run(&args).await, + "smoke" => cmd_smoke().await, "version" | "-V" | "--version" => { println!("grokboy {}", env!("CARGO_PKG_VERSION")); Ok(()) } - "help" | "-h" | "--help" | _ => { + "help" | "-h" | "--help" => { print_help(); Ok(()) } + other => { + eprintln!("unknown command: {other}\n"); + print_help(); + Err(anyhow!("unknown command")) + } } } fn print_help() { println!( "\ -GrokBoy — minimal local CLI agent (P0: chat) +GrokBoy — minimal local CLI agent (P1: tools + ReAct) USAGE: - grokboy chat Interactive streaming chat + grokboy chat Interactive streaming chat (no tools) + grokboy run \"\" One-shot agent with tools + grokboy run --session \"...\" Continue a saved session + grokboy smoke Offline tool checks (no API key required) grokboy version grokboy help ENV: GROKBOY_API_KEY API key (or XAI_API_KEY / OPENAI_API_KEY) GROKBOY_BASE_URL default https://api.x.ai/v1 - GROKBOY_MODEL default grok-4 + GROKBOY_MODEL default grok-4.6 -P0 has no tools yet. P1 will add shell/files + ReAct. +Sessions are stored under ~/.grokboy/sessions/.json " ); } @@ -58,7 +76,7 @@ async fn cmd_chat() -> Result<()> { ); println!("Type a message. Empty line or /exit to quit.\n"); - let mut history = vec![ChatMessage::system(SYSTEM)]; + let mut history = vec![ChatMessage::system(CHAT_SYSTEM)]; let stdin = io::stdin(); let mut stdout = io::stdout(); @@ -88,3 +106,187 @@ async fn cmd_chat() -> Result<()> { } Ok(()) } + +async fn cmd_run(args: &[String]) -> Result<()> { + let mut session_id: Option = None; + let mut prompt_parts: Vec = Vec::new(); + let mut i = 0; + while i < args.len() { + match args[i].as_str() { + "--session" | "-s" => { + i += 1; + let id = args + .get(i) + .ok_or_else(|| anyhow!("--session requires an id"))?; + session_id = Some(id.clone()); + } + "--help" | "-h" => { + println!( + "Usage: grokboy run [--session ] \"\"\n\ + Runs a one-shot tool-using agent. Creates a session under ~/.grokboy/sessions/." + ); + return Ok(()); + } + other => prompt_parts.push(other.to_string()), + } + i += 1; + } + let prompt = prompt_parts.join(" "); + if prompt.trim().is_empty() { + return Err(anyhow!("usage: grokboy run [--session ] \"\"")); + } + + let config = Config::from_env().map_err(anyhow::Error::msg)?; + let cwd = std::env::current_dir().context("cwd")?; + let mut session = load_or_create(session_id.as_deref(), &cwd)?; + + // Ensure system prompt is present once at the start. + if session.messages.is_empty() { + session.push(ChatMessage::system(AGENT_SYSTEM)); + } + session.cwd = cwd.clone(); + session.push(ChatMessage::user(&prompt)); + + let tool_ctx = ToolContext::new(session.cwd.clone()); + let answer = run_agent( + &config, + &mut session.messages, + &tool_ctx, + DEFAULT_MAX_ROUNDS, + ) + .await?; + + session.touch(); + let path = save_session(&session)?; + println!("{answer}"); + eprintln!( + "\n[session {} saved → {}]", + session.id, + path.display() + ); + Ok(()) +} + +async fn cmd_smoke() -> Result<()> { + println!("GrokBoy smoke (offline tools)…"); + let stamp = uuid_like(); + let dir = std::env::temp_dir().join(format!("grokboy-smoke-{stamp}")); + std::fs::create_dir_all(&dir).context("temp dir")?; + let ctx = ToolContext::new(dir.clone()); + + // write_file + let w = execute_tool( + &ctx, + "write_file", + &json!({"path": "note.txt", "content": "smoke ok\n第二行"}).to_string(), + ) + .await; + let w: serde_json::Value = serde_json::from_str(&w)?; + assert_ok(&w, "write_file")?; + println!(" write_file ok"); + + // read_file + let r = execute_tool( + &ctx, + "read_file", + &json!({"path": "note.txt"}).to_string(), + ) + .await; + let r: serde_json::Value = serde_json::from_str(&r)?; + assert_ok(&r, "read_file")?; + if r["content"].as_str() != Some("smoke ok\n第二行") { + return Err(anyhow!("read_file content mismatch: {r}")); + } + println!(" read_file ok"); + + // list_dir + let l = execute_tool(&ctx, "list_dir", &json!({"path": "."}).to_string()).await; + let l: serde_json::Value = serde_json::from_str(&l)?; + assert_ok(&l, "list_dir")?; + let names: Vec<&str> = l["entries"] + .as_array() + .context("entries")? + .iter() + .filter_map(|e| e["name"].as_str()) + .collect(); + if !names.contains(&"note.txt") { + return Err(anyhow!("list_dir missing note.txt: {l}")); + } + println!(" list_dir ok"); + + // shell + let s = execute_tool( + &ctx, + "shell", + &json!({"command": "printf 'hi'; wc -c < note.txt"}).to_string(), + ) + .await; + let s: serde_json::Value = serde_json::from_str(&s)?; + assert_ok(&s, "shell")?; + if s["exit_code"] != 0 { + return Err(anyhow!("shell exit_code != 0: {s}")); + } + println!(" shell ok"); + + // path traversal should fail + let bad = execute_tool( + &ctx, + "read_file", + &json!({"path": "../outside.txt"}).to_string(), + ) + .await; + let bad: serde_json::Value = serde_json::from_str(&bad)?; + if bad.get("error").is_none() { + return Err(anyhow!("expected path traversal error, got {bad}")); + } + println!(" sandbox ok"); + + // tool definitions present + let defs = tool_definitions(); + if defs.as_array().map(|a| a.len()).unwrap_or(0) != 4 { + return Err(anyhow!("expected 4 tool defs")); + } + println!(" tool defs ok"); + + // session roundtrip in temp (does not require ~/.grokboy for this check — + // we still exercise Session serialize via save into temp using core types) + let mut sess = Session::new(dir.clone()); + sess.push(ChatMessage::system(AGENT_SYSTEM)); + sess.push(ChatMessage::user("smoke")); + let sess_path = dir.join("session.json"); + let data = serde_json::to_vec_pretty(&sess)?; + std::fs::write(&sess_path, data)?; + let loaded: Session = serde_json::from_slice(&std::fs::read(&sess_path)?)?; + if loaded.messages.len() != 2 { + return Err(anyhow!("session roundtrip failed")); + } + println!(" session ok"); + + let _ = std::fs::remove_dir_all(&dir); + + // Optional live ping if API key is present (does not fail smoke). + if Config::from_env().is_ok() { + println!(" (API key present — skipping live call in smoke; use `run` to exercise)"); + } else { + println!(" (no API key — live agent not checked; offline smoke passed)"); + } + + println!("smoke passed"); + Ok(()) +} + +fn assert_ok(v: &serde_json::Value, label: &str) -> Result<()> { + if let Some(err) = v.get("error") { + return Err(anyhow!("{label} failed: {err}")); + } + Ok(()) +} + +fn uuid_like() -> String { + use std::time::{SystemTime, UNIX_EPOCH}; + let n = SystemTime::now() + .duration_since(UNIX_EPOCH) + .map(|d| d.as_nanos()) + .unwrap_or(0); + format!("{n}") +} diff --git a/docs/ACCEPTANCE.md b/docs/ACCEPTANCE.md index d67c239..63f58d6 100644 --- a/docs/ACCEPTANCE.md +++ b/docs/ACCEPTANCE.md @@ -7,11 +7,12 @@ - [x] `grokboy chat` streams assistant tokens - [x] `cargo test` passes without API key -## P1 — tools + ReAct (next) -- [ ] `shell`, `list_dir`, `read_file`, `write_file` -- [ ] Multi-step tool loop -- [ ] Sessions under `~/.grokboy/sessions/` -- [ ] `grokboy run` / `grokboy smoke` +## P1 — tools + ReAct +- [x] `shell`, `list_dir`, `read_file`, `write_file` +- [x] Multi-step tool loop +- [x] Sessions under `~/.grokboy/sessions/` +- [x] `grokboy run` / `grokboy smoke` +- [x] Default model `grok-4.6` ## P2 — completion contract - [ ] `report_done` / blocked