Skip to content

Commit 176b448

Browse files
feat: add sys-init macos step (#67)
* feat: add hidden sys-init macos command for system diagnostics Add a hidden 'sys-init macos' command that collects macOS system information including current user, console user, Finder process status, and startup disk name. This diagnostic command is useful for troubleshooting macOS-specific runner initialization issues. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * build for testing * refactor: convert sys-init to package with --with-sysinit flag Refactor the hidden sys-init command into a proper package that runs automatically during bootup when the --with-sysinit flag is present. Changes: - Create pkg/sysinit package with OS detection - Remove hidden sys-init command - Add --with-sysinit flag to agentd - Automatically detect OS and run appropriate diagnostics - Gracefully skip on unsupported platforms - Add documentation in pkg/sysinit/README.md The sysinit package now provides a clean SysInit() API that: 1. Detects the current OS using runtime.GOOS 2. Runs macOS-specific diagnostics on darwin 3. Silently skips on other platforms Usage: agentd --with-sysinit --settings=settings.json 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: use existing log package in sysinit Move sysinit call from root.go to app.NewApp() after logger initialization, and use the existing pkg/log package directly instead of reimplementing logging. Changes: - Remove custom Logger interface from sysinit package - Use pkg/log directly via log.Logger() - Move sysinit call to NewApp() after logger is initialized - Pass WithSysInit flag through ApplicationOptions - Simplify output formatting using log.Logger().Infof/Errorf This ensures sysinit runs after the logger is properly initialized in NewApp(), before waiting for the settings file, and uses the standard logging infrastructure. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: add --with-sysinit flag to macOS agent launcher Update the warpbuild-agentd-launcher.sh script to include the --with-sysinit flag, enabling macOS system initialization diagnostics on agent startup. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * remove unintentional commit * add comment --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 086d69c commit 176b448

File tree

5 files changed

+88
-1
lines changed

5 files changed

+88
-1
lines changed

.github/workflows/release-testing.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Branch Build and Upload to R2
33
on:
44
push:
55
branches:
6-
- PrashantRaj18198/upgrade-gofiber-v2.52.11
6+
- feat/macos-init-commands
77

88
env:
99
AWS_ACCESS_KEY_ID: ${{ secrets.WB_PACKAGES_DEV_R2_ACCESS_KEY_ID }}

cmd/agentd/cmd/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type flagsStruct struct {
1919
telemetrySigNozEnable bool
2020
telemetrySigNozEndpoint string
2121
telemetrySigNozAPIKey string
22+
withSysInit bool
2223
}
2324

2425
var flags flagsStruct
@@ -41,6 +42,7 @@ var rootCmd = &cobra.Command{
4142
TelemetrySigNozEnable: flags.telemetrySigNozEnable,
4243
TelemetrySigNozEndpoint: flags.telemetrySigNozEndpoint,
4344
TelemetrySigNozAPIKey: flags.telemetrySigNozAPIKey,
45+
WithSysInit: flags.withSysInit,
4446
})
4547
if err != nil {
4648
return err
@@ -89,4 +91,5 @@ func init() {
8991
rootCmd.PersistentFlags().BoolVar(&flags.telemetrySigNozEnable, "telemetry-signoz-enable", false, "enable SigNoz telemetry export")
9092
rootCmd.PersistentFlags().StringVar(&flags.telemetrySigNozEndpoint, "telemetry-signoz-endpoint", "", "SigNoz OTLP endpoint (e.g., ingest.us.signoz.cloud:443)")
9193
rootCmd.PersistentFlags().StringVar(&flags.telemetrySigNozAPIKey, "telemetry-signoz-api-key", "", "SigNoz ingestion API key")
94+
rootCmd.PersistentFlags().BoolVar(&flags.withSysInit, "with-sysinit", false, "run system initialization diagnostics on startup")
9295
}

pkg/app/app.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/warpbuilds/warpbuild-agent/pkg/log"
1616
"github.com/warpbuilds/warpbuild-agent/pkg/manager"
1717
"github.com/warpbuilds/warpbuild-agent/pkg/proxy"
18+
"github.com/warpbuilds/warpbuild-agent/pkg/sysinit"
1819
"github.com/warpbuilds/warpbuild-agent/pkg/telemetry"
1920
transparentcache "github.com/warpbuilds/warpbuild-agent/pkg/transparent-cache"
2021
)
@@ -30,6 +31,7 @@ type ApplicationOptions struct {
3031
TelemetrySigNozEnable bool `json:"telemetry_signoz_enable"`
3132
TelemetrySigNozEndpoint string `json:"telemetry_signoz_endpoint"`
3233
TelemetrySigNozAPIKey string `json:"telemetry_signoz_api_key"`
34+
WithSysInit bool `json:"with_sysinit"`
3335
}
3436

3537
func (opts *ApplicationOptions) ApplyDefaults() {
@@ -166,6 +168,14 @@ func NewApp(ctx context.Context, opts *ApplicationOptions) error {
166168
log.Logger().Infof("starting warpbuild agent")
167169
log.Logger().Infof("settings file: %s", opts.SettingsFile)
168170

171+
// Run sys-init diagnostics if --with-sysinit flag is present
172+
// The sysinit package will automatically detect the OS and run appropriate diagnostics
173+
if opts.WithSysInit {
174+
if err := sysinit.SysInit(); err != nil {
175+
log.Logger().Errorf("sys-init failed: %v", err)
176+
}
177+
}
178+
169179
var elapsedTime time.Duration
170180
var settings Settings
171181
var foundSettings bool

pkg/sysinit/macos.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package sysinit
2+
3+
import (
4+
"os/exec"
5+
"strings"
6+
7+
"github.com/warpbuilds/warpbuild-agent/pkg/log"
8+
)
9+
10+
// runMacOSDiagnostics runs macOS-specific system initialization diagnostics
11+
func runMacOSDiagnostics() error {
12+
// whoami
13+
whoamiCmd := exec.Command("sh", "-c", "whoami")
14+
if output, err := whoamiCmd.CombinedOutput(); err == nil {
15+
log.Logger().Infof("whoami: %s", strings.TrimSpace(string(output)))
16+
} else {
17+
log.Logger().Errorf("whoami command failed: %v", err)
18+
}
19+
20+
// console user
21+
consoleUserCmd := exec.Command("sh", "-c", "stat -f '%Su' /dev/console")
22+
if output, err := consoleUserCmd.CombinedOutput(); err == nil {
23+
log.Logger().Infof("console user: %s", strings.TrimSpace(string(output)))
24+
} else {
25+
log.Logger().Errorf("console user command failed: %v", err)
26+
}
27+
28+
// pgrep Finder
29+
pgrepCmd := exec.Command("sh", "-c", "pgrep -lf Finder || true")
30+
if output, err := pgrepCmd.CombinedOutput(); err == nil {
31+
if len(output) > 0 {
32+
log.Logger().Infof("Finder processes: %s", strings.TrimSpace(string(output)))
33+
} else {
34+
log.Logger().Infof("Finder processes: none found")
35+
}
36+
} else {
37+
log.Logger().Errorf("pgrep Finder command failed: %v", err)
38+
}
39+
40+
// osascript startup disk
41+
// This is what triggers the popup for 'Automations' on warpbuild-agent
42+
osascriptCmd := exec.Command("osascript", "-e", "tell application \"Finder\" to get name of startup disk")
43+
if output, err := osascriptCmd.CombinedOutput(); err == nil {
44+
log.Logger().Infof("startup disk: %s", strings.TrimSpace(string(output)))
45+
} else {
46+
log.Logger().Errorf("osascript startup disk command failed: %v", err)
47+
}
48+
49+
return nil
50+
}

pkg/sysinit/sysinit.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package sysinit
2+
3+
import (
4+
"fmt"
5+
"runtime"
6+
7+
"github.com/warpbuilds/warpbuild-agent/pkg/log"
8+
)
9+
10+
// SysInit runs system initialization diagnostics based on the current OS and architecture.
11+
// It automatically detects the platform and runs the appropriate initialization routine.
12+
// If the platform is not supported, it silently skips without error.
13+
func SysInit() error {
14+
// Only run on macOS (darwin)
15+
if runtime.GOOS == "darwin" {
16+
log.Logger().Infof("=== Running macOS System Initialization Diagnostics ===")
17+
if err := runMacOSDiagnostics(); err != nil {
18+
return fmt.Errorf("macOS diagnostics failed: %w", err)
19+
}
20+
log.Logger().Infof("=== System Initialization Diagnostics Complete ===")
21+
}
22+
23+
return nil
24+
}

0 commit comments

Comments
 (0)