展示HN:一个人 + 一个代理 = 从头开始用2万行代码构建一个浏览器
Show HN: One Human + One Agent = One Browser From Scratch in 20K LOC

原始链接: https://emsh.cat/one-human-one-agent-one-browser/

## 一人、一个代理、一个浏览器 出于好奇心和探索AI辅助开发的愿望,作者发起了一项72小时的挑战,仅使用一个LLM代理和自身的专业知识,从头开始构建一个基本的网页浏览器——渲染HTML和CSS(不含JavaScript)。目标不仅仅是一个可用的浏览器,而是评估专注的人机协作的有效性。 该项目遵循严格的限制:不使用任何第三方的Rust依赖,跨平台兼容性(Windows、macOS、Linux),以及可读的代码库,每个文件不超过1000行。工作流程包括与代理分享网站截图,请求复制,并使用截图进行迭代测试以查找回归问题。 最终成果是一个20,000行的浏览器,能够成功渲染作者的博客和Hacker News等网站。作者得出结论,一个人与一个代理的组合效率出乎意料地高,可能比扩展到多个代理更有效。这引发了关于自主编码的最佳方法的问题,并表明人类的作用——引导和指导代理——可能比单纯增加代理数量更为关键。完整的代码库和二进制文件已在GitHub上公开可用。

## 一人 + 一代理 = 一浏览器 一位开发者最近使用AI编码代理,以大约20,000行代码从头开始构建了一个功能性网络浏览器,重点采用人工引导的方法。这与Cursor的FastRender(约160万行)等更大、更复杂的AI生成浏览器形成对比。该项目优先考虑最小依赖,主要依赖系统库进行渲染。 这一成功凸显了将人类的“良好品味”与AI辅助相结合的力量,重点在于工具 *增强* 人类能力,而非取代它们。讨论的中心是评估指标的重要性、代码的可弃用性,以及在有限的人工监督下扩展项目的潜力。 虽然该浏览器可以渲染基本的HTML和CSS,但在JavaScript、安全性和完全的网络兼容性方面仍然存在挑战。尽管存在这些障碍,开发者认为到2029年,借助AI辅助构建一个生产级浏览器是可行的,这可能由Ladybird Browser等项目所体现。该项目的源代码可在GitHub上获取,供实验使用。
相关文章

原文

Just for the fun of it, I thought I'd embark on a week-long quest to generate millions of tokens and millions of lines of source code to create one basic browser that can render HTML and CSS (no JS tho), and hopefully I could use this to receive even more VC investments.

But then I remembered that I have something even better: a human brain! It is usually better than any machine at coordinating and thinking through things, so let's see if we can hack something together, one human brain and one LLM agent brain!

The above might look like a simple .webm video, but it's actually a highly sophisticated and advanced browser that was super hard to build, encoded as pixels in a video file! Wowzers.

Day 1 - Starting out

For extra fun when building this, I set these requirements for myself and the agent:

  • I have three days to build it
  • Not a single 3rd party Rust library/dependency allowed
  • Allowed to use anything (commonly) provided out of the box on the OS it runs on
  • Should run on Windows, macOS and common Linux distributions
  • Should be able to render some websites, most importantly, my own blog and Hacker News, should be easy right?
  • The codebase can always compile and be built
  • The codebase should be readable by a human, although code quality isn't the top concern

So with these things in mind, I set out on the journal to build a browser "from scratch". I started with something really based, being able to just render "Hello World". Then to be able to render some nested tags. Added the ability of taking screenshots so the agent could use that. Added specifications for HTML/CSS (which I think the agent never used :| ), and tried to nail down the requirements for the agent to use. Also started doing "regression" or "E2E" tests with the screenshotting feature, so we could compare to some baseline images and so on. Added the ability to click on links just for the fun of it.

After about a day together with Codex, I had something that could via X11 and cURL, fetch and render websites when run, and the Cargo.lock is empty. It was about 7500 lines long in total at that point, split across files with all of them under 1000 lines long (which was a stated requirement, so not a surprise).

Day 2 - Moving On

Second day I got annoyed by the tests spawning windows while I was doing other stuff, so added a --headless flag too. Did some fixes for resizing the window, various compatibility fixes, some performance issues and improved the font/text rendering a bunch. Workflow was basically to pick a website, share a screenshot of the website without JavaScript, ask Codex to replicate it following our instructions. Most of the time was the agent doing work by itself, and me checking in when it notifies me it was done.

Day 3 - Polish & Cross-platform (+ day 4)

Third day we made large changes, lots of new features and a bunch of new features supported. More regression tests, fixing performance issues, fixing crashes and whatnot. Also added scrolling because this is a mother fucking browser, it has to be able to scroll. Added some debug logs too because that'll look cool in the demonstration video above, and also added support for the back button because it was annoying to start from scratch if I clicked the wrong link while testing.

At the end of the third day we also added starting support for macOS, and managed to get a window to open, and the tests to pass. Seems to work OK :) Once we had that working, we also added Windows support, basically the same process, just another platform after all.

Then the fourth day (whaaaat?) was basically polish, fixing CI for all three platforms, making it pass and finally cutting a release based on what got built in CI. Still all within 72 hours (3 days * 24 hours, which obviously this is how you count days).

The results after ~3 days (~70 hours)

And here it is, in all its glory, made in ~20K lines of code and under 72 hours of total elapsed time from first commit to last:

Screenshot of one-agent-one-browser running on X11

You could try compiling it yourself (zero Rust dependencies, so it's really fast :) ), or you can find binaries built on CI here:
https://github.com/embedding-shapes/one-agent-one-browser/releases

You can clone the repository, build it and try it out for yourself. It's not great, I wouldn't even say it's good, but it works, and demonstrates that one person with one agent can build a browser from scratch.

This is what the "lines of code" count ended up being after all was said and done, including support for three OSes:

$ git rev-parse HEAD
e2556016a5aa504ecafd5577c1366854ffd0e280

$ cloc src --by-file
      72 text files.
      72 unique files.
       0 files ignored.

github.com/AlDanial/cloc v 2.06  T=0.06 s (1172.5 files/s, 373824.0 lines/s)
-----------------------------------------------------------------------------------
File                                            blank        comment           code
-----------------------------------------------------------------------------------
src/layout/flex.rs                                 96              0            994
src/layout/inline.rs                               85              0            933
src/layout/mod.rs                                  82              0            910
src/browser.rs                                     78              0            867
src/platform/macos/painter.rs                      96              0            765
src/platform/x11/cairo.rs                          77              0            713
src/platform/windows/painter.rs                    88              0            689
src/bin/render-test.rs                             87              0            666
src/style/builder.rs                               83              0            663
src/platform/windows/d2d.rs                        53              0            595
src/platform/windows/windowed.rs                   72              0            591
src/style/declarations.rs                          18              0            547
src/image.rs                                       81              0            533
src/platform/macos/windowed.rs                     80              2            519
src/net/winhttp.rs                                 61              2            500
src/platform/x11/mod.rs                            56              2            487
src/css.rs                                        103            346            423
src/html.rs                                        58              0            413
src/platform/x11/painter.rs                        48              0            407
src/platform/x11/scale.rs                          57              3            346
src/layout/table.rs                                39              1            340
src/platform/x11/xft.rs                            35              0            338
src/style/parse.rs                                 34              0            311
src/win/wic.rs                                     39              8            305
src/style/mod.rs                                   26              0            292
src/style/computer.rs                              35              0            279
src/platform/x11/xlib.rs                           32              0            278
src/layout/floats.rs                               31              0            265
src/resources.rs                                   36              0            238
src/css_media.rs                                   36              1            232
src/debug.rs                                       32              0            227
src/platform/windows/dwrite.rs                     20              0            222
src/render.rs                                      18              0            196
src/style/custom_properties.rs                     34              0            186
src/platform/windows/scale.rs                      28              0            184
src/url.rs                                         32              0            173
src/layout/helpers.rs                              12              0            172
src/net/curl.rs                                    31              0            171
src/platform/macos/svg.rs                          35              0            171
src/browser/url_loader.rs                          17              0            166
src/platform/windows/gdi.rs                        17              0            165
src/platform/windows/scaled.rs                     16              0            159
src/platform/macos/scaled.rs                       16              0            158
src/layout/svg_xml.rs                               9              0            152
src/win/com.rs                                     26              0            152
src/png.rs                                         27              0            146
src/layout/replaced.rs                             15              0            131
src/net/pool.rs                                    18              0            129
src/platform/macos/scale.rs                        17              0            124
src/style/selectors.rs                             18              0            123
src/style/length.rs                                17              0            121
src/cli.rs                                         15              0            112
src/platform/windows/headless.rs                   20              0            112
src/platform/macos/headless.rs                     19              0            109
src/bin/fetch-resource.rs                          14              0            101
src/geom.rs                                        10              0            101
src/browser/render_helpers.rs                      11              0            100
src/dom.rs                                         11              0            100
src/style/background.rs                            15              0            100
src/layout/tests.rs                                 7              0             85
src/platform/windows/d3d11.rs                      14              0             83
src/win/stream.rs                                  10              0             63
src/platform/windows/svg.rs                        13              0             54
src/main.rs                                         4              0             33
src/platform/mod.rs                                 6              0             28
src/app.rs                                          5              0             25
src/lib.rs                                          1              0             20
src/platform/windows/mod.rs                         2              0             19
src/net/mod.rs                                      4              0             16
src/platform/macos/mod.rs                           2              0             14
src/platform/windows/wstr.rs                        0              0              5
src/win/mod.rs                                      0              0              3
-----------------------------------------------------------------------------------
SUM:                                             2440            365          20150
-----------------------------------------------------------------------------------

Takeaways

  • One human using one agent seems far more effective than one human using thousands of agents
  • One agent can work on a single codebase for hours, making real progress on ambitious projects
  • This could probably scale to multiple humans too, each equipped with their own agent, imagine what we could achieve!
  • Sometimes slower is faster and also better
  • The human who drives the agent might matter more than how the agents work and are set up, the judge is still out on this one

If one person with one agent can produce equal or better results than "hundreds of agents for weeks", then the answer to the question: "Can we scale autonomous coding by throwing more agents at a problem?", probably has a more pessimistic answer than some expected.

Versions
2026-01-27 7916ba2 I'm apparently very bad at spelling, luckily :set spell exists