Public: anyone can read this; the crew can change it.
A client's first screen offers "Ask for something" on each app, opening the tell form for that app #3357
scout/forge:scout/3345-a-client-s-first-screen-offers-ask-for-s → main 2 commits fork
10 files
changed +145
−6
README.md +6
| @@ -1845,3 +1845,9 @@ same rule. A guard installed by hand without the prefix answers `refused` | ||
| 1845 | 1845 | until it is re-created with `forge: ` in front of its message. |
| 1846 | 1846 | |
| 1847 | 1847 | `reach` is a boards source for an admin only (anyone else gets 403, an agent too): `visitors` per day, `lcp_p75` and `inp_p75` per route per day, `server_p50` and `server_p95` per route per day (the beacon's time to first byte, the only per-route server timing the forge keeps), and `accounts_active_1d`, `accounts_active_7d` and `accounts_total` as of now. Filter by `metric`, group by `route` or a time bucket. Percentiles are nearest-rank within one route and day, so a `max` or `avg` over several days is a summary of daily percentiles, not a percentile of the period. Account activity comes from a session's last-seen time, so it is a count as of now, not a history. No dependency was added. |
| 1848 | ||
| 1849 | A client's first screen offers "Ask for something" on each app they may direct | |
| 1850 | (`mayDirectCrew`): on the web a link to `/:owner/:name/tell?from=/&ask=1` (no | |
| 1851 | script), in the terminal the `t` key on the app under the cursor. Both go | |
| 1852 | through the same `tell()` and answer "Sent. The agents will pick it up."; the | |
| 1853 | web returns to `/` with that line. |
src/actions/tell.ts +3
| @@ -64,6 +64,9 @@ export function parseFrom(raw: unknown): string | null | undefined { | ||
| 64 | 64 | export const FROM_WORDS = |
| 65 | 65 | "from is a path on this forge, like /alice/notes/pulls/3, at most 512 characters"; |
| 66 | 66 | |
| 67 | /** What a client reads after asking for something, on the web and in the terminal. */ | |
| 68 | export const SENT_WORDS = "Sent. The agents will pick it up."; | |
| 69 | ||
| 67 | 70 | export type TellError = |
| 68 | 71 | | "empty" |
| 69 | 72 | | "bad_from" |
src/tui/screens/dashboard.ts +11
| @@ -22,6 +22,7 @@ import { coveredByVerdict, forgeVerdict, verdictLine } from "../../kernel/guard_ | ||
| 22 | 22 | import { clientAppRows } from "../../core/client-apps.ts"; |
| 23 | 23 | import { nextStepsFor } from "../../core/next-steps.ts"; |
| 24 | 24 | import { agentsLine } from "../../web/studio/client_home.ts"; |
| 25 | import { askForSomething } from "./tell.ts"; | |
| 25 | 26 | import { mayView } from "../../core/sealed.ts"; |
| 26 | 27 | import { applyFleetIds, previewFleetIds, undoFleetOp } from "../../actions/fleet.ts"; |
| 27 | 28 | import { plain } from "./boards.ts"; |
| @@ -158,6 +159,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 158 | 159 | let forge: string[] | undefined; |
| 159 | 160 | /** A client's apps, one sentence each on whether its agents work or wait (#1812). */ |
| 160 | 161 | let clientLines: string[] = []; |
| 162 | /** The ids of those apps, so the key that asks for something stays on them. */ | |
| 163 | let clientRepoIds = new Set<string>(); | |
| 161 | 164 | /** The check lane, as the board's strip says it; null when nothing is queued. */ |
| 162 | 165 | let lane: string | null = null; |
| 163 | 166 | /** What the decider did today, the board's Today line; null on a quiet day or for a reader. */ |
| @@ -181,6 +184,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 181 | 184 | // A client's home never carries the forge-wide figures, on either door. |
| 182 | 185 | figures = []; |
| 183 | 186 | const apps = await clientAppRows(f.app, f.user); |
| 187 | clientRepoIds = new Set(apps.map((a) => a.repo.id)); | |
| 184 | 188 | clientLines = |
| 185 | 189 | apps.length === 0 |
| 186 | 190 | ? ["Your apps will appear here."] |
| @@ -758,6 +762,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 758 | 762 | disabled: focus !== "machine" || pins.length === 0, |
| 759 | 763 | }), |
| 760 | 764 | binding(["C"], "decider", { disabled: !f.user }), |
| 765 | ...(clientLines.length > 0 ? [binding(["t"], "ask for something")] : []), | |
| 761 | 766 | binding(["n"], "new repo", { disabled: !f.signedIn }), |
| 762 | 767 | binding(["A"], "account", { disabled: !f.signedIn }), |
| 763 | 768 | binding(["s"], "sign in", { disabled: f.signedIn }), |
| @@ -951,6 +956,12 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 951 | 956 | } |
| 952 | 957 | return true; |
| 953 | 958 | } |
| 959 | if (e.key === "t" && f.user && clientLines.length > 0) { | |
| 960 | // A client's apps are the list; the one under the cursor is asked. | |
| 961 | const repo = shown()[at("repos").index]; | |
| 962 | if (repo && clientRepoIds.has(repo.id)) askForSomething(f, ctx, () => screen, repo); | |
| 963 | return true; | |
| 964 | } | |
| 954 | 965 | if (e.key === "n" && f.signedIn) { |
| 955 | 966 | ctx.push(newRepoScreen(f, ctx)); |
| 956 | 967 | return true; |
src/tui/screens/tell.ts +21 −1
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | * the same `parseContext` and `contextNote` the pill's tell and the MCP use. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { tell, toldWords, TOO_LONG_WORDS, UNVERIFIED_WORDS, type Told, type TellError } from "../../actions/tell.ts"; | |
| 11 | import { SENT_WORDS, tell, toldWords, TOO_LONG_WORDS, UNVERIFIED_WORDS, type Told, type TellError } from "../../actions/tell.ts"; | |
| 12 | 12 | import { contextNote, parseContext } from "../../actions/tell_context.ts"; |
| 13 | 13 | import type { Repo } from "../../core/repos.ts"; |
| 14 | 14 | import { DIRECTION_NOTE, mayDirectCrew } from "../../crew/direct.ts"; |
| @@ -118,3 +118,23 @@ export async function tellFromPage( | ||
| 118 | 118 | const answer = tellAnswer(await tell(f.app, f.user, repo, `${said}${contextNote(where)}`)); |
| 119 | 119 | ctx.toast(answer.text, answer.tone); |
| 120 | 120 | } |
| 121 | ||
| 122 | /** A client's "Ask for something" on the first screen: one line to the app's crew, answered in the web's words. */ | |
| 123 | export function askForSomething(f: Session, ctx: Ctx, parent: () => Screen, repo: Repo): void { | |
| 124 | if (!mayDirectCrew(f.db, repo, f.user)) return; | |
| 125 | ctx.push( | |
| 126 | promptScreen(ctx, parent(), { | |
| 127 | title: "Ask for something", | |
| 128 | label: repo.name, | |
| 129 | hint: "enter sends", | |
| 130 | onSubmit: (said) => { | |
| 131 | if (said === "") return "Say something first."; | |
| 132 | return (async () => { | |
| 133 | const told = await tell(f.app, f.user, repo, said, 1, "/"); | |
| 134 | const answer = told.ok ? { text: SENT_WORDS, tone: "success" as const } : tellAnswer(told); | |
| 135 | ctx.toast(answer.text, answer.tone); | |
| 136 | })(); | |
| 137 | }, | |
| 138 | }), | |
| 139 | ); | |
| 140 | } |
src/web/pages/thread.ts +5 −2
| @@ -431,7 +431,7 @@ export interface ComposerOptions { | ||
| 431 | 431 | * the button tells the crew, and `from` (a path on this forge, or null) |
| 432 | 432 | * rides along as a hidden field so the tell remembers the page it was |
| 433 | 433 | * said on (`actions/tell.ts`). `rows` sizes it; one is a single line. */ |
| 434 | tell?: { from: string | null; rows?: number; page?: string; pull?: number; text?: string }; | |
| 434 | tell?: { from: string | null; rows?: number; page?: string; pull?: number; text?: string; ask?: boolean }; | |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** The comment box. Close and reopen are their own form, not an `intent` |
| @@ -516,6 +516,9 @@ export function composer(ctx: Ctx, o: ComposerOptions): Html { | ||
| 516 | 516 | ${tell?.from |
| 517 | 517 | ? html`<input type="hidden" name="from" value="${tell.from}" />` |
| 518 | 518 | : null} |
| 519 | ${tell?.ask | |
| 520 | ? html`<input type="hidden" name="ask" value="1" />` | |
| 521 | : null} | |
| 519 | 522 | ${tell?.page |
| 520 | 523 | ? html`<input type="hidden" name="page" value="${tell.page}" />` |
| 521 | 524 | : null} |
| @@ -528,7 +531,7 @@ export function composer(ctx: Ctx, o: ComposerOptions): Html { | ||
| 528 | 531 | <div class="form-actions"> |
| 529 | 532 | <span class="muted small" |
| 530 | 533 | >${tell |
| 531 | ? html`${tell.from | |
| 534 | ? html`${tell.from && !tell.ask | |
| 532 | 535 | ? html`From <code>${tell.from}</code>. ` |
| 533 | 536 | : null}${tell.page |
| 534 | 537 | ? html`From <code>${tell.page}</code>. ` |
src/web/studio/actions.ts +4 −1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | import { mayView } from "../../core/sealed.ts"; |
| 12 | 12 | import { holdPull, releasePull } from "../../actions/holds.ts"; |
| 13 | 13 | import { addComment } from "../../actions/issues.ts"; |
| 14 | import { parseFrom, tell, toldWords, TOO_LONG_WORDS } from "../../actions/tell.ts"; | |
| 14 | import { parseFrom, SENT_WORDS, tell, toldWords, TOO_LONG_WORDS } from "../../actions/tell.ts"; | |
| 15 | 15 | import { contextNote, parseContext } from "../../actions/tell_context.ts"; |
| 16 | 16 | import { keepThought } from "../../actions/thought.ts"; |
| 17 | 17 | import { DIRECTION_NOTE } from "../../crew/direct.ts"; |
| @@ -77,6 +77,9 @@ async function tellFrom( | ||
| 77 | 77 | : "That could not be told.", |
| 78 | 78 | }); |
| 79 | 79 | const { routed } = told.value; |
| 80 | // A client's "Ask for something" (named by the form, not guessed from `/`): | |
| 81 | // they asked for something and want nothing more than to know it went. | |
| 82 | if (from === "/" && field(form, "ask") === "1") return flashOrJson(ctx, back, { message: SENT_WORDS }); | |
| 80 | 83 | if (routed === undefined) |
| 81 | 84 | return flashOrJson(ctx, back, { |
| 82 | 85 | message: `Told. Nobody is on the crew to take it yet — add someone under Settings → Crew.`, |
src/web/studio/client_home.ts +10 −2
| @@ -10,9 +10,10 @@ import { notePhase, takeSessionTime, timePhaseAsync } from "../../core/route_tim | ||
| 10 | 10 | import { clientAppRows } from "../../core/client-apps.ts"; |
| 11 | 11 | import type { User } from "../../core/users.ts"; |
| 12 | 12 | import type { Ctx } from "../../http/context.ts"; |
| 13 | import { mayDirectCrew } from "../../crew/direct.ts"; | |
| 13 | 14 | import { repoBase } from "../chrome.ts"; |
| 14 | 15 | import { html, type Html } from "../html.ts"; |
| 15 | import { card } from "../ui.ts"; | |
| 16 | import { btn, card } from "../ui.ts"; | |
| 16 | 17 | |
| 17 | 18 | /** The sentence about the agents, from how many are going and how many are lined up. */ |
| 18 | 19 | export function agentsLine(working: number, queued: number): string { |
| @@ -31,8 +32,15 @@ export async function clientApps(ctx: Ctx, user: User): Promise<Html> { | ||
| 31 | 32 | const rendering = performance.now(); |
| 32 | 33 | const rows = apps.map(({ repo, working, queued }) => { |
| 33 | 34 | const about = repo.description !== "" ? repo.description : "An app of yours."; |
| 35 | // The tell form with this app chosen; it sends the person back to `/`. | |
| 36 | const ask = mayDirectCrew(ctx.app.db, repo, user) | |
| 37 | ? btn("Ask for something", { | |
| 38 | href: `${repoBase(repo)}/tell?from=/&ask=1`, | |
| 39 | variant: "outline", | |
| 40 | }) | |
| 41 | : null; | |
| 34 | 42 | return html`<li class="client-app"> |
| 35 | <a href="${repoBase(repo)}"><b>${repo.name}</b></a> | |
| 43 | <a href="${repoBase(repo)}"><b>${repo.name}</b></a> ${ask} | |
| 36 | 44 | <span class="client-app-about">${about}</span> |
| 37 | 45 | <span class="client-app-agents muted" data-agents="${working > 0 ? "working" : "waiting"}" |
| 38 | 46 | >${agentsLine(working, queued)}</span |
src/web/studio/feed_style.ts +4
| @@ -14,6 +14,10 @@ export const feedCss = /* css */ ` | ||
| 14 | 14 | .fcard-unblock span { flex: 1 1 16ch; min-width: 0; overflow-wrap: anywhere; } |
| 15 | 15 | .fcard-who { font-weight: 600; } |
| 16 | 16 | .fcard-why { margin: 0 0 4px; } |
| 17 | /* A client's app row: its name, its words, then one outlined action. */ | |
| 18 | .client-app { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; } | |
| 19 | .client-app > .client-app-about, .client-app > .client-app-agents { flex: 1 1 100%; } | |
| 20 | .client-app > .btn { margin-left: auto; } | |
| 17 | 21 | /* The composer: the home's one primary action, on top of the timeline. */ |
| 18 | 22 | .composer { display: grid; gap: 8px; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--card, var(--bg)); } |
| 19 | 23 | .composer textarea { width: 100%; min-height: 64px; resize: vertical; } |
src/web/studio/tell_here.ts +2
| @@ -40,6 +40,8 @@ export function tellHerePage(ctx: Ctx): Response { | ||
| 40 | 40 | from, |
| 41 | 41 | rows: ctx.url.searchParams.get("in") === "place" ? 1 : 4, |
| 42 | 42 | ...(text === "" ? {} : { text }), |
| 43 | // A client's "Ask for something": sent from `/`, and said plainly there. | |
| 44 | ...(ctx.url.searchParams.get("ask") === "1" && from === "/" ? { ask: true } : {}), | |
| 43 | 45 | ...(where?.page === undefined ? {} : { page: where.page }), |
| 44 | 46 | ...(where?.pull === undefined ? {} : { pull: where.pull }), |
| 45 | 47 | }, |
test/client-home.test.ts +79
| @@ -12,6 +12,8 @@ import { join } from "node:path"; | ||
| 12 | 12 | import { createRepo } from "../src/actions/repos.ts"; |
| 13 | 13 | import { childDirOf, spawnForge } from "../src/actions/spawn.ts"; |
| 14 | 14 | import { createApp, type App } from "../src/app.ts"; |
| 15 | import { clientApps } from "../src/web/studio/client_home.ts"; | |
| 16 | import type { Ctx } from "../src/http/context.ts"; | |
| 15 | 17 | import { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts"; |
| 16 | 18 | import { createSession } from "../src/core/sessions.ts"; |
| 17 | 19 | import { linkEveryday } from "../src/core/everyday.ts"; |
| @@ -176,6 +178,83 @@ describe("a client's first screen", () => { | ||
| 176 | 178 | expect(home).toContain('href="/?all=1"'); |
| 177 | 179 | }); |
| 178 | 180 | |
| 181 | test("each app offers Ask for something, which opens the tell form for it, and sending lands back here", async () => { | |
| 182 | const home = main(await page(owner)); | |
| 183 | expect(home).toContain('href="/marias/bakery/tell?from=/&ask=1"'); | |
| 184 | expect(home).toContain("Ask for something"); | |
| 185 | const form = await page(owner, "/marias/bakery/tell?from=/&ask=1"); | |
| 186 | expect(form).toContain('action="/marias/bakery/tell"'); | |
| 187 | expect(form).toContain('name="ask" value="1"'); | |
| 188 | expect(form).not.toContain("From <code>"); | |
| 189 | const sent = await post(owner, "/marias/bakery/tell", { text: "Add a rye loaf", from: "/", ask: "1" }); | |
| 190 | expect(sent.status).toBe(303); | |
| 191 | expect(new URL(sent.headers.get("location")!, servers.url).pathname).toBe("/"); | |
| 192 | const flash = sent.headers.get("set-cookie")!.split(";")[0]!; | |
| 193 | expect(await page(`${owner}; ${flash}`)).toContain("Sent. The agents will pick it up."); | |
| 194 | }); | |
| 195 | ||
| 196 | test("a tell sent from / without asking keeps its routed line", async () => { | |
| 197 | const sent = await post(owner, "/marias/bakery/tell", { text: "Add a plain loaf", from: "/" }); | |
| 198 | const flash = decodeURIComponent(sent.headers.get("set-cookie")!); | |
| 199 | expect(flash).not.toContain("Sent. The agents will pick it up."); | |
| 200 | }); | |
| 201 | ||
| 202 | test("the link keeps the same-origin rule: a tell from another origin is refused", async () => { | |
| 203 | const res = await fetch(url("/marias/bakery/tell"), { | |
| 204 | method: "POST", | |
| 205 | headers: { cookie: owner, origin: "https://evil.test" }, | |
| 206 | body: new URLSearchParams({ text: "x", from: "/" }), | |
| 207 | redirect: "manual", | |
| 208 | }); | |
| 209 | expect(res.status).toBeGreaterThanOrEqual(400); | |
| 210 | }); | |
| 211 | ||
| 212 | test("a viewer who may not tell is offered no link", async () => { | |
| 213 | const reader = await createUser(child.db, { | |
| 214 | origin: "seed", | |
| 215 | trusted: true, | |
| 216 | username: "lookeronly", | |
| 217 | email: "[email protected]", | |
| 218 | password: PASSWORD, | |
| 219 | }); | |
| 220 | if (!reader.ok) throw new Error("reader"); | |
| 221 | child.db.query("UPDATE repo SET visibility = 'public' WHERE name = 'bakery'").run(); | |
| 222 | try { | |
| 223 | const ctx = { | |
| 224 | app: child, | |
| 225 | request: new Request("https://x.test/"), | |
| 226 | auth: { user: reader.value }, | |
| 227 | } as unknown as Ctx; | |
| 228 | const shown = String(await clientApps(ctx, reader.value)); | |
| 229 | expect(shown).toContain('href="/marias/bakery"'); | |
| 230 | expect(shown).not.toContain("Ask for something"); | |
| 231 | const maria = getUserByName(child.db, "maria")!; | |
| 232 | expect(String(await clientApps(ctx, maria))).toContain("Ask for something"); | |
| 233 | } finally { | |
| 234 | child.db.query("UPDATE repo SET visibility = 'private' WHERE name = 'bakery'").run(); | |
| 235 | } | |
| 236 | }); | |
| 237 | ||
| 238 | test("the terminal's first screen asks for something with t, in the web's words", async () => { | |
| 239 | const maria = getUserByName(child.db, "maria")!; | |
| 240 | const terminal = headlessTerminal(120, 30); | |
| 241 | const { app } = createForgeApp( | |
| 242 | child, | |
| 243 | { sshUsername: "maria", remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user: maria }, | |
| 244 | { terminal, exitHooks: false }, | |
| 245 | ); | |
| 246 | app.start(); | |
| 247 | await settleApp(app); | |
| 248 | for (const k of ["t", ..."a rye loaf".split(""), "\r"]) { | |
| 249 | terminal.feed(k); | |
| 250 | await settleApp(app); | |
| 251 | } | |
| 252 | expect(app.screen.toText()).toContain("Sent. The agents will pick it up."); | |
| 253 | const told = child.db.query("SELECT COUNT(*) AS n FROM issue WHERE title LIKE '%rye loaf%'").get() as { n: number }; | |
| 254 | expect(told.n).toBeGreaterThan(0); | |
| 255 | app.stop(); | |
| 256 | }); | |
| 257 | ||
| 179 | 258 | test("a running agent turns the line to working", async () => { |
| 180 | 259 | const repo = child.db |
| 181 | 260 | .query<{ id: string }, []>("SELECT id FROM repo WHERE name = 'bakery'") |
new above
offline