Public: anyone can read this; the crew can change it.

Revert "An empty talk conversation offers three starter prompts that each send in one tap" #13572

Closed opened this
Closed without merging

revert-13339 → main 1 commit

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
8 files changed +48 −111
docs/features/README.md −1
@@ -99,7 +99,6 @@ Read with the guide page [Tell the crew](../guide-tell-the-crew.md).
9999 - [Tell the crew from the terminal's screen: key M](tell-from-here.md)
100100 - [A write the restart cut short, in a conversation](talk-resume-writes.md)
101101 - [Actions that answer at once](act-now.md)
102 - [Starter prompts in an empty conversation](talk-starters.md)
103102 - [A thread folds its settled history](thread-fold.md)
104103 - [An agent says what it does; a repo's team is three lists](crew-roles.md)
105104 - [An assigned ask can be settled where it stands](ask-settles.md)
docs/features/talk-starters.md deleted −11
@@ -1,11 +0,0 @@
1 # Starter prompts in an empty conversation (#13317)
2
3 An empty `/talk` conversation offers three prompts, each a one-tap send: "What is waiting for me?", "What shipped this week?" and "Start something new". The list is `STARTER_PROMPTS` in `src/actions/talk.ts`.
4
5 - Each is a `form[data-starter]` that posts its words to the same handler as the composer (`talkSend`), so the same-origin check, the rate limit and the account checks apply unchanged.
6 - With script, `talk_client.ts` puts the words in the composer and submits it, so the reply streams in place. Without script the form posts and redirects back to the conversation; reload to see the answer, as with the composer.
7 - They show only while the conversation has no turns and is not paged.
8
9 ## In the terminal
10
11 The Conversations screen (`src/tui/screens/talk_chats.ts`, palette entry "Conversations") offers the same `STARTER_PROMPTS` in a conversation with nothing said yet, numbered 1 to 3. Pressing a number sends that prompt through the same `talk()` call that `s` uses, in that conversation. The header shows the result or the refusal; `r` reloads to see the answer. Once a turn exists the list goes away and the numbers send nothing.
src/actions/talk.ts −3
@@ -18,9 +18,6 @@ import { err, ok, type Result } from "../kernel/result.ts";
1818 /** Messages a person may send in a minute. */
1919 export const TALK_PER_MINUTE = 12;
2020
21 /** What an empty conversation offers to send in one tap: plain text, the one list. */
22 export const STARTER_PROMPTS = ["What is waiting for me?", "What shipped this week?", "Start something new"] as const;
23
2421 export type TalkRefusal = SayRefusal | RedoRefusal | "off" | "rate_limited";
2522
2623 /** What each refusal says, with its status. */
src/tui/screens/talk_chats.ts +3 −24
@@ -5,11 +5,9 @@
55 * `a` flips between the live list and the archived one; Enter opens one,
66 * to read it and, with `s`, say something in it through `talk()`. `d` reads the conversation
77 * as the Markdown file /talk/:id/download serves (`conversationMarkdown`, its owner's alone).
8 * An empty conversation lists the page's starter prompts (#13317), numbered: 1, 2 or 3
9 * sends that one through the same `talk()`.
108 */
119
12 import { STARTER_PROMPTS, TALK_WORDS, talk } from "../../actions/talk.ts";
10 import { TALK_WORDS, talk } from "../../actions/talk.ts";
1311 import {
1412 archiveConversation,
1513 createConversation,
@@ -114,11 +112,7 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr
114112 const lines = (): { text: string; style: ReturnType<typeof style> }[][] => {
115113 const c = ctx.theme.c;
116114 if (pane) return paneLines().flatMap((l) => wrap(l, Math.max(10, width - 2))).map((l) => [{ text: l, style: style(c.fg, c.bg) }]);
117 if (turns.length === 0)
118 return [
119 [{ text: "Nothing said yet; s says something, or a number sends one of these:", style: style(c.mutedFg, c.bg) }],
120 ...STARTER_PROMPTS.map((p, i) => [{ text: ` ${String(i + 1)} ${p}`, style: style(c.fg, c.bg) }]),
121 ];
115 if (turns.length === 0) return [[{ text: "Nothing said yet; s says something.", style: style(c.mutedFg, c.bg) }]];
122116 let n = 0;
123117 return turns.flatMap((t) => {
124118 if (t.id === around) mark = n;
@@ -136,15 +130,7 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr
136130 get title() {
137131 return chat.title === "" ? "Untitled conversation" : chat.title;
138132 },
139 keys: [
140 binding(["j", "k"], "scroll"),
141 binding(["s"], "say"),
142 binding(["1", "2", "3"], "starter"),
143 binding(["r"], "reload"),
144 binding(["p"], "pane"),
145 binding(["d"], "download"),
146 binding(["esc"], "back"),
147 ],
133 keys: [binding(["j", "k"], "scroll"), binding(["s"], "say"), binding(["r"], "reload"), binding(["p"], "pane"), binding(["d"], "download"), binding(["esc"], "back")],
148134 render(area, s) {
149135 const c = ctx.theme.c;
150136 width = area.w;
@@ -183,13 +169,6 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr
183169 ctx.invalidate();
184170 return true;
185171 }
186 const starter = turns.length === 0 && !pane && around === undefined ? STARTER_PROMPTS[Number(e.key) - 1] : undefined;
187 if (starter !== undefined && /^[1-9]$/.test(e.key)) {
188 const said = talk(f.app, user, starter, [], "inject", chat.id);
189 note = said.ok ? `Sent "${starter}"; r reloads to see the answer.` : TALK_WORDS[said.error][1];
190 ctx.invalidate();
191 return true;
192 }
193172 if (e.key === "d") {
194173 ctx.push(downloadScreen(f, ctx, chat));
195174 return true;
src/web/pages/talk.ts +12 −5
@@ -17,7 +17,7 @@
1717 import { blockedFlash } from "../blocked.ts";
1818 import { noTalkAccountBlocked } from "../../actions/blocked_words.ts";
1919 import type { Database } from "bun:sqlite";
20 import { cancelTalk, queuedTalk, STARTER_PROMPTS, TALK_WORDS, talk, talkAgain } from "../../actions/talk.ts";
20 import { cancelTalk, queuedTalk, TALK_WORDS, talk, talkAgain } from "../../actions/talk.ts";
2121 import { REFUSED, sayNo, sayYes, UNDO_REFUSED, undoReceipt, waitingConfirms } from "../../actions/conversation_confirms.ts";
2222 import { filesOfTurns, type ConversationFile } from "../../core/conversation_files.ts";
2323 import {
@@ -171,6 +171,12 @@ const stepCard = (id: string, step: Step, at: string, set = ""): Html =>
171171 const workHtml = (work: Work): Html =>
172172 html`<p class="talk-steps small muted">${work.steps.charAt(0).toUpperCase() + work.steps.slice(1)}</p>${work.links.length === 0 ? null : html`<p class="talk-links small">${work.links.map((l) => html`<a href="${l.href}">${l.label}</a>`)}</p>`}`;
173173
174 /**
175 * What an empty chat offers to start with; each is a link that fills the composer (`?q=`), so it
176 * works without the script.
177 */
178 const SUGGESTIONS = ["What needs my attention?", "What did the crew do today?", "Show me my apps"] as const;
179
174180 /** Ask again as a form, so it works without the script; the script only enhances it. */
175181 const againForm = (base: string, how: "regenerate" | "retry", label: string, words: string): Html =>
176182 html`<form method="post" action="${base}/again/${how}" data-again="${how}">${btn(label, { icon: "sync", label: words })}</form>`;
@@ -334,7 +340,7 @@ function chats(ctx: Ctx, conversation: Conversation, showArchived: boolean, type
334340 </div>`;
335341 }
336342
337 async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | undefined, latest: boolean, edit: boolean): Promise<Response> {
343 async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | undefined, prefill: string, latest: boolean, edit: boolean): Promise<Response> {
338344 const user = ctx.auth.user!;
339345 let before = before0;
340346 const here = latest ? HERE : urlOf(conversation);
@@ -389,7 +395,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
389395 <ol class="talk-log" role="log" data-last="${last}" aria-label="Conversation with the forge">
390396 ${turns.length === 0
391397 ? html`<li class="muted talk-turn">Ask the forge anything, or tell it what to change. It acts as you, with your permissions, and asks before anything hard to undo.
392 <div class="talk-suggest">${STARTER_PROMPTS.map((q) => html`<form method="post" action="${here}" data-starter><input type="hidden" name="text" value="${q}" />${btn(q)}</form>`)}</div></li>`
398 <span class="talk-suggest">${SUGGESTIONS.map((q) => html`<a class="btn" href="${here}?q=${encodeURIComponent(q)}" data-suggest="${q}">${q}</a>`)}</span></li>`
393399 : turns.map((t) => turnHtml(t, waiting, costs.get(t.id), acts.get(t.id), works.get(t.id), sent.get(t.id), expired, undone))}
394400 ${!paged && running ? queuedTalk(ctx.app, user, conversation.id).map(queuedHtml) : null}
395401 </ol>
@@ -401,7 +407,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
401407 <p class="talk-status small muted" role="status">${running ? "The forge is answering…" : ""}</p>
402408 <div class="talk-chips" data-chips role="group" aria-label="Attached files"></div>
403409 ${editing === undefined && aboutText(ctx.app.db, ctx.url.searchParams.get("about"), ctx.auth.user) !== null ? html`<input type="hidden" name="about" value="${ctx.url.searchParams.get("about")}" />` : null}
404 <textarea class="input" name="text" rows="1" maxlength="${WORDS_MAX}" required placeholder="Talk to the forge" aria-label="Talk to the forge" aria-keyshortcuts="/">${editing === undefined ? "" : editing.text}</textarea>
410 <textarea class="input" name="text" rows="1" maxlength="${WORDS_MAX}" required placeholder="Talk to the forge" aria-label="Talk to the forge" aria-keyshortcuts="/">${editing === undefined ? prefill : editing.text}</textarea>
405411 <div class="bar">
406412 <span class="muted small" data-compose-hint></span>
407413 <label class="btn talk-attach" data-attach hidden>Attach<input type="file" multiple hidden data-pick /></label>
@@ -434,10 +440,11 @@ export function talkView(ctx: Ctx): Response | Promise<Response> {
434440 if (ctx.auth.user === undefined) return signInFirst(ctx);
435441 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
436442 const before = ctx.url.searchParams.get("before");
443 const q = ctx.url.searchParams.get("q");
437444 const conversation = conversationOf(ctx, ctx.auth.user);
438445 if (conversation === undefined) return notFoundPage(ctx);
439446 return timePhase(ctx.request, "render", () =>
440 talkPage(ctx, conversation, before !== null && TURN_ID.test(before) && before !== "" ? before : undefined, ctx.params["id"] === undefined, ctx.url.searchParams.get("edit") === "1" && before === null),
447 talkPage(ctx, conversation, before !== null && TURN_ID.test(before) && before !== "" ? before : undefined, q !== null && SUGGESTIONS.some((s) => s === q) ? q : "", ctx.params["id"] === undefined, ctx.url.searchParams.get("edit") === "1" && before === null),
441448 );
442449 }
443450
src/web/pages/talk_client.ts +3 −6
@@ -114,7 +114,7 @@ if (root) {
114114 });
115115 // Links drawn as buttons answer Space as well as Enter.
116116 root.addEventListener("keydown", (e) => {
117 const l = e.key === " " && e.target.closest && e.target.closest("a[data-act]");
117 const l = e.key === " " && e.target.closest && e.target.closest("a.btn[data-suggest], a[data-act]");
118118 if (l) { e.preventDefault(); l.click(); }
119119 });
120120 const nearEnd = () => window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 120;
@@ -139,6 +139,8 @@ if (root) {
139139 return b;
140140 };
141141 root.addEventListener("click", async (e) => {
142 const s = e.target.closest("[data-suggest]");
143 if (s) { e.preventDefault(); box.value = s.dataset.suggest; grow(); box.focus(); return; }
142144 const a = e.target.closest("[data-act]");
143145 if (a) {
144146 e.preventDefault();
@@ -347,11 +349,6 @@ if (root) {
347349 }
348350 };
349351 form.addEventListener("submit", send);
350 // A starter sends through the composer, so its answer streams here.
351 log.addEventListener("submit", (e) => {
352 const f = e.target.closest("form[data-starter]");
353 if (f) { e.preventDefault(); box.value = f.elements.text.value; form.requestSubmit(); }
354 });
355352 box.addEventListener("keydown", (e) => {
356353 if (e.key === "Escape" && editing) { editing = false; box.value = ""; grow(); say(""); return; }
357354 if (e.key === "Enter" && !e.shiftKey && !e.isComposing) { e.preventDefault(); form.requestSubmit(); }
test/talk-page.test.ts +30 −41
@@ -19,7 +19,7 @@ import { clock, STREAMS_MAX } from "../src/web/pages/talk.ts";
1919 import { addSubscription, setGrants } from "../src/core/subscriptions.ts";
2020 import { serveTalk } from "../src/tui/ssh-talk.ts";
2121 import { aboutContext, aboutLine, parseAbout } from "../src/core/talk_about.ts";
22 import { STARTER_PROMPTS, talk as talkTo } from "../src/actions/talk.ts";
22 import { talk as talkTo } from "../src/actions/talk.ts";
2323 import { configureConversation } from "../src/crew/conversation.ts";
2424 import { appendTurn, createConversation, listTurns, openConversation } from "../src/core/conversations.ts";
2525 import { HELD_TTL_MS, hold, waitingFor } from "../src/core/fence.ts";
@@ -148,13 +148,13 @@ describe("the page", () => {
148148 if (!carol.ok) throw new Error(carol.error);
149149 promote(app.db, carol.value);
150150 const empty = await (await get("/talk", carol.value)).text();
151 expect(empty).toContain('name="text" value="What is waiting for me?"');
152 expect(empty).not.toMatch(/<button[^>]*(data-copy|data-jump)/);
151 expect(empty).toContain('href="/talk?q=What%20needs%20my%20attention%3F"');
152 expect(empty).not.toMatch(/<button[^>]*(data-suggest|data-copy|data-jump)/);
153153 say(carol.value, "person", "hi");
154154 say(carol.value, "agent", "hello");
155155 say(carol.value, "tool", "list_issues {\"repo\":\"x\"}");
156156 const page = await (await get("/talk", carol.value)).text();
157 expect(page).not.toContain("data-starter");
157 expect(page).not.toContain("data-suggest=");
158158 expect(page).toContain("You · <time");
159159 expect(page).toContain("Forge · <time");
160160 expect(page).not.toContain("data-copy");
@@ -163,6 +163,15 @@ describe("the page", () => {
163163 expect(page).not.toMatch(/<details open/);
164164 });
165165
166 test("a suggestion link prefills the composer without the script, and only with a known suggestion", async () => {
167 const q = "What needs my attention?";
168 const page = await (await get(`/talk?q=${encodeURIComponent(q)}`, alice)).text();
169 expect(page).toMatch(/<textarea[^>]*>What needs my attention\?<\/textarea>/);
170 const other = await (await get(`/talk?q=${encodeURIComponent("<script>x</script>")}`, alice)).text();
171 expect(other).not.toContain("<script>x</script>");
172 expect(other).not.toMatch(/<textarea[^>]*>[^<]/);
173 });
174
166175 test("markdown in a reply: highlighted code, a table and a link render; every <script> is escaped", async () => {
167176 const eve = await createUser(app.db, { origin: "seed", trusted: true, username: "eve", email: "[email protected]", password: "a-good-passphrase" });
168177 if (!eve.ok) throw new Error(eve.error);
@@ -254,16 +263,16 @@ describe("the page", () => {
254263 expect(talkJs).toContain('e.key === " "');
255264 });
256265
257 test("Confirm, Cancel, Regenerate and Retry are buttons in a post form; the starters are forms of buttons in a div; none is a span", async () => {
266 test("Confirm, Cancel, Regenerate and Retry are buttons in a post form; the suggestions are links; none is a div or span", async () => {
258267 const { Window: W } = await import("happy-dom");
259268 const parse = (html: string) => { const d = new W().document; d.body.innerHTML = html; return d; };
260269 // an empty chat: the suggestions the page itself draws
261270 const empty = await createUser(app.db, { origin: "seed", trusted: true, username: "emptyone", email: "[email protected]", password: "a-good-passphrase" });
262271 if (!empty.ok) throw new Error(empty.error);
263272 const doc0 = parse(await (await get("/talk", empty.value)).text());
264 const chips = [...doc0.querySelectorAll("form[data-starter]")];
273 const chips = [...doc0.querySelectorAll("[data-suggest]")];
265274 expect(chips.length).toBe(3);
266 for (const c of chips) { expect(c.getAttribute("method")).toBe("post"); expect(c.querySelector("button")).not.toBeNull(); expect(c.parentElement?.tagName).toBe("DIV"); }
275 for (const c of chips) { expect(c.tagName).toBe("A"); expect(c.getAttribute("href")).toMatch(/^\/talk\?q=/); }
267276 // a reply, then a waiting confirm
268277 const who = await createUser(app.db, { origin: "seed", trusted: true, username: "confirmer", email: "[email protected]", password: "a-good-passphrase" });
269278 if (!who.ok) throw new Error(who.error);
@@ -483,18 +492,6 @@ describe("the page", () => {
483492 expect(t.bodies.at(-1)!.files).toEqual([]);
484493 });
485494
486 test("tapping a starter sends its prompt through the composer and follows the answer, with no page load", async () => {
487 const t = await boot();
488 t.doc.querySelector(".talk-log").insertAdjacentHTML("beforeend", '<li><div class="talk-suggest"><form method="post" action="/talk" data-starter><input type="hidden" name="text" value="What shipped this week?" /><button class="btn" type="submit">What shipped this week?</button></form></div></li>');
489 const tap = new t.window.Event("submit", { bubbles: true, cancelable: true });
490 t.doc.querySelector("form[data-starter]").dispatchEvent(tap);
491 await tick();
492 expect(tap.defaultPrevented).toBe(true);
493 expect(t.sent).toEqual(["What shipped this week?"]);
494 expect(t.box.value).toBe("");
495 expect(t.sources.length).toBeGreaterThan(0);
496 });
497
498495 test("Enter submits; Shift+Enter and an IME composition do not", async () => {
499496 const t = await boot();
500497 t.box.value = "hello";
@@ -605,6 +602,20 @@ describe("the page", () => {
605602 }
606603 });
607604
605 test("Space on a suggestion or Edit link acts like Enter", async () => {
606 const t = await boot();
607 const root = t.doc.querySelector("[data-talk]");
608 root.insertAdjacentHTML("beforeend", '<a class="btn" href="/talk?q=x" data-suggest="Show me my apps">Show me my apps</a>');
609 const a = root.querySelector("[data-suggest]");
610 const e = new t.window.KeyboardEvent("keydown", { key: " ", bubbles: true, cancelable: true });
611 a.dispatchEvent(e);
612 expect(e.defaultPrevented).toBe(true);
613 expect(t.box.value).toBe("Show me my apps");
614 const typing = new t.window.KeyboardEvent("keydown", { key: " ", bubbles: true, cancelable: true });
615 t.box.dispatchEvent(typing);
616 expect(typing.defaultPrevented).toBe(false);
617 });
618
608619 test("the jump button shows only when scrolled up, and a new message is announced", async () => {
609620 const t = await boot();
610621 const jump = t.doc.querySelector(".talk-jump");
@@ -1067,28 +1078,6 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"Heard.","t
10671078 expect(input()).toContain("and then?");
10681079 });
10691080
1070 test("a starter's post reaches the agent as one person turn, same-origin only", async () => {
1071 const who = await createUser(app.db, { origin: "seed", trusted: true, username: "starter", email: "[email protected]", password: "a-good-passphrase" });
1072 if (!who.ok) throw new Error(who.error);
1073 const plan = addSubscription(app.db, dir, { name: "starter-plan", token: "sk-ant-api-test-token" });
1074 if (!plan.ok) throw new Error(plan.error);
1075 setGrants(app.db, who.value.id, "", [plan.value.id]);
1076 const c = fresh(who.value);
1077 const doc = await (await get("/talk", who.value)).text();
1078 expect(STARTER_PROMPTS.length).toBe(3);
1079 for (const q of STARTER_PROMPTS) expect(doc).toContain(`<input type="hidden" name="text" value="${q}" />`);
1080 rmSync(join(dir, "first.json"), { force: true });
1081 expect((await post("/talk", who.value, { text: STARTER_PROMPTS[1] }, { origin: "https://elsewhere.example" })).status).toBe(403);
1082 expect(existsSync(join(dir, "first.json"))).toBe(false);
1083 expect((await post("/talk", who.value, { text: STARTER_PROMPTS[1] })).status).toBe(303);
1084 for (let i = 0; i < 400 && !existsSync(join(dir, "first.json")); i++) await Bun.sleep(50); // real-timer: the agent runs in a child process behind the HTTP post; no handle to await
1085 expect(existsSync(join(dir, "first.json"))).toBe(true);
1086 expect(input()).toContain(STARTER_PROMPTS[1]!);
1087 const turns = listTurns(app.db, who.value.id, c);
1088 if (!turns.ok) throw new Error("turns");
1089 expect(turns.value.filter((t) => t.role === "person").map((t) => t.text)).toEqual([STARTER_PROMPTS[1]!]);
1090 }, 30_000);
1091
10921081 test("a forged about naming a private repository the sender cannot read adds nothing", async () => {
10931082 const made = await createRepo(app, alice, { name: "ctx-priv", visibility: "private" });
10941083 if (!made.ok) throw new Error(String(made.error));
test/tui-talk-chats.test.ts −20
@@ -11,7 +11,6 @@ import { createApp, type App } from "../src/app.ts";
1111 import { appendTurn, archiveConversation, CONVERSATIONS_MAX, createConversation, listConversations, listTurns, renameConversation } from "../src/core/conversations.ts";
1212 import { createUser, type User } from "../src/core/users.ts";
1313 import { createRepo } from "../src/actions/repos.ts";
14 import { STARTER_PROMPTS } from "../src/actions/talk.ts";
1514 import { createForgeApp } from "../src/tui/forge.ts";
1615 import { headlessTerminal } from "../src/tui/term/terminal.ts";
1716 import { settleApp } from "./helpers/tui.ts";
@@ -101,25 +100,6 @@ describe("the terminal's conversations screen", () => {
101100 expect(turns.ok && turns.value.length).toBe(2);
102101 });
103102
104 test("an empty conversation numbers the starter prompts, and a number sends that one through talk()", async () => {
105 const carol = await createUser(app.db, { origin: "seed", trusted: true, username: "carol", email: "[email protected]", password: "a-good-passphrase" });
106 if (!carol.ok) throw new Error(carol.error);
107 const made = createConversation(app.db, carol.value.id);
108 if (!made.ok) throw new Error(made.error);
109 const text = await drive(carol.value, [...open, "\r"]);
110 STARTER_PROMPTS.forEach((p, i) => expect(text).toContain(`${String(i + 1)} ${p}`));
111 // The crew is off in this app: talk() refuses, the header says why, and nothing is stored.
112 const sent = await drive(carol.value, [...open, "\r", "2"]);
113 expect(sent).toContain("not running here");
114 const turns = listTurns(app.db, carol.value.id, made.value.id, { limit: 50 });
115 expect(turns.ok && turns.value.length).toBe(0);
116 // Once something is said the list is gone, and a number is not a send.
117 appendTurn(app.db, carol.value.id, made.value.id, { role: "person", text: "hello" });
118 const later = await drive(carol.value, [...open, "\r", "1"]);
119 expect(later).not.toContain(STARTER_PROMPTS[0]);
120 expect(later).not.toContain("not running here");
121 });
122
123103 test("d reads the conversation as the Markdown download, from the list and from the chat; another person's is not reachable", async () => {
124104 const made = createConversation(app.db, bob.id);
125105 if (!made.ok) throw new Error(made.error);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs