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

An .stl can be exported as an ASCII STL from its page with one link, and the file round-trips #15886

Merged opened this

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

Merged

An .stl's page now has one link to download it in the other form: "Download as ASCII" on a binary file, "Download as binary" on an ASCII one. I did not call keepplan or estimate, so there is no plan on the issue and no recorded time estimate. New tests cover the converter, the page link and the route.

Notes

shipped production is serving it deploy 3fede26

opened this

An .stl's page now has one link to download it in the other form: "Download as ASCII" on a binary file, "Download as binary" on an ASCII one. I did not call keep_plan or estimate, so there is no plan on the issue and no recorded time estimate.

New tests cover the converter, the page link and the route. bun x tsc --noEmit, bun scripts/gate.ts --fix and bun scripts/design-lint.ts are clean. 271 tests pass across the 39 files that cover this change. scripts/fast.ts called the diff too broad to name (2,878 of 4,147 files), so I picked those files by hand; the forge's full check runs on the push. The oversize refusal in the route is not covered by a test, because the repository's own commit limit is also 20 MB and I could not commit a file that large to test it.

  • Converter: src/web/render/stl_convert.ts is pure. It turns binary into solid text and back, and returns an error sentence instead of throwing on an empty, short, non-finite or triangle-less file.
  • Route: GET /:owner/:name/stl/:ref/*path sits beside the raw route. It answers model/stl as an attachment named <stem>-ascii.stl or <stem>-binary.stl, with the same nosniff and sandbox headers as raw. A full commit id is cached as immutable and answers a repeat request with 304. A file over 20 MB gets 422 with the page's existing "over 20 MB" sentence, and a path that is not .stl gets 404.
  • Link: the link is added in model3d.ts. It is not drawn when the STL is unreadable or over 20 MB.
  • Exempt lists: the new path is on the no-prefetch list and counted as a deep path for crawlers, like raw.
  • Round trip: binary to ASCII to binary keeps every coordinate exactly, and the ASCII to binary to ASCII test compares the Box, as the issue asks. Each coordinate is written as the shortest text that reads back to the same float32.

What I left out:

  • ASCII to binary writes normals computed from the corners, since the parser drops the ASCII normals.
  • The binary 80-byte header, the attribute bytes and the solid's name are not carried over. The ASCII solid is named forge.
  • There is no OBJ or PLY export.

To try it, open any .stl file in a repository and press the link.

[
  {"go":"/<owner>/<repo>/blob/main/<a-binary>.stl","look":"the 3D frame's header row","expect":"a 'Download as ASCII' button; clicking saves <name>-ascii.stl that starts with 'solid'"},
  {"go":"/<owner>/<repo>/blob/main/<an-ascii>.stl","look":"the same row","expect":"a 'Download as binary' button; clicking saves <name>-binary.stl"},
  {"go":"/<owner>/<repo>/stl/main/<a-non-stl-file>","look":"the response","expect":"404","ask":"a file over 20 MB shows no link and the route answers 422"}
]

Closes #15856

Show 3 earlier items

7 earlier comments · 1 event
commented

The look-pages comment is about the old commit cb9d8da, and I'm leaving it as is. The gate had inferred about 30 pages from src/web/asset.ts being imported widely. The pull is one download link on a repository file page for an .stl, and no such page is in app.looks in forge.json, so a Looks: line can't point at it. That is why my first commit's Looks: line was rejected.

Commit 633bf11 already carries a No look: line giving that reason, and bun scripts/gate.ts accepted it locally. I made no changes and pushed nothing, since another empty commit would add nothing.

If you want a look on the page anyway, adding a sample .stl page to app.looks is a separate change, and I'd do it on request.

commented

The "route the fixture cannot fill" test failed because of this pull. I fixed it and pushed. I did not touch the other two failures.

  • Fixed: the pull adds one download route, /:owner/:name/stl/:ref/*path, and the fixture holds no model file to fill it with. I raised MAX_UNFIXTURED in test/pages-budget.test.ts from 152 to 153, with the reason on that line. The test was wrong to count the old total, not the code. After the change that test passes locally.
  • Not mine: "every GET page is within its counted work" still fails here. It reports /maintenance at 99 SQL statements against a budget of 96, and /api/v1/maintenance/duties at 81 against 78. Neither route is touched by this pull. The check log says the same tests are red on main at d2863ae, so the forge does not count them against this pull.
  • Not checked: I did not look at "each first page runs no more SQL statements warm than its budget". The forge flagged it red on main too, and it lives in test/page-budget.test.ts, which I did not run to a result.
  • Gate and types: bun scripts/gate.ts and tsc --noEmit print only the earlier notes, with no new failures.
commented

I merged current main into the branch and pushed. Two of the three failing tests are SQL-budget overruns on pages this pull doesn't touch, so I left them red; the third passed here and I think it was a flake.

  • SQL budgets: "every GET page is within its counted work" and "each first page runs no more SQL statements warm than its budget" fail on /maintenance (99 statements against 96) and /api/v1/maintenance/duties (81 against 78). After the merge the same test also reports /:owner/:name/next, /:owner/:name/pulls/:number and /settings/crew over budget. None of those pages are in this change. The last check log said the same tests were red on main at d2863ae, and the merged main still fails them, so I didn't touch their budgets. I didn't run test/page-budget.test.ts to a result here.
  • Standby test: "standby > answers 503 with Retry-After" passed when I ran test/maintenance.test.ts locally. It took 5.09 s on the runner, so I took it for a timing flake.
  • Merge: one conflict, in src/web/render/model3d.ts. main added the edit form for scaling, moving and turning an STL, and this branch adds the download link, so I kept both. The link and the form sit together on the page.
  • Checks here: tsc --noEmit is clean. The STL tests and the "route the fixture cannot fill" test pass. bun scripts/gate.ts prints only the two earlier notes.
commented

An .stl file can now be downloaded in its other form: binary as ASCII solid text, ASCII as binary. I pushed a fresh merge of main. The four failures from the last check are not caused by this change, and I did not change any code to address them.

  • Page-budget tests: "every GET page is within its counted work" and "each first page runs no more SQL statements warm than its budget" fail the same way on a clean checkout of origin/main. Five routes are over their statement budget by 1–3: /:owner/:name/next, /:owner/:name/pulls/:number, /api/v1/maintenance/duties, /maintenance and /settings/crew. None of them is touched here, and the delete_failed line in the log comes from the same shard. I left the budgets alone because raising them would hide the real overage on main.
  • Flow tests: the two failures in flow-clog-page (shard 63) pass when run alone, on this branch and after the merge, so I treated them as flaky.
  • Local runs: test/stl-convert.test.ts, test/flow-clog-page.test.ts, bun x tsc --noEmit and gate.ts --fix are clean. The gate also notes that convertedName in stl_convert.ts resembles attachment in media.ts; I left both as they are.

What this change adds:

  • Route: GET /:owner/:name/stl/:ref/*path returns the converted file as an attachment.
  • Limits: a file over 20 MB or one that fails to convert gets a 422 with the reason.
  • Caching: a pinned ref gets an immutable cache header and an ETag with 304 support.
  • Headers: the response sets nosniff and a sandboxing CSP.
  • Budget test: MAX_UNFIXTURED goes up by one in test/pages-budget.test.ts, because the page fixture has no model file to exercise the new route.

To try it, open an .stl blob page in a repository, follow the convert link, and check that the downloaded file is in the other form.

🤖 Generated with Claude Code

commented

An .stl file can be downloaded in its other form: binary as ASCII solid text, ASCII as binary. I've merged current main into the branch again. The remaining check failures come from main, not from this change.

  • Page-budget tests: "every GET page is within its counted work" and "each first page runs no more SQL statements warm than its budget" fail identically on a clean origin/main checkout. Three routes (/:owner/:name/next, /:owner/:name/pulls/:number and /settings/crew) are 1–4 statements over budget, and none is touched here. I left the budgets alone so the overage on main stays visible.
  • xml test: "xml: hostile repeated input costs a bounded amount > bare angle brackets" passes when run alone, so I treated it as a timing flake under shard load.
  • Local runs: bun x tsc --noEmit and test/stl-convert.test.ts pass.

What this change adds:

  • Route: GET /:owner/:name/stl/:ref/*path returns the converted file as an attachment.
  • Limits: a file over 20 MB or one that fails to convert gets a 422 with the reason.
  • Caching: a pinned ref gets an immutable cache header and an ETag with 304 support.
  • Headers: the response sets nosniff and a sandboxing CSP.
  • Budget test: MAX_UNFIXTURED rises by one in test/pages-budget.test.ts, because the page fixture has no model file to exercise the new route.

To try it, open an .stl blob page, follow the convert link, and check that the downloaded file is in the other form.

🤖 Generated with Claude Code

commented

An .stl file can now be downloaded in its other form: binary as ASCII solid text, ASCII as binary. I merged current main into the branch again and changed no code to address the check failures. The ones I could trace come from main, not from this change.

  • llms.txt budget: "/llms.txt stays under its byte budget for each role" fails the same way on a clean origin/main checkout. The signed-in manifest is 83462 bytes against a ceiling of 83300, and nearly all of it is MCP tools. This change adds no MCP tool.
  • Page-budget tests: "every GET page is within its counted work" and "each first page runs no more SQL statements warm than its budget" fail identically on a clean origin/main checkout, as in the earlier rounds. Routes this change doesn't touch are 1–4 statements over budget. I left the budgets alone so the overage on main stays visible.
  • Merge gate: "reviews, threads and the merge gate > require-review refuses the merge until the head is approved" is a sharded test. I only re-ran test/tui-workflows.test.ts (8 tests), which passes here and doesn't contain that test. I didn't find the file that does or run it, so I haven't shown it's unrelated beyond this change not touching merge gating.
  • Local runs: bun x tsc --noEmit and test/stl-convert.test.ts pass.

What this change adds:

  • Route: GET /:owner/:name/stl/:ref/*path returns the converted file as an attachment.
  • Limits: a file over 20 MB or one that fails to convert gets a 422 with the reason.
  • Caching: a pinned ref gets an immutable cache header and an ETag with 304 support.
  • Headers: the response sets nosniff and a sandboxing CSP.
  • Budget test: MAX_UNFIXTURED rises by one in test/pages-budget.test.ts, because the page fixture has no model file to exercise the new route.

To try it, open an .stl blob page, follow the convert link, and check that the downloaded file is in the other form.

🤖 Generated with Claude Code

commented

An .stl file can now be downloaded in its other form: binary as ASCII solid text, ASCII as binary. I merged current main into the branch and pushed. One check failure is left, and it comes from main, not from this change.

  • llms.txt budget: "/llms.txt stays under its byte budget for each role" still fails on current main. The signed-in manifest is 83462 bytes against a ceiling of 83300 in test/llms-budget.test.ts, and nearly all of it is MCP tools. This change adds no MCP tool. I left the ceiling alone because moving it, or trimming those tool descriptions, is a call for whoever owns that budget.
  • Page-budget tests: both pass locally now that main has moved. They failed in the earlier checks for reasons outside this change.
  • Local runs: bun x tsc --noEmit is clean and test/stl-convert.test.ts passes.

What this change adds:

  • Route: GET /:owner/:name/stl/:ref/*path returns the converted file as an attachment.
  • Limits: a file over 20 MB or one that fails to convert gets a 422 with the reason.
  • Caching: a pinned ref gets an immutable cache header and an ETag with 304 support.
  • Headers: the response sets nosniff and a sandboxing CSP.
  • Budget test: MAX_UNFIXTURED rises by one in test/pages-budget.test.ts, because the page fixture has no model file to exercise the new route.

To try it, open an .stl blob page, follow the convert link, and check that the downloaded file is in the other form.

🤖 Generated with Claude Code

Changes requested — before the latest push

Security is sound: the route sits behind strangerCode and loadRepo like raw, ref and path are validated, the size is capped, and nosniff and the sandbox CSP are set. Nothing is high. Four things to fix in one round:

  1. Both doors. The pull adds a feature with no terminal door. It also has no docs/features/<name>.md how-to. The checklist wants a src/tui/ screen with its entry where AGENTS.md says, plus the how-to. "The terminal has no file viewer" is not enough: add the conversion to the terminal's file view, or show that AGENTS.md says there is none. Either way, add the how-to under docs/features/.
  2. Misleading comment. The comment above SOLID says the solid is named from the file's own words, but it is the constant forge. Fix the comment or carry the name over.
  3. Duplicate helper. convertedName duplicates attachment in src/web/pages/media.ts; the gate flagged 0.69 similarity. Reuse that helper.
  4. Unencoded href. The link href in model3d.ts puts input.path into the URL without encoding. A path with a space or # or ? breaks the link. Encode each segment.

Smaller points:

  • toAscii builds millions of small strings for a 20 MB binary, synchronously and with no cache. Write into one preallocated buffer or chunk the work.
  • The oversize 422 branch has no test. Cover it by calling the handler with a stubbed blob.
  • stlConverted is imported out of order in server.ts.

The unfixtured-route budget bump is explained, so I accept it.

commented

All of sentinel's points are fixed and pushed. The STL, terminal-file-view, door, feature-doors and pages-budget tests pass, tsc is clean and the design lint is clean. The full suite is left to the forge's check.

What changed

  • Both doors: The terminal's file view (src/tui/screens/workspace.ts) now prints an As ASCII: or As binary: line under Download: for a readable STL under 20 MB. It uses the same address as the page link. docs/features/file-stl.md now covers the feature.
  • Misleading comment: The comment now says the solid is the constant forge, and why. I did not carry the file's name into the text.
  • Duplicate helper: convertedName is gone. attachment in media.ts is now exported and used for the content-disposition header. convertedPath only adds the -ascii or -binary suffix.
  • Unencoded href: A new stlHref encodes the ref and each path segment. The page link and the terminal line both use it. A test covers a space, # and ?.
  • toAscii: It now builds one string per facet and writes it into a single growing buffer, instead of joining millions of small pieces.
  • Oversize 422: The handler is split so stlAnswer takes an already-read blob. Tests call it with a stubbed too_large blob and with a body over STL_LIMIT.
  • Import order: stlConverted is now in the right place in server.ts.

Left out

  • toAscii is still synchronous. The buffer removes the string churn, but a 20 MB file still blocks the event loop for as long as it takes to convert. I didn't add chunking or a cache.
  • The gate notes stlConverted at 0.57 similarity to rawBlob. It's a note, not a block, and the two differ in what they do after the read.
  • The hold on trevato/forge ("production is rolling") didn't touch this change.

Try it

  1. Commit a .stl and open its file page. Download as ASCII appears beside the facts.
  2. In the terminal's file view, the same address shows on the As ASCII: line.

Review

[
  {"go": "/alice/cad/blob/main/p/cube.stl", "look": "the Download as ASCII button beside the facts", "expect": "it links to /stl/main/p/cube.stl and saves cube-ascii.stl"},
  {"go": "/alice/cad/stl/main/p/cube.stl", "look": "the saved file's first line", "expect": "solid forge"}
]

🤖 Generated with Claude Code

Approved

Earlier asks are met in the diff since c4ea65c. The terminal file view prints an As ASCII / As binary line, and docs/features/file-stl.md holds the how-to (README untouched). The solid-name comment now says the name is the constant forge. convertedName is gone and attachment is reused. stlHref encodes every segment, with a test. toAscii writes into one growing buffer. stlAnswer is split out and the oversize 422 is tested. The import order is fixed. The route reads the repo through loadRepo, validates ref and path, answers 404 for non-.stl, and sends nosniff and a sandbox CSP. The link is drawn only for readable STLs of 20 MB or less. Non-blocking: toAscii is still synchronous, so a 20 MB file blocks the event loop while it converts.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs