pi-post 0.6.2 → 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 +6 -1
- package/bin/pi-post.mjs +0 -0
- package/extensions/pi-post.ts +9 -0
- package/package.json +2 -2
- 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
|
|
|
@@ -145,6 +145,11 @@ sessions can read state; only one can consume a message.
|
|
|
145
145
|
| `PI_POST_FROM` | — | Default `--from` label for the CLI |
|
|
146
146
|
| `PI_POST_REPLY_TO` | — | Default `--reply-to` address for the CLI |
|
|
147
147
|
|
|
148
|
+
The extension also *sets* one variable: `PI_SESSION_ADDRESS`, the session's
|
|
149
|
+
own `s-…` address, exported at session start so child processes (bash tools,
|
|
150
|
+
spawned scripts) can capture a reply target without shelling out to
|
|
151
|
+
`pi-post whoami`.
|
|
152
|
+
|
|
148
153
|
The directory is created `0700` and messages `0600`.
|
|
149
154
|
|
|
150
155
|
## Limits
|
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();
|
|
@@ -88,8 +92,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
88
92
|
const canonical = canonicalPath(ctx.cwd);
|
|
89
93
|
selfAddress = sessionAddress(sessionId);
|
|
90
94
|
selfName = pi.getSessionName() ?? defaultSessionName(canonical, selfAddress);
|
|
95
|
+
// Expose the address to child processes (bash tools inherit process.env),
|
|
96
|
+
// so scripts can capture a send_message target without shelling out to
|
|
97
|
+
// `pi-post whoami` or re-deriving the hash from PI_SESSION_ID.
|
|
98
|
+
process.env.PI_SESSION_ADDRESS = selfAddress;
|
|
91
99
|
|
|
92
100
|
ensureDirs(root, selfAddress);
|
|
101
|
+
ensureCliShim(root, CLI_TARGET);
|
|
93
102
|
writeRecord(root, {
|
|
94
103
|
v: 1,
|
|
95
104
|
address: selfAddress,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-post",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Messages between pi sessions — delivered mid-task or queued until they return.
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Messages between pi sessions — delivered mid-task or queued until they return.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
7
7
|
"pi-extension",
|
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
|
+
}
|