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
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
| Location | Constraint |
|---|---|
packages/core | Must 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/litegraph | Aggregate 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/tests | Cross-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
pnpm new-node math Square --title "Square" --desc "Squares its input"The script will:
- create
packages/nodes-math/src/Square.ts(modern style based onslotLayout); - append an import and
registerNodeType({ class, title, desc, type })to the end ofsrc/install.ts; - add
export { default as Square }tosrc/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
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
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:
pnpm test:coverageThe 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:
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:
- Have your agent load the
openspec-proposeskill (in DSH, just describe the requirement) to generateproposal.md,specs/,design.mdandtasks.md; - Review the requirements and scenarios; use
openspec-explorefirst when the direction is still open; - Implement and tick the
tasks.mditems, and include the change directory in the PR; - After merge, archive it with
pnpm dlx @fission-ai/openspec@2.2.0 archive <change>; delta specs are merged intoopenspec/specs/.
Pure refactors, tooling and doc fixes may skip specs, but the change's .openspec.yaml must then set skip_specs: true.
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 specsOnly 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):
| Path | Language |
|---|---|
docs/guide/*.md, docs/index.md | Simplified Chinese |
docs/en/guide/*.md, docs/en/index.md | English |
docs/nodes/*.md, docs/en/nodes/*.md | Generated by a script; do not edit by hand |
docs/api/*.md | Generated 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:
pnpm docs:build # generate the node catalog + API docs + VitePress buildIf 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 separatespecsjob (pnpm spec:validateon Node 22). - After merging to
master, thedeployjob buildsdist/and pushes it to thegh-pagesbranch 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.