Skip to content

Run a template's logic in Clojure, with Trustblocks' own runtime - #1

Merged
tbrooke merged 1 commit into
trustblocksfrom
feat/sci-runtime
Sep 28, 2026
Merged

tbrooke merged 1 commit into
trustblocksfrom
feat/sci-runtime

Conversation

@tbrooke

@tbrooke tbrooke commented Sep 28, 2026

Copy link
Copy Markdown

Step 3 of the SCI playground. The playground's TypeScript logic runtime is replaced by Trustblocks' clause runtime: trustblocks-logic.js, built from trustblocks-templates' runtime/. A request gets exactly the answer it gets in Trustblocks, lifecycle and all. Accord's own playground stays the place for TypeScript logic.

Base: trustblocks is Accord's webmcp-poc (so the WebMCP agent relay is kept in the dev build) with Accord's latest main merged in. upstream = accordproject/template-playground, for pulling their updates.

What changes

  • The sandbox runs our runtime.

    • The null-origin iframe receives trustblocks-logic.js as text, once. It still loads no script by URL.
    • It keeps one worker holding the runtime. check, nextSteps and trigger run there, with the same 5-second kill switch; a timed-out worker is replaced.
  • "Compile" is the runtime's check. The clause is built without running, and anything outside the vocabulary is refused. For example, (rand) is refused with Refused by the clause vocabulary: ….

  • "Init" starts with no state and asks the lifecycle what can happen first.

  • "Trigger" is one step, exactly as Trustblocks takes it: the lifecycle, then the clause.

    • The certification is simulated: the first one the transition accepts, and the run says which.
    • The store has a simulateNow; with none set, the step is taken at the current time. There's no UI control for it yet.
    • A lifecycle with no clause (the vendor form) runs too.
  • The Logic step edits clause.clj in Monaco's Clojure mode. The skeleton it builds from model.cto is now a Clojure clause, and it's tested against the real runtime.

  • Samples come from trustblocks-templates. scripts/sync-trustblocks.mjs brings in:

    • the runtime;
    • the 9 templates as samples;
    • the shared models they import (agreement, attestation, usa.state), added to the built-in set;
    • for a template with no request.json, a default request: the first event its lifecycle allows.

    It reads the trustblocks-templates commit pinned in trustblocks.json.

  • Design-v2's start cards are the Contractor Pay Request, the Town Manager Contract and the Vendor Information Form. Design-v2 and logic are on by default. Accord's TypeScript-logic samples stay in the tree, unlisted, so merges from upstream stay clean.

  • GitHub Pages.

    • The base path, router basename, share links, the sandbox URL and public assets all work under /template-playground/.
    • .github/workflows/pages.yml checks out trustblocks-templates at the pinned commit, runs bb logic-bundle, syncs, and fails if the committed samples differ from what that commit gives. Then it runs the unit tests, builds, and deploys on push to trustblocks.
    • Pages is enabled on the repo, deploying from the workflow. I disabled upstream's Build and Publish (Accord's own production deploy) and Stale.
  • Branding: "Trustblocks · Template Playground", described as Trustblocks' fork of Accord Project's playground, with Accord's wordmark as credit. The README says what the fork is.

Tests

  • Unit: 309 of 309 pass. Upstream tests that asserted the TypeScript path were rewritten for the runtime: executionHistory, sandbox, compileLogic, SandboxFrame, logicSource, LogicView and others. The logic skeleton is now checked and run through the real runtime.
  • e2e/trustblocks.spec.ts, run in Chrome with PW_CHANNEL=chrome: 2 of 2 pass.
    • A pay request, refused out of order with InspectionCertified cannot happen before the lifecycle has begun (no-transition), then received under RECEIVE_PAY_APPLICATIONS, then inspected, with the clause recording the approved item.
    • The vendor form, received and then given a vendor number.
  • The production build was smoke-tested under /template-playground/ in Chrome: the runtime loads, the clause is checked, and the refusal reads as in Trustblocks.
  • Typecheck: clean.
  • Lint: the new code is clean. npm run lint fails upstream too; store.ts alone had 23 errors before this change.

Known, and left alone

  • Upstream's drafting engine fetches TypeScript library files from typescriptlang.org's CDN, some of which 404. It's harmless.
  • The WebMCP relay registers its tools twice under React's dev-mode double mount. That's upstream webmcp-poc, dev only.
  • An e2e helper sets the request through a dev-only store hook, because Monaco resists replacing its text by keyboard.

🤖 Generated with Claude Code

The playground's TypeScript logic runtime is replaced by Trustblocks' clause
runtime -- trustblocks-logic.js, built from trustblocks-templates' runtime/ --
so a request gets exactly the answer it gets in Trustblocks, lifecycle and
all. Accord's own playground remains the place for TypeScript logic.

- The sandbox iframe receives the runtime's text once and keeps a worker
  holding it; check, nextSteps and trigger run there, with the same timeout
  kill-switch, and the iframe still loads no script by URL.
- "Compile" is the runtime's check: the clause is built without running,
  and anything outside the vocabulary is refused. "Init" starts with no
  state and asks what can happen first; "trigger" is one step --
  lifecycle, then clause -- with a simulated certification and a
  settable `now`. A lifecycle with no clause (the vendor form) runs too.
- The Logic step edits clause.clj in Monaco's Clojure mode; its skeleton
  from the model is a Clojure clause, tested against the runtime.
- scripts/sync-trustblocks.mjs brings in the runtime and Trustblocks'
  templates as samples, from the trustblocks-templates commit
  trustblocks.json pins, and bundles the shared models they import.
  Design-v2's start cards are the pay request, the Town Manager contract
  and the vendor form. Accord's TypeScript-logic samples stay in the tree,
  unlisted, for easy merges from upstream.
- GitHub Pages: base path, router basename, share links and public assets
  work under a sub-path; .github/workflows/pages.yml builds the runtime and
  samples from source, tests, and deploys.
- Branded as Trustblocks' fork of Accord Project's playground.

Tests: upstream's unit tests rewritten where they asserted the TypeScript
path (309 pass); e2e/trustblocks.spec.ts drives a pay request and the
vendor form through their lifecycles in a browser.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@tbrooke
tbrooke merged commit 9ec1f9b into trustblocks Sep 28, 2026
2 checks passed
@tbrooke
tbrooke deleted the feat/sci-runtime branch September 28, 2026 20:14
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.

1 participant