feat(conductor): Source/JS CSE machine evaluators and plugin#2004
feat(conductor): Source/JS CSE machine evaluators and plugin#2004Akshay-2007-1 wants to merge 10 commits into
Conversation
…lugin Mirrors the local working state from the upstream js-slang checkout onto a forkable branch so it can be turned into PRs. - src/conductor: SourceEvaluator1 + JSCseEvaluator3/4 conductor evaluators, initialise/evaluator entrypoints, and JsCseMachinePlugin (sends CseSnapshots over the __cse channel) - JSCseEvaluator: synchronous for...of snapshot collection with step-limit cap (via /__cse_config__), and currentLine (context.runtime.nodes[0] line) per snapshot for the editor's blue current-line highlight - build tooling: rollup.config.evaluator.mjs + scripts/build-evaluators.mjs (+ evaluator shims) to bundle the IIFE worker evaluators - package.json: @sourceacademy/conductor via portal:../conductor (local) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ackages - Remove JsCseMachinePlugin.ts; types now come from @sourceacademy/common-cse-machine - JSCseEvaluator.ts imports CseMachinePlugin from @sourceacademy/runner-cse-machine - All local CseSnapshot / CseSerialized* type definitions removed (canonical in common pkg) - Uses cast for IPlugin id/name compat until conductor PR merges - Add portal: deps for common-cse-machine and runner-cse-machine in package.json Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces standalone conductor evaluators for the CSE machine (chapters 3 and 4) and Source 1, along with a Rollup build configuration and script to bundle them. The review feedback focuses on improving robustness and cross-platform compatibility. Key recommendations include handling destructuring and default values in closure parameter serialization, adding defensive checks for env.heap and JSON parsing of configRaw, wrapping runFilesInContext in a try...catch block to prevent worker crashes, and executing Rollup via its JS entry point to ensure the build script runs successfully on Windows.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| function serializeValue(v: Value, depth = 0): CseSerializedValue { | ||
| if (v instanceof Closure) { | ||
| const paramNames = v.node.params.map((p: Identifier | RestElement) => | ||
| p.type === 'RestElement' ? '...' + (p.argument as Identifier).name : p.name, | ||
| ); |
There was a problem hiding this comment.
When serializing closure parameters, the current implementation assumes parameters are only Identifier or RestElement nodes. However, in JavaScript/Source, parameters can also be AssignmentPattern (for default values), ObjectPattern, or ArrayPattern (for destructuring). If these patterns are encountered, p.name will be undefined, leading to incorrect serialization or potential visualizer issues. We should use a robust helper function to extract parameter names recursively.
function getParamName(p: any): string {
if (!p) return '?';
switch (p.type) {
case 'Identifier':
return p.name;
case 'RestElement':
return '...' + getParamName(p.argument);
case 'AssignmentPattern':
return getParamName(p.left);
case 'ObjectPattern':
return '{...}';
case 'ArrayPattern':
return '[...]';
default:
return '?';
}
}
function serializeValue(v: Value, depth = 0): CseSerializedValue {
if (v instanceof Closure) {
const paramNames = v.node.params.map(getParamName);…tructor in SourceEvaluator1 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- SourceEvaluator1: wrap evaluateChunk in try/catch, use parseError for errors - JSCseEvaluator: guard env.heap before calling getHeap() - JSCseEvaluator: isolate JSON.parse of cse config with graceful fallback to 1000 - build-evaluators: use rollup JS entry point for cross-platform compatibility Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Coverage Report for CI Build 27940446406Coverage remained the same at 78.53%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
Summary
Adds conductor-based evaluators for Source 1–4 and a JS CSE machine plugin, enabling the CSE machine visualiser to work with Source/JS programs via the Conductor framework.
New files
src/conductor/JSCseEvaluator.ts: ExtendsBasicEvaluatorto run Source/JS code through the CSE engine. Registers aCseMachinePlugin(from@sourceacademy/runner-cse-machine) and sends a full batch ofCseSnapshots to the host after each evaluation.src/conductor/SourceEvaluator1.ts: Thin evaluator for Source 1 (non-CSE chapters) via conductor.src/conductor/evaluator.ts/index.ts/initialise.ts: Entry points and exports for the conductor evaluator bundle.rollup.config.evaluator.mjs/scripts/build-evaluators.mjs: Build configuration for producing the Web Worker evaluator bundles.