Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

perf(eve): remove redundant hosted build work and replace gray-matter (#4182)

Andrew Barbadc50f62df36f
diff --git a/.changeset/faster-hosted-bundle.md b/.changeset/faster-hosted-bundle.md
new file mode 100644
index 000000000..45bdaa4dd
--- /dev/null
+++ b/.changeset/faster-hosted-bundle.md
@@ -0,0 +1,7 @@
+---
+"eve": patch
+---
+
+Hosted builds bundle faster: eve no longer re-parses its largest output chunk while adding the Node ESM compatibility banner, and Nitro no longer gzips every output file just to annotate the build log. The repeated `MISSING_CODE_SPLITTING_GROUP_DEBUG_NAME` warning also no longer appears in build logs.
+
+eve no longer depends on `gray-matter`. Frontmatter and YAML files (skills, schedules, instructions, OpenAPI specs, and `loadYaml`) now parse with js-yaml 4, whose schema cannot evaluate code, and each deployed function is about 180 kB smaller. Frontmatter fences must be `---` or `---yaml`; other languages such as `---json` or `---js` now fail with an error instead of being parsed.
diff --git a/package.json b/package.json
index 89317f6ba..11df9cc53 100644
--- a/package.json
+++ b/package.json
@@ -36,7 +36,7 @@
"@changesets/cli": "3.0.1",
"@microsoft/api-extractor": "7.59.0",
"@types/node": "catalog:",
- "gray-matter": "4.0.3",
+ "js-yaml": "4.3.2",
"oxfmt": "0.66.0",
"oxlint": "1.81.0",
"syncpack": "15.3.3",
diff --git a/packages/eve/package.json b/packages/eve/package.json
index 6343b3a29..f6899b411 100644
--- a/packages/eve/package.json
+++ b/packages/eve/package.json
@@ -581,8 +581,8 @@
"emulate": "0.6.0",
"env-runner": "0.1.16",
"eventsource-parser": "3.1.0",
- "gray-matter": "4.0.3",
"jose": "6.2.3",
+ "js-yaml": "4.3.2",
"jsonc-parser": "3.3.1",
"just-bash": "3.1.0",
"just-secrets": "0.0.2",
diff --git a/packages/eve/scripts/vendor-compiled/declarations/gray-matter.d.ts b/packages/eve/scripts/vendor-compiled/declarations/gray-matter.d.ts
deleted file mode 100644
index e4f318565..000000000
--- a/packages/eve/scripts/vendor-compiled/declarations/gray-matter.d.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-// Hand-authored ESM declaration for the vendored slice of `gray-matter`.
-// The upstream `gray-matter.d.ts` is `export =` (CJS-style) and cannot be
-// re-exported as a default ESM binding without rewriting. Only the surface
-// eve touches is typed here: invoking the default function, the static
-// `test()` predicate, and the `data`/`content` properties on the result.
-
-export type Input = string | Buffer;
-
-export interface GrayMatterOption<I extends Input, O extends GrayMatterOption<I, O>> {
- parser?: () => void;
- eval?: boolean;
- excerpt?: boolean | ((input: I, options: O) => string);
- excerpt_separator?: string;
- engines?: Record<
- string,
- ((input: string) => object) | { parse(input: string): object; stringify?(data: object): string }
- >;
- language?: string;
- delimiters?: string | [string, string];
-}
-
-export interface GrayMatterFile<I extends Input> {
- data: Record<string, unknown>;
- content: string;
- excerpt?: string;
- orig: Buffer | I;
- language: string;
- matter: string;
- stringify(lang: string): string;
-}
-
-export interface GrayMatterFunction {
- <I extends Input, O extends GrayMatterOption<I, O>>(
- input: I | { content: I },
- options?: O,
- ): GrayMatterFile<I>;
-
- test<O extends GrayMatterOption<string, O>>(
- str: string,
- options?: GrayMatterOption<string, O>,
- ): boolean;
-
- read<O extends GrayMatterOption<string, O>>(
- filepath: string,
- options?: GrayMatterOption<string, O>,
- ): GrayMatterFile<string>;
-
- stringify<O extends GrayMatterOption<string, O>>(
- file: string | { content: string },
- data: object,
- options?: GrayMatterOption<string, O>,
- ): string;
-
- language<O extends GrayMatterOption<string, O>>(
- str: string,
- options?: GrayMatterOption<string, O>,
- ): { name: string; raw: string };
-}
-
-declare const matter: GrayMatterFunction;
-
-export default matter;
diff --git a/packages/eve/scripts/vendor-compiled/declarations/js-yaml.d.ts b/packages/eve/scripts/vendor-compiled/declarations/js-yaml.d.ts
new file mode 100644
index 000000000..d24ac4018
--- /dev/null
+++ b/packages/eve/scripts/vendor-compiled/declarations/js-yaml.d.ts
@@ -0,0 +1,12 @@
+// Hand-authored declaration for the vendored slice of `js-yaml` v4, which
+// ships no types. Only `load` is vendored.
+
+export interface LoadOptions {
+ /** File name used in error messages. */
+ filename?: string;
+ /** Allows duplicate mapping keys, keeping the last value. Defaults to `false`. */
+ json?: boolean;
+}
+
+/** Parses one YAML document with the default (data-only) schema. */
+export function load(source: string, options?: LoadOptions): unknown;
diff --git a/packages/eve/scripts/vendor-compiled/entries/js-yaml.mjs b/packages/eve/scripts/vendor-compiled/entries/js-yaml.mjs
new file mode 100644
index 000000000..1178e10f2
--- /dev/null
+++ b/packages/eve/scripts/vendor-compiled/entries/js-yaml.mjs
@@ -0,0 +1 @@
+export { load } from "js-yaml";
diff --git a/packages/eve/scripts/vendor-compiled/gray-matter.mjs b/packages/eve/scripts/vendor-compiled/gray-matter.mjs
deleted file mode 100644
index a4d79b4f6..000000000
--- a/packages/eve/scripts/vendor-compiled/gray-matter.mjs
+++ /dev/null
@@ -1,21 +0,0 @@
-import { loadDeclaration } from "./_shared.mjs";
-
-/**
- * Vendor config for `gray-matter` v4. Upstream is CommonJS
- * (`module.exports = matter`) and its `.d.ts` uses the legacy
- * `export = matter` ambient-module form. Rolldown converts the CJS
- * default into an ESM default export, but the upstream declaration
- * cannot be vendored as-is for ESM consumers.
- *
- * A hand-authored ESM-style declaration covers the call signatures and
- * static methods (`matter()`, `matter.test()`) eve actually uses. The
- * surface is small and upstream is dormant (last release 2019), so
- * curated declarations have a much lower drift risk than for actively
- * developed packages.
- */
-export default {
- packageName: "gray-matter",
- compiledPath: "gray-matter",
- bundling: "standalone",
- declaration: await loadDeclaration("gray-matter.d.ts"),
-};
diff --git a/packages/eve/scripts/vendor-compiled/index.mjs b/packages/eve/scripts/vendor-compiled/index.mjs
index 3f0ef4a85..d0a22a7b4 100644
--- a/packages/eve/scripts/vendor-compiled/index.mjs
+++ b/packages/eve/scripts/vendor-compiled/index.mjs
@@ -45,8 +45,8 @@ import chokidar from "./chokidar.mjs";
import commander from "./commander.mjs";
import eventsourceParserStream from "./eventsource-parser-stream.mjs";
import envRunner from "./env-runner.mjs";
-import grayMatter from "./gray-matter.mjs";
import jose from "./jose.mjs";
+import jsYaml from "./js-yaml.mjs";
import jsoncParser from "./jsonc-parser.mjs";
import jsonSchema from "./json-schema.mjs";
import justSecrets from "./just-secrets.mjs";
@@ -74,8 +74,8 @@ export const MODULES = [
envRunner,
eveCatalog,
google,
- grayMatter,
jose,
+ jsYaml,
jsoncParser,
jsonSchema,
justSecrets,
diff --git a/packages/eve/scripts/vendor-compiled/js-yaml.mjs b/packages/eve/scripts/vendor-compiled/js-yaml.mjs
new file mode 100644
index 000000000..149cb8dcf
--- /dev/null
+++ b/packages/eve/scripts/vendor-compiled/js-yaml.mjs
@@ -0,0 +1,21 @@
+import { fileURLToPath } from "node:url";
+
+import { loadDeclaration } from "./_shared.mjs";
+
+/**
+ * Vendor config for `js-yaml` v4. Only `load` is vendored: v4's default
+ * schema has no code-evaluating `!!js/*` types, so eve can parse untrusted
+ * YAML without an esprima dependency or a guard around the parser.
+ */
+export default {
+ packageName: "js-yaml",
+ compiledPath: "js-yaml",
+ entries: [
+ {
+ input: fileURLToPath(new URL("./entries/js-yaml.mjs", import.meta.url)),
+ outputPath: "index",
+ declaration: await loadDeclaration("js-yaml.d.ts"),
+ },
+ ],
+ bundling: "standalone",
+};
diff --git a/packages/eve/src/evals/loaders/yaml.ts b/packages/eve/src/evals/loaders/yaml.ts
index 7bb16d803..3fe7cbaaa 100644
--- a/packages/eve/src/evals/loaders/yaml.ts
+++ b/packages/eve/src/evals/loaders/yaml.ts
@@ -1,7 +1,7 @@
import { readFile } from "node:fs/promises";
import { isAbsolute, resolve } from "node:path";
-import { parseFrontmatter } from "#internal/helpers/gray-matter.js";
+import { parseYaml } from "#internal/helpers/frontmatter.js";
/**
* Loads a YAML file and returns its top-level mapping as a plain object.
@@ -22,9 +22,5 @@ export async function loadYaml(filePath: string): Promise<Record<string, unknown
const resolved = isAbsolute(filePath) ? filePath : resolve(process.cwd(), filePath);
const raw = await readFile(resolved, "utf-8");
- // gray-matter parses YAML frontmatter from content. For pure YAML files
- // we wrap the content so gray-matter sees the entire file as frontmatter.
- const needsWrapper = !raw.trimStart().startsWith("---");
- const input = needsWrapper ? `---\n${raw}\n---` : raw;
- return parseFrontmatter(input).data;
+ return parseYaml(raw) as Record<string, unknown>;
}
diff --git a/packages/eve/src/internal/bundler/vendored-dependency-log.test.ts b/packages/eve/src/internal/bundler/vendored-dependency-log.test.ts
index 6866be6dd..ccd5bfef7 100644
--- a/packages/eve/src/internal/bundler/vendored-dependency-log.test.ts
+++ b/packages/eve/src/internal/bundler/vendored-dependency-log.test.ts
@@ -15,11 +15,11 @@ describe("onVendoredDependencyLog", () => {
["a Windows dependency path", { id: "C:\\app\\node_modules\\dep\\index.js" }],
[
"eve's generated vendor modules",
- { ids: ["/repo/packages/eve/.generated/compiled/gray-matter/index.js"] },
+ { ids: ["/repo/packages/eve/.generated/compiled/js-yaml/index.js"] },
],
[
"eve's published vendor modules",
- { id: "/app/node_modules/eve/dist/src/compiled/gray-matter/index.js" },
+ { id: "/app/node_modules/eve/dist/src/compiled/js-yaml/index.js" },
],
])("drops a warning raised only by %s", (_, log) => {
expect(forwardedLogs("warn", { message: "dependency detail", ...log })).toEqual([]);
diff --git a/packages/eve/src/internal/helpers/frontmatter.test.ts b/packages/eve/src/internal/helpers/frontmatter.test.ts
new file mode 100644
index 000000000..4186d7c0c
--- /dev/null
+++ b/packages/eve/src/internal/helpers/frontmatter.test.ts
@@ -0,0 +1,71 @@
+import { describe, expect, it } from "vitest";
+
+import { hasFrontmatter, parseFrontmatter, parseYaml } from "#internal/helpers/frontmatter.js";
+
+describe("parseFrontmatter", () => {
+ it.each([
+ ["LF", "---\ntitle: T\n---\nhello\n"],
+ ["CRLF", "---\r\ntitle: T\r\n---\r\nhello\r\n"],
+ ["a byte order mark", "\uFEFF---\ntitle: T\n---\nhello\n"],
+ ["an explicit yaml fence", "---yaml\ntitle: T\n---\nhello\n"],
+ ])("splits frontmatter and body with %s", (_label, source) => {
+ const document = parseFrontmatter(source);
+ expect(document?.data).toEqual({ title: "T" });
+ expect(document?.content.trimEnd()).toBe("hello");
+ });
+
+ it("parses an empty block to an empty object", () => {
+ expect(parseFrontmatter("---\n---\nbody")).toEqual({ data: {}, content: "body" });
+ });
+
+ it.each([
+ ["no opening fence", "title: T\n---\n"],
+ ["a horizontal rule", "----\ntitle: T\n----\n"],
+ ["no closing fence", "---\ntitle: T\nbody"],
+ ])("returns undefined for %s", (_label, source) => {
+ expect(parseFrontmatter(source)).toBeUndefined();
+ });
+
+ it.each(["js", "javascript", "coffee"])(
+ "rejects a %s fence without evaluating it",
+ (language) => {
+ const marker = `eve_frontmatter_${language}_marker`;
+ const source = `---${language}\n(globalThis[${JSON.stringify(marker)}] = true)\n---\n`;
+
+ expect(() => parseFrontmatter(source)).toThrow(`Frontmatter language "${language}"`);
+ expect(Reflect.get(globalThis, marker)).toBeUndefined();
+ },
+ );
+
+ it("refuses code-evaluating YAML tags", () => {
+ expect(() =>
+ parseFrontmatter('---\nrun: !!js/function "function () { return 1; }"\n---\n'),
+ ).toThrow(/unknown tag/);
+ });
+});
+
+describe("hasFrontmatter", () => {
+ it.each([
+ ["---\ntitle: T\n---\n", true],
+ ["---js\n1\n---\n", true],
+ ["\uFEFF---\n", true],
+ ["----\n", false],
+ ["no frontmatter", false],
+ ])("detects the opening fence in %j", (source, expected) => {
+ expect(hasFrontmatter(source)).toBe(expected);
+ });
+});
+
+describe("parseYaml", () => {
+ it.each([
+ ["a plain YAML file", "name: test\n"],
+ ["a fenced YAML file", "---\nname: test\n---\n"],
+ ["a leading document marker without a closing fence", "---\nname: test\n"],
+ ])("parses %s", (_label, source) => {
+ expect(parseYaml(source)).toEqual({ name: "test" });
+ });
+
+ it.each(["", "# comment only\n"])("parses %j to an empty object", (source) => {
+ expect(parseYaml(source)).toEqual({});
+ });
+});
diff --git a/packages/eve/src/internal/helpers/frontmatter.ts b/packages/eve/src/internal/helpers/frontmatter.ts
new file mode 100644
index 000000000..8ad32e74d
--- /dev/null
+++ b/packages/eve/src/internal/helpers/frontmatter.ts
@@ -0,0 +1,55 @@
+import { load } from "#compiled/js-yaml/index.js";
+
+/** A document split into its YAML frontmatter and body. */
+export interface FrontmatterDocument {
+ /** Parsed frontmatter. An empty block parses to `{}`. */
+ readonly data: unknown;
+ /** Body after the closing delimiter line. */
+ readonly content: string;
+}
+
+const OPENING_FENCE = /^\uFEFF?---(?!-)([^\r\n]*)(?:\r?\n|$)/;
+const CLOSING_FENCE = /^---[ \t]*(?:\r?\n|$)/m;
+
+/** Reports whether a document opens with a `---` frontmatter delimiter. */
+export function hasFrontmatter(source: string): boolean {
+ return OPENING_FENCE.test(source);
+}
+
+/**
+ * Splits a document into YAML frontmatter and body. Returns `undefined` when
+ * the document has no complete `---` block.
+ *
+ * Frontmatter is always data: js-yaml's default schema has no code-evaluating
+ * types, and a fence that names any language other than YAML, such as `---js`,
+ * throws instead of being interpreted.
+ */
+export function parseFrontmatter(source: string): FrontmatterDocument | undefined {
+ const opening = OPENING_FENCE.exec(source);
+ if (opening === null) return undefined;
+
+ const language = opening[1]!.trim();
+ if (language !== "" && language.toLowerCase() !== "yaml") {
+ throw new Error(`Frontmatter language "${language}" is not supported. Use YAML frontmatter.`);
+ }
+
+ const rest = source.slice(opening[0].length);
+ const closing = CLOSING_FENCE.exec(rest);
+ if (closing === null) return undefined;
+
+ const yaml = rest.slice(0, closing.index);
+ return {
+ data: (yaml.trim() === "" ? undefined : load(yaml)) ?? {},
+ content: rest.slice(closing.index + closing[0].length),
+ };
+}
+
+/**
+ * Parses a YAML file. A file that opens and closes a `---` block parses only
+ * that block, so frontmatter-style YAML files keep working. An empty file
+ * parses to `{}`.
+ */
+export function parseYaml(source: string): unknown {
+ const frontmatter = parseFrontmatter(source);
+ return frontmatter === undefined ? (load(source) ?? {}) : frontmatter.data;
+}
diff --git a/packages/eve/src/internal/helpers/gray-matter.test.ts b/packages/eve/src/internal/helpers/gray-matter.test.ts
deleted file mode 100644
index 439ec08eb..000000000
--- a/packages/eve/src/internal/helpers/gray-matter.test.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-import { describe, expect, it } from "vitest";
-
-import { hasFrontmatter, parseFrontmatter } from "#internal/helpers/gray-matter.js";
-
-describe("parseFrontmatter", () => {
- it("parses YAML frontmatter into data and body", () => {
- const doc = parseFrontmatter("---\ntitle: T\n---\nhello");
- expect(doc.data).toEqual({ title: "T" });
- expect(doc.content.trim()).toBe("hello");
- });
-
- it("rejects a JavaScript frontmatter fence by default without evaluating it", () => {
- const marker = "eve_gray_matter_default_marker";
- const source = `---js\n(globalThis[${JSON.stringify(marker)}] = true)\n---\n`;
-
- expect(() => parseFrontmatter(source)).toThrow(/JavaScript frontmatter is not supported/);
- expect((globalThis as Record<string, unknown>)[marker]).toBeUndefined();
- });
-
- it("evaluates a JavaScript fence only when allowCodeEngines is opted in", () => {
- const marker = "eve_gray_matter_optin_marker";
- const source = `---js\n(globalThis[${JSON.stringify(marker)}] = true)\n---\n`;
-
- parseFrontmatter(source, { allowCodeEngines: true });
- expect((globalThis as Record<string, unknown>)[marker]).toBe(true);
- delete (globalThis as Record<string, unknown>)[marker];
- });
-
- it("detects a leading frontmatter delimiter", () => {
- expect(hasFrontmatter("---\ntitle: T\n---\n")).toBe(true);
- expect(hasFrontmatter("no frontmatter")).toBe(false);
- });
-});
diff --git a/packages/eve/src/internal/helpers/gray-matter.ts b/packages/eve/src/internal/helpers/gray-matter.ts
deleted file mode 100644
index 641cfb1e7..000000000
--- a/packages/eve/src/internal/helpers/gray-matter.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-import matter, { type GrayMatterFile } from "#compiled/gray-matter/index.js";
-
-/**
- * gray-matter ships built-in `javascript`/`js` frontmatter engines that
- * `eval()` the frontmatter body, so a document whose opening fence is
- * `---js` (or `---javascript`) executes that body the instant it is parsed —
- * before any validation runs. eve treats frontmatter strictly as data, so
- * these options disable the code-capable engines and pin the default language
- * to YAML. Pinning `language` alone is not enough: gray-matter reads the
- * language named after the opening fence and uses it in preference to the
- * option, so the engines must be replaced as well.
- */
-function rejectJavaScriptFrontmatter(): never {
- throw new Error("JavaScript frontmatter is not supported.");
-}
-
-const SAFE_GRAY_MATTER_OPTIONS = {
- language: "yaml",
- engines: {
- javascript: rejectJavaScriptFrontmatter,
- js: rejectJavaScriptFrontmatter,
- },
-} as const;
-
-/** Options for {@link parseFrontmatter}. */
-export interface ParseFrontmatterOptions {
- /**
- * Opt in to gray-matter's built-in code-capable engines, so a `---js` /
- * `---javascript` frontmatter fence is `eval()`d while parsing. This runs
- * arbitrary code the instant the document is read, so only enable it for
- * input you fully control and trust. Defaults to `false`, which rejects a
- * JavaScript frontmatter fence instead of evaluating it.
- */
- readonly allowCodeEngines?: boolean;
-}
-
-/**
- * Parses a document's YAML frontmatter and body.
- *
- * Safe by default: the code-capable frontmatter engines are disabled, so a
- * `---js` fence throws rather than executing. This is the only supported way
- * to run gray-matter in eve — callers must not import the bundled module
- * directly, so that untrusted input can never reach an evaluating engine by
- * accident. Pass `{ allowCodeEngines: true }` to deliberately opt back into
- * evaluation for trusted input.
- */
-export function parseFrontmatter(
- source: string,
- options: ParseFrontmatterOptions = {},
-): GrayMatterFile<string> {
- return options.allowCodeEngines ? matter(source) : matter(source, SAFE_GRAY_MATTER_OPTIONS);
-}
-
-/** Reports whether a document opens with a frontmatter delimiter. */
-export function hasFrontmatter(source: string): boolean {
- return matter.test(source);
-}
diff --git a/packages/eve/src/internal/helpers/markdown.test.ts b/packages/eve/src/internal/helpers/markdown.test.ts
index b50d6f2a2..ea9333118 100644
--- a/packages/eve/src/internal/helpers/markdown.test.ts
+++ b/packages/eve/src/internal/helpers/markdown.test.ts
@@ -214,14 +214,14 @@ plain markdown`),
});
it("rejects JavaScript frontmatter in skill markdown instead of evaluating it", () => {
- // gray-matter's built-in `javascript` engine would `eval()` the frontmatter
- // body, so a `---javascript` fence must throw rather than execute code.
const malicious = `---javascript
globalThis.__eveMarkdownRce = true
---
When the user asks about weather, call the weather tool before answering.`;
- expect(() => lowerSkillMarkdown(malicious)).toThrow("JavaScript frontmatter is not supported.");
+ expect(() => lowerSkillMarkdown(malicious)).toThrow(
+ 'Frontmatter language "javascript" is not supported.',
+ );
expect(Reflect.get(globalThis, "__eveMarkdownRce")).toBeUndefined();
});
@@ -232,7 +232,7 @@ globalThis.__eveScheduleRce = true
body`;
expect(() => lowerScheduleMarkdown(malicious)).toThrow(
- "JavaScript frontmatter is not supported.",
+ 'Frontmatter language "js" is not supported.',
);
expect(Reflect.get(globalThis, "__eveScheduleRce")).toBeUndefined();
});
diff --git a/packages/eve/src/internal/helpers/markdown.ts b/packages/eve/src/internal/helpers/markdown.ts
index 8e51a405e..e050fe688 100644
--- a/packages/eve/src/internal/helpers/markdown.ts
+++ b/packages/eve/src/internal/helpers/markdown.ts
@@ -1,4 +1,4 @@
-import { parseFrontmatter, hasFrontmatter } from "#internal/helpers/gray-matter.js";
+import { parseFrontmatter, hasFrontmatter } from "#internal/helpers/frontmatter.js";
import {
normalizeScheduleDefinition,
normalizeSkillDefinition,
@@ -9,8 +9,6 @@ import { defineSchedule, type ScheduleDefinition } from "#public/definitions/sch
import { defineSkill, type SkillDefinition } from "#public/definitions/skill.js";
import type { InstructionsDefinition } from "#public/definitions/instructions.js";
-const CLOSED_FRONTMATTER_PATTERN = /^---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/;
-
/**
* Parsed markdown document with optional YAML frontmatter.
*/
@@ -42,19 +40,9 @@ function parseMarkdownDocument(source: string): ParsedMarkdownDocument {
};
}
- let document: {
- content: string;
- data: unknown;
- };
-
- try {
- document = parseFrontmatter(source);
- } catch (error) {
- if (startsWithFrontmatterFence(source) && !hasClosedFrontmatterFence(source)) {
- throw new Error("Markdown frontmatter is missing a closing delimiter.");
- }
-
- throw error;
+ const document = parseFrontmatter(source);
+ if (document === undefined) {
+ throw new Error("Markdown frontmatter is missing a closing delimiter.");
}
if (!isObject(document.data)) {
@@ -173,14 +161,6 @@ export function lowerSkillMarkdown(
);
}
-function startsWithFrontmatterFence(source: string): boolean {
- return source.startsWith("---\n") || source.startsWith("---\r\n");
-}
-
-function hasClosedFrontmatterFence(source: string): boolean {
- return CLOSED_FRONTMATTER_PATTERN.test(source);
-}
-
function normalizeFrontmatterMarkdownBody(markdown: string): string {
return markdown.replace(/^\r?\n/u, "");
}
diff --git a/packages/eve/src/internal/nitro/host/create-application-nitro.ts b/packages/eve/src/internal/nitro/host/create-application-nitro.ts
index 8b280c1cd..9ed011215 100644
--- a/packages/eve/src/internal/nitro/host/create-application-nitro.ts
+++ b/packages/eve/src/internal/nitro/host/create-application-nitro.ts
@@ -809,6 +809,8 @@ export async function createProductionApplicationNitro(
features: {
websocket: manifestHasWebSocketChannel(preparedHost.compileResult.manifest),
},
+ // Gzipping every output file only annotates the build log's file tree.
+ logging: { compressedSizes: false },
output: { dir: options.outputDir },
preset,
plugins: nitroPlugins,
diff --git a/packages/eve/src/internal/nitro/host/nitro-bundler-config.test.ts b/packages/eve/src/internal/nitro/host/nitro-bundler-config.test.ts
index 5a53595f4..5f3705116 100644
--- a/packages/eve/src/internal/nitro/host/nitro-bundler-config.test.ts
+++ b/packages/eve/src/internal/nitro/host/nitro-bundler-config.test.ts
@@ -1,11 +1,29 @@
-import { describe, expect, it } from "vitest";
-
-import { onVendoredDependencyLog } from "#internal/bundler/vendored-dependency-log.js";
+import { describe, expect, it, vi } from "vitest";
import { createNitroBundlerConfig } from "./nitro-bundler-config.js";
+type OnLog = (
+ level: string,
+ log: unknown,
+ defaultHandler: (level: string, log: unknown) => void,
+) => void;
+
describe("createNitroBundlerConfig", () => {
- it("filters vendored dependency warnings from hosted builds", () => {
- expect(createNitroBundlerConfig([]).onLog).toBe(onVendoredDependencyLog);
+ it.each([
+ ["Nitro's unlabeled code-splitting group", { code: "MISSING_CODE_SPLITTING_GROUP_DEBUG_NAME" }],
+ ["vendored dependency code", { code: "EVAL", id: "/app/node_modules/pkg/index.js" }],
+ ])("drops warnings about %s", (_label, log) => {
+ const onLog = createNitroBundlerConfig([]).onLog as OnLog;
+ const defaultHandler = vi.fn();
+ onLog("warn", log, defaultHandler);
+ expect(defaultHandler).not.toHaveBeenCalled();
+ });
+
+ it("forwards warnings about authored code", () => {
+ const onLog = createNitroBundlerConfig([]).onLog as OnLog;
+ const defaultHandler = vi.fn();
+ const log = { code: "EVAL", id: "/app/agent/tools/weather.ts" };
+ onLog("warn", log, defaultHandler);
+ expect(defaultHandler).toHaveBeenCalledWith("warn", log);
});
});
diff --git a/packages/eve/src/internal/nitro/host/nitro-bundler-config.ts b/packages/eve/src/internal/nitro/host/nitro-bundler-config.ts
index 758fde8fd..55b732ea5 100644
--- a/packages/eve/src/internal/nitro/host/nitro-bundler-config.ts
+++ b/packages/eve/src/internal/nitro/host/nitro-bundler-config.ts
@@ -1,13 +1,36 @@
-import { onVendoredDependencyLog } from "#internal/bundler/vendored-dependency-log.js";
+import {
+ type BundlerDefaultLogHandler,
+ onVendoredDependencyLog,
+} from "#internal/bundler/vendored-dependency-log.js";
import { createNodeEsmCompatBannerPlugin } from "#internal/node-esm-compat-banner.js";
+// Nitro's default `codeSplitting` group names chunks with a function and no
+// `debugName`. Newer Rolldown releases warn about the missing timing label on
+// every build, while older releases in Nitro's range reject the key, so eve
+// cannot set it for Nitro.
+const MISSING_CODE_SPLITTING_GROUP_DEBUG_NAME = "MISSING_CODE_SPLITTING_GROUP_DEBUG_NAME";
+
+function onNitroBundlerLog(
+ level: string,
+ log: unknown,
+ defaultHandler: BundlerDefaultLogHandler,
+): void {
+ if (
+ level === "warn" &&
+ (log as { code?: unknown } | null)?.code === MISSING_CODE_SPLITTING_GROUP_DEBUG_NAME
+ ) {
+ return;
+ }
+ onVendoredDependencyLog(level, log, defaultHandler);
+}
+
/**
* Creates eve-owned Nitro bundler overrides that must apply to both Rollup
* and Rolldown hosted builds.
*/
export function createNitroBundlerConfig(plugins: readonly object[]): Record<string, unknown> {
return {
- onLog: onVendoredDependencyLog,
+ onLog: onNitroBundlerLog,
plugins: [createNodeEsmCompatBannerPlugin(), ...plugins],
};
}
diff --git a/packages/eve/src/internal/node-esm-compat-banner.test.ts b/packages/eve/src/internal/node-esm-compat-banner.test.ts
index 60b7df003..9a6029d1a 100644
--- a/packages/eve/src/internal/node-esm-compat-banner.test.ts
+++ b/packages/eve/src/internal/node-esm-compat-banner.test.ts
@@ -155,6 +155,18 @@ describe("createNodeEsmCompatBannerPlugin", () => {
expect(result?.code).toContain("const __dirname =");
});
+ it("does not parse chunks that only declare bundler-suffixed bindings", () => {
+ const parse = vi.fn(() => EMPTY_PROGRAM);
+ const code =
+ "const require$1 = createRequire$1(import.meta.url);\nconst __filename$1 = fileURLToPath$1(import.meta.url), __dirname$1 = dirname$1(__filename$1);";
+ const result = createNodeEsmCompatBannerPlugin({ includeRequire: true }).renderChunk.call(
+ { parse },
+ code,
+ );
+ expect(parse).not.toHaveBeenCalled();
+ expect(result?.code).toContain("const __dirname =");
+ });
+
it.each([
String.raw`const separators = /[\u2028,\u2029]/; export const value = __dirname;`,
String.raw`const label = "caf\u00e9", other\u0041 = 1; export const value = __dirname;`,
diff --git a/packages/eve/src/internal/node-esm-compat-banner.ts b/packages/eve/src/internal/node-esm-compat-banner.ts
index 02b3f1c2d..2151919ab 100644
--- a/packages/eve/src/internal/node-esm-compat-banner.ts
+++ b/packages/eve/src/internal/node-esm-compat-banner.ts
@@ -179,10 +179,15 @@ const DECLARATION_TRIVIA = String.raw`(?:\s|/\*(?:[^*]|\*(?!/))*\*/|//[^\r\n\u20
// own banner templates are bundled into every dev host, so without the
// lookbehind they would force a full parse of eve's largest chunk.
const DECLARATION_START = String.raw`(?:(?<![\w$"'\x60])(?:var|let|const|using)\b|,)${DECLARATION_TRIVIA}`;
+// `\b` would accept bundler-deconflicted names such as `__filename$1`, which
+// force a full parse of eve's largest vendor chunk on every hosted build.
+const BINDING_END = String.raw`(?![\w$])`;
const PATH_BINDING_DECLARATION = new RegExp(
- String.raw`${DECLARATION_START}(?:__filename|__dirname)\b`,
+ String.raw`${DECLARATION_START}(?:__filename|__dirname)${BINDING_END}`,
+);
+const REQUIRE_BINDING_DECLARATION = new RegExp(
+ String.raw`${DECLARATION_START}require${BINDING_END}`,
);
-const REQUIRE_BINDING_DECLARATION = new RegExp(String.raw`${DECLARATION_START}require\b`);
const IDENTIFIER_ESCAPE = String.raw`\\u(?:[\da-fA-F]{4}|\{[\da-fA-F]+\})`;
const ESCAPED_IDENTIFIER_DECLARATION = new RegExp(
String.raw`${DECLARATION_START}([\w$]*(?:${IDENTIFIER_ESCAPE}[\w$]*)+)`,
diff --git a/packages/eve/src/runtime/connections/openapi-spec.test.ts b/packages/eve/src/runtime/connections/openapi-spec.test.ts
index 724f0701b..a310b5460 100644
--- a/packages/eve/src/runtime/connections/openapi-spec.test.ts
+++ b/packages/eve/src/runtime/connections/openapi-spec.test.ts
@@ -18,7 +18,7 @@ describe("parseSpecDocument", () => {
const marker = "eve_openapi_spec_js_marker";
const body = `---js\n(globalThis[${JSON.stringify(marker)}] = true)\n---\n`;
- expect(() => parseSpecDocument(body)).toThrow(/JavaScript frontmatter is not supported/);
+ expect(() => parseSpecDocument(body)).toThrow('Frontmatter language "js" is not supported.');
expect((globalThis as Record<string, unknown>)[marker]).toBeUndefined();
});
});
diff --git a/packages/eve/src/runtime/connections/openapi-spec.ts b/packages/eve/src/runtime/connections/openapi-spec.ts
index b39a70456..ec30d4d9c 100644
--- a/packages/eve/src/runtime/connections/openapi-spec.ts
+++ b/packages/eve/src/runtime/connections/openapi-spec.ts
@@ -1,4 +1,4 @@
-import { parseFrontmatter } from "#internal/helpers/gray-matter.js";
+import { parseYaml } from "#internal/helpers/frontmatter.js";
import { isArray } from "#runtime/connections/openapi-schema.js";
import { isObject } from "#shared/guards.js";
@@ -6,10 +6,7 @@ import { isObject } from "#shared/guards.js";
* Parses a fetched spec body as either JSON or YAML.
*
* JSON is tried first (the common case and fastest path); on a parse
- * failure the body is treated as YAML. YAML is parsed by wrapping the
- * document in front-matter delimiters so the bundled `gray-matter`
- * engine reads the whole file — the same approach the eval YAML loader
- * uses, avoiding a second YAML dependency.
+ * failure the body is treated as YAML.
*/
export function parseSpecDocument(text: string): unknown {
try {
@@ -17,9 +14,7 @@ export function parseSpecDocument(text: string): unknown {
} catch {
// Not JSON — fall through to YAML.
}
- const body = text.replace(/^\uFEFF/, "");
- const wrapped = body.trimStart().startsWith("---") ? body : `---\n${body}\n---`;
- return parseFrontmatter(wrapped).data;
+ return parseYaml(text.replace(/^\uFEFF/, ""));
}
/**
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 67ac4200f..06fa00d89 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -268,9 +268,9 @@ importers:
'@types/node':
specifier: 'catalog:'
version: 24.13.3
- gray-matter:
- specifier: 4.0.3
- version: 4.0.3
+ js-yaml:
+ specifier: 4.3.2
+ version: 4.3.2
oxfmt:
specifier: 0.66.0
version: 0.66.0([email protected](@typescript-eslint/[email protected]))
@@ -1737,12 +1737,12 @@ importers:
eventsource-parser:
specifier: 3.1.0
version: 3.1.0
- gray-matter:
- specifier: 4.0.3
- version: 4.0.3
jose:
specifier: 6.2.3
version: 6.2.3
+ js-yaml:
+ specifier: 4.3.2
+ version: 4.3.2
jsonc-parser:
specifier: 3.3.1
version: 3.3.1
@@ -9672,10 +9672,6 @@ packages:
resolution: {integrity: sha512-9U/jZUgjnSGyntRr6y5Muu1MJcwFl6kPu7k8qLF0IMNfLqvw0NZ4nnVDq0RVoZ0RvCyumib4Ez3KYrVfilrw+g==}
- resolution: {integrity: sha512-zCnTtlxNoAiDc3gqY2aYAWFx7XWWiasuF2K8Me5WbN8otHKTUKBwjPtNpRs/rbUZm7KxWAaNj7P1a/p52GbVug==}
- engines: {node: '>=0.10.0'}
-
resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==}
@@ -10172,10 +10168,6 @@ packages:
engines: {node: '>=14.0.0'}
hasBin: true
- resolution: {integrity: sha512-5v6yZd4JK3eMI3FqqCouswVqwugaA9r4dNZB1wwcmrD02QkV5H0y7XBQW8QwQqEaZY1pM9aqORSORhJRdNK44Q==}
- engines: {node: '>=6.0'}
-
resolution: {integrity: sha512-+CqsMbHPiSTdtSO14O51eMNlrp9N79gmeqmXeouJOhfucAedHw9noVe/n5uJk3tbKE6a+6ZCQg3RPhVhHByAIw==}
engines: {node: '>=18'}
@@ -10565,10 +10557,6 @@ packages:
resolution: {integrity: sha512-FO/Rhvz5tuw4MCWkpMzHFKWD2LsfHzIb7i6MdPYZ/KW7AlxawyLkqdy+jPZP1WubqEADE3O4FUENlJHDfQASRg==}
- resolution: {integrity: sha512-5BMULNob1vgFX6EjQw5izWDxrecWK9AM72rugNr0TFldMOi0fj6Jk+zeKIt0xGj4cEfQIJth4w3OKWOJ4f+AFw==}
- engines: {node: '>=0.10.0'}
-
resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==}
engines: {node: '>=0.10.0'}
@@ -10812,10 +10800,6 @@ packages:
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
- resolution: {integrity: sha512-6EuL879VkRA+1Cz578mKMiKvjPNEuk6+r1JaFzoSWejZmtf7xWbIyw1e3KkxlkzTIt9Taw6JBhEppG7utc1P+w==}
- hasBin: true
-
resolution: {integrity: sha512-SFNOvSJ+Dgf/9An904Yx+CgSlIPCkIpao4qo51lpee25TIRejdH3rhR4EZMGoNx3/TP3O+wzWuiTFl4sqbltzA==}
hasBin: true
@@ -10912,10 +10896,6 @@ packages:
resolution: {integrity: sha512-Ls993zuzfayK269Svk9hzpeGUKob/sIgZzyHYdjQoAdQetRKpOLj+k/QQQ/6Qi0Yz65mlROrfd+Ev+1+7dz9Kw==}
- resolution: {integrity: sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==}
- engines: {node: '>=0.10.0'}
-
resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==}
engines: {node: '>=6'}
@@ -13250,10 +13230,6 @@ packages:
resolution: {integrity: sha512-gfYVRGxjHkGF2NPeUWHw5u6T/KGFtS5/drPms73gaSuMaVHKCY3lpLnGDfswVQO0kddeePoti09AwhYP4zA8dQ==}
hasBin: true
- resolution: {integrity: sha512-vfD3pmTzGpufjScBh50YHKzEu2lxBWhVEHsNGoEXmCmn2hKGfeNLYMzCJpe8cD7gqX7TJluOVpBkAequ6dgMmA==}
- engines: {node: '>=4'}
-
resolution: {integrity: sha512-6aU+Rwsezw7VR8/nyvKTx8QpWH9FrcYiXXlqC4z5d5XQBDRqtbfsRjnwGyqbi3gddNtWHuEk9OANUotL26qKUw==}
@@ -13639,10 +13615,6 @@ packages:
resolution: {integrity: sha512-yDPMNjp4WyfYBkHnjIRLfca1i6KMyGCtsVgoKe/z1+6vukgaENdgGBZt+ZmKPc4gavvEZ5OgHfHdrazhgNyG7w==}
engines: {node: '>=12'}
- resolution: {integrity: sha512-uCC2VHvQRYu+lMh4My/sFNmF2klFymLX1wHJeXnbEJERpV/ZsVuonzerjfrGpIGF7LBVa1O7i9kjiWvJiFck8g==}
- engines: {node: '>=0.10.0'}
-
resolution: {integrity: sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==}
engines: {node: '>=4'}
@@ -23730,10 +23702,6 @@ snapshots:
- dependencies:
- is-extendable: 0.1.1
-
@@ -24394,13 +24362,6 @@ snapshots:
- supports-color
- typescript
- dependencies:
- js-yaml: 3.15.2
- kind-of: 6.0.3
- section-matter: 1.0.0
- strip-bom-string: 1.0.0
-
dependencies:
gaxios: 7.1.3([email protected])
@@ -24917,8 +24878,6 @@ snapshots:
-
@@ -25132,11 +25091,6 @@ snapshots:
- dependencies:
- argparse: 1.0.10
- esprima: 4.0.1
-
dependencies:
argparse: 2.0.1
@@ -25240,8 +25194,6 @@ snapshots:
-
@@ -28718,11 +28670,6 @@ snapshots:
- dependencies:
- extend-shallow: 2.0.1
- kind-of: 6.0.3
-
@@ -29301,8 +29248,6 @@ snapshots:
dependencies:
ansi-regex: 6.3.0
-
diff --git a/scripts/guard-invariants.mjs b/scripts/guard-invariants.mjs
index 46865fffd..3098716ed 100644
--- a/scripts/guard-invariants.mjs
+++ b/scripts/guard-invariants.mjs
@@ -78,11 +78,6 @@
* `queue-namespace.ts`. The generated agent bootstrap installs the
* agent-scoped namespace before queue-producing APIs can run.
* rule 34 — `phase` stays a runtime-only dependency. No file under the Eve\n * logo renderer's GPU/runtime boundary (render/, shaders/, or the\n * offline render harness) may import the `phase` package. This keeps\n * the mechanical separation between the lifecycle layer and the GPU\n * renderer enforceable.
- * rule 35 — No direct `#compiled/gray-matter` imports outside the
- * `internal/helpers/gray-matter.ts` wrapper. gray-matter's default
- * engines `eval()` a `---js` frontmatter fence, so every call must
- * route through `parseFrontmatter`, which is safe by default. A
- * direct import lets untrusted input reach an evaluating engine.
* rule 36 — Extension capability epochs have immutable hashed API metadata
* and explicit support history. The current hash must match the
* authoring roots, every historical epoch must be supported or
@@ -135,7 +130,7 @@ import { glob, readFile, readdir, lstat } from "node:fs/promises";
import { createRequire } from "node:module";
import { dirname, join, relative, resolve, sep } from "node:path";
import { fileURLToPath } from "node:url";
-import matter from "gray-matter";
+import { load as loadYaml } from "js-yaml";
import { checkExtensionCapabilityContracts } from "./extension-capability-contracts.mjs";
const require = createRequire(import.meta.url);
@@ -144,6 +139,26 @@ const ts = extractorRequire("typescript");
const REPO_ROOT = resolve(fileURLToPath(import.meta.url), "../..");
const BASELINE_PATH = join(REPO_ROOT, "scripts/guard-invariants-baseline.json");
+const FRONTMATTER_RE = /^\uFEFF?---\r?\n([\s\S]*?)^---[ \t]*(?:\r?\n|$)/m;
+
+/**
+ * Parses a Markdown document's YAML frontmatter. Returns `undefined` when the
+ * document has no complete leading `---` block.
+ *
+ * @param {string} content
+ * @returns {unknown}
+ */
+function readFrontmatter(content) {
+ const match = FRONTMATTER_RE.exec(content);
+ if (match === null || match.index !== 0) return undefined;
+ return loadYaml(match[1] ?? "") ?? {};
+}
+
+/** @param {string} content */
+function startsWithFrontmatter(content) {
+ return /^\uFEFF?---/.test(content);
+}
+
const SKIP_DIRS = new Set([
"node_modules",
".git",
@@ -218,7 +233,6 @@ function isTsLike(relPath) {
* rule27: Violation[];
* rule28: Violation[];
* rule33: Violation[];
- * rule35: Violation[];
* rule37: Violation[];
* rule43: Violation[];
* rule44: Violation[];
@@ -252,7 +266,6 @@ async function scanRepo(state) {
checkRule27(posix, lines, state.rule27);
checkRule28(posix, lines, state.rule28);
checkRule33(posix, lines, state.rule33);
- checkRule35(posix, lines, state.rule35);
checkRule37(posix, content, state.rule37);
checkRule43(posix, lines, state.rule43);
checkRule44(posix, lines, state.rule44);
@@ -563,33 +576,6 @@ function checkRule33(posix, lines, violations) {
});
}
-// ---------- Rule 35: direct gray-matter imports ----------
-
-const GRAY_MATTER_SPECIFIER_RE = /["']#compiled\/gray-matter(?:\/[^"']+)?["']/;
-const GRAY_MATTER_FACADE = "packages/eve/src/internal/helpers/gray-matter.ts";
-
-/**
- * @param {string} posix
- * @param {string[]} lines
- * @param {Violation[]} violations
- */
-function checkRule35(posix, lines, violations) {
- if (posix === GRAY_MATTER_FACADE) return;
- lines.forEach((line, idx) => {
- const isImport =
- /^(?:import|export)\b|^}\s*from\b|\b(?:import|require)\s*\(/.test(line.trimStart()) &&
- GRAY_MATTER_SPECIFIER_RE.test(line);
- if (isImport) {
- violations.push({
- rule: 35,
- file: posix,
- line: idx + 1,
- message: `imports "#compiled/gray-matter" directly. gray-matter's default engines eval() a \`---js\` frontmatter fence, so parse through parseFrontmatter() from "#internal/helpers/gray-matter.js" instead — it is safe by default and takes an explicit { allowCodeEngines: true } opt-in for trusted input.`,
- });
- }
- });
-}
-
// ---------- Rule 37: instrumentation lifecycle provider boundary ----------
const INSTRUMENTATION_LIFECYCLE_CONTRACT = "packages/eve/src/instrumentation/lifecycle.ts";
@@ -1029,7 +1015,7 @@ async function checkRule29ChangesetPackageNames() {
const relPath = `${CHANGESET_DIR}/${entry.name}`;
const content = await readFile(join(REPO_ROOT, relPath), "utf8");
- if (!matter.test(content)) {
+ if (!startsWithFrontmatter(content)) {
violations.push({
rule: 29,
file: relPath,
@@ -1041,7 +1027,7 @@ async function checkRule29ChangesetPackageNames() {
let data;
try {
- data = matter(content).data;
+ data = readFrontmatter(content);
} catch (error) {
violations.push({
rule: 29,
@@ -1215,7 +1201,7 @@ async function checkRule32ResearchFrontmatter() {
if (!posix.endsWith(".md")) continue;
const content = await readFile(absPath, "utf8");
- if (!matter.test(content)) {
+ if (!startsWithFrontmatter(content)) {
violations.push({
rule: 32,
file: posix,
@@ -1227,7 +1213,7 @@ async function checkRule32ResearchFrontmatter() {
let data;
try {
- data = matter(content).data;
+ data = readFrontmatter(content);
} catch (error) {
violations.push({
rule: 32,
@@ -1547,7 +1533,6 @@ async function main() {
rule27: /** @type {Violation[]} */ ([]),
rule28: /** @type {Violation[]} */ ([]),
rule33: /** @type {Violation[]} */ ([]),
- rule35: /** @type {Violation[]} */ ([]),
rule37: /** @type {Violation[]} */ ([]),
rule43: /** @type {Violation[]} */ ([]),
rule44: /** @type {Violation[]} */ ([]),
@@ -1643,9 +1628,6 @@ async function main() {
// Rule 34
violations.push(...(await checkRule34PhaseBoundary()));
- // Rule 35
- violations.push(...state.rule35);
-
// Rule 36
for (const issue of await checkExtensionCapabilityContracts()) {
violations.push({ rule: 36, ...issue });