Skip to content

feat(conductor): Source/JS CSE machine evaluators and plugin#2004

Open
Akshay-2007-1 wants to merge 10 commits into
source-academy:masterfrom
Akshay-2007-1:feature/cse-machine-conductor
Open

feat(conductor): Source/JS CSE machine evaluators and plugin#2004
Akshay-2007-1 wants to merge 10 commits into
source-academy:masterfrom
Akshay-2007-1:feature/cse-machine-conductor

Conversation

@Akshay-2007-1

@Akshay-2007-1 Akshay-2007-1 commented Jun 22, 2026

Copy link
Copy Markdown

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: Extends BasicEvaluator to run Source/JS code through the CSE engine. Registers a CseMachinePlugin (from @sourceacademy/runner-cse-machine) and sends a full batch of CseSnapshots 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.

Akshay-2007-1 and others added 4 commits June 16, 2026 23:18
…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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +23 to +27
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,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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);

Comment thread src/conductor/JSCseEvaluator.ts Outdated
Comment thread src/conductor/JSCseEvaluator.ts Outdated
Comment thread src/conductor/SourceEvaluator1.ts Outdated
Comment thread src/conductor/SourceEvaluator1.ts
Comment thread scripts/build-evaluators.mjs
Akshay-2007-1 and others added 5 commits June 22, 2026 15:43
…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>
@coveralls

coveralls commented Jun 22, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 27940446406

Coverage remained the same at 78.53%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 8768
Covered Lines: 7054
Line Coverage: 80.45%
Relevant Branches: 4222
Covered Branches: 3147
Branch Coverage: 74.54%
Branches in Coverage %: Yes
Coverage Strength: 179705.43 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants