Skip to content

Trust Graph monorepo: pure Rust core with CLI, WebAssembly and Node wrappers - #15

Merged
harlantwood merged 7 commits into
masterfrom
claude/trustcraft-cli-modernize-bsuvj4
Oct 7, 2026
Merged

harlantwood merged 7 commits into
masterfrom
claude/trustcraft-cli-modernize-bsuvj4

Conversation

@harlantwood

@harlantwood harlantwood commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Summary

This makes the repo the Trust Graph monorepo: Rust first, TypeScript where it fits. Inside it is one pure Rust core with three thin wrappers, so Convex is just another caller. Full write-up: doc/architecture.md.

crates/                 Cargo workspace (crates/*)
├── trustgraph-core     pure Rust: no I/O, no async runtime, data in → data out
├── trustgraph-cli      `trust` binary
├── trustgraph-wasm     @trustgraph/trustgraph-wasm (wasm-bindgen): browsers, Workers, Deno, Convex queries
└── trustgraph-node     @trustgraph/trustgraph (napi-rs): Node and Convex Node actions
packages/               pnpm workspace (packages/*), for TypeScript projects as they arrive
bindings/               TypeScript types shared by both npm packages

Monorepo

  • Cargo workspace: crates/*, so new crates join automatically.
  • pnpm workspace: crates/trustgraph-node plus packages/*.
    • One pnpm-lock.yaml, and packageManager: pnpm@12.9.1.
    • Root scripts: build:node, test:node, typecheck.
  • Node versions:
    • Development and CI use the latest LTS: .nvmrc is lts/*, which is Node 24 today.
    • Published packages support Node ≥ 22. CI also smoke-tests on Node 22.
  • Language policy: protocol logic lives only in trustgraph-core. TypeScript calls the core through the WebAssembly or native package. It never re-implements signing, IDs or scoring.
  • README: now the monorepo front page. It covers what's in the repo and where new crates and packages go.

The core never does I/O

  • Renamed: trustgraph → trustgraph-core, trust-cli → trustgraph-cli. The binary is still trust.
  • Callers pass in timestamps and data. The file-backed Store lives in the CLI. Record and Query stay in the core.
  • Randomness is optional: the random cargo feature is off by default and on in all three wrappers.
    • It adds Keypair::generate and generateKeypair(). They use the OS random number generator, or crypto.getRandomValues in WebAssembly.
    • keypairFromSeed still works.
    • generateKeypair is the one non-deterministic function. Call it in a client or action, not inside a reactive query.
  • scripts/check-core-purity.sh fails CI if any of these happen:
    • the core's source does I/O outside the feature-gated src/random.rs;
    • that module loses its gate;
    • the default dependencies gain getrandom, rand, tokio, libc or an HTTP client.
  • CI also lints the core alone with default features.
  • Deterministic otherwise, signatures included.

One API, three wrappers

  • trustgraph_core::api is a JSON-shaped API with camelCase names: generateKeypair, keypairFromSeed, parseAtom, atomId, canonicalAtom, toCredential, signAtom, verify, lens, rollup.
    • Every wrapper exposes exactly these, and the CLI calls them too.
  • trustgraph-wasm has two builds, both made by scripts/build-wasm-package.sh:
    • web/: initialized from the .wasm bytes with initSync, no fetch.
    • node/: for Node.
  • trustgraph-node uses napi-rs with one package per platform, the same pattern as @resvg/resvg-js.
  • Shared TypeScript types are in bindings/trustgraph.d.ts, checked with tsc --strict.
  • One smoke test, tests/js/smoke.mjs, runs against the native addon and both WebAssembly builds.

CI

  • Jobs:
    • lint and purity
    • tests on Linux, macOS and Windows
    • MSRV (1.85)
    • the WebAssembly package: build, smoke tests, tsc, benchmark, and a 1 MiB size budget
    • the native addon on all three OSes, plus Node 22
  • actions/checkout v7. This supersedes Dependabot #13.
  • Dependabot now ignores dtolnay/rust-toolchain. Its ref is the Rust version under test, which Dependabot misread in #14. Dependabot still covers cargo and npm/pnpm.

Removed

  • Holochain support: the link-tag codec, Value::to_holochain_string, and trust convert --to holochain.

Performance (Node 24 LTS, Linux x86-64)

WebAssembly Native
Size 540 KiB (226 KiB gzipped) 1.2 MB (Linux x64)
Module load 4.5 ms 2.7 ms
lens, 10k atoms 51 ms 35 ms
lens, 100k atoms 0.54 s 0.43 s
  • lens is about 2× faster than on master. It computes each agent's edges once and skips content IDs it doesn't need.
  • 100k atoms fits well under Convex's 1 s query limit. Bigger graphs should use rollups precomputed natively or by the CLI.

Still open

  1. Public or private npm: Convex's externalPackages installs from npm at deploy time.
  2. A real Convex deployment spike: the numbers above come from Node, not Convex.

Test plan

  • cargo test --workspace on Rust 1.99 and 1.85 (random on): 64 core unit, 7 property, 3 doctests, 8 CLI unit, 12 CLI end-to-end
  • cargo test -p trustgraph-core with default features (no randomness): 61 unit tests
  • cargo clippy -D warnings (workspace, core alone, and wasm32-unknown-unknown); cargo doc -D warnings; cargo fmt --check
  • scripts/check-core-purity.sh passes. It also fails on a planted std::fs call or a removed feature gate.
  • JS smoke test (including generateKeypair) passes on Node 24 against all three builds, and on Node 22 against the native addon
  • pnpm install --frozen-lockfile, pnpm run build:node, pnpm run test:node, pnpm run typecheck
  • CI green on the latest commit (6b29a20): all 9 jobs

Merge this before #12 (the roadmap), which links to doc/architecture.md.


History: this started as the CoreNexus architecture pass (a pure core with wrappers). At your request it grew to cover the monorepo setup, pnpm, the latest Node LTS, removing Holochain and opt-in randomness. Before merging, it also absorbed the two pending Dependabot CI updates.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UdKneRqUnsbv1t7NyvcT68

Adopt the "one Rust core, thin wrappers" architecture: the core never
does I/O, and each wrapper handles input and output for its host.

- Rename crates: trustgraph -> trustgraph-core, trust-cli ->
  trustgraph-cli (binary still `trust`).
- Make the core pure: drop Keypair::generate and the random Holochain
  bucket (callers pass seeds/bytes), move the file-backed Store to the
  CLI, and drop getrandom and std::io errors. Record/Query stay in core.
- Add trustgraph_core::api, a JSON-shaped API (camelCase) that every
  wrapper exposes one-to-one; the CLI's verify/convert now use it.
- Add trustgraph-wasm (wasm-bindgen; @trustgraph/trustgraph-wasm) with
  web and Node builds, and trustgraph-node (napi-rs;
  @trustgraph/trustgraph) with napi's per-platform package layout.
- Shared TypeScript types (bindings/trustgraph.d.ts), one JS smoke test
  run against the native addon and both wasm builds, and a benchmark.
- Speed up lens ~2x: compute each agent's edges once, and skip content
  IDs when building the graph. 100k atoms: 0.78 s in wasm, 0.48 s native.
- scripts/check-core-purity.sh fails CI if the core gains I/O in source
  or dependencies; wasm size budget of 1 MiB (now 547 KiB, 229 KiB gz).
- CI: purity check, wasm package job (clippy for wasm32, build, smoke
  tests, tsc, benchmark), native addon job on Linux/macOS/Windows.
- doc/architecture.md; README updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UdKneRqUnsbv1t7NyvcT68
harlantwood pushed a commit that referenced this pull request Oct 6, 2026
Reflect PR #15 (pure trustgraph-core with CLI, WebAssembly and Node
wrappers): add it to what has shipped, make 'one pure core, thin
wrappers' the first principle, fold 'Embed everywhere' into a new
'Release and publish' phase (npm per-platform packages, wasm package,
Convex spike), and add the package-name and public/private npm decisions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UdKneRqUnsbv1t7NyvcT68
@harlantwood harlantwood mentioned this pull request Oct 6, 2026
1 task done
Treat this repository as the home of every Trust Graph project: Rust
first, TypeScript where it fits.

- Cargo workspace members are now `crates/*`, so new crates join
  automatically.
- Add a root npm workspace (`crates/trustgraph-node`, `packages/*`) with
  one root lockfile and `build:node`, `test:node` and `typecheck` scripts;
  TypeScript is pinned as a dev dependency instead of fetched by npx.
- CI and Dependabot run npm from the root.
- README is now the monorepo front page: what's in the repo, where new
  Rust crates and TypeScript packages go, and the language policy
  (protocol logic only in trustgraph-core; TypeScript calls it through
  the WebAssembly or native package, never re-implements it).
- doc/architecture.md gains a "monorepo, Rust first" section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UdKneRqUnsbv1t7NyvcT68
@harlantwood harlantwood changed the title Pure Rust core with CLI, WebAssembly and Node wrappers Trust Graph monorepo: pure Rust core with CLI, WebAssembly and Node wrappers Oct 6, 2026
claude added 5 commits October 6, 2026 21:28
Replace the npm workspace with pnpm: pnpm-workspace.yaml (the Node
binding crate plus packages/*), pnpm-lock.yaml instead of
package-lock.json, and `packageManager: pnpm@12.9.1` so local and CI
use the same version. CI installs with pnpm/action-setup and
`pnpm install --frozen-lockfile`; docs use pnpm commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UdKneRqUnsbv1t7NyvcT68
- .nvmrc pins `lts/*` (Node 24 today); CI's setup-node reads it, so CI
  moves to each new LTS when it is promoted.
- The root package.json asks for Node >= 24 for development.
- The published packages declare Node >= 22, the oldest line still
  maintained (Node 20 reached end of life in April 2026); CI runs the
  smoke test on Node 22 to keep that promise.
- Re-ran the benchmark on Node 24 and updated doc/architecture.md:
  lens on 100k atoms is now 0.54 s in WebAssembly, 0.43 s native.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UdKneRqUnsbv1t7NyvcT68
Drop the Holochain link-tag codec and everything built on it: the
`holochain` module and `Value::to_holochain_string` in the core,
`InvalidLinkTag`, `api::holochain_tags`, the `holochainTags` and
`bucketFromBytes` bindings and their TypeScript types, and
`trust convert --to holochain --bucket`. Tests and docs updated; the
WebAssembly build shrinks to 538 KiB (225 KiB gzipped).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UdKneRqUnsbv1t7NyvcT68
Add a `random` cargo feature to trustgraph-core (off by default, on in
the CLI, WebAssembly and Node wrappers) that provides Keypair::generate
and api::generate_keypair, backed by getrandom: the OS RNG natively,
crypto.getRandomValues in WebAssembly (getrandom's wasm_js feature).

- New `generateKeypair()` in both npm packages and the TypeScript types;
  keypairFromSeed still works for callers who bring their own seed.
- The CLI uses Keypair::generate and drops its own random module.
- The purity check exempts only the feature-gated src/random.rs and
  verifies the gate; the default dependency tree still has no getrandom.
  CI also lints the core alone with default features.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UdKneRqUnsbv1t7NyvcT68
Supersedes Dependabot PRs #13 (checkout v5 -> v7) and #14, which would
have changed the MSRV job's dtolnay/rust-toolchain@1.85 to @1.120: that
ref is the Rust version under test, not an action version, so it is now
ignored in dependabot.yml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UdKneRqUnsbv1t7NyvcT68
@harlantwood
harlantwood merged commit 8a58704 into master Oct 7, 2026
9 checks passed
harlantwood pushed a commit that referenced this pull request Oct 7, 2026
…drafts

Update the TL;DR, shipped table and Phase 0 for PR #15 (merged): monorepo
layout, optional randomness, CI. Carry forward three ideas from the
2022-23 drafts #9 and #10: Reputon export (Phase 1), IPFS publishing
(Phase 3), and lens value filters plus a per-hop falloff view (Phase 4).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UdKneRqUnsbv1t7NyvcT68
harlantwood added a commit that referenced this pull request Oct 8, 2026
## Summary

Adds `doc/plan/README.md`, the roadmap for the **Trust Graph monorepo**:
the Rust core, the `trust` CLI, the WebAssembly and Node packages built
on the core, and every future Trust Graph project.

**Start with the TL;DR at the top.** It covers:
- **What's shipped:**
- [#11](#11): the
CLI and protocol library
- [#15](#15): the
monorepo layout, a pure core with CLI, WebAssembly and Node wrappers,
optional randomness, and CI
- **Next phases:**
- 0: Finish the monorepo. Bring in the protocol docs and the JSON-LD
schema, archive the old repos, and rename this repo to
`trustgraph/trustgraph`.
  - 1: Lock the v1 data format, and add Reputon export.
- 2: Release and publish: npm, crates, cargo-dist, and a real Convex
spike.
  - 3: Share over HTTPS, with IPFS as the next transport.
  - 4: UX, including lens value filters and an `--explain` view.
  - 5: Harden.
- **Decisions for you:**
  - value range
  - JSON-LD context domain
  - package names
  - public or private npm
  - the existing `trustgraph/trustgraph` repo

The rest of the doc covers:
- design principles
- a status table
- each phase, with acceptance criteria
- an open-decisions table
- the 2022 TODO list, mapped to what's done

It also picks up three ideas from the early drafts
[#9](#9) and
[#10](#10).

Docs only. `master` is merged in, so the links to `doc/architecture.md`
resolve. Merging this also makes the README's roadmap link work.

## Test plan
- [x] Docs only; I checked links and anchors by hand

---

**History:** this started as the first roadmap for the Rust CLI. It was
revised as
[#11](#11) and
[#15](#15)
shipped. At your request I removed Trustcraft and Holochain, and the
roadmap now reflects everything merged so far.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01UdKneRqUnsbv1t7NyvcT68

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants