Public: anyone can read this; the crew can change it.
The inbox's decision forms leave asks.ts for src/web/studio/decisions.ts #6316
mason/forge:mason/6311-the-inbox-s-decision-forms-leave-asks-ts → main 2 commits fork
7 files
changed +354
−344
docs/STUDIO.md +2 −1
| @@ -333,7 +333,8 @@ issue, which is also what the board's line above its regions offers), and, for a | ||
| 333 | 333 | forge's health (`needs` in `/api/v1/health`). What counts as an ask is |
| 334 | 334 | defined once, in `src/web/studio/asks.ts`: the header's **Asks** count, the |
| 335 | 335 | page, the dashboard's _Needs you_ link and the phone notifier all read it, |
| 336 | so the numbers agree. It is server-rendered and every button is a form post, | |
| 336 | so the numbers agree. Each card's words, forms and buttons are drawn in | |
| 337 | `src/web/studio/decisions.ts`. It is server-rendered and every button is a form post, | |
| 337 | 338 | so it works without JavaScript. |
| 338 | 339 | |
| 339 | 340 | ## What you asked for |
src/web/studio/asks.ts +7 −331
| @@ -2,15 +2,14 @@ | ||
| 2 | 2 | * What asks a person, and what they can do about it: a *decision* is one |
| 3 | 3 | * card — a pull the crew stopped on, a green pull waiting for a look, or a |
| 4 | 4 | * repository parked at its ceiling — read from the same tables the rest of |
| 5 | * the forge reads, with the same access the owner has. This module owns the | |
| 6 | * card, the row and the panel of them; every button here posts | |
| 7 | * to the route a person could have posted to by hand (`actions.ts`). | |
| 5 | * the forge reads, with the same access the owner has. This module owns | |
| 6 | * which asks there are, the row and the panel of them; the card's words, | |
| 7 | * forms and buttons are `decisions.ts`. | |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | import type { Database } from "bun:sqlite"; |
| 11 | 11 | import { forgeVitals, needLine } from "../../actions/health.ts"; |
| 12 | 12 | import type { Degraded } from "../../kernel/vitals.ts"; |
| 13 | import { previewEnv } from "../../apps/data.ts"; | |
| 14 | 13 | import { waitingFor, type WaitingFor } from "../../core/waiting_for.ts"; |
| 15 | 14 | import { crewForRepos } from "../../core/agents.ts"; |
| 16 | 15 | import { appsForRepos } from "../../core/apps.ts"; |
| @@ -31,7 +30,6 @@ import { | ||
| 31 | 30 | type Issue, |
| 32 | 31 | } from "../../core/issues.ts"; |
| 33 | 32 | import { mayView } from "../../core/sealed.ts"; |
| 34 | import { looksForApps } from "../../core/looks.ts"; | |
| 35 | 33 | import { closesFromBody, getPull, joinMany, type Pull } from "../../core/pulls.ts"; |
| 36 | 34 | import { |
| 37 | 35 | canRead, |
| @@ -56,18 +54,11 @@ import { | ||
| 56 | 54 | } from "../../crew/autonomy.ts"; |
| 57 | 55 | import { breakerParked, WAITING_NOTES } from "../../crew/breaker.ts"; |
| 58 | 56 | import { CHECK_FAILED_LIMIT } from "../../crew/dispatch.ts"; |
| 59 | import { handoverLines, handoversOf, type Handover } from "../../crew/guard.ts"; | |
| 57 | import { handoversOf, type Handover } from "../../crew/guard.ts"; | |
| 60 | 58 | import { conflictsOf, isStalePull, mergesAgainSince, staleGreen } from "../../crew/stale_asks.ts"; |
| 61 | 59 | import { reviewWaitsFor, type ReviewWait } from "../../crew/review.ts"; |
| 62 | 60 | import type { Ctx } from "../../http/context.ts"; |
| 63 | import { repoBase } from "../chrome.ts"; | |
| 64 | import { html, type Html } from "../html.ts"; | |
| 65 | import { btn, row } from "../ui.ts"; | |
| 66 | import { lookUrl } from "../../core/looks.ts"; | |
| 67 | import { thumbLook } from "../pages/looks.ts"; | |
| 68 | import { changeHref } from "./nouns.ts"; | |
| 69 | 61 | import { NO_LONGER_ASKS } from "../../actions/asks_words.ts"; |
| 70 | import { testsClause } from "./words.ts"; | |
| 71 | 62 | |
| 72 | 63 | /** Repos narrowed to those with an app record, with the records — the one |
| 73 | 64 | * join `appsOf` and `writableAppsOf` share. */ |
| @@ -110,9 +101,6 @@ export function writableAppsOf(ctx: Ctx, user: User | undefined) { | ||
| 110 | 101 | |
| 111 | 102 | export type DecisionKind = "stopped" | "look" | "review" | "paused" | "parked" | "declined" | "handover" | "waiting" | "assigned" | "proposal"; |
| 112 | 103 | |
| 113 | /** Dollars as a person reads them: cents when small, whole when not. */ | |
| 114 | const dollars = (n: number): string => (n < 10 ? n.toFixed(2) : n.toFixed(0)); | |
| 115 | ||
| 116 | 104 | export interface Decision { |
| 117 | 105 | readonly kind: DecisionKind; |
| 118 | 106 | /** Stable across renders — the kind and what it is about — so a form can |
| @@ -778,7 +766,7 @@ export function askRows< | ||
| 778 | 766 | })); |
| 779 | 767 | } |
| 780 | 768 | |
| 781 | type Scored = AskCandidate & { | |
| 769 | export type Scored = AskCandidate & { | |
| 782 | 770 | readonly consequence: Consequence; |
| 783 | 771 | readonly waiting: WaitingFor; |
| 784 | 772 | }; |
| @@ -795,7 +783,7 @@ function waitingOf(db: Database, user: User | undefined, a: AskCandidate): Waiti | ||
| 795 | 783 | } |
| 796 | 784 | |
| 797 | 785 | /** Every candidate for the viewer, scored, dismissed or not. */ |
| 798 | function scoredFor( | |
| 786 | export function scoredFor( | |
| 799 | 787 | db: Database, |
| 800 | 788 | user: User | undefined, |
| 801 | 789 | repos: readonly Repo[], |
| @@ -968,7 +956,7 @@ function lineOf(c: AskCandidate): string { | ||
| 968 | 956 | } |
| 969 | 957 | |
| 970 | 958 | /** Why an agent's change waits for a person's review, in a clause. */ |
| 971 | const reviewWhy = (wait: ReviewWait | undefined): string => | |
| 959 | export const reviewWhy = (wait: ReviewWait | undefined): string => | |
| 972 | 960 | wait?.why === "rounds" |
| 973 | 961 | ? `the reviewer asked for changes three times, since ${wait.since.slice(0, 10)}` |
| 974 | 962 | : wait?.why === "lapsed" && wait.lateCheckMinutes !== undefined |
| @@ -1090,305 +1078,6 @@ export function askLinesFor( | ||
| 1090 | 1078 | }); |
| 1091 | 1079 | } |
| 1092 | 1080 | |
| 1093 | /** | |
| 1094 | * The decisions waiting on the viewer, worded and pictured. A change's own | |
| 1095 | * page passes `evenDismissed`: setting an ask aside quiets the lists, never | |
| 1096 | * the decision on the thing itself. | |
| 1097 | */ | |
| 1098 | export function decisionsFor( | |
| 1099 | ctx: Ctx, | |
| 1100 | allRepos: readonly Repo[], | |
| 1101 | options: { evenDismissed?: boolean } = {}, | |
| 1102 | ): Decision[] { | |
| 1103 | const db = ctx.app.db; | |
| 1104 | const candidates = options.evenDismissed | |
| 1105 | ? scoredFor(db, ctx.auth.user, allRepos) | |
| 1106 | : waitingOn(db, ctx.auth.user, allRepos); | |
| 1107 | // The pictures, in one read: a green pull's row leads with its preview. | |
| 1108 | const repoIds = [...new Set(candidates.map((c) => c.repo.id))]; | |
| 1109 | const records = appsForRepos(db, repoIds); | |
| 1110 | const looks = looksForApps( | |
| 1111 | db, | |
| 1112 | [...records.values()].map((r) => r.id), | |
| 1113 | ); | |
| 1114 | const pictureOf = (repo: Repo, pull: Pull): string | undefined => { | |
| 1115 | const record = records.get(repo.id); | |
| 1116 | if (record === undefined) return undefined; | |
| 1117 | const env = previewEnv(pull.number); | |
| 1118 | const look = thumbLook( | |
| 1119 | ctx, | |
| 1120 | repo, | |
| 1121 | record, | |
| 1122 | looks.filter((l) => l.appId === record.id && l.env === env), | |
| 1123 | ); | |
| 1124 | return ( | |
| 1125 | look && lookUrl(repoBase(repo), look) | |
| 1126 | ); | |
| 1127 | }; | |
| 1128 | const worded = (c: Scored): Omit<Decision, "consequence" | "waiting"> => { | |
| 1129 | if (c.kind === "assigned") { | |
| 1130 | const thing = c.pull ?? c.issue!; | |
| 1131 | return { | |
| 1132 | kind: "assigned", | |
| 1133 | id: `assigned:${thing.id}`, | |
| 1134 | repo: c.repo, | |
| 1135 | ...(c.pull === undefined ? { issue: c.issue } : { pull: c.pull }), | |
| 1136 | who: c.who, | |
| 1137 | says: `"${thing.title}" is assigned to you.`, | |
| 1138 | short: `assigned to you · updated ${thing.updatedAt.slice(0, 10)}`, | |
| 1139 | }; | |
| 1140 | } | |
| 1141 | if (c.kind === "proposal" && c.proposal) | |
| 1142 | return { | |
| 1143 | kind: "proposal", | |
| 1144 | id: `proposal:${c.proposal.id}`, | |
| 1145 | repo: c.repo, | |
| 1146 | proposal: c.proposal, | |
| 1147 | who: c.who, | |
| 1148 | says: `${c.who} proposes "${c.proposal.title}" (${issueTitles(c.proposal).length} issues). Approve opens them, Redirect hands your words to the planner, Later puts it aside.`, | |
| 1149 | short: `proposes "${c.proposal.title}"`, | |
| 1150 | }; | |
| 1151 | if (c.kind === "parked" && c.issue) | |
| 1152 | return { | |
| 1153 | kind: "parked", | |
| 1154 | id: `parked:${c.issue.id}`, | |
| 1155 | repo: c.repo, | |
| 1156 | issue: c.issue, | |
| 1157 | who: c.who, | |
| 1158 | says: `Three runs on #${c.issue.number} failed or were declined within an hour, so the crew parked it. Say what to try and it starts again.`, | |
| 1159 | short: `#${c.issue.number} parked after three failed runs`, | |
| 1160 | }; | |
| 1161 | if (c.kind === "declined" && c.issue && c.decline) | |
| 1162 | return { | |
| 1163 | kind: "declined", | |
| 1164 | id: `declined:${c.decline.runId}`, | |
| 1165 | repo: c.repo, | |
| 1166 | issue: c.issue, | |
| 1167 | who: c.who, | |
| 1168 | says: `The planner declined the direction: \u201c${c.decline.words}\u201d. It plans nothing more until you answer on #${c.issue.number}.`, | |
| 1169 | short: `the planner declined the direction: \u201c${c.decline.words}\u201d`, | |
| 1170 | }; | |
| 1171 | if (c.kind === "handover" && c.pull && c.handover) | |
| 1172 | return { | |
| 1173 | kind: "handover", | |
| 1174 | id: `handover:${c.pull.id}`, | |
| 1175 | repo: c.repo, | |
| 1176 | pull: c.pull, | |
| 1177 | who: c.who, | |
| 1178 | says: `The reviewer asked for changes three times with no approval between, so the crew stopped. ${handoverLines(c.handover).join(" ")} Say what to try (or approve it on its page), or close it.`, | |
| 1179 | short: `"${c.pull.title}" had three reviews asking for changes`, | |
| 1180 | why: c.why, | |
| 1181 | recommendation: c.recommendation, | |
| 1182 | }; | |
| 1183 | if (c.kind === "waiting" && c.pull) | |
| 1184 | return { | |
| 1185 | kind: "waiting", | |
| 1186 | id: `waiting:${c.pull.id}`, | |
| 1187 | repo: c.repo, | |
| 1188 | pull: c.pull, | |
| 1189 | who: c.who, | |
| 1190 | says: `"${c.pull.title}" is ${c.why ?? "waiting"}, and no person has acted on it. Ship it, say what to change, or close it.`, | |
| 1191 | short: c.why ?? "waiting for a person", | |
| 1192 | why: c.why, | |
| 1193 | recommendation: c.recommendation, | |
| 1194 | }; | |
| 1195 | if (c.kind === "stopped" && c.pull) { | |
| 1196 | const tries = c.tries ?? 0; | |
| 1197 | const stopped = c.stoppedByDecider ?? false; | |
| 1198 | return { | |
| 1199 | kind: "stopped", | |
| 1200 | id: `stopped:${c.pull.id}`, | |
| 1201 | repo: c.repo, | |
| 1202 | pull: c.pull, | |
| 1203 | who: c.who, | |
| 1204 | says: stopped | |
| 1205 | ? `${c.who}'s check failed and the crew's decider stopped rather than spend another run. Say what to try, or close it.` | |
| 1206 | : `${c.who} tried ${tries + 1} times and the check still fails. The crew stopped here. Say what to try, or close it.`, | |
| 1207 | short: stopped | |
| 1208 | ? `the check failed; the decider stopped for you` | |
| 1209 | : `${c.who} tried ${tries + 1} times; the check still fails`, | |
| 1210 | }; | |
| 1211 | } | |
| 1212 | if (c.kind === "review" && c.pull) | |
| 1213 | return { | |
| 1214 | kind: "review", | |
| 1215 | id: `review:${c.pull.id}`, | |
| 1216 | repo: c.repo, | |
| 1217 | pull: c.pull, | |
| 1218 | who: c.who, | |
| 1219 | says: `${c.who}'s "${c.pull.title}" is green and waits for a review: ${reviewWhy(c.reviewWait)}. An agent's change never ships unreviewed; ship it, or say what is off.`, | |
| 1220 | short: `green; waits for a review — ${reviewWhy(c.reviewWait)}`, | |
| 1221 | }; | |
| 1222 | if (c.kind === "look" && c.pull) { | |
| 1223 | const picture = pictureOf(c.repo, c.pull); | |
| 1224 | const clause = testsClause(c.check ?? null); | |
| 1225 | // The crew's own words say who finished it; a person's own change | |
| 1226 | // gets the wording that is true of it — nobody "finished" it for | |
| 1227 | // them, it is simply green and waiting. | |
| 1228 | return { | |
| 1229 | kind: "look", | |
| 1230 | id: `look:${c.pull.id}`, | |
| 1231 | repo: c.repo, | |
| 1232 | pull: c.pull, | |
| 1233 | who: c.who, | |
| 1234 | says: c.authorIsAgent | |
| 1235 | ? `${c.who} finished "${c.pull.title}" and the check is green${clause === "" ? "" : ` (${clause})`}. Look at the preview, then ship it or say what is off.` | |
| 1236 | : `"${c.pull.title}" is green — ${clause === "" ? "" : `${clause}, `}ready for a look. Ship it, or say what is off.`, | |
| 1237 | short: c.authorIsAgent | |
| 1238 | ? `${c.who} finished it; the check is green${clause === "" ? "" : ` (${clause})`}` | |
| 1239 | : `green — ${clause === "" ? "" : `${clause}, `}ready for a look`, | |
| 1240 | ...(picture === undefined ? {} : { picture }), | |
| 1241 | }; | |
| 1242 | } | |
| 1243 | return { | |
| 1244 | kind: "paused", | |
| 1245 | id: `paused:${c.repo.id}`, | |
| 1246 | repo: c.repo, | |
| 1247 | who: "the crew", | |
| 1248 | says: `${c.repo.name} reached its $${dollars(c.repo.autonomyCeilingUsd)} for today. The crew picks nothing more until 00:00 UTC. Raise the ceiling in settings to go on now.`, | |
| 1249 | short: `at its $${dollars(c.repo.autonomyCeilingUsd)} ceiling until 00:00 UTC`, | |
| 1250 | }; | |
| 1251 | }; | |
| 1252 | const previewOf = (c: Scored): string | undefined => | |
| 1253 | c.pull === undefined || !records.has(c.repo.id) | |
| 1254 | ? undefined | |
| 1255 | : `${repoBase(c.repo)}/app/pull-${c.pull.number}/open`; | |
| 1256 | return candidates.map((c) => ({ | |
| 1257 | ...worded(c), | |
| 1258 | preview: previewOf(c), | |
| 1259 | consequence: c.consequence, | |
| 1260 | waiting: c.waiting, | |
| 1261 | })); | |
| 1262 | } | |
| 1263 | /** The id of the form a row's own button submits (see `decisionForm`). */ | |
| 1264 | const askFormId = (d: Decision): string => `ask-${d.id}`; | |
| 1265 | ||
| 1266 | /** | |
| 1267 | * The form behind a row's landing button — its own post, exactly as it was. | |
| 1268 | * It sits after the panel's form, because a form inside a form is not | |
| 1269 | * HTML; the button reaches it by id. | |
| 1270 | */ | |
| 1271 | export function decisionForm(d: Decision, back?: string): Html | null { | |
| 1272 | const pull = d.pull; | |
| 1273 | const own = html`id="${askFormId(d)}" method="post" hidden`; | |
| 1274 | if (d.kind === "parked") | |
| 1275 | return html`<form ${own} action="/asks/decide"> | |
| 1276 | <input type="hidden" name="ask" value="${d.id}" /> | |
| 1277 | </form>`; | |
| 1278 | if (d.kind === "proposal" && d.proposal) return proposalForms(d, back); | |
| 1279 | if (pull === undefined) return null; | |
| 1280 | const base = repoBase(d.repo); | |
| 1281 | const where = back === undefined ? null : html`<input type="hidden" name="back" value="${back}" />`; | |
| 1282 | if (d.kind === "stopped" || d.kind === "handover") | |
| 1283 | return html`<form ${own} action="${base}/pulls/${pull.number}/state"> | |
| 1284 | <input type="hidden" name="state" value="closed" />${where} | |
| 1285 | </form>`; | |
| 1286 | if (d.kind === "look" || d.kind === "review") | |
| 1287 | return html`<form ${own} action="${base}/pulls/${pull.number}/ship"> | |
| 1288 | <input type="hidden" name="pull" value="${pull.number}" />${where} | |
| 1289 | </form>`; | |
| 1290 | if (d.kind === "waiting") | |
| 1291 | return html`<form ${own} action="${base}/pulls/${pull.number}/ship"> | |
| 1292 | <input type="hidden" name="pull" value="${pull.number}" />${where} | |
| 1293 | </form> | |
| 1294 | <form id="${askFormId(d)}-close" method="post" hidden action="${base}/pulls/${pull.number}/state"> | |
| 1295 | <input type="hidden" name="state" value="closed" />${where} | |
| 1296 | </form>`; | |
| 1297 | return null; | |
| 1298 | } | |
| 1299 | ||
| 1300 | /** | |
| 1301 | * The actions on one ask, on one line: a button for what lands (submitting | |
| 1302 | * the row's own form, `decisionForm`), links for what needs a look or a | |
| 1303 | * word. Saying something to the crew happens on the change's own page, | |
| 1304 | * where the conversation is — not in a box in a list. | |
| 1305 | */ | |
| 1306 | export function decisionActions(ctx: Ctx, d: Decision): Html { | |
| 1307 | const { primary, others } = decisionButtons(ctx, d); | |
| 1308 | return html`${primary} ${others}`; | |
| 1309 | } | |
| 1310 | ||
| 1311 | /** An ask's actions in two parts: the one that decides, and the rest. */ | |
| 1312 | export function decisionButtons(ctx: Ctx, d: Decision): { primary: Html; others: Html[] } { | |
| 1313 | const base = repoBase(d.repo); | |
| 1314 | const pull = d.pull; | |
| 1315 | const preview = d.preview; | |
| 1316 | if ((d.kind === "stopped" || d.kind === "handover") && pull) | |
| 1317 | return { | |
| 1318 | primary: btn("Tell them", { | |
| 1319 | href: `${changeHref(base, pull.number)}#comment-body`, | |
| 1320 | size: "sm", | |
| 1321 | variant: "primary", | |
| 1322 | }), | |
| 1323 | others: [ | |
| 1324 | btn("Close", { size: "sm", form: askFormId(d) }), | |
| 1325 | btn("See", { href: changeHref(base, pull.number), size: "sm" }), | |
| 1326 | ], | |
| 1327 | }; | |
| 1328 | if ((d.kind === "look" || d.kind === "review") && pull) | |
| 1329 | return { | |
| 1330 | primary: btn("Ship", { size: "sm", form: askFormId(d), variant: "primary" }), | |
| 1331 | others: [ | |
| 1332 | ...(preview === undefined ? [] : [btn("Preview", { href: preview, size: "sm" })]), | |
| 1333 | btn("Not like this", { | |
| 1334 | href: `${changeHref(base, pull.number)}#comment-body`, | |
| 1335 | size: "sm", | |
| 1336 | }), | |
| 1337 | ], | |
| 1338 | }; | |
| 1339 | if (d.kind === "waiting" && pull) | |
| 1340 | return { | |
| 1341 | primary: btn("Ship", { size: "sm", form: askFormId(d), variant: "primary" }), | |
| 1342 | others: [ | |
| 1343 | btn("Say what to change", { | |
| 1344 | href: `${changeHref(base, pull.number)}#comment-body`, | |
| 1345 | size: "sm", | |
| 1346 | }), | |
| 1347 | btn("Close", { size: "sm", form: `${askFormId(d)}-close` }), | |
| 1348 | ], | |
| 1349 | }; | |
| 1350 | if (d.kind === "assigned" && (d.pull ?? d.issue)) | |
| 1351 | return { | |
| 1352 | primary: btn("Open", { | |
| 1353 | href: pull ? changeHref(base, pull.number) : `${base}/issues/${d.issue!.number}`, | |
| 1354 | size: "sm", | |
| 1355 | variant: "primary", | |
| 1356 | }), | |
| 1357 | others: [], | |
| 1358 | }; | |
| 1359 | if (d.kind === "proposal" && d.proposal) | |
| 1360 | return { | |
| 1361 | primary: btn("Approve", { size: "sm", form: askFormId(d), variant: "primary" }), | |
| 1362 | others: [btn("Later", { size: "sm", form: `${askFormId(d)}-later` })], | |
| 1363 | }; | |
| 1364 | if (d.kind === "declined" && d.issue) | |
| 1365 | return { | |
| 1366 | primary: btn("Answer", { | |
| 1367 | href: `${base}/issues/${d.issue.number}#comment-body`, | |
| 1368 | size: "sm", | |
| 1369 | variant: "primary", | |
| 1370 | }), | |
| 1371 | others: [], | |
| 1372 | }; | |
| 1373 | if (d.kind === "parked" && d.issue) | |
| 1374 | return { | |
| 1375 | primary: btn("Tell them", { | |
| 1376 | href: `${base}/issues/${d.issue.number}#comment-body`, | |
| 1377 | size: "sm", | |
| 1378 | variant: "primary", | |
| 1379 | }), | |
| 1380 | // Only where a decider is there to answer. | |
| 1381 | others: | |
| 1382 | ctx.app.config.decider === undefined | |
| 1383 | ? [] | |
| 1384 | : [btn("Let the decider", { size: "sm", form: askFormId(d) })], | |
| 1385 | }; | |
| 1386 | return { | |
| 1387 | primary: btn("Settings", { href: `${base}/settings/autonomy`, size: "sm" }), | |
| 1388 | others: [], | |
| 1389 | }; | |
| 1390 | } | |
| 1391 | ||
| 1392 | 1081 | /** |
| 1393 | 1082 | * What the forge itself needs, for a site admin: each sentence of the |
| 1394 | 1083 | * health answer (`/api/v1/health`) as one ask. Anyone else gets none — the |
| @@ -1522,16 +1211,3 @@ export function askTargetsFor( | ||
| 1522 | 1211 | } |
| 1523 | 1212 | return { issueIds: [...new Set(issueIds)], refused }; |
| 1524 | 1213 | } |
| 1525 | ||
| 1526 | /** | |
| 1527 | * The forms behind a proposal card: Approve, Later and Redirect, each one | |
| 1528 | * POST to `/asks/proposal/:id/<verb>` that lands back on the page it came | |
| 1529 | * from. They sit apart from the card's own form, as forms do not nest. | |
| 1530 | */ | |
| 1531 | function proposalForms(d: Decision, back?: string): Html { | |
| 1532 | const id = askFormId(d); | |
| 1533 | const post = (verb: string) => `/asks/proposal/${d.proposal!.id}/${verb}`; | |
| 1534 | const where = back === undefined ? null : html`<input type="hidden" name="back" value="${back}" />`; | |
| 1535 | return html`<form id="${id}" method="post" action="${post("approve")}" hidden>${where}</form> | |
| 1536 | <form id="${id}-later" method="post" action="${post("later")}" hidden>${where}</form>`; | |
| 1537 | } |
src/web/studio/asks_page.ts +1 −3
| @@ -49,9 +49,6 @@ import { | ||
| 49 | 49 | askSentence, |
| 50 | 50 | ASK_WORDS, |
| 51 | 51 | ROW_PLURAL, |
| 52 | decisionButtons, | |
| 53 | decisionForm, | |
| 54 | decisionsFor, | |
| 55 | 52 | forgeNeedsFor, |
| 56 | 53 | silencedRepos, |
| 57 | 54 | putAsideWaves, |
| @@ -59,6 +56,7 @@ import { | ||
| 59 | 56 | type Consequence, |
| 60 | 57 | type Decision, |
| 61 | 58 | } from "./asks.ts"; |
| 59 | import { decisionButtons, decisionForm, decisionsFor } from "./decisions.ts"; | |
| 62 | 60 | import { changeHref } from "./nouns.ts"; |
| 63 | 61 | |
| 64 | 62 | /** The kinds, in a word each, for "select by kind". */ |
src/web/studio/change.ts +2 −7
| @@ -76,13 +76,8 @@ import { | ||
| 76 | 76 | parseNumber, |
| 77 | 77 | type Entry, |
| 78 | 78 | } from "../pages/thread.ts"; |
| 79 | import { | |
| 80 | decisionActions, | |
| 81 | decisionForm, | |
| 82 | decisionsFor, | |
| 83 | KIND_TIER, | |
| 84 | type Decision, | |
| 85 | } from "./asks.ts"; | |
| 79 | import { KIND_TIER, type Decision } from "./asks.ts"; | |
| 80 | import { decisionActions, decisionForm, decisionsFor } from "./decisions.ts"; | |
| 86 | 81 | import { tellLine, tellsAnswered } from "./branch_tell.ts"; |
| 87 | 82 | import { previewVision } from "../../crew/vision.ts"; |
| 88 | 83 | import { visionPreviewCard } from "./direction.ts"; |
src/web/studio/decisions.ts added +339
| @@ -0,0 +1,339 @@ | ||
| 1 | /** | |
| 2 | * The inbox's decision cards: `decisionsFor` words and pictures each ask | |
| 3 | * `asks.ts` finds, and `decisionForm` / `decisionButtons` draw what a person | |
| 4 | * can do about it. Every button posts to the route a person could have | |
| 5 | * posted to by hand (`actions.ts`); the asks themselves — which there are, | |
| 6 | * how they score, how they count — stay in `asks.ts`. | |
| 7 | */ | |
| 8 | ||
| 9 | import { previewEnv } from "../../apps/data.ts"; | |
| 10 | import { appsForRepos } from "../../core/apps.ts"; | |
| 11 | import { issueTitles } from "../../core/proposals.ts"; | |
| 12 | import { looksForApps, lookUrl } from "../../core/looks.ts"; | |
| 13 | import type { Pull } from "../../core/pulls.ts"; | |
| 14 | import type { Repo } from "../../core/repos.ts"; | |
| 15 | import { handoverLines } from "../../crew/guard.ts"; | |
| 16 | import type { Ctx } from "../../http/context.ts"; | |
| 17 | import { repoBase } from "../chrome.ts"; | |
| 18 | import { html, type Html } from "../html.ts"; | |
| 19 | import { btn } from "../ui.ts"; | |
| 20 | import { thumbLook } from "../pages/looks.ts"; | |
| 21 | import { changeHref } from "./nouns.ts"; | |
| 22 | import { testsClause } from "./words.ts"; | |
| 23 | import { reviewWhy, scoredFor, waitingOn, type Decision, type Scored } from "./asks.ts"; | |
| 24 | ||
| 25 | /** Dollars as a person reads them: cents when small, whole when not. */ | |
| 26 | const dollars = (n: number): string => (n < 10 ? n.toFixed(2) : n.toFixed(0)); | |
| 27 | ||
| 28 | /** | |
| 29 | * The decisions waiting on the viewer, worded and pictured. A change's own | |
| 30 | * page passes `evenDismissed`: setting an ask aside quiets the lists, never | |
| 31 | * the decision on the thing itself. | |
| 32 | */ | |
| 33 | export function decisionsFor( | |
| 34 | ctx: Ctx, | |
| 35 | allRepos: readonly Repo[], | |
| 36 | options: { evenDismissed?: boolean } = {}, | |
| 37 | ): Decision[] { | |
| 38 | const db = ctx.app.db; | |
| 39 | const candidates = options.evenDismissed | |
| 40 | ? scoredFor(db, ctx.auth.user, allRepos) | |
| 41 | : waitingOn(db, ctx.auth.user, allRepos); | |
| 42 | // The pictures, in one read: a green pull's row leads with its preview. | |
| 43 | const repoIds = [...new Set(candidates.map((c) => c.repo.id))]; | |
| 44 | const records = appsForRepos(db, repoIds); | |
| 45 | const looks = looksForApps( | |
| 46 | db, | |
| 47 | [...records.values()].map((r) => r.id), | |
| 48 | ); | |
| 49 | const pictureOf = (repo: Repo, pull: Pull): string | undefined => { | |
| 50 | const record = records.get(repo.id); | |
| 51 | if (record === undefined) return undefined; | |
| 52 | const env = previewEnv(pull.number); | |
| 53 | const look = thumbLook( | |
| 54 | ctx, | |
| 55 | repo, | |
| 56 | record, | |
| 57 | looks.filter((l) => l.appId === record.id && l.env === env), | |
| 58 | ); | |
| 59 | return ( | |
| 60 | look && lookUrl(repoBase(repo), look) | |
| 61 | ); | |
| 62 | }; | |
| 63 | const worded = (c: Scored): Omit<Decision, "consequence" | "waiting"> => { | |
| 64 | if (c.kind === "assigned") { | |
| 65 | const thing = c.pull ?? c.issue!; | |
| 66 | return { | |
| 67 | kind: "assigned", | |
| 68 | id: `assigned:${thing.id}`, | |
| 69 | repo: c.repo, | |
| 70 | ...(c.pull === undefined ? { issue: c.issue } : { pull: c.pull }), | |
| 71 | who: c.who, | |
| 72 | says: `"${thing.title}" is assigned to you.`, | |
| 73 | short: `assigned to you · updated ${thing.updatedAt.slice(0, 10)}`, | |
| 74 | }; | |
| 75 | } | |
| 76 | if (c.kind === "proposal" && c.proposal) | |
| 77 | return { | |
| 78 | kind: "proposal", | |
| 79 | id: `proposal:${c.proposal.id}`, | |
| 80 | repo: c.repo, | |
| 81 | proposal: c.proposal, | |
| 82 | who: c.who, | |
| 83 | says: `${c.who} proposes "${c.proposal.title}" (${issueTitles(c.proposal).length} issues). Approve opens them, Redirect hands your words to the planner, Later puts it aside.`, | |
| 84 | short: `proposes "${c.proposal.title}"`, | |
| 85 | }; | |
| 86 | if (c.kind === "parked" && c.issue) | |
| 87 | return { | |
| 88 | kind: "parked", | |
| 89 | id: `parked:${c.issue.id}`, | |
| 90 | repo: c.repo, | |
| 91 | issue: c.issue, | |
| 92 | who: c.who, | |
| 93 | says: `Three runs on #${c.issue.number} failed or were declined within an hour, so the crew parked it. Say what to try and it starts again.`, | |
| 94 | short: `#${c.issue.number} parked after three failed runs`, | |
| 95 | }; | |
| 96 | if (c.kind === "declined" && c.issue && c.decline) | |
| 97 | return { | |
| 98 | kind: "declined", | |
| 99 | id: `declined:${c.decline.runId}`, | |
| 100 | repo: c.repo, | |
| 101 | issue: c.issue, | |
| 102 | who: c.who, | |
| 103 | says: `The planner declined the direction: \u201c${c.decline.words}\u201d. It plans nothing more until you answer on #${c.issue.number}.`, | |
| 104 | short: `the planner declined the direction: \u201c${c.decline.words}\u201d`, | |
| 105 | }; | |
| 106 | if (c.kind === "handover" && c.pull && c.handover) | |
| 107 | return { | |
| 108 | kind: "handover", | |
| 109 | id: `handover:${c.pull.id}`, | |
| 110 | repo: c.repo, | |
| 111 | pull: c.pull, | |
| 112 | who: c.who, | |
| 113 | says: `The reviewer asked for changes three times with no approval between, so the crew stopped. ${handoverLines(c.handover).join(" ")} Say what to try (or approve it on its page), or close it.`, | |
| 114 | short: `"${c.pull.title}" had three reviews asking for changes`, | |
| 115 | why: c.why, | |
| 116 | recommendation: c.recommendation, | |
| 117 | }; | |
| 118 | if (c.kind === "waiting" && c.pull) | |
| 119 | return { | |
| 120 | kind: "waiting", | |
| 121 | id: `waiting:${c.pull.id}`, | |
| 122 | repo: c.repo, | |
| 123 | pull: c.pull, | |
| 124 | who: c.who, | |
| 125 | says: `"${c.pull.title}" is ${c.why ?? "waiting"}, and no person has acted on it. Ship it, say what to change, or close it.`, | |
| 126 | short: c.why ?? "waiting for a person", | |
| 127 | why: c.why, | |
| 128 | recommendation: c.recommendation, | |
| 129 | }; | |
| 130 | if (c.kind === "stopped" && c.pull) { | |
| 131 | const tries = c.tries ?? 0; | |
| 132 | const stopped = c.stoppedByDecider ?? false; | |
| 133 | return { | |
| 134 | kind: "stopped", | |
| 135 | id: `stopped:${c.pull.id}`, | |
| 136 | repo: c.repo, | |
| 137 | pull: c.pull, | |
| 138 | who: c.who, | |
| 139 | says: stopped | |
| 140 | ? `${c.who}'s check failed and the crew's decider stopped rather than spend another run. Say what to try, or close it.` | |
| 141 | : `${c.who} tried ${tries + 1} times and the check still fails. The crew stopped here. Say what to try, or close it.`, | |
| 142 | short: stopped | |
| 143 | ? `the check failed; the decider stopped for you` | |
| 144 | : `${c.who} tried ${tries + 1} times; the check still fails`, | |
| 145 | }; | |
| 146 | } | |
| 147 | if (c.kind === "review" && c.pull) | |
| 148 | return { | |
| 149 | kind: "review", | |
| 150 | id: `review:${c.pull.id}`, | |
| 151 | repo: c.repo, | |
| 152 | pull: c.pull, | |
| 153 | who: c.who, | |
| 154 | says: `${c.who}'s "${c.pull.title}" is green and waits for a review: ${reviewWhy(c.reviewWait)}. An agent's change never ships unreviewed; ship it, or say what is off.`, | |
| 155 | short: `green; waits for a review — ${reviewWhy(c.reviewWait)}`, | |
| 156 | }; | |
| 157 | if (c.kind === "look" && c.pull) { | |
| 158 | const picture = pictureOf(c.repo, c.pull); | |
| 159 | const clause = testsClause(c.check ?? null); | |
| 160 | // The crew's own words say who finished it; a person's own change | |
| 161 | // gets the wording that is true of it — nobody "finished" it for | |
| 162 | // them, it is simply green and waiting. | |
| 163 | return { | |
| 164 | kind: "look", | |
| 165 | id: `look:${c.pull.id}`, | |
| 166 | repo: c.repo, | |
| 167 | pull: c.pull, | |
| 168 | who: c.who, | |
| 169 | says: c.authorIsAgent | |
| 170 | ? `${c.who} finished "${c.pull.title}" and the check is green${clause === "" ? "" : ` (${clause})`}. Look at the preview, then ship it or say what is off.` | |
| 171 | : `"${c.pull.title}" is green — ${clause === "" ? "" : `${clause}, `}ready for a look. Ship it, or say what is off.`, | |
| 172 | short: c.authorIsAgent | |
| 173 | ? `${c.who} finished it; the check is green${clause === "" ? "" : ` (${clause})`}` | |
| 174 | : `green — ${clause === "" ? "" : `${clause}, `}ready for a look`, | |
| 175 | ...(picture === undefined ? {} : { picture }), | |
| 176 | }; | |
| 177 | } | |
| 178 | return { | |
| 179 | kind: "paused", | |
| 180 | id: `paused:${c.repo.id}`, | |
| 181 | repo: c.repo, | |
| 182 | who: "the crew", | |
| 183 | says: `${c.repo.name} reached its $${dollars(c.repo.autonomyCeilingUsd)} for today. The crew picks nothing more until 00:00 UTC. Raise the ceiling in settings to go on now.`, | |
| 184 | short: `at its $${dollars(c.repo.autonomyCeilingUsd)} ceiling until 00:00 UTC`, | |
| 185 | }; | |
| 186 | }; | |
| 187 | const previewOf = (c: Scored): string | undefined => | |
| 188 | c.pull === undefined || !records.has(c.repo.id) | |
| 189 | ? undefined | |
| 190 | : `${repoBase(c.repo)}/app/pull-${c.pull.number}/open`; | |
| 191 | return candidates.map((c) => ({ | |
| 192 | ...worded(c), | |
| 193 | preview: previewOf(c), | |
| 194 | consequence: c.consequence, | |
| 195 | waiting: c.waiting, | |
| 196 | })); | |
| 197 | } | |
| 198 | ||
| 199 | /** The id of the form a row's own button submits (see `decisionForm`). */ | |
| 200 | const askFormId = (d: Decision): string => `ask-${d.id}`; | |
| 201 | ||
| 202 | /** | |
| 203 | * The form behind a row's landing button — its own post, exactly as it was. | |
| 204 | * It sits after the panel's form, because a form inside a form is not | |
| 205 | * HTML; the button reaches it by id. | |
| 206 | */ | |
| 207 | export function decisionForm(d: Decision, back?: string): Html | null { | |
| 208 | const pull = d.pull; | |
| 209 | const own = html`id="${askFormId(d)}" method="post" hidden`; | |
| 210 | if (d.kind === "parked") | |
| 211 | return html`<form ${own} action="/asks/decide"> | |
| 212 | <input type="hidden" name="ask" value="${d.id}" /> | |
| 213 | </form>`; | |
| 214 | if (d.kind === "proposal" && d.proposal) return proposalForms(d, back); | |
| 215 | if (pull === undefined) return null; | |
| 216 | const base = repoBase(d.repo); | |
| 217 | const where = back === undefined ? null : html`<input type="hidden" name="back" value="${back}" />`; | |
| 218 | if (d.kind === "stopped" || d.kind === "handover") | |
| 219 | return html`<form ${own} action="${base}/pulls/${pull.number}/state"> | |
| 220 | <input type="hidden" name="state" value="closed" />${where} | |
| 221 | </form>`; | |
| 222 | if (d.kind === "look" || d.kind === "review") | |
| 223 | return html`<form ${own} action="${base}/pulls/${pull.number}/ship"> | |
| 224 | <input type="hidden" name="pull" value="${pull.number}" />${where} | |
| 225 | </form>`; | |
| 226 | if (d.kind === "waiting") | |
| 227 | return html`<form ${own} action="${base}/pulls/${pull.number}/ship"> | |
| 228 | <input type="hidden" name="pull" value="${pull.number}" />${where} | |
| 229 | </form> | |
| 230 | <form id="${askFormId(d)}-close" method="post" hidden action="${base}/pulls/${pull.number}/state"> | |
| 231 | <input type="hidden" name="state" value="closed" />${where} | |
| 232 | </form>`; | |
| 233 | return null; | |
| 234 | } | |
| 235 | ||
| 236 | /** | |
| 237 | * The actions on one ask, on one line: a button for what lands (submitting | |
| 238 | * the row's own form, `decisionForm`), links for what needs a look or a | |
| 239 | * word. Saying something to the crew happens on the change's own page, | |
| 240 | * where the conversation is — not in a box in a list. | |
| 241 | */ | |
| 242 | export function decisionActions(ctx: Ctx, d: Decision): Html { | |
| 243 | const { primary, others } = decisionButtons(ctx, d); | |
| 244 | return html`${primary} ${others}`; | |
| 245 | } | |
| 246 | ||
| 247 | /** An ask's actions in two parts: the one that decides, and the rest. */ | |
| 248 | export function decisionButtons(ctx: Ctx, d: Decision): { primary: Html; others: Html[] } { | |
| 249 | const base = repoBase(d.repo); | |
| 250 | const pull = d.pull; | |
| 251 | const preview = d.preview; | |
| 252 | if ((d.kind === "stopped" || d.kind === "handover") && pull) | |
| 253 | return { | |
| 254 | primary: btn("Tell them", { | |
| 255 | href: `${changeHref(base, pull.number)}#comment-body`, | |
| 256 | size: "sm", | |
| 257 | variant: "primary", | |
| 258 | }), | |
| 259 | others: [ | |
| 260 | btn("Close", { size: "sm", form: askFormId(d) }), | |
| 261 | btn("See", { href: changeHref(base, pull.number), size: "sm" }), | |
| 262 | ], | |
| 263 | }; | |
| 264 | if ((d.kind === "look" || d.kind === "review") && pull) | |
| 265 | return { | |
| 266 | primary: btn("Ship", { size: "sm", form: askFormId(d), variant: "primary" }), | |
| 267 | others: [ | |
| 268 | ...(preview === undefined ? [] : [btn("Preview", { href: preview, size: "sm" })]), | |
| 269 | btn("Not like this", { | |
| 270 | href: `${changeHref(base, pull.number)}#comment-body`, | |
| 271 | size: "sm", | |
| 272 | }), | |
| 273 | ], | |
| 274 | }; | |
| 275 | if (d.kind === "waiting" && pull) | |
| 276 | return { | |
| 277 | primary: btn("Ship", { size: "sm", form: askFormId(d), variant: "primary" }), | |
| 278 | others: [ | |
| 279 | btn("Say what to change", { | |
| 280 | href: `${changeHref(base, pull.number)}#comment-body`, | |
| 281 | size: "sm", | |
| 282 | }), | |
| 283 | btn("Close", { size: "sm", form: `${askFormId(d)}-close` }), | |
| 284 | ], | |
| 285 | }; | |
| 286 | if (d.kind === "assigned" && (d.pull ?? d.issue)) | |
| 287 | return { | |
| 288 | primary: btn("Open", { | |
| 289 | href: pull ? changeHref(base, pull.number) : `${base}/issues/${d.issue!.number}`, | |
| 290 | size: "sm", | |
| 291 | variant: "primary", | |
| 292 | }), | |
| 293 | others: [], | |
| 294 | }; | |
| 295 | if (d.kind === "proposal" && d.proposal) | |
| 296 | return { | |
| 297 | primary: btn("Approve", { size: "sm", form: askFormId(d), variant: "primary" }), | |
| 298 | others: [btn("Later", { size: "sm", form: `${askFormId(d)}-later` })], | |
| 299 | }; | |
| 300 | if (d.kind === "declined" && d.issue) | |
| 301 | return { | |
| 302 | primary: btn("Answer", { | |
| 303 | href: `${base}/issues/${d.issue.number}#comment-body`, | |
| 304 | size: "sm", | |
| 305 | variant: "primary", | |
| 306 | }), | |
| 307 | others: [], | |
| 308 | }; | |
| 309 | if (d.kind === "parked" && d.issue) | |
| 310 | return { | |
| 311 | primary: btn("Tell them", { | |
| 312 | href: `${base}/issues/${d.issue.number}#comment-body`, | |
| 313 | size: "sm", | |
| 314 | variant: "primary", | |
| 315 | }), | |
| 316 | // Only where a decider is there to answer. | |
| 317 | others: | |
| 318 | ctx.app.config.decider === undefined | |
| 319 | ? [] | |
| 320 | : [btn("Let the decider", { size: "sm", form: askFormId(d) })], | |
| 321 | }; | |
| 322 | return { | |
| 323 | primary: btn("Settings", { href: `${base}/settings/autonomy`, size: "sm" }), | |
| 324 | others: [], | |
| 325 | }; | |
| 326 | } | |
| 327 | ||
| 328 | /** | |
| 329 | * The forms behind a proposal card: Approve, Later and Redirect, each one | |
| 330 | * POST to `/asks/proposal/:id/<verb>` that lands back on the page it came | |
| 331 | * from. They sit apart from the card's own form, as forms do not nest. | |
| 332 | */ | |
| 333 | function proposalForms(d: Decision, back?: string): Html { | |
| 334 | const id = askFormId(d); | |
| 335 | const post = (verb: string) => `/asks/proposal/${d.proposal!.id}/${verb}`; | |
| 336 | const where = back === undefined ? null : html`<input type="hidden" name="back" value="${back}" />`; | |
| 337 | return html`<form id="${id}" method="post" action="${post("approve")}" hidden>${where}</form> | |
| 338 | <form id="${id}-later" method="post" action="${post("later")}" hidden>${where}</form>`; | |
| 339 | } |
test/asks.test.ts +1 −1
| @@ -21,7 +21,7 @@ import { getUserByName } from "../src/core/users.ts"; | ||
| 21 | 21 | import type { Ctx } from "../src/http/context.ts"; |
| 22 | 22 | import { serve, type Servers } from "../src/http/server.ts"; |
| 23 | 23 | import { setCapacity, storedCapacity } from "../src/core/capacity.ts"; |
| 24 | import { decisionsFor } from "../src/web/studio/asks.ts"; | |
| 24 | import { decisionsFor } from "../src/web/studio/decisions.ts"; | |
| 25 | 25 | import { quietLogs } from "./helpers/globals.ts"; |
| 26 | 26 | import { adminCookie } from "./helpers/admin.ts"; |
| 27 | 27 |
test/crew-loop.test.ts +2 −1
| @@ -28,7 +28,8 @@ import { startCrew, queueAgentRun, type CrewHandle } from "../src/crew/dispatch. | ||
| 28 | 28 | import { getAgent } from "../src/core/agents.ts"; |
| 29 | 29 | import type { Ctx } from "../src/http/context.ts"; |
| 30 | 30 | import { setIssueState } from "../src/actions/issues.ts"; |
| 31 | import { ASK_WORDS, KIND_TIER, askLinesFor, decisionActions, decisionForm, decisionsFor, endOf } from "../src/web/studio/asks.ts"; | |
| 31 | import { ASK_WORDS, KIND_TIER, askLinesFor, endOf } from "../src/web/studio/asks.ts"; | |
| 32 | import { decisionActions, decisionForm, decisionsFor } from "../src/web/studio/decisions.ts"; | |
| 32 | 33 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 33 | 34 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| 34 | 35 | import { settleApp } from "./helpers/tui.ts"; |
new above
offline