Skip to content

VIP-84: Project file types (a project registers an extension and a lowering module)

Status: open — proposed 2026-12-01 from the onto and fucorytweetlang domain languages (pending Will's decision). Proposal only: no compiler change accompanies this document.

Will's words

"Understand how to make vibelang as a dsl. look at our twitter example we pushed to roninjin10/fucorytweetlang"

Motivation

Two domain languages are built on VibeLang today, the same way:

  • fucorytweetlang (roninjin10/fucorytweetlang): a .tweet file is a VibeLang module plus six declaration forms (voice, thought, rubric, tweet, thread, schedule).
  • onto (smithersai/t3code, packages/onto): a .onto file is a VibeLang module plus seven forms (object, shape, link, lifecycle, action, derive, event) for a domain's ontology.

Both follow one pattern: a compiler written in VibeLang lowers each form to typed VibeLang on the line where the form started and leaves every other line alone, so a vibe diagnostic on line N is about line N of the domain file. The pattern works. What surrounds it is done by hand, twice:

Jobfucorytweetlang todayonto today
Get the lowered module to vibeIts CLI writes .fucory/build/<name>.vibe; a second tsconfig.examples.json includes that directoryonto compile writes t3code.onto.vibe beside the source, and the file is committed
Keep the lowered module currentRerun the CLI before vibeA test (t3code.onto.test.ts) lowers the source again and fails when the committed file differs
Import the domain fileImport the build pathimport * as Ontology from "../ontology/t3code.onto.vibe": the generated name, not the source
Map a diagnostic backLine only, by the line-for-line discipline; the file name is the build file, and the column is wrong whenever the lowered line is longerThe same; lowered lines run to several thousand columns
Show the domain language's own errorsOnly from its CLIOnly from onto check
EditorNone: the language service does not open .tweetNone: the language service does not open .onto
Loader, Vite, test runnerEach sees only the build outputEach sees only the committed .onto.vibe

Every further domain language will rebuild this list. A generated file that is committed can also drift from its source between the edit and the test run, and a reviewer reads a diff twice the size of the change.

Decision (proposed)

A project registers a file extension and a lowering module. The compiler lowers such a file in memory, compiles the result as the VibeLang module at that path, and maps every diagnostic back to the domain file.

1. Registration

In tsconfig.json, under the existing vibe options:

{
  "vibe": {
    "fileTypes": {
      ".onto": { "lower": "@t3tools/onto/lower" },
      ".tweet": { "lower": "fucorytweetlang/lower" }
    }
  }
}
  • The key is the extension. .vibe, .vibex, .ts, .tsx, .js, .json and their declaration forms cannot be registered (EK3020).
  • lower is a module specifier resolved from the tsconfig.json that names it, the way a plugin is. It may itself be a .vibe module; the compiler compiles it first, and a lowering module cannot be of a registered file type (EK3021, no cycles).
  • Files with a registered extension are matched by include like any source file. A file type is active only in the project that registers it.

2. The lowering module

It exports one pure, synchronous function:

export interface LowerInput {
  readonly fileName: string
  readonly source: string
}
 
export interface LowerDiagnostic {
  readonly line: number          // 1-based, in the domain file
  readonly column?: number       // 1-based; the whole line when absent
  readonly endLine?: number
  readonly endColumn?: number
  readonly message: string
  readonly code?: string         // the language's own code, shown as given
}
 
export interface Segment {
  readonly lowered: { readonly line: number; readonly column: number; readonly length: number }
  readonly source: { readonly line: number; readonly column: number; readonly length: number }
}
 
export interface LowerOutput {
  readonly code: string                          // a VibeLang module
  readonly diagnostics: ReadonlyArray<LowerDiagnostic>
  readonly segments?: ReadonlyArray<Segment>     // where lowered text was copied from the source
}
 
export function lower(input: LowerInput): LowerOutput
  • lower gets one file and returns one module. It reads nothing else: no file system, no network, no clock. The compiler runs it in the sandbox compile-time evaluation already uses, and caches the result by the hash of source and of the lowering module.
  • A lowering that returns any diagnostic produces no module; the diagnostics are the file's errors.

3. Mapping back, with line and column

The default mapping is the discipline both languages already keep: line N of code is line N of source; lines past the end of the source map to its last line. That alone gives the right file and line with no work from the language.

Columns need help, because a lowered line is longer than what the author wrote. segments supplies it: each one says "these characters of the lowered module are these characters of the domain file". A type or an expression the author wrote (it.responseCapability.type === "not_resumable") is copied through as a segment, so an error inside it lands on the exact characters. A diagnostic outside every segment is reported on the whole form's first line.

The compiler composes this map with its own, so .js.map and .d.ts.map point at the domain file, and stack traces under --enable-source-maps name t3code.onto:343.

4. Module identity

./t3code.onto resolves to the lowered module, exactly as ./Orchestrator.vibe resolves today. Declaration output is t3code.onto.d.ts. No lowered file is written beside the source; vibe --showLowered <file> prints it for debugging.

5. Language service

The language service opens registered files, runs lower on each change, and shows the lowering module's diagnostics and the mapped VibeLang diagnostics on the domain file. Hover, go-to-definition and rename work inside segments (they are VibeLang text at a known place) and are off elsewhere. Syntax colouring of the forms stays the language's own business (a TextMate grammar).

6. What does not change

  • .vibe files compile exactly as before. A project that registers nothing sees no difference.
  • A file type is a front end only. It cannot add syntax to .vibe files, change a rule, or silence a diagnostic.
  • vibelang/register, vibelang-vite and vibelang-unplugin need no new options: they ask the compiler for a module by path and get the lowered one.

What each language deletes

  • onto: the committed t3code.onto.vibe and board.onto.vibe, the onto compile step, the drift test, and the "generated, do not edit" rule. Its Lower.vibe already returns code and line diagnostics; it adds segments for the type and expression text it copies through.
  • fucorytweetlang: .fucory/build, tsconfig.examples.json, and the rerun-before-vibe step. Its Lower.vibe has the same shape.

Both keep their CLI for what is not compiling (graph, explain, can; compose, schedule).

Testing & Verification Plan

  1. Cases under typescript/vibelang/cases/: a project with a .demo type whose lowering turns const NAME = "text" shorthand into VibeLang; a type error in a copied expression is reported at the domain file's line and column; a lowering diagnostic is reported with its own code; EK3020 and EK3021.
  2. A fuzz target in typescript/tsc/internal/vibelangfuzz: random segment lists never map a diagnostic outside the domain file's text.
  3. Language-service test: diagnostics appear on the .demo document and move when it is edited.
  4. Both motivating languages build with their generated files deleted.

Open Questions for Will

  1. Where is the registration? tsconfig.json under vibe (proposed, beside vibe.syntax), or package.json.
  2. May lower be an Effect? Proposed: no. A pure function can be cached, sandboxed and run on every keystroke; a language that needs the network does that in its own CLI.
  3. Is one file to one module enough? Proposed: yes for now. onto and fucorytweetlang both keep one ontology or one set of posts per file; cross-file references are ordinary VibeLang imports.
  4. Do registered types ship in packages? Proposed: a package publishes compiled JavaScript and declarations, as it does for .vibe; the registration is the author's build detail.