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
40 changes: 39 additions & 1 deletion apps/code/electron.vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync } from "node:fs";
import { existsSync, readFileSync } from "node:fs";
import { builtinModules, createRequire } from "node:module";
import path from "node:path";
import { fileURLToPath } from "node:url";
Expand Down Expand Up @@ -45,6 +45,43 @@ const nodeExternals = [
// the staged node_modules at runtime (see scripts/before-pack.ts).
const nativeModules = buildExternals;

const nearestPackageType = (fromFile: string): string | undefined => {
let dir = path.dirname(fromFile);
while (true) {
const manifest = path.join(dir, "package.json");
if (existsSync(manifest)) {
try {
return JSON.parse(readFileSync(manifest, "utf-8")).type;
} catch {
return undefined;
}
}
const parent = path.dirname(dir);
if (parent === dir) return undefined;
dir = parent;
}
};

const resolvesToCommonJs = (name: string): boolean => {
let resolved: string;
try {
resolved = require.resolve(name);
} catch {
return false;
}
if (resolved.endsWith(".cjs")) return true;
if (resolved.endsWith(".mjs")) return false;
return nearestPackageType(resolved) !== "module";
};

const computeDevThirdPartyExternals = (): RegExp[] =>
Object.keys(pkg.dependencies ?? {})
.filter((name) => !name.startsWith("@posthog/") && resolvesToCommonJs(name))
.map(
(name) =>
new RegExp(`^${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(/.+)?$`),
);

export default defineConfig(({ mode }) => {
const env = loadEnv(mode, path.resolve(__dirname, "../.."), "");
const isDev = mode === "development";
Expand Down Expand Up @@ -115,6 +152,7 @@ export default defineConfig(({ mode }) => {
"electron/main",
...nodeExternals,
...nativeModules,
...(isDev ? computeDevThirdPartyExternals() : []),
],
onwarn(warning, warn) {
if (warning.code === "UNUSED_EXTERNAL_IMPORT") return;
Expand Down
2 changes: 1 addition & 1 deletion apps/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@types/react": "^19.2.15",
"@types/react-dom": "^19.2.3",
"@types/semver": "^7.7.1",
"@vitejs/plugin-react": "^4.7.0",
"@vitejs/plugin-react": "^5.2.0",
"@vitest/ui": "^4.1.8",
"adm-zip": "^0.5.17",
"electron": "^42.3.0",
Expand Down
15 changes: 15 additions & 0 deletions apps/code/vite-main-plugins.mts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ function detectBinaryArch(
return null;
}

function isStagedCopyCurrent(source: string, dest: string): boolean {
if (!existsSync(dest)) return false;
return statSync(dest).mtimeMs >= statSync(source).mtimeMs;
}

function signClaudeBinary(destPath: string): void {
if (targetPlatform() !== "darwin") return;
if (process.platform !== "darwin") {
Expand Down Expand Up @@ -196,6 +201,11 @@ export function copyClaudeExecutable(): Plugin {
return;
}

if (isStagedCopyCurrent(source, destBinary)) {
claudeCliCopied = true;
return;
}

copyFileSync(source, destBinary);
if (targetPlatform() !== "win32") {
execSync(`chmod +x "${destBinary}"`);
Expand Down Expand Up @@ -569,6 +579,11 @@ export function copyCodexAcpBinaries(): Plugin {

if (existsSync(sourcePath)) {
const destPath = join(destDir, binaryName);

if (isStagedCopyCurrent(sourcePath, destPath)) {
continue;
}

copyFileSync(sourcePath, destPath);
console.log(`Copied ${binary.name} binary to ${destDir}`);

Expand Down
8 changes: 8 additions & 0 deletions apps/code/vite.shared.mts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export const workspaceAliases: Alias[] = [
"../../packages/workspace-server/src/$1",
),
},
{
find: /^@posthog\/platform\/(.+)$/,
replacement: path.resolve(__dirname, "../../packages/platform/src/$1"),
},
];

export const mainAliases: Alias[] = [
Expand All @@ -113,6 +117,10 @@ export const mainAliases: Alias[] = [
"../../packages/electron-trpc/src/main/index.ts",
),
},
{
find: /^@posthog\/git\/(.+)$/,
replacement: path.resolve(__dirname, "../../packages/git/src/$1"),
},
...workspaceAliases,
];

Expand Down
6 changes: 3 additions & 3 deletions apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"phosphor-react-native": "^3.0.2",
"posthog-react-native": "^4.18.0",
"posthog-react-native-session-replay": "^1.6.0",
"react": "19.1.0",
"react": "19.2.6",
"react-native": "0.81.5",
"react-native-keyboard-controller": "1.18.5",
"react-native-reanimated": "~4.1.1",
Expand All @@ -77,11 +77,11 @@
},
"devDependencies": {
"@testing-library/react-native": "^13.3.3",
"@types/react": "^19.1.0",
"@types/react": "^19.2.0",
"@types/react-test-renderer": "^19.1.0",
"@vitejs/plugin-react": "^4.7.0",
"react-native-svg-transformer": "^1.5.3",
"react-test-renderer": "^19.1.0",
"react-test-renderer": "^19.2.6",
"tailwindcss": "^3.4.18",
"typescript": "~5.9.2",
"vite": "^6.4.1",
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,10 @@
"biome check --write --unsafe --files-ignore-unknown=true --no-errors-on-unmatched",
"bash -c 'pnpm typecheck'"
]
},
"pnpm": {
"overrides": {
"vite": "npm:rolldown-vite@7.3.1"
}
}
}
2 changes: 1 addition & 1 deletion packages/agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"tsup": "^8.5.1",
"tsx": "^4.20.6",
"typescript": "^5.5.0",
"vitest": "^2.1.8"
"vitest": "^4.1.8"
},
"dependencies": {
"@agentclientprotocol/sdk": "0.25.0",
Expand Down
28 changes: 14 additions & 14 deletions packages/agent/src/adapters/codex/codex-agent.refresh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ const hoisted = vi.hoisted(() => {
cancel: vi.fn().mockResolvedValue(undefined),
});

const clientSideConnectionCtor = vi.fn(() => {
const conn = makeConnection();
createdConnections.push(conn);
return conn;
});
const clientSideConnectionCtor = class {
constructor() {
Object.assign(this, makeConnection());
createdConnections.push(this as unknown as MockCodexConnection);
}
};

const spawnCodexProcessMock = vi.fn(() => {
const handle: SpawnHandle = {
Expand All @@ -75,7 +76,6 @@ const hoisted = vi.hoisted(() => {

const createdConnections = hoisted.createdConnections;
const spawnedProcesses = hoisted.spawnedProcesses;
const clientSideConnectionCtor = hoisted.clientSideConnectionCtor;

vi.mock("@agentclientprotocol/sdk", async () => {
const actual = await vi.importActual("@agentclientprotocol/sdk");
Expand All @@ -91,13 +91,14 @@ vi.mock("./spawn", () => ({
}));

vi.mock("./settings", () => ({
CodexSettingsManager: vi.fn().mockImplementation((cwd: string) => ({
initialize: vi.fn().mockResolvedValue(undefined),
dispose: vi.fn(),
getCwd: () => cwd,
setCwd: vi.fn(),
getSettings: () => ({ mcpServerNames: [] }),
})),
CodexSettingsManager: class {
constructor(private readonly cwd: string) {}
initialize = vi.fn().mockResolvedValue(undefined);
dispose = vi.fn();
getCwd = () => this.cwd;
setCwd = vi.fn();
getSettings = () => ({ mcpServerNames: [] });
},
}));

import { CodexAcpAgent } from "./codex-agent";
Expand Down Expand Up @@ -171,7 +172,6 @@ describe("CodexAcpAgent.extMethod refresh_session", () => {
beforeEach(() => {
spawnedProcesses.length = 0;
createdConnections.length = 0;
clientSideConnectionCtor.mockClear();
});

it("returns methodNotFound for unknown extension methods", async () => {
Expand Down
21 changes: 13 additions & 8 deletions packages/agent/src/adapters/codex/codex-agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ vi.mock("@agentclientprotocol/sdk", async () => {

return {
...actual,
ClientSideConnection: vi.fn(() => mockCodexConnection),
ClientSideConnection: class {
constructor() {
Object.assign(this, mockCodexConnection);
}
},
ndJsonStream: vi.fn(() => ({}) as object),
};
});
Expand All @@ -44,13 +48,14 @@ vi.mock("./spawn", () => ({
}));

vi.mock("./settings", () => ({
CodexSettingsManager: vi.fn().mockImplementation((cwd: string) => ({
initialize: vi.fn(),
dispose: vi.fn(),
getCwd: () => cwd,
setCwd: vi.fn(),
getSettings: () => ({}),
})),
CodexSettingsManager: class {
constructor(private readonly cwd: string) {}
initialize = vi.fn();
dispose = vi.fn();
getCwd = () => this.cwd;
setCwd = vi.fn();
getSettings = () => ({});
},
}));

vi.mock("node:fs", async (importActual) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/agent/src/otel-log-writer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const mockExport = vi.fn((_logs, callback) => {
});

vi.mock("@opentelemetry/exporter-logs-otlp-http", () => ({
OTLPLogExporter: vi.fn().mockImplementation(() => ({
export: mockExport,
shutdown: vi.fn().mockResolvedValue(undefined),
})),
OTLPLogExporter: class {
export = mockExport;
shutdown = vi.fn().mockResolvedValue(undefined);
},
}));

describe("OtelLogWriter", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"@posthog/tsconfig": "workspace:*",
"typescript": "catalog:",
"vitest": "^2.1.9"
"vitest": "^4.1.8"
},
"files": [
"src/**/*"
Expand Down
2 changes: 1 addition & 1 deletion packages/di/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@types/react": "catalog:",
"react": "catalog:",
"typescript": "catalog:",
"vitest": "^2.1.9"
"vitest": "^4.1.8"
},
"files": [
"src/**/*"
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-trpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
"@trpc/client": "^11.8.0",
"@trpc/server": "^11.8.0",
"@types/node": "^24.0.0",
"@vitest/coverage-v8": "^2.1.8",
"@vitest/coverage-v8": "^4.1.8",
"electron": "^42.3.0",
"superjson": "^2.2.2",
"typescript": "^5.8.3",
"vite": "^7.0.0",
"vitest": "^2.1.8",
"vitest": "^4.1.8",
"zod": "^4.2.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/enricher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"tree-sitter-cli": "^0.26.6",
"tsup": "^8.5.1",
"typescript": "^5.5.0",
"vitest": "^2.1.9"
"vitest": "^4.1.8"
},
"files": [
"dist/**/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"@types/tar": "^6.1.13",
"typescript": "^5.5.0",
"vitest": "^2.1.8"
"vitest": "^4.1.8"
},
"files": [
"dist/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,68 @@ describe("PosthogPluginService", () => {
});
});

describe("last-check persistence across restarts", () => {
const MARKER_PATH = "/mock/userData/.skills-last-check";

function restartService(): PosthogPluginService {
return new PosthogPluginService(
mockStoragePaths as unknown as IStoragePaths,
mockBundledResources as unknown as IBundledResources,
mockAnalytics as unknown as IAnalytics,
mockAppMeta as unknown as IAppMeta,
mockLog as unknown as RootLogger,
);
}

it("writes the last-check marker after a successful update", async () => {
simulateExtractZip();

await service.updateSkills();

expect(vol.existsSync(MARKER_PATH)).toBe(true);
});

it("skips the download on restart when the marker is still fresh", async () => {
setupBundledPlugin();
simulateExtractZip();
await service.updateSkills();
mockFetch.mockClear();

const restarted = restartService();
await (restarted as unknown as TestablePluginService).initialize();

expect(mockFetch).not.toHaveBeenCalled();
restarted.cleanup();
});

it("re-downloads on restart once the interval has expired", async () => {
setupBundledPlugin();
simulateExtractZip();
await service.updateSkills();
mockFetch.mockClear();

vi.advanceTimersByTime(31 * 60 * 1000);
const restarted = restartService();
await (restarted as unknown as TestablePluginService).initialize();

expect(mockFetch).toHaveBeenCalled();
restarted.cleanup();
});

it("re-downloads on restart when the skills cache is missing despite a fresh marker", async () => {
setupBundledPlugin();
simulateExtractZip();
vol.mkdirSync("/mock/userData", { recursive: true });
vol.writeFileSync(MARKER_PATH, `${Date.now()}\n`);

const restarted = restartService();
await (restarted as unknown as TestablePluginService).initialize();

expect(mockFetch).toHaveBeenCalled();
restarted.cleanup();
});
});

describe("copyBundledPlugin", () => {
it("copies entire bundled dir to runtime dir", async () => {
setupBundledPlugin();
Expand Down
Loading
Loading