refactor: Update import paths and save logic

- Update import paths from `freeflowuniverse.herolib` to `incubaid.herolib`
- Ensure `ws.parent.save()` is only called when `ws.parent` is present
- Remove redundant symlink cleanup for `freeflowuniverse.herolib`
This commit is contained in:
Mahmoud-Emad
2025-10-15 15:03:25 +03:00
parent d91957b945
commit 3d25fe0f04
14 changed files with 63 additions and 44 deletions

View File

@@ -17,7 +17,7 @@ The `heroprompt` module provides a hierarchical workspace-based system for organ
### 1. Getting Started
```v
import freeflowuniverse.herolib.develop.heroprompt
import incubaid.herolib.develop.heroprompt
// Create or get a HeroPrompt instance
mut hp := heroprompt.get(name: 'my_project', create: true)!
@@ -355,7 +355,7 @@ Files marked with `*` in the file_map are the selected files included in the pro
## Complete Example
```v
import freeflowuniverse.herolib.develop.heroprompt
import incubaid.herolib.develop.heroprompt
mut hp := heroprompt.get(name: 'my_app', create: true)!
mut ws := hp.new_workspace(name: 'backend')!

View File

@@ -31,7 +31,7 @@ HeroPrompt helps you organize code files and generate structured prompts for AI
### 1. Create Instance and Workspace
```v
import freeflowuniverse.herolib.develop.heroprompt
import incubaid.herolib.develop.heroprompt
// Create or get instance
mut hp := heroprompt.get(name: 'my_project', create: true)!

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env -S v -n -w -gc none -cg -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.develop.heroprompt
import incubaid.herolib.develop.heroprompt
import os
println('=== HeroPrompt: AI Prompt Generation Example ===\n')
@@ -47,7 +47,7 @@ homepath := os.home_dir()
// Add the examples directory
mut examples_dir := workspace.add_directory(
path: '${homepath}/code/github/freeflowuniverse/herolib/examples/develop/heroprompt'
path: '${homepath}/code/github/incubaid/herolib/examples/develop/heroprompt'
name: 'examples'
scan: true
)!
@@ -55,7 +55,7 @@ println('✓ Added directory: examples')
// Add the library directory
mut lib_dir := workspace.add_directory(
path: '${homepath}/code/github/freeflowuniverse/herolib/lib/develop/heroprompt'
path: '${homepath}/code/github/incubaid/herolib/lib/develop/heroprompt'
name: 'library'
scan: true
)!
@@ -70,12 +70,12 @@ println('Step 5: Selecting specific files...')
// Select individual files from the examples directory
examples_dir.select_file(
path: '${homepath}/code/github/freeflowuniverse/herolib/examples/develop/heroprompt/README.md'
path: '${homepath}/code/github/incubaid/herolib/examples/develop/heroprompt/README.md'
)!
println(' Selected: README.md')
examples_dir.select_file(
path: '${homepath}/code/github/freeflowuniverse/herolib/examples/develop/heroprompt/prompt_example.vsh'
path: '${homepath}/code/github/incubaid/herolib/examples/develop/heroprompt/prompt_example.vsh'
)!
println(' Selected: prompt_example.vsh')

View File

@@ -45,7 +45,7 @@ fn addtoscript(tofind string, toadd string) ! {
// Reset symlinks (cleanup)
println('Resetting all symlinks...')
os.rm('${os.home_dir()}/.vmodules/incubaid/herolib') or {}
os.rm('${os.home_dir()}/.vmodules/freeflowuniverse/herolib') or {}
os.rm('${os.home_dir()}/.vmodules/incubaid/herolib') or {}
// Create necessary directories
os.mkdir_all('${os.home_dir()}/.vmodules/incubaid') or {

View File

@@ -1,7 +1,7 @@
module heroprompt
import rand
import freeflowuniverse.herolib.data.ourtime
import incubaid.herolib.data.ourtime
// HeroPrompt Methods - Workspace Management

View File

@@ -2,9 +2,9 @@ module heroprompt
import os
import rand
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.develop.codewalker
import freeflowuniverse.herolib.data.ourtime
import incubaid.herolib.core.pathlib
import incubaid.herolib.develop.codewalker
import incubaid.herolib.data.ourtime
// Directory represents a directory/directory added to a workspace
// It contains metadata about the directory and its location

View File

@@ -17,17 +17,18 @@ pub mut:
name string = 'default'
fromdb bool // will load from filesystem
create bool // default will not create if not exist
reset bool // will delete and recreate if exists
}
pub fn new(args ArgsGet) !&Workspace {
mut obj := Workspace{
pub fn new(args ArgsGet) !&HeroPrompt {
mut obj := HeroPrompt{
name: args.name
}
set(obj)!
return get(name: args.name)!
}
pub fn get(args ArgsGet) !&Workspace {
pub fn get(args ArgsGet) !&HeroPrompt {
mut context := base.context()!
mut r := context.redis()!

View File

@@ -1,8 +1,8 @@
module heroprompt
import rand
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.data.ourtime
import incubaid.herolib.core.pathlib
import incubaid.herolib.data.ourtime
// HeropromptFile represents a standalone file added to a workspace
// (not part of a directory)

View File

@@ -1,7 +1,7 @@
module heroprompt
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.logger
import incubaid.herolib.ui.console
import incubaid.herolib.core.logger
// log writes a log message with the specified level
// Outputs to both console and log file (unless run_in_tests is true)

View File

@@ -1,7 +1,9 @@
module heroprompt
import time
import incubaid.herolib.core.playbook
import incubaid.herolib.data.ourtime
import incubaid.herolib.data.encoderhero
import incubaid.herolib.core.logger
import rand
pub const version = '1.0.0'
const singleton = false
@@ -41,7 +43,7 @@ pub mut:
files []HeropromptFile // Standalone files in this workspace
created ourtime.OurTime // Time of creation
updated ourtime.OurTime // Time of last update
parent &HeroPrompt @[skip; str: skip] // Reference to parent HeroPrompt (not serialized)
parent ?&HeroPrompt @[skip; str: skip] // Reference to parent HeroPrompt (not serialized)
}
// obj_init validates and initializes the HeroPrompt instance

View File

@@ -1,6 +1,6 @@
module heroprompt
import freeflowuniverse.herolib.develop.codewalker
import incubaid.herolib.develop.codewalker
import os
// Prompt generation functionality for HeroPrompt workspaces

View File

@@ -1,6 +1,6 @@
module heroprompt
import freeflowuniverse.herolib.core.base
import incubaid.herolib.core.base
// Test HeroPrompt: new_workspace
fn test_heroprompt_new_workspace() ! {

View File

@@ -1,8 +1,8 @@
module heroprompt
import os
import incubaid.herolib.core.pathlib
import incubaid.herolib.develop.codewalker
import incubaid.herolib.ui.console
import incubaid.herolib.data.ourtime
@[params]
pub struct WorkspaceAddDirectoryParams {
@@ -36,8 +36,10 @@ pub fn (mut ws Workspace) add_directory(args WorkspaceAddDirectoryParams) !&Dire
ws.updated = ourtime.now()
// Auto-save to Redis
ws.parent.save() or {
console.print_stderr('Warning: Failed to auto-save after adding directory: ${err}')
if mut parent := ws.parent {
parent.save() or {
console.print_stderr('Warning: Failed to auto-save after adding directory: ${err}')
}
}
console.print_info('Directory added: ${repo.name}')
@@ -87,8 +89,10 @@ pub fn (mut ws Workspace) remove_directory(args WorkspaceRemoveDirectoryParams)
ws.updated = ourtime.now()
// Auto-save to Redis
ws.parent.save() or {
console.print_stderr('Warning: Failed to auto-save after removing directory: ${err}')
if mut parent := ws.parent {
parent.save() or {
console.print_stderr('Warning: Failed to auto-save after removing directory: ${err}')
}
}
console.print_info('Directory removed from workspace')
@@ -136,8 +140,10 @@ pub fn (mut ws Workspace) add_file(args WorkspaceAddFileParams) !HeropromptFile
ws.updated = ourtime.now()
// Auto-save to Redis
ws.parent.save() or {
console.print_stderr('Warning: Failed to auto-save after adding file: ${err}')
if mut parent := ws.parent {
parent.save() or {
console.print_stderr('Warning: Failed to auto-save after adding file: ${err}')
}
}
console.print_info('File added: ${file.name}')
@@ -174,8 +180,10 @@ pub fn (mut ws Workspace) remove_file(args WorkspaceRemoveFileParams) ! {
ws.updated = ourtime.now()
// Auto-save to Redis
ws.parent.save() or {
console.print_stderr('Warning: Failed to auto-save after removing file: ${err}')
if mut parent := ws.parent {
parent.save() or {
console.print_stderr('Warning: Failed to auto-save after removing file: ${err}')
}
}
console.print_info('File removed from workspace')
@@ -219,8 +227,10 @@ pub fn (mut ws Workspace) select_file(path string) ! {
if os.real_path(file.path) == file_path {
file.is_selected = true
ws.updated = ourtime.now()
ws.parent.save() or {
console.print_stderr('Warning: Failed to auto-save after selecting file: ${err}')
if mut parent := ws.parent {
parent.save() or {
console.print_stderr('Warning: Failed to auto-save after selecting file: ${err}')
}
}
return
}
@@ -240,8 +250,10 @@ pub fn (mut ws Workspace) deselect_file(path string) ! {
if os.real_path(file.path) == file_path {
file.is_selected = false
ws.updated = ourtime.now()
ws.parent.save() or {
console.print_stderr('Warning: Failed to auto-save after deselecting file: ${err}')
if mut parent := ws.parent {
parent.save() or {
console.print_stderr('Warning: Failed to auto-save after deselecting file: ${err}')
}
}
return
}
@@ -259,8 +271,10 @@ pub fn (mut ws Workspace) select_all_files() ! {
}
ws.updated = ourtime.now()
ws.parent.save() or {
console.print_stderr('Warning: Failed to auto-save after selecting all files: ${err}')
if mut parent := ws.parent {
parent.save() or {
console.print_stderr('Warning: Failed to auto-save after selecting all files: ${err}')
}
}
}
@@ -272,8 +286,10 @@ pub fn (mut ws Workspace) deselect_all_files() ! {
}
ws.updated = ourtime.now()
ws.parent.save() or {
console.print_stderr('Warning: Failed to auto-save after deselecting all files: ${err}')
if mut parent := ws.parent {
parent.save() or {
console.print_stderr('Warning: Failed to auto-save after deselecting all files: ${err}')
}
}
}

View File

@@ -1,7 +1,7 @@
module heroprompt
import os
import freeflowuniverse.herolib.core.base
import incubaid.herolib.core.base
// Test workspace: add directory
fn test_workspace_add_directory() ! {