From 2401703dbd6c7607d47766e8b6fd573774346edf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 21:07:02 +0000 Subject: [PATCH 1/7] chore(deps): bump posthog-node from 5.73.0 to 6.0.5 Bumps [posthog-node](https://github.com/PostHog/posthog-js/tree/HEAD/packages/node) from 5.73.0 to 6.0.5. - [Release notes](https://github.com/PostHog/posthog-js/releases) - [Changelog](https://github.com/PostHog/posthog-js/blob/main/packages/node/CHANGELOG.md) - [Commits](https://github.com/PostHog/posthog-js/commits/posthog-node@6.0.5/packages/node) --- updated-dependencies: - dependency-name: posthog-node dependency-version: 6.0.5 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- bun.lock | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bun.lock b/bun.lock index db420579b..c9abb3317 100644 --- a/bun.lock +++ b/bun.lock @@ -7,7 +7,7 @@ "dependencies": { "html-to-image": "^1.11.13", "jsonc-parser": "^3.3.1", - "posthog-node": "^5.50.0", + "posthog-node": "^6.0.5", "smol-toml": "^1.9.1", "sql.js": "^1.14.1", "yaml": "^2.9.0", @@ -235,9 +235,9 @@ "@oxc-project/types": ["@oxc-project/types@0.139.0", "", {}, "sha512-r9gHphtCs+1M7J0pw6Sn/hh/Wpa/iQrOOkrNAlVLF/gHq+/CJmHIWKKUUhdWjcD6CIa8idarspCsASiXCXvFUw=="], - "@posthog/core": ["@posthog/core@1.68.0", "", { "dependencies": { "@posthog/types": "^1.425.1" } }, "sha512-5kjPcLquzj47qBGn52+7RRXrJJvrTHaRKgxV9izYPFzoVFEftFqSXYZF/ug+yialxDU73dR9apyi+mSaAeaXPw=="], + "@posthog/core": ["@posthog/core@1.69.2", "", { "dependencies": { "@posthog/types": "^1.427.0" } }, "sha512-toMfPKklwLW+a4ZY3/EzM3GNMVXmk2ylGb8NPJXRH4igXMoI8wgNL2jqXOiglWAXqFBLZGYFN1oQx6LVmUTxTg=="], - "@posthog/types": ["@posthog/types@1.425.1", "", {}, "sha512-mh7jyQ5lN+XCeOnMdYkBEFtO/G0TxeLOKTWNH6E6OZjxS4nVM0Tb2xQt+FG5DCFM9qzL2HmuX6A793TwlJVDvw=="], + "@posthog/types": ["@posthog/types@1.427.1", "", {}, "sha512-Kx9hWf6Au64CrBLafscANAeswkRFUMs4zlU9/gwB2Hf/9ggU9YNjbw/MQA5tt7cbzTCkh+4fNIPjQeJz7/j63w=="], "@rolldown/binding-android-arm64": ["@rolldown/binding-android-arm64@1.1.5", "", { "os": "android", "cpu": "arm64" }, "sha512-lZg8fqIv2v7FF237bwMgzGZEJvGL79/s5knJ/i6FmsGF4XXlzccZ4jb+TrFIxtSSxFtIpdsgrPZeMk1I9AFcyQ=="], @@ -1021,7 +1021,7 @@ "postcss": ["postcss@8.5.26", "", { "dependencies": { "nanoid": "^3.3.17", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" } }, "sha512-u82N74LFzG8ca+dD8puPnplTXoGH4fTPpVGuIbt36G3qvNlkvfD0lEAZSxaly3KX8TS/L1A1gsCEmvKmBcVbkQ=="], - "posthog-node": ["posthog-node@5.73.0", "", { "dependencies": { "@posthog/core": "^1.67.3" }, "peerDependencies": { "@opentelemetry/api": "^1.2.0", "@react-email/render": "^2.1.0", "rxjs": "^7.0.0" }, "optionalPeers": ["@opentelemetry/api", "@react-email/render", "rxjs"] }, "sha512-OH5PZA2GVftiHPwTCA31fy2E33sWW/o2f+ubxi3/ugPEEYzq+/Fw4h2igVpa+RThw1oYrmzgOHCOFdSkh2SzOQ=="], + "posthog-node": ["posthog-node@6.0.5", "", { "dependencies": { "@posthog/core": "^1.69.2" }, "peerDependencies": { "@opentelemetry/api": "^1.2.0", "@react-email/render": "^2.1.0", "rxjs": "^7.0.0" }, "optionalPeers": ["@opentelemetry/api", "@react-email/render", "rxjs"] }, "sha512-trvLy4y6I2SDU9DOJ6vVv3n2Gw8Jp1mbbaxSGGsrgO9ihF2l4Mz/AgVVdTSV9DPv7Y+VeQnfpE6I8ipJlAMtzg=="], "prelude-ls": ["prelude-ls@1.2.1", "", {}, "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g=="], diff --git a/package.json b/package.json index eb2b6d694..fb0b245a7 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,7 @@ "dependencies": { "html-to-image": "^1.11.13", "jsonc-parser": "^3.3.1", - "posthog-node": "^5.50.0", + "posthog-node": "^6.0.5", "smol-toml": "^1.9.1", "sql.js": "^1.14.1", "yaml": "^2.9.0" From 43b2ae80871d2832f075fc33e7f7d62dc77684e4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 21:07:02 +0000 Subject: [PATCH 2/7] chore(deps): bump posthog-node from 5.73.0 to 6.0.5 Bumps [posthog-node](https://github.com/PostHog/posthog-js/tree/HEAD/packages/node) from 5.73.0 to 6.0.5. - [Release notes](https://github.com/PostHog/posthog-js/releases) - [Changelog](https://github.com/PostHog/posthog-js/blob/main/packages/node/CHANGELOG.md) - [Commits](https://github.com/PostHog/posthog-js/commits/posthog-node@6.0.5/packages/node) --- updated-dependencies: - dependency-name: posthog-node dependency-version: 6.0.5 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- bun.lock | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bun.lock b/bun.lock index 2d9cfd65c..4a73662a0 100644 --- a/bun.lock +++ b/bun.lock @@ -7,7 +7,7 @@ "dependencies": { "html-to-image": "^1.11.13", "jsonc-parser": "^3.3.1", - "posthog-node": "^5.50.0", + "posthog-node": "^6.0.5", "smol-toml": "^1.9.1", "sql.js": "^1.14.1", "yaml": "^2.9.0", @@ -235,9 +235,9 @@ "@oxc-project/types": ["@oxc-project/types@0.139.0", "", {}, "sha512-r9gHphtCs+1M7J0pw6Sn/hh/Wpa/iQrOOkrNAlVLF/gHq+/CJmHIWKKUUhdWjcD6CIa8idarspCsASiXCXvFUw=="], - "@posthog/core": ["@posthog/core@1.68.0", "", { "dependencies": { "@posthog/types": "^1.425.1" } }, "sha512-5kjPcLquzj47qBGn52+7RRXrJJvrTHaRKgxV9izYPFzoVFEftFqSXYZF/ug+yialxDU73dR9apyi+mSaAeaXPw=="], + "@posthog/core": ["@posthog/core@1.69.2", "", { "dependencies": { "@posthog/types": "^1.427.0" } }, "sha512-toMfPKklwLW+a4ZY3/EzM3GNMVXmk2ylGb8NPJXRH4igXMoI8wgNL2jqXOiglWAXqFBLZGYFN1oQx6LVmUTxTg=="], - "@posthog/types": ["@posthog/types@1.425.1", "", {}, "sha512-mh7jyQ5lN+XCeOnMdYkBEFtO/G0TxeLOKTWNH6E6OZjxS4nVM0Tb2xQt+FG5DCFM9qzL2HmuX6A793TwlJVDvw=="], + "@posthog/types": ["@posthog/types@1.427.1", "", {}, "sha512-Kx9hWf6Au64CrBLafscANAeswkRFUMs4zlU9/gwB2Hf/9ggU9YNjbw/MQA5tt7cbzTCkh+4fNIPjQeJz7/j63w=="], "@rolldown/binding-android-arm64": ["@rolldown/binding-android-arm64@1.1.5", "", { "os": "android", "cpu": "arm64" }, "sha512-lZg8fqIv2v7FF237bwMgzGZEJvGL79/s5knJ/i6FmsGF4XXlzccZ4jb+TrFIxtSSxFtIpdsgrPZeMk1I9AFcyQ=="], @@ -1021,7 +1021,7 @@ "postcss": ["postcss@8.5.26", "", { "dependencies": { "nanoid": "^3.3.17", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" } }, "sha512-u82N74LFzG8ca+dD8puPnplTXoGH4fTPpVGuIbt36G3qvNlkvfD0lEAZSxaly3KX8TS/L1A1gsCEmvKmBcVbkQ=="], - "posthog-node": ["posthog-node@5.73.0", "", { "dependencies": { "@posthog/core": "^1.67.3" }, "peerDependencies": { "@opentelemetry/api": "^1.2.0", "@react-email/render": "^2.1.0", "rxjs": "^7.0.0" }, "optionalPeers": ["@opentelemetry/api", "@react-email/render", "rxjs"] }, "sha512-OH5PZA2GVftiHPwTCA31fy2E33sWW/o2f+ubxi3/ugPEEYzq+/Fw4h2igVpa+RThw1oYrmzgOHCOFdSkh2SzOQ=="], + "posthog-node": ["posthog-node@6.0.5", "", { "dependencies": { "@posthog/core": "^1.69.2" }, "peerDependencies": { "@opentelemetry/api": "^1.2.0", "@react-email/render": "^2.1.0", "rxjs": "^7.0.0" }, "optionalPeers": ["@opentelemetry/api", "@react-email/render", "rxjs"] }, "sha512-trvLy4y6I2SDU9DOJ6vVv3n2Gw8Jp1mbbaxSGGsrgO9ihF2l4Mz/AgVVdTSV9DPv7Y+VeQnfpE6I8ipJlAMtzg=="], "prelude-ls": ["prelude-ls@1.2.1", "", {}, "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g=="], diff --git a/package.json b/package.json index d07da89d4..0ee5d84d2 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,7 @@ "dependencies": { "html-to-image": "^1.11.13", "jsonc-parser": "^3.3.1", - "posthog-node": "^5.50.0", + "posthog-node": "^6.0.5", "smol-toml": "^1.9.1", "sql.js": "^1.14.1", "yaml": "^2.9.0" From 4078b492bfb72e5a49b59108970169c5f08e51f7 Mon Sep 17 00:00:00 2001 From: hermes-exosphere Date: Tue, 24 Nov 2026 15:29:31 +0530 Subject: [PATCH 3/7] fix(ci): validate telemetry delivery against PostHog 6 --- CHANGELOG.md | 5 +++ __tests__/lib/telemetry-delivery.test.ts | 47 ++++++++++++++---------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27f07145c..f451cc9a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,8 +14,13 @@ ### Fixes +- Update the real telemetry delivery test for PostHog 6's ingestion endpoint, per-event acknowledgements and library attribution, retaining payload and retry checks (#1043) - Releases no longer depend on the removed version-bot GitHub App. Its absence stopped the 1.0.16 npm publish at its first step and failed every post-release version bump. Nothing in CI pushes to `main` any more: each release workflow pushes its bump commit to a `version-bump/-` branch with the job's own token (`scripts/push-version-bump.sh`) and links a pre-filled pull request, which lands through review. `bump-platform-submodule.yml` is gone; Dependabot's `gitsubmodule` updates now keep `skills` current, and `platform` and `agenteye` need the same entry. `@failproofai/sdk`'s post-publish install check now reads the registry with `--prefer-online` and waits up to about 12 minutes; it had gone red on both releases even though both published. `@failproofai/sdk` opens 0.0.1-beta.3 (#1048) +### Dependencies + +- Update `posthog-node` from 5.73.0 to 6.0.5 (#1043) + ## 1.0.16-beta.0 — 2026-11-23 ### Fixes diff --git a/__tests__/lib/telemetry-delivery.test.ts b/__tests__/lib/telemetry-delivery.test.ts index 0bc436f2a..faa0f7f75 100644 --- a/__tests__/lib/telemetry-delivery.test.ts +++ b/__tests__/lib/telemetry-delivery.test.ts @@ -28,6 +28,7 @@ import { trackHookEvent, flushHookTelemetry } from "@/src/hooks/hook-telemetry"; interface CapturedRequest { url: string; body: string; + authorization?: string; } interface TestServer { @@ -60,12 +61,22 @@ async function startServer(opts: { failFirst?: number } = {}): Promise }).batch + .map(({ uuid }) => [uuid, { result: "ok" }]), + ), + } + : { status: 1 }; + res.writeHead(200, { "Content-Type": "application/json" }).end(JSON.stringify(response)); }); }); @@ -115,6 +126,7 @@ describe("lib/telemetry delivery (real posthog-node)", () => { afterEach(async () => { await shutdownTelemetry().catch(() => {}); + vi.restoreAllMocks(); globalThis.__FAILPROOFAI_POSTHOG__ = undefined; delete process.env.FAILPROOFAI_POSTHOG_KEY; delete process.env.FAILPROOFAI_POSTHOG_HOST; @@ -136,7 +148,9 @@ describe("lib/telemetry delivery (real posthog-node)", () => { await waitFor(() => deliveredEvents(ph!.received).includes("app_started"), 10_000); expect(deliveredEvents(ph.received)).toContain("app_started"); - expect(ph.received.map((r) => r.url)).toContain("/batch/"); + expect(ph.received.map((r) => r.url)).toContain("/i/v1/analytics/events"); + expect(ph.received.find((r) => r.url === "/i/v1/analytics/events")?.authorization) + .toBe("Bearer phc_delivery_test"); // The payload is the point — assert the properties survived the trip, not // just that some request arrived. @@ -152,18 +166,13 @@ describe("lib/telemetry delivery (real posthog-node)", () => { failproofai_version: expect.any(String), }); - // `$lib` is NOT ours on this path, despite trackEvent() setting it to - // "failproofai": posthog-node owns that reserved property and overwrites it - // with its own name and version on every event. (The raw-fetch dispatcher in - // src/hooks/hook-telemetry.ts has no SDK to overwrite it, so its - // "failproofai-hooks" value does survive — the two paths disagree by - // construction.) Attribution that actually holds across both is `product`, - // asserted above; pinned here so nobody "fixes" trackEvent to fight the SDK. - expect((event!.properties as Record).$lib).toBe("posthog-node"); + // Capture V1 preserves the application-provided $lib attribution. + expect((event!.properties as Record).$lib).toBe("failproofai"); }, 15_000); it("does not log a flush error when delivery succeeds", async () => { const consoleError = vi.spyOn(console, "error").mockImplementation(() => {}); + const consoleWarn = vi.spyOn(console, "warn").mockImplementation(() => {}); ph = await startServer(); process.env.FAILPROOFAI_POSTHOG_HOST = ph.url; @@ -171,14 +180,12 @@ describe("lib/telemetry delivery (real posthog-node)", () => { trackEvent("app_started"); await waitFor(() => deliveredEvents(ph!.received).includes("app_started"), 10_000); - // posthog-node reports flush failures through a hardcoded console.error - // (`logFlushError`) on a fire-and-forget internal promise — no `.catch()` at - // our call sites can intercept it, so this is the only way to assert it. - const flushErrors = consoleError.mock.calls.filter((c) => - String(c[0]).includes("Error while flushing PostHog"), - ); - expect(flushErrors).toEqual([]); - consoleError.mockRestore(); + expect(deliveredEvents(ph.received)).toContain("app_started"); + // Wait for the SDK to process the acknowledgement. A request reaching the + // server is insufficient if the client rejects the response as unreadable. + await shutdownTelemetry(); + expect(consoleError).not.toHaveBeenCalled(); + expect(consoleWarn).not.toHaveBeenCalled(); }, 15_000); it("retries a failed send and still delivers the event", async () => { @@ -190,7 +197,7 @@ describe("lib/telemetry delivery (real posthog-node)", () => { await initTelemetry(); trackEvent("app_started"); - // posthog-node's first retry waits `fetchRetryDelay` (3s), so budget past it. + // Allow time for the SDK's retry backoff. await waitFor(() => ph!.hits() >= 2, 20_000); expect(ph.hits()).toBeGreaterThanOrEqual(2); From 2c18735ac00eb3630285246a23857833e1e253e2 Mon Sep 17 00:00:00 2001 From: hermes-exosphere Date: Tue, 24 Nov 2026 15:47:49 +0530 Subject: [PATCH 4/7] fix(hooks): preserve CommonJS when rewriting policy imports --- __tests__/e2e/helpers/hook-runner.ts | 8 ++- .../e2e/hooks/node-custom-hooks.e2e.test.ts | 46 +++++++++++++ __tests__/hooks/loader-commonjs.test.ts | 58 +++++++++++++++++ src/hooks/custom-hooks-loader.ts | 3 +- src/hooks/loader-utils.ts | 65 ++++++++++++++----- 5 files changed, 159 insertions(+), 21 deletions(-) create mode 100644 __tests__/e2e/hooks/node-custom-hooks.e2e.test.ts create mode 100644 __tests__/hooks/loader-commonjs.test.ts diff --git a/__tests__/e2e/helpers/hook-runner.ts b/__tests__/e2e/helpers/hook-runner.ts index f97901868..2d464336e 100644 --- a/__tests__/e2e/helpers/hook-runner.ts +++ b/__tests__/e2e/helpers/hook-runner.ts @@ -41,13 +41,17 @@ export function runHook( event: string, payload: Record, opts?: { + /** Node exercises the packaged CLI; Bun exercises the source entrypoint. */ + runtime?: "bun" | "node"; homeDir?: string; cwd?: string; agentScope?: "user" | "project" | "local"; cli?: "claude" | "codex" | "copilot" | "cursor" | "opencode" | "pi" | "hermes" | "openclaw" | "factory" | "devin" | "antigravity" | "goose"; }, ): HookRunResult { - const binaryPath = getBinaryPath(); + const binaryPath = opts?.runtime === "node" + ? resolve(REPO_ROOT, "dist", "cli.mjs") + : getBinaryPath(); if (!existsSync(binaryPath)) { throw new Error(`E2E binary not found: ${binaryPath}`); @@ -63,7 +67,7 @@ export function runHook( const args = [binaryPath, "--hook", event]; if (opts?.cli) args.push("--cli", opts.cli); if (opts?.agentScope) args.push("--agent-scope", opts.agentScope); - const result = spawnSync("bun", args, { + const result = spawnSync(opts?.runtime ?? "bun", args, { input: JSON.stringify(payload), env, cwd: opts?.cwd, diff --git a/__tests__/e2e/hooks/node-custom-hooks.e2e.test.ts b/__tests__/e2e/hooks/node-custom-hooks.e2e.test.ts new file mode 100644 index 000000000..d3d0f0efb --- /dev/null +++ b/__tests__/e2e/hooks/node-custom-hooks.e2e.test.ts @@ -0,0 +1,46 @@ +import { describe, expect, it } from "vitest"; +import { createFixtureEnv } from "../helpers/fixture-env"; +import { assertPreToolUseDeny, runHook } from "../helpers/hook-runner"; +import { Payloads } from "../helpers/payloads"; + +describe("CommonJS policies in the packaged Node CLI", () => { + it("loads a CommonJS entry with a transitive CommonJS helper", () => { + const env = createFixtureEnv(); + env.writeConfig({ enabledPolicies: [] }); + env.writePolicyFile("helper.cjs", ` + const { deny } = require("failproofai"); + module.exports = () => deny("CommonJS helper enforced"); + `); + env.writePolicyFile("node-policies.js", ` + const { customPolicies } = require("failproofai"); + const policy = require("./helper.cjs"); + customPolicies.add({ name: "node-cjs", match: { events: ["PreToolUse"] }, fn: async () => policy() }); + `); + const result = runHook("PreToolUse", Payloads.preToolUse.bash("ls", env.cwd), { + homeDir: env.home, runtime: "node", + }); + expect(result.exitCode, result.stderr).toBe(0); + assertPreToolUseDeny(result); + expect(result.stdout).toContain("CommonJS helper enforced"); + }); + + it("loads an ESM entry importing a CommonJS helper", () => { + const env = createFixtureEnv(); + env.writeConfig({ enabledPolicies: [] }); + env.writePolicyFile("helper.cjs", ` + const { deny } = require("failproofai"); + module.exports = () => deny("ESM to CommonJS helper enforced"); + `); + env.writePolicyFile("node-policies.mjs", ` + import { customPolicies } from "failproofai"; + import policy from "./helper.cjs"; + customPolicies.add({ name: "node-esm", match: { events: ["PreToolUse"] }, fn: async () => policy() }); + `); + const result = runHook("PreToolUse", Payloads.preToolUse.bash("ls", env.cwd), { + homeDir: env.home, runtime: "node", + }); + expect(result.exitCode, result.stderr).toBe(0); + assertPreToolUseDeny(result); + expect(result.stdout).toContain("ESM to CommonJS helper enforced"); + }); +}); diff --git a/__tests__/hooks/loader-commonjs.test.ts b/__tests__/hooks/loader-commonjs.test.ts new file mode 100644 index 000000000..71693a9b8 --- /dev/null +++ b/__tests__/hooks/loader-commonjs.test.ts @@ -0,0 +1,58 @@ +/** Exercise rewritten modules in native Node, which has no global ESM require. */ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { spawnSync } from "node:child_process"; +import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { basename, join } from "node:path"; +import { pathToFileURL } from "node:url"; +import { cleanupTmpFiles, rewriteFileTree, TMP_SUFFIX } from "../../src/hooks/loader-utils"; + +describe("rewritten CommonJS policies under Node", () => { + let dir: string; + let temporaryFiles: string[]; + + beforeEach(() => { + dir = mkdtempSync(join(tmpdir(), "fpai-cjs-loader-")); + temporaryFiles = []; + vi.stubEnv("FAILPROOFAI_HOME", join(dir, "fp-home")); + writeFileSync(join(dir, "dist.cjs"), "module.exports = { value: 8 };\n"); + writeFileSync(join(dir, "helper.cjs"), 'module.exports = require("failproofai").value;\n'); + }); + + afterEach(async () => { + await cleanupTmpFiles(temporaryFiles); + vi.unstubAllEnvs(); + rmSync(dir, { recursive: true, force: true }); + }); + + async function importInNode(entry: string): Promise { + const dist = join(dir, "dist.cjs"); + temporaryFiles = await rewriteFileTree(entry, pathToFileURL(dist).href, dist); + const rewrittenEntry = temporaryFiles.find((file) => file.startsWith(entry + TMP_SUFFIX)); + expect(rewrittenEntry).toBeDefined(); + const result = spawnSync("node", [ + "--input-type=module", "-e", + "const loaded = await import(process.argv[1]); console.log(JSON.stringify(loaded.default));", + pathToFileURL(rewrittenEntry!).href, + ], { encoding: "utf8", timeout: 10_000 }); + expect(result.status, result.stderr).toBe(0); + return JSON.parse(result.stdout); + } + + it.each(["js", "cjs"])("preserves require and CommonJS globals in a .%s entry and its helper", async (extension) => { + const entry = join(dir, `entry.${extension}`); + writeFileSync(entry, [ + "#!/usr/bin/env node", + 'const { basename } = require("node:path");', + 'exports.value = require("./helper.cjs") + 1;', + "exports.directory = basename(__dirname);", + ].join("\n")); + expect(await importInNode(entry)).toEqual({ value: 9, directory: basename(dir) }); + }); + + it("keeps ESM .js imports working when a dependency is CommonJS", async () => { + const entry = join(dir, "entry.js"); + writeFileSync(entry, 'import value from "./helper.cjs"; export default value + 1;\n'); + expect(await importInNode(entry)).toBe(9); + }); +}); diff --git a/src/hooks/custom-hooks-loader.ts b/src/hooks/custom-hooks-loader.ts index 99e064a93..9e7a58d65 100644 --- a/src/hooks/custom-hooks-loader.ts +++ b/src/hooks/custom-hooks-loader.ts @@ -227,7 +227,8 @@ async function loadSingleFile( return null; } - const entryTmp = absPath + tmpSuffix; + const commonJsEntry = absPath + tmpSuffix + ".cjs"; + const entryTmp = tmpFiles.includes(commonJsEntry) ? commonJsEntry : absPath + tmpSuffix; const fileUrl = pathToFileURL(entryTmp).href; const hooksBefore = getCustomHooks().length; const semanticBefore = getSemanticRegistrations().length; diff --git a/src/hooks/loader-utils.ts b/src/hooks/loader-utils.ts index 52eaa7b23..48dff820f 100644 --- a/src/hooks/loader-utils.ts +++ b/src/hooks/loader-utils.ts @@ -16,6 +16,7 @@ import { tmpdir } from "os"; import { resolve, dirname, relative, join } from "path"; import { pathToFileURL } from "url"; import { createHash } from "crypto"; +import { Script } from "node:vm"; import { shimsDir } from "./fp-home"; import { hookLogWarn } from "./hook-logger"; @@ -86,6 +87,19 @@ const LOCAL_IMPORT_RE = /(?:import\s+(?:[\s\S]*?\s+from\s+)?|export\s+(?:[\s\S]* /** Regex to find local relative require specifiers (CJS). */ const LOCAL_REQUIRE_RE = /require\s*\(\s*(['"])(\.\.?\/[^'"]+)\1\s*\)/g; +/** Parse without executing; CommonJS copies need native require/module/exports. */ +function isCommonJs(filePath: string, code: string): boolean { + if (filePath.endsWith(".cjs")) return true; + if (filePath.endsWith(".mjs")) return false; + try { + new Script(`(function (exports, require, module, __filename, __dirname) {\n${code.replace(/^#![^\n]*/, "")}\n})`); + return true; + } catch { + // Static imports, exports and top-level await need an ESM copy. + return false; + } +} + export async function fileExists(path: string): Promise { try { await access(path); @@ -259,6 +273,36 @@ export async function rewriteFileTree( const queue: string[] = [entryPath]; const visited = new Set(); const tmpFiles: string[] = []; + const sourceCode = new Map(); + const temporaryPaths = new Map(); + + async function readSource(filePath: string): Promise { + const cached = sourceCode.get(filePath); + if (cached !== undefined) return cached; + // Verify the same raw bytes used to choose the module format and rewrite + // imports. Dependencies can be inspected before their turn in the queue. + const buf = await readFile(filePath); + if (entrySha256 && filePath === entryPath) { + const actual = createHash("sha256").update(buf).digest("hex"); + if (actual !== entrySha256) { + throw new Error( + `cloud-managed policy failed integrity re-verification at load: expected ${entrySha256}, got ${actual}`, + ); + } + } + const code = buf.toString("utf-8"); + sourceCode.set(filePath, code); + return code; + } + + async function temporaryPath(filePath: string): Promise { + const cached = temporaryPaths.get(filePath); + if (cached) return cached; + const extension = isCommonJs(filePath, await readSource(filePath)) ? ".cjs" : ""; + const path = filePath + tmpSuffix + extension; + temporaryPaths.set(filePath, path); + return path; + } let esmShimUrl: string | null = null; if (distIndex && distUrl) { @@ -272,22 +316,7 @@ export async function rewriteFileTree( if (visited.has(filePath)) continue; visited.add(filePath); - let code: string; - if (entrySha256 && filePath === entryPath) { - // Read the raw bytes, verify the pin against THEM, then decode and rewrite - // that same in-memory content — filePath is never read again, so the bytes - // imported below are exactly the bytes verified here. - const buf = await readFile(filePath); - const actual = createHash("sha256").update(buf).digest("hex"); - if (actual !== entrySha256) { - throw new Error( - `cloud-managed policy failed integrity re-verification at load: expected ${entrySha256}, got ${actual}`, - ); - } - code = buf.toString("utf-8"); - } else { - code = await readFile(filePath, "utf-8"); - } + let code = await readSource(filePath); // Rewrite 'failproofai' or legacy 'claudeye' imports to the ESM shim (or direct CJS for require) if (esmShimUrl) { @@ -317,7 +346,7 @@ export async function rewriteFileTree( if (!visited.has(resolved) && !queue.includes(resolved)) { queue.push(resolved); } - let relPath = relative(dir, resolved + tmpSuffix).split("\\").join("/"); + let relPath = relative(dir, await temporaryPath(resolved)).split("\\").join("/"); if (!relPath.startsWith(".")) relPath = "./" + relPath; rewrites.set(specifier, relPath); } @@ -332,7 +361,7 @@ export async function rewriteFileTree( code = code.replace(new RegExp(`"${escaped}"`, "g"), `"${replacement}"`); } - const tmpPath = filePath + tmpSuffix; + const tmpPath = await temporaryPath(filePath); await writeFile(tmpPath, code, "utf-8"); tmpFiles.push(tmpPath); } From f2d6e3ffca9efd2c23f924ad3b500312d6ca8087 Mon Sep 17 00:00:00 2001 From: hermes-exosphere Date: Tue, 24 Nov 2026 15:47:49 +0530 Subject: [PATCH 5/7] docs: record Node CommonJS policy-loading fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f451cc9a4..39b020fad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ ### Fixes - Update the real telemetry delivery test for PostHog 6's ingestion endpoint, per-event acknowledgements and library attribution, retaining payload and retry checks (#1043) +- Preserve CommonJS policy files and their helpers as `.cjs` during import rewriting so packaged Node installs support `require`, `module.exports` and mixed ESM imports (#1043) - Releases no longer depend on the removed version-bot GitHub App. Its absence stopped the 1.0.16 npm publish at its first step and failed every post-release version bump. Nothing in CI pushes to `main` any more: each release workflow pushes its bump commit to a `version-bump/-` branch with the job's own token (`scripts/push-version-bump.sh`) and links a pre-filled pull request, which lands through review. `bump-platform-submodule.yml` is gone; Dependabot's `gitsubmodule` updates now keep `skills` current, and `platform` and `agenteye` need the same entry. `@failproofai/sdk`'s post-publish install check now reads the registry with `--prefer-online` and waits up to about 12 minutes; it had gone red on both releases even though both published. `@failproofai/sdk` opens 0.0.1-beta.3 (#1048) ### Dependencies From cf138d79d114af2a92cfb08fdf85b3ad0b52a239 Mon Sep 17 00:00:00 2001 From: hermes-exosphere Date: Tue, 24 Nov 2026 16:01:54 +0530 Subject: [PATCH 6/7] docs: align CI fixes with current release notes --- CHANGELOG.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39b020fad..11a0cb853 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,14 @@ ### Fixes +- Update the real telemetry delivery test for PostHog 6's ingestion endpoint, per-event acknowledgements and library attribution, retaining payload and retry checks (#1043) +- Preserve CommonJS policy files and their helpers as `.cjs` during import rewriting so packaged Node installs support `require`, `module.exports` and mixed ESM imports (#1043) - Release workflows now open the version-bump pull request themselves, using the job's own token, when the repository lets GitHub Actions create pull requests. When it does not, the run prints the pre-filled link as a warning and the release still succeeds. A re-run reuses an open bump pull request instead of opening a second one (#1052) +### Dependencies + +- Update `posthog-node` from 5.73.0 to 6.0.5 (#1043) + ## 1.0.16-beta.0 — 2026-11-24 ### Features @@ -14,13 +20,8 @@ ### Fixes -- Update the real telemetry delivery test for PostHog 6's ingestion endpoint, per-event acknowledgements and library attribution, retaining payload and retry checks (#1043) -- Preserve CommonJS policy files and their helpers as `.cjs` during import rewriting so packaged Node installs support `require`, `module.exports` and mixed ESM imports (#1043) - Releases no longer depend on the removed version-bot GitHub App. Its absence stopped the 1.0.16 npm publish at its first step and failed every post-release version bump. Nothing in CI pushes to `main` any more: each release workflow pushes its bump commit to a `version-bump/-` branch with the job's own token (`scripts/push-version-bump.sh`) and links a pre-filled pull request, which lands through review. `bump-platform-submodule.yml` is gone; Dependabot's `gitsubmodule` updates now keep `skills` current, and `platform` and `agenteye` need the same entry. `@failproofai/sdk`'s post-publish install check now reads the registry with `--prefer-online` and waits up to about 12 minutes; it had gone red on both releases even though both published. `@failproofai/sdk` opens 0.0.1-beta.3 (#1048) -### Dependencies - -- Update `posthog-node` from 5.73.0 to 6.0.5 (#1043) ## 1.0.16-beta.0 — 2026-11-23 From f91d1ccd4ac2434fc2a26c845bbc0bac462dbbd6 Mon Sep 17 00:00:00 2001 From: NiveditJain Date: Mon, 30 Nov 2026 16:10:15 +0530 Subject: [PATCH 7/7] docs(changelog): posthog-node runs only in the dashboard server Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1151b88cb..96c3ab068 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ ### Dependencies -- Update `posthog-node` from 5.73.0 to 6.0.5. The dashboard and CLI events it sends now go to PostHog's Capture V1 endpoint (`/i/v1/analytics/events`) and keep the `$lib` they set, so they report `$lib: failproofai` with a `$lib_version` instead of `posthog-node`; the real delivery test checks the new endpoint, its bearer token, per-event acknowledgements and retries (#1043) +- Update `posthog-node` from 5.73.0 to 6.0.5. The dashboard server's events now go to PostHog's Capture V1 endpoint (`/i/v1/analytics/events`) and keep the `$lib` they set, so they report `$lib: failproofai` with a `$lib_version` instead of `posthog-node`; the real delivery test checks the new endpoint, its bearer token, per-event acknowledgements and retries (#1043) ## 1.0.18-beta.0 — 2026-11-24