Add initial Go CLI skeleton

This commit is contained in:
2026-03-19 02:55:41 +08:00
parent 84bd4fd9a7
commit 7b35f4dc5f
17 changed files with 536 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
package inbox
import (
"fmt"
"ai-workflow-skill/internal/db"
"ai-workflow-skill/internal/protocol"
"github.com/spf13/cobra"
)
func newInitCmd(opts *rootOptions) *cobra.Command {
return &cobra.Command{
Use: "init",
Short: "Initialize the shared SQLite database schema",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
sqlDB, err := db.Open(ctx, opts.dbPath)
if err != nil {
return err
}
defer sqlDB.Close()
if err := db.ApplyMigrations(ctx, sqlDB); err != nil {
return err
}
resp := protocol.Success{
OK: true,
Command: "init",
Data: map[string]any{
"db_path": opts.dbPath,
"status": "initialized",
},
}
if opts.json {
return protocol.WriteJSON(cmd.OutOrStdout(), resp)
}
_, err = fmt.Fprintf(cmd.OutOrStdout(), "initialized database: %s\n", opts.dbPath)
return err
},
}
}
+28
View File
@@ -0,0 +1,28 @@
package inbox
import (
"github.com/spf13/cobra"
)
type rootOptions struct {
dbPath string
json bool
agent string
}
func NewRootCmd() *cobra.Command {
opts := &rootOptions{}
cmd := &cobra.Command{
Use: "inbox",
Short: "Worker-facing durable coordination bus",
}
cmd.PersistentFlags().StringVar(&opts.dbPath, "db", ".agents/coord.db", "SQLite database path")
cmd.PersistentFlags().BoolVar(&opts.json, "json", false, "Emit machine-readable JSON")
cmd.PersistentFlags().StringVar(&opts.agent, "agent", "", "Agent identity")
cmd.AddCommand(newInitCmd(opts))
return cmd
}
+26
View File
@@ -0,0 +1,26 @@
package orch
import (
"github.com/spf13/cobra"
)
type rootOptions struct {
dbPath string
json bool
}
func NewRootCmd() *cobra.Command {
opts := &rootOptions{}
cmd := &cobra.Command{
Use: "orch",
Short: "Leader-facing scheduler and control plane",
}
cmd.PersistentFlags().StringVar(&opts.dbPath, "db", ".agents/coord.db", "SQLite database path")
cmd.PersistentFlags().BoolVar(&opts.json, "json", false, "Emit machine-readable JSON")
cmd.AddCommand(newRunCmd())
return cmd
}
+20
View File
@@ -0,0 +1,20 @@
package orch
import "github.com/spf13/cobra"
func newRunCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "run",
Short: "Run management commands",
}
cmd.AddCommand(&cobra.Command{
Use: "init",
Short: "Stub for future run initialization",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
})
return cmd
}