@code-yeongyu/senpi-pty 2026.8.18 → 2026.8.20
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/dist/loader.d.ts +6 -0
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +11 -0
- package/dist/loader.js.map +1 -1
- package/dist/quarantine.d.ts +15 -0
- package/dist/quarantine.d.ts.map +1 -0
- package/dist/quarantine.js +27 -0
- package/dist/quarantine.js.map +1 -0
- package/package.json +1 -1
package/dist/loader.d.ts
CHANGED
|
@@ -34,8 +34,14 @@ export interface NativePtyCandidatePathOptions {
|
|
|
34
34
|
readonly execDir?: string;
|
|
35
35
|
}
|
|
36
36
|
export type NativePtyRequireBinding = (modulePath: string) => unknown;
|
|
37
|
+
/**
|
|
38
|
+
* Reports whether a candidate prebuild carries macOS `com.apple.quarantine`.
|
|
39
|
+
* Injectable so tests can exercise the guard without a quarantined artifact.
|
|
40
|
+
*/
|
|
41
|
+
export type NativePtyQuarantineProbe = (modulePath: string) => boolean;
|
|
37
42
|
export interface NativePtyLoaderOptions extends NativePtyCandidatePathOptions {
|
|
38
43
|
readonly requireBinding?: NativePtyRequireBinding;
|
|
44
|
+
readonly isQuarantined?: NativePtyQuarantineProbe;
|
|
39
45
|
}
|
|
40
46
|
export declare const NATIVE_PTY_PACKAGE_VERSION: string;
|
|
41
47
|
/**
|
package/dist/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,KAAK,CAAC;AAE9C,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,EAAE,UAAU,EAAE,MAAM,GAAG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G,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;AAEtE;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;AAEvE,MAAM,WAAW,sBAAuB,SAAQ,6BAA6B;IAC5E,QAAQ,CAAC,cAAc,CAAC,EAAE,uBAAuB,CAAC;IAClD,QAAQ,CAAC,aAAa,CAAC,EAAE,wBAAwB,CAAC;CAClD;AAGD,eAAO,MAAM,0BAA0B,QAAuB,CAAC;AAC/D;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAyB1C,wBAAgB,0BAA0B,CAAC,UAAU,GAAE,MAA+B,GAAG,MAAM,CAE9F;AAED,wBAAgB,sBAAsB,CACrC,QAAQ,GAAE,MAAM,CAAC,eAAe,GAAG;IAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAqB,GAC9E,gBAAgB,CAElB;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,GAAE,MAAyB,EAAE,IAAI,GAAE,MAAqB,GAAG,MAAM,CAEzG;AAED,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,6BAAkC,GAAG,SAAS,MAAM,EAAE,CAOzG;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,sBAA2B,GAAG,mBAAmB,CA2CvF"}
|
package/dist/loader.js
CHANGED
|
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { isQuarantinedNativeFile } from "./quarantine.js";
|
|
5
6
|
export class NativePtySentinelMismatchError extends Error {
|
|
6
7
|
constructor(modulePath, expectedExport, actualExports) {
|
|
7
8
|
super(`@earendil-works/pi-pty native sentinel mismatch: expected ${expectedExport}() in ${modulePath}, exports=${actualExports.join(",") || "<none>"}`);
|
|
@@ -67,8 +68,18 @@ export function loadNativePty(options = {}) {
|
|
|
67
68
|
const host = getNativePtyHost(options.platform, options.arch);
|
|
68
69
|
const attemptedPaths = getNativePtyCandidatePaths({ ...options, runtime });
|
|
69
70
|
const requireBinding = options.requireBinding ?? cjsRequire;
|
|
71
|
+
const platform = options.platform ?? process.platform;
|
|
72
|
+
const isQuarantined = options.isQuarantined ?? (platform === "darwin" ? isQuarantinedNativeFile : undefined);
|
|
70
73
|
const causes = [];
|
|
71
74
|
for (const modulePath of attemptedPaths) {
|
|
75
|
+
// `dlopen()` on a quarantined, non-notarized addon hands control to Gatekeeper,
|
|
76
|
+
// which blocks the process behind a "could not verify ... free of malware" dialog
|
|
77
|
+
// instead of returning an error. Detect that state first and keep the diagnostic
|
|
78
|
+
// path, so the caller degrades to the pipe fallback rather than hanging.
|
|
79
|
+
if (isQuarantined?.(modulePath) === true) {
|
|
80
|
+
causes.push(`${modulePath}: blocked because com.apple.quarantine is present (macOS Gatekeeper)`);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
72
83
|
try {
|
|
73
84
|
const native = requireBinding(modulePath);
|
|
74
85
|
return {
|
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AA6BzC,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAMxD,YAAY,UAAkB,EAAE,cAAsB,EAAE,aAAgC;QACvF,KAAK,CACJ,6DAA6D,cAAc,SAAS,UAAU,aAAa,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,EAAE,CAChJ,CAAC;QARM,SAAI,GA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,EAAE,CAAC;QAC5C,MAAM,IAAI,8BAA8B,CAAC,UAAU,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;IACnF,CAAC;IAED,MAAM,cAAc,GAAG,0BAA0B,EAAE,CAAC;IACpD,MAAM,QAAQ,GAAG,KAAK,CAAC,cAAc,CAAC,CAAC;IACvC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,8BAA8B,CAAC,UAAU,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;IACrF,CAAC;IAED,MAAM,aAAa,GAAG,QAAQ,EAAE,CAAC;IACjC,IAAI,aAAa,KAAK,sBAAsB,EAAE,CAAC;QAC9C,MAAM,IAAI,8BAA8B,CAAC,UAAU,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;IACrF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACpD,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc;IACzC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC;AAClE,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACpC,CAAC;AAED,SAAS,gBAAgB,CAAC,UAAkB,EAAE,KAAc;IAC3D,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,GAAG,UAAU,KAAK,OAAO,EAAE,CAAC;AACpC,CAAC","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport type NativePtyRuntime = \"node\" | \"bun\";\n\nexport interface NativePtyBinding {\n\treadonly PtySession: unknown;\n\treadonly [exportName: string]: unknown;\n}\n\nexport interface NativePtyUnavailableDiagnostic {\n\treadonly code: \"native-unavailable\";\n\treadonly runtime: NativePtyRuntime;\n\treadonly host: string;\n\treadonly attemptedPath: string;\n\treadonly attemptedPaths: readonly string[];\n\treadonly message: string;\n\treadonly cause?: string;\n}\n\nexport type NativePtyLoadResult =\n\t| {\n\t\t\treadonly native: NativePtyBinding;\n\t\t\treadonly diagnostic: null;\n\t }\n\t| {\n\t\t\treadonly native: null;\n\t\t\treadonly diagnostic: NativePtyUnavailableDiagnostic;\n\t };\n\nexport class NativePtySentinelMismatchError extends Error {\n\treadonly code = \"native-sentinel-mismatch\";\n\treadonly modulePath: string;\n\treadonly expectedExport: string;\n\treadonly actualExports: readonly string[];\n\n\tconstructor(modulePath: string, expectedExport: string, actualExports: readonly string[]) {\n\t\tsuper(\n\t\t\t`@earendil-works/pi-pty native sentinel mismatch: expected ${expectedExport}() in ${modulePath}, exports=${actualExports.join(\",\") || \"<none>\"}`,\n\t\t);\n\t\tthis.name = \"NativePtySentinelMismatchError\";\n\t\tthis.modulePath = modulePath;\n\t\tthis.expectedExport = expectedExport;\n\t\tthis.actualExports = actualExports;\n\t}\n}\n\nexport interface NativePtyCandidatePathOptions {\n\treadonly runtime?: NativePtyRuntime;\n\treadonly platform?: string;\n\treadonly arch?: string;\n\treadonly moduleDir?: string;\n\treadonly execDir?: string;\n}\n\nexport type NativePtyRequireBinding = (modulePath: string) => unknown;\n\nexport interface NativePtyLoaderOptions extends NativePtyCandidatePathOptions {\n\treadonly requireBinding?: NativePtyRequireBinding;\n}\n\nconst cjsRequire = createRequire(import.meta.url);\nexport const NATIVE_PTY_PACKAGE_VERSION = readPackageVersion();\n/**\n * Native ABI version. INTENTIONALLY decoupled from the package/CalVer version: it\n * identifies the native surface (exports + signatures) this loader requires. Must\n * match `NATIVE_PTY_ABI_VERSION` and the `__senpiPtyAbi<N>` export in\n * `crates/senpi-pty/src/lib.rs`. Bump ONLY on a backward-incompatible native change\n * (and rebuild the vendored prebuilds); a CalVer release must NOT change it.\n */\nexport const NATIVE_PTY_ABI_VERSION = \"1\";\n\nfunction readPackageVersion(): string {\n\t// node/tsx/tarball layouts: the sibling `../package.json` resolves normally.\n\ttry {\n\t\tconst packageMetadata = cjsRequire(\"../package.json\");\n\t\tif (isRecord(packageMetadata) && typeof packageMetadata.version === \"string\") {\n\t\t\treturn packageMetadata.version;\n\t\t}\n\t} catch {\n\t\t// Compiled Bun binary: `../package.json` is not in the embedded FS. Fall through.\n\t}\n\t// Compiled Bun binary: the release ships package.json beside the executable. All\n\t// workspace packages are lockstep-versioned, so the sibling version matches pty's.\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(readFileSync(join(dirname(process.execPath), \"package.json\"), \"utf-8\"));\n\t\tif (isRecord(parsed) && typeof parsed.version === \"string\") {\n\t\t\treturn parsed.version;\n\t\t}\n\t} catch {\n\t\t// No readable sibling package.json either.\n\t}\n\tthrow new Error(\"@earendil-works/pi-pty package.json is missing a string version\");\n}\n\nexport function getNativePtySentinelExport(abiVersion: string = NATIVE_PTY_ABI_VERSION): string {\n\treturn `__senpiPtyAbi${abiVersion}`;\n}\n\nexport function detectNativePtyRuntime(\n\tversions: NodeJS.ProcessVersions & { readonly bun?: unknown } = process.versions,\n): NativePtyRuntime {\n\treturn typeof versions.bun === \"string\" ? \"bun\" : \"node\";\n}\n\nexport function getNativePtyHost(platform: string = process.platform, arch: string = process.arch): string {\n\treturn `${platform}-${arch}`;\n}\n\nexport function getNativePtyCandidatePaths(options: NativePtyCandidatePathOptions = {}): readonly string[] {\n\tconst host = getNativePtyHost(options.platform, options.arch);\n\tconst moduleDir = options.moduleDir ?? dirname(fileURLToPath(import.meta.url));\n\tconst execDir = options.execDir ?? dirname(process.execPath);\n\tconst nativePath = join(\"native\", \"prebuilds\", host, `senpi_pty.${host}.node`);\n\n\treturn [join(moduleDir, \"..\", nativePath), join(moduleDir, nativePath), join(execDir, nativePath)];\n}\n\nexport function loadNativePty(options: NativePtyLoaderOptions = {}): NativePtyLoadResult {\n\tconst runtime = options.runtime ?? detectNativePtyRuntime();\n\tconst host = getNativePtyHost(options.platform, options.arch);\n\tconst attemptedPaths = getNativePtyCandidatePaths({ ...options, runtime });\n\tconst requireBinding = options.requireBinding ?? cjsRequire;\n\tconst causes: string[] = [];\n\n\tfor (const modulePath of attemptedPaths) {\n\t\ttry {\n\t\t\tconst native = requireBinding(modulePath);\n\t\t\treturn {\n\t\t\t\tnative: assertNativePtyBinding(native, modulePath),\n\t\t\t\tdiagnostic: null,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (error instanceof NativePtySentinelMismatchError) throw error;\n\t\t\tcauses.push(formatErrorCause(modulePath, error));\n\t\t}\n\t}\n\n\treturn {\n\t\tnative: null,\n\t\tdiagnostic: {\n\t\t\tcode: \"native-unavailable\",\n\t\t\truntime,\n\t\t\thost,\n\t\t\tattemptedPath: attemptedPaths[0] ?? \"\",\n\t\t\tattemptedPaths,\n\t\t\tmessage: `No @earendil-works/pi-pty ${runtime} native prebuild is available for ${host}.`,\n\t\t\tcause: causes.join(\"; \"),\n\t\t},\n\t};\n}\n\nfunction assertNativePtyBinding(value: unknown, modulePath: string): NativePtyBinding {\n\tif (!isNativePtyBinding(value)) {\n\t\tthrow new NativePtySentinelMismatchError(modulePath, getNativePtySentinelExport(), []);\n\t}\n\n\tconst actualExports = Object.keys(value).sort();\n\tif (typeof value.PtySession !== \"function\") {\n\t\tthrow new NativePtySentinelMismatchError(modulePath, \"PtySession\", actualExports);\n\t}\n\n\tconst sentinelExport = getNativePtySentinelExport();\n\tconst sentinel = value[sentinelExport];\n\tif (!isUnknownFunction(sentinel)) {\n\t\tthrow new NativePtySentinelMismatchError(modulePath, sentinelExport, actualExports);\n\t}\n\n\tconst sentinelValue = sentinel();\n\tif (sentinelValue !== NATIVE_PTY_ABI_VERSION) {\n\t\tthrow new NativePtySentinelMismatchError(modulePath, sentinelExport, actualExports);\n\t}\n\n\treturn value;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction isNativePtyBinding(value: unknown): value is NativePtyBinding {\n\treturn isRecord(value) && typeof value.PtySession === \"function\";\n}\n\nfunction isUnknownFunction(value: unknown): value is () => unknown {\n\treturn typeof value === \"function\";\n}\n\nfunction formatErrorCause(modulePath: string, error: unknown): string {\n\tconst message = error instanceof Error ? error.message : String(error);\n\treturn `${modulePath}: ${message}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AA6B1D,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAMxD,YAAY,UAAkB,EAAE,cAAsB,EAAE,aAAgC;QACvF,KAAK,CACJ,6DAA6D,cAAc,SAAS,UAAU,aAAa,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,EAAE,CAChJ,CAAC;QARM,SAAI,GAAG,0BAA0B,CAAC;QAS1C,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;QAC7C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACpC,CAAC;CACD;AAuBD,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,CAAC,MAAM,0BAA0B,GAAG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fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { isQuarantinedNativeFile } from \"./quarantine.ts\";\n\nexport type NativePtyRuntime = \"node\" | \"bun\";\n\nexport interface NativePtyBinding {\n\treadonly PtySession: unknown;\n\treadonly [exportName: string]: unknown;\n}\n\nexport interface NativePtyUnavailableDiagnostic {\n\treadonly code: \"native-unavailable\";\n\treadonly runtime: NativePtyRuntime;\n\treadonly host: string;\n\treadonly attemptedPath: string;\n\treadonly attemptedPaths: readonly string[];\n\treadonly message: string;\n\treadonly cause?: string;\n}\n\nexport type NativePtyLoadResult =\n\t| {\n\t\t\treadonly native: NativePtyBinding;\n\t\t\treadonly diagnostic: null;\n\t }\n\t| {\n\t\t\treadonly native: null;\n\t\t\treadonly diagnostic: NativePtyUnavailableDiagnostic;\n\t };\n\nexport class NativePtySentinelMismatchError extends Error {\n\treadonly code = \"native-sentinel-mismatch\";\n\treadonly modulePath: string;\n\treadonly expectedExport: string;\n\treadonly actualExports: readonly string[];\n\n\tconstructor(modulePath: string, expectedExport: string, actualExports: readonly string[]) {\n\t\tsuper(\n\t\t\t`@earendil-works/pi-pty native sentinel mismatch: expected ${expectedExport}() in ${modulePath}, exports=${actualExports.join(\",\") || \"<none>\"}`,\n\t\t);\n\t\tthis.name = \"NativePtySentinelMismatchError\";\n\t\tthis.modulePath = modulePath;\n\t\tthis.expectedExport = expectedExport;\n\t\tthis.actualExports = actualExports;\n\t}\n}\n\nexport interface NativePtyCandidatePathOptions {\n\treadonly runtime?: NativePtyRuntime;\n\treadonly platform?: string;\n\treadonly arch?: string;\n\treadonly moduleDir?: string;\n\treadonly execDir?: string;\n}\n\nexport type NativePtyRequireBinding = (modulePath: string) => unknown;\n\n/**\n * Reports whether a candidate prebuild carries macOS `com.apple.quarantine`.\n * Injectable so tests can exercise the guard without a quarantined artifact.\n */\nexport type NativePtyQuarantineProbe = (modulePath: string) => boolean;\n\nexport interface NativePtyLoaderOptions extends NativePtyCandidatePathOptions {\n\treadonly requireBinding?: NativePtyRequireBinding;\n\treadonly isQuarantined?: NativePtyQuarantineProbe;\n}\n\nconst cjsRequire = createRequire(import.meta.url);\nexport const NATIVE_PTY_PACKAGE_VERSION = readPackageVersion();\n/**\n * Native ABI version. INTENTIONALLY decoupled from the package/CalVer version: it\n * identifies the native surface (exports + signatures) this loader requires. Must\n * match `NATIVE_PTY_ABI_VERSION` and the `__senpiPtyAbi<N>` export in\n * `crates/senpi-pty/src/lib.rs`. Bump ONLY on a backward-incompatible native change\n * (and rebuild the vendored prebuilds); a CalVer release must NOT change it.\n */\nexport const NATIVE_PTY_ABI_VERSION = \"1\";\n\nfunction readPackageVersion(): string {\n\t// node/tsx/tarball layouts: the sibling `../package.json` resolves normally.\n\ttry {\n\t\tconst packageMetadata = cjsRequire(\"../package.json\");\n\t\tif (isRecord(packageMetadata) && typeof packageMetadata.version === \"string\") {\n\t\t\treturn packageMetadata.version;\n\t\t}\n\t} catch {\n\t\t// Compiled Bun binary: `../package.json` is not in the embedded FS. Fall through.\n\t}\n\t// Compiled Bun binary: the release ships package.json beside the executable. All\n\t// workspace packages are lockstep-versioned, so the sibling version matches pty's.\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(readFileSync(join(dirname(process.execPath), \"package.json\"), \"utf-8\"));\n\t\tif (isRecord(parsed) && typeof parsed.version === \"string\") {\n\t\t\treturn parsed.version;\n\t\t}\n\t} catch {\n\t\t// No readable sibling package.json either.\n\t}\n\tthrow new Error(\"@earendil-works/pi-pty package.json is missing a string version\");\n}\n\nexport function getNativePtySentinelExport(abiVersion: string = NATIVE_PTY_ABI_VERSION): string {\n\treturn `__senpiPtyAbi${abiVersion}`;\n}\n\nexport function detectNativePtyRuntime(\n\tversions: NodeJS.ProcessVersions & { readonly bun?: unknown } = process.versions,\n): NativePtyRuntime {\n\treturn typeof versions.bun === \"string\" ? \"bun\" : \"node\";\n}\n\nexport function getNativePtyHost(platform: string = process.platform, arch: string = process.arch): string {\n\treturn `${platform}-${arch}`;\n}\n\nexport function getNativePtyCandidatePaths(options: NativePtyCandidatePathOptions = {}): readonly string[] {\n\tconst host = getNativePtyHost(options.platform, options.arch);\n\tconst moduleDir = options.moduleDir ?? dirname(fileURLToPath(import.meta.url));\n\tconst execDir = options.execDir ?? dirname(process.execPath);\n\tconst nativePath = join(\"native\", \"prebuilds\", host, `senpi_pty.${host}.node`);\n\n\treturn [join(moduleDir, \"..\", nativePath), join(moduleDir, nativePath), join(execDir, nativePath)];\n}\n\nexport function loadNativePty(options: NativePtyLoaderOptions = {}): NativePtyLoadResult {\n\tconst runtime = options.runtime ?? detectNativePtyRuntime();\n\tconst host = getNativePtyHost(options.platform, options.arch);\n\tconst attemptedPaths = getNativePtyCandidatePaths({ ...options, runtime });\n\tconst requireBinding = options.requireBinding ?? cjsRequire;\n\tconst platform = options.platform ?? process.platform;\n\tconst isQuarantined = options.isQuarantined ?? (platform === \"darwin\" ? isQuarantinedNativeFile : undefined);\n\tconst causes: string[] = [];\n\n\tfor (const modulePath of attemptedPaths) {\n\t\t// `dlopen()` on a quarantined, non-notarized addon hands control to Gatekeeper,\n\t\t// which blocks the process behind a \"could not verify ... free of malware\" dialog\n\t\t// instead of returning an error. Detect that state first and keep the diagnostic\n\t\t// path, so the caller degrades to the pipe fallback rather than hanging.\n\t\tif (isQuarantined?.(modulePath) === true) {\n\t\t\tcauses.push(`${modulePath}: blocked because com.apple.quarantine is present (macOS Gatekeeper)`);\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\tconst native = requireBinding(modulePath);\n\t\t\treturn {\n\t\t\t\tnative: assertNativePtyBinding(native, modulePath),\n\t\t\t\tdiagnostic: null,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (error instanceof NativePtySentinelMismatchError) throw error;\n\t\t\tcauses.push(formatErrorCause(modulePath, error));\n\t\t}\n\t}\n\n\treturn {\n\t\tnative: null,\n\t\tdiagnostic: {\n\t\t\tcode: \"native-unavailable\",\n\t\t\truntime,\n\t\t\thost,\n\t\t\tattemptedPath: attemptedPaths[0] ?? \"\",\n\t\t\tattemptedPaths,\n\t\t\tmessage: `No @earendil-works/pi-pty ${runtime} native prebuild is available for ${host}.`,\n\t\t\tcause: causes.join(\"; \"),\n\t\t},\n\t};\n}\n\nfunction assertNativePtyBinding(value: unknown, modulePath: string): NativePtyBinding {\n\tif (!isNativePtyBinding(value)) {\n\t\tthrow new NativePtySentinelMismatchError(modulePath, getNativePtySentinelExport(), []);\n\t}\n\n\tconst actualExports = Object.keys(value).sort();\n\tif (typeof value.PtySession !== \"function\") {\n\t\tthrow new NativePtySentinelMismatchError(modulePath, \"PtySession\", actualExports);\n\t}\n\n\tconst sentinelExport = getNativePtySentinelExport();\n\tconst sentinel = value[sentinelExport];\n\tif (!isUnknownFunction(sentinel)) {\n\t\tthrow new NativePtySentinelMismatchError(modulePath, sentinelExport, actualExports);\n\t}\n\n\tconst sentinelValue = sentinel();\n\tif (sentinelValue !== NATIVE_PTY_ABI_VERSION) {\n\t\tthrow new NativePtySentinelMismatchError(modulePath, sentinelExport, actualExports);\n\t}\n\n\treturn value;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction isNativePtyBinding(value: unknown): value is NativePtyBinding {\n\treturn isRecord(value) && typeof value.PtySession === \"function\";\n}\n\nfunction isUnknownFunction(value: unknown): value is () => unknown {\n\treturn typeof value === \"function\";\n}\n\nfunction formatErrorCause(modulePath: string, error: unknown): string {\n\tconst message = error instanceof Error ? error.message : String(error);\n\treturn `${modulePath}: ${message}`;\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const QUARANTINE_ATTRIBUTE = "com.apple.quarantine";
|
|
2
|
+
/**
|
|
3
|
+
* SECURITY: `dlopen()` on a quarantined, non-notarized addon hands control to
|
|
4
|
+
* Gatekeeper, which suspends the process behind an "Apple could not verify ... is
|
|
5
|
+
* free of malware" dialog instead of returning an error. Senpi's prebuilds carry
|
|
6
|
+
* only a linker ad-hoc signature, so a quarantined prebuild is never auto-approved.
|
|
7
|
+
* Detection MUST NOT become removal: clearing the attribute would silently defeat
|
|
8
|
+
* the user's malware protection.
|
|
9
|
+
*
|
|
10
|
+
* Node exposes no `getxattr` binding, so `xattr -p` is the only available channel;
|
|
11
|
+
* it exits 0 only when the attribute is present. Any spawn failure returns `false`
|
|
12
|
+
* so an unreadable attribute never rejects an otherwise loadable prebuild.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isQuarantinedNativeFile(modulePath: string, platform?: string): boolean;
|
|
15
|
+
//# sourceMappingURL=quarantine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quarantine.d.ts","sourceRoot":"","sources":["../src/quarantine.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAE3D;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAyB,GAAG,OAAO,CAUxG"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
export const QUARANTINE_ATTRIBUTE = "com.apple.quarantine";
|
|
4
|
+
/**
|
|
5
|
+
* SECURITY: `dlopen()` on a quarantined, non-notarized addon hands control to
|
|
6
|
+
* Gatekeeper, which suspends the process behind an "Apple could not verify ... is
|
|
7
|
+
* free of malware" dialog instead of returning an error. Senpi's prebuilds carry
|
|
8
|
+
* only a linker ad-hoc signature, so a quarantined prebuild is never auto-approved.
|
|
9
|
+
* Detection MUST NOT become removal: clearing the attribute would silently defeat
|
|
10
|
+
* the user's malware protection.
|
|
11
|
+
*
|
|
12
|
+
* Node exposes no `getxattr` binding, so `xattr -p` is the only available channel;
|
|
13
|
+
* it exits 0 only when the attribute is present. Any spawn failure returns `false`
|
|
14
|
+
* so an unreadable attribute never rejects an otherwise loadable prebuild.
|
|
15
|
+
*/
|
|
16
|
+
export function isQuarantinedNativeFile(modulePath, platform = process.platform) {
|
|
17
|
+
if (platform !== "darwin")
|
|
18
|
+
return false;
|
|
19
|
+
if (!existsSync(modulePath))
|
|
20
|
+
return false;
|
|
21
|
+
const probe = spawnSync("/usr/bin/xattr", ["-p", QUARANTINE_ATTRIBUTE, modulePath], {
|
|
22
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
23
|
+
timeout: 2000,
|
|
24
|
+
});
|
|
25
|
+
return probe.error === undefined && probe.status === 0;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=quarantine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quarantine.js","sourceRoot":"","sources":["../src/quarantine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAE3D;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,uBAAuB,CAAC,UAAkB,EAAE,WAAmB,OAAO,CAAC,QAAQ;IAC9F,IAAI,QAAQ,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACxC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;QAAE,OAAO,KAAK,CAAC;IAE1C,MAAM,KAAK,GAAG,SAAS,CAAC,gBAAgB,EAAE,CAAC,IAAI,EAAE,oBAAoB,EAAE,UAAU,CAAC,EAAE;QACnF,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC;QACrC,OAAO,EAAE,IAAI;KACb,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;AACxD,CAAC","sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\n\nexport const QUARANTINE_ATTRIBUTE = \"com.apple.quarantine\";\n\n/**\n * SECURITY: `dlopen()` on a quarantined, non-notarized addon hands control to\n * Gatekeeper, which suspends the process behind an \"Apple could not verify ... is\n * free of malware\" dialog instead of returning an error. Senpi's prebuilds carry\n * only a linker ad-hoc signature, so a quarantined prebuild is never auto-approved.\n * Detection MUST NOT become removal: clearing the attribute would silently defeat\n * the user's malware protection.\n *\n * Node exposes no `getxattr` binding, so `xattr -p` is the only available channel;\n * it exits 0 only when the attribute is present. Any spawn failure returns `false`\n * so an unreadable attribute never rejects an otherwise loadable prebuild.\n */\nexport function isQuarantinedNativeFile(modulePath: string, platform: string = process.platform): boolean {\n\tif (platform !== \"darwin\") return false;\n\tif (!existsSync(modulePath)) return false;\n\n\tconst probe = spawnSync(\"/usr/bin/xattr\", [\"-p\", QUARANTINE_ATTRIBUTE, modulePath], {\n\t\tstdio: [\"ignore\", \"ignore\", \"ignore\"],\n\t\ttimeout: 2000,\n\t});\n\n\treturn probe.error === undefined && probe.status === 0;\n}\n"]}
|