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 #11280

Parked opened this in answer to
Closed without merging

mason/forge:mason/11278-on-a-new-forge-with-included-credit-the → main 3 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
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
99 **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.
1010
1111 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_
2525 import { clientAppRows, clientDoings, clientFinished, doingLine, finishedLine } from "../../core/client-apps.ts";
2626 import { appCrew } from "../../core/app-crew.ts";
2727 import { nextStepsFor } from "../../core/next-steps.ts";
28 import { keepThought } from "../../actions/thought.ts";
28 import { firstAsk } from "../../actions/first_ask.ts";
2929 import { SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts";
3030 import { crewNote } from "../../web/studio/crew_key.ts";
3131 import { agentsLine } from "../../web/studio/client_home.ts";
@@ -1293,9 +1293,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
12931293 hint: "enter sends",
12941294 onSubmit: (said) => {
12951295 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 });
12991300 return undefined;
13001301 },
13011302 }),
src/web/pages/new-forge.ts +1 −1
@@ -192,7 +192,7 @@ function formView(
192192 : "Pick a name and the apps to start from; you get one link to send.",
193193 actions: btn("Forges you sent", { href: "/forges", size: "sm" }),
194194 })}
195 <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>
195 <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>
196196 ${quota ? html`<p role="status" id="quota-full">This forge has no room for another forge: ${quota}.</p>` : null}
197197 ${errors["form"]
198198 ? html`<p class="error mb" role="alert">${errors["form"]}</p>`
src/web/pages/next-steps.ts +2 −2
@@ -28,7 +28,7 @@ import { everydayAsk } from "./everyday.ts";
2828 import { EVERYDAY_WHY } from "../../core/everyday.ts";
2929 import { crewNote } from "../studio/crew_key.ts";
3030 import { crewHasCredential } from "../../core/subscriptions.ts";
31 import { FORGE_TARGET } from "../studio/feed.ts";
31 import { NEW_APP_TARGET } from "../../actions/first_ask.ts";
3232 import { COMPOSER_FIELDS, TELL_MAX } from "../share_target.ts";
3333
3434 /** One line per app: the app is the row's title, the crew member and what they are doing its meta. */
@@ -68,7 +68,7 @@ function firstTell(ctx: Ctx, user: User, crew: Html[]): Html {
6868 return html`<section id="next-steps" data-first-tell>
6969 <h2>What do you want built?</h2>
7070 <form id="composer" class="stack" method="post" action="/tell">
71 <input type="hidden" name="${COMPOSER_FIELDS.app}" value="${FORGE_TARGET}" />
71 <input type="hidden" name="${COMPOSER_FIELDS.app}" value="${NEW_APP_TARGET}" />
7272 <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>
7373 <div class="bar">${btn("Tell the crew", { variant: "primary" })}</div>
7474 </form>
src/web/studio/actions.ts +13
@@ -17,6 +17,7 @@ import { SENT_WORDS, tell, toldWords, TOO_LONG_WORDS } from "../../actions/tell.
1717 import { contextNote, parseContext } from "../../actions/tell_context.ts";
1818 import { NOT_TOLD_FROM_WORDS, NOT_TOLD_WORDS, SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts";
1919 import { keepThought } from "../../actions/thought.ts";
20 import { firstAsk, NEW_APP_TARGET } from "../../actions/first_ask.ts";
2021 import { DIRECTION_NOTE } from "../../crew/direct.ts";
2122 import { mergePull } from "../../actions/pulls.ts";
2223 import { revertPull } from "../../actions/revert.ts";
@@ -207,6 +208,18 @@ export async function composerSubmit(ctx: Ctx): Promise<Response> {
207208
208209 async function composerTell(ctx: Ctx, form: Form, target: string, home: string, onTold: () => void): Promise<Response> {
209210 if (!ctx.auth.user) return signInFirst(ctx);
211 // The first ask on a new forge: a new app, named from the words, and the ask told there (#11278).
212 if (target === NEW_APP_TARGET) {
213 const made = await firstAsk(ctx.app, ctx.auth.user, field(form, COMPOSER_FIELDS.text));
214 if (!made.ok) return flashOrJson(ctx, home, { tone: "danger", message: made.words }, { href: home });
215 onTold();
216 return flashOrJson(
217 ctx,
218 home,
219 { message: made.words, link: { href: `/${made.repo.ownerName}/${made.repo.name}`, label: "open it" } },
220 { href: home },
221 );
222 }
210223 // "the forge" is no app: the words are kept as a thought, exactly as typed.
211224 if (target === FORGE_TARGET) {
212225 if (field(form, COMPOSER_FIELDS.text).trim() === "")
test/starter-crew.test.ts +28
@@ -10,6 +10,8 @@ import { mkdtemp, rm } from "node:fs/promises";
1010 import { tmpdir } from "node:os";
1111 import { join } from "node:path";
1212 import { createRepo } from "../src/actions/repos.ts";
13 import { firstAsk } from "../src/actions/first_ask.ts";
14 import { listIssues } from "../src/core/issues.ts";
1315 import { childDirOf } from "../src/actions/spawn.ts";
1416 import { createApp, type App } from "../src/app.ts";
1517 import { createAgentRow, listAgents, listCrewRoles } from "../src/core/agents.ts";
@@ -126,6 +128,32 @@ describe("a new forge's starter crew", () => {
126128 expect(getRepo(child.db, "maria", "second")!.autonomy).toBe("autonomous");
127129 });
128130
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
129157 test("a forge brought its own key is lent nothing; 0 turns the credit off", async () => {
130158 setLimit(parent.db, "spawn.included_credit_usd", 0, parent.db.query<{ id: string }, []>("SELECT id FROM user LIMIT 1").get()!.id);
131159 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
3838 expect(h.text()).toContain("included credit.");
3939 expect(h.text()).not.toContain("K keeps using admin");
4040
41 const repos = () => forge.child.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM repo").get()!.n;
42 const before = repos();
4143 await h.key("t");
4244 for (const ch of "A weekly menu page") await h.key(ch);
4345 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);
4550 h.app.stop();
4651
4752 // Once the crew has made an issue of it, the home is the everyday one and offers the account.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs