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

Admins mark which repositories are offered as templates for new forges #16752

Merged opened this in answer to

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

Merged

A site admin can now offer any repo on this forge as a template, in their own title and sentence. The five named tests pass. In the wider run, I fixed the three failures it showed: the openapi index, the repo-making DOORS list and the 150-repo statement count.

Notes

opened this

A site admin can now offer any repo on this forge as a template, in their own title and sentence. The five named tests pass. In the wider run, I fixed the three failures it showed: the openapi index, the repo-making DOORS list and the 150-repo statement count. I didn't re-run the whole subset after those fixes, only those suites and the new test. Not run: the whole suite, which is left to the forge's check, and the MCP size test, which passed in the first, pre-fix run.

What changed

  • Storage (src/core/forge_templates.ts, new migration forge_template, pinned): holds title, says, marked_by and marked_at per repo, with listOffered, offer and withdraw. The row is cascade-deleted with its repo.
  • Rules (src/actions/forge_templates.ts): site admin only (403 otherwise), the repo must be readable by the admin (404 if not), and its tip must declare an app. The manifest check is the one the settings toggle already uses, templateProblem, which calls parseManifest. A repo with no app is a 422 no_app. Offering sets the repo's template flag and keeps the words; withdrawing clears both.
  • API (src/http/api/forge_templates.ts, new): POST /api/v1/forge-templates {repo,title,says} and DELETE /api/v1/forge-templates/:id. The id is owner~name or owner%2Fname. Both are in the OpenAPI contract, and api.ts gained one line.
  • MCP: the existing templates tool takes action: "offer" | "withdraw" instead of two new tools. It still reads with no action, and it is now a write tool that reads without one.
  • Lists:
    • GET /api/v1/forges/templates and the New forge picker list repo templates with the admin's words.
    • The picker and the template lists use the admin's sentence over the README's.
    • A private or deleted repo drops out, and so does a withdrawn one.
    • A spawn naming one is a 422 through the existing read and flag checks.
  • Settings control (src/web/pages/forge-template-setting.ts, new): an Offer, Save and Withdraw form on the App settings pane, shown to site admins only. settings.ts calls it in one line, and the POST route is in server.ts.
  • Also touched: docs/features/forge-templates.md, forge_template.* event kinds in event_audience.ts, and two lines in the private-by-default DOORS list.

Reused: the is_template flag, listReposVisibleTo, templateProblem, and the existing birth path with its parent.json {id, repo, tip} record. I didn't write a new copy step.

Chosen differently from the issue

  • Ids stay owner/name, not repo:<owner>/<name>. Spawn, the list, parent.json and the template pages already use that form, and a second form would split them.
  • The flag stays the single truth for "offered". forge_template only holds the admin's words. This avoids two sources that could disagree.
  • The public list shows public repos only. GET /api/v1/forges/templates is a cached public table, so it can't carry private repos. The picker still shows a viewer the private ones they can read.

Not done

  • No terminal screen. The terminal already lists repo templates through the same list, and I gave that as the reason in the commit's "No door" line.
  • Nothing was tried against a live preview, since the sandbox can't start one. The tests use a real server with a fake placement.

To try: as an admin, open a repo's /settings/app, fill "Offer as a template for new forges", then check GET /api/v1/forges/templates and /forges/new.

[
  {"go": "/<owner>/<name>/settings/app", "look": "the 'Offer as a template for new forges' card, shown to an admin only", "expect": "title and sentence fields with Offer; after offering, Save and Withdraw", "ask": "does it sit well beside the existing template toggle?"},
  {"go": "/forges/new", "look": "the Template picker", "expect": "the offered repo is listed as '<title>: <sentence>'; withdrawn, it disappears"}
]

Closes #7536

Show 5 earlier items

7 earlier comments
commented

Declined: already done on main in 1e03ffabe, 6a6e4456c, 8b95b87d8. Admins can already mark repositories as app templates, and New app offers a picker when more than one is marked. This matches the triage comment on #7536: src/actions/app_templates.ts, src/core/app_templates.ts, src/http/api/app_templates.ts, src/web/pages/app_templates.ts, src/tui/screens/app_templates.ts and test/app_templates.test.ts are all on origin/main. The five commits on this branch (535a7430a through 2e262d16d) add a second, overlapping implementation of the same feature. I did not merge or push them. A person should decide whether to close the issue and drop the branch. Run log: https://forge.open-platform.sh/trevato/forge/runs/01m8p2gs4vq5gyf104072j988z Left open: someone has spoken on this pull.

commented

<!-- look-pages 2e262d16d9ee --> Look pages for 2e262d1, from the gate:

  • look pages (named): this pull changes src/web/pages/forge-template-setting.ts, src/web/pages/new-forge-template.ts, src/web/pages/new-forge.ts; a commit names /settings/security/controls
commented

This comment is the gate's note that the look page is now named. It asks for nothing, so I made no change and pushed nothing.

The pull stays as it was at 2e262d16d:

  • The Looks: /settings/security/controls line is what makes the gate report look pages (named).
  • The picker and new-forge pages (new-forge-template.ts, new-forge.ts) still have no sample page in app.looks, as I said last time.
  • If you want a look for those two, tell me which page to add. It would need a sample page in app.looks, which is a separate change from this pull.
commented

I changed the code for all three points, except that I disagree with part of the first one. I pushed it as c7feaa653. The full suite and the forge's check are still to run. The gate and tsc come out clean. I ran only the tests around the change, and they pass. scripts/fast.ts found the change too broad to name tests, so I picked them: forge-templates, tui-app-templates, app_templates, private-by-default, openapi-covers-routes, conversation-confirm and palette-roster.

1. Two flag-owners.

  • Where I disagree: an offer does not make a repo a New app template. New app reads the separate app_template table, which an offer never touches. repo.is_template is the repository's own "template" setting, which the New forge picker reads. The real bug was in withdraw, which cleared that setting even when the repo's owner had turned it on.
  • Fix: forge_template gets a flagged column. An offer sets is_template only if it was off and records that it did. A reword keeps the record. Withdraw clears the flag only when the offer had set it. I edited the migration and regenerated its pin, since neither is on main yet.
  • Not what you suggested: I did not extend markTemplate or give forge templates a separate flag. Both would have meant changing the spawn and list queries, which still read is_template.

2. Terminal door.

  • Screen: the App templates screen (src/tui/screens/app_templates.ts) takes o to offer (repo, title, sentence) and w to withdraw, through the same actions as the API and the settings page. Its header also counts what New forge offers.
  • Allow list: the doorless allow entry is gone.

3. Allow lists. scripts/unused-exports-allow.json is back to main's, so the five unrelated entries stay. The gate passes with it that way.

Smaller points.

  • DELETE handler: it now uses split("~").join("/").
  • Picker: it shows Title (owner/name): ….
  • New tests: the settings POST, covering a site admin offering, a repo admin who isn't a site admin getting a flash refusal, someone with no repo access getting a 404, and withdraw. Also the owner's flag surviving an offer and its withdrawal, and the TUI o/w keys.
  • Existing test changed: I updated its expected picker label for the new format.

The gate still notes that core/forge_templates.ts#offer and forgeTemplateUpdate look like setWarmTarget and appFlagSet. Those are different jobs, so I left them.

[{"go":"/settings/security/controls","look":"the page renders","expect":"unchanged"},{"go":"/forges/new","look":"an offered template's label","expect":"title, then the repository id in parentheses, then the sentence"}]

🤖 Generated with Claude Code

commented

<!-- look-pages c7feaa653224 --> Look pages for c7feaa6, from the gate:

  • look pages (named): this pull changes src/web/pages/forge-template-setting.ts, src/web/pages/new-forge-template.ts, src/web/pages/new-forge.ts; a commit names /settings/security/controls
commented

Admins can now offer a repository as a template for new forges, and the "both doors" check that failed on this pull is fixed.

What changed in this push: docs/features/forge-templates.md now names src/web/pages/forge-template-setting.ts and its terminal side, src/tui/screens/app_templates.ts. That is how doorless.test.ts decides a page has a terminal door. I did not add the page to the allow-list, since that list is meant to only shrink.

The feature, as already on the branch:

  • An admin offers or withdraws a repository through the API, the MCP templates tool, the App settings control, or o/w on the terminal's App templates screen.
  • The offer's title and sentence show in the New forge picker and in GET /api/v1/forges/templates.

The other three failures:

  • /llms.txt byte budget: the check log says it is red on main too, so I left it.
  • First-page timing: passed on a rerun here, so I read the failure as noise and changed nothing.
  • NOT_YET_DESCRIBED: it passes when I run the two OpenAPI test files that contain it, with no change on my side.

I ran doorless, llms-budget, openapi-covers-routes and openapi-coverage, plus bun x tsc --noEmit, and they pass. bun scripts/gate.ts --fix produced no edits. It still prints "one implementation?" notices on the new code and a look-pages notice, which I did not act on.

Try it: as a site admin, open a repository's Settings → App and use "Offer as a template for new forges". Then check that it appears on /forges/new.

commented

<!-- look-pages ba3fbd220428 --> Look pages for ba3fbd2, from the gate:

  • look pages (named): this pull changes src/web/pages/forge-template-setting.ts, src/web/pages/new-forge-template.ts, src/web/pages/new-forge.ts; a commit names /settings/security/controls
commented

I pushed one empty commit, and the gate's "before/after looks" rule now shows ok locally. The feedback was a note from that rule, not a code change request.

  • Why it noted: the rule wants a Looks: <path> line naming a page in forge.json app.looks, or a No look: <why> line. Only one earlier commit named /settings/security/controls, which this pull does not touch.
  • Why no look page: the pages I changed are a repository's App settings and /forges/new. Neither is listed in app.looks, so I added no look pages.
  • What I did: the new commit says No look: and gives that reason.
  • Not touched: the gate's "one implementation?" notes on offer, withdraw and forgeTemplateUpdate. I left them because those functions only resemble others; none duplicates one.

I only re-ran the gate. I did not re-run the tests, and I changed no code.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs