* Persist an explicit user choice (installer toggle or `codegraph * telemetry on|off`). Turning telemetry off also deletes any buffered, * unsent data — off means off.
(enabled: boolean, source: 'installer' | 'cli')
| 263 | * unsent data — off means off. |
| 264 | */ |
| 265 | setEnabled(enabled: boolean, source: 'installer' | 'cli'): void { |
| 266 | const existing = this.readConfig(); |
| 267 | this.writeConfig({ |
| 268 | enabled, |
| 269 | machine_id: enabled ? (existing?.enabled && existing.machine_id ? existing.machine_id : randomUUID()) : null, |
| 270 | consent_source: source, |
| 271 | first_run_notice_shown: true, |
| 272 | updated_at: this.now().toISOString(), |
| 273 | }); |
| 274 | if (!enabled) { |
| 275 | this.clearPending(); |
| 276 | try { |
| 277 | // Claimed data must not reappear on a later opt-in/crash recovery. |
| 278 | for (const name of fs.readdirSync(this.dir)) { |
| 279 | if (name === 'telemetry-queue.jsonl' || /^telemetry-queue\.sending\.\d+\.jsonl$/.test(name)) { |
| 280 | try { fs.rmSync(path.join(this.dir, name), { force: true }); } catch { /* fail silent */ } |
| 281 | } |
| 282 | } |
| 283 | } catch { /* fail silent */ } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | /** True once any consent decision (or the first-run notice) is on disk. */ |
| 288 | hasStoredChoice(): boolean { |
no test coverage detected