2 shared content workspace
forgejo-actions edited this page 2026-07-11 10:33:50 +00:00

Shared Content Workspace

Purpose

The shared authoring diagnostics workspace is the editor-facing snapshot for content panels that need the same scene graph, authored catalogs, diagnostics, and dependency freshness data. Its main entry point is current_editor_authored_content_workspace().

Use it when a panel needs a read-only view of authored content. Do not reload scene graphs or catalogs independently inside each panel unless the panel is intentionally editing or testing an isolated candidate state.

Steps

  1. Call current_editor_authored_content_workspace() once in the draw or update path.
  2. Pass the returned Arc to child panels instead of reloading catalogs.
  3. Read catalog snapshots, signatures, diagnostics runs, and manifest rows from the workspace accessors.
  4. Use workspace source signatures when building authoring registry cache keys.
  5. After saving content, wait for or request the next shared workspace refresh before trusting follow-up projections.

Snapshot Contents

EditorAuthoredContentWorkspace is built from an EditorAuthoredContentWorkspaceKey plus loaded catalog snapshots. The key owns:

  • the discovered SceneAssetGraph;
  • content catalog signatures for game data, dialogue, quest, and NPC service;
  • mob catalog signatures;
  • NPC catalog signatures.

The workspace keeps shared snapshots for:

  • game-data, dialogue, quest, and NPC-service catalogs through EditorAuthoredContentCatalogSnapshots;
  • mob and NPC catalogs;
  • diagnostics runs from the default provider registry;
  • a snapshot manifest with signature lanes, source summaries, stale dependency owners, and diagnostics freshness rows;
  • an NPC content intelligence projection for placement, dialogue-trigger routes, topic links, and NPC state read/write links.

The status block exposes scene count, prefab count, content signature count, diagnostics report/error counts, dependency owner count, and stale dependency owner count. Panels should prefer these counts over recomputing summaries from raw source.

Expected Outputs

A healthy workspace gives panels shared catalog snapshots, lane fingerprints, source summaries, diagnostics freshness rows, stale dependency owner rows, provider run status, dependency ownership summaries, and an NPC content intelligence projection for scene and dialogue authoring.

Signatures

The workspace uses PathDependencySignature values as freshness keys. Signature rows include whether the source exists, byte length, modified time, source id, and content hash when available.

Signature lanes are stable editor contracts:

  • scene: discovered scene assets.
  • prefab: discovered prefab assets.
  • catalog lanes from authored catalog descriptors, including game data, dialogue, quest, NPC service, mob, and NPC.
  • diagnostics input lanes from AuthoringDiagnosticsInputLane, including scene graph, prefab graph, tileset atlas, catalog lanes, UI skin catalog, UI layout manifest, and input profiles.

EditorAuthoredContentSnapshotManifest turns signatures into lane fingerprints and source summaries. AuthoringDiagnosticsProviderContext::input_signatures_for also appends the provider id and discovery source so diagnostics freshness changes when provider ownership changes, even if content files do not.

Cache Freshness

There are two cache layers:

  • EditorAuthoredContentSnapshotService checks authored catalog signatures at most once every 2 seconds.
  • EditorAuthoredContentWorkspaceCache checks the full workspace key at most once every 500 ms.

Both caches reuse the existing Arc when signatures or keys match. This keeps panels from thrashing asset discovery during egui frames. It also means a panel should treat the workspace as a frame-local projection, not as an immediate filesystem watcher. After saving content, request or await the next shared workspace refresh instead of forcing a private reload path.

Diagnostics Providers

default_authoring_diagnostics_provider_registry() owns provider registration. Built-in providers cover:

  • scene validation from the scene graph;
  • duplicate scene ids;
  • prefab validation;
  • tileset atlas discovery;
  • authored catalog diagnostics from catalog domain descriptors;
  • UI skin catalog validation;
  • UI layout manifest validation;
  • input profile validation.

Each provider declares an AuthoringAssetKind, discovery source label, input lanes, and collector callback. Provider reports are wrapped with AuthoringDiagnosticsDescriptor metadata, and panics are caught as failed AuthoringDiagnosticsRun values so one provider cannot prevent the rest of the workspace from reporting.

When adding diagnostics, register a provider or extend an authored catalog domain descriptor. Avoid adding a panel-local validation pass that produces diagnostics outside this registry, because those diagnostics will not participate in shared freshness, dependency ownership, or bake/preflight aggregation.

Dependency Graph Ownership

AuthoringDependencyGraph::from_scene_graph_and_provider_reports joins scene graph data and provider reports into a single dependency view. Owners include scene assets, prefab assets, authored catalog assets, generated cache outputs, and validation reports.

Dependency relations distinguish authored asset dependencies, scene tilesets, scene transitions, prefab tilesets, catalog sources, generated cache manifests, generated cache assets, and validation inputs. Provider reports carry AuthoringDiagnosticsDependencyOwnership, which tells the graph whether a provider owns a primary asset, a validation report, or both.

The shared workspace exposes graph information through status counts and stale-owner manifest rows rather than by exposing the graph itself. If a panel needs richer where-used behavior, add a focused workspace accessor instead of rebuilding the graph from raw assets.

Stale Dependencies

Stale dependency checks compare recorded dependency signatures against current signatures from config::asset_dependency_signature. A dependency owner is stale when at least one recorded dependency path no longer matches its current signature.

The manifest stores stale rows with asset path, owner kind, dependency count, stale dependency count, and validation issue count. Rows sort by most stale dependencies, then most validation issues, then path. This is the intended ordering for dashboards.

Stale means "the projection may be based on old inputs." It is not always a validation error. Panels should make stale state visible and avoid presenting generated cache output as authoritative until the relevant owner has been refreshed or rebuilt.

Panel Consumption Rules

Editor panels should:

  • call current_editor_authored_content_workspace() once per draw/update path and pass the Arc down;
  • consume catalog snapshots through workspace accessors such as game_data_snapshot, dialogue_snapshot, quest_snapshot, mob_snapshot, and npc_snapshot;
  • consume source signatures from the workspace when building authoring registry cache keys;
  • use manifest() for freshness/status panels instead of duplicating lane fingerprint logic;
  • use diagnostics_runs() when showing provider health, elapsed time, failures, or input fingerprints;
  • use npc_content_intelligence_projection() for NPC placement/topic/dialogue panels.

Panels should not:

  • call catalog loaders directly during draw;
  • discover the scene graph independently when the shared workspace already has it;
  • hold a workspace forever after saving content;
  • merge diagnostics without provider descriptors;
  • treat stale dependency rows as blocking unless a provider report also marks a blocking issue.

Common Mistakes

  • Loading catalogs inside UI draw code.
  • Building a private scene graph when the workspace already has one.
  • Holding an old workspace forever after saving content.
  • Bypassing the diagnostics provider registry with panel-local validation.
  • Treating stale dependency rows as hard errors without checking provider diagnostics.

Recovery Paths

If a panel shows stale or missing data, compare the workspace manifest lane fingerprints with the source that changed, inspect diagnostics provider failures, and wait for the shared cache refresh. If the workspace lacks data a panel genuinely needs, add a focused workspace accessor or provider registration rather than rescanning files in that panel.

Contributor Checklist

When adding a shared content domain:

  1. Add or reuse an authored catalog descriptor with signature lanes.
  2. Add snapshot access to EditorAuthoredContentWorkspace only if panels need it.
  3. Register diagnostics through the default provider registry or descriptor-backed catalog providers.
  4. Add input signatures for every provider lane the diagnostics read.
  5. Add dependency graph ownership so stale dependencies can point at the owner that must refresh.
  6. Add tests for cache reuse, signature changes, provider metadata, and manifest rows.