From 72b84a772925daa9e9128fa63d7657af35ef2fa0 Mon Sep 17 00:00:00 2001 From: madclaws Date: Sun, 8 Mar 2026 22:39:26 +0530 Subject: [PATCH] feat: Added scripts and just command for .pkg build - just build_pkg for building .pkg --- .gitignore | 2 + Cargo.lock | 2 +- justfile | 3 + pkg/build.sh | 73 +++++++++++++++++++ pkg/scripts/postinstall | 17 +++++ scripts/install.sh | 13 +++- .../app-server/packages-app-server.txt | 4 +- .../app-server/pylock.app-server.meta.json | 4 +- .../app-server/pylock.app-server.toml | 44 +++++------ tiles/Cargo.toml | 2 +- tiles/src/runtime/mlx.rs | 5 +- tiles/src/utils/config.rs | 5 +- 12 files changed, 135 insertions(+), 39 deletions(-) create mode 100755 pkg/build.sh create mode 100755 pkg/scripts/postinstall diff --git a/.gitignore b/.gitignore index 1575e17..c9132aa 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ stack_export_prod/ tilekit/target tiles/target .DS_Store +pkgroot/ +*.pkg diff --git a/Cargo.lock b/Cargo.lock index cf1fed1..299b433 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4255,7 +4255,7 @@ dependencies = [ [[package]] name = "tiles" -version = "0.4.2" +version = "0.4.3" dependencies = [ "anyhow", "async-std", diff --git a/justfile b/justfile index c8a138b..2eee773 100644 --- a/justfile +++ b/justfile @@ -20,3 +20,6 @@ bundle: install: ./scripts/install.sh + +bundle_pkg: + ./pkg/build.sh diff --git a/pkg/build.sh b/pkg/build.sh new file mode 100755 index 0000000..b3c1bdc --- /dev/null +++ b/pkg/build.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +set -euo pipefail + +VERSION=$(grep '^version' tiles/Cargo.toml | head -1 | awk -F'"' '{print $2}') + +TARGET="release" +MODELFILE_DIR="modelfiles" +SERVER_DIR="server" +BINARY_NAME="tiles" + +VERSION=$(grep '^version' tiles/Cargo.toml | head -1 | awk -F'"' '{print $2}') +OS=$(uname -s | tr '[:upper:]' '[:lower:]') +ARCH=$(uname -m) +OUT_NAME="${BINARY_NAME}-v${VERSION}-${ARCH}-${OS}" + +echo "🚀 Building ${BINARY_NAME} (${TARGET} mode)..." + +cargo build -p tiles --${TARGET} + +CLI_BIN_PATH="pkgroot/usr/local/bin" +LIBS_PATH="pkgroot/usr/local/share/tiles" + +# CLI binary install path + +mkdir -p "${CLI_BIN_PATH}" + +mkdir -p "${LIBS_PATH}" + + +# move cli to bin path + +cp "target/${TARGET}/${BINARY_NAME}" "${CLI_BIN_PATH}" +chmod +x "${CLI_BIN_PATH}/tiles" + + +# Build venvstack and move to /usr/local/share/tiles +# +# flushing this folder, else the final zip will have previous app-server zips too (#84) + +rm -rf "${SERVER_DIR}/stack_export_prod" + +echo "🔒 Locking the venvstack...." + +venvstacks lock server/stack/venvstacks.toml + +echo "🛠️ Building the venvstack...." + +venvstacks build server/stack/venvstacks.toml + +echo "📦 Publishing the venvstack...." + +venvstacks publish --tag-outputs --output-dir ../stack_export_prod server/stack/venvstacks.toml + +cp -r "${SERVER_DIR}" "${LIBS_PATH}" + +rm -rf "${LIBS_PATH}/server/__pycache__" +rm -rf "${LIBS_PATH}/server/mem_agent/__pycache__" +rm -rf "${LIBS_PATH}/server/backend/__pycache__" +rm -rf "${LIBS_PATH}/server/.venv" +rm -rf "${LIBS_PATH}/server/stack" + +cp -r "${MODELFILE_DIR}" "${LIBS_PATH}" + + +# Creating .pkg +pkgbuild --root pkgroot --scripts pkg/scripts --identifier com.tilesprivacy.tiles --version "$VERSION" "tiles-${VERSION}".pkg" + + +# signing + + +# notarizing diff --git a/pkg/scripts/postinstall b/pkg/scripts/postinstall new file mode 100755 index 0000000..7c25563 --- /dev/null +++ b/pkg/scripts/postinstall @@ -0,0 +1,17 @@ +#!/bin/bash + +SERVER_DIR="/usr/local/share/tiles/server" + +echo "🔧 Setting up Python environment..." + +cd "${SERVER_DIR}/stack_export_prod" || exit 1 + +for f in *.tar.xz; do + tar -xvf "$f" +done + +rm -f *.tar.xz + +./cpython3.13/bin/python cpython3.13/postinstall.py +./framework-mlx/bin/python framework-mlx/postinstall.py +./app-server/bin/python app-server/postinstall.py diff --git a/scripts/install.sh b/scripts/install.sh index d69eb3d..ff7e12d 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -4,10 +4,15 @@ set -euo pipefail ENV="prod" # prod is another env, try taking it from github env REPO="tilesprivacy/tiles" # VERSION="${TILES_VERSION:-latest}" -VERSION="0.4.2" -INSTALL_DIR="$HOME/.local/bin" # CLI install location -SERVER_DIR="$HOME/.local/lib/tiles/server" # Python server folder -MODELFILE_DIR="$HOME/.local/lib/tiles/modelfiles" # Python server folder +VERSION="0.4.3" +# INSTALL_DIR="$HOME/.local/bin" # CLI install location +INSTALL_DIR="/usr/local/bin" # CLI install location +# SERVER_DIR="$HOME/.local/lib/tiles/server" # Python server folder +# MODELFILE_DIR="$HOME/.local/lib/tiles/modelfiles" # Python server folder + +SERVER_DIR="/usr/local/share/tiles/server" # Python server folder +MODELFILE_DIR="/usr/local/share/tiles/modelfiles" # Python server folder + TMPDIR="$(mktemp -d)" OS=$(uname -s | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m) diff --git a/server/stack/requirements/app-server/packages-app-server.txt b/server/stack/requirements/app-server/packages-app-server.txt index 0e5a2fc..2839779 100644 --- a/server/stack/requirements/app-server/packages-app-server.txt +++ b/server/stack/requirements/app-server/packages-app-server.txt @@ -4,7 +4,7 @@ annotated-types==0.7.0 anyio==4.12.1 black==25.9.0 certifi==2026.2.25 -charset-normalizer==3.4.4 +charset-normalizer==3.4.5 click==8.3.1 fastapi==0.119.0 filelock==3.25.0 @@ -22,7 +22,7 @@ openai-harmony==0.0.8 openresponses-types==2.3.0.post1 packaging==26.0 pathspec==1.0.4 -platformdirs==4.9.2 +platformdirs==4.9.4 protobuf==7.34.0 pydantic==2.12.5 pydantic-core==2.41.5 diff --git a/server/stack/requirements/app-server/pylock.app-server.meta.json b/server/stack/requirements/app-server/pylock.app-server.meta.json index d03f432..1d36ac4 100644 --- a/server/stack/requirements/app-server/pylock.app-server.meta.json +++ b/server/stack/requirements/app-server/pylock.app-server.meta.json @@ -1,8 +1,8 @@ { "lock_input_hash": "sha256:c836d5cfb697330a57241b2b8f275a804178488ec906b19866809ef33c95ba81", "lock_version": 1, - "locked_at": "2026-03-01T18:20:47.939345+00:00", + "locked_at": "2026-03-08T15:32:49.822954+00:00", "other_inputs_hash": "sha256:63b3c2cfe2ec414938e81dace7aac779c7b902bae681618cd8827e9f16880985", - "requirements_hash": "sha256:bc1a0df3c15a1fad6f446be81a50a01835c1a11ff412440842f751ecdce9cbdd", + "requirements_hash": "sha256:579ae09437373494896b65ca902382b680f2d42170dfa57c62618ca7d5d3457a", "version_inputs_hash": "sha256:58db986b7cd72eeded675f7c9afd8138fe024fb51451131b5562922bbde3cf43" } diff --git a/server/stack/requirements/app-server/pylock.app-server.toml b/server/stack/requirements/app-server/pylock.app-server.toml index b8991c8..5bd3d7b 100644 --- a/server/stack/requirements/app-server/pylock.app-server.toml +++ b/server/stack/requirements/app-server/pylock.app-server.toml @@ -75,40 +75,40 @@ sha256 = "027692e4402ad994f1c42e52a4997a9763c646b73e4096e4d5d6db8af1d6f0fa" [[packages]] name = "charset-normalizer" -version = "3.4.4" +version = "3.4.5" index = "https://pypi.org/simple" [[packages.wheels]] -url = "https://files.pythonhosted.org/packages/97/45/4b3a1239bbacd321068ea6e7ac28875b03ab8bc0aa0966452db17cd36714/charset_normalizer-3.4.4-cp313-cp313-macosx_10_13_universal2.whl" -upload-time = 2025-10-14T04:41:13Z -size = 208091 +url = "https://files.pythonhosted.org/packages/f5/48/9f34ec4bb24aa3fdba1890c1bddb97c8a4be1bd84ef5c42ac2352563ad05/charset_normalizer-3.4.5-cp313-cp313-macosx_10_13_universal2.whl" +upload-time = 2026-03-06T06:01:37Z +size = 280788 [packages.wheels.hashes] -sha256 = "e1f185f86a6f3403aa2420e815904c67b2f9ebc443f045edd0de921108345794" +sha256 = "ac59c15e3f1465f722607800c68713f9fbc2f672b9eb649fe831da4019ae9b23" [[packages.wheels]] -url = "https://files.pythonhosted.org/packages/f5/83/6ab5883f57c9c801ce5e5677242328aa45592be8a00644310a008d04f922/charset_normalizer-3.4.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl" -upload-time = 2025-10-14T04:41:19Z -size = 153076 +url = "https://files.pythonhosted.org/packages/94/0a/af49691938dfe175d71b8a929bd7e4ace2809c0c5134e28bc535660d5262/charset_normalizer-3.4.5-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl" +upload-time = 2026-03-06T06:01:43Z +size = 195572 [packages.wheels.hashes] -sha256 = "a8a8b89589086a25749f471e6a900d3f662d1d3b6e2e59dcecf787b1cc3a1894" +sha256 = "0625665e4ebdddb553ab185de5db7054393af8879fb0c87bd5690d14379d6819" [[packages.wheels]] -url = "https://files.pythonhosted.org/packages/7a/10/f882167cd207fbdd743e55534d5d9620e095089d176d55cb22d5322f2afd/charset_normalizer-3.4.4-cp313-cp313-musllinux_1_2_x86_64.whl" -upload-time = 2025-10-14T04:41:28Z -size = 154465 +url = "https://files.pythonhosted.org/packages/84/31/faa6c5b9d3688715e1ed1bb9d124c384fe2fc1633a409e503ffe1c6398c1/charset_normalizer-3.4.5-cp313-cp313-musllinux_1_2_x86_64.whl" +upload-time = 2026-03-06T06:01:56Z +size = 197509 [packages.wheels.hashes] -sha256 = "9a26f18905b8dd5d685d6d07b0cdf98a79f3c7a918906af7cc143ea2e164c8bc" +sha256 = "c7a80a9242963416bd81f99349d5f3fce1843c303bd404f204918b6d75a75fd6" [[packages.wheels]] -url = "https://files.pythonhosted.org/packages/0a/4c/925909008ed5a988ccbb72dcc897407e5d6d3bd72410d69e051fc0c14647/charset_normalizer-3.4.4-py3-none-any.whl" -upload-time = 2025-10-14T04:42:31Z -size = 53402 +url = "https://files.pythonhosted.org/packages/c5/60/3a621758945513adfd4db86827a5bafcc615f913dbd0b4c2ed64a65731be/charset_normalizer-3.4.5-py3-none-any.whl" +upload-time = 2026-03-06T06:03:17Z +size = 55455 [packages.wheels.hashes] -sha256 = "7a32c560861a02ff789ad905a2fe94e3f840803362c84fecf1851cb4cf3dc37f" +sha256 = "9db5e3fcdcee89a78c04dffb3fe33c79f77bd741a624946db2591c81b2fc85b0" [[packages]] name = "click" @@ -495,16 +495,16 @@ sha256 = "fb6ae2fd4e7c921a165808a552060e722767cfa526f99ca5156ed2ce45a5c723" [[packages]] name = "platformdirs" -version = "4.9.2" +version = "4.9.4" index = "https://pypi.org/simple" [[packages.wheels]] -url = "https://files.pythonhosted.org/packages/48/31/05e764397056194206169869b50cf2fee4dbbbc71b344705b9c0d878d4d8/platformdirs-4.9.2-py3-none-any.whl" -upload-time = 2026-02-16T03:56:08Z -size = 21168 +url = "https://files.pythonhosted.org/packages/63/d7/97f7e3a6abb67d8080dd406fd4df842c2be0efaf712d1c899c32a075027c/platformdirs-4.9.4-py3-none-any.whl" +upload-time = 2026-03-05T18:34:12Z +size = 21216 [packages.wheels.hashes] -sha256 = "9170634f126f8efdae22fb58ae8a0eaa86f38365bc57897a6c4f781d1f5875bd" +sha256 = "68a9a4619a666ea6439f2ff250c12a853cd1cbd5158d258bd824a7df6be2f868" [[packages]] name = "protobuf" diff --git a/tiles/Cargo.toml b/tiles/Cargo.toml index 2882cf7..f49ad72 100644 --- a/tiles/Cargo.toml +++ b/tiles/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tiles" -version = "0.4.2" +version = "0.4.3" edition = "2024" [dependencies] diff --git a/tiles/src/runtime/mlx.rs b/tiles/src/runtime/mlx.rs index f7431bc..72e8aa4 100644 --- a/tiles/src/runtime/mlx.rs +++ b/tiles/src/runtime/mlx.rs @@ -455,10 +455,7 @@ async fn chat( .from .clone() .ok_or_else(|| anyhow!("Failed to get model name"))?; - let prompt = modelfile - .system - .clone() - .ok_or_else(|| anyhow!("Failed to get system prompt"))?; + let prompt = modelfile.system.clone().unwrap_or("".to_owned()); let convo_input = create_chat_input(input, prompt.as_str(), conversations); let body = json!({ "model": modelname, diff --git a/tiles/src/utils/config.rs b/tiles/src/utils/config.rs index 5bbafbf..54da7f9 100644 --- a/tiles/src/utils/config.rs +++ b/tiles/src/utils/config.rs @@ -9,7 +9,7 @@ /// - /logs /// - /data (default, user can change this location tho) /// - /memory (memory stored as PKM) -/// - ~/.local/lib/tiles (lib dir) - Some internal App files, libraries etc go here.. +/// - /usr/local/share/tiles (lib dir) - Some internal App files, libraries etc go here.. /// - /modelfiles /// - /server use anyhow::{Context, Result, anyhow}; @@ -117,8 +117,7 @@ impl ConfigProvider for DefaultProvider { let base_dir = env::current_dir().context("Failed to fetch CURRENT_DIR")?; Ok(base_dir) } else { - let home_dir = env::home_dir().context("Failed to fetch $HOME")?; - let data_dir = home_dir.join(".local/lib"); + let data_dir = PathBuf::from_str("/usr/local/share")?; Ok(data_dir.join("tiles")) } } -- 2.51.2