This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
A significant part of this AI collaboration is an experiment to teach Claude Code how to develop in Lively4. By working together on real development tasks, we are:
This documentation serves dual purposes: guiding AI development work and creating human-readable documentation of Lively4’s development practices. The demos/claude/
directory contains examples and experiments from this collaborative learning process.
Testing:
npm test
- Run all tests with Karma (single run)npm run test-single <test-file>
- Run single test file with custom test runner (fast, ~8-13s)npm run test-list
- List all available test filesnpm run test-debug <test-file>
- Run tests with debugging (headless=false, devtools enabled)Example:
npm run test-single test/client/strings-test.js
# ✅ 6 tests passed, 0 failed in 0.01s
Development:
npm run explore-lively4
- Explore the Lively4 codebase programmaticallynpm run explore-lively4:debug
- Same as above with debug output enabledIn-Browser Development:
Lively4 System: Self-supporting browser-based development environment using:
Morph
(from src/components/widgets/lively-morph.js
)src/plugin-babel.js
initialize()
, connectedCallback()
, livelyExample()
, livelyMigrate()
Module System:
src/systemjs-config.js
defines transpilation rules per file patternliveES7
, moduleOptionsNon
, aexprViaDirective
, workspace
lively.reloadModule(path)
updates JS and templates at runtimesrc/client/morphic/component-loader.js
Central API (src/client/lively.js
):
lively.create(tagName)
- creates web componentslively.openComponentInWindow(name)
- opens components in windowslively.components.loadByName(name)
- loads component definitionslively.files.loadFile()
, lively.files.saveFile()
- file operations through lively4-serverDirectory Structure:
src/components/
- Web components (tools/, widgets/, demo/, halo/)templates/
- Reusable component templatessrc/client/
- Core runtime and utilities (lively.js, boot.js, etc.)src/external/
- Third-party librariestest/
- Test files (Karma + Mocha)doc/
- Documentation and project notesComponent Development Pattern:
templates/my-component.html
+ templates/my-component.js
Morph
and follow this structure:export default class MyComponent extends Morph {
async initialize() {
this.windowTitle = "Component Title";
this.registerButtons(); // auto-registers onButtonName handlers
lively.html.registerKeys(this); // auto-registers onKeyDown handlers
}
livelyExample() {
// Customize instance with example content
}
livelyMigrate(other) {
// Handle live updates during development
this.someProperty = other.someProperty;
}
}
Template Pattern (HTML):
<template id="my-component">
<style data-src="/templates/livelystyle.css"></style>
<style>/* component-specific styles */</style>
<div id="content">
<button id="myButton">Click Me</button>
</div>
</template>
Container System: lively-container
(src/components/tools/lively-container.js
)
Event System: Use lively.addEventListener()
for proper cleanup:
lively.addEventListener("myId", this, "click", evt => this.onClick(evt))
// Automatically cleaned up with lively.removeEventListener("myId", this)
Component Access:
this.get("#selector") // querySelector in component and shadowRoot
await lively.openComponentInWindow("component-name")
lively.components.searchTemplateFilename()
to locate templates programmaticallylivelyExample()
method to provide example content for componentsdemos/claude/
directory to avoid cluttering main demosScript Integration in Markdown Files:
import lib from 'https://cdn.example.com/lib.js'
lively.query(this, "lively-markdown")
markdownComponent.shadowRoot
for proper DOM scopingdoc/journal/
as directories named YYYY-MM-DD.md/
containing index.md
- [ ]
and - [x]
for task lists (renders as checkboxes)[filename](edit://path/to/file)
syntax for direct editing (not in code blocks)