Public: anyone can read this; the crew can change it.
On a new forge with included credit, the first ask builds: today it says "Received" and nobody ever takes it #11314
mason/forge:mason/11278-on-a-new-forge-with-included-credit-the → main 6 commits fork
8 files
changed +112
−8
docs/features/starter-crew.md +4
| @@ -9,3 +9,7 @@ A hosted forge is made with a crew: a `builder` and a `reviewer`, seated on ever | ||
| 9 | 9 | **Included credit** is the on-ramp. When no key was handed over, the host lends the new forge `spawn.included_credit_usd` dollars (default 2, once; 0 turns it off) through the child credit (`src/spawn/included_credit.ts`). The crew runs on the host's model door up to that amount; past it the door answers 402 and the forge says: add your own key to keep building, or wait for next month. The forge never holds the host's key, only a capped bearer. Settings → Limits shows the worst case a day: new accounts an hour × 24 × forges a person may own × the credit. |
| 10 | 10 | |
| 11 | 11 | Try: open `/` on a new forge, paste a key, write one ask. |
| 12 | ||
| 13 | ## The first ask (#11278) | |
| 14 | ||
| 15 | On a new forge, "What do you want built?" posts to `/tell` with the target `new-app` (`src/actions/first_ask.ts`). It makes a new app under the forge's organisation, named from the ask, which the starter crew seats and sets autonomous on creation, then tells the ask there, so the builder takes it. The receipt says which app and who is on it, or what is missing (nobody on the crew; no key or credit). The forge's own code is never the target. The terminal's `t` does the same. |
src/actions/first_ask.ts added +53
| @@ -0,0 +1,53 @@ | ||
| 1 | /** | |
| 2 | * The first ask on a new forge (#11278): "What do you want built?" makes a new | |
| 3 | * app under the forge's organisation, named from the ask, and tells it there. | |
| 4 | * The organisation carries the starter crew (`spawn/starter_crew.ts`), so the | |
| 5 | * app is seated and autonomous the moment it exists and the tell is routed to | |
| 6 | * its builder. The forge's own code is never the target of this box. | |
| 7 | */ | |
| 8 | ||
| 9 | import type { App } from "../app.ts"; | |
| 10 | import { crewHasCredential } from "../core/subscriptions.ts"; | |
| 11 | import type { Repo } from "../core/repos.ts"; | |
| 12 | import type { User } from "../core/users.ts"; | |
| 13 | import { spawnedOrg } from "../spawn/claim.ts"; | |
| 14 | import { NEW_APP_ERRORS, NO_NAME_ERROR, newAppFromSentence } from "./apps.ts"; | |
| 15 | import { tell, toldWords, type Told } from "./tell.ts"; | |
| 16 | ||
| 17 | /** The composer field value that means "a new app, from these words". */ | |
| 18 | export const NEW_APP_TARGET = "new-app"; | |
| 19 | ||
| 20 | export type FirstAsk = | |
| 21 | | { readonly ok: true; readonly repo: Repo; readonly told: Told; readonly words: string } | |
| 22 | | { readonly ok: false; readonly words: string }; | |
| 23 | ||
| 24 | /** What the page says once the ask is placed: who took it, or exactly what is missing. */ | |
| 25 | export function firstAskWords(app: App, repo: Repo, told: Told): string { | |
| 26 | const base = `${repo.name}: ${toldWords(told)}`; | |
| 27 | return told.assigned && !crewHasCredential(app.db) | |
| 28 | ? `${base} Nothing will run until the crew has a model key or included credit.` | |
| 29 | : base; | |
| 30 | } | |
| 31 | ||
| 32 | export async function firstAsk(app: App, user: User, text: string): Promise<FirstAsk> { | |
| 33 | const said = text.trim(); | |
| 34 | if (said === "") return { ok: false, words: "Say what you want built." }; | |
| 35 | const spawned = await spawnedOrg(app); | |
| 36 | if (spawned === undefined) return { ok: false, words: "This forge has no organisation to make an app in." }; | |
| 37 | // The tell below is the first issue; the repository description stays the words, cut to a line. | |
| 38 | const made = await newAppFromSentence(app, user, { | |
| 39 | sentence: said.slice(0, 200), | |
| 40 | description: "", | |
| 41 | owner: spawned.org.username, | |
| 42 | }); | |
| 43 | if (!made.ok) | |
| 44 | return { | |
| 45 | ok: false, | |
| 46 | words: made.code === "no_name" ? NO_NAME_ERROR : (NEW_APP_ERRORS[made.code] ?? "That app could not be made."), | |
| 47 | }; | |
| 48 | const told = await tell(app, user, made.repo, said); | |
| 49 | if (!told.ok) | |
| 50 | return { ok: false, words: `${made.repo.name} was made, but the ask could not be placed on it (${told.error}).` }; | |
| 51 | return { ok: true, repo: made.repo, told: told.value, words: firstAskWords(app, made.repo, told.value) }; | |
| 52 | } | |
| 53 |
src/tui/screens/dashboard.ts +5 −4
| @@ -25,7 +25,7 @@ import { coveredByVerdict, forgeVerdict, verdictLine } from "../../kernel/guard_ | ||
| 25 | 25 | import { clientAppRows, clientDoings, clientFinished, doingLine, finishedLine } from "../../core/client-apps.ts"; |
| 26 | 26 | import { appCrew } from "../../core/app-crew.ts"; |
| 27 | 27 | import { nextStepsFor } from "../../core/next-steps.ts"; |
| 28 | import { keepThought } from "../../actions/thought.ts"; | |
| 28 | import { firstAsk } from "../../actions/first_ask.ts"; | |
| 29 | 29 | import { SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts"; |
| 30 | 30 | import { crewFirstText } from "../../web/studio/crew_key.ts"; |
| 31 | 31 | import { agentsLine } from "../../web/studio/client_home.ts"; |
| @@ -1293,9 +1293,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 1293 | 1293 | hint: "enter sends", |
| 1294 | 1294 | onSubmit: (said) => { |
| 1295 | 1295 | if (said.trim() === "") return SAY_SOMETHING_WORDS; |
| 1296 | const kept = keepThought(f.app, f.user, said, "composer"); | |
| 1297 | ctx.toast(kept.ok ? "Received." : "That could not be kept.", kept.ok ? "success" : "danger"); | |
| 1298 | if (kept.ok) void loadClientLines().then(reload); | |
| 1296 | void firstAsk(f.app, f.user!, said).then((made) => { | |
| 1297 | ctx.toast(made.words, made.ok ? "success" : "danger"); | |
| 1298 | if (made.ok) void loadClientLines().then(reload); | |
| 1299 | }); | |
| 1299 | 1300 | return undefined; |
| 1300 | 1301 | }, |
| 1301 | 1302 | }), |
src/web/pages/new-forge.ts +1 −1
| @@ -201,7 +201,7 @@ function formView( | ||
| 201 | 201 | // /forges answers only an admin; to anyone else the link would lead to a 404. |
| 202 | 202 | actions: ctx.auth.user?.isAdmin ? sentLink() : undefined, |
| 203 | 203 | })} |
| 204 | <p class="muted small" id="hosting-terms">Free within limits: it sleeps when idle, and its crew starts once you add your AI account.</p> | |
| 204 | <p class="muted small" id="hosting-terms">Free within limits: it sleeps when idle, and its crew starts on the included credit, or on your own AI account key if you add one.</p> | |
| 205 | 205 | ${quota ? html`<p role="status" id="quota-full">This forge has no room for another forge: ${quota}.</p>` : null} |
| 206 | 206 | ${errors["form"] |
| 207 | 207 | ? html`<p class="error mb" role="alert">${errors["form"]}</p>` |
src/web/pages/next-steps.ts +2 −2
| @@ -27,7 +27,7 @@ import { tellHref } from "../studio/nouns.ts"; | ||
| 27 | 27 | import { everydayAsk } from "./everyday.ts"; |
| 28 | 28 | import { EVERYDAY_WHY } from "../../core/everyday.ts"; |
| 29 | 29 | import { crewFirstLine } from "../studio/crew_key.ts"; |
| 30 | import { FORGE_TARGET } from "../studio/feed.ts"; | |
| 30 | import { NEW_APP_TARGET } from "../../actions/first_ask.ts"; | |
| 31 | 31 | import { COMPOSER_FIELDS, TELL_MAX } from "../share_target.ts"; |
| 32 | 32 | |
| 33 | 33 | /** One line per app: the app is the row's title, the crew member and what they are doing its meta. */ |
| @@ -67,7 +67,7 @@ function firstTell(ctx: Ctx, user: User, crew: Html[]): Html { | ||
| 67 | 67 | return html`<section id="next-steps" data-first-tell> |
| 68 | 68 | <h2>What do you want built?</h2> |
| 69 | 69 | <form id="composer" class="stack" method="post" action="/tell"> |
| 70 | <input type="hidden" name="${COMPOSER_FIELDS.app}" value="${FORGE_TARGET}" /> | |
| 70 | <input type="hidden" name="${COMPOSER_FIELDS.app}" value="${NEW_APP_TARGET}" /> | |
| 71 | 71 | <textarea class="input" name="${COMPOSER_FIELDS.text}" rows="3" maxlength="${String(TELL_MAX)}" required placeholder="A weekly menu page for the bakery" aria-label="Your request" data-draft="${user.id}"></textarea> |
| 72 | 72 | <div class="bar">${btn("Tell the crew", { variant: "primary" })}</div> |
| 73 | 73 | </form> |
src/web/studio/actions.ts +13
| @@ -17,6 +17,7 @@ import { SENT_WORDS, tell, toldWords, TOO_LONG_WORDS } from "../../actions/tell. | ||
| 17 | 17 | import { contextNote, parseContext } from "../../actions/tell_context.ts"; |
| 18 | 18 | import { NOT_TOLD_FROM_WORDS, NOT_TOLD_WORDS, SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts"; |
| 19 | 19 | import { keepThought } from "../../actions/thought.ts"; |
| 20 | import { firstAsk, NEW_APP_TARGET } from "../../actions/first_ask.ts"; | |
| 20 | 21 | import { DIRECTION_NOTE } from "../../crew/direct.ts"; |
| 21 | 22 | import { mergePull } from "../../actions/pulls.ts"; |
| 22 | 23 | import { revertPull } from "../../actions/revert.ts"; |
| @@ -219,6 +220,18 @@ export async function composerSubmit(ctx: Ctx): Promise<Response> { | ||
| 219 | 220 | |
| 220 | 221 | async function composerTell(ctx: Ctx, form: Form, target: string, home: string, onTold: () => void): Promise<Response> { |
| 221 | 222 | if (!ctx.auth.user) return signInFirst(ctx); |
| 223 | // The first ask on a new forge: a new app, named from the words, and the ask told there (#11278). | |
| 224 | if (target === NEW_APP_TARGET) { | |
| 225 | const made = await firstAsk(ctx.app, ctx.auth.user, field(form, COMPOSER_FIELDS.text)); | |
| 226 | if (!made.ok) return flashOrJson(ctx, home, { tone: "danger", message: made.words }, { href: home }); | |
| 227 | onTold(); | |
| 228 | return flashOrJson( | |
| 229 | ctx, | |
| 230 | home, | |
| 231 | { message: made.words, link: { href: `/${made.repo.ownerName}/${made.repo.name}`, label: "open it" } }, | |
| 232 | { href: home }, | |
| 233 | ); | |
| 234 | } | |
| 222 | 235 | // "the forge" is no app: the words are kept as a thought, exactly as typed. |
| 223 | 236 | if (target === FORGE_TARGET) { |
| 224 | 237 | if (field(form, COMPOSER_FIELDS.text).trim() === "") |
test/starter-crew.test.ts +28
| @@ -10,6 +10,8 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 10 | 10 | import { tmpdir } from "node:os"; |
| 11 | 11 | import { join } from "node:path"; |
| 12 | 12 | import { createRepo } from "../src/actions/repos.ts"; |
| 13 | import { firstAsk } from "../src/actions/first_ask.ts"; | |
| 14 | import { listIssues } from "../src/core/issues.ts"; | |
| 13 | 15 | import { childDirOf } from "../src/actions/spawn.ts"; |
| 14 | 16 | import { createApp, type App } from "../src/app.ts"; |
| 15 | 17 | import { createAgentRow, listAgents, listCrewRoles } from "../src/core/agents.ts"; |
| @@ -126,6 +128,32 @@ describe("a new forge's starter crew", () => { | ||
| 126 | 128 | expect(getRepo(child.db, "maria", "second")!.autonomy).toBe("autonomous"); |
| 127 | 129 | }); |
| 128 | 130 | |
| 131 | test("the first ask makes a new app, named from it, and hands it to the builder (#11278)", async () => { | |
| 132 | const owners = listTeams(child.db, getUserByName(child.db, "maria")!.id).find((t) => t.name === OWNERS_TEAM)!; | |
| 133 | const founder = listTeamMembers(child.db, owners.id)[0]!; | |
| 134 | const before = child.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM repo").get()!.n; | |
| 135 | const made = await firstAsk(child, founder, "A page that says hello and shows today's date."); | |
| 136 | if (!made.ok) throw new Error(made.words); | |
| 137 | expect(child.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM repo").get()!.n).toBe(before + 1); | |
| 138 | expect(made.repo.ownerName).toBe("maria"); | |
| 139 | expect(made.repo.name).not.toBe(FORGE_CODE_NAME); | |
| 140 | expect(made.repo.name).toBe("page-says"); | |
| 141 | expect(made.told.assigned).toBe(true); | |
| 142 | expect(made.words).toContain("builder is on it"); | |
| 143 | expect(made.words).toContain(made.repo.name); | |
| 144 | const issues = listIssues(child.db, made.repo.id, {}); | |
| 145 | expect(issues.length).toBe(1); | |
| 146 | expect(issues[0]!.assigneeId).toBe(getUserByName(child.db, "builder")!.id); | |
| 147 | expect(getRepo(child.db, "maria", made.repo.name)!.autonomy).toBe("autonomous"); | |
| 148 | }); | |
| 149 | ||
| 150 | test("an ask with nothing to name an app from is refused and makes nothing", async () => { | |
| 151 | const owners = listTeams(child.db, getUserByName(child.db, "maria")!.id).find((t) => t.name === OWNERS_TEAM)!; | |
| 152 | const founder = listTeamMembers(child.db, owners.id)[0]!; | |
| 153 | const refused = await firstAsk(child, founder, "!!! ???"); | |
| 154 | expect(refused.ok).toBe(false); | |
| 155 | }); | |
| 156 | ||
| 129 | 157 | test("a forge brought its own key is lent nothing; 0 turns the credit off", async () => { |
| 130 | 158 | setLimit(parent.db, "spawn.included_credit_usd", 0, parent.db.query<{ id: string }, []>("SELECT id FROM user LIMIT 1").get()!.id); |
| 131 | 159 | await spawn("nolend"); |
test/tui-first-tell.test.ts +6 −1
| @@ -38,10 +38,15 @@ test("before the first tell the home says what to do and offers no everyday acco | ||
| 38 | 38 | expect(h.text()).toContain("included credit."); |
| 39 | 39 | expect(h.text()).not.toContain("K keeps using admin"); |
| 40 | 40 | |
| 41 | const repos = () => forge.child.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM repo").get()!.n; | |
| 42 | const before = repos(); | |
| 41 | 43 | await h.key("t"); |
| 42 | 44 | for (const ch of "A weekly menu page") await h.key(ch); |
| 43 | 45 | await h.key("enter"); |
| 44 | expect(forge.child.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM thought").get()!.n).toBe(1); | |
| 46 | // The first ask makes a new app (#11278), asynchronously; no thought is kept. | |
| 47 | for (let i = 0; i < 100 && repos() === before; i++) await Bun.sleep(50); | |
| 48 | expect(repos()).toBe(before + 1); | |
| 49 | expect(forge.child.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM thought").get()!.n).toBe(0); | |
| 45 | 50 | h.app.stop(); |
| 46 | 51 | |
| 47 | 52 | // Once the crew has made an issue of it, the home is the everyday one and offers the account. |
new above
offline