1- import type { KernelJson } from '@onkernel/sdk' ;
21import { Command } from 'commander' ;
32import fs from 'fs' ;
43import getPort from 'get-port' ;
54import os from 'os' ;
65import path from 'path' ;
6+ import type { KernelJson } from '../core/app-framework' ;
77import { packageApp } from './lib/package' ;
88import { getPackageVersion , isPnpmInstalled , isUvInstalled } from './lib/util' ;
99
@@ -13,29 +13,23 @@ const program = new Command();
1313// This is useful for local dev.
1414// KERNEL_NODE_SDK_OVERRIDE=/Users/rafaelgarcia/code/onkernel/kernel/packages/sdk-node
1515// KERNEL_NODE_SDK_OVERRIDE_VERSION=0.0.1alpha.1
16- const KERNEL_NODE_SDK_OVERRIDE = process . env . KERNEL_NODE_SDK_OVERRIDE || undefined ;
16+ const KERNEL_NODE_SDK_OVERRIDE = process . env [ ' KERNEL_NODE_SDK_OVERRIDE' ] || undefined ;
1717// Same for python...
1818// KERNEL_PYTHON_SDK_OVERRIDE=/Users/rafaelgarcia/code/onkernel/kernel/packages/sdk-python
1919// KERNEL_PYTHON_SDK_OVERRIDE_VERSION=0.0.1alpha.1
20- const KERNEL_PYTHON_SDK_OVERRIDE = process . env . KERNEL_PYTHON_SDK_OVERRIDE || undefined ;
20+ const KERNEL_PYTHON_SDK_OVERRIDE = process . env [ ' KERNEL_PYTHON_SDK_OVERRIDE' ] || undefined ;
2121
2222// Point to a local version of the boot loader or a specific version
23- const KERNEL_NODE_BOOT_LOADER_OVERRIDE = process . env . KERNEL_NODE_BOOT_LOADER_OVERRIDE ;
24- const KERNEL_PYTHON_BOOT_LOADER_OVERRIDE = process . env . KERNEL_PYTHON_BOOT_LOADER_OVERRIDE ;
23+ const KERNEL_NODE_BOOT_LOADER_OVERRIDE = process . env [ ' KERNEL_NODE_BOOT_LOADER_OVERRIDE' ] || undefined ;
24+ const KERNEL_PYTHON_BOOT_LOADER_OVERRIDE = process . env [ ' KERNEL_PYTHON_BOOT_LOADER_OVERRIDE' ] || undefined ;
2525
26- program
27- . name ( 'kernel' )
28- . description ( 'CLI for Kernel deployment and invocation' )
29- . version ( getPackageVersion ( ) ) ;
26+ program . name ( 'kernel' ) . description ( 'CLI for Kernel deployment and invocation' ) . version ( getPackageVersion ( ) ) ;
3027
3128program
3229 . command ( 'deploy' )
3330 . description ( 'Deploy a Kernel application' )
3431 . argument ( '<entrypoint>' , 'Path to entrypoint file (TypeScript or Python)' )
35- . option (
36- '--local' ,
37- 'Does not publish the app to Kernel, but installs it on disk for invoking locally' ,
38- )
32+ . option ( '--local' , 'Does not publish the app to Kernel, but installs it on disk for invoking locally' )
3933 . action ( async ( entrypoint , options ) => {
4034 const resolvedEntrypoint = path . resolve ( entrypoint ) ;
4135 if ( ! fs . existsSync ( resolvedEntrypoint ) ) {
@@ -48,12 +42,12 @@ program
4842 sourceDir : path . dirname ( resolvedEntrypoint ) , // TODO: handle nested entrypoint, i.e. ./src/entrypoint.ts
4943 entrypoint : resolvedEntrypoint ,
5044 sdkOverrides : {
51- node : KERNEL_NODE_SDK_OVERRIDE ,
52- python : KERNEL_PYTHON_SDK_OVERRIDE ,
45+ ... ( KERNEL_NODE_SDK_OVERRIDE && { node : KERNEL_NODE_SDK_OVERRIDE } ) ,
46+ ... ( KERNEL_PYTHON_SDK_OVERRIDE && { python : KERNEL_PYTHON_SDK_OVERRIDE } ) ,
5347 } ,
5448 bootLoaderOverrides : {
55- node : KERNEL_NODE_BOOT_LOADER_OVERRIDE ,
56- python : KERNEL_PYTHON_BOOT_LOADER_OVERRIDE ,
49+ ... ( KERNEL_NODE_BOOT_LOADER_OVERRIDE && { node : KERNEL_NODE_BOOT_LOADER_OVERRIDE } ) ,
50+ ... ( KERNEL_PYTHON_BOOT_LOADER_OVERRIDE && { python : KERNEL_PYTHON_BOOT_LOADER_OVERRIDE } ) ,
5751 } ,
5852 } ) ;
5953
@@ -109,25 +103,15 @@ program
109103 console . log ( JSON . stringify ( parsedPayload , null , 2 ) ) ;
110104
111105 // Get the app directory
112- const cacheFile = path . join (
113- os . homedir ( ) ,
114- '.local' ,
115- 'state' ,
116- 'kernel' ,
117- 'deploy' ,
118- 'local' ,
119- appName ,
120- ) ;
106+ const cacheFile = path . join ( os . homedir ( ) , '.local' , 'state' , 'kernel' , 'deploy' , 'local' , appName ) ;
121107 if ( ! fs . existsSync ( cacheFile ) ) {
122108 console . error ( `Error: App "${ appName } " local deployment not found. ` ) ;
123109 console . error ( 'Did you `kernel deploy --local <entrypoint>`?' ) ;
124110 process . exit ( 1 ) ;
125111 }
126112 const kernelLocalDir = fs . readFileSync ( cacheFile , 'utf8' ) . trim ( ) ;
127113 if ( ! fs . existsSync ( kernelLocalDir ) ) {
128- console . error (
129- `Error: App "${ appName } " local deployment has been corrupted, please re-deploy.` ,
130- ) ;
114+ console . error ( `Error: App "${ appName } " local deployment has been corrupted, please re-deploy.` ) ;
131115 process . exit ( 1 ) ;
132116 }
133117
@@ -176,10 +160,7 @@ async function waitForStartupMessage(
176160 const text = decoder . decode ( value ) ;
177161 process . stderr . write ( text ) ;
178162
179- if (
180- text . includes ( 'Application startup complete.' ) ||
181- text . includes ( 'Kernel application running' )
182- ) {
163+ if ( text . includes ( 'Application startup complete.' ) || text . includes ( 'Kernel application running' ) ) {
183164 clearTimeout ( timeout ) ;
184165 resolve ( ) ;
185166 break ;
@@ -201,12 +182,7 @@ type InvokeLocalOptions = {
201182/**
202183 * Invokes a locally deployed Python app action
203184 */
204- async function invokeLocalPython ( {
205- kernelLocalDir,
206- appName,
207- actionName,
208- parsedPayload,
209- } : InvokeLocalOptions ) {
185+ async function invokeLocalPython ( { kernelLocalDir, appName, actionName, parsedPayload } : InvokeLocalOptions ) {
210186 const uvInstalled = await isUvInstalled ( ) ;
211187 if ( ! uvInstalled ) {
212188 console . error ( 'Error: uv is not installed. Please install it with:' ) ;
@@ -254,12 +230,7 @@ async function invokeLocalPython({
254230/**
255231 * Invokes a locally deployed TypeScript app action
256232 */
257- async function invokeLocalNode ( {
258- kernelLocalDir,
259- appName,
260- actionName,
261- parsedPayload,
262- } : InvokeLocalOptions ) {
233+ async function invokeLocalNode ( { kernelLocalDir, appName, actionName, parsedPayload } : InvokeLocalOptions ) {
263234 const pnpmInstalled = await isPnpmInstalled ( ) ;
264235 if ( ! pnpmInstalled ) {
265236 console . error ( 'Error: pnpm is not installed. Please install it with:' ) ;
@@ -279,15 +250,7 @@ async function invokeLocalNode({
279250 // Find an available port and start the boot loader
280251 const port = await getPort ( ) ;
281252 const tsProcess = Bun . spawn (
282- [
283- 'pnpm' ,
284- 'exec' ,
285- 'tsx' ,
286- 'index.ts' ,
287- '--port' ,
288- port . toString ( ) ,
289- path . join ( kernelLocalDir , 'app' ) ,
290- ] ,
253+ [ 'pnpm' , 'exec' , 'tsx' , 'index.ts' , '--port' , port . toString ( ) , path . join ( kernelLocalDir , 'app' ) ] ,
291254 {
292255 cwd : kernelLocalDir ,
293256 stdio : [ 'inherit' , 'inherit' , 'pipe' ] ,
0 commit comments