From 1a469ba533be5e11c700556433cc74eb176ac86f Mon Sep 17 00:00:00 2001 From: "peng.li24" <734991033@qq.com> Date: Tue, 1 Sep 2026 23:04:08 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BA=AF=20kvlang=20=E8=BD=AC?= =?UTF-8?q?=E5=90=91=E2=80=94=E2=80=94=E5=88=A0=20Rust=20=E4=BA=8C?= =?UTF-8?q?=E8=BF=9B=E5=88=B6=EF=BC=8CKVLANG=5FLIB=3Dlib=20kvlang=20?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #$N byteseek 不再是可执行文件:删 Cargo.toml/build.rs/src(Rust crate), 改为 kvspace 里一棵 .kv 代码树,由 kvlang 工具链驱动(boot/run/test Makefile)。 shell·run/python·run 改 kv rwfunc 经 internet/proc·exec;CI 改 selftest。 Co-Authored-By: Claude --- .github/workflows/ci.yml | 19 +- Cargo.lock | 866 ------------------------------------- Cargo.toml | 14 - Makefile | 42 +- README.md | 18 +- README_CN.md | 18 +- build.rs | 52 --- doc/substrate.md | 174 ++++---- lib/byteseek/main.kv | 22 +- lib/byteseek/prompt.kv | 5 +- lib/byteseek/python.kv | 12 + lib/byteseek/shell.kv | 13 + src/main.rs | 73 ---- src/rwir/mod.rs | 153 ------- tests/selftest.kv | 30 ++ tests/selftest_kvlayout.kv | 22 - 16 files changed, 217 insertions(+), 1316 deletions(-) delete mode 100644 Cargo.lock delete mode 100644 Cargo.toml delete mode 100644 build.rs create mode 100644 lib/byteseek/python.kv create mode 100644 lib/byteseek/shell.kv delete mode 100644 src/main.rs delete mode 100644 src/rwir/mod.rs create mode 100644 tests/selftest.kv delete mode 100644 tests/selftest_kvlayout.kv diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea400a2..dd0c4f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,18 +1,19 @@ name: ci on: [push, pull_request, repository_dispatch] jobs: - build: + selftest: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: 检出 kvlang(runtime-rs 源依赖,path ../kvlang/runtime-rs) - run: | - git clone --depth 1 https://github.com/array2d/kvlang.git ../kvlang - - name: 下载 ABI 依赖 + - name: 检出 kvlang(提供 kvlang / kvlanglayout 工具链源) + run: git clone --depth 1 https://github.com/array2d/kvlang.git ../kvlang + - name: 下载 ABI 依赖(kvspace / kvspace-durable .so → /usr/lib) env: { GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" } run: ./ci/deps.sh - - name: 构建 kvlang runtime(bin/libkvlang_runtime.so,供 kvlang_rs build.rs 链接) + - name: 构建并安装 kvlang 工具链(kvlang / kvlanglayout + .so → /usr) working-directory: ../kvlang - run: make runtime - - name: 构建 - run: sudo -E make + run: | + make runtime runtime-rs layout + sudo -E make install + - name: byteseek 自检(无网络、无 LLM,shm 后端) + run: KVSPACE=shm:///tmp/byteseek_ci make test diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 161d1b9..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,866 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "adler2" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" - -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - -[[package]] -name = "bitflags" -version = "2.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da" - -[[package]] -name = "byteseek" -version = "0.1.0" -dependencies = [ - "kvlang-rs", -] - -[[package]] -name = "cc" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "509591b7bcd67f4ef775afad7662703b4935daaa6ec0e5605cfb1090b32a2b6d" -dependencies = [ - "find-msvc-tools", - "shlex", -] - -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - -[[package]] -name = "cfg_aliases" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" - -[[package]] -name = "clipboard-win" -version = "5.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bde03770d3df201d4fb868f2c9c59e66a3e4e2bd06692a0fe701e7103c7e84d4" -dependencies = [ - "error-code", -] - -[[package]] -name = "crc32fast" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "displaydoc" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" -dependencies = [ - "proc-macro2", - "quote", - "syn 3.0.3", -] - -[[package]] -name = "endian-type" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" - -[[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 = "error-code" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b5343afd4a8365a643ac588dab4cf234a190c7f6c88c9f6dd6ffe00837661b7" - -[[package]] -name = "fd-lock" -version = "4.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce92ff622d6dadf7349484f42c93271a0d49b7cc4d466a936405bacbe10aa78" -dependencies = [ - "cfg-if", - "rustix", - "windows-sys 0.59.0", -] - -[[package]] -name = "find-msvc-tools" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890" - -[[package]] -name = "flate2" -version = "1.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" -dependencies = [ - "crc32fast", - "miniz_oxide", -] - -[[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 = "getrandom" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "home" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" -dependencies = [ - "windows-sys 0.61.2", -] - -[[package]] -name = "icu_collections" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" -dependencies = [ - "displaydoc", - "potential_utf", - "utf8_iter", - "yoke", - "zerofrom", - "zerovec", -] - -[[package]] -name = "icu_locale_core" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" -dependencies = [ - "displaydoc", - "litemap", - "tinystr", - "writeable", - "zerovec", -] - -[[package]] -name = "icu_normalizer" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" -dependencies = [ - "icu_collections", - "icu_normalizer_data", - "icu_properties", - "icu_provider", - "smallvec", - "zerovec", -] - -[[package]] -name = "icu_normalizer_data" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" - -[[package]] -name = "icu_properties" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" -dependencies = [ - "displaydoc", - "icu_collections", - "icu_locale_core", - "icu_properties_data", - "icu_provider", - "zerotrie", - "zerovec", -] - -[[package]] -name = "icu_properties_data" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" - -[[package]] -name = "icu_provider" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92a7ed671a6aad807a8651a2e1782a6598fda9ce5185dd8158549e95a91c6428" -dependencies = [ - "displaydoc", - "icu_locale_core", - "writeable", - "yoke", - "zerofrom", - "zerotrie", - "zerovec", -] - -[[package]] -name = "idna" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" -dependencies = [ - "idna_adapter", - "smallvec", - "utf8_iter", -] - -[[package]] -name = "idna_adapter" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" -dependencies = [ - "icu_normalizer", - "icu_properties", -] - -[[package]] -name = "itoa" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" - -[[package]] -name = "kvlang-rs" -version = "0.1.0" -dependencies = [ - "libc", - "rustyline", - "serde_json", - "ureq", -] - -[[package]] -name = "libc" -version = "0.2.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" - -[[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.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" - -[[package]] -name = "log" -version = "0.4.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" - -[[package]] -name = "memchr" -version = "2.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" - -[[package]] -name = "miniz_oxide" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" -dependencies = [ - "adler2", - "simd-adler32", -] - -[[package]] -name = "nibble_vec" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" -dependencies = [ - "smallvec", -] - -[[package]] -name = "nix" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" -dependencies = [ - "bitflags", - "cfg-if", - "cfg_aliases", - "libc", -] - -[[package]] -name = "once_cell" -version = "1.21.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" - -[[package]] -name = "percent-encoding" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" - -[[package]] -name = "potential_utf" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" -dependencies = [ - "zerovec", -] - -[[package]] -name = "proc-macro2" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.47" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radix_trie" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" -dependencies = [ - "endian-type", - "nibble_vec", -] - -[[package]] -name = "ring" -version = "0.17.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" -dependencies = [ - "cc", - "cfg-if", - "getrandom", - "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.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0283386ce02abc0151e1761d08802dfe86c173b0b494af5cbc086574e453da06" -dependencies = [ - "log", - "once_cell", - "ring", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-pki-types" -version = "1.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" -dependencies = [ - "zeroize", -] - -[[package]] -name = "rustls-webpki" -version = "0.103.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0527518605e68109d875e248ea259b6758801cf165e4b2c2733ae3b51f12535a" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - -[[package]] -name = "rustyline" -version = "15.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ee1e066dc922e513bda599c6ccb5f3bb2b0ea5870a579448f2622993f0a9a2f" -dependencies = [ - "bitflags", - "cfg-if", - "clipboard-win", - "fd-lock", - "home", - "libc", - "log", - "memchr", - "nix", - "radix_trie", - "unicode-segmentation", - "unicode-width", - "utf8parse", - "windows-sys 0.59.0", -] - -[[package]] -name = "serde" -version = "1.0.229" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" -dependencies = [ - "serde_core", -] - -[[package]] -name = "serde_core" -version = "1.0.229" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.229" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" -dependencies = [ - "proc-macro2", - "quote", - "syn 3.0.3", -] - -[[package]] -name = "serde_json" -version = "1.0.151" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" -dependencies = [ - "itoa", - "memchr", - "serde", - "serde_core", - "zmij", -] - -[[package]] -name = "shlex" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" - -[[package]] -name = "simd-adler32" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" - -[[package]] -name = "smallvec" -version = "1.15.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" - -[[package]] -name = "stable_deref_trait" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "syn" -version = "2.0.119" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "3.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "synstructure" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", -] - -[[package]] -name = "tinystr" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" -dependencies = [ - "displaydoc", - "zerovec", -] - -[[package]] -name = "unicode-ident" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" - -[[package]] -name = "unicode-segmentation" -version = "1.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" - -[[package]] -name = "unicode-width" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" - -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - -[[package]] -name = "ureq" -version = "2.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" -dependencies = [ - "base64", - "flate2", - "log", - "once_cell", - "rustls", - "rustls-pki-types", - "url", - "webpki-roots 0.26.11", -] - -[[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 = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - -[[package]] -name = "wasi" -version = "0.11.1+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" - -[[package]] -name = "webpki-roots" -version = "0.26.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" -dependencies = [ - "webpki-roots 1.0.9", -] - -[[package]] -name = "webpki-roots" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" -dependencies = [ - "rustls-pki-types", -] - -[[package]] -name = "windows-link" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" - -[[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.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-sys" -version = "0.61.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "writeable" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" - -[[package]] -name = "yoke" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" -dependencies = [ - "stable_deref_trait", - "yoke-derive", - "zerofrom", -] - -[[package]] -name = "yoke-derive" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", - "synstructure", -] - -[[package]] -name = "zerofrom" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" -dependencies = [ - "zerofrom-derive", -] - -[[package]] -name = "zerofrom-derive" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.119", - "synstructure", -] - -[[package]] -name = "zeroize" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" - -[[package]] -name = "zerotrie" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" -dependencies = [ - "displaydoc", - "yoke", - "zerofrom", -] - -[[package]] -name = "zerovec" -version = "0.11.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b5c6b5976d66c1d703c4fd17d3f5e43c8cedaacf604961b171adc7130896d8" -dependencies = [ - "yoke", - "zerofrom", - "zerovec-derive", -] - -[[package]] -name = "zerovec-derive" -version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f212a141d820099d57ffafb9569be9617a6f27d3dc881fbee8fb56642f917a9" -dependencies = [ - "proc-macro2", - "quote", - "syn 3.0.3", -] - -[[package]] -name = "zmij" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index de0b97b..0000000 --- a/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "byteseek" -version = "0.1.0" -edition = "2021" -description = "KV 原生 agent substrate —— agent 的自己(代码/状态/记忆/执行)全在一棵可寻址、可持久、可自改的 kvspace 树" - -[[bin]] -name = "byteseek" -path = "src/main.rs" - -[dependencies] -# 复用 kvlang runtime-rs:Engine / ffi / 纯净 rwir(term/json/http/kvlanglayout) + 内嵌 stdlib。 -# byteseek 只叠加 agent 专属 rwir(byteseek·run/shell·run/python·run)与驱动循环。 -kvlang-rs = { path = "../kvlang/runtime-rs" } diff --git a/Makefile b/Makefile index ccf7572..bbbda42 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,26 @@ -# byteseek Makefile —— make 编译并安装到 /usr/bin 与 ~/.local/bin(/usr/bin 需 root:sudo -E make)。 -# 依赖 .so 由 ci/deps.sh 下载安装到 /usr/lib(kvspace_durable / kvlang_runtime / kvlang_layout)。 +# byteseek 全 kvlang(无 Rust,无编译产物)。byteseek 不是可执行文件,而是活在 kvspace 里的 +# 一棵 .kv 代码树,由标准 kvlang 工具链(kvlang / kvlanglayout)驱动。 +# deps 下载 ABI .so 到 /usr/lib(kvlang 二进制需另装,见 README) +# boot layout lib/ 全部 .kv 进 kvspace 并执行各 init(config/语法速览/系统提示种入) +# run boot 后进入 REPL(kvlang byteseek·main) +# test 无网络无 LLM 自检(boot → layout tests/selftest.kv → run selftest·go) +KVSPACE ?= redis://127.0.0.1:6379 +export KVSPACE -BIN := byteseek -PREFIX ?= /usr/bin -CARGO ?= $(shell command -v cargo 2>/dev/null || printf '%s' '$(HOME)/.cargo/bin/cargo') -OWNER ?= $(SUDO_USER) +.PHONY: deps boot run test -.PHONY: all install run clean +deps: + ./ci/deps.sh -all: install +boot: + KVLANG_LIB=lib kvlang -install: - $(CARGO) build --release - install -d $(HOME)/.local/bin - install -m 755 target/release/$(BIN) $(HOME)/.local/bin/$(BIN) - @if [ -n "$(OWNER)" ]; then chown $(OWNER) $(HOME)/.local/bin/$(BIN); fi - install -d $(PREFIX) - install -m 755 target/release/$(BIN) $(PREFIX)/$(BIN) - @echo "✅ 已安装: $(HOME)/.local/bin/$(BIN) 与 $(PREFIX)/$(BIN)" +run: boot + kvlang byteseek·main -run: all - $(HOME)/.local/bin/$(BIN) - -clean: - $(CARGO) clean +test: boot + kvlanglayout tests/selftest.kv "$(KVSPACE)" + @out=$$(kvlang selftest·go 2>&1); echo "$$out"; \ + echo "$$out" | grep -q "vet(good)= ok" && \ + echo "$$out" | grep -q "SESSION: selftest-shell" && \ + echo "$$out" | grep -q "PY: 42" && echo "✅ selftest 通过" || { echo "❌ selftest 失败"; exit 1; } diff --git a/README.md b/README.md index 42754b0..02a12bb 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,20 @@ A KV-native agent substrate: an agent's *self* — its code, state, memory, and execution progress — all live in one addressable, persistent, self-modifiable KV -tree (kvspace, backed by redis). LLM, shell, python, and sub-agents become -first-class citizens of this tree as registered rwir. One process = one -**corebrain**: lay the `.kv` into redis → register rwir → bootstrap a vthread → -drive execution (kvlang mode 2), handling rwir in place. +tree (kvspace, backed by redis/fs/shm/s3). LLM, shell, python, and sub-agents +become first-class citizens of this tree through kvlang's standard rwir and kv +`rwfunc`s. byteseek has no host language of its own and is not an executable: it +*is* a tree of `.kv` code, driven by the standard `kvlang` toolchain. -See `doc/substrate.md` for the architecture and implementation notes. +```bash +KVLANG_LIB=lib kvlang # boot: lay all lib/*.kv into kvspace, run each init +kvlang byteseek·main # run: drive the already-laid-out funckey (REPL) +``` + +Booting runs the layout-time `init`s that seed config, the kvlang syntax brief, +and the system prompt into the tree; running just drives the persisted funckey — +no rebuild, because there is nothing to compile. See `doc/substrate.md` for the +architecture and implementation notes. ## Roadmap: three stages diff --git a/README_CN.md b/README_CN.md index 1bd2f5d..44c9354 100644 --- a/README_CN.md +++ b/README_CN.md @@ -1,12 +1,18 @@ # byteseek KV 原生的 agent substrate:agent 的"自己"——代码、状态、记忆、执行进度——全部活在 -**同一棵可寻址、可持久、可自改的 KV 树**(kvspace,后端 redis)里。LLM、shell、 -python、子 agent 通过注册 rwir 成为这棵树里的一等公民。一个进程 = 一个 -**corebrain**:把 `.kv` 布局进 redis → 注册 rwir → bootstrap 一条 vthread → -主导驱动执行(kvlang 模式 2),遇到 rwir 就地处理。 - -架构与实现细节见 `doc/substrate.md`。 +**同一棵可寻址、可持久、可自改的 KV 树**(kvspace,后端 redis/fs/shm/s3)里。LLM、 +shell、python、子 agent 通过 kvlang 标准 rwir 与 kv `rwfunc` 成为这棵树里的一等公民。 +byteseek 没有自己的宿主语言,也不是可执行文件:它**就是**一棵 `.kv` 代码树,由标准 +`kvlang` 工具链驱动。 + +```bash +KVLANG_LIB=lib kvlang # 引导:layout lib/ 全部 .kv 进 kvspace,并执行各 init +kvlang byteseek·main # 运行:驱动已入库的 funckey(进入 REPL) +``` + +引导执行 layout 期的各 `init`,把配置、kvlang 语法速览、系统提示种进树;运行只驱动持久化的 +funckey——无需重编译,因为没有可编译之物。架构与实现细节见 `doc/substrate.md`。 ## 发展三阶段(roadmap) diff --git a/build.rs b/build.rs deleted file mode 100644 index e342b01..0000000 --- a/build.rs +++ /dev/null @@ -1,52 +0,0 @@ -// 链接 /usr/lib 下的三方 .so(byteseek 依赖 kvlang_rs,但其 build.rs 链接指令不传播, -// 故本 crate 须自带全部链接标志,解析 kvlang_rs::ffi 引用的 C 符号): -// kvspace_durable —— byteseek 自持 kvspace 句柄(KV 存取 + TLV) -// kvlang_runtime —— 模式2 执行 + rwirext 宿主 -// kvlanglayout —— .kv 编译入库 -// 并把 lib/**/*.kv(现仅 lib/byteseek/ 自举代码;http.kv 已下沉 runtime-rs stdlib) -// 全部 include_str! 进二进制(EMBEDDED_KV),启动时 layout 进 kvspace。 -use std::path::{Path, PathBuf}; - -fn collect_kv(dir: &Path, files: &mut Vec) { - let Ok(entries) = std::fs::read_dir(dir) else { - return; - }; - for e in entries.flatten() { - let p = e.path(); - if p.is_dir() { - collect_kv(&p, files); - } else if p.extension().is_some_and(|x| x == "kv") { - files.push(p); - } - } -} - -fn main() { - let manifest = env!("CARGO_MANIFEST_DIR"); - - println!("cargo:rustc-link-search=native=/usr/lib"); - println!("cargo:rustc-link-lib=dylib=kvspace_durable"); - println!("cargo:rustc-link-lib=dylib=kvlang_runtime"); - println!("cargo:rustc-link-lib=dylib=kvlanglayout"); - - println!("cargo:rustc-link-arg=-Wl,--disable-new-dtags"); // rpath 转 DT_RPATH,传递解析子依赖 - println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN"); - println!("cargo:rustc-link-arg=-Wl,-rpath,/usr/lib"); - - let libdir = format!("{manifest}/lib"); - let mut files: Vec = Vec::new(); - collect_kv(Path::new(&libdir), &mut files); - files.sort(); - let mut code = String::from("pub static EMBEDDED_KV: &[(&str, &str)] = &[\n"); - for p in &files { - let rel = p.strip_prefix(&libdir).unwrap_or(p); - let name = rel.to_string_lossy().trim_start_matches('/').to_string(); - let abs = p.to_string_lossy(); - code.push_str(&format!(" ({name:?}, include_str!({abs:?})),\n")); - println!("cargo:rerun-if-changed={abs}"); - } - code.push_str("];\n"); - let out = std::env::var("OUT_DIR").unwrap(); - std::fs::write(format!("{out}/embedded_kv.rs"), code).unwrap(); - println!("cargo:rerun-if-changed={libdir}"); -} diff --git a/doc/substrate.md b/doc/substrate.md index de3abf9..4595587 100644 --- a/doc/substrate.md +++ b/doc/substrate.md @@ -1,124 +1,126 @@ # byteseek —— KV 原生 agent substrate -> 日期:2026-08-19 -> 实现:`src/`(corebrain 引擎,Rust)+ `lib/byteseek/*.kv`(执行逻辑与提示词) +> 实现:`lib/byteseek/*.kv` + `lib/local/config.kv`(执行逻辑、提示词、配置,全部 kvlang)。 +> 无自有 Rust:byteseek 不是可执行文件,而是活在 kvspace 里的一棵 `.kv` 代码树,由标准 +> `kvlang` 工具链(runtime-rs 编译出的 `kvlang` 二进制)驱动。 + +## 定位 + +agent 的「自己」——代码、状态、记忆、执行进度——全部活在**同一棵可寻址、可持久、可自改的 +KV 树**(kvspace,后端 redis/fs/shm/s3)里。LLM、shell、python、json、http 通过 rwir 成为 +这棵树里的一等公民。byteseek 自身不叠加任何宿主语言:它复用 kvlang 标准 rwir,主脑逻辑全是 +`lib/` 下的 kv rwfunc。 ## 源码结构 ``` -src/main.rs 入口:连 kvspace → 清空 → 连 runtime → 注册 rwir → 种 LLM 配置 - → layout 全部内嵌 lib/byteseek/*.kv → 跑 byteseek.init → 进 REPL -src/ffi.rs C ABI:kvspace-durable(自持句柄)+ kvlang runtime(模式2 主导执行) - + rwirext 宿主 ABI + kvlang layout(vet/layout/format) -src/engine.rs Engine:kvspace 读写、talk 队列、主导驱动 vthread(run_fn 可重入) -src/rwir/ 一等公民 rwir,一模块一职责: - ├─ io.rs print / println / cerr / input(term 输入输出) - ├─ llm.rs llm.call(userinput) -> entry:代码脑,LLM 生成 kv 程序 - ├─ json.rs json.to / json.from:KV 子树 ↔ JSON(rust 内嵌,照搬 go/json) - ├─ http.rs http.call(method,header,url,body) -> resp(rust 原生 ureq) - ├─ kvlayout.rs kvlanglayout.vet / .layout / .src(layout C ABI) - └─ mod.rs 注册表 REGS + dispatch 派发 + shell/python 共用 tool_run +lib/byteseek/main.kv main / mainbrain(REPL 循环)/ run(动态执行生成程序) +lib/byteseek/llm.kv llm·call(userinput) -> entry:代码脑,LLM 生成 kv 程序并入库 +lib/byteseek/prompt.kv 系统提示(lib prompt 顶层写 → byteseek/prompt·init,layout 期种入) +lib/byteseek/kvlangbrief.kv kvlang 语法速览(顶层写 → byteseek·init,layout 期种入) +lib/byteseek/shell.kv shell·run(cmd) -> out:bash 子进程,捕获 stdout +lib/byteseek/python.kv python·run(code) -> out:python3 子进程,捕获 stdout +lib/local/config.kv LLM 配置(lib local 顶层写 → local·init,layout 期种入;gitignored) ``` -## 定位 +## 引导与运行 -byteseek 不是又一个 agent 框架。agent 的「自己」——代码、状态、记忆、执行进度——全部 -活在**同一棵可寻址、可持久、可自改的 KV 树**(kvspace,后端 redis/fs/s3)里。LLM、 -shell、python、json、http 通过注册 rwir 成为这棵树里的一等公民。 +byteseek 无「拉起进程」一说。两步: -一个进程 = 一个 **corebrain**:把 `.kv` 布局进 kvspace → 注册 rwir → bootstrap 一条 -vthread → 主导驱动执行(kvlang 模式 2),遇 rwir 就地处理。扩展库(json/http/…)是 -**单进程内嵌**的 Rust rwir + `lib/` 下 kv 源码的 rwfunc,不再起独立进程。 +```bash +KVLANG_LIB=lib kvlang # 引导:layout lib/ 全部 .kv 进 kvspace,并执行各 init +kvlang byteseek·main # 运行:驱动已入库的 funckey(进入 REPL) +``` + +`KVLANG_LIB=lib kvlang`(无 entry)复用标准 kvlang 的「layout 全部 lib + 跑各 init」机制: +`config.kv`/`kvlangbrief.kv`/`prompt.kv` 的顶层写语句被 parser 合成为 `local·init` / +`byteseek·init` / `byteseek/prompt·init`,在 layout 期执行一次,把配置、语法速览、系统提示 +种进 kvspace(跑完即删 init 子树)。rwfunc(`main`/`mainbrain`/`run`/`llm·call`/`shell·run`/ +`python·run`)留在 `/lib` 下持久。之后 `kvlang byteseek·main` 直接驱动 funckey,不再 layout、 +不再重跑 init。`byteseek·main` 是 funckey 路径(去 `/lib` 前缀),不是文件路径。 ## 状态树布局 ``` -/byteseek/llm.api LLM 接口地址(seed 从 DEEPSEEK_API_URL 读入,有默认) -/byteseek/llm.key LLM 鉴权 key(DEEPSEEK_API_KEY,可空) -/byteseek/prompt/system 系统提示(prompt.kv 的 seed_prompts() 播种) -/lib/byteseek.kvlangbrief kvlang 语法速览(llm.call 拼进 system prompt) -/byteseek/session/talk/* 对话队列(input 落入,可寻址/持久) +/byteseek/llm.api LLM 接口地址(config.kv 种入) +/byteseek/llm.key LLM 鉴权 key(config.kv 种入,可空) +/byteseek/llm.print 是否打印 LLM 交互(config.kv 种入) +/byteseek/prompt/system 系统提示(prompt.kv 种入) +/lib/byteseek.kvlangbrief kvlang 语法速览(kvlangbrief.kv 种入;llm·call 拼进 system prompt) +/lib/byteseek/session/ llm·call 生成并入库的一次性程序(可寻址/持久) /vthread/{vid}/‥pc 执行到哪一步(KV 路径字符串,崩溃可恢复) -/lib/./... 编译后函数(签名 + 指令 + 源码 .src) +/lib/·/... 编译后函数(签名 + 指令 + 源码 .src) ``` -一个 session 的全部状态可直接观测:`kvspace tree /byteseek/session/`。 - ## 提示词与 LLM 参数也是 KV 数据 -系统提示不硬编码在 Rust 里,而是 `lib/byteseek/prompt.kv` 的 `seed_prompts()` 把提示词 -写进 `/byteseek/prompt/system`;语法速览由 `kvlangbrief.kv` 落进 `/lib/byteseek.kvlangbrief`。 -`llm.call` 每轮把两者拼成 system prompt。LLM 接口地址与 key 由 `llm::seed` 从环境读入 -`/byteseek/llm.api` / `/byteseek/llm.key`。换模型/网关/提示词只需改树,无需重编译。 +系统提示不硬编码,而是 `prompt.kv` 的 `lib prompt` 顶层写把提示词落进 `/byteseek/prompt/system`; +语法速览由 `kvlangbrief.kv` 落进 `/lib/byteseek.kvlangbrief`。`llm·call` 每轮把两者拼成 +system prompt。接口地址与 key 由 `config.kv` 种入。换模型/网关/提示词只需改树,无需重编译—— +本就无可编译之物。 -## 代码脑:llm.call 生成 kv 代码(自造代码) +## 代码脑:llm·call 生成 kv 代码(自造代码) -corebrain 的主循环不再是「LLM 决定动作类型 → 分派固定工具」,而是 **LLM 直接生成一段 -kvlang 程序并执行**: +主循环不是「LLM 决定动作类型 → 分派固定工具」,而是 **LLM 直接生成一段 kvlang 程序并执行**: -``` -rwfunc main() -> () { seed_prompts(); mainbrain() } +```kv +rwfunc main() -> () { byteseek·mainbrain() } rwfunc mainbrain() -> () { running = 1 while (running == 1) { input("byteseek> ") -> userinput - string.cmp(userinput, "exit") -> q + string·cmp(userinput, "exit") -> q if (q == 0) { running <- 0 } - else { llm.call(userinput) -> entry; byteseek.run(entry) } + else { llm·call(userinput) -> entry; byteseek·run(entry) } } println("bye.") } ``` -`llm.call(userinput)`:system prompt(提示词 + 语法速览)→ LLM → 解析 ``/`` → -包进 `lib byteseek { lib session { lib NAME {…} } }` → `kvlanglayout.vet` 校验 → 通过后 -`kvlanglayout.src` layout 入库 → 返回入口 `byteseek/session/NAME.init`。生成失败回填 -`error: …`,`byteseek.run` 跳过执行。 - -## rwir(一等公民) - -在 `rwir::register`(`src/rwir/mod.rs` 的 `REGS` 表)里注册到 `/lib/`: +`llm·call(userinput)`:system prompt(提示词 + 语法速览)→ LLM → 解析 ``/`` → +包进 `lib byteseek { lib session { lib NAME { … NAME·main() } } }` → `kvlanglayout·vet` 校验 → +通过后 `kvlanglayout·layout` 入库 → 返回入口 `byteseek/session/NAME·init`。生成失败回填 +`error: …`,`byteseek·run` 据前缀跳过执行。 -| opcode | 处理 | -|--------|------| -| `print / println / cerr / input` | term 输入输出(io.rs) | -| `llm.call(userinput) -> entry` | 代码脑:LLM 生成 kv 程序入库 | -| `byteseek.run(entry)` | 把生成的 kv 程序作为嵌套 vthread 跑完 | -| `shell.run(cmd) -> out` / `python.run(code) -> out` | 子进程工具(mod.rs tool_run,截断 TOOL_CAP) | -| `json.to(root) -> str` / `json.from(str) -> root` | KV 子树 ↔ JSON | -| `http.call(method,header,url,body) -> resp` | 网络抓取(rust 原生 ureq) | -| `kvlanglayout.vet / .layout / .src` | .kv 校验/入库(layout C ABI) | - -`lib/byteseek/http.kv` 是 rwfunc 标准库示例:`lib http { rwfunc get/post/put/del }` 封装 -`http.call`(kv 源码,可寻址/可自改)。 - -## 模式 2 主导驱动 - -`Engine::run_fn(funcname)`:`kvlangRuntimeBootstrap` 拿 vid → 循环 -`kvlangRuntimeExecuteVthread`:rc==0 结束;rc==1 遇 ext rwir,就地 `dispatch`(op 由 -`kvlang_rwirextParams` 首行解码),再 `kvlang_rwirextNextPc` 写回 `/vthread/{vid}/‥pc`。 -可重入:`byteseek.run` 在 dispatch 里嵌套调用 `run_fn`。 - -## 实现要点(踩坑记录) - -**带 scope 的函数必须在被调用的嵌套帧里执行。** layout 禁止顶层 `while`,会把顶层语句 -包进 `init` 帧。若直接 bootstrap 带 scope 的函数作为顶层 vthread 帧,其 while 的 scope PC -无法经该帧的 extindex 解析,会静默失败。正确做法:`main()` 无 scope,由它调用带 while -的 `mainbrain()`,让 scope PC 在嵌套调用帧里正确寻址。见 `run_fn`。 +## byteseek·run:同 vthread 动态执行(进程↔vid 1:1) -## 运行 - -```bash -cargo build --release -KVSPACE=redis://127.0.0.1:6379 DEEPSEEK_API_KEY=... ./target/release/byteseek +```kv +rwfunc run(entry:[]char/utf32) -> () { + if (entry == "") { return } + string·find(entry, "error") -> iserr + if (iserr == 0) { println("[byteseek] 跳过执行(生成失败):", entry); return } + vthread·call(entry) +} ``` -环境变量:`KVSPACE`(默认 `redis://127.0.0.1:6379`)、`DEEPSEEK_API_URL`(默认 deepseek)、 -`DEEPSEEK_API_KEY`。 +`vthread·call(funckey)` 是 kvlang 的 native builtin(`runtime/src/builtin.c`):在**当前 vthread** +(同 vid)按运行时 funckey 造一次动态 `OP_CALL`,跑到被调函数结束再回到本指令的 NextPc。与 +`vthread·run` 不同——不新开 vid、不 WATCH 挂起——被调程序里的 rwir(`println`/`shell·run`/…) +由当前驱动就地派发。故一次 REPL 请求、生成程序的执行、其内工具调用全在同一进程同一 vid 内完成, +契合「一个进程 ⟺ 一条 vthread」。 -## 已验证 +## rwir:全部复用 kvlang 标准集 -- json.to/from 子树 ↔ JSON 往返(fs 后端单测,输出与 tutorial/10 一致) -- http lib 源码 vet(`[]char/utf32` 参数类型) -- 多级嵌套 lib layout + 增量合并(layout 单测,`lib a { lib b {…} }`) -- layout 三 ABI:vet / format(保 lib 分组、幂等)/ layoutcode(按函数覆盖) +byteseek 不再注册任何自有 Rust rwir。所需能力全部是 kvlang 标准 rwir(runtime-rs / runtime-c): + +| opcode | 来源 | +|--------|------| +| `print` / `println` / `cerr` / `input` | 标准 term rwir | +| `json·to` / `json·from` | 标准 json rwir | +| `http·call(method,header,url,body) -> resp` | 标准 http rwir | +| `kvlanglayout·vet / ·format / ·layout / ·dump` | 标准 layout rwir | +| `internet/proc·exec(args,envs) -> code, out, err` | 标准 internet rwir(子进程 + 捕获 @ 句柄) | +| `vthread·call(funckey)` | native builtin(同 vid 动态调用) | +| `string·* / kv·* / xv·*` | native builtin | + +`shell·run` / `python·run` 是 `lib/` 下的 kv rwfunc:把命令包成 `{"bash","-c",cmd}` / +`{"python3","-c",code}` 交给 `internet/proc·exec`,绑定 stdout/stderr 写槽即捕获(`@[]uint8` +扩展句柄,`println` 读时按 body 前缀 `/internet/{host}/proc` 路由回兑现物理字节),返回 stdout。 + +## 已验证(0rs) + +- `KVLANG_LIB=lib kvlang` 引导:config/语法速览/系统提示三 init 于 layout 期种入,rwfunc 持久。 +- `kvlang byteseek·main`:REPL 循环、`exit` 退出、无 key 时 `llm·call` 回填 error 且 `byteseek·run` 跳过。 +- `byteseek·run(entry)` → `vthread·call`:同 vid 动态执行入库的 session 程序,其内 rwir 就地派发。 +- `shell·run` / `python·run`:经 `internet/proc·exec` 捕获子进程 stdout 并透明兑现。 +- `make test`(无网络无 LLM,shm 后端):vet + session 执行 + shell/python 捕获全链路通过。 diff --git a/lib/byteseek/main.kv b/lib/byteseek/main.kv index b2ae5ed..2473cd6 100644 --- a/lib/byteseek/main.kv +++ b/lib/byteseek/main.kv @@ -1,17 +1,14 @@ -# byteseek 主脑。main 播种提示词后进入 mainbrain 循环: -# input 等待用户输入 → llm·call 生成一段 kv 程序(layout 到 /lib/byteseek/session/<名>) -# → byteseek·run 执行它。输入 exit 退出。 -# main 无 scope(只是两个调用),可被直接 bootstrap;mainbrain 的 while/if 在嵌套帧里寻址。 +# byteseek 主脑(全 kvlang,无自有 Rust)。config/语法速览/系统提示皆为 layout 期 init 种入, +# main 不再播种,只进 mainbrain 循环:input 等输入 → llm·call 生成 kv 程序(layout 入库)→ +# byteseek·run 执行它。输入 exit 退出。byteseek 不是可执行文件,用 `kvlang byteseek·main` 驱动。 lib byteseek { rwfunc main() -> () { - local·init() - byteseek·seed_prompts() byteseek·mainbrain() } rwfunc mainbrain() -> () { - running = 1 # = 等价于 <- + running = 1 while (running == 1) { input("byteseek> ") -> userinput string·cmp(userinput, "exit") -> q @@ -24,4 +21,15 @@ lib byteseek { } println("bye.") } + + # byteseek·run(entry):在当前 vthread(同 vid)动态调用生成程序的入口 funckey,跑完回主循环。 + rwfunc run(entry:[]char/utf32) -> () { + if (entry == "") { return } + string·find(entry, "error") -> iserr + if (iserr == 0) { + println("[byteseek] 跳过执行(生成失败):", entry) + return + } + vthread·call(entry) + } } diff --git a/lib/byteseek/prompt.kv b/lib/byteseek/prompt.kv index 4193180..6f636ec 100644 --- a/lib/byteseek/prompt.kv +++ b/lib/byteseek/prompt.kv @@ -1,8 +1,9 @@ # byteseek 代码脑的系统提示 —— 也是 KV 数据(活在 /byteseek/prompt/system,可寻址/持久/自改)。 -# seed_prompts() 由 byteseek.main 启动时调用;llm.call 把这段与 /lib/byteseek.kvlangbrief(语法速览)拼成 system prompt。 +# 嵌套 lib prompt 的顶层写语句 → byteseek/prompt·init,KVLANG_LIB 引导时(layout 期)执行一次种入。 +# llm·call 把这段与 /lib/byteseek.kvlangbrief(语法速览)拼成 system prompt。 lib byteseek { - rwfunc seed_prompts() -> () { + lib prompt { """你是 byteseek 的代码脑。你不是在回答问题,你在写代码:把用户的自然语言需求翻译成一段可运行的 kvlang 程序。 严格按下面格式输出,只输出这一段,不要任何解释、markdown 围栏、问候语、前后缀: diff --git a/lib/byteseek/python.kv b/lib/byteseek/python.kv new file mode 100644 index 0000000..2a41859 --- /dev/null +++ b/lib/byteseek/python.kv @@ -0,0 +1,12 @@ +# python·run(code) -> out:跑一段 python3 -c,返回 stdout(@ 句柄,读时兑现)。 + +lib python { + rwfunc run(code:[]char/utf32) -> (out:[]char/utf32) { + println("🔧 python:", code) + noenv = map() + a = {"python3", "-c", code} + internet/proc·exec(a, noenv) -> ret, o, e + println("↳", o, e) + o -> out + } +} diff --git a/lib/byteseek/shell.kv b/lib/byteseek/shell.kv new file mode 100644 index 0000000..5244617 --- /dev/null +++ b/lib/byteseek/shell.kv @@ -0,0 +1,13 @@ +# shell·run(cmd) -> out:跑一段 bash,返回 stdout(@ 句柄,读时兑现)。 +# 绑定 out/err 写槽 → internet/proc·exec 管道捕获两流;就地打印工具头与两流后返回 stdout。 + +lib shell { + rwfunc run(cmd:[]char/utf32) -> (out:[]char/utf32) { + println("🔧 shell:", cmd) + noenv = map() + a = {"bash", "-c", cmd} + internet/proc·exec(a, noenv) -> code, o, e + println("↳", o, e) + o -> out + } +} diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index f8e28c0..0000000 --- a/src/main.rs +++ /dev/null @@ -1,73 +0,0 @@ -//! byteseek —— KV 原生 agent substrate。 -//! -//! agent 的"自己"(代码/状态/记忆/执行)整个放进一棵可寻址、可持久、可自改的 kvspace(redis) 树。 -//! 本进程启动即:连 kvspace → 注册 rwir(kvlang_rs 纯净集 + byteseek 自有)→ layout runtime-rs -//! 内嵌 stdlib 与自举 lib/byteseek/*.kv → 跑 byteseek·init 种语法速览 → 驱动 byteseek·main 进入 -//! REPL(input 等 stdin、llm·call 生成 kv、byteseek·run 执行)。 -//! -//! Engine / ffi / 纯净 rwir(term/json/http/kvlanglayout) 全部复用 kvlang runtime-rs(kvlang_rs crate), -//! byteseek 仅叠加 agent 专属 rwir 与驱动循环(见 crate::rwir)。 -#![allow(non_snake_case)] - -mod rwir; - -use kvlang_rs::engine::Engine; -use kvlang_rs::ffi::*; -use std::ffi::c_char; - -include!(concat!(env!("OUT_DIR"), "/embedded_kv.rs")); // byteseek 自举代码 lib/byteseek/*.kv - -fn main() { - let dsn = std::env::var("KVSPACE").unwrap_or_else(|_| "redis://127.0.0.1:6379".to_string()); - - // 1) 连接 kvspace(byteseek 自持句柄)并清空 - let kv = unsafe { kvspaceConnect(cs(&dsn).as_ptr()) }; - if kv.is_null() { - eprintln!("kvspaceConnect 失败: {dsn}"); - std::process::exit(1); - } - let mut cerr = [0u8; 256]; - unsafe { kvspaceClear(kv, cerr.as_mut_ptr() as *mut c_char, 256) }; - - // 2) 连接 runtime - let rt = unsafe { kvlangRuntimeConnect(cs(&dsn).as_ptr()) }; - if rt.is_null() { - eprintln!("kvlangRuntimeConnect 失败: {dsn}"); - std::process::exit(1); - } - let eng = Engine { - rt, - kv, - dsn: dsn.clone(), - ext: None, // byteseek 用自有 run_fn 驱动(rwir::dispatch 就地处理),不走 kvlang_rs run_fn 的 ext 委托。 - }; - - // 3) 注册 rwir(纯净集 + byteseek 自有) - rwir::register(&eng); - - // 4) layout+run runtime-rs 内嵌 stdlib(http/kv/string/… 常量落值),再 layout byteseek 自举代码 - eng.layout_stdlib(); - eng.run_stdlib_init(); - for (name, src) in EMBEDDED_KV { - rwir::layout_src(&eng, name, src); - } - - // 5) 跑 byteseek·init,把语法速览种进 /lib/byteseek.kvlangbrief - rwir::run_fn(&eng, "byteseek·init"); - let brief = eng.get_kv("/lib/byteseek.kvlangbrief"); - println!( - "[byteseek] kvlangbrief 已种入 /lib/byteseek.kvlangbrief({} 字符)", - brief.chars().count() - ); - if brief.trim().is_empty() { - eprintln!("[byteseek] 警告:/lib/byteseek.kvlangbrief 为空"); - } - - // 6) 驱动 byteseek·main 进入 REPL - rwir::run_fn(&eng, "byteseek·main"); - - unsafe { - kvlangRuntimeDisconnect(rt); - kvspaceClose(kv); - }; -} diff --git a/src/rwir/mod.rs b/src/rwir/mod.rs deleted file mode 100644 index 61a3c0e..0000000 --- a/src/rwir/mod.rs +++ /dev/null @@ -1,153 +0,0 @@ -//! byteseek 运行时胶水:复用 kvlang_rs 的 Engine / ffi / 纯净 rwir(term/json/http/kvlanglayout), -//! 只叠加 agent 专属 rwir 与模式2 驱动循环: -//! byteseek·run : 把生成的 kv 程序作为嵌套 vthread 跑到结束(可重入 run_fn) -//! shell·run : 跑一段 bash,stdout(+stderr) 截断后写回槽 -//! python·run : 跑一段 python3,同上 -//! input : 委托纯净 input 读行,再把该行落入 byteseek session 的 talk 队列 -//! env·get : 读环境变量(缺省空串),供 kv 侧自播配置 -//! llm·call 与 llm 配置种子(seedllm)皆已是 kv 代码(lib/byteseek/llm.kv、main.kv),Rust 无 llm 逻辑。 - -use std::ffi::c_char; -use std::process::Command; -use std::ptr::null_mut; - -use kvlang_rs::engine::Engine; -use kvlang_rs::ffi::*; -use kvlang_rs::rwir as std_rwir; - -const TOOL_CAP: usize = 4000; // shell/python 工具输出截断 - -/// byteseek 自有 rwir 注册表:(opcode, 读参数, 写参数, 签名)。 -pub const REGS: &[(&str, i32, i32, &str)] = &[ - ("byteseek·run", 1, 0, "any"), - ("shell·run", 1, 1, "any\nany"), - ("python·run", 1, 1, "any\nany"), -]; - -/// 先注册 kvlang_rs 纯净集(term/json/http/kvlanglayout),再叠加 byteseek 自有 rwir。 -pub fn register(eng: &Engine) { - std_rwir::register(eng); - for (op, nr, nw, sig) in REGS { - unsafe { kvlang_rwirextRegister(eng.kv, cs(op).as_ptr(), *nr, *nw, cs(sig).as_ptr()) }; - } -} - -/// 把一段 .kv 源码 layout 进 kvspace(byteseek 自举代码 lib/byteseek/*.kv)。 -pub fn layout_src(eng: &Engine, name: &str, src: &str) { - let mut err = [0u8; 4096]; - let rc = unsafe { - kvlangLayoutCode( - cs(src).as_ptr(), - cs(&eng.dsn).as_ptr(), - null_mut(), - 0, - err.as_mut_ptr() as *mut c_char, - err.len() as u32, - ) - }; - if rc != 0 { - eprintln!("[byteseek] layout {name} 失败: {}", cbuf(&err).trim()); - std::process::exit(1); - } - println!("[byteseek] layout {name}"); -} - -/// bootstrap 一个函数并主导驱动其 vthread 直到结束(模式2,全部就地 dispatch)。 -/// funcname 按最后一个点切分为 pkg/name(如 "byteseek.main"、"byteseek/session/x.init")。 -/// 可重入:byteseek·run 在 dispatch 里嵌套调用本函数。 -pub fn run_fn(eng: &Engine, funcname: &str) { - let vid = take(unsafe { kvlangRuntimeBootstrap(eng.rt, cs(funcname).as_ptr(), null_mut(), 0) }); - if vid.is_empty() { - eprintln!("[byteseek] bootstrap {funcname} 失败"); - return; - } - let vpc = format!("/vthread/{vid}/\u{2025}pc"); - loop { - let mut pc: *mut c_char = null_mut(); - let rc = unsafe { kvlangRuntimeExecuteVthread(eng.rt, cs(&vid).as_ptr(), &mut pc) }; - if rc == 0 { - break; // done - } - if rc != 1 { - let st = eng.get_kv(&format!("/vthread/{vid}/\u{2025}status")); - let msg = eng.get_kv(&format!("/vthread/{vid}/\u{2025}error/msg")); - eprintln!("[byteseek] vthread {vid} 错误 rc={rc} {st}: {msg}"); - break; - } - let c = take(pc); - let params = take(unsafe { kvlang_rwirextParams(eng.kv, cs(&c).as_ptr()) }); - let op = params.lines().next().unwrap_or("").to_string(); - dispatch(eng, &op, &c); - let nxt = take(unsafe { kvlang_rwirextNextPc(cs(&c).as_ptr()) }); - eng.set_kv(&vpc, &nxt); - } -} - -/// 驱动循环遇到 rwir 分派:byteseek 自有就地处理,其余委托 kvlang_rs 纯净 rwir。 -pub fn dispatch(eng: &Engine, op: &str, pc: &str) { - match op { - "byteseek·run" => byteseek_run(eng, &eng.read0(pc)), - "shell·run" => { - let out = tool_run("shell", "bash", "-c", &eng.read0(pc)); - eng.set_kv(&eng.write0(pc), &out); - } - "python·run" => { - let out = tool_run("python", "python3", "-c", &eng.read0(pc)); - eng.set_kv(&eng.write0(pc), &out); - } - "input" => { - std_rwir::dispatch(eng, "input", pc); - let line = eng.get_kv(&eng.write0(pc)); - talk_push(eng, "user", &line); - } - other => std_rwir::dispatch(eng, other, pc), - } -} - -/// byteseek·run(entry):把生成的 kv 程序作为嵌套 vthread 跑到结束。 -fn byteseek_run(eng: &Engine, entry: &str) { - if entry.is_empty() || entry.starts_with("error") { - eprintln!("[byteseek] 跳过执行(生成失败):{entry}"); - return; - } - run_fn(eng, entry); -} - -/// talk 队列:byteseek session 下的对话记录(input 落入此处,可寻址/持久)。 -fn talk_push(eng: &Engine, role: &str, content: &str) { - let n: u32 = eng - .get_kv("/byteseek/session/talk/count") - .trim() - .parse() - .unwrap_or(0); - eng.set_kv(&format!("/byteseek/session/talk/{n}/role"), role); - eng.set_kv(&format!("/byteseek/session/talk/{n}/content"), content); - eng.set_kv("/byteseek/session/talk/count", &(n + 1).to_string()); -} - -/// shell·run / python·run 共用:跑一段代码,stdout(+stderr) 截断后作为字符串返回。 -fn tool_run(label: &str, prog: &str, flag: &str, code: &str) -> String { - println!("\n🔧 {label}:\n{code}"); - let out = Command::new(prog).arg(flag).arg(code).output(); - let mut result = match out { - Ok(o) => { - let mut s = String::from_utf8_lossy(&o.stdout).into_owned(); - let e = String::from_utf8_lossy(&o.stderr); - if !e.trim().is_empty() { - s.push_str("\n[stderr]\n"); - s.push_str(&e); - } - if s.trim().is_empty() { - s = format!("(无输出, exit={})", o.status.code().unwrap_or(-1)); - } - s - } - Err(e) => format!("执行失败: {e}"), - }; - if result.len() > TOOL_CAP { - result.truncate(TOOL_CAP); - result.push_str("\n…(已截断)"); - } - println!("↳ 输出:\n{result}"); - result -} diff --git a/tests/selftest.kv b/tests/selftest.kv new file mode 100644 index 0000000..d268468 --- /dev/null +++ b/tests/selftest.kv @@ -0,0 +1,30 @@ +# byteseek 自检(无网络、无 LLM):验证全 kvlang 主脑的执行链—— +# byteseek·run(entry) → vthread·call 在当前 vthread 动态执行生成程序; +# shell·run / python·run 经 internet/proc·exec 捕获子进程 stdout。 +# 先 boot byteseek 库(KVLANG_LIB=lib kvlang),再 layout 本文件,最后 run selftest·go。 +# 期望输出: +# vet(good)= ok +# SESSION: selftest-shell +# PY: 42 + +lib byteseek { + lib session { + lib demo { + rwfunc main() -> () { + shell·run("echo selftest-shell") -> o + println("SESSION:", o) + python·run("print(6*7)") -> p + println("PY:", p) + } + byteseek/session/demo·main() + } + } +} + +lib selftest { + rwfunc go() -> () { + kvlanglayout·vet("rwfunc twice(a:int64) -> (b:int64) { a + a -> b }") -> v + println("vet(good)=", v) + byteseek·run("byteseek/session/demo·init") + } +} diff --git a/tests/selftest_kvlayout.kv b/tests/selftest_kvlayout.kv deleted file mode 100644 index aa06a1a..0000000 --- a/tests/selftest_kvlayout.kv +++ /dev/null @@ -1,22 +0,0 @@ -# byteseek 自检:kvlanglayout.vet / .src / .layout 三入口(无网络、无 LLM)。 -# 验证 corebrain 自造 kv 代码 → 校验 → 入库 → 可寻址读回 全链路。 -# 用法:BYTESEEK_AGENT=agent/selftest_kvlayout.kv ./target/debug/byteseek - -good = "rwfunc twice(a:int64) -> b:int64 { add(a, a) -> b }" # = 等价于 <- -bad <- "rwfunc broken( -> {" - -# 1) vet 合法源码 => ok(只校验,不入库) -kvlanglayout.vet(good) -> vok -println("vet(good) => ", vok) - -# 2) vet 非法源码 => 错误信息(不打崩进程) -kvlanglayout.vet(bad) -> badout -println("vet(bad) => ", badout) - -# 3) src 把内存源码 layout 进 kvspace => 入口名 twice -kvlanglayout.src(good) -> entry -println("src(good) => ", entry) - -# 4) 读回 /lib/twice.src —— 自造代码可寻址、可读回 -src_back <- /lib/twice.src -println("readback => ", src_back)