Page Editor Template System Repair Program
Document date: 2026-04-14. Scope: template loading, AI prompt generation, clipboard/export, payload import, persistence, documentation alignment, and release validation.
Purpose
This repair program defines the phased work needed to restore, harden, and govern the Page Editor template system so that defects are caught systematically rather than only after release. It treats the template feature as a production subsystem with its own contracts, validation requirements, release gates, and defect register.
Repair objectives
- functionally correct
- internally consistent
- verifiable before release
- recoverable when browser features fail
- aligned across code, templates, prompts, help text, and saved page metadata
Current defect classes
Runtime breakage
Inline JavaScript or rendered-output failures that can disable the entire template workflow.
Contract drift
Manifest, templates, prompts, help text, and actual UI behavior falling out of sync.
Persistence defects
Template choice or workflow state failing to persist or restore predictably.
Environment fragility
Clipboard or browser-dependent behavior that fails silently under HTTP or restricted contexts.
Packaging defects
Broken bundles shipping because only source lint is checked instead of rendered runtime output.
Structural code defects
Warnings, malformed regex/path logic, or low-level issues that create hidden instability.
Phased repair program
Phase 0 - Freeze and baseline capture
Freeze the failing bundle, record the relevant file inventory, and create a defect ledger with exact reproduction paths.
Checkpoint: baseline snapshot and defect ledger exist. Acceptance: no repair proceeds without them.
Phase 1 - Failure-class inventory
Classify each issue under runtime, contract, persistence, environment, packaging, or structural code and assign impact and severity.
Checkpoint: every confirmed defect belongs to a tracked class. Acceptance: no known issue remains unclassified or unowned.
Phase 2 - Verification matrix definition
Define exactly what a working template system must do: selector load, defaults apply, prompt build, copy/export, payload import, persistence, and documentation alignment.
Checkpoint: verification matrix exists. Acceptance: every repair maps to one or more checks.
Phase 3 - Runtime blocker repair
Repair JavaScript parse failures and validate the rendered admin output, not just the PHP source.
Checkpoint: template UI executes in the browser. Acceptance: no runtime parse failure remains.
Phase 4 - Contract alignment
Treat the manifest as the source of truth and ensure each shipped template has matching JSON defaults, prompt file, UI label, and help/manual coverage.
Checkpoint: manifest, templates, prompts, and help are aligned. Acceptance: no documentation refers to nonexistent templates.
Phase 5 - Persistence and state integrity
Persist the selected template key, restore it on reopen, and define which AI-assist fields are durable or transient.
Checkpoint: saved pages reopen with correct template state. Acceptance: template state survives save/reload consistently.
Phase 6 - Clipboard and export hardening
Separate generation from copy success, use secure-context clipboard where available, and provide a truthful manual-copy fallback.
Checkpoint: clipboard/export tested in normal browser conditions. Acceptance: users always have a recoverable prompt-export path.
Phase 7 - Structural cleanup
Repair malformed regex/path logic and remove warning-producing code in normal admin operation.
Checkpoint: admin load and save flow runs without structural warnings. Acceptance: no known warning-producing defect remains.
Phase 8 - Automated validation
Add PHP lint, JSON validation, manifest-file existence checks, rendered admin validation, runtime smoke tests, and documentation drift checks.
Checkpoint: pre-release validation checklist exists. Acceptance: this class of failure would now be caught before release.
Phase 9 - Release gates
Require all validation layers to pass before any bundle is marked releasable.
Checkpoint: go/no-go gates defined and used. Acceptance: no bundle ships without passing them.
Phase 10 - Controlled expansion
Add missing template families only after stabilization, and ship each new template as a complete governed unit.
Checkpoint: new templates are added without reintroducing drift. Acceptance: every new template ships with manifest, defaults, prompt, help, and smoke test.
Execution waves
Wave A: baseline, defect ledger, runtime repair, full manual retest.
Wave B: manifest/template/prompt/help alignment.
Wave C: persistence and clipboard/export hardening.
Wave D: structural cleanup and warning audit.
Wave E: automated validation, release gates, then controlled expansion.
Acceptance criteria by subsystem
Template loading
- selector is populated
- description updates on change
- defaults apply correctly
Prompt generation
- prompt builds without JS errors
- prompt reflects the selected template and page notes
Clipboard/export
- copy succeeds in supported secure contexts
- manual fallback is available and truthful when blocked
Import workflow
- valid payloads import correctly
- invalid payloads fail clearly
- fields land in the correct controls
Persistence
- selected template is saved
- selected template restores on reopen
Runtime integrity
- no JS parse failures
- no normal-load PHP warnings
Defect tracking table
| Defect ID | Title | Failure class | Symptom | Root cause | Affected files | Severity | Status | Validation method | Owner | Notes |
|---|---|---|---|---|---|---|---|---|---|---|
| PED-001 | Template workflow JS parse failure | Runtime breakage | Template actions appear but do not work | Malformed inline JS string prevented script execution | public/admin.php | Critical | Closed in current patched bundle | Render admin page and verify build/copy/apply flow | ||
| PED-002 | Clipboard success falsely reported | Environment fragility | User may be told copy succeeded when browser blocked it | Fallback lacked confirmed success handling | public/admin.php | High | Closed in current patched bundle | Test secure-context copy and manual-copy fallback | ||
| PED-003 | Selected template not persisted | Persistence defect | Template choice lost after save/reload | Template key not stored meaningfully in saved page metadata | public/admin.php; src/PageFactory.php | High | Closed in current patched bundle | Save page with selected template and reopen it | ||
| PED-004 | Missing long-form article block | Contract / feature gap | Long articles have no dedicated structured block beneath cards | No dedicated editor fields or render block for substantial prose section | public/admin.php; src/PageFactory.php; templates/page.php; templates/page.twig; public/assets/site.css | Medium | Closed in current patched bundle | Publish a page with long article content and verify render order | ||
| PED-005 | Dictionary template inventory gap | Contract drift | Help text referenced dictionary template but app did not ship one | Missing manifest/template/prompt unit | config/page_templates/*; config/import_prompts/* | Medium | Closed in current patched bundle | Verify template appears in selector and prompt builds | ||
| PED-006 | Article/teaching template inventory gap | Contract drift | Help text referred to article/teaching pages without a dedicated shipped template | Missing manifest/template/prompt unit | config/page_templates/*; config/import_prompts/* | Medium | Closed in current patched bundle | Verify template appears in selector and prompt builds | ||
| PED-007 | Config path regex warning | Structural code defect | Runtime warning during path detection | Malformed regex in config path resolution | src/Config.php | Medium | Closed in current patched bundle | Load diagnostics and save/publish paths without warnings | ||
| PED-008 | No rendered-output release gate | Packaging defect | Broken UI can ship even if PHP lint passes | No rendered admin validation before packaging | release process | High | Open | Add checklist / smoke test and require sign-off | Process defect | |
| PED-009 | No manifest-driven documentation drift check | Packaging defect | Help/manual can diverge from shipped inventory | No explicit comparison step between manifest and docs | release process | Medium | Open | Add pre-release manifest/documentation audit | Process defect |
Release checklist
- PHP lint passes on all PHP files
- Manifest and template JSON files parse cleanly
- Every manifest entry points to an existing JSON template and prompt file
- Rendered admin output shows no JavaScript parse errors
- Template selector, load defaults, prompt build, prompt copy, and payload import all work
- Clipboard fallback tested under non-ideal browser conditions
- Saved template key restores correctly on reopen
- Help/manual template inventory matches manifest inventory
- No normal-load warnings during diagnostics, save, or publish
- Bundle manifest and current-state notes updated