Skip to content

Commit 3f59920

Browse files
tas50claude
andcommitted
🧹 Skip permissions.json write when only timestamp changed
The permissions tool regenerates on every provider build, and the timestamp comes from the latest git commit. This causes a dirty diff even when no permissions actually changed. Compare the existing file content (ignoring generated_at) before writing to avoid noise. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b0bccb5 commit 3f59920

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

providers-sdk/v1/util/permissions/permissions.go

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,29 @@ func main() {
110110
Details: details,
111111
}
112112

113+
if outputPath == "" {
114+
outputPath = filepath.Join(providerPath, "resources", providerName+".permissions.json")
115+
}
116+
117+
// Skip writing if only the timestamp changed.
118+
if existing, err := os.ReadFile(outputPath); err == nil {
119+
var old PermissionManifest
120+
if json.Unmarshal(existing, &old) == nil {
121+
old.GeneratedAt = manifest.GeneratedAt
122+
if manifestsEqual(old, manifest) {
123+
fmt.Printf(" %s: %d permissions (unchanged) → %s\n", providerName, len(permissions), outputPath)
124+
return
125+
}
126+
}
127+
}
128+
113129
data, err := json.MarshalIndent(manifest, "", " ")
114130
if err != nil {
115131
fmt.Fprintf(os.Stderr, "error marshaling JSON: %v\n", err)
116132
os.Exit(1)
117133
}
118134
data = append(data, '\n')
119135

120-
if outputPath == "" {
121-
outputPath = filepath.Join(providerPath, "resources", providerName+".permissions.json")
122-
}
123-
124136
if err := os.MkdirAll(filepath.Dir(outputPath), 0o755); err != nil {
125137
fmt.Fprintf(os.Stderr, "error creating output directory: %v\n", err)
126138
os.Exit(1)
@@ -172,6 +184,30 @@ func deterministicTimestamp() string {
172184
return "unknown"
173185
}
174186

187+
// manifestsEqual reports whether two manifests are identical in all fields.
188+
func manifestsEqual(a, b PermissionManifest) bool {
189+
if a.Provider != b.Provider || a.Version != b.Version || a.GeneratedAt != b.GeneratedAt {
190+
return false
191+
}
192+
if len(a.Permissions) != len(b.Permissions) {
193+
return false
194+
}
195+
for i := range a.Permissions {
196+
if a.Permissions[i] != b.Permissions[i] {
197+
return false
198+
}
199+
}
200+
if len(a.Details) != len(b.Details) {
201+
return false
202+
}
203+
for i := range a.Details {
204+
if a.Details[i] != b.Details[i] {
205+
return false
206+
}
207+
}
208+
return true
209+
}
210+
175211
// listGoFiles returns all non-test, non-generated .go files in a directory tree.
176212
func listGoFiles(dir string) []string {
177213
var files []string

0 commit comments

Comments
 (0)