-
Notifications
You must be signed in to change notification settings - Fork 453
feat: [ENG-2621] serve analytics disclosure markdown via daemon + canonicalise privacy URL #752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e8de448
feat: [ENG-2621] point PRIVACY_POLICY_URL at the canonical services page
ncnthien 94b1cae
feat: [ENG-2621] serve analytics disclosure markdown via daemon and r…
ncnthien 1275ff0
feat: [ENG-2621] address PR review on analytics disclosure wiring
ncnthien e4f8b10
feat: [ENG-2621] parse disclosure markdown into sections + restore ic…
ncnthien 8cb7599
feat: [ENG-2621] render disclosure section bodies as markdown in the …
ncnthien ed90d74
feat: [ENG-2621] cache parsed disclosure sections + trim handler docs…
ncnthien 1aa060b
feat: [ENG-2621] address PR review on disclosure rendering robustness
ncnthien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/server/infra/transport/handlers/analytics-disclosure-handler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import type {ITransportServer} from '../../../core/interfaces/transport/i-transport-server.js' | ||
|
|
||
| import { | ||
| type AnalyticsDisclosureResponse, | ||
| type AnalyticsDisclosureSection, | ||
| AnalyticsEvents, | ||
| } from '../../../../shared/transport/events/analytics-events.js' | ||
| import {loadAnalyticsDisclosureText} from '../../../../shared/utils/load-analytics-disclosure.js' | ||
| import {parseAnalyticsDisclosure} from '../../../../shared/utils/parse-analytics-disclosure.js' | ||
|
|
||
| export interface AnalyticsDisclosureHandlerDeps { | ||
| readonly loadDisclosure?: () => Promise<string> | ||
| readonly transport: ITransportServer | ||
| } | ||
|
|
||
| export class AnalyticsDisclosureHandler { | ||
| private cachedSections: AnalyticsDisclosureSection[] | undefined | ||
| private readonly loadDisclosure: () => Promise<string> | ||
| private readonly transport: ITransportServer | ||
|
|
||
| public constructor(deps: AnalyticsDisclosureHandlerDeps) { | ||
| this.loadDisclosure = deps.loadDisclosure ?? loadAnalyticsDisclosureText | ||
| this.transport = deps.transport | ||
| } | ||
|
|
||
| public setup(): void { | ||
| this.transport.onRequest<void, AnalyticsDisclosureResponse>(AnalyticsEvents.GET_DISCLOSURE, async () => ({ | ||
| sections: await this.getSections(), | ||
| })) | ||
| } | ||
|
|
||
| private async getSections(): Promise<AnalyticsDisclosureSection[]> { | ||
| if (this.cachedSections) return this.cachedSections | ||
|
|
||
| const markdown = await this.loadDisclosure() | ||
| const sections = parseAnalyticsDisclosure(markdown) | ||
| if (sections.length === 0) { | ||
| throw new Error('Analytics disclosure is missing or contains no sections.') | ||
| } | ||
|
|
||
| this.cachedSections = sections | ||
| return sections | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1 @@ | ||
| /** | ||
| * Public privacy policy URL for ByteRover CLI analytics. | ||
| * Placeholder until M1.5 lands the canonical docs page; reviewers should | ||
| * update this constant when the byterover-docs URL is finalized. | ||
| */ | ||
| export const PRIVACY_POLICY_URL = 'https://byterover.dev/privacy' | ||
| export const PRIVACY_POLICY_URL = 'https://www.byterover.dev/services/privacy' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| export type AnalyticsDisclosureSection = { | ||
| body: string | ||
| label: string | ||
| } | ||
|
|
||
| const H2_PATTERN = /^##\s+(.+?)\s*$/ | ||
|
|
||
| export function parseAnalyticsDisclosure(markdown: string): AnalyticsDisclosureSection[] { | ||
| const sections: AnalyticsDisclosureSection[] = [] | ||
| let currentLabel: string | undefined | ||
| let currentBodyLines: string[] = [] | ||
|
|
||
| function pushCurrent() { | ||
| if (currentLabel === undefined) return | ||
| const body = currentBodyLines.join('\n').trim() | ||
| if (body.length > 0) sections.push({body, label: currentLabel}) | ||
| } | ||
|
|
||
| for (const line of markdown.split('\n')) { | ||
| const match = H2_PATTERN.exec(line) | ||
| if (match) { | ||
| pushCurrent() | ||
| currentLabel = match[1] | ||
| currentBodyLines = [] | ||
| continue | ||
| } | ||
|
|
||
| if (currentLabel !== undefined) currentBodyLines.push(line) | ||
| } | ||
|
|
||
| pushCurrent() | ||
| return sections | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/webui/features/analytics/api/get-analytics-disclosure.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import {queryOptions, useQuery} from '@tanstack/react-query' | ||
|
|
||
| import type {QueryConfig} from '../../../lib/react-query' | ||
|
|
||
| import { | ||
| type AnalyticsDisclosureResponse, | ||
| AnalyticsEvents, | ||
| } from '../../../../shared/transport/events/analytics-events.js' | ||
| import {useTransportStore} from '../../../stores/transport-store' | ||
|
|
||
| export const getAnalyticsDisclosure = (): Promise<AnalyticsDisclosureResponse> => { | ||
| const {apiClient} = useTransportStore.getState() | ||
| if (!apiClient) return Promise.reject(new Error('Not connected')) | ||
| return apiClient.request<AnalyticsDisclosureResponse, void>(AnalyticsEvents.GET_DISCLOSURE) | ||
| } | ||
|
|
||
| export const getAnalyticsDisclosureQueryOptions = () => | ||
| queryOptions({ | ||
| queryFn: getAnalyticsDisclosure, | ||
| queryKey: ['analyticsDisclosure'], | ||
| staleTime: Number.POSITIVE_INFINITY, | ||
| }) | ||
|
ncnthien marked this conversation as resolved.
|
||
|
|
||
| type UseGetAnalyticsDisclosureOptions = { | ||
| queryConfig?: QueryConfig<typeof getAnalyticsDisclosureQueryOptions> | ||
| } | ||
|
|
||
| export const useGetAnalyticsDisclosure = ({queryConfig}: UseGetAnalyticsDisclosureOptions = {}) => | ||
| useQuery({ | ||
| ...getAnalyticsDisclosureQueryOptions(), | ||
| ...queryConfig, | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 63 additions & 6 deletions
69
src/webui/features/analytics/components/disclosure-details.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.