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

createGraspCodeRepo({ title, … })

Creates a repository owned by the active viewer with an initial commit containing either supplied files or a default README and entry point.

pushCommitToGraspRepo({ repoId, branch, filePath, content, message })

Commits a single file modification onto the target branch.

mergeBranchInGraspRepo({ repoId, sourceBranch, targetBranch })

Merges sourceBranch into targetBranch.

updateGraspCodeRepo(id, patch)

Applies owner-editable metadata updates restricted strictly to GRASP_EDITABLE_FIELDS (title, name, description, topics, metadata, visibility, privacy rung, and hidden status).

loadGraspCodeRepos(), getGraspRepoForTarget(id)

Retrieves persisted repositories or resolves the repository associated with a target identifier.

buildArcadeCodeShard(user), hydrateGraspCodeReposFromShard(repos)

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, including git~1), traversing above the working tree, or containing empty, ., or .. segments (refusal code invalid_path).

  • Branch validation (graspBranchName): Rejects branch names that git may parse as options or disallow: names beginning with -, containing .., ending with .lock or ., or exceeding 200 characters (refusal code invalid_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

graspCodeRepoStore

Client-side repository store and commit/merge operations.

graspRepoRecords

buildKind30617Event, makeRepoRecord, computeRepoBao, and buildSeededGraspRepos.

graspCodeRepoSeeds

Seeded repository specifications (SEEDED_REPO_SPECS) and default template files for library items and engines.

gitObjects

Native Git object hashing and formatting: gitTreeId, gitCommitId, gitIdentity, and cleanGitMessage.

graspNames, graspRepoTrust

Path, branch, ownership, and integrity validation functions.

hostAdapter

configureGraspHost, graspCloneUrl, and graspGitRoot.