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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13845-an-app-made-from-one-sentence-is-named-f → main 4 commits fork 1 thread · 1 unresolved
4 files
changed +80
−10
docs/features/new-app.md +3 −1
| @@ -9,7 +9,9 @@ never to agents. | ||
| 9 | 9 | owner already has that name) by `newAppFromSentence`, the same action the |
| 10 | 10 | `/apps/new` form calls with its name left blank. A sentence with nothing to |
| 11 | 11 | 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`. | |
| 13 | 15 | 2. If you are in organizations, a second **Owner** prompt lists them with your |
| 14 | 16 | own username (prefilled). An owner not on the list keeps the prompt open. |
| 15 | 17 | 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([ | ||
| 90 | 90 | ]); |
| 91 | 91 | |
| 92 | 92 | /** |
| 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. | |
| 126 | * A sentence of only stop or generic words falls back to the window | |
| 127 | * verbatim, so the name is never built from nothing. | |
| 97 | 128 | */ |
| 98 | 129 | function contentWords(sentence: string): string[] { |
| 99 | 130 | const front = sentence.trim().split(/\s+/).slice(0, MAX_WORDS); |
| 100 | 131 | 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, "")), | |
| 102 | 133 | ); |
| 103 | 134 | return (meaningful.length > 0 ? meaningful : front).slice(0, MAX_NAME_WORDS); |
| 104 | 135 | } |
| @@ -127,7 +158,7 @@ export function deriveAppName(sentence: string): string | undefined { | ||
| 127 | 158 | * script blanks it on submit unless the person edited it themselves. |
| 128 | 159 | * |
| 129 | 160 | * 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. | |
| 131 | 162 | */ |
| 132 | 163 | export const appNameJs = /* js */ ` |
| 133 | 164 | (function () { |
| @@ -137,7 +168,7 @@ export const appNameJs = /* js */ ` | ||
| 137 | 168 | if (!desc || !name || !form) return; |
| 138 | 169 | var touched = name.value.trim() !== ''; |
| 139 | 170 | name.addEventListener('input', function () { touched = true; }); |
| 140 | var stopWords = ${JSON.stringify(Array.from(STOP_WORDS))}; | |
| 171 | var stopWords = ${JSON.stringify(Array.from(DROPPED))}; | |
| 141 | 172 | function contentWords(s) { |
| 142 | 173 | var front = s.trim().split(/\\s+/).slice(0, ${MAX_WORDS}); |
| 143 | 174 | 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)", | ||
| 328 | 328 | const cases: Array<[string, string | undefined]> = [ |
| 329 | 329 | // Leading articles and small connecting words are dropped. |
| 330 | 330 | ["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"], | |
| 332 | 332 | // Already short: nothing to drop. |
| 333 | 333 | ["logs", "logs"], |
| 334 | 334 | // 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)", | ||
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | 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}"`); | |
| 350 | 350 | }); |
| 351 | 351 | }); |
| 352 | 352 |
new above
offline
Stale and overlong: the fallback now applies to a sentence of only stop or generic words. Reword and rewrap this block.