diff --git a/.vscode/settings.json b/.vscode/settings.json index 30ff6544a..36045e7e4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { "python.defaultInterpreterPath": "${workspaceFolder}/server/.venv/bin/python3", - "continue.showInlineTip": false + "continue.showInlineTip": false, + "rust-analyzer.linkedProjects": ["./server/Cargo.toml"] } diff --git a/server/Cargo.lock b/server/Cargo.lock new file mode 100644 index 000000000..a9da92fbd --- /dev/null +++ b/server/Cargo.lock @@ -0,0 +1,1015 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "542f33a8835a0884b006a0c3df3dadd99c0c3f296ed26c2fdc8028e01ad6230c" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + +[[package]] +name = "cc" +version = "1.0.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f8e7c90afad890484a21653d08b6e209ae34770fb5ee298f9c699fcc1e5c856" +dependencies = [ + "libc", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets", +] + +[[package]] +name = "continuedev" +version = "0.1.0" +dependencies = [ + "hex-literal", + "homedir", + "ignore", + "pyo3", + "serde", + "serde_json", + "sha1", + "tempfile", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + +[[package]] +name = "cpufeatures" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "errno" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "futures" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" + +[[package]] +name = "futures-executor" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" + +[[package]] +name = "futures-macro" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "futures-sink" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" + +[[package]] +name = "futures-task" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" + +[[package]] +name = "futures-util" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "globset" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d" +dependencies = [ + "aho-corasick", + "bstr", + "fnv", + "log", + "regex", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "homedir" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22074da8bba2ef26fc1737ae6c777b5baab5524c2dc403b5c6a76166766ccda5" +dependencies = [ + "cfg-if", + "nix", + "serde", + "widestring", + "windows-sys", + "wmi", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ignore" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" +dependencies = [ + "globset", + "lazy_static", + "log", + "memchr", + "regex", + "same-file", + "thread_local", + "walkdir", + "winapi-util", +] + +[[package]] +name = "indoc" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8" + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "js-sys" +version = "0.3.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "memoffset" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +dependencies = [ + "autocfg", +] + +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "nix" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "libc", + "memoffset 0.7.1", + "pin-utils", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pyo3" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04e8453b658fe480c3e70c8ed4e3d3ec33eb74988bd186561b0cc66b85c3bc4b" +dependencies = [ + "cfg-if", + "indoc", + "libc", + "memoffset 0.9.0", + "parking_lot", + "pyo3-build-config", + "pyo3-ffi", + "pyo3-macros", + "unindent", +] + +[[package]] +name = "pyo3-build-config" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a96fe70b176a89cff78f2fa7b3c930081e163d5379b4dcdf993e3ae29ca662e5" +dependencies = [ + "once_cell", + "target-lexicon", +] + +[[package]] +name = "pyo3-ffi" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "214929900fd25e6604661ed9cf349727c8920d47deff196c4e28165a6ef2a96b" +dependencies = [ + "libc", + "pyo3-build-config", +] + +[[package]] +name = "pyo3-macros" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac53072f717aa1bfa4db832b39de8c875b7c7af4f4a6fe93cdbf9264cf8383b" +dependencies = [ + "proc-macro2", + "pyo3-macros-backend", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "pyo3-macros-backend" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7774b5a8282bd4f25f803b1f0d945120be959a36c72e08e7cd031c792fdfd424" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rustix" +version = "0.38.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" +dependencies = [ + "bitflags 2.4.1", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.192" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.192" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "serde_json" +version = "1.0.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a" + +[[package]] +name = "tempfile" +version = "3.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" +dependencies = [ + "cfg-if", + "fastrand", + "redox_syscall", + "rustix", + "windows-sys", +] + +[[package]] +name = "thiserror" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unindent" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "walkdir" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.39", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" + +[[package]] +name = "widestring" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-targets", +] + +[[package]] +name = "windows-core" +version = "0.51.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-implement" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e2ee588991b9e7e6c8338edf3333fbe4da35dc72092643958ebb43f0ab2c49c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "windows-interface" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6fb8df20c9bcaa8ad6ab513f7b40104840c8867d5751126e4df3b08388d0cc7" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "wmi" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced703d10188571ce53582c2932ce640ed3c413cff7ee6e2d961f9abdb6a63d1" +dependencies = [ + "chrono", + "futures", + "log", + "serde", + "thiserror", + "windows", +] diff --git a/server/Cargo.toml b/server/Cargo.toml new file mode 100644 index 000000000..fe2f0ae48 --- /dev/null +++ b/server/Cargo.toml @@ -0,0 +1,29 @@ +# If you already have [package] information in `Cargo.toml`, you can ignore +# this section! +[package] +# `name` here is name of the package. +name = "continuedev" +# these are good defaults: +version = "0.1.0" +edition = "2021" + +[lib] +# The name of the native library. This is the name which will be used in Python to import the +# library (i.e. `import string_sum`). If you change this, you must also change the name of the +# `#[pymodule]` in `src/lib.rs`. +name = "continuedev" + +# "cdylib" is necessary to produce a shared library for Python to import from. +crate-type = ["cdylib"] + +[dependencies] +hex-literal = "0.4.1" +homedir = "0.2.1" +ignore = "0.4.20" +pyo3 = { version = "0.20.0", features = ["extension-module"] } +serde = { version = "1.0.192", features = ["derive"] } +serde_json = "1.0.108" +sha1 = "0.10.6" + +[dev-dependencies] +tempfile = "3.8.1" diff --git a/server/continuedev/continuedev.py b/server/continuedev/continuedev.py new file mode 100644 index 000000000..9a26baeea --- /dev/null +++ b/server/continuedev/continuedev.py @@ -0,0 +1,20 @@ +import asyncio +from typing import Union + +from .core.config import ContinueConfig +from .core.main import Step + +# from .headless import start_headless_session + + +def run(step_or_config: Union[Step, ContinueConfig]): + if isinstance(step_or_config, ContinueConfig): + config = step_or_config + else: + config = ContinueConfig() + config.steps_on_startup = [step_or_config] + + loop = asyncio.get_event_loop() + # loop.run_until_complete(start_headless_session(config=config)) + tasks = asyncio.all_tasks(loop) + loop.run_until_complete(asyncio.gather(*tasks)) diff --git a/server/continuedev/continuedev.pyi b/server/continuedev/continuedev.pyi new file mode 100644 index 000000000..18fb9beac --- /dev/null +++ b/server/continuedev/continuedev.pyi @@ -0,0 +1,5 @@ +from typing import List, Tuple + +def sync_results( + dir: str, branch: str +) -> Tuple[List[Tuple[str, str]], List[Tuple[str, str]]]: ... diff --git a/server/continuedev/py.typed b/server/continuedev/py.typed new file mode 100644 index 000000000..e69de29bb diff --git a/server/poetry.lock b/server/poetry.lock index 85400b817..a585af10e 100644 --- a/server/poetry.lock +++ b/server/poetry.lock @@ -1615,6 +1615,35 @@ files = [ [package.dependencies] traitlets = "*" +[[package]] +name = "maturin" +version = "1.3.1" +description = "Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages" +optional = false +python-versions = ">=3.7" +files = [ + {file = "maturin-1.3.1-py3-none-linux_armv6l.whl", hash = "sha256:925f8324d9bbe8fad90b73ebc6c7f6f594645e7f13af50bded72606b6c233208"}, + {file = "maturin-1.3.1-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:f3c2c694b76e63e78c353e4a2a74f8baff5ac6becf807f23435d28e47a567d63"}, + {file = "maturin-1.3.1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:13188296f389d05043b8bd2265df66692490b61ba219ae7d5abc09e81e5659ce"}, + {file = "maturin-1.3.1-py3-none-manylinux_2_12_i686.manylinux2010_i686.musllinux_1_1_i686.whl", hash = "sha256:11bbf9978695ac066729af08bc24123317ca3fad51757b0fbdfe811212896714"}, + {file = "maturin-1.3.1-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.musllinux_1_1_x86_64.whl", hash = "sha256:d566d2f424fa3f5cd6bd3033fd300b80654884abd061bd53c68f4717753e7d58"}, + {file = "maturin-1.3.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.musllinux_1_1_aarch64.whl", hash = "sha256:c0e2b8171f1a70270b86ed72397ba548e3bf4d914f24cd50a228ed85a9d5e914"}, + {file = "maturin-1.3.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.musllinux_1_1_armv7l.whl", hash = "sha256:804c6706588a9ca78f18f1a10adf9d24099b9cd3c2917628063ba8d4418b8a50"}, + {file = "maturin-1.3.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.musllinux_1_1_ppc64le.whl", hash = "sha256:c533d02563bb185125488cdcf161cc6ba2cdd4812ebff1b6504d1b29880ba1f8"}, + {file = "maturin-1.3.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:066b0c515505d4a4c526a9afc26fad4f010972d60937530dc4949dda0f49aa61"}, + {file = "maturin-1.3.1-py3-none-win32.whl", hash = "sha256:4835c332e3b632547db12e6a70abc18cb90ba9df06200dd9a7cc73424919901d"}, + {file = "maturin-1.3.1-py3-none-win_amd64.whl", hash = "sha256:871268417d6b3e2b46018c54a0522efc018bc4918b885d005df90b338e0674c7"}, + {file = "maturin-1.3.1-py3-none-win_arm64.whl", hash = "sha256:659a601c27984a50350f792447ff65ec60309423747f5304c98cb7b7fbb63d39"}, + {file = "maturin-1.3.1.tar.gz", hash = "sha256:efa194e99ae5fff185263d8244acacb12ae256ea73aba62c9446f6075ffc7ac1"}, +] + +[package.dependencies] +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} + +[package.extras] +patchelf = ["patchelf"] +zig = ["ziglang (>=0.10.0,<0.11.0)"] + [[package]] name = "mdurl" version = "0.1.2" @@ -4260,4 +4289,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "05cdea7254c872a290327729b8cea62ad62a865b9a528823e109fd51d2ded9cf" +content-hash = "62e8f3ea636a605897e697ad7ce0d49dad49a44e8cbe0103dc731efba9669664" diff --git a/server/pyproject.toml b/server/pyproject.toml index 521d03fbf..af1230b4d 100644 --- a/server/pyproject.toml +++ b/server/pyproject.toml @@ -43,6 +43,7 @@ pathspec = "^0.11.2" tqdm = "^4.66.1" html2text = "^2020.1.16" pygit2 = "^1.13.2" +maturin = "^1.3.1" [tool.poetry.scripts] typegen = "continuedev.models.generate_json_schema:main" @@ -53,5 +54,19 @@ pytest-asyncio = "^0.21.1" ipykernel = "^6.26.0" [build-system] -requires = ["poetry-core"] -build-backend = "poetry.core.masonry.api" +requires = ["poetry-core", "maturin>=1,<2"] +# build-backend = "poetry.core.masonry.api" +build-backend = "maturin" + +[project] +name = "continuedev" +version = "0.1.90" +description = "" +authors = [{ name= "Nate Sesti", email = "" }] +readme = "README.md" +requires-python = ">=3.8.1" +classifiers = [ + "Programming Language :: Rust", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", +] \ No newline at end of file diff --git a/server/src/gitignore.rs b/server/src/gitignore.rs new file mode 100644 index 000000000..bb7c2389b --- /dev/null +++ b/server/src/gitignore.rs @@ -0,0 +1,102 @@ +use std::collections::HashMap; +use std::fs; +use std::io::{self, Read}; +use std::path::{Path, PathBuf}; + +pub fn local_find_gitignores(workspace_dir: &Path) -> io::Result> { + let mut gitignores = HashMap::new(); + for entry in fs::read_dir(workspace_dir)? { + let entry = entry?; + let path = entry.path(); + if path.is_dir() { + gitignores.extend(local_find_gitignores(&path)?); + } else { + match path.file_name().and_then(|name| name.to_str()) { + Some(file_name) if file_name.ends_with(".gitignore") || file_name.ends_with(".continueignore") => { + let mut contents = String::new(); + fs::File::open(&path)?.read_to_string(&mut contents)?; + gitignores.insert(path, contents); + } + _ => {} + } + } + } + Ok(gitignores) +} + +fn main() -> io::Result<()> { + let workspace_dir = Path::new("path/to/workspace"); + let gitignore_map = local_find_gitignores(workspace_dir)?; + + // Print out the result (optional) + for (path, contents) in gitignore_map { + println!("{}:\n{}", path.display(), contents); + } + + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + use std::fs::{self, File}; + use std::io::Write; + use tempfile::tempdir; + + #[test] + fn test_local_find_gitignores() -> io::Result<()> { + // Create a temporary directory for the test + let temp_dir = tempdir()?; + let temp_path = temp_dir.path(); + + // Create some directories and .gitignore/.continueignore files + let dir_structure = [ + ("dir1", Some(".gitignore"), "node_modules/"), + ("dir2", Some(".continueignore"), "target/"), + ("dir3", None, ""), + ]; + + for (dir, file, contents) in dir_structure.iter() { + let dir_path = temp_path.join(dir); + fs::create_dir(&dir_path)?; + + if let Some(file_name) = file { + let file_path = dir_path.join(file_name); + let mut file = File::create(file_path)?; + writeln!(file, "{}", contents)?; + } + } + + // Call the function under test + let gitignores = local_find_gitignores(temp_path)?; + + // Verify that the returned HashMap contains the correct paths and contents + for (dir, file, contents) in dir_structure.iter() { + if let Some(file_name) = file { + let file_path = temp_path.join(dir).join(file_name); + assert!(gitignores.contains_key(&file_path)); + assert_eq!(gitignores.get(&file_path).unwrap().trim(), *contents); + } + } + + // Cleanup the temporary directory automatically + temp_dir.close()?; + + Ok(()) + } + + #[test] + fn test_in_continue_repo() -> io::Result<()> { + // Get the current directory + let current_dir = std::env::current_dir()?; + let parent_dir = current_dir.parent().unwrap(); + let gitignores = local_find_gitignores(&parent_dir)?; + + // Verify that the returned HashMap contains the correct paths and contents + let top_level_gitignore = parent_dir.join(".gitignore"); + assert!(gitignores.contains_key(&top_level_gitignore)); + assert!(gitignores[&top_level_gitignore].contains(".tiktoken_cache")); + + Ok(()) + } +} diff --git a/server/src/lib.rs b/server/src/lib.rs new file mode 100644 index 000000000..7c25def44 --- /dev/null +++ b/server/src/lib.rs @@ -0,0 +1,19 @@ +use pyo3::{exceptions, prelude::*}; +use std::path::Path; +mod gitignore; +mod sync; + +#[pyfunction] +fn sync_results( + dir: String, + branch: String, +) -> PyResult<(Vec<(String, String)>, Vec<(String, String)>)> { + return sync::sync(Path::new(&dir), Some(&branch)) + .map_err(|err| PyErr::new::(format!("{}", err))); +} + +#[pymodule] +fn continuedev(_py: Python<'_>, m: &PyModule) -> PyResult<()> { + m.add_function(wrap_pyfunction!(sync_results, m)?)?; + Ok(()) +} diff --git a/server/src/sync/merkle.rs b/server/src/sync/merkle.rs new file mode 100644 index 000000000..f0171f923 --- /dev/null +++ b/server/src/sync/merkle.rs @@ -0,0 +1,620 @@ +use ignore::{Walk, WalkBuilder}; +use serde::{Deserialize, Serialize}; +use sha1::{Digest, Sha1}; +use std::{ + io::{self, Read, Result, Write}, + path::Path, +}; + +pub type ObjectHash = [u8; 20]; + +pub fn hash_string(hash: ObjectHash) -> String { + let mut result = String::new(); + for byte in hash { + result.push_str(&format!("{:02x}", byte)); + } + return result; +} + +#[derive(Clone)] +pub struct Tree { + parent: Option, + children: Vec, + hash: ObjectHash, + path: String, +} + +#[derive(Serialize, Deserialize)] +struct SerializeableNode { + parent: Option, + + /// Blobs would have no children + children: Option>, + hash: ObjectHash, + path: String, +} + +#[derive(Clone)] +struct Blob { + parent: Option, + hash: ObjectHash, + path: String, +} + +#[derive(Clone)] +enum Object { + Tree(Tree), + Blob(Blob), +} + +pub struct ObjDescription { + pub hash: ObjectHash, + pub path: String, + pub is_blob: bool, +} + +impl Object { + fn hash(&self) -> ObjectHash { + match self { + Object::Tree(tree) => tree.hash, + Object::Blob(blob) => blob.hash, + } + } + + fn path(&self) -> &String { + match self { + Object::Tree(tree) => &tree.path, + Object::Blob(blob) => &blob.path, + } + } + + fn json_for_obj(&self) -> String { + match self { + Object::Tree(tree) => tree.json_for_obj(), + Object::Blob(blob) => blob.json_for_obj(), + } + } + + fn descr(&self) -> ObjDescription { + return ObjDescription { + hash: self.hash(), + path: self.path().clone(), + is_blob: match self { + Object::Tree(_) => false, + Object::Blob(_) => true, + }, + }; + } + + /// Return a tuple of (paths to add, paths to remove) + fn diff(&self, other: &Object) -> (Vec, Vec) { + let mut add: Vec = Vec::new(); + let mut remove: Vec = Vec::new(); + + if self.hash() == other.hash() { + return (add, remove); + } + + match (self, other) { + (Object::Tree(self_tree), Object::Tree(other_tree)) => { + // This is where you recurse like below + let (child_add, child_remove) = self_tree.diff_children(other_tree); + add.push(other_tree.descr()); + remove.push(self_tree.descr()); + add.extend(child_add); + remove.extend(child_remove); + } + (Object::Blob(self_blob), Object::Blob(other_blob)) => { + add.push(self_blob.descr()); + remove.push(other_blob.descr()); + } + (Object::Blob(self_blob), Object::Tree(other_tree)) => { + // Remove blob, add entire new tree + remove.push(self_blob.descr()); + add.extend(other_tree.all_obj_descriptions()); + } + (Object::Tree(self_tree), Object::Blob(other_blob)) => { + // Remove entire old tree, add blob + remove.extend(self_tree.all_obj_descriptions()); + add.push(other_blob.descr()); + } + } + + return (add, remove); + } +} + +pub fn diff(old_tree: &Tree, new_tree: &Tree) -> (Vec, Vec) { + let mut add: Vec = Vec::new(); + let mut remove: Vec = Vec::new(); + + if old_tree.hash == new_tree.hash { + return (add, remove); + } + + let (child_add, child_remove) = old_tree.diff_children(new_tree); + + add.push(new_tree.descr()); + remove.push(old_tree.descr()); + add.extend(child_add); + remove.extend(child_remove); + + return (add, remove); +} + +impl Blob { + fn json_for_obj(&self) -> String { + let node = SerializeableNode { + parent: self.parent, + children: None, + hash: self.hash, + path: self.path.clone(), + }; + + let mut json = serde_json::to_string(&node).unwrap(); + json.push_str("\n"); + return json; + } + + fn descr(&self) -> ObjDescription { + return ObjDescription { + hash: self.hash, + path: self.path.clone(), + is_blob: true, + }; + } +} + +enum DiffType { + Add, + Update, + Remove, +} +impl Tree { + fn descr(&self) -> ObjDescription { + return ObjDescription { + hash: self.hash, + path: self.path.clone(), + is_blob: false, + }; + } + + fn json_for_node(&self) -> String { + let node = SerializeableNode { + parent: self.parent, + children: Some(self.children.iter().map(|child| child.hash()).collect()), + hash: self.hash, + path: self.path.clone(), + }; + + let mut json = serde_json::to_string(&node).unwrap(); + json.push_str("\n"); + return json; + } + + fn json_for_obj(&self) -> String { + let mut result = String::new(); + result.push_str(&self.json_for_node()); + + for child in &self.children { + result.push_str(&child.json_for_obj()); + } + + return result; + } + + fn obj_from_jsonl(lines: &mut std::str::Lines, first_line: Option) -> Tree { + let root_node = match first_line { + Some(line) => line, + None => serde_json::from_str(lines.next().unwrap()).unwrap(), + }; + + let mut children: Vec = Vec::new(); + for child_hash in root_node.children.unwrap() { + let child_jsonl = lines.next().unwrap(); + let child_node: SerializeableNode = serde_json::from_str(child_jsonl).unwrap(); + match child_node.children { + Some(_) => { + let child = Tree::obj_from_jsonl(lines, Some(child_node)); + children.push(Object::Tree(child)); + } + None => { + let child = Blob { + parent: child_node.parent, + hash: child_node.hash, + path: child_node.path, + }; + children.push(Object::Blob(child)); + } + } + } + + return Tree { + parent: root_node.parent, + children, + hash: root_node.hash, + path: root_node.path, + }; + } + + /// Persist the tree to disk as JSONL + pub fn persist(&self, filepath: &Path) { + if let Some(dir) = filepath.parent() { + std::fs::create_dir_all(dir) + .expect(format!("Failed to create dir {}", dir.display()).as_str()); + } + let mut file = std::fs::File::create(filepath).unwrap(); + file.write_all(self.json_for_obj().as_bytes()).unwrap(); + } + + /// Load the tree from JSONL file + pub fn load(filepath: &Path) -> Result { + let mut file = std::fs::File::open(filepath)?; + let mut contents = String::new(); + file.read_to_string(&mut contents)?; + let mut lines = contents.lines(); + return Ok(Tree::obj_from_jsonl(&mut lines, None)); + } + + pub fn empty() -> Tree { + return Tree { + parent: None, + children: Vec::new(), + hash: tree_hash(Vec::new()), + path: String::new(), + }; + } + + fn set_childrens_parent(&mut self) { + for child in &mut self.children { + match child { + Object::Tree(tree) => { + tree.parent = Some(self.hash); + tree.set_childrens_parent(); + } + Object::Blob(blob) => { + blob.parent = Some(self.hash); + } + } + } + } + + fn walk(&self, callback: &mut dyn FnMut(&Object)) { + callback(&Object::Tree(self.clone())); + for child in &self.children { + match child { + Object::Tree(tree) => tree.walk(callback), + Object::Blob(blob) => callback(&Object::Blob(blob.clone())), + } + } + } + + fn all_obj_descriptions(&self) -> Vec { + let mut result = Vec::new(); + self.walk(&mut |obj| result.push(obj.descr())); + return result; + } + + /// Return a list of paths that have changed and the type of change (0 = add, 1 = update, 2 = remove) + /// other is considered the "new" tree + fn diff_children(&self, other: &Tree) -> (Vec, Vec) { + let mut add = Vec::new(); + let mut remove = Vec::new(); + + // There are situations where the names of two folders could be swapped and then each slightly changed + // where you would need some heuristics to avoid throwing them out...but...don't worry for now. Just match by path + + let mut old_path_to_object: std::collections::HashMap = self + .children + .iter() + .map(|child| (child.path().clone(), child)) + .collect(); + + for child in &other.children { + if let Some(old_child) = old_path_to_object.remove(child.path()) { + // If the same path name exists in old children + let (child_add, child_remove) = old_child.diff(child); + add.extend(child_add); + remove.extend(child_remove); + } else { + // Name didn't exist before. Add all + match child { + Object::Tree(tree) => { + add.extend(tree.all_obj_descriptions()); + } + Object::Blob(blob) => { + add.push(blob.descr()); + } + } + } + } + + // Remove - along with all children + for (path, obj) in old_path_to_object { + match obj { + Object::Tree(tree) => tree.walk(&mut |obj| { + remove.extend(tree.all_obj_descriptions()); + }), + Object::Blob(_) => remove.push(obj.descr()), + } + } + + return (add, remove); + } +} + +pub fn build_walk(dir: &Path) -> Walk { + // Make sure it sorts alphabetically by default + return WalkBuilder::new(dir) + .add_custom_ignore_filename(".continueignore") + .build(); +} + +fn sha1_hash(content: &str) -> ObjectHash { + let mut hasher = Sha1::new(); + hasher.update(content); + let result = hasher.finalize(); + let hash_bytes: [u8; 20] = result.into(); + return hash_bytes; +} + +fn blob_hash(content: &str, file_ext: &str) -> ObjectHash { + return sha1_hash(&format!("blob {} {}", file_ext, content)); +} + +fn create_blob(filepath: &Path, parent: Option) -> Result { + let content = std::fs::read_to_string(filepath)?; + let hash = blob_hash( + &content, + match filepath.extension() { + Some(ext) => ext.to_str().unwrap(), + None => "", + }, + ); + return Ok(Blob { + parent: parent, + hash: hash, + path: filepath.to_str().unwrap().to_string(), + }); +} + +fn tree_hash(children: Vec) -> ObjectHash { + let mut hasher = Sha1::new(); + hasher.update("tree".as_bytes()); + + // Note you're not just concatenating + for child in &children { + hasher.update(child); + } + let result = hasher.finalize(); + let hash_bytes: [u8; 20] = result.into(); + return hash_bytes; +} + +struct PreTree { + children: Vec, + path: String, +} + +impl PreTree { + fn finalize(&self) -> Tree { + return Tree { + parent: None, + children: self.children.clone(), + hash: tree_hash(self.children.iter().map(|child| child.hash()).collect()), + path: self.path.clone(), + }; + } +} + +/// Compute merkle tree and all sub-objects +/// The last element in the vector is the root of the tree +pub fn compute_tree_for_dir(dir: &Path, parent: Option) -> Result { + let mut walk = build_walk(dir); + let root_entry = walk + .next() // This is just "." + .expect("Directory does not exist") + .expect("Error parsing directory"); + + // The last in the vector is the latest + // The first in the stack will end up being the root + let mut tree_stack: Vec = Vec::new(); + tree_stack.push(PreTree { + children: Vec::new(), + path: root_entry.path().to_str().unwrap().to_string(), + }); + let mut current_dir = dir.to_path_buf(); + + for entry in walk { + let entry = entry.unwrap(); + let path = entry.path(); + let metadata = entry.metadata().unwrap(); + + // Check whether current_dir is complete + while !path.starts_with(current_dir.as_path()) { + // We've moved up by (at least) one directory + // We need to pop the current directory off the stack + // and create a tree object for it + let partial_tree = tree_stack.pop().unwrap(); + tree_stack + .last_mut() + .unwrap() + .children + .push(Object::Tree(partial_tree.finalize())); + + // Update current_dir + current_dir = current_dir.parent().unwrap().to_path_buf(); + } + + if metadata.is_dir() { + let partial_tree = PreTree { + children: Vec::new(), + path: path.to_str().unwrap().to_string(), + }; + tree_stack.push(partial_tree); + current_dir = path.to_owned(); + } else { + match create_blob(path, None) { + Ok(blob) => { + tree_stack + .last_mut() + .unwrap() + .children + .push(Object::Blob(blob)); + } + Err(err) => { + // Not UTF-8 formatted. Binary file. Ignore. + } + } + } + } + + // Collapse the stack upward + while tree_stack.len() > 1 { + let partial_tree = tree_stack.pop().unwrap(); + tree_stack + .last_mut() + .unwrap() + .children + .push(Object::Tree(partial_tree.finalize())); + } + + assert!( + tree_stack.len() == 1, + "Tree stack should only have exactly one element" + ); + + // Convert to Tree + let mut root_tree = tree_stack.pop().unwrap().finalize(); + + // Go through and update the parent of each child + root_tree.set_childrens_parent(); + + return Ok(root_tree); +} + +// Tests +#[cfg(test)] +mod tests { + use super::*; + use std::fs::{self, File}; + use std::io::Write; + use tempfile::{tempdir, Builder}; + + struct TempDirBuilder { + files: Vec<(String, String)>, + } + + impl TempDirBuilder { + fn new() -> TempDirBuilder { + return TempDirBuilder { files: Vec::new() }; + } + + fn add(&mut self, path: &str, content: &str) -> &mut TempDirBuilder { + self.files.push((path.to_string(), content.to_string())); + return self; + } + + fn create(&self) -> tempfile::TempDir { + let temp_dir = tempdir().expect("Failed to create temp dir"); + + for (path, content) in &self.files { + let file_path = temp_dir.path().join(path); + if let Some(dir) = file_path.parent() { + fs::create_dir_all(dir).expect("Failed to create directory"); + } + let mut file = File::create(&file_path).expect("Failed to create test file"); + writeln!(file, "{}", content).expect("Failed to write to test file"); + } + + return temp_dir; + } + } + + #[test] + fn test_compute_tree_for_temp_dir() { + let temp_dir = TempDirBuilder::new() + .add("dir1/file1.txt", "Hello, world!") + .add("dir1/file2.txt", "Hello, world!") + .add("dir2/file3.txt", "Hello, world!") + .add("dir2/subdir/continue.py", "[continue for i in range(10)]") + .add("__init__.py", "a = 5") + .create(); + + let tree = compute_tree_for_dir(temp_dir.path(), None).expect("Failed to compute tree"); + + // Check that every node but the root has a parent, matching that parent's hash + tree.walk(&mut |obj| match obj { + Object::Tree(tree) => { + for child in &tree.children { + match child { + Object::Tree(child_tree) => { + assert_eq!(child_tree.parent, Some(tree.hash)); + } + Object::Blob(child_blob) => { + assert_eq!(child_blob.parent, Some(tree.hash)); + } + } + } + } + Object::Blob(_) => {} + }); + + // TODO: If a folder was removed, and another added, but they have the same hash, you should then assume it was renamed + + // Make sure hash was calculated in same way as always + assert_eq!( + hash_string(tree.hash), + "cb6bf3834fdc9c356a23fca2cb6f6d7a571474c4" + ); + + let temp_dir2 = TempDirBuilder::new() + .add("dir1/file1.txt", "Hello, world!") + .add("dir1/file2.txt", "Hello, world!") + .add("dir2/file3.txt", "Hello, world!") + .add("dir2/subdir/continue.py", "[continue for i in range(11)]") // Difference here + .add("__init__.py", "a = 5") + .create(); + + let tree2 = compute_tree_for_dir(temp_dir2.path(), None).expect("Failed to compute tree"); + + // Make sure hash was calculated in same way as always + + // Check that certain nodes have different hashes + assert_ne!(tree.hash, tree2.hash); + assert_ne!(tree.children[0].hash(), tree2.children[0].hash()); + assert_eq!(tree.children[1].hash(), tree2.children[1].hash()); + assert_eq!(tree.children[2].hash(), tree2.children[2].hash()); + + // Make a small change and recompute the tree + let path = temp_dir.path().join("dir2/subdir/continue.py"); + fs::write(path, "[continue for i in range(11)]").expect("Failed to write to file"); + let tree_prime = + compute_tree_for_dir(temp_dir.path(), None).expect("Failed to compute tree"); + + // All nodes up the tree from dir2/subdir/continue.py should be marked as changed + let (add, remove) = diff(&tree, &tree_prime); + assert_eq!(add.len(), 4); + assert_eq!(remove.len(), 4); + + // Try adding a file at the root level + let path = temp_dir.path().join("new_file.txt"); + fs::write(path, "42").expect("Failed to write to file"); + let tree_prime_prime = compute_tree_for_dir(temp_dir.path(), None) + .expect("Failed to compute tree") + .clone(); + + // Compare original and '' + let (add, remove) = diff(&tree, &tree_prime_prime); + assert_eq!(add.len(), 5); + assert_eq!(remove.len(), 4); + + // Compare ' and '' + let (add, remove) = diff(&tree_prime, &tree_prime_prime); + assert_eq!(add.len(), 2); + assert_eq!(remove.len(), 1); + + temp_dir.close().expect("Failed to clean up temp dir"); + temp_dir2.close().expect("Failed to clean up temp dir"); + } +} diff --git a/server/src/sync/mod.rs b/server/src/sync/mod.rs new file mode 100644 index 000000000..2a6b7f5bd --- /dev/null +++ b/server/src/sync/mod.rs @@ -0,0 +1,317 @@ +mod merkle; +use homedir::get_my_home; +use ignore; +use merkle::{build_walk, compute_tree_for_dir, diff, hash_string, ObjectHash}; +use std::{ + fs::{File, OpenOptions}, + io::{BufRead, BufReader, Read, Seek, SeekFrom, Write}, + path::{Path, PathBuf}, + time::{SystemTime, UNIX_EPOCH}, +}; + +use self::merkle::{ObjDescription, Tree}; + +/// Stored in ~/.continue/index/.last_sync +fn get_last_sync_time() -> u64 { + // TODO: Error handle here + let home = get_my_home().unwrap().unwrap(); + let path = home.join(".continue/index/.last_sync"); + + let mut file = File::open(path).unwrap(); + let mut contents = String::new(); + file.read_to_string(&mut contents).unwrap(); + + let last_sync_time = contents.parse::().unwrap(); + return last_sync_time; +} + +fn write_sync_time() { + let home = get_my_home().unwrap().unwrap(); + let path = home.join(".continue/index/.last_sync"); + + let mut file = File::create(path).unwrap(); + let now = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_secs(); + file.write_all(now.to_string().as_bytes()).unwrap(); +} + +/// Use stat to find files since last sync time +pub fn get_modified_files(dir: &Path) -> Vec { + let last_sync_time = get_last_sync_time(); + let mut modified_files = Vec::new(); + for entry in build_walk(dir) { + let entry = entry.unwrap(); + let path = entry.path(); + let metadata = path.metadata().unwrap(); + let modified = metadata.modified().unwrap(); + + if modified.duration_since(UNIX_EPOCH).unwrap().as_secs() > last_sync_time { + modified_files.push(path.to_path_buf().clone()); + } + } + + return modified_files; +} + +// Merkle trees are unique to directories, even if nested, but .index_cache is shared between all + +fn remove_seps_from_path(dir: &Path) -> String { + let mut path = String::new(); + for component in dir.components() { + path.push_str(component.as_os_str().to_str().unwrap()); + } + + // Remove leading slash + if path.starts_with("/") || path.starts_with("\\") { + path.remove(0); + } + return path; +} + +fn tree_path_for_dir_branch(dir: &Path, branch: Option<&str>) -> PathBuf { + let mut path = get_my_home().unwrap().unwrap(); + path.push(".continue/index"); + path.push(remove_seps_from_path(dir)); + if let Some(branch) = branch { + path.push(branch); + } else { + path.push("main"); + } + path.push("merkle_tree"); + return path; +} + +struct DiskSet { + file: File, +} + +const ITEM_SIZE: usize = 20; + +impl DiskSet { + pub fn new(path: &str) -> DiskSet { + let path = Path::new(path); + if !path.exists() { + File::create(path).unwrap(); + } + + DiskSet { + file: OpenOptions::new() + .read(true) + .write(true) + .open(path) + .unwrap(), + } + } + + pub fn contains(&mut self, item: &[u8; ITEM_SIZE]) -> bool { + self.file.seek(SeekFrom::Start(0)).unwrap(); + let mut buffer = [0; ITEM_SIZE]; + while self.file.read_exact(&mut buffer).is_ok() { + if &buffer == item { + return true; + } + } + false + } + + pub fn add(&mut self, item: &[u8; ITEM_SIZE]) { + if self.contains(item) { + return; + } + + self.file.write_all(item).unwrap(); + self.file.flush().unwrap(); + } + + pub fn remove(&mut self, item: &[u8; ITEM_SIZE]) { + self.file.seek(SeekFrom::Start(0)).unwrap(); + let mut buffer = [0; ITEM_SIZE]; + let mut pos = 0; + let mut found = false; + while self.file.read_exact(&mut buffer).is_ok() { + if &buffer == item { + found = true; + break; + } + pos = self.file.stream_position().unwrap() as usize; + } + + if found { + // Calculate the position of the last item + let len = self.file.metadata().unwrap().len() as usize; + let last_item_pos = len - ITEM_SIZE; + + // Move the last item in the file to the position of the item we want to remove + self.file + .seek(SeekFrom::Start(last_item_pos as u64)) + .unwrap(); + self.file.read_exact(&mut buffer).unwrap(); + self.file.seek(SeekFrom::Start(pos as u64)).unwrap(); + self.file.write_all(&buffer).unwrap(); + + // Truncate the file at the position of the last item + self.file.set_len(last_item_pos as u64).unwrap(); + } + } +} + +pub fn sync( + dir: &Path, + branch: Option<&str>, +) -> Result< + ( + Vec<(String, String)>, + Vec<(String, String)>, + Vec<(String, String)>, + Vec<(String, String)>, + ), + Box, +> { + let tree_path = tree_path_for_dir_branch(dir, branch); + let old_tree: Tree = match Tree::load(&tree_path) { + Ok(tree) => tree, + Err(_) => Tree::empty(), + }; + + // Calculate and save new tree + // TODO: Use modified files to speed up calculation + // let modified_files = get_modified_files(dir); + let new_tree = compute_tree_for_dir(dir, None)?; + + // Update last sync time + write_sync_time(); + + // Save new tree + new_tree.persist(&tree_path); + + // Compute diff + let (add, remove) = diff(&old_tree, &new_tree); + + // Compute the four action types: compute, remove, add tag, remove tag, + // transform into desired format: [(path, hash), ...], + // and update .index_cache + let index_cache_path = get_my_home() + .unwrap() + .unwrap() + .join(".continue/index/.index_cache"); + let mut disk_set = DiskSet::new(index_cache_path.to_str().unwrap()); + + let mut compute: Vec<(String, String)> = Vec::new(); + let mut delete: Vec<(String, String)> = Vec::new(); + let mut add_label: Vec<(String, String)> = Vec::new(); + let mut remove_label: Vec<(String, String)> = Vec::new(); + + for item in add { + if !item.is_blob { + continue; + } + let path = item.path.as_str().to_string(); + let hash = hash_string(item.hash); + if disk_set.contains(&item.hash) { + add_label.push((path, hash)); + } else { + compute.push((path, hash)); + } + } + + for item in remove { + if !item.is_blob { + continue; + } + if disk_set.contains(&item.hash) { + let path = item.path.as_str().to_string(); + let hash = hash_string(item.hash); + } else { + // Should never happen + } + } + + return Ok((compute, delete, add_label, remove_label)); +} + +#[cfg(test)] +mod tests { + use super::*; + use std::fs::remove_file; + + #[test] + fn test_disk_set() { + let path = "testfile"; + let mut disk_set = DiskSet::new(path); + + let item1: ObjectHash = [1; ITEM_SIZE]; + let item2: ObjectHash = [20; ITEM_SIZE]; + let item3: ObjectHash = [30; ITEM_SIZE]; + + // Test add and contains + disk_set.add(&item1); + disk_set.add(&item2); + assert!(disk_set.contains(&item1)); + assert!(disk_set.contains(&item2)); + + // Test the exact contents of the file + disk_set.file.seek(SeekFrom::Start(0)).unwrap(); + let mut buffer = [0; ITEM_SIZE]; + disk_set.file.read_exact(&mut buffer).unwrap(); + assert_eq!(buffer, item1); + disk_set.file.read_exact(&mut buffer).unwrap(); + assert_eq!(buffer, item2); + + // Test remove + disk_set.remove(&item1); + assert!(!disk_set.contains(&item1)); + assert!(disk_set.contains(&item2)); + + // Test one more add + disk_set.add(&item3); + assert!(disk_set.contains(&item3)); + + // Test the length of the file + disk_set.file.seek(SeekFrom::Start(0)).unwrap(); + let mut buffer = [0; ITEM_SIZE]; + let mut count = 0; + while disk_set.file.read_exact(&mut buffer).is_ok() { + count += 1; + } + assert_eq!(count, 2); + + // Clean up + remove_file(path).unwrap(); + } + + #[test] + fn test_sync() { + let ti = std::time::Instant::now(); + let results = sync( + Path::new("/Users/natesesti/Desktop/continue"), + Some("nate/pyO3"), + ); + println!("Sync took {:?}", ti.elapsed()); + // Vast majority (90+%) of this time is spent in compute_tree_for_dir + } + + #[test] + fn test_double_sync() { + let ti = std::time::Instant::now(); + let results = sync( + Path::new("/Users/natesesti/Desktop/continue"), + Some("nate/pyO3"), + ) + .expect("Sync failed."); + println!("First sync took {:?}", ti.elapsed()); + assert!(results.0.len() > 0); + assert!(results.1.len() > 0); + + let ti = std::time::Instant::now(); + let results = sync( + Path::new("/Users/natesesti/Desktop/continue"), + Some("nate/pyO3"), + ) + .expect("Sync failed"); + println!("Second sync took {:?}", ti.elapsed()); + assert_eq!(results.0.len(), 0); + assert_eq!(results.1.len(), 0); + } +}