Skip to content

Fully-qualified names

Split out of CLAUDE.md to keep that file's per-session load light. Linked from there — read this when you're actually touching this subsystem.

Fully-qualified names — src/find-usages.ts, src/workbench/project.ts, src/workbench/lang-class.ts

struktJS gives models, root nodes, languages, and concepts each a small, automatically-derived, dotted qualified name — deliberately not MPS-style (no reversed-domain root, no project segment baked into every name). The design principle: derive the FQN from containment that already exists on disk, never invent new stored identity for it, and keep the project boundary out of it — exactly one Project is ever loaded at a time (workbench/project.ts's Project class), so nothing anywhere resolves a name across two simultaneously-open projects. Baking project-name uniqueness into every model/root FQN would solve a problem the runtime doesn't have, at the permanent cost of longer names — this is the MPS mistake being deliberately avoided.

Model FQN — modelFqn(model, models?) (find-usages.ts) is modelQualifiedName(model, models) (the pre-existing package/ancestor-nesting computation, unchanged — see below) with every dot-separated segment run through toKebabSlug() (workbench/project.ts). modelQualifiedName itself: meta.package ? "pkg.name" : name, prefixed by the qualified name of the nearest ancestor model when one exists (a model nested inside another model's own folder, walking up through any plain grouping folders in between — _ancestorQualifiedPrefix). Example: model "Console Cookbook" → modelFqn = "console-cookbook". meta.name here is always the model's own folder/file basename (stripModelExtension, computed at load time by _loadModelDirFromPath and its dir-handle/webkitdirectory siblings) — never a persisted header field. The model file's own header carries no name line (see source-file-format.ts's buildSourceFileHeaderLines).

Root FQN — rootQualifiedName(model, root, lang, models?) (find-usages.ts) is modelFqn(model, models) + "." + toKebabSlug(displayName), where displayName is the root's own name (fileRootDisplayName(root.ast, lang), src/model.ts — the root concept's name slot), falling back to the root file's stripped basename (stripModelExtension) when the concept has no name slot at all. Example: root "Console Sample" inside "Console Cookbook" → "console-cookbook.console-sample". That name slot has no representation in the parsed body (see PythonFile's own doc comment in plugins/lang-core) — every root's own display name lives in the sibling model.json's roots map instead, keyed by that root's basename (see model-language.ts's ModelJsonData doc and project.ts's _applyRootLabelOverrides/saveModelAndSyncMeta).

Language FQN — already solved, unchanged by this work: Language.qualifiedName (lang-class.ts) = namespace || displayName || name. namespace is an author-supplied complete dotted path (e.g. "core.py.math") for languages that want deliberate structure; languages that don't set one fall back automatically to their display name. Uniqueness is convention-only (a linear scan, last-registered-wins on collision) — acceptable today because at most one project's languages are registered at a time (lang-registry.ts's per-name Map).

Concept FQN — already solved too: Language#getConceptQualifiedName(head) (lang-class.ts) returns `${owner.namespace}.${PascalName}`, or null when the owning language has no namespace. No change needed here.

Declaration FQN (functions, entities, anything isDeclaration) — declarationQualifiedName(node, root, model, lang, models?) (find-usages.ts) is rootQualifiedName(...) + "." + toKebabSlug(declarationName) per enclosing declaration, and remains display-only (docs, tooltips, "copy qualified name"). It is not the resolution key for same-named references: a reference that needs disambiguating carries its own qualifier, derived from the same containment (named ancestors, then root, then model) but spelled identifier-safe and matched by kind — see ambiguous-references.md. Cross-model linking by node id (resolveNodeRef, the G10 byId mechanism) is unchanged.

Why the separators are split: slugifyName vs. toKebabSlug

workbench/project.ts has two slug functions, deliberately not unified:

  • slugifyName(name) — pre-existing, underscore-separated ("console cookbook" → "console_cookbook"). Used at model/root creation time to name real files/folders on disk (ensureEditableModel, doNewModel, uniqueRootFilename's -2/-3 collision suffixing). Left untouched: changing its separator would rename every already-created model folder and root file on next save, which this work has no reason to force.
  • toKebabSlug(name) — new, hyphen-separated, treats _/-/any other non-alphanumeric run as an equivalent word separator on the way in. Used only for display-facing FQN computation (modelFqn, rootQualifiedName). Because it normalizes _ and - identically, an old underscore-slugified folder name (console_cookbook, from before this feature existed) and a freshly-typed display name (Console Cookbook) both resolve to the same FQN segment (console-cookbook) with no forced migration of existing projects' on-disk names.

Compatibility: what this deliberately does NOT touch

ImportFrom (Core's bare-name cross-model import, plugins/lang-core/languages/concepts-modules.concept.js) persists literal typed text in its module_ slot and matches it against modelQualifiedName() — the unnormalized, non-kebab function — via findModelImportUsages/getModelByQualifiedName. modelFqn/rootQualifiedName are new, separate functions layered on top for display purposes; modelQualifiedName itself is untouched, so every already-saved from X import Y statement in an existing project keeps resolving exactly as before. Do not redirect ImportFrom matching to modelFqn without a migration pass (rewriting persisted import text via renameModelImportUsages/doSetModelPackage's existing cascade, editor-view-mount-language-actions.ts) — that would break every existing cross-model import whose declaring model's display name/package isn't already kebab-case.

Likewise, Language.qualifiedName's namespace-less fallback (displayName) is untouched — some already-registered languages' persisted ModelImportRef.qualifiedName strings are snapshots of that exact fallback text; auto-kebab-casing it would break their resolution the same way.

What's NOT built (and shouldn't be, without a real consumer)

  • Project-level FQN / cross-project uniqueness. Model and root FQNs stay project-free. Multi-project attach (Project.attachedProjects, allOpenProjects) now exists, so a name can cross a project boundary: projectSlugsFor (workbench/project.ts) gives each open project a slug, auto-suffixed on collision, used by the console's project/<slug> and project-slug/model-fqn; and a reference that must name an attached library's declaration spells that slug as the outermost segment of its qualifier — see ambiguous-references.md, which also explains why a colliding project is named by a folder tag there, not by -2.
  • UI surfacing. Nothing in InspectorPane/LanguagePane/tooltips currently shows a model or root's FQN — modelFqn/rootQualifiedName exist as pure functions with no caller yet. Add a display row once there's an actual place users need to see or copy one from.
  • Declaration-level FQN — see above; deferred, display-only if built, and only once there's a concrete consumer (docs generation, a "copy reference" action), matching the precedent already established for bare-name cross-model imports (built only once directly requested with a real use, not speculatively).