Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/developers/share-source.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ through `hyperframes share --manage`.
Source uses the same portable project policy as Desktop: authored HTML, scripts,
styles, assets, and supported Studio edit metadata. Known credential filenames
(such as `.env`, `.npmrc`, and `*.pem`), dependency directories, chat
history, local sharing state, and recorded render outputs stay out.
history, local sharing state, and recorded render outputs stay out. Files ending in `.key` stay local,
including Keynote decks.

These are filename rules, not a secret scanner. `.gitignore` does not control
source capture. Other regular files can be included even if Git ignores them. For example,
Expand Down
67 changes: 29 additions & 38 deletions packages/parsers/src/privatePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,10 @@ function withoutTrailingDotsOrSpaces(segment: string): string {
return segment.slice(0, end);
}

// Git metadata and env files hold commands other tools run and secrets: nothing serves or inlines them.
export function isVcsOrSecretPath(relPath: string): boolean {
return projectPathSegments(relPath).some(
(segment) => segment === ".git" || segment.startsWith(".env"),
);
}

// `.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. Studio
// reads and writes those only in the project's own `.hyperframes/`, so one in a subfolder holds records only.
const STUDIO_FILES = new Set([
".hyperframes/studio-motion.json",
".hyperframes/studio-manual-edits.json",
]);
const STUDIO_FOLDERS = [".hyperframes/prepared-assets", ".hyperframes/requests"];
const UNCONVERTED_PREVIEW_DOWNLOADS = ".hyperframes/prepared-assets/downloads";

// Credentials and coding-tool state that projects often sit next to: registry tokens, MCP and agent settings, cloud and
// SSH keys. No composition loads one, so no file server serves one and no upload ships one.
const CREDENTIAL_FILES = new Set([
// Shared with the editable-source contract. Each expression matches whole normalized paths.
const anyDepth = String.raw`(?:[^/]*/)*`;
const vcsOrEnv = String.raw`(?:\.git|\.env[^/]*)(?:/.*)?`;
const credentialNames = [
".npmrc",
".yarnrc",
".yarnrc.yml",
Expand All @@ -67,8 +51,8 @@ const CREDENTIAL_FILES = new Set([
"serviceaccountkey.json",
"service-account.json",
"service_account.json",
]);
const CREDENTIAL_FOLDERS = new Set([
];
const toolFolders = [
".ssh",
".aws",
".gnupg",
Expand All @@ -82,26 +66,33 @@ const CREDENTIAL_FOLDERS = new Set([
".gemini",
".vscode",
".idea",
];
const alternatives = (names: string[]) =>
names.map((name) => name.replaceAll(".", "\\.")).join("|");
const keyOrStore = String.raw`id_(?:rsa|dsa|ecdsa|ed25519)[^/]*|[^/]*\.(?:pem|key|p12|pfx|p8|ppk|jks|keystore|kdbx|tfstate(?:\.backup)?|tfvars(?:\.json)?)`;
const folders = String.raw`(?:${alternatives(toolFolders)}|\.config/(?:gcloud|gh))(?:/.*)?`;
const credentials = [alternatives(credentialNames), keyOrStore, folders].join("|");

export const portablePrivatePattern = `${anyDepth}(?:${vcsOrEnv}|${credentials})`;
const vcsOrSecret = new RegExp(`^${anyDepth}(?:${vcsOrEnv})$`, "su");
const credentialOrToolState = new RegExp(`^${anyDepth}(?:${credentials})$`, "su");

// Git metadata and env files hold commands other tools run and secrets: nothing serves or inlines them.
export function isVcsOrSecretPath(relPath: string): boolean {
return vcsOrSecret.test(projectPathSegments(relPath).join("/"));
}

// Only known project files in the root .hyperframes directory can be served as assets.
const STUDIO_FILES = new Set([
".hyperframes/studio-motion.json",
".hyperframes/studio-manual-edits.json",
]);
const CREDENTIAL_CONFIG_FOLDERS = new Set(["gcloud", "gh"]);
const KEY_FILE =
/^(?:id_(?:rsa|dsa|ecdsa|ed25519).*|.*\.(?:pem|key|p12|pfx|p8|ppk|jks|keystore|kdbx))$/;
const SECRET_STORE_FILE = /\.(?:tfstate(?:\.backup)?|tfvars(?:\.json)?)$/;
const STUDIO_FOLDERS = [".hyperframes/prepared-assets", ".hyperframes/requests"];
const UNCONVERTED_PREVIEW_DOWNLOADS = ".hyperframes/prepared-assets/downloads";

/** Credential files and tool or agent state, for a project-relative path in any spelling Windows opens. */
export function isCredentialOrToolStatePath(relPath: string): boolean {
const segments = projectPathSegments(relPath);
const name = segments.at(-1) ?? "";
return (
CREDENTIAL_FILES.has(name) ||
KEY_FILE.test(name) ||
SECRET_STORE_FILE.test(name) ||
segments.some(
(segment, at) =>
CREDENTIAL_FOLDERS.has(segment) ||
(segment === ".config" && CREDENTIAL_CONFIG_FOLDERS.has(segments[at + 1] ?? "")),
)
);
return credentialOrToolState.test(projectPathSegments(relPath).join("/"));
}

/** Files no composition loads, in any spelling Windows opens: git, env, credentials, tool state, app records. */
Expand Down
2 changes: 1 addition & 1 deletion packages/share/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ can use video-only; changed source, conflicts and unexpected upload failures nee
an explicit choice to omit source. The CLI exposes `--video-only` for that choice.
`filesForExport` only validates already-prepared source; it does not upload.

The adapter uses the portable-source-v11 capture/manifest rules and
The adapter uses the portable-source-v12 capture/manifest rules and
multipart transport. The pinned policy, Unicode 15.1 registry (with its license),
and manifest test vectors are checked into this repository. Source is captured through
verified file handles; upload bytes are streamed and checked against their hash.
Expand Down
3 changes: 3 additions & 0 deletions packages/share/src/projectSnapshot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import path from "node:path";
import { createHash } from "node:crypto";
import { isOutsideFilm } from "./appOwnedPaths.mjs";

export { readSourceIgnore };
export { isPrivateSourcePath, privateSourceSpelling } from "./sources/privateSource.mjs";

export const HF_ID_ATTRIBUTE = /\sdata-hf-id\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/g;

const sha256 = (/** @type {import("node:crypto").BinaryLike} */ data) =>
Expand Down
27 changes: 21 additions & 6 deletions packages/share/src/sources/contract/path-policy.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"policy_version": "portable-source-v11",
"policy_version": "portable-source-v12",
"manifest": {
"format_version": 1,
"entrypoint": "index.html",
Expand Down Expand Up @@ -57,7 +57,7 @@
"max_segment_bytes": 240,
"separator": "/",
"forbidden_characters": "<>:\"|?*\\",
"reserved_segment_regex": "(?:con|prn|aux|nul|com[1-9\u00b9\u00b2\u00b3]|lpt[1-9\u00b9\u00b2\u00b3])(?:\\..*)?",
"reserved_segment_regex": "(?:con|prn|aux|nul|com[1-9¹²³]|lpt[1-9¹²³])(?:\\..*)?",
"reserved_segment_match": "full match against each segment's comparison key, so CON, Con.txt and nul.tar.gz are all reserved",
"canonical_spelling_roots": [
".media",
Expand All @@ -71,18 +71,21 @@
".amazonq",
".augment",
".aws",
".azure",
".cache",
".claude",
".cline",
".clinerules",
".codex",
".config",
".continue",
".continuerc.json",
".crush",
".crush.json",
".cursor",
".devcontainer",
".devcontainer.json",
".docker",
".ds_store",
".env",
".envrc",
Expand All @@ -92,9 +95,11 @@
".git",
".git-credentials",
".gitattributes",
".gitconfig",
".github",
".gitmodules",
".gitpod.yml",
".gnupg",
".grok",
".hg",
".hyperframes",
Expand All @@ -103,6 +108,7 @@
".junie",
".kilocode",
".kiro",
".kube",
".lock",
".mcp.json",
".media",
Expand Down Expand Up @@ -293,10 +299,10 @@
},
{
"id": "credential-files",
"regex": "(?:[^/]+/)*(?:\\.netrc|\\.pypirc|\\.git-credentials|[^/]*\\.(?:pem|p12|pfx)|id_rsa[^/]*|id_ed25519[^/]*|(?:\\.ssh|\\.aws)(?:/.*)?)",
"regex": "(?:[^/]+/)*(?:\\.netrc|_netrc|\\.pypirc|\\.git-credentials|\\.gitconfig|pip\\.ini|[^/]*\\.(?:pem|p12|pfx)|id_(?:rsa|dsa|ecdsa|ed25519)[^/]*|(?:\\.ssh|\\.aws|\\.gnupg|\\.docker|\\.kube|\\.azure|\\.config/(?:gcloud|gh))(?:/.*)?)",
"client_action": "exclude",
"server_action": "reject",
"basis": "Credential files by name at any depth. *.key is deliberately absent: Keynote decks are plausible project sources"
"basis": "Credential files and stores by name at any depth."
},
{
"id": "os-metadata",
Expand All @@ -312,6 +318,13 @@
"server_action": "reject",
"basis": "A .hyperframes folder below the project root, such as one inside a project copied into compositions/, holds that copy's client records; only the root folder's named portable files below travel"
},
{
"id": "private-source",
"regex": "(?:[^/]*/)*(?:(?:\\.git|\\.env[^/]*)(?:/.*)?|\\.npmrc|\\.yarnrc|\\.yarnrc\\.yml|\\.pypirc|pip\\.conf|pip\\.ini|\\.netrc|_netrc|\\.git-credentials|\\.gitconfig|\\.mcp\\.json|credentials\\.json|serviceaccountkey\\.json|service-account\\.json|service_account\\.json|id_(?:rsa|dsa|ecdsa|ed25519)[^/]*|[^/]*\\.(?:pem|key|p12|pfx|p8|ppk|jks|keystore|kdbx|tfstate(?:\\.backup)?|tfvars(?:\\.json)?)|(?:\\.ssh|\\.aws|\\.gnupg|\\.docker|\\.kube|\\.azure|\\.claude|\\.codex|\\.cursor|\\.agents|\\.gemini|\\.vscode|\\.idea|\\.config/(?:gcloud|gh))(?:/.*)?)",
"client_action": "exclude",
"server_action": "reject",
"basis": "The private-path rule for credentials, tool state, Git and environment files. Also match the parser spelling after NFKC, upper then lower case, removal of default-ignorable code points and Windows segment cleanup."
},
{
"id": "portable-transcripts",
"regex": "\\.hyperframes/transcripts/(?:[^/]+/)*[^/]+\\.json",
Expand Down Expand Up @@ -440,7 +453,9 @@
"agent-client-state": "(?:[^/]+/)*(?:\\.claude|\\.agents|\\.cursor|\\.vscode|\\.idea)(?:/.*)?",
"work-tree-config": "(?!)",
"git-directory-head": "(?!)",
"nested-hyperframes-state": "(?!)"
"nested-hyperframes-state": "(?!)",
"credential-files": "(?:[^/]+/)*(?:\\.netrc|\\.pypirc|\\.git-credentials|[^/]*\\.(?:pem|p12|pfx)|id_rsa[^/]*|id_ed25519[^/]*|(?:\\.ssh|\\.aws)(?:/.*)?)",
"private-source": "(?!)"
},
"legacy_short_name_alias_names": [
".agent",
Expand Down Expand Up @@ -483,6 +498,6 @@
".yarnrc",
".yarnrc.yml"
],
"rule": "Only stored snapshot reads use each listed rule's regex in place of its current one, and the v10 short_name_alias_names in place of the current ones, to retain immutable manifest digests: agent-client-state its v3 regex, and work-tree-config, added in v7, git-directory-head, added in v9, and nested-hyperframes-state, added in v10, none. New captures and uploads use the current rules and short names. Clients never install, and the server never signs a download URL for, a path a current rule excludes or a segment that is a current short name."
"rule": "Only stored snapshot reads use each listed rule's regex in place of its current one, and the v10 short_name_alias_names in place of the current ones, to retain immutable manifest digests: agent-client-state its v3 regex, and work-tree-config, added in v7, git-directory-head, added in v9, and nested-hyperframes-state, added in v10, none. The credential-files rule keeps its v11 regex. New captures and uploads use the current rules and short names. Clients never install, and the server never signs a download URL for, a path a current rule excludes or a segment that is a current short name. The private-source rule applies only to current validation and delivery."
}
}
18 changes: 10 additions & 8 deletions packages/share/src/sources/pathPolicy.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
// Validate source manifests against the bundled sync contract.
import { isCredentialOrToolStatePath, isVcsOrSecretPath } from "@hyperframes/parsers/private-path";
import { isPrivateSourcePath, privateSourceSpelling } from "./privateSource.mjs";
export { isPrivateSourcePath };
import { readContract } from "./contract.mjs";
import {
UNICODE_VERSION,
Expand All @@ -11,7 +12,7 @@ import {
withoutIgnorable,
} from "./unicode.mjs";

const PATH_POLICY_VERSION = "portable-source-v11";
const PATH_POLICY_VERSION = "portable-source-v12";

/** @typedef {import("./types.js").PathRule} PathRule @typedef {import("./types.js").PolicyDocument} PolicyDocument */

Expand Down Expand Up @@ -109,10 +110,15 @@ const policy = () => (compiled ??= compile(readContract("path-policy.json")));
/** Every segment replaced by its comparison key. @param {string} path */
const foldedPath = (path) => path.split("/").map(comparisonKey).join("/");

/** @param {{ pattern: RegExp, rule: PathRule }} entry @param {string} folded @param {string} path */
const matches = ({ pattern, rule }, folded, path) =>
pattern.test(folded) ||
(rule.id === "private-source" && pattern.test(privateSourceSpelling(path)));

/** The first rule matching a path's folded spelling. @param {string} path @returns {PathRule} */
export function classifyPath(path) {
const folded = foldedPath(path);
const found = policy().rules.find(({ pattern }) => pattern.test(folded));
const found = policy().rules.find((entry) => matches(entry, folded, path));
if (!found) throw new Error("the path policy's catch-all rule did not match");
return found.rule;
}
Expand Down Expand Up @@ -169,7 +175,7 @@ export function validatePath(path, mode = "current") {
if (root !== undefined && segments[0] !== root)
throw new PathViolation("reserved_path_alias", path);
const folded = keys.join("/");
const found = rules.find(({ pattern }) => pattern.test(folded));
const found = rules.find((entry) => matches(entry, folded, path));
if (!found) throw new Error("the path policy's catch-all rule did not match");
if (found.rule.server_action === "reject")
throw new PathViolation("excluded_path", path, found.rule.id);
Expand Down Expand Up @@ -246,10 +252,6 @@ export function excludedFolder(dir) {
});
}

/** Private names omitted locally even when the wire contract accepts them. @param {string} path */
export const isPrivateSourcePath = (path) =>
isVcsOrSecretPath(path) || isCredentialOrToolStatePath(path);

/** A stored manifest may contain paths that are no longer eligible for upload. @param {string} path */
export function canUploadStoredPath(path) {
if (isPrivateSourcePath(path)) return false;
Expand Down
13 changes: 13 additions & 0 deletions packages/share/src/sources/privateSource.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @ts-check
import {
isCredentialOrToolStatePath,
isVcsOrSecretPath,
projectPathSegments,
} from "@hyperframes/parsers/private-path";

/** @param {string} path */
export const isPrivateSourcePath = (path) =>
isVcsOrSecretPath(path) || isCredentialOrToolStatePath(path);

/** @param {string} path */
export const privateSourceSpelling = (path) => projectPathSegments(path).join("/");
Loading
Loading