pi-courier 0.1.34 → 0.1.35
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/README.zh-CN.md +1 -1
- package/package.json +3 -1
- package/scripts/ensure-crypto-native.d.mts +19 -0
- package/scripts/ensure-crypto-native.mjs +147 -0
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ npm run build
|
|
|
56
56
|
npm link # make the `pi-courier` command available globally
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
**Do not use `--ignore-scripts`**: the Matrix E2EE library downloads its native binary via postinstall.
|
|
59
|
+
**Do not use `--ignore-scripts`**: the Matrix E2EE library downloads its native binary via postinstall. On npm >= 11 the `allow-scripts` default may block that dependency's postinstall; `pi-courier`'s own postinstall self-checks for it and auto-downloads the missing native binary (one extra download on first install). If you still hit `Cannot find module '@matrix-org/matrix-sdk-crypto-nodejs-linux-x64-gnu'` (e.g. the auto-download was skipped), run manually:
|
|
60
60
|
|
|
61
61
|
```bash
|
|
62
62
|
cd node_modules/@matrix-org/matrix-sdk-crypto-nodejs
|
package/README.zh-CN.md
CHANGED
|
@@ -56,7 +56,7 @@ npm run build
|
|
|
56
56
|
npm link # 让 `pi-courier` 命令全局可用
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
**不要用 `--ignore-scripts`**:Matrix E2EE 库的 postinstall
|
|
59
|
+
**不要用 `--ignore-scripts`**:Matrix E2EE 库的 postinstall 会下载原生二进制。npm >= 11 的 `allow-scripts` 默认可能拦截该依赖的 postinstall;`pi-courier` 自己的 postinstall 会自检并**自动补下**缺失的原生二进制(首次安装多下载一次)。若仍报 `Cannot find module '@matrix-org/matrix-sdk-crypto-nodejs-linux-x64-gnu'`(比如自检被跳过),再手动补:
|
|
60
60
|
|
|
61
61
|
```bash
|
|
62
62
|
cd node_modules/@matrix-org/matrix-sdk-crypto-nodejs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-courier",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
4
4
|
"description": "Run pi coding agent from Matrix. Slash commands, skills and prompts fully work from messengers via the RPC protocol.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/standalone.js",
|
|
@@ -11,12 +11,14 @@
|
|
|
11
11
|
"dist/",
|
|
12
12
|
"deploy/",
|
|
13
13
|
"extensions/",
|
|
14
|
+
"scripts/",
|
|
14
15
|
"README.md",
|
|
15
16
|
"README.zh-CN.md"
|
|
16
17
|
],
|
|
17
18
|
"scripts": {
|
|
18
19
|
"build": "rm -rf dist && tsc",
|
|
19
20
|
"prepare": "npm run build",
|
|
21
|
+
"postinstall": "node scripts/ensure-crypto-native.mjs",
|
|
20
22
|
"watch": "tsc --watch",
|
|
21
23
|
"clean": "rm -rf dist",
|
|
22
24
|
"start": "node dist/standalone.js",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Type declarations for scripts/ensure-crypto-native.mjs (postinstall self-check). */
|
|
2
|
+
|
|
3
|
+
export interface EnsureResult {
|
|
4
|
+
ok: boolean;
|
|
5
|
+
downloaded?: boolean;
|
|
6
|
+
reason?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function nativeBindingBasename(): string | null;
|
|
10
|
+
|
|
11
|
+
export function isMusl(): boolean;
|
|
12
|
+
|
|
13
|
+
export function resolveCryptoPackageDir(): string | null;
|
|
14
|
+
|
|
15
|
+
export function isNativeBindingMissing(cryptoDir: string, basename: string | null): boolean;
|
|
16
|
+
|
|
17
|
+
export function runNativeDownloader(cryptoDir: string): void;
|
|
18
|
+
|
|
19
|
+
export function ensureCryptoNative(): EnsureResult;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Postinstall self-check for the matrix-rust-sdk-crypto native binding.
|
|
4
|
+
*
|
|
5
|
+
* WHY: `matrix-bot-sdk` depends on `@matrix-org/matrix-sdk-crypto-nodejs`, whose
|
|
6
|
+
* platform native binary (.node) is only produced by its own `postinstall`
|
|
7
|
+
* script (`node download-lib.js`) on first install. npm >= 11 ships
|
|
8
|
+
* `allow-scripts`, which by default BLOCKS a dependency's install scripts, so
|
|
9
|
+
* that binary never gets downloaded. At runtime the ESM top-level
|
|
10
|
+
* `import matrix-bot-sdk` synchronously requires the crypto module and the
|
|
11
|
+
* process dies with:
|
|
12
|
+
*
|
|
13
|
+
* Cannot find module '@matrix-org/matrix-sdk-crypto-nodejs-linux-x64-gnu'
|
|
14
|
+
*
|
|
15
|
+
* This self-check runs during *our* (the root package's) postinstall — that
|
|
16
|
+
* script is NOT blocked by allow-scripts — and, when the native binding is
|
|
17
|
+
* missing, re-runs the crypto package's own downloader so the binary is
|
|
18
|
+
* present before first run. Any failure here degrades to a warning; it never
|
|
19
|
+
* fails the install (the bridge can still run without E2EE crypto).
|
|
20
|
+
*
|
|
21
|
+
* Usage (from package root): node scripts/ensure-crypto-native.mjs
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { execFileSync } from "node:child_process";
|
|
25
|
+
import { existsSync } from "node:fs";
|
|
26
|
+
import { createRequire } from "node:module";
|
|
27
|
+
|
|
28
|
+
const require = createRequire(import.meta.url);
|
|
29
|
+
|
|
30
|
+
/** Current platform/arch names as napi-rs names them (no .node suffix). */
|
|
31
|
+
export function nativeBindingBasename() {
|
|
32
|
+
const { platform, arch } = process;
|
|
33
|
+
if (platform === "win32") return `matrix-sdk-crypto.win32-${arch}-msvc`;
|
|
34
|
+
if (platform === "darwin") return `matrix-sdk-crypto.darwin-${arch}`;
|
|
35
|
+
if (platform === "linux") {
|
|
36
|
+
const libc = isMusl() ? "musl" : "gnu";
|
|
37
|
+
return `matrix-sdk-crypto.linux-${arch}-${libc}`;
|
|
38
|
+
}
|
|
39
|
+
return null; // unsupported platform — native E2EE unavailable, skip silently
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isMusl() {
|
|
43
|
+
// Node >= 10 provides the runtime report; absent report => assume gnu.
|
|
44
|
+
try {
|
|
45
|
+
const { glibcVersionRuntime } = process.report.getReport().header;
|
|
46
|
+
return !glibcVersionRuntime;
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Locate the crypto package's own directory. Works both when we are an npm
|
|
54
|
+
* dependency (node_modules/<scope>/<pkg>) and when running from a repo clone.
|
|
55
|
+
*/
|
|
56
|
+
export function resolveCryptoPackageDir() {
|
|
57
|
+
const paths = [
|
|
58
|
+
// As a dependency (global/local npm install). createRequire resolves
|
|
59
|
+
// relative to this script inside the installed package tree.
|
|
60
|
+
(() => {
|
|
61
|
+
try {
|
|
62
|
+
return require.resolve("@matrix-org/matrix-sdk-crypto-nodejs/package.json");
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
})(),
|
|
67
|
+
// Nested copy under our own node_modules when hybrid layouts appear.
|
|
68
|
+
(() => {
|
|
69
|
+
try {
|
|
70
|
+
return require.resolve("@matrix-org/matrix-sdk-crypto-nodejs/package.json", {
|
|
71
|
+
paths: [process.cwd()],
|
|
72
|
+
});
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
})(),
|
|
77
|
+
].filter(Boolean);
|
|
78
|
+
|
|
79
|
+
// Prefer the one actually under a node_modules chain (global installs wire
|
|
80
|
+
// this via the primary resolution); fall back to any hit.
|
|
81
|
+
const hit = paths.find((p) => p.includes("node_modules")) ?? paths[0];
|
|
82
|
+
if (!hit) return null;
|
|
83
|
+
// hit is the package.json path; chop the filename to get the package dir.
|
|
84
|
+
return hit.slice(0, hit.lastIndexOf("package.json"));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* True when the crypto package dir lacks the native binding this platform needs.
|
|
89
|
+
* A platform we don't recognise (nativeBindingBasename() === null) counts as
|
|
90
|
+
* "fine" (skips download) rather than "missing".
|
|
91
|
+
*/
|
|
92
|
+
export function isNativeBindingMissing(cryptoDir, basename) {
|
|
93
|
+
if (basename === null) return false;
|
|
94
|
+
return !existsSync(`${cryptoDir}/${basename}.node`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Run the crypto package's own downloader to fetch the native binding. */
|
|
98
|
+
export function runNativeDownloader(cryptoDir) {
|
|
99
|
+
const script = `${cryptoDir}/download-lib.js`;
|
|
100
|
+
if (!existsSync(script)) {
|
|
101
|
+
throw new Error(`crypto downloader not found: ${script}`);
|
|
102
|
+
}
|
|
103
|
+
execFileSync(process.execPath, [script], {
|
|
104
|
+
cwd: cryptoDir,
|
|
105
|
+
stdio: "inherit",
|
|
106
|
+
// Inherit proxy env so machines behind a proxy still reach GitHub.
|
|
107
|
+
env: process.env,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function ensureCryptoNative() {
|
|
112
|
+
const basename = nativeBindingBasename();
|
|
113
|
+
const cryptoDir = resolveCryptoPackageDir();
|
|
114
|
+
|
|
115
|
+
if (!cryptoDir) {
|
|
116
|
+
console.warn(
|
|
117
|
+
"[pi-courier] crypto package not found — can't verify native binding; continuing (E2EE may be unavailable)."
|
|
118
|
+
);
|
|
119
|
+
return { ok: false, reason: "crypto-package-not-found" };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!isNativeBindingMissing(cryptoDir, basename)) {
|
|
123
|
+
// Already present (either downloaded once, or platform unsupported).
|
|
124
|
+
return { ok: true, downloaded: false };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
console.info(
|
|
128
|
+
`[pi-courier] crypto native binding (${basename}.node) missing — downloading (POSTINSTALL due to npm 11 allow-scripts).`
|
|
129
|
+
);
|
|
130
|
+
try {
|
|
131
|
+
runNativeDownloader(cryptoDir);
|
|
132
|
+
return { ok: true, downloaded: true };
|
|
133
|
+
} catch (err) {
|
|
134
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
135
|
+
console.warn(
|
|
136
|
+
`[pi-courier] could not auto-download crypto native binding: ${message}\n` +
|
|
137
|
+
` The bridge may still run without E2EE. To install manually:\n` +
|
|
138
|
+
` cd ${cryptoDir} && node download-lib.js`
|
|
139
|
+
);
|
|
140
|
+
return { ok: false, reason: "download-failed" };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Allow running both as a bin and importing the named exports for tests.
|
|
145
|
+
if (process.argv[1] && process.argv[1].endsWith("ensure-crypto-native.mjs")) {
|
|
146
|
+
ensureCryptoNative();
|
|
147
|
+
}
|