Skip to content

Embedded Python scripting terminal #387

Open

Description

@Relm-Arrowny

Part of #373 Queue Management & Experiment Control:

Integrate an embedded terminal leverage the BlueAPI Python client for manual scripting and custom acquisition execution.

Goals

Acceptance criteria : What journeys should the user be able to complete to consider your feature done
Be as specific as you can, check them off once they work. Add more if you find more requirements during development. Issue should only be considered done after all of them are checked

  • Power users can write custom plans and command devices manually from an embedded command-line interface.
  • Interactive Web Terminal Workspace: Users can open a dockable/collapsible command-line panel inside the UI with full keyboard navigation, copy/paste support.
  • Pressing Tab inside the embedded terminal auto-completes blueapi plan names, device names (stage_x, stage_y), and detector and PV.
  • Pre-Authenticated Session: Users can run plans and command devices via blueapi.client Python session without requiring manual connection setup or boilerplate imports
  • Streaming Output: Execution logs, stdout, stderr, print emitted data, tracebacks, and plan status updates render in inside the terminal.
  • Error Message: Provide useful error reporting including device level error with a stack trace.
  • State Synchronization: Plans executed from the terminal update scan numbers, register on the main acquisition progress bar, and stream live scan data to the plot canvas.
  • Persistent Command History: Command history (up/down arrow navigation and search) is stored per visit and automatically restored across browser reloads or workspace sessions.
  • Useful help function: Ensure all functions and devices have useful doc strings accessible via the help command (e.g. scan -h).
  • Execution Safety: The terminal restricts issuing conflicting manual hardware movement commands while a BlueAPI queue plan is actively executing.

Tasks

base on the goals, deduce the tasks required. check them off once they're done

Caution

Should this interact with Blueapi or the queue?

  • BlueAPI/Queue Client integration: Terminal inputs and outputs directly through the BlueAPI python client or via block/queue.
  • Embedded Terminal Widget: Integrate a terminal widget within the main UI workspace.
  • Does it really have to be two in one?
  • Does it has to be a web terminal?

Related Resources

Current CLI from BlueAPI: It is worth mentioning that the current CLI met 80% of our requirement and we have wrapped into a ipython terminal together with our cli #406

Bluesky magic: Bluesky kind of has some magics for plans already https://blueskyproject.io/bluesky/v1.14.2/magics.html
Bluesky also offer persistent dictionary: https://blueskyproject.io/bluesky/v1.14.2/generated/bluesky.utils.PersistentDict.html

Current thinking from the UI team Server side Jupyter Enterprise Gateway

Image

Screen shoot of Emily slide
Image

Activity

  1. changed the title [-]Integrate an embedded Python terminal with BlueAPI client support to drive experiments.[/-] [+]Embedded Python scripting terminal[/+] on Sep 9, 2026
  2. NKatti2011 commented on Sep 16, 2026

    @NKatti2011
    Collaborator

    Include notes from meetings with @EmsArnold.

    Architecture is not yet settled. Current expectation is that the terminal sits behind
    the queue and submits to it
    , rather than talking to BlueAPI directly, that keeps a
    single ordering of work and avoids the RunEngine contention problem described in #381.

    Needs confirmation from the DAQ team.

  3. Relm-Arrowny commented on Sep 16, 2026

    @Relm-Arrowny
    CollaboratorAuthor

    Just noting some question I may have running it off queue:
    Running it off the queue raise a different question, how scripting going to work with queue?
    This also change the user experience, you send a command in cli and nothing happen until the queue is empty?
    Do you send a message back cli will only run if queue is empty or we going to put it at the black of the queue?
    How are we going handle the python logic in queue?
    Does scripting just mean program block generation for queue?

  4. NKatti2011 commented on Sep 16, 2026

    @NKatti2011
    Collaborator

    From @jacob-williamson I gleaned that there was no current or future solutions planned for how scripting will work with the queue.

    My own note - scripting does not mean a program block generation for the queue. Scripting and the program block are separate entities. This will likely be hashed out in whatever scripting vertical slice will happen.

  5. oliwenmandiamond commented on Sep 21, 2026

    @oliwenmandiamond
    Collaborator

    The current behaviour when scripting with blueapi client if something else is already running, it returns instantly saying worker is busy. So if a bunch of things are queued up via queue service and running, then scripting wouldn't work anyway. I think we should probably leave this as is, queue takes priority as it will auto submit a job as soon as it becomes free? There would be a tiny edge case where if you try to run something via scripting the moment something becomes free, it could beat the queue service and probably break that.

    Maybe a baton should be added to blueapi? So you have to request to hold the baton before you are allowed to submit anything to blueapi and different services aren't competing to submit to blueapi?

  6. Relm-Arrowny commented on Sep 22, 2026

    @Relm-Arrowny
    CollaboratorAuthor

    Client side solution: Python within WebAssembly(Pyodide)

    Pro

    Deploy and go nothing to worry about as it is running on the client side(no DMZ), but need to config our services to have Cross-Origin Resource Sharing and have a valid ssl certificate.
    May or may not work with blueAPI client as not all library is supported.

    Con

    Sharing anything is difficult, no session, no different from running a local python and make use of blueapi cli.

    • It may be possible to host those script on Git and user can have their own branch and push pull their own branch of script?
  7. Relm-Arrowny commented on Sep 22, 2026

    @Relm-Arrowny
    CollaboratorAuthor

    Server side JupyterHub

    Pro

    • Built-in auth (OAuth/tokens), session management, proxy routing, and automatic pod lifecycle/idle-culling out of the box.
    • Offers both an interactive notebook UI and an embedded bash terminal for scripts and debugging.

    Con

    • Does not isolate untrusted code by default. Still requires a DMZ node pol.
    • Either have share script live inside PVC or create yet another service with api to gatekeep the shared script, it may be possible to host those script on Git and user can have their own branch and push pull their own branch of script.
    • Not sure how you integrate the jupterHub prebuilt into webUI.
    • Resource heavy with all the UI overhead.
  8. Relm-Arrowny commented on Sep 22, 2026

    @Relm-Arrowny
    CollaboratorAuthor

    Server side ttyd

    Pro

    • Very easy to build as a service and ready to use terminal, just like running python locally.

    Cons

    • No Authentication beyond user and password.
    • No Sandboxing
    • ttyd is not stateless. so it require each user to be routed correctly to their own services.
  9. Relm-Arrowny commented on Sep 22, 2026

    @Relm-Arrowny
    CollaboratorAuthor

    Server side xterm.js + Gateway

    Pro

    • xterm built into the UI.
    • Solve the routing issue, auth issue with gateway.

    Cons

    • Need to build and maintain a gateway that track pod life cycle and redirect user traffic to the correct pod.
    • No sandbox.
  10. Relm-Arrowny commented on Sep 23, 2026

    @Relm-Arrowny
    CollaboratorAuthor

    Server side Jupyter Enterprise Gateway

    Pro

    • Barebone light weight version of JupyterHub, pykernel pods on demand without JupyterLab UI.
    • Jupyter Protocol means, support for images PNG, SVG, JSON transmition out of the box.
    • Potentially very simple UI, embed a editor and just run from it.

    Cons

    • No terminal support. (Ipython console via jupyterlab/console possible?)
    • No UI out of the box, has to build every part.
    • No sandbox.
    • No auth out of the box.
    • code cell format only(Jupyter Protocol)
  11. EmsArnold commented on Sep 23, 2026

    @EmsArnold

    For some context, the intended UI implementation will be an app within atlas, which will provide both UI, and integrated data visualisation.

  12. Relm-Arrowny commented on Sep 25, 2026

    @Relm-Arrowny
    CollaboratorAuthor

    We must be doing something wrong, the more we think about terminal and script the more it seem, we reintroducing the original bluesky ux, surely the design is not quite what we want somewhere.

  13. Relm-Arrowny commented on Sep 25, 2026

    @Relm-Arrowny
    CollaboratorAuthor

    I wonder if we should separate these two thing:

    "Terminal" is just a quick command bar for single plan . These can either go through the queue service as "run-next" tasks or use an explicit baton lock. Because it only needs to send one-off commands, this can easily live client-side without we doing any work.

    Scripting: Instead of running an interactive shell, we treat scripts as batch jobs. Users construct them via a block builder or a script editor, which compiles the logic into task and submits it directly to the queue.

  14. Relm-Arrowny commented on Oct 9, 2026

    @Relm-Arrowny
    CollaboratorAuthor

    If JEG is the core team design, when it is ready we will need #411 to covert what we have to run on JEG. And it will effectively complete this issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Decision neededDecision is required before this is ready to be scopedcore dependencyMore needed to know before we can fully scope this work.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions