Repository-wide rules for the Bespoke-powered linear algebra playground. Read
this file first, then the nested AGENTS.md files (client/, client/core/,
client/modes/) before touching code in those areas.
BESPOKE.md– canonical Bespoke framework contract (HTML slots, CSS variables, component semantics). Never overridebespoke.css; scope changes in app-specific styles.client/help-content-template.html– authoritative help markup that new sections must clone.CLAUDE.md– product primer; keep it aligned with these AGENTS notes.
- Education-focused web app served by
server.js; static assets live underclient/. No build step. - Three interaction modes share services in
client/coreand controllers inclient/modes: vector canvas, matrix transformer, and 3D tensor explorer. - Mode availability is config-driven (
config.json.enabledModes); mode buttons render dynamically viaModeManagerand content for disabled modes is hidden. - Status messaging, help modal, theming, coordinate system, and logging are all centralized services; do not reimplement per feature.
server.js– static file server +/messageWebSocket broadcast (requiresws) +/logendpoint that appends tologs/user_actions.log.client/– HTML, CSS, runtime JS, logger, WebSocket + help bootstrap. Seeclient/AGENTS.md.client/core/– shared services (ConfigService, ModeManager, CanvasTheme, StatusService, HelpService, CoordinateSystem, Vector class, utilities).client/modes/– controllers for vector/matrix/tensor modes plus sidebar, canvas, operations, and 3D renderer (tensor-canvas-3d.js). Destroy listeners indestroy(). Details inclient/modes/AGENTS.md.client/entities/matrix.js– immutable 2×2Matrixmodel.BESPOKE.md,CLAUDE.md,README.md,refactoring.md– guidance only; do not contradict AGENTS contracts.- No AGENTS files are required under
logs/or other data-only folders.
- Optional deps (needed for WebSocket hub + curl broadcast demo):
npm install. - Start server:
npm start(ornpm run dev, both callnode server.js). - App lives at
http://localhost:3000. Manual exercise only; no automated tests exist. - WebSocket broadcast check (requires
ws):
curl -X POST http://localhost:3000/message -H 'Content-Type: application/json' -d '{"message":"Hello"}' - Logging check: POST to
/logor calllogAction(); entries append tologs/user_actions.log.
- Status strings: Only use
"Ready","Loading...","Saving...","Changes saved","Save failed (will retry)","Error: failed to [OPERATION]","Auto-save initialized". Route all updates throughwindow.StatusService. - Async safety: Wrap every fetch/WebSocket/localStorage call in try/catch,
console.errorfailures, and fall back toStatusService.setReady()after recovery. Implement retry loops for save workflows and surfaceQuotaExceededErrorwhen touching localStorage. - Config: Fetch
client/config.jsonviaConfigService. Treat the returned object as immutable (it isObject.freezed inlinear-algebra.js). Validate operation groups withOperationSchemas.validateOperationGroupsbefore binding UI or enabling controls. - Mode lifecycle: Register modes with
ModeManager.registerMode(name, factory)and switch viaModeManager.setMode(). Factories must return an object exposingdestroy()to remove DOM/canvas listeners and unsubscribe fromCanvasThemeService. - Logging: Use the global
logAction(message)helper. It POSTs to/logand intentionally swallows errors; do not block UX on logging failures. - Help modal: Bootstrap through
HelpService.initializeHelpModal({ triggerSelector: '#btn-help', theme: 'auto' }). Mode-specific sections must callHelpService.appendHelpContentand follow the template structure. - Theme + canvas:
CanvasThemeService.init(STYLE_CONSTANTS)already runs inlinear-algebra.js. Subscribe viaCanvasThemeService.subscribeto refresh renderers when system theme flips; propagate colors toCoordinateSystemand per-mode canvases. - HTML contract: Keep
<body class="bespoke">. Preserve script order as inclient/index.html:help-modal.js→logger.js→ core services (status.js,config.js,operation-schemas.js,help.js,mode-manager.js,color-utils.js,theme-service.js,results-panel.js,format-utils.js,vector.js,animator.js,coordinate-system.js) →app.js→ entities (entities/matrix.js) → mode scripts (vector-*,matrix-*,tensor-*) →linear-algebra.jsentrypoint. New shared utilities belong with the core block; new modes load with other mode scripts. - Bespoke snapshot: Follow the Bespoke-specific rules listed in
the user instructions and
BESPOKE.md.
client/AGENTS.md– HTML shell, asset order, runtime bootstrap, logging, and WebSocket details.client/core/AGENTS.md– shared service APIs and invariants.client/modes/AGENTS.md– vector/matrix orchestration, UI bindings, canvas rendering, teardown patterns. Always read the root-to-leaf chain relevant to your change before editing.
- Server hardens path traversal; keep files under
client/. Do not add dynamic endpoints without updating this doc. /logaccepts arbitrary JSON; never trust user input elsewhere. Only log sanitized strings.