Skip to content

Commit 5db5cf4

Browse files
committed
Merge remote-tracking branch 'upstream/main' into feat/dte-1-experiment
2 parents 1cf4f0d + 1ad8f52 commit 5db5cf4

61 files changed

Lines changed: 1050 additions & 150 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎PRIVACY.md‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Zoo Code Privacy Policy
22

3-
**Last Updated: May 13th, 2026**
3+
**Last Updated: August 15th, 2026**
44

55
Zoo Code respects your privacy and is committed to transparency about how we
66
handle your data. Below is a simple breakdown of where key pieces of data
@@ -32,14 +32,18 @@ go—and, importantly, where they don't.
3232
- **API Keys & Credentials**: If you enter an API key (e.g., to connect an AI
3333
model), it is stored locally on your device and never sent to us or any third
3434
party, except the provider you have chosen.
35-
- **Telemetry (Usage Data)**: We collect feature usage and error data to help
36-
us improve Zoo Code. This telemetry is powered by PostHog and includes your
37-
VS Code machine ID, feature usage patterns, and exception reports. The VS Code
35+
- **Telemetry (Usage Data)**: We collect feature usage and error data to help us
36+
improve Zoo Code. This telemetry is powered by PostHog and includes your VS
37+
Code machine ID, feature usage patterns, and exception reports. The VS Code
3838
machine ID is a persistent identifier and may be considered personal data in
3939
some jurisdictions; we use it only for product analytics and error grouping.
40-
We retain telemetry only as long as needed for product analytics and debugging.
41-
Telemetry does **not** collect your code or AI prompts, and you can opt out at
42-
any time through the settings.
40+
PostHog event data is retained for 12 months under our current project
41+
configuration. This PostHog-based telemetry does **not** collect your code or AI
42+
prompts. Telemetry is on by default. To turn it off, choose "Disabled" in
43+
the settings or in the notice shown on first use. The notice remains until
44+
you explicitly Accept or Decline. Telemetry also follows VS Code's own
45+
global telemetry setting: if you turn that off, Zoo Code stops sending
46+
telemetry right away, even if the Zoo Code setting says "Enabled."
4347
- **Marketplace Requests**: When you browse or search the Marketplace for Model
4448
Configuration Profiles (MCPs) or Custom Modes, Zoo Code makes a secure API
4549
call to Zoo Code's backend servers to retrieve listing information. These

‎codecov.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ flag_management:
4242
- packages/core/src/
4343
carryforward: true
4444

45+
ignore:
46+
# Playwright CT-only fixtures/helpers: exercised by the webview-ui-ct flag's browser run, not
47+
# Vitest, and excluded from that flag's own lcov by playwright-ct.config.ts's sourceFilter (same
48+
# ".visual." match). Without this, patch coverage sees 0% for these paths on any PR that adds or
49+
# touches one, since no flag's lcov contains them.
50+
- "webview-ui/src/**/*.visual.fixture.tsx"
51+
- "webview-ui/src/**/*.visual.i18n.ts"
52+
4553
component_management:
4654
individual_components:
4755
- component_id: webview_components
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// pnpm --filter @roo-code/types test src/__tests__/telemetry.isTelemetryOptedIn.test.ts
2+
3+
import { isTelemetryOptedIn } from "../telemetry.js"
4+
5+
describe("isTelemetryOptedIn", () => {
6+
it("returns true for an explicit 'enabled' setting", () => {
7+
expect(isTelemetryOptedIn("enabled")).toBe(true)
8+
})
9+
10+
it("returns false for an explicit 'disabled' setting", () => {
11+
expect(isTelemetryOptedIn("disabled")).toBe(false)
12+
})
13+
14+
it("returns true for 'unset' (disclosed opt-out default applies)", () => {
15+
expect(isTelemetryOptedIn("unset")).toBe(true)
16+
})
17+
18+
it("returns true for undefined (treated the same as unset)", () => {
19+
expect(isTelemetryOptedIn(undefined)).toBe(true)
20+
})
21+
})

‎packages/types/src/telemetry.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ export const telemetrySettingsSchema = z.enum(telemetrySettings)
1313

1414
export type TelemetrySetting = z.infer<typeof telemetrySettingsSchema>
1515

16+
/**
17+
* Whether telemetry should be captured for this install.
18+
*
19+
* Telemetry is on by default (disclosed opt-out): "unset" (no choice made yet) and
20+
* "enabled" both mean telemetry may be captured. Only an explicit "disabled" opts out.
21+
* The consent banner's dismiss/close action never writes a setting, so it stays neutral --
22+
* it just leaves the default in effect rather than recording an affirmative choice either way.
23+
*/
24+
export function isTelemetryOptedIn(telemetrySetting: TelemetrySetting | undefined): boolean {
25+
return telemetrySetting !== "disabled"
26+
}
27+
1628
/**
1729
* TelemetryEventName
1830
*/

‎packages/types/src/vscode-extension-host.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ export type ExtensionState = Pick<
364364
telemetrySetting: TelemetrySetting
365365
telemetryKey?: string
366366
machineId?: string
367+
// Live vscode.env.isTelemetryEnabled, so the webview's own PostHog client can respect
368+
// the VS Code global telemetry toggle the same way the extension-side gate does --
369+
// without this, an explicit user Accept can still send events while VS Code's global
370+
// telemetry is disabled.
371+
vscodeTelemetryEnabled?: boolean
367372

368373
renderContext: "sidebar" | "editor"
369374
settingsImportedAt?: number

‎src/__tests__/extension.spec.ts‎

Lines changed: 195 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ vi.mock("vscode", () => ({
3636
},
3737
env: {
3838
language: "en",
39+
isTelemetryEnabled: true,
40+
onDidChangeTelemetryEnabled: vi.fn(),
3941
},
4042
ExtensionMode: {
4143
Production: 1,
@@ -72,19 +74,19 @@ vi.mock("@roo-code/cloud", () => ({
7274
getRooCodeApiUrl: vi.fn().mockReturnValue("https://app.roocode.com"),
7375
}))
7476

77+
const mockTelemetryServiceInstance = {
78+
register: vi.fn(),
79+
setProvider: vi.fn(),
80+
shutdown: vi.fn(),
81+
updateTelemetryState: vi.fn(),
82+
}
83+
7584
vi.mock("@roo-code/telemetry", () => ({
7685
TelemetryService: {
77-
createInstance: vi.fn().mockReturnValue({
78-
register: vi.fn(),
79-
setProvider: vi.fn(),
80-
shutdown: vi.fn(),
81-
}),
86+
createInstance: vi.fn().mockReturnValue(mockTelemetryServiceInstance),
87+
hasInstance: vi.fn().mockReturnValue(true),
8288
get instance() {
83-
return {
84-
register: vi.fn(),
85-
setProvider: vi.fn(),
86-
shutdown: vi.fn(),
87-
}
89+
return mockTelemetryServiceInstance
8890
},
8991
},
9092
PostHogTelemetryClient: vi.fn(),
@@ -114,6 +116,7 @@ vi.mock("../core/config/ContextProxy", () => ({
114116
setValue: vi.fn(),
115117
getValues: vi.fn().mockReturnValue({}),
116118
getProviderSettings: vi.fn().mockReturnValue({}),
119+
getGlobalState: vi.fn().mockReturnValue("enabled"),
117120
}),
118121
},
119122
}))
@@ -286,7 +289,7 @@ describe("extension.ts", () => {
286289
telemetryClient: null,
287290
authService: null,
288291
hasActiveSession: vi.fn().mockReturnValue(false),
289-
} as any
292+
} as unknown as never
290293
})
291294

292295
vi.mocked(CloudService.hasInstance).mockReturnValue(true)
@@ -295,7 +298,11 @@ describe("extension.ts", () => {
295298
const { activate } = await import("../extension")
296299
await activate(mockContext)
297300

298-
const provider = (ClineProvider as any).getVisibleInstance()
301+
const provider = (
302+
ClineProvider as unknown as {
303+
getVisibleInstance(): { postStateToWebviewWithoutClineMessages: ReturnType<typeof vi.fn> }
304+
}
305+
).getVisibleInstance()
299306
provider.postStateToWebviewWithoutClineMessages.mockClear()
300307

301308
await authStateChangedHandler!({
@@ -317,4 +324,180 @@ describe("extension.ts", () => {
317324
await expect(activate(mockContext)).resolves.toBeDefined()
318325
})
319326
})
327+
328+
describe("telemetry level reactivity", () => {
329+
beforeEach(async () => {
330+
vi.resetModules()
331+
const vscode = await import("vscode")
332+
;(vscode.env as { isTelemetryEnabled: boolean }).isTelemetryEnabled = true
333+
})
334+
335+
test("registers a listener for vscode.env.onDidChangeTelemetryEnabled", async () => {
336+
const vscode = await import("vscode")
337+
338+
const { activate } = await import("../extension")
339+
await activate(mockContext)
340+
341+
expect(vscode.env.onDidChangeTelemetryEnabled).toHaveBeenCalledTimes(1)
342+
expect(vscode.env.onDidChangeTelemetryEnabled).toHaveBeenCalledWith(expect.any(Function))
343+
})
344+
345+
test("re-evaluates telemetry state from stored settings when VS Code's global toggle changes", async () => {
346+
const vscode = await import("vscode")
347+
const { TelemetryService } = await import("@roo-code/telemetry")
348+
const { ContextProxy } = await import("../core/config/ContextProxy")
349+
350+
const mockContextProxyInstance = await (
351+
ContextProxy.getInstance as unknown as () => Promise<{ getGlobalState: ReturnType<typeof vi.fn> }>
352+
)()
353+
vi.mocked(mockContextProxyInstance.getGlobalState).mockReturnValue("enabled")
354+
;(vscode.env as { isTelemetryEnabled: boolean }).isTelemetryEnabled = true
355+
356+
const { activate } = await import("../extension")
357+
await activate(mockContext)
358+
359+
const updateTelemetryStateMock = vi.mocked(TelemetryService.instance.updateTelemetryState)
360+
updateTelemetryStateMock.mockClear()
361+
362+
// The real vscode.env.onDidChangeTelemetryEnabled event carries no payload; the handler
363+
// must read the current vscode.env.isTelemetryEnabled value, not any argument it's called with.
364+
const onDidChangeHandler = vi.mocked(vscode.env.onDidChangeTelemetryEnabled).mock.calls[0][0]
365+
onDidChangeHandler(undefined as never)
366+
367+
expect(updateTelemetryStateMock).toHaveBeenCalledWith(true)
368+
})
369+
370+
test("treats a disabled stored setting as opted out even when VS Code telemetry is enabled", async () => {
371+
const vscode = await import("vscode")
372+
const { TelemetryService } = await import("@roo-code/telemetry")
373+
const { ContextProxy } = await import("../core/config/ContextProxy")
374+
375+
const mockContextProxyInstance = await (
376+
ContextProxy.getInstance as unknown as () => Promise<{ getGlobalState: ReturnType<typeof vi.fn> }>
377+
)()
378+
vi.mocked(mockContextProxyInstance.getGlobalState).mockReturnValue("disabled")
379+
;(vscode.env as { isTelemetryEnabled: boolean }).isTelemetryEnabled = true
380+
381+
const { activate } = await import("../extension")
382+
await activate(mockContext)
383+
384+
const updateTelemetryStateMock = vi.mocked(TelemetryService.instance.updateTelemetryState)
385+
updateTelemetryStateMock.mockClear()
386+
387+
const onDidChangeHandler = vi.mocked(vscode.env.onDidChangeTelemetryEnabled).mock.calls[0][0]
388+
onDidChangeHandler(undefined as never)
389+
390+
expect(updateTelemetryStateMock).toHaveBeenCalledWith(false)
391+
})
392+
393+
test("treats VS Code's live telemetry-disabled signal as opted out even when the stored setting is enabled", async () => {
394+
const vscode = await import("vscode")
395+
const { TelemetryService } = await import("@roo-code/telemetry")
396+
const { ContextProxy } = await import("../core/config/ContextProxy")
397+
398+
const mockContextProxyInstance = await (
399+
ContextProxy.getInstance as unknown as () => Promise<{ getGlobalState: ReturnType<typeof vi.fn> }>
400+
)()
401+
vi.mocked(mockContextProxyInstance.getGlobalState).mockReturnValue("enabled")
402+
;(vscode.env as { isTelemetryEnabled: boolean }).isTelemetryEnabled = true
403+
404+
const { activate } = await import("../extension")
405+
await activate(mockContext)
406+
407+
const updateTelemetryStateMock = vi.mocked(TelemetryService.instance.updateTelemetryState)
408+
updateTelemetryStateMock.mockClear()
409+
410+
// Simulate the user turning off VS Code's global telemetry toggle: the live env value
411+
// flips before the event fires, and the handler must honor it rather than only the
412+
// stored extension setting.
413+
;(vscode.env as { isTelemetryEnabled: boolean }).isTelemetryEnabled = false
414+
415+
const onDidChangeHandler = vi.mocked(vscode.env.onDidChangeTelemetryEnabled).mock.calls[0][0]
416+
onDidChangeHandler(undefined as never)
417+
418+
expect(updateTelemetryStateMock).toHaveBeenCalledWith(false)
419+
})
420+
421+
test("pushes a state update to the webview so its own PostHog client picks up the new vscode.env.isTelemetryEnabled value", async () => {
422+
const vscode = await import("vscode")
423+
const { ClineProvider } = await import("../core/webview/ClineProvider")
424+
425+
const { activate } = await import("../extension")
426+
await activate(mockContext)
427+
428+
const visibleInstance = (
429+
ClineProvider as unknown as {
430+
getVisibleInstance(): { postStateToWebviewWithoutClineMessages: ReturnType<typeof vi.fn> }
431+
}
432+
).getVisibleInstance()
433+
vi.mocked(visibleInstance.postStateToWebviewWithoutClineMessages).mockClear()
434+
435+
const onDidChangeHandler = vi.mocked(vscode.env.onDidChangeTelemetryEnabled).mock.calls[0][0]
436+
onDidChangeHandler(undefined as never)
437+
438+
expect(visibleInstance.postStateToWebviewWithoutClineMessages).toHaveBeenCalled()
439+
})
440+
})
441+
442+
describe("deactivate", () => {
443+
beforeEach(() => {
444+
vi.resetModules()
445+
})
446+
447+
test("still runs terminal cleanup when telemetry shutdown rejects", async () => {
448+
const { TelemetryService } = await import("@roo-code/telemetry")
449+
const { Terminal } = await import("../integrations/terminal/Terminal")
450+
const { TerminalRegistry } = await import("../integrations/terminal/TerminalRegistry")
451+
452+
vi.mocked(TelemetryService.instance.shutdown).mockRejectedValue(new Error("shutdown failed"))
453+
const setTerminalProfileSpy = vi.spyOn(Terminal, "setTerminalProfile")
454+
455+
const { activate, deactivate } = await import("../extension")
456+
await activate(mockContext)
457+
458+
await expect(deactivate()).resolves.toBeUndefined()
459+
460+
expect(setTerminalProfileSpy).toHaveBeenCalledWith(undefined)
461+
expect(TerminalRegistry.cleanup).toHaveBeenCalledTimes(1)
462+
463+
setTerminalProfileSpy.mockRestore()
464+
})
465+
466+
// Review finding: every other TelemetryService call site touched by this PR checks
467+
// hasInstance() first; deactivate()'s shutdown call didn't. Not a crash today (the mock
468+
// always resolves), but TelemetryService.instance throws for real if no instance exists,
469+
// so the guard keeps this call site consistent with the rest of the file.
470+
test("does not touch TelemetryService.instance when no instance exists", async () => {
471+
const { TelemetryService } = await import("@roo-code/telemetry")
472+
const { Terminal } = await import("../integrations/terminal/Terminal")
473+
const { TerminalRegistry } = await import("../integrations/terminal/TerminalRegistry")
474+
475+
const setTerminalProfileSpy = vi.spyOn(Terminal, "setTerminalProfile")
476+
477+
const { activate, deactivate } = await import("../extension")
478+
await activate(mockContext)
479+
480+
// Flip to false only after activate() completes, so this only exercises
481+
// deactivate()'s own guard rather than any hasInstance() check during activation.
482+
vi.mocked(TelemetryService.hasInstance).mockReturnValue(false)
483+
484+
// Model the real singleton failure mode: TelemetryService.instance throws when no
485+
// instance exists. If deactivate()'s hasInstance() guard were ever removed, this
486+
// throw would surface instead of the assertion below silently passing regardless.
487+
const instanceGetterSpy = vi.spyOn(TelemetryService, "instance", "get").mockImplementation(() => {
488+
throw new Error("TelemetryService not initialized")
489+
})
490+
491+
await expect(deactivate()).resolves.toBeUndefined()
492+
493+
expect(instanceGetterSpy).not.toHaveBeenCalled()
494+
expect(mockTelemetryServiceInstance.shutdown).not.toHaveBeenCalled()
495+
expect(setTerminalProfileSpy).toHaveBeenCalledWith(undefined)
496+
expect(TerminalRegistry.cleanup).toHaveBeenCalledTimes(1)
497+
498+
instanceGetterSpy.mockRestore()
499+
500+
setTerminalProfileSpy.mockRestore()
501+
})
502+
})
320503
})

‎src/core/webview/ClineProvider.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,6 +2593,7 @@ export class ClineProvider
25932593

25942594
const telemetryKey = process.env.POSTHOG_API_KEY
25952595
const machineId = vscode.env.machineId
2596+
const vscodeTelemetryEnabled = vscode.env.isTelemetryEnabled
25962597
const mergedAllowedCommands = this.mergeAllowedCommands(allowedCommands)
25972598
const mergedDeniedCommands = this.mergeDeniedCommands(deniedCommands)
25982599
const cwd = this.cwd
@@ -2696,6 +2697,7 @@ export class ClineProvider
26962697
telemetrySetting,
26972698
telemetryKey,
26982699
machineId,
2700+
vscodeTelemetryEnabled,
26992701
showRooIgnoredFiles: showRooIgnoredFiles ?? false,
27002702
enableSubfolderRules: enableSubfolderRules ?? false,
27012703
language: language ?? formatLanguage(vscode.env.language),

0 commit comments

Comments
 (0)