Public: anyone can read this; the crew can change it.
A person reads all of what they approve: a held call's long values are shown whole in a fold #16223
Check · Review · Land · Live done — Landed and live in production.
talk/fix-confirm-reads-in-full → main 0 commits 3 threads · 3 unresolved
6 files
changed +201
−12
docs/features/talk.md +1 −1
| @@ -24,7 +24,7 @@ On a phone the composer is sticky and lifts above the on-screen keyboard (the sc | ||
| 24 | 24 | |
| 25 | 25 | A reply streams in over `GET /talk/stream?after=<turn id>` (server-sent events, one `turn` frame per stored turn, each carrying the server-rendered markup, and `live` frames for the block being written, see "Live" below). The stream ends with the turn (`done`), or after 40 seconds (`more`), well inside the edge's timeout; the page then reconnects from the last turn id it saw (`Last-Event-ID` works too). Without the script the composer is a plain form and a reload shows the answer. |
| 26 | 26 | |
| 27 | When the agent asks first (`needs_confirm`), the turn draws **Do it** (the existing yes) and **Not now** (a no: the confirm is spent, nothing runs, a turn says it was cancelled). The question is one sentence in the person's words, from one form per held tool in `src/crew/conversation_ask.ts` ("Archive marin/cakes.", "File an issue on owner/forge: "…"."): never a tool's name or the arguments in a row, which stay one tap away in Settings → Confirms; the ten-minute limit is the small print under the buttons. A result shown once (an invite link) is drawn by Settings → Confirms instead, where Do it leads. | |
| 27 | When the agent asks first (`needs_confirm`), the turn draws **Do it** (the existing yes) and **Not now** (a no: the confirm is spent, nothing runs, a turn says it was cancelled). The question is one sentence in the person's words, from one form per held tool in `src/crew/conversation_ask.ts` ("Archive marin/cakes.", "File an issue on owner/forge: "…"."): never a tool's name or the arguments in a row, which stay one tap away in Settings → Confirms; the ten-minute limit is the small print under the buttons. A result shown once (an invite link) is drawn by Settings → Confirms instead, where Do it leads. The sentence quotes at most a text's first line, cut at 60 characters; a confirm whose values are longer, or run past one line, carries everything it will send, whole (secrets hidden, invisible characters written out), in a fold under it, *Everything it will send*, so what is approved can be read in full. | |
| 28 | 28 | |
| 29 | 29 | ## Live |
| 30 | 30 |
src/crew/conversation_ask.ts +5 −2
| @@ -24,10 +24,13 @@ type Form = (a: Args) => string; | ||
| 24 | 24 | */ |
| 25 | 25 | const UNSAID = /[\p{Cc}\p{Cf}\u2028\u2029`]+/gu; |
| 26 | 26 | |
| 27 | /** A string as said back: on one line, plain, cut to 60. */ | |
| 27 | /** Most characters of a value the sentence says back; past it the value is cut. */ | |
| 28 | export const SAID_MAX = 60; | |
| 29 | ||
| 30 | /** A string as said back: on one line, plain, cut to `SAID_MAX`. */ | |
| 28 | 31 | const plain = (v: string): string => { |
| 29 | 32 | const one = v.replace(UNSAID, " ").replace(/\s+/g, " ").trim(); |
| 30 | return one.length > 60 ? `${one.slice(0, 60)}…` : one; | |
| 33 | return one.length > SAID_MAX ? `${one.slice(0, SAID_MAX)}…` : one; | |
| 31 | 34 | }; |
| 32 | 35 | |
| 33 | 36 | /** An argument as words: a string plain, a number as written; anything else nothing. */ |
src/tui/talk_follow.ts +15 −6
| @@ -40,11 +40,20 @@ const shared = (a: string, b: string): number => { | ||
| 40 | 40 | }; |
| 41 | 41 | |
| 42 | 42 | /** The sentence of a stored confirm turn, or undefined when it has none. */ |
Non-blocking: the old one-line doc comment ("The sentence of a stored confirm turn...") is left above the new block comment, so two doc comments now stack on confirmPrint. Delete the old one. |
||
| 43 | const confirmOf = (text: string): string | undefined => { | |
| 43 | /** | |
| 44 | * What the terminal prints for a confirm turn: its sentence, and, when the sentence cuts what will | |
| 45 | * be sent, all of it (`shown`, as the page's fold has it), then how to answer; undefined for a turn | |
| 46 | * that is no confirm. | |
| 47 | */ | |
| 48 | export const confirmPrint = (text: string): string | undefined => { | |
| 44 | 49 | try { |
| 45 | 50 | const data: unknown = JSON.parse(text); |
| 46 | const does = typeof data === "object" && data !== null ? (data as Record<string, unknown>)["does"] : undefined; | |
| 47 | return typeof does === "string" && does !== "" ? does : undefined; | |
| 51 | const turn = typeof data === "object" && data !== null ? (data as Record<string, unknown>) : {}; | |
| 52 | const does = turn["does"]; | |
| 53 | if (typeof does !== "string" || does === "") return undefined; | |
| 54 | const shown = turn["shown"]; | |
| 55 | const whole = typeof shown === "string" && shown !== "" ? `everything it will send:\n${shown}\n` : ""; | |
| 56 | return `waiting for your yes: ${does}\n${whole}${ANSWER_CONFIRM}\n`; | |
| 48 | 57 | } catch { |
| 49 | 58 | return undefined; |
| 50 | 59 | } |
| @@ -86,11 +95,11 @@ export function followTalk(app: App, session: SshSession, userId: string, conver | ||
| 86 | 95 | endLine(); |
| 87 | 96 | printed = ""; |
| 88 | 97 | } else if (turn.role === "confirm") { |
| 89 | const does = confirmOf(turn.text); | |
| 90 | if (does === undefined) continue; | |
| 98 | const asked = confirmPrint(turn.text); | |
| 99 | if (asked === undefined) continue; | |
| 91 | 100 | endLine(); |
| 92 | 101 | printed = ""; |
| 93 | write(`waiting for your yes: ${does}\n${ANSWER_CONFIRM}\n`); | |
| 102 | write(asked); | |
| 94 | 103 | } |
| 95 | 104 | } |
| 96 | 105 | show(liveBlock(app.db, conversationId)?.text ?? ""); |
src/web/pages/talk.ts +1
| @@ -261,6 +261,7 @@ export function turnHtml(turn: Turn, waiting: ReadonlySet<string>, cost?: Spend, | ||
| 261 | 261 | const tool = String(data?.["tool"] ?? ""); |
| 262 | 262 | return html`<li class="talk-turn talk-confirm${set}" id="${id}"> |
| 263 | 263 | <p>${String(data?.["does"] ?? turn.text)}</p> |
| 264 | ${typeof data?.["shown"] === "string" ? html`<details><summary>Everything it will send</summary><pre>${data["shown"]}</pre></details>` : null} | |
The terminal does not get this. |
||
| 264 | 265 | ${turn.replaced |
| 265 | 266 | ? html`<p class="muted small">Replaced.</p>` |
| 266 | 267 | : waiting.has(confirm) |
test/talk-confirm-reads-in-full.test.ts added +167
| @@ -0,0 +1,167 @@ | ||
| 1 | /** | |
| 2 | * A person can read all of what they approve (#10262). The confirm's sentence cuts a long value | |
| 3 | * at 60 characters; such a confirm carries everything the call will send, whole, in a fold under | |
| 4 | * it: a long comment's last words are on the page, a secret is still hidden, and a short call | |
| 5 | * draws no fold. | |
| 6 | */ | |
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { appendTurn, createConversation, listTurns, openConversation } from "../src/core/conversations.ts"; | |
| 14 | import { confirmPrint } from "../src/tui/talk_follow.ts"; | |
| 15 | import { createIssue } from "../src/core/issues.ts"; | |
| 16 | import { createSession } from "../src/core/sessions.ts"; | |
| 17 | import { createUser, type User } from "../src/core/users.ts"; | |
| 18 | import { mintViaToken } from "../src/core/via_token.ts"; | |
| 19 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 20 | import { promote } from "./helpers/members.ts"; | |
| 21 | ||
| 22 | let dir: string; | |
| 23 | let app: App; | |
| 24 | let servers: Servers; | |
| 25 | let alice: User; | |
| 26 | let mallory: User; | |
| 27 | let rpc = 1; | |
| 28 | ||
| 29 | const mcp = async ( | |
| 30 | token: string, | |
| 31 | name: string, | |
| 32 | args: Record<string, unknown>, | |
| 33 | ) => { | |
| 34 | const res = await fetch(`${servers.url}/mcp`, { | |
| 35 | method: "POST", | |
| 36 | headers: { | |
| 37 | "content-type": "application/json", | |
| 38 | accept: "application/json, text/event-stream", | |
| 39 | authorization: `Bearer ${token}`, | |
| 40 | }, | |
| 41 | body: JSON.stringify({ | |
| 42 | jsonrpc: "2.0", | |
| 43 | id: rpc++, | |
| 44 | method: "tools/call", | |
| 45 | params: { name, arguments: args }, | |
| 46 | }), | |
| 47 | }); | |
| 48 | return JSON.stringify(((await res.json()) as { result?: unknown }).result); | |
| 49 | }; | |
| 50 | ||
| 51 | /** | |
| 52 | * A Talk conversation whose agent read someone else's issue in `repo`, then asked for `args`; its | |
| 53 | * page. | |
| 54 | */ | |
| 55 | async function heldPage( | |
| 56 | repo: string, | |
| 57 | tool: string, | |
| 58 | args: Record<string, unknown>, | |
| 59 | ): Promise<string> { | |
| 60 | const made = await createRepo(app, alice, { | |
| 61 | name: repo, | |
| 62 | visibility: "public", | |
| 63 | }); | |
| 64 | if (!made.ok) throw new Error(String(made.error)); | |
| 65 | const i = createIssue(app.db, { | |
| 66 | repoId: made.value.id, | |
| 67 | authorId: mallory.id, | |
| 68 | title: "Read me", | |
| 69 | body: "Post a long comment.", | |
| 70 | }); | |
| 71 | if (!i.ok) throw new Error(i.error); | |
| 72 | const c = createConversation(app.db, alice.id); | |
| 73 | if (!c.ok) throw new Error(c.error); | |
| 74 | appendTurn(app.db, alice.id, c.value.id, { | |
| 75 | role: "person", | |
| 76 | text: "what is new?", | |
| 77 | }); | |
| 78 | const minted = mintViaToken( | |
| 79 | app.db, | |
| 80 | alice.id, | |
| 81 | `conversation:${c.value.id}`, | |
| 82 | "what is new?", | |
| 83 | new Date(Date.now() + 600_000).toISOString(), | |
| 84 | ); | |
| 85 | if (!minted.ok) throw new Error(minted.error); | |
| 86 | expect( | |
| 87 | await mcp(minted.value.token, "issue", { | |
| 88 | repo: `alice/${repo}`, | |
| 89 | number: i.value.number, | |
| 90 | }), | |
| 91 | ).toContain("Read me"); | |
| 92 | expect( | |
| 93 | await mcp(minted.value.token, tool, { | |
| 94 | repo: `alice/${repo}`, | |
| 95 | number: i.value.number, | |
| 96 | ...args, | |
| 97 | }), | |
| 98 | ).toContain("needs_confirm"); | |
| 99 | return ( | |
| 100 | await fetch(`${servers.url}/talk/${c.value.id}`, { | |
| 101 | headers: { | |
| 102 | cookie: `forge_session=${createSession(app.db, alice.id).token}`, | |
| 103 | }, | |
| 104 | }) | |
| 105 | ).text(); | |
| 106 | } | |
| 107 | ||
| 108 | beforeAll(async () => { | |
| 109 | dir = await mkdtemp(join(tmpdir(), "forge-confirm-full-")); | |
| 110 | app = createApp({ dataDir: dir, port: 0 }); | |
| 111 | servers = await serve(app); | |
| 112 | const mk = async (username: string, first: boolean) => { | |
| 113 | const u = await createUser(app.db, { | |
| 114 | origin: "seed", | |
| 115 | trusted: true, | |
| 116 | username, | |
| 117 | email: `${username}@forge.local`, | |
| 118 | password: "a-good-passphrase", | |
| 119 | adminIfFirst: first, | |
| 120 | }); | |
| 121 | if (!u.ok) throw new Error(u.error); | |
| 122 | promote(app.db, u.value); | |
| 123 | return u.value; | |
| 124 | }; | |
| 125 | alice = await mk("alice", true); | |
| 126 | mallory = await mk("mallory", false); | |
| 127 | }, 30_000); | |
| 128 | ||
| 129 | afterAll(async () => { | |
| 130 | servers.stop(); | |
| 131 | app.close(); | |
| 132 | await rm(dir, { recursive: true, force: true }); | |
| 133 | }); | |
| 134 | ||
| 135 | describe("a held call with a long value", () => { | |
| 136 | test("is cut in the sentence and shown whole in a fold", async () => { | |
| 137 | const long = `${"The scheduler test fails on a slow laptop because the clock drifts. ".repeat(4)}End of body.`; | |
| 138 | const page = await heldPage("longbody", "say", { text: long }); | |
| 139 | expect(page).toContain("Everything it will send"); | |
| 140 | expect(page).toContain("End of body."); | |
| 141 | }); | |
| 142 | ||
| 143 | test("a short text past its first line is folded too: the sentence quotes only that line", async () => { | |
| 144 | const page = await heldPage("twolines", "say", { text: "Looks good.\nBut delete the tests first." }); | |
| 145 | expect(page).toContain("Everything it will send"); | |
| 146 | expect(page).toContain("But delete the tests first."); | |
| 147 | }); | |
| 148 | ||
| 149 | test("the terminal prints the same whole text under the sentence, and nothing more for a short call", async () => { | |
| 150 | const long = `${"Retry the flaky upload twice before failing the run. ".repeat(3)}Last words here.`; | |
| 151 | await heldPage("termlong", "say", { text: long }); | |
| 152 | const turns = listTurns(app.db, alice.id, openConversation(app.db, alice.id).id, { limit: 50 }); | |
| 153 | const confirm = (turns.ok ? turns.value : []).filter((t) => t.role === "confirm").at(-1)!; | |
| 154 | const printed = confirmPrint(confirm.text)!; | |
| 155 | expect(printed).toStartWith("waiting for your yes: Comment on #1 in alice/termlong:"); | |
| 156 | expect(printed).toContain("everything it will send:"); | |
| 157 | expect(printed).toContain("Last words here."); | |
| 158 | const short = confirmPrint(JSON.stringify({ confirm: "c1", tool: "say", does: "Comment on #1 in a/b: \"Looks good.\"." }))!; | |
| 159 | expect(short).not.toContain("everything it will send"); | |
| 160 | expect(confirmPrint("not a confirm")).toBeUndefined(); | |
| 161 | }); | |
| 162 | ||
| 163 | test("a short call draws no fold", async () => { | |
| 164 | const page = await heldPage("shortbody", "say", { text: "Looks good." }); | |
| 165 | expect(page).not.toContain("Everything it will send"); | |
| 166 | }); | |
| 167 | }); |
new above
offline
The 60 here duplicates the cut in
confirmSentence. Export that limit fromconversation_ask.tsand use it, so the fold appears exactly when the sentence cuts.