feat(HAI-090): remove package.json dependency from compiled binary
- Inline version/name resolution in bin.ts so the binary works without package.json - Simplify build.ts by removing package.json bundling steps - Remove unused dynamic package.json lookups in engine merger, triage, and executor - Expand build-exe tests to verify binary runs independently of package.json - Clean up obsolete engine unit tests tied to removed package.json logic
This commit is contained in:
@@ -1,7 +1,45 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { runDashboard } from "./commands/dashboard.js";
|
||||
import { runTaskCreate, runTaskList, runTaskMove, runTaskMerge, runTaskUpdate, runTaskLog, runTaskShow, runTaskAttach } from "./commands/task.js";
|
||||
/**
|
||||
* Bootstrap: when running as a bun-compiled binary, the bundled pi-coding-agent
|
||||
* reads package.json from the executable's directory at module-init time
|
||||
* (top-level `readFileSync` in its config module). We redirect that read to a
|
||||
* temp directory containing a minimal package.json so the binary works
|
||||
* standalone without any co-located package.json.
|
||||
*
|
||||
* Node built-ins are safe to import statically — they have no side-effects
|
||||
* that depend on package.json. All application imports MUST be dynamic
|
||||
* (after the env is configured) so they resolve after PI_PACKAGE_DIR is set.
|
||||
*/
|
||||
import { mkdtempSync, writeFileSync, existsSync } from "node:fs";
|
||||
import { join, dirname } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
|
||||
// @ts-expect-error -- Bun-only global; undefined in Node
|
||||
const isBunBinary = typeof Bun !== "undefined" && !!Bun.embeddedFiles;
|
||||
|
||||
if (isBunBinary) {
|
||||
const execDir = dirname(process.execPath);
|
||||
const localPkg = join(execDir, "package.json");
|
||||
|
||||
if (!existsSync(localPkg)) {
|
||||
// Write a minimal package.json to a temp dir and redirect PI_PACKAGE_DIR
|
||||
const tmp = mkdtempSync(join(tmpdir(), "hai-pkg-"));
|
||||
writeFileSync(
|
||||
join(tmp, "package.json"),
|
||||
JSON.stringify(
|
||||
{ name: "hai", version: "0.1.0", type: "module", piConfig: { name: "hai", configDir: ".hai" } },
|
||||
null,
|
||||
2,
|
||||
) + "\n",
|
||||
);
|
||||
process.env.PI_PACKAGE_DIR = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// Dynamic imports so the pi-coding-agent config module sees PI_PACKAGE_DIR
|
||||
const { runDashboard } = await import("./commands/dashboard.js");
|
||||
const { runTaskCreate, runTaskList, runTaskMove, runTaskMerge, runTaskUpdate, runTaskLog, runTaskShow, runTaskAttach } = await import("./commands/task.js");
|
||||
|
||||
const HELP = `
|
||||
hai — AI-orchestrated task board
|
||||
|
||||
Reference in New Issue
Block a user