Merlin Terminal Challenges

Back to API Overview

A terminal challenge combines learner instructions, an embedded Merlin Terminal, an optional shell startup script or shell service, and an assessment when the exercise is graded. This guide connects those pieces from authoring through publication and student use.

Terminal means the client-side interface: the merlin-terminal component, its controls, and the input and output it displays. Shell means the server-side execution environment and its infrastructure: shell sessions, pods, the shell gateway, startup scripts, and shell services. Selecting Connect in the terminal creates a shell session. API identifiers and directive options keep their exact names.

For session and protocol implementation, see Shell Access and Shell WebSocket Interaction. For the general lesson and assessment lifecycle, see Content Models and Authoring.

Choose the Exercise Environment

Requirement Authoring choice
An interactive command prompt Embed merlin-terminal; no startup script or service is required.
Prepare learner-visible files or set shell variables Add a version-pinned shell startup script.
Provide a separate application or database with challenge-specific data Select an existing shell service content registration.
Open that service in a browser tab Select a browser-attachable definition version and explicitly enable the terminal’s browser button.
Grade an answer or explanation Create a challenge variant and configure its evaluation strategy separately.

A startup script executes in the learner’s shell and is readable under the learner’s file permissions. It is suitable for setup, not for hiding answers or server credentials. A shell service runs separately from the interactive shell; its program and content files are not mounted into the learner’s shell.

Prerequisites and Responsibilities

The viewing application must support the merlin-terminal MyST directive, load the component, and supply authentication and the asserted realm at mount time. Authors do not put JWTs or realm assertions in lesson Markdown. The component does not create a shell session on page load or preview: the learner must select Connect. Missing authentication or realm context prevents connection.

Authorization depends on the actual grants in the selected realm. Use the endpoint privileges map to check each operation; the responsibilities below describe the current role model.

Actor Responsibilities and permissions
Platform operator Publishes vetted service definitions; holds /shell-service/definition/write. Uploads service content into their own asset zone and creates or updates registrations with realm-scoped /shell-service/content/write.
Instructor Authors lessons and assessments; lists and reads existing registrations with realm-scoped /shell-service/content/list and /shell-service/content/read. Selects registrations rather than creating them.
Learner Connects with self-scoped /shell/access; additionally needs self-scoped /shell-service/use when a service is requested, and file-read permission when a startup script is requested.

The action suffixes above belong to urn:ayode:privilege-action:. Asset uploads also require the applicable file-system access/create/write privileges; service registration privileges do not grant asset-writing permission.

Public is the service-definition catalog. Members can discover its definitions, but Public membership does not grant content-registration or service-use permissions there. Register content in the teaching realm where the shell session will run. That registration can pin a readable Public-catalog definition. For publication, the registration must also belong to the lesson’s course realm; do not assume moving a lesson or selecting another realm relocates registrations.

Embed the Terminal

The minimal MyST embed is:

:::{merlin-terminal}
:::

These options are independent except where noted:

Option Value and meaning
:startup-script: An asset pathname and explicit positive version, such as challenges/file-count/start.sh@1. The shell sources this script before becoming interactive.
:startup-script-owner: The script owner’s user EID, as a UUID or urn:ayode:user-eid:<uuid>. Without it, the component uses the signed-in user’s asset zone. Requires :startup-script: to have an effect.
:service: The bare UUID of a content registration, not a definition UUID or name. The component passes it as contentRegistrationEID when creating the shell session.
:service-browser-button: Exactly true to request the browser-tab control. Requires a service whose pinned definition version is browser-attachable. Omit for terminal-only services.

Startup Script Ownership and Versions

Upload the script with writeAssetV2 and record the returned version; use headAssetV2 when checking an existing asset. Uploading identical bytes can return the existing version, so do not assume every upload increments it.

The component expands the authored reference into startupScript fields realmEID, userEID, pathname, and version. It takes the realm from the viewing application. The owner option changes the user, not the realm: this embed does not provide a cross-realm script option.

The generic file-read check allows one’s own script through self-scoped /file-system/file/read, or another owner’s script through realm-scoped file-read authorization. If that check fails, the platform also checks whether the caller is an actively enrolled student reading content under the publishing instructor’s published lesson directory. Place a shared instructor-owned startup script within that published content directory and set the owner option; an arbitrary file elsewhere in the instructor’s zone does not gain this access.

This enrollment-based fallback covers the published directory, not only the single script named in the embed. Keep private grading material outside it. Verify the published exercise as a student before assigning it broadly; instructor preview alone does not prove the student’s read authorization. Alternatively, arrange a readable copy in each learner’s own zone and omit the owner option; the embed does not perform that copy.

The script is sourced into the interactive shell. Avoid exit, which would end that shell, and make setup repeatable without overwriting saved learner work. Uploading a newer script does not change an existing @version reference; update the reference and publish a new lesson version when adopting it.

Prepare and Select a Shell Service

There are three distinct artifacts:

Artifact Contains Selected by
Service definition version Vetted program, launch command, port, content contract, and browser-attachment capability Operator when registering content
Content registration Challenge-specific content snapshot plus a pinned definition version Instructor in :service:
Shell session Copies of the program and content pinned when the session is created Learner selecting Connect

An operator follows this sequence:

  1. Discover and inspect the definition using listShellServiceDefinitionsV2 and readShellServiceDefinitionV2. Read its contentContract, connection details, and browser capability.
  2. Prepare the files required by that particular service and upload them into a directory in the operator’s own asset zone in the teaching realm.
  3. Call createShellServiceContentRegistrationV1 with a unique registration name, the content-root path, and the definition UUID, preferably with an explicit @version.
  4. Give the instructor the returned registration externalID. Instructors can also discover it with listShellServiceContentRegistrationsV2 and inspect it with readShellServiceContentRegistrationV2.

For example, the registration request body has this shape. Replace the example definition UUID and version with the selected catalog entry:

{
  "definitionEID": "a1b2c3d4-e5f6-7890-abcd-ef1234567890@1",
  "name": "database-records-practice",
  "contentRootUserPath": "/challenges/database-records"
}

API calls require Authorization and X-Ayode-Asserted-Realm-EID; see Security and Authorization. Registration writes remain v1; v2 reads expose definitionBrowserAttachable.

Content manifests allow at most 256 files, 8 MiB total, and 4 MiB per file. Individual services can impose smaller limits and stricter formats. The API’s contentContract describes the format; the service program enforces it. A successful registration alone does not prove that the service can start.

Updates and Reset Behavior

Registration pins the current file versions and a definition version. A bare definition UUID selects its latest version at registration time. Later file uploads or definition releases do not silently replace those pins. An operator must explicitly update the registration to adopt changes.

A registration itself can be updated under the same externalID. Future shell sessions then use the updated registration; sessions already created keep their own snapshots. For an exercise revision that must leave older lessons using their original service content, create a new registration and publish the new reference rather than updating the shared registration.

Service data is a per-session copy. Mutable database contents reset when a new shell session starts; reconnecting does not resume the old service state. This does not imply that files in the learner’s permanent shell storage are reset.

Terminal Access and Browser Access

Service Content contract and connection
Static site server (static-site-server) Static files, with index.html fallback; terminal access at http://127.0.0.1:8000/. No browser attachment.
Anonymous FTP server (anonymous-ftp-server) A nonempty ftp/ subtree, served read-only at /pub; terminal access on 127.0.0.1:8021.
Seeded MariaDB server (seeded-mariadb) A data-only seed.json; terminal access on 127.0.0.1:8306 using an account from that file.
Browser-attachable static site server (browser-static-site) Static files; / serves index.htm, with no index.html fallback. Use the terminal’s authenticated browser-tab control.

Check the selected definition version for its current contract. The browser-static-site definition documents that its listener is reachable from other pods because network-policy enforcement is absent; use only non-secret exercise content with that definition. Browser authentication does not remove that separate exposure.

While a service starts, the terminal shows output but holds learner input until the shell gateway reports readiness, failure, or timeout. A connected WebSocket or shell prompt alone does not prove the service is ready. On failure or timeout, the terminal releases input with a warning and keeps the browser button hidden.

Browser access requires both :service-browser-button: true and a pinned browser-attachable definition version. After service readiness, the component obtains a one-time browser redemption URL and uses it to establish the scoped service cookie. The option controls the browser affordance; it does not grant permission, make a terminal-only service browser-attachable, or control whether the service starts. See Shell Access.

Worked Examples

The UUIDs below are placeholders. Substitute real user or registration EIDs; the service examples each require a separate registration in the lesson’s course realm. Publish and assess each example using the following section.

1. Count Files with a Startup Script

Prerequisites: shell access and a readable, pinned startup asset. For a self-owned exercise, upload these bytes to each participant’s challenges/file-count/start.sh, record its version, and use that version in the embed. An instructor-owned asset instead needs the owner option and the student read authorization described above.

# This script is sourced; return to the prompt after preparing temporary data.
challenge_dir=$(mktemp -d /tmp/merlin-file-count.XXXXXX)
printf 'alpha\n' > "$challenge_dir/first.txt"
printf 'beta\n' > "$challenge_dir/second.txt"
printf 'notes\n' > "$challenge_dir/notes.log"
cd "$challenge_dir"
printf 'Count the .txt files in this directory, then submit the count.\n'
Count the `.txt` files in the starting directory and submit the count.

:::{merlin-terminal}
:startup-script: challenges/file-count/start.sh@1
:::

After Connect, pwd should show the temporary exercise directory and find . -maxdepth 1 -name '*.txt' | wc -l should return 2. A fresh session creates a new temporary directory. Grade the submitted count with a sync text-equivalence variant accepting 2; terminal output is not itself a submission.

2. Query a Seeded MariaDB Service

Prerequisites: an operator-provided registration pinned to seeded-mariadb, student shell/service-use privileges, and the following complete seed.json uploaded at /challenges/database-records/seed.json in the registrant’s zone:

{
  "format": "seeded-mariadb-content/v1",
  "schemas": [{
    "name": "practice",
    "tables": [{
      "name": "records",
      "columns": [
        {"name": "id", "type": "int"},
        {"name": "label", "type": "varchar", "length": 64}
      ],
      "primaryKey": ["id"],
      "rows": [[1, "cedar"], [2, "maple"]]
    }]
  }],
  "accounts": [{"user": "learner", "password": "Practice1pw"}],
  "grants": [{
    "account": "learner",
    "privileges": ["SELECT"],
    "schema": "practice",
    "table": "records"
  }]
}

Use the registration procedure above, then substitute its returned externalID:

Connect, then run `mysql -h 127.0.0.1 -P 8306 -u learner -p practice`.
Enter the exercise password `Practice1pw`. Query `records` and submit the
label of the row whose `id` is `2`.

:::{merlin-terminal}
:service: b2c3d4e5-f6a7-8901-bcde-f12345678901
:::

Wait for service readiness. SELECT label FROM records WHERE id = 2; should return maple; an UPDATE should be denied by the account’s SELECT-only grant. Use 127.0.0.1, not localhost, because the client otherwise attempts a Unix socket that is not available in the interactive shell. A fresh session seeds the original rows again. Configure a sync variant accepting maple.

The password is an intentionally disclosed exercise credential, never a platform credential. The content contract accepts data and bounded grants, not arbitrary SQL, shell commands, plugins, or administrative privileges.

3. Inspect a Browser-Accessible Site

Prerequisites: a registration pinned to a browser-attachable browser-static-site version and student shell/service-use privileges. Upload this non-secret teaching fixture as /challenges/page-title/index.htm in the registrant’s zone:

<!doctype html>
<html lang="en">
  <head><meta charset="utf-8"><title>Orchard Observatory</title></head>
  <body><h1>Welcome</h1><p>Inspect this page's document title.</p></body>
</html>

Register /challenges/page-title, then use the returned registration EID:

Connect and open the service in a new browser tab. Submit the document title.

:::{merlin-terminal}
:service: c3d4e5f6-a7b8-4901-acde-f12345678902
:service-browser-button: true
:::

After readiness, use Open new browser tab for service. The page should load and its title should be Orchard Observatory; configure a sync variant accepting that text. Naming the fixture only index.html produces a 404 at / for this definition. A new session has a new service copy and requires its own browser access; do not publish a previous session’s service URL in the lesson.

Publish, Assign, and Assess

Embedding a terminal provisions an interactive experience; it does not create a graded challenge, capture commands as attempts, or automatically inspect shell state. Decide what the student must submit and configure that assessment explicitly.

  1. Create the lesson, mission, challenge, and challenge variant using the authoring workflow. Put the terminal exercise instructions in the lesson asset and configure the variant’s prompt to request the corresponding answer. For the examples above, use evaluationStrategy: sync with a text-equivalence responsesJSON such as:

    {
      "version": 1,
      "evaluationMode": "textEquivalence",
      "acceptedResponses": ["2"]
    }
    

    Replace 2 with the answer for the chosen example. Keep accepted answers in the server-side evaluation configuration, outside learner-facing lesson text. Use a supported AI evaluation strategy when the required submission is an explanation; see Evaluation Strategies. Do not infer automatic shell-state grading from the presence of a service.

  2. Upload the lesson asset and create a lesson variant pinned to its explicit asset version. Publish it with the required challenge bindings using createLessonPublicationV2. Every :service: reference in the published lesson must resolve to a valid registration in the lesson’s course realm whose definition is not retired. Invalid references reject the entire publication with 422 UnprocessableEntity_UnpublishableShellServiceReference.
  3. Release the lesson, then create an assignment for the section with a grading entry for every published challenge. Follow publishing and assigning for bindings, weights, lifecycle status, and realm constraints.
  4. Test as a learner in the actual viewing realm: open the assigned lesson, connect the terminal, complete the exercise, and submit through the challenge response interface. API clients use createChallengeAttemptV2 and retrieve the resulting grade. Verify both a correct and incorrect answer.
  5. Disconnect, start a fresh shell session, and confirm the example’s reset behavior. Verify that a learner without shell-service-use permission cannot launch a service-backed session.

Retiring a definition prevents new publication references; it does not retroactively invalidate an existing publication’s service pin. Separately, updating a registration can affect future sessions under its existing EID as described in Updates and Reset Behavior.

Troubleshooting

Symptom Check
Connect unavailable Host authentication and asserted realm; lesson Markdown cannot supply them.
Startup-script connection denied Script version, owning user, asserted realm, and either file-read privileges or the enrolled student’s access to the published lesson directory.
Conflict_ShellSessionAlreadyActive The user already has a shell session. Disconnect it and wait for the terminal control to become available before reconnecting.
Service connection denied Registration realm matches the session realm, and the learner holds /shell-service/use as well as /shell/access.
Service failed or timed out Validate its content format and pinned definition version. A missing readiness check requires an operator to publish a supported definition version and update the registration.
Browser button absent Explicit true option, definitionBrowserAttachable on the pinned version, successful readiness, and successful browser authorization. Terminal-only services intentionally have no button.
Browser service root returns 404 The browser static-site fixture needs index.htm, not just index.html.
Uploaded changes do not appear Check the script’s @version or the registration’s pinned manifest; upload alone does not update a pin.
Publication rejected Inspect the offending references in the 422 response; resolve missing, malformed, wrong-realm, or retired service references before retrying.