master
md 243 lines 8.61 KB
Rendered Raw
1 ---
2 name: mirror-netdata-repos
3 description: Maintains a local mirror of Netdata-org source repositories at `${NETDATA_REPOS_DIR}` so AI assistants and developers can do cross-repo grep / code review locally without GitHub API round-trips and rate limits. Ships a vendored sync script (`scripts/sync-netdata-repos.sh`) that updates ~150 repos in two phases (resync existing on default branch, discover and clone new). Safety -- skips repos that have staged or modified changes; otherwise switches to the default branch and recursively updates submodules. Reset-to-default is intentional -- it prevents stale-feature-branch "black hole" repos that confuse cross-repo reasoning. Supports `--repo NAME` (repeatable) to scope to specific repos. Independent from any other repo mirrors this workstation may have. Use when the local mirror is out of date, before a cross-repo grep / review session, when adding a new netdata-org repo (auto-discovered), when an assistant needs cross-repo cognition without `gh` API turnaround.
4 ---
5
6 # mirror-netdata-repos
7
8 A local mirror of every active Netdata-org source repository,
9 synced by a vendored bash script. Built for AI assistants
10 (and humans) that need cross-repo grep, code review, and
11 pattern lookup without paying GitHub API costs.
12
13 ## Why this skill exists
14
15 Netdata maintains ~150 active source repos across the
16 `netdata` GitHub org (the agent monorepo, cloud-* services,
17 ai-agent, charts, helmchart, blogs, dashboards, ...). Routine
18 work (cross-repo grep, "how does service X handle this?",
19 pattern lookup, build) needs all of them locally.
20
21 Without a local mirror:
22 - Each cross-repo question hits the GitHub API.
23 - Searches are paginated and rate-limited.
24 - An AI assistant cannot pipeline grep results across repos.
25 - Iteration speed and reasoning depth fall through the floor.
26
27 With a local mirror at `${NETDATA_REPOS_DIR}`, all of that is
28 fast local I/O.
29
30 This is a **netdata repos mirror, independent from any other
31 repo mirrors this workstation may have**. It exists for this
32 project's cross-repo work; it is not a generic research mirror.
33
34 ## How it works
35
36 The vendored script `scripts/sync-netdata-repos.sh` does two
37 phases:
38
39 ### Phase 1 -- update existing repos
40
41 For each `.git`-bearing subdirectory under `${NETDATA_REPOS_DIR}`,
42 sorted by recent activity (cached in `.repo-activity-cache`):
43
44 - If staged OR modified files exist -> **skip** with details.
45 - Else: detect default branch (master / main / develop),
46 switch to it (committed feature-branch state survives in
47 the branch ref), `git pull`, and `git submodule update
48 --init --force --recursive`.
49
50 ### Phase 2 -- discover and clone new repos
51
52 Runs only when:
53 - no `--repo` flag was given (full sync), AND
54 - `gh` is available AND authenticated.
55
56 Lists `gh repo list netdata --source --no-archived` and clones
57 any that are not yet in the mirror. The `--source --no-archived`
58 filter excludes forks and dead repos -- they add no value for
59 cross-repo grep.
60
61 If `gh` is missing or not authenticated, Phase 2 is skipped
62 with a clear warning. Phase 1 still runs (it uses local `git`
63 only, no GitHub API).
64
65 ## Reset-to-default-branch is the feature, not a hazard
66
67 Sub-repos in a mirror tend to drift onto stale feature
68 branches that no one remembers. A repo whose `HEAD` is on
69 `fix/something-from-six-months-ago` is a **black hole** for
70 cross-repo reasoning -- the assistant grepping it sees
71 out-of-date code and reasons wrong.
72
73 The only viable fix: always reset to the default branch when
74 it's safe to do so. The script's safety conditions:
75
76 - **Untracked files**: OK; they survive checkout.
77 - **Staged or modified files**: NOT safe; script skips the
78 repo and prints what was found.
79 - **Unpushed feature-branch commits**: SAFE; the branch ref
80 preserves them, no data is lost. Script switches to default
81 with a warning summarizing the unpushed commits.
82
83 So the rule is: if you have working changes you want to keep,
84 commit them or stash them before running this. Anything else
85 the script handles correctly.
86
87 ## When to run
88
89 - **Before any cross-repo grep / review** session.
90 - **After a long absence** from the workstation (catches up to
91 upstream on every repo).
92 - **When you've just added a new netdata-org repo**: nothing
93 to do manually; the next full run picks it up via Phase 2.
94 - **Periodically** (daily / weekly) to keep the mirror fresh.
95
96 There's no automation here; the script is interactive (colored
97 output, end-of-run summary). Run it on demand.
98
99 ## Setup
100
101 ### One-time
102
103 1. Pick a directory for the mirror (large; expect 30-50 GB).
104 2. Set `NETDATA_REPOS_DIR` in `<repo>/.env`:
105 ```
106 NETDATA_REPOS_DIR="/path/to/your/mirror"
107 ```
108 3. `mkdir -p "$NETDATA_REPOS_DIR"`.
109 4. Required tools: `git` and `jq`. Install via your package
110 manager.
111 5. For Phase 2 (auto-discovery): install `gh` (the GitHub CLI)
112 and run `gh auth login`. SSH clone access to GitHub for the
113 `netdata` organization must work for clones.
114
115 ### First sync
116
117 ```bash
118 # Source the env, run the script.
119 source <(grep -E '^NETDATA_REPOS_DIR=' <repo>/.env)
120 .agents/skills/mirror-netdata-repos/scripts/sync-netdata-repos.sh
121 ```
122
123 Or with the variable inline:
124
125 ```bash
126 NETDATA_REPOS_DIR="/path/to/mirror" \
127 .agents/skills/mirror-netdata-repos/scripts/sync-netdata-repos.sh
128 ```
129
130 The first run clones every netdata-org source repo. Expect it
131 to take several minutes; subsequent runs are fast (only
132 fetch+pull on each repo).
133
134 ## Common usage
135
136 ### Sync everything (default)
137
138 ```bash
139 .agents/skills/mirror-netdata-repos/scripts/sync-netdata-repos.sh
140 ```
141
142 ### Sync just one or two repos
143
144 ```bash
145 .agents/skills/mirror-netdata-repos/scripts/sync-netdata-repos.sh \
146 --repo netdata \
147 --repo cloud-frontend
148 ```
149
150 `--repo` is repeatable. When any `--repo` is given, Phase 2
151 (discovery) is skipped -- you asked for specific repos, the
152 script does not go looking for new ones.
153
154 ### See help
155
156 ```bash
157 .agents/skills/mirror-netdata-repos/scripts/sync-netdata-repos.sh --help
158 ```
159
160 Works without `NETDATA_REPOS_DIR` set.
161
162 ## Reading the output
163
164 The script prints colored per-repo progress and ends with a
165 summary covering:
166
167 - **Branches switched to default**: every repo that was on a
168 non-default branch and got switched. Inspect this list if
169 you had work in progress.
170 - **Repositories with uncommitted changes (skipped)**: these
171 weren't synced. Commit / stash / revert and re-run.
172 - **Repositories with unpushed commits**: switched to default,
173 but you have feature-branch commits that haven't been
174 pushed. The branch ref preserves them; push when you're
175 ready.
176 - **Repositories on wrong branch**: tried to switch but
177 failed (rare). Manual intervention needed.
178 - **Repositories that failed to update**: fetch or pull
179 failure. Inspect manually.
180
181 ## Adding a new netdata-org repo
182
183 Nothing to do in this skill or its script. Phase 2's
184 `gh repo list netdata --source --no-archived` discovers any
185 new netdata-org repo on the next full sync run. The repo
186 must be:
187
188 - Owned by the `netdata` org (not a fork).
189 - Not archived.
190
191 Otherwise it's skipped intentionally.
192
193 If you want to mirror a fork or an archived repo (rare),
194 clone it manually into `${NETDATA_REPOS_DIR}/<name>` and the
195 next run's Phase 1 will start syncing it.
196
197 ## Sanitization (what the script checks)
198
199 The script refuses to run unsafely. Hard errors (exit 2):
200
201 - `NETDATA_REPOS_DIR` not set.
202 - `NETDATA_REPOS_DIR` set but the directory doesn't exist.
203 - `git` not in `PATH`.
204 - `jq` not in `PATH`.
205
206 Soft warnings (Phase 2 skipped, Phase 1 still runs):
207
208 - `gh` not installed.
209 - `gh` installed but not authenticated.
210
211 ## Limitations
212
213 - **Org is hardcoded** (`netdata`). This skill is
214 netdata-org-specific.
215 - **Filter is hardcoded** (`--source --no-archived`). To
216 mirror forks or archived repos, clone them manually -- the
217 script will then sync them in Phase 1.
218 - **`gh` rate limit**: Phase 2 calls `gh repo list netdata
219 --limit 1000` once per run. On a properly-authed `gh` this
220 is well within the limit.
221 - **Submodule `--force --recursive`**: intentional. Cross-repo
222 review and most build steps depend on accurate, up-to-date
223 submodule state. Local submodule modifications are
224 overwritten -- if you have work-in-progress inside a
225 submodule, commit it before running.
226
227 ## Path discipline
228
229 This skill follows
230 `<repo>/.agents/sow/specs/sensitive-data-discipline.md`:
231
232 - All references to the mirror directory go through
233 `${NETDATA_REPOS_DIR}` (the env key from `.env`).
234 - The script itself contains no hardcoded user paths.
235 - The skill content contains no workstation paths.
236
237 ## See also
238
239 - `<repo>/.agents/skills/mirror-netdata-repos/scripts/sync-netdata-repos.sh`
240 -- the vendored script.
241 - `<repo>/.agents/skills/mirror-netdata-repos/how-tos/INDEX.md`
242 -- live catalog of how-tos.
243 - `<repo>/.env` -- where `NETDATA_REPOS_DIR` lives.