Pear Platform

repository·main·Indexed 43 days ago

https://github.com/holepunchto/pear

A platform for platform development providing a runtime environment supporting macOS, Linux, and Windows. Version 3.5.0-rc.0 includes a CLI for managing project links, seeding data, staging local changes, and coordinating production releases via quorum-based multisig cosigning. It also features tools for managing blind peers, blind relays, and Distributed Hash Table (DHT) node information.

Tokens
13.5K
Snippets
61
Records
74
Agent score
55%

What's inside Pear

  1. Set up a local development environment for Pear

    main

    If you are contributing to Pear or developing for the platform, you can set up a local development environment (referred to as localdev) by cloning the repository, installing dependencies, and building the runtime binaries.

    Built artifacts are stored in out/make. To run the current checkout directly in localdev mode, use the ./pear.dev script (or . pear.ps1 / . pear.cmd on Windows).

    git clone https://github.com/holepunchto/pear && cd pear
    npm install
    npm run make
    ./pear.dev
  2. Install Pear via npx

    main

    You can install Pear onto your system using Node.js's npx command. After running the command, you must follow the specific instructions provided in the terminal output to set your PATH to ensure the pear command is available globally.

    npx pear
  3. Coordinate production releases with `pear multisig`

    main

    Pear multisig provides quorum-based cryptographic cosigning for production releases. It allows a group of keys to approve a release to be synchronized onto a production link.

    Workflow Overview

    1. Configure: Define the multisig field in your pear.json with publicKeys, namespace, and quorum.
    2. Get Keys: Use pear multisig keys get <name> to create local signing keypairs.
    3. Identify Link: Use pear multisig link to find your project's multisig link.
    4. Request: Use pear multisig request <verlink> to create a signing request for a specific versioned source link.
    5. Sign: Signers use pear multisig sign <request> <name> to provide their signature.
    6. Verify & Commit: Once enough signatures are gathered, use pear multisig verify followed by pear multisig commit to apply the signatures and allow the sync to the production link.

    Key Subcommands

    • keys: Manage signing keys (get, paths, list, add, remove).
    • link: Print the project's multisig link.
    • request: Create a signing request for a versioned source link.
    • sign: Sign a request using a local key.
    • verify: Perform a dry-run to verify the request and all collected responses.
    • commit: Apply signatures to go live.
    pear multisig keys get my-key
    pear multisig request pear://<fork>.<length>.<key>
    pear multisig sign <request-string> my-key
    pear multisig commit <source-link> <request-string> <response1> <response2>
  4. Handle missing `package.json` during staging

    main

    By default, pear stage expects to find a valid package.json file in the target directory.

    If no package.json is found:

    1. In non-interactive environments (e.g., CI/CD or --json mode): The command will throw an ERR_INVALID_PROJECT_DIR error.
    2. In interactive terminals: The command will prompt for confirmation. You must type STAGE (in uppercase) to confirm staging a folder without a package.json.

    To bypass this check automatically, use the --skip-package-json flag.

  5. Post-staging workflows

    main

    After successfully running pear stage, you can follow up with these commands depending on your goal:

    • To keep the staged version available:

      pear seed <link>
    • To provision for prerelease, stakeholder preview, QA, or dogfooding:

      pear touch
      # OR
      pear provision --dry-run <source-verlink> <target-link> <production-verlink>
  6. Get help with Pear commands

    main

    Pear provides built-in help documentation for its commands. You can view help information using the following syntax:

    • pear help <cmd>: Detailed help for a specific command.
    • pear <cmd> --help: Standard help flag for a command.
    • pear <cmd> -h: Short help flag for a command.
    pear help <cmd>
    pear <cmd> --help
    pear <cmd> -h
  7. Verify changes with a dry run using `pear provision`

    main

    To inspect what changes would be applied to a target without actually modifying it, use the --dry-run flag. This is the recommended workflow to ensure the diff looks correct before committing to a provision.

    pear provision <source-verlink> <target-link> <production-verlink> --dry-run

    After a successful dry run, if the diff is satisfactory, run the command again without the --dry-run flag to apply the changes.

    pear provision <source-verlink> <target-link> <production-verlink> --dry-run
  8. Validate a project directory with validate()

    main

    The validate(dir) function checks if a given path is a valid directory. It will throw an ERR_INVALID_PROJECT_DIR error if the path does not exist or if the path points to a file instead of a directory.

    const { validate } = require('pear/lib/package')
    
    try {
      await validate('./my-project')
      console.log('Directory is valid')
    } catch (err) {
      console.error('Validation failed:', err.message)
    }
  9. Model API Reference

    main

    The Model class provides the following methods for interacting with the sidecar database:

    • ready(): Returns a Promise that resolves when the underlying hyperdb is ready.
    • getDhtNodes(): Retrieves the list of nodes from the @pear/dht namespace. Returns an empty array if no nodes exist.
    • setDhtNodes(nodes): Atomically updates the @pear/dht namespace with the provided nodes array using a database transaction.
    • getMultisig(key): Retrieves a multisig record matching the provided key from the @pear/multisig namespace.
    • allMultisig(): Returns an array of all records found in the @pear/multisig namespace.
    • setMultisig(key): Atomically inserts a new multisig record with the provided key into the @pear/multisig namespace.
    • close(): Closes the underlying hyperdb instance.
  10. Manage Sidecar client connections

    main

    The Sidecar provides properties and methods to manage active IPC clients:

    • sidecar.clients: Returns a list of all connected IPC clients.
    • sidecar.hasClients: A boolean indicating if there are any active clients.
    • sidecar.closeClients(params, originClient): Closes all clients except for the originClient. It returns an array of metadata containing the cmdArgs of the closed clients.
  11. Retrieve platform and runtime versions

    main

    You can query the current platform and runtime information using the versions(params, client) method. This returns an object containing:

    • platform: An object with the UPGRADE key (containing the version, fork, and length), and the current version.
    • runtimes: An object containing the versions for bare and pear runtimes.
    // Example of what the return shape looks like
    // {
    //   platform: { key: '...', version: '...', fork: ..., length: ... },
    //   runtimes: { bare: '...', pear: '...' }
    // }
  12. Find core links by package name

    main

    The getLinksByName(params, client) method allows you to search for metadata cores within the corestore that match a specific package name. It iterates through the corestore, inspects the package.json of the associated Hyperdrive, and returns the links of matching metadata cores.

    Parameters:

    • params.name: The string name of the package to search for.
    const links = await sidecar.getLinksByName({ name: 'my-app-name' }, client)