Public: anyone can read this; the crew can change it.

A new forge's first ask makes a new app from the ask and files it there as an issue #11350

Parked opened this
Closed without merging

scout/forge:scout/11342-a-new-forge-s-first-ask-makes-a-new-app → main 5 commits fork 3 threads · 3 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
8 files changed +193 −12
docs/features/starter-crew.md +2
@@ -9,3 +9,5 @@ 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 on a new forge makes a new app named from it and files the ask there as an issue (target `new-app`), startable by a builder when the crew can run.
src/actions/first_ask.ts added +58
@@ -0,0 +1,58 @@
1 /**
2 * The first ask of a new forge (#11342): one sentence makes a new app named
3 * from it, turns the crew loose on it when the crew can run, and files the
4 * sentence there as the app's one issue. The page and the terminal both call
5 * this, so what one door does the other does.
6 */
7
8 import type { App } from "../app.ts";
9 import type { Repo } from "../core/repos.ts";
10 import type { User } from "../core/users.ts";
11 import { err, ok, type Result } from "../kernel/result.ts";
12 import { newAppFromSentence, NEW_APP_ERRORS } from "./apps.ts";
13 import { updateRepoSettings } from "./repos.ts";
14 import { NOT_TOLD_WORDS, SAY_SOMETHING_WORDS } from "./tell_words.ts";
15 import { tell, type TellError, type Told } from "./tell.ts";
16
17 export interface FirstAsk {
18 /** The app made from the ask. */
19 readonly repo: Repo;
20 /** Whether the app's autonomy was turned on; false when the crew cannot run, or when it could not be set. */
21 readonly autonomous: boolean;
22 /** True when the crew could run but autonomy could not be set: the ask is filed on an app a builder will not start by itself. */
23 readonly autonomyFailed: boolean;
24 /** The ask's own tell, refused or told. */
25 readonly told: Result<Told, TellError>;
26 }
27
28 /** What a failed first ask says, in words: the empty sentence, or why no app could be made. */
29 export type FirstAskError = { readonly words: string };
30
31 /** The note a person is given when the app was made and filed but autonomy could not be turned on. */
32 export const AUTONOMY_FAILED_WORDS = "The app is made, but the crew could not be set to start on it by itself. Turn on autonomy in its settings.";
33
34 export async function firstAsk(
35 app: App,
36 actor: User | undefined,
37 said: string,
38 crewCanRun: boolean,
39 from: string | null = null,
40 ): Promise<Result<FirstAsk, FirstAskError>> {
41 const text = said.trim();
42 if (text === "") return err({ words: SAY_SOMETHING_WORDS });
43 // An empty description: the issue the tell files is the one issue of the ask.
44 const made = await newAppFromSentence(app, actor, { sentence: text, description: "" });
45 if (!made.ok) return err({ words: NEW_APP_ERRORS[made.code] ?? NOT_TOLD_WORDS });
46 let repo = made.repo;
47 let autonomous = false;
48 let autonomyFailed = false;
49 if (crewCanRun) {
50 const on = await updateRepoSettings(app, actor, repo, { autonomy: "autonomous" });
51 if (on.ok) {
52 repo = on.value;
53 autonomous = true;
54 } else autonomyFailed = true;
55 }
56 const told = await tell(app, actor, repo, text, 1, from);
57 return ok({ repo, autonomous, autonomyFailed, told });
58 }
src/tui/screens/dashboard.ts +11 −6
@@ -25,13 +25,13 @@ 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 { AUTONOMY_FAILED_WORDS, firstAsk } from "../../actions/first_ask.ts";
2929 import { SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts";
30 import { crewFirstText } from "../../web/studio/crew_key.ts";
30 import { crewCanRun, crewFirstText } from "../../web/studio/crew_key.ts";
3131 import { agentsLine } from "../../web/studio/client_home.ts";
3232 import { lastVisit } from "../../core/home_visit.ts";
3333 import { sinceDigest } from "../../web/studio/since.ts";
34 import { askForSomething } from "./tell.ts";
34 import { askForSomething, tellAnswer } from "./tell.ts";
3535 import { movingLines } from "./moving.ts";
3636 import { pipelineNow } from "../../web/studio/living.ts";
3737 import { askForEveryday, everydayOf, EVERYDAY_WHY, keepAdmin } from "../../core/everyday.ts";
@@ -1292,10 +1292,15 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
12921292 label: "Your request",
12931293 hint: "enter sends",
12941294 onSubmit: (said) => {
1295 const user = f.user;
12951296 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);
1297 void firstAsk(f.app, user, said, crewCanRun(f.app)).then((first) => {
1298 if (!first.ok) return ctx.toast(first.error.words, "danger");
1299 const { repo, told, autonomyFailed } = first.value;
1300 if (!told.ok) return ctx.toast(tellAnswer(told).text, "danger");
1301 ctx.toast(autonomyFailed ? AUTONOMY_FAILED_WORDS : `Made ${repo.name} and filed your ask there.`, autonomyFailed ? "danger" : "success");
1302 void loadClientLines().then(reload);
1303 }).catch(() => ctx.toast("Could not make the app. Try again.", "danger"));
12991304 return undefined;
13001305 },
13011306 }),
src/web/pages/next-steps.ts +2 −2
@@ -27,7 +27,7 @@ import { tellHref } from "../studio/nouns.ts";
2727 import { everydayAsk } from "./everyday.ts";
2828 import { EVERYDAY_WHY } from "../../core/everyday.ts";
2929 import { crewFirstLine } from "../studio/crew_key.ts";
30 import { FORGE_TARGET } from "../studio/feed.ts";
30 import { NEW_APP_TARGET } from "../studio/feed.ts";
3131 import { COMPOSER_FIELDS, TELL_MAX } from "../share_target.ts";
3232
3333 /** 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 {
6767 return html`<section id="next-steps" data-first-tell>
6868 <h2>What do you want built?</h2>
6969 <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}" />
7171 <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>
7272 <div class="bar">${btn("Tell the crew", { variant: "primary" })}</div>
7373 </form>
src/web/studio/actions.ts +25 −2
@@ -34,7 +34,8 @@ import { isLocalPath } from "../flash.ts";
3434 import { html } from "../html.ts";
3535 import { flashOrJson, flashTo, page } from "../layout.ts";
3636 import { crewCanRun, NO_CREDIT_WORDS } from "./crew_key.ts";
37 import { FORGE_TARGET } from "./feed.ts";
37 import { FORGE_TARGET, NEW_APP_TARGET } from "./feed.ts";
38 import { AUTONOMY_FAILED_WORDS, firstAsk } from "../../actions/first_ask.ts";
3839 import { changeHref } from "./nouns.ts";
3940
4041 /** A merge refusal in a person's words. */
@@ -73,7 +74,20 @@ async function tellFrom(
7374 tone: "danger",
7475 message: SAY_SOMETHING_WORDS,
7576 });
76 const told = await tell(ctx.app, ctx.auth.user, repo, text, 1, from);
77 return toldAnswer(ctx, repo, form, back, from, await tell(ctx.app, ctx.auth.user, repo, text, 1, from), onTold);
78 }
79
80 /** The answer to one tell, however it was made: refused as the crew's direction says, or told. */
81 function toldAnswer(
82 ctx: Ctx,
83 repo: Repo,
84 form: Form,
85 back: string,
86 from: string | null,
87 told: Awaited<ReturnType<typeof tell>>,
88 onTold: () => void,
89 note = "",
90 ): Promise<Response> | Response {
7791 if (!told.ok && told.error === "body_too_long")
7892 return flashOrJson(ctx, back, {
7993 tone: "danger",
@@ -98,6 +112,7 @@ async function tellFrom(
98112 const at = { href: `${repoBase(repo)}/issues/${told.value.issue.number}` };
99113 // "Build" never silently does nothing: with no credit the person is told, with the way forward.
100114 if (!crewCanRun(ctx.app)) return flashOrJson(ctx, back, noCreditFlash(ctx), at);
115 if (note !== "") return flashOrJson(ctx, back, { tone: "attn", message: note }, at);
101116 if (routed === undefined)
102117 return flashOrJson(
103118 ctx,
@@ -219,6 +234,14 @@ export async function composerSubmit(ctx: Ctx): Promise<Response> {
219234
220235 async function composerTell(ctx: Ctx, form: Form, target: string, home: string, onTold: () => void): Promise<Response> {
221236 if (!ctx.auth.user) return signInFirst(ctx);
237 // The first ask of a new forge: the same action the terminal calls.
238 if (target === NEW_APP_TARGET) {
239 const from = parseFrom(field(form, "from") || undefined) ?? null;
240 const first = await firstAsk(ctx.app, ctx.auth.user, field(form, COMPOSER_FIELDS.text), crewCanRun(ctx.app), from);
241 if (!first.ok) return flashOrJson(ctx, home, { tone: "danger", message: first.error.words });
242 const { repo, told, autonomyFailed } = first.value;
243 return toldAnswer(ctx, repo, form, repoBase(repo), from, told, onTold, autonomyFailed ? AUTONOMY_FAILED_WORDS : "");
244 }
222245 // "the forge" is no app: the words are kept as a thought, exactly as typed.
223246 if (target === FORGE_TARGET) {
224247 if (field(form, COMPOSER_FIELDS.text).trim() === "")
src/web/studio/feed.ts +2
@@ -187,6 +187,8 @@ export function feedCard(
187187
188188 /** The composer's app value for "the forge": no app, so no slash to collide with one. */
189189 export const FORGE_TARGET = "forge";
190 /** The first-tell form's target: "a new app", made from the ask. */
191 export const NEW_APP_TARGET = "new-app";
190192
191193 /** How many thoughts stand at the top of the feed. */
192194 const THOUGHTS_SHOWN = 3;
test/first-ask-new-app.test.ts added +77
@@ -0,0 +1,77 @@
1 /**
2 * The first ask of a spawned forge (#11342): "What do you want built?" makes
3 * a new app named from the ask and files the ask there as an issue; no
4 * thought is kept on `forge`, and the person lands on the new app.
5 */
6
7 import { afterAll, beforeAll, expect, test } from "bun:test";
8 import { listIssues } from "../src/core/issues.ts";
9 import { listReposOwnedBy } from "../src/core/repos.ts";
10 import { recentThoughts } from "../src/core/thoughts.ts";
11 import { fundingOf, keepFunding } from "../src/spawn/funding.ts";
12 import { crewCanRun } from "../src/web/studio/crew_key.ts";
13 import { getUserByName } from "../src/core/users.ts";
14 import { claimedForge, type ClaimedForge } from "./helpers/claimed-forge.ts";
15 import { quietLogs } from "./helpers/globals.ts";
16
17 quietLogs();
18
19 let forge: ClaimedForge;
20 beforeAll(async () => {
21 forge = await claimedForge("forge-first-ask-");
22 }, 60_000);
23 afterAll(() => forge.stop());
24
25 test("the first-tell form targets a new app, not the forge", async () => {
26 const html = await (await fetch(`${forge.base}/`, { headers: { cookie: forge.owner } })).text();
27 const card = html.slice(html.indexOf("data-first-tell"));
28 expect(card).toContain('value="new-app"');
29 expect(card).not.toContain('value="forge"');
30 });
31
32 test("the first tell makes one app, files one open issue on it, keeps no thought", async () => {
33 const db = forge.child.db;
34 const maria = getUserByName(db, "maria")!;
35 const before = listReposOwnedBy(db, maria.id).length;
36 const ask = "A weekly menu page for the bakery";
37 const res = await forge.post(forge.owner, "/tell", { app: "new-app", text: ask });
38 expect(res.status).toBe(303);
39 const made = listReposOwnedBy(db, maria.id);
40 expect(made.length).toBe(before + 1);
41 const repo = made.find((r) => r.name.includes("menu"))!;
42 expect(repo).toBeDefined();
outdated

{ state: "open" } as never silences the type check. Use the real filter type. This test also never checks autonomy (box 2) or the terminal door.

43 expect(res.headers.get("location")).toContain(`/maria/${repo.name}`);
44 const issues = listIssues(db, repo.id, { state: "open" });
45 expect(issues.length).toBe(1);
46 expect(issues[0]!.body + issues[0]!.title).toContain("weekly menu page");
47 // The forge's included credit lets the crew run: the new app starts autonomous (box 2).
48 expect(crewCanRun(forge.child)).toBe(true);
49 expect(repo.autonomy).toBe("autonomous");
50 expect(recentThoughts(db, maria.id, 10).length).toBe(0);
51 });
52
53 test("with no credit the app is made and filed, and left as it was made", async () => {
54 const db = forge.child.db;
55 const maria = getUserByName(db, "maria")!;
56 const dir = forge.child.config.dataDir;
57 const funding = fundingOf(dir)!;
58 keepFunding(dir, { token: funding.token, capUsd: 2, spentUsd: 2 });
59 try {
60 expect(crewCanRun(forge.child)).toBe(false);
61 const res = await forge.post(forge.owner, "/tell", { app: "new-app", text: "A parking map for the market" });
62 expect(res.status).toBe(303);
63 const repo = listReposOwnedBy(db, maria.id).find((r) => r.name.includes("parking"))!;
64 expect(listIssues(db, repo.id, { state: "open" }).length).toBe(1);
65 expect(repo.autonomy).not.toBe("autonomous");
66 } finally {
67 keepFunding(dir, funding);
68 }
69 });
70
71 test("an empty ask makes no app", async () => {
72 const db = forge.child.db;
73 const before = listReposOwnedBy(db, getUserByName(db, "maria")!.id).length;
74 const res = await forge.post(forge.owner, "/tell", { app: "new-app", text: " " });
75 expect(res.status).toBe(303);
76 expect(listReposOwnedBy(db, getUserByName(db, "maria")!.id).length).toBe(before);
77 });
test/tui-first-tell.test.ts +16 −2
@@ -1,5 +1,7 @@
11 /** The terminal's home of a new forge: before the first tell, "what do you want built" and no everyday offer; after it, the offer. */
22 import { afterAll, beforeAll, expect, test } from "bun:test";
3 import { listIssues } from "../src/core/issues.ts";
4 import { getRepo, listReposOwnedBy } from "../src/core/repos.ts";
35 import { getUserById } from "../src/core/users.ts";
46 import { createForgeApp } from "../src/tui/forge.ts";
57 import { headlessTerminal } from "../src/tui/term/terminal.ts";
@@ -32,6 +34,7 @@ function boot() {
3234 }
3335
3436 test("before the first tell the home says what to do and offers no everyday account; after it, the offer", async () => {
37 const user = getUserById(forge.child.db, forge.child.db.query<{ id: string }, []>("SELECT id FROM user WHERE is_admin = 1 AND is_agent = 0 AND kind = 'user' LIMIT 1").get()!.id)!;
3538 const h = boot();
3639 await settleApp(h.app);
3740 expect(h.text()).toContain("What do you want built?");
@@ -41,7 +44,18 @@ test("before the first tell the home says what to do and offers no everyday acco
4144 await h.key("t");
4245 for (const ch of "A weekly menu page") await h.key(ch);
4346 await h.key("enter");
44 expect(forge.child.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM thought").get()!.n).toBe(1);
47 // The terminal's first tell is the page's: an app made from the ask, the ask filed there, no thought kept.
48 const owned = () => listReposOwnedBy(forge.child.db, user.id).filter((r) => r.name.includes("menu"));
49 for (let i = 0; i < 400 && owned().length === 0; i++) await Bun.sleep(50);
50 const repo = owned()[0]!;
51 expect(repo).toBeDefined();
52 for (let i = 0; i < 400 && listIssues(forge.child.db, repo.id).length === 0; i++) await Bun.sleep(50);
53 expect(listIssues(forge.child.db, repo.id).length).toBe(1);
54 expect(getRepo(forge.child.db, user.username, repo.name)!.autonomy).toBe("autonomous");
55 expect(forge.child.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM thought").get()!.n).toBe(0);
56 // Let the terminal finish its own follow-up (toast, reload) before the app stops.
57 for (let i = 0; i < 400 && !h.text().includes("filed your ask"); i++) await Bun.sleep(50);
58 await settleApp(h.app);
4559 h.app.stop();
4660
4761 // Once the crew has made an issue of it, the home is the everyday one and offers the account.
@@ -52,4 +66,4 @@ test("before the first tell the home says what to do and offers no everyday acco
5266 expect(after.text()).not.toContain("What do you want built?");
5367 expect(after.text()).toContain("K keeps using admin");
5468 after.app.stop();
55 });
69 }, 60_000);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs