Skip to content

Contributing ​

This guide is for contributors who want to change code, add nodes or fix docs. CI runs every check below, so getting them green locally first saves round trips.

Development setup ​

bash
git clone https://github.com/gausszhou/litegraph.git
cd litegraph
pnpm install
pnpm --filter @litegraph/editor dev
  • Node.js ≥ 18, pnpm 12;
  • The first install resolves dependencies from pnpm-lock.yaml; commit lockfile changes rather than deleting the lockfile;
  • Before committing, run at least pnpm lint && pnpm typecheck && pnpm test.

Layering rules ​

LocationConstraint
packages/coreMust not depend on any nodes-* package; the entry point must not touch window implicitly or import CSS
packages/nodes-*Depend only on core; register nodes through install(LiteGraph); styles live only in core
packages/litegraphAggregate package: installation and re-exports only, no business logic
apps/*May depend on the aggregate package; node plugins for example apps live in each app's src
packages/testsCross-package tests; not published

TypeScript runs with strict on, and pnpm nullcheck maintains nullcheck-baseline.json: existing issues are recorded per file and new ones are not allowed. If you fix some, remember to tighten the baseline accordingly.

Adding a node ​

1. Generate the scaffold ​

bash
pnpm new-node math Square --title "Square" --desc "Squares its input"

The script will:

  1. create packages/nodes-math/src/Square.ts (modern style based on slotLayout);
  2. append an import and registerNodeType({ class, title, desc, type }) to the end of src/install.ts;
  3. add export { default as Square } to src/index.ts.

The default type is <pack>/<kebab-case class name>; override it with --type math/square. Add --dry-run to print the result without writing files.

2. Implement the node ​

ts
import { type SlotLayout, type Vector2 } from "@gausszhou/litegraph-core";
import { LGraphNode } from "@gausszhou/litegraph-core";

export default class Square extends LGraphNode {
  static slotLayout: SlotLayout = {
    inputs: [{ name: "in", type: "number" }],
    outputs: [{ name: "out", type: "number" }],
  };

  override size: Vector2 = [140, 30];

  override onExecute() {
    const value = this.getInputData(0);
    if (value == null) return;
    this.setOutputData(0, value * value);
  }
}

Common extension points:

  • static slotLayout / static propertyLayout: declarative ports and editable properties;
  • override onExecute(): per-frame logic;
  • override onDrawForeground(ctx) / onDrawBackground(ctx): custom drawing;
  • override onAction(action, param): receive event ports;
  • override onPropertyChanged(name, value): property-change callback;
  • onConnect / onDisconnect / onAdded / onRemoved: lifecycle callbacks.

The legacy style (calling this.addInput() in the constructor, Class.title = ... factory functions) is still supported, but new nodes should use classes + slotLayout.

3. Verify ​

bash
pnpm typecheck
pnpm test          # NodeContractsTests automatically discovers new registered types and round-trips create/serialize
pnpm docs:nodes    # regenerate the Chinese and English node catalogs (must be committed)

The node contract tests iterate over the types each pack registers, so new nodes usually need no dedicated test; add unit tests only when behaviour is complex (execution logic, state machines, drawing).

Changing the core ​

Core paths (LGraph, LGraphNode, LLink, Subgraph, GraphInput, GraphOutput, utils, types) have coverage thresholds:

bash
pnpm test:coverage

The thresholds are lines/statements ≥ 70%, branches ≥ 60%, functions ≥ 66%. Add tests for new branches; if you change the serialization format, update the example snapshots first and explain why.

Tests follow a custom minitest style:

ts
import { expect } from "vitest";
import UnitTest from "./UnitTest";

export default class MyTests extends UnitTest {
  test__category__shouldDoSomething() {
    expect(1 + 1).toBe(2);
  }
}

Export the class from packages/tests/src/testSuite.ts and main.ts registers it; __ in method names becomes a describe group.

Specs and changes (OpenSpec) ​

Any change to observable behaviour (new nodes, API or serialization changes, interaction tweaks) starts as a plan under openspec/changes/<change>/ before code is written:

  1. Have your agent load the openspec-propose skill (in DSH, just describe the requirement) to generate proposal.md, specs/, design.md and tasks.md;
  2. Review the requirements and scenarios; use openspec-explore first when the direction is still open;
  3. Implement and tick the tasks.md items, and include the change directory in the PR;
  4. After merge, archive it with pnpm dlx @fission-ai/openspec@2.2.0 archive <change>; delta specs are merged into openspec/specs/.

Pure refactors, tooling and doc fixes may skip specs, but the change's .openspec.yaml must then set skip_specs: true.

bash
pnpm spec:list                       # in-flight changes + existing specs
pnpm spec:validate                   # structural validation (CI uses --strict)
pnpm spec:view                       # terminal dashboard
pnpm dlx @fission-ai/openspec@2.2.0 show <change>     # inspect one change
pnpm dlx @fission-ai/openspec@2.2.0 archive <change>  # archive and merge specs

Only openspec/ is committed; install the agent skills on your machine with pnpm dlx @fission-ai/openspec@2.2.0 init --scope global --tools dsh (written to ~/.agents/skills by default) and keep them out of the repo. Spec bodies are written in Simplified Chinese, while structural headings (## Requirements, ### Requirement:, #### Scenario:) and the SHALL/MUST keyword stay in English (see openspec/config.yaml). The OpenSpec CLI requires Node ≥ 22.20; Node 18 is still enough for code-only work.

Documentation ​

Docs are bilingual (Chinese and English):

PathLanguage
docs/guide/*.md, docs/index.mdSimplified Chinese
docs/en/guide/*.md, docs/en/index.mdEnglish
docs/nodes/*.md, docs/en/nodes/*.mdGenerated by a script; do not edit by hand
docs/api/*.mdGenerated by Typedoc; not committed (generated at build time)

When you change docs, update both language versions and keep code blocks, links and table structure in sync. Then run:

bash
pnpm docs:build    # generate the node catalog + API docs + VitePress build

If you only changed node source, remember to run pnpm docs:nodes and commit the generated catalog; CI's pnpm docs:nodes:check verifies that the output matches the source.

Commits and PRs ​

  • Use Conventional Commits: feat: / fix: / test: / docs: / style: / chore:;
  • One thing per PR; keep formatting or rename changes separate from feature changes;
  • Explain the motivation, behaviour changes and verification method in the PR description;
  • CI must be green: lint → typecheck → test → test:coverage → nullcheck → build → size → verify-umd → verify-pack → demo:smoke → docs:build, plus the separate specs job (pnpm spec:validate on Node 22).
  • After merging to master, the deploy job builds dist/ and pushes it to the gh-pages branch once checks pass. The site root is /litegraph/, docs live at /litegraph/docs/ (Chinese) and /litegraph/docs/en/ (English), and the demo at /litegraph/demo/.

Roadmap ​

The release plan and acceptance criteria for each phase live in ROADMAP.md at the repo root. v0.1–v0.4 are done; next comes feature completion (touch, undo/redo, WebGL, i18n, auto layout) and the v1.0 release.

Released under the MIT License.