-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
153 lines (143 loc) · 3.92 KB
/
main.go
File metadata and controls
153 lines (143 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package main
import (
"fmt"
"os"
"github.com/AxeForging/aigate/actions"
"github.com/AxeForging/aigate/helpers"
"github.com/AxeForging/aigate/services"
"github.com/urfave/cli"
)
// Version information - set during build
var (
Version = "dev"
BuildTime = "unknown"
GitCommit = "unknown"
)
func main() {
helpers.SetupLogger("info")
platform := services.DetectPlatform()
configSvc := services.NewConfigService()
ruleSvc := services.NewRuleService()
runnerSvc := services.NewRunnerService(platform)
initAction := actions.NewInitAction(configSvc)
setupAction := actions.NewSetupAction(platform, configSvc)
helpAIAction := actions.NewHelpAIAction()
doctorAction := actions.NewDoctorAction()
denyAction := actions.NewDenyAction(ruleSvc, configSvc, platform)
allowAction := actions.NewAllowAction(ruleSvc, configSvc, platform)
runAction := actions.NewRunAction(runnerSvc, configSvc, platform)
statusAction := actions.NewStatusAction(configSvc, platform)
resetAction := actions.NewResetAction(platform, configSvc)
app := cli.NewApp()
app.Name = "aigate"
app.Usage = "OS-level sandbox for AI coding agents"
app.Version = Version
app.Commands = []cli.Command{
{
Name: "init",
Aliases: []string{"i"},
Usage: "Create default config (~/.aigate/config.yaml)",
Flags: []cli.Flag{verboseFlag, forceFlag},
Action: initAction.Execute,
},
{
Name: "setup",
Usage: "Create OS group and user for sandbox (requires sudo)",
Flags: []cli.Flag{groupFlag, userFlag, verboseFlag},
Action: setupAction.Execute,
},
{
Name: "deny",
Usage: "Add deny rules for AI agent isolation",
Subcommands: []cli.Command{
{
Name: "read",
Usage: "Deny AI agent read access to files/directories",
Flags: []cli.Flag{verboseFlag, dryRunFlag},
Action: denyAction.ExecuteRead,
},
{
Name: "exec",
Usage: "Deny AI agent from executing specific commands",
Flags: []cli.Flag{verboseFlag, dryRunFlag},
Action: denyAction.ExecuteExec,
},
{
Name: "net",
Usage: "Restrict AI agent network access (allow only --except domains)",
Flags: []cli.Flag{exceptFlag, verboseFlag, dryRunFlag},
Action: denyAction.ExecuteNet,
},
},
},
{
Name: "allow",
Usage: "Remove deny rules",
Subcommands: []cli.Command{
{
Name: "read",
Usage: "Remove file read deny rules",
Flags: []cli.Flag{verboseFlag},
Action: allowAction.ExecuteRead,
},
{
Name: "exec",
Usage: "Remove command execution deny rules",
Flags: []cli.Flag{verboseFlag},
Action: allowAction.ExecuteExec,
},
{
Name: "net",
Usage: "Remove network deny rules (add allowed domains)",
Flags: []cli.Flag{verboseFlag},
Action: allowAction.ExecuteNet,
},
},
},
{
Name: "run",
Aliases: []string{"r"},
Usage: "Run a command inside the AI sandbox (use -- before command)",
Flags: []cli.Flag{verboseFlag, configFlag},
Action: runAction.Execute,
},
{
Name: "status",
Aliases: []string{"s"},
Usage: "Show current sandbox configuration and state",
Flags: []cli.Flag{verboseFlag},
Action: statusAction.Execute,
},
{
Name: "reset",
Usage: "Remove sandbox group, user, and all rules",
Flags: []cli.Flag{forceFlag, verboseFlag},
Action: resetAction.Execute,
},
{
Name: "doctor",
Usage: "Check sandbox prerequisites and show active isolation mode",
Action: doctorAction.Execute,
},
{
Name: "help-ai",
Usage: "Show AI-friendly usage examples",
Action: helpAIAction.Execute,
},
{
Name: "version",
Usage: "Show version information",
Action: func(c *cli.Context) error {
fmt.Printf("aigate version %s\n", Version)
fmt.Printf("Build time: %s\n", BuildTime)
fmt.Printf("Git commit: %s\n", GitCommit)
return nil
},
},
}
err := app.Run(os.Args)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}