Skip to content

Commit ab8f8fb

Browse files
committed
trim comments
1 parent bb197d6 commit ab8f8fb

15 files changed

Lines changed: 49 additions & 128 deletions

File tree

‎src/lib/agent/__tests__/run-tags.test.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ describe('buildRunTags', () => {
2222
});
2323

2424
it('marks every run as agent work rather than leaving call_type unset', () => {
25-
// Scan triage overrides this to `yara-triage`. Both sides are stamped so a
26-
// missing `call_type` means "an old build sent none", not "agent work" —
27-
// the two would otherwise be indistinguishable in cost breakdowns.
25+
// Triage and detection override this; stamping both sides means a missing
26+
// value is an old build, not agent work.
2827
expect(
2928
buildRunTags({
3029
programId: 'posthog-integration',

‎src/lib/agent/__tests__/triage-provider.test.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ describe('createTriageLLMProvider', () => {
9191
});
9292

9393
it('attributes its spend to the program that triggered the scan', async () => {
94-
// Triage fires per tool call. Before it carried run tags, every scan's
95-
// gateway spend landed in the unattributed bucket; `call_type` keeps it
96-
// separable from the agent work inside the same program.
94+
// Triage fires per tool call; untagged it billed to no program at all.
9795
complete.mockResolvedValue(reply(''));
9896
const provider = createTriageLLMProvider(
9997
{

‎src/lib/agent/agent-interface.ts‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,7 @@ export function buildRunTags(args: {
346346
integration: args.integration,
347347
run_id: args.runId,
348348
build: args.build,
349-
// Every caller is agent work; the triage provider spreads these tags and
350-
// overrides this one. Sent explicitly so a missing value never has to be
351-
// read as "agent" — old builds send none at all.
349+
// Triage and detection spread these tags and override this one.
352350
call_type: CallType.agent,
353351
...(args.skillId ? { skill_id: args.skillId } : {}),
354352
};
@@ -530,12 +528,9 @@ export async function initializeAgent(
530528
process.env.CLAUDE_CODE_OAUTH_TOKEN = config.posthogApiKey;
531529

532530
// Same values the env vars above carry, handed over explicitly so triage
533-
// never has to read them back out of the environment.
534-
//
535-
// The run tags ride along too: triage fires per tool call, so leaving them
536-
// off put every scan's gateway spend in the unattributed bucket. Tagged
537-
// here it folds into the program that triggered it, and `call_type` keeps
538-
// it separable — security scanning is its own cost line, not agent work.
531+
// never has to read them back out of the environment. The run tags ride
532+
// along so scan spend bills to this program, with `call_type` keeping it
533+
// separable from the agent's own calls.
539534
const triageProvider = createTriageLLMProvider(
540535
{
541536
baseURL: gatewayUrl,

‎src/lib/agent/mcp-prompt-streaming.ts‎

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,9 @@ function buildTerminalFitPrompt(): string {
174174
}
175175

176176
/**
177-
* Gateway trace tags for a tutorial prompt run.
178-
*
179-
* The gateway attributes each `$ai_generation` it emits from the
180-
* `X-POSTHOG-PROPERTY-*` headers on the request, so a run with no tags lands
181-
* in the unattributed bucket — which is where every tutorial generation went
182-
* before this existed. Exported so that contract is testable without booting
183-
* the SDK.
184-
*
185-
* Returns `{}` when the caller supplies no program, keeping the tagless
186-
* behavior explicit rather than silently emitting a half-populated bag.
177+
* Gateway trace tags for a tutorial prompt run — without them the gateway has
178+
* nothing to attribute its `$ai_generation` events to. Returns `{}` when no
179+
* program is supplied. Exported so the contract is testable without the SDK.
187180
*/
188181
export function buildTutorialRunTags(args: {
189182
programId?: string;
@@ -192,9 +185,8 @@ export function buildTutorialRunTags(args: {
192185
if (!args.programId) return {};
193186
return buildRunTags({
194187
programId: args.programId,
195-
// The tutorial runs against a project, not a codebase, so there's usually
196-
// no detected framework — fall back to the program so the axis is never
197-
// an empty string in the gateway's breakdowns.
188+
// The tutorial usually has no detected framework; fall back to the
189+
// program so the axis is never an empty string.
198190
integration: args.integration ?? args.programId,
199191
runId: analytics.runId,
200192
build: analytics.build,
@@ -209,10 +201,8 @@ export async function* runMcpPromptViaSdk(args: {
209201
* context so the follow-up prompt can reference what the agent
210202
* already showed. */
211203
resumeSessionId?: string;
212-
/** Program this run's gateway spend attributes to. Resolved by the caller
213-
* (`store.analyticsProgramId`) so both tutorial entry points report as
214-
* one program. Omitting it makes the spend unattributable — see the
215-
* `ANTHROPIC_CUSTOM_HEADERS` note below. */
204+
/** Program this run's gateway spend attributes to; omitting it leaves the
205+
* spend unattributed. */
216206
programId?: string;
217207
/** Integration label for the trace tags; the tutorial usually has none. */
218208
integration?: string;
@@ -378,13 +368,9 @@ export async function* runMcpPromptViaSdk(args: {
378368
// default; without this the agent may try to call tools
379369
// before posthog-wizard is connected on turn 1.
380370
MCP_CONNECTION_NONBLOCKING: '0',
381-
// Same Bedrock-fallback + telemetry-friendly headers as the main
382-
// runner, plus this run's trace tags. The gateway reads
383-
// `X-POSTHOG-PROPERTY-*` off the request to attribute each
384-
// `$ai_generation` it emits, so sending none put every tutorial
385-
// generation in the unattributed bucket — `posthog.capture` events
386-
// carry a program id but nothing joins them to gateway spend.
387-
// Flags stay empty: the tutorial doesn't fork on any.
371+
// Bedrock fallback plus this run's trace tags — the gateway reads
372+
// these to attribute its `$ai_generation` events. Flags stay empty:
373+
// the tutorial doesn't fork on any.
388374
ANTHROPIC_CUSTOM_HEADERS: buildAgentEnv(wizardMetadata ?? {}, {}),
389375
},
390376
},

‎src/lib/agent/triage-provider.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@ export interface TriageGatewayAuth {
2424
baseURL: string;
2525
/** The run's OAuth access token. */
2626
authToken: string;
27-
/**
28-
* The run's gateway trace tags. Pass the run's own `wizardMetadata` with
29-
* `call_type` overridden to `CallType.yaraTriage` — that keeps scan spend
30-
* attributed to the program that triggered it while staying separable from
31-
* the agent work inside it.
32-
*/
27+
/** The run's trace tags, with `call_type` overridden to
28+
* `CallType.yaraTriage` so scan spend is separable from agent work. */
3329
wizardMetadata?: Record<string, string>;
3430
wizardFlags?: Record<string, string>;
3531
}

‎src/lib/constants.ts‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,15 @@ export enum Sequence {
5959

6060
/**
6161
* What kind of call produced a gateway generation — the `call_type` trace tag.
62-
*
63-
* Splits a program's LLM spend by workload, so security scanning is separable
64-
* from the work the user asked for. Both members are sent explicitly rather
65-
* than treating `agent` as the unset default: old wizard builds in the field
66-
* send no `call_type` at all, so an absent value can't be read as "agent"
67-
* without conflating the two.
68-
*
69-
* Lives here rather than beside the triage provider because `buildRunTags`
70-
* (agent-interface) sets the default and the triage provider overrides it —
71-
* agent-interface already imports the provider, so a shared home avoids a
72-
* module cycle.
62+
* Splits a program's LLM spend by workload. Every member is sent explicitly so
63+
* an absent value means "old build", not "agent".
7364
*/
7465
export enum CallType {
7566
/** The agent doing the work the user asked for. */
7667
agent = 'agent',
7768
/** Warlock's classifier deciding whether a YARA match is a true positive. */
7869
yaraTriage = 'yara-triage',
79-
/** The cheap repo scan that classifies which projects a program should act on. */
70+
/** The cheap repo scan that classifies which projects a program acts on. */
8071
detection = 'detection',
8172
}
8273

‎src/lib/detection/__tests__/project-scope.test.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ describe('scopeInstallDirToProject', () => {
126126
});
127127

128128
it('bills the scan to the program that asked for it', async () => {
129-
// The detector drives a real (if cheap) agent through the gateway. It runs
130-
// before bootstrap, so nothing upstream supplies run tags — an unattributed
131-
// scan is exactly how this spend went missing before.
129+
// Runs before bootstrap, so nothing upstream supplies run tags.
132130
flagsSpy.mockResolvedValue(FLAG_ON);
133131
scan.mockResolvedValue({ repoType: 'single', projects: [web] });
134132

‎src/lib/detection/agentic.ts‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,9 @@ export type AgenticDetectOptions = {
110110
* through ordering (e.g. a bundler target before a generic framework target).
111111
*/
112112
targets: readonly DetectTarget[];
113-
/**
114-
* The program this scan runs on behalf of, for gateway cost attribution.
115-
*
116-
* Required, not optional: this scan drives a real (if cheap) agent through
117-
* the LLM gateway, and a caller that forgets to say who it's for sends spend
118-
* to the unattributed bucket with no way to trace it back. `call_type`
119-
* separates it from the program's own agent work.
120-
*/
113+
/** The program this scan bills to. Required, not optional: the scan drives a
114+
* real agent through the gateway, and a caller that forgets leaves that
115+
* spend unattributed. */
121116
programId: string;
122117
/** One short clause describing what the scan is for (frames the prompt). */
123118
purpose?: string;
@@ -349,10 +344,8 @@ export async function detectProjectsWithAgent(
349344
const cwd = session.installDir;
350345
const runOptions = sessionToWizardOptions(session);
351346

352-
// Gateway trace tags. This scan runs before `bootstrapProgram` exists, so
353-
// they're built here from the caller's program plus the run's analytics
354-
// identity rather than inherited from `boot.wizardMetadata`. Without them
355-
// the scan — and the YARA triage it wires up — bill to no program at all.
347+
// Built here rather than inherited: this scan runs before
348+
// `bootstrapProgram`, so there's no `boot.wizardMetadata` yet.
356349
const wizardMetadata = {
357350
...buildRunTags({
358351
programId,

‎src/lib/detection/project-scope.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ export async function scopeInstallDirToProject(
9090
try {
9191
report = await Promise.race([
9292
detectIntegrationProjects(session, {
93-
// Same literal the `authenticate` call above uses — importing the
94-
// program registry here would cycle back through the programs that
95-
// import this module.
93+
// Literal, like the `authenticate` call above: importing the program
94+
// registry here would cycle.
9695
programId: 'posthog-integration',
9796
recommend: true,
9897
onEvent: (line) => logToFile('[agentic detect]', line),

‎src/lib/programs/mcp/index.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,9 @@ export const mcpAddConfig: ProgramConfig = {
4545
// talk to from the tutorial.
4646
show: (s) => s.mcpOutcome === McpOutcome.Installed,
4747
isComplete: (s) => s.mcpSuggestedPromptsDismissed,
48-
// This step *is* the tutorial, so its events belong to the tutorial's
49-
// funnel rather than to `mcp-add` — otherwise the same screen reports
50-
// under two program ids depending on how the user arrived, and neither
51-
// one measures the tutorial. String literal (not `Program.McpTutorial`)
52-
// to avoid a runtime cycle with `program-registry.ts`; the `ProgramId`
53-
// type on the field still catches a rename at compile time.
48+
// This step *is* the tutorial, so it reports there rather than to
49+
// `mcp-add`. Literal avoids a runtime cycle with the program registry;
50+
// the `ProgramId` type still catches a rename.
5451
reportsAsProgramId: 'mcp-tutorial',
5552
},
5653
],

0 commit comments

Comments
 (0)