✅ CUSTOM EXTENSION GENERATION PROMPT
MVPL Extension Generator — CustomExtension
SYSTEM ROLE
You are Codex.
You are generating a fully compliant MVPL calculator extension that integrates with an already existing MVPL Modular Calculator Core (index.html is already implemented and loaded in the environment).
GLOBAL OBJECTIVE
Generate a new MVPL extension script named:
custom.js
This extension must fully comply with the MVPL extension architecture, lifecycle system, and safety model already implemented in the core platform.
OUTPUT REQUIREMENTS
Generate EXACTLY ONE FILE:
custom.js
Do NOT include explanations outside code comments.
Return ONLY the JavaScript source code.
GLOBAL TECHNICAL CONSTRAINTS
• Must be standalone JavaScript
• Must run offline
• Must not require external libraries
• Must not modify core globals
• Must interact ONLY through extensionAPI
• Must follow MVPL lifecycle model
• Must preserve backward compatibility
• Must be safe if lifecycle hooks are missing in other extensions
• Must prevent duplicate UI insertion
• Must preserve profile state isolation
MVPL EXTENSION CONTRACT
The extension MUST use the manifest structure:
{
name: string,
version: string,
description: string,
dependencies?: string[],
priority?: number,
stateSchema?: object,
onInit(api, state),
onProfileSwitch(api, state),
onLayoutChange(api, state),
onDestroy(api, state)
}
Extension must be registered using:
registerExtension(manifest)
EXTENSION NAME
CustomExtension
FUNCTIONAL BEHAVIOR
The extension must:
• Add a button labeled K
• When pressed, compute a custom function of the current display value
• Initially, the function MUST return the value unchanged
• The function logic must be clearly isolated and documented so developers can easily edit it later inside custom.js
PROFILE RESTRICTION
The K button MUST:
• Only appear in the education profile
• Be removed automatically when switching to any other profile
• Only execute its function when the education profile is active
• Remain inactive or hidden otherwise
UI INSERTION RULES
• Must insert using extension slot system
• Must use slot-extension-2
• Must NOT replace or reposition core calculator buttons
• Must prevent duplicate button insertion
ERROR HANDLING REQUIREMENTS
The extension MUST:
• Display "Error" if display value is invalid numeric input
• Display "Error" if division by zero occurs within future custom functions
• Fail safely without crashing the calculator core
STATE SCHEMA REQUIREMENTS
The extension must implement a namespaced state model using:
stateSchema: {
lastUsed: null
}
State must be stored and retrieved through:
api.state("CustomExtension")
State must persist per profile and MUST NOT leak across profiles.
LIFECYCLE REQUIREMENTS
CustomExtension MUST implement:
onInit
onProfileSwitch
onLayoutChange
onDestroy
Lifecycle behavior must follow MVPL rules:
onInit:
• Create button
• Insert button only if education profile is active
onProfileSwitch:
• Insert or remove button based on profile
onLayoutChange:
• Must remain safe and not duplicate UI
onDestroy:
• Must remove UI components
• Must preserve stored state
SAFETY REQUIREMENTS
The extension MUST:
• Never modify calculator core variables
• Never assume slot exists without checking
• Safely remove UI elements when destroyed
• Avoid duplicate event bindings
• Fail gracefully if extensionAPI functions are unavailable
DOCUMENTATION REQUIREMENTS (INSIDE CODE COMMENTS)
Include clear teaching comments explaining:
• MVPL extension lifecycle
• Profile restriction logic
• Slot keypad insertion rules
• Namespaced state handling
• How developers can later customize the function logic
ACCEPTANCE CRITERIA
The extension is considered complete ONLY if:
✔ K button appears only in education profile
✔ Button disappears when profile changes
✔ Button inserts using slot-extension-2
✔ Extension uses lifecycle hooks correctly
✔ State persists per profile
✔ Calculator core remains stable
✔ Button executes identity function initially
✔ Error handling works
✔ No duplicate UI insertion occurs
TESTING INSTRUCTIONS (INSIDE CODE COMMENTS)
In index.html:
• Edit the profile for ‘education’, adding CustomExtension to enabledExtensions, and just before the </body> end tag add <script src="custom.js"></script>
Include instructions describing how to:
• Load custom.js alongside index.html
• Switch to education profile
• Verify K button visibility
• Verify button removal when switching profiles
• Confirm state persistence
• Confirm error handling
• Confirm calculator arithmetic remains correct
FINAL AUTHORITATIVE RULE
If any instruction conflicts:
Preserve calculator core stability
Preserve backward compatibility
Preserve profile state isolation
Preserve lifecycle correctness
OUTPUT FORMAT (STRICT)
Return EXACTLY:
----- custom.js -----
<full code>
No summaries
No explanations
Only code output
No comments:
Post a Comment