Skip to content

Commit 1b043a5

Browse files
authored
Add remaining elements for create kernel app (#48)
This PR competes the remaining work for [KERNEL-374](https://linear.app/onkernel/issue/KERNEL-374/port-create-kernel-app-to-the-kernel-cli) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Implements the `kernel create` flow with template selection and overwrite prompts, adds deploy/invoke guidance per template, expands tests, and updates README docs. > > - **Create CLI**: > - Implement `kernel create` with `create.CreateInput` type, interactive prompts, and overwrite confirmation via `PromptForOverwrite`. > - Copies template files with spinner feedback; handles existing dirs by optional removal. > - Refactor install flow: `InstallDependencies(appPath, CreateInput)`; prints tailored next steps on failure/missing tools. > - **Templates & Commands**: > - Add template key constants and `Templates` map; provide `GetDeployCommand` and `GetInvokeSample` via new `Commands` matrix per language/template. > - Normalize language shorthands; expose supported templates per language. > - **Tests**: > - Major expansion: creation flow, dependency failure/missing tool paths, overwrite behavior, permissions, invalid combos, shorthands, and template coverage (`pkg/create/copy_test.go`, updates to `cmd/create_test.go`). > - **Docs**: > - README: add app creation to capabilities, reorder Quick Start (create → login → deploy → invoke), document create flags/templates, and add create examples. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 83f218a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 1bc8095 commit 1b043a5

File tree

8 files changed

+769
-45
lines changed

8 files changed

+769
-45
lines changed

README.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Kernel provides sandboxed, ready-to-use Chrome browsers for browser automations
2121

2222
### What you can do with the CLI
2323

24+
- Create new Kernel applications from templates
2425
- Deploy and version apps to Kernel
2526
- Invoke app actions (sync or async) and stream logs
2627
- Create, list, view, and delete managed browser sessions
@@ -50,19 +51,25 @@ kernel --version
5051

5152
## Quick Start
5253

53-
1. **Authenticate with Kernel:**
54+
1. **Create a new Kernel app:**
55+
56+
```bash
57+
kernel create
58+
```
59+
60+
2. **Authenticate with Kernel:**
5461

5562
```bash
5663
kernel login
5764
```
5865

59-
2. **Deploy your first app:**
66+
3. **Deploy your app:**
6067

6168
```bash
6269
kernel deploy index.ts
6370
```
6471

65-
3. **Invoke your app:**
72+
4. **Invoke your app:**
6673
```bash
6774
kernel invoke my-app action-name --payload '{"key": "value"}'
6875
```
@@ -103,6 +110,20 @@ Create an API key from the [Kernel dashboard](https://dashboard.onkernel.com).
103110
- `kernel logout` - Clear stored credentials
104111
- `kernel auth` - Check authentication status
105112

113+
### App Creation
114+
115+
- `--name <name>`, `-n` - Name of the application
116+
- `--language <language>`, `-l` - Sepecify app language: `typescript`, or `python`
117+
- `--template <template>`, `-t` - Template to use:
118+
- `sample-app` - Basic template with Playwright integration
119+
- `advanced-sample` - Sample apps using advanced Kernel configs
120+
- `stagehand` - Template with Stagehand SDK (TypeScript only)
121+
- `browser-use` - Template with Browser Use SDK (Python only)
122+
- `computer-use` - Anthropic Computer Use prompt loop
123+
- `cua` - OpenAI Computer Using Agent (CUA) sample
124+
- `gemini-cua` - Google Gemini CUA sample (TypeScript only)
125+
- `magnitude` - Magnitude framework sample (TypeScript only)
126+
106127
### App Deployment
107128

108129
- `kernel deploy <file>` - Deploy an app to Kernel
@@ -356,6 +377,25 @@ Create an API key from the [Kernel dashboard](https://dashboard.onkernel.com).
356377

357378
## Examples
358379

380+
### Create a new app
381+
382+
```bash
383+
# Interactive mode (prompts for all options)
384+
kernel create
385+
386+
# Create a TypeScript app with sample template
387+
kernel create --name my-app --language typescript --template sample-app
388+
389+
# Create a Python app with Browser Use
390+
kernel create --name my-scraper --language python --template browser-use
391+
392+
# Create a TypeScript app with Stagehand
393+
kernel create --name my-agent --language ts --template stagehand
394+
395+
# Create a Python Computer Use app
396+
kernel create --name my-cu-app --language py --template computer-use
397+
```
398+
359399
### Deploy with environment variables
360400

361401
```bash

cmd/create.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,32 @@ import (
1111
"github.com/spf13/cobra"
1212
)
1313

14-
type CreateInput struct {
15-
Name string
16-
Language string
17-
Template string
18-
}
19-
2014
// CreateCmd is a cobra-independent command handler for create operations
2115
type CreateCmd struct{}
2216

2317
// Create executes the creating a new Kernel app logic
24-
func (c CreateCmd) Create(ctx context.Context, ci CreateInput) error {
18+
func (c CreateCmd) Create(ctx context.Context, ci create.CreateInput) error {
2519
appPath, err := filepath.Abs(ci.Name)
2620
if err != nil {
2721
return fmt.Errorf("failed to resolve app path: %w", err)
2822
}
2923

30-
// TODO: handle overwrite gracefully (prompt user)
31-
// Check if directory already exists
24+
// Check if directory already exists and prompt for overwrite
3225
if _, err := os.Stat(appPath); err == nil {
33-
return fmt.Errorf("directory %s already exists", ci.Name)
26+
overwrite, err := create.PromptForOverwrite(ci.Name)
27+
if err != nil {
28+
return fmt.Errorf("failed to prompt for overwrite: %w", err)
29+
}
30+
31+
if !overwrite {
32+
pterm.Warning.Println("Operation cancelled.")
33+
return nil
34+
}
35+
36+
// Remove existing directory
37+
if err := os.RemoveAll(appPath); err != nil {
38+
return fmt.Errorf("failed to remove existing directory: %w", err)
39+
}
3440
}
3541

3642
if err := os.MkdirAll(appPath, 0755); err != nil {
@@ -45,8 +51,9 @@ func (c CreateCmd) Create(ctx context.Context, ci CreateInput) error {
4551
spinner.Fail("Failed to copy template files")
4652
return fmt.Errorf("failed to copy template files: %w", err)
4753
}
54+
spinner.Success()
4855

49-
nextSteps, err := create.InstallDependencies(ci.Name, appPath, ci.Language)
56+
nextSteps, err := create.InstallDependencies(appPath, ci)
5057
if err != nil {
5158
return fmt.Errorf("failed to install dependencies: %w", err)
5259
}
@@ -91,7 +98,7 @@ func runCreateApp(cmd *cobra.Command, args []string) error {
9198
}
9299

93100
c := CreateCmd{}
94-
return c.Create(cmd.Context(), CreateInput{
101+
return c.Create(cmd.Context(), create.CreateInput{
95102
Name: appName,
96103
Language: language,
97104
Template: template,

0 commit comments

Comments
 (0)