From 81a0c79b63048bd508077aae4161eb3c556482ae Mon Sep 17 00:00:00 2001 From: baeyc0510 Date: Sat, 15 Nov 2025 20:26:59 +0900 Subject: [PATCH 01/11] feat: enhance policy editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove policy change history feature * Delete internal/policy/history.go * Remove /api/policy/history endpoint from server * Remove history UI components (button, modal, event handlers) * Remove 'policy history' CLI command - Set default language for new rules from global settings * New rules now inherit languages from policy.defaults.languages * Improves consistency across policy rules πŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- internal/cmd/policy.go | 49 +---------- internal/policy/history.go | 105 ----------------------- internal/server/server.go | 18 ---- internal/server/static/index.html | 30 ------- internal/server/static/policy-editor.js | 54 +----------- internal/server/static/styles/output.css | 2 +- sym | Bin 10094114 -> 0 bytes 7 files changed, 5 insertions(+), 253 deletions(-) delete mode 100644 internal/policy/history.go delete mode 100755 sym diff --git a/internal/cmd/policy.go b/internal/cmd/policy.go index a8e4ac2..e497f94 100644 --- a/internal/cmd/policy.go +++ b/internal/cmd/policy.go @@ -1,7 +1,6 @@ package cmd import ( - "encoding/json" "fmt" "os" "github.com/DevSymphony/sym-cli/internal/config" @@ -18,8 +17,7 @@ var policyCmd = &cobra.Command{ Commands: sym policy path # Show current policy file path sym policy path --set PATH # Set policy file path - sym policy validate # Validate policy file - sym policy history # Show policy change history`, + sym policy validate # Validate policy file`, } var policyPathCmd = &cobra.Command{ @@ -36,27 +34,15 @@ var policyValidateCmd = &cobra.Command{ Run: runPolicyValidate, } -var policyHistoryCmd = &cobra.Command{ - Use: "history", - Short: "Show policy change history", - Long: `Display the git commit history for the policy file.`, - Run: runPolicyHistory, -} - var ( policyPathSet string - historyLimit int - jsonOutput bool ) func init() { policyPathCmd.Flags().StringVar(&policyPathSet, "set", "", "Set new policy file path") - policyHistoryCmd.Flags().IntVarP(&historyLimit, "limit", "n", 10, "Number of commits to show") - policyHistoryCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format") policyCmd.AddCommand(policyPathCmd) policyCmd.AddCommand(policyValidateCmd) - policyCmd.AddCommand(policyHistoryCmd) } func runPolicyPath(cmd *cobra.Command, args []string) { @@ -136,36 +122,3 @@ func runPolicyValidate(cmd *cobra.Command, args []string) { } } } - -func runPolicyHistory(cmd *cobra.Command, args []string) { - cfg, err := config.LoadConfig() - if err != nil { - fmt.Printf("❌ Failed to load config: %v\n", err) - os.Exit(1) - } - - history, err := policy.GetPolicyHistory(cfg.PolicyPath, historyLimit) - if err != nil { - fmt.Printf("❌ Failed to get history: %v\n", err) - os.Exit(1) - } - - if len(history) == 0 { - fmt.Println("No policy changes found") - return - } - - if jsonOutput { - data, _ := json.MarshalIndent(history, "", " ") - fmt.Println(string(data)) - return - } - - fmt.Printf("Policy change history (last %d commits):\n\n", len(history)) - - for i, commit := range history { - fmt.Printf("%d. %s\n", i+1, commit.Message) - fmt.Printf(" %s - %s <%s>\n", commit.Hash[:7], commit.Author, commit.Email) - fmt.Printf(" %s\n\n", commit.Date.Format("2006-01-02 15:04:05")) - } -} diff --git a/internal/policy/history.go b/internal/policy/history.go deleted file mode 100644 index 6e22084..0000000 --- a/internal/policy/history.go +++ /dev/null @@ -1,105 +0,0 @@ -package policy - -import ( - "fmt" - "os/exec" - "strings" - "time" -) - -// PolicyCommit represents a single commit in policy history -type PolicyCommit struct { - Hash string `json:"hash"` - Author string `json:"author"` - Email string `json:"email"` - Date time.Time `json:"date"` - Message string `json:"message"` - FilesChanged int `json:"filesChanged"` -} - -// GetPolicyHistory returns the git commit history for the policy file -func GetPolicyHistory(customPath string, limit int) ([]PolicyCommit, error) { - policyPath, err := GetPolicyPath(customPath) - if err != nil { - return nil, err - } - - if limit <= 0 { - limit = 10 - } - - // Git log command with custom format - // Format: hash|author|email|timestamp|subject - cmd := exec.Command("git", "log", - fmt.Sprintf("--max-count=%d", limit), - "--pretty=format:%H|%an|%ae|%at|%s", - "--", policyPath) - - output, err := cmd.Output() - if err != nil { - // If file has no history yet, return empty list - return []PolicyCommit{}, nil - } - - lines := strings.Split(strings.TrimSpace(string(output)), "\n") - commits := make([]PolicyCommit, 0, len(lines)) - - for _, line := range lines { - if line == "" { - continue - } - - parts := strings.SplitN(line, "|", 5) - if len(parts) != 5 { - continue - } - - var timestamp int64 - if _, err := fmt.Sscanf(parts[3], "%d", ×tamp); err != nil { - continue - } - - commit := PolicyCommit{ - Hash: parts[0], - Author: parts[1], - Email: parts[2], - Date: time.Unix(timestamp, 0), - Message: parts[4], - } - - commits = append(commits, commit) - } - - return commits, nil -} - -// GetPolicyDiff returns the diff for a specific commit -func GetPolicyDiff(commitHash string, customPath string) (string, error) { - policyPath, err := GetPolicyPath(customPath) - if err != nil { - return "", err - } - - // Get diff for specific commit - cmd := exec.Command("git", "show", fmt.Sprintf("%s:%s", commitHash, policyPath)) - output, err := cmd.Output() - if err != nil { - return "", fmt.Errorf("failed to get diff: %w", err) - } - - return string(output), nil -} - -// GetLatestCommit returns the most recent commit for the policy file -func GetLatestCommit(customPath string) (*PolicyCommit, error) { - commits, err := GetPolicyHistory(customPath, 1) - if err != nil { - return nil, err - } - - if len(commits) == 0 { - return nil, fmt.Errorf("no commits found for policy file") - } - - return &commits[0], nil -} diff --git a/internal/server/server.go b/internal/server/server.go index aa05372..04ba9fc 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -62,7 +62,6 @@ func (s *Server) Start() error { // Policy API endpoints mux.HandleFunc("/api/policy", s.handlePolicy) mux.HandleFunc("/api/policy/path", s.handlePolicyPath) - mux.HandleFunc("/api/policy/history", s.handlePolicyHistory) mux.HandleFunc("/api/policy/templates", s.handlePolicyTemplates) mux.HandleFunc("/api/policy/templates/", s.handlePolicyTemplateDetail) mux.HandleFunc("/api/users", s.handleUsers) @@ -455,23 +454,6 @@ func (s *Server) handleSetPolicyPath(w http.ResponseWriter, r *http.Request) { }) } -// handlePolicyHistory returns the policy commit history -func (s *Server) handlePolicyHistory(w http.ResponseWriter, r *http.Request) { - if r.Method != http.MethodGet { - http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) - return - } - - history, err := policy.GetPolicyHistory(s.cfg.PolicyPath, 20) - if err != nil { - http.Error(w, fmt.Sprintf("Failed to get policy history: %v", err), http.StatusInternalServerError) - return - } - - w.Header().Set("Content-Type", "application/json") - _ = json.NewEncoder(w).Encode(history) -} - // handlePolicyTemplates returns the list of available templates func (s *Server) handlePolicyTemplates(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet { diff --git a/internal/server/static/index.html b/internal/server/static/index.html index 7c8450a..58dd26b 100644 --- a/internal/server/static/index.html +++ b/internal/server/static/index.html @@ -49,10 +49,6 @@

ν…œν”Œλ¦Ώ - @@ -104,12 +100,6 @@

Info -
- -
@@ -121,10 +111,6 @@

μ •μ±… 파일의 μƒλŒ€ 경둜λ₯Ό μ§€μ •ν•©λ‹ˆλ‹€.

-
- - -
@@ -191,22 +177,6 @@

- - -