Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"nanostores": "^1.1.1",
"opn": "^5.4.0",
"pi-mcp-adapter": "~5.2.0",
"posthog-node": "^5.45.2",
"posthog-node": "^6.0.5",
"react": "^19.2.4",
"read-cmd-shim": "^6.0.0",
"read-env": "^1.3.0",
Expand Down
32 changes: 19 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/agent/runner/sequence/linear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ async function executeLinear(
matchKeys,
installDir: input.installDir,
triageProvider: boot.triageProvider,
reportTelemetry: config.reportDiscoveryTelemetry?.() ?? false,
signal,
});
if (traitInstall.aborted) return aborted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ describe('installTraitSkills', () => {
yaraScanResult = null;
seenProviders.length = 0;
vi.mocked(analytics.wizardCapture).mockClear();
vi.mocked(analytics.setTag).mockClear();
});

afterEach(() => {
Expand All @@ -146,13 +147,77 @@ describe('installTraitSkills', () => {
matchKeys: { posthogSdks: ['posthog-node@5'] },
installDir: dir,
triageProvider: provider,
reportTelemetry: true,
});

expect(result).toEqual({ paths: [], aborted: false });
expect(seenProviders).toEqual([provider]);
expect(analytics.setTag).not.toHaveBeenCalledWith(
'sdk_skills',
expect.anything(),
);
expect(analytics.setTag).toHaveBeenCalledWith(
'sdk_non_default_major',
false,
);
expect(analytics.wizardCapture).toHaveBeenCalledWith(
'sdk skills resolved',
{
resolved_sdk_skill_ids: [],
non_default_sdk_skill_ids: [],
failed_sdk_skill_ids: ['sdk-posthog-node-v5'],
unmatched_sdks: [],
},
);
});

it('reports default skills and unmatched_sdks with sdk_skills tags when telemetry is allowed', async () => {
const entries = mockMenuAndZip();

const result = await installTraitSkills({
entries,
matchKeys: { posthogSdks: ['posthog-node@6', 'rubygems:posthog-ruby@3'] },
installDir: dir,
triageProvider: undefined,
reportTelemetry: true,
});

expect(result.aborted).toBe(false);
expect(analytics.setTag).toHaveBeenCalledWith(
'sdk_skills',
'sdk-posthog-node-v6',
);
expect(analytics.setTag).toHaveBeenCalledWith(
'sdk_non_default_major',
false,
);
expect(analytics.wizardCapture).toHaveBeenCalledWith(
'sdk trait skill resolved',
{ skill_id: 'sdk-posthog-node-v5', installed: false },
'sdk skills resolved',
{
resolved_sdk_skill_ids: ['sdk-posthog-node-v6'],
non_default_sdk_skill_ids: [],
failed_sdk_skill_ids: [],
unmatched_sdks: ['rubygems:posthog-ruby@3'],
},
);
});

it('emits neither sdk skills resolved nor SDK tags when reportTelemetry is false', async () => {
const entries = mockMenuAndZip();

const result = await installTraitSkills({
entries,
matchKeys: { posthogSdks: ['posthog-node@5', 'rubygems:posthog-ruby@3'] },
installDir: dir,
triageProvider: undefined,
reportTelemetry: false,
});

expect(result.paths).toHaveLength(1);
expect(analytics.setTag).not.toHaveBeenCalled();
expect(analytics.wizardCapture).not.toHaveBeenCalledWith(
'sdk skills resolved',
expect.anything(),
);
});

Expand Down Expand Up @@ -192,6 +257,7 @@ describe('runOrchestrator with trait SDK skills', () => {
framework: ['nextjs'],
posthogSdks: ['posthog-node@5'],
}),
reportDiscoveryTelemetry: () => true,
},
input: { installDir: dir, flags: { ci: true } },
boot: {
Expand All @@ -218,6 +284,7 @@ describe('runOrchestrator with trait SDK skills', () => {
seenProviders.length = 0;
seenTaskPrompt = '';
vi.mocked(analytics.wizardCapture).mockClear();
vi.mocked(analytics.setTag).mockClear();
});

afterEach(() => {
Expand All @@ -236,9 +303,22 @@ describe('runOrchestrator with trait SDK skills', () => {
expect(seenTaskPrompt).toContain(
path.join('.claude', 'skills', 'sdk-posthog-node-v5', 'SKILL.md'),
);
expect(analytics.setTag).toHaveBeenCalledWith(
'sdk_skills',
'sdk-posthog-node-v5',
);
expect(analytics.setTag).toHaveBeenCalledWith(
'sdk_non_default_major',
true,
);
expect(analytics.wizardCapture).toHaveBeenCalledWith(
'sdk trait skill resolved',
{ skill_id: 'sdk-posthog-node-v5', installed: true },
'sdk skills resolved',
{
resolved_sdk_skill_ids: ['sdk-posthog-node-v5'],
non_default_sdk_skill_ids: ['sdk-posthog-node-v5'],
failed_sdk_skill_ids: [],
unmatched_sdks: [],
},
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ async function executeOrchestrator(
matchKeys,
installDir: input.installDir,
triageProvider: boot.triageProvider,
reportTelemetry: config.reportDiscoveryTelemetry?.() ?? false,
signal,
});
if (traitInstall.aborted) return cancelledRun();
Expand Down
37 changes: 32 additions & 5 deletions src/agent/runner/shared/trait-skills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { LLMProvider } from '@posthog/warlock';
import { downloadSkill } from '@shared/skill-install';
import type { SkillEntry } from '@shared/skill-menu';
import {
DEFAULT_SKILL_TAG,
FRAMEWORK_KEY,
resolveTraitSkills,
type MatchKeys,
Expand All @@ -31,38 +32,64 @@ export async function installTraitSkills({
matchKeys,
installDir,
triageProvider,
reportTelemetry = false,
signal,
}: {
entries: readonly SkillEntry[];
matchKeys: MatchKeys;
installDir: string;
triageProvider: LLMProvider | undefined;
reportTelemetry?: boolean;
signal?: AbortSignal;
}): Promise<{ paths: string[]; aborted: boolean }> {
const paths: string[] = [];
if (signal?.aborted) return { paths, aborted: true };

for (const skill of resolveTraitSkills(entries, matchKeys)) {
const matched = resolveTraitSkills(entries, matchKeys);
const resolvedIds: string[] = [];
const nonDefaultIds: string[] = [];
const failedIds: string[] = [];

for (const skill of matched) {
if (signal?.aborted) return { paths, aborted: true };
const installed = await downloadSkill(skill, installDir, {
scan: (dir) => scanInstalledSkill(dir, triageProvider),
});
if (signal?.aborted) return { paths, aborted: true };
analytics.wizardCapture('sdk trait skill resolved', {
skill_id: skill.id,
installed: installed.success,
});
if (!installed.success) {
failedIds.push(skill.id);
logToFile(
`[sdk-skills] unavailable ${skill.id}: ${
installed.error ?? 'unknown error'
}`,
);
continue;
}
resolvedIds.push(skill.id);
if (!skill.tags?.includes(DEFAULT_SKILL_TAG)) {
nonDefaultIds.push(skill.id);
}
const skillPath = path.join('.claude', 'skills', skill.id, 'SKILL.md');
paths.push(skillPath);
logToFile(`[sdk-skills] installed ${skill.id} at ${skillPath}`);
}

const declaredSdks = matchKeys.posthogSdks ?? [];
if (reportTelemetry && (declaredSdks.length > 0 || matched.length > 0)) {
const matchedTags = new Set(matched.flatMap((skill) => skill.tags ?? []));
const unmatchedSdks = declaredSdks.filter(
(sdk) => !matchedTags.has(`posthogSdks:${sdk}`),
);
if (resolvedIds.length > 0) {
analytics.setTag('sdk_skills', resolvedIds.join(','));
}
analytics.setTag('sdk_non_default_major', nonDefaultIds.length > 0);
analytics.wizardCapture('sdk skills resolved', {
Comment thread
veria-ai[bot] marked this conversation as resolved.
Resolved

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new sdk skills resolved event and the sdk_skills / sdk_non_default_major run tags send manifest-derived SDK data without checking discovery consent or --no-telemetry, unlike the same PR's report.ts path.

low privacy-consent (not a security vulnerability) (confidence 5/5)

Details

installTraitSkills (called from linear.ts:101 and orchestrator-runner.ts:942) now does three things whatever the run's sharing consent. It emits wizard: sdk skills resolved with unmatched_sdks. It sets the run tag sdk_skills. It sets the run tag sdk_non_default_major. unmatched_sdks is the posthogSdks match key (traits/registry.ts posthogSdks.detect), which lists each PostHog SDK the project's manifests declare, as <ecosystem>:<pkg>@<major>. That is a local discovery result. setTag puts both tags into this.tags, so they ride on every later capture, every exception and the setup wizard finished event.

Nothing in this path checks consent. matchKeys comes from toMatchKeys(getTraits(...)) (run-program.ts:672), and declaredSdks is gated only by the wizard-versioned-sdk-skills flag. The repo treats this class of data as consent-gated everywhere else. tags.ts says discovery-derived tags "leave the machine under the same consent as the discovery report". reportableDetections withholds posthog_sdk_detected unless sharing is granted. This same PR puts the matching has_existing_sdk / sdk_version_found / posthog sdks detected data behind noTelemetry and mayReportDiscovery in report.ts:57,63. program-session.ts documents --no-telemetry as "nothing about the run leaves the machine, whatever the consent".

This is not a security hole. The values are closed-schema: package names from an allowlist plus a major version, sent to PostHog's own analytics project. The old per-skill sdk trait skill resolved event already sent matched skill ids without a consent check. This diff widens that to declared SDKs that match no skill, and to run-wide tags on every later event.

Impact — A user picks "Don't share tools" on the intro (declineSharing sets DiscoveryConsent.Declined), or passes --no-telemetry, with wizard-versioned-sdk-skills on. The run still sends, for example, unmatched_sdks: ["pypi:posthog@2"], and stamps sdk_skills / sdk_non_default_major onto every later event. The user explicitly opted out of sharing this discovery data.

Fix — Gate the event and the tags on maySendDiscovery(session). For example, callers pass a reportDiscovery: boolean (or a tagDiscovery-style deferred setter) into installTraitSkills:

if (reportDiscovery && (declaredSdks.length > 0 || matched.length > 0)) {
  // setTag + wizardCapture as now
}

Or route the tags through tagDiscovery(session, setFrameworkContext, {...}), so they apply only once sharing is granted, as the report.ts half of this PR does.

Agent-driven security review. Not visible from the repo: whether wizard-versioned-sdk-skills is rolled out to interactive users who decline sharing. The code path is traced end to end.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed in e4fcfb07. installTraitSkills now defaults reportTelemetry to false and guards setTag and wizardCapture behind it, while linear.ts and orchestrator-runner.ts pass maySendDiscovery(session()).

resolved_sdk_skill_ids: resolvedIds,
non_default_sdk_skill_ids: nonDefaultIds,
failed_sdk_skill_ids: failedIds,
unmatched_sdks: unmatchedSdks,
});
}
return { paths, aborted: false };
}
2 changes: 2 additions & 0 deletions src/agent/runner/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ export interface ResolvedRunConfig {
matchKeys?: () => MatchKeys;
/** The project's traits by name, read when the orchestrator applies each task's `skipWhen`. */
traitKeys?: () => MatchKeys;
/** Whether discovery-derived telemetry (e.g. SDK skill resolution) may be sent. Defaults to false. */
reportDiscoveryTelemetry?: () => boolean;
/** Completion hooks, bound by the caller. */
hooks?: RunHooks;
scanReport?: 'flush' | 'defer'; // defer leaves the scan report to the outer run
Expand Down
3 changes: 3 additions & 0 deletions src/programs/program-runner/__tests__/migrated-from.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ vi.mock('posthog-node', () => ({
capture(event: SentEvent) {
sent.push(event);
}
on() {
return () => undefined;
}
shutdown() {
return Promise.resolve();
}
Expand Down
2 changes: 2 additions & 0 deletions src/programs/program-runner/run-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
DETECTED_PROJECT_KEY,
detectedProjectOf,
getDiscovery,
maySendDiscovery,
picksProject,
askUserToSelectProject,
shouldRankProjects,
Expand Down Expand Up @@ -671,6 +672,7 @@ async function invokeProgram(
// The session's own run project: a step scoped to a sub-folder reads that folder's traits.
matchKeys: () => toMatchKeys(getTraits(session())),
traitKeys: () => toTraitKeys(getTraits(session())),
reportDiscoveryTelemetry: () => maySendDiscovery(session()),
projectFacts:
planned.config.decisions || planned.config.detectedFacts
? () => [
Expand Down
Loading
Loading