Repository navigation
feat: add the Vibe Coding Mad Libs challenge #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6307518
feat: add the Vibe Coding Mad Libs challenge
claude 3ab1a65
chore: exempt challenge intros from the first-heading lint rule
claude c58668b
test: cover the Mad Libs prompt, extension load, and preview hooks
claude b100a67
fix: address review on the preview server, form, and prompt
claude ebea405
test: cover crash cleanup, the process group, and the form preview
claude a9b31d1
fix: address review on the typed sentence, preview, and dice sheet
claude 880a27f
fix: place the reload script at the last closing body tag by regex
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Vibe Coding Mad Libs | ||
|
|
||
| A 10-minute terminal challenge. The participant fills four Mad Libs blanks, | ||
| Theme, Subject, Audience, and Style, by inventing answers or rolling physical | ||
| dice against [`dice-sheet.md`](dice-sheet.md). Pi builds a self-contained | ||
| `index.html` from the sentence, shows it in Chrome beside the station, and | ||
| then makes one change the participant asks for. | ||
|
|
||
| | File | Role | | ||
| | --- | --- | | ||
| | `mad-libs.mjs` | Pi extension: the four-blank form and `/mad-libs` | | ||
| | `prompt.mjs` | Assembles and checks the sentence | | ||
| | `preview.mjs` | Serves `index.html` on `http://127.0.0.1:4321/` with live reload | | ||
| | `install` | Installs the Pi packages the extension imports | | ||
| | `setup`, `cleanup` | Copy the dice sheet and start the preview; stop it | | ||
|
|
||
| ## Run it standalone | ||
|
|
||
| Install Pi and the adapter at the versions boothstrap pins, as in | ||
| boothstrap's authoring guide, then, from this repo's root: | ||
|
|
||
| ```sh | ||
| challenge="$PWD/vibe-coding-mad-libs" | ||
| "$challenge/install" | ||
| mkdir -p tmp/mad-libs && cd tmp/mad-libs | ||
| "$challenge/setup" | ||
| GEMINI_API_KEY=... pi --model google/gemini-3.8-flash \ | ||
| --skill "$challenge/skills/start-challenge/SKILL.md" \ | ||
| --extension "$challenge/mad-libs.mjs" \ | ||
| '/skill:start-challenge' | ||
| "$challenge/cleanup" | ||
| ``` | ||
|
|
||
| `setup` and `cleanup` treat the current directory as the workspace. Without | ||
| boothstrap there's no `show_preview`, so Pi gives the preview URL to open | ||
| yourself, and no points: Pi says which step you finished instead. Setup fails | ||
| if port 4321 is already in use. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { | ||
| "id": "vibe-coding-mad-libs", | ||
| "title": "Vibe Coding Mad Libs", | ||
| "tagline": "Fill four blanks, and Pi builds the web app you described.", | ||
| "icon": "laptop", | ||
| "type": "terminal", | ||
| "agent": "pi", | ||
| "model": "google/gemini-3.8-flash", | ||
| "vault_services": ["gemini"], | ||
| "points": 100, | ||
| "estimated_minutes": 10, | ||
| "learning_objectives": ["prompting an agent to build a web app", "iterating on generated code"], | ||
| "featured_tech": ["Pi", "Gemini", "HTML"], | ||
| "intro": "intro.md", | ||
| "steps": [ | ||
| { | ||
| "id": "fill-prompt", | ||
| "title": "Fill in your prompt", | ||
| "hint": "Fill the four blanks. Invent answers, or roll dice and ask Pi to show dice-sheet.md.", | ||
| "done_when": "The participant sent a prompt naming a kind of app, a subject, an audience, and a style, with no blank left unfilled." | ||
| }, | ||
| { | ||
| "id": "build-app", | ||
| "title": "Build and try your app", | ||
| "hint": "Let Pi build it, open the preview, and try it out.", | ||
| "done_when": "index.html holds a working self-contained app built from the prompt, and the participant confirmed they tried it in the preview." | ||
| }, | ||
| { | ||
| "id": "improve-app", | ||
| "title": "Make it yours", | ||
| "hint": "Ask Pi for one change, then try the updated app.", | ||
| "done_when": "Pi made one change the participant asked for to index.html, and the participant confirmed they tried the updated app." | ||
| } | ||
| ] | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/bin/sh | ||
| # Stops the app preview setup started. Safe to run twice, after a crash, or | ||
| # after setup failed. | ||
| set -eu | ||
|
|
||
| package_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) | ||
| workspace=${BOOTHSTRAP_WORKSPACE:-$PWD} | ||
|
|
||
| [ -d "$workspace" ] || exit 0 | ||
| exec node "$package_dir/preview.mjs" stop "$workspace" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # Optional dice sheet | ||
|
|
||
| Roll a d6 for Theme, a d6 for Subject, a d20 for Audience, and a d20 for | ||
| Style, then type the matching options into the form. You can also invent any | ||
| answer, or mix your own answers with rolled ones. Pi can't roll for you. | ||
|
|
||
| ## Theme (d6) | ||
|
|
||
| | Roll | Option | | ||
| | --- | --- | | ||
| | 1 | Dashboard | | ||
| | 2 | Game | | ||
| | 3 | Generator | | ||
| | 4 | Visualizer | | ||
| | 5 | Calculator / What-If Tool | | ||
| | 6 | Scrollytelling Story | | ||
|
|
||
| ## Subject (d6) | ||
|
|
||
| | Roll | Option | | ||
| | --- | --- | | ||
| | 1 | Space & Astronomy | | ||
| | 2 | Food & Recipes | | ||
| | 3 | Music & Sound | | ||
| | 4 | Weather & Climate | | ||
| | 5 | Sports & Fitness | | ||
| | 6 | Internet Culture & Memes | | ||
|
|
||
| ## Audience (d20) | ||
|
|
||
| | Roll | Option | | ||
| | --- | --- | | ||
| | 1 | First-time hackers | | ||
| | 2 | Exhausted night-shift nurses | | ||
| | 3 | Competitive dog groomers | | ||
| | 4 | Retired astronauts | | ||
| | 5 | Middle school science teachers | | ||
| | 6 | Touring musicians | | ||
| | 7 | Urban beekeepers | | ||
| | 8 | Long-haul truck drivers | | ||
| | 9 | Museum curators | | ||
| | 10 | Amateur storm chasers | | ||
| | 11 | Bakery owners | | ||
| | 12 | Marine biologists | | ||
| | 13 | Chess club captains | | ||
| | 14 | Film festival programmers | | ||
| | 15 | Community garden organizers | | ||
| | 16 | Ultramarathon runners | | ||
| | 17 | Librarians | | ||
| | 18 | Ski patrol | | ||
| | 19 | Podcast producers | | ||
| | 20 | Lighthouse keepers | | ||
|
|
||
| ## Style (d20) | ||
|
|
||
| | Roll | Option | | ||
| | --- | --- | | ||
| | 1 | Cyberpunk | | ||
| | 2 | Cottagecore | | ||
| | 3 | Y2K Web 1.0 | | ||
| | 4 | Brutalist | | ||
| | 5 | Solarpunk | | ||
| | 6 | Dark Academia | | ||
| | 7 | Scandinavian Minimalism | | ||
| | 8 | Retro 80s Synthwave | | ||
| | 9 | Mid-Century Modern | | ||
| | 10 | Vaporwave | | ||
| | 11 | Art Nouveau | | ||
| | 12 | Deep Space | | ||
| | 13 | Terminal / Green Phosphor | | ||
| | 14 | Pastel Pop | | ||
| | 15 | Industrial Loft | | ||
| | 16 | Glassmorphism | | ||
| | 17 | Bauhaus | | ||
| | 18 | Art Deco | | ||
| | 19 | Claymorphism | | ||
| | 20 | Neon Noir | |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #!/bin/sh | ||
| # Installs the Pi packages the Mad Libs form extension imports, at the | ||
| # versions boothstrap's Pi uses, into this package's node_modules. | ||
| set -eu | ||
|
|
||
| package_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) | ||
| npm ci --ignore-scripts --no-audit --no-fund --prefix "$package_dir" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Tell Pi what to build by filling in one sentence: | ||
|
|
||
| > Build a [Theme] about [Subject] for [Audience] in [Style] style. | ||
|
|
||
| A form opens after Pi says hello. Type your own answers, or roll the dice | ||
| at the booth: press Esc and ask Pi to show `dice-sheet.md` to look up each | ||
| roll, then type `/mad-libs` to return to the form. The dice are optional, | ||
| and mixing rolled and invented answers is fine. | ||
|
|
||
| Pi then builds your app as one web page and offers to open it in Chrome | ||
| beside the station. Try it, ask Pi for one change, and try it again. | ||
|
|
||
| Your sentence and requests go to the Gemini model, so leave out anything | ||
| private. Everything here is wiped when you leave. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| // Pi extension: the four-blank Mad Libs form. It opens once Pi's welcome | ||
| // finishes, reopens with /mad-libs, and sends the filled sentence as the | ||
| // participant's message. Typing the sentence in Pi's editor works without it. | ||
|
|
||
| import { Input, matchesKey, truncateToWidth, wrapTextWithAnsi } from '@earendil-works/pi-tui' | ||
|
|
||
| import { FIELDS, PROMPT_TEMPLATE, assemblePrompt, fillSentence, findBlankField, hasUnfilledBlank, isFinishedPrompt } from './prompt.mjs' | ||
|
|
||
| /** The form's focus stops: one per field, then the Build button. */ | ||
| const BUILD_BUTTON = FIELDS.length | ||
| const FOCUS_STOPS = FIELDS.length + 1 | ||
|
|
||
| /** How many lines of the sentence preview the form shows. */ | ||
| const PREVIEW_LINES = 5 | ||
|
|
||
| /** Lists the text parts of a message's `content`, a string or an array of parts. */ | ||
| function textParts(content) { | ||
| if (typeof content === 'string') return [content] | ||
|
|
||
| return content.filter((part) => part.type === 'text').map((part) => part.text) | ||
| } | ||
|
|
||
| /** True when this session's branch already holds a finished sentence from the participant. */ | ||
| function promptAlreadySent(ctx) { | ||
| return ctx.sessionManager.getBranch().some((entry) => entry.type === 'message' | ||
| && entry.message.role === 'user' | ||
| && textParts(entry.message.content).some(isFinishedPrompt)) | ||
| } | ||
|
|
||
| /** | ||
| * Builds the form component for `ctx.ui.custom`. `draft` keeps answers | ||
| * across closes, keyed by field; `keybindings` supplies Pi's submit and | ||
| * cancel keys; `done` receives the sentence, or null when cancelled. | ||
| */ | ||
| function createForm({ tui, theme, keybindings, draft, done }) { | ||
| const inputs = FIELDS.map((field) => { | ||
| const input = new Input({ prompt: '', placeholder: field.placeholder }) | ||
| // setValue leaves the cursor at column zero; typing the draft puts it at the end. | ||
| if (draft[field.key]) input.handleInput(draft[field.key]) | ||
|
|
||
| return input | ||
| }) | ||
| let focusedStop = 0 | ||
| let hasFocus = true | ||
| let error = '' | ||
|
|
||
| /** Moves focus to stop `target`, wrapping around both ends. */ | ||
| function focusStop(target) { | ||
| focusedStop = (target + FOCUS_STOPS) % FOCUS_STOPS | ||
| inputs.forEach((input, index) => { | ||
| input.focused = hasFocus && index === focusedStop | ||
| }) | ||
| tui.requestRender() | ||
| } | ||
|
|
||
| /** Sends the sentence, or points at the first blank field. */ | ||
| function build() { | ||
| const blankField = findBlankField(draft) | ||
| if (blankField) { | ||
| error = `Fill in ${blankField.label} first.` | ||
| focusStop(FIELDS.indexOf(blankField)) | ||
| return | ||
| } | ||
|
|
||
| done(assemblePrompt(draft)) | ||
| } | ||
|
|
||
| focusStop(0) | ||
|
|
||
| return { | ||
| get focused() { | ||
| return hasFocus | ||
| }, | ||
| set focused(value) { | ||
| hasFocus = value | ||
| focusStop(focusedStop) | ||
| }, | ||
| handleInput(data) { | ||
| if (keybindings.matches(data, 'tui.select.cancel')) return done(null) | ||
| if (matchesKey(data, 'shift+tab')) return focusStop(focusedStop - 1) | ||
| if (matchesKey(data, 'tab')) return focusStop(focusedStop + 1) | ||
| if (keybindings.matches(data, 'tui.input.submit')) { | ||
| return focusedStop === BUILD_BUTTON ? build() : focusStop(focusedStop + 1) | ||
| } | ||
| if (focusedStop === BUILD_BUTTON) return | ||
|
|
||
| const field = FIELDS[focusedStop] | ||
| inputs[focusedStop].handleInput(data) | ||
| draft[field.key] = inputs[focusedStop].getValue() | ||
| error = '' | ||
| tui.requestRender() | ||
| }, | ||
| render(width) { | ||
| const fit = (text) => truncateToWidth(text, Math.max(1, width)) | ||
| const marker = (stop) => (focusedStop === stop ? '›' : ' ') | ||
| const lines = [ | ||
| fit(theme.fg('accent', theme.bold('Fill in the blanks'))), | ||
| fit(theme.fg('muted', 'Tab/Shift+Tab: move Enter: next, then Build Esc: back to chat')), | ||
| ] | ||
| FIELDS.forEach((field, index) => { | ||
| lines.push(fit(`${marker(index)} ${field.label}`)) | ||
| lines.push(...inputs[index].render(width).map(fit)) | ||
| }) | ||
| lines.push(fit(`${marker(BUILD_BUTTON)} [ Build ]`), '') | ||
|
|
||
| const preview = wrapTextWithAnsi(fillSentence(draft), Math.max(1, width)) | ||
| lines.push(...preview.slice(0, PREVIEW_LINES).map(fit)) | ||
| if (preview.length > PREVIEW_LINES) lines.push(fit(theme.fg('muted', '… (your answers are kept in full)'))) | ||
| if (error) lines.push(fit(theme.fg('warning', error))) | ||
|
|
||
| return lines | ||
| }, | ||
| invalidate() { | ||
| inputs.forEach((input) => input.invalidate()) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| /** Registers the form, its /mad-libs command, and the typed-sentence check with Pi. */ | ||
| export default function madLibs(pi) { | ||
| const draft = Object.fromEntries(FIELDS.map((field) => [field.key, ''])) | ||
| let formOpen = false | ||
| let openAfterWelcome = false | ||
|
|
||
| /** | ||
| * Opens the form in Pi's terminal UI and sends the sentence it returns. | ||
| * Once the idea is sent, only an explicit /mad-libs (`requested`) says so. | ||
| */ | ||
| async function openForm(ctx, { requested }) { | ||
| if (ctx.mode !== 'tui' || formOpen) return | ||
| if (promptAlreadySent(ctx)) { | ||
| if (requested) ctx.ui.notify('Your idea is already sent. Ask Pi for a change to the app instead.', 'info') | ||
| return | ||
| } | ||
|
|
||
| formOpen = true | ||
| let sentence | ||
| try { | ||
| sentence = await ctx.ui.custom((tui, theme, keybindings, done) => createForm({ tui, theme, keybindings, draft, done })) | ||
| } catch { | ||
| ctx.ui.notify(`The form couldn't open. Type the sentence instead: ${PROMPT_TEMPLATE}`, 'warning') | ||
| return | ||
| } finally { | ||
| formOpen = false | ||
| } | ||
|
|
||
| if (!sentence) { | ||
| ctx.ui.notify('Form closed. Type /mad-libs to reopen it.', 'info') | ||
| return | ||
| } | ||
|
|
||
| pi.sendUserMessage(sentence, ctx.isIdle() ? undefined : { deliverAs: 'followUp' }) | ||
| } | ||
|
|
||
| pi.registerCommand('mad-libs', { | ||
| description: 'Open the four-blank app idea form', | ||
| handler: async (_args, ctx) => openForm(ctx, { requested: true }), | ||
| }) | ||
|
|
||
| pi.on('session_start', (event, ctx) => { | ||
| openAfterWelcome = event.reason === 'startup' && ctx.mode === 'tui' && !promptAlreadySent(ctx) | ||
| }) | ||
|
|
||
| // Not awaited: the form stays open while the participant types, and | ||
| // holding the event would stall Pi until they finish. | ||
| pi.on('agent_settled', (_event, ctx) => { | ||
| if (!openAfterWelcome) return | ||
|
|
||
| openAfterWelcome = false | ||
| openForm(ctx, { requested: false }).catch((error) => ctx.ui.notify(`The form failed: ${error.message}`, 'error')) | ||
| }) | ||
|
|
||
| pi.on('input', (event, ctx) => { | ||
| const typedSentenceWithBlank = event.source === 'interactive' | ||
| && /^\s*Build an?\b/i.test(event.text) | ||
| && hasUnfilledBlank(event.text) | ||
| && !promptAlreadySent(ctx) | ||
| if (!typedSentenceWithBlank) return { action: 'continue' } | ||
|
|
||
| ctx.ui.setEditorText(event.text) | ||
| ctx.ui.notify(`Fill in all four blanks: ${PROMPT_TEMPLATE}`, 'warning') | ||
|
|
||
| return { action: 'handled' } | ||
| }) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.