mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 00:02:31 +00:00
* Revert "fix(terminal): add proportional scroll fallback for sidebar resize" (#937) * fix(sidebar): smoothly animate off-screen worktree reveal on click (#1302) Clicking a worktree card whose row lies outside the sidebar viewport caused an instant jump when scrolling it into view. Switching `scrollToIndex` to `behavior: 'smooth'` turns that minimum-distance scroll into an animated slide while keeping `align: 'auto'` so visible cards still no-op (no re-centering). Co-authored-by: Orca <help@stably.ai> * Avoid local scrollback serialization on shutdown (#1821) * Fix PR refresh coordinator test arguments (#2545) * release: v1.4.31 * release: v1.4.31 * release: v1.4.31 * release: v1.4.31 * release: v1.4.31 * release: v1.4.31 * release: v1.4.31 * release: v1.4.36-rc.6 * release: v1.4.36-rc.6 * release: v1.4.36-rc.6 * ci: gate release-cut to the canonical repo so it skips forks (#4815) The cut job checks out main, bumps package.json's version, and fast-forwards main. On a fork with Actions enabled, the scheduled RC cut runs against the fork's main and diverges it on the version line every slot, so that contributor's PRs back to upstream conflict on package.json even when their change never touches it. Gate the job to github.repository == 'stablyai/orca' so it (and the jobs that depend on it) no-op on forks. Canonical scheduled and manual cuts are unaffected. * feat(hooks): install Devin managed status hooks * feat(devin): address hook review, resume, and UI polish - Parse Devin config.json as JSONC; warn on read_config_from overlap - Windows hook command uses forward slashes; APPDATA fallback - Add devin to sleeping-agent resume and UI registries (plan 003/004) - Add hook-service and hook-config-json tests Closes follow-up for plans 002–004 on feat/add-devin-agent. * feat(devin): scan ATIF transcripts for AI Vault Register devin in AI_VAULT_AGENTS, discover ~/.local/share/devin/cli/transcripts (or DEVIN_HOME), parse ATIF JSON sessions, and build devin --resume commands. * docs(devin): clarify stdin-after-start vs bracketed paste * fix(devin): use JSONC for remote install, add partial+APPDATA tests - installRemote: replace readHooksJsonRemote (JSON.parse) with readTextFileRemote + parseJsonc for JSONC compatibility on SSH - Add partial status test (some hooks missing → state:'partial') - Add Windows APPDATA config path test with fallback * fix(devin): address CodeRabbit review — sessionId fallback, parseJsonc errors, comment, i18n * Fix Devin integration edge cases Co-authored-by: Orca <help@stably.ai> * Package Devin JSONC parser dependency Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com> Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Co-authored-by: Orca <help@stably.ai> Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Trevin Chow <trevin@trevinchow.com> Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
358 lines
12 KiB
JavaScript
358 lines
12 KiB
JavaScript
const { existsSync, readFileSync, readdirSync, realpathSync, rmSync } = require('node:fs')
|
|
const { dirname, join, resolve } = require('node:path')
|
|
const { builtinModules, createRequire } = require('node:module')
|
|
|
|
const projectDir = resolve(__dirname, '..')
|
|
const requireFromProject = createRequire(join(projectDir, 'package.json'))
|
|
|
|
const PACKAGED_RUNTIME_PACKAGE_ROOTS = [
|
|
'@electron-toolkit/utils',
|
|
'@linear/sdk',
|
|
'@parcel/watcher',
|
|
'electron-updater',
|
|
'i18next',
|
|
'jsonc-parser',
|
|
'node-pty',
|
|
'posthog-node',
|
|
// serve-sim (for CLI JS entry + closure + state/middleware + to make packaged require('serve-sim') + its internal relatives work; mirrors other runtime JS like ws/yaml/zod. Natives/dylibs still via extraResources + the node_modules/serve-sim copy in resources from builder. Client if added too.
|
|
'serve-sim',
|
|
'qrcode',
|
|
'ssh2',
|
|
'tweetnacl',
|
|
'ws',
|
|
'yaml',
|
|
'zod'
|
|
]
|
|
|
|
const NODE_PTY_PREBUILD_PREFIX_BY_PLATFORM = {
|
|
darwin: 'darwin-',
|
|
linux: 'linux-',
|
|
win32: 'win32-'
|
|
}
|
|
const PARCEL_WATCHER_PLATFORM_PREFIX_BY_PLATFORM = {
|
|
darwin: 'watcher-darwin',
|
|
linux: 'watcher-linux',
|
|
win32: 'watcher-win32'
|
|
}
|
|
const TYPE_DECLARATION_ARTIFACT_RE = /\.d\.(?:c|m)?ts(?:\.map)?$/
|
|
const VERSIONED_ONNXRUNTIME_DYLIB_RE = /^libonnxruntime\.\d[\d.]*\.dylib$/
|
|
|
|
const NODE_BUILTINS = new Set([
|
|
...builtinModules,
|
|
...builtinModules.map((moduleName) => `node:${moduleName}`)
|
|
])
|
|
|
|
function packageNameFromSpecifier(specifier) {
|
|
if (specifier.startsWith('@')) {
|
|
const [scope, name] = specifier.split('/')
|
|
return scope && name ? `${scope}/${name}` : specifier
|
|
}
|
|
return specifier.split('/')[0]
|
|
}
|
|
|
|
function isPackagedExternalSpecifier(specifier) {
|
|
return (
|
|
!specifier.startsWith('.') &&
|
|
!specifier.startsWith('/') &&
|
|
specifier !== 'electron' &&
|
|
!NODE_BUILTINS.has(specifier)
|
|
)
|
|
}
|
|
|
|
function resolvePackageJsonPath(packageName, fromDir = projectDir) {
|
|
const nested = join(fromDir, 'node_modules', packageName, 'package.json')
|
|
if (existsSync(nested)) {
|
|
return nested
|
|
}
|
|
// Why: published serve-sim has no "." export (only ./middleware and ./state), so
|
|
// require.resolve('serve-sim') fails even though the package is present for bridge exec.
|
|
if (packageName === 'serve-sim') {
|
|
const direct = join(projectDir, 'node_modules', 'serve-sim', 'package.json')
|
|
if (existsSync(direct)) {
|
|
return direct
|
|
}
|
|
}
|
|
try {
|
|
return requireFromProject.resolve(`${packageName}/package.json`, { paths: [fromDir] })
|
|
} catch {
|
|
let entryPath
|
|
try {
|
|
entryPath = requireFromProject.resolve(packageName, { paths: [fromDir] })
|
|
} catch {
|
|
throw new Error(`Could not resolve package ${packageName} from ${fromDir}`)
|
|
}
|
|
let dir = dirname(entryPath)
|
|
while (dir !== dirname(dir)) {
|
|
const packageJsonPath = join(dir, 'package.json')
|
|
if (existsSync(packageJsonPath)) {
|
|
return packageJsonPath
|
|
}
|
|
dir = dirname(dir)
|
|
}
|
|
throw new Error(`Could not find package.json for ${packageName}`)
|
|
}
|
|
}
|
|
|
|
function readPackage(packageName, fromDir = projectDir) {
|
|
const packageJsonPath = resolvePackageJsonPath(packageName, fromDir)
|
|
const packageDir = realpathSync(dirname(packageJsonPath))
|
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
|
|
return {
|
|
name: packageJson.name ?? packageName,
|
|
packageDir,
|
|
dependencies: Object.keys(packageJson.dependencies ?? {})
|
|
}
|
|
}
|
|
|
|
function isKnownOmittedServeSimDependency(packageName, fromDir) {
|
|
if (packageName !== 'inspect-webkit') {
|
|
return false
|
|
}
|
|
const serveSimPackageJsonPath = join(projectDir, 'node_modules', 'serve-sim', 'package.json')
|
|
if (!existsSync(serveSimPackageJsonPath)) {
|
|
return false
|
|
}
|
|
try {
|
|
return realpathSync(fromDir) === realpathSync(dirname(serveSimPackageJsonPath))
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
function collectPackagedRuntimePackages() {
|
|
const packages = new Map()
|
|
const visit = (packageName, fromDir = projectDir) => {
|
|
if (packageName === 'electron' || packages.has(packageName)) {
|
|
return
|
|
}
|
|
|
|
let packageInfo
|
|
try {
|
|
packageInfo = readPackage(packageName, fromDir)
|
|
} catch (error) {
|
|
// Why: serve-sim declares inspect-webkit, but current installs omit it.
|
|
// Keep that escape hatch narrow so broken packages still fail packaging.
|
|
if (isKnownOmittedServeSimDependency(packageName, fromDir)) {
|
|
return
|
|
}
|
|
throw error
|
|
}
|
|
if (packages.has(packageInfo.name)) {
|
|
return
|
|
}
|
|
packages.set(packageInfo.name, packageInfo.packageDir)
|
|
|
|
for (const dependencyName of packageInfo.dependencies) {
|
|
visit(dependencyName, packageInfo.packageDir)
|
|
}
|
|
}
|
|
|
|
for (const packageName of PACKAGED_RUNTIME_PACKAGE_ROOTS) {
|
|
visit(packageName)
|
|
}
|
|
|
|
// Why: @parcel/watcher loads its native .node addon from a platform-specific
|
|
// optionalDependency (e.g. @parcel/watcher-linux-x64-glibc) that the
|
|
// dependencies graph above never reaches. Include the ones installed for the
|
|
// build's supported architectures; afterPack pruning trims non-target
|
|
// platforms. Without this the packaged main bundle's import of
|
|
// '@parcel/watcher' resolves at runtime but throws loading its binary.
|
|
const parcelWatcherDir = packages.get('@parcel/watcher')
|
|
if (parcelWatcherDir) {
|
|
const parcelWatcherPackage = JSON.parse(
|
|
readFileSync(join(parcelWatcherDir, 'package.json'), 'utf8')
|
|
)
|
|
for (const optionalName of Object.keys(parcelWatcherPackage.optionalDependencies ?? {})) {
|
|
try {
|
|
visit(optionalName)
|
|
} catch {
|
|
// Optional platform subpackage is not installed for this build; skip it.
|
|
}
|
|
}
|
|
}
|
|
|
|
return [...packages.entries()].sort(([left], [right]) => left.localeCompare(right))
|
|
}
|
|
|
|
function createPackagedRuntimeNodeModuleResources() {
|
|
return collectPackagedRuntimePackages().map(([packageName, packageDir]) => ({
|
|
from: packageDir,
|
|
to: join('node_modules', ...packageName.split('/'))
|
|
}))
|
|
}
|
|
|
|
function normalizeAsarEntryPath(entry) {
|
|
return entry.replace(/\\/g, '/').replace(/^\/+/, '')
|
|
}
|
|
|
|
function findAsarEntry(entries, expectedPath) {
|
|
return entries.find((entry) => normalizeAsarEntryPath(entry) === expectedPath)
|
|
}
|
|
|
|
function verifyPackagedMainRuntimeDeps(resourcesDir, asar = require('@electron/asar')) {
|
|
const asarPath = join(resourcesDir, 'app.asar')
|
|
if (!existsSync(asarPath)) {
|
|
return
|
|
}
|
|
|
|
const mainFiles = ['out/main/index.js', 'out/main/agent-hooks/managed-agent-hook-controls.js']
|
|
const entries = asar.listPackage(asarPath)
|
|
const missing = new Set()
|
|
|
|
for (const file of mainFiles) {
|
|
const entry = findAsarEntry(entries, file)
|
|
if (!entry) {
|
|
throw new Error(`Packaged main file ${file} was not found in ${asarPath}`)
|
|
}
|
|
|
|
// Why: @electron/asar lists entries with host separators; Windows returns
|
|
// backslashes, and extractFile expects that same host-style path.
|
|
const internalPath = entry.replace(/^[\\/]+/, '')
|
|
const source = asar.extractFile(asarPath, internalPath).toString('utf8')
|
|
for (const match of source.matchAll(/require\(["']([^"']+)["']\)/g)) {
|
|
const specifier = match[1]
|
|
if (!isPackagedExternalSpecifier(specifier)) {
|
|
continue
|
|
}
|
|
const packageName = packageNameFromSpecifier(specifier)
|
|
if (!existsSync(join(resourcesDir, 'node_modules', ...packageName.split('/')))) {
|
|
missing.add(packageName)
|
|
}
|
|
}
|
|
}
|
|
|
|
if (missing.size > 0) {
|
|
throw new Error(
|
|
`Packaged main bundle has bare runtime imports without copied node_modules: ${[
|
|
...missing
|
|
].join(', ')}`
|
|
)
|
|
}
|
|
}
|
|
|
|
function prunePackagedNodePty(resourcesDir, electronPlatformName) {
|
|
const nodePtyDir = join(resourcesDir, 'node_modules', 'node-pty')
|
|
if (!existsSync(nodePtyDir)) {
|
|
return
|
|
}
|
|
|
|
const allowedPrebuildPrefix = NODE_PTY_PREBUILD_PREFIX_BY_PLATFORM[electronPlatformName]
|
|
if (allowedPrebuildPrefix) {
|
|
const prebuildsDir = join(nodePtyDir, 'prebuilds')
|
|
if (existsSync(prebuildsDir)) {
|
|
for (const entry of readdirSync(prebuildsDir, { withFileTypes: true })) {
|
|
if (entry.isDirectory() && !entry.name.startsWith(allowedPrebuildPrefix)) {
|
|
rmSync(join(prebuildsDir, entry.name), { recursive: true, force: true })
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (electronPlatformName !== 'win32') {
|
|
// Why: conpty is Windows-only and node-pty resolves runtime binaries from
|
|
// build/Release or prebuilds/<platform>-<arch>, not third_party/conpty.
|
|
rmSync(join(nodePtyDir, 'third_party', 'conpty'), { recursive: true, force: true })
|
|
rmSync(join(nodePtyDir, 'deps', 'winpty'), { recursive: true, force: true })
|
|
}
|
|
}
|
|
|
|
function prunePackagedParcelWatcher(resourcesDir, electronPlatformName) {
|
|
const parcelDir = join(resourcesDir, 'node_modules', '@parcel')
|
|
if (!existsSync(parcelDir)) {
|
|
return
|
|
}
|
|
|
|
// Why: we package every installed @parcel/watcher-<platform> optional
|
|
// subpackage (supportedArchitectures fetches all), but each build only needs
|
|
// its own platform's binary. Keep the core package and the matching platform
|
|
// subpackages; drop the rest so a Linux serve doesn't ship macOS/Windows .node.
|
|
const keepPrefix = PARCEL_WATCHER_PLATFORM_PREFIX_BY_PLATFORM[electronPlatformName]
|
|
for (const entry of readdirSync(parcelDir, { withFileTypes: true })) {
|
|
if (!entry.isDirectory() || entry.name === 'watcher') {
|
|
continue
|
|
}
|
|
// Why: only ever prune the watcher's own platform subpackages. Guards against
|
|
// nuking an unrelated @parcel/* runtime dep if one is added to the roots later.
|
|
if (!entry.name.startsWith('watcher-')) {
|
|
continue
|
|
}
|
|
if (keepPrefix && entry.name.startsWith(keepPrefix)) {
|
|
continue
|
|
}
|
|
rmSync(join(parcelDir, entry.name), { recursive: true, force: true })
|
|
}
|
|
}
|
|
|
|
function prunePackagedRuntimeTypeDeclarations(resourcesDir) {
|
|
const nodeModulesDir = join(resourcesDir, 'node_modules')
|
|
if (!existsSync(nodeModulesDir)) {
|
|
return
|
|
}
|
|
pruneMatchingFiles(nodeModulesDir, (filename) => TYPE_DECLARATION_ARTIFACT_RE.test(filename))
|
|
}
|
|
|
|
function prunePackagedSherpaOnnx(resourcesDir, electronPlatformName) {
|
|
if (electronPlatformName !== 'darwin') {
|
|
return
|
|
}
|
|
const nodeModulesDir = join(resourcesDir, 'node_modules')
|
|
if (!existsSync(nodeModulesDir)) {
|
|
return
|
|
}
|
|
for (const entry of readdirSync(nodeModulesDir, { withFileTypes: true })) {
|
|
if (!entry.isDirectory() || !entry.name.startsWith('sherpa-onnx-darwin-')) {
|
|
continue
|
|
}
|
|
const packageDir = join(nodeModulesDir, entry.name)
|
|
const packageEntries = readdirSync(packageDir)
|
|
const hasVersionedOnnxRuntime = packageEntries.some((filename) =>
|
|
VERSIONED_ONNXRUNTIME_DYLIB_RE.test(filename)
|
|
)
|
|
if (hasVersionedOnnxRuntime) {
|
|
// Why: darwin sherpa-onnx binaries link to the versioned ONNX Runtime
|
|
// install name; the unversioned dylib is a duplicate fallback copy.
|
|
rmSync(join(packageDir, 'libonnxruntime.dylib'), { force: true })
|
|
}
|
|
}
|
|
}
|
|
|
|
function prunePackagedZodSources(resourcesDir) {
|
|
// Why: Zod's src tree is TypeScript source only selected by the @zod/source
|
|
// condition; packaged runtime import/require paths resolve to built JS.
|
|
rmSync(join(resourcesDir, 'node_modules', 'zod', 'src'), { recursive: true, force: true })
|
|
}
|
|
|
|
function prunePackagedRuntimeNodeModules(resourcesDir, electronPlatformName) {
|
|
prunePackagedNodePty(resourcesDir, electronPlatformName)
|
|
prunePackagedParcelWatcher(resourcesDir, electronPlatformName)
|
|
prunePackagedRuntimeTypeDeclarations(resourcesDir)
|
|
prunePackagedSherpaOnnx(resourcesDir, electronPlatformName)
|
|
prunePackagedZodSources(resourcesDir)
|
|
}
|
|
|
|
function pruneMatchingFiles(directory, shouldPrune) {
|
|
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
const entryPath = join(directory, entry.name)
|
|
if (entry.isDirectory()) {
|
|
pruneMatchingFiles(entryPath, shouldPrune)
|
|
} else if (entry.isFile() && shouldPrune(entry.name)) {
|
|
rmSync(entryPath, { force: true })
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
PACKAGED_RUNTIME_PACKAGE_ROOTS,
|
|
createPackagedRuntimeNodeModuleResources,
|
|
findAsarEntry,
|
|
isPackagedExternalSpecifier,
|
|
packageNameFromSpecifier,
|
|
prunePackagedNodePty,
|
|
prunePackagedParcelWatcher,
|
|
prunePackagedRuntimeNodeModules,
|
|
prunePackagedSherpaOnnx,
|
|
prunePackagedRuntimeTypeDeclarations,
|
|
prunePackagedZodSources,
|
|
verifyPackagedMainRuntimeDeps
|
|
}
|