Public: anyone can read this; the crew can change it.
Tell from any forge page: the palette's "Tell the crew" opens a composer in place, and the tell carries the page it was told from #1228
scout/forge:scout/1059-tell-from-any-forge-page-the-palette-s-t → main 7 commits fork
15 files
changed +348
−25
README.md +4 −1
| @@ -13,7 +13,10 @@ crew proposes, you decide what ships. | ||
| 13 | 13 | That view is the **studio**, and it is the front door — a browser with no |
| 14 | 14 | `forge_mode` cookie lands there. It speaks four words for the whole loop: |
| 15 | 15 | _tell_, _working_, _look_ and _shipped_; an autonomous app lands its own |
| 16 | green changes, and nothing waits on a person. [](docs/STUDIO.md) is the tour; | |
| 16 | green changes, and nothing waits on a person. On any page of an app, the | |
| 17 | palette's "Tell the crew" opens a composer in place (without a script, the app | |
| 18 | page's form with `?from=` prefilled); the tell ends with a `Told from: <path>` | |
| 19 | line, and the MCP `tell` tool takes the same `from`. [](docs/STUDIO.md) is the tour; | |
| 17 | 20 | [](docs/APPS.md) is the contract for apps, previews and runs. The |
| 18 | 21 | git underneath is one click away — the switch in the top bar, or `?mode=dev` on |
| 19 | 22 | any URL — and it is the rest of this page. |
src/actions/tell.ts +28 −4
| @@ -39,11 +39,34 @@ export type TellError = | ||
| 39 | 39 | | "body_too_long" |
| 40 | 40 | | MirrorError; |
| 41 | 41 | |
| 42 | /** | |
| 43 | * The page a tell was told from, if it is a forge path: one `/`-led path | |
| 44 | * (query allowed) with no whitespace, control characters, backslash or | |
| 45 | * second leading slash. Anything else — another origin, a scheme, a | |
| 46 | * protocol-relative address — is dropped, not repaired. | |
| 47 | */ | |
| 48 | export function toldFrom(raw: string | undefined): string | undefined { | |
| 49 | if (raw === undefined) return undefined; | |
| 50 | const path = raw.trim(); | |
| 51 | if (path.length === 0 || path.length > 300) return undefined; | |
| 52 | if (!/^\/[^\s\\\u0000-\u001f\u007f]*$/.test(path)) return undefined; | |
| 53 | if (path.startsWith("//")) return undefined; | |
| 54 | try { | |
| 55 | if (new URL(path, "http://forge.invalid").origin !== "http://forge.invalid") | |
| 56 | return undefined; | |
| 57 | } catch { | |
| 58 | return undefined; | |
| 59 | } | |
| 60 | return path; | |
| 61 | } | |
| 62 | ||
| 42 | 63 | export async function tell( |
| 43 | 64 | app: App, |
| 44 | 65 | actor: User | undefined, |
| 45 | 66 | repo: Repo, |
| 46 | 67 | said: string, |
| 68 | /** The page it was told from; validated here, dropped when not a forge path. */ | |
| 69 | from?: string, | |
| 47 | 70 | ): Promise<Result<Told, TellError>> { |
| 48 | 71 | // A tell is a run: only someone who may direct the crew here says one, |
| 49 | 72 | // and a refused tell opens nothing (`crew/direct.ts`). |
| @@ -58,10 +81,11 @@ export async function tell( | ||
| 58 | 81 | const firstLine = text.split(/\n/)[0]!.trim(); |
| 59 | 82 | const title = |
| 60 | 83 | firstLine.length <= 80 ? firstLine : `${firstLine.slice(0, 77).trimEnd()}…`; |
| 61 | const opened = openIssue(app, actor, repo, { | |
| 62 | title, | |
| 63 | body: text === firstLine ? "" : text, | |
| 64 | }); | |
| 84 | const page = toldFrom(from); | |
| 85 | const body = [text === firstLine ? "" : text, page ? `Told from: ${page}` : ""] | |
| 86 | .filter((x) => x !== "") | |
| 87 | .join("\n\n"); | |
| 88 | const opened = openIssue(app, actor, repo, { title, body }); | |
| 65 | 89 | if (!opened.ok) return opened; |
| 66 | 90 | const crew = listCrewRoles(app.db, repo.id); |
| 67 | 91 | const inFlight = new Map<string, number>(); |
src/http/mcp.ts +17 −2
| @@ -272,14 +272,29 @@ const TOOLS: readonly Tool[] = [ | ||
| 272 | 272 | "Tell an app's crew what should change. One sentence or several; the first line becomes the title. A builder is picked and starts on the crew's next tick.", |
| 273 | 273 | inputSchema: { |
| 274 | 274 | type: "object", |
| 275 | properties: { repo: REPO_ARG, text: { type: "string", maxLength: 8000 } }, | |
| 275 | properties: { | |
| 276 | repo: REPO_ARG, | |
| 277 | text: { type: "string", maxLength: 8000 }, | |
| 278 | from: { | |
| 279 | type: "string", | |
| 280 | maxLength: 300, | |
| 281 | description: | |
| 282 | "The forge page this is told from, as a path (/owner/name/pulls/3). The tell ends with a 'Told from:' line; anything but a forge path is dropped.", | |
| 283 | }, | |
| 284 | }, | |
| 276 | 285 | required: ["repo", "text"], |
| 277 | 286 | }, |
| 278 | 287 | writes: true, |
| 279 | 288 | async run(ctx, user, args) { |
| 280 | 289 | const repo = repoArg(ctx, user, args); |
| 281 | 290 | if (isAnswer(repo)) return repo; |
| 282 | const told = await tell(ctx.app, user, repo, str(args["text"])); | |
| 291 | const told = await tell( | |
| 292 | ctx.app, | |
| 293 | user, | |
| 294 | repo, | |
| 295 | str(args["text"]), | |
| 296 | str(args["from"]), | |
| 297 | ); | |
| 283 | 298 | if (!told.ok) |
| 284 | 299 | return bad( |
| 285 | 300 | told.error, |
src/web/chrome.ts +2 −4
| @@ -9,7 +9,6 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | import { sshCommand } from "../ssh/command.ts"; |
| 12 | import { mayDirectCrew } from "../crew/direct.ts"; | |
| 13 | 12 | import { mayReadRuns } from "../actions/runs.ts"; |
| 14 | 13 | import { getAppByRepo } from "../core/apps.ts"; |
| 15 | 14 | import { edgeLoginUrl } from "../http/edge.ts"; |
| @@ -34,6 +33,7 @@ import { | ||
| 34 | 33 | whereRow, |
| 35 | 34 | type RepoScope, |
| 36 | 35 | } from "./scope.ts"; |
| 36 | import { tellRow } from "./tell-row.ts"; | |
| 37 | 37 | import { changesHref, tellsHref } from "./studio/nouns.ts"; |
| 38 | 38 | import { badge, btn, empty, tabs, type TabItem } from "./ui.ts"; |
| 39 | 39 | |
| @@ -369,9 +369,7 @@ export function repoPalette(ctx: Ctx, repo: Repo): PaletteItem[] { | ||
| 369 | 369 | // Telling the crew is for who may direct it (`mayDirectCrew`: a |
| 370 | 370 | // writer, or anyone signed in where the owner let outsiders in), so |
| 371 | 371 | // nobody else is offered a door that leads nowhere. |
| 372 | ...(mayDirectCrew(ctx.app.db, repo, ctx.auth.user) | |
| 373 | ? [{ t: `${name} — Tell the crew`, h: `${base}#tell`, c: "This repo" }] | |
| 374 | : []), | |
| 372 | ...tellRow(ctx, repo, "This repo"), | |
| 375 | 373 | ...(mayReadRuns(ctx.app, ctx.auth.user, repo) |
| 376 | 374 | ? [{ t: `${name} — Runs`, h: `${base}/runs`, c: "This repo" }] |
| 377 | 375 | : []), |
src/web/client.ts +90 −3
| @@ -1559,7 +1559,13 @@ export const shellJs = /* js */ ` | ||
| 1559 | 1559 | var input = dlg.querySelector('.palette-input'); |
| 1560 | 1560 | var list = dlg.querySelector('.palette-list'); |
| 1561 | 1561 | var items = (loadIndex().items || []).map(function (i) { |
| 1562 | return { t: String(i.t), h: String(i.h), g: i.c ? String(i.c) : 'Go to' }; | |
| 1562 | var r = { t: String(i.t), h: String(i.h), g: i.c ? String(i.c) : 'Go to' }; | |
| 1563 | // "Tell the crew" opens a composer in place; its address is the | |
| 1564 | // no-script fallback, a link to the app page's own form. | |
| 1565 | if (i.k === 'tell' && typeof i.a === 'string' && i.a.charAt(0) === '/') { | |
| 1566 | r.k = 'tell'; r.a = i.a; r.f = typeof i.f === 'string' ? i.f : ''; | |
| 1567 | } | |
| 1568 | return r; | |
| 1563 | 1569 | }); |
| 1564 | 1570 | var recent = readRecent().map(function (r) { return { t: r.t, h: r.h, g: 'Recent', d: r.g }; }); |
| 1565 | 1571 | var recentHrefs = recent.map(function (r) { return r.h; }); |
| @@ -1571,6 +1577,74 @@ export const shellJs = /* js */ ` | ||
| 1571 | 1577 | var nodes = []; // the rows on screen, in order … |
| 1572 | 1578 | var shown = []; // … and what each one is |
| 1573 | 1579 | var at = 0; |
| 1580 | var composer = null; // the tell form, while it is open in place | |
| 1581 | ||
| 1582 | // One thought, sent in place: the same action the app page's form posts | |
| 1583 | // to, answered as JSON. The receipt line is reserved up front, so | |
| 1584 | // sending moves nothing. | |
| 1585 | function openComposer(r) { | |
| 1586 | var form = doc.createElement('form'); | |
| 1587 | form.className = 'palette-tell'; | |
| 1588 | var ta = doc.createElement('textarea'); | |
| 1589 | ta.className = 'input'; | |
| 1590 | ta.name = 'text'; | |
| 1591 | ta.rows = 4; | |
| 1592 | ta.maxLength = 8000; | |
| 1593 | ta.required = true; | |
| 1594 | ta.setAttribute('aria-label', 'Tell the crew'); | |
| 1595 | ta.placeholder = 'What should change? One thing at a time works best.'; | |
| 1596 | var bar = doc.createElement('div'); | |
| 1597 | bar.className = 'bar'; | |
| 1598 | var receipt = doc.createElement('p'); | |
| 1599 | receipt.className = 'palette-receipt muted small grow'; | |
| 1600 | receipt.setAttribute('role', 'status'); | |
| 1601 | receipt.setAttribute('aria-live', 'polite'); | |
| 1602 | var send = doc.createElement('button'); | |
| 1603 | send.className = 'btn primary'; | |
| 1604 | send.type = 'submit'; | |
| 1605 | send.textContent = 'Send'; | |
| 1606 | bar.appendChild(receipt); bar.appendChild(send); | |
| 1607 | form.appendChild(ta); form.appendChild(bar); | |
| 1608 | input.hidden = true; list.hidden = true; | |
| 1609 | dlg.insertBefore(form, list); | |
| 1610 | composer = form; | |
| 1611 | form.onsubmit = function (e) { | |
| 1612 | e.preventDefault(); | |
| 1613 | var text = ta.value.trim(); | |
| 1614 | if (text === '') { receipt.textContent = 'Say something first.'; return; } | |
| 1615 | send.disabled = true; | |
| 1616 | receipt.textContent = 'Sending…'; | |
| 1617 | var body = new URLSearchParams(); | |
| 1618 | body.set('text', text); | |
| 1619 | if (r.f) body.set('from', r.f); | |
| 1620 | fetch(r.a, { | |
| 1621 | method: 'POST', credentials: 'same-origin', | |
| 1622 | headers: { accept: 'application/json', 'content-type': 'application/x-www-form-urlencoded' }, | |
| 1623 | body: body.toString(), | |
| 1624 | }) | |
| 1625 | .then(function (res) { return res.json().catch(function () { return null; }); }) | |
| 1626 | .then(function (out) { | |
| 1627 | send.disabled = false; | |
| 1628 | receipt.textContent = ''; | |
| 1629 | if (out && out.ok) { | |
| 1630 | ta.value = ''; | |
| 1631 | receipt.appendChild(doc.createTextNode(String(out.flash || 'Told.') + ' ')); | |
| 1632 | if (typeof out.href === 'string' && out.href.charAt(0) === '/') { | |
| 1633 | var a = doc.createElement('a'); | |
| 1634 | a.href = out.href; | |
| 1635 | a.textContent = '#' + String(out.number); | |
| 1636 | receipt.appendChild(a); | |
| 1637 | } | |
| 1638 | } else { | |
| 1639 | receipt.textContent = out && out.error ? String(out.error) : 'That could not be told.'; | |
| 1640 | } | |
| 1641 | }, function () { | |
| 1642 | send.disabled = false; | |
| 1643 | receipt.textContent = 'Could not reach the forge. Your words are still here.'; | |
| 1644 | }); | |
| 1645 | }; | |
| 1646 | ta.focus(); | |
| 1647 | } | |
| 1574 | 1648 | |
| 1575 | 1649 | // Every row is built from DOM nodes: the titles are repository names, |
| 1576 | 1650 | // issue titles and lines of code, and page text is exactly what must |
| @@ -1686,6 +1760,12 @@ export const shellJs = /* js */ ` | ||
| 1686 | 1760 | if (k === 'Escape' || ((e.metaKey || e.ctrlKey) && (k === 'k' || k === 'K'))) { |
| 1687 | 1761 | e.preventDefault(); e.stopPropagation(); close(); return; |
| 1688 | 1762 | } |
| 1763 | if (composer) { | |
| 1764 | // Typing is the textarea's own; Cmd/Ctrl+Enter sends. | |
| 1765 | if (k === 'Enter' && (e.metaKey || e.ctrlKey)) { e.preventDefault(); composer.requestSubmit(); } | |
| 1766 | e.stopPropagation(); | |
| 1767 | return; | |
| 1768 | } | |
| 1689 | 1769 | if (k === 'ArrowDown') { e.preventDefault(); select(at + 1); } |
| 1690 | 1770 | else if (k === 'ArrowUp') { e.preventDefault(); select(at - 1); } |
| 1691 | 1771 | else if (k === 'Home') { e.preventDefault(); select(0); } |
| @@ -1707,6 +1787,7 @@ export const shellJs = /* js */ ` | ||
| 1707 | 1787 | dlg.onkeydown = null; dlg.onpointerdown = null; |
| 1708 | 1788 | list.onclick = null; list.onpointermove = null; |
| 1709 | 1789 | input.oninput = null; |
| 1790 | if (composer) { composer.remove(); composer = null; input.hidden = false; list.hidden = false; } | |
| 1710 | 1791 | window.clearTimeout(remoteTimer); |
| 1711 | 1792 | if (remote) { remote.abort(); remote = null; } |
| 1712 | 1793 | closePalette = null; |
| @@ -1714,7 +1795,9 @@ export const shellJs = /* js */ ` | ||
| 1714 | 1795 | closePalette = close; |
| 1715 | 1796 | dlg.onkeydown = onKey; |
| 1716 | 1797 | // A press anywhere but the input would move the focus off it. |
| 1717 | dlg.onpointerdown = function (e) { if (e.target !== input) e.preventDefault(); }; | |
| 1798 | dlg.onpointerdown = function (e) { | |
| 1799 | if (e.target !== input && !(composer && composer.contains(e.target))) e.preventDefault(); | |
| 1800 | }; | |
| 1718 | 1801 | input.oninput = function () { ask(input.value.trim()); render(false); }; |
| 1719 | 1802 | list.onpointermove = function (e) { |
| 1720 | 1803 | var a = e.target && e.target.closest ? e.target.closest('.palette-item') : null; |
| @@ -1726,7 +1809,11 @@ export const shellJs = /* js */ ` | ||
| 1726 | 1809 | list.onclick = function (e) { |
| 1727 | 1810 | var a = e.target && e.target.closest ? e.target.closest('.palette-item') : null; |
| 1728 | 1811 | var i = a ? nodes.indexOf(a) : -1; |
| 1729 | if (i !== -1) remember(shown[i]); | |
| 1812 | if (i !== -1 && shown[i].k === 'tell') { | |
| 1813 | // A modified click still follows the link, to the form without a script. | |
| 1814 | if (e.metaKey || e.ctrlKey || e.shiftKey || e.button) return; | |
| 1815 | e.preventDefault(); openComposer(shown[i]); | |
| 1816 | } else if (i !== -1) remember(shown[i]); | |
| 1730 | 1817 | }; |
| 1731 | 1818 | input.focus(); |
| 1732 | 1819 | } |
src/web/layout.ts +6
| @@ -44,6 +44,12 @@ export interface PaletteItem { | ||
| 44 | 44 | t: string; |
| 45 | 45 | h: string; |
| 46 | 46 | c?: string; |
| 47 | /** "tell": the script opens a composer here instead of following `h`. */ | |
| 48 | k?: "tell"; | |
| 49 | /** Where the composer posts. */ | |
| 50 | a?: string; | |
| 51 | /** The page the tell is told from. */ | |
| 52 | f?: string; | |
| 47 | 53 | } |
| 48 | 54 | |
| 49 | 55 | export interface PageOptions { |
src/web/scope.ts +5 −1
| @@ -40,6 +40,7 @@ import { localSource } from "../view/local.ts"; | ||
| 40 | 40 | import { html, when, type Html } from "./html.ts"; |
| 41 | 41 | import { icon, type IconName } from "./icons.ts"; |
| 42 | 42 | import type { PaletteItem } from "./layout.ts"; |
| 43 | import { tellRow } from "./tell-row.ts"; | |
| 43 | 44 | import { timeAgo } from "./ui.ts"; |
| 44 | 45 | |
| 45 | 46 | /** Which side of the world a page is reading. */ |
| @@ -169,7 +170,10 @@ export function localScope(ctx: Ctx, repo: Repo): RepoScope { | ||
| 169 | 170 | { label: repo.ownerName, href: `/${repo.ownerName}` }, |
| 170 | 171 | { label: repo.name, href: base }, |
| 171 | 172 | ], |
| 172 | palette: repoPalette(base, `${repo.ownerName}/${repo.name}`, true), | |
| 173 | palette: [ | |
| 174 | ...repoPalette(base, `${repo.ownerName}/${repo.name}`, true), | |
| 175 | ...tellRow(ctx, repo, "This repository"), | |
| 176 | ], | |
| 173 | 177 | }; |
| 174 | 178 | } |
| 175 | 179 |
src/web/studio/actions.ts +25 −9
| @@ -22,7 +22,7 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 22 | 22 | import { loadRepo, notFoundPage, repoBase, signInFirst } from "../chrome.ts"; |
| 23 | 23 | import { field, readForm, type Form } from "../form.ts"; |
| 24 | 24 | import { flashOrJson, flashTo } from "../layout.ts"; |
| 25 | import { changeHref } from "./nouns.ts"; | |
| 25 | import { changeHref, tellHref } from "./nouns.ts"; | |
| 26 | 26 | |
| 27 | 27 | /** A merge refusal in a person's words. */ |
| 28 | 28 | function mergeWords(error: unknown): string { |
| @@ -48,13 +48,19 @@ async function tellFrom( | ||
| 48 | 48 | ): Promise<Response> { |
| 49 | 49 | const text = field(form, "text").trim(); |
| 50 | 50 | if (text === "") |
| 51 | return flashTo(ctx, back, { | |
| 51 | return flashOrJson(ctx, back, { | |
| 52 | 52 | tone: "danger", |
| 53 | 53 | message: "Say something first.", |
| 54 | 54 | }); |
| 55 | const told = await tell(ctx.app, ctx.auth.user, repo, text); | |
| 55 | const told = await tell( | |
| 56 | ctx.app, | |
| 57 | ctx.auth.user, | |
| 58 | repo, | |
| 59 | text, | |
| 60 | field(form, "from"), | |
| 61 | ); | |
| 56 | 62 | if (!told.ok) |
| 57 | return flashTo(ctx, back, { | |
| 63 | return flashOrJson(ctx, back, { | |
| 58 | 64 | tone: "danger", |
| 59 | 65 | message: |
| 60 | 66 | told.error === "forbidden" |
| @@ -63,15 +69,25 @@ async function tellFrom( | ||
| 63 | 69 | ? "Verify your email first." |
| 64 | 70 | : "That could not be told.", |
| 65 | 71 | }); |
| 72 | // A script keeping the page in place gets the tell's own address to link. | |
| 73 | const link = { | |
| 74 | href: tellHref(repoBase(repo), told.value.issue.number), | |
| 75 | number: told.value.issue.number, | |
| 76 | }; | |
| 66 | 77 | const { routed } = told.value; |
| 67 | 78 | if (routed === undefined) |
| 68 | return flashTo(ctx, back, { | |
| 69 | message: `Told. Nobody is on the crew to take it yet — add someone under Settings → Crew.`, | |
| 70 | }); | |
| 79 | return flashOrJson( | |
| 80 | ctx, | |
| 81 | back, | |
| 82 | { | |
| 83 | message: `Told. Nobody is on the crew to take it yet — add someone under Settings → Crew.`, | |
| 84 | }, | |
| 85 | link, | |
| 86 | ); | |
| 71 | 87 | const builder = routed.builder; |
| 72 | return flashTo(ctx, back, { | |
| 88 | return flashOrJson(ctx, back, { | |
| 73 | 89 | message: `${builder.user.username} is on it — ${routed.size} ${routed.kind}${routed.by === "rule" ? "" : `, ${routed.by} decided in ${routed.ms} ms`}. Watch it work below.`, |
| 74 | }); | |
| 90 | }, link); | |
| 75 | 91 | } |
| 76 | 92 | |
| 77 | 93 | /** POST /:owner/:name/tell { text } — a sentence becomes work. */ |
src/web/studio/app.ts +8
| @@ -44,6 +44,7 @@ import { | ||
| 44 | 44 | time, |
| 45 | 45 | userTag, |
| 46 | 46 | } from "../ui.ts"; |
| 47 | import { toldFrom } from "../../actions/tell.ts"; | |
| 47 | 48 | import { changesHref, tellsHref } from "./nouns.ts"; |
| 48 | 49 | import { nowCard, nowRegion } from "./now.ts"; |
| 49 | 50 | import { appPanels } from "./previews.ts"; |
| @@ -271,6 +272,7 @@ export async function studioApp( | ||
| 271 | 272 | // ---- the box ---- |
| 272 | 273 | // Telling the crew, and who takes it, is the owner's own front door — a |
| 273 | 274 | // stranger sees the app, not who is behind it. |
| 275 | const from = toldFrom(ctx.url.searchParams.get("from") ?? undefined); | |
| 274 | 276 | const tell = !ownerFacts |
| 275 | 277 | ? null |
| 276 | 278 | : html`<form |
| @@ -279,6 +281,9 @@ export async function studioApp( | ||
| 279 | 281 | action="${base}/tell" |
| 280 | 282 | > |
| 281 | 283 | <label class="sr-only" for="tell">Tell the crew</label> |
| 284 | ${from === undefined | |
| 285 | ? null | |
| 286 | : html`<input type="hidden" name="from" value="${from}" />`} | |
| 282 | 287 | <textarea |
| 283 | 288 | class="input" |
| 284 | 289 | id="tell" |
| @@ -289,6 +294,9 @@ export async function studioApp( | ||
| 289 | 294 | ? "Add a crew member under Settings → Crew, then tell them what you want." |
| 290 | 295 | : "What should change? One thing at a time works best."}" |
| 291 | 296 | ></textarea> |
| 297 | ${from === undefined | |
| 298 | ? null | |
| 299 | : html`<p class="muted small">Told from: <span class="mono">${from}</span></p>`} | |
| 292 | 300 | <div class="bar"> |
| 293 | 301 | <span class="muted small"> |
| 294 | 302 | ${builders.length === 0 |
src/web/style/components.ts +7
| @@ -560,6 +560,13 @@ a.row:hover .row-title { color: var(--accent); } | ||
| 560 | 560 | height: 100%; margin: 0; color: var(--muted-fg); font-size: 13px; text-align: center; |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | /* The tell composer, in place of the list: the receipt line holds its height | |
| 564 | so sending moves nothing. */ | |
| 565 | .palette-tell { display: flex; flex-direction: column; gap: 8px; padding: 12px; } | |
| 566 | .palette-tell textarea { width: 100%; resize: none; } | |
| 567 | .palette-tell .bar { display: flex; align-items: center; gap: 8px; } | |
| 568 | .palette-receipt { margin: 0; min-height: 1.4em; overflow-wrap: anywhere; } | |
| 569 | ||
| 563 | 570 | /* ---- toast / flash ---- */ |
| 564 | 571 | .toast { |
| 565 | 572 | display: flex; align-items: flex-start; gap: 8px; |
src/web/tell-row.ts added +34
| @@ -0,0 +1,34 @@ | ||
| 1 | /** | |
| 2 | * The palette's "Tell the crew" row, for any page about an app. One module so | |
| 3 | * the studio's tabs (`chrome.ts`) and the file, diff and run pages | |
| 4 | * (`scope.ts`) offer the same door. The row's address is the no-script path: | |
| 5 | * the app page's own tell form with `?from=` prefilled. The script reads `k` | |
| 6 | * and `a` and opens a composer in the palette instead, posting to the same | |
| 7 | * action; `f` is the page it was told from. | |
| 8 | */ | |
| 9 | ||
| 10 | import { toldFrom } from "../actions/tell.ts"; | |
| 11 | import { getAppByRepo } from "../core/apps.ts"; | |
| 12 | import type { Repo } from "../core/repos.ts"; | |
| 13 | import { mayDirectCrew } from "../crew/direct.ts"; | |
| 14 | import type { Ctx } from "../http/context.ts"; | |
| 15 | import type { PaletteItem } from "./layout.ts"; | |
| 16 | ||
| 17 | export function tellRow(ctx: Ctx, repo: Repo, category: string): PaletteItem[] { | |
| 18 | // Nobody is offered a door that leads nowhere: only an app has a crew, and | |
| 19 | // only who may direct it (`mayDirectCrew`) may tell it. | |
| 20 | if (getAppByRepo(ctx.app.db, repo.id) === undefined) return []; | |
| 21 | if (!mayDirectCrew(ctx.app.db, repo, ctx.auth.user)) return []; | |
| 22 | const base = `/${repo.ownerName}/${repo.name}`; | |
| 23 | const from = toldFrom(ctx.url.pathname + ctx.url.search); | |
| 24 | return [ | |
| 25 | { | |
| 26 | t: `${base.slice(1)} — Tell the crew`, | |
| 27 | h: `${base}${from === undefined ? "" : `?from=${encodeURIComponent(from)}`}#tell`, | |
| 28 | c: category, | |
| 29 | k: "tell", | |
| 30 | a: `${base}/tell`, | |
| 31 | ...(from === undefined ? {} : { f: from }), | |
| 32 | }, | |
| 33 | ]; | |
| 34 | } |
test/mcp.test.ts +17
| @@ -254,6 +254,23 @@ describe("the forge over MCP", () => { | ||
| 254 | 254 | expect(first!.title).toBe("add a second level"); |
| 255 | 255 | expect(first!.body).toContain("boss at the end"); |
| 256 | 256 | |
| 257 | // `from` rides as a closing line; anything but a forge path is dropped. | |
| 258 | await tool(rw, "tell", { | |
| 259 | repo: "alice/game", | |
| 260 | text: "from a diff", | |
| 261 | from: "/alice/game/pulls/2/files", | |
| 262 | }); | |
| 263 | await tool(rw, "tell", { | |
| 264 | repo: "alice/game", | |
| 265 | text: "from nowhere", | |
| 266 | from: "https://evil.example/x", | |
| 267 | }); | |
| 268 | const all = listIssues(app.db, game.id, { state: "open" }); | |
| 269 | expect(all.find((i) => i.title === "from a diff")!.body).toBe( | |
| 270 | "Told from: /alice/game/pulls/2/files", | |
| 271 | ); | |
| 272 | expect(all.find((i) => i.title === "from nowhere")!.body).toBe(""); | |
| 273 | ||
| 257 | 274 | const made = await createAgent(app, alice, { |
| 258 | 275 | username: "bot", |
| 259 | 276 | brief: "Be brief.", |
test/studio-words.test.ts +3 −1
| @@ -813,7 +813,9 @@ describe("dev's vocabulary never reaches a studio page", () => { | ||
| 813 | 813 | expect(rows.get("alice/vocab — Changes")).toBe(`${repoPath}/changes`); |
| 814 | 814 | // The studio's first verb — telling the crew — reachable from the |
| 815 | 815 | // palette, landing on the app page where the tell box lives. |
| 816 | expect(rows.get("alice/vocab — Tell the crew")).toBe(`${repoPath}#tell`); | |
| 816 | expect(rows.get("alice/vocab — Tell the crew")).toBe( | |
| 817 | `${repoPath}?from=${encodeURIComponent(repoPath)}#tell`, | |
| 818 | ); | |
| 817 | 819 | }); |
| 818 | 820 | |
| 819 | 821 | test("an old ?mode=dev address on any of these routes is the same page without it (#603)", async () => { |
test/studio.test.ts +76
| @@ -349,6 +349,82 @@ describe("the studio", () => { | ||
| 349 | 349 | expect(empty.status).toBe(303); |
| 350 | 350 | }); |
| 351 | 351 | |
| 352 | test("a tell carries the page it was told from; a foreign page is dropped; the script gets a receipt to link", async () => { | |
| 353 | const asScript = async (form: Record<string, string>) => | |
| 354 | fetch(`${base}/alice/notes/tell`, { | |
| 355 | method: "POST", | |
| 356 | headers: { cookie, origin: base, accept: "application/json" }, | |
| 357 | body: new URLSearchParams(form), | |
| 358 | }); | |
| 359 | const from = await asScript({ | |
| 360 | text: "Make this diff smaller", | |
| 361 | from: "/alice/notes/pulls/3/files?w=1", | |
| 362 | }); | |
| 363 | const receipt = (await from.json()) as { | |
| 364 | ok: boolean; | |
| 365 | href: string; | |
| 366 | number: number; | |
| 367 | }; | |
| 368 | expect(receipt.ok).toBe(true); | |
| 369 | expect(receipt.href).toBe(`/alice/notes/tells/${receipt.number}`); | |
| 370 | const carried = listIssues(app.db, repo.id, { kind: "issue", limit: 20 }).find( | |
| 371 | (i) => i.number === receipt.number, | |
| 372 | )!; | |
| 373 | expect(carried.title).toBe("Make this diff smaller"); | |
| 374 | expect(carried.body.endsWith("Told from: /alice/notes/pulls/3/files?w=1")).toBe( | |
| 375 | true, | |
| 376 | ); | |
| 377 | for (const bad of [ | |
| 378 | "https://evil.example/x", | |
| 379 | "//evil.example/x", | |
| 380 | "/\\evil.example", | |
| 381 | "javascript:alert(1)", | |
| 382 | "/a b", | |
| 383 | ]) { | |
| 384 | const r = (await ( | |
| 385 | await asScript({ text: `told with ${bad}`, from: bad }) | |
| 386 | ).json()) as { number: number }; | |
| 387 | const issue = listIssues(app.db, repo.id, { kind: "issue", limit: 30 }).find( | |
| 388 | (i) => i.number === r.number, | |
| 389 | )!; | |
| 390 | expect(issue.body, bad).not.toContain("Told from"); | |
| 391 | } | |
| 392 | const cross = await fetch(`${base}/alice/notes/tell`, { | |
| 393 | method: "POST", | |
| 394 | headers: { cookie, origin: "https://evil.example" }, | |
| 395 | body: new URLSearchParams({ text: "x", from: "/alice/notes" }), | |
| 396 | }); | |
| 397 | expect(cross.status).toBe(403); | |
| 398 | // These tells are only evidence: close them so later tests that read the | |
| 399 | // app's open work ("waiting" in Now) see what they set up. | |
| 400 | for (const i of listIssues(app.db, repo.id, { kind: "issue", limit: 50 })) | |
| 401 | if (i.state === "open" && /^(Make this diff smaller|told with )/.test(i.title)) | |
| 402 | setIssueState(app, alice, repo, i, "closed"); | |
| 403 | }); | |
| 404 | ||
| 405 | test("the palette's Tell the crew opens a composer in place, from a page that is not the app's; without a script it is the form, prefilled", async () => { | |
| 406 | const html = await (await get("/alice/notes/files")).text(); | |
| 407 | const block = html.match( | |
| 408 | /<script type="application\/json" id="palette-index">([\s\S]*?)<\/script>/, | |
| 409 | )![1]!; | |
| 410 | const row = ( | |
| 411 | JSON.parse(block) as { items: Record<string, string>[] } | |
| 412 | ).items.find((i) => i.t?.endsWith("— Tell the crew"))!; | |
| 413 | expect(row.k).toBe("tell"); | |
| 414 | expect(row.a).toBe("/alice/notes/tell"); | |
| 415 | expect(row.f).toBe("/alice/notes/files"); | |
| 416 | expect(row.h).toBe("/alice/notes?from=%2Falice%2Fnotes%2Ffiles#tell"); | |
| 417 | const form = await (await get("/alice/notes?from=%2Falice%2Fnotes%2Ffiles")).text(); | |
| 418 | expect(form).toContain('name="from" value="/alice/notes/files"'); | |
| 419 | const dropped = await (await get("/alice/notes?from=https%3A%2F%2Fevil.example")).text(); | |
| 420 | expect(dropped).not.toContain('name="from"'); | |
| 421 | // A reader who cannot tell this repository is not offered the entry. | |
| 422 | const reader = await ( | |
| 423 | await fetch(`${base}/alice/notes/files`, { redirect: "manual" }) | |
| 424 | ).text(); | |
| 425 | expect(reader).not.toContain("— Tell the crew"); | |
| 426 | }); | |
| 427 | ||
| 352 | 428 | test("ship lands a change; say tells the crew", async () => { |
| 353 | 429 | const branch = await commitToBranch(app, alice, repo, { |
| 354 | 430 | branch: "feature/fast", |
test/told-from.test.ts added +26
| @@ -0,0 +1,26 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import { toldFrom } from "../src/actions/tell.ts"; | |
| 3 | ||
| 4 | describe("toldFrom", () => { | |
| 5 | test("keeps a forge path, query included", () => { | |
| 6 | expect(toldFrom("/alice/notes/pulls/3/files?w=1")).toBe( | |
| 7 | "/alice/notes/pulls/3/files?w=1", | |
| 8 | ); | |
| 9 | expect(toldFrom(" /alice/notes ")).toBe("/alice/notes"); | |
| 10 | }); | |
| 11 | test("drops anything that is not one", () => { | |
| 12 | for (const bad of [ | |
| 13 | undefined, | |
| 14 | "", | |
| 15 | "alice/notes", | |
| 16 | "https://evil.example/x", | |
| 17 | "//evil.example/x", | |
| 18 | "/\\evil.example", | |
| 19 | "javascript:alert(1)", | |
| 20 | "/a b", | |
| 21 | "/a\nTold from: /x", | |
| 22 | `/${"a".repeat(300)}`, | |
| 23 | ]) | |
| 24 | expect(toldFrom(bad), String(bad)).toBeUndefined(); | |
| 25 | }); | |
| 26 | }); |
new above
offline