SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

quickstart-chat issues with Claude Code

Open capncleaver opened this issue 9 months ago • 2 comments

Ahoy! Very interesting tool, excited to try it out Claude Code and I tried to install the quickstart-chat app, vanilla.

It was fiddly business, we got there in the end (took ~one instance worth of context.) Here's CC's writeup, I hope this is useful.

In particular I noticed the version depenency was wrong for the rust-client (first attempt, aborted) and I think the quickstart-chat. Given that quickstart-chat is a rust client, the presence of both is confusing but quickstart seems the more recent.

Getting SpacetimeDB Quickstart-Chat Working: The Ideal Path

Here's a summary of the steps needed to get the SpacetimeDB quickstart-chat example working, following the most direct path:

1. Setting up the proper Rust environment

# Install Rust with rustup (not Homebrew) to ensure proper WebAssembly support
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.84.0 --profile default --target wasm32-unknown-unknown

# Add WebAssembly target support
rustup target add wasm32-unknown-unknown

2. Installing and running SpacetimeDB

# Install SpacetimeDB CLI
curl -sSf https://install.spacetimedb.com | sh

# Add SpacetimeDB to PATH
export PATH="$HOME/.local/bin:$PATH"

# Start SpacetimeDB in the background
spacetime start > /tmp/spacetime.log 2>&1 &

3. Publishing the module

# Navigate to the quickstart-chat module directory
cd modules/quickstart-chat

# Build and publish the module
spacetime publish --server http://127.0.0.1:3000 --anonymous chat-demo

4. Building and running the client

# Create a directory for the client
mkdir -p quickstart-chat-client/src

# Copy the module bindings
cp -R modules/quickstart-chat/module_bindings quickstart-chat-client/src/

# Create Cargo.toml with proper dependencies
cat > quickstart-chat-client/Cargo.toml << EOF
[package]
name = "quickstart-chat-client"
version = "0.1.0"
edition = "2021"

[dependencies]
spacetimedb-sdk = "1.0.1"
EOF

# Create main.rs with the client code, using the correct module name
# (Key point: The with_token handling should be optional for first-time users)

# Build and run the client
cd quickstart-chat-client
cargo run

Feedback for SpacetimeDB developers

  1. Rust installation instructions: The documentation should emphasize that rustup (not Homebrew Rust) is required for proper WebAssembly support, with specific instructions for the target.

  2. Client authentication handling: The example should better handle first-time connections without credentials. Currently, it uses .expect() which causes errors for new users.

  3. Module ownership and permissions: We encountered several permission errors when trying to republish or update modules. A clearer ownership model or easier way to manage modules for development would be helpful.

  4. Non-interactive client options: The example could benefit from a non-interactive mode for testing, as interactive terminal input can be challenging in some environments.

  5. Better error messages: When the server isn't running, the client error messages could be more clear about connection issues.

  6. Documentation for common operations: More examples for common tasks like listing databases, checking status, deleting, and updating modules would be helpful.

  7. WebAssembly optimization warnings: The warning about missing wasm-opt is confusing for beginners. Either include it or make the warning less prominent.

  8. Consistent API across language SDKs: Ensure authentication and connection patterns are consistent across different SDKs.

  9. Offline development mode: A simpler local development experience that doesn't require authentication would help developers get started more quickly.

capncleaver avatar Apr 02 '25 04:04 capncleaver

I followed the instructions and got it working myself, np. Score one for team human!

I do think putting a quickstart guide for AI in the repo docs is a good idea for us game designer muppets who want to vibe our way to the next MMO (or have fun crashing against the context limit trying!) Rust and Spacetime look v promising for this as they are very simple and the code is tiny relative to js / ts twisty maze esp.

capncleaver avatar Apr 02 '25 22:04 capncleaver

Thanks for following up! I'm glad that the instructions were easy to follow for a human.

We do have plans to improve our AI-readability though!

We also created these issues:

  • https://github.com/clockworklabs/SpacetimeDB/issues/3083
  • https://github.com/clockworklabs/SpacetimeDB/issues/2545
  • https://github.com/clockworklabs/SpacetimeDB/issues/3081

Some folks from the dev team also had this to say about the expect piece:

Claude is wrong about the expect call in with_token. From the doc comment of spacetimedb_sdk::credentials::File::load:

Returns Err if I/O fails, None if credentials have not previously been stored, or Some if credentials are successfully loaded from disk. After unwrapping the Result, the returned Option can be passed to [super::DbConnectionBuilder::with_token].

Note that the return type of that method is Result<Option<String>, CredentialFileError>.

bfops avatar Apr 02 '25 23:04 bfops

It would be nice if the quickstart for typescript as rust was made into some code I could pull down ready to go. Preferably in docker compose.

chrisjd20 avatar May 16 '25 22:05 chrisjd20

@chrisjd20 A complete TypeScript quickstart client is here: https://github.com/clockworklabs/spacetimedb-typescript-sdk/tree/main/examples/quickstart-chat. Is that what you're looking for? (It's compatible with either a Rust or C# quickstart-chat server modules, but we don't have server-side support for TypeScript.. yet).

bfops avatar May 20 '25 21:05 bfops

@bfops thanks I didnt realize that existed. I managed to get it from build to run into a single docker compose as I was suggesting (server and client both built and running):

https://github.com/chrisjd20/spacetimedb-chat-quickstart-example

chrisjd20 avatar May 23 '25 18:05 chrisjd20