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

Parked opened this
Closed without merging

scout/forge:scout/3345-a-client-s-first-screen-offers-ask-for-s → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
10 files changed +145 −6
README.md +6
@@ -1845,3 +1845,9 @@ same rule. A guard installed by hand without the prefix answers `refused`
18451845 until it is re-created with `forge: ` in front of its message.
18461846
18471847 `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 {
6464 export const FROM_WORDS =
6565 "from is a path on this forge, like /alice/notes/pulls/3, at most 512 characters";
6666
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
6770 export type TellError =
6871 | "empty"
6972 | "bad_from"
src/tui/screens/dashboard.ts +11
@@ -22,6 +22,7 @@ import { coveredByVerdict, forgeVerdict, verdictLine } from "../../kernel/guard_
2222 import { clientAppRows } from "../../core/client-apps.ts";
2323 import { nextStepsFor } from "../../core/next-steps.ts";
2424 import { agentsLine } from "../../web/studio/client_home.ts";
25 import { askForSomething } from "./tell.ts";
2526 import { mayView } from "../../core/sealed.ts";
2627 import { applyFleetIds, previewFleetIds, undoFleetOp } from "../../actions/fleet.ts";
2728 import { plain } from "./boards.ts";
@@ -158,6 +159,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
158159 let forge: string[] | undefined;
159160 /** A client's apps, one sentence each on whether its agents work or wait (#1812). */
160161 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>();
161164 /** The check lane, as the board's strip says it; null when nothing is queued. */
162165 let lane: string | null = null;
163166 /** 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 {
181184 // A client's home never carries the forge-wide figures, on either door.
182185 figures = [];
183186 const apps = await clientAppRows(f.app, f.user);
187 clientRepoIds = new Set(apps.map((a) => a.repo.id));
184188 clientLines =
185189 apps.length === 0
186190 ? ["Your apps will appear here."]
@@ -758,6 +762,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
758762 disabled: focus !== "machine" || pins.length === 0,
759763 }),
760764 binding(["C"], "decider", { disabled: !f.user }),
765 ...(clientLines.length > 0 ? [binding(["t"], "ask for something")] : []),
761766 binding(["n"], "new repo", { disabled: !f.signedIn }),
762767 binding(["A"], "account", { disabled: !f.signedIn }),
763768 binding(["s"], "sign in", { disabled: f.signedIn }),
@@ -951,6 +956,12 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
951956 }
952957 return true;
953958 }
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 }
954965 if (e.key === "n" && f.signedIn) {
955966 ctx.push(newRepoScreen(f, ctx));
956967 return true;
src/tui/screens/tell.ts +21 −1
@@ -8,7 +8,7 @@
88 * the same `parseContext` and `contextNote` the pill's tell and the MCP use.
99 */
1010
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";
1212 import { contextNote, parseContext } from "../../actions/tell_context.ts";
1313 import type { Repo } from "../../core/repos.ts";
1414 import { DIRECTION_NOTE, mayDirectCrew } from "../../crew/direct.ts";
@@ -118,3 +118,23 @@ export async function tellFromPage(
118118 const answer = tellAnswer(await tell(f.app, f.user, repo, `${said}${contextNote(where)}`));
119119 ctx.toast(answer.text, answer.tone);
120120 }
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 {
431431 * the button tells the crew, and `from` (a path on this forge, or null)
432432 * rides along as a hidden field so the tell remembers the page it was
433433 * 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 };
435435 }
436436
437437 /** 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 {
516516 ${tell?.from
517517 ? html`<input type="hidden" name="from" value="${tell.from}" />`
518518 : null}
519 ${tell?.ask
520 ? html`<input type="hidden" name="ask" value="1" />`
521 : null}
519522 ${tell?.page
520523 ? html`<input type="hidden" name="page" value="${tell.page}" />`
521524 : null}
@@ -528,7 +531,7 @@ export function composer(ctx: Ctx, o: ComposerOptions): Html {
528531 <div class="form-actions">
529532 <span class="muted small"
530533 >${tell
531 ? html`${tell.from
534 ? html`${tell.from && !tell.ask
532535 ? html`From <code>${tell.from}</code>. `
533536 : null}${tell.page
534537 ? html`From <code>${tell.page}</code>. `
src/web/studio/actions.ts +4 −1
@@ -11,7 +11,7 @@
1111 import { mayView } from "../../core/sealed.ts";
1212 import { holdPull, releasePull } from "../../actions/holds.ts";
1313 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";
1515 import { contextNote, parseContext } from "../../actions/tell_context.ts";
1616 import { keepThought } from "../../actions/thought.ts";
1717 import { DIRECTION_NOTE } from "../../crew/direct.ts";
@@ -77,6 +77,9 @@ async function tellFrom(
7777 : "That could not be told.",
7878 });
7979 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 });
8083 if (routed === undefined)
8184 return flashOrJson(ctx, back, {
8285 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
1010 import { clientAppRows } from "../../core/client-apps.ts";
1111 import type { User } from "../../core/users.ts";
1212 import type { Ctx } from "../../http/context.ts";
13 import { mayDirectCrew } from "../../crew/direct.ts";
1314 import { repoBase } from "../chrome.ts";
1415 import { html, type Html } from "../html.ts";
15 import { card } from "../ui.ts";
16 import { btn, card } from "../ui.ts";
1617
1718 /** The sentence about the agents, from how many are going and how many are lined up. */
1819 export function agentsLine(working: number, queued: number): string {
@@ -31,8 +32,15 @@ export async function clientApps(ctx: Ctx, user: User): Promise<Html> {
3132 const rendering = performance.now();
3233 const rows = apps.map(({ repo, working, queued }) => {
3334 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;
3442 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}
3644 <span class="client-app-about">${about}</span>
3745 <span class="client-app-agents muted" data-agents="${working > 0 ? "working" : "waiting"}"
3846 >${agentsLine(working, queued)}</span
src/web/studio/feed_style.ts +4
@@ -14,6 +14,10 @@ export const feedCss = /* css */ `
1414 .fcard-unblock span { flex: 1 1 16ch; min-width: 0; overflow-wrap: anywhere; }
1515 .fcard-who { font-weight: 600; }
1616 .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; }
1721 /* The composer: the home's one primary action, on top of the timeline. */
1822 .composer { display: grid; gap: 8px; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--card, var(--bg)); }
1923 .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 {
4040 from,
4141 rows: ctx.url.searchParams.get("in") === "place" ? 1 : 4,
4242 ...(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 } : {}),
4345 ...(where?.page === undefined ? {} : { page: where.page }),
4446 ...(where?.pull === undefined ? {} : { pull: where.pull }),
4547 },
test/client-home.test.ts +79
@@ -12,6 +12,8 @@ import { join } from "node:path";
1212 import { createRepo } from "../src/actions/repos.ts";
1313 import { childDirOf, spawnForge } from "../src/actions/spawn.ts";
1414 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";
1517 import { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts";
1618 import { createSession } from "../src/core/sessions.ts";
1719 import { linkEveryday } from "../src/core/everyday.ts";
@@ -176,6 +178,83 @@ describe("a client's first screen", () => {
176178 expect(home).toContain('href="/?all=1"');
177179 });
178180
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=/&amp;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
179258 test("a running agent turns the line to working", async () => {
180259 const repo = child.db
181260 .query<{ id: string }, []>("SELECT id FROM repo WHERE name = 'bakery'")

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs