Public: anyone can read this; the crew can change it.
An empty talk conversation offers three starter prompts that each send in one tap #13339
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13317-an-empty-talk-conversation-offers-three → main 11 commits fork 6 threads · 6 unresolved
docs/features/README.md +1
| @@ -99,6 +99,7 @@ Read with the guide page [Tell the crew](../guide-tell-the-crew.md). | ||
| 99 | 99 | - [](tell-from-here.md) |
| 100 | 100 | - [](talk-resume-writes.md) |
| 101 | 101 | - [](act-now.md) |
| 102 | - [](talk-starters.md) | |
| 102 | 103 | - [](thread-fold.md) |
| 103 | 104 | - [](crew-roles.md) |
| 104 | 105 | - [](ask-settles.md) |
docs/features/talk-starters.md added +11
| @@ -0,0 +1,11 @@ | ||
| 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,6 +18,9 @@ import { err, ok, type Result } from "../kernel/result.ts"; | ||
| 18 | 18 | /** Messages a person may send in a minute. */ |
| 19 | 19 | export const TALK_PER_MINUTE = 12; |
| 20 | 20 | |
| 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 | ||
| 21 | 24 | export type TalkRefusal = SayRefusal | RedoRefusal | "off" | "rate_limited"; |
| 22 | 25 | |
| 23 | 26 | /** What each refusal says, with its status. */ |
src/tui/screens/talk_chats.ts +24 −3
| @@ -5,9 +5,11 @@ | ||
| 5 | 5 | * `a` flips between the live list and the archived one; Enter opens one, |
| 6 | 6 | * to read it and, with `s`, say something in it through `talk()`. `d` reads the conversation |
| 7 | 7 | * 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()`. | |
| 8 | 10 | */ |
| 9 | 11 | |
| 10 | import { TALK_WORDS, talk } from "../../actions/talk.ts"; | |
| 12 | import { STARTER_PROMPTS, TALK_WORDS, talk } from "../../actions/talk.ts"; | |
| 11 | 13 | import { |
| 12 | 14 | archiveConversation, |
| 13 | 15 | createConversation, |
| @@ -112,7 +114,11 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 112 | 114 | const lines = (): { text: string; style: ReturnType<typeof style> }[][] => { |
| 113 | 115 | const c = ctx.theme.c; |
| 114 | 116 | if (pane) return paneLines().flatMap((l) => wrap(l, Math.max(10, width - 2))).map((l) => [{ text: l, style: style(c.fg, c.bg) }]); |
| 115 | if (turns.length === 0) return [[{ text: "Nothing said yet; s says something.", style: style(c.mutedFg, 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 | ]; | |
| 116 | 122 | let n = 0; |
| 117 | 123 | return turns.flatMap((t) => { |
| 118 | 124 | if (t.id === around) mark = n; |
| @@ -130,7 +136,15 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 130 | 136 | get title() { |
| 131 | 137 | return chat.title === "" ? "Untitled conversation" : chat.title; |
| 132 | 138 | }, |
| 133 | keys: [binding(["j", "k"], "scroll"), binding(["s"], "say"), binding(["r"], "reload"), binding(["p"], "pane"), binding(["d"], "download"), binding(["esc"], "back")], | |
| 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 | ], | |
| 134 | 148 | render(area, s) { |
| 135 | 149 | const c = ctx.theme.c; |
| 136 | 150 | width = area.w; |
| @@ -169,6 +183,13 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 169 | 183 | ctx.invalidate(); |
| 170 | 184 | return true; |
| 171 | 185 | } |
| 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)) { | |
Non-blocking: the success branch (Sent ...) has no test, only the refusal. Stub the agent as talk-page.test does and assert one person turn is stored. |
||
| 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 | } | |
| 172 | 193 | if (e.key === "d") { |
| 173 | 194 | ctx.push(downloadScreen(f, ctx, chat)); |
| 174 | 195 | return true; |
src/web/pages/talk.ts +5 −12
| @@ -17,7 +17,7 @@ | ||
| 17 | 17 | import { blockedFlash } from "../blocked.ts"; |
| 18 | 18 | import { noTalkAccountBlocked } from "../../actions/blocked_words.ts"; |
| 19 | 19 | import type { Database } from "bun:sqlite"; |
| 20 | import { cancelTalk, queuedTalk, TALK_WORDS, talk, talkAgain } from "../../actions/talk.ts"; | |
| 20 | import { cancelTalk, queuedTalk, STARTER_PROMPTS, TALK_WORDS, talk, talkAgain } from "../../actions/talk.ts"; | |
| 21 | 21 | import { REFUSED, sayNo, sayYes, UNDO_REFUSED, undoReceipt, waitingConfirms } from "../../actions/conversation_confirms.ts"; |
| 22 | 22 | import { filesOfTurns, type ConversationFile } from "../../core/conversation_files.ts"; |
| 23 | 23 | import { |
| @@ -171,12 +171,6 @@ const stepCard = (id: string, step: Step, at: string, set = ""): Html => | ||
| 171 | 171 | const workHtml = (work: Work): Html => |
| 172 | 172 | 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>`}`; |
| 173 | 173 | |
| 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 | ||
| 180 | 174 | /** Ask again as a form, so it works without the script; the script only enhances it. */ |
| 181 | 175 | const againForm = (base: string, how: "regenerate" | "retry", label: string, words: string): Html => |
| 182 | 176 | html`<form method="post" action="${base}/again/${how}" data-again="${how}">${btn(label, { icon: "sync", label: words })}</form>`; |
| @@ -333,7 +327,7 @@ function chats(ctx: Ctx, conversation: Conversation, showArchived: boolean, type | ||
| 333 | 327 | </div>`; |
| 334 | 328 | } |
| 335 | 329 | |
| 336 | async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | undefined, prefill: string, latest: boolean, edit: boolean): Promise<Response> { | |
| 330 | async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | undefined, latest: boolean, edit: boolean): Promise<Response> { | |
| 337 | 331 | const user = ctx.auth.user!; |
| 338 | 332 | let before = before0; |
| 339 | 333 | const here = latest ? HERE : urlOf(conversation); |
| @@ -387,7 +381,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 387 | 381 | <ol class="talk-log" role="log" data-last="${last}" aria-label="Conversation with the forge"> |
| 388 | 382 | ${turns.length === 0 |
outdated
Principle 1/accessibility: this form is not intercepted by talk_client.ts, so a tap does a full-page POST and the answer needs a reload. Add a data-starter submit handler that sends through the composer. Also a form inside a span is invalid HTML; use a div. |
||
| 389 | 383 | ? 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. |
| 390 | <span class="talk-suggest">${SUGGESTIONS.map((q) => html`<a class="btn" href="${here}?q=${encodeURIComponent(q)}" data-suggest="${q}">${q}</a>`)}</span></li>` | |
| 384 | <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>` | |
| 391 | 385 | : turns.map((t) => turnHtml(t, waiting, costs.get(t.id), acts.get(t.id), works.get(t.id), sent.get(t.id), expired, undone))} |
| 392 | 386 | ${!paged && running ? queuedTalk(ctx.app, user, conversation.id).map(queuedHtml) : null} |
| 393 | 387 | </ol> |
| @@ -399,7 +393,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string | | ||
| 399 | 393 | <p class="talk-status small muted" role="status">${running ? "The forge is answering…" : ""}</p> |
| 400 | 394 | <div class="talk-chips" data-chips role="group" aria-label="Attached files"></div> |
| 401 | 395 | ${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} |
| 402 | <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> | |
| 396 | <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> | |
| 403 | 397 | <div class="bar"> |
| 404 | 398 | <span class="muted small" data-compose-hint></span> |
| 405 | 399 | <label class="btn talk-attach" data-attach hidden>Attach<input type="file" multiple hidden data-pick /></label> |
| @@ -432,11 +426,10 @@ export function talkView(ctx: Ctx): Response | Promise<Response> { | ||
| 432 | 426 | if (ctx.auth.user === undefined) return signInFirst(ctx); |
| 433 | 427 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 434 | 428 | const before = ctx.url.searchParams.get("before"); |
| 435 | const q = ctx.url.searchParams.get("q"); | |
| 436 | 429 | const conversation = conversationOf(ctx, ctx.auth.user); |
| 437 | 430 | if (conversation === undefined) return notFoundPage(ctx); |
| 438 | 431 | return timePhase(ctx.request, "render", () => |
outdated
Dead path: nothing links to ?q= any more. Remove the prefill and its test. |
||
| 439 | 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), | |
| 432 | talkPage(ctx, conversation, before !== null && TURN_ID.test(before) && before !== "" ? before : undefined, ctx.params["id"] === undefined, ctx.url.searchParams.get("edit") === "1" && before === null), | |
| 440 | 433 | ); |
| 441 | 434 | } |
| 442 | 435 |
src/web/pages/talk_client.ts +6 −3
| @@ -114,7 +114,7 @@ if (root) { | ||
| 114 | 114 | }); |
| 115 | 115 | // Links drawn as buttons answer Space as well as Enter. |
| 116 | 116 | root.addEventListener("keydown", (e) => { |
| 117 | const l = e.key === " " && e.target.closest && e.target.closest("a.btn[data-suggest], a[data-act]"); | |
| 117 | const l = e.key === " " && e.target.closest && e.target.closest("a[data-act]"); | |
| 118 | 118 | if (l) { e.preventDefault(); l.click(); } |
| 119 | 119 | }); |
| 120 | 120 | const nearEnd = () => window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 120; |
| @@ -139,8 +139,6 @@ if (root) { | ||
| 139 | 139 | return b; |
| 140 | 140 | }; |
| 141 | 141 | 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; } | |
| 144 | 142 | const a = e.target.closest("[data-act]"); |
| 145 | 143 | if (a) { |
| 146 | 144 | e.preventDefault(); |
| @@ -348,6 +346,11 @@ if (root) { | ||
| 348 | 346 | } |
| 349 | 347 | }; |
| 350 | 348 | form.addEventListener("submit", send); |
| 349 | // A starter sends through the composer, so its answer streams here. | |
| 350 | log.addEventListener("submit", (e) => { | |
| 351 | const f = e.target.closest("form[data-starter]"); | |
| 352 | if (f) { e.preventDefault(); box.value = f.elements.text.value; form.requestSubmit(); } | |
| 353 | }); | |
| 351 | 354 | box.addEventListener("keydown", (e) => { |
| 352 | 355 | if (e.key === "Escape" && editing) { editing = false; box.value = ""; grow(); say(""); return; } |
| 353 | 356 | if (e.key === "Enter" && !e.shiftKey && !e.isComposing) { e.preventDefault(); form.requestSubmit(); } |
test/talk-page.test.ts +41 −30
| @@ -19,7 +19,7 @@ import { clock, STREAMS_MAX } from "../src/web/pages/talk.ts"; | ||
| 19 | 19 | import { addSubscription, setGrants } from "../src/core/subscriptions.ts"; |
| 20 | 20 | import { serveTalk } from "../src/tui/ssh-talk.ts"; |
| 21 | 21 | import { aboutContext, aboutLine, parseAbout } from "../src/core/talk_about.ts"; |
| 22 | import { talk as talkTo } from "../src/actions/talk.ts"; | |
| 22 | import { STARTER_PROMPTS, talk as talkTo } from "../src/actions/talk.ts"; | |
| 23 | 23 | import { configureConversation } from "../src/crew/conversation.ts"; |
| 24 | 24 | import { appendTurn, createConversation, listTurns, openConversation } from "../src/core/conversations.ts"; |
| 25 | 25 | import { HELD_TTL_MS, hold, waitingFor } from "../src/core/fence.ts"; |
| @@ -148,13 +148,13 @@ describe("the page", () => { | ||
| 148 | 148 | if (!carol.ok) throw new Error(carol.error); |
| 149 | 149 | promote(app.db, carol.value); |
| 150 | 150 | const empty = await (await get("/talk", carol.value)).text(); |
| 151 | expect(empty).toContain('href="/talk?q=What%20needs%20my%20attention%3F"'); | |
| 152 | expect(empty).not.toMatch(/<button[^>]*(data-suggest|data-copy|data-jump)/); | |
| 151 | expect(empty).toContain('name="text" value="What is waiting for me?"'); | |
| 152 | expect(empty).not.toMatch(/<button[^>]*(data-copy|data-jump)/); | |
| 153 | 153 | say(carol.value, "person", "hi"); |
| 154 | 154 | say(carol.value, "agent", "hello"); |
| 155 | 155 | say(carol.value, "tool", "list_issues {\"repo\":\"x\"}"); |
| 156 | 156 | const page = await (await get("/talk", carol.value)).text(); |
| 157 | expect(page).not.toContain("data-suggest="); | |
| 157 | expect(page).not.toContain("data-starter"); | |
| 158 | 158 | expect(page).toContain("You · <time"); |
| 159 | 159 | expect(page).toContain("Forge · <time"); |
| 160 | 160 | expect(page).not.toContain("data-copy"); |
| @@ -163,15 +163,6 @@ describe("the page", () => { | ||
| 163 | 163 | expect(page).not.toMatch(/<details open/); |
| 164 | 164 | }); |
| 165 | 165 | |
| 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 | ||
| 175 | 166 | test("markdown in a reply: highlighted code, a table and a link render; every <script> is escaped", async () => { |
| 176 | 167 | const eve = await createUser(app.db, { origin: "seed", trusted: true, username: "eve", email: "[email protected]", password: "a-good-passphrase" }); |
| 177 | 168 | if (!eve.ok) throw new Error(eve.error); |
| @@ -263,16 +254,16 @@ describe("the page", () => { | ||
| 263 | 254 | expect(talkJs).toContain('e.key === " "'); |
| 264 | 255 | }); |
| 265 | 256 | |
| 266 | test("Confirm, Cancel, Regenerate and Retry are buttons in a post form; the suggestions are links; none is a div or span", async () => { | |
| 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 () => { | |
| 267 | 258 | const { Window: W } = await import("happy-dom"); |
| 268 | 259 | const parse = (html: string) => { const d = new W().document; d.body.innerHTML = html; return d; }; |
| 269 | 260 | // an empty chat: the suggestions the page itself draws |
| 270 | 261 | const empty = await createUser(app.db, { origin: "seed", trusted: true, username: "emptyone", email: "[email protected]", password: "a-good-passphrase" }); |
| 271 | 262 | if (!empty.ok) throw new Error(empty.error); |
| 272 | 263 | const doc0 = parse(await (await get("/talk", empty.value)).text()); |
| 273 | const chips = [...doc0.querySelectorAll("[data-suggest]")]; | |
| 264 | const chips = [...doc0.querySelectorAll("form[data-starter]")]; | |
| 274 | 265 | expect(chips.length).toBe(3); |
| 275 | for (const c of chips) { expect(c.tagName).toBe("A"); expect(c.getAttribute("href")).toMatch(/^\/talk\?q=/); } | |
| 266 | for (const c of chips) { expect(c.getAttribute("method")).toBe("post"); expect(c.querySelector("button")).not.toBeNull(); expect(c.parentElement?.tagName).toBe("DIV"); } | |
| 276 | 267 | // a reply, then a waiting confirm |
| 277 | 268 | const who = await createUser(app.db, { origin: "seed", trusted: true, username: "confirmer", email: "[email protected]", password: "a-good-passphrase" }); |
| 278 | 269 | if (!who.ok) throw new Error(who.error); |
| @@ -492,6 +483,18 @@ describe("the page", () => { | ||
| 492 | 483 | expect(t.bodies.at(-1)!.files).toEqual([]); |
| 493 | 484 | }); |
| 494 | 485 | |
| 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 | ||
| 495 | 498 | test("Enter submits; Shift+Enter and an IME composition do not", async () => { |
| 496 | 499 | const t = await boot(); |
| 497 | 500 | t.box.value = "hello"; |
| @@ -602,20 +605,6 @@ describe("the page", () => { | ||
| 602 | 605 | } |
| 603 | 606 | }); |
| 604 | 607 | |
| 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 | ||
| 619 | 608 | test("the jump button shows only when scrolled up, and a new message is announced", async () => { |
| 620 | 609 | const t = await boot(); |
| 621 | 610 | const jump = t.doc.querySelector(".talk-jump"); |
| @@ -1077,6 +1066,28 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"Heard.","t | ||
| 1077 | 1066 | expect(input()).toContain("and then?"); |
| 1078 | 1067 | }); |
| 1079 | 1068 | |
| 1069 | test("a starter's post reaches the agent as one person turn, same-origin only", async () => { | |
| 1070 | const who = await createUser(app.db, { origin: "seed", trusted: true, username: "starter", email: "[email protected]", password: "a-good-passphrase" }); | |
| 1071 | if (!who.ok) throw new Error(who.error); | |
| 1072 | const plan = addSubscription(app.db, dir, { name: "starter-plan", token: "sk-ant-api-test-token" }); | |
| 1073 | if (!plan.ok) throw new Error(plan.error); | |
| 1074 | setGrants(app.db, who.value.id, "", [plan.value.id]); | |
| 1075 | const c = fresh(who.value); | |
| 1076 | const doc = await (await get("/talk", who.value)).text(); | |
| 1077 | expect(STARTER_PROMPTS.length).toBe(3); | |
| 1078 | for (const q of STARTER_PROMPTS) expect(doc).toContain(`<input type="hidden" name="text" value="${q}" />`); | |
| 1079 | rmSync(join(dir, "first.json"), { force: true }); | |
| 1080 | expect((await post("/talk", who.value, { text: STARTER_PROMPTS[1] }, { origin: "https://elsewhere.example" })).status).toBe(403); | |
| 1081 | expect(existsSync(join(dir, "first.json"))).toBe(false); | |
| 1082 | expect((await post("/talk", who.value, { text: STARTER_PROMPTS[1] })).status).toBe(303); | |
| 1083 | 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 | |
| 1084 | expect(existsSync(join(dir, "first.json"))).toBe(true); | |
| 1085 | expect(input()).toContain(STARTER_PROMPTS[1]!); | |
| 1086 | const turns = listTurns(app.db, who.value.id, c); | |
| 1087 | if (!turns.ok) throw new Error("turns"); | |
| 1088 | expect(turns.value.filter((t) => t.role === "person").map((t) => t.text)).toEqual([STARTER_PROMPTS[1]!]); | |
| 1089 | }, 30_000); | |
| 1090 | ||
| 1080 | 1091 | test("a forged about naming a private repository the sender cannot read adds nothing", async () => { |
| 1081 | 1092 | const made = await createRepo(app, alice, { name: "ctx-priv", visibility: "private" }); |
| 1082 | 1093 | if (!made.ok) throw new Error(String(made.error)); |
test/tui-talk-chats.test.ts +20
| @@ -11,6 +11,7 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 11 | 11 | import { appendTurn, archiveConversation, CONVERSATIONS_MAX, createConversation, listConversations, listTurns, renameConversation } from "../src/core/conversations.ts"; |
| 12 | 12 | import { createUser, type User } from "../src/core/users.ts"; |
| 13 | 13 | import { createRepo } from "../src/actions/repos.ts"; |
| 14 | import { STARTER_PROMPTS } from "../src/actions/talk.ts"; | |
| 14 | 15 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 15 | 16 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| 16 | 17 | import { settleApp } from "./helpers/tui.ts"; |
| @@ -100,6 +101,25 @@ describe("the terminal's conversations screen", () => { | ||
| 100 | 101 | expect(turns.ok && turns.value.length).toBe(2); |
| 101 | 102 | }); |
| 102 | 103 | |
| 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 | ||
| 103 | 123 | test("d reads the conversation as the Markdown download, from the list and from the chat; another person's is not reachable", async () => { |
| 104 | 124 | const made = createConversation(app.db, bob.id); |
| 105 | 125 | if (!made.ok) throw new Error(made.error); |
Both doors: the terminal gets no starters. Add a src/tui/ screen offering the same STARTER_PROMPTS on an empty conversation (with a test), and describe it here, instead of declaring the gap deliberate.