UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

3 lines (2 loc) • 2.92 kB
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url); { const __piWorkerThreads = require("node:worker_threads"); if (typeof __piWorkerThreads.markAsUncloneable !== "function") { __piWorkerThreads.markAsUncloneable = () => {}; } } import{getPackageDir}from"./chunk-QJTWAOBX.js";import"./chunk-ATQFN5HI.js";import"./chunk-IKOFCODM.js";import{createRequire}from"node:module";import{dirname,join}from"node:path";import{fileURLToPath}from"node:url";import{isQuarantinedNativeFile,QUARANTINE_ATTRIBUTE}from"@earendil-works/pi-pty";var NATIVE_GREP_ABI_VERSION="1",NativeGrepSentinelMismatchError=class extends Error{constructor(modulePath){super(`Native grep ABI mismatch in ${modulePath}: expected __senpiGrepAbi1() === "1" and a grep function`),this.code="native-sentinel-mismatch",this.name="NativeGrepSentinelMismatchError",this.modulePath=modulePath}};function getNativeGrepCandidatePaths(options={}){let env=options.env??process.env;if(env.SENPI_GREP_NATIVE_PATH)return[env.SENPI_GREP_NATIVE_PATH];let host=`${options.platform??process.platform}-${options.arch??process.arch}`,file=`senpi_grep.${host}.node`,packageDir=options.packageDir??(env.SENPI_PACKAGE_DIR||getPackageDir()),moduleDir=options.moduleDir??dirname(fileURLToPath(import.meta.url)),execPath=options.execPath??process.execPath;return[join(packageDir,"native/prebuilds",host,file),join(moduleDir,"../../../../native/prebuilds",host,file),join(dirname(execPath),"native/prebuilds",host,file)]}function loadNativeGrep(options={}){let attemptedPaths=getNativeGrepCandidatePaths(options),platform=options.platform??process.platform,host=`${platform}-${options.arch??process.arch}`,requireBinding=options.requireBinding??createRequire(import.meta.url),isQuarantined=options.isQuarantined??(path=>isQuarantinedNativeFile(path,platform)),causes=[];for(let modulePath of attemptedPaths){if(isQuarantined(modulePath)){causes.push(`${modulePath}: blocked because ${QUARANTINE_ATTRIBUTE} is present (macOS Gatekeeper)`);continue}try{let native=requireBinding(modulePath);return assertNativeGrepBinding(native,modulePath),{native,diagnostic:null}}catch(error){if(error instanceof NativeGrepSentinelMismatchError)throw error;causes.push(`${modulePath}: ${error instanceof Error?error.message:String(error)}`)}}return{native:null,diagnostic:{code:"native-unavailable",host,attemptedPaths,message:`No native grep prebuild is available for ${host}.`,cause:causes.join("; ")}}}function assertNativeGrepBinding(value,modulePath){if(typeof value!="object"||value===null||!("grep"in value)||typeof value.grep!="function"||!("__senpiGrepAbi1"in value)||typeof value.__senpiGrepAbi1!="function"||value.__senpiGrepAbi1()!==NATIVE_GREP_ABI_VERSION)throw new NativeGrepSentinelMismatchError(modulePath)}export{NATIVE_GREP_ABI_VERSION,NativeGrepSentinelMismatchError,getNativeGrepCandidatePaths,loadNativeGrep};