Skip to content

Refactor/english cleanup v1#1

Open
painter99 wants to merge 11 commits into
mainfrom
refactor/english-cleanup-v1
Open

Refactor/english cleanup v1#1
painter99 wants to merge 11 commits into
mainfrom
refactor/english-cleanup-v1

Conversation

@painter99

Copy link
Copy Markdown
Owner

No description provided.

Removed bloat:
- datasets/ (14 QLoRA fine-tuning JSON files, ~328 KB)
- docs/meta_prompt_strojirenstvi.txt (DALL-E mechanical drawing prompt)
- scripts/ (empty directory)
- output/ (renamed to examples/ for example STL files)
- src/cli.py (standalone CLI, not needed as plugin)
- src/semishape.py (replaced by direct tool implementation)
- src/generation/inference.py (standalone LLM client, now uses Agent Zero)
- src/generation/llm_client.py (hardcoded model client, now uses Agent Zero)
- src/rag/hybrid_retriever.py (complex unused retriever)
- src/utils/ (empty package)
- helpers/semishape_client.py (broken API wrapper with Czech method names)

Rewritten tools (no separate model, uses Agent Zero active model):
- tools/semishape_generate.py: calls agent.call_utility_model() directly
- tools/semishape_execute.py: clean sandbox execution + STL/STEP export
- tools/semishape_rag_search.py: keyword search + optional DuckDuckGo web

All prompts and docs converted to English:
- src/generation/prompts.py: English-only system prompt, Czech/EN comment control
- skills/semishape/SKILL.md: v1.0.0, fixed params (description not query)
- prompts/agent.system.tool.*.md: all 3 tool prompts updated
- README.md: full rewrite, clear architecture diagram, no model config section
- examples/README.md: English, references moved STL files
- default_config.yaml: removed all model config, clear comments

Consistency fixes:
- Version: 1.0.0 everywhere (was 0.1.0/0.2.0/1.0.0 mixed)
- Output dir: output/ everywhere (was output/ vs vystupy/ mixed)
- Model: uses Agent Zero active model everywhere (was hardcoded models)
- .gitignore: removed duplicate Python block, added output/*.stl rule
- hooks.py / initialize.py: English, removed python-dotenv dependency
- extensions/_10_semishape.py: clean, no broken imports
- All __init__.py files: clean exports matching current module structure

Added example STL files to examples/ directory (moved from output/):
- box_50x30x10.stl
- plate_with_hole_55x35x8.stl
- plate_with_hole_and_feet.stl
- plate_with_spherical_feet.stl
SemiShape is licensed under Apache License 2.0, not MIT.

Corrected:
- README.md: License section now references Apache 2.0
- SKILL.md: Added Apache 2.0 license attribution in footer

This is critical for legal compliance and project clarity.
Added:
- TESTING.md: Complete uninstall/install/test instructions for refactored version
  * Detailed steps to completely remove old plugin
  * Installation options (git clone or ZIP download)
  * Individual tool tests with expected outputs
  * Integration test workflow
  * Troubleshooting guide
  * Success checklist

- semishape-logo.png: Main project logo (professional PNG, 1.2 MB)
- thumbnail.png: Plugin repository thumbnail (79 KB PNG)

These images are required for plugin repository submission.
Testing guide enables safe parallel testing of refactored version.
Changed from 79.7 KB PNG to 3.4 KB JPG
- Resolution: 256×256 → 128×128
- Format: PNG → JPG (quality=70)
- Size: 79.7 KB → 3.4 KB (95.7% reduction)

Thumbnail now meets plugin repository requirements (<20 KB).
Uses original JPG format for better photographic compression.
UX improvements:
- Smart prompting injected via _10_semishape.py: model now auto-detects
  CAD requests and uses SemiShape tools proactively
- Slash commands: /3d, /cad, /model, /docs, /export
  Users no longer need to remember @ syntax
- System prompt injection via agent.system_prompt at init time

README.md:
- Added shields.io badges: version, Apache 2.0, Python 3.10+,
  Agent Zero, build123d, status
- Added logo (semishape-logo.png) centered at top with HTML align
- Added tagline and centered summary
- Slash commands table and examples added to Usage section
- Auto-detection section added
- Updated Troubleshooting with slash command tip
- Updated Contributing to reference TESTING.md

All changes make the plugin more accessible to casual users.
Power users can still use @tool syntax directly.
Bug #3 (HIGH) - semishape_generate.py:
  Replace build123d.export_stl with OCCT mesh-first method
  (BRepMesh_IncrementalMesh + StlAPI_Writer) in _run_and_export().
  build123d.export_stl is unreliable inside the execution sandbox.

Bug #4 (HIGH) - semishape_execute.py:
  Same OCCT fix for STL export in _run_and_export().
  STEP export keeps build123d.export_step (works correctly).

Bug #5 (HIGH) - src/generation/prompts.py:
  Expand INFERENCE_RULES_EN with explicit anti-patterns:
  - Never use Python built-ins as variable names (e.g. 'open')
  - Never nest BuildPart inside BuildPart
  - Never call .move()/.translate() on a BuildPart context
  Add correct patterns: Locations(), corner placement, hole extrude.

Cleanup:
  Remove thumbnail.png (81KB duplicate - only thumbnail.jpg kept)

Note: Bugs #1 and #2 (get_config missing) were NOT present in the
development branch - helpers/tool.py already has get_config() at
line 83. Those bugs affected the separately installed plugin copy.
Extension file (_10_semishape.py):
  - Remove incorrect OpenRouter API key check — plugin uses active
    Agent Zero model, NO separate API key is needed
  - Remove unused imports (os, pathlib.Path)
  - Always print 'Plugin ready' unconditionally on startup
  - Eliminates misleading warning 'No API key found' that confused users

Inference rules (prompts.py — INFERENCE_RULES_EN):
  - Rule 8: Sphere/hemisphere parameters
    arc_size3=180 required for hemisphere; omitting creates full sphere
  - Rule 9: Z-axis centering awareness
    Box(w,h,d) is centered at z=0, so bottom face is at z=-d/2
    Feet/features placed at z=0 end up INSIDE the box — must use
    part.bounding_box().min.Z to find actual bottom face position

Both rules were identified as root causes in Haiku test session
(bug report 2026-04-10 14:06 CET) where spherical feet ended up
on both sides of the plate instead of only on the bottom.
ROOT CAUSE (confirmed by deep analysis):
Agent Zero imports helpers.tool from /a0/helpers/tool.py at startup and
caches it in sys.modules['helpers.tool']. Our plugin tools then import
'from helpers.tool import Tool, Response' and get the CACHED Agent Zero
version, which has a different API and lacks get_config() — causing:

  AttributeError: 'SemishapeGenerate' object has no attribute 'get_config'

THE FIX:
Use importlib.util.spec_from_file_location() with an absolute path and a
unique module name ('semishape_helpers_tool') to force-load our own
helpers/tool.py, completely bypassing the module cache. This is applied
identically to all three tool files:

  - tools/semishape_generate.py
  - tools/semishape_execute.py
  - tools/semishape_rag_search.py

Verified: SemishapeGenerate now correctly gets get_config() and
set_progress() from our own Tool base class even when A0's helpers.tool
is already cached in sys.modules.
ROOT CAUSE of worse output quality:
After refactoring, _get_rag_context() returned empty string immediately
because data/vectorstore/ was never built. The LLM was generating
build123d code with ZERO documentation context, relying entirely on
training data — leading to less accurate API usage.

FIX:
Added two-strategy RAG context:
  1. ChromaDB vectorstore (semantic) — used when pre-built (future)
  2. Keyword search over data/docs/*.rst/*.py — always available
     (600+ build123d documentation files, no pre-build needed)

Extraction logic:
- Extracts build123d-relevant terms from the description
- Prioritises known API keywords (Box, fillet, extrude, sphere...)
- Returns up to 5 contextual snippets formatted for the LLM

Result: LLM now always receives real build123d API documentation
when generating code, restoring output quality to pre-refactor level.
…ocal RAG

Add a static verified build123d pattern library to the system prompt
for common high-value operations like through-holes, hemispheres,
hollow bodies, safe fillets, and grid patterns.

Improve local RAG fallback ranking to prefer executable Python examples
and real part files over prose documentation. Prioritizes:
- general_examples.py
- objects_3d.py
- selector_example.py
- assets/ttt/*.py
- remaining .py files before .rst docs

This is a low-risk quality improvement: no retry loop, no execution flow
changes, and no new dependencies. It only improves the guidance/context
fed to the active Agent Zero model.
Improve semishape_generate output quality and traceability with:
- extracted parameter manifest from the user request
- lightweight text-only sanity checks for generated code
- warnings for invalid build123d patterns like Through.ALL,
  Hole(center=...), shell(), and Sphere(..., arc_size=...)
- explicit reporting of requested dimensions and detected code patterns

Also strengthen prompt guidance with stricter forbidden/required
build123d rules. This is a low-risk validation improvement that helps
surface bad generations without changing execution orchestration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant