feat(web): add shell-first runbook UI and mock demo (#2)

Add notebook parameters, literal highlighted scripts, copy helpers, streamed runs, host-key confirmation, artifacts, conditional notes, login and optimistic Markdown editing. Keep the temporary core renderer isolated to mock mode.

Use React and Vite for the UI, react-markdown for safe Markdown rendering, highlight.js for shell syntax, and CodeMirror 6 for Markdown editing. Add Testing Library, jsdom and Vitest for component and event-state coverage.

Validate pnpm install, root typecheck and test (29 web tests, 1 server test), plus normal and mock web builds. Core contracts remain unchanged; real backend execution awaits the parallel core/server implementations.
This commit is contained in:
Florian Schmidt
2026-11-16 00:08:30 +01:00
parent d06f4336ae
commit 443bf944b8
25 changed files with 4510 additions and 2 deletions
+123
View File
@@ -0,0 +1,123 @@
import type { ServerEvent, StartRunRequest } from "@shellbook/core";
import type { Api } from "../api";
import { HttpError } from "../api";
import { parseNotebook, renderStep } from "./core";
import initial from "./ssh-key.md?raw";
let source = initial;
let version = 1;
let counter = 0;
const listeners = new Set<(event: ServerEvent) => void>();
const emit = (event: ServerEvent) =>
listeners.forEach((listener) => listener(event));
const hosts = [
{
name: "staging",
user: "admin",
address: "192.0.2.10",
port: 22,
tags: ["demo"],
},
{
name: "production",
user: "ops",
address: "192.0.2.20",
port: 2222,
tags: ["prod"],
},
];
const artifactUrl = URL.createObjectURL(
new Blob(["Demo artifact only. No real key material.\n"], {
type: "text/plain",
}),
);
export const mockApi: Api = {
me: async () => ({ authenticated: true }),
login: async () => undefined,
list: async () => ({
notebooks: [{ path: "ssh-key.md", title: "New server SSH key" }],
}),
hosts: async () => ({ hosts }),
notebook: async (path) => ({
path,
source,
notebook: parseNotebook(source),
version: String(version),
}),
save: async (_path, next, base) => {
if (base !== String(version)) throw new HttpError(409);
source = next;
version++;
return { version: String(version) };
},
events: (receive, connected) => {
listeners.add(receive);
connected(true);
return () => {
listeners.delete(receive);
};
},
artifact: () => artifactUrl,
run: async (request: StartRunRequest) => {
const notebook = parseNotebook(source);
const block = notebook.blocks.find(
(b) => b.type === "step" && b.step.attrs.id === request.stepId,
);
if (!block || block.type !== "step") throw new Error("Unknown demo step");
const rendered = renderStep(
notebook,
block.step,
request.params,
request.runtime,
hosts.map((h) => h.name),
);
const runId = `demo-${++counter}`;
setTimeout(() => {
emit({
type: "run.started",
runId,
notebookPath: request.notebookPath,
stepId: request.stepId,
script: rendered.script,
host: rendered.host,
});
if (rendered.host === "production" && !request.acceptHostKey) {
emit({
type: "run.hostKeyUnknown",
runId,
host: "production",
fingerprint: "SHA256:DEMO-VERIFY-OUT-OF-BAND",
changed: true,
});
return;
}
emit({
type: "run.output",
runId,
stream: "stdout",
data: "Demo stream — no shell commands execute.\n",
});
setTimeout(() => {
const failed = request.stepId === "password-login-disabled";
emit({
type: "run.output",
runId,
stream: failed ? "stderr" : "stdout",
data: failed
? "Demo: password authentication is enabled.\n"
: "Demo: completed successfully.\n",
});
emit({
type: "run.finished",
runId,
exitCode: failed ? 1 : 0,
durationMs: 850,
artifacts: rendered.artifacts,
captured: block.step.attrs.capture
? { name: block.step.attrs.capture, value: "demo-value" }
: undefined,
});
}, 850);
}, 50);
return { runId };
},
};