feat(cli-analytics): scaffold @posthog/cli-analytics package#3890
feat(cli-analytics): scaffold @posthog/cli-analytics package#3890DanielVisca wants to merge 1 commit into
Conversation
New SDK for command-line tools, sibling to @posthog/mcp. This base sets up the package (build, lint, test config), shared types, the $cli_* event and property schema, and the id/logger primitives. Generated-By: PostHog Code Task-Id: b56cf1bb-97f1-4daf-a65c-01a2cdb12eaa
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
📝 No Changeset FoundThis PR doesn't include a changeset. A changeset is required to release a new version. How to add a changesetRun this command and follow the prompts: pnpm changesetRemember: Never use |
Prompt To Fix All With AIFix the following 3 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 3
packages/cli-analytics/src/__tests__/ids.test.ts:4-8
Per project conventions, parameterised tests are preferred. The multiple `expect` assertions in `'prefixes generated ids'` are a natural fit for `it.each` — each prefix becomes an independent test case with its own pass/fail signal.
```suggestion
it.each(['evt', 'ses', 'anon'] as const)('prefixes generated id with %s', (prefix) => {
expect(newPrefixedId(prefix)).toMatch(new RegExp(`^${prefix}_`))
})
```
### Issue 2 of 3
packages/cli-analytics/src/extensions/logger.ts:12-16
**Module-level logger is a process-wide singleton**
`activeLogger` is module-level state shared across every instance of `CliAnalytics` in the same process. Two callers calling `instrument()` with different `logger` options will overwrite each other, and Jest's `clearMocks` won't reset it between tests. If the logger is an instance concern rather than a process-level facility, passing it through the call-site context (e.g., captured in a closure when the analytics instance is created) would isolate instances cleanly.
### Issue 3 of 3
packages/cli-analytics/src/extensions/ids.ts:32-33
The multipliers used here are not valid FNV primes and produce poor avalanche effect. `0x000001b3` (435) and `0x00000193` (403) are only the low 9 bits of the 64-bit FNV prime and the 32-bit FNV prime respectively — the critical high bits are missing. With these tiny multipliers, a `Math.imul` only propagates carries through ~9 bits of the 32-bit output, so most input bits have no effect on the upper half of each word. The correct 32-bit FNV-1a prime is `0x01000193` (16777619).
```suggestion
h1 = Math.imul(h1 ^ c, 0x01000193)
h2 = Math.imul(h2 ^ c, 0x01000193)
```
Reviews (1): Last reviewed commit: "feat(cli-analytics): scaffold @posthog/c..." | Re-trigger Greptile |
| it('prefixes generated ids', () => { | ||
| expect(newPrefixedId('evt')).toMatch(/^evt_/) | ||
| expect(newPrefixedId('ses')).toMatch(/^ses_/) | ||
| expect(newPrefixedId('anon')).toMatch(/^anon_/) | ||
| }) |
There was a problem hiding this comment.
Per project conventions, parameterised tests are preferred. The multiple
expect assertions in 'prefixes generated ids' are a natural fit for it.each — each prefix becomes an independent test case with its own pass/fail signal.
| it('prefixes generated ids', () => { | |
| expect(newPrefixedId('evt')).toMatch(/^evt_/) | |
| expect(newPrefixedId('ses')).toMatch(/^ses_/) | |
| expect(newPrefixedId('anon')).toMatch(/^anon_/) | |
| }) | |
| it.each(['evt', 'ses', 'anon'] as const)('prefixes generated id with %s', (prefix) => { | |
| expect(newPrefixedId(prefix)).toMatch(new RegExp(`^${prefix}_`)) | |
| }) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cli-analytics/src/__tests__/ids.test.ts
Line: 4-8
Comment:
Per project conventions, parameterised tests are preferred. The multiple `expect` assertions in `'prefixes generated ids'` are a natural fit for `it.each` — each prefix becomes an independent test case with its own pass/fail signal.
```suggestion
it.each(['evt', 'ses', 'anon'] as const)('prefixes generated id with %s', (prefix) => {
expect(newPrefixedId(prefix)).toMatch(new RegExp(`^${prefix}_`))
})
```
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| let activeLogger: LoggerFn | undefined | ||
|
|
||
| export function setLogger(logger: LoggerFn | undefined): void { | ||
| activeLogger = logger | ||
| } |
There was a problem hiding this comment.
Module-level logger is a process-wide singleton
activeLogger is module-level state shared across every instance of CliAnalytics in the same process. Two callers calling instrument() with different logger options will overwrite each other, and Jest's clearMocks won't reset it between tests. If the logger is an instance concern rather than a process-level facility, passing it through the call-site context (e.g., captured in a closure when the analytics instance is created) would isolate instances cleanly.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cli-analytics/src/extensions/logger.ts
Line: 12-16
Comment:
**Module-level logger is a process-wide singleton**
`activeLogger` is module-level state shared across every instance of `CliAnalytics` in the same process. Two callers calling `instrument()` with different `logger` options will overwrite each other, and Jest's `clearMocks` won't reset it between tests. If the logger is an instance concern rather than a process-level facility, passing it through the call-site context (e.g., captured in a closure when the analytics instance is created) would isolate instances cleanly.
How can I resolve this? If you propose a fix, please make it concise.| h1 = Math.imul(h1 ^ c, 0x000001b3) | ||
| h2 = Math.imul(h2 ^ c, 0x00000193) |
There was a problem hiding this comment.
The multipliers used here are not valid FNV primes and produce poor avalanche effect.
0x000001b3 (435) and 0x00000193 (403) are only the low 9 bits of the 64-bit FNV prime and the 32-bit FNV prime respectively — the critical high bits are missing. With these tiny multipliers, a Math.imul only propagates carries through ~9 bits of the 32-bit output, so most input bits have no effect on the upper half of each word. The correct 32-bit FNV-1a prime is 0x01000193 (16777619).
| h1 = Math.imul(h1 ^ c, 0x000001b3) | |
| h2 = Math.imul(h2 ^ c, 0x00000193) | |
| h1 = Math.imul(h1 ^ c, 0x01000193) | |
| h2 = Math.imul(h2 ^ c, 0x01000193) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cli-analytics/src/extensions/ids.ts
Line: 32-33
Comment:
The multipliers used here are not valid FNV primes and produce poor avalanche effect. `0x000001b3` (435) and `0x00000193` (403) are only the low 9 bits of the 64-bit FNV prime and the 32-bit FNV prime respectively — the critical high bits are missing. With these tiny multipliers, a `Math.imul` only propagates carries through ~9 bits of the 32-bit output, so most input bits have no effect on the upper half of each word. The correct 32-bit FNV-1a prime is `0x01000193` (16777619).
```suggestion
h1 = Math.imul(h1 ^ c, 0x01000193)
h2 = Math.imul(h2 ^ c, 0x01000193)
```
How can I resolve this? If you propose a fix, please make it concise.|
Size Change: 0 B Total Size: 17 MB ℹ️ View Unchanged
|
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the |
|
This PR was closed due to lack of activity. Feel free to reopen if it's still relevant. |

Problem
Changes
Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted) — or — Fully autonomous
Created with PostHog Code