diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50dcb11 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Generated by Cargo +# will have compiled files and executables +debug +target + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# Generated by cargo mutants +# Contains mutation testing data +**/mutants.out*/ + +# rustc will dump stack traces when hitting an internal compiler error to PWD +rustc-ice-*.txt + +.vs +docs/devlog/* +docs/tasks +docs/questions.md + +# RustRover +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ \ No newline at end of file diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..52ececd --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,39 @@ +# AGENTS.md + +Instructions for AI agents contributing to Exoshell. + +## Engineering + +* Prefer the simplest solution that satisfies the requirement. +* Do not implement speculative future requirements. +* Extend existing systems before creating new ones. +* Determine whether an existing implementation can be extended before introducing a new subsystem, abstraction, or dependency. +* Always defer to the user when requirements are unclear or tradeoffs are uncertain. +* New dependencies require justification. +* Never duplicate functionality unless doing so avoids unnecessary dependency complexity. + +## Documentation + +* Use direct, humble technical language, Write like an engineer, not a marketer. +* Be accurate and honest about capabilities and limitations. +* Record known bugs, limitations, and technical debt in `docs/BUGS.md`. +* If there is information worth communicating after completing work, append it to `docs/devlog/YYYY-MM-DD.md`. + +## Versioning + +* Bump the version for any user-visible change or major feature. +* Follow `docs/versioning.md`. + +## Source of Truth +Review before significant changes: + +* `docs/DESIGN.md` +* `docs/PHASES.md` +* `docs/tasks/*` +* `docs/versioning.md` + +If instructions conflict: + +1. AGENTS.md +2. Documentation +3. Code diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..6f56f87 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1792 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cc" +version = "1.2.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f" +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 = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "displaydoc" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ac70aa55017e108007fbaf5aa0f54b021c98f92ff8af59d42eda9da96e3dd4f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[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 = "exoshell" +version = "0.1.0" +dependencies = [ + "async-trait", + "futures-util", + "reqwest", + "serde", + "serde_json", + "tempfile", + "thiserror", + "tokio", + "toml", +] + +[[package]] +name = "fastrand" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[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.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-io" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" + +[[package]] +name = "futures-macro" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +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", + "libc", + "wasi", +] + +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasip2", + "wasip3", +] + +[[package]] +name = "h2" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "171fefbc92fe4a4de27e0698d6a5b392d6a0e333506bc49133760b3bcf948733" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "http" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be7462df143984c4598a256ef469b251d7d7f9e271135073e78fc535414f3d0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +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.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55281c53a1894c864990125767da440a4e630446785086f52523b20033b74498" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "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", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[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", + "system-configuration", + "tokio", + "tower-service", + "tracing", + "windows-registry", +] + +[[package]] +name = "icu_collections" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" + +[[package]] +name = "icu_properties" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" + +[[package]] +name = "icu_provider" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[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 = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", + "serde", + "serde_core", +] + +[[package]] +name = "ipnet" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" + +[[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.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11" +dependencies = [ + "cfg-if", + "futures-util", + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "libc" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" + +[[package]] +name = "log" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5" + +[[package]] +name = "memchr" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mio" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02bd0af71c67b473010cbbc60715ee815645a4dc942899111f494b4b737d6fda" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "native-tls" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "openssl" +version = "0.10.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a45fa2aa886c42762255da344f0a0d313e254066c46aad76f300c3d3da62d967" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + +[[package]] +name = "openssl-sys" +version = "0.9.116" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28a22dc7140cda5f096e5e7724a6962ca81a7f8bfd2979f9b18c11af56318c4" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[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 = "pkg-config" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" + +[[package]] +name = "potential_utf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +dependencies = [ + "zerovec", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +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 = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "js-sys", + "log", + "mime", + "native-tls", + "percent-encoding", + "pin-project-lite", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-native-tls", + "tokio-util", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", +] + +[[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 = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30a7197ae7eb376e574fe940d068c30fe0462554a3ddbe4eca7838e049c937a9" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "schannel" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags", + "core-foundation 0.10.1", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_spanned" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26" +dependencies = [ + "serde_core", +] + +[[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.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52d1cfed4120b4d927bf7c0f86d2087a4a7d6027c906d9f9d525a80573b9be51" +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.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +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", +] + +[[package]] +name = "system-configuration" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b" +dependencies = [ + "bitflags", + "core-foundation 0.9.4", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.2", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinystr" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tokio" +version = "1.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "0.9.12+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf92845e79fc2e2def6a5d828f0801e29a2f8acc037becc5ab08595c7d5e9863" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow 0.7.15", +] + +[[package]] +name = "toml_datetime" +version = "0.7.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" +dependencies = [ + "winnow 1.0.3", +] + +[[package]] +name = "toml_writer" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db" + +[[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 = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[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 = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[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 = "wasip2" +version = "1.0.3+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" +dependencies = [ + "wit-bindgen 0.57.1", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen 0.51.0", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.122" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9473dbd2991ae90b6291c3c32c30c6187ac49aa32f9905d1cce280ec1e110b0f" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.122" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.122" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.122" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[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 = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "web-sys" +version = "0.3.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621441cfc37b84979402712047321980c178f299193a3589d05b99e8763436" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" +dependencies = [ + "windows-link", + "windows-result", + "windows-strings", +] + +[[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 = "winnow" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" + +[[package]] +name = "winnow" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0592e1c9d151f854e6fd382574c3a0855250e1d9b2f99d9281c6e6391af352f1" + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "writeable" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" + +[[package]] +name = "yoke" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" +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", + "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", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..980ce9a --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "exoshell" +version = "0.1.0" +edition = "2024" +license = "GPL-3.0-or-later" + +[dependencies] +async-trait = "0.1" +futures-util = "0.3" +reqwest = { version = "0.12", features = ["json", "stream"] } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +thiserror = "2" +tokio = { version = "1", features = ["macros", "rt-multi-thread", "signal"] } +toml = "0.9" + +[dev-dependencies] +tempfile = "3" diff --git a/docs/BUGS.md b/docs/BUGS.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/PHASES.md b/docs/PHASES.md new file mode 100644 index 0000000..4e18c9c --- /dev/null +++ b/docs/PHASES.md @@ -0,0 +1,161 @@ +# Exoshell Phases + +This roadmap turns the project vision into concrete build phases. The phases are intentionally ordered from the smallest useful shell-adjacent assistant toward the broader cognitive shell described in `README.md` and `docs/DESIGN.md`. + +## Phase 1: Shell-Adjacent Model Chat + +Goal: ship a usable terminal program that lets a user talk to a model from PowerShell, bash, zsh, and similar shells without replacing the shell. + +Core features: + +- CLI entry point, likely `exoshell`, that runs as a normal terminal application. +- Provider configuration for at least one OpenAI-compatible backend. +- Local-first-compatible model adapter interface, even if the first implementation targets one backend. +- Interactive chat loop with streaming responses. +- Basic command suggestion formatting that distinguishes prose, shell commands, and warnings. +- Explicit copy/paste-oriented workflow: Exoshell suggests commands, the user remains responsible for execution. +- Cross-platform terminal behavior on Windows, macOS, and Linux. +- Shell-family awareness for PowerShell versus POSIX-like shells. +- Basic session transcript saved as markdown. +- Minimal config file for provider, model, default shell family, and notebook location. +- Clear error handling for missing API keys, provider failures, and interrupted requests. + +User experience: +- User should be able to run "exo this is a prompt" and get a response, the program exiting +- User should be able to run exo (without a prompt) and have an open session, or "exo this is a prompt --stay" (or a more appropriate flag) to keep the shell/conversation open +- User should be able to pipe (bash) or powershell equivalent into exo and have it treated as a prompt, with the additional context of the command run that sent the pipe, cwd, etc. + - For example, "ls | exo" should send a prompt similar to "{"command": "ls", "stdout": "foo bar baz", "cwd": "/foo/bar"}" and any relevant system prompts +Non-goals: + +- PTY control of the user's shell. +- Hotkeys that inject commands into the shell. +- Ambient context collection. +- Tree-sitter repo indexing. +- Long-term memory. +- Stances and personalities beyond a fixed default behavior. +- Autonomous command execution. + +Exit criteria: + +- A user can install/run Exoshell, configure a model backend, ask for help from a terminal, receive command suggestions appropriate to PowerShell or bash/zsh, and save the session transcript. +- The implementation has a small automated test suite for provider abstraction, shell-family prompt behavior, config loading, and transcript writing. + +## Phase 2: Context, Modes, and Operator Controls + +Goal: make Exoshell feel like an operational overlay instead of a generic chat client. + +Core features: + +- Explicit context commands for adding files, command output, directory summaries, and pasted logs. +- Session-scoped context panel or context summary visible in the TUI. +- Stances such as `operator`, `audit`, `teach`, and `quiet`. +- Hotkeys for accepting, copying, explaining, and discarding suggested commands. +- Safer command suggestion UI with destructive-command detection and confirmation language. +- Context budget management with visible token or character estimates. +- Shell-specific command rendering and explanation for PowerShell and POSIX-like shells. +- Notebook improvements: title, timestamps, model metadata, commands suggested, and user-marked discoveries. +- Basic configuration profiles for different providers and shells. + +Non-goals: + +- Passive screen watching. +- Full PTY embedding. +- Repository-wide semantic indexing. +- Long-term memory outside user-controlled markdown/log files. + +Exit criteria: + +- A user can deliberately attach context, switch stance, inspect what context is being sent, and act on suggestions through predictable terminal controls. + +## Phase 3: Repo Awareness and Operational Notebooks + +Goal: give Exoshell useful project awareness while keeping memory inspectable and scoped. + +Core features: + +- Repo detection and project-root selection. +- File tree summaries with ignore rules. +- Structural parsing for common languages using tree-sitter where practical. +- Commands to add source files, symbols, recent git changes, and test output to context. +- Markdown notebooks scoped by global, repo, task, and session. +- Searchable operational notes and discoveries. +- Runbook generation from session notes. +- Diff-oriented patch suggestions that require user review. +- Better uncertainty reporting through explicit signal strength. + +Non-goals: + +- Hidden long-term behavioral profiling. +- Blind patch application. +- Autonomous multi-file rewrites. + +Exit criteria: + +- A user can open a repo, ask informed questions about local code and recent command output, preserve useful notes, and generate reviewable runbooks or patch suggestions. + +## Phase 4: Follow Mode and Shell Integration + +Goal: let Exoshell observe explicit shell activity and provide contextual help without becoming a replacement shell. + +Core features: + +- PTY or shell-hook integration strategy for supported environments. +- Follow mode that can ingest selected command history, stdout/stderr snippets, current directory, and exit status. +- User-visible controls for what is observed and retained. +- Hotkey workflows for sending command output to Exoshell. +- Optional paste-to-shell and paste-and-run flows with clear confirmation boundaries. +- Command outcome interpretation and next-step suggestions. +- Per-shell integration docs for PowerShell, bash, zsh, and fish. + +Non-goals: + +- Covert monitoring. +- Unreviewed execution. +- Replacing the user's shell configuration. + +Exit criteria: + +- A user can work in their normal shell while Exoshell follows explicitly permitted context and offers useful, nonintrusive operational guidance. + +## Phase 5: Tuning, Extensibility, and Local-First Depth + +Goal: make Exoshell configurable, hackable, and effective with weaker local models. + +Core features: + +- Robust local model support through OpenAI-compatible local servers and/or dedicated adapters. +- Prompt and stance customization. +- User-editable command policies and safety rules. +- Extension points for tools, context providers, and notebook processors. +- Model routing by task type. +- Context compression and retrieval tuned for smaller models. +- Export/import of user configuration and notebooks. +- Advanced visual themes that remain restrained and terminal-native. + +Non-goals: + +- Cloud lock-in. +- Manager analytics. +- Personality behavior that compromises operational clarity. + +Exit criteria: + +- A technical user can tune Exoshell to their environment, run local-first workflows, and extend context/tool behavior without modifying core code. + +## Phase 6: Mature Cognitive Shell Overlay + +Goal: converge on the broader vision: a calm, inspectable, practitioner-oriented cognitive shell environment. + +Core features: + +- Mature cockpit-style TUI with dense but readable operational instrumentation. +- Stable shell integrations across major platforms. +- High-quality repo, session, task, and notebook workflows. +- Reviewable command, patch, and runbook pipelines. +- Strong safety posture around destructive commands and hidden state. +- Comprehensive docs for installation, configuration, shell integration, model backends, stances, notebooks, and local-first operation. +- Packaging and release automation. + +Exit criteria: + +- Exoshell is a dependable daily-driver assistant for terminal-native practitioners who want AI augmentation while preserving control and understanding. diff --git a/docs/phase1_run.md b/docs/phase1_run.md new file mode 100644 index 0000000..1f1670e --- /dev/null +++ b/docs/phase1_run.md @@ -0,0 +1,97 @@ +# Phase 1 Local Run + +Exoshell Phase 1 is a shell-adjacent model chat REPL. It suggests commands and explanations, but it does not execute commands. + +Run locally: + +```sh +cargo run +``` + +Use a config file: + +```sh +cargo run -- --config path/to/config.toml +``` + +Select the command dialect from the CLI: + +```sh +cargo run -- --shell powershell +cargo run -- --shell posix +``` + +Control transcript behavior: + +```sh +cargo run -- --no-transcript +cargo run -- --transcript-dir transcripts +``` + +Example config: + +```toml +[provider] +base_url = "https://api.openai.com/v1" +api_key_env = "OPENAI_API_KEY" +model = "gpt-4.1-mini" + +[shell] +family = "powershell" + +[transcript] +enabled = true +directory = "transcripts" +``` + +Supported shell families in this first pass are `powershell` and `posix`. + +PowerShell example: + +```powershell +$env:OPENAI_API_KEY = "..." +cargo run -- --shell powershell +``` + +POSIX example: + +```sh +export OPENAI_API_KEY="..." +cargo run -- --shell posix +``` + +Inside the REPL: + +- `/exit` quits. +- `/quit` quits. +- `/multi` starts multi-line input. Finish with a single `.` line. + +Phase 1 behavior: + +- Exoshell suggests commands, but does not execute them. +- Suggested command blocks are labeled for review in terminal output. +- Risky commands should be reviewed manually before use. +- Session transcripts are markdown files when transcripts are enabled. +- API keys are read from environment variables and are not written to transcripts. + +Current limitations: + +- No PTY integration. +- No hotkey command injection. +- No ambient context collection. +- No repo indexing. +- No autonomous execution. + +Quality commands: + +```sh +cargo fmt +cargo test +cargo clippy --all-targets --all-features +``` + +Manual startup smoke test on Windows PowerShell: + +```powershell +powershell -ExecutionPolicy Bypass -File scripts\manual_phase1_startup.ps1 +``` diff --git a/docs/versioning.md b/docs/versioning.md new file mode 100644 index 0000000..986914d --- /dev/null +++ b/docs/versioning.md @@ -0,0 +1,102 @@ +Exoshell uses Semantic Versioning (SemVer) for all machine-readable version numbers. + +Version numbers follow: + +MAJOR.MINOR.PATCH + +Examples: + +0.1.0 +0.3.3 +1.0.0 + +The numeric version is the authoritative version used by Cargo, Git tags, releases, package managers, automation, and compatibility decisions. + +## Release Codenames + +Each release also receives a human-readable codename. + +Codenames exist for display purposes only and have no semantic meaning. They do not indicate compatibility, stability, feature scope, or release type. + +Example display: + +Exoshell v0.3.3 +codename: packet-goblin + +or: + +Exoshell 0.3.3 "Packet Goblin" + +The codename should be shown in the UI wherever version information is displayed. + +## Codename Generation + +Release codenames should be generated using a constrained naming scheme. + +Recommended format: + +- + +Example tech terms: + +kernel +packet +daemon +socket +cache +cipher +terminal +process +satellite +router + +Example artifacts: + +goblin +wizard +familiar +relic +oracle +ghost +hotdog +cult +seance +rat-king + +The lists above are examples only. + +Future releases may introduce additional terms as long as they remain consistent with the project's tone. + +## Codename Rules + +A codename must: + +be lowercase +use hyphens as separators +be safe for public display +be memorable +be mildly absurd +be unique across all releases + +A codename must not: + +contain version numbers +imply compatibility guarantees +contain offensive or discriminatory language +be reused + +## Naming Guidance + +When creating a release: + +Increment the semantic version according to SemVer rules. +Generate a new codename. +Verify that the codename has not been used previously. +Add the codename to release notes and changelog entries. +Preserve existing codenames in project history. + + +## Historical Codenames +Historical codenames should be tracked in docs/versioning.md below + +* 0.1.0 packet-kobold diff --git a/scripts/manual_phase1_startup.ps1 b/scripts/manual_phase1_startup.ps1 new file mode 100644 index 0000000..73a6fba --- /dev/null +++ b/scripts/manual_phase1_startup.ps1 @@ -0,0 +1,17 @@ +$ErrorActionPreference = "Stop" + +$env:OPENAI_API_KEY = "manual-startup-placeholder" +$configPath = Join-Path $env:TEMP "exoshell-manual-startup.toml" +@" +[provider] +api_key_env = "OPENAI_API_KEY" +model = "manual-startup-model" + +[shell] +family = "powershell" + +[transcript] +enabled = false +"@ | Set-Content -Path $configPath -Encoding utf8 + +"/exit" | cargo run -- --config $configPath diff --git a/scripts/quality.ps1 b/scripts/quality.ps1 new file mode 100644 index 0000000..2394e2d --- /dev/null +++ b/scripts/quality.ps1 @@ -0,0 +1,5 @@ +$ErrorActionPreference = "Stop" + +cargo fmt --check +cargo test +cargo clippy --all-targets --all-features diff --git a/src/app.rs b/src/app.rs new file mode 100644 index 0000000..749fbc4 --- /dev/null +++ b/src/app.rs @@ -0,0 +1,187 @@ +use std::path::PathBuf; + +use crate::config::Config; +use crate::prompts::phase1_system_prompt; +use crate::providers::{ChatMessage, ChatRequest, ChatResponse, ChatRole, Provider, ProviderError}; +use crate::repl::ReplError; +use crate::shell::ShellFamily; +use crate::transcripts::{Transcript, TranscriptError}; + +pub struct App { + config: Config, + provider: Box, + messages: Vec, + transcript: Transcript, +} + +impl App { + pub fn new(config: Config, provider: Box) -> Self { + let transcript = Transcript::new( + "openai-compatible".into(), + config.provider.model.clone(), + config.shell.family, + ); + let messages = vec![ChatMessage::new( + ChatRole::System, + phase1_system_prompt(config.shell.family), + )]; + + Self { + config, + provider, + messages, + transcript, + } + } + + pub async fn send(&mut self, input: String) -> Result { + self.messages + .push(ChatMessage::new(ChatRole::User, input.clone())); + self.transcript.record_user(&input); + + let request = ChatRequest { + messages: self.messages.clone(), + stream: false, + }; + + let response = match self.provider.chat(request).await { + Ok(ChatResponse::Complete(response)) => response, + Ok(ChatResponse::Stream(chunks)) => chunks.concat(), + Err(error) => { + self.transcript.record_error(&error.to_string()); + return Err(error.into()); + } + }; + self.messages + .push(ChatMessage::new(ChatRole::Assistant, response.clone())); + self.transcript.record_assistant(&response); + + Ok(response) + } + + pub fn save_transcript(&self) -> Result, AppError> { + if !self.config.transcript.enabled { + return Ok(None); + } + + let path = self + .transcript + .write_to_dir(&self.config.transcript.directory)?; + Ok(Some(path)) + } +} + +#[derive(Debug, thiserror::Error)] +pub enum AppError { + #[error(transparent)] + Config(#[from] crate::config::ConfigError), + #[error(transparent)] + Provider(#[from] ProviderError), + #[error(transparent)] + Repl(#[from] ReplError), + #[error(transparent)] + Transcript(#[from] TranscriptError), +} + +#[derive(Debug, Default, PartialEq, Eq)] +pub struct CliOptions { + pub config_path: Option, + pub shell_family: Option, + pub transcript_enabled: Option, + pub transcript_directory: Option, + pub no_color: bool, + pub show_help: bool, +} + +impl CliOptions { + pub fn parse(args: I) -> Result + where + I: IntoIterator, + { + let mut options = CliOptions::default(); + let mut args = args.into_iter(); + + while let Some(arg) = args.next() { + match arg.as_str() { + "-h" | "--help" => options.show_help = true, + "--config" => { + let value = args.next().ok_or_else(|| { + crate::config::ConfigError::Invalid("--config requires a path".into()) + })?; + options.config_path = Some(PathBuf::from(value)); + } + "--shell" => { + let value = args.next().ok_or_else(|| { + crate::config::ConfigError::Invalid("--shell requires a value".into()) + })?; + options.shell_family = Some(value.parse().map_err( + |error: crate::shell::ShellFamilyError| { + crate::config::ConfigError::Invalid(error.to_string()) + }, + )?); + } + "--no-transcript" => options.transcript_enabled = Some(false), + "--transcript-dir" => { + let value = args.next().ok_or_else(|| { + crate::config::ConfigError::Invalid( + "--transcript-dir requires a path".into(), + ) + })?; + options.transcript_directory = Some(PathBuf::from(value)); + options.transcript_enabled = Some(true); + } + "--no-color" => options.no_color = true, + other => { + return Err(crate::config::ConfigError::Invalid(format!( + "unknown argument: {other}" + )) + .into()); + } + } + } + + Ok(options) + } + + pub fn help() -> &'static str { + "Usage: exoshell [--config ] [--shell powershell|posix] [--no-transcript] [--transcript-dir ] [--no-color]\n\nStarts the Exoshell Phase 1 interactive model chat. Exoshell suggests commands; it does not execute them." + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parses_config_path() { + let options = CliOptions::parse(["--config".to_string(), "config.toml".to_string()]) + .expect("options parse"); + + assert_eq!(options.config_path, Some(PathBuf::from("config.toml"))); + } + + #[test] + fn help_flag_is_supported() { + let options = CliOptions::parse(["--help".to_string()]).expect("options parse"); + + assert!(options.show_help); + } + + #[test] + fn parses_phase1_cli_overrides() { + let options = CliOptions::parse([ + "--shell".to_string(), + "posix".to_string(), + "--no-transcript".to_string(), + "--transcript-dir".to_string(), + "out".to_string(), + "--no-color".to_string(), + ]) + .expect("options parse"); + + assert_eq!(options.shell_family, Some(ShellFamily::Posix)); + assert_eq!(options.transcript_enabled, Some(true)); + assert_eq!(options.transcript_directory, Some(PathBuf::from("out"))); + assert!(options.no_color); + } +} diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..418f6e3 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,306 @@ +use std::env; +use std::fs; +use std::path::{Path, PathBuf}; + +use serde::Deserialize; + +use crate::app::CliOptions; +use crate::shell::ShellFamily; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Config { + pub provider: ProviderConfig, + pub shell: ShellConfig, + pub transcript: TranscriptConfig, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ProviderConfig { + pub base_url: String, + pub api_key: String, + pub api_key_env: String, + pub model: String, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ShellConfig { + pub family: ShellFamily, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct TranscriptConfig { + pub directory: PathBuf, + pub enabled: bool, +} + +#[derive(Debug, Deserialize, Default)] +struct RawConfig { + provider: Option, + shell: Option, + transcript: Option, +} + +#[derive(Debug, Deserialize, Default)] +struct RawProviderConfig { + base_url: Option, + api_key_env: Option, + model: Option, +} + +#[derive(Debug, Deserialize, Default)] +struct RawShellConfig { + family: Option, +} + +#[derive(Debug, Deserialize, Default)] +struct RawTranscriptConfig { + directory: Option, + enabled: Option, +} + +impl Config { + pub fn load(path: Option<&Path>) -> Result { + let raw = match path { + Some(path) => RawConfig::from_path(path)?, + None => RawConfig::from_default_path()?.unwrap_or_default(), + }; + + Self::from_raw(raw) + } + + fn from_raw(raw: RawConfig) -> Result { + let provider = raw.provider.unwrap_or_default(); + let shell = raw.shell.unwrap_or_default(); + let transcript = raw.transcript.unwrap_or_default(); + + let api_key_env = provider + .api_key_env + .unwrap_or_else(|| "OPENAI_API_KEY".into()); + let api_key = env::var(&api_key_env).map_err(|_| { + ConfigError::MissingApiKey(format!( + "set {api_key_env} or configure provider.api_key_env" + )) + })?; + + let family = shell.family.unwrap_or_else(default_shell_family); + let family = family + .parse::() + .map_err(|error| ConfigError::Invalid(error.to_string()))?; + + Ok(Self { + provider: ProviderConfig { + base_url: provider + .base_url + .unwrap_or_else(|| "https://api.openai.com/v1".into()), + api_key, + api_key_env, + model: provider.model.unwrap_or_else(|| "gpt-4.1-mini".into()), + }, + shell: ShellConfig { family }, + transcript: TranscriptConfig { + directory: transcript.directory.unwrap_or_else(default_transcript_dir), + enabled: transcript.enabled.unwrap_or(true), + }, + }) + } + + pub fn apply_cli_overrides(&mut self, options: &CliOptions) -> Result<(), ConfigError> { + if let Some(shell_family) = options.shell_family { + self.shell.family = shell_family; + } + + if let Some(transcript_enabled) = options.transcript_enabled { + self.transcript.enabled = transcript_enabled; + } + + if let Some(transcript_directory) = &options.transcript_directory { + self.transcript.directory = transcript_directory.clone(); + } + + Ok(()) + } +} + +impl RawConfig { + fn from_path(path: &Path) -> Result { + let contents = fs::read_to_string(path).map_err(|error| ConfigError::Read { + path: path.to_path_buf(), + error, + })?; + + toml::from_str(&contents).map_err(ConfigError::Parse) + } + + fn from_default_path() -> Result, ConfigError> { + let path = default_config_path(); + if !path.exists() { + return Ok(None); + } + + Self::from_path(&path).map(Some) + } +} + +fn default_shell_family() -> String { + ShellFamily::default_for_platform().to_string() +} + +fn default_config_path() -> PathBuf { + if cfg!(windows) { + env::var_os("APPDATA") + .map(PathBuf::from) + .unwrap_or_else(|| PathBuf::from(".")) + .join("exoshell") + .join("config.toml") + } else { + env::var_os("XDG_CONFIG_HOME") + .map(PathBuf::from) + .or_else(|| env::var_os("HOME").map(|home| PathBuf::from(home).join(".config"))) + .unwrap_or_else(|| PathBuf::from(".")) + .join("exoshell") + .join("config.toml") + } +} + +fn default_transcript_dir() -> PathBuf { + if cfg!(windows) { + env::var_os("APPDATA") + .map(PathBuf::from) + .unwrap_or_else(|| PathBuf::from(".")) + .join("exoshell") + .join("transcripts") + } else { + env::var_os("XDG_DATA_HOME") + .map(PathBuf::from) + .or_else(|| env::var_os("HOME").map(|home| PathBuf::from(home).join(".local/share"))) + .unwrap_or_else(|| PathBuf::from(".")) + .join("exoshell") + .join("transcripts") + } +} + +#[derive(Debug, thiserror::Error)] +pub enum ConfigError { + #[error("failed to read config at {path}: {error}")] + Read { + path: PathBuf, + #[source] + error: std::io::Error, + }, + #[error("failed to parse config: {0}")] + Parse(toml::de::Error), + #[error("missing provider API key: {0}")] + MissingApiKey(String), + #[error("invalid config: {0}")] + Invalid(String), +} + +#[cfg(test)] +mod tests { + use std::io::Write; + + use super::*; + + #[test] + fn loads_defaults_from_environment() { + unsafe { + env::set_var("EXOSHELL_TEST_KEY", "secret"); + } + + let config = Config::from_raw(RawConfig { + provider: Some(RawProviderConfig { + api_key_env: Some("EXOSHELL_TEST_KEY".into()), + ..RawProviderConfig::default() + }), + ..RawConfig::default() + }) + .expect("config loads"); + + assert_eq!(config.provider.api_key, "secret"); + assert_eq!(config.provider.base_url, "https://api.openai.com/v1"); + assert_eq!(config.provider.model, "gpt-4.1-mini"); + } + + #[test] + fn rejects_unknown_shell_family() { + unsafe { + env::set_var("EXOSHELL_TEST_KEY", "secret"); + } + + let error = Config::from_raw(RawConfig { + provider: Some(RawProviderConfig { + api_key_env: Some("EXOSHELL_TEST_KEY".into()), + ..RawProviderConfig::default() + }), + shell: Some(RawShellConfig { + family: Some("cmd".into()), + }), + transcript: None, + }) + .expect_err("shell family should be rejected"); + + assert!(matches!(error, ConfigError::Invalid(_))); + } + + #[test] + fn loads_toml_config_file() { + unsafe { + env::set_var("EXOSHELL_TEST_KEY", "secret"); + } + + let mut file = tempfile::NamedTempFile::new().expect("temp config"); + write!( + file, + r#" +[provider] +base_url = "http://localhost:11434/v1" +api_key_env = "EXOSHELL_TEST_KEY" +model = "local-model" + +[shell] +family = "posix" + +[transcript] +enabled = false +"# + ) + .expect("write config"); + + let config = Config::load(Some(file.path())).expect("config loads"); + + assert_eq!(config.provider.base_url, "http://localhost:11434/v1"); + assert_eq!(config.provider.model, "local-model"); + assert_eq!(config.shell.family, ShellFamily::Posix); + assert!(!config.transcript.enabled); + } + + #[test] + fn applies_cli_overrides() { + unsafe { + env::set_var("EXOSHELL_TEST_KEY", "secret"); + } + + let mut config = Config::from_raw(RawConfig { + provider: Some(RawProviderConfig { + api_key_env: Some("EXOSHELL_TEST_KEY".into()), + ..RawProviderConfig::default() + }), + ..RawConfig::default() + }) + .expect("config loads"); + + let tempdir = PathBuf::from("manual-transcripts"); + let options = CliOptions { + shell_family: Some(ShellFamily::Posix), + transcript_enabled: Some(false), + transcript_directory: Some(tempdir.clone()), + ..CliOptions::default() + }; + + config.apply_cli_overrides(&options).expect("overrides"); + + assert_eq!(config.shell.family, ShellFamily::Posix); + assert!(!config.transcript.enabled); + assert_eq!(config.transcript.directory, tempdir); + } +} diff --git a/src/formatting.rs b/src/formatting.rs new file mode 100644 index 0000000..ca501a7 --- /dev/null +++ b/src/formatting.rs @@ -0,0 +1,66 @@ +pub fn render_assistant_output(response: &str) -> String { + let mut rendered = String::new(); + let mut in_command_block = false; + + for line in response.lines() { + if in_command_block && line.trim() == "```" { + in_command_block = false; + rendered.push_str("--- end suggested command ---\n"); + rendered.push_str(line); + rendered.push('\n'); + continue; + } + + if let Some(language) = command_language_from_fence(line) { + rendered.push_str(&format!( + "--- suggested command ({language}); review before running ---\n" + )); + in_command_block = true; + rendered.push_str(line); + rendered.push('\n'); + continue; + } + + rendered.push_str(line); + rendered.push('\n'); + } + + if response.contains("[risk: high]") || response.contains("risk: high") { + rendered.push_str("--- review required: model marked this response as high risk ---\n"); + } + + rendered.trim_end().to_string() +} + +fn command_language_from_fence(line: &str) -> Option<&str> { + let trimmed = line.trim(); + let language = trimmed.strip_prefix("```")?; + + match language { + "powershell" | "pwsh" | "sh" | "bash" | "zsh" | "posix" => Some(language), + _ => None, + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn labels_command_blocks() { + let output = render_assistant_output( + "Try this:\n```powershell\nGet-ChildItem\n```\nThen inspect the output.", + ); + + assert!(output.contains("suggested command (powershell); review before running")); + assert!(output.contains("end suggested command")); + } + + #[test] + fn preserves_high_risk_language() { + let output = render_assistant_output("[risk: high]\n```sh\nrm -rf build\n```"); + + assert!(output.contains("review required")); + assert!(output.contains("rm -rf build")); + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..bb17e2b --- /dev/null +++ b/src/main.rs @@ -0,0 +1,37 @@ +mod app; +mod config; +mod formatting; +mod prompts; +mod providers; +mod repl; +mod shell; +mod transcripts; + +use crate::app::{App, CliOptions}; +use crate::config::Config; +use crate::providers::openai_compatible::OpenAiCompatibleProvider; +use crate::repl::Repl; + +#[tokio::main] +async fn main() { + if let Err(error) = run().await { + eprintln!("error: {error}"); + std::process::exit(1); + } +} + +async fn run() -> Result<(), app::AppError> { + let options = CliOptions::parse(std::env::args().skip(1))?; + + if options.show_help { + println!("{}", CliOptions::help()); + return Ok(()); + } + + let mut config = Config::load(options.config_path.as_deref())?; + config.apply_cli_overrides(&options)?; + let provider = OpenAiCompatibleProvider::from_config(&config)?; + let app = App::new(config, Box::new(provider)); + + Repl::new(app).run().await +} diff --git a/src/prompts.rs b/src/prompts.rs new file mode 100644 index 0000000..bf2a4f1 --- /dev/null +++ b/src/prompts.rs @@ -0,0 +1,50 @@ +use crate::shell::ShellFamily; + +pub fn phase1_system_prompt(shell_family: ShellFamily) -> String { + format!( + "You are Exoshell, a shell-adjacent assistant for technical operators.\n\ + Sacred rule: enhance skill; do not replace it.\n\ + The human keeps the controls. Suggest commands, but never say or imply that you executed them.\n\ + Do not request or perform autonomous execution. Do not normalize blind destructive commands.\n\ + Prefer deterministic shell tools when they are the right fit; do not force AI into workflows where awk, sed, jq, rg, git, cargo, make, or platform-native tools are better.\n\ + Surface uncertainty with signal language such as 'signal: weak', 'signal: medium', or 'signal: high' when confidence matters.\n\ + Target shell family: {shell_family}.\n\ + Shell instructions: {}\n\ + Command convention: put suggested commands in fenced code blocks using language tag `{}`. Add a short review note before risky operations. For destructive commands, require explicit user review and provide a safer inspection command first when possible.", + shell_family.prompt_instructions(), + command_language(shell_family) + ) +} + +fn command_language(shell_family: ShellFamily) -> &'static str { + match shell_family { + ShellFamily::PowerShell => "powershell", + ShellFamily::Posix => "sh", + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn powershell_prompt_contains_shell_specific_instructions() { + let prompt = phase1_system_prompt(ShellFamily::PowerShell); + + assert!(prompt.contains("Target shell family: powershell")); + assert!(prompt.contains("Use PowerShell syntax")); + assert!(prompt.contains("never say or imply that you executed")); + assert!(prompt.contains("signal: weak")); + assert!(prompt.contains("fenced code blocks using language tag `powershell`")); + } + + #[test] + fn posix_prompt_contains_shell_specific_instructions() { + let prompt = phase1_system_prompt(ShellFamily::Posix); + + assert!(prompt.contains("Target shell family: posix")); + assert!(prompt.contains("bash or zsh")); + assert!(prompt.contains("Prefer deterministic shell tools")); + assert!(prompt.contains("fenced code blocks using language tag `sh`")); + } +} diff --git a/src/providers/mod.rs b/src/providers/mod.rs new file mode 100644 index 0000000..5414442 --- /dev/null +++ b/src/providers/mod.rs @@ -0,0 +1,81 @@ +pub mod openai_compatible; + +#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct ChatMessage { + pub role: ChatRole, + pub content: String, +} + +impl ChatMessage { + pub fn new(role: ChatRole, content: impl Into) -> Self { + Self { + role, + content: content.into(), + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum ChatRole { + System, + User, + Assistant, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ChatRequest { + pub messages: Vec, + pub stream: bool, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ChatResponse { + Complete(String), + Stream(Vec), +} + +#[async_trait::async_trait] +pub trait Provider: Send + Sync { + async fn chat(&self, request: ChatRequest) -> Result; +} + +#[derive(Debug, thiserror::Error)] +pub enum ProviderError { + #[error("provider configuration error: {0}")] + Configuration(String), + #[error("provider authentication failed: {0}")] + Authentication(String), + #[error("provider network error: {0}")] + Network(String), + #[error("provider returned an invalid response: {0}")] + Response(String), +} + +#[cfg(test)] +mod tests { + use super::*; + + struct FailingProvider; + + #[async_trait::async_trait] + impl Provider for FailingProvider { + async fn chat(&self, _request: ChatRequest) -> Result { + Err(ProviderError::Authentication("bad key".into())) + } + } + + #[tokio::test] + async fn provider_trait_surfaces_typed_errors() { + let provider = FailingProvider; + let error = provider + .chat(ChatRequest { + messages: vec![], + stream: false, + }) + .await + .expect_err("provider should fail"); + + assert!(matches!(error, ProviderError::Authentication(_))); + } +} diff --git a/src/providers/openai_compatible.rs b/src/providers/openai_compatible.rs new file mode 100644 index 0000000..b162cf4 --- /dev/null +++ b/src/providers/openai_compatible.rs @@ -0,0 +1,245 @@ +use futures_util::StreamExt; +use reqwest::StatusCode; +use serde::{Deserialize, Serialize}; + +use crate::config::Config; +use crate::providers::{ChatMessage, ChatRequest, ChatResponse, Provider, ProviderError}; + +#[derive(Debug)] +pub struct OpenAiCompatibleProvider { + client: reqwest::Client, + base_url: String, + api_key: String, + model: String, +} + +impl OpenAiCompatibleProvider { + pub fn from_config(config: &Config) -> Result { + Self::new( + config.provider.base_url.clone(), + config.provider.api_key.clone(), + config.provider.model.clone(), + ) + } + + pub fn new( + base_url: impl Into, + api_key: impl Into, + model: impl Into, + ) -> Result { + let base_url = base_url.into().trim_end_matches('/').to_string(); + if base_url.is_empty() { + return Err(ProviderError::Configuration("base URL is empty".into())); + } + + let api_key = api_key.into(); + if api_key.is_empty() { + return Err(ProviderError::Configuration("API key is empty".into())); + } + + let model = model.into(); + if model.is_empty() { + return Err(ProviderError::Configuration("model is empty".into())); + } + + Ok(Self { + client: reqwest::Client::new(), + base_url, + api_key, + model, + }) + } + + fn chat_url(&self) -> String { + format!("{}/chat/completions", self.base_url) + } +} + +#[async_trait::async_trait] +impl Provider for OpenAiCompatibleProvider { + async fn chat(&self, request: ChatRequest) -> Result { + let payload = ChatCompletionRequest { + model: self.model.clone(), + messages: request.messages, + stream: request.stream, + }; + + let response = self + .client + .post(self.chat_url()) + .bearer_auth(&self.api_key) + .json(&payload) + .send() + .await + .map_err(|error| ProviderError::Network(error.to_string()))?; + + let status = response.status(); + if status == StatusCode::UNAUTHORIZED || status == StatusCode::FORBIDDEN { + return Err(ProviderError::Authentication( + "check provider API key and permissions".into(), + )); + } + + if !status.is_success() { + let body = response.text().await.unwrap_or_default(); + return Err(ProviderError::Response(format!( + "HTTP {status}: {}", + body.trim() + ))); + } + + if payload.stream { + return read_streaming_response(response).await; + } + + let body: ChatCompletionResponse = response + .json() + .await + .map_err(|error| ProviderError::Response(error.to_string()))?; + + let content = body + .choices + .into_iter() + .next() + .map(|choice| choice.message.content) + .ok_or_else(|| ProviderError::Response("missing assistant choice".into()))?; + + Ok(ChatResponse::Complete(content)) + } +} + +async fn read_streaming_response( + response: reqwest::Response, +) -> Result { + let mut stream = response.bytes_stream(); + let mut buffer = String::new(); + let mut chunks = Vec::new(); + + while let Some(item) = stream.next().await { + let bytes = item.map_err(|error| ProviderError::Network(error.to_string()))?; + buffer.push_str(&String::from_utf8_lossy(&bytes)); + + while let Some(line_end) = buffer.find('\n') { + let line = buffer[..line_end].trim().to_string(); + buffer = buffer[line_end + 1..].to_string(); + + let Some(data) = line.strip_prefix("data:") else { + continue; + }; + + let data = data.trim(); + if data == "[DONE]" { + return Ok(ChatResponse::Stream(chunks)); + } + + let event: ChatCompletionChunk = serde_json::from_str(data) + .map_err(|error| ProviderError::Response(error.to_string()))?; + + for choice in event.choices { + if let Some(content) = choice.delta.content { + chunks.push(content); + } + } + } + } + + Ok(ChatResponse::Stream(chunks)) +} + +#[derive(Debug, Serialize)] +struct ChatCompletionRequest { + model: String, + messages: Vec, + stream: bool, +} + +#[derive(Debug, Deserialize)] +struct ChatCompletionResponse { + choices: Vec, +} + +#[derive(Debug, Deserialize)] +struct Choice { + message: ResponseMessage, +} + +#[derive(Debug, Deserialize)] +struct ResponseMessage { + content: String, +} + +#[derive(Debug, Deserialize)] +struct ChatCompletionChunk { + choices: Vec, +} + +#[derive(Debug, Deserialize)] +struct ChunkChoice { + delta: ChunkDelta, +} + +#[derive(Debug, Deserialize)] +struct ChunkDelta { + content: Option, +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::providers::ChatRole; + use tokio::io::{AsyncReadExt, AsyncWriteExt}; + use tokio::net::TcpListener; + + #[test] + fn rejects_empty_configuration() { + let error = OpenAiCompatibleProvider::new("", "key", "model") + .expect_err("empty base URL should fail"); + + assert!(matches!(error, ProviderError::Configuration(_))); + } + + #[tokio::test] + async fn sends_openai_compatible_request_and_reads_response() { + let listener = TcpListener::bind("127.0.0.1:0").await.expect("bind mock"); + let address = listener.local_addr().expect("mock address"); + + let server = tokio::spawn(async move { + let (mut socket, _) = listener.accept().await.expect("accept request"); + let mut request = vec![0; 4096]; + let bytes = socket.read(&mut request).await.expect("read request"); + let request = String::from_utf8_lossy(&request[..bytes]); + + assert!(request.contains("POST /chat/completions HTTP/1.1")); + assert!(request.contains("\"model\":\"test-model\"")); + assert!(request.contains("\"role\":\"user\"")); + assert!(request.contains("\"stream\":false")); + + let body = r#"{"choices":[{"message":{"content":"hello from mock"}}]}"#; + let response = format!( + "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\n\r\n{}", + body.len(), + body + ); + + socket + .write_all(response.as_bytes()) + .await + .expect("write response"); + }); + + let provider = + OpenAiCompatibleProvider::new(format!("http://{address}"), "test-key", "test-model") + .expect("provider"); + + let response = provider + .chat(ChatRequest { + messages: vec![ChatMessage::new(ChatRole::User, "hello")], + stream: false, + }) + .await + .expect("chat response"); + + server.await.expect("server task"); + assert_eq!(response, ChatResponse::Complete("hello from mock".into())); + } +} diff --git a/src/repl.rs b/src/repl.rs new file mode 100644 index 0000000..4559a7a --- /dev/null +++ b/src/repl.rs @@ -0,0 +1,100 @@ +use std::io::{self, Write}; + +use crate::app::{App, AppError}; +use crate::formatting::render_assistant_output; + +pub struct Repl { + app: App, +} + +impl Repl { + pub fn new(app: App) -> Self { + Self { app } + } + + pub async fn run(mut self) -> Result<(), AppError> { + println!("Exoshell Phase 1"); + println!( + "Type /exit to quit. Type /multi to enter multi-line input, then finish with a single '.' line." + ); + + loop { + print!("exo> "); + io::stdout().flush().map_err(ReplError::Io)?; + + let Some(input) = read_input()? else { + break; + }; + + let input = input.trim().to_string(); + if input.is_empty() { + continue; + } + + if input == "/exit" || input == "/quit" { + break; + } + + let input = if input == "/multi" { + read_multiline()? + } else { + input + }; + + if input.trim().is_empty() { + continue; + } + + match self.app.send(input).await { + Ok(response) => println!("\n{}\n", render_assistant_output(&response)), + Err(error) => eprintln!("request failed: {error}"), + } + } + + match self.app.save_transcript()? { + Some(path) => println!("transcript: {}", path.display()), + None => println!("transcript: disabled"), + } + + Ok(()) + } +} + +fn read_input() -> Result, ReplError> { + let mut input = String::new(); + let bytes = io::stdin().read_line(&mut input).map_err(ReplError::Io)?; + if bytes == 0 { + return Ok(None); + } + + Ok(Some(input)) +} + +fn read_multiline() -> Result { + println!("multi-line input; finish with a single '.' line"); + + let mut lines = Vec::new(); + loop { + print!("... "); + io::stdout().flush().map_err(ReplError::Io)?; + + let Some(line) = read_input()? else { + break; + }; + + let line = line.trim_end_matches(['\r', '\n']); + if line == "." { + break; + } + + lines.push(line.to_string()); + } + + Ok(lines.join("\n")) +} + +#[derive(Debug, thiserror::Error)] +pub enum ReplError { + #[error("terminal I/O failed: {0}")] + Io(std::io::Error), +} diff --git a/src/shell.rs b/src/shell.rs new file mode 100644 index 0000000..a52e660 --- /dev/null +++ b/src/shell.rs @@ -0,0 +1,80 @@ +use std::fmt; +use std::str::FromStr; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ShellFamily { + PowerShell, + Posix, +} + +impl ShellFamily { + pub fn default_for_platform() -> Self { + if cfg!(windows) { + Self::PowerShell + } else { + Self::Posix + } + } + + pub fn prompt_instructions(self) -> &'static str { + match self { + Self::PowerShell => { + "Use PowerShell syntax. Prefer PowerShell cmdlets for native Windows tasks, and use external tools such as rg, git, jq, or cargo when they are the right deterministic tool." + } + Self::Posix => { + "Use POSIX-like shell syntax suitable for bash or zsh. Prefer standard shell tools and common deterministic utilities such as rg, awk, sed, jq, git, make, or cargo when they fit." + } + } + } +} + +impl fmt::Display for ShellFamily { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::PowerShell => formatter.write_str("powershell"), + Self::Posix => formatter.write_str("posix"), + } + } +} + +impl FromStr for ShellFamily { + type Err = ShellFamilyError; + + fn from_str(value: &str) -> Result { + match value { + "powershell" => Ok(Self::PowerShell), + "posix" => Ok(Self::Posix), + other => Err(ShellFamilyError { + value: other.to_string(), + }), + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] +#[error("unsupported shell family '{value}', expected 'powershell' or 'posix'")] +pub struct ShellFamilyError { + value: String, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parses_supported_shell_families() { + assert_eq!( + "powershell".parse::().expect("powershell"), + ShellFamily::PowerShell + ); + assert_eq!( + "posix".parse::().expect("posix"), + ShellFamily::Posix + ); + } + + #[test] + fn rejects_unsupported_shell_family() { + assert!("cmd".parse::().is_err()); + } +} diff --git a/src/transcripts.rs b/src/transcripts.rs new file mode 100644 index 0000000..a6fb3f8 --- /dev/null +++ b/src/transcripts.rs @@ -0,0 +1,154 @@ +use std::fs; +use std::path::{Path, PathBuf}; +use std::time::{SystemTime, UNIX_EPOCH}; + +use crate::shell::ShellFamily; + +#[derive(Debug, Clone)] +pub struct Transcript { + started_at_epoch_ms: u128, + provider: String, + model: String, + shell_family: ShellFamily, + entries: Vec, +} + +impl Transcript { + pub fn new(provider: String, model: String, shell_family: ShellFamily) -> Self { + Self { + started_at_epoch_ms: unix_millis(), + provider, + model, + shell_family, + entries: Vec::new(), + } + } + + pub fn record_user(&mut self, content: &str) { + self.entries + .push(TranscriptEntry::User(content.to_string())); + } + + pub fn record_assistant(&mut self, content: &str) { + self.entries + .push(TranscriptEntry::Assistant(content.to_string())); + } + + pub fn record_error(&mut self, content: &str) { + self.entries + .push(TranscriptEntry::Error(content.to_string())); + } + + pub fn write_to_dir(&self, directory: &Path) -> Result { + fs::create_dir_all(directory).map_err(|error| TranscriptError::CreateDir { + path: directory.to_path_buf(), + error, + })?; + + let path = directory.join(format!( + "session-{}-{}.md", + self.started_at_epoch_ms, + std::process::id() + )); + fs::write(&path, self.to_markdown()).map_err(|error| TranscriptError::Write { + path: path.clone(), + error, + })?; + + Ok(path) + } + + fn to_markdown(&self) -> String { + let mut markdown = format!( + "# Exoshell Session {}\n\n- started_at_epoch_ms: `{}`\n- provider: `{}`\n- model: `{}`\n- shell_family: `{}`\n\n", + self.started_at_epoch_ms, + self.started_at_epoch_ms, + self.provider, + self.model, + self.shell_family + ); + + for entry in &self.entries { + match entry { + TranscriptEntry::User(content) => { + markdown.push_str("## User\n\n"); + markdown.push_str(content); + markdown.push_str("\n\n"); + } + TranscriptEntry::Assistant(content) => { + markdown.push_str("## Assistant\n\n"); + markdown.push_str(content); + markdown.push_str("\n\n"); + } + TranscriptEntry::Error(content) => { + markdown.push_str("## Error\n\n"); + markdown.push_str(content); + markdown.push_str("\n\n"); + } + } + } + + markdown + } +} + +#[derive(Debug, Clone)] +enum TranscriptEntry { + User(String), + Assistant(String), + Error(String), +} + +fn unix_millis() -> u128 { + SystemTime::now() + .duration_since(UNIX_EPOCH) + .expect("system time before UNIX epoch") + .as_millis() +} + +#[derive(Debug, thiserror::Error)] +pub enum TranscriptError { + #[error("failed to create transcript directory {path}: {error}")] + CreateDir { + path: PathBuf, + #[source] + error: std::io::Error, + }, + #[error("failed to write transcript {path}: {error}")] + Write { + path: PathBuf, + #[source] + error: std::io::Error, + }, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn writes_markdown_transcript() { + let tempdir = tempfile::tempdir().expect("tempdir"); + let mut transcript = Transcript::new( + "test-provider".into(), + "test-model".into(), + ShellFamily::Posix, + ); + transcript.record_user("hello"); + transcript.record_assistant("hi"); + transcript.record_error("provider failed"); + + let path = transcript + .write_to_dir(tempdir.path()) + .expect("transcript writes"); + let contents = fs::read_to_string(path).expect("read transcript"); + + assert!(contents.contains("test-model")); + assert!(contents.contains("test-provider")); + assert!(contents.contains("shell_family: `posix`")); + assert!(contents.contains("## User")); + assert!(contents.contains("hello")); + assert!(contents.contains("## Assistant")); + assert!(contents.contains("## Error")); + } +}