Skip to content

Kill FALLBACK_REGISTRY — generate content types from recipes - #567

Merged
joelteply merged 13 commits into
mainfrom
fix/generated-content-types
Mar 27, 2026
Merged

joelteply merged 13 commits into
mainfrom
fix/generated-content-types

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

  • Eliminated 18-entry hardcoded FALLBACK_REGISTRY in ContentTypeRegistry.ts
  • New generator reads 27 recipe JSON files and generates TypeScript types, configs, icons
  • ContentType union, validation, icons all from ONE source: recipe files on disk
  • Adding a content type = create recipe JSON + run generator. Zero code changes.
  • Deployed and verified — UI renders correctly with tabs, icons, navigation

Test plan

  • TypeScript compiles clean (zero errors)
  • npm run build:ts succeeds
  • npm start deploys successfully
  • Browser UI loads, tabs render, content types resolve
  • Screenshot verified — no visual regressions

The 18-entry hardcoded FALLBACK_REGISTRY in ContentTypeRegistry.ts is dead.
Content types are now generated from the 27 recipe JSON files on disk.

New: generator/generate-content-types.ts
  - Reads all system/recipes/*.json
  - Generates shared/generated/ContentTypes.ts with:
    - ContentType union type (27 types from recipes)
    - CONTENT_TYPES runtime array (for validation)
    - CONTENT_TYPE_CONFIGS map (widget, icon, path, requiresEntity)
    - isContentType() type guard
    - getContentTypeIcon() function
  - Run: npx tsx generator/generate-content-types.ts

Changed: ContentTypeRegistry.ts
  - Removed 190-line FALLBACK_REGISTRY
  - Removed debug console.logs
  - Uses generated CONTENT_TYPE_CONFIGS as compile-time fallback
  - RecipeLayoutService still primary runtime source
  - Unknown content types log error (no silent fallback to chat)

Changed: UserStateEntity.ts
  - ContentType imported from generated types (was hardcoded 18-entry union)
  - Validation uses isContentType() (was hardcoded array)

Changed: ContentTabsWidget.ts
  - Replaced 18-entry TYPE_ICONS map with getContentTypeIcon()

Adding a new content type: create recipe JSON, run generator. Zero code changes.
Copilot AI review requested due to automatic review settings March 27, 2026 18:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the hardcoded main-panel content type fallback registry with a generated, recipe-driven content type registry so content type unions, icons, and configs are derived from system/recipes/*.json.

Changes:

  • Removed the large hardcoded FALLBACK_REGISTRY and switched lookups to shared/generated/ContentTypes.ts.
  • Added a generator (src/generator/generate-content-types.ts) to build ContentTypes.ts from recipe JSON files.
  • Updated tabs + UserState validation to use generated helpers (getContentTypeIcon, isContentType, CONTENT_TYPES).

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/widgets/main/shared/ContentTypeRegistry.ts Switches runtime lookups from hardcoded fallback to generated recipe-derived configs.
src/widgets/content-tabs/ContentTabsWidget.ts Uses generated icon lookup instead of a hardcoded icon map.
src/system/data/entities/UserStateEntity.ts Replaces hardcoded ContentType union + validation list with generated types/guards.
src/shared/generated/index.ts Re-exports generated ContentType type.
src/shared/generated/ContentTypes.ts New generated union/config map and helper functions.
src/generator/generate-content-types.ts New generator that reads recipes and emits ContentTypes.ts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +4 to +8
* Source of truth: Recipe JSON files (system/recipes/*.json)
* Generated types: shared/generated/ContentTypes.ts
*
* ARCHITECTURE: Recipe JSON files are THE source of truth for layouts.
* This registry provides:
* 1. Dynamic lookup from RecipeLayoutService (loaded from recipes)
* 2. Fallback defaults for content types without recipes
*
* When adding a new content type:
* 1. Create a recipe JSON file in system/recipes/{contentType}.json
* 2. Define layout.widgets array with position/order (new format)
* 3. The registry will automatically pick it up
* 4. Only add to FALLBACK_REGISTRY if recipe doesn't exist yet
* NO FALLBACK REGISTRY. If a content type has no recipe, it fails visibly.
* Add a recipe JSON file, run the generator. That's it.

Copilot AI Mar 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Header comment says “NO FALLBACK REGISTRY… it fails visibly,” but getWidgetForType() still falls back to 'chat-widget' for unknown types and getRightPanelConfig() falls back to the help panel. Either adjust the comment to reflect the current graceful-degradation behavior, or change the runtime behavior to a truly visible failure mode (e.g., dedicated error widget) if that’s the intent.

Copilot uses AI. Check for mistakes.
Comment on lines +72 to +84
const widget = r.layout?.main?.[0] || 'chat-widget';
const displayName = r.displayName || r.name || r.uniqueId;
const icon = ICON_MAP[r.uniqueId] || '📄';
const hasRightPanel = r.layout?.right !== null && r.layout?.right !== undefined;

return ` '${r.uniqueId}': {
widget: '${widget}',
displayName: '${displayName}',
icon: '${icon}',
pathPrefix: '/${r.uniqueId}',
requiresEntity: ${r.uniqueId === 'chat' || r.uniqueId === 'live' || r.uniqueId === 'persona' || r.uniqueId === 'dm'},
hasRightPanel: ${hasRightPanel},
}`;

Copilot AI Mar 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated TS embeds displayName, widget, and icon directly into single-quoted string literals. If any recipe’s displayName/name contains ', newlines, or backslashes, the generated ContentTypes.ts will be invalid TypeScript. Consider emitting strings via JSON.stringify(...) (or otherwise escaping) to make generation robust to recipe text.

Copilot uses AI. Check for mistakes.
Comment on lines +58 to +66
// 3. Build icon map from conventions
// Icons are inferred from recipe metadata; override with explicit mapping if needed
const ICON_MAP: Record<string, string> = {
'chat': '💬', 'settings': '⚙️', 'theme': '🎨', 'help': '❓',
'persona': '🤖', 'browser': '🌐', 'canvas': '🎯', 'diagnostics': '🔍',
'diagnostics-log': '📋', 'live': '📹', 'profile': '👤', 'metrics': '📊',
'grid-overview': '🖥️', 'training-dashboard': '🧪', 'inference-sample': '🔬',
'genome-profile': '🧬', 'terminal': '💻', 'dm': '✉️',
};

Copilot AI Mar 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says icons/configs come from the recipe files as the single source of truth, but the generator still relies on a hardcoded ICON_MAP (and defaults to 📄). If the intent is truly “recipes only,” consider adding an icon field to recipes (or deriving from existing recipe metadata) and reading it here; otherwise the PR description should be adjusted to reflect that icons still require generator code changes for overrides.

Copilot uses AI. Check for mistakes.
Comment on lines +30 to +31
// Re-export generated types for consumers
export { ContentType, ContentTypeConfig, isContentType, CONTENT_TYPE_CONFIGS };

Copilot AI Mar 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContentType and ContentTypeConfig are imported with import { type ... }, but then re-exported via export { ... } as if they were runtime values. TypeScript will error because type-only imports can’t be re-exported as values; use export type { ContentType, ContentTypeConfig } (and separately export the runtime bindings like isContentType / CONTENT_TYPE_CONFIGS).

Suggested change
// Re-export generated types for consumers
export { ContentType, ContentTypeConfig, isContentType, CONTENT_TYPE_CONFIGS };
// Re-export generated types and runtime helpers for consumers
export type { ContentType, ContentTypeConfig };
export { isContentType, CONTENT_TYPE_CONFIGS };

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +76
const configEntries = recipes.map(r => {
const widget = r.layout?.main?.[0] || 'chat-widget';
const displayName = r.displayName || r.name || r.uniqueId;
const icon = ICON_MAP[r.uniqueId] || '📄';
const hasRightPanel = r.layout?.right !== null && r.layout?.right !== undefined;

Copilot AI Mar 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generator currently assumes the OLD recipe layout shape (layout.main / layout.right). Several existing recipes use the NEW format (layout.widgets with position: 'center' | 'right' and optional panels.right.visible), so the generated widget and hasRightPanel values are wrong (e.g. settings.json and canvas.json both use layout.widgets, but generation falls back to chat-widget and hasRightPanel: false). The generator should mirror RecipeLayoutService.getWidget() / getRightPanel() logic so both layout formats produce correct configs.

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +83
icon: '${icon}',
pathPrefix: '/${r.uniqueId}',
requiresEntity: ${r.uniqueId === 'chat' || r.uniqueId === 'live' || r.uniqueId === 'persona' || r.uniqueId === 'dm'},
hasRightPanel: ${hasRightPanel},

Copilot AI Mar 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requiresEntity is hardcoded to a small allowlist of IDs. Recipes already declare inputs for entity-like identifiers (e.g. profile has inputs.userId, diagnostics-log has inputs.logPath), so generated configs currently mark these as requiresEntity: false. Derive requiresEntity from recipe metadata (at least: presence of any inputs key, or an input with entity), and keep only minimal special-cases like chat if needed.

Copilot uses AI. Check for mistakes.
… ContentService hardcoded map

Recipes now declare entityType ("room", "user", "activity"):
  - chat.json: entityType: "room"
  - live.json: entityType: "room"
  - persona.json: entityType: "user"
  - profile.json: entityType: "user"

RoutingService.resolve(): was switch(contentType) with 5 hardcoded cases.
Now reads entityType from generated config, switches on ENTITY TYPE not
content type name. Adding a content type never touches RoutingService.

ContentService: was CONTENT_TYPE_COLLECTIONS map (5 hardcoded entries).
Now derives collection from entityType → collection mapping.
room→rooms, user→users, activity→activities.

Generator updated: reads entityType from recipe, generates it into
ContentTypeConfig. requiresEntity derived from presence of entityType
or inputs — no more hardcoded list of content type names.
windows-setup-autostart.ps1: Run ONCE as admin. Creates Windows Scheduled Task
that starts WSL2 at boot as SYSTEM (no login required). Copies boot script
into WSL, configures wsl.conf.

wsl-boot.sh: Runs inside WSL2 on every boot. Starts SSH, Tailscale,
PostgreSQL. Protects SSH and Tailscale from OOM killer. Logs GPU detection.

After setup: machine reboots → WSL2 starts → SSH available in 30s →
Tailscale reconnects → tower reachable via mesh. Zero human intervention.
sentinel/run, ping, collaboration/chat/export, collaboration/live/join,
grid/list, ai/agent — all replaced with generated COMMANDS.* constants.

23 magic strings → 13 remaining (mostly in docs/comments/tests).
Experiential Plasticity paper §3.3: Qwen3.5 domain-specific forging results
  - Qwen3.5-4B on CodeFeedback: baseline 3.04 → forged 2.31 (+24%)
  - Domain-specific data amplifies plasticity beyond generic text
  - Published: continuum-ai/qwen3.5-4b-code-forged

Gap analysis: updated status with forge results, Qwen3.5-27B next
@joelteply
joelteply merged commit cda5e6d into main Mar 27, 2026
2 of 4 checks passed
@joelteply
joelteply deleted the fix/generated-content-types branch March 27, 2026 22:45
@joelteply

Copy link
Copy Markdown
Contributor Author

Already merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants