cross.stream / docs
GitHub Discord

xs.nu

The xs.nu module provides Nushell-friendly wrappers around the core xs CLI commands, enabling seamless pipeline integration and environment-aware operations. See Topics for naming rules and wildcards.

All functions automatically use the $env.XS_ADDR environment variable when connecting to stores, supporting local paths, TCP addresses, and iroh peer-to-peer QUIC connections. See Exposing Streams reference for connection setup and remote access configuration.

Installation

Install the module into your Nushell configuration:

xs nu --install

Or use it directly in a session:

use xs.nu *

Stream Operations

.append

Append content to a topic. Wraps xs append.

.append <topic> [--meta <record>] [--ttl <ttl>] [--with-timestamp]
"My first note" | .append note
"Important note" | .append note --meta {priority: "high"}
"Timestamped note" | .append note --with-timestamp

.cat

Stream frames from the store. Wraps xs cat.

.cat [--follow (-f)] [--pulse (-p) <ms>] [--new (-n)] [--detail (-d)]
     [--with-timestamp] [--limit <n>] [--last <n>] [--after (-a) <id>]
     [--from <id>] [--topic (-T) <patterns>]

The flags are the read options; --topic accepts a topic pattern, a comma-separated list, or a Nushell list of strings. Two flags are Nushell-only: --detail (-d) includes all frame fields, and --with-timestamp returns the timestamp as a native datetime.

With --follow, a reader that falls behind the live stream gets an error (xs.lagged: fell behind the live stream: N frames skipped) in place of its last frame; see What a follow delivers. .last --follow does the same, as do the built-in .cat and .last inside actors, services and xs eval.

.cat --topic note
.cat -f --topic note    # Follow new notes
.cat --last 10          # Show last 10 events
.cat --limit 5          # Show first 5 events
.cat -f -p 1000         # Follow with 1s pulse heartbeat
.cat --detail           # Include all frame fields (e.g., ttl)
.cat --with-timestamp   # Include timestamp field

.last

Get the most recent frame(s) for a topic. Wraps xs last.

.last [topic] [count] [--follow] [--with-timestamp]

The arguments and flags are read options: topic is a topic filter (optional, defaults to all topics; accepts wildcards, a comma list, or a Nushell list), count is last (default: 1), --follow (-f) streams updates, and --with-timestamp returns the timestamp as a native datetime.

.last note              # last frame for topic "note"
.last                   # last frame across all topics
.last note 5            # last 5 frames for topic "note"
.last 10                # last 10 frames across all topics
.last "user.*"          # last frame matching wildcard
.last note --follow     # stream updates for topic "note"
.last --with-timestamp  # include timestamp field

.remove

Remove a frame by ID. Wraps xs remove.

.remove <id>
let note_id = (.last note).id
.remove $note_id

.get

Retrieve a frame by ID. Wraps xs get.

.get <id> [--with-timestamp]
let note_id = (.last note).id
.get $note_id
.get $note_id --with-timestamp  # include timestamp field

.eval

Evaluate a Nushell script with store helper commands available. Wraps xs eval.

.eval [file] [--commands (-c) <string>]
# Inline script with -c
.eval -c '.cat --topic note | length'

# Script file
.eval script.nu

# Pipeline input
".cat --topic note | length" | .eval

SCRU128 ID Operations

.id

Generate a new SCRU128 ID. Wraps xs scru128.

.id
let new_id = .id
# => "03d4q1qhbiv09ovtuhokw5yxv"

.id unpack

Unpack a SCRU128 ID into its component fields. Wraps xs scru128 unpack.

.id unpack [<id>]

The function accepts the ID as an argument or via pipeline input. The timestamp is converted to a native Nushell datetime type.

# Using argument
.id unpack "03d4q1qhbiv09ovtuhokw5yxv"

# Using pipeline
"03d4q1qhbiv09ovtuhokw5yxv" | .id unpack

# Using with generated ID
.id | .id unpack
# =>
# ╭────────────┬──────────╮
# │ timestamp  │ now      │
# │ counter_hi │ 1234     │
# │ counter_lo │ 5678     │
# │ node       │ abcd1234 │
# ╰────────────┴──────────╯

.id pack

Pack component fields into a SCRU128 ID. Wraps xs scru128 pack.

.id pack [<components>]

The function accepts a record as an argument or via pipeline input. Nushell datetime values are automatically converted to the required float timestamp format.

# Using argument
let components = {
  timestamp: (date now)
  counter_hi: 1234
  counter_lo: 5678
  node: "abcd1234"
}
.id pack $components

# Using pipeline (round-trip example)
.id | .id unpack | .id pack

The SCRU128 functions provide perfect round-trip compatibility while leveraging Nushell's native data types for timestamps.

Content Storage

.cas

Retrieve content from Content-Addressable Storage by hash. Wraps xs cas.

.cas <hash>
let note = .last note
.cas $note.hash  # Get the note content

Utilities

.cas-post

Store content in Content-Addressable Storage. Wraps xs cas-post.

.cas-post
"note content" | .cas-post  # Returns content hash

.import

Import frames from a backup directory. Wraps xs import.

.import <path>
.import ./notes-backup

.export

Export frames to a backup directory.

.export <path>
.export ./notes-backup

.tmp-spawn

Spawn a temporary xs serve instance, run a closure, then cleanup. Useful for testing and isolated operations.

.tmp-spawn <closure> [--interactive]

The function:

.tmp-spawn {
  "test note" | .append note
  assert (.last note).hash != null
  print "Test passed!"
}

# Start an interactive session after running the closure
.tmp-spawn --interactive {
  "setup note" | .append note
  print "Setup complete - dropping to interactive shell"
}

This is particularly useful for integration tests where you need a clean, isolated cross.stream environment. The --interactive flag is especially helpful for debugging and exploration, as it allows you to interact with the temporary environment after your setup code runs.

Key Advantages

The xs.nu functions provide several advantages over direct CLI usage:

Environment Variables

Many functions automatically use this environment variable when available: