fiatrete / OpenDAN-Personal-AI-OS

OpenDAN is an open source Personal AI OS , which consolidates various AI modules in one place for your personal use.
https://opendan.ai
MIT License
1.59k stars 129 forks source link

Project Proposal for Package System #38

Open waterflier opened 11 months ago

waterflier commented 11 months ago

Hi guys~

Follow the guildeline in https://github.com/fiatrete/OpenDAN-Personal-AI-OS/issues/32, I'm pleased to announce that I have completed the project proposal for our Package System. I hope this document can serve as an example for future project proposals within our community.

The proposal has been submitted and can be found at the following path: https://github.com/fiatrete/OpenDAN-Personal-AI-OS/blob/MVP/doc/mvp/package_manager.md. Please note that I will continue to update this document throughout the development process to reflect the most current status and plans.

Here is the full text of the proposal:

Problems to Solve

The Package Manager is a fundamental component of the system for managing Packages. The sub system provides fundamental support for packaging, publishing, downloading, verifying, installing, and loading folders containing required packages under different scenarios. Based on relevant modules, it's easy to build a package management system similar to apt/pip/npm.

The system design has deeply referenced Git and NDN networks. The distinction between client and server is not that important. Through cryptography, it achieves decentralized trustworthy verification. Any client can become an effective repo server through simple configuration.

Design

Let's start by introducing the two important processes.

Load Package

load_package

Install Package

install_package

Note that the dependency check during installation allows for the missing packages to be installed into the current environment.

Some Basic Concepts

Package Env Directory Structure

pkg_tree

The diagram represents a typical pkg_env directory structure, where:

During the local testing phase, users can easily place their own packages in the pkgs directory for successful loading. Any local changes will not affect the content of the index-db, nor will it impact testing. Cryptographic verification only occurs during the download and installation process.

The above environment isolation design also provides a fairly standard solution for common dependency conflicts.

Test

Load Package Test

Load testing some times not depend on index-db.

Loading Using pkg_id

This is the simplest mode for users. Not specifying a version number usually means using the default version. When an index exists, the default version is fetched from the index. In the absence of an index, the default version will prioritize links without suffixes; otherwise, it will use the link with the highest version.

load("english-dict")

Actual load:

./pkgs/english-dict/
./pkgs/english-dict#0.1.5/

When there's an index-db, it will determine the default version based on the index-db information and load using the directory name with the version:

./pkgs/english-dict#0.1.3/

Note that even when there's an index-db with a cid, the system still primarily loads by symbol. This gives system administrators more flexibility. Try to avoid modifying directories named with cids.

Loading Using pkg_id + cid

load("english-dict#sha256:1234567890")

This is the simplest method and doesn't rely on index-db. The system can precisely locate and load the package, which is stored in:

./.pkgs/english-dict/sha256:1234567890/

Verification of media information does not occur before loading; it only takes place after the download is complete.

The channel is part of the version. If it's not specified, the default channel name will be read from the environment. If the version number is fixed, the directory is directly constructed for loading. If the version number is conditional, it depends on the locally installed version list to first determine the version, and then constructs the directory for loading.

load("english-dict#>0.1.4")

The package will be loaded based on the actual version installed locally:

./pkgs/english-dict#0.1.5/

Automatic local repair logic for loading using an exact version number: At this point, if that directory does not exist, but it can be seen from the index-db that the cid corresponding to version 0.1.5 is already installed locally, loading will fail by default (simply deleting the version link effectively blocks a version).

Only when the option to automatically repair links during loading is enabled (which requires permissions), will it automatically create a link to that cid directory and successfully load.

Version Control

Support Only 4 Comparison Operators: >, <, >=, <=

The logic for version selection during load is as follows:

  1. Retrieve all locally installed versions.
  2. Based on the version selection criteria, choose one version.

Note that during installation, the version chosen based on dependency information has its selection set from all versions in index-db, and it is not related to the versions already installed locally.

Package Installation Testing (To Be Completed)

Installation testing depends on index-db.

Installing Using pkg_id

Check if the installed result matches the current version specified in index-db.

Installing Using pkg_id + cid

Verify that the installation process correctly validates the cid. After successful installation, making simple changes to the files on the server should result in a download verification failure.

Installing Using pkg_id + Version Constraints

Check if the installed result matches the correct version specified in index-db.

Installation with Local Upgrades

After installing using the pkg_id method, make changes to the package content, then reinstall. At this point, the locally modified version should be backed up, and the current version should be reinstalled.