pi-orchestrator-config 4.3.5 → 4.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -921,55 +921,60 @@ export function registerAsyncAgents(
921
921
  // Find the runner script
922
922
  const runnerPath = path.join(path.dirname(fileURLToPath(import.meta.url)), "async-runner.ts");
923
923
 
924
- // Find jiti for TypeScript execution
924
+ // Find jiti for TypeScript execution — walk UP from known roots until
925
+ // found; never assume a fixed depth (install layouts vary: dist/,
926
+ // dist/bundle/, workspace hoisting, nested node_modules).
925
927
  let jitiCliPath: string | undefined;
926
- // Strategy 1: resolve from pi's own require context
927
- // NOTE: newer pi SDK "exports" maps hide ./package.json — fall back to
928
- // resolving the main entry and walking up to its package root.
929
- try {
930
- const req = createRequire(import.meta.url);
931
- let piPkgJsonPath: string | undefined;
932
- try {
933
- piPkgJsonPath = req.resolve("@earendil-works/pi-coding-agent/package.json");
934
- } catch {
935
- const entry = req.resolve("@earendil-works/pi-coding-agent");
936
- let dir = path.dirname(entry);
937
- while (dir !== path.dirname(dir)) {
938
- const pj = path.join(dir, "package.json");
939
- if (fs.existsSync(pj) && JSON.parse(fs.readFileSync(pj, "utf8"))?.name === "@earendil-works/pi-coding-agent") { piPkgJsonPath = pj; break; }
940
- dir = path.dirname(dir);
941
- }
928
+ const jitiProbes: string[] = [];
929
+ const findJitiUnder = (label: string, startDir: string): string | undefined => {
930
+ let dir = startDir;
931
+ while (dir !== path.dirname(dir)) {
932
+ const candidate = path.join(dir, "node_modules/jiti/lib/jiti-cli.mjs");
933
+ jitiProbes.push(`${fs.existsSync(candidate) ? "HIT" : "--"} ${candidate}`);
934
+ if (fs.existsSync(candidate)) return candidate;
935
+ dir = path.dirname(dir);
942
936
  }
943
- if (piPkgJsonPath) {
944
- const candidate = path.join(path.dirname(piPkgJsonPath), "node_modules/jiti/lib/jiti-cli.mjs");
945
- if (fs.existsSync(candidate)) jitiCliPath = candidate;
937
+ jitiProbes.push(`(exhausted from ${label}: ${startDir})`);
938
+ return undefined;
939
+ };
940
+
941
+ // Strategy 1: resolve from pi's own install location (the running binary).
942
+ try {
943
+ if (process.argv[1]) {
944
+ const piRoot = path.dirname(fs.realpathSync(process.argv[1]));
945
+ jitiCliPath = findJitiUnder("argv-binary", piRoot);
946
946
  }
947
947
  } catch (e: any) {
948
- log.debug(`jiti strategy 1 (require.resolve) failed: ${e?.message || e}`);
948
+ log.debug(`jiti strategy 1 (running binary) failed: ${e?.message || e}`);
949
949
  }
950
- // Strategy 2: resolve from the pi binary (works for global npm installs)
950
+
951
+ // Strategy 2: resolve the pi SDK package from this module's require context.
951
952
  if (!jitiCliPath) {
952
953
  try {
953
- const piScript = process.argv[1];
954
- if (piScript) {
955
- const realPath = fs.realpathSync(piScript);
956
- // pi script -> dist/cli.js, package root is 2 levels up
957
- const piPkgDir = path.dirname(path.dirname(realPath));
958
- const candidate = path.join(piPkgDir, "node_modules/jiti/lib/jiti-cli.mjs");
959
- if (fs.existsSync(candidate)) jitiCliPath = candidate;
954
+ const req = createRequire(fileURLToPath(import.meta.url));
955
+ let sdkPkgJson: string | undefined;
956
+ try {
957
+ sdkPkgJson = req.resolve("@earendil-works/pi-coding-agent/package.json");
958
+ } catch {
959
+ // Newer SDK "exports" maps hide ./package.json — resolve the entry
960
+ // and walk up to the owning package.json instead.
961
+ let dir = path.dirname(req.resolve("@earendil-works/pi-coding-agent"));
962
+ while (dir !== path.dirname(dir)) {
963
+ const pj = path.join(dir, "package.json");
964
+ if (fs.existsSync(pj) && JSON.parse(fs.readFileSync(pj, "utf8"))?.name === "@earendil-works/pi-coding-agent") { sdkPkgJson = pj; break; }
965
+ dir = path.dirname(dir);
966
+ }
960
967
  }
968
+ if (sdkPkgJson) jitiCliPath ??= findJitiUnder("sdk-pkg", path.dirname(sdkPkgJson));
961
969
  } catch (e: any) {
962
- log.debug(`jiti strategy 2 (process.argv) failed: ${e?.message || e}`);
970
+ log.debug(`jiti strategy 2 (SDK package) failed: ${e?.message || e}`);
963
971
  }
964
972
  }
965
973
 
966
- // Strategy 3: this package's own node_modules — git/stow installs ship
967
- // jiti themselves (npm consumers are covered by strategies 1-2).
974
+ // Strategy 3: this package's own node_modules (git/stow clones ship jiti).
968
975
  if (!jitiCliPath) {
969
976
  try {
970
- const pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
971
- const candidate = path.join(pkgRoot, "node_modules/jiti/lib/jiti-cli.mjs");
972
- if (fs.existsSync(candidate)) jitiCliPath = candidate;
977
+ jitiCliPath = findJitiUnder("extension-dir", path.dirname(fileURLToPath(import.meta.url)));
973
978
  } catch (e: any) {
974
979
  log.debug(`jiti strategy 3 (package root) failed: ${e?.message || e}`);
975
980
  }
@@ -978,7 +983,7 @@ export function registerAsyncAgents(
978
983
  // Fail fast with a self-explanatory error instead of spawning a child that
979
984
  // cannot load TypeScript (bare node dies on ".js"→".ts" specifiers).
980
985
  if (!jitiCliPath) {
981
- log.error(`async-spawn: ${id} — no jiti-cli.mjs found (strategies 1-3 failed); refusing to spawn`);
986
+ log.error(`async-spawn: ${id} — no jiti-cli.mjs found. Probes:\n ${(jitiProbes.slice(-14)).join("\n ")}`);
982
987
  // Clean up the artifacts we already created — nothing will consume them.
983
988
  try { fs.rmSync(configPath, { force: true }); } catch {}
984
989
  try { fs.rmSync(workerDir, { recursive: true, force: true }); } catch {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-orchestrator-config",
3
- "version": "4.3.5",
3
+ "version": "4.3.6",
4
4
  "description": "Orchestrator pattern for pi: specialist subagents, enforcement, code review loop, workflow commands",
5
5
  "keywords": [
6
6
  "pi-package"