How sugarlabs/sugar-activity-on-demand works
Purpose and entry points
Sugar Activity Studio is a Linux GTK3/PyGObject desktop application that turns natural-language learning ideas into installable Sugar activities. It runs standalone without the Sugar shell, or as a Sugar-ring activity.
• Standalone launch: main.py, bin/sugar-aod-studio
• Sugar activity launch: activity.py, activity/activity.info
• Application UI is shared across both modes, centered on the studio panel/window.
UI and interaction layer
The GTK/Sugar interface provides a Sugar-inspired home ring, project creation, generation progress, preview, code/plan review, refinement, and export actions.
• ui/window.py
• ui/panel.py
• ui/ring.py
• ui/reference_image.py
UI submits requests to service and generation layers rather than directly managing model calls or generated files.
Project domain and persistence
Core models define activity specifications, project/revision state, and licensing constraints. Persistent user state—including projects, sessions, queued jobs, and credentials—lives under ~/.sugar/default/aod/.
• core/spec.py
• core/projects.py
• core/licenses.py
Projects form the durable boundary between UI sessions and generated Sugar activity artifacts.
LLM access and prompt preparation
The LLM layer abstracts provider selection, local credential storage, prompt clarification/enhancement, and optional reference-image handling. Supported remote providers include OpenRouter, Gemini, OpenAI, Claude, DeepSeek, Qwen, Moonshot, and Ollama; offline template mode avoids a provider.
• llm/providers.py
• llm/credentials.py
• llm/enhance.py
Provider calls are an external-service boundary; keys remain local and are used only for the selected provider.
Generation pipeline and safety gates
The generation subsystem orchestrates idea-to-activity production: focus/spec work, local RAG retrieval from installed Sugar activities, planning, code creation, criticism/reflection, validation, and iterative repair.
• generation/pipeline.py
• generation/generator.py
• generation/rag.py
• generation/validator.py
• generation/repair_loop.py
A complete candidate is generated once; failures trigger transactional, focused search/replace repairs with rollback, then rerun acceptance gates. Validation covers syntax, Sugar API/import safety, allowlisted calls, and alignment with the request.
Runtime execution, preview, and refinement
Accepted candidates can be exercised in a constrained subprocess with minimal environment, GTK event pumping, and save/restore checks when runtime infrastructure exists. Preview runs the generated activity inside the studio; user-selected preview targets drive minimal refinement patches and revision history.
• generation/runtime_harness.py
• generation/runtime_check.py
• preview/runner.py
• generation/refine.py
Runtime verification may explicitly remain unavailable instead of being falsely reported as passing.
Jobs, packaging, and deployment
Service modules decouple long-running generation work from interactive UI through sessions, jobs, and a queue. Outputs can be packaged as Sugar .xo bundles, installed to ~/Activities, or emitted as Flatpak sources. The studio itself supports Sugar bundle and AppImage distribution.
• service/service.py
• service/jobs.py
• service/queue.py
• exports/flatpak.py
• packaging/appimage/build-appimage.sh
Generated activities launch through Sugar Toolkit tooling such as sugar-activity3; GTK3 and Sugar Toolkit GTK3 are material runtime dependencies supplied by the OS or bundled in the AppImage.
Main entry points: pipeline.py Generation pipeline · panel.py Studio UI · projects.py Project domain · repair_loop.py Validation & repair
Components 17
Launch & UI
- Standalone launcher
main.py - Sugar activity launcher
activity.py - Studio UI · Shared panel, window, ring, and reference-image interaction layer.
ui/panel.py
Projects & Jobs
- Project domain · Specifications, revisions, project state, and license constraints.
core/projects.py - User state store · Stores projects, sessions, queued jobs, and credentials.
- Job service · Decouples interactive requests from long-running generation work.
service/service.py - Job queue
service/queue.py
Generation Pipeline
- Prompt preparation · Clarifies and enhances ideas, including optional reference images.
llm/enhance.py - Provider gateway · Selects a remote provider or offline template mode.
llm/providers.py - Generation pipeline · Coordinates spec work, retrieval, planning, creation, criticism, and acceptance.
generation/pipeline.py - Installed-activity RAG · Retrieves context from installed Sugar activities.
generation/rag.py - Validation & repair · Runs acceptance checks and transactional focused repairs with rollback.
generation/repair_loop.py
Preview & Export
- Runtime verification · Can report unavailable rather than falsely passing.
generation/runtime_harness.py - In-studio preview · Drives minimal refinement patches and revision history.
preview/runner.py - Activity export · Produces Sugar bundles, installs activities, or emits Flatpak sources.
exports/flatpak.py
External Boundaries
- LLM providers · Selected remote provider receives requests; offline mode bypasses it.
- Sugar Toolkit runtime · Runs generated activities through sugar-activity3 with GTK3.
Connections 19
- Standalone launcher → Studio UI: launches
- Sugar activity launcher → Studio UI: launches
- Studio UI → Job service: submits generation
- Studio UI → Project domain: edits projects
- Project domain → User state store: persists
- Job service → Job queue: queues work
- Job queue → Generation pipeline: dispatches
- Generation pipeline → Prompt preparation: prepares request
- Prompt preparation → Provider gateway: uses model access
- Provider gateway → LLM providers: selected provider call
- Generation pipeline → Installed-activity RAG: retrieves context
- Generation pipeline → Validation & repair: candidate acceptance
- Validation & repair → Generation pipeline: repair and retry
- Validation & repair → Runtime verification: accepted candidate
- Runtime verification → In-studio preview: verified candidate
- In-studio preview → Project domain: stores refinements
- In-studio preview → Sugar Toolkit runtime: runs activity
- Project domain → Activity export: exports revision
- Activity export → Sugar Toolkit runtime: Sugar bundle target