From 443c808517e60dffc9c621eb315c075b43cd8b05 Mon Sep 17 00:00:00 2001 From: mola <2249464964@qq.com> Date: Thu, 29 Oct 2026 21:07:14 +0800 Subject: [PATCH] layerfs 0.10.0: the page's live channel returns, out of the install's own folder (#441) LayerFS's trajectory page is served by a loopback service the host starts once a store exists (no write into the install), keeps its view in location.hash across its 5 s reload, reports every skipped secret-shaped file in sorted order (#477), and drops the unloaded sample. By @Mola-maker. Run at dfa99f7e merged onto current main: - mote (macOS, Bun 1.4.2, temp HOME): bun test in packages/layerfs, 64 pass 0 fail, 2 of 2; bun scripts/check.mjs layerfs ok; the temp HOME held nothing from layerfs afterwards. - WSL2 Ubuntu 24.04 (temp HOME): 64 pass 0 fail, 2 of 2 (#477's item 3 was red here on f3633eaf8). - Broken by hand: dropping the `location.hash =` assignment in page/app.js turns the hash test red. Earlier rounds' breaks (Origin/Host checks, < escape, start gates, nosniff, sort, restore/settle/round, reload guard) each went red, see the 05:18 and 05:45 reviews. - Earlier round: the page in a magpie-shaped sandboxed frame with pagePolicy CSP, Chromium and WebKit. - PR checks: test and on-npm pass. Not tried: a real magpie window. --- packages/layerfs/README.md | 92 +++++++++-- packages/layerfs/icon.svg | 10 ++ packages/layerfs/index.mjs | 67 ++++++-- packages/layerfs/layerfs.mjs | 22 ++- packages/layerfs/layerfs.test.mjs | 213 +++++++++++++++++++++++++- packages/layerfs/no-magpie.test.mjs | 4 + packages/layerfs/package.json | 10 +- packages/layerfs/page-service.mjs | 162 ++++++++++++++++++++ packages/layerfs/page.test.mjs | 82 ++++++++-- packages/layerfs/page/app.js | 97 ++++++++++-- packages/layerfs/page/boot.js | 42 +++++ packages/layerfs/page/index.html | 65 ++------ packages/layerfs/page/style.css | 10 ++ packages/layerfs/page/trajectory.html | 73 +++++++++ packages/layerfs/page/trajectory.js | 1 - packages/layerfs/page/view.js | 60 +++++++- 16 files changed, 895 insertions(+), 115 deletions(-) create mode 100644 packages/layerfs/icon.svg create mode 100644 packages/layerfs/page-service.mjs create mode 100644 packages/layerfs/page/boot.js create mode 100644 packages/layerfs/page/trajectory.html delete mode 100644 packages/layerfs/page/trajectory.js diff --git a/packages/layerfs/README.md b/packages/layerfs/README.md index 6a56067..fadfef2 100644 --- a/packages/layerfs/README.md +++ b/packages/layerfs/README.md @@ -165,21 +165,54 @@ draws its own outline and fills in, a publish pops its Layer badge easing; with reduced motion preferred, the page simply shows the finished picture, every icon fully drawn. -A magpie page cannot read plugin-private data: its sandbox forbids -fetch, and the bridge's reads are a fixed host list (`usage:summary`, -`providers:list`) with no entry a plugin can serve its own data -through. So the page animates the sample bundled with it — -`page/trajectory.js`, a labeled recording from the benchmark scenario -(one project, six agents, three checkpoints each), a package asset -that nothing rewrites at runtime. The trajectory itself is computed -on demand from the store's records whenever it is asked for -(`backend.trajectory()`; `tools/gen-trajectory.mjs` uses it to make -the sample). No recording file is maintained per tool call: an +A magpie page cannot fetch, and the bridge's reads are a fixed host +list (`usage:summary`, `providers:list`) with no entry a plugin can +serve its own data through — but magpie lets a page navigate its +frame elsewhere, and pulls a plugin's host part up the moment its +page is requested, waiting up to 7 seconds for it (pageHost / +plugin.Warm). So the page's live channel is the host's own +localhost-only service (`page-service.mjs`), the way page-chat +serves its chat page: + +- **The installed page only jumps.** `page/index.html` does one + thing: it reads the port from the plugin's options + (`pagePort`, default 43717) and `location.replace`s its frame to + `http://127.0.0.1:/`. The install's folder is never + renamed, linked, or written into. A user with no store gets no + service and nothing written anywhere. +- **The service returns the page with its data inside.** Each + request rebuilds `backend.trajectory()` on demand and answers one + route, GET /, as HTML: the trajectory UI with the recording + embedded as `y" + await call("provision", { project: "website" }) + await call("checkpoint", { project: "website", message: evil }) + const { data, html } = await serviceData(url, + (x) => (x.projects.find((p) => p.name === "website")?.branches.find((b) => b.name === "main")?.commits ?? []) + .some((c) => c.message === evil)) + // the breakout is escaped in the raw HTML, and parses back whole + expect(html).not.toContain(" cannot break out of the data script. +// - Cache-Control: no-store, so each reload (the page reloads itself +// every few seconds for liveness) re-asks and gets fresh data. +import { createServer } from "node:http" +import { readFileSync } from "node:fs" +import { dirname, join } from "node:path" +import { fileURLToPath } from "node:url" + +// The default port, shared with page/boot.js's fallback (a static file +// cannot import it): the user may move it in the plugin's options +// (pagePort), and MAGPIE_LAYERFS_PAGE_PORT moves it for a test run. +export const DEFAULT_PAGE_PORT = 43717 + +export function resolvePagePort(options = {}, env = process.env) { + for (const raw of [options?.pagePort, env.MAGPIE_LAYERFS_PAGE_PORT]) { + const n = Number(raw) + if (Number.isInteger(n) && n > 0 && n < 65536) return n + } + return DEFAULT_PAGE_PORT +} + +const htmlLang = (lang) => { + const l = String(lang || "").toLowerCase() + if (l.startsWith("ja")) return "ja" + if (/^(zh-tw|zh-hk|zh-hant)/.test(l)) return "zh-TW" + if (l.startsWith("zh")) return "zh" + return "en" +} + +// Compose the served page from the shell and the UI files beside it: +// the shell carries two markers, one for the style, one for the +// scripts. Everything is inlined — the service has no asset routes to +// probe — and the data script sits before the UI scripts that read it. +function compose(pageDir, data, lang) { + const shell = readFileSync(join(pageDir, "trajectory.html"), "utf8") + const css = readFileSync(join(pageDir, "style.css"), "utf8") + const view = readFileSync(join(pageDir, "view.js"), "utf8") + const app = readFileSync(join(pageDir, "app.js"), "utf8") + if (!shell.includes("") || !shell.includes("")) + throw new Error("trajectory.html is missing its injection markers") + const json = JSON.stringify(data).replace(/', ``) + .replace("", ``) + .replace("", + `` + + `` + + ``) + // No reload script here: the page owns its own liveness tick (see + // app.js) — it must write the view into location.hash and skip the + // reload while the replay runs or the menu stands open, and a blind + // timer appended here would reset the view every 5 s regardless. +} + +// Start the service. backend answers trajectory(); port is the +// configured port (0 asks the OS for a free one, for tests). The +// returned listening promise resolves to { port, url } once bound, or +// null when the bind fails — a held port leaves no service, and the +// tools are untouched. close() stops the server. +export function startPageService({ backend, port, pageDir }) { + const dir = pageDir ?? join(dirname(fileURLToPath(import.meta.url)), "page") + const server = createServer(async (req, res) => { + const send = (code, body) => { + res.writeHead(code, { + "Content-Type": "text/html; charset=utf-8", + "X-Content-Type-Options": "nosniff", + "Cache-Control": "no-store", + }) + res.end(body) + } + const err = (code, text) => send(code, `LayerFS

${text}

`) + // The bound port, not the requested one: a test's port 0 binds + // elsewhere, and a Host naming the requested port must not pass. + const actual = server.address()?.port + if (!actual) { err(503, "not listening"); return } + const host = String(req.headers.host || "").toLowerCase() + if (host !== `127.0.0.1:${actual}` && host !== `localhost:${actual}`) { + err(403, "this service answers only its own loopback names") + return + } + if (req.headers.origin !== undefined) { + err(403, "this service answers navigations, not cross-origin reads") + return + } + let path = "", lang = "" + try { + const u = new URL(req.url, "http://127.0.0.1") + path = u.pathname + lang = u.searchParams.get("lang") || "" + } catch { /* a malformed target is not a route */ } + if (req.method !== "GET" || path !== "/") { err(404, "no such route"); return } + let data + try { data = await backend.trajectory() } catch { err(500, "the trajectory could not be read"); return } + let html + try { html = compose(dir, data, lang) } catch { err(500, "the page could not be composed"); return } + send(200, html) + }) + server.on("error", () => { /* a held port or a refused bind: no service */ }) + // Unref: a listening server must not keep a test process (or a host + // that is otherwise done) alive on its own — it still answers while + // the process lives for other reasons. + if (typeof server.unref === "function") server.unref() + const listening = new Promise((resolve) => { + server.once("listening", () => { + const p = server.address().port + resolve({ port: p, url: `http://127.0.0.1:${p}/` }) + }) + server.once("error", () => resolve(null)) + }) + server.listen(port, "127.0.0.1") + return { + server, + port, + url: `http://127.0.0.1:${port}/`, + listening, + close: () => new Promise((r) => server.close(() => r())), + } +} diff --git a/packages/layerfs/page.test.mjs b/packages/layerfs/page.test.mjs index 3178288..2c687f5 100644 --- a/packages/layerfs/page.test.mjs +++ b/packages/layerfs/page.test.mjs @@ -19,24 +19,34 @@ test("the package declares the page magpie shows", () => { expect(p.file).toBe("page/index.html") expect(p.icon).toBe("page/icon.svg") expect(pkg.files).toContain("page") - for (const f of ["index.html", "app.js", "view.js", "style.css", "icon.svg"]) + expect(pkg.files).toContain("page-service.mjs") + for (const f of ["index.html", "boot.js", "trajectory.html", "app.js", "view.js", "style.css", "icon.svg"]) expect(existsSync(join(page, f))).toBe(true) const html = read("index.html") expect(html).toContain("_magpie/bridge.js") // the host serves the bridge beside every page - expect(html).toContain('src="trajectory.js"') - expect(html).not.toContain("trajectory-live.js") // no runtime live file: the tools never write into the install folder - // the page sandbox forbids inline scripts and any fetch; the only - // data script is the bundled sample trajectory shipped with the page + // the installed page only jumps: it loads the bridge and the boot + // script, and nothing else — no data scripts, no inline scripts + expect(html).toContain('src="boot.js"') + expect(html).not.toContain('src="trajectory.js"') + expect(html).not.toContain('src="trajectory-live.js"') expect(html).not.toMatch(/ - - - + -
-
-

HISTORY

-

-
- -

-
- -
-
-
Checkpoints0 / 0
-
Branches0
-
as copies0 B
-
stored0 B
-
dedupe–
-
-
as copies
-
stored
-

-
- -
- - -
- - -
- - - - -
-
- -
-
-

-

-
- - +
LayerFS trajectoryConnecting to the local trajectory service…
+ + diff --git a/packages/layerfs/page/style.css b/packages/layerfs/page/style.css index 79b3c50..fd982b2 100644 --- a/packages/layerfs/page/style.css +++ b/packages/layerfs/page/style.css @@ -176,3 +176,13 @@ header { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; borde @media (prefers-reduced-motion: reduce) { #play { transition: none; } } + +/* Agent activity: the per-agent tool-call table under the replay */ +section.agents { margin-top: 22px; } +section.agents h2 { margin: 0 0 10px; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; opacity: .75; } +.agent-table { width: 100%; border-collapse: collapse; font-size: 12.5px; } +.agent-table th { text-align: left; font-weight: 600; opacity: .6; padding: 4px 10px; border-bottom: 1px solid var(--magpie-border, rgba(128,128,128,.25)); } +.agent-table td { padding: 5px 10px; border-bottom: 1px solid var(--magpie-border, rgba(128,128,128,.15)); font-variant-numeric: tabular-nums; } +.agent-table tr:last-child td { border-bottom: none; } +.agent-table td:first-child { font-weight: 600; } +.agents-empty { opacity: .6; font-size: 12.5px; margin: 0; } diff --git a/packages/layerfs/page/trajectory.html b/packages/layerfs/page/trajectory.html new file mode 100644 index 0000000..f918a2b --- /dev/null +++ b/packages/layerfs/page/trajectory.html @@ -0,0 +1,73 @@ + + + + + +LayerFS trajectory + + + +
+
+

HISTORY

+

+
+ +

+
+ +
+
+
Checkpoints0 / 0
+
Branches0
+
as copies0 B
+
stored0 B
+
dedupe–
+
+
as copies
+
stored
+

+
+ +
+ + +
+ + +
+ + + + +
+
+ +
+
+

+

+
+ + + + + + + diff --git a/packages/layerfs/page/trajectory.js b/packages/layerfs/page/trajectory.js deleted file mode 100644 index b02ebde..0000000 --- a/packages/layerfs/page/trajectory.js +++ /dev/null @@ -1 +0,0 @@ -globalThis.LayerfsTrajectory = {"generatedAt":"2026-10-22T16:23:37.610Z","backend":"sim","projects":[{"name":"demo","branches":[{"name":"claude","commits":[{"id":"91fd049a2e02","parent":"73ef781c1180","message":"claude: round 1 edits","time":"2026-10-22T16:23:37.327Z","files":25,"logicalBytes":229927,"newBytes":16132,"delta":{"added":0,"modified":4,"deleted":0}},{"id":"be54f31c73e6","parent":"91fd049a2e02","message":"claude: round 2 edits","time":"2026-10-22T16:23:37.347Z","files":26,"logicalBytes":219318,"newBytes":32147,"delta":{"added":1,"modified":4,"deleted":0}},{"id":"783846ed73db","parent":"be54f31c73e6","message":"claude: round 3 edits","time":"2026-10-22T16:23:37.355Z","files":26,"logicalBytes":224694,"newBytes":48132,"delta":{"added":0,"modified":4,"deleted":0}}]},{"name":"codex","commits":[{"id":"201b3e7532cd","parent":"73ef781c1180","message":"codex: round 1 edits","time":"2026-10-22T16:23:37.367Z","files":25,"logicalBytes":229923,"newBytes":16128,"delta":{"added":0,"modified":4,"deleted":0}},{"id":"d251d3299d0e","parent":"201b3e7532cd","message":"codex: round 2 edits","time":"2026-10-22T16:23:37.375Z","files":26,"logicalBytes":219309,"newBytes":32142,"delta":{"added":1,"modified":4,"deleted":0}},{"id":"d9b237bcece0","parent":"d251d3299d0e","message":"codex: round 3 edits","time":"2026-10-22T16:23:37.382Z","files":26,"logicalBytes":224681,"newBytes":48128,"delta":{"added":0,"modified":4,"deleted":0}}]},{"name":"cursor","commits":[{"id":"71b2dd5a5e10","parent":"73ef781c1180","message":"cursor: round 1 edits","time":"2026-10-22T16:23:37.428Z","files":25,"logicalBytes":229927,"newBytes":16132,"delta":{"added":0,"modified":4,"deleted":0}},{"id":"6303b7629ab1","parent":"71b2dd5a5e10","message":"cursor: round 2 edits","time":"2026-10-22T16:23:37.441Z","files":26,"logicalBytes":219318,"newBytes":32147,"delta":{"added":1,"modified":4,"deleted":0}},{"id":"86c8fc87627e","parent":"6303b7629ab1","message":"cursor: round 3 edits","time":"2026-10-22T16:23:37.452Z","files":26,"logicalBytes":224694,"newBytes":48132,"delta":{"added":0,"modified":4,"deleted":0}}]},{"name":"gemini","commits":[{"id":"d3a15a864eeb","parent":"73ef781c1180","message":"gemini: round 1 edits","time":"2026-10-22T16:23:37.472Z","files":25,"logicalBytes":229927,"newBytes":16132,"delta":{"added":0,"modified":4,"deleted":0}},{"id":"5f25521930c6","parent":"d3a15a864eeb","message":"gemini: round 2 edits","time":"2026-10-22T16:23:37.495Z","files":26,"logicalBytes":219318,"newBytes":32147,"delta":{"added":1,"modified":4,"deleted":0}},{"id":"26dc7718a1d9","parent":"5f25521930c6","message":"gemini: round 3 edits","time":"2026-10-22T16:23:37.509Z","files":26,"logicalBytes":224694,"newBytes":48132,"delta":{"added":0,"modified":4,"deleted":0}}]},{"name":"main","commits":[{"id":"73ef781c1180","parent":null,"message":"Import /tmp/lfs-sample-wp308x/src","time":"2026-10-22T16:23:37.291Z","files":25,"logicalBytes":256551,"newBytes":256551,"delta":{"added":25,"modified":0,"deleted":0}}]},{"name":"opencode","commits":[{"id":"d595570cae2c","parent":"73ef781c1180","message":"opencode: round 1 edits","time":"2026-10-22T16:23:37.391Z","files":25,"logicalBytes":229935,"newBytes":16140,"delta":{"added":0,"modified":4,"deleted":0}},{"id":"4a41d832201b","parent":"d595570cae2c","message":"opencode: round 2 edits","time":"2026-10-22T16:23:37.397Z","files":26,"logicalBytes":219336,"newBytes":32157,"delta":{"added":1,"modified":4,"deleted":0}},{"id":"8ea084955aff","parent":"4a41d832201b","message":"opencode: round 3 edits","time":"2026-10-22T16:23:37.403Z","files":26,"logicalBytes":224720,"newBytes":48140,"delta":{"added":0,"modified":4,"deleted":0}}]},{"name":"pi","commits":[{"id":"42310fc68fbb","parent":"73ef781c1180","message":"pi: round 1 edits","time":"2026-10-22T16:23:37.533Z","files":25,"logicalBytes":229911,"newBytes":16116,"delta":{"added":0,"modified":4,"deleted":0}},{"id":"8445e58c0cb1","parent":"42310fc68fbb","message":"pi: round 2 edits","time":"2026-10-22T16:23:37.548Z","files":26,"logicalBytes":219282,"newBytes":32127,"delta":{"added":1,"modified":4,"deleted":0}},{"id":"949429bb257c","parent":"8445e58c0cb1","message":"pi: round 3 edits","time":"2026-10-22T16:23:37.560Z","files":26,"logicalBytes":224642,"newBytes":48116,"delta":{"added":0,"modified":4,"deleted":0}}]},{"name":"release","commits":[{"id":"626e6a6ee6cf","parent":"d9b237bcece0","message":"release: round 1","time":"2026-10-22T16:23:37.585Z","files":27,"logicalBytes":224699,"newBytes":18,"delta":{"added":1,"modified":0,"deleted":0}},{"id":"d06e4115a6a6","parent":"626e6a6ee6cf","message":"release: round 2","time":"2026-10-22T16:23:37.596Z","files":28,"logicalBytes":224717,"newBytes":18,"delta":{"added":1,"modified":0,"deleted":0}}]}]}],"events":[{"t":"2026-10-22T16:23:37.298Z","kind":"provision","project":"demo","branch":"main","path":"/tmp/lfs-sample-wp308x/store/workspaces/demo--main","commit":"73ef781c1180"},{"t":"2026-10-22T16:23:37.301Z","kind":"fork","project":"demo","branch":"claude","from":"main","commit":"73ef781c1180"},{"t":"2026-10-22T16:23:37.314Z","kind":"provision","project":"demo","branch":"claude","path":"/tmp/lfs-sample-wp308x/store/workspaces/demo--claude","commit":"73ef781c1180"},{"t":"2026-10-22T16:23:37.329Z","kind":"checkpoint","project":"demo","branch":"claude","commit":"91fd049a2e02","message":"claude: round 1 edits"},{"t":"2026-10-22T16:23:37.348Z","kind":"checkpoint","project":"demo","branch":"claude","commit":"be54f31c73e6","message":"claude: round 2 edits"},{"t":"2026-10-22T16:23:37.355Z","kind":"checkpoint","project":"demo","branch":"claude","commit":"783846ed73db","message":"claude: round 3 edits"},{"t":"2026-10-22T16:23:37.356Z","kind":"fork","project":"demo","branch":"codex","from":"main","commit":"73ef781c1180"},{"t":"2026-10-22T16:23:37.359Z","kind":"provision","project":"demo","branch":"codex","path":"/tmp/lfs-sample-wp308x/store/workspaces/demo--codex","commit":"73ef781c1180"},{"t":"2026-10-22T16:23:37.368Z","kind":"checkpoint","project":"demo","branch":"codex","commit":"201b3e7532cd","message":"codex: round 1 edits"},{"t":"2026-10-22T16:23:37.375Z","kind":"checkpoint","project":"demo","branch":"codex","commit":"d251d3299d0e","message":"codex: round 2 edits"},{"t":"2026-10-22T16:23:37.383Z","kind":"checkpoint","project":"demo","branch":"codex","commit":"d9b237bcece0","message":"codex: round 3 edits"},{"t":"2026-10-22T16:23:37.383Z","kind":"fork","project":"demo","branch":"opencode","from":"main","commit":"73ef781c1180"},{"t":"2026-10-22T16:23:37.386Z","kind":"provision","project":"demo","branch":"opencode","path":"/tmp/lfs-sample-wp308x/store/workspaces/demo--opencode","commit":"73ef781c1180"},{"t":"2026-10-22T16:23:37.392Z","kind":"checkpoint","project":"demo","branch":"opencode","commit":"d595570cae2c","message":"opencode: round 1 edits"},{"t":"2026-10-22T16:23:37.398Z","kind":"checkpoint","project":"demo","branch":"opencode","commit":"4a41d832201b","message":"opencode: round 2 edits"},{"t":"2026-10-22T16:23:37.404Z","kind":"checkpoint","project":"demo","branch":"opencode","commit":"8ea084955aff","message":"opencode: round 3 edits"},{"t":"2026-10-22T16:23:37.405Z","kind":"fork","project":"demo","branch":"cursor","from":"main","commit":"73ef781c1180"},{"t":"2026-10-22T16:23:37.420Z","kind":"provision","project":"demo","branch":"cursor","path":"/tmp/lfs-sample-wp308x/store/workspaces/demo--cursor","commit":"73ef781c1180"},{"t":"2026-10-22T16:23:37.430Z","kind":"checkpoint","project":"demo","branch":"cursor","commit":"71b2dd5a5e10","message":"cursor: round 1 edits"},{"t":"2026-10-22T16:23:37.443Z","kind":"checkpoint","project":"demo","branch":"cursor","commit":"6303b7629ab1","message":"cursor: round 2 edits"},{"t":"2026-10-22T16:23:37.453Z","kind":"checkpoint","project":"demo","branch":"cursor","commit":"86c8fc87627e","message":"cursor: round 3 edits"},{"t":"2026-10-22T16:23:37.454Z","kind":"fork","project":"demo","branch":"gemini","from":"main","commit":"73ef781c1180"},{"t":"2026-10-22T16:23:37.465Z","kind":"provision","project":"demo","branch":"gemini","path":"/tmp/lfs-sample-wp308x/store/workspaces/demo--gemini","commit":"73ef781c1180"},{"t":"2026-10-22T16:23:37.474Z","kind":"checkpoint","project":"demo","branch":"gemini","commit":"d3a15a864eeb","message":"gemini: round 1 edits"},{"t":"2026-10-22T16:23:37.498Z","kind":"checkpoint","project":"demo","branch":"gemini","commit":"5f25521930c6","message":"gemini: round 2 edits"},{"t":"2026-10-22T16:23:37.510Z","kind":"checkpoint","project":"demo","branch":"gemini","commit":"26dc7718a1d9","message":"gemini: round 3 edits"},{"t":"2026-10-22T16:23:37.511Z","kind":"fork","project":"demo","branch":"pi","from":"main","commit":"73ef781c1180"},{"t":"2026-10-22T16:23:37.523Z","kind":"provision","project":"demo","branch":"pi","path":"/tmp/lfs-sample-wp308x/store/workspaces/demo--pi","commit":"73ef781c1180"},{"t":"2026-10-22T16:23:37.533Z","kind":"checkpoint","project":"demo","branch":"pi","commit":"42310fc68fbb","message":"pi: round 1 edits"},{"t":"2026-10-22T16:23:37.549Z","kind":"checkpoint","project":"demo","branch":"pi","commit":"8445e58c0cb1","message":"pi: round 2 edits"},{"t":"2026-10-22T16:23:37.562Z","kind":"checkpoint","project":"demo","branch":"pi","commit":"949429bb257c","message":"pi: round 3 edits"},{"t":"2026-10-22T16:23:37.566Z","kind":"publish","project":"demo","branch":"codex","commit":"d9b237bcece0","layer":1,"overwrote":false},{"t":"2026-10-22T16:23:37.567Z","kind":"fork","project":"demo","branch":"release","from":"main","commit":"d9b237bcece0"},{"t":"2026-10-22T16:23:37.577Z","kind":"provision","project":"demo","branch":"release","path":"/tmp/lfs-sample-wp308x/store/workspaces/demo--release","commit":"d9b237bcece0"},{"t":"2026-10-22T16:23:37.588Z","kind":"checkpoint","project":"demo","branch":"release","commit":"626e6a6ee6cf","message":"release: round 1"},{"t":"2026-10-22T16:23:37.598Z","kind":"checkpoint","project":"demo","branch":"release","commit":"d06e4115a6a6","message":"release: round 2"},{"t":"2026-10-22T16:23:37.602Z","kind":"publish","project":"demo","branch":"release","commit":"d06e4115a6a6","layer":2,"overwrote":false}],"totals":{"logicalBytes":4749523,"storedBytes":835014,"savedBytes":3914509,"dedupRatio":5.69,"workspaces":8},"sample":true}; diff --git a/packages/layerfs/page/view.js b/packages/layerfs/page/view.js index 5080210..1a2c9cb 100644 --- a/packages/layerfs/page/view.js +++ b/packages/layerfs/page/view.js @@ -15,6 +15,8 @@ live: "live", layers: "layers", history: "HISTORY", stats: "store.stats · read-only", dedupe: "dedupe", graft: "published", twig: "bare twig", checkpointsK: "Checkpoints", branchesK: "Branches", + agentsK: "Agent activity", agentsEmpty: "No tool calls yet. Each agent's provision, fork, checkpoint and publish lands here as it happens.", + agentCol: "Agent", toolCol: "Tool", projectCol: "Project", branchCol: "Branch", whenCol: "When", }, zh: { title: "LayerFS 轨迹", replay: "回放", pause: "暂停", @@ -26,6 +28,8 @@ live: "条存活分支", layers: "层", history: "HISTORY", stats: "store.stats · 只读", dedupe: "去重", graft: "已发布", twig: "未发布的枝条", checkpointsK: "检查点", branchesK: "分支", + agentsK: "Agent 活动", agentsEmpty: "还没有工具调用。每个 agent 的 provision、fork、checkpoint 和 publish 会实时落在这里。", + agentCol: "Agent", toolCol: "工具", projectCol: "项目", branchCol: "分支", whenCol: "时间", }, "zh-TW": { title: "LayerFS 軌跡", replay: "重播", pause: "暫停", @@ -37,6 +41,8 @@ live: "條存活分支", layers: "層", history: "HISTORY", stats: "store.stats · 唯讀", dedupe: "去重", graft: "已發布", twig: "未發布的枝條", checkpointsK: "檢查點", branchesK: "分支", + agentsK: "Agent 活動", agentsEmpty: "還沒有工具呼叫。每個 agent 的 provision、fork、checkpoint 和 publish 會即時落在這裡。", + agentCol: "Agent", toolCol: "工具", projectCol: "專案", branchCol: "分支", whenCol: "時間", }, ja: { title: "LayerFS の軌跡", replay: "再生", pause: "一時停止", @@ -48,6 +54,8 @@ live: "本の生存ブランチ", layers: "レイヤー", history: "HISTORY", stats: "store.stats · 読み取り専用", dedupe: "重複排除", graft: "公開済み", twig: "未公開の枝", checkpointsK: "チェックポイント", branchesK: "ブランチ", + agentsK: "エージェントの活動", agentsEmpty: "まだツール呼び出しはありません。各エージェントの provision、fork、checkpoint、publish は随時ここに記録されます。", + agentCol: "エージェント", toolCol: "ツール", projectCol: "プロジェクト", branchCol: "ブランチ", whenCol: "時刻", }, }; @@ -96,7 +104,56 @@ if (n >= 1e9) return (n / 1e9).toFixed(2) + " GB"; if (n >= 1e6) return (n / 1e6).toFixed(1) + " MB"; if (n >= 1e3) return (n / 1e3).toFixed(1) + " KB"; - return n + " B"; + // byte counts are whole: the counters interpolate mid-replay, and + // an unrounded fraction here used to show as 3.164870684975676 B + return Math.round(n) + " B"; + } + + // The view state a reload carries in location.hash: the project, the + // vertical scroll, and the replay playhead. The hash survives + // location.reload() in a sandboxed frame and needs no storage, which + // is what makes it usable here: the page cannot fetch, and the + // service must not answer cross-origin reads, so the fresh document + // cannot ask what changed — it can only read what the old document + // left in the hash. Pure, so a test can check the round-trip and + // the restore decision without a DOM. + function formatViewHash(state) { + const p = encodeURIComponent(String(state.project || "")); + const y = Math.max(0, Math.round(Number(state.scrollY) || 0)); + const t = Math.max(0, Math.round((Number(state.playhead) || 0) * 1000) / 1000); + return `#p=${p}&y=${y}&t=${t}`; + } + function parseViewHash(hash) { + const h = String(hash || "").replace(/^#/, ""); + if (!h) return null; + let params; + try { params = new URLSearchParams(h); } catch { return null; } + const project = params.get("p"); + if (!project) return null; + const y = Number(params.get("y")); + const t = Number(params.get("t")); + return { + project, + scrollY: Number.isFinite(y) && y > 0 ? Math.round(y) : 0, + playhead: Number.isFinite(t) && t > 0 ? t : 0, + }; + } + // Which view a fresh document restores from the hash, or null for a + // plain first look (no hash, or a hash naming a project that is no + // longer there — a renamed project must not pin the page to a + // ghost). The playhead clamps to the project's steps: the data may + // have grown or shrunk since the hash was written. Under reduced + // motion the page settles on the final state whatever the hash says. + function resolveRestoredView(projects, hash, reducedMotion) { + const parsed = parseViewHash(hash); + if (!parsed) return null; + const project = (projects || []).find((p) => p.name === parsed.project); + if (!project) return null; + const n = steps(project).length; + if (reducedMotion || parsed.playhead >= n) { + return { project: parsed.project, scrollY: parsed.scrollY, playhead: n, settled: true }; + } + return { project: parsed.project, scrollY: parsed.scrollY, playhead: Math.min(parsed.playhead, n), settled: false }; } // Lane 0 is main, the middle bough; other branches follow in the order @@ -392,5 +449,6 @@ TEXT, text, bytes, lanes, steps, publishes, layout, detail, AGENTS, agentOf, ICONS, LEAF_GLYPH, glyphFor, iconDraw, cubicBezier, magpieEase, easeOutCubic, easeOutBack, clamp01, frame, pulse, markInk, + formatViewHash, parseViewHash, resolveRestoredView, }; })();