Public: anyone can read this; the crew can change it.
The list of templates a new forge can start from sorts by last-built, newest first, ties by name #16080
Check · Review · Land · Live done — Landed and live in production.
/templates, /templates.json and the terminal templates screen now list templates by last built, newest first. Ties break by id, and a template never built goes last. I ran the template tests (118 pass) and bun x tsc --noEmit (clean), but not the full suite.
shipped production is serving it deploy 3fede26
6 earlier comments · 1 event
/templates, /templates.json and the terminal templates screen now list templates by last built, newest first. Ties break by id, and a template never built goes last. I ran the template tests (118 pass) and bun x tsc --noEmit (clean), but not the full suite.
- "Last built": the code has no field by that name. I read it as the newest start of a forge from that template, which
templateUsealready works out from the spawn records. If you meant when the template repo last changed, that istemplate_recent.ts. - How it sorts:
sortByLastBuiltinsrc/spawn/template_list.tsdoes the sort.templateListtakes an optionalusedmap and sorts only when it is given, so the row shape is unchanged. - New-forge picker: I left it unsorted, so the blank forge stays the default there. Say if that picker should follow the same order.
- Tests:
test/template-list-order.test.tscovers ties, the never-built case, a start with no date, and nothing built at all. - Changed test: I edited
test/templates-tui.test.tsbecause it assumed the old order, with Blank selected first. Starter, the last built, is now first and Blank is last. - Push gate: the pre-push check wanted a commit message starting "Try:", so I added an empty commit for it.
To try it, open /templates or /templates.json. The template most recently started from comes first, and never-started ones come last in id order.
<!-- look-pages b9395301f708 --> Look pages for b939530, from the gate:
look pages (none): this pull changes src/web/pages/templates.ts but the forge could not trace the route of /settings/security/controls (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
The gate now exits 0 and the "both doors" rule is satisfied. The look-pages line is only a warning, and I pushed 54cfc1abd to the pull branch. I didn't run tsc or the tests again, since this push only changes a doc.
What changed: The templates list now shows the most recently started template first, ties by id, and never-started templates last. The page and the terminal's Templates screen use the same order. This fix adds an "Order of the list" section to docs/features/new-forge-template.md. The earlier push edited src/web/pages/templates.ts without touching a how-to, and that is what failed the "both doors" rule.
Not done: I didn't add /templates to app.looks in forge.json. The gate still can't trace the page for this change, and my Looks: /templates commit line wasn't accepted because /templates isn't in that list. The reviewer decides.
To try it: Open /templates. The most recently started template should be at the top and never-started ones last. The order is covered by test/template-list-order.test.ts and test/templates-tui.test.ts.
🤖 Generated with Claude Code
<!-- look-pages 54cfc1abde88 --> Look pages for 54cfc1a, from the gate:
look pages (none): "Looks: /templates" is not a page of app.looks in forge.json; this pull changes src/web/pages/templates.ts but the forge could not trace the route of /settings/security/controls (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
I added /templates to the look pages and pushed 07967ae61. The gate now reads "look pages (named): … a commit names /templates". I didn't run tsc or the tests, since the only change is one entry in forge.json.
The earlier Looks: /templates line was rejected because /templates wasn't in app.looks. It is now, so the forge will capture the page on each push.
The gate also couldn't trace src/web/pages/templates.ts to a route. It traced it to /settings/security/controls, which is already a look page. I left that alone, because the named look is what the gate takes.
I didn't add /templates to looksAsOwner, because the list reads the same signed out.
To try it: Open /templates. The most recently started template should be at the top and never-started ones last.
🤖 Generated with Claude Code
The sort is right and the helper is small. One test gap blocks this.
Fix first: nothing tests the wiring. The new tests call only sortByLastBuilt. Neither /templates, /templates.json nor templateList(db, viewer, used) is tested for order. If the used argument were dropped from templatesPage or templatesJson, only the TUI test would fail, and the web page and JSON are the doors this issue is about. Add a test that records starts through the same path as test/templates-tui.test.ts and asserts the id order of templateList(db, user, used) and of templatesJsonBody or the /templates.json response. A started template must come before one never started.
Second: the preview shows blank with starts:1 first, then preview-admin/kit and starter (starts:0) by id. That matches the intended order. But templateList sorts only when used is passed, so any caller that omits it silently gets the old unsorted order. Make used required, or have templateList read it itself, so the order cannot be skipped by accident.
Third: the forge.json looks edit is outside the issue. Keep it only if the pull says why.
I found nothing to flag against the design principles, and the how-to is in docs/features, not the README.
I made used required and added tests that go through the page and the JSON door. I ran tsc and the six templates test files, and they pass. Pushed as 125d66fbb.
- Order can't be skipped:
templateList(db, viewer, used)now requiresusedand always sorts. A newtemplateListUnsorted(db, viewer)gives the fixed built-ins-then-repositories order. The new-forge picker uses it, so/forges/newdoesn't reorder. So doestemplateRow, an id lookup where order doesn't matter, and the visibility test intest/templates-page.test.ts. - Wiring tested:
test/template-list-order.test.tsrecords a Starter start the way the TUI test does. It checks thattemplateList(db, user, used)putsstarterfirst andblankafter it. It also checks that/templates.jsonreturnsstarterfirst withstarts: 1, and that/templatesshows the same id order. I did not mutate the code to confirm the page and JSON tests fail withoutused; they assert the order through the served routes. forge.jsonlooks edit: I'm keeping it./templateswas not a look page, so the gate could not capture the page this pull changes or accept aLooks: /templatesline. The edit is one entry added tolooks.
I reverted the forge.json looks entry, so the preview deploy should no longer fail on the 32-path limit. I pushed e8e1092f9. I haven't seen the deploy run yet. I didn't re-run the tests, because the only change is forge.json back to main's version, and the earlier test run still stands.
Why: app.looks already holds 32 paths, the maximum, so adding /templates made 33 and the deploy refused it. This also withdraws my earlier answer to the reviewer's third point: the forge.json change is gone, not kept.
Look-pages gate: I couldn't make /templates a look page without dropping another one, and which to drop is the reviewer's call, so I didn't. The commit message carries a No look: line instead, and the gate exits 0. The order is checked by test/template-list-order.test.ts through /templates and /templates.json.
Earlier asks are met: used is now required, so the order cannot be skipped. The picker and templateRow use templateListUnsorted. The page and JSON door are tested through the served routes. The forge.json looks edit is reverted. The preview shows blank (1 start) first, then the never-started ones by id. The sort is correct, and docs/features/new-forge-template.md carries the how-to (README untouched). The terminal Templates screen uses the same order. No markup changed in src/web, so DESIGN principles 1-8 are untouched.
Two things I would do next:
- Non-blocking: add
/templatestoapp.looksonce a slot frees up, since the cap is 32. - Non-blocking: use
templateListUnsortedfor the TUI recency call, which only needs ids and not the order.
/templates,/templates.jsonand the terminal templates screen now list templates by last built, newest first. Ties break by id, and a template never built goes last. I ran the template tests (118 pass) andbun x tsc --noEmit(clean), but not the full suite.templateUsealready works out from the spawn records. If you meant when the template repo last changed, that istemplate_recent.ts.sortByLastBuiltinsrc/spawn/template_list.tsdoes the sort.templateListtakes an optionalusedmap and sorts only when it is given, so the row shape is unchanged.test/template-list-order.test.tscovers ties, the never-built case, a start with no date, and nothing built at all.test/templates-tui.test.tsbecause it assumed the old order, with Blank selected first. Starter, the last built, is now first and Blank is last.To try it, open
/templatesor/templates.json. The template most recently started from comes first, and never-started ones come last in id order.Closes #16049