Go implementation of DeepSeek Harness and self-hosted personal agent.
Go
#!/usr/bin/env python3
"""Regenerate the embedded upstream HTML renderer from a pinned checkout."""
import pathlib
import shutil
import subprocess
import sys
import tempfile
ROOT = pathlib.Path(__file__).resolve().parent.parent
COMMIT = "fcc0ad462172522aaf5c93a7b2e01f6b9f0b0159"
UPSTREAM_PATH = "packages/web/tool-web/src"
def source(checkout, name):
return subprocess.check_output(
["git", "-C", checkout, "show", f"{COMMIT}:{UPSTREAM_PATH}/{name}.ts"],
text=True,
)
def main():
if len(sys.argv) != 2:
raise SystemExit("usage: python3 scripts/build-web-markdown.py UPSTREAM_CHECKOUT")
checkout = pathlib.Path(sys.argv[1]).resolve()
fetch = source(checkout, "fetch")
trust = source(checkout, "trust").replace("export const ", "const ")
rules = fetch[fetch.index("const turndown ="):fetch.index("/**\n * Validate value constraints")]
render = fetch[fetch.index("const MAX_CONVERSION_DEPTH ="):fetch.index("/**\n * Format a fetch result")]
with tempfile.TemporaryDirectory(prefix="web-markdown-") as temp:
build = pathlib.Path(temp)
for name in ("package.json", "package-lock.json"):
shutil.copyfile(ROOT / "build/web-markdown" / name, build / name)
subprocess.run(["npm", "ci", "--ignore-scripts", "--no-audit", "--no-fund"], cwd=build, check=True)
entry = build / "render.ts"
entry.write_text(
"import TurndownService from 'turndown'\n"
"import {gfm} from '@joplin/turndown-plugin-gfm'\n"
"function assertNever(): never { throw new Error('unexpected fetch body kind') }\n"
+ trust + rules + render
+ "\nObject.assign(globalThis, { renderWebFetch: computeFetchOutput })\n",
encoding="utf-8",
)
dest = ROOT / "internal/webmarkdown/render.js"
subprocess.run([
"go", "run", "github.com/evanw/esbuild/cmd/esbuild", str(entry),
"--bundle", "--platform=node", "--target=es2020", "--minify", "--legal-comments=none",
"--banner:js=// Generated by scripts/build-web-markdown.py. See THIRD_PARTY_NOTICES.md.",
f"--outfile={dest}",
], cwd=ROOT, check=True)
if __name__ == "__main__":
main()