Function bodies 513 total
main.main function · go · L79-L132 (54 LOC)cmd/rubichan/main.go
func main() {
rootCmd := &cobra.Command{
Use: "rubichan",
Short: "An AI coding assistant",
Long: "rubichan — an interactive AI coding assistant powered by LLMs.",
RunE: func(_ *cobra.Command, _ []string) error {
if headless {
return runHeadless()
}
return runInteractive()
},
SilenceUsage: true,
SilenceErrors: true,
}
rootCmd.PersistentFlags().StringVar(&configPath, "config", "", "path to config file")
rootCmd.PersistentFlags().StringVar(&modelFlag, "model", "", "override model name")
rootCmd.PersistentFlags().StringVar(&providerFlag, "provider", "", "override provider name")
rootCmd.PersistentFlags().BoolVar(&autoApprove, "auto-approve", false, "auto-approve all tool calls (dangerous: enables RCE)")
rootCmd.PersistentFlags().BoolVar(&headless, "headless", false, "run in non-interactive headless mode")
rootCmd.PersistentFlags().StringVar(&promptFlag, "prompt", "", "prompt text for headless mode")
rootCmd.PersistentFlags().StringVar(&fileFlag, "fimain.parseSkillsFlag function · go · L136-L147 (12 LOC)cmd/rubichan/main.go
func parseSkillsFlag(s string) []string {
if strings.TrimSpace(s) == "" {
return nil
}
var names []string
for _, name := range strings.Split(s, ",") {
if trimmed := strings.TrimSpace(name); trimmed != "" {
names = append(names, trimmed)
}
}
return names
}main.createSkillRuntime function · go · L156-L290 (135 LOC)cmd/rubichan/main.go
func createSkillRuntime(ctx context.Context, registry *tools.Registry, p provider.LLMProvider, cfg *config.Config) (*skills.Runtime, io.Closer, error) {
skillNames := parseSkillsFlag(skillsFlag)
if len(skillNames) == 0 {
return nil, nil, nil
}
if cfg == nil {
return nil, nil, fmt.Errorf("config is required for skill runtime")
}
// Determine user config directory.
home, err := os.UserHomeDir()
if err != nil {
return nil, nil, fmt.Errorf("cannot determine home directory: %w", err)
}
configDir := filepath.Join(home, ".config", "rubichan")
// Ensure config directory exists for the database file.
if err := os.MkdirAll(configDir, 0o755); err != nil {
return nil, nil, fmt.Errorf("creating config directory: %w", err)
}
// Use persistent SQLite store so skill approvals survive across sessions.
dbPath := filepath.Join(configDir, "skills.db")
s, err := store.NewStore(dbPath)
if err != nil {
return nil, nil, fmt.Errorf("creating skill store: %w", err)
}
userDir :=main.openStore function · go · L294-L300 (7 LOC)cmd/rubichan/main.go
func openStore(configDir string) (*store.Store, error) {
if err := os.MkdirAll(configDir, 0o755); err != nil {
return nil, fmt.Errorf("creating config directory: %w", err)
}
dbPath := filepath.Join(configDir, "rubichan.db")
return store.NewStore(dbPath)
}main.configDir function · go · L303-L309 (7 LOC)cmd/rubichan/main.go
func configDir() (string, error) {
home, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("cannot determine home directory: %w", err)
}
return filepath.Join(home, ".config", "rubichan"), nil
}main.newDefaultSecurityEngine function · go · L314-L323 (10 LOC)cmd/rubichan/main.go
func newDefaultSecurityEngine(cfg security.EngineConfig) *security.Engine {
e := security.NewEngine(cfg)
e.AddScanner(scanner.NewSecretScanner())
e.AddScanner(scanner.NewSASTScanner())
e.AddScanner(scanner.NewConfigScanner())
e.AddScanner(scanner.NewDepScanner(nil))
e.AddScanner(scanner.NewLicenseScanner())
e.AddScanner(scanner.NewAppleScanner())
return e
}main.loadConfig function · go · L328-L351 (24 LOC)cmd/rubichan/main.go
func loadConfig() (*config.Config, error) {
cfgPath := configPath
if cfgPath == "" {
home, err := os.UserHomeDir()
if err != nil {
return nil, fmt.Errorf("cannot determine home directory: %w", err)
}
cfgPath = filepath.Join(home, ".config", "rubichan", "config.toml")
}
cfg, err := config.Load(cfgPath)
if err != nil {
return nil, fmt.Errorf("loading config: %w", err)
}
if modelFlag != "" {
cfg.Provider.Model = modelFlag
}
if providerFlag != "" {
cfg.Provider.Default = providerFlag
}
return cfg, nil
}Repobility — the code-quality scanner for AI-generated software · https://repobility.com
main.runInteractive function · go · L353-L445 (93 LOC)cmd/rubichan/main.go
func runInteractive() error {
cfg, err := loadConfig()
if err != nil {
return err
}
// Create provider
p, err := provider.NewProvider(cfg)
if err != nil {
return fmt.Errorf("creating provider: %w", err)
}
// Create tool registry
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("getting working directory: %w", err)
}
registry := tools.NewRegistry()
if err := registry.Register(tools.NewFileTool(cwd)); err != nil {
return fmt.Errorf("registering file tool: %w", err)
}
if err := registry.Register(tools.NewShellTool(cwd, 120*time.Second)); err != nil {
return fmt.Errorf("registering shell tool: %w", err)
}
if err := registry.Register(tools.NewSearchTool(cwd)); err != nil {
return fmt.Errorf("registering search tool: %w", err)
}
// Auto-activate apple-dev skill if Apple project detected.
var opts []agent.AgentOption
if appleOpt, err := wireAppleDev(cwd, registry, nil); err != nil {
return err
} else if appleOpt != nil {
opts = append(opts, apmain.parseToolsFlag function · go · L684-L695 (12 LOC)cmd/rubichan/main.go
func parseToolsFlag(s string) map[string]bool {
if strings.TrimSpace(s) == "" {
return nil
}
m := make(map[string]bool)
for _, t := range strings.Split(s, ",") {
if name := strings.TrimSpace(t); name != "" {
m[name] = true
}
}
return m
}main.shouldRegister function · go · L699-L704 (6 LOC)cmd/rubichan/main.go
func shouldRegister(name string, allowed map[string]bool) bool {
if allowed == nil {
return true
}
return allowed[name]
}main.removeSkill function · go · L707-L717 (11 LOC)cmd/rubichan/main.go
func removeSkill(name, flagValue string) string {
var kept []string
for _, s := range strings.Split(flagValue, ",") {
if strings.TrimSpace(s) != name {
if trimmed := strings.TrimSpace(s); trimmed != "" {
kept = append(kept, trimmed)
}
}
}
return strings.Join(kept, ",")
}main.containsSkill function · go · L720-L727 (8 LOC)cmd/rubichan/main.go
func containsSkill(name, flagValue string) bool {
for _, s := range strings.Split(flagValue, ",") {
if strings.TrimSpace(s) == name {
return true
}
}
return false
}main.wireAppleDev function · go · L732-L755 (24 LOC)cmd/rubichan/main.go
func wireAppleDev(cwd string, registry *tools.Registry, allowed map[string]bool) (agent.AgentOption, error) {
appleProject := xcode.DiscoverProject(cwd)
if appleProject.Type == "none" && !containsSkill("apple-dev", skillsFlag) {
return nil, nil
}
pc := xcode.NewRealPlatformChecker()
appleBackend := &appledev.Backend{WorkDir: cwd, Platform: pc}
if err := appleBackend.Load(appledev.Manifest(), nil); err != nil {
return nil, fmt.Errorf("loading apple-dev skill: %w", err)
}
registered := 0
for _, tool := range appleBackend.Tools() {
if shouldRegister(tool.Name(), allowed) {
if err := registry.Register(tool); err != nil {
return nil, fmt.Errorf("registering xcode tool %s: %w", tool.Name(), err)
}
registered++
}
}
if registered == 0 {
return nil, nil
}
return agent.WithExtraSystemPrompt("Apple Platform Expertise", appledev.SystemPrompt()), nil
}main.starlarkGitRunnerAdapter.Log method · go · L774-L784 (11 LOC)cmd/rubichan/main.go
func (a *starlarkGitRunnerAdapter) Log(ctx context.Context, args ...string) ([]starengine.GitLogEntry, error) {
commits, err := a.runner.Log(ctx, args...)
if err != nil {
return nil, err
}
entries := make([]starengine.GitLogEntry, len(commits))
for i, c := range commits {
entries[i] = starengine.GitLogEntry{Hash: c.Hash, Author: c.Author, Message: c.Message}
}
return entries, nil
}main.starlarkGitRunnerAdapter.Status method · go · L786-L796 (11 LOC)cmd/rubichan/main.go
func (a *starlarkGitRunnerAdapter) Status(ctx context.Context) ([]starengine.GitStatusEntry, error) {
statuses, err := a.runner.Status(ctx)
if err != nil {
return nil, err
}
entries := make([]starengine.GitStatusEntry, len(statuses))
for i, s := range statuses {
entries[i] = starengine.GitStatusEntry{Path: s.Path, Status: s.Status}
}
return entries, nil
}If a scraper extracted this row, it came from Repobility (https://repobility.com)
main.pluginGitRunnerAdapter.Log method · go · L832-L842 (11 LOC)cmd/rubichan/main.go
func (a *pluginGitRunnerAdapter) Log(args ...string) ([]skillsdk.GitCommit, error) {
commits, err := a.runner.Log(a.ctx, args...)
if err != nil {
return nil, err
}
entries := make([]skillsdk.GitCommit, len(commits))
for i, c := range commits {
entries[i] = skillsdk.GitCommit{Hash: c.Hash, Author: c.Author, Message: c.Message}
}
return entries, nil
}main.pluginGitRunnerAdapter.Status method · go · L844-L854 (11 LOC)cmd/rubichan/main.go
func (a *pluginGitRunnerAdapter) Status() ([]skillsdk.GitFileStatus, error) {
statuses, err := a.runner.Status(a.ctx)
if err != nil {
return nil, err
}
entries := make([]skillsdk.GitFileStatus, len(statuses))
for i, s := range statuses {
entries[i] = skillsdk.GitFileStatus{Path: s.Path, Status: s.Status}
}
return entries, nil
}main.skillCmd function · go · L25-L43 (19 LOC)cmd/rubichan/skill.go
func skillCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "skill",
Short: "Manage skills",
Long: "List, inspect, search, install, remove, add, create, test, and manage permissions for skills.",
}
cmd.AddCommand(skillListCmd())
cmd.AddCommand(skillInfoCmd())
cmd.AddCommand(skillSearchCmd())
cmd.AddCommand(skillInstallCmd())
cmd.AddCommand(skillRemoveCmd())
cmd.AddCommand(skillAddCmd())
cmd.AddCommand(skillCreateCmd())
cmd.AddCommand(skillTestCmd())
cmd.AddCommand(skillPermissionsCmd())
return cmd
}main.resolveStorePath function · go · L46-L57 (12 LOC)cmd/rubichan/skill.go
func resolveStorePath(cmd *cobra.Command) (string, error) {
storePath, _ := cmd.Flags().GetString("store")
if storePath != "" {
return storePath, nil
}
home, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("cannot determine home directory: %w", err)
}
return filepath.Join(home, ".config", "rubichan", "skills.db"), nil
}main.skillListCmd function · go · L59-L81 (23 LOC)cmd/rubichan/skill.go
func skillListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List installed skills",
Long: `Display a table of all installed skills with their name, version, and source.
Use --available to list skills from the remote registry instead.`,
RunE: func(cmd *cobra.Command, args []string) error {
available, err := cmd.Flags().GetBool("available")
if err != nil {
return fmt.Errorf("reading --available flag: %w", err)
}
if available {
return listAvailableSkills(cmd)
}
return listInstalledSkills(cmd)
},
}
cmd.Flags().String("store", "", "path to skills database (default: ~/.config/rubichan/skills.db)")
cmd.Flags().Bool("available", false, "list skills from the remote registry")
cmd.Flags().String("registry", "", "registry URL (default: "+defaultRegistryURL+")")
return cmd
}main.listInstalledSkills function · go · L84-L115 (32 LOC)cmd/rubichan/skill.go
func listInstalledSkills(cmd *cobra.Command) error {
storePath, err := resolveStorePath(cmd)
if err != nil {
return err
}
s, err := store.NewStore(storePath)
if err != nil {
return fmt.Errorf("opening store: %w", err)
}
defer s.Close()
states, err := s.ListAllSkillStates()
if err != nil {
return fmt.Errorf("listing skills: %w", err)
}
if len(states) == 0 {
fmt.Fprintln(cmd.OutOrStdout(), "No skills installed.")
return nil
}
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "NAME\tVERSION\tSOURCE\tINSTALLED")
for _, st := range states {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n",
st.Name, st.Version, st.Source,
st.InstalledAt.Format(time.RFC3339),
)
}
return w.Flush()
}main.listAvailableSkills function · go · L118-L150 (33 LOC)cmd/rubichan/skill.go
func listAvailableSkills(cmd *cobra.Command) error {
registryURL, err := cmd.Flags().GetString("registry")
if err != nil {
return fmt.Errorf("reading --registry flag: %w", err)
}
if registryURL == "" {
registryURL = defaultRegistryURL
}
client := skills.NewRegistryClient(registryURL, nil, 0)
ctx := cmd.Context()
if ctx == nil {
ctx = context.Background()
}
results, err := client.Search(ctx, "")
if err != nil {
return fmt.Errorf("fetching available skills: %w", err)
}
if len(results) == 0 {
fmt.Fprintln(cmd.OutOrStdout(), "No skills available in the registry.")
return nil
}
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "NAME\tVERSION\tDESCRIPTION")
for _, r := range results {
fmt.Fprintf(w, "%s\t%s\t%s\n", r.Name, r.Version, r.Description)
}
return w.Flush()
}main.skillInfoCmd function · go · L152-L232 (81 LOC)cmd/rubichan/skill.go
func skillInfoCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "info <name>",
Short: "Show details for an installed skill",
Long: "Display the full manifest details for a named skill.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
storePath, err := resolveStorePath(cmd)
if err != nil {
return err
}
s, err := store.NewStore(storePath)
if err != nil {
return fmt.Errorf("opening store: %w", err)
}
defer s.Close()
state, err := s.GetSkillState(name)
if err != nil {
return fmt.Errorf("looking up skill: %w", err)
}
if state == nil {
return fmt.Errorf("skill %q not found", name)
}
// The Source field stores the skill directory path.
skillDir := state.Source
manifestPath := filepath.Join(skillDir, "SKILL.yaml")
data, err := os.ReadFile(manifestPath)
if err != nil {
return fmt.Errorf("reading manifest: %w", err)
}
manifest, err := skills.ParseRepobility analyzer · published findings · https://repobility.com
main.skillSearchCmd function · go · L234-L275 (42 LOC)cmd/rubichan/skill.go
func skillSearchCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "search <query>",
Short: "Search the skill registry",
Long: "Search for skills in the remote registry by keyword.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
query := args[0]
registryURL, _ := cmd.Flags().GetString("registry")
if registryURL == "" {
registryURL = defaultRegistryURL
}
client := skills.NewRegistryClient(registryURL, nil, 0)
ctx := cmd.Context()
if ctx == nil {
ctx = context.Background()
}
results, err := client.Search(ctx, query)
if err != nil {
return fmt.Errorf("searching registry: %w", err)
}
if len(results) == 0 {
fmt.Fprintln(cmd.OutOrStdout(), "No results found.")
return nil
}
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "NAME\tVERSION\tDESCRIPTION")
for _, r := range results {
fmt.Fprintf(w, "%s\t%s\t%s\n", r.Name, r.Version, r.Descriptiomain.resolveSkillsDir function · go · L278-L288 (11 LOC)cmd/rubichan/skill.go
func resolveSkillsDir(cmd *cobra.Command) (string, error) {
dir, _ := cmd.Flags().GetString("skills-dir")
if dir != "" {
return dir, nil
}
home, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("cannot determine home directory: %w", err)
}
return filepath.Join(home, ".config", "rubichan", "skills"), nil
}main.parseNameVersion function · go · L298-L303 (6 LOC)cmd/rubichan/skill.go
func parseNameVersion(source string) (name, version string) {
if idx := strings.LastIndex(source, "@"); idx > 0 {
return source[:idx], source[idx+1:]
}
return source, "latest"
}main.validateSkillName function · go · L312-L321 (10 LOC)cmd/rubichan/skill.go
func validateSkillName(name string) error {
const maxSkillNameLength = 128
if len(name) > maxSkillNameLength {
return fmt.Errorf("invalid skill name %q: exceeds maximum length of %d characters", name, maxSkillNameLength)
}
if !validSkillNamePattern.MatchString(name) {
return fmt.Errorf("invalid skill name %q: must contain only letters, digits, hyphens, and underscores", name)
}
return nil
}main.copyDir function · go · L325-L343 (19 LOC)cmd/rubichan/skill.go
func copyDir(src, dst string) error {
return filepath.WalkDir(src, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
relPath, err := filepath.Rel(src, path)
if err != nil {
return err
}
target := filepath.Join(dst, relPath)
if d.IsDir() {
return os.MkdirAll(target, 0o755)
}
return copyFile(path, target)
})
}main.copyFile function · go · L346-L368 (23 LOC)cmd/rubichan/skill.go
func copyFile(src, dst string) error {
in, err := os.Open(src)
if err != nil {
return fmt.Errorf("open source: %w", err)
}
defer in.Close()
info, err := in.Stat()
if err != nil {
return fmt.Errorf("stat source: %w", err)
}
out, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, info.Mode())
if err != nil {
return fmt.Errorf("create dest: %w", err)
}
defer out.Close()
if _, err := io.Copy(out, in); err != nil {
return fmt.Errorf("copy: %w", err)
}
return nil
}main.skillInstallCmd function · go · L370-L402 (33 LOC)cmd/rubichan/skill.go
func skillInstallCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "install <source>",
Short: "Install a skill from a local path or registry",
Long: `Install a skill from a local directory path or the remote registry.
If source contains '/' or starts with '.', it is treated as a local directory.
Otherwise it is treated as a registry skill name. Use name@version to pin a
specific version; otherwise "latest" is used.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
source := args[0]
storePath, err := resolveStorePath(cmd)
if err != nil {
return err
}
skillsDir, err := resolveSkillsDir(cmd)
if err != nil {
return err
}
if isLocalPath(source) {
return installFromLocal(cmd, source, skillsDir, storePath)
}
return installFromRegistry(cmd, source, skillsDir, storePath)
},
}
cmd.Flags().String("store", "", "path to skills database (default: ~/.config/rubichan/skills.db)")
cmd.Flags().String("skills-main.installFromLocal function · go · L406-L445 (40 LOC)cmd/rubichan/skill.go
func installFromLocal(cmd *cobra.Command, source, skillsDir, storePath string) error {
// Validate SKILL.yaml exists in source.
manifestPath := filepath.Join(source, "SKILL.yaml")
data, err := os.ReadFile(manifestPath)
if err != nil {
return fmt.Errorf("reading SKILL.yaml from %s: %w", source, err)
}
manifest, err := skills.ParseManifest(data)
if err != nil {
return fmt.Errorf("invalid manifest: %w", err)
}
dest := filepath.Join(skillsDir, manifest.Name)
if err := os.MkdirAll(dest, 0o755); err != nil {
return fmt.Errorf("creating skill directory: %w", err)
}
if err := copyDir(source, dest); err != nil {
return fmt.Errorf("copying skill: %w", err)
}
// Save state to store.
s, err := store.NewStore(storePath)
if err != nil {
return fmt.Errorf("opening store: %w", err)
}
defer s.Close()
if err := s.SaveSkillState(store.SkillInstallState{
Name: manifest.Name,
Version: manifest.Version,
Source: dest,
}); err != nil {
return fmt.Errorf("saving sRepobility · MCP-ready · https://repobility.com
main.installFromRegistry function · go · L451-L536 (86 LOC)cmd/rubichan/skill.go
func installFromRegistry(cmd *cobra.Command, source, skillsDir, storePath string) error {
name, version := parseNameVersion(source)
if err := validateSkillName(name); err != nil {
return err
}
registryURL, err := cmd.Flags().GetString("registry")
if err != nil {
return fmt.Errorf("reading --registry flag: %w", err)
}
if registryURL == "" {
registryURL = defaultRegistryURL
}
client := skills.NewRegistryClient(registryURL, nil, 0)
ctx := cmd.Context()
if ctx == nil {
ctx = context.Background()
}
// Resolve SemVer ranges by fetching available versions from the registry.
if skills.IsSemVerRange(version) {
available, err := client.ListVersions(ctx, name)
if err != nil {
return fmt.Errorf("listing versions: %w", err)
}
resolved, err := skills.ResolveVersion(version, available)
if err != nil {
return fmt.Errorf("resolving version %q: %w", version, err)
}
version = resolved
}
dest := filepath.Join(skillsDir, name)
if err := os.MkdirAll(dest, 0main.skillRemoveCmd function · go · L538-L588 (51 LOC)cmd/rubichan/skill.go
func skillRemoveCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "remove <name>",
Short: "Remove an installed skill",
Long: "Delete the skill directory and remove its entry from the store.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
storePath, err := resolveStorePath(cmd)
if err != nil {
return err
}
skillsDir, err := resolveSkillsDir(cmd)
if err != nil {
return err
}
// Verify skill exists in store before deleting anything.
s, err := store.NewStore(storePath)
if err != nil {
return fmt.Errorf("opening store: %w", err)
}
defer s.Close()
existing, err := s.GetSkillState(name)
if err != nil {
return fmt.Errorf("checking skill state: %w", err)
}
if existing == nil {
return fmt.Errorf("skill %q is not installed", name)
}
// Remove from store first, then delete directory.
if err := s.DeleteSkillState(name); err != nil {
return fmt.Errorfmain.skillAddCmd function · go · L590-L635 (46 LOC)cmd/rubichan/skill.go
func skillAddCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "add <path>",
Short: "Add a skill to the current project",
Long: "Copy a skill from the given path into the project's .agent/skills/<name>/ directory.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
source := args[0]
projectDir, _ := cmd.Flags().GetString("project-dir")
if projectDir == "" {
var err error
projectDir, err = os.Getwd()
if err != nil {
return fmt.Errorf("cannot determine working directory: %w", err)
}
}
// Validate SKILL.yaml exists in source.
manifestPath := filepath.Join(source, "SKILL.yaml")
data, err := os.ReadFile(manifestPath)
if err != nil {
return fmt.Errorf("reading SKILL.yaml from %s: %w", source, err)
}
manifest, err := skills.ParseManifest(data)
if err != nil {
return fmt.Errorf("invalid manifest: %w", err)
}
dest := filepath.Join(projectDir, ".agent", "skills", manifest.Name)
main.skillCreateCmd function · go · L666-L713 (48 LOC)cmd/rubichan/skill.go
func skillCreateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create <name>",
Short: "Scaffold a new skill directory",
Long: "Create a new skill directory with a template SKILL.yaml and skill.star file.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
parentDir, _ := cmd.Flags().GetString("dir")
if parentDir == "" {
var err error
parentDir, err = os.Getwd()
if err != nil {
return fmt.Errorf("cannot determine working directory: %w", err)
}
}
skillDir := filepath.Join(parentDir, name)
if err := os.MkdirAll(skillDir, 0o755); err != nil {
return fmt.Errorf("creating skill directory: %w", err)
}
// Write SKILL.yaml template.
manifestContent := fmt.Sprintf(skillCreateTemplate, name)
if err := os.WriteFile(
filepath.Join(skillDir, "SKILL.yaml"),
[]byte(manifestContent), 0o644,
); err != nil {
return fmt.Errorf("writing SKILL.yaml: %w", err)
}
//main.skillTestCmd function · go · L715-L743 (29 LOC)cmd/rubichan/skill.go
func skillTestCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "test <path>",
Short: "Validate a skill manifest",
Long: "Read and validate the SKILL.yaml from the given skill directory.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
skillPath := args[0]
manifestPath := filepath.Join(skillPath, "SKILL.yaml")
data, err := os.ReadFile(manifestPath)
if err != nil {
return fmt.Errorf("reading SKILL.yaml from %s: %w", skillPath, err)
}
manifest, err := skills.ParseManifest(data)
if err != nil {
return fmt.Errorf("manifest validation failed: %w", err)
}
fmt.Fprintf(cmd.OutOrStdout(),
"Skill '%s' v%s validated successfully\n",
manifest.Name, manifest.Version,
)
return nil
},
}
return cmd
}main.skillPermissionsCmd function · go · L745-L798 (54 LOC)cmd/rubichan/skill.go
func skillPermissionsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "permissions <name>",
Short: "List or revoke permission approvals for a skill",
Long: "Display permission approvals for a skill, or revoke all approvals with --revoke.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
revoke, _ := cmd.Flags().GetBool("revoke")
storePath, err := resolveStorePath(cmd)
if err != nil {
return err
}
s, err := store.NewStore(storePath)
if err != nil {
return fmt.Errorf("opening store: %w", err)
}
defer s.Close()
if revoke {
if err := s.Revoke(name); err != nil {
return fmt.Errorf("revoking permissions: %w", err)
}
fmt.Fprintf(cmd.OutOrStdout(), "All permissions revoked for skill '%s'\n", name)
return nil
}
approvals, err := s.ListApprovals(name)
if err != nil {
return fmt.Errorf("listing approvals: %w", err)
}
if len(approvals) == 0 {
fmt.Fmain.wikiCmd function · go · L16-L77 (62 LOC)cmd/rubichan/wiki.go
func wikiCmd() *cobra.Command {
var (
formatFlag string
outputFlag string
diagramsFlag string
concurrencyFlag int
)
cmd := &cobra.Command{
Use: "wiki [path]",
Short: "Generate project documentation wiki",
Long: `Analyze a codebase and generate a static documentation site with
architecture diagrams, module documentation, and improvement suggestions.`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
dir := "."
if len(args) > 0 {
dir = args[0]
}
cfg, err := loadConfig()
if err != nil {
return err
}
p, err := provider.NewProvider(cfg)
if err != nil {
return fmt.Errorf("creating provider: %w", err)
}
llm := integrations.NewLLMCompleter(p, cfg.Provider.Model)
psr := parser.NewParser()
// Populate the wiki security page; failures are non-fatal.
engine := newDefaultSecurityEngine(security.EngineConfig{Concurrency: 4})
var findings []security.Finding
report, err agent.New function · go · L117-L187 (71 LOC)internal/agent/agent.go
func New(p provider.LLMProvider, t *tools.Registry, approve ApprovalFunc, cfg *config.Config, opts ...AgentOption) *Agent {
systemPrompt := buildSystemPrompt(cfg)
a := &Agent{
provider: p,
tools: t,
conversation: NewConversation(systemPrompt),
context: NewContextManager(cfg.Agent.ContextBudget),
approve: approve,
model: cfg.Provider.Model,
maxTurns: cfg.Agent.MaxTurns,
}
for _, opt := range opts {
opt(a)
}
// Rebuild system prompt if AGENT.md content was provided.
if a.agentMD != "" {
prompt := a.conversation.SystemPrompt() +
"\n\n## Project Guidelines (from AGENT.md)\n\n" + a.agentMD
a.conversation = NewConversation(prompt)
}
// Append extra system prompt sections (e.g., from apple-dev skill).
if len(a.extraPrompts) > 0 {
prompt := a.conversation.SystemPrompt()
for _, ep := range a.extraPrompts {
prompt += "\n\n## " + ep.Name + "\n\n" + ep.Content
}
a.conversation = NewConversation(prompt)
}
if a.store != niRepobility — the code-quality scanner for AI-generated software · https://repobility.com
agent.Agent.persistMessage method · go · L214-L221 (8 LOC)internal/agent/agent.go
func (a *Agent) persistMessage(role string, content []provider.ContentBlock) {
if a.store == nil {
return
}
if err := a.store.AppendMessage(a.sessionID, role, content); err != nil {
log.Printf("warning: failed to persist message: %v", err)
}
}agent.Agent.Turn method · go · L225-L236 (12 LOC)internal/agent/agent.go
func (a *Agent) Turn(ctx context.Context, userMessage string) (<-chan TurnEvent, error) {
a.conversation.AddUser(userMessage)
a.persistMessage("user", []provider.ContentBlock{{Type: "text", Text: userMessage}})
a.context.Truncate(a.conversation)
ch := make(chan TurnEvent, 64)
go func() {
defer close(ch)
a.runLoop(ctx, ch, 0)
}()
return ch, nil
}agent.Agent.buildSystemPromptWithFragments method · go · L240-L258 (19 LOC)internal/agent/agent.go
func (a *Agent) buildSystemPromptWithFragments() string {
base := a.conversation.SystemPrompt()
if a.skillRuntime == nil {
return base
}
fragments := a.skillRuntime.GetPromptFragments()
if len(fragments) == 0 {
return base
}
result := base
for _, f := range fragments {
if f.ResolvedPrompt != "" {
result += "\n\n" + f.ResolvedPrompt
}
}
return result
}agent.Agent.dispatchHook method · go · L262-L267 (6 LOC)internal/agent/agent.go
func (a *Agent) dispatchHook(event skills.HookEvent) (*skills.HookResult, error) {
if a.skillRuntime == nil {
return nil, nil
}
return a.skillRuntime.DispatchHook(event)
}agent.ContextManager.EstimateTokens method · go · L18-L34 (17 LOC)internal/agent/context.go
func (cm *ContextManager) EstimateTokens(conv *Conversation) int {
total := 0
// System prompt tokens
total += len(conv.SystemPrompt())/4 + 10
// Message tokens
for _, msg := range conv.messages {
for _, block := range msg.Content {
chars := len(block.Text) + len(block.ID) + len(block.Name) +
len(block.ToolUseID) + len(block.Input)
total += chars/4 + 10
}
}
return total
}agent.ContextManager.Truncate method · go · L44-L63 (20 LOC)internal/agent/context.go
func (cm *ContextManager) Truncate(conv *Conversation) {
for cm.ExceedsBudget(conv) && len(conv.messages) > 2 {
// Find a safe removal boundary: skip any leading tool_result messages
// since removing them without their tool_use would corrupt the conversation.
start := 0
for start < len(conv.messages) && hasToolResult(conv.messages[start]) {
start++
}
// Remove 2 messages (a user+assistant pair) starting from the safe boundary.
remove := start + 2
if remove > len(conv.messages)-2 {
remove = len(conv.messages) - 2
}
if remove <= 0 {
break
}
conv.messages = conv.messages[remove:]
}
}agent.hasToolResult function · go · L66-L73 (8 LOC)internal/agent/context.go
func hasToolResult(msg provider.Message) bool {
for _, block := range msg.Content {
if block.Type == "tool_result" {
return true
}
}
return false
}agent.Conversation.AddAssistant method · go · L36-L41 (6 LOC)internal/agent/conversation.go
func (c *Conversation) AddAssistant(blocks []provider.ContentBlock) {
c.messages = append(c.messages, provider.Message{
Role: "assistant",
Content: blocks,
})
}If a scraper extracted this row, it came from Repobility (https://repobility.com)
config.LoadAgentMD function · go · L11-L24 (14 LOC)internal/config/agentmd.go
func LoadAgentMD(projectRoot string) (string, error) {
data, err := os.ReadFile(filepath.Join(projectRoot, "AGENT.md"))
if err != nil {
if os.IsNotExist(err) {
return "", nil
}
return "", err
}
content := strings.TrimSpace(string(data))
if content == "" {
return "", nil
}
return string(data), nil
}config.ResolveAPIKey function · go · L11-L25 (15 LOC)internal/config/apikey.go
func ResolveAPIKey(source, configValue, envVar string) (string, error) {
switch source {
case "keyring":
return resolveFromEnv(envVar)
case "env":
return resolveFromEnv(envVar)
case "config":
if configValue == "" {
return "", fmt.Errorf("api_key_source is 'config' but no api_key value provided")
}
return configValue, nil
default:
return "", fmt.Errorf("unknown api_key_source: %q", source)
}
}config.resolveFromEnv function · go · L27-L36 (10 LOC)internal/config/apikey.go
func resolveFromEnv(envVar string) (string, error) {
if envVar == "" {
return "", fmt.Errorf("no environment variable name specified")
}
val := os.Getenv(envVar)
if val == "" {
return "", fmt.Errorf("environment variable %s is not set", envVar)
}
return val, nil
}page 1 / 11next ›