Skip to content

CSE Machine Plugin#28

Open
Akshay-2007-1 wants to merge 11 commits into
mainfrom
feat/cse-machine
Open

CSE Machine Plugin#28
Akshay-2007-1 wants to merge 11 commits into
mainfrom
feat/cse-machine

Conversation

@Akshay-2007-1

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

Copy link
Copy Markdown

Depends on Conductor PR by @Shrey5132.
Depends on #25

Summary

Adds three new installable packages that implement the language-agnostic CSE (Control–Stash–Environment) machine plugin pair for the Conductor framework.

Packages

@sourceacademy/common-cse-machine
Shared protocol — channel ID, plugin IDs, and the CseSnapshot / CseSerializedEnvFrame / CseSerializedValue type hierarchy. Everything that crosses the __cse channel must be structured-clone-able JSON; all language evaluators serialise into these shared shapes.

@sourceacademy/runner-cse-machine
Worker-side plugin. Exposes CseMachinePlugin.sendSnapshots(snapshots) which a language evaluator calls after collecting its steps. Sends a single CseSnapshotMessage over the __cse channel.

@sourceacademy/web-cse-machine
Host-side plugin. Subscribes to the __cse channel and delivers received snapshots to the host app via a receiveSnapshots callback. The host app wires this to its own rendering layer.

TODO : In the future, we should be moving the entire Frontend and the Konva visualisation layer into this host plugin and aim to make it external!

Design notes

  • All three are installable plugins — the runner and web sidlementations live in each language evaluator repo and thefrontend respectively. (The host should be made EXTERNAL soon)
  • The common package is the single source of truth for the sna three diverged copies that previously existed across js-slang, py-slang, and the frontend.
  • Language evaluators currently depend on this via portal: lo published npm versions once this PR merges.

Akshay-2007-1 and others added 6 commits June 17, 2026 12:32
…ages

Local checkpoint (plugins remote is upstream; fork/push when opening the PR).

- common/cse-machine: language-agnostic CSE machine protocol — channel/plugin/
  directory ids, the snapshot-message type, and the consolidated CseSnapshot
  schema (superset of the previously-duplicated copies in py-slang, js-slang and
  the frontend: includes heapObjects, isOnCallStack, isConst, currentLine)
- runner/cse-machine: abstract CseMachinePlugin that forwards a run's CseSnapshots
  over the __cse channel; per-language serialization stays in the evaluators
- both build (rollup -> cjs/mjs/d.ts) and pass jest

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Local checkpoint.

- web/cse-machine: CseMachineHostPlugin subscribes to the __cse channel and hands
  each received CseSnapshot batch to the host via receiveSnapshots. Transport only,
  no UI deps — the adapter + Konva visualizer stay in the frontend for now
  (deferred extraction), so this plugin is small and language-agnostic.
- re-exports the common-cse-machine protocol types for host convenience.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Mirrors the Jest → Vitest migration done in main (PR #27):
- Remove jest, ts-jest, @types/jest from all three packages
- Add vitest (+ @vitest/coverage-istanbul for test packages)
- Update test/test-coverage scripts to use vitest run
- Delete jest.config.cjs from common and runner packages
- Remove "types": ["jest"] from tsconfigs
- Add explicit vitest imports to test files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Akshay-2007-1 Akshay-2007-1 self-assigned this Jun 17, 2026
@changeset-bot

changeset-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6be569d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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

Copy link
Copy Markdown

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 three new packages to support a language-agnostic CSE (Control-Stash-Environment) machine plugin pair: @sourceacademy/common-cse-machine for shared protocol types, @sourceacademy/runner-cse-machine for sending snapshots, and @sourceacademy/web-cse-machine for receiving snapshots. The feedback identifies potential runtime crashes in both the runner and web plugins if the cseChannel array is empty during initialization, and suggests adding defensive checks to handle this safely.

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 thread src/runner/cse-machine/src/index.ts
Comment thread src/web/cse-machine/src/index.ts
Akshay-2007-1 and others added 2 commits June 17, 2026 19:39
@Akshay-2007-1

Copy link
Copy Markdown
Author

@coderabbitai, any comments?

@coderabbitai

This comment was marked as resolved.

@AaravMalani AaravMalani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mostly LGTM, just want a couple of issues addressed before I approve

Comment thread src/common/cse-machine/src/__tests__/common.test.ts Outdated
Comment thread src/common/cse-machine/package.json Outdated
Comment thread src/web/cse-machine/src/index.ts Outdated

@AaravMalani AaravMalani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Maybe add a README in this or a future PR?

@Akshay-2007-1

Copy link
Copy Markdown
Author

LGTM! Maybe add a README in this or a future PR?

Shall I add one based on the wiki in this very same PR?
Its not related to just the CSE Machine and is about the overall Plugins in general right? How do we go about this?

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