Add self-correction loop: logs, call, and shot commands#30
Open
molefrog wants to merge 1 commit into
Open
Conversation
The agent that builds applets could not tell when they broke: a widget compiles, then fails to load in the browser, crashes on render, or its server function throws — and nothing reaches the agent until the user complains. Visual defects were worse: nothing but human eyes caught them. Close the loop with three legs (spec: docs/self-correction.md): - moi logs — a per-workspace, in-memory applet error journal. Server-side producers (RPC failures, build failures) record directly; the browser reports load failures, render crashes (error boundary), and window errors attributed by bundle-URL stack match. Identical errors dedup into a count; a successful rebuild clears the applet's standing entries; `moi bundle` ends with a nudge when errors remain on record. - moi call — invoke a .server.ts function directly through the same worker pool/env/timeout as browser RPC. Args as one JSON array; the result renders through devalue (Map/Set/Date intact) with duration. - moi shot — screenshot a widget (true grid footprint) or view (panel size) through a live workspace tab: offscreen mount inside the themed wrapper, modern-screenshot rasterization, plus box-vs-content render facts as an objective overflow signal. Fails fast when nothing is built or no browser is connected. The scratchpad's pending-map relay generalizes into server/relay.ts with the shot relay as a second instance. The moi-workspace skill grows a "Verify your work" section teaching the loop (bump to 0.5.0). Also replaces a stray literal NUL byte in views.ts with the '\0' escape so the file diffs as text again. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M8rSCv39HrkfaH23tceb2q
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the three-leg self-correction feedback loop for applets, allowing the agent to detect runtime failures, test server functions, and see what applets actually look like without waiting for user feedback.
Summary
Adds three new CLI commands (
moi logs,moi call,moi shot) that close the gap between successful builds and actual runtime behavior. The agent can now:moi logs) — query an in-memory error journal of applet runtime failuresmoi call) — invoke server functions directly through the same worker pool as browser RPCmoi shot) — render applets to PNG through a live workspace tabKey Changes
Server-side error journal (
server/applet-log.ts)build,load,render,window,rpcCLI commands (
server/cli.ts)moi logs [--json] [--clear]— display or clear the error journalmoi call <module>/<fn> '[args]'— invoke a server function with JSON arguments, returns devalue-encoded resultmoi shot widget|view <name>— screenshot an applet at its real grid size (or full panel for views)Browser-side error reporting (
client/lib/applet-log.ts)POST /api/workspaces/:id/applet-logwith per-error cooldown (5s) to prevent stormsApplet screenshot support (
client/lib/applet-shot.tsx,server/applet-shot.ts)modern-screenshotand measures content overflowControl port integration (
server/control.ts)sendScratch→ genericsendControlto handle multiple request typeslogs,call, andshotrequest typesmoi bundleoutput now nudges towardmoi logswhen errors are on recordType definitions (
lib/types.ts)AppletKind—'widget' | 'view'AppletLogSource—'build' | 'load' | 'render' | 'window' | 'rpc'AppletLogEntry— full journal entry shape with dedup countShotRequest/ShotResult— screenshot request/response typesGeneric relay utility (
server/relay.ts)createRelay<Res>scratchpad-relay.ts) and applet shots (applet-shot.ts)Error boundary updates (
client/components/WidgetErrorBoundary.tsx)kind(widget/view) andworkspaceIdfor attributiononErrorcallback for callers like applet shotsRPC error recording (
server/api.ts)moi callto surface issues before the browser sees themhttps://claude.ai/code/session_01M8rSCv39HrkfaH23tceb2q