0
0
site: the owner's page back (video, diagram, his text); one source link
site/.gitignore+1−0
| @@ -1 +1,2 @@ | ||
out/ | ||
node_modules/ | ||
site/build.sh+17−3
| @@ -1,7 +1,21 @@ | ||
#!/bin/sh | ||
# Renders README.md and the user docs to site/out, the tree of https://socialweb.computer/ (marked: site/deno.json, | ||
# locked by site/deno.lock; deno: site/deno.sh). | ||
# Renders site/index.md (with README.md sections spliced in) and the user docs to site/out, the tree of | ||
# https://socialweb.computer/. marked, mermaid and puppeteer-core: site/deno.json, locked by site/deno.lock; deno: | ||
# site/deno.sh; the mermaid diagrams become inline SVG in the pinned Chrome of tests/compositions/staging/page-tools.json | ||
# (PATH's google-chrome, or $CHROME, when it is that version, else the one tools.sh fetches and checks by its sha256). | ||
# site/build.sh | ||
set -eu | ||
cd "$(dirname "$0")/.." | ||
exec site/deno.sh run --config site/deno.json --allow-read=. --allow-write=site/out --allow-run=git site/build.ts | ||
pin=$(jq -er .chrome.version tests/compositions/staging/page-tools.json) | ||
chrome=${CHROME:-google-chrome} | ||
if ! "$chrome" --version 2>/dev/null | grep -qw "$pin"; then | ||
tools=$(SWC_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/socialweb-site" SWC_REPO="$PWD" bash tests/compositions/staging/tools.sh chrome) | ||
chrome=$tools/chrome/chrome | ||
fi | ||
chrome=$(command -v "$chrome") | ||
export TMPDIR="${TMPDIR:-$HOME/.tmp}" | ||
mkdir -p "$TMPDIR" | ||
site/deno.sh install --config site/deno.json --frozen >/dev/null | ||
SITE_CHROME=$chrome exec site/deno.sh run --config site/deno.json --frozen \ | ||
--allow-read --allow-write="site/out,$TMPDIR" --allow-run --allow-env --allow-sys --allow-net=127.0.0.1,localhost \ | ||
site/build.ts | ||
site/build.ts+148−55
| @@ -1,34 +1,28 @@ | ||
import { Marked } from "marked"; | ||
import puppeteer from "puppeteer-core"; | ||
| ||
const REPO = "https://knotless.dev/socialweb.computer/socialweb-computer-kcp"; | ||
const REF = "main"; | ||
const SITE = "socialweb.computer"; | ||
const PAGES = [ | ||
"README.md", | ||
"docs/README.md", | ||
"docs/quickstart-prod.md", | ||
"docs/quickstart-local.md", | ||
"docs/bidder.md", | ||
"docs/gateway.md", | ||
"docs/deploy.md", | ||
]; | ||
const EXTRA_LINKS = [ | ||
{ href: "https://blog.socialweb.computer", text: "blog" }, | ||
{ | ||
href: "https://docs.google.com/presentation/d/1hvM3jk-t_3vkjIXr1gJL1fmtUMhHm76369Vos3QumZU/edit", | ||
text: "2026-08-04 talk: slides", | ||
}, | ||
{ href: "https://asciinema.org/a/1262425", text: "recording" }, | ||
| ||
type Page = { src: string; as: string; out: string; raw: boolean; landing: boolean }; | ||
| ||
const PAGES: Page[] = [ | ||
{ src: "site/index.md", as: "README.md", out: "index.html", raw: true, landing: true }, | ||
...[ | ||
["docs/README.md", "docs/index.html"], | ||
["docs/quickstart-prod.md", "docs/quickstart-prod.html"], | ||
["docs/quickstart-local.md", "docs/quickstart-local.html"], | ||
["docs/bidder.md", "docs/bidder.html"], | ||
["docs/gateway.md", "docs/gateway.html"], | ||
["docs/deploy.md", "docs/deploy.html"], | ||
].map(([src, out]) => ({ src, as: src, out, raw: false, landing: false })), | ||
]; | ||
const OUT_OF = new Map(PAGES.map((p) => [p.as, p.out])); | ||
| ||
const root = new URL("..", import.meta.url).pathname.replace(/\/$/, ""); | ||
const out = `${root}/site/out`; | ||
| ||
function outPath(src: string): string { | ||
if (src === "README.md") return "index.html"; | ||
return src.replace(/(^|\/)README\.md$/, "$1index.html").replace(/\.md$/, ".html"); | ||
} | ||
| ||
function dirname(p: string): string { | ||
const i = p.lastIndexOf("/"); | ||
return i < 0 ? "" : p.slice(0, i); | ||
| @@ -49,8 +43,7 @@ function relative(fromFile: string, toFile: string): string { | ||
const to = toFile.split("/"); | ||
let i = 0; | ||
while (i < from.length && i < to.length - 1 && from[i] === to[i]) i++; | ||
const up = from.slice(i).map(() => ".."); | ||
let rel = [...up, ...to.slice(i)].join("/"); | ||
let rel = [...from.slice(i).map(() => ".."), ...to.slice(i)].join("/"); | ||
if (rel === "index.html") rel = "./"; | ||
else if (rel.endsWith("/index.html")) rel = rel.slice(0, -"index.html".length); | ||
return rel; | ||
| @@ -64,13 +57,14 @@ function isDir(path: string): boolean { | ||
} | ||
} | ||
| ||
function rewrite(src: string, href: string): string { | ||
function rewrite(page: Page, href: string): string { | ||
if (/^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith("#")) return href; | ||
const hash = href.indexOf("#"); | ||
const path = hash < 0 ? href : href.slice(0, hash); | ||
const frag = hash < 0 ? "" : href.slice(hash); | ||
const target = normalize(`${dirname(src)}/${path}`); | ||
if (PAGES.includes(target)) return relative(outPath(src), outPath(target)) + frag; | ||
const target = normalize(`${dirname(page.as)}/${path}`); | ||
const rendered = OUT_OF.get(target); | ||
if (rendered) return relative(page.out, rendered) + frag; | ||
const kind = path.endsWith("/") || isDir(target) ? "tree" : "blob"; | ||
return `${REPO}/${kind}/${REF}/${target}${frag}`; | ||
} | ||
| @@ -83,13 +77,53 @@ function slug(text: string): string { | ||
return text.toLowerCase().trim().replace(/<[^>]*>/g, "").replace(/[^\p{L}\p{N}\s_-]/gu, "").replace(/\s/g, "-"); | ||
} | ||
| ||
function render(src: string, md: string): { title: string; body: string } { | ||
const seen = new Map<string, number>(); | ||
function section(md: string, id: string, from: string): string { | ||
const lines = md.split("\n"); | ||
let fence = false; | ||
let start = -1; | ||
let level = 0; | ||
for (let i = 0; i < lines.length; i++) { | ||
if (/^(```|~~~)/.test(lines[i])) fence = !fence; | ||
const m = !fence && lines[i].match(/^(#{1,6})\s+(.*)$/); | ||
if (!m) continue; | ||
if (start >= 0 && m[1].length <= level) return lines.slice(start, i).join("\n").trim(); | ||
if (start < 0 && slug(m[2].replace(/`/g, "")) === id) { | ||
start = i + 1; | ||
level = m[1].length; | ||
} | ||
} | ||
if (start < 0) throw new Error(`${from}: no section #${id}`); | ||
return lines.slice(start).join("\n").trim(); | ||
} | ||
| ||
async function splice(md: string, page: Page): Promise<{ md: string; ids: string[] }> { | ||
const ids: string[] = []; | ||
const parts: string[] = []; | ||
let last = 0; | ||
for (const m of md.matchAll(/^<!--\s*([\w./-]+\.md)#([\w-]+)\s*-->$/gm)) { | ||
const file = normalize(`${dirname(page.as)}/${m[1]}`); | ||
const body = section(await Deno.readTextFile(`${root}/${file}`), m[2], page.src); | ||
ids.push(m[2]); | ||
parts.push(md.slice(last, m.index), `<span id="${m[2]}"></span>\n\n${body}`); | ||
last = m.index! + m[0].length; | ||
} | ||
parts.push(md.slice(last)); | ||
return { md: parts.join(""), ids }; | ||
} | ||
| ||
const CALLOUTS: Record<string, string> = { NOTE: "Note", TIP: "Tip", IMPORTANT: "Important", WARNING: "Warning", CAUTION: "Caution" }; | ||
| ||
type Rendered = { page: Page; title: string; body: string }; | ||
const diagrams: string[] = []; | ||
| ||
async function render(page: Page): Promise<Rendered> { | ||
const spliced = await splice(await Deno.readTextFile(`${root}/${page.src}`), page); | ||
const seen = new Map<string, number>(spliced.ids.map((id) => [id, 1])); | ||
let title = ""; | ||
const marked = new Marked({ gfm: true }); | ||
marked.use({ | ||
walkTokens(token) { | ||
if (token.type === "link") token.href = rewrite(src, token.href); | ||
if (token.type === "link") token.href = rewrite(page, token.href); | ||
}, | ||
renderer: { | ||
heading({ tokens, depth, text }) { | ||
| @@ -99,11 +133,24 @@ function render(src: string, md: string): { title: string; body: string } { | ||
const n = seen.get(base) ?? 0; | ||
seen.set(base, n + 1); | ||
const id = n ? `${base}-${n}` : base; | ||
const inner = this.parser.parseInline(tokens); | ||
return `<h${depth} id="${id}"><a class="anchor" href="#${id}">${inner}</a></h${depth}>\n`; | ||
return `<h${depth} id="${id}"><a class="anchor" href="#${id}">${this.parser.parseInline(tokens)}</a></h${depth}>\n`; | ||
}, | ||
html({ text }) { | ||
return escape(text); | ||
return page.raw ? text : escape(text); | ||
}, | ||
code({ text, lang }) { | ||
if ((lang ?? "").split(/\s/)[0] === "mermaid") { | ||
diagrams.push(text); | ||
return `<!--diagram:${diagrams.length - 1}-->\n`; | ||
} | ||
return false; | ||
}, | ||
blockquote({ tokens }) { | ||
const body = this.parser.parse(tokens); | ||
const m = body.match(/^<p>\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(<\/p>\s*)?/); | ||
if (!m) return `<blockquote>\n${body}</blockquote>\n`; | ||
const rest = m[2] ? body.slice(m[0].length) : `<p>${body.slice(m[0].length)}`; | ||
return `<div class="callout ${m[1].toLowerCase()}"><p class="callout-title">${CALLOUTS[m[1]]}</p>\n${rest}</div>\n`; | ||
}, | ||
table(token) { | ||
const head = token.header.map((c) => `<th>${this.parser.parseInline(c.tokens)}</th>`).join(""); | ||
| @@ -112,8 +159,37 @@ function render(src: string, md: string): { title: string; body: string } { | ||
}, | ||
}, | ||
}); | ||
const body = marked.parse(md, { async: false }) as string; | ||
return { title: title || src, body }; | ||
const body = marked.parse(spliced.md, { async: false }) as string; | ||
return { page, title: title || page.src, body }; | ||
} | ||
| ||
async function renderDiagrams(sources: string[]): Promise<string[]> { | ||
if (!sources.length) return []; | ||
const chrome = Deno.env.get("SITE_CHROME"); | ||
if (!chrome) throw new Error("SITE_CHROME is not set (site/build.sh sets it)"); | ||
const mermaid = await Deno.readTextFile(`${root}/site/node_modules/mermaid/dist/mermaid.min.js`); | ||
const profile = await Deno.makeTempDir({ prefix: "site-chrome-" }); | ||
const browser = await puppeteer.launch({ | ||
executablePath: chrome, | ||
headless: true, | ||
userDataDir: profile, | ||
args: ["--no-sandbox", "--disable-dev-shm-usage"], | ||
}); | ||
try { | ||
const tab = await browser.newPage(); | ||
await tab.setContent("<!doctype html><html><body></body></html>"); | ||
await tab.addScriptTag({ content: mermaid }); | ||
return await tab.evaluate(async (codes: string[]) => { | ||
const m = (globalThis as unknown as { mermaid: { initialize(c: unknown): void; render(id: string, code: string): Promise<{ svg: string }> } }).mermaid; | ||
m.initialize({ startOnLoad: false, theme: "default", securityLevel: "strict", fontFamily: "Arial, Helvetica, sans-serif" }); | ||
const svgs: string[] = []; | ||
for (let i = 0; i < codes.length; i++) svgs.push((await m.render(`diagram-${i}`, codes[i])).svg); | ||
return svgs; | ||
}, sources); | ||
} finally { | ||
await browser.close(); | ||
await Deno.remove(profile, { recursive: true }).catch(() => {}); | ||
} | ||
} | ||
| ||
async function git(...args: string[]): Promise<string> { | ||
| @@ -122,28 +198,23 @@ async function git(...args: string[]): Promise<string> { | ||
return new TextDecoder().decode(r.stdout).trim(); | ||
} | ||
| ||
function page(src: string, title: string, body: string, commit: string, tagline: string, css: string): string { | ||
const here = outPath(src); | ||
function shell(r: Rendered, commit: string, tagline: string): string { | ||
const here = r.page.out; | ||
const nav = [ | ||
{ href: REPO, text: "repository" }, | ||
{ href: relative(here, "index.html"), text: "README" }, | ||
...(r.page.landing ? [] : [{ href: relative(here, "index.html"), text: "home" }]), | ||
{ href: relative(here, "docs/index.html"), text: "docs" }, | ||
{ href: `${REPO}/blob/${REF}/${src}`, text: "this page's source" }, | ||
...(r.page.landing ? [] : [{ href: REPO, text: "source" }]), | ||
]; | ||
const a = (l: { href: string; text: string }) => `<a href="${escape(l.href)}">${escape(l.text)}</a>`; | ||
const short = commit.slice(0, 12); | ||
const commitLink = commit.endsWith("-dirty") | ||
? escape(commit) | ||
: `<a href="${REPO}/commit/${commit}">${short}</a>`; | ||
return `<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta name="description" content="${escape(tagline)}"> | ||
<title>${escape(src === "README.md" ? SITE : `${title} - ${SITE}`)}</title> | ||
<title>${escape(r.page.landing ? SITE : `${r.title} - ${SITE}`)}</title> | ||
<link rel="icon" href="data:,"> | ||
<link rel="stylesheet" href="${relative(here, css)}"> | ||
<link rel="stylesheet" href="${relative(here, "style.css")}"> | ||
</head> | ||
<body> | ||
<header> | ||
| @@ -152,30 +223,52 @@ function page(src: string, title: string, body: string, commit: string, tagline: | ||
<nav>${nav.map(a).join("\n")}</nav> | ||
</header> | ||
<main> | ||
${body}</main> | ||
${r.body}</main> | ||
<footer> | ||
<p>Rendered from <code>${escape(src)}</code> of ${a({ href: REPO, text: "socialweb-computer-kcp" })} at commit ${commitLink}. Unlicense (public domain).</p> | ||
<p>${EXTRA_LINKS.map(a).join(" | ")}</p> | ||
<p>Built from commit <code>${escape(commit.slice(0, 12))}${commit.endsWith("-dirty") ? "-dirty" : ""}</code>. Unlicense (public domain).</p> | ||
</footer> | ||
</body> | ||
</html> | ||
`; | ||
} | ||
| ||
function anchorsOk(pages: Map<string, string>): string[] { | ||
const bad: string[] = []; | ||
const ids = new Map([...pages].map(([p, html]) => [p, new Set([...html.matchAll(/ id="([^"]+)"/g)].map((m) => m[1]))])); | ||
for (const [p, html] of pages) { | ||
for (const m of html.matchAll(/href="([^"]+)"/g)) { | ||
const u = new URL(m[1].replace(/&/g, "&"), `https://${SITE}/${p}`); | ||
if (u.host !== SITE) continue; | ||
let path = u.pathname.slice(1); | ||
if (path === "" || path.endsWith("/")) path += "index.html"; | ||
if (!ids.has(path) && path !== "style.css") bad.push(`${p}: ${m[1]}: no page`); | ||
else if (u.hash && !ids.get(path)?.has(decodeURIComponent(u.hash.slice(1)))) bad.push(`${p}: ${m[1]}: no anchor`); | ||
} | ||
} | ||
return bad; | ||
} | ||
| ||
const head = await git("rev-parse", "HEAD"); | ||
const dirty = (await git("status", "--porcelain", "--", ...PAGES, "site")) !== ""; | ||
const dirty = (await git("status", "--porcelain", "--", "README.md", ...PAGES.map((p) => p.src), "site")) !== ""; | ||
const commit = dirty ? `${head}-dirty` : head; | ||
const readme = await Deno.readTextFile(`${root}/README.md`); | ||
const tagline = (readme.split(/\n\s*\n/).find((p) => p.trim() && !p.startsWith("#")) ?? "") | ||
.replace(/\s+/g, " ").replace(/`/g, "").trim().split(/(?<=\.) /)[0]; | ||
| ||
const rendered: Rendered[] = []; | ||
for (const page of PAGES) rendered.push(await render(page)); | ||
const svgs = await renderDiagrams(diagrams); | ||
const html = new Map<string, string>(); | ||
for (const r of rendered) { | ||
r.body = r.body.replace(/<!--diagram:(\d+)-->/g, (_, i) => `<figure class="diagram">${svgs[Number(i)]}</figure>`); | ||
html.set(r.page.out, shell(r, commit, tagline)); | ||
} | ||
const bad = anchorsOk(html); | ||
if (bad.length) throw new Error(`dangling links:\n${bad.join("\n")}`); | ||
| ||
await Deno.remove(out, { recursive: true }).catch(() => {}); | ||
await Deno.mkdir(`${out}/docs`, { recursive: true }); | ||
await Deno.copyFile(`${root}/site/style.css`, `${out}/style.css`); | ||
for (const src of PAGES) { | ||
const md = await Deno.readTextFile(`${root}/${src}`); | ||
const { title, body } = render(src, md); | ||
await Deno.writeTextFile(`${out}/${outPath(src)}`, page(src, title, body, commit, tagline, "style.css")); | ||
} | ||
for (const [p, h] of html) await Deno.writeTextFile(`${out}/${p}`, h); | ||
await Deno.writeTextFile(`${out}/COMMIT`, `${commit}\n`); | ||
console.log(`built ${out} from ${commit}: ${PAGES.length} pages`); | ||
console.log(`built ${out} from ${commit}: ${html.size} pages, ${svgs.length} diagrams`); | ||
site/deno.json+4−2
| @@ -1,10 +1,12 @@ | ||
{ | ||
"imports": { | ||
"marked": "npm:marked@18.0.5" | ||
"marked": "npm:marked@18.0.5", | ||
"mermaid": "npm:mermaid@11.17.2", | ||
"puppeteer-core": "npm:puppeteer-core@23.11.1" | ||
}, | ||
"lock": { | ||
"path": "deno.lock", | ||
"frozen": true | ||
}, | ||
"nodeModulesDir": "none" | ||
"nodeModulesDir": "auto" | ||
} | ||
site/deno.lock+1083−2
1085 lines changed: not loaded until asked for.
site/index.mdnew+328−0
| @@ -0,0 +1,328 @@ | ||
# Compute Contracts - Pre-Alpha | ||
| ||
- [Blog](https://blog.socialweb.computer) | ||
- [Deck: ATproto PDX: 2026-08-04: Compute Contracts](https://docs.google.com/presentation/d/1hvM3jk-t_3vkjIXr1gJL1fmtUMhHm76369Vos3QumZU/edit) | ||
- [source](https://knotless.dev/socialweb.computer/socialweb-computer-kcp) | ||
- Asciinema version of the following video: <https://asciinema.org/a/1262425> | ||
| ||
<iframe width="100%" height="auto" style="aspect-ratio:16/9" src="https://www.youtube-nocookie.com/embed/LftvIIfQPtU" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> | ||
| ||
This is a spec for ATProto accounts to request and advertise (compute) | ||
resources. | ||
| ||
This spec is for you if you run an organization and want to leverage | ||
decentralized identity to allow access to your org's compute (and in the future | ||
more) resources to your members and their workloads/agents. | ||
| ||
The flow is: Request For Proposal -> Bid -> Accept -> Receipt | ||
| ||
> [!CAUTION] | ||
> | ||
> This is pre-alpha software and it has yet to have a thorough review!!! | ||
> Multiple passes of refactors were done and while things work they are just to | ||
> play with right now! The compute contract flow can be considered proven. | ||
> However, there is a lot of security pieces involved here and they need to be | ||
> gone through with a fine toothed comb before Alpha. Please consider re-writing | ||
> everything using your favorite LLM etc. let's please have many | ||
> implementations! :D | ||
| ||
## Quickstart | ||
| ||
<!-- README.md#install --> | ||
| ||
### Ephemeral Accounts with association records | ||
| ||
A bidder gets a DID of its own and an association record that makes it an | ||
agent of your ATProto account once you sign in when prompted (scan the QR code / | ||
open the link in the logs). It bids only for requesters you vouch for. | ||
| ||
#### Bid on compute contracts | ||
| ||
<!-- README.md#run-a-bidder --> | ||
| ||
### Try a local market | ||
| ||
<!-- README.md#try-a-local-market --> | ||
| ||
## BlueSky Accounts via QR Code Session Transfer | ||
| ||
Both operators scan the QR codes from their own processes using the | ||
did-key-associator webapp at <https://qr.fedfork.com>. | ||
| ||
#### Request Compute | ||
| ||
<!-- README.md#rent-a-vm --> | ||
| ||
## Secrets | ||
| ||
To send secrets to the VM without putting them in cloud-init (public ATproto | ||
data), just pass a JSON file to `--secrets`: | ||
| ||
For example, if you wanted to send your https://cocore.dev token to a new VM you | ||
could do it like so: | ||
| ||
```bash | ||
# Set ATP_HANDLE and ATP_PASSWORD for goat account login or provide like so: | ||
goat account login -u "aliceoa.bsky.social" -p "aaaa-aaaa-aaaa-aaaa" | ||
| ||
TOKEN=$(goat account service-auth \ | ||
--lxm dev.cocore.account.createApiKey \ | ||
--aud did:web:appview.cocore.dev) | ||
| ||
PI_CONFIG=$(curl -sS -X POST \ | ||
-H "Authorization: Bearer ${TOKEN}" \ | ||
-H "Content-Type: application/json" \ | ||
'https://appview.cocore.dev/xrpc/dev.cocore.account.createApiKey' \ | ||
-d '{"name":"my-pi"}' | jq -r '{"apiKey": .secret}') | ||
| ||
socialweb-computer run request --name pi \ | ||
--secrets <(jq -n \ | ||
--arg pi "${PI_CONFIG}" \ | ||
--arg provider "cocore" \ | ||
--arg model "mlx-community/Ornith-1.0-9B-4bit" \ | ||
'[ | ||
{ | ||
path: "/root/.pi/agent/cocore-config.json", | ||
value: $pi, | ||
}, | ||
{ | ||
"path": "/root/.pi/agent/settings.json", | ||
"value": { | ||
"defaultProvider": $provider, | ||
"defaultModel": $model | ||
} | ||
} | ||
]') \ | ||
-- --atproto-oauth-qr | ||
``` | ||
| ||
Here's a quick `jq` example of using env var names as arguments instead of | ||
writing each one out (then you'd pass `--secrets /tmp/secrets.json`): | ||
| ||
```bash | ||
jq -n --args '[$ARGS.positional[] | {path: ("/root/secrets/" + ascii_downcase), value: env[.]}]' \ | ||
SOME_API_KEY OTHER_ENV_VAR > /tmp/secrets.json | ||
``` | ||
| ||
Passing secrets this way works by leveraging Workload Identity Federation. We | ||
thereby avoid storing anything sensitive in the public `compute.vm` record. | ||
| ||
- Each bid's config carries a | ||
`com.publicdomainrelay.temp.compute.config.wif.simple` instance which | ||
tells the requester prior to accept what the OIDC issuer will be for the VM | ||
and how it's `sub` (subject) claim will be formatted. | ||
| ||
- This means that if a contract fails, aka the VM disappears for whatever | ||
reason. We can turn around and *accept a different bid* from another | ||
provider! This loose coupling of Workload Identity Federation configuration | ||
information ensures we can even preemptively spin more than one instance of | ||
the compute we are requesting for resiliency. The following repo has an | ||
in-depth exploitation of how workload identity works: | ||
[droplet-oidc-poc](https://github.com/digitalocean-labs/droplet-oidc-poc). | ||
| ||
- `--secrets` puts the bundle in the requester's own vault (OpenBao), and the | ||
requester serves it from its ingress only for the contract. | ||
| ||
- It also adds a script to the VM's cloud-init `user_data` so that When the VM | ||
starts, it makes a request to the requester using a token retrieved via | ||
token-exchange from the bidder/compute-provider's Workload Identity issuer. | ||
| ||
- Access to the secrets is then gated by an RBAC policy which ensures that the | ||
token the VM passes to the requester belongs to our newly spun | ||
VM per the bid config Workload Identity Federation (WIF) record. | ||
| ||
## Protocol | ||
| ||
```mermaid | ||
sequenceDiagram | ||
autonumber | ||
actor Alice | ||
actor Bob | ||
| ||
rect rgb(240, 248, 255) | ||
Note over Alice,Bob: Request For Proposal (RFP) | ||
Alice->>Bob: createRecord: compute.vm<br/>(CPUs, Memory, Disk, etc.) | ||
Alice->>Bob: createRecord: rfp<br/>(strongRef to compute.vm) | ||
end | ||
| ||
rect rgb(245, 245, 245) | ||
Note over Alice,Bob: Bid | ||
Bob->>Alice: createRecord: bids.free (or x402)<br/>(determine price) | ||
Bob->>Alice: createRecord: bid<br/>(strongRef to RFP + payment type) | ||
end | ||
| ||
rect rgb(240, 248, 255) | ||
Note over Alice,Bob: Accept | ||
Note over Alice: Payment Settlement Flow (NOP if bids.free) | ||
Alice->>Bob: createRecord: accept<br/>(strongRef to RFP + Bid + receipt-of-payment) | ||
end | ||
| ||
rect rgb(245, 245, 255) | ||
Note over Alice,Bob: Receipt | ||
Note over Bob: Provision Compute | ||
Bob->>Alice: createRecord: receipt<br/>(strongRef to RFP + Bid + Accept) | ||
Bob->>Alice: createRecord: compute.events.vm.onNetwork<br/>(address: public IP or proxied FQDN) | ||
Bob->>Alice: createRecord: market.event<br/>(strongRef to onNetwork + receipt) | ||
end | ||
| ||
Note over Alice: Connect to compute at/via address | ||
``` | ||
| ||
- Alice, Bob, and Eve are on the network | ||
- Alice wants to issue a Compute Contract Request For Proposal (CCRFP) | ||
- Alice's CCRFP will state she wants an OpenCode instance | ||
- Bob has plenty of builder machines | ||
- Eve wants to know what Alice is doing | ||
- Alice has vouched for Bob | ||
- Alice has denounced Eve | ||
- Alice creates a CCRFP manifest (the VM-specific payload: cpus, mem, disk, | ||
cloud-init `user_data`, ...) | ||
- Alice wraps her CCRFP in a top-level RFP record (`domain: "compute"`, | ||
`payload` is a strongRef to the CCRFP). The RFP is the domain-tagged envelope | ||
bidders and indexers route on; the CCRFP is the inner VM-specific record. | ||
- Alice makes her RFP/CCRFP pair available to the network | ||
- Bob and Eve each issue a Compute Contract Bid (CCB) against the CCRFP | ||
- Alice's policy engine sees that she's denounced Eve and vouched for Bob | ||
- Alice issues a Compute Contract Bid Accept (CCBA) against Bob's CCB. | ||
- Alice issues a x402 payment to Bob per info provided in his CCB. | ||
- Using the CCBA AT URI and CID to the CCB's stated CCR endpoint. | ||
- Bob issues a Compute Contract Receipt (CCR) over the CCRFP, CCB, and CCBA | ||
- The CCR references the CCRFP, the CCB, and the CCBA. | ||
- Bob builds to the CCRFP manifest's spec | ||
| ||
### Compute Contract Flow (High level) | ||
| ||
The compute contract flow can be executed purely over the firehose/relays. | ||
That's what we'll cover in this section. For more details see the | ||
open-architecture repo's [`COMPUTE_CONTRACT_FLOW_MAP.md`](https://github.com/publicdomainrelay/open-architecture/blob/main/COMPUTE_CONTRACT_FLOW_MAP.md). | ||
| ||
All `market.*` records use https://badge.blue signatures, not shown here for | ||
brevity. | ||
| ||
Alice createRecord's the type of compute she wants | ||
| ||
```yaml | ||
$type: com.publicdomainrelay.temp.compute.vm | ||
cpus: 2 | ||
mem: 4G | ||
disk: 40G | ||
network: 500G | ||
role: my-cool-role | ||
user_data: | | ||
#cloud-config | ||
runcmd: | ||
- [sh, -c, "echo hello world"] | ||
location: | ||
country: USA | ||
region: west | ||
``` | ||
| ||
Alice createRecord's a Request For Proposal (**rfp**) `strongRef`erencing the | ||
compute she wants. | ||
| ||
```yaml | ||
$type: com.publicdomainrelay.temp.market.rfp | ||
payload: | ||
$type: com.atproto.repo.strongRef | ||
uri: at://did:plc:alice/com.publicdomainrelay.temp.compute.vm/3mm3dolfolz2c | ||
cid: bafyrei...vm | ||
``` | ||
| ||
Bob decides what he wants Alice to pay for the compute and createRecord's the | ||
payment type for his bid. | ||
| ||
```yaml | ||
$type: com.publicdomainrelay.temp.market.bids.free | ||
reason: free | ||
# Can also do x402 but haven't tested this in a while: | ||
# $type: com.publicdomainrelay.temp.market.bids.x402 | ||
# cost: 100000 (0.10 USDC, in the currency's smallest unit) | ||
# currency: USDC | ||
# frequency: hourly | ||
# prepay: true | ||
# url: https://compute-contract.bob.example/receipt | ||
``` | ||
| ||
Bob createRecord's a Bid (**bid**) `strongRef`erencing the compute she | ||
wants. | ||
| ||
```yaml | ||
$type: com.publicdomainrelay.temp.market.bid | ||
rfp: | ||
$type: com.atproto.repo.strongRef | ||
uri: at://did:plc:alice/com.publicdomainrelay.temp.market.rfp/3mm3doliee72s | ||
cid: bafyrei...rfp | ||
payload: | ||
$type: com.atproto.repo.strongRef | ||
uri: at://did:plc:bob/com.publicdomainrelay.temp.market.bids.x402/3mm4... | ||
cid: bafyrei...x402 | ||
``` | ||
| ||
Alice settles the payment and gets a payment receipt according to settlement | ||
sub-flow. If `bids.free`, then that's a NOP. | ||
| ||
> [!NOTE] | ||
> | ||
> Settlement subflow hasn't been tested in a while for x402 and these docs will | ||
> be updated in the future once we re-test and validate. We're focusing on orgs | ||
> who want to distribute compute to their members in an ATProto native way for | ||
> free first. | ||
| ||
Alice then createRecord's an Accept (**accept**) record which wraps her | ||
proof-of-payment receipt (only if not `bids.free`) | ||
| ||
```yaml | ||
$type: com.publicdomainrelay.temp.market.accept | ||
rfp: | ||
$type: com.atproto.repo.strongRef | ||
uri: at://did:plc:alice/com.publicdomainrelay.temp.market.rfp/3mm3doliee72s | ||
cid: bafyrei...rfp | ||
bid: | ||
$type: com.atproto.repo.strongRef | ||
uri: at://did:plc:bob/com.publicdomainrelay.temp.market.bid/3mm4... | ||
cid: bafyrei...bid | ||
``` | ||
| ||
Finally, Bob provisions the compute and issues a Receipt (**receipt**) when he | ||
sees the Accept. | ||
| ||
```yaml | ||
$type: com.publicdomainrelay.temp.market.receipt | ||
rfp: | ||
$type: com.atproto.repo.strongRef | ||
uri: at://did:plc:alice/com.publicdomainrelay.temp.market.rfp/3mm3doliee72s | ||
cid: bafyrei...rfp | ||
bid: | ||
$type: com.atproto.repo.strongRef | ||
uri: at://did:plc:bob/com.publicdomainrelay.temp.market.bid/3mm4... | ||
cid: bafyrei...bid | ||
accept: | ||
$type: com.atproto.repo.strongRef | ||
uri: at://did:plc:alice/com.publicdomainrelay.temp.market.accept/3mlagijgoeb23 | ||
cid: bafyrei...accept | ||
cid: bafyrei...attestation | ||
``` | ||
| ||
Alice then awaits the onNetwork event | ||
| ||
```yaml | ||
$type: com.publicdomainrelay.temp.compute.events.vm.onNetwork | ||
kind: iroh | ||
address: <the VM's iroh ticket> | ||
``` | ||
| ||
```yaml | ||
$type: com.publicdomainrelay.temp.market.event | ||
payload: | ||
cid: bafyreihp5j7tc6xbj4yqnzanwjsqfqasazqr6cbdthuwni3xdrgy2ymmeq | ||
uri: at://did:plc:5svqtrhheairglgiiyvutzik/com.publicdomainrelay.temp.compute.events.vm.onNetwork/3mqqgq57oss26 | ||
$type: com.atproto.repo.strongRef | ||
receipt: | ||
cid: bafyreicpqkmnigboxueqaa2y6lvn7b5qjaiw46jb6mqgymlahpl3v5fal4 | ||
uri: at://did:plc:5svqtrhheairglgiiyvutzik/com.publicdomainrelay.temp.market.receipt/3mqqgpxvfls26 | ||
$type: com.atproto.repo.strongRef | ||
``` | ||
| ||
## Docs | ||
| ||
<!-- README.md#docs --> | ||
site/README.md+13−7
| @@ -1,13 +1,19 @@ | ||
# site | ||
| ||
The source of https://socialweb.computer/: `build.ts` renders [README.md](../README.md) to `out/index.html` and the | ||
user docs (`docs/README.md`, `docs/quickstart-prod.md`, `docs/quickstart-local.md`, `docs/bidder.md`, | ||
`docs/gateway.md`, `docs/deploy.md`) to `out/docs/`, so the page is the README of the commit it was built from. A link | ||
to a rendered doc goes to its page; any other repository link goes to the file on | ||
https://knotless.dev/socialweb.computer/socialweb-computer-kcp (main). The footer and `out/COMMIT` name the commit. | ||
The source of https://socialweb.computer/. The landing page is [index.md](index.md): the owner's Compute Contracts page | ||
(first written as the publicdomainrelay org-root README), with the current commands spliced in at build time from | ||
[README.md](../README.md) sections, so they cannot drift: a line `<!-- README.md#<heading id> -->` becomes that | ||
section's body. `build.ts` renders it to `out/index.html`, and the user docs (`docs/README.md`, | ||
`docs/quickstart-prod.md`, `docs/quickstart-local.md`, `docs/bidder.md`, `docs/gateway.md`, `docs/deploy.md`) to | ||
`out/docs/`. A link to a rendered doc (or to README.md) goes to its page; any other repository link goes to the file on | ||
https://knotless.dev/socialweb.computer/socialweb-computer-kcp (main); the build fails on a link to a missing page or | ||
anchor. A ```` ```mermaid ```` block becomes an inline SVG at build time (no script on the page). The footer and | ||
`out/COMMIT` name the commit. | ||
| ||
Dependencies: jq, git, the deno pinned in `tests/compositions/staging/page-tools.json` (`deno.sh` uses PATH's when it | ||
is that version, else fetches it and checks its sha256), and marked pinned in `deno.json` and locked in `deno.lock`. | ||
Dependencies, all pinned: jq, git; deno and Chrome as pinned in `tests/compositions/staging/page-tools.json` (`deno.sh` | ||
and `build.sh` use PATH's `deno` and `google-chrome` when they are those versions, else fetch them with | ||
`tests/compositions/staging/tools.sh`, which checks their sha256; Chrome for Testing is linux/amd64 only); marked, | ||
mermaid and puppeteer-core in `deno.json`, locked in `deno.lock`. | ||
| ||
Build, then look at `site/out/index.html`: | ||
| ||
site/style.css+52−0
| @@ -125,6 +125,58 @@ th, td { | ||
vertical-align: top; | ||
} | ||
| ||
iframe { | ||
display: block; | ||
max-width: 100%; | ||
border: 0; | ||
margin: 1rem 0; | ||
} | ||
| ||
figure.diagram { | ||
margin: 1rem 0; | ||
padding: 0.75rem; | ||
background: #ffffff; | ||
border: 1px solid var(--border); | ||
border-radius: 6px; | ||
overflow-x: auto; | ||
} | ||
| ||
figure.diagram svg { | ||
display: block; | ||
margin: 0 auto; | ||
height: auto; | ||
} | ||
| ||
.callout { | ||
border-left: 4px solid var(--border); | ||
padding: 0.25rem 1rem; | ||
margin: 1rem 0; | ||
} | ||
| ||
.callout-title { | ||
font-weight: 700; | ||
margin: 0.5rem 0 0; | ||
} | ||
| ||
.callout.caution, .callout.warning { | ||
border-left-color: #cf222e; | ||
} | ||
| ||
.callout.note { | ||
border-left-color: #0969da; | ||
} | ||
| ||
.callout.tip { | ||
border-left-color: #1a7f37; | ||
} | ||
| ||
blockquote { | ||
border-left: 4px solid var(--border); | ||
margin: 1rem 0; | ||
padding: 0 1rem; | ||
color: var(--muted); | ||
} | ||
| ||
footer { | ||
border-top: 1px solid var(--border); | ||
margin-top: 3rem; | ||
AGENTS.md+1−1
| @@ -46,7 +46,7 @@ Go: | ||
| `rust/` | socialweb-meshd | | ||
| `did-key-associator/` | the QR session-transfer service (qr.fedfork.com): static page and deno backend, vendored 2026-11-18 with its history from github.com/publicdomainrelay/did-key-associator (0a48e76); deployed by `infra/did-key-associator` | | ||
| `typescript-helpers/` | the deno libraries did-key-associator imports by relative path (`../typescript-helpers/lib/{oauth-scope,cli-args-env,logger,serve}`), vendored 2026-11-18 with its history from github.com/publicdomainrelay/typescript-helpers (3fae6da) | | ||
| `site/` | https://socialweb.computer/: README.md and the user docs rendered to static pages (`site/build.sh`), deployed by hand with `site/deploy.sh` (`site/README.md`); in no CI workflow's `paths:` | | ||
| `site/` | https://socialweb.computer/: the landing page (`site/index.md`, the owner's text; README sections spliced in at build) and the user docs rendered to static pages (`site/build.sh`; mermaid drawn at build), deployed by hand with `site/deploy.sh` (`site/README.md`); in no CI workflow's `paths:` | | ||
| `tests/` | the Rust system integration tests: `testkit` (harness), `system` (runbook ports), `targets/`; `vmm` (the VMM wrapper on a KVM host, `-p swc-vmm-tests`) | | ||
| ||
TypeScript: | ||