refactor(coding-agent): restructured plugin system and build logic
- Migrated legacy static bundled-module registry to a dynamic Bun-based in-memory plugin system. - Removed over 4,000 lines of manually maintained registry files to reduce maintenance overhead. - Implemented CJS absolute path rewriting and native-addon load hooks to improve FFI dependency resolution. - Standardized binary build processes by centralizing compilation logic into shared utilities.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import { createLegacyPiVirtualModulePlugin } from "./legacy-pi-virtual-module";
|
||||
import { buildDocsIndexPayload } from "./generate-docs-index";
|
||||
|
||||
/** Inputs shared by local and release coding-agent binary builds. */
|
||||
export interface CodingAgentCompileOptions {
|
||||
/** Absolute repository root used for package resolution. */
|
||||
readonly repoRoot: string;
|
||||
/** Absolute CLI entrypoint. */
|
||||
readonly entrypoint: string;
|
||||
/** Absolute standalone executable output path. */
|
||||
readonly outfile: string;
|
||||
/** Concrete Transformers.js version baked into the tiny-model worker. */
|
||||
readonly transformersVersion: string;
|
||||
/** Optional cross-compilation runtime target. */
|
||||
readonly target?: Bun.Build.CompileTarget;
|
||||
/** Dependencies intentionally resolved from the runtime filesystem. */
|
||||
readonly external?: readonly string[];
|
||||
/** Match release builds that minify identifiers while retaining names. */
|
||||
readonly minifyIdentifiers?: boolean;
|
||||
/** Disable Bun's built-in Darwin signing before the caller re-signs. */
|
||||
readonly skipBuiltinCodesign?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the coding-agent executable with its legacy Pi compatibility module
|
||||
* graph supplied by an in-memory build plugin rather than generated files.
|
||||
*/
|
||||
export async function compileCodingAgent(options: CodingAgentCompileOptions): Promise<void> {
|
||||
const previousCodesignSetting = Bun.env.BUN_NO_CODESIGN_MACHO_BINARY;
|
||||
if (options.skipBuiltinCodesign) {
|
||||
Bun.env.BUN_NO_CODESIGN_MACHO_BINARY = "1";
|
||||
}
|
||||
try {
|
||||
const output = await Bun.build({
|
||||
entrypoints: [options.entrypoint],
|
||||
root: options.repoRoot,
|
||||
external: options.external ? [...options.external] : undefined,
|
||||
define: {
|
||||
"process.env.PI_COMPILED": JSON.stringify("true"),
|
||||
"process.env.PI_TINY_TRANSFORMERS_VERSION": JSON.stringify(options.transformersVersion),
|
||||
"process.env.PI_DOCS_EMBED": JSON.stringify((await buildDocsIndexPayload()).payload),
|
||||
},
|
||||
minify: {
|
||||
identifiers: options.minifyIdentifiers ?? false,
|
||||
keepNames: true,
|
||||
},
|
||||
plugins: [await createLegacyPiVirtualModulePlugin()],
|
||||
compile: {
|
||||
...(options.target ? { target: options.target } : {}),
|
||||
outfile: options.outfile,
|
||||
autoloadBunfig: false,
|
||||
autoloadDotenv: false,
|
||||
autoloadTsconfig: false,
|
||||
autoloadPackageJson: false,
|
||||
},
|
||||
throw: false,
|
||||
});
|
||||
if (!output.success) {
|
||||
throw new Error(`Coding-agent binary bundle failed:\n${output.logs.map(log => log.message).join("\n")}`);
|
||||
}
|
||||
} finally {
|
||||
if (previousCodesignSetting === undefined) {
|
||||
delete Bun.env.BUN_NO_CODESIGN_MACHO_BINARY;
|
||||
} else {
|
||||
Bun.env.BUN_NO_CODESIGN_MACHO_BINARY = previousCodesignSetting;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user