Public: anyone can read this; the crew can change it.
Asked what needs me, /talk answers with the held decisions as links and the one action each, not a paragraph #12719
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12691-asked-what-needs-me-talk-answers-with-th → main 6 commits fork 5 threads · 5 unresolved
8 files
changed +309
−14
docs/features/README.md +1
| @@ -114,6 +114,7 @@ Read with the guide page [Tell the crew](../guide-tell-the-crew.md). | ||
| 114 | 114 | - [](first-ask.md) |
| 115 | 115 | - [](share-to-the-forge.md) |
| 116 | 116 | - [](since-you-were-here.md) |
| 117 | - [](talk-decisions.md) | |
| 117 | 118 | - [](talk-builder.md) |
| 118 | 119 | - [](talk-attachments.md) |
| 119 | 120 | - [](talk-captain.md) |
docs/features/talk-decisions.md added +10
| @@ -0,0 +1,10 @@ | ||
| 1 | # /talk answers "what needs me?" (#12691) | |
| 2 | ||
| 3 | Ask /talk what waits on you and the answer is the inbox's held decisions as a short list: no model turn, no cost, nothing written but the two turns. | |
| 4 | ||
| 5 | - **Phrasings:** short questions about your own queue: "what needs me?", "what's waiting on me", "anything waiting for me?", "what should I decide", and the bare "inbox" or "decisions". Over 80 characters, or anything else, is a task for the agent as before. A message with attachments, or sent while an answer is running, goes to the agent too. | |
| 6 | - **The answer:** up to 5 rows, in the inbox's own order (`askRows`: highest consequence first), each a link to where the one action is taken, why it waits, and the action word in bold. The word is read from `primaryLabel` in `web/studio/decisions.ts`, the same source as the inbox's button, so the two cannot disagree. A proposal links to `/asks` (Approve). More than 5 ends with `N more in your inbox`. | |
| 7 | - **Nothing held:** one line, "Nothing is waiting on you." | |
| 8 | - **Read as you:** the rows are the signed-in person's own; nobody sees another's queue. Nothing is acted on here; the link opens the page whose form has its own confirm. | |
| 9 | - **Both doors:** the terminal's `talk` goes through the same `say()` and prints the answer itself, one line per row, every control character in a title turned to a space (`terminalAnswer` in `src/tui/ssh-talk.ts`). | |
| 10 | - **Left out:** buttons in the chat itself, and acting from the answer. |
src/actions/talk_decisions.ts added +67
| @@ -0,0 +1,67 @@ | ||
| 1 | /** | |
| 2 | * "What needs me?" in /talk (#12691): the held decisions as a short list, not a | |
| 3 | * paragraph. The rows are the inbox's own (`decisionsFor`, the same scoring, | |
| 4 | * order and filters as /asks), read as the signed-in person. Nothing is acted | |
| 5 | * on here: each row links to where the one action is taken, which is the | |
| 6 | * existing form with its own confirm. | |
| 7 | */ | |
| 8 | ||
| 9 | import type { App } from "../app.ts"; | |
| 10 | import { listReposVisibleTo } from "../core/repos.ts"; | |
| 11 | import type { User } from "../core/users.ts"; | |
| 12 | import { repoBase } from "../web/chrome.ts"; | |
| 13 | import { askRows, type Decision } from "../web/studio/asks.ts"; | |
| 14 | import { decisionsFor, primaryLabel } from "../web/studio/decisions.ts"; | |
| 15 | import { changeHref } from "../web/studio/nouns.ts"; | |
| 16 | ||
| 17 | /** The most rows an answer lists. */ | |
| 18 | export const DECISIONS_MAX = 5; | |
| 19 | ||
| 20 | /** The only words ever asked of the sentence: short, and about the person's own queue. */ | |
| 21 | const ASKS = [ | |
| 22 | /\bwhat(?:'s| is| else)?\s+(?:needs?|wants?)\s+(?:me|my\s+(?:attention|decision|nod|call))\b/, | |
| 23 | /\bwhat(?:'s| is)?\s+(?:waiting|held|pending)\s+(?:on|for)\s+me\b/, | |
| 24 | /\b(?:anything|something)\s+(?:waiting\s+)?(?:on|for)\s+me\b/, | |
| 25 | /\bwhat\s+(?:do|should)\s+i\s+(?:need\s+to\s+)?(?:decide|look\s+at|review)\b/, | |
| 26 | /^(?:show\s+|open\s+)?(?:me\s+)?(?:my\s+)?(?:inbox|decisions|held decisions)$/, | |
| 27 | ]; | |
| 28 | ||
| 29 | /** Whether the words ask for what waits on the person; a long message is a task, never this. */ | |
| 30 | export function asksWhatNeedsMe(text: string): boolean { | |
| 31 | const said = text.trim().toLowerCase().replace(/[?!.]+$/g, "").replace(/\s+/g, " "); | |
| 32 | return said.length > 0 && said.length <= 80 && ASKS.some((re) => re.test(said)); | |
| 33 | } | |
| 34 | ||
| 35 | /** | |
| 36 | * Where a row's one action is taken: its change, its issue, the inbox for a proposal, | |
| 37 | * or the repository's settings. | |
| 38 | */ | |
| 39 | export function actionHref(d: Decision): string { | |
| 40 | const base = repoBase(d.repo); | |
| 41 | if (d.kind === "proposal") return "/asks"; | |
| 42 | return d.pull !== undefined ? changeHref(base, d.pull.number) : d.issue !== undefined ? `${base}/issues/${d.issue.number}` : `${base}/settings/autonomy`; | |
| 43 | } | |
| 44 | ||
| 45 | /** | |
| 46 | * Link text that cannot end its own link or start a tag. The talk renderer has | |
| 47 | * no backslash escapes (they would show), and keeps `_` inside link text as it | |
| 48 | * is, so snake_case stays; brackets become parentheses and `*`, which would turn | |
| 49 | * into emphasis, its look-alike. | |
| 50 | */ | |
| 51 | const plain = (s: string): string => | |
| 52 | s.replace(/[\[\]]/g, (c) => (c === "[" ? "(" : ")")).replace(/\*/g, "\u2217").replace(/[<>`\\\n\r]/g, " ").replace(/\s+/g, " ").trim().slice(0, 100); | |
| 53 | ||
| 54 | /** The answer, as markdown the talk page already renders. */ | |
| 55 | export function decisionsAnswer(app: App, user: User): string { | |
| 56 | const repos = listReposVisibleTo(app.db, user, { limit: 200, withoutArchived: true }); | |
| 57 | // The inbox's own order (`askRows`: highest consequence first), each held decision once. | |
| 58 | const rows = askRows(decisionsFor({ app, auth: { user } }, repos, { noPictures: true })).flatMap((row) => row.items); | |
| 59 | if (rows.length === 0) return "Nothing is waiting on you."; | |
| 60 | const shown = rows.slice(0, DECISIONS_MAX); | |
| 61 | const lines = shown.map((d, i) => { | |
outdated
Stripping _ and * mangles real titles (snake_case); backslash-escape instead. |
||
| 62 | const thing = d.pull?.title ?? d.issue?.title ?? d.proposal?.title ?? d.repo.name; | |
| 63 | return `${i + 1}. [${plain(thing)}](${actionHref(d)}) — ${plain(d.short)}. **${primaryLabel(d)}**`; | |
outdated
Mis-indented by four spaces; align it with the line above. |
||
| 64 | }); | |
| 65 | const more = rows.length > shown.length ? `\n\n[${rows.length - shown.length} more in your inbox](/asks)` : ""; | |
| 66 | return `${rows.length === 1 ? "One thing waits" : `${rows.length} things wait`} on you:\n\n${lines.join("\n")}${more}`; | |
| 67 | } | |
outdated
|
src/crew/conversation.ts +12 −1
| @@ -20,6 +20,7 @@ import { join } from "node:path"; | ||
| 20 | 20 | import type { App } from "../app.ts"; |
| 21 | 21 | import { dailyLeft } from "../core/account_ceiling.ts"; |
| 22 | 22 | import { aboutContext } from "../core/talk_about.ts"; |
| 23 | import { asksWhatNeedsMe, decisionsAnswer } from "../actions/talk_decisions.ts"; | |
| 23 | 24 | import { buildTurnEnded } from "../actions/build_pull.ts"; |
| 24 | 25 | import { buildLead, chatBuildOf } from "../core/chat_build.ts"; |
| 25 | 26 | import { getRepoById } from "../core/repos.ts"; |
| @@ -209,11 +210,13 @@ export type SayRefusal = "not_found" | "unauthorized" | "empty" | "too_long" | " | ||
| 209 | 210 | |
| 210 | 211 | export interface Said { |
| 211 | 212 | /** `started` a new turn, `steered` words into the one running, `queued` for after it, or `interrupted` it to send these at once. */ |
| 212 | readonly how: "started" | "steered" | "queued" | "interrupted"; | |
| 213 | readonly how: "started" | "steered" | "queued" | "interrupted" | "answered"; | |
| 213 | 214 | /** Settles when the turn does; only a started turn has one. */ |
| 214 | 215 | readonly done?: Promise<void>; |
| 215 | 216 | /** The queue id of a `queued` message, to cancel it by. */ |
| 216 | 217 | readonly queued?: string; |
| 218 | /** The text of an `answered` message, so a door with no page (the terminal) prints it at once. */ | |
| 219 | readonly answer?: string; | |
| 217 | 220 | } |
| 218 | 221 | |
| 219 | 222 | /** |
| @@ -318,6 +321,14 @@ export function say( | ||
| 318 | 321 | cancelHeld(app.db, `conversation:${conversation.id}`); |
| 319 | 322 | return ok({ how: "interrupted" }); |
| 320 | 323 | } |
outdated
If appendTurn fails this falls through to a model turn silently; return the error.
outdated
The |
||
| 324 | // "What needs me?" is answered from the inbox's own rows: no model turn, no write (#12691). | |
| 325 | if (!live.has(conversation.id) && files.length === 0 && asksWhatNeedsMe(text)) { | |
| 326 | const asked = appendTurn(app.db, userId, conversation.id, { role: "person", text }); | |
| 327 | if (!asked.ok) return err("too_long"); | |
| 328 | const answer = decisionsAnswer(app, user); | |
| 329 | appendTurn(app.db, userId, conversation.id, { role: "agent", text: answer }); | |
| 330 | return ok({ how: "answered", answer }); | |
| 331 | } | |
| 321 | 332 | // The subject rides with a new conversation's first message only (#10496), as fenced data the agent reads before the words. |
| 322 | 333 | const first = listTurns(app.db, userId, conversation.id, { limit: 1 }); |
| 323 | 334 | const subject = about === undefined || about === null || !first.ok || first.value.length > 0 ? "" : aboutContext(app.db, about, user); |
src/tui/ssh-talk.ts +13
| @@ -91,6 +91,15 @@ function readStdin(session: SshSession, max: number): Promise<Uint8Array | "too_ | ||
| 91 | 91 | }); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | /** | |
| 95 | * The inbox answer for a terminal: its lines as they are, every other control character a | |
| 96 | * space, so a title cannot move the cursor or recolour the screen. | |
| 97 | */ | |
| 98 | export function terminalAnswer(answer: string): string { | |
| 99 | const lines = answer.split("\n").map((l) => l.replace(/[\x00-\x1f\x7f-\x9f\u2028\u2029]/g, " ")); | |
| 100 | return lines.map((l) => `${l}${CRLF}`).join(""); | |
| 101 | } | |
| 102 | ||
| 94 | 103 | /** Run one `talk` exec for `user` (undefined: an unknown key). */ |
| 95 | 104 | export function serveTalk(app: App, session: SshSession, user: User | undefined, words: string): void { |
| 96 | 105 | const refuse = (text: string): void => { |
| @@ -131,6 +140,10 @@ export function serveTalk(app: App, session: SshSession, user: User | undefined, | ||
| 131 | 140 | } |
| 132 | 141 | const finish = (said: ReturnType<typeof talk>): void => { |
| 133 | 142 | if (!said.ok) return refuse(TALK_WORDS[said.error][1]); |
| 143 | if (said.value.how === "answered") { | |
| 144 | session.write(terminalAnswer(said.value.answer ?? "")); | |
| 145 | return session.exit(0); | |
| 146 | } | |
| 134 | 147 | session.write( |
| 135 | 148 | `${said.value.how === "steered" ? "said to the forge's agent, mid-answer" : said.value.how === "queued" ? `queued, it sends after this answer (cancel: talk /unqueue ${said.value.queued})` : said.value.how === "interrupted" ? "stopped the answer; sending now" : "the forge's agent is answering"}${CRLF}`, |
| 136 | 149 | ); |
src/web/pages/looks.ts +5 −2
| @@ -42,6 +42,9 @@ export const pictured = ( | ||
| 42 | 42 | kind: LookKind, |
| 43 | 43 | ): Look | undefined => looks.find((l) => l.kind === kind && l.error === null); |
| 44 | 44 | |
| 45 | /** What reading a look or the inbox needs of a request: the app and who is asking. */ | |
| 46 | export type Reader = Pick<Ctx, "app"> & { readonly auth: Pick<Ctx["auth"], "user"> }; | |
| 47 | ||
| 45 | 48 | /** |
| 46 | 49 | * The picture for a small slot: the dedicated thumb, or — for a commit |
| 47 | 50 | * taken before it existed — the phone shot a thumbnail loaded before, |
| @@ -51,7 +54,7 @@ export const pictured = ( | ||
| 51 | 54 | * of an app, and the home page is the one everyone means by it. |
| 52 | 55 | */ |
| 53 | 56 | export function thumbLook( |
| 54 | ctx: Ctx, | |
| 57 | ctx: Reader, | |
| 55 | 58 | repo: Repo, |
| 56 | 59 | record: AppRecord, |
| 57 | 60 | looks: readonly Look[], |
| @@ -108,7 +111,7 @@ export function lookImage(ctx: Ctx): Response { | ||
| 108 | 111 | |
| 109 | 112 | /** `mayFetchLook` for a request (`looks/readable.ts`). */ |
| 110 | 113 | export const mayFetchLook = ( |
| 111 | ctx: Ctx, | |
| 114 | ctx: Reader, | |
| 112 | 115 | repo: Repo, |
| 113 | 116 | record: AppRecord, |
| 114 | 117 | look: Look, |
src/web/studio/decisions.ts +26 −11
| @@ -17,7 +17,7 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 17 | 17 | import { repoBase } from "../chrome.ts"; |
| 18 | 18 | import { html, type Html } from "../html.ts"; |
| 19 | 19 | import { btn } from "../ui.ts"; |
| 20 | import { thumbLook } from "../pages/looks.ts"; | |
| 20 | import { thumbLook, type Reader } from "../pages/looks.ts"; | |
| 21 | 21 | import { changeHref } from "./nouns.ts"; |
| 22 | 22 | import { flatten } from "./note.ts"; |
| 23 | 23 | import { testsClause } from "./words.ts"; |
| @@ -50,9 +50,9 @@ function withoutHidden(db: Database, user: User | undefined, repos: readonly Rep | ||
| 50 | 50 | * own decisions are read, never the repository's whole list. |
| 51 | 51 | */ |
| 52 | 52 | export function decisionsFor( |
| 53 | ctx: Ctx, | |
| 53 | ctx: Reader, | |
| 54 | 54 | allRepos: readonly Repo[], |
| 55 | options: { evenDismissed?: boolean; pull?: string; onHidden?: (rows: number) => void } = {}, | |
| 55 | options: { evenDismissed?: boolean; pull?: string; onHidden?: (rows: number) => void; noPictures?: boolean } = {}, | |
| 56 | 56 | ): Decision[] { |
| 57 | 57 | const db = ctx.app.db; |
| 58 | 58 | const candidates = options.evenDismissed |
| @@ -67,7 +67,7 @@ export function decisionsFor( | ||
| 67 | 67 | ); |
| 68 | 68 | const pictureOf = (repo: Repo, pull: Pull): string | undefined => { |
| 69 | 69 | const record = records.get(repo.id); |
| 70 | if (record === undefined) return undefined; | |
| 70 | if (record === undefined || options.noPictures === true) return undefined; | |
| 71 | 71 | const env = previewEnv(pull.number); |
| 72 | 72 | const look = thumbLook( |
| 73 | 73 | ctx, |
| @@ -302,6 +302,21 @@ export function decisionActions(ctx: Ctx, d: Decision): Html { | ||
| 302 | 302 | return html`${primary} ${others}`; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | /** | |
| 306 | * The word on an ask's one deciding action: the single source for the inbox's | |
| 307 | * button and for /talk's answer (`actions/talk_decisions.ts`), so they cannot | |
| 308 | * disagree. Mirrors the cases of `decisionButtons`, which draws it. | |
| 309 | */ | |
| 310 | export function primaryLabel(d: Decision): string { | |
| 311 | if ((d.kind === "stopped" || d.kind === "handover") && d.pull) return "Tell them"; | |
| 312 | if ((d.kind === "look" || d.kind === "review" || d.kind === "waiting") && d.pull) return "Ship"; | |
| 313 | if (d.kind === "assigned" && (d.pull ?? d.issue)) return d.giveBack !== undefined ? "Give to the crew" : d.canLand === true ? "Land" : "Close"; | |
| 314 | if (d.kind === "proposal" && d.proposal) return "Approve"; | |
| 315 | if (d.kind === "declined" && d.issue) return "Answer"; | |
| 316 | if (d.kind === "parked" && d.issue) return "Tell them"; | |
| 317 | return "Settings"; | |
| 318 | } | |
| 319 | ||
| 305 | 320 | /** An ask's actions in two parts: the one that decides, and the rest. */ |
| 306 | 321 | export function decisionButtons(ctx: Ctx, d: Decision): { primary: Html; others: Html[] } { |
| 307 | 322 | const base = repoBase(d.repo); |
| @@ -309,7 +324,7 @@ export function decisionButtons(ctx: Ctx, d: Decision): { primary: Html; others: | ||
| 309 | 324 | const preview = d.preview; |
| 310 | 325 | if ((d.kind === "stopped" || d.kind === "handover") && pull) |
| 311 | 326 | return { |
| 312 | primary: btn("Tell them", { | |
| 327 | primary: btn(primaryLabel(d), { | |
| 313 | 328 | href: `${changeHref(base, pull.number)}#comment-body`, |
| 314 | 329 | size: "sm", |
| 315 | 330 | variant: "primary", |
| @@ -324,7 +339,7 @@ export function decisionButtons(ctx: Ctx, d: Decision): { primary: Html; others: | ||
| 324 | 339 | }; |
| 325 | 340 | if ((d.kind === "look" || d.kind === "review") && pull) |
| 326 | 341 | return { |
| 327 | primary: btn("Ship", { size: "sm", form: askFormId(d), variant: "primary" }), | |
| 342 | primary: btn(primaryLabel(d), { size: "sm", form: askFormId(d), variant: "primary" }), | |
| 328 | 343 | others: [ |
| 329 | 344 | ...(preview === undefined ? [] : [btn("Preview", { href: preview, size: "sm" })]), |
| 330 | 345 | btn("Not like this", { |
| @@ -335,7 +350,7 @@ export function decisionButtons(ctx: Ctx, d: Decision): { primary: Html; others: | ||
| 335 | 350 | }; |
| 336 | 351 | if (d.kind === "waiting" && pull) |
| 337 | 352 | return { |
| 338 | primary: btn("Ship", { size: "sm", form: askFormId(d), variant: "primary" }), | |
| 353 | primary: btn(primaryLabel(d), { size: "sm", form: askFormId(d), variant: "primary" }), | |
| 339 | 354 | others: [ |
| 340 | 355 | btn("Say what to change", { |
| 341 | 356 | href: `${changeHref(base, pull.number)}#comment-body`, |
| @@ -358,12 +373,12 @@ export function decisionButtons(ctx: Ctx, d: Decision): { primary: Html; others: | ||
| 358 | 373 | } |
| 359 | 374 | if (d.kind === "proposal" && d.proposal) |
| 360 | 375 | return { |
| 361 | primary: btn("Approve", { size: "sm", form: askFormId(d), variant: "primary" }), | |
| 376 | primary: btn(primaryLabel(d), { size: "sm", form: askFormId(d), variant: "primary" }), | |
| 362 | 377 | others: [btn("Later", { size: "sm", form: `${askFormId(d)}-later` })], |
| 363 | 378 | }; |
| 364 | 379 | if (d.kind === "declined" && d.issue) |
| 365 | 380 | return { |
| 366 | primary: btn("Answer", { | |
| 381 | primary: btn(primaryLabel(d), { | |
| 367 | 382 | href: `${base}/issues/${d.issue.number}#comment-body`, |
| 368 | 383 | size: "sm", |
| 369 | 384 | variant: "primary", |
| @@ -372,7 +387,7 @@ export function decisionButtons(ctx: Ctx, d: Decision): { primary: Html; others: | ||
| 372 | 387 | }; |
| 373 | 388 | if (d.kind === "parked" && d.issue) |
| 374 | 389 | return { |
| 375 | primary: btn("Tell them", { | |
| 390 | primary: btn(primaryLabel(d), { | |
| 376 | 391 | href: `${base}/issues/${d.issue.number}#comment-body`, |
| 377 | 392 | size: "sm", |
| 378 | 393 | variant: "primary", |
| @@ -384,7 +399,7 @@ export function decisionButtons(ctx: Ctx, d: Decision): { primary: Html; others: | ||
| 384 | 399 | : [btn("Let the decider", { size: "sm", form: askFormId(d) })], |
| 385 | 400 | }; |
| 386 | 401 | return { |
| 387 | primary: btn("Settings", { href: `${base}/settings/autonomy`, size: "sm" }), | |
| 402 | primary: btn(primaryLabel(d), { href: `${base}/settings/autonomy`, size: "sm" }), | |
| 388 | 403 | others: [], |
| 389 | 404 | }; |
| 390 | 405 | } |
test/talk-decisions.test.ts added +175
| @@ -0,0 +1,175 @@ | ||
| 1 | /** "What needs me?" in /talk (#12691): the inbox's rows as a short list, with no model turn. */ | |
| 2 | ||
| 3 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 4 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 5 | import { tmpdir } from "node:os"; | |
| 6 | import { join } from "node:path"; | |
| 7 | import { createApp, type App } from "../src/app.ts"; | |
| 8 | import { openIssue } from "../src/actions/issues.ts"; | |
| 9 | import { createRepo } from "../src/actions/repos.ts"; | |
| 10 | import { talk } from "../src/actions/talk.ts"; | |
| 11 | import { actionHref, asksWhatNeedsMe, DECISIONS_MAX } from "../src/actions/talk_decisions.ts"; | |
| 12 | import { listTurns, newConversation } from "../src/core/conversations.ts"; | |
| 13 | import { setAssignee } from "../src/core/issues.ts"; | |
| 14 | import type { Repo } from "../src/core/repos.ts"; | |
| 15 | import { createUser, type User } from "../src/core/users.ts"; | |
| 16 | import { configureConversation } from "../src/crew/conversation.ts"; | |
| 17 | import { askLinesFor, askRows } from "../src/web/studio/asks.ts"; | |
| 18 | import { decisionsFor, primaryLabel } from "../src/web/studio/decisions.ts"; | |
| 19 | import { KIND_TIER, type Decision } from "../src/web/studio/asks.ts"; | |
| 20 | import type { Proposal } from "../src/core/proposals.ts"; | |
| 21 | import { serveTalk, terminalAnswer } from "../src/tui/ssh-talk.ts"; | |
| 22 | import type { SshSession } from "../src/ssh/channels.ts"; | |
| 23 | import { pendingAmong, storeFile } from "../src/core/conversation_files.ts"; | |
| 24 | import { quietLogs } from "./helpers/globals.ts"; | |
| 25 | ||
| 26 | quietLogs(); | |
| 27 | ||
| 28 | describe("talk answers what needs me", () => { | |
| 29 | let dir = ""; | |
| 30 | let app: App; | |
| 31 | let alice: User; | |
| 32 | let bob: User; | |
| 33 | let repo: Repo; | |
| 34 | ||
| 35 | const answer = async (user: User, words: string): Promise<string> => { | |
| 36 | const conversation = newConversation(app.db, user.id); | |
| 37 | const said = talk(app, user, words, [], "inject", conversation.id); | |
| 38 | if (!said.ok) throw new Error(said.error); | |
| 39 | await said.value.done; | |
| 40 | const turns = listTurns(app.db, user.id, conversation.id); | |
| 41 | if (!turns.ok) throw new Error("no turns"); | |
| 42 | const last = turns.value[turns.value.length - 1]!; | |
| 43 | expect(last.role).toBe("agent"); | |
| 44 | return last.text; | |
| 45 | }; | |
| 46 | ||
| 47 | beforeAll(async () => { | |
| 48 | dir = await mkdtemp(join(tmpdir(), "forge-talk-decisions-")); | |
| 49 | app = createApp({ dataDir: dir, port: 0, disk: () => ({ freeBytes: 95, totalBytes: 100 }) }); | |
| 50 | // A binary that does not exist: if a model turn started, the answer would be a failure. | |
| 51 | configureConversation(app, { binary: join(dir, "no-agent"), localUrl: "http://127.0.0.1:1", budgetUsd: 1, timeoutMs: 5_000, signal: new AbortController().signal }); | |
| 52 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-long-talk-decisions-pass", adminIfFirst: true }); | |
| 53 | const b = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-long-talk-decisions-pass" }); | |
| 54 | if (!a.ok || !b.ok) throw new Error("users"); | |
| 55 | alice = a.value; | |
| 56 | bob = b.value; | |
| 57 | const made = await createRepo(app, alice, { name: "shelf", visibility: "public" }); | |
| 58 | if (!made.ok) throw new Error(String(made.error)); | |
| 59 | repo = made.value; | |
| 60 | }, 30_000); | |
| 61 | ||
| 62 | afterAll(async () => { | |
| 63 | await rm(dir, { recursive: true, force: true }); | |
| 64 | }); | |
| 65 | ||
| 66 | test("only a short question about the person's own queue is taken", () => { | |
| 67 | for (const yes of ["What needs me?", "what's waiting on me", "anything waiting for me?", "inbox"]) expect(asksWhatNeedsMe(yes)).toBe(true); | |
| 68 | for (const no of ["build me a notes app", "what needs me to change in the footer of this page so that it is wider and the colours match the rest of the page", "who needs a hug"]) expect(asksWhatNeedsMe(no)).toBe(false); | |
| 69 | }); | |
| 70 | ||
| 71 | test("none held says so in one line", async () => { | |
| 72 | expect(await answer(bob, "what needs me?")).toBe("Nothing is waiting on you."); | |
| 73 | }); | |
| 74 | ||
| 75 | test("held items are listed in the inbox's order, each with a link and its one action", async () => { | |
| 76 | const one = openIssue(app, alice, repo, { title: "First [thing]", body: "" }); | |
| 77 | const two = openIssue(app, alice, repo, { title: "snake_case thing", body: "" }); | |
| 78 | if (!one.ok || !two.ok) throw new Error("issues"); | |
| 79 | setAssignee(app.db, one.value.id, alice.id); | |
| 80 | setAssignee(app.db, two.value.id, alice.id); | |
| 81 | const text = await answer(alice, "What needs me?"); | |
| 82 | expect(askLinesFor(app.db, alice).filter((l) => l.id.startsWith("assigned:")).length).toBe(2); | |
| 83 | expect(text).toContain("2 things wait on you"); | |
| 84 | expect(text).toContain(`/alice/shelf/issues/${one.value.number}`); | |
| 85 | expect(text).toContain("**Close**"); | |
| 86 | expect(text).toContain("[First (thing)]("); | |
| 87 | expect(text).toContain("[snake_case thing]("); | |
| 88 | // The word is the inbox button's own. | |
| 89 | const rows = askRows(decisionsFor({ app, auth: { user: alice } }, [repo], { noPictures: true })).flatMap((r) => r.items); | |
| 90 | expect(text).toContain(`**${primaryLabel(rows[0]!)}**`); | |
| 91 | // Read as the signed-in person: bob sees none of alice's. | |
| 92 | expect(await answer(bob, "what needs me")).toBe("Nothing is waiting on you."); | |
| 93 | }); | |
| 94 | ||
| 95 | test("the older row, which scores higher in its tier, is listed first", async () => { | |
| 96 | const lone = await createRepo(app, alice, { name: "second", visibility: "public" }); | |
| 97 | if (!lone.ok) throw new Error("repo"); | |
| 98 | const newer = openIssue(app, alice, lone.value, { title: "Newer one", body: "" }); | |
| 99 | const older = openIssue(app, alice, lone.value, { title: "Older one", body: "" }); | |
| 100 | if (!newer.ok || !older.ok) throw new Error("issues"); | |
| 101 | setAssignee(app.db, newer.value.id, alice.id); | |
| 102 | setAssignee(app.db, older.value.id, alice.id); | |
| 103 | app.db.run("UPDATE issue SET created_at = '2020-01-01T00:00:00.000Z', updated_at = '2020-01-01T00:00:00.000Z' WHERE id = ?1", [older.value.id]); | |
| 104 | const rows = askRows(decisionsFor({ app, auth: { user: alice } }, [lone.value], { noPictures: true })).flatMap((r) => r.items); | |
| 105 | expect(rows[0]!.issue!.id).toBe(older.value.id); | |
| 106 | expect(rows[0]!.consequence.score).toBeGreaterThan(rows[1]!.consequence.score); | |
| 107 | const text = await answer(alice, "what needs me?"); | |
| 108 | expect(text.indexOf("[Older one](")).toBeGreaterThanOrEqual(0); | |
| 109 | expect(text.indexOf("[Older one](")).toBeLessThan(text.indexOf("[Newer one](")); | |
| 110 | }); | |
| 111 | ||
| 112 | test("more than five held rows list five and link the rest", async () => { | |
| 113 | for (let i = 0; i < 7; i++) { | |
| 114 | const made = openIssue(app, alice, repo, { title: `Extra ${i}`, body: "" }); | |
| 115 | if (!made.ok) throw new Error("issue"); | |
| 116 | setAssignee(app.db, made.value.id, alice.id); | |
| 117 | } | |
| 118 | const text = await answer(alice, "inbox"); | |
| 119 | expect(text.split("\n").filter((l) => /^\d+\. \[/.test(l)).length).toBe(DECISIONS_MAX); | |
| 120 | expect(text).toMatch(/\[\d+ more in your inbox\]\(\/asks\)/); | |
| 121 | }); | |
| 122 | ||
| 123 | test("a proposal row links /asks with Approve", () => { | |
| 124 | const proposal: Proposal = { id: "1", repoId: repo.id, authorId: alice.id, title: "Plan", why: "", issues: [], state: "pending", createdAt: "2026-11-14T00:00:00.000Z" }; | |
| 125 | const d: Decision = { kind: "proposal", id: "proposal:1", repo, proposal, who: "planner", says: "", short: 'proposes "Plan"', consequence: KIND_TIER.proposal, waiting: { word: "a decision", on: "you" } }; | |
| 126 | expect(actionHref(d)).toBe("/asks"); | |
| 127 | expect(primaryLabel(d)).toBe("Approve"); | |
| 128 | }); | |
| 129 | ||
| 130 | test("while a turn is live the question goes to that turn, not the inbox", async () => { | |
| 131 | const conversation = newConversation(app.db, alice.id); | |
| 132 | const first = talk(app, alice, "hello there", [], "inject", conversation.id); | |
| 133 | if (!first.ok) throw new Error(first.error); | |
| 134 | expect(first.value.how).toBe("started"); | |
| 135 | const second = talk(app, alice, "what needs me?", [], "inject", conversation.id); | |
| 136 | expect(second.ok && second.value.how).not.toBe("answered"); | |
| 137 | await first.value.done?.catch(() => undefined); | |
| 138 | if (second.ok) await second.value.done?.catch(() => undefined); | |
| 139 | const turns = listTurns(app.db, alice.id, conversation.id); | |
| 140 | expect(turns.ok && turns.value.some((t) => t.role === "agent" && t.text.includes("on you"))).toBe(false); | |
| 141 | }); | |
| 142 | ||
| 143 | test("the terminal prints the answer itself, its lines intact and no escape code", async () => { | |
| 144 | let out = ""; | |
| 145 | let code: number | undefined; | |
| 146 | const session: Pick<SshSession, "write" | "writeStderr" | "exit"> = { | |
| 147 | write: (s) => { | |
| 148 | out += String(s); | |
| 149 | }, | |
| 150 | writeStderr: (s) => { | |
| 151 | out += String(s); | |
| 152 | }, | |
| 153 | exit: (c) => { | |
| 154 | code = c; | |
| 155 | }, | |
| 156 | }; | |
| 157 | serveTalk(app, session as SshSession, bob, "what needs me?"); | |
| 158 | expect(code).toBe(0); | |
| 159 | expect(out).toBe("Nothing is waiting on you.\r\n"); | |
| 160 | expect(terminalAnswer("Two:\n\n1. [a\x1b[31m](/x)")).toBe("Two:\r\n\r\n1. [a [31m](/x)\r\n"); | |
| 161 | }); | |
| 162 | ||
| 163 | test("a message with files, or while a turn is live, still goes to the agent", async () => { | |
| 164 | const conversation = newConversation(app.db, alice.id); | |
| 165 | const stored = storeFile(app.db, app.config.dataDir, alice.id, "n.txt", new TextEncoder().encode("hi")); | |
| 166 | if (!stored.ok) throw new Error("file"); | |
| 167 | const pending = pendingAmong(app.db, alice.id, [stored.value.id]); | |
| 168 | if (!pending.ok) throw new Error("pending"); | |
| 169 | const withFile = talk(app, alice, "what needs me?", pending.value, "inject", conversation.id); | |
| 170 | expect(withFile.ok && withFile.value.how).not.toBe("answered"); | |
| 171 | if (withFile.ok) await withFile.value.done?.catch(() => undefined); | |
| 172 | const turns = listTurns(app.db, alice.id, conversation.id); | |
| 173 | expect(turns.ok && turns.value.some((t) => t.text.startsWith("Nothing is waiting") || t.text.includes("wait on you"))).toBe(false); | |
| 174 | }); | |
| 175 | }); |
new above
offline
Second copy of the action words (see decisionButtons); read them from the one source so the page and /talk cannot disagree.