@narumitw/pi-starship 0.60.0 → 0.60.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-starship",
3
- "version": "0.60.0",
3
+ "version": "0.60.1",
4
4
  "description": "Native Starship-style TOML statusline and configuration skill for Pi.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -47,9 +47,23 @@ Read [runtime and security](references/runtime-and-security.md) before enabling
47
47
 
48
48
  Use an explicit user-provided path when present.
49
49
 
50
- Otherwise resolve the active path through Pi's `getAgentDir()` API by running `node scripts/config-path.mjs` relative to this `SKILL.md`.
50
+ Otherwise resolve the active path through Pi's `getAgentDir()` API with the bundled resolver:
51
51
 
52
+ ```bash
53
+ skill_dir="<directory containing this SKILL.md>"
54
+ node "$skill_dir/scripts/config-path.mjs"
55
+ ```
56
+
57
+ Keep the current working directory unchanged so relative agent-directory settings retain their meaning.
52
58
  The resolver prints a JSON string containing the exact absolute path, including correct expansion of a configured `~`.
59
+ It first resolves Pi from the skill's module tree; when Pi is absent there, it resolves beside the first `pi` executable on `PATH`, following symbolic links.
60
+ This supports separate npm or Bun global Pi installations without assuming a fixed global directory.
61
+ Make sure `PATH` selects the intended Pi installation when multiple installations exist.
62
+ Shell wrappers or compiled launchers without a nearby Pi package can still fail resolution.
63
+
64
+ If resolution fails, report the error and stop before reading or writing a guessed settings path.
65
+ Ask for the exact settings path or the intended Pi executable to be made available on `PATH`.
66
+ Do not install another Pi copy, modify `node_modules`, hard-code a Bun global directory, or use an ad hoc loader hook to bypass the failure.
53
67
 
54
68
  Read the existing document before editing it.
55
69
 
@@ -1,11 +1,71 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { resolve } from "node:path";
4
- import { getAgentDir } from "@earendil-works/pi-coding-agent";
3
+ import { spawnSync } from "node:child_process";
4
+ import { accessSync, constants, realpathSync, statSync } from "node:fs";
5
+ import { delimiter, dirname, resolve } from "node:path";
6
+ import { formatError } from "./script-support.mjs";
7
+
8
+ const hostPackage = "@earendil-works/pi-coding-agent";
9
+
10
+ function resolveHostEntry() {
11
+ try {
12
+ return import.meta.resolve(hostPackage);
13
+ } catch (error) {
14
+ if (error.code !== "ERR_MODULE_NOT_FOUND") throw error;
15
+ }
16
+
17
+ // Pi maps host peers inside its loader, not inside standalone Node scripts.
18
+ // Resolve beside the real CLI so npm and Bun global installs need no extra copy.
19
+ const names = process.platform === "win32" ? ["pi.exe", "pi.cmd", "pi"] : ["pi"];
20
+ for (const directory of process.env.PATH?.split(delimiter) ?? []) {
21
+ for (const name of names) {
22
+ const candidate = resolve(directory, name);
23
+ try {
24
+ accessSync(candidate, constants.X_OK);
25
+ if (!statSync(candidate).isFile()) continue;
26
+ } catch {
27
+ continue;
28
+ }
29
+ const result = spawnSync(
30
+ process.execPath,
31
+ [
32
+ "--input-type=module",
33
+ "--eval",
34
+ `console.log(JSON.stringify(import.meta.resolve(${JSON.stringify(hostPackage)})))`,
35
+ ],
36
+ {
37
+ cwd: dirname(realpathSync(candidate)),
38
+ encoding: "utf8",
39
+ timeout: 5000,
40
+ maxBuffer: 64 * 1024,
41
+ },
42
+ );
43
+ if (result.error) throw result.error;
44
+ if (result.status !== 0) {
45
+ throw new Error(`Cannot resolve ${hostPackage} beside the first pi executable on PATH: ${result.stderr}`);
46
+ }
47
+ const entry = JSON.parse(result.stdout);
48
+ if (typeof entry !== "string" || !entry.startsWith("file:")) {
49
+ throw new Error("Pi resolution did not return a local module URL.");
50
+ }
51
+ return entry;
52
+ }
53
+ }
54
+ throw new Error("Pi is not resolvable from this skill and no pi executable is available on PATH.");
55
+ }
5
56
 
6
57
  if (process.argv.length > 2) {
7
58
  console.error("Usage: node scripts/config-path.mjs");
8
59
  process.exitCode = 2;
9
60
  } else {
10
- process.stdout.write(`${JSON.stringify(resolve(getAgentDir(), "pi-starship.toml"))}\n`);
61
+ try {
62
+ const { getAgentDir } = await import(resolveHostEntry());
63
+ process.stdout.write(`${JSON.stringify(resolve(getAgentDir(), "pi-starship.toml"))}\n`);
64
+ } catch (error) {
65
+ console.error(`Unable to locate pi-starship.toml: ${formatError(error)}`);
66
+ console.error(
67
+ "Make the intended Pi installation available on PATH, or ask for an explicit settings path. No settings were changed.",
68
+ );
69
+ process.exitCode = 1;
70
+ }
11
71
  }