pi-post 0.6.3 → 0.7.0
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/README.md +1 -1
- package/bin/pi-post.mjs +0 -0
- package/extensions/pi-post.ts +5 -0
- package/package.json +1 -1
- package/src/cli-shim.ts +25 -0
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ inert.
|
|
|
74
74
|
pi install npm:pi-post
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
Nothing to enable; every session registers itself on startup.
|
|
77
|
+
Nothing to enable; every session registers itself on startup. Once a session has started, the CLI is also available at `~/.pi/agent/post/bin/pi-post` for hooks and scripts on hosts where `pi-post` is not on `PATH`.
|
|
78
78
|
|
|
79
79
|
## Use
|
|
80
80
|
|
package/bin/pi-post.mjs
CHANGED
|
File without changes
|
package/extensions/pi-post.ts
CHANGED
|
@@ -6,6 +6,8 @@ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-a
|
|
|
6
6
|
import { Text } from "@earendil-works/pi-tui";
|
|
7
7
|
import { Type } from "typebox";
|
|
8
8
|
import type { FSWatcher } from "node:fs";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { dirname, resolve } from "node:path";
|
|
9
11
|
import { canonicalPath, sessionAddress } from "../src/address.ts";
|
|
10
12
|
import { createMessage, type Message } from "../src/message.ts";
|
|
11
13
|
import {
|
|
@@ -31,8 +33,10 @@ import {
|
|
|
31
33
|
writeRecord,
|
|
32
34
|
} from "../src/registry.ts";
|
|
33
35
|
import { resolveTargets } from "../src/resolve.ts";
|
|
36
|
+
import { ensureCliShim } from "../src/cli-shim.ts";
|
|
34
37
|
|
|
35
38
|
const HEARTBEAT_MS = 30_000;
|
|
39
|
+
const CLI_TARGET = resolve(dirname(fileURLToPath(import.meta.url)), "../bin/pi-post.mjs");
|
|
36
40
|
|
|
37
41
|
export default function (pi: ExtensionAPI) {
|
|
38
42
|
const root = postRoot();
|
|
@@ -94,6 +98,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
94
98
|
process.env.PI_SESSION_ADDRESS = selfAddress;
|
|
95
99
|
|
|
96
100
|
ensureDirs(root, selfAddress);
|
|
101
|
+
ensureCliShim(root, CLI_TARGET);
|
|
97
102
|
writeRecord(root, {
|
|
98
103
|
v: 1,
|
|
99
104
|
address: selfAddress,
|
package/package.json
CHANGED
package/src/cli-shim.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { existsSync, lstatSync, mkdirSync, readlinkSync, symlinkSync, unlinkSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
/** Ensure the mailbox-owned CLI path points at the package's own executable. */
|
|
5
|
+
export function ensureCliShim(baseDir: string, targetPath: string): void {
|
|
6
|
+
const shimDir = join(baseDir, "bin");
|
|
7
|
+
const shimPath = join(shimDir, "pi-post");
|
|
8
|
+
try {
|
|
9
|
+
mkdirSync(shimDir, { recursive: true, mode: 0o700 });
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
if (lstatSync(shimPath).isSymbolicLink()) {
|
|
13
|
+
const linkTarget = readlinkSync(shimPath);
|
|
14
|
+
if (resolve(dirname(shimPath), linkTarget) === resolve(targetPath) && existsSync(targetPath)) return;
|
|
15
|
+
}
|
|
16
|
+
unlinkSync(shimPath);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
symlinkSync(targetPath, shimPath);
|
|
22
|
+
} catch {
|
|
23
|
+
// A CLI convenience must never prevent a session from starting.
|
|
24
|
+
}
|
|
25
|
+
}
|