Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.8 KB
Raw Blame
'use strict'

// Probe addon load in fresh runtime process: failed native load can poison process. Usage: <runtime> this.cjs <module> <dir>.

const { accessSync, constants, existsSync } = require('node:fs')
const { join } = require('node:path')
const { assertNodePtyJobOwnership } = require('./node-pty-job-ownership.cjs')
const { assertWindowsProcessTreeCreationTime } = require('./windows-process-tree-creation-time.cjs')
const { nodePtyNativeModuleName } = require('./native-build-entry.cjs')

const NODE_PTY_CONPTY_RUNTIME_FILES = ['conpty.dll', 'OpenConsole.exe']

function probeNativeBuildDir(moduleName, dir) {
  if (moduleName === 'node-pty') {
    const nativeName = nodePtyNativeModuleName()
    const addonPath = join(dir, `${nativeName}.node`)
    const native = { dir, module: require(addonPath) }
    assertNodePtyJobOwnership({ nativeName, native, addonPath })
    if (process.platform === 'darwin') {
      accessSync(join(dir, 'spawn-helper'), constants.X_OK)
    }
    if (nativeName === 'conpty') {
      for (const filename of NODE_PTY_CONPTY_RUNTIME_FILES) {
        if (!existsSync(join(dir, 'conpty', filename))) {
          throw new Error(
            `node-pty ConPTY runtime file is missing: ${join(dir, 'conpty', filename)}`
          )
        }
      }
    }
    return
  }
  if (moduleName === '@vscode/windows-process-tree') {
    assertWindowsProcessTreeCreationTime({
      module: require(join(dir, 'windows_process_tree.node'))
    })
    return
  }
  throw new Error(`no probe for ${moduleName}`)
}

if (require.main === module) {
  const [moduleName, dir] = process.argv.slice(2)
  try {
    probeNativeBuildDir(moduleName, dir)
  } catch (error) {
    console.error(`${moduleName}: ${error instanceof Error ? error.message : String(error)}`)
    process.exit(1)
  }
}

module.exports = { probeNativeBuildDir }