6. @fleetmesh/grasp#
@fleetmesh/grasp implements client-side GRASP (Git Repositories Hosted on Nostr Relays) functionality in TypeScript: local repositories with branches, commits, and merges; NIP-34 kind 30617 repository announcements; Bao roots over repository trees; and native Git blob, tree, and commit object identifiers. It is the browser counterpart to fleetmesh_protocols.grasp (GRASP Git Hosting (fleetmesh_protocols.grasp)) and enforces identical path, branch, and integrity validation rules prior to recording local commits.
6.1. Installation#
npm install @fleetmesh/grasp@next
Runtime dependencies are @fleetmesh/textile and @noble/hashes.
6.2. Repositories#
graspCodeRepoStore persists user repositories locally in the browser and synchronizes mutations to the host through the configured adapter:
Function |
Description |
|---|---|
|
Creates a repository owned by the active viewer with an initial commit containing either supplied files or a default README and entry point. |
|
Commits a single file modification onto the target branch. |
|
Merges |
|
Applies owner-editable metadata updates restricted strictly to |
|
Retrieves persisted repositories or resolves the repository associated with a target identifier. |
|
Serializes user repositories into a portable Textile shard and restores repositories from an imported shard. |
Each commit computes native Git object identifiers (gitTreeId and gitCommitId via gitObjects) alongside the Bao root of the tree (computeRepoBao), ensuring identical trees produce identical hashes across the browser client, host git binaries, and fleetmesh_protocols.grasp.
6.3. Validation and Trust Rules#
Client-side validation mirrors the host git_store rules (repo_path and branch_name):
Path validation (
graspRepoPath): Rejects paths targeting.git(case-insensitively, includinggit~1), traversing above the working tree, or containing empty,., or..segments (refusal codeinvalid_path).Branch validation (
graspBranchName): Rejects branch names thatgitmay parse as options or disallow: names beginning with-, containing.., ending with.lockor., or exceeding 200 characters (refusal codeinvalid_branch).Trust boundaries (
graspRepoTrust): Ownership and integrity fields are never accepted from untrusted client payloads. Existing repositories retain their original owner, seeded repositories are immutable, and repository roots are always recomputed from file contents rather than trusted from claims (editablePatch,repoFromShard).
6.4. Host Adapter#
configureGraspHost registers getViewerIdentity, syncRepoToServer, syncMetadataToServer, setAssetPrivacyRungOverride, jsonAuthHeaders, and gitBaseUrl. gitBaseUrl specifies the host base URL serving /git/ (for example, https://host). graspCloneUrl(slug) constructs clone URLs under gitBaseUrl and returns '' when gitBaseUrl is unset, avoiding fabricated clone URLs. If server synchronization callbacks are unconfigured, repositories remain local to the browser and a single warning is logged.
6.5. Modules#
Module |
Contents |
|---|---|
|
Client-side repository store and commit/merge operations. |
|
|
|
Seeded repository specifications ( |
|
Native Git object hashing and formatting: |
|
Path, branch, ownership, and integrity validation functions. |
|
|