fix(pi): strengthen final release proof

This commit is contained in:
2026-08-24 15:47:57 +08:00
parent c7e777246e
commit df1151b5eb
19 changed files with 1120 additions and 149 deletions

View File

@@ -1,5 +1,6 @@
import { spawn } from 'node:child_process';
import { readFile, readdir, stat } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { arch as hostArch, platform as hostPlatform } from 'node:os';
import {
dirname,
@@ -22,6 +23,8 @@ import {
packagedResourcesDirectory,
} from '../probe-pi-packaged-runtime.mjs';
const { listPackage } = createRequire(import.meta.url)('@electron/asar');
const PRODUCT_NAME = 'Makelore';
const LINUX_EXECUTABLE_NAME = 'niancode';
const EXTENSION_CONTRACT_MARKERS = Object.freeze([
@@ -31,6 +34,7 @@ const EXTENSION_CONTRACT_MARKERS = Object.freeze([
'MAKELORE_PI_BRIDGE_URL',
]);
const PI_AI_PROVIDER_PREFIX = 'pi-runtime/node_modules/@earendil-works/pi-ai/dist/providers/';
const PI_AI_PROVIDER_ASAR_PREFIX = 'app.asar/node_modules/@earendil-works/pi-ai/dist/providers/';
async function pathExists(path) {
try {
@@ -179,11 +183,23 @@ export async function collectForbiddenResourcePaths(root, pattern = /opencode/i)
}
export function classifyOpenCodeResourcePaths(paths) {
const upstreamPiProvider = paths.filter((path) => path.startsWith(PI_AI_PROVIDER_PREFIX));
const productOwned = paths.filter((path) => !path.startsWith(PI_AI_PROVIDER_PREFIX));
const isUpstreamPiProvider = (path) => path.startsWith(PI_AI_PROVIDER_PREFIX)
|| path.startsWith(PI_AI_PROVIDER_ASAR_PREFIX);
const upstreamPiProvider = paths.filter(isUpstreamPiProvider);
const productOwned = paths.filter((path) => !isUpstreamPiProvider(path));
return { productOwned, upstreamPiProvider };
}
export function collectForbiddenAsarPaths(appAsar, pattern = /opencode/i) {
const paths = listPackage(appAsar, { isPack: false }).map((entry) => (
`app.asar/${entry.replace(/^[\\/]+/, '').replaceAll('\\', '/')}`
));
return {
entryCount: paths.length,
matches: paths.filter((entry) => pattern.test(entry)).sort(),
};
}
async function filesContainingNeedles(root, needles) {
const matches = [];
const visit = async (path) => {
@@ -283,9 +299,12 @@ export async function verifyPiProductArtifact({ projectRoot, executable }) {
if (absoluteManifestValues.length > 0) {
throw new Error(`Pi runtime manifest contains absolute paths: ${JSON.stringify(absoluteManifestValues)}`);
}
const openCodeResourcePaths = classifyOpenCodeResourcePaths(
await collectForbiddenResourcePaths(resourcesDirectory),
);
const physicalOpenCodePaths = await collectForbiddenResourcePaths(resourcesDirectory);
const asarOpenCodePaths = collectForbiddenAsarPaths(appAsar);
const openCodeResourcePaths = classifyOpenCodeResourcePaths([
...physicalOpenCodePaths,
...asarOpenCodePaths.matches,
]);
if (openCodeResourcePaths.productOwned.length > 0) {
throw new Error(
`Product-owned resources contain OpenCode paths: ${openCodeResourcePaths.productOwned.join(', ')}`,
@@ -355,6 +374,8 @@ export async function verifyPiProductArtifact({ projectRoot, executable }) {
skills: actualSkills,
openCodeResourcePaths: {
...openCodeResourcePaths,
physicalMatches: physicalOpenCodePaths,
asar: asarOpenCodePaths,
upstreamDecision: openCodeResourcePaths.upstreamPiProvider.length > 0
? 'retained-required-files-from-exact-pinned-pi-production-package'
: 'none',