Documentation
¶
Index ¶
- Constants
- Variables
- func CopyTemplateFiles(appPath, language, template string) error
- func GetDeployCommand(language, template string) string
- func GetInvokeSample(language, template string) string
- func InstallDependencies(appPath string, ci CreateInput) (string, error)
- func LanguageShorthand(language string) string
- func NormalizeLanguage(language string) string
- func ProblemMessages(problems []Problem) []string
- func PromptLanguage(p interactive.Prompter) (string, error)
- func PromptName(p interactive.Prompter) (string, error)
- func PromptOverwrite(p interactive.Prompter, dirName string) (bool, error)
- func PromptTemplate(p interactive.Prompter, language string) (string, error)
- func ResolveInput(raw RawInput) (CreateInput, []Problem)
- type CreateInput
- type DeployConfig
- type Field
- type Problem
- type RawInput
- type TemplateInfo
- type TemplateKeyValue
- type TemplateKeyValues
- type Tools
Constants ¶
const ( DIR_PERM = 0755 // rwxr-xr-x FILE_PERM = 0644 // rw-r--r-- )
const ( TemplateSampleApp = "sample-app" TemplateCaptchaSolver = "captcha-solver" TemplateAnthropicComputerUse = "anthropic-computer-use" TemplateOpenAIComputerUse = "openai-computer-use" TemplateMagnitude = "magnitude" TemplateGeminiComputerUse = "gemini-computer-use" TemplateBrowserUse = "browser-use" TemplateStagehand = "stagehand" TemplateOpenAGIComputerUse = "openagi-computer-use" TemplateClaudeAgentSDK = "claude-agent-sdk" TemplateYutoriComputerUse = "yutori" TemplateTzafonComputerUse = "tzafon" )
Template key constants
const ( DefaultAppName = "my-kernel-app" AppNamePrompt = "What is the name of your project?" LanguagePrompt = "Choose a programming language:" TemplatePrompt = "Select a template:" )
const ( LanguageTypeScript = "typescript" LanguagePython = "python" LanguageShorthandTypeScript = "ts" LanguageShorthandPython = "py" )
Variables ¶
var Commands = map[string]map[string]DeployConfig{ LanguageTypeScript: { TemplateSampleApp: { EntryPoint: "index.ts", NeedsEnvFile: false, InvokeCommand: `kernel invoke ts-basic get-page-title --payload '{"url": "https://www.google.com"}'`, }, TemplateCaptchaSolver: { EntryPoint: "index.ts", NeedsEnvFile: false, InvokeCommand: "kernel invoke ts-captcha-solver test-captcha-solver", }, TemplateStagehand: { EntryPoint: "index.ts", NeedsEnvFile: true, InvokeCommand: `kernel invoke ts-stagehand teamsize-task --payload '{"company": "Kernel"}'`, }, TemplateAnthropicComputerUse: { EntryPoint: "index.ts", NeedsEnvFile: true, InvokeCommand: `kernel invoke ts-anthropic-cua cua-task --payload '{"query": "Navigate to http://magnitasks.com and click on Tasks in the sidebar"}'`, }, TemplateMagnitude: { EntryPoint: "index.ts", NeedsEnvFile: true, InvokeCommand: `kernel invoke ts-magnitude mag-url-extract --payload '{"url": "https://en.wikipedia.org/wiki/Special:Random"}'`, }, TemplateOpenAIComputerUse: { EntryPoint: "index.ts", NeedsEnvFile: true, InvokeCommand: `kernel invoke ts-openai-cua cua-task --payload '{"task": "Go to https://news.ycombinator.com and get the top 5 articles"}'`, }, TemplateGeminiComputerUse: { EntryPoint: "index.ts", NeedsEnvFile: true, InvokeCommand: `kernel invoke ts-gemini-cua cua-task --payload '{"query": "Navigate to http://magnitasks.com and click on Tasks in the sidebar"}'`, }, TemplateClaudeAgentSDK: { EntryPoint: "index.ts", NeedsEnvFile: true, InvokeCommand: `kernel invoke ts-claude-agent-sdk agent-task --payload '{"task": "Go to https://news.ycombinator.com and get the top 3 stories"}'`, }, TemplateYutoriComputerUse: { EntryPoint: "index.ts", NeedsEnvFile: true, InvokeCommand: `kernel invoke ts-yutori-cua cua-task --payload '{"query": "Navigate to https://www.yutori.com and list the team member names."}'`, }, TemplateTzafonComputerUse: { EntryPoint: "index.ts", NeedsEnvFile: true, InvokeCommand: `kernel invoke ts-tzafon-cua cua-task --payload '{"query": "Go to wikipedia.org and search for Alan Turing"}'`, }, }, LanguagePython: { TemplateSampleApp: { EntryPoint: "main.py", NeedsEnvFile: false, InvokeCommand: `kernel invoke python-basic get-page-title --payload '{"url": "https://www.google.com"}'`, }, TemplateCaptchaSolver: { EntryPoint: "main.py", NeedsEnvFile: false, InvokeCommand: "kernel invoke python-captcha-solver test-captcha-solver", }, TemplateBrowserUse: { EntryPoint: "main.py", NeedsEnvFile: true, InvokeCommand: `kernel invoke python-bu bu-task --payload '{"task": "Compare the price of gpt-4o and DeepSeek-V3"}'`, }, TemplateAnthropicComputerUse: { EntryPoint: "main.py", NeedsEnvFile: true, InvokeCommand: `kernel invoke python-anthropic-cua cua-task --payload '{"query": "Navigate to http://magnitasks.com and click on Tasks in the sidebar"}'`, }, TemplateOpenAIComputerUse: { EntryPoint: "main.py", NeedsEnvFile: true, InvokeCommand: `kernel invoke python-openai-cua cua-task --payload '{"task": "Go to https://news.ycombinator.com and get the top 5 articles"}'`, }, TemplateOpenAGIComputerUse: { EntryPoint: "main.py", NeedsEnvFile: true, InvokeCommand: `kernel invoke python-openagi-cua openagi-default-task -p '{"instruction": "Navigate to https://agiopen.org and click the What is Computer Use? button", "record_replay": "True"}'`, }, TemplateClaudeAgentSDK: { EntryPoint: "main.py", NeedsEnvFile: true, InvokeCommand: `kernel invoke py-claude-agent-sdk agent-task --payload '{"task": "Go to https://news.ycombinator.com and get the top 3 stories"}'`, }, TemplateGeminiComputerUse: { EntryPoint: "main.py", NeedsEnvFile: true, InvokeCommand: `kernel invoke python-gemini-cua cua-task --payload '{"query": "Navigate to http://magnitasks.com and click on Tasks in the sidebar"}'`, }, TemplateYutoriComputerUse: { EntryPoint: "main.py", NeedsEnvFile: true, InvokeCommand: `kernel invoke python-yutori-cua cua-task --payload '{"query": "Navigate to https://www.yutori.com and list the team member names."}'`, }, TemplateTzafonComputerUse: { EntryPoint: "main.py", NeedsEnvFile: true, InvokeCommand: `kernel invoke python-tzafon-cua cua-task --payload '{"query": "Go to wikipedia.org and search for Alan Turing"}'`, }, }, }
var InstallCommands = map[string]string{ LanguageTypeScript: "pnpm install", LanguagePython: "uv venv", }
var RequiredTools = Tools{ LanguageTypeScript: "pnpm", LanguagePython: "uv", }
var SupportedLanguages = []string{ LanguageTypeScript, LanguagePython, }
SupportedLanguages returns a list of all supported languages
var Templates = map[string]TemplateInfo{ TemplateSampleApp: { Name: "Sample App", Description: "Implements a basic Kernel app", Languages: []string{LanguageTypeScript, LanguagePython}, }, TemplateCaptchaSolver: { Name: "CAPTCHA Solver", Description: "Demo of Kernel's auto-CAPTCHA solving capability", Languages: []string{LanguageTypeScript, LanguagePython}, }, TemplateAnthropicComputerUse: { Name: "Anthropic Computer Use", Description: "Implements an Anthropic computer use agent", Languages: []string{LanguageTypeScript, LanguagePython}, }, TemplateOpenAIComputerUse: { Name: "OpenAI Computer Use", Description: "Implements an OpenAI computer use agent", Languages: []string{LanguageTypeScript, LanguagePython}, }, TemplateMagnitude: { Name: "Magnitude", Description: "Implements the Magnitude.run SDK", Languages: []string{LanguageTypeScript}, }, TemplateGeminiComputerUse: { Name: "Gemini Computer Use", Description: "Implements a Gemini computer use agent", Languages: []string{LanguageTypeScript, LanguagePython}, }, TemplateBrowserUse: { Name: "Browser Use", Description: "Implements Browser Use SDK", Languages: []string{LanguagePython}, }, TemplateStagehand: { Name: "Stagehand", Description: "Implements the Stagehand v3 SDK", Languages: []string{LanguageTypeScript}, }, TemplateOpenAGIComputerUse: { Name: "OpenAGI Computer Use", Description: "Implements an OpenAGI computer use agent", Languages: []string{LanguagePython}, }, TemplateClaudeAgentSDK: { Name: "Claude Agent SDK", Description: "Implements a Claude Agent SDK browser automation agent", Languages: []string{LanguageTypeScript, LanguagePython}, }, TemplateYutoriComputerUse: { Name: "Yutori n1.5 Computer Use", Description: "Implements a Yutori n1.5 computer use agent", Languages: []string{LanguageTypeScript, LanguagePython}, }, TemplateTzafonComputerUse: { Name: "Tzafon Northstar Computer Use", Description: "Implements a Tzafon Northstar CUA Fast computer use agent", Languages: []string{LanguageTypeScript, LanguagePython}, }, }
Functions ¶
func CopyTemplateFiles ¶
CopyTemplateFiles copies all files and directories from the specified embedded template into the target application path. It uses the given language and template names to locate the template inside the embedded filesystem.
- appPath: filesystem path where the files should be written (the project directory)
- language: language subdirectory (e.g., "typescript")
- template: template subdirectory (e.g., "sample-app")
The function will recursively walk through the embedded template directory and replicate all files and folders in appPath. If a file named "_gitignore" is encountered, it is renamed to ".gitignore" in the output, to work around file embedding limitations.
Returns an error if the template path is invalid, empty, or if any file operations fail.
func GetDeployCommand ¶
GetDeployCommand returns the full deploy command string for a given language and template
func GetInvokeSample ¶
GetInvokeSample returns the sample invoke command for a given language and template
func InstallDependencies ¶
func InstallDependencies(appPath string, ci CreateInput) (string, error)
InstallDependencies sets up project dependencies based on language
func LanguageShorthand ¶ added in v0.19.0
LanguageShorthand returns the shorthand for a canonical language name, or an empty string if the language has no shorthand. Inverse of NormalizeLanguage.
func NormalizeLanguage ¶
Helper to normalize language input (handle shorthand)
func ProblemMessages ¶ added in v0.24.0
ProblemMessages extracts the messages from problems, in order.
func PromptLanguage ¶ added in v0.24.0
func PromptLanguage(p interactive.Prompter) (string, error)
PromptLanguage prompts for the application language.
func PromptName ¶ added in v0.24.0
func PromptName(p interactive.Prompter) (string, error)
PromptName prompts for the app name. An empty entry falls back to DefaultAppName.
func PromptOverwrite ¶ added in v0.24.0
func PromptOverwrite(p interactive.Prompter, dirName string) (bool, error)
PromptOverwrite asks for confirmation before overwriting an existing directory.
func PromptTemplate ¶ added in v0.24.0
func PromptTemplate(p interactive.Prompter, language string) (string, error)
PromptTemplate prompts for a template supported by the given (normalized) language.
func ResolveInput ¶ added in v0.24.0
func ResolveInput(raw RawInput) (CreateInput, []Problem)
ResolveInput is the single canonical resolver from raw flag values to a normalized CreateInput. It validates and normalizes every field, collecting a Problem for each one that is missing, invalid, or (for an existing target directory) would require an overwrite confirmation. It never prompts, but every Problem it emits carries the prompt step that resolves it.
Both modes of `kernel create` consume its problem model: the interactive flow resolves one problem at a time and re-resolves, while the non-interactive flow reports all problems in a single fail-fast error. Problems are ordered name, language, template, overwrite so interactive resolution fixes the language before the language-dependent template list is needed.
The returned CreateInput carries the fields that did resolve (with the language normalized) even when problems remain.
Types ¶
type CreateInput ¶
type DeployConfig ¶
type Field ¶ added in v0.24.0
type Field string
Field identifies a scaffolding input that a Problem refers to.
type Problem ¶ added in v0.24.0
type Problem struct {
Field Field
Message string
// Invalid marks that a value was provided but rejected (as opposed to
// missing); the interactive flow warns with Message before prompting.
Invalid bool
// contains filtered or unexported fields
}
Problem describes one input that is missing, invalid, or would require a confirmation. Message is phrased as the non-interactive fix instruction (naming the exact flag to pass); the interactive flow surfaces the same message as a warning before prompting for the field.
type RawInput ¶ added in v0.24.0
type RawInput struct {
Name string
Language string
Template string
// SkipOverwriteConfirm is set by --yes, or after the user interactively
// confirms overwriting an existing directory.
SkipOverwriteConfirm bool
}
RawInput carries the raw `kernel create` flag values before resolution.
type TemplateInfo ¶
type TemplateKeyValue ¶
type TemplateKeyValues ¶
type TemplateKeyValues []TemplateKeyValue
func GetSupportedTemplatesForLanguage ¶
func GetSupportedTemplatesForLanguage(language string) TemplateKeyValues
GetSupportedTemplatesForLanguage returns a list of all supported template names for a given language
func (TemplateKeyValues) ContainsKey ¶
func (tkv TemplateKeyValues) ContainsKey(key string) bool
ContainsKey checks if a template key exists in the TemplateKeyValues
func (TemplateKeyValues) GetTemplateDisplayValues ¶
func (tkv TemplateKeyValues) GetTemplateDisplayValues() []string
GetTemplateDisplayValues extracts display values from TemplateKeyValue slice
func (TemplateKeyValues) GetTemplateKeyFromValue ¶
func (tkv TemplateKeyValues) GetTemplateKeyFromValue(selectedValue string) (string, error)
GetTemplateKeyFromValue maps the selected display value back to the template key