@oh-my-pi/pi-natives 12.8.1 → 12.9.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/native/pi_natives.darwin-arm64.node +0 -0
- package/native/pi_natives.darwin-x64-baseline.node +0 -0
- package/native/pi_natives.darwin-x64-modern.node +0 -0
- package/native/pi_natives.linux-arm64.node +0 -0
- package/native/pi_natives.linux-x64-baseline.node +0 -0
- package/native/pi_natives.linux-x64-modern.node +0 -0
- package/native/pi_natives.win32-x64-baseline.node +0 -0
- package/native/pi_natives.win32-x64-modern.node +0 -0
- package/package.json +2 -2
- package/src/index.ts +0 -6
- package/src/native.ts +29 -4
- package/src/system-info/index.ts +0 -9
- package/src/system-info/types.ts +0 -41
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-pi/pi-natives",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.9.0",
|
|
4
4
|
"description": "Native Rust functionality via N-API",
|
|
5
5
|
"keywords": ["napi", "rust", "native", "grep", "text-processing"],
|
|
6
6
|
"type": "module",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"url": "https://github.com/can1357/oh-my-pi/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@oh-my-pi/pi-utils": "12.
|
|
40
|
+
"@oh-my-pi/pi-utils": "12.9.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/bun": "^1.3.9"
|
package/src/index.ts
CHANGED
|
@@ -93,12 +93,6 @@ export {
|
|
|
93
93
|
|
|
94
94
|
export { type HtmlToMarkdownOptions, htmlToMarkdown } from "./html";
|
|
95
95
|
|
|
96
|
-
// =============================================================================
|
|
97
|
-
// System info
|
|
98
|
-
// =============================================================================
|
|
99
|
-
|
|
100
|
-
export { getSystemInfo, type SystemInfo } from "./system-info";
|
|
101
|
-
|
|
102
96
|
// =============================================================================
|
|
103
97
|
// Shell execution (brush-core)
|
|
104
98
|
// =============================================================================
|
package/src/native.ts
CHANGED
|
@@ -22,12 +22,13 @@ import "./keys/types";
|
|
|
22
22
|
import "./ps/types";
|
|
23
23
|
import "./pty/types";
|
|
24
24
|
import "./shell/types";
|
|
25
|
-
import "./system-info/types";
|
|
26
25
|
import "./text/types";
|
|
27
26
|
import "./work/types";
|
|
28
27
|
|
|
29
28
|
export type { NativeBindings, TsFunc } from "./bindings";
|
|
30
29
|
|
|
30
|
+
const debugStartup = $env.PI_DEBUG_STARTUP ? (stage: string) => process.stderr.write(`[startup] ${stage}\n`) : () => {};
|
|
31
|
+
|
|
31
32
|
type CpuVariant = "modern" | "baseline";
|
|
32
33
|
const require = createRequire(import.meta.url);
|
|
33
34
|
const textDecoder = new TextDecoder();
|
|
@@ -91,34 +92,49 @@ function getVariantOverride(): CpuVariant | null {
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
function detectAvx2Support(): boolean {
|
|
94
|
-
|
|
95
|
+
debugStartup("native:detectAvx2Support:start");
|
|
96
|
+
if (process.arch !== "x64") {
|
|
97
|
+
debugStartup("native:detectAvx2Support:done");
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
95
100
|
|
|
96
101
|
if (process.platform === "linux") {
|
|
97
102
|
try {
|
|
103
|
+
debugStartup("native:detectAvx2Support:readCpuinfo");
|
|
98
104
|
const cpuInfo = fs.readFileSync("/proc/cpuinfo", "utf8");
|
|
105
|
+
debugStartup("native:detectAvx2Support:done");
|
|
99
106
|
return /\bavx2\b/i.test(cpuInfo);
|
|
100
107
|
} catch {
|
|
108
|
+
debugStartup("native:detectAvx2Support:done");
|
|
101
109
|
return false;
|
|
102
110
|
}
|
|
103
111
|
}
|
|
104
112
|
|
|
105
113
|
if (process.platform === "darwin") {
|
|
114
|
+
debugStartup("native:detectAvx2Support:sysctl");
|
|
106
115
|
const leaf7 = runCommand("sysctl", ["-n", "machdep.cpu.leaf7_features"]);
|
|
107
|
-
if (leaf7 && /\bAVX2\b/i.test(leaf7))
|
|
116
|
+
if (leaf7 && /\bAVX2\b/i.test(leaf7)) {
|
|
117
|
+
debugStartup("native:detectAvx2Support:done");
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
108
120
|
const features = runCommand("sysctl", ["-n", "machdep.cpu.features"]);
|
|
121
|
+
debugStartup("native:detectAvx2Support:done");
|
|
109
122
|
return Boolean(features && /\bAVX2\b/i.test(features));
|
|
110
123
|
}
|
|
111
124
|
|
|
112
125
|
if (process.platform === "win32") {
|
|
126
|
+
debugStartup("native:detectAvx2Support:powershell");
|
|
113
127
|
const output = runCommand("powershell.exe", [
|
|
114
128
|
"-NoProfile",
|
|
115
129
|
"-NonInteractive",
|
|
116
130
|
"-Command",
|
|
117
131
|
"[System.Runtime.Intrinsics.X86.Avx2]::IsSupported",
|
|
118
132
|
]);
|
|
133
|
+
debugStartup("native:detectAvx2Support:done");
|
|
119
134
|
return output?.toLowerCase() === "true";
|
|
120
135
|
}
|
|
121
136
|
|
|
137
|
+
debugStartup("native:detectAvx2Support:done");
|
|
122
138
|
return false;
|
|
123
139
|
}
|
|
124
140
|
|
|
@@ -153,6 +169,7 @@ function selectEmbeddedAddonFile(): { filename: string; filePath: string } | nul
|
|
|
153
169
|
return embeddedAddon.files.find(file => file.variant === "baseline") ?? null;
|
|
154
170
|
}
|
|
155
171
|
function maybeExtractEmbeddedAddon(errors: string[]): string | null {
|
|
172
|
+
debugStartup("native:maybeExtractEmbeddedAddon:start");
|
|
156
173
|
if (!isCompiledBinary || !embeddedAddon) return null;
|
|
157
174
|
if (embeddedAddon.platformTag !== platformTag || embeddedAddon.version !== packageVersion) return null;
|
|
158
175
|
|
|
@@ -161,6 +178,7 @@ function maybeExtractEmbeddedAddon(errors: string[]): string | null {
|
|
|
161
178
|
const targetPath = path.join(versionedDir, selectedEmbeddedFile.filename);
|
|
162
179
|
|
|
163
180
|
try {
|
|
181
|
+
debugStartup("native:maybeExtractEmbeddedAddon:mkdir");
|
|
164
182
|
fs.mkdirSync(versionedDir, { recursive: true });
|
|
165
183
|
} catch (err) {
|
|
166
184
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -168,13 +186,18 @@ function maybeExtractEmbeddedAddon(errors: string[]): string | null {
|
|
|
168
186
|
return null;
|
|
169
187
|
}
|
|
170
188
|
|
|
189
|
+
debugStartup("native:maybeExtractEmbeddedAddon:exists");
|
|
171
190
|
if (fs.existsSync(targetPath)) {
|
|
191
|
+
debugStartup("native:maybeExtractEmbeddedAddon:done");
|
|
172
192
|
return targetPath;
|
|
173
193
|
}
|
|
174
194
|
|
|
175
195
|
try {
|
|
196
|
+
debugStartup("native:maybeExtractEmbeddedAddon:read");
|
|
176
197
|
const buffer = fs.readFileSync(selectedEmbeddedFile.filePath);
|
|
198
|
+
debugStartup("native:maybeExtractEmbeddedAddon:write");
|
|
177
199
|
fs.writeFileSync(targetPath, buffer);
|
|
200
|
+
debugStartup("native:maybeExtractEmbeddedAddon:done");
|
|
178
201
|
return targetPath;
|
|
179
202
|
} catch (err) {
|
|
180
203
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -183,16 +206,19 @@ function maybeExtractEmbeddedAddon(errors: string[]): string | null {
|
|
|
183
206
|
}
|
|
184
207
|
}
|
|
185
208
|
function loadNative(): NativeBindings {
|
|
209
|
+
debugStartup("native:loadNative:start");
|
|
186
210
|
const errors: string[] = [];
|
|
187
211
|
const embeddedCandidate = maybeExtractEmbeddedAddon(errors);
|
|
188
212
|
const runtimeCandidates = embeddedCandidate ? [embeddedCandidate, ...dedupedCandidates] : dedupedCandidates;
|
|
189
213
|
for (const candidate of runtimeCandidates) {
|
|
190
214
|
try {
|
|
215
|
+
debugStartup(`native:loadNative:require:${path.basename(candidate)}`);
|
|
191
216
|
const bindings = require(candidate) as NativeBindings;
|
|
192
217
|
validateNative(bindings, candidate);
|
|
193
218
|
if ($env.PI_DEV) {
|
|
194
219
|
console.log(`Loaded native addon from ${candidate}`);
|
|
195
220
|
}
|
|
221
|
+
debugStartup("native:loadNative:done");
|
|
196
222
|
return bindings;
|
|
197
223
|
} catch (err) {
|
|
198
224
|
if ($env.PI_DEV) {
|
|
@@ -267,7 +293,6 @@ function validateNative(bindings: NativeBindings, source: string): void {
|
|
|
267
293
|
checkFn("visibleWidth");
|
|
268
294
|
checkFn("killTree");
|
|
269
295
|
checkFn("listDescendants");
|
|
270
|
-
checkFn("getSystemInfo");
|
|
271
296
|
checkFn("getWorkProfile");
|
|
272
297
|
checkFn("invalidateFsScanCache");
|
|
273
298
|
if (missing.length) {
|
package/src/system-info/index.ts
DELETED
package/src/system-info/types.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Types for system information.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/** Snapshot of system details reported by native probes. */
|
|
6
|
-
export interface SystemInfo {
|
|
7
|
-
/** Operating system name (e.g. Linux, macOS, Windows). */
|
|
8
|
-
os: string;
|
|
9
|
-
/** CPU architecture (e.g. x64, arm64). */
|
|
10
|
-
arch: string;
|
|
11
|
-
/** Linux distro or detailed OS name when available. */
|
|
12
|
-
distro?: string;
|
|
13
|
-
/** Kernel version string, if the OS reports one. */
|
|
14
|
-
kernel?: string;
|
|
15
|
-
/** Hostname of the current machine. */
|
|
16
|
-
hostname?: string;
|
|
17
|
-
/** Active login shell, when detected. */
|
|
18
|
-
shell?: string;
|
|
19
|
-
/** Terminal program identifier, when available. */
|
|
20
|
-
terminal?: string;
|
|
21
|
-
/** Desktop environment name, if reported. */
|
|
22
|
-
de?: string;
|
|
23
|
-
/** Window manager name, if reported. */
|
|
24
|
-
wm?: string;
|
|
25
|
-
/** Primary CPU brand/model string. */
|
|
26
|
-
cpu?: string;
|
|
27
|
-
/** Primary GPU identifier, when available. */
|
|
28
|
-
gpu?: string;
|
|
29
|
-
/** System memory summary (used/total). */
|
|
30
|
-
memory?: string;
|
|
31
|
-
/** Disk usage summary (used/total) for primary mount. */
|
|
32
|
-
disk?: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
declare module "../bindings" {
|
|
36
|
-
/** Native bindings that expose system info collection. */
|
|
37
|
-
interface NativeBindings {
|
|
38
|
-
/** Get system information (OS, CPU, memory, and disk summaries). */
|
|
39
|
-
getSystemInfo(): SystemInfo;
|
|
40
|
-
}
|
|
41
|
-
}
|