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

An app made from one sentence is named for what it does: "A page that counts down the days to New Year" is not page-counts #13857

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13845-an-app-made-from-one-sentence-is-named-f → main 4 commits fork 1 thread · 1 unresolved

  • Merged. scout/13845-an-app-made-from-one-sentence-is-named-f was merged into main as 6d0cf92.

Review

Sign in to review this change.
4 files changed +80 −10
docs/features/new-app.md +3 −1
@@ -9,7 +9,9 @@ never to agents.
99 owner already has that name) by `newAppFromSentence`, the same action the
1010 `/apps/new` form calls with its name left blank. A sentence with nothing to
1111 name from (empty, punctuation only) keeps the prompt open with the no-name
12 words.
12 words. Generic words (page, app, site, tool, make, build and the like) are
13 skipped like stop words, so `A page that counts down the days to New Year`
14 becomes `counts-down`.
1315 2. If you are in organizations, a second **Owner** prompt lists them with your
1416 own username (prefilled). An owner not on the list keeps the prompt open.
1517 3. A working line ("Making your app…") shows while the starter is committed and
src/web/pages/apps-name.ts +38 −7
@@ -90,15 +90,46 @@ export const STOP_WORDS = new Set([
9090 ]);
9191
9292 /**
93 * The first few meaningful words of the sentence: the stop words dropped
94 * from a window at its front, capped to a couple of words. A sentence that
95 * is only stop words falls back to the window verbatim, so the name is
96 * never built from nothing.
93 * Generic container and request words ("a page that...", "make me a
94 * website"): they say nothing about what the app does, so they are dropped
95 * beside `STOP_WORDS`, and the browser mirror reads this same list.
96 */
97 export const GENERIC_WORDS = [
98 "page",
99 "app",
100 "application",
101 "site",
102 "website",
103 "tool",
104 "thing",
105 "simple",
106 "small",
107 "little",
108 "basic",
109 "make",
110 "build",
111 "create",
112 "want",
113 "need",
114 "which",
115 "who",
116 "me",
117 "us",
118 "please",
119 ];
120
121 const DROPPED = new Set([...STOP_WORDS, ...GENERIC_WORDS]);
122
123 /**
124 * The first few meaningful words of the sentence: the stop and generic
125 * words dropped from a window at its front, capped to a couple of words.
outdated

Stale and overlong: the fallback now applies to a sentence of only stop or generic words. Reword and rewrap this block.

126 * A sentence of only stop or generic words falls back to the window
127 * verbatim, so the name is never built from nothing.
97128 */
98129 function contentWords(sentence: string): string[] {
99130 const front = sentence.trim().split(/\s+/).slice(0, MAX_WORDS);
100131 const meaningful = front.filter(
101 (word) => !STOP_WORDS.has(word.toLowerCase().replace(/[^a-z0-9]/g, "")),
132 (word) => !DROPPED.has(word.toLowerCase().replace(/[^a-z0-9]/g, "")),
102133 );
103134 return (meaningful.length > 0 ? meaningful : front).slice(0, MAX_NAME_WORDS);
104135 }
@@ -127,7 +158,7 @@ export function deriveAppName(sentence: string): string | undefined {
127158 * script blanks it on submit unless the person edited it themselves.
128159 *
129160 * Generated from `deriveAppName`'s own constants (`MAX_WORDS`,
130 * `MAX_NAME_WORDS`, `STOP_WORDS`) so the two never drift apart.
161 * `MAX_NAME_WORDS`, `STOP_WORDS`, `GENERIC_WORDS`) so the two never drift apart.
131162 */
132163 export const appNameJs = /* js */ `
133164 (function () {
@@ -137,7 +168,7 @@ export const appNameJs = /* js */ `
137168 if (!desc || !name || !form) return;
138169 var touched = name.value.trim() !== '';
139170 name.addEventListener('input', function () { touched = true; });
140 var stopWords = ${JSON.stringify(Array.from(STOP_WORDS))};
171 var stopWords = ${JSON.stringify(Array.from(DROPPED))};
141172 function contentWords(s) {
142173 var front = s.trim().split(/\\s+/).slice(0, ${MAX_WORDS});
143174 var meaningful = front.filter(function (word) {
test/apps-name-generic.test.ts added +37
@@ -0,0 +1,37 @@
1 import { describe, expect, test } from "bun:test";
2 import { GENERIC_WORDS, appNameJs, deriveAppName } from "../src/web/pages/apps-name.ts";
3
4 /** Runs the browser mirror against a fake form and returns the preview. */
5 function mirror(sentence: string): string {
6 const field = { value: sentence, addEventListener() {} };
7 const name = {
8 value: "",
9 addEventListener() {},
10 closest: () => ({ addEventListener() {} }),
11 };
12 const doc = { getElementById: (id: string) => (id === "f-description" ? field : name) };
13 new Function("document", appNameJs)(doc);
14 return name.value;
15 }
16
17 const table: Array<[string, string]> = [
18 ["A page that counts down the days to New Year", "counts-down"],
19 ["Make a website for my bakery", "bakery"],
20 ["Build me a guestbook", "guestbook"],
21 ["please", "please"],
22 ["a simple small app", "a-simple"],
23 ["Create a tool which tracks habits", "tracks-habits"],
24 ];
25
26 describe("generic words are dropped from a derived name", () => {
27 for (const [sentence, expected] of table) {
28 test(`${sentence} -> ${expected}, same in the browser mirror`, () => {
29 expect(deriveAppName(sentence)).toBe(expected);
30 expect(mirror(sentence)).toBe(expected);
31 });
32 }
33
34 test("the mirror carries every generic word", () => {
35 for (const word of GENERIC_WORDS) expect(appNameJs).toContain(`"${word}"`);
36 });
37 });
test/apps-new.test.ts +2 −2
@@ -328,7 +328,7 @@ describe("deriveAppName: a sentence yields a short, ordinary name (issue #186)",
328328 const cases: Array<[string, string | undefined]> = [
329329 // Leading articles and small connecting words are dropped.
330330 ["a notepad that counts words", "notepad-counts"],
331 ["an app for tracking my plants", "app-tracking"],
331 ["an app for tracking my plants", "tracking-plants"],
332332 // Already short: nothing to drop.
333333 ["logs", "logs"],
334334 // Only stop words: falls back to the window itself, never empty.
@@ -346,7 +346,7 @@ describe("deriveAppName: a sentence yields a short, ordinary name (issue #186)",
346346 }
347347
348348 test("appNameJs embeds the same stop words, window and cap as deriveAppName", () => {
349 expect(appNameJs).toContain(JSON.stringify(Array.from(STOP_WORDS)));
349 for (const word of STOP_WORDS) expect(appNameJs).toContain(`"${word}"`);
350350 });
351351 });
352352

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs