diff --git a/packages/cli/src/utils/staticProjectServer.test.ts b/packages/cli/src/utils/staticProjectServer.test.ts index f63e8b36b0..3a8f662a95 100644 --- a/packages/cli/src/utils/staticProjectServer.test.ts +++ b/packages/cli/src/utils/staticProjectServer.test.ts @@ -1,5 +1,12 @@ import { afterEach, describe, expect, it, vi } from "vitest"; -import { mkdirSync, mkdtempSync, rmSync, writeFileSync, type ReadStream } from "node:fs"; +import { + mkdirSync, + mkdtempSync, + rmSync, + symlinkSync, + writeFileSync, + type ReadStream, +} from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import fs from "node:fs"; @@ -721,3 +728,36 @@ describe("serveStaticProjectHtml private project files", () => { }, ); }); + +function writeToolRecords(projectDir: string): void { + mkdirSync(join(projectDir, ".hyperframes", "prepared-assets"), { recursive: true }); + for (const name of ["app-history.jsonl", "agent-handoff.json", "comments.jsonl"]) { + writeFileSync(join(projectDir, ".hyperframes", name), "PRIVATE_RECORD"); + } + writeFileSync(join(projectDir, ".hyperframes", "prepared-assets", "clip.txt"), "prepared"); + symlinkSync( + join(projectDir, ".hyperframes", "app-history.jsonl"), + join(projectDir, "linked-history.json"), + ); +} + +describe("serveStaticProjectHtml tool records", () => { + it.each([ + ".hyperframes/app-history.jsonl", + ".hyperframes/agent-handoff.json", + ".hyperframes/comments.jsonl", + "%2ehyperframes/agent-handoff.json", + ".hyperframes%2fcomments.jsonl", + "linked-history.json", + ])("answers %s with 404 and still serves prepared assets", async (requestPath) => { + dir = mkdtempSync(join(tmpdir(), "hf-static-records-")); + writeToolRecords(dir); + server = await serveStaticProjectHtml(dir, ""); + + const res = await fetch(`${server.url}${requestPath}`); + expect(res.status).toBe(404); + expect(await res.text()).not.toContain("PRIVATE_RECORD"); + const prepared = await fetch(`${server.url}.hyperframes/prepared-assets/clip.txt`); + expect(await prepared.text()).toBe("prepared"); + }); +}); diff --git a/packages/cli/src/utils/staticProjectServer.ts b/packages/cli/src/utils/staticProjectServer.ts index 298ef78c2a..00c7ba7e43 100644 --- a/packages/cli/src/utils/staticProjectServer.ts +++ b/packages/cli/src/utils/staticProjectServer.ts @@ -2,7 +2,7 @@ import { createServer, request as httpRequest, type Server, type ServerResponse import { Duplex } from "node:stream"; import { createReadStream, existsSync, readFileSync, statSync } from "node:fs"; import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags"; -import { isPrivateFileUnder, isVcsOrSecretPath } from "@hyperframes/core/safe-path"; +import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path"; import { isAbsolute, relative, resolve } from "node:path"; import { PREVIEW_PROXY_BOX_PARAM, @@ -332,7 +332,7 @@ export async function serveStaticProjectHtml( const filePath = resolve(root, requestPath); const rel = relative(root, filePath); if (rel.startsWith("..") || isAbsolute(rel)) continue; // traversal guard; try next root - if (isPrivateFileUnder(root, filePath, isVcsOrSecretPath)) continue; + if (isPrivateFileUnder(root, filePath, isStudioPrivatePath)) continue; if (existsSync(filePath)) { if (proxyRequest) { void serveProxyRequest( diff --git a/packages/core/src/compiler/htmlBundler.test.ts b/packages/core/src/compiler/htmlBundler.test.ts index 4fddfaf3e5..0aeddc5c45 100644 --- a/packages/core/src/compiler/htmlBundler.test.ts +++ b/packages/core/src/compiler/htmlBundler.test.ts @@ -235,7 +235,7 @@ describe("bundleToSingleHtml", () => { } }); - it("refuses the app's records only under the studio private-file policy", async () => { + it("refuses the app's records by default, and inlines them only when asked for git and env files alone", async () => { const dir = makeTempProject({ "index.html": `
@@ -250,7 +250,10 @@ describe("bundleToSingleHtml", () => { expect(studio).toContain('href=".hyperframes/handoff.css"'); expect(studio).toContain(".prepared { color: blue; }"); const plain = await bundleToSingleHtml(dir); - expect(plain).toContain(".app-record { color: red; }"); + expect(plain).not.toContain(".app-record"); + expect(plain).toContain(".prepared { color: blue; }"); + const narrow = await bundleToSingleHtml(dir, { privateFiles: "vcs-and-secrets" }); + expect(narrow).toContain(".app-record { color: red; }"); } finally { rmSync(dir, { recursive: true, force: true }); } diff --git a/packages/core/src/compiler/htmlBundler.ts b/packages/core/src/compiler/htmlBundler.ts index 73c335551b..c301a482cc 100644 --- a/packages/core/src/compiler/htmlBundler.ts +++ b/packages/core/src/compiler/htmlBundler.ts @@ -928,7 +928,7 @@ export interface BundleOptions { onRead?: (filePath: string) => void; /** * Project files the build never reads; a refused file keeps its authored reference. Git metadata and env files - * always; `"studio"` also refuses the app's records under `.hyperframes/`, as Studio's file routes do. + * always; `"studio"`, the default, also refuses the app's records under `.hyperframes/`, as every file server does. */ privateFiles?: BundlePrivateFiles; } @@ -1069,7 +1069,7 @@ export function bundleToSingleHtml(projectDir: string, options?: BundleOptions): }; const scope: BundleReadScope = { projectDir, - privateFiles: options?.privateFiles ?? "vcs-and-secrets", + privateFiles: options?.privateFiles ?? "studio", noteRead, }; return bundleReads.run(scope, () => bundleProject(projectDir, options)); diff --git a/packages/core/src/safePath.test.ts b/packages/core/src/safePath.test.ts index e6af569f23..7439cb0ff0 100644 --- a/packages/core/src/safePath.test.ts +++ b/packages/core/src/safePath.test.ts @@ -14,6 +14,7 @@ import { folderGone, isProjectRootMissing, isSafePath, + isStudioPrivatePath, mkdirWithinProject, resolveWithinProject, } from "./safePath.js"; @@ -263,3 +264,33 @@ describe("folderGone", () => { }, ); }); + +describe("isStudioPrivatePath", () => { + it.each([ + ".hyperframes", + ".hyperframes/app-history.jsonl", + ".hyperframes/agent-handoff.json", + ".HYPERFRAMES/comments.jsonl", + ".hyperframes./heygen-jobs.jsonl", + ".hyperframes /agent-handoff.json", + ".hyperframes\\comments.jsonl", + ".hyperframes:stream/comments.jsonl", + ".git/config", + ".env.local", + ])("refuses %s", (path) => { + expect(isStudioPrivatePath(path)).toBe(true); + }); + + it.each([ + ".hyperframes/prepared-assets/gif/clip.gif", + ".HYPERFRAMES/Prepared-Assets./heif/photo.png", + ".hyperframes/requests/sketch.png", + ".hyperframes/studio-motion.json", + ".hyperframes/studio-manual-edits.json", + ".hyperframes-pull.json", + "assets/.hyperframes/logo.png", + "assets/logo.png", + ])("allows %s", (path) => { + expect(isStudioPrivatePath(path)).toBe(false); + }); +}); diff --git a/packages/core/src/safePath.ts b/packages/core/src/safePath.ts index 32316f998a..728d05433d 100644 --- a/packages/core/src/safePath.ts +++ b/packages/core/src/safePath.ts @@ -126,18 +126,18 @@ export function isVcsOrSecretPath(relPath: string): boolean { ); } -// `.hyperframes/` holds the desktop app's and the CLI's own records (a hand-off, chat history, read marks): Studio -// reaches none of it, the folder itself included, but its own files and the app's request pictures. +// `.hyperframes/` holds the desktop app's and the CLI's own records (a hand-off, chat history, read marks): no file +// server serves any of it, the folder itself included, but Studio's own files and the assets compositions load. const STUDIO_FILES = new Set([ ".hyperframes/studio-motion.json", ".hyperframes/studio-manual-edits.json", ]); const STUDIO_FOLDERS = [".hyperframes/prepared-assets", ".hyperframes/requests"]; -/** Studio's private files, for a project-relative path with `/` separators: git, env, and the app's records. */ +/** Files no composition loads, for a project-relative path in any spelling Windows opens: git, env, app records. */ export function isStudioPrivatePath(relPath: string): boolean { - const path = relPath.toLowerCase(); - if (isVcsOrSecretPath(path)) return true; + if (isVcsOrSecretPath(relPath)) return true; + const path = projectPathSegments(relPath).join("/"); return ( (path === ".hyperframes" || path.startsWith(".hyperframes/")) && !STUDIO_FILES.has(path) && diff --git a/packages/engine/src/services/fileServer.pathSafety.test.ts b/packages/engine/src/services/fileServer.pathSafety.test.ts index a0d18ac666..a74f42766a 100644 --- a/packages/engine/src/services/fileServer.pathSafety.test.ts +++ b/packages/engine/src/services/fileServer.pathSafety.test.ts @@ -85,3 +85,51 @@ describe("fileServer private project files", () => { }, ); }); + +describe("fileServer tool records", () => { + it.each([ + ".hyperframes/app-history.jsonl", + ".hyperframes/agent-handoff.json", + ".hyperframes/comments.jsonl", + "%2ehyperframes/agent-handoff.json", + ".hyperframes%2fcomments.jsonl", + "linked-history.json", + ])( + "answers %s with 404 from either root and still serves prepared assets", + async (requestPath) => { + const projectDir = fs.mkdtempSync(path.join(tmpdir(), "hf-fileserver-records-")); + const compiledDir = fs.mkdtempSync(path.join(tmpdir(), "hf-fileserver-records-compiled-")); + for (const root of [projectDir, compiledDir]) { + fs.mkdirSync(path.join(root, ".hyperframes", "prepared-assets"), { recursive: true }); + for (const name of ["app-history.jsonl", "agent-handoff.json", "comments.jsonl"]) { + fs.writeFileSync(path.join(root, ".hyperframes", name), "PRIVATE_RECORD"); + } + } + fs.writeFileSync( + path.join(projectDir, ".hyperframes", "prepared-assets", "clip.txt"), + "prepared", + ); + fs.symlinkSync( + path.join(projectDir, ".hyperframes", "app-history.jsonl"), + path.join(projectDir, "linked-history.json"), + ); + const server = await createFileServer({ + headScripts: [], + bodyScripts: [], + projectDir, + compiledDir, + }); + try { + const response = await fetch(`${server.url}/${requestPath}`); + expect(response.status).toBe(404); + expect(await response.text()).not.toContain("PRIVATE_RECORD"); + const prepared = await fetch(`${server.url}/.hyperframes/prepared-assets/clip.txt`); + expect(await prepared.text()).toBe("prepared"); + } finally { + server.close(); + fs.rmSync(projectDir, { recursive: true, force: true }); + fs.rmSync(compiledDir, { recursive: true, force: true }); + } + }, + ); +}); diff --git a/packages/engine/src/services/fileServer.ts b/packages/engine/src/services/fileServer.ts index 5bbfe89568..b70efd672e 100644 --- a/packages/engine/src/services/fileServer.ts +++ b/packages/engine/src/services/fileServer.ts @@ -11,7 +11,7 @@ import { serve } from "@hono/node-server"; import { readFileSync, openSync, fstatSync, closeSync, statSync, constants } from "node:fs"; import { join, extname } from "node:path"; import { injectScriptsIntoHtml } from "@hyperframes/core/compiler"; -import { isPrivateFileUnder, isVcsOrSecretPath } from "@hyperframes/core/safe-path"; +import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path"; import { isWithinProjectRoot } from "@hyperframes/parsers/asset-resolution"; const MIME_TYPES: Record