{"record":{"id":"93e372d15493e491","repo":"chenhg5/cc-connect","slug":"parse-existing-agy-hooks-s-w","errorCode":null,"errorMessage":"parse existing Agy hooks %s: %w","messagePattern":"parse existing Agy hooks (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/antigravity/permission_bridge.go","lineNumber":123,"sourceCode":"\toverlayConfigRoot := filepath.Join(rootDir, \"agy-config\")\n\toverlayConfigDir := filepath.Join(overlayConfigRoot, \"config\")\n\tif err := os.MkdirAll(overlayConfigDir, 0o700); err != nil {\n\t\treturn \"\", fmt.Errorf(\"create Agy permission overlay: %w\", err)\n\t}\n\n\tif err := mirrorDirectoryEntries(realConfigRoot, overlayConfigRoot, map[string]bool{\"config\": true}); err != nil {\n\t\treturn \"\", err\n\t}\n\trealConfigDir := filepath.Join(realConfigRoot, \"config\")\n\tif err := mirrorDirectoryEntries(realConfigDir, overlayConfigDir, map[string]bool{\"hooks.json\": true}); err != nil {\n\t\treturn \"\", err\n\t}\n\n\thooks := make(map[string]json.RawMessage)\n\thooksPath := filepath.Join(realConfigDir, \"hooks.json\")\n\tif data, err := os.ReadFile(hooksPath); err == nil {\n\t\tif err := json.Unmarshal(data, &hooks); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"parse existing Agy hooks %s: %w\", hooksPath, err)\n\t\t}\n\t\tif hooks == nil {\n\t\t\thooks = make(map[string]json.RawMessage)\n\t\t}\n\t} else if !os.IsNotExist(err) {\n\t\treturn \"\", fmt.Errorf(\"read existing Agy hooks %s: %w\", hooksPath, err)\n\t}\n\n\texecutable, err := os.Executable()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"resolve cc-connect executable for Agy hook: %w\", err)\n\t}\n\tbridgeHook, err := json.Marshal(map[string]any{\n\t\t\"PreToolUse\": []any{\n\t\t\tmap[string]any{\n\t\t\t\t\"matcher\": \"*\",\n\t\t\t\t\"hooks\": []any{\n\t\t\t\t\tmap[string]any{","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/antigravity/permission_bridge.go#L105-L141","documentation":"When building the overlay, createAgyConfigOverlay reads the existing ~/.gemini/config/hooks.json and unmarshals it into a map of raw JSON messages so the bridge hook can be merged. If the file exists but is not valid JSON (or not a JSON object), this wrapped error is returned.","triggerScenarios":"newAgyPermissionBridge → createAgyConfigOverlay with a pre-existing <home>/.gemini/config/hooks.json containing malformed JSON, JSON arrays, or other non-object top-level values.","commonSituations":"Hand-edited hooks.json with syntax errors, a partial/truncated write from a crashed process, or a hooks.json written by a different tool version with an incompatible schema.","solutions":["Validate the file: `python3 -m json.tool ~/.gemini/config/hooks.json` and fix any syntax errors.","If the content is not recoverable, remove or rename hooks.json so the bridge recreates a fresh overlay (note: existing hooks in it will be lost).","Back up the file, then restore only valid hook entries.","Ensure no other process concurrently rewrites hooks.json while a session starts."],"exampleFix":"// before: ~/.gemini/config/hooks.json\n{ \"PreToolUse\": [ }, // trailing comma → invalid\n// after\n{ \"PreToolUse\": [ { \"matcher\": \"*\", \"hooks\": [] } ] }","handlingStrategy":"validation","validationCode":"// shell: validate existing hooks.json before starting cc-connect\npython3 -m json.tool \"$HOME/.gemini/config/hooks.json\" > /dev/null \\\n  || echo \"hooks.json is not valid JSON\"","typeGuard":null,"tryCatchPattern":"if err := startAntigravitySession(); err != nil && strings.Contains(err.Error(), \"parse existing Agy hooks\") {\n    // back up ~/.gemini/config/hooks.json, fix or remove it, retry\n}","preventionTips":["Always validate hooks.json after hand edits or tool migrations.","Edit JSON config files with schema-aware editors.","Keep backups before overwriting hooks.json."],"tags":["json","config","antigravity","go"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}