The iframe preview sandboxing service is now maintained as a separate
project at https://gitlab.com/soapbox-pub/iframe.diy and deployed at
https://iframe.diy/. Remove the stale in-tree copy and update the
services README to point to the upstream project.
Each built-in shell command has been audited and rewritten to support the
options AI agents (and humans) typically reach for, close critical behavior
gaps, and align with POSIX/GNU conventions:
- Shared argument parser (utils.ts) handles combined short flags, long
options with '=VALUE' or space-separated values, the '--' sentinel,
numeric shortcuts like 'head -5', and '-' for stdin.
- cat, ls, cp, mv, rm, mkdir, touch: added missing common flags; removed
the legacy 'absolute paths are not supported' and 'reading from stdin
is not supported' barriers where they made agent use awkward.
- mv now overwrites destinations by default (POSIX) and supports -n.
- touch updates mtime on existing files (by rewriting content) and
accepts -c/-a/-m/-h/-r/-d/-t options.
- find: new expression engine with -iname, -path, -regex, -type,
-empty, -size, -maxdepth, -mindepth, -not, -or, -print/-print0,
-delete, -quit.
- grep: -v, -c, -l, -L, -w, -x, -o, -q, -E, -F, -G, -H, -h, -A/-B/-C
context, --include/--exclude, multiple -e, -f scriptfile.
- head/tail: -c bytes, -NUM shorthand, negative/positive line counts,
proper multi-file headers.
- sort: -k keys, -t separator, -o output, -f/-b/-d/-s, -h/-V/-M modes.
- uniq: -i, -f, -s, -w, -D, and the [input [output]] form.
- wc: -m characters and -L longest line; -c now counts bytes (UTF-8).
- cut: open-ended ranges (3-, -5), -s, --complement, --output-delimiter.
- tr: -c/-s/-t, [:class:] character classes, escape sequences.
- sed: real multi-command parser supporting ';', addresses (N, $,
/re/, N,M), '!' negation, proper -n quiet mode, y///, and -i[SUFFIX].
- echo: -n, -e, -E with standard backslash escapes.
- pwd/cd: -L/-P, plus cd -, cd ~, cd $HOME with OLDPWD tracking.
- diff: proper LCS algorithm producing correct normal and unified
output; adds -q, -s, -N, -i, -w, -b, -B.
- env: -i, -u, NAME=VAL assignments; reads the live shell environment.
- date: -u, -d, -R, -I, and a full GNU-subset format specifier set.
Tests for each command were updated to reflect the corrected behavior
(e.g. absolute paths and stdin are now accepted, POSIX error messages).
All 1334 tests pass; typecheck and production build succeed.
The old ShellTool used a flat string scanner that couldn't distinguish
quote context from operator context. In practice this produced a long
tail of surprising behaviours that confused AI agents and occasionally
corrupted the virtual filesystem:
* `echo hi 2>&1` wrote 'hi 2' to a file named literally `&1`
* `echo hi >&2` wrote to a file named `&2`
* `cat < in.txt` silently produced no output (input redirection
was unimplemented but not rejected)
* `for f in *.tsx; do ... done` was split into three separate
"command not found" errors
* `echo $HOME`, `echo $(pwd)`, `echo \`pwd\`` all printed
the unexpanded source text
* `# comment`, backslash escapes, brace expansion, tilde, and
arithmetic all fell through as literal characters
Introduce a proper mini-shell in src/lib/shell/:
* tokenizer.ts — POSIX-flavoured lexer that understands single and
double quotes, backslash escapes (including line continuations),
comments, operators, fd-prefixed redirections (IO_NUMBER), and
dollar-led expressions ($VAR, ${...}, $(...), $((...)), backticks).
* parser.ts — recursive-descent parser producing an AST covering
pipelines, and-or lists, sequences, redirections (including `<<`
heredocs and fd duplication like `2>&1`), and the full suite of
compound commands: if/elif/else/fi, for, while, until, case,
subshells, and brace groups.
* expand.ts — word expansion following POSIX ordering: brace
expansion, tilde, parameter, command substitution, arithmetic,
word splitting, pathname expansion, quote removal. Glob patterns
match against the virtual filesystem; unmatched patterns pass
through unchanged.
* executor.ts — AST interpreter that dispatches simple commands to
the existing ShellCommand registry, applies redirections safely
(validateWritePath runs BEFORE any file write so bogus paths can
no longer materialize), evaluates control flow, and tracks exit
status in $? with a safe iteration cap on while/until loops.
* Built-ins: true, false, :, export, unset, exit, test, [.
ShellTool.ts is now a thin integration layer that wires the registry
into a ShellExecutor and formats the final output, keeping its public
API (execute, getCurrentWorkingDirectory, setCurrentWorkingDirectory,
getAvailableCommands) unchanged so existing callers (ChatPane,
Terminal) don't need to change.
Tests:
* All 35 existing ShellTool tests still pass (adjusted two
assertions for the improved error messages).
* Added 29 tokenizer, 19 parser, 24 expander, and 49 end-to-end
tests covering the bash features listed above and confirming that
the data-corrupting redirection bugs are gone.
* Full suite: 1316 passed / 6 skipped, typecheck clean, lint clean,
build clean.
AI agents frequently write bash-style commands like `cp *.tsx src/` or
`ls src/**/*.ts`, but ShellTool previously passed wildcard tokens through
to individual commands literally. Since the command implementations don't
do their own expansion, these invocations failed with confusing errors
like "cannot stat '*.tsx'", leading agents to retry with increasingly
complex workarounds (find -exec, for loops) that also aren't supported.
Move glob expansion into the shell itself, matching how real shells work:
unquoted arguments containing `*`, `?`, or `[...]` are expanded
against the virtual filesystem before being handed to the command. Quoted
patterns and option flags are left untouched, and patterns that match
nothing pass through literally (bash default behaviour).
Tailwind v4 projects typically include `@import "tailwindcss";` in
their CSS entry and often `@import` third-party CSS plugins like
`tw-animate-css`. Both cases were broken:
1. esbuild tried to resolve `tailwindcss` through the ESM CDN as JS,
producing 'Cannot import <...> into a CSS file'. The existing
CSS-importer guard used `new URL(args.importer)` to detect CSS
importers, but esbuild passes fs-namespace importers as plain paths
(e.g. `/projects/foo/src/index.css`) which don't parse as URLs, so
the guard never fired.
2. `@tailwindcss/browser@4` only resolves a hardcoded set of `@import`
specifiers (`tailwindcss`, `tailwindcss/preflight`,
`tailwindcss/theme`, `tailwindcss/utilities`) and throws
'The browser build does not support @import for <x>' for everything
else, so plugin packages couldn't be preserved as external either.
Detect CSS importers with a plain string match and split behavior:
`tailwindcss` and its subpaths stay external so the v4 runtime can
handle them, while other bare CSS imports fall through to the normal
esm.sh resolution path. esm.sh redirects CSS-only packages to their
`.css` entry and `onLoad` picks `loader: "css"` via the content-type
mapping, so the dependency is bundled inline. The combined CSS then
lands in the `<style type="text/tailwindcss">` block where the v4
runtime can process v4 directives (`@custom-variant`, `@theme`, etc.)
from third-party plugins.
Detect the Tailwind major version from the project's package.json and
branch the build pipeline accordingly. v3 projects keep loading the Play
CDN runtime and a JS tailwind.config via the existing synthetic entry.
v4 projects instead pull in @tailwindcss/browser@4, which auto-scans the
document and reads theme config from CSS (@theme / @import 'tailwindcss')
so no config shim is required.
Shakespeare's esbuild-wasm pipeline now handles the Vite/webpack-compatible
patterns for module workers and static asset URLs, so projects using
new Worker(new URL('./w.ts', import.meta.url), { type: 'module' })
new SharedWorker(new URL('./w.ts', import.meta.url), { type: 'module' })
new URL('./logo.svg', import.meta.url)
build correctly under Shakespeare instead of emitting a 404'ing URL
that pointed at the source-file path inside the main bundle.
Mechanics:
- A new detection pass (src/lib/build/workerPlugin.ts) is invoked from
the fs plugin's onLoad for .ts/.tsx/.js/.jsx/.mjs files. It cheaply
regex-prefilters on 'new URL(' so 99% of files pay zero overhead,
then strips TS/JSX via esbuild.transform and parses with acorn +
acorn-jsx for the handful of files that actually match. The string
literal spec inside each matched new URL() call is replaced with a
unique placeholder token, preserving the enclosing new URL(...,
import.meta.url) shape so runtime resolution against the main
bundle URL still works.
- bundle() now runs a per-worker sub-build (esbuild.build) with the
same plugin stack, producing a hashed ESM chunk alongside the main
output. The queue drains recursively so nested workers / assets
discovered during a sub-build are handled in the same bundle call.
- Non-source assets are copied into the output with content-hashed
filenames (SHA-256 when SubtleCrypto is available, FNV-1a fallback
for test environments).
- After all sub-builds finish, placeholder tokens are string-replaced
in every JS output with the corresponding './<emitted-filename>'.
- updateCSPForEsmSh gains an emittedWorkers option; when set it
additionally ensures worker-src and child-src exist and extends
them with the ESM CDN so module workers can import from esm.sh.
Errors (with file:line context) are raised for classic (non-module)
workers, dynamic specifiers, and unresolvable worker specs. Plain
new URL() pointing at a source file emits a console warning and is
left untransformed.
Tests: 16 new workerPlugin unit tests cover detection, errors,
dedup, and quote-style handling; 4 new CSP tests cover the
emittedWorkers path.
The refresh mechanism posted a JSON-RPC `refresh` command to the nested
iframe.diy frames. During rapid build cycles, the command could be
silently dropped when the inner iframe was mid-reload, not yet mounted,
or when the outer frame's handshake was still pending \u2014 leaving the
preview stuck on a stale build with no way to recover short of reloading
the whole page.
Switch to remounting the iframe via a React key bump, which always works
regardless of handshake state. Also fix a bug in the injected preview
script where `++rpcId` (a function) silently corrupted the id generator
to NaN, breaking navigation state and uncaught error reporting.
The tools JSON is typically 7-12K tokens, stable across every turn in
a session, and was previously re-billed at full input price on every
turn. OpenRouter explicitly supports cache_control on tool definitions
for Anthropic models (announced in their 'tool caching' release), and
the OpenAI SDK serializes the body via JSON.stringify so unknown fields
like cache_control pass through untouched.
This adds a cache_control breakpoint on the last tool, which caches the
entire tools array. Combined with the existing system + last-2-messages
breakpoints, we now use all 4 breakpoints Anthropic allows, matching
the cache hierarchy (tools -> system -> messages).
Expected savings for a 280-turn session (Opus): ~$27 for 16 tools or
~$47 for 31 tools.
Refactors the request-body transform into a named, exported
applyOpenRouterTransforms function with unit tests covering:
- cache_control placement on tools, system, and last two messages
- non-Anthropic models skip the transform
- byte-stability of the tools JSON across calls (the property the
cache actually relies on)
- no mutation of the caller's tools array
The project ID used for the preview iframe subdomain is AI-generated
from user input. Using it directly as the iframe.diy subdomain lets
a crafted project name produce a subdomain that collides with another
project's origin, gaining access to its localStorage/IndexedDB.
Introduce a persistent random seed in localStorage (shakespeare:seed)
and derive the subdomain as base36(HMAC-SHA256(seed, prefix|identifier)).
The prefix ("preview") domain-separates different use-cases.
The subdomain is stable per device+project but unpredictable to
third parties.
Separate EMPTY_AI_SETTINGS (for initial state and error fallback) from
OPENCODE_DEFAULT_SETTINGS (for genuinely new users only). Previously,
readAISettings returned OPENCODE_DEFAULT_SETTINGS on any error, which
could overwrite an existing user's recentlyUsedModels with
['opencode/big-pickle']. Now the error path returns empty settings, and
OPENCODE defaults are only applied when no providers are configured.
Pre-configure OpenCode Zen as the default AI provider so new users can
submit prompts immediately without any setup. Sends x-opencode-* headers
to qualify for the higher daily rate limit tier.
Add blossom.ditto.pub and blossom.dreamith.to to the top of all blossom
server lists. Add relay.dreamith.to below relay.ditto.pub and remove
relay.damus.io and purplerelay.com from deploy relay lists.
After deploying a named site, the adapter probes the gateway for vanity
subdomain support via X-Nsite-* response headers. When the gateway
confirms a vanity name (e.g. ditto.shakespeare.wtf), it is used as the
primary deploy URL. Gracefully degrades to the canonical base36 URL when
the gateway doesn't support vanity subdomains.
The fetch event handler was skipping all paths starting with `/_`,
intended to protect iframe-fetch-client system files. But this also
excluded SvelteKit asset paths like `/_app/immutable/chunks/*.js`,
causing them to bypass JSON-RPC and hit the network directly, which
returns HTML instead of JavaScript.
Narrow the exclusion to only `/_iframe-client/` — the specific
prefix used by the iframe-fetch-client's own assets.