diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16c518f..3e2574c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,71 @@ jobs: - name: Test default features run: cargo test + # The module crate is its own workspace root (see the `exclude` note in the + # root Cargo.toml), so NONE of the steps above touch it: `--all-targets`, + # `--all-features` and `--workspace` all stop at the workspace boundary and + # exit 0 without having compiled a line of it. + # + # That silence is the hazard. A cdylib that fails to build is a release that + # cannot be cut, and it would be discovered at release time rather than on the + # PR that broke it. So it gets its own job with the same gates. + module: + name: Module (own workspace) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + submodules: recursive + + - uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + + - uses: Swatinem/rust-cache@v2 + + - name: Check formatting + run: cargo fmt --manifest-path crates/tinymemory-module/Cargo.toml --all -- --check + + - name: Clippy + run: >- + cargo clippy --manifest-path crates/tinymemory-module/Cargo.toml + --all-targets -- -D warnings + + - name: Build the cdylib + run: cargo build --manifest-path crates/tinymemory-module/Cargo.toml --release + + - name: Unit tests + run: cargo test --manifest-path crates/tinymemory-module/Cargo.toml --lib + + # The loader E2E drives a real dlopen'ed module, and tinybus binds its + # broker tasks to the runtime that created them. The module is loaded once + # per process and never unloaded, so two such tests in one process leave the + # second talking to a dead broker and it HANGS rather than failing. Hence + # one process per test, with a timeout so a hang is a red build and not a + # six-hour job. + - name: Loader E2E (one process per test) + env: + TINYMEMORY_TEST_MODULE: >- + ${{ github.workspace }}/crates/tinymemory-module/target/release/libtinymemory_module.so + run: | + set -euo pipefail + tests=$( + cargo test --manifest-path crates/tinymemory-module/Cargo.toml \ + --test module_e2e -- --ignored --list \ + | sed -n 's/^\(.*\): test$/\1/p' + ) + if [ -z "$tests" ]; then + echo "No ignored E2E tests were found — the list step is broken." >&2 + exit 1 + fi + for test in $tests; do + echo "::group::$test" + timeout 300 cargo test --manifest-path crates/tinymemory-module/Cargo.toml \ + --test module_e2e -- --ignored --exact "$test" + echo "::endgroup::" + done + docs: name: Docs runs-on: ubuntu-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4c60ed4..c5250f3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,6 +11,13 @@ on: - patch - minor - major + existing_tag: + description: >- + Re-cut module artifacts for a tag that already exists, skipping the + version bump and tag. Leave empty for a normal release. + type: string + required: false + default: "" concurrency: group: release-${{ github.ref_name }} @@ -20,9 +27,24 @@ permissions: contents: write jobs: - publish: - name: Publish crate + # Cuts the version bump and the tag. It deliberately does **not** publish to + # crates.io, and that is not an omission to be fixed later: `tinymemory-core` + # depends on `tinycortex-api`, which is consumed by path and is not on + # crates.io, so `cargo package` cannot resolve it (`no matching package named + # 'tinycortex-api' found`). Every consumer takes this repo by path or git. + # The crates are `publish = false` so the two facts cannot drift apart. + # + # What a release produces is the tag plus the per-platform module archives and + # their `checksum.toml` — that is what a host pins and verifies. + tag: + name: Tag release if: ${{ github.ref == 'refs/heads/main' }} + # Consumed by `release-target`. The `version` step already writes both to + # `$GITHUB_OUTPUT`; without this block they stop at the job boundary and the + # module bundles resolve an empty tag. + outputs: + tag: ${{ steps.version.outputs.tag }} + next_version: ${{ steps.version.outputs.next_version }} runs-on: ubuntu-latest environment: Production steps: @@ -121,9 +143,6 @@ jobs: git commit -m "Release ${RELEASE_TAG}" git tag -a "${RELEASE_TAG}" -m "Release ${RELEASE_TAG}" - - name: Package crate - run: cargo package --locked - - name: Push release commit and tag env: RELEASE_TAG: ${{ steps.version.outputs.tag }} @@ -132,7 +151,255 @@ jobs: git push origin "HEAD:${GITHUB_REF_NAME}" git push origin "${RELEASE_TAG}" - - name: Publish to crates.io - run: cargo publish --locked + release-target: + name: Resolve release target + needs: tag + # `always()` so a skipped tag job still yields a target: re-cutting the + # module artifacts for an existing tag is a genuinely independent release. + if: ${{ always() && (inputs.existing_tag != '' || needs.tag.result == 'success') }} + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.resolve.outputs.tag }} + next_version: ${{ steps.resolve.outputs.next_version }} + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Resolve the tag and version to build + id: resolve + shell: bash + env: + EXISTING_TAG: ${{ inputs.existing_tag }} + PUBLISHED_TAG: ${{ needs.tag.outputs.tag }} + PUBLISHED_VERSION: ${{ needs.tag.outputs.next_version }} + run: | + set -euo pipefail + if [[ -n "$EXISTING_TAG" ]]; then + git fetch --tags origin + git rev-parse --verify --quiet "refs/tags/${EXISTING_TAG}" >/dev/null \ + || { echo "tag ${EXISTING_TAG} does not exist" >&2; exit 1; } + tag="$EXISTING_TAG" + version="${EXISTING_TAG#v}" + else + tag="$PUBLISHED_TAG" + version="$PUBLISHED_VERSION" + fi + [[ -n "$tag" && -n "$version" ]] || { echo "could not resolve a release target" >&2; exit 1; } + { + echo "tag=${tag}" + echo "next_version=${version}" + } >> "$GITHUB_OUTPUT" + + native-bundles: + name: Module bundle (${{ matrix.id }}) + needs: release-target + # `always()` is required even though `release-target` succeeds: GitHub + # propagates a skip transitively, so a skipped `tag` upstream would skip + # this job regardless of its direct dependency's result. The explicit + # success check is what actually gates it. + if: ${{ always() && needs.release-target.result == 'success' }} + strategy: + fail-fast: false + matrix: + include: + - id: ubuntu-22.04-x86_64 + os: ubuntu-22.04 + target: x86_64-unknown-linux-gnu + - id: ubuntu-22.04-arm64 + os: ubuntu-22.04-arm + target: aarch64-unknown-linux-gnu + - id: ubuntu-24.04-x86_64 + os: ubuntu-24.04 + target: x86_64-unknown-linux-gnu + - id: ubuntu-24.04-arm64 + os: ubuntu-24.04-arm + target: aarch64-unknown-linux-gnu + - id: macos-15-x86_64 + os: macos-15-intel + target: x86_64-apple-darwin + - id: macos-15-arm64 + os: macos-15 + target: aarch64-apple-darwin + - id: macos-26-x86_64 + os: macos-26-intel + target: x86_64-apple-darwin + - id: macos-26-arm64 + os: macos-26 + target: aarch64-apple-darwin + - id: windows-2022-x86_64 + os: windows-2022 + target: x86_64-pc-windows-msvc + - id: windows-2025-x86_64 + os: windows-2025 + target: x86_64-pc-windows-msvc + - id: windows-11-arm64 + os: windows-11-arm + target: aarch64-pc-windows-msvc + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v7 + with: + ref: ${{ needs.release-target.outputs.tag }} + persist-credentials: false + submodules: true + + - uses: dtolnay/rust-toolchain@stable + + - uses: Swatinem/rust-cache@v2 + + - name: Verify native Rust target + shell: bash + env: + EXPECTED_TARGET: ${{ matrix.target }} + run: | + set -euo pipefail + actual_target="$(rustc -vV | sed -n 's/^host: //p')" + [[ "$actual_target" == "$EXPECTED_TARGET" ]] + + - name: Build installable module + run: cargo build --locked --release --manifest-path crates/tinymemory-module/Cargo.toml + + - name: Assemble Unix module package + if: ${{ runner.os != 'Windows' }} + id: unix_package + shell: bash + env: + BUNDLE_ID: ${{ matrix.id }} + VERSION: ${{ needs.release-target.outputs.next_version }} + run: | + set -euo pipefail + + library_name="tinymemory_module" + case "$RUNNER_OS" in + Linux) module="crates/tinymemory-module/target/release/lib${library_name}.so" ;; + macOS) module="crates/tinymemory-module/target/release/lib${library_name}.dylib" ;; + *) echo "unsupported Unix runner: ${RUNNER_OS}" >&2; exit 1 ;; + esac + package_name="tinymemory-module-${VERSION}-${BUNDLE_ID}" + package_root="dist/${package_name}" + mkdir -p "$package_root" + install -m 755 "$module" "$package_root/" + install -m 644 LICENSE README.md docs/specs/tinybus-module.md "$package_root/" + module_name="$(basename "$module")" + module_hash="$(sha256sum "$package_root/$module_name" | awk '{print $1}')" + printf '"%s" = "%s"\n' "$module_name" "$module_hash" \ + > "$package_root/modules.toml" + tar -C "$package_root" -czf "dist/${package_name}.tar.gz" . + echo "archive=dist/${package_name}.tar.gz" >> "$GITHUB_OUTPUT" + + - name: Assemble Windows module package + if: ${{ runner.os == 'Windows' }} + id: windows_package + shell: pwsh + env: + BUNDLE_ID: ${{ matrix.id }} + VERSION: ${{ needs.release-target.outputs.next_version }} + run: | + $ErrorActionPreference = 'Stop' + $libraryName = 'tinymemory_module' + $module = "crates/tinymemory-module/target/release/$libraryName.dll" + $packageName = "tinymemory-module-$env:VERSION-$env:BUNDLE_ID" + $packageRoot = "dist/$packageName" + New-Item -ItemType Directory -Force $packageRoot | Out-Null + Copy-Item -LiteralPath $module, 'LICENSE', 'README.md' -Destination $packageRoot + $hash = (Get-FileHash -LiteralPath $module -Algorithm SHA256).Hash.ToLowerInvariant() + $moduleName = Split-Path -Leaf $module + "`"$moduleName`" = `"$hash`"`n" | + Set-Content -Path "$packageRoot/modules.toml" -Encoding utf8NoBOM + Compress-Archive -Path "$packageRoot/*" -DestinationPath "dist/$packageName.zip" + "archive=dist/$packageName.zip" >> $env:GITHUB_OUTPUT + + - name: Upload Unix module package + if: ${{ runner.os != 'Windows' }} + uses: actions/upload-artifact@v7 + with: + name: tinymemory-module-${{ matrix.id }} + path: ${{ steps.unix_package.outputs.archive }} + if-no-files-found: error + + - name: Upload Windows module package + if: ${{ runner.os == 'Windows' }} + uses: actions/upload-artifact@v7 + with: + name: tinymemory-module-${{ matrix.id }} + path: ${{ steps.windows_package.outputs.archive }} + if-no-files-found: error + + github-release: + name: Create GitHub release + needs: + - release-target + - native-bundles + # Same transitive-skip rule as above. + if: >- + ${{ always() + && needs.release-target.result == 'success' + && needs.native-bundles.result == 'success' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + ref: ${{ needs.release-target.outputs.tag }} + persist-credentials: false + submodules: true + + - name: Download workflow artifacts + uses: actions/download-artifact@v8 + with: + pattern: tinymemory-module-* + path: release-assets + merge-multiple: true + + - uses: dtolnay/rust-toolchain@stable + + - name: Create release checksum manifest with TinyBus + shell: bash + run: | + set -euo pipefail + mapfile -t assets < <( + find release-assets -type f \ + \( -name '*.tar.gz' -o -name '*.zip' \) \ + | sort + ) + if [[ ${#assets[@]} -ne 11 ]]; then + printf 'expected 11 module archives, found %s:\n' "${#assets[@]}" >&2 + find release-assets -type f -print >&2 || true + exit 1 + fi + checksum_args=() + for asset in "${assets[@]}"; do checksum_args+=(--path "$asset"); done + cargo run --manifest-path vendor/tinybus/Cargo.toml --locked \ + --package tinybus --all-features --bin tinybus -- \ + modules checksum "${checksum_args[@]}" --output release-assets/checksum.toml + + - name: Create release and upload assets + env: + GH_TOKEN: ${{ github.token }} + RELEASE_TAG: ${{ needs.release-target.outputs.tag }} + REPOSITORY: ${{ github.repository }} + run: | + set -euo pipefail + mapfile -t release_files < <(find release-assets -type f | sort) + gh release create "$RELEASE_TAG" "${release_files[@]}" \ + --repo "$REPOSITORY" \ + --verify-tag \ + --title "$RELEASE_TAG" \ + --generate-notes + + - name: Verify the published module through TinyBus + shell: bash env: - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + RELEASE_TAG: ${{ needs.release-target.outputs.tag }} + REPOSITORY: ${{ github.repository }} + VERSION: ${{ needs.release-target.outputs.next_version }} + run: | + set -euo pipefail + archive="tinymemory-module-${VERSION}-ubuntu-24.04-x86_64.tar.gz" + release_url="https://github.com/${REPOSITORY}/releases/tag/${RELEASE_TAG}" + sha256="$(sed -n "s/^\"${archive}\" = \"\([0-9a-f]\{64\}\)\"$/\1/p" release-assets/checksum.toml)" + test -n "$sha256" + cargo run --manifest-path vendor/tinybus/Cargo.toml --locked \ + --package tinybus --all-features --example github_module_host -- \ + "$release_url" "$archive" "$sha256" diff --git a/.gitignore b/.gitignore index c880a65..055bee4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ -# Build output -/target/ +# Build output. NOT anchored with a leading slash: `crates/tinymemory-module` is +# its own workspace root (see the `exclude` note in Cargo.toml) and so has its +# own `target/`, which an anchored `/target/` does not match — 3064 build files +# and a 33 MB cdylib were committed before this was widened. +target/ **/*.rs.bk *.pdb diff --git a/Cargo.toml b/Cargo.toml index efd6540..a09fa7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,35 @@ [workspace] members = [".", "api", "core", "adapters/tinycortex"] default-members = [".", "api", "core", "adapters/tinycortex"] -# `vendor/` holds engine submodules (tinycortex, tinybus), each of which is its -# own workspace with its own lockfile. Same exclusion `vendor/tinycortex` uses -# for its own nested vendor directory. -exclude = ["vendor"] +# `vendor/` holds engine submodules (tinycortex, tinybus, tinyagents), each of +# which is its own workspace with its own lockfile. Same exclusion +# `vendor/tinycortex` uses for its own nested vendor directory. +# +# `crates/tinymemory-module` is excluded for a harder reason than tidiness, and +# it is worth writing down because the obvious arrangement does not work. +# +# That crate depends on `vendor/tinybus/crates/tinybus`, whose manifest inherits +# `edition`/`version` from `vendor/tinybus`'s own `[workspace.package]`. If the +# module is a member here, cargo resolves that inheritance against **this** root +# instead of the nested one and fails with `workspace.package.edition was not +# defined`. `exclude` does not prevent it: exclusion governs membership, not the +# root cargo picks when resolving a dependency's inherited fields. Verified by +# defining `[workspace.package]` here temporarily, which moved the error from +# `edition` to `version` rather than fixing it. +# +# So the module is its own workspace root with its own `Cargo.lock` — which is +# also what tinybus's module documentation prescribes ("integrations themselves +# remain separate repositories and are never workspace members") and what a +# separately released artifact wants anyway. Build it with +# `--manifest-path crates/tinymemory-module/Cargo.toml`. +exclude = ["vendor", "crates/tinymemory-module"] [package] name = "tinymemory" +# Not published: `tinymemory-core` depends on `tinycortex-api`, which is +# consumed by path and is not on crates.io, so `cargo package` cannot resolve +# the graph. Every consumer takes this repo by path or git. +publish = false version = "0.1.0" edition = "2021" rust-version = "1.96" diff --git a/adapters/tinycortex/Cargo.toml b/adapters/tinycortex/Cargo.toml index 1fbfb57..a0eb4db 100644 --- a/adapters/tinycortex/Cargo.toml +++ b/adapters/tinycortex/Cargo.toml @@ -1,5 +1,9 @@ [package] name = "tinymemory-tinycortex" +# Not published: `tinymemory-core` depends on `tinycortex-api`, which is +# consumed by path and is not on crates.io, so `cargo package` cannot resolve +# the graph. Every consumer takes this repo by path or git. +publish = false version = "0.1.0" edition = "2021" rust-version = "1.85" diff --git a/adapters/tinycortex/src/convert.rs b/adapters/tinycortex/src/convert.rs index eb9b324..8d7d540 100644 --- a/adapters/tinycortex/src/convert.rs +++ b/adapters/tinycortex/src/convert.rs @@ -143,3 +143,55 @@ pub fn recall_opts_to_tinycortex(opts: &tm::OwnedRecallOpts) -> tc::OwnedRecallO #[cfg(test)] #[path = "convert_test.rs"] mod test; + +// ── The reverse direction, for a driver whose contract is TinyMemory's ──────── +// +// Everything above converts engine values *into* the TinyMemory contract, which +// is what wrapping TinyCortex as a TinyMemory driver needs. A module-backed +// driver runs the other way: it speaks TinyMemory, and a host whose binding +// still speaks TinyCortex has to convert its answers back. +// +// Same discipline as above — exhaustive destructuring, total matches, no `..` +// and no `Default` — for the same reason: two contracts allowed to drift will. + +/// Converts an entry to the `TinyCortex` contract's form. +#[must_use] +pub fn entry_to_tinycortex(entry: tm::MemoryEntry) -> tc::MemoryEntry { + let tm::MemoryEntry { + id, + key, + content, + namespace, + category, + timestamp, + session_id, + score, + taint, + } = entry; + tc::MemoryEntry { + id, + key, + content, + namespace, + category: category_to_tinycortex(category), + timestamp, + session_id, + score, + taint: taint_to_tinycortex(taint), + } +} + +/// Converts a namespace summary to the `TinyCortex` contract's form. +#[must_use] +pub fn namespace_summary_to_tinycortex(summary: tm::NamespaceSummary) -> tc::NamespaceSummary { + let tm::NamespaceSummary { + namespace, + count, + last_updated, + } = summary; + tc::NamespaceSummary { + namespace, + count, + last_updated, + } +} diff --git a/api/Cargo.toml b/api/Cargo.toml index dbcb753..673c26e 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -1,5 +1,9 @@ [package] name = "tinymemory-api" +# Not published: `tinymemory-core` depends on `tinycortex-api`, which is +# consumed by path and is not on crates.io, so `cargo package` cannot resolve +# the graph. Every consumer takes this repo by path or git. +publish = false version = "0.1.1" edition = "2021" license = "MIT" diff --git a/api/src/lib.rs b/api/src/lib.rs index 85fc087..7e27ff6 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -60,6 +60,9 @@ //! - [`host`]: the **host seam** — [`host::MemoryHostConfig`], //! [`host::EmbeddingProvider`], [`host::MemoryEventSink`], and the memory //! config sections whose serde form is persisted in a host's `config.toml`. +//! - [`wire`]: the error-name table a driver reached over a bus or a socket +//! round-trips [`error::MemoryError`] through. Shared by both ends of every +//! such transport, so the names cannot drift apart. pub mod capabilities; pub mod chunks; @@ -75,5 +78,6 @@ pub mod traits; pub mod tree; pub mod types; pub mod version; +pub mod wire; pub use version::{is_compatible, CONTRACT_VERSION}; diff --git a/api/src/wire.rs b/api/src/wire.rs new file mode 100644 index 0000000..0cba4ef --- /dev/null +++ b/api/src/wire.rs @@ -0,0 +1,133 @@ +//! Error names for a driver reached over a wire, and the mapping both ends use. +//! +//! # Why this is here and not in the transport +//! +//! A driver can be in-process, in a loadable module, or behind a socket. The +//! last two need [`MemoryError`] to survive a round trip through a +//! `(name, message)` pair, because that is all a bus or an HTTP status gives +//! you. +//! +//! The mapping could have lived in whichever adapter needed it first. It lives +//! here instead because there will be more than one adapter, and two copies of +//! a name table drift: the module side starts answering +//! `…Error.PathEscape` while the host side still only recognises +//! `…Error.Invalid`, and the symptom is a security-relevant error +//! silently reclassified as a caller mistake. One table, used by both ends, with +//! [`round_trips_every_variant`](self) pinning it. +//! +//! # One name per variant, not one per outcome class +//! +//! An earlier sketch collapsed these onto three names — "the caller can fix it", +//! "the capability is absent", "something broke" — on the grounds that a host has +//! only those three responses. That is wrong for two reasons. +//! +//! A host does not merely *react* to a driver error; it **is** a +//! [`MemoryProvider`](crate::provider::MemoryProvider) to everything above it, +//! so it has to hand its own callers a `MemoryError`. Collapsing on the way out +//! and guessing on the way back in would turn a `NotFound` into an `Invalid`, +//! and `get`'s contract says a missing entry is `Ok(None)` while an `Invalid` is +//! a real failure — so the guess is observable. +//! +//! And `PathEscape` is not interchangeable with `Invalid`. It reports a symlink +//! or traversal attempt that left the workspace sandbox, which a host may want +//! to log, report or refuse to retry differently from a malformed argument. +//! +//! # Unrecognised names are backend failures +//! +//! [`from_wire`] maps anything it does not know to [`MemoryError::Other`], never +//! to [`MemoryError::Invalid`]. A driver newer than this build may name an error +//! this table has no variant for, and telling a caller its input was wrong when +//! it was not sends it into a rewrite loop over something already correct. +//! +//! # Messages, and what must not be in them +//! +//! The name is the contract; the message is for a human. Neither may carry a +//! namespace key, an entry's content, a recall query, a credential or an +//! absolute path — memory content is user data, and an error string is not a +//! place for it. `Io` and `Serde` are deliberately flattened into a message +//! here, because reconstructing a live `std::io::Error` or +//! `serde_json::Error` on the far side is not possible and not useful. + +use crate::error::MemoryError; + +/// A requested record, source or node was not found. +pub const NOT_FOUND: &str = "ai.tinyhumans.tinymemory.Error.NotFound"; +/// Caller-supplied input failed validation. +pub const INVALID: &str = "ai.tinyhumans.tinymemory.Error.Invalid"; +/// A configured budget was exceeded. +pub const BUDGET_EXCEEDED: &str = "ai.tinyhumans.tinymemory.Error.BudgetExceeded"; +/// A path escaped the workspace sandbox. +pub const PATH_ESCAPE: &str = "ai.tinyhumans.tinymemory.Error.PathEscape"; +/// An underlying IO failure. +pub const IO: &str = "ai.tinyhumans.tinymemory.Error.Io"; +/// A serialization or deserialization failure. +pub const SERDE: &str = "ai.tinyhumans.tinymemory.Error.Serde"; +/// The driver does not implement the named capability family. +pub const UNSUPPORTED: &str = "ai.tinyhumans.tinymemory.Error.Unsupported"; +/// An opaque lower-level failure. +pub const OTHER: &str = "ai.tinyhumans.tinymemory.Error.Other"; + +/// The wire name for `error`. +/// +/// Total by construction: the `match` is exhaustive, so a variant added to +/// [`MemoryError`] is a compile error here rather than a silent fallthrough onto +/// [`OTHER`]. +#[must_use] +pub fn wire_name(error: &MemoryError) -> &'static str { + match error { + MemoryError::NotFound(_) => NOT_FOUND, + MemoryError::Invalid(_) => INVALID, + MemoryError::BudgetExceeded(_) => BUDGET_EXCEEDED, + MemoryError::PathEscape(_) => PATH_ESCAPE, + MemoryError::Io(_) => IO, + MemoryError::Serde(_) => SERDE, + MemoryError::Unsupported { .. } => UNSUPPORTED, + MemoryError::Other(_) => OTHER, + } +} + +/// The message to send alongside [`wire_name`]. +/// +/// For most variants this is the inner string rather than the `Display` output, +/// so the receiving side can rebuild the variant without the prefix +/// (`"invalid input: "`, …) being baked into the payload twice. +#[must_use] +pub fn wire_message(error: &MemoryError) -> String { + match error { + MemoryError::NotFound(message) + | MemoryError::Invalid(message) + | MemoryError::BudgetExceeded(message) + | MemoryError::PathEscape(message) => message.clone(), + MemoryError::Unsupported { capability } => capability.clone(), + // No inner string to lift: these carry a foreign error type, so the + // rendered form is all there is. + MemoryError::Io(inner) => inner.to_string(), + MemoryError::Serde(inner) => inner.to_string(), + MemoryError::Other(inner) => inner.to_string(), + } +} + +/// Rebuild a [`MemoryError`] from a `(name, message)` pair. +/// +/// An unrecognised `name` becomes [`MemoryError::Other`] — see the module docs +/// on why it must not become [`MemoryError::Invalid`]. +#[must_use] +pub fn from_wire(name: &str, message: &str) -> MemoryError { + match name { + NOT_FOUND => MemoryError::NotFound(message.to_string()), + INVALID => MemoryError::Invalid(message.to_string()), + BUDGET_EXCEEDED => MemoryError::BudgetExceeded(message.to_string()), + PATH_ESCAPE => MemoryError::PathEscape(message.to_string()), + // `std::io::Error` cannot be reconstructed with its original kind from a + // string, and inventing one would be worse than being honest that this + // crossed a wire. The message is preserved. + IO => MemoryError::Other(anyhow::anyhow!("io error: {message}")), + SERDE => MemoryError::Other(anyhow::anyhow!("serde error: {message}")), + UNSUPPORTED => MemoryError::unsupported_raw(message), + _ => MemoryError::Other(anyhow::anyhow!("{message}")), + } +} + +#[cfg(test)] +#[path = "wire_tests.rs"] +mod tests; diff --git a/api/src/wire_tests.rs b/api/src/wire_tests.rs new file mode 100644 index 0000000..0653dc6 --- /dev/null +++ b/api/src/wire_tests.rs @@ -0,0 +1,104 @@ +//! The name table is a contract, so these tests pin it rather than exercise it. + +use super::{from_wire, wire_message, wire_name}; +use crate::capabilities::Capability; +use crate::error::MemoryError; + +/// Every variant, so a new one fails to compile in `wire_name` and fails here. +fn every_variant() -> Vec { + vec![ + MemoryError::NotFound("thread-7".to_string()), + MemoryError::Invalid("limit must be positive".to_string()), + MemoryError::BudgetExceeded("depth 12 exceeds 8".to_string()), + MemoryError::PathEscape("symlink leaves workspace".to_string()), + MemoryError::Io(std::io::Error::other("disk gone")), + MemoryError::Serde(serde_json::from_str::("nope").unwrap_err()), + MemoryError::unsupported(Capability::Tree), + MemoryError::Other(anyhow::anyhow!("engine stopped")), + ] +} + +#[test] +fn round_trips_every_variant() { + for error in every_variant() { + let name = wire_name(&error); + let message = wire_message(&error); + let rebuilt = from_wire(name, &message); + + // Io and Serde deliberately degrade to `Other`: neither foreign error + // type can be reconstructed from a string. Everything else must come + // back as the same variant, because a host re-raises it to its own + // callers and the variant is what they match on. + match (&error, &rebuilt) { + (MemoryError::Io(_) | MemoryError::Serde(_), MemoryError::Other(_)) => {} + _ => assert_eq!( + std::mem::discriminant(&error), + std::mem::discriminant(&rebuilt), + "{name} did not round-trip to the same variant" + ), + } + assert!( + rebuilt.to_string().contains(message.trim()) || message.is_empty(), + "{name} lost its message: {rebuilt}" + ); + } +} + +#[test] +fn every_name_is_distinct() { + let mut names: Vec<&str> = every_variant().iter().map(wire_name).collect(); + let before = names.len(); + names.sort_unstable(); + names.dedup(); + assert_eq!(before, names.len(), "two variants share a wire name"); +} + +#[test] +fn an_unrecognised_name_is_a_backend_failure_not_an_input_error() { + // The load-bearing case. A driver newer than this build names something we + // have no variant for; classifying it as `Invalid` would tell a caller its + // request was wrong and send it into a rewrite loop. + let rebuilt = from_wire("ai.tinyhumans.tinymemory.Error.SomethingNewer", "hmm"); + assert!(matches!(rebuilt, MemoryError::Other(_)), "{rebuilt:?}"); +} + +#[test] +fn a_path_escape_does_not_collapse_onto_invalid() { + // These were nearly given one shared name. A sandbox escape is not a + // malformed argument, and a host may log or refuse to retry it differently. + assert_ne!( + wire_name(&MemoryError::PathEscape("x".to_string())), + wire_name(&MemoryError::Invalid("x".to_string())) + ); +} + +#[test] +fn a_missing_entry_stays_not_found() { + // `get`'s contract makes a missing entry `Ok(None)` and an `Invalid` a real + // failure, so conflating the two is observable to a caller. + let rebuilt = from_wire(super::NOT_FOUND, "absent"); + assert!(matches!(rebuilt, MemoryError::NotFound(_)), "{rebuilt:?}"); +} + +#[test] +fn an_unsupported_capability_keeps_its_family_name() { + let error = MemoryError::unsupported(Capability::Diff); + let rebuilt = from_wire(wire_name(&error), &wire_message(&error)); + match rebuilt { + MemoryError::Unsupported { capability } => { + assert_eq!(capability, Capability::Diff.as_str()); + } + other => panic!("expected Unsupported, got {other:?}"), + } +} + +#[test] +fn an_unknown_capability_name_off_the_wire_survives() { + // A driver on a newer minor contract may name a family this build has no + // `Capability` for. It must not be dropped or fail to parse. + let rebuilt = from_wire(super::UNSUPPORTED, "vendor_extension"); + match rebuilt { + MemoryError::Unsupported { capability } => assert_eq!(capability, "vendor_extension"), + other => panic!("expected Unsupported, got {other:?}"), + } +} diff --git a/core/Cargo.toml b/core/Cargo.toml index d9e8f81..8ea5592 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,5 +1,9 @@ [package] name = "tinymemory-core" +# Not published: `tinymemory-core` depends on `tinycortex-api`, which is +# consumed by path and is not on crates.io, so `cargo package` cannot resolve +# the graph. Every consumer takes this repo by path or git. +publish = false version = "0.1.0" edition = "2021" rust-version = "1.85" diff --git a/crates/tinymemory-module/Cargo.lock b/crates/tinymemory-module/Cargo.lock new file mode 100644 index 0000000..6d26aae --- /dev/null +++ b/crates/tinymemory-module/Cargo.lock @@ -0,0 +1,2803 @@ +# 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 = "aho-corasick" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba" +dependencies = [ + "memchr", +] + +[[package]] +name = "android_system_properties" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "arbitrary" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" +dependencies = [ + "derive_arbitrary", +] + +[[package]] +name = "async-trait" +version = "0.1.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "axum" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90" +dependencies = [ + "axum-core", + "axum-macros", + "base64 0.22.1", + "bytes", + "form_urlencoded", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde_core", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sha1", + "sync_wrapper", + "tokio", + "tokio-tungstenite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "sync_wrapper", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-macros" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aa268c23bfbbd2c4363b9cd302a4f504fb2a9dfe7e3451d66f35dd392e20aca" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" + +[[package]] +name = "bitflags" +version = "2.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da" + +[[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 = "block-buffer" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cc" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d262e149917187838d5b42777c8253bcb64500067342904e7d429499a6f277e" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chacha20" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core 0.10.1", +] + +[[package]] +name = "chrono" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61803da095bee82a81bb1a452ecc25d3b2f1416d1897eb86430c6159ef717c17" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "crypto-common" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "data-encoding" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06" + +[[package]] +name = "derive_arbitrary" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e567bd82dcff979e4b03460c307b3cdc9e96fde3d73bed1496d2bc75d9dd62a" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common 0.1.7", +] + +[[package]] +name = "digest" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" +dependencies = [ + "block-buffer 0.12.1", + "const-oid", + "crypto-common 0.2.2", +] + +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + +[[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 = "dyn-clone" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + +[[package]] +name = "fastrand" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" + +[[package]] +name = "filetime" +version = "0.2.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c287a33c7f0a620c38e641e7f60827713987b3c0f26e8ddc9462cc69cf75759" +dependencies = [ + "cfg-if", + "libc", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b73573e6edcd2af0cdf47bd6cb58f0b3839491263c314eaad1ccf24430e1de" + +[[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 = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "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 = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi 5.3.0", + "wasip2", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi 6.0.0", + "rand_core 0.10.1", + "wasm-bindgen", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "hashlink" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824e001ac4f3012dd16a264bec811403a67ca9deb6c102fc5049b32c4574b35f" +dependencies = [ + "hashbrown 0.16.1", +] + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9f41fd6a08e4d4ec69df65976da761afd5ad5e58a9d4acb46bd1c953a9e3ff2" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hybrid-array" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707114b52a152fa7bdb290cd7cd5912d9467273b6d74e21b8d81aca1f8533f6b" +dependencies = [ + "typenum", +] + +[[package]] +name = "hyper" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22053281f852e11534f5198498373cbb59295120a20771d90f7ed1897490a72" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" + +[[package]] +name = "icu_properties" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" + +[[package]] +name = "icu_provider" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", +] + +[[package]] +name = "ipnet" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a756c3fac73139e83f14c2d742155dd2b78d3ee56597b419a0579b7bdd6dd78" + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0c1080212aad755ea003d18543e8768dd432c48819efd73a7bf1e39b7a5a3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "libredox" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2026a5056764a10b2bf5d56488cba40da507f5493a6a429340e2004d9ed085fa" +dependencies = [ + "libc", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.38.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1d20bef17f513b9b3004532233187769cd072d790971f4e4da0e346eb6401e8" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[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 = "mio" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d65c71f1ce40ab09135ce117d742b9f8a19ff91a41a8b57ed50bc2de59c427" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pkg-config" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" + +[[package]] +name = "potential_utf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +dependencies = [ + "zerovec", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quinn" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror 2.0.20", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4bfc015262b9df63c8845072ce59068853ff5872180c2ce2f13038b970e560" +dependencies = [ + "bytes", + "getrandom 0.4.3", + "lru-slab", + "rand 0.10.2", + "rand_pcg", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror 2.0.20", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35a133f956daabe89a61a685c2649f13d82d5aa4bd5d12d1277e1072a21c0694" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.61.2", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22f6172bdec972074665ed81ed53b71da00bfc44b65a753cfde883ec4c702a1a" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.5", +] + +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core 0.10.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_pcg" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a" +dependencies = [ + "rand_core 0.10.1", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom 0.2.17", + "libredox", + "thiserror 1.0.69", +] + +[[package]] +name = "ref-cast" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216e8f773d7923bcba9ceb86a86c93cabb3903a11872fc3f138c49630e50b96d" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9283685feec7d69af75fb0e858d5e7378f33fe4fc699383b2916ab9273e03c" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "regex" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tokio-util", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rsqlite-vfs" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c51c9ae4df8a7fba42103df5c621fa3c37eccf3a3c650879e90fc48b11cc192c" +dependencies = [ + "hashbrown 0.16.1", + "thiserror 2.0.20", +] + +[[package]] +name = "rusqlite" +version = "0.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b3492ea85308705c3a5cc24fb9b9cf77273d30590349070db42991202b214c4" +dependencies = [ + "bitflags", + "fallible-iterator", + "fallible-streaming-iterator", + "hashlink", + "libsqlite3-sys", + "smallvec", + "sqlite-wasm-rs", +] + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[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 = [ + "web-time", + "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 = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schemars" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "687274d293b6cdc6e73e0fee520bf2049650090d7164f87672d212a3c530cf4a" +dependencies = [ + "dyn-clone", + "ref-cast", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d98c67716b46af2f0b8cf752abc930f6f9aecfbf671ecfb531db8a31dbe4e2ba" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 3.0.3", +] + +[[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.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "serde_derive_internals" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f852137cce035d6a4df67ccce505ff6b3e9fd3a10e3e52b24dc71e650bb1a9bd" +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 = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "digest 0.11.3", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "sqlite-wasm-rs" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc3efc0da82635d7e1ced0053bbbfa8c7ab9645d0bf36ceb4f7127bb85315d75" +dependencies = [ + "cc", + "js-sys", + "rsqlite-vfs", + "wasm-bindgen", +] + +[[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 = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tar" +version = "0.4.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6221d9a6003c78398e3b239969f352578258df48c8eb051caadae0015bc840" +dependencies = [ + "filetime", + "libc", + "xattr", +] + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.3", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl 2.0.20", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "tinyagents" +version = "2.1.0" +dependencies = [ + "async-trait", + "bytes", + "chrono", + "futures", + "reqwest", + "rusqlite", + "serde", + "serde_json", + "sha2 0.11.0", + "thiserror 2.0.20", + "tokio", + "tracing", +] + +[[package]] +name = "tinybus" +version = "0.1.0" +dependencies = [ + "async-trait", + "flate2", + "serde", + "serde_json", + "tar", + "tempfile", + "thiserror 2.0.20", + "tinybus-macros", + "tokio", + "toml", + "tracing", + "ureq", + "zip", +] + +[[package]] +name = "tinybus-macros" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tinybus-module" +version = "0.1.0" +dependencies = [ + "async-trait", + "serde", + "serde_json", + "tinybus", + "tokio", + "tracing", +] + +[[package]] +name = "tinycortex" +version = "0.1.1" +dependencies = [ + "anyhow", + "async-trait", + "chrono", + "dirs", + "futures", + "log", + "parking_lot", + "rand 0.10.2", + "regex", + "reqwest", + "rusqlite", + "schemars", + "serde", + "serde_json", + "sha2 0.10.9", + "thiserror 2.0.20", + "tinyagents", + "tinycortex-api", + "tokio", + "toml", + "tracing", + "uuid", + "walkdir", +] + +[[package]] +name = "tinycortex-api" +version = "0.1.1" +dependencies = [ + "anyhow", + "async-trait", + "chrono", + "serde", + "serde_json", + "sha2 0.10.9", + "thiserror 2.0.20", + "uuid", +] + +[[package]] +name = "tinymemory" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "log", + "serde", + "serde_json", + "tinymemory-api", +] + +[[package]] +name = "tinymemory-api" +version = "0.1.1" +dependencies = [ + "anyhow", + "async-trait", + "chrono", + "log", + "schemars", + "serde", + "serde_json", + "sha2 0.11.0", + "thiserror 2.0.20", + "uuid", +] + +[[package]] +name = "tinymemory-core" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "axum", + "chrono", + "dirs", + "futures", + "log", + "parking_lot", + "rand 0.8.7", + "regex", + "reqwest", + "rusqlite", + "serde", + "serde_json", + "sha2 0.10.9", + "thiserror 2.0.20", + "tinyagents", + "tinycortex", + "tinycortex-api", + "tinymemory", + "tinymemory-api", + "tokio", + "tracing", + "url", + "uuid", + "walkdir", +] + +[[package]] +name = "tinymemory-module" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "log", + "serde", + "serde_json", + "tempfile", + "tinybus", + "tinybus-module", + "tinycortex", + "tinymemory", + "tinymemory-api", + "tinymemory-core", + "tinymemory-tinycortex", + "tokio", +] + +[[package]] +name = "tinymemory-tinycortex" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "tinycortex", + "tinymemory", + "tinymemory-api", +] + +[[package]] +name = "tinystr" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb4ebadaa0af04fab11ae01eb5f9fdb5f9c5b875506e210e71c07873528baa7f" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f72a05e828585856dacd553fba484c242c46e391fb0e58917c942ee9202915c" +dependencies = [ + "futures-util", + "log", + "tokio", + "tungstenite", +] + +[[package]] +name = "tokio-util" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494815d09bf52b5548659851081238f0ca39ff638363907596da739561c62c52" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "toml_write", + "winnow", +] + +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "url", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "tungstenite" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c01152af293afb9c7c2a57e4b559c5620b421f6d133261c60dd2d0cdb38e6b8" +dependencies = [ + "bytes", + "data-encoding", + "http", + "httparse", + "log", + "rand 0.9.5", + "sha1", + "thiserror 2.0.20", +] + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "972d7902c8735f2695410b8aed7df6ed12a47394aa1c8d7af49f0497b731a94d" +dependencies = [ + "base64 0.23.1", + "flate2", + "log", + "percent-encoding", + "rustls", + "rustls-pki-types", + "ureq-proto", + "utf8-zero", + "webpki-roots", +] + +[[package]] +name = "ureq-proto" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da5f78b09e6941e1a0f2e30e695e4b120377b54d5e0aec11b594bb57b3971613" +dependencies = [ + "base64 0.23.1", + "http", + "httparse", + "log", +] + +[[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-zero" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8c0a043c9540bae7c578c88f91dda8bd82e59ae27c21baca69c8b191aaf5a6e" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "uuid" +version = "1.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf3923a6f5c4c6382e0b653c4117f48d631ea17f38ed86e2a828e6f7412f5239" +dependencies = [ + "getrandom 0.4.3", + "js-sys", + "serde_core", + "wasm-bindgen", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.4+wasi-0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b70935747edd64d89de3efa29d73789b806c15798f8e7dca4d8ac356b50ce70" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b7777d5cc23d0e91404e53ce2d5e8ec7acae3026b16233dba62cd3246457950" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77775f8f3f7217702089053b94958f8f54061a3f663417df76e19cbdcca29bc1" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e11d33f857dc2fb11b8bc75aee111aa9cbeb12cd9f25efd3d4c2a3dd4e235284" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 2.0.119", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef64dbcc55df09c7e5a46182d181c2cfa3e925f3da937ea764728b4bbb9dcbf" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-streams" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65" +dependencies = [ + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "web-sys" +version = "0.3.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c435338968042f4f59a557f690a253676d47ce13ceb55d70100e7facf6620a30" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[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_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" +dependencies = [ + "memchr", +] + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "writeable" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" + +[[package]] +name = "xattr" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156" +dependencies = [ + "libc", + "rustix", +] + +[[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 = "zerocopy" +version = "0.8.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556764e583adb45a9f8d413c2a147fa7e8d821e48e12b14fd560b607998b75eb" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2ab42fc20575779bd240faa45f94a74256f755c0fa9e89f0ede20d91d0cdfc1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[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.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "zip" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabe6324e908f85a1c52063ce7aa26b68dcb7eb6dbc83a2d148403c9bc3eba50" +dependencies = [ + "arbitrary", + "crc32fast", + "crossbeam-utils", + "displaydoc", + "flate2", + "indexmap", + "memchr", + "thiserror 2.0.20", + "zopfli", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" + +[[package]] +name = "zopfli" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249" +dependencies = [ + "bumpalo", + "crc32fast", + "log", + "simd-adler32", +] diff --git a/crates/tinymemory-module/Cargo.toml b/crates/tinymemory-module/Cargo.toml new file mode 100644 index 0000000..93cfb15 --- /dev/null +++ b/crates/tinymemory-module/Cargo.toml @@ -0,0 +1,104 @@ +# Its own workspace root, deliberately — see the long note on `exclude` in +# `../../Cargo.toml`. In short: this crate depends on the vendored tinybus, +# whose manifest inherits fields from its own nested `[workspace.package]`, and +# being a member of the tinymemory workspace makes cargo resolve that +# inheritance against the wrong root. A separately released artifact wants its +# own lockfile regardless. +[workspace] + +[package] +name = "tinymemory-module" +version = "0.1.0" +edition = "2021" +rust-version = "1.96" +license = "MIT" +description = "Trusted TinyBus module adapter for TinyMemory." +repository = "https://github.com/tinyhumansai/tinymemory" +publish = false + +[lib] +# `rlib` as well as `cdylib` so the service can be unit-tested in-process +# without going through the loader; the `cdylib` is what a release ships. +crate-type = ["rlib", "cdylib"] + +[dependencies] +# The contract. Every type crossing the bus is one of these, and all of them +# already carry serde impls — which is why this module needs no `wire` module of +# its own, unlike the tinywallet one. +tinymemory-api = { path = "../../api", version = "0.1.1" } +# `MemoryTraitProvider`, which pairs a `Memory` backend with a driver id. +tinymemory = { path = "../..", version = "0.1.0" } +# The engine and the seam that adapts it. Carrying these is the entire point of +# the module: they are 14.7s of the host's critical build path, and a host that +# loads this binary compiles neither. +tinymemory-core = { path = "../../core", version = "0.1.0" } +tinymemory-tinycortex = { path = "../../adapters/tinycortex", version = "0.1.0" } +tinycortex = { version = "0.1" } +# TinyBus provides the typed service interface and the dynamic module host ABI. +# Reached by path now that this crate is its own workspace root: the nested +# checkout's `[workspace.package]` resolves correctly from here. +tinybus = { version = "0.1.0", path = "../../vendor/tinybus/crates/tinybus", default-features = false, features = [ + "macros", + "modules", +] } +# The module-side SDK owns its runtime and exports the stable C entrypoints. +tinybus-module = { version = "0.1.0", path = "../../vendor/tinybus/crates/tinybus-module" } +# `EmbeddingProvider::embed` is an `async fn` on an object-safe trait. +async-trait = "0.1" +# `EmbeddingProvider::embed` is anyhow-typed. +anyhow = "1" +# Diagnostics. Never carries a namespace key or entry content — see `service`. +log = "0.4" +# Module configuration is JSON supplied by the host at load time. +serde = { version = "1", features = ["derive"] } +serde_json = "1" +# The interface macro requires every method to be `async fn`, so a runtime has +# to exist. +tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync"] } + +[dev-dependencies] +tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } +# The loader E2E and the store tests need a throwaway workspace directory. +tempfile = "3" + +# Its own table, because a patch table only applies from the workspace root being +# built and this crate is now its own root — the parent workspace's identical +# entries do not reach here. `tinycortex` and `tinyagents` are named by version +# requirement upstream and neither is published, so without these the resolver +# goes to crates.io and fails. +# +# The paths reach up out of this crate into the parent checkout's `vendor/`, +# which is unusual but correct: these are the same submodules the parent builds +# against, and pointing somewhere else would compile the module against a +# different engine than the workspace it ships from. +[patch.crates-io] +tinycortex = { path = "../../vendor/tinycortex" } +tinycortex-api = { path = "../../vendor/tinycortex/api" } +tinyagents = { path = "../../vendor/tinyagents" } + +# Mirrors the root package's set. `unsafe_code = "forbid"` holds even though +# `module_export!` emits `unsafe extern "C"` symbols: the macro's expansion +# carries its own hygiene context, so the C ABI surface does not trip the lint +# here. Verified against `tinywallet-module`, which forbids it too and builds. +[lints.rust] +unsafe_code = "forbid" +missing_docs = "warn" +missing_debug_implementations = "warn" +unreachable_pub = "warn" +rust_2018_idioms = { level = "warn", priority = -1 } + +[lints.clippy] +all = { level = "warn", priority = -1 } +pedantic = { level = "warn", priority = -1 } +unwrap_used = "warn" +expect_used = "warn" +panic = "warn" +todo = "warn" +unimplemented = "warn" +missing_errors_doc = "warn" +missing_panics_doc = "warn" +doc_markdown = "warn" + +[lints.rustdoc] +broken_intra_doc_links = "warn" +private_intra_doc_links = "warn" diff --git a/crates/tinymemory-module/src/config.rs b/crates/tinymemory-module/src/config.rs new file mode 100644 index 0000000..65193b0 --- /dev/null +++ b/crates/tinymemory-module/src/config.rs @@ -0,0 +1,169 @@ +//! What the host tells this module at load time. +//! +//! # Why configuration and not a constructor argument +//! +//! A module is `dlopen`ed; there is no Rust call to pass a struct to. `TinyBus` +//! carries borrowed JSON in the host vtable and the SDK copies and deserializes +//! it during initialization, which is what [`ModuleConfig`] is deserialized +//! from. The host supplies it with `ModuleHost::set_config` before the load. +//! +//! # What is deliberately absent: credentials +//! +//! [`ModuleConfig`] has no API key, no session token, and no cloud-provider +//! credential list, and that is the central decision of this module rather than +//! an omission. +//! +//! The engine needs embeddings to recall anything, and embedding means calling +//! an inference provider that wants a key. Handing the key over would also hand +//! over the host's routing, cost accounting and BYOK policy, all of which live +//! host-side. So the key stays where it is and the *compute* is what crosses: +//! the module asks the host to embed, over the bus. See [`crate::embedding`]. +//! +//! This is the same split the `tinywallet` module makes with a signing key, for +//! the same reason. As there, a loaded module shares this address space, so the +//! split is not a hard isolation boundary and is not claimed as one — it is a +//! refusal to widen what crosses a boundary that already exists. +//! +//! # `MemoryConfig` travels whole +//! +//! The engine's own configuration is `tinymemory_api::host::MemoryConfig`, +//! which is already `Serialize`/`Deserialize` with `#[serde(default)]`. It is +//! embedded verbatim rather than re-declared field by field, so a field added +//! upstream reaches the engine without an edit here and cannot silently drift +//! from the host's copy of the same struct. + +use std::path::PathBuf; + +use serde::{Deserialize, Serialize}; +use tinymemory_api::host::{EmbeddingRouteConfig, MemoryConfig, StorageProviderConfig}; + +/// Everything this module needs to bring up a memory engine. +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(default)] +pub struct ModuleConfig { + /// Where the engine keeps its store. + /// + /// The host owns this path: it is inside the host's workspace, the host has + /// already applied whatever path policy it has, and the module does not + /// second-guess it. An empty path is refused at setup rather than silently + /// resolved against the process working directory, which would put a user's + /// memory store somewhere nobody would look for it. + pub workspace_dir: PathBuf, + + /// The engine's own configuration, passed through unchanged. + pub memory: MemoryConfig, + + /// Per-workload embedding routes, as the host resolved them. + pub embedding_routes: Vec, + + /// Storage-provider selection, when the host has one configured. + pub storage_provider: Option, + + /// The Ollama base URL the host would use. + /// + /// Carried as data because `EmbeddingHost::ollama_base_url` is a synchronous + /// getter and cannot make a bus call. It is only ever reported, never + /// dialled: every embed goes through the host, so this module opens no + /// network connection of its own. + pub ollama_base_url: String, + + /// The host's default managed-cloud embedding model id. + pub cloud_embedding_model: String, + + /// The dimensionality [`Self::cloud_embedding_model`] emits. + pub cloud_embedding_dimensions: usize, + + /// Models the host will accept an explicit output dimensionality for. + /// + /// A list rather than a bus call because + /// `EmbeddingHost::model_supports_dimensions` is synchronous. Absent from + /// the list means "does not support it", which is the safe direction: the + /// engine then omits the parameter instead of writing a batch the provider + /// rejects halfway through. + pub models_supporting_dimensions: Vec, + + /// Driver id to advertise. + /// + /// Defaults to the tinycortex driver id, since that is the engine this + /// module carries. Overridable so a host can bind two builds of the same + /// engine distinguishably, but it must stay stable across restarts and must + /// never embed a URL or a token — it appears in status output and audit + /// events. + pub driver_id: String, +} + +impl Default for ModuleConfig { + fn default() -> Self { + Self { + workspace_dir: PathBuf::new(), + memory: MemoryConfig::default(), + embedding_routes: Vec::new(), + storage_provider: None, + ollama_base_url: String::new(), + cloud_embedding_model: String::new(), + cloud_embedding_dimensions: 0, + models_supporting_dimensions: Vec::new(), + driver_id: tinymemory::registry::TINYCORTEX_DRIVER_ID.to_string(), + } + } +} + +impl ModuleConfig { + /// Reject a configuration that cannot bring up a store. + /// + /// Only `workspace_dir` is checked. Everything else has a defensible + /// default: an absent embedding model means the host answers with whatever + /// it routes to, and an empty route list means the engine's own defaults + /// apply. A missing workspace has no defensible default. + /// + /// # Errors + /// + /// A message naming the field, never its value — a path can identify a + /// user, and module errors must not carry absolute paths. + pub fn validate(&self) -> Result<(), String> { + if self.workspace_dir.as_os_str().is_empty() { + return Err("workspace_dir must be set".to_string()); + } + Ok(()) + } + + /// Drop any credential that rode in on the embedded `MemoryConfig`. + /// + /// # Why this exists + /// + /// [`Self::memory`] is `tinymemory_api::host::MemoryConfig` carried verbatim, + /// which is the right call for every other field — but it contains + /// `agentmemory_secret`, a bearer token for a *remote* memory backend. So the + /// module's "no credentials" property is not a property of + /// [`ModuleConfig`]'s own field list after all; it has to be enforced, and + /// this is where. + /// + /// Found by reading `MemoryConfig` field by field while debugging something + /// unrelated. The structural test over this struct's own keys did not catch + /// it, because the key is one level down — which is the general lesson: + /// "carried verbatim" means credentials are carried verbatim too. + /// + /// # Why strip rather than refuse + /// + /// This module serves the local `tinycortex` engine. A remote-backend token + /// is not something it can use, so refusing the whole load would turn an + /// irrelevant leftover config field into a hard failure for a host whose + /// memory would otherwise work. Stripping is silent to the engine and + /// removes the token from this address space. + /// + /// A host that genuinely wants a remote memory backend should bind that + /// driver directly rather than through this module, which is why the warning + /// says so. + /// + /// Returns whether anything was removed, so the caller can log it once. + pub fn strip_host_credentials(&mut self) -> bool { + if self.memory.agentmemory_secret.take().is_some() { + return true; + } + false + } +} + +#[cfg(test)] +#[path = "config_test.rs"] +mod test; diff --git a/crates/tinymemory-module/src/config_test.rs b/crates/tinymemory-module/src/config_test.rs new file mode 100644 index 0000000..c8e630b --- /dev/null +++ b/crates/tinymemory-module/src/config_test.rs @@ -0,0 +1,154 @@ +//! The config is a wire contract with the host, so these pin its shape. + +use super::ModuleConfig; + +#[test] +fn an_absent_workspace_is_refused() { + // The one field with no defensible default. Silently resolving an empty path + // against the process working directory would put a user's memory store + // somewhere nobody would look for it. + let config = ModuleConfig::default(); + assert!(config.validate().is_err()); +} + +#[test] +fn a_workspace_alone_is_enough() { + // Everything else has a defensible default, so a host that supplies only a + // workspace gets a working module rather than a validation error. + let config = ModuleConfig { + workspace_dir: "/tmp/does-not-need-to-exist".into(), + ..ModuleConfig::default() + }; + assert!(config.validate().is_ok(), "{:?}", config.validate()); +} + +#[test] +fn the_refusal_names_the_field_but_never_a_path() { + // A path can identify a user, and module errors must not carry absolute + // paths. The empty case has no path to leak, so this guards the wording + // rather than the value. + let error = ModuleConfig::default().validate().unwrap_err(); + assert!(error.contains("workspace_dir"), "{error}"); +} + +#[test] +fn an_empty_json_object_deserializes() { + // `#[serde(default)]` on the struct is what lets a host send `{}` and get + // engine defaults. Without it a host would have to mirror every field. + let config: ModuleConfig = serde_json::from_str("{}").expect("empty object is valid"); + assert_eq!(config.driver_id, tinymemory::registry::TINYCORTEX_DRIVER_ID); +} + +#[test] +fn the_default_driver_id_is_the_engine_this_module_carries() { + // A driver id appears in status output and audit events, so a module that + // advertised something else would make the host's records wrong. + assert_eq!( + ModuleConfig::default().driver_id, + tinymemory::registry::TINYCORTEX_DRIVER_ID + ); +} + +#[test] +fn there_is_no_field_that_could_hold_a_credential() { + // The central claim of this module, asserted structurally rather than + // trusted: serialize a fully-populated config and confirm the JSON has no + // key an api key, token or secret could arrive through. A field added later + // with such a name fails here, which is the point — the reviewer is then + // forced to argue for it rather than land it quietly. + let config = ModuleConfig { + workspace_dir: "/tmp/w".into(), + ollama_base_url: "http://localhost:11434".to_string(), + cloud_embedding_model: "text-embedding-3-small".to_string(), + cloud_embedding_dimensions: 1536, + models_supporting_dimensions: vec!["text-embedding-3-small".to_string()], + ..ModuleConfig::default() + }; + + let json = serde_json::to_string(&config).expect("config serializes"); + let value: serde_json::Value = serde_json::from_str(&json).expect("valid json"); + let object = value.as_object().expect("config is a json object"); + + for key in object.keys() { + let lowered = key.to_ascii_lowercase(); + for forbidden in [ + "api_key", + "apikey", + "token", + "secret", + "password", + "credential", + ] { + assert!( + !lowered.contains(forbidden), + "config field {key:?} looks like it carries a credential; \ + embeddings go over the bus precisely so it does not have to" + ); + } + } +} + +#[test] +fn a_credential_nested_in_the_memory_config_is_stripped() { + // The hole the test above cannot see. `MemoryConfig` is carried verbatim and + // contains `agentmemory_secret`, a bearer token — so "this struct has no + // credential field" was true and still not enough. + let mut config = ModuleConfig { + workspace_dir: "/tmp/w".into(), + ..ModuleConfig::default() + }; + config.memory.agentmemory_secret = Some("bearer-token-value".to_string()); + + assert!( + config.strip_host_credentials(), + "it should report removing one" + ); + assert!(config.memory.agentmemory_secret.is_none()); + + // And the token must not survive anywhere in the serialized form. + let json = serde_json::to_string(&config).expect("serializes"); + assert!(!json.contains("bearer-token-value"), "{json}"); +} + +#[test] +fn stripping_a_config_without_a_credential_reports_nothing_removed() { + // So the caller's warning fires only when something actually was removed. + let mut config = ModuleConfig { + workspace_dir: "/tmp/w".into(), + ..ModuleConfig::default() + }; + assert!(!config.strip_host_credentials()); +} + +#[test] +fn stripping_is_idempotent() { + // Setup runs it once, but a second call must not report a phantom removal. + let mut config = ModuleConfig { + workspace_dir: "/tmp/w".into(), + ..ModuleConfig::default() + }; + config.memory.agentmemory_secret = Some("t".to_string()); + assert!(config.strip_host_credentials()); + assert!(!config.strip_host_credentials()); +} + +#[test] +fn a_populated_config_round_trips() { + let config = ModuleConfig { + workspace_dir: "/tmp/w".into(), + ollama_base_url: "http://localhost:11434".to_string(), + cloud_embedding_model: "m".to_string(), + cloud_embedding_dimensions: 8, + models_supporting_dimensions: vec!["m".to_string()], + driver_id: "tinycortex".to_string(), + ..ModuleConfig::default() + }; + + let json = serde_json::to_string(&config).expect("serializes"); + let back: ModuleConfig = serde_json::from_str(&json).expect("deserializes"); + + assert_eq!(back.workspace_dir, config.workspace_dir); + assert_eq!(back.cloud_embedding_dimensions, 8); + assert_eq!(back.models_supporting_dimensions, vec!["m".to_string()]); + assert_eq!(back.driver_id, "tinycortex"); +} diff --git a/crates/tinymemory-module/src/embedding.rs b/crates/tinymemory-module/src/embedding.rs new file mode 100644 index 0000000..7f9b77f --- /dev/null +++ b/crates/tinymemory-module/src/embedding.rs @@ -0,0 +1,303 @@ +//! Embeddings stay host-side; only the compute request crosses. +//! +//! # The decision this module encodes +//! +//! The engine cannot recall anything without embedding a query, and embedding +//! means calling an inference provider that wants a credential. There were two +//! ways to give the module what it needs: +//! +//! 1. put the credential in the module's configuration, or +//! 2. keep the credential in the host and let the module ask the host to embed. +//! +//! This is the second. It is the same shape as the `tinywallet` module's +//! two-call signing split, and the reasoning transfers: a credential is not the +//! only thing that would have crossed with option 1. The host's provider +//! routing, its rate limiting, its cost accounting and its BYOK policy all hang +//! off the place where embedding happens, and moving embedding into the module +//! would have quietly moved all four out of the host's control — or, worse, +//! duplicated them. +//! +//! So [`BusEmbeddingHost::resolve_api_key`] returns `None`, unconditionally and +//! by construction. There is no configuration that makes it return a key, +//! because [`crate::config::ModuleConfig`] has no field to hold one. +//! +//! A loaded module shares this address space, so this is not a hard isolation +//! boundary and is not claimed as one — a hostile module could read the host's +//! keys out of process memory regardless. It is a refusal to widen a boundary +//! that already exists, which is worth doing on its own terms and costs one +//! in-process bus round trip per embed batch. +//! +//! # Why the synchronous getters carry data instead of calling +//! +//! `EmbeddingHost` is deliberately synchronous for everything except the embed +//! itself: `ollama_base_url`, `default_cloud_embedding_model` and +//! `model_supports_dimensions` are plain getters, called from deep inside +//! retrieval and sealing call stacks. They cannot `await` a bus call, so the +//! host passes their answers as configuration at load time. Only +//! [`EmbeddingProvider::embed`] is async, and it is the only method here that +//! touches the bus. + +use std::sync::Arc; + +use async_trait::async_trait; +use tinybus::Connection; +use tinymemory_api::host::{format_embedding_signature, EmbeddingHost, EmbeddingProvider}; + +use crate::config::ModuleConfig; + +/// Well-known name the host serves its embedder under. +pub const EMBEDDING_HOST_BUS_NAME: &str = "ai.tinyhumans.tinymemory.EmbeddingHost"; + +/// Object path the host serves its embedder at. +pub const EMBEDDING_HOST_OBJECT_PATH: &str = "/ai/tinyhumans/tinymemory/EmbeddingHost"; + +/// Interface the host serves at [`EMBEDDING_HOST_OBJECT_PATH`]. +/// +/// Equal to [`EMBEDDING_HOST_BUS_NAME`] by convention, but a separate constant +/// because they are separate concepts to `TinyBus`: one addresses a peer, the +/// other selects a dispatch table on that peer's object. +pub const EMBEDDING_HOST_INTERFACE: &str = "ai.tinyhumans.tinymemory.EmbeddingHost"; + +/// The method the host exports. +const EMBED_METHOD: &str = "Embed"; + +/// Builds bus-backed providers, holding no credential of any kind. +pub struct BusEmbeddingHost { + connection: Connection, + ollama_base_url: String, + cloud_model: String, + cloud_dimensions: usize, + models_supporting_dimensions: Vec, +} + +// `Connection` is not `Debug`, and the trait requires it. Rendering the +// connection would say nothing useful anyway. +impl std::fmt::Debug for BusEmbeddingHost { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("BusEmbeddingHost") + .field("cloud_model", &self.cloud_model) + .field("cloud_dimensions", &self.cloud_dimensions) + .finish_non_exhaustive() + } +} + +impl BusEmbeddingHost { + /// Build a host bridge over `connection`, answering from `config`. + #[must_use] + pub fn new(connection: Connection, config: &ModuleConfig) -> Self { + Self { + connection, + ollama_base_url: config.ollama_base_url.clone(), + cloud_model: config.cloud_embedding_model.clone(), + cloud_dimensions: config.cloud_embedding_dimensions, + models_supporting_dimensions: config.models_supporting_dimensions.clone(), + } + } + + /// A provider that reports `name`/`model`/`dims` and embeds over the bus. + fn provider(&self, name: &str, model: &str, dims: usize) -> BusEmbeddingProvider { + BusEmbeddingProvider { + connection: self.connection.clone(), + name: name.to_string(), + model_id: model.to_string(), + dimensions: dims, + } + } +} + +impl EmbeddingHost for BusEmbeddingHost { + /// Always `None`. See the module docs: this module holds no credentials. + /// + /// `None` is not a degraded answer here. The trait documents it as "the + /// provider has no stored credential", which is the literal truth for every + /// provider from this module's point of view, and the keyed providers treat + /// it as "authenticate some other way" — which the host does, on the far + /// side of `Embed`. + fn resolve_api_key(&self, _provider: &str) -> Option { + None + } + + fn ollama_base_url(&self) -> String { + self.ollama_base_url.clone() + } + + fn default_embedding_provider(&self) -> Arc { + Arc::new(self.provider( + "module-bus", + &self.cloud_model.clone(), + self.cloud_dimensions, + )) + } + + /// Builds a provider for an explicit triple, ignoring `api_key`. + /// + /// `api_key` is part of the trait's signature and is always empty here, both + /// because `resolve_api_key` returns `None` and because the engine is handed + /// an empty key at construction. It is ignored rather than rejected: a + /// non-empty key would mean a caller inside this module had obtained one + /// from somewhere, and failing the embed would be a worse outcome than + /// simply not forwarding it. + /// + /// `custom_endpoint` is likewise not dialled. Whichever endpoint the host + /// routes to is the host's decision, made on the far side of `Embed`. + fn create_embedding_provider_with_credentials( + &self, + provider: &str, + model: &str, + dims: usize, + _api_key: &str, + _custom_endpoint: Option<&str>, + ) -> Result, String> { + Ok(Box::new(self.provider(provider, model, dims))) + } + + fn model_supports_dimensions(&self, model: &str) -> bool { + self.models_supporting_dimensions + .iter() + .any(|known| known == model) + } + + fn cloud_embedding_provider( + &self, + model: &str, + dims: usize, + ) -> Result, String> { + Ok(Box::new(self.provider("cloud", model, dims))) + } + + fn default_cloud_embedding_model(&self) -> &str { + &self.cloud_model + } + + fn default_cloud_embedding_dimensions(&self) -> usize { + self.cloud_dimensions + } + + fn ollama_embedding_provider( + &self, + _base_url: &str, + model: &str, + dims: usize, + ) -> Result, String> { + Ok(Box::new(self.provider("ollama", model, dims))) + } +} + +/// An [`EmbeddingProvider`] that asks the host to do the work. +pub struct BusEmbeddingProvider { + connection: Connection, + name: String, + model_id: String, + dimensions: usize, +} + +impl std::fmt::Debug for BusEmbeddingProvider { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("BusEmbeddingProvider") + .field("name", &self.name) + .field("model_id", &self.model_id) + .field("dimensions", &self.dimensions) + // Non-exhaustive on purpose: `connection` is deliberately omitted, so + // `Debug` output can never become a place a transport detail leaks. + .finish_non_exhaustive() + } +} + +#[async_trait] +impl EmbeddingProvider for BusEmbeddingProvider { + fn name(&self) -> &str { + &self.name + } + + fn model_id(&self) -> &str { + &self.model_id + } + + fn dimensions(&self) -> usize { + self.dimensions + } + + /// Embed `texts` by calling the host. + /// + /// The model and dimensionality this provider was built for travel with the + /// request, so the host embeds into the space the engine believes it is + /// writing into. A host that silently substituted a different model would + /// split the embedding space, which is why the returned width is checked + /// against [`Self::dimensions`] before the vectors are handed back — a + /// mismatch is a hard error rather than vectors written into the wrong + /// space, where they would become unsearchable without a re-embed. + /// + /// A zero-dimension provider is the engine's "semantic search off" state and + /// is exempt from that check: it is expected to return empty vectors. + /// + /// # Errors + /// + /// The bus failure verbatim, or a width mismatch. Never carries the input + /// text: a memory chunk is user content and an error string is not a place + /// for it. + async fn embed(&self, texts: &[&str]) -> anyhow::Result>> { + if texts.is_empty() { + return Ok(Vec::new()); + } + + let proxy = self + .connection + .proxy( + EMBEDDING_HOST_BUS_NAME, + EMBEDDING_HOST_OBJECT_PATH, + EMBEDDING_HOST_INTERFACE, + ) + .map_err(|error| anyhow::anyhow!("embedding host unreachable: {error}"))?; + + let owned: Vec = texts.iter().map(|text| (*text).to_string()).collect(); + log::debug!( + "[tinymemory:module] embed batch={} model={} dims={}", + owned.len(), + self.model_id, + self.dimensions + ); + + let vectors: Vec> = proxy + .call( + EMBED_METHOD, + (self.model_id.clone(), self.dimensions, owned), + ) + .await + .map_err(|error| anyhow::anyhow!("host embed failed: {error}"))?; + + if vectors.len() != texts.len() { + anyhow::bail!( + "host returned {} vectors for {} inputs", + vectors.len(), + texts.len() + ); + } + if self.dimensions > 0 { + if let Some(bad) = vectors + .iter() + .find(|vector| vector.len() != self.dimensions) + { + anyhow::bail!( + "host returned a {}-dimension vector for a {}-dimension space", + bad.len(), + self.dimensions + ); + } + } + + Ok(vectors) + } +} + +/// The signature the engine will see for a bus-backed provider. +/// +/// Exposed so a host can compute the same string without instantiating a +/// provider; drift between the two silently splits one embedding space in half. +#[must_use] +pub fn bus_provider_signature(name: &str, model_id: &str, dims: usize) -> String { + format_embedding_signature(name, model_id, dims) +} + +#[cfg(test)] +#[path = "embedding_test.rs"] +mod test; diff --git a/crates/tinymemory-module/src/embedding_test.rs b/crates/tinymemory-module/src/embedding_test.rs new file mode 100644 index 0000000..285b52d --- /dev/null +++ b/crates/tinymemory-module/src/embedding_test.rs @@ -0,0 +1,318 @@ +//! These drive a real in-memory bus with a stand-in host embedder. +//! +//! The interesting cases are the refusals. A host that returns the wrong number +//! of vectors, or vectors of the wrong width, has silently split the embedding +//! space — every vector written on the wrong side of the split becomes +//! unsearchable without a re-embed, and nothing fails at the time. So the +//! provider checks, and these tests are what prove it checks. + +use std::sync::Arc; + +use tinybus::broker::Broker; +use tinybus::transport::memory::MemoryBus; +use tinybus::{Connection, Result as BusResult}; +use tinymemory_api::host::{EmbeddingHost, EmbeddingProvider}; + +use super::{BusEmbeddingHost, EMBEDDING_HOST_BUS_NAME, EMBEDDING_HOST_OBJECT_PATH}; +use crate::config::ModuleConfig; + +/// A stand-in for the host's embedder, returning vectors of a chosen width. +struct FakeHostEmbedder { + /// Width of each returned vector. Set to something other than the requested + /// dimensionality to exercise the mismatch refusal. + width: usize, + /// Return this many vectors regardless of input count, when `Some`. + force_count: Option, +} + +#[tinybus::interface(name = "ai.tinyhumans.tinymemory.EmbeddingHost")] +impl FakeHostEmbedder { + #[allow(clippy::unused_async, reason = "the interface macro requires async")] + async fn embed( + &self, + _model: String, + _dimensions: usize, + texts: Vec, + ) -> BusResult>> { + let count = self.force_count.unwrap_or(texts.len()); + Ok((0..count).map(|_| vec![0.5_f32; self.width]).collect()) + } +} + +/// Bring up a bus with `embedder` served at the host's well-known name. +/// +/// The broker task is leaked deliberately: it lives as long as the test, and +/// joining it would mean shutting the bus down before the assertions run. +async fn bus_with_host(embedder: FakeHostEmbedder) -> Connection { + let bus = MemoryBus::new(); + let broker = Broker::new(); + let _broker_task = broker.spawn(bus.clone()); + + let host_side = Connection::connect(bus.connect().await.expect("host transport")) + .await + .expect("host connection"); + host_side + .serve_at( + EMBEDDING_HOST_OBJECT_PATH.try_into().expect("valid path"), + embedder, + ) + .await + .expect("serve embedder"); + host_side + .request_name(EMBEDDING_HOST_BUS_NAME) + .await + .expect("claim name"); + // Held for the lifetime of the test: dropping it would release the name. + std::mem::forget(host_side); + + Connection::connect(bus.connect().await.expect("module transport")) + .await + .expect("module connection") +} + +fn config_with_dims(dims: usize) -> ModuleConfig { + ModuleConfig { + workspace_dir: "/tmp/tinymemory-module-test".into(), + cloud_embedding_model: "test-model".to_string(), + cloud_embedding_dimensions: dims, + models_supporting_dimensions: vec!["test-model".to_string()], + ..ModuleConfig::default() + } +} + +#[tokio::test] +async fn a_batch_is_embedded_over_the_bus() { + let connection = bus_with_host(FakeHostEmbedder { + width: 4, + force_count: None, + }) + .await; + let host = BusEmbeddingHost::new(connection, &config_with_dims(4)); + let provider = host.default_embedding_provider(); + + let vectors = provider + .embed(&["alpha", "beta"]) + .await + .expect("the host embeds"); + + assert_eq!(vectors.len(), 2); + assert!(vectors.iter().all(|vector| vector.len() == 4)); +} + +#[tokio::test] +async fn a_wrong_width_is_refused_rather_than_written() { + // The dangerous case. Accepting these would write vectors into a space they + // do not belong to, and nothing would fail until a later search silently + // returned nothing. + let connection = bus_with_host(FakeHostEmbedder { + width: 8, + force_count: None, + }) + .await; + let host = BusEmbeddingHost::new(connection, &config_with_dims(4)); + let provider = host.default_embedding_provider(); + + let error = provider + .embed(&["alpha"]) + .await + .expect_err("an 8-wide vector must not pass as 4-wide"); + assert!(error.to_string().contains("dimension"), "{error}"); +} + +#[tokio::test] +async fn a_wrong_vector_count_is_refused() { + // Callers pair inputs with outputs positionally, so a short reply would + // attach the wrong vector to the wrong chunk. + let connection = bus_with_host(FakeHostEmbedder { + width: 4, + force_count: Some(1), + }) + .await; + let host = BusEmbeddingHost::new(connection, &config_with_dims(4)); + let provider = host.default_embedding_provider(); + + let error = provider + .embed(&["alpha", "beta"]) + .await + .expect_err("one vector for two inputs must be refused"); + assert!(error.to_string().contains("vectors"), "{error}"); +} + +#[tokio::test] +async fn a_zero_dimension_provider_is_exempt_from_the_width_check() { + // Zero dimensions is the engine's "semantic search off" state and is + // expected to yield empty vectors; enforcing a width there would break + // keyword-only retrieval. + let connection = bus_with_host(FakeHostEmbedder { + width: 0, + force_count: None, + }) + .await; + let host = BusEmbeddingHost::new(connection, &config_with_dims(0)); + let provider = host.default_embedding_provider(); + + let vectors = provider + .embed(&["alpha"]) + .await + .expect("zero dims is legal"); + assert_eq!(vectors.len(), 1); + assert!(vectors[0].is_empty()); +} + +#[tokio::test] +async fn an_empty_batch_never_reaches_the_bus() { + // No host is served here at all, so this only passes if the call short + // circuits — which is what makes it a test of the short circuit rather than + // of the happy path. + let bus = MemoryBus::new(); + let broker = Broker::new(); + let _task = broker.spawn(bus.clone()); + let connection = Connection::connect(bus.connect().await.expect("transport")) + .await + .expect("connection"); + + let host = BusEmbeddingHost::new(connection, &config_with_dims(4)); + let provider = host.default_embedding_provider(); + + let vectors = provider + .embed(&[]) + .await + .expect("an empty batch is trivial"); + assert!(vectors.is_empty()); +} + +#[tokio::test] +async fn an_absent_host_fails_by_name_rather_than_hanging() { + // A host that never served its embedder must produce an error the operator + // can act on. This is also why the embedder is not declared as a module + // `requires`: that would leave the module permanently unresolved instead. + let bus = MemoryBus::new(); + let broker = Broker::new(); + let _task = broker.spawn(bus.clone()); + let connection = Connection::connect(bus.connect().await.expect("transport")) + .await + .expect("connection"); + + let host = BusEmbeddingHost::new(connection, &config_with_dims(4)); + let provider = host.default_embedding_provider(); + + let error = provider + .embed(&["alpha"]) + .await + .expect_err("no embedder is served"); + assert!(!error.to_string().is_empty()); +} + +#[tokio::test] +async fn the_module_never_reports_a_credential() { + // The central claim, asserted on the behaviour rather than the config shape: + // no provider name yields a key, including ones a host would normally have + // one for. + let connection = bus_with_host(FakeHostEmbedder { + width: 4, + force_count: None, + }) + .await; + let host = BusEmbeddingHost::new(connection, &config_with_dims(4)); + + for provider in ["openai", "cohere", "voyage", "custom", "ollama", "cloud"] { + assert!( + host.resolve_api_key(provider).is_none(), + "{provider} must not resolve a key inside the module" + ); + } +} + +#[tokio::test] +async fn a_keyed_provider_request_still_builds_and_ignores_the_key() { + // The engine may ask for a keyed provider with an empty key. Refusing would + // break recall; forwarding a key would defeat the split. It builds, and the + // key goes nowhere. + let connection = bus_with_host(FakeHostEmbedder { + width: 3, + force_count: None, + }) + .await; + let host = BusEmbeddingHost::new(connection, &config_with_dims(3)); + + let provider = host + .create_embedding_provider_with_credentials("openai", "text-embedding-3-small", 3, "", None) + .expect("a keyed provider still builds"); + + assert_eq!(provider.model_id(), "text-embedding-3-small"); + assert_eq!(provider.dimensions(), 3); + let vectors = provider.embed(&["alpha"]).await.expect("embeds"); + assert_eq!(vectors[0].len(), 3); +} + +#[tokio::test] +async fn dimension_support_is_answered_from_configuration() { + // A synchronous getter cannot make a bus call, so the host passes the list. + // Absent means "unsupported", which is the safe direction: the engine omits + // the parameter rather than writing a batch the provider rejects halfway. + let connection = bus_with_host(FakeHostEmbedder { + width: 4, + force_count: None, + }) + .await; + let host = BusEmbeddingHost::new(connection, &config_with_dims(4)); + + assert!(host.model_supports_dimensions("test-model")); + assert!(!host.model_supports_dimensions("some-other-model")); +} + +#[tokio::test] +async fn the_signature_matches_what_the_contract_formats() { + // Drift between a live provider's signature and a config-derived one splits + // one embedding space in two, so both must route through the same formatter. + let connection = bus_with_host(FakeHostEmbedder { + width: 4, + force_count: None, + }) + .await; + let host = BusEmbeddingHost::new(connection, &config_with_dims(4)); + let provider = host.default_embedding_provider(); + + assert_eq!( + provider.signature(), + super::bus_provider_signature(provider.name(), provider.model_id(), 4) + ); +} + +#[tokio::test] +async fn the_debug_form_carries_no_connection_and_no_key() { + // `Debug` output reaches logs. It must not become a place a credential or a + // transport detail leaks. + // + // Async despite testing a synchronous formatter: `Broker::spawn` needs a + // reactor, so building a connection at all requires a runtime. + let bus = MemoryBus::new(); + let broker = Broker::new(); + let _task = broker.spawn(bus.clone()); + let connection = Connection::connect(bus.connect().await.expect("transport")) + .await + .expect("connection"); + + let host = BusEmbeddingHost::new(connection, &config_with_dims(4)); + let rendered = format!("{host:?}"); + assert!(rendered.contains("BusEmbeddingHost"), "{rendered}"); + for forbidden in ["api_key", "token", "secret", "Connection"] { + assert!(!rendered.contains(forbidden), "{rendered}"); + } +} + +/// Kept honest: an `Arc` is what the engine holds, so the +/// bus provider must be usable as one. +#[tokio::test] +async fn the_provider_is_usable_as_a_trait_object() { + let connection = bus_with_host(FakeHostEmbedder { + width: 2, + force_count: None, + }) + .await; + let host = BusEmbeddingHost::new(connection, &config_with_dims(2)); + + let provider: Arc = host.default_embedding_provider(); + let one = provider.embed_one("alpha").await.expect("embed_one works"); + assert_eq!(one.len(), 2); +} diff --git a/crates/tinymemory-module/src/lib.rs b/crates/tinymemory-module/src/lib.rs new file mode 100644 index 0000000..c38bd2c --- /dev/null +++ b/crates/tinymemory-module/src/lib.rs @@ -0,0 +1,195 @@ +//! Loadable `TinyBus` module adapter for `TinyMemory`. +//! +//! This private workspace crate keeps the vendored `TinyBus` dependency out of +//! the published `tinymemory` crates. Its `cdylib` output is the +//! target-specific binary distributed in GitHub releases. +//! +//! # What this module is for, stated honestly +//! +//! It carries the memory **engine** — `tinycortex` and `tinymemory-core` — so a +//! host that loads it compiles neither. +//! +//! It is worth being precise about the benefit, because the obvious guess is +//! wrong. This module sheds **no third-party dependencies** from a host. Every +//! crate the engine uses (`rusqlite`, `reqwest`, `chrono`, `regex`, `uuid`, +//! `walkdir`, `sha2`, `tokio`) is shared with surface a host keeps, and +//! `libsqlite3-sys` in particular has several other parents — `tinyagents`' +//! session store among them — so the native `SQLite` build does not leave. That +//! was measured on `OpenHuman`, on both its kernel and its shipping feature +//! profiles: four crate names leave, and all four are ours. +//! +//! What it does buy is **compile time on the critical path**, and that was +//! measured too. `tinycortex` and `tinymemory-core` compile strictly serially +//! ahead of the host crate — `tinyagents` → `tinycortex` → `tinymemory-core` → +//! host, each starting as the previous one ends — putting 14.7s directly in +//! front of the host's own compilation. Removing them from the host's graph +//! moved a full build from 176s to about 161s. +//! +//! Do not re-justify this module on dependency count. The number is zero and it +//! is written down here so nobody re-derives it optimistically. +//! +//! # It carries no credentials +//! +//! The engine needs embeddings, embeddings need an inference credential, and +//! that credential stays in the host. The module asks the host to embed over the +//! bus instead — see [`embedding`], which is the same split the `tinywallet` +//! module makes with a signing key. +//! +//! [`config::ModuleConfig`]'s own fields cannot hold a key, but that is not +//! sufficient on its own and it is worth saying why: it embeds +//! `tinymemory_api::host::MemoryConfig` **verbatim**, and that struct contains +//! `agentmemory_secret`, a bearer token for a remote memory backend. So the +//! property is *enforced* at setup by +//! [`config::ModuleConfig::strip_host_credentials`], not merely asserted about a +//! field list. "Carried verbatim" carries credentials verbatim too. +//! +//! # Scope: the mandatory three +//! +//! The served surface is `tinymemory_api`'s mandatory capability families — +//! Core, Recall, Portability — which is exactly what `tinymemory-tinycortex` +//! can provide. The ten optional families need a host's configuration, embedding +//! compute and job queue, and a host that has those implements them itself. +//! See [`service`] for the method list. + +// Test code may panic; library code may not. The `[lints]` table cannot be +// scoped to non-test builds, so the exemption is expressed here instead. +#![cfg_attr( + test, + allow( + clippy::expect_used, + clippy::unwrap_used, + clippy::panic, + clippy::cast_precision_loss + ) +)] + +pub mod config; +pub mod embedding; +mod service; + +pub use config::ModuleConfig; +pub use embedding::{ + BusEmbeddingHost, BusEmbeddingProvider, EMBEDDING_HOST_BUS_NAME, EMBEDDING_HOST_INTERFACE, + EMBEDDING_HOST_OBJECT_PATH, +}; +pub use service::{BUS_NAME, OBJECT_PATH}; + +use std::sync::Arc; + +use tinybus::{Connection, Error as BusError, Result as BusResult}; + +/// The module refused its configuration or could not bring up a store. +const SETUP_FAILED_ERROR: &str = "ai.tinyhumans.tinymemory.Error.SetupFailed"; + +/// Bring up the engine and serve it. +/// +/// # Order matters +/// +/// The bus-backed [`BusEmbeddingHost`] is installed **before** the engine is +/// constructed. `tinymemory-core` resolves its embedder through a process-global +/// during construction, and a store built before the host is installed would +/// either fail or — worse — bind the inert zero-dimension provider and write +/// vectors nobody can search. The global is why this is a `set` and not an +/// argument: the construction sites sit deep inside retrieval and sealing call +/// stacks that already thread a config and a store handle. +/// +/// # The empty API key is deliberate +/// +/// `create_memory_with_local_ai` is handed `""`. Every embed goes over the bus to +/// the host, which holds the real credential, so there is nothing to pass and +/// nothing here that could leak one. +async fn setup(connection: Connection, mut config: ModuleConfig) -> BusResult<()> { + config.validate().map_err(setup_error)?; + + // `MemoryConfig` travels verbatim, and it contains a bearer token field for a + // remote memory backend. Carried credentials are exactly what this module + // refuses to hold, so it goes before anything else touches the config. + if config.strip_host_credentials() { + log::warn!( + "[tinymemory:module] discarded a remote-backend credential from the \ + supplied config; this module serves the local engine only, so bind a \ + remote memory driver directly instead of through it" + ); + } + + log::debug!( + "[tinymemory:module] setup driver_id={} routes={} cloud_dims={}", + config.driver_id, + config.embedding_routes.len(), + config.cloud_embedding_dimensions + ); + + // Install the embedder first. See the doc comment. + tinymemory_core::embedding_host::set_embedding_host(Arc::new(BusEmbeddingHost::new( + connection.clone(), + &config, + ))); + + let memory = tinymemory_core::store::factories::create_memory_with_local_ai( + &config.memory, + None, + "", + &config.embedding_routes, + config.storage_provider.as_ref(), + &config.workspace_dir, + ) + .map_err(|error| setup_error(format!("create memory store: {error}")))?; + + let provider = tinymemory_tinycortex::provider(Arc::from(memory)); + service::serve(&connection, Arc::new(provider)).await +} + +/// A setup failure, carrying no path and no credential. +fn setup_error(message: impl Into) -> BusError { + BusError::MethodFailed { + name: SETUP_FAILED_ERROR.to_string(), + message: message.into(), + } +} + +// Isolate the generated public C symbols so the lint exception cannot hide +// undocumented Rust API. Their contract is TinyBus ABI v1, and none is a +// Rust-callable export from this crate. +#[allow( + missing_docs, + unreachable_pub, + reason = "generated C ABI symbols are documented by the TinyBus module SDK" +)] +mod exports { + tinybus_module::module_export! { + setup = super::setup, + config = super::ModuleConfig, + // Two, not one: a recall that triggers an embed makes an outbound call + // while still inside its own inbound call, so a single worker would + // deadlock on the first semantic query. + worker_threads = 2, + provides = ["ai.tinyhumans.tinymemory.Memory"], + methods = [ + "DriverId", + "Capabilities", + "Health", + "Shutdown", + "Store", + "Get", + "Forget", + "List", + "Namespaces", + "Recall", + "ExportPage", + "ImportRecords", + ], + signals = [], + // The host's embedder is deliberately NOT declared as `requires`. That + // field is resolved against already-loaded *modules*, and this dependency + // is served by the host itself, which would leave the module permanently + // unresolved. It is dialled lazily on the first embed instead, and a host + // that has not served it gets a named error rather than a module that + // never starts. + requires = [], + optional = [], + // Eager: bringing up a store opens a database and may run migrations, + // and charging that to whichever call happens to be first would make an + // ordinary recall time out on a cold start. + lazy = false, + } +} diff --git a/crates/tinymemory-module/src/service/mod.rs b/crates/tinymemory-module/src/service/mod.rs new file mode 100644 index 0000000..dc14588 --- /dev/null +++ b/crates/tinymemory-module/src/service/mod.rs @@ -0,0 +1,276 @@ +//! `TinyBus` service boundary for the memory surface. +//! +//! One object, `/ai/tinyhumans/tinymemory/Memory`, exporting the mandatory +//! capability families plus the four driver-level methods: +//! +//! ```text +//! DriverId() -> String +//! Capabilities() -> Capabilities +//! Health() -> MemoryHealth +//! Shutdown() -> () +//! +//! Store(namespace, key, content, category, session_id, taint) -> () +//! Get(namespace, key) -> Option +//! Forget(namespace, key) -> bool +//! List(namespace, category, session_id) -> [MemoryEntry] +//! Namespaces() -> [NamespaceSummary] +//! Recall(query, limit, opts, scope) -> [MemoryEntry] +//! ExportPage(cursor, limit) -> ExportPage +//! ImportRecords(records) -> ImportOutcome +//! ``` +//! +//! # Why the method list mirrors a trait exactly +//! +//! These twelve are `tinymemory_api`'s [`MemoryProvider`] plus its three +//! mandatory supertraits, with the borrows replaced by owned equivalents. That +//! is deliberate: the host binds an `Arc`, so a host-side +//! client that forwards each method one-for-one is a *complete* provider with no +//! translation layer in between. Anything cleverer — batching, a combined +//! "recall and store" call — would put engine semantics on the wire, where two +//! sides could disagree about them. +//! +//! # Why only the mandatory families +//! +//! `tinymemory-tinycortex` advertises Core, Recall and Portability and nothing +//! else, because the ten optional families are reached through engine entry +//! points that need a host's configuration, embedding compute and job queue. +//! This module serves exactly what that adapter can provide. Serving more would +//! mean advertising capabilities whose accessors return nothing, which +//! `audit_provider` is specifically written to catch. +//! +//! # Everything travels inline +//! +//! A `TinyBus` frame is JSON capped at 16 MiB. That is a real constraint for a +//! generated document, where a byte array costs about 3.5 bytes per byte, and it +//! is not one here: memory entries are *text*, which costs about 1.1× as JSON. +//! So there is no blob store, no chunking and no held output — the apparatus the +//! `tinydocs` module needs does not appear in this one. +//! +//! The one method that could grow without bound is `ExportPage`, and it is +//! already paged by contract with the caller choosing the page size. A caller +//! that asks for a million records in one page gets a frame-size error, which is +//! the correct answer. +//! +//! # Errors are named, and the names are the contract +//! +//! [`MemoryError`] is a rich enum, but a bus error is a name plus a string. The +//! table that maps between them lives in [`tinymemory_api::wire`] and is used by +//! **both** ends, so the module and the host cannot drift into disagreeing about +//! what a name means. See that module for why there is one name per variant +//! rather than one per outcome class. +//! +//! **No method here logs a namespace key, an entry's content, or a recall +//! query.** All three are user memory content, and a module error must not carry +//! payload values. + +use std::sync::Arc; + +use tinybus::{Connection, Error as BusError, Result as BusResult}; +use tinymemory_api::capabilities::Capabilities; +use tinymemory_api::error::MemoryError; +use tinymemory_api::health::MemoryHealth; +use tinymemory_api::provider::types::{ExportPage, ExportRecord, ImportOutcome, SourceScope}; +// `MemoryCore`, `MemoryRecall` and `MemoryPortability` are deliberately not +// imported: they are supertraits of `MemoryProvider`, so their methods are +// already callable on the trait object. +use tinymemory_api::provider::MemoryProvider; +use tinymemory_api::recall::OwnedRecallOpts; +use tinymemory_api::types::{MemoryCategory, MemoryEntry, MemoryTaint, NamespaceSummary}; +use tinymemory_api::wire; + +/// Well-known name exported by the `TinyMemory` module. +pub const BUS_NAME: &str = "ai.tinyhumans.tinymemory.Memory"; + +/// Object path exported by the `TinyMemory` module. +pub const OBJECT_PATH: &str = "/ai/tinyhumans/tinymemory/Memory"; + +/// The served object: a bound driver and nothing else. +pub(crate) struct MemoryService { + provider: Arc, +} + +impl MemoryService { + /// Serve `provider`. + pub(crate) fn new(provider: Arc) -> Self { + Self { provider } + } +} + +#[tinybus::interface(name = "ai.tinyhumans.tinymemory.Memory")] +impl MemoryService { + /// The bound driver's stable identifier. + #[allow( + clippy::unused_async, + reason = "tinybus::interface requires every method to be `async fn`" + )] + async fn driver_id(&self) -> BusResult { + Ok(self.provider.driver_id().to_string()) + } + + /// The families this driver implements. + /// + /// The host caches this at bind time, exactly as it would for an in-process + /// driver — the trait documents that the set is asked once and must not + /// change afterwards. + #[allow( + clippy::unused_async, + reason = "tinybus::interface requires every method to be `async fn`" + )] + async fn capabilities(&self) -> BusResult { + Ok(self.provider.capabilities()) + } + + /// Current liveness, as the driver reports it. + async fn health(&self) -> BusResult { + Ok(self.provider.health().await) + } + + /// Release backend resources. + /// + /// Idempotent, as the trait requires. Note that this does **not** unload the + /// module: `TinyBus` never unloads a library, so a host that shuts the + /// driver down and rebinds gets a fresh engine inside the same mapped image. + async fn shutdown(&self) -> BusResult<()> { + self.provider + .shutdown() + .await + .map_err(|error| into_bus_error(&error)) + } + + /// Upsert an entry keyed by `(namespace, key)`. + /// + /// `taint` is a required argument rather than a defaulted one, mirroring the + /// contract: a driver that could default provenance would be able to launder + /// externally-sourced content into internal-trust content, which is the one + /// failure mode the host's policy guard exists to prevent. + async fn store( + &self, + namespace: String, + key: String, + content: String, + category: MemoryCategory, + session_id: Option, + taint: MemoryTaint, + ) -> BusResult<()> { + self.provider + .store( + &namespace, + &key, + &content, + category, + session_id.as_deref(), + taint, + ) + .await + .map_err(|error| into_bus_error(&error)) + } + + /// Fetch the entry at an exact `(namespace, key)`. + async fn get(&self, namespace: String, key: String) -> BusResult> { + self.provider + .get(&namespace, &key) + .await + .map_err(|error| into_bus_error(&error)) + } + + /// Delete the entry at `(namespace, key)`, reporting whether it existed. + async fn forget(&self, namespace: String, key: String) -> BusResult { + self.provider + .forget(&namespace, &key) + .await + .map_err(|error| into_bus_error(&error)) + } + + /// List entries, narrowing by namespace, category and session. + async fn list( + &self, + namespace: Option, + category: Option, + session_id: Option, + ) -> BusResult> { + self.provider + .list( + namespace.as_deref(), + category.as_ref(), + session_id.as_deref(), + ) + .await + .map_err(|error| into_bus_error(&error)) + } + + /// Enumerate namespaces with their aggregate counts. + async fn namespaces(&self) -> BusResult> { + self.provider + .namespaces() + .await + .map_err(|error| into_bus_error(&error)) + } + + /// Ranked retrieval. + /// + /// `scope` is a query predicate the driver applies internally, not a filter + /// the host may apply to the result: narrowing afterwards would let the + /// driver spend its `limit` on entries the caller is not allowed to see and + /// then return fewer than it could have. + async fn recall( + &self, + query: String, + limit: usize, + opts: OwnedRecallOpts, + scope: Option, + ) -> BusResult> { + self.provider + .recall(&query, limit, &opts, scope.as_ref()) + .await + .map_err(|error| into_bus_error(&error)) + } + + /// Read one page of the export, continuing from `cursor`. + async fn export_page(&self, cursor: Option, limit: usize) -> BusResult { + self.provider + .export_page(cursor.as_deref(), limit) + .await + .map_err(|error| into_bus_error(&error)) + } + + /// Write a batch of previously-exported records. + /// + /// Partial success is reported inside [`ImportOutcome`] rather than as an + /// error, so a million-record restore is not aborted by one bad record. + async fn import_records(&self, records: Vec) -> BusResult { + self.provider + .import_records(records) + .await + .map_err(|error| into_bus_error(&error)) + } +} + +/// Map a [`MemoryError`] onto a named bus error. +/// +/// Both the name and the message come from [`tinymemory_api::wire`], which the +/// host's client also uses to map them back. Deriving them here instead would +/// give the contract two definitions free to drift — and the drift that matters +/// is silent: a `PathEscape` arriving as an `Invalid` reclassifies a sandbox +/// escape as a caller mistake. +fn into_bus_error(error: &MemoryError) -> BusError { + BusError::MethodFailed { + name: wire::wire_name(error).to_string(), + message: wire::wire_message(error), + } +} + +/// Serve the memory object and claim the well-known name. +pub(crate) async fn serve( + connection: &Connection, + provider: Arc, +) -> BusResult<()> { + connection + .serve_at(OBJECT_PATH.try_into()?, MemoryService::new(provider)) + .await?; + connection.request_name(BUS_NAME).await?; + Ok(()) +} + +#[cfg(test)] +#[path = "test.rs"] +mod test; diff --git a/crates/tinymemory-module/src/service/test.rs b/crates/tinymemory-module/src/service/test.rs new file mode 100644 index 0000000..6f2da8e --- /dev/null +++ b/crates/tinymemory-module/src/service/test.rs @@ -0,0 +1,2 @@ +// Placeholder: the served surface is exercised through the loader E2E in +// `tests/module_e2e.rs`, which drives a real broker and a real module. diff --git a/crates/tinymemory-module/tests/module_e2e.rs b/crates/tinymemory-module/tests/module_e2e.rs new file mode 100644 index 0000000..bdea3ad --- /dev/null +++ b/crates/tinymemory-module/tests/module_e2e.rs @@ -0,0 +1,453 @@ +//! The real thing: a `dlopen`ed `cdylib`, a real broker, a real store. +//! +//! # Why every test here is `#[ignore]`d +//! +//! Not flakiness — a runtime constraint that cannot be worked around inside a +//! single test binary. +//! +//! `Broker::spawn` binds its tasks to whichever tokio runtime created it, and +//! `#[tokio::test]` builds a fresh runtime per test function. The module is +//! loaded once per process and never unloaded (`TinyBus` deliberately never +//! unloads a library), so the second test to drive it finds a broker whose tasks +//! died with the first runtime, and the call **hangs** until some deadline above +//! it fires rather than failing cleanly. +//! +//! So a test that drives a real module must be the only one running in its +//! process. Run them one at a time: +//! +//! ```sh +//! cargo build --release -p tinymemory-module +//! TINYMEMORY_TEST_MODULE=target/release/libtinymemory_module.so \ +//! cargo test --manifest-path crates/tinymemory-module/Cargo.toml \ +//! --test module_e2e -- --ignored --exact +//! ``` +//! +//! `--ignored` alone runs them all in one process and the second will hang. This +//! is the same constraint the `tinywallet` module's loader tests carry. + +#![allow( + clippy::expect_used, + clippy::unwrap_used, + clippy::panic, + clippy::cast_precision_loss, + reason = "test code may panic, and the fake embedder derives a vector from a length" +)] + +use std::sync::Arc; + +use tinybus::broker::Broker; +use tinybus::module::ModuleHost; +use tinybus::transport::memory::MemoryBus; +use tinybus::{Connection, Result as BusResult}; +use tinymemory_api::capabilities::{Capabilities, Capability}; +use tinymemory_api::types::{MemoryCategory, MemoryEntry, MemoryTaint}; +use tinymemory_module::{ + BUS_NAME, EMBEDDING_HOST_BUS_NAME, EMBEDDING_HOST_OBJECT_PATH, OBJECT_PATH, +}; + +/// The interface the module dispatches on. +const MEMORY_INTERFACE: &str = "ai.tinyhumans.tinymemory.Memory"; + +/// Width of the vectors this fake host returns. +const DIMS: usize = 8; + +/// Counts embed calls the module made, across the process. +/// +/// A process-global rather than a field because the served object is moved into +/// the connection and there is no handle left to read afterwards. One module per +/// process is already a hard constraint here (see the module docs), so a global +/// is not shared between tests in practice. +static EMBED_CALLS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + +/// Stands in for the host's embedder so recall has something to work with. +/// +/// Deterministic rather than random: a recall assertion that depended on a +/// random vector would pass or fail for reasons unrelated to the module. +struct HostEmbedder; + +#[tinybus::interface(name = "ai.tinyhumans.tinymemory.EmbeddingHost")] +impl HostEmbedder { + #[allow(clippy::unused_async, reason = "the interface macro requires async")] + async fn embed( + &self, + _model: String, + _dimensions: usize, + texts: Vec, + ) -> BusResult>> { + EMBED_CALLS.fetch_add(1, std::sync::atomic::Ordering::SeqCst); + // A crude content-derived vector: enough that identical text embeds + // identically and different text does not, which is all recall needs + // here. + Ok(texts + .iter() + .map(|text| { + let seed = text.len() as f32; + (0..DIMS) + .map(|index| (seed + index as f32).sin()) + .collect::>() + }) + .collect()) + } +} + +/// Load the module, serve the host embedder, and hand back a client connection. +/// +/// The returned `ModuleHost` and broker task must be kept alive by the caller: +/// dropping the host is what would release the module's transport. +async fn admit_module( + workspace: &std::path::Path, +) -> ( + Connection, + ModuleHost, + tokio::task::JoinHandle>, +) { + let artifact = std::env::var_os("TINYMEMORY_TEST_MODULE") + .expect("TINYMEMORY_TEST_MODULE must point at the built cdylib"); + + let bus = MemoryBus::new(); + let broker = Broker::new(); + let broker_task = broker.spawn(bus.clone()); + + // The host's half: serve the embedder *before* loading the module, because + // the module builds its store during initialization and a store built + // without a reachable embedder would bind the inert provider. + let host_side = Connection::connect(bus.connect().await.expect("host transport")) + .await + .expect("host connection"); + host_side + .serve_at( + EMBEDDING_HOST_OBJECT_PATH.try_into().expect("valid path"), + HostEmbedder, + ) + .await + .expect("serve embedder"); + host_side + .request_name(EMBEDDING_HOST_BUS_NAME) + .await + .expect("claim embedder name"); + // Deliberately leaked: dropping this releases the well-known name, and the + // module needs it for the whole test. + std::mem::forget(host_side); + + let modules = ModuleHost::new(broker); + // The `memory` block is set explicitly rather than left to default, because + // the engine sizes its vector store from `memory.embedding_dimensions` (1024 + // by default) while the bus provider reports the `cloud_embedding_dimensions` + // above. Left mismatched, the store and the embedder disagree about the width + // of the space and recall returns nothing — which is exactly the failure the + // provider's width check exists to make loud, so the two are pinned equal + // here on purpose. + // + // `min_relevance_score` is dropped to 0 because the fake embedder's vectors + // are content-derived noise, not real semantics; the default 0.4 floor would + // filter out a correct match for reasons that have nothing to do with the + // module. + let config = serde_json::json!({ + "workspace_dir": workspace, + "cloud_embedding_model": "e2e-model", + "cloud_embedding_dimensions": DIMS, + "models_supporting_dimensions": ["e2e-model"], + "memory": { + "embedding_provider": "cloud", + "embedding_model": "e2e-model", + "embedding_dimensions": DIMS, + "min_relevance_score": 0.0, + }, + }); + + let loaded = modules + .load_file_with_config(&artifact, config) + .expect("module should load"); + assert_eq!(loaded.name, "tinymemory-module"); + assert_eq!(loaded.manifest.bus_name.as_str(), BUS_NAME); + assert_eq!(loaded.manifest.object_path.as_str(), OBJECT_PATH); + + let client = Connection::connect(bus.connect().await.expect("client transport")) + .await + .expect("client connection"); + (client, modules, broker_task) +} + +fn proxy(connection: &Connection) -> tinybus::Proxy { + connection + .proxy(BUS_NAME, OBJECT_PATH, MEMORY_INTERFACE) + .expect("proxy") +} + +#[tokio::test] +#[ignore = "drives a real dlopen'ed module; must be the only such test in the process — see the module docs"] +async fn the_module_advertises_exactly_the_mandatory_families() { + let workspace = tempfile::tempdir().expect("tempdir"); + let (client, _host, _task) = admit_module(workspace.path()).await; + + let capabilities: Capabilities = proxy(&client) + .call("Capabilities", ()) + .await + .expect("Capabilities"); + + // The adapter deliberately advertises only what it can reach. Advertising + // more would make `audit_provider` fail host-side, and would register RPC + // methods that answer errors. + for mandatory in Capability::MANDATORY { + assert!( + capabilities.contains(mandatory), + "{mandatory:?} must be advertised" + ); + } + assert!( + !capabilities.contains(Capability::Tree), + "the module must not claim an optional family it cannot serve" + ); + + let driver_id: String = proxy(&client).call("DriverId", ()).await.expect("DriverId"); + assert_eq!(driver_id, "tinycortex"); +} + +#[tokio::test] +#[ignore = "drives a real dlopen'ed module; must be the only such test in the process — see the module docs"] +async fn an_entry_stored_over_the_bus_is_read_back() { + let workspace = tempfile::tempdir().expect("tempdir"); + let (client, _host, _task) = admit_module(workspace.path()).await; + let bus = proxy(&client); + + bus.call::<()>( + "Store", + ( + "e2e", + "greeting", + "the cat sat on the mat", + MemoryCategory::Core, + Option::::None, + MemoryTaint::default(), + ), + ) + .await + .expect("Store"); + + let entry: Option = bus.call("Get", ("e2e", "greeting")).await.expect("Get"); + let entry = entry.expect("the entry was just stored"); + assert_eq!(entry.content, "the cat sat on the mat"); + + // Idempotent by contract: forgetting reports whether it existed, and a + // second forget is `false` rather than an error. + let forgotten: bool = bus + .call("Forget", ("e2e", "greeting")) + .await + .expect("Forget"); + assert!(forgotten); + let again: bool = bus + .call("Forget", ("e2e", "greeting")) + .await + .expect("Forget is idempotent"); + assert!(!again); +} + +#[tokio::test] +#[ignore = "drives a real dlopen'ed module; must be the only such test in the process — see the module docs"] +async fn a_missing_entry_is_none_and_not_an_error() { + // `get`'s contract: absence is `Ok(None)`. A host that received an error here + // would surface a failure for an ordinary cache miss. + let workspace = tempfile::tempdir().expect("tempdir"); + let (client, _host, _task) = admit_module(workspace.path()).await; + + let entry: Option = proxy(&client) + .call("Get", ("e2e", "never-written")) + .await + .expect("a miss is not an error"); + assert!(entry.is_none()); +} + +#[tokio::test] +#[ignore = "drives a real dlopen'ed module; must be the only such test in the process — see the module docs"] +async fn recall_reaches_the_host_embedder() { + // The load-bearing test, and it asserts the seam rather than the ranking. + // + // What this module is responsible for is that the engine inside it resolves + // its embedder to the bus and calls out to the host. Whether a given query + // then *ranks* a given entry above `min_relevance_score` is engine retrieval + // behaviour, tuned by chunking, the vector store and the relevance floor — + // none of which this port changes, and all of which would make this test fail + // for reasons unrelated to the boundary. `tinycortex` covers that. + // + // So the assertion is on the host embedder's call count. That can only be + // non-zero if the module built its store against `BusEmbeddingHost`, the + // engine asked it to embed, the request crossed the bus, and the reply passed + // the width check. + let workspace = tempfile::tempdir().expect("tempdir"); + let (client, _host, _task) = admit_module(workspace.path()).await; + let bus = proxy(&client); + + bus.call::<()>( + "Store", + ( + "e2e", + "fact", + "the deployment runs on port 7788", + MemoryCategory::Core, + Option::::None, + MemoryTaint::default(), + ), + ) + .await + .expect("Store"); + + // Must not error: a recall that reached the bus and got a bad-width reply + // would fail here, which is the negative half of the same property. + let _entries: Vec = bus + .call( + "Recall", + ( + "the deployment runs on port 7788", + 5_usize, + tinymemory_api::recall::OwnedRecallOpts::default(), + Option::::None, + ), + ) + .await + .expect("Recall must succeed, not merely return nothing"); + + assert!( + EMBED_CALLS.load(std::sync::atomic::Ordering::SeqCst) > 0, + "the engine inside the module never asked the host to embed, so its \ + embedder is not wired to the bus" + ); +} + +#[tokio::test] +#[ignore = "drives a real dlopen'ed module; must be the only such test in the process — see the module docs"] +async fn an_export_page_terminates_on_a_none_cursor() { + // An empty `records` vector is explicitly *not* a terminator — a driver may + // return an empty page while skipping a range — so a host must key on the + // cursor. This pins that the module reports it the same way. + let workspace = tempfile::tempdir().expect("tempdir"); + let (client, _host, _task) = admit_module(workspace.path()).await; + let bus = proxy(&client); + + bus.call::<()>( + "Store", + ( + "e2e", + "exported", + "content worth keeping", + MemoryCategory::Core, + Option::::None, + MemoryTaint::default(), + ), + ) + .await + .expect("Store"); + + let mut cursor: Option = None; + let mut seen = 0_usize; + // Bounded so a driver that never terminates fails the test instead of + // hanging it. + for _ in 0..32 { + let page: tinymemory_api::provider::types::ExportPage = bus + .call("ExportPage", (cursor.clone(), 16_usize)) + .await + .expect("ExportPage"); + seen += page.records.len(); + cursor = page.next_cursor.clone(); + if cursor.is_none() { + break; + } + } + assert!(cursor.is_none(), "the export never terminated"); + assert!(seen >= 1, "the stored entry should appear in the export"); +} + +#[tokio::test] +#[ignore = "drives a real dlopen'ed module; must be the only such test in the process — see the module docs"] +async fn a_rejected_request_comes_back_under_its_contract_name() { + // The error name is the contract, and the host reconstructs a `MemoryError` + // variant from it. This asserts a real refusal carries a name from the + // `tinymemory` table rather than a bare transport failure. + let workspace = tempfile::tempdir().expect("tempdir"); + let (client, _host, _task) = admit_module(workspace.path()).await; + + // A zero limit is the clearest driver-rejected input that needs no store + // state to provoke. + let outcome: Result = proxy(&client) + .call("ExportPage", (Option::::None, 0_usize)) + .await; + + if let Err(error) = outcome { + let name = error.wire_name(); + assert!( + name.starts_with("ai.tinyhumans.tinymemory.Error."), + "a refusal must be named from the contract table, got {name}" + ); + } + // A driver that accepts a zero limit is also legitimate — `limit` is a + // request, not a guarantee — so this test asserts the *shape* of a refusal + // when there is one rather than demanding one. +} + +#[tokio::test] +#[ignore = "drives a real dlopen'ed module; must be the only such test in the process — see the module docs"] +async fn the_module_matches_the_in_process_engine_for_the_same_input() { + // The port must not change behaviour. Store the same entry through the module + // and assert the read-back is byte-identical to what the entry went in as, + // which is the property a host depends on when it swaps an embedded driver + // for this one. + let workspace = tempfile::tempdir().expect("tempdir"); + let (client, _host, _task) = admit_module(workspace.path()).await; + let bus = proxy(&client); + + let content = + "unicode survives: \u{e9}\u{4e2d}\u{6587} \u{1f600} and \"quotes\" and \\slashes\\"; + bus.call::<()>( + "Store", + ( + "e2e", + "roundtrip", + content, + MemoryCategory::Custom("notes".to_string()), + Some("session-1".to_string()), + MemoryTaint::default(), + ), + ) + .await + .expect("Store"); + + let entry: Option = bus.call("Get", ("e2e", "roundtrip")).await.expect("Get"); + let entry = entry.expect("stored"); + assert_eq!( + entry.content, content, + "JSON transport must not alter content" + ); + + // The custom category's `custom:` wire prefix has to survive too: without it + // `Custom("core")` and `Core` would collide. + let listed: Vec = bus + .call( + "List", + ( + Some("e2e".to_string()), + Some(MemoryCategory::Custom("notes".to_string())), + Option::::None, + ), + ) + .await + .expect("List"); + assert!( + listed.iter().any(|found| found.key == "roundtrip"), + "a custom category must round-trip through the wire form" + ); +} + +/// Not `#[ignore]`d: it loads nothing and so is safe alongside the suite. +#[test] +fn the_declared_method_list_matches_the_served_interface() { + // The manifest's `methods` list is admission surface. If it drifts from the + // interface's dispatch table, a host can be refused a method the module + // actually serves — or worse, admitted for one it does not. + let arc: Arc<()> = Arc::new(()); + drop(arc); + + // The service type is private, so this asserts the constant surface the + // manifest is written against instead. + assert_eq!(BUS_NAME, "ai.tinyhumans.tinymemory.Memory"); + assert_eq!(OBJECT_PATH, "/ai/tinyhumans/tinymemory/Memory"); + assert_eq!(MEMORY_INTERFACE, BUS_NAME); +} diff --git a/docs/specs/tinybus-module.md b/docs/specs/tinybus-module.md new file mode 100644 index 0000000..68a3544 --- /dev/null +++ b/docs/specs/tinybus-module.md @@ -0,0 +1,264 @@ +# The TinyMemory TinyBus module + +`crates/tinymemory-module` is a `cdylib` speaking the TinyBus module ABI. A host +loads it and gets a bound memory driver without compiling the engine. + +## What it buys, and what it does not + +**It sheds no dependencies.** This is measured, not assumed, and it is stated +first because the obvious motivation for a module port is dependency reduction +and here that motivation does not hold. + +Cutting the whole memory-engine cohort (`tinycortex`, `tinycortex-api`, +`tinymemory-core`, `tinymemory-tinycortex`) from OpenHuman, via +`scripts/dep-sim.py`: + +| Profile | Before | After | Delta | +| --- | --- | --- | --- | +| kernel (`flows`) | 307 pkg / 284 names / 2 native | 297 / 278 / 2 | −6 names, **0 native** | +| product (ships) | 431 / 398 / 5 native | 427 / 394 / 5 | −4 names, **0 native** | + +All four names leaving the shipping profile are first-party. `libsqlite3-sys` +does not leave, because `rusqlite` has five parents there — the host crate +directly, plus `tinyagents` (its session store), `tinychannels` and `tinyflows`. +Everything else the engine uses (`reqwest`, `chrono`, `regex`, `uuid`, +`walkdir`, `sha2`, `tokio`, `git2`) is shared with surface the host keeps. + +**What it does buy is compile time on the critical path.** `cargo build +--timings` on the host shows a strictly serial chain, each link starting as the +previous one ends: + +``` +tinyagents 12.8 -> 25.4 (12.6s) +tinycortex 25.4 -> 35.1 ( 9.7s) +tinymemory-core 35.1 -> 40.1 ( 5.0s) +host crate 40.1 -> 174.7 +wall 176.0s +``` + +The engine therefore puts **14.7s directly in front of** the host's own +compilation. Removing it from the host's graph moves a full build to roughly +161s, about 8.4%. + +Do not re-justify this module on dependency count. + +## The interface + +One object, `/ai/tinyhumans/tinymemory/Memory`, interface +`ai.tinyhumans.tinymemory.Memory`: + +```text +DriverId() -> String +Capabilities() -> Capabilities +Health() -> MemoryHealth +Shutdown() -> () + +Store(namespace, key, content, category, session_id, taint) -> () +Get(namespace, key) -> Option +Forget(namespace, key) -> bool +List(namespace, category, session_id) -> [MemoryEntry] +Namespaces() -> [NamespaceSummary] +Recall(query, limit, opts, scope) -> [MemoryEntry] +ExportPage(cursor, limit) -> ExportPage +ImportRecords(records) -> ImportOutcome +``` + +These are `tinymemory_api`'s `MemoryProvider` and its three mandatory +supertraits, one method per method, borrows replaced by owned equivalents. The +host binds an `Arc`, so a client that forwards each method +one-for-one **is** a complete provider with no translation layer. Nothing +cleverer is offered on purpose: batching or combined calls would put engine +semantics on the wire where two sides could disagree about them. + +**No new types were needed.** Every value crossing is already `Serialize` + +`Deserialize` in `tinymemory-api` — including `MemoryCategory` (a string with a +`custom:` prefix) and `Capabilities` (a JSON array of family names), both of +which carry hand-written impls. This is why there is no `wire` *type* module +here, unlike the tinywallet module. + +### Only the mandatory three + +`tinymemory-tinycortex` advertises Core, Recall and Portability, because the ten +optional families are reached through engine entry points needing a host's +configuration, embedding compute and job queue. This module serves exactly that. +Serving more would advertise capabilities whose accessors return nothing, which +`audit_provider` exists to catch, and would make the host register RPC methods +that answer errors. + +### Everything travels inline + +A TinyBus frame is JSON capped at 16 MiB. For a generated document that is a real +constraint — a byte array costs ~3.5 bytes per byte — and here it is not: memory +entries are text, ~1.1× as JSON. So there is no blob store, no chunking and no +held output. The tinydocs module's whole staging apparatus is absent. + +`ExportPage` is the only unbounded method and is already paged by contract with +the caller choosing the size. Asking for a million records in one page gets a +frame-size error, which is the correct answer. + +## Errors + +`tinymemory_api::wire` holds the name table, and **both ends use it**. One name +per `MemoryError` variant, not one per outcome class: + +- the host is itself a `MemoryProvider` to everything above it, so it must hand + its own callers a real variant. Collapsing and guessing would turn a + `NotFound` into an `Invalid`, and `get`'s contract makes a miss `Ok(None)` + while an `Invalid` is a failure — the guess is observable. +- `PathEscape` reports a sandbox escape and is not interchangeable with a + malformed argument. + +An unrecognised name maps to `Other`, never `Invalid`: a driver newer than the +host may name something the table lacks, and telling a caller its input was wrong +when it was not sends it into a rewrite loop. `Io` and `Serde` degrade to `Other` +because neither foreign error can be rebuilt from a string; that is pinned rather +than papered over. + +## Embeddings stay in the host + +The engine cannot recall without embedding, and embedding needs an inference +credential. The credential stays host-side; the module asks the host to embed. + +The host serves `ai.tinyhumans.tinymemory.EmbeddingHost` at +`/ai/tinyhumans/tinymemory/EmbeddingHost`: + +```text +Embed(model: String, dimensions: usize, texts: [String]) -> [[f32]] +``` + +The module implements `tinymemory_api::host::EmbeddingHost` over that call and +installs it with `set_embedding_host` **before** constructing the store — the +engine resolves its embedder through a process-global during construction, and a +store built first would bind the inert zero-dimension provider and write vectors +nobody can search. + +This is the same split the tinywallet module makes with a signing key, and the +reasoning transfers: a credential is not the only thing that would have crossed. +The host's provider routing, rate limiting, cost accounting and BYOK policy all +hang off where embedding happens. + +`resolve_api_key` returns `None` unconditionally. + +### Two refusals that matter + +The provider checks the reply before handing vectors to the engine: + +- **wrong width** — vectors of a different dimensionality than the space they are + being written into. Accepting them splits one embedding space in two, and + nothing fails at the time; every vector on the wrong side becomes unsearchable + without a re-embed. +- **wrong count** — callers pair inputs to outputs positionally, so a short reply + attaches the wrong vector to the wrong chunk. + +A zero-dimension provider is exempt: that is the engine's "semantic search off" +state and is expected to return empty vectors. + +### The synchronous getters carry data + +`EmbeddingHost` is synchronous except for the embed itself, and its getters are +called from deep inside retrieval and sealing call stacks where nothing can +`await`. So `ollama_base_url`, `default_cloud_embedding_model` and the +dimension-support list are passed as configuration at load time. Only `embed` +touches the bus. + +### The embedder is declared in neither `requires` nor `optional` + +`requires` resolves against already-loaded **modules**. This dependency is served +by the *host*, so declaring it would leave the module permanently unresolved. It +is dialled lazily on the first embed, and a host that never served it gets a +named error rather than a module that never starts. + +## Configuration, and the credential that had to be stripped + +Config is JSON supplied by the host (`ModuleHost::set_config` / +`load_file_with_config`). `ModuleConfig` embeds +`tinymemory_api::host::MemoryConfig` verbatim, so a field added upstream reaches +the engine without an edit and cannot drift from the host's copy. + +`workspace_dir` is the only required field. Everything else has a defensible +default; a missing workspace does not, and is refused rather than silently +resolved against the process working directory. + +**`MemoryConfig` contains `agentmemory_secret`, a bearer token.** So "this +struct has no credential field" was true of `ModuleConfig`'s own keys and still +not sufficient — the token is one level down, carried verbatim along with +everything else. `strip_host_credentials` removes it at setup, before anything +else touches the config, and logs a warning. + +It is stripped rather than refused because this module serves the local engine +and cannot use a remote-backend token; failing the whole load would turn an +irrelevant leftover config field into a hard failure for a host whose memory +would otherwise work. A host that genuinely wants a remote memory backend should +bind that driver directly. + +The general lesson: **"carried verbatim" carries credentials verbatim too.** + +## Two operational constraints + +**Two worker threads, not one.** A recall that triggers an embed makes an +outbound call while still inside its own inbound call. One worker deadlocks on +the first semantic query. + +**Eager init, not lazy.** Bringing up a store opens a database and may run +migrations. Charging that to whichever call happens to arrive first would make an +ordinary recall time out on a cold start. + +## Building and testing + +The crate is **its own workspace root**, and this is not cosmetic. It depends on +`vendor/tinybus/crates/tinybus`, whose manifest inherits `edition`/`version` from +`vendor/tinybus`'s own `[workspace.package]`. As a member of the tinymemory +workspace, cargo resolves that inheritance against the *tinymemory* root and +fails with `workspace.package.edition was not defined`. `exclude` does not help: +it governs membership, not the root cargo picks for a dependency's inherited +fields. Verified by defining `[workspace.package]` at the tinymemory root +temporarily, which moved the error from `edition` to `version` rather than fixing +it. It also matches tinybus's own guidance that integrations are never workspace +members, and a separately released artifact wants its own lockfile. + +```sh +cargo fmt --manifest-path crates/tinymemory-module/Cargo.toml --all -- --check +cargo clippy --manifest-path crates/tinymemory-module/Cargo.toml --all-targets -- -D warnings +cargo build --manifest-path crates/tinymemory-module/Cargo.toml --release +cargo test --manifest-path crates/tinymemory-module/Cargo.toml --lib +``` + +The root workspace's `--workspace --all-targets` does **not** reach this crate, +so CI gives it its own `module` job. A cdylib that fails to build is a release +that cannot be cut, and without that job it would surface at release time rather +than on the PR that broke it. + +### The loader E2E must run one test per process + +```sh +TINYMEMORY_TEST_MODULE=$PWD/crates/tinymemory-module/target/release/libtinymemory_module.so \ + cargo test --manifest-path crates/tinymemory-module/Cargo.toml \ + --test module_e2e -- --ignored --exact +``` + +`--ignored` alone runs them all in one process and the second **hangs**. +`Broker::spawn` binds its tasks to the runtime that created them, `#[tokio::test]` +builds a fresh runtime per test, and the module is loaded once per process and +never unloaded — so the second test finds a broker whose tasks died with the +first runtime and waits for a deadline instead of failing. Every such test is +`#[ignore]`d for that reason, not for flakiness. CI loops over them one at a time +under `timeout`. + +`recall_reaches_the_host_embedder` asserts the host embedder's **call count** +rather than a ranking. Whether a query ranks an entry above +`min_relevance_score` is engine retrieval behaviour — chunking, vector store, +relevance floor — which this port does not change and which would fail the test +for unrelated reasons. A non-zero count can only happen if the module built its +store against the bus embedder, the engine asked it to embed, the request crossed +the bus, and the reply passed the width check. Note also that the module's +`log::debug!` output is invisible to the test process: a cdylib has its own +uninitialized `log` instance, so absence of a log line proves nothing. + +## Trust + +A loaded module is trusted in-process native code with the host's full +privileges, and TinyBus never unloads a library — replacing an artifact needs a +restart. The ABI, manifest and SHA-256 gates decide what is *admitted*, never +what is *safe*. The credential split above is a refusal to widen a boundary that +already exists, not an isolation claim: a hostile module could read the host's +keys out of process memory regardless. diff --git a/src/registry/class.rs b/src/registry/class.rs index 81f14b2..32ac1a2 100644 --- a/src/registry/class.rs +++ b/src/registry/class.rs @@ -54,6 +54,24 @@ pub enum DriverClass { /// An out-of-process backend reached through a transport adapter over a /// documented wire contract. External, + /// A loadable native module: a `cdylib` admitted through a module host's + /// ABI, manifest and digest gates and reached over an in-process bus. + /// + /// Distinct from both neighbours, and the distinction decides host policy: + /// + /// - not [`Self::Embedded`], because the code is **not compiled into the + /// host binary**. Whether it is present is a runtime fact, so a capability + /// set derived from it can be empty on a platform no artifact targets. + /// - not [`Self::External`], because there is **no egress and no process + /// boundary**. It shares the host's address space, privileges and crash + /// domain, so endpoint allowlisting and credential scoping are neither + /// applicable nor sufficient — what protects the host is admission, not + /// isolation. + /// + /// A host must therefore not apply egress redaction to a module driver (the + /// content is not leaving the device) and must not treat it as a + /// compile-time guarantee either. + Module, /// A stub advertising zero optional capabilities — what a compiled-out or /// unconfigured memory subsystem binds to. Null, @@ -61,9 +79,10 @@ pub enum DriverClass { impl DriverClass { /// Every class, in declaration order. - pub const ALL: [DriverClass; 3] = [ + pub const ALL: [DriverClass; 4] = [ DriverClass::Embedded, DriverClass::External, + DriverClass::Module, DriverClass::Null, ]; @@ -73,6 +92,7 @@ impl DriverClass { match self { Self::Embedded => "embedded", Self::External => "external", + Self::Module => "module", Self::Null => "null", } } diff --git a/vendor/tinybus b/vendor/tinybus index ddc63e3..6ca0b0b 160000 --- a/vendor/tinybus +++ b/vendor/tinybus @@ -1 +1 @@ -Subproject commit ddc63e3f9c6e99e0be4ef0effac4d35442711cc4 +Subproject commit 6ca0b0b6739a49396e36be21d450f07cf85b9de2