@posthog/wizard 2.77.0 → 2.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -15
- package/dist/{add-mcp-server-to-clients-BnRyE4pw.js → add-mcp-server-to-clients-JMv8LP-O.js} +6 -5
- package/dist/{add-mcp-server-to-clients-BnRyE4pw.js.map → add-mcp-server-to-clients-JMv8LP-O.js.map} +1 -1
- package/dist/agent-bCZ3i3fh.js +3085 -0
- package/dist/agent-bCZ3i3fh.js.map +1 -0
- package/dist/{agent-interface-Avtr_5M5.js → agent-interface-BAOIHuXS.js} +429 -378
- package/dist/agent-interface-BAOIHuXS.js.map +1 -0
- package/dist/{agent-prompt-loader-CHixNPgY.js → agent-prompt-loader-7Pd4CfZO.js} +6 -6
- package/dist/agent-prompt-loader-7Pd4CfZO.js.map +1 -0
- package/dist/analytics-BcV-WCM4.js +2 -0
- package/dist/{analytics-C67F2vee.js → analytics-CHCZ_qUR.js} +10 -6
- package/dist/analytics-CHCZ_qUR.js.map +1 -0
- package/dist/{api-Dj1yabTj.js → api-Diy_2fp8.js} +4 -17
- package/dist/api-Diy_2fp8.js.map +1 -0
- package/dist/bin.js +410 -68
- package/dist/bin.js.map +1 -1
- package/dist/{bounded-fs-CWRYuLAn.js → bounded-fs-Bx9zTe6m.js} +4 -4
- package/dist/bounded-fs-Bx9zTe6m.js.map +1 -0
- package/dist/check-screens.tsx +1 -1
- package/dist/{ci-install-CvXL5h13.js → ci-install-CDdQYsPe.js} +6 -5
- package/dist/ci-install-CDdQYsPe.js.map +1 -0
- package/dist/constants-jFI2SaE1.js +260 -0
- package/dist/constants-jFI2SaE1.js.map +1 -0
- package/dist/debug-Ch4BDOtD.js +171 -0
- package/dist/debug-Ch4BDOtD.js.map +1 -0
- package/dist/{debug-CziFS0cA.js → debug-M2gV2iDq.js} +1 -1
- package/dist/{defaults-4c4YwTmW.js → defaults-C6J7yL4O.js} +1 -1
- package/dist/{defaults-4c4YwTmW.js.map → defaults-C6J7yL4O.js.map} +1 -1
- package/dist/endpoints-DCVbM06L.js +108 -0
- package/dist/endpoints-DCVbM06L.js.map +1 -0
- package/dist/{env-api-key-BZ5wE3Y4.js → env-api-key-Qx8NnYHm.js} +3 -3
- package/dist/env-api-key-Qx8NnYHm.js.map +1 -0
- package/dist/{environment-BEvsey6i.js → environment-B07Bmxae.js} +6 -6
- package/dist/environment-B07Bmxae.js.map +1 -0
- package/dist/{errors-BoJvrdw8.js → errors-CQ9kttJD.js} +27 -34
- package/dist/errors-CQ9kttJD.js.map +1 -0
- package/dist/{file-BoD3REGB.js → file-BcLTjU16.js} +2 -2
- package/dist/{file-BoD3REGB.js.map → file-BcLTjU16.js.map} +1 -1
- package/dist/{file-watcher-BPFazvG_.js → file-watcher-DWc_bTs6.js} +2 -2
- package/dist/{file-watcher-BPFazvG_.js.map → file-watcher-DWc_bTs6.js.map} +1 -1
- package/dist/{gateway-session-xPFv6p5c.js → gateway-CjoShdLa.js} +175 -20
- package/dist/gateway-CjoShdLa.js.map +1 -0
- package/dist/generate-version.cjs +1 -1
- package/dist/{headless-ui-CsmQrDIl.js → headless-ui-BFFmYC4v.js} +13 -2
- package/dist/headless-ui-BFFmYC4v.js.map +1 -0
- package/dist/{interactive-Dej-sxvR.js → interactive-D6zV7brJ.js} +2 -2
- package/dist/{interactive-Dej-sxvR.js.map → interactive-D6zV7brJ.js.map} +1 -1
- package/dist/{local-dev-DPZiIPCK.js → local-dev-McsurOC-.js} +2 -2
- package/dist/local-dev-McsurOC-.js.map +1 -0
- package/dist/logging-ui-_TwoMNbG.js +226 -0
- package/dist/logging-ui-_TwoMNbG.js.map +1 -0
- package/dist/mcp-DAgaoGk5.js +97 -0
- package/dist/mcp-DAgaoGk5.js.map +1 -0
- package/dist/{mcp-prompt-streaming-BU_kuur_.js → mcp-prompt-streaming-I2U_X7BC.js} +7 -6
- package/dist/mcp-prompt-streaming-I2U_X7BC.js.map +1 -0
- package/dist/{mint-failure-BrleGqMd.js → mint-failure-D4nd2XmZ.js} +82 -25
- package/dist/mint-failure-D4nd2XmZ.js.map +1 -0
- package/dist/models-DDdBJKwT.js +83 -0
- package/dist/models-DDdBJKwT.js.map +1 -0
- package/dist/{non-interactive-DcOjH2fw.js → non-interactive-Dzow7YKY.js} +3 -3
- package/dist/non-interactive-Dzow7YKY.js.map +1 -0
- package/dist/oauth-session-DJ8h6GFa.js +74 -0
- package/dist/oauth-session-DJ8h6GFa.js.map +1 -0
- package/dist/{orchestrator-tools-DXwr8Sp3.js → orchestrator-tools-szcdscwn.js} +4 -4
- package/dist/orchestrator-tools-szcdscwn.js.map +1 -0
- package/dist/{package-json-xt3eeyBI.js → package-json-DY70kkNp.js} +2 -2
- package/dist/package-json-DY70kkNp.js.map +1 -0
- package/dist/{pi-mY8I2XkG.js → pi-D3h5Ok0i.js} +329 -65
- package/dist/pi-D3h5Ok0i.js.map +1 -0
- package/dist/{playground-CDUUKLkC.js → playground-5AB4WgNF.js} +11 -7
- package/dist/playground-5AB4WgNF.js.map +1 -0
- package/dist/{posthog-Hc_-9wrr.js → posthog-DNn574nW.js} +8 -3
- package/dist/posthog-DNn574nW.js.map +1 -0
- package/dist/{provisioning-xfdjhFtA.js → provisioning-B8uSqRZk.js} +6 -5
- package/dist/provisioning-B8uSqRZk.js.map +1 -0
- package/dist/{queue-tools-C8y_xZJi.js → queue-tools-9OOVx5TE.js} +7 -86
- package/dist/queue-tools-9OOVx5TE.js.map +1 -0
- package/dist/{registry-DTmREJ-f.js → registry-8YG-kuXk.js} +265 -6
- package/dist/registry-8YG-kuXk.js.map +1 -0
- package/dist/run-agent-legacy-d7rWlzQR.js +3739 -0
- package/dist/run-agent-legacy-d7rWlzQR.js.map +1 -0
- package/dist/{security-Dw2oFJjP.js → security-Cg_4a7vB.js} +6 -6
- package/dist/security-Cg_4a7vB.js.map +1 -0
- package/dist/{setup-utils-fjJTBhaB.js → setup-utils-CmTCTPkX.js} +46 -18
- package/dist/setup-utils-CmTCTPkX.js.map +1 -0
- package/dist/smoke-test.sh +1 -1
- package/dist/{start-tui-UNe2xQ0U.js → start-tui-CB2PZs1x.js} +38 -44
- package/dist/start-tui-CB2PZs1x.js.map +1 -0
- package/dist/{steps-C2yqOk_h.js → steps-BZcXRJNY.js} +7 -7
- package/dist/{steps-C2yqOk_h.js.map → steps-BZcXRJNY.js.map} +1 -1
- package/dist/{store-Bic4Cr3L.js → store-UN7c-ASf.js} +18 -28
- package/dist/store-UN7c-ASf.js.map +1 -0
- package/dist/{subagent-Dz41vV9j.js → subagent-BofIDK-O.js} +8 -3
- package/dist/subagent-BofIDK-O.js.map +1 -0
- package/dist/{task-5-fw_Vw3.js → task-r9t1UhQP.js} +124 -36
- package/dist/task-r9t1UhQP.js.map +1 -0
- package/dist/{task-stream-dVzl6b_q.js → task-stream-CMUilu54.js} +45 -15
- package/dist/task-stream-CMUilu54.js.map +1 -0
- package/dist/{tasks-D1c2z1aw.js → tasks-Bbv_lOBG.js} +17 -13
- package/dist/tasks-Bbv_lOBG.js.map +1 -0
- package/dist/{telemetry-BRnxBRWK.js → telemetry-D6ruCtnv.js} +5 -5
- package/dist/telemetry-D6ruCtnv.js.map +1 -0
- package/dist/{terminal-9bvRa4Qt.js → terminal-DrGyci_a.js} +39 -74
- package/dist/terminal-DrGyci_a.js.map +1 -0
- package/dist/{tools-Dp6i9k70.js → tools-Dyfh9aCD.js} +11 -11
- package/dist/tools-Dyfh9aCD.js.map +1 -0
- package/dist/ui-BBVuTM1v.js +15 -0
- package/dist/ui-BBVuTM1v.js.map +1 -0
- package/dist/version-aXxpgRKx.js +6 -0
- package/dist/version-aXxpgRKx.js.map +1 -0
- package/dist/warlock-smoke-test.ts +2 -2
- package/dist/{wizard-abort-lE6umflt.js → wizard-abort-BBkiUxfS.js} +23 -20
- package/dist/wizard-abort-BBkiUxfS.js.map +1 -0
- package/dist/wizard-abort-BU4aLyvh.js +3 -0
- package/dist/{wizard-session-FSJCkTcP.js → wizard-session-2w4Ru-Wz.js} +12 -16
- package/dist/wizard-session-2w4Ru-Wz.js.map +1 -0
- package/dist/wizard-session-DGaUHOF3.js +2 -0
- package/dist/wizard-ui-DoyOZxK8.js +16 -0
- package/dist/wizard-ui-DoyOZxK8.js.map +1 -0
- package/dist/{yara-hooks-BTNJ6MGW.js → yara-hooks-DCeMDd1o.js} +19 -68
- package/dist/yara-hooks-DCeMDd1o.js.map +1 -0
- package/dist/yara-hooks-DSGuCU9A.js +2 -0
- package/package.json +1 -1
- package/dist/agent-interface-Avtr_5M5.js.map +0 -1
- package/dist/agent-prompt-loader-CHixNPgY.js.map +0 -1
- package/dist/agent-runner-COOIUJCP.js +0 -6188
- package/dist/agent-runner-COOIUJCP.js.map +0 -1
- package/dist/analytics-C67F2vee.js.map +0 -1
- package/dist/analytics-CJA1uLlk.js +0 -2
- package/dist/api-Dj1yabTj.js.map +0 -1
- package/dist/bounded-fs-CWRYuLAn.js.map +0 -1
- package/dist/ci-install-CvXL5h13.js.map +0 -1
- package/dist/debug-B4kzIZPi.js +0 -754
- package/dist/debug-B4kzIZPi.js.map +0 -1
- package/dist/env-api-key-BZ5wE3Y4.js.map +0 -1
- package/dist/environment-BEvsey6i.js.map +0 -1
- package/dist/errors-BoJvrdw8.js.map +0 -1
- package/dist/gateway-session-C118uACz.js +0 -2
- package/dist/gateway-session-xPFv6p5c.js.map +0 -1
- package/dist/headless-ui-CsmQrDIl.js.map +0 -1
- package/dist/local-dev-DPZiIPCK.js.map +0 -1
- package/dist/mcp-Cbuw_xss.js +0 -64
- package/dist/mcp-Cbuw_xss.js.map +0 -1
- package/dist/mcp-prompt-streaming-BU_kuur_.js.map +0 -1
- package/dist/mint-failure-BrleGqMd.js.map +0 -1
- package/dist/non-interactive-DcOjH2fw.js.map +0 -1
- package/dist/orchestrator-tools-DXwr8Sp3.js.map +0 -1
- package/dist/package-json-xt3eeyBI.js.map +0 -1
- package/dist/package-manager-DR23m5Jg.js +0 -290
- package/dist/package-manager-DR23m5Jg.js.map +0 -1
- package/dist/pi-mY8I2XkG.js.map +0 -1
- package/dist/playground-CDUUKLkC.js.map +0 -1
- package/dist/posthog-Hc_-9wrr.js.map +0 -1
- package/dist/provisioning-xfdjhFtA.js.map +0 -1
- package/dist/queue-tools-C8y_xZJi.js.map +0 -1
- package/dist/registry-DTmREJ-f.js.map +0 -1
- package/dist/security-Dw2oFJjP.js.map +0 -1
- package/dist/setup-utils-fjJTBhaB.js.map +0 -1
- package/dist/start-tui-UNe2xQ0U.js.map +0 -1
- package/dist/store-Bic4Cr3L.js.map +0 -1
- package/dist/subagent-Dz41vV9j.js.map +0 -1
- package/dist/task-5-fw_Vw3.js.map +0 -1
- package/dist/task-stream-dVzl6b_q.js.map +0 -1
- package/dist/tasks-D1c2z1aw.js.map +0 -1
- package/dist/telemetry-BRnxBRWK.js.map +0 -1
- package/dist/terminal-9bvRa4Qt.js.map +0 -1
- package/dist/tools-Dp6i9k70.js.map +0 -1
- package/dist/wizard-abort-CAcInAxg.js +0 -2
- package/dist/wizard-abort-lE6umflt.js.map +0 -1
- package/dist/wizard-session-CYvyYnti.js +0 -2
- package/dist/wizard-session-FSJCkTcP.js.map +0 -1
- package/dist/yara-hooks-BTNJ6MGW.js.map +0 -1
- package/dist/yara-hooks-CFY4pGcW.js +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging-ui-_TwoMNbG.js","names":[],"sources":["../src/shared/health-checks/readiness.ts","../src/ui/logging-ui.ts"],"sourcesContent":["import {\n ServiceHealthStatus,\n type AllServicesHealth,\n type BaseHealthResult,\n type HealthCheckKey,\n} from './types';\nimport { checkSkillsOriginHealth } from './endpoints';\nimport { logToFile } from '@utils/debug';\n\n// ---------------------------------------------------------------------------\n// Service labels (used in human-readable reason strings)\n// ---------------------------------------------------------------------------\n\nexport const SERVICE_LABELS: Record<HealthCheckKey, string> = {\n skillsOrigin: 'Skills download',\n};\n\n// ---------------------------------------------------------------------------\n// Readiness config\n// ---------------------------------------------------------------------------\n\nexport interface WizardReadinessConfig {\n /** Services where status=Down blocks the run (readiness=No). */\n downBlocksRun: HealthCheckKey[];\n /** Services where status=Degraded (or worse) blocks the run (readiness=No). */\n degradedBlocksRun?: HealthCheckKey[];\n}\n\n// Skills gate startup; gateway readiness is checked against the minted URL.\nexport const DEFAULT_WIZARD_READINESS_CONFIG: WizardReadinessConfig = {\n downBlocksRun: ['skillsOrigin'],\n};\n\nexport const SIGNUP_WIZARD_READINESS_CONFIG = DEFAULT_WIZARD_READINESS_CONFIG;\n\n// ---------------------------------------------------------------------------\n// Aggregate check\n// ---------------------------------------------------------------------------\n\nexport async function checkAllExternalServices(): Promise<AllServicesHealth> {\n return { skillsOrigin: await checkSkillsOriginHealth() };\n}\n\n// ---------------------------------------------------------------------------\n// Wizard readiness evaluation\n// ---------------------------------------------------------------------------\n\nexport enum WizardReadiness {\n Yes = 'yes',\n No = 'no',\n YesWithWarnings = 'yes_with_warnings',\n}\n\nexport interface WizardReadinessResult {\n decision: WizardReadiness;\n health: AllServicesHealth;\n reasons: string[];\n}\n\nfunction describeResult(label: string, h: BaseHealthResult): string {\n const parts = [`${label}: ${h.status}`];\n if (h.rawIndicator) parts.push(`indicator=${h.rawIndicator}`);\n if (h.error) parts.push(h.error);\n return parts.join(' — ');\n}\n\n// Each probe can take up to one base timeout + two retries with the\n// 500ms / 2000ms backoffs in endpoints.ts (worst case ~17.5s for a\n// network failure that exhausts retries). Probes run in parallel so\n// the aggregate ceiling is one probe, not the sum.\nconst READINESS_TIMEOUT_MS = 20_000;\n\nexport async function evaluateWizardReadiness(\n config: WizardReadinessConfig = DEFAULT_WIZARD_READINESS_CONFIG,\n): Promise<WizardReadinessResult> {\n try {\n const health = await Promise.race([\n checkAllExternalServices(),\n new Promise<AllServicesHealth>((resolve) =>\n setTimeout(\n () => resolve(allUnknown('Health check timed out')),\n READINESS_TIMEOUT_MS,\n ),\n ),\n ]);\n\n const blockingKeys = getBlockingServiceKeys(health, config);\n const reasons = blockingKeys.map((key) =>\n describeResult(SERVICE_LABELS[key], health[key]),\n );\n if (blockingKeys.length > 0) {\n const blockingDetails = blockingKeys.map((key) => {\n const h = health[key];\n return `${key} (${h.status}${h.error ? ` — ${h.error}` : ''})`;\n });\n logToFile(`[health-checks] blocked by: ${blockingDetails.join(', ')}`);\n return { decision: WizardReadiness.No, health, reasons };\n }\n\n return { decision: WizardReadiness.Yes, health, reasons };\n } catch (err) {\n logToFile(\n `[health-checks] error: ${err instanceof Error ? err.message : err}`,\n );\n // Health checks must never block the wizard run\n return {\n decision: WizardReadiness.Yes,\n health: allUnknown('Unexpected error'),\n reasons: [],\n };\n }\n}\n\n// ---------------------------------------------------------------------------\n// Blocking service detection\n// ---------------------------------------------------------------------------\n\n// Report only dependencies that prevent this run from starting.\nexport function getBlockingServiceKeys(\n health: AllServicesHealth,\n config: WizardReadinessConfig = DEFAULT_WIZARD_READINESS_CONFIG,\n): HealthCheckKey[] {\n return (Object.keys(health) as HealthCheckKey[]).filter((key) => {\n const result = health[key];\n if (\n config.downBlocksRun.includes(key) &&\n (result.status === ServiceHealthStatus.Down ||\n result.status === ServiceHealthStatus.NoConnection)\n ) {\n return true;\n }\n if (\n (config.degradedBlocksRun ?? []).includes(key) &&\n result.status !== ServiceHealthStatus.Healthy\n ) {\n return true;\n }\n return false;\n });\n}\n\n/** Build an AllServicesHealth where every service is Degraded with the given error. */\nfunction allUnknown(error: string): AllServicesHealth {\n const base: BaseHealthResult = {\n status: ServiceHealthStatus.Degraded,\n error,\n };\n return { skillsOrigin: base };\n}\n","/* eslint-disable no-console */\n/**\n * LoggingUI — Logging-only implementation for CI mode.\n * No prompts, no TUI, no interactivity. Just console output.\n */\n\nimport {\n TaskStatus,\n type WizardUI,\n type SpinnerHandle,\n type AuthErrorDetail,\n type TokenUsageDelta,\n} from './wizard-ui';\nimport type { SettingsConflict } from '@shared/claude-settings';\nimport type { ApiUser } from '@shared/api';\nimport { OAUTH_TIMEOUT_MS } from '@shared/constants';\nimport {\n type WizardReadinessResult,\n getBlockingServiceKeys,\n SERVICE_LABELS,\n} from '@shared/health-checks/readiness';\nimport type {\n AskAnswers,\n Credentials,\n OutroData,\n PendingQuestion,\n TaskNotice,\n} from '@lib/wizard-session';\n\nexport class LoggingUI implements WizardUI {\n intro(message: string): void {\n console.log(`┌ ${message}`);\n }\n\n outro(message: string): void {\n console.log(`└ ${message}`);\n }\n\n outroError(data: OutroData): void {\n console.log(`✖ ${data.message ?? 'Wizard aborted'}`);\n if (data.body) console.log(`│ ${data.body}`);\n if (data.docsUrl) console.log(`│ Docs: ${data.docsUrl}`);\n }\n\n waitForOutroDismissed(): Promise<void> {\n return Promise.resolve();\n }\n\n waitForAiOptIn(): Promise<void> {\n // Non-TUI runs are CI runs, which auto-consent to AI usage.\n return Promise.resolve();\n }\n\n cancel(message: string): void {\n console.log(`■ ${message}`);\n }\n\n log = {\n info(message: string): void {\n console.log(`│ ${message}`);\n },\n warn(message: string): void {\n console.log(`▲ ${message}`);\n },\n error(message: string): void {\n console.log(`✖ ${message}`);\n },\n success(message: string): void {\n console.log(`✔ ${message}`);\n },\n step(message: string): void {\n console.log(`◇ ${message}`);\n },\n };\n\n note(message: string): void {\n console.log(`│ ${message}`);\n }\n\n spinner(): SpinnerHandle {\n return {\n start(message?: string) {\n if (message) console.log(`◌ ${message}`);\n },\n stop(message?: string) {\n if (message) console.log(`● ${message}`);\n },\n message(msg?: string) {\n if (msg) console.log(`◌ ${msg}`);\n },\n };\n }\n\n pushStatus(message: string): void {\n console.log(`◇ ${message}`);\n }\n\n setDetectedFramework(label: string): void {\n console.log(`✔ Framework: ${label}`);\n }\n\n onEnterScreen(_screen: string, _fn: () => void): void {\n // No screen transitions in CI\n }\n\n setLoginUrl(url: string | null): void {\n if (url) {\n console.log(\n `│ If the browser didn't open automatically, use this link:`,\n );\n console.log(`│ ${url}`);\n }\n }\n\n setAuthorizeUrl(_url: string | null): void {\n // Manual-paste modal is TUI-only; CI/non-interactive runs don't use it.\n }\n\n showBlockingOutage(result: WizardReadinessResult): Promise<void> {\n console.log(`▲ Service health issues detected.`);\n const blockingKeys = getBlockingServiceKeys(result.health);\n if (blockingKeys.length > 0) {\n console.log(`│`);\n console.log(`│ Blocking services:`);\n for (const key of blockingKeys) {\n const status = result.health[key].status;\n const error = result.health[key].error;\n const label = SERVICE_LABELS[key];\n const detail = error ? ` — ${error}` : '';\n console.log(`│ ✖ ${label}: ${status}${detail}`);\n }\n console.log(`│`);\n }\n for (const reason of result.reasons) {\n console.log(`│ ${reason}`);\n }\n console.log(\n `│ Continuing anyway — health checks are advisory in non-interactive runs.`,\n );\n return Promise.resolve();\n }\n\n setReadinessWarnings(result: WizardReadinessResult): void {\n console.log(`▲ Service health warnings detected.`);\n for (const reason of result.reasons) {\n console.log(`│ ${reason}`);\n }\n }\n\n showPortConflict(_processInfo: {\n command: string;\n pid: string;\n port: number;\n user: string;\n }): Promise<void> {\n return Promise.resolve();\n }\n\n waitForManualAuthCode(): Promise<string> {\n // No interactive prompt in CI/logging mode — never resolves. CI bypasses\n // OAuth entirely, so this is only here to satisfy the interface.\n return new Promise<string>(() => {\n /* intentionally never resolves */\n });\n }\n\n showTaskNotice(_notice: TaskNotice): Promise<boolean> {\n return Promise.resolve(false);\n }\n\n cancelTaskNotice(): void {\n // Nothing to dismiss — showTaskNotice never opened anything.\n }\n\n showSettingsOverride(\n _conflicts: SettingsConflict[],\n _backupAndFix: () => boolean,\n ): Promise<void> {\n return Promise.resolve();\n }\n\n requestQuestion(_question: PendingQuestion): Promise<AskAnswers> {\n return Promise.reject(\n new Error(\n 'wizard_ask is not available in CI / non-interactive mode. ' +\n 'Re-run the wizard without --ci to answer interactively.',\n ),\n );\n }\n\n cancelPendingQuestion(): void {\n // Nothing to dismiss — requestQuestion never opens an overlay here.\n }\n\n showAuthError(detail?: AuthErrorDetail): void {\n console.log(`✖ Authentication failed (401)`);\n if (detail?.hasSettingsConflict) {\n console.log(\n `│ Claude Code auth is conflicting with the wizard. Please try again after logging out:`,\n );\n console.log(`│ claude auth logout`);\n } else {\n console.log(\n `│ The PostHog LLM Gateway rejected the API key. Common causes:`,\n );\n console.log(\n `│ - Wrong key type: pass a personal API key (phx_xxx). pha_ is an OAuth access token, phc_ is a project key.`,\n );\n console.log(\n `│ - Missing scope: the personal API key needs the \"llm_gateway:read\" scope.`,\n );\n console.log(`│ - Expired or revoked key.`);\n console.log(\n `│ - Region mismatch: --region must match the region the key was issued in (us vs eu).`,\n );\n }\n if (detail?.logFilePath) {\n console.log(`│ Verbose log: ${detail.logFilePath}`);\n }\n }\n\n showSessionTimeout(): void {\n const minutes = Math.round(OAUTH_TIMEOUT_MS / 60_000);\n console.log(\n `✖ Login timed out. The OAuth link timed out after ${minutes} minutes.`,\n );\n console.log(`│ Re-run the wizard to get a fresh link and try again.`);\n }\n\n startRun(): void {\n // No-op in CI mode\n }\n\n setCredentials(_credentials: Credentials): void {\n // No-op in CI mode — credentials are handled directly\n }\n\n setAccessToken(_credentials: Credentials): void {\n // No-op in CI mode — CI runs on a non-expiring key and never refreshes\n }\n\n setRoleAtOrganization(_role: string | null): void {\n // No-op in CI mode — there's no TUI to render role-tailored prompts\n }\n\n setApiUser(_user: ApiUser | null): void {\n // No-op in CI mode — there's no TUI to read account context from\n // the session.\n }\n\n private lastTodoLine = '';\n\n syncTodos(\n todos: Array<{\n id?: string;\n source?: string;\n content: string;\n status: string;\n activeForm?: string;\n }>,\n ): void {\n const completed = todos.filter(\n (t) => t.status === TaskStatus.Completed,\n ).length;\n const active = todos.filter((t) => t.status === TaskStatus.InProgress);\n if (active.length === 0) return;\n const labels = active.map((t) => t.activeForm || t.content).join(' · ');\n const line = `◌ [${completed}/${todos.length}] ${labels}`;\n // The queue re-renders on every transition; print only what changed.\n if (line === this.lastTodoLine) return;\n this.lastTodoLine = line;\n console.log(line);\n }\n\n setEventPlan(_events: Array<{ name: string; description: string }>): void {\n // No-op in CI mode\n }\n\n setDashboardUrl(_url: string): void {\n // No-op in CI mode\n }\n\n setStage(_stage: string): void {\n // No-op in CI mode\n }\n\n setNotebookUrl(_url: string): void {\n // No-op in CI mode\n }\n\n setHandoffText(_text: string): void {\n // No-op without a store — HeadlessUI overrides to feed the session sync\n }\n\n addTokenUsage(_delta: TokenUsageDelta): void {\n // No-op — the hidden Ctrl+T HUD is TUI-only\n }\n\n setFinalTokenCostUsd(_costUsd: number): void {\n // No-op — the hidden Ctrl+T HUD is TUI-only\n }\n\n setOutroData(_data: import('@lib/wizard-session').OutroData): void {\n // No-op in CI mode\n }\n\n setFrameworkContext(_key: string, _value: unknown): void {\n // No-op in CI mode\n }\n\n getFrameworkContext(_key: string): unknown {\n // No frameworkContext in CI mode\n return undefined;\n }\n\n waitForGate(_stepId: string): Promise<void> {\n // No interactive gates in CI mode\n return Promise.resolve();\n }\n}\n"],"mappings":";;;;;AAaA,MAAa,iBAAiD,EAC5D,cAAc,mBACf;AAcD,MAAa,kCAAyD,EACpE,eAAe,CAAC,eAAe,EAChC;AAED,MAAa,iCAAiC;AAM9C,eAAsB,2BAAuD;AAC3E,QAAO,EAAE,cAAc,MAAM,yBAAyB,EAAE;;AAmB1D,SAAS,eAAe,OAAe,GAA6B;CAClE,MAAM,QAAQ,CAAC,GAAG,MAAM,IAAI,EAAE,SAAS;AACvC,KAAI,EAAE,aAAc,OAAM,KAAK,aAAa,EAAE,eAAe;AAC7D,KAAI,EAAE,MAAO,OAAM,KAAK,EAAE,MAAM;AAChC,QAAO,MAAM,KAAK,MAAM;;AAO1B,MAAM,uBAAuB;AAE7B,eAAsB,wBACpB,SAAgC,iCACA;AAChC,KAAI;EACF,MAAM,SAAS,MAAM,QAAQ,KAAK,CAChC,0BAA0B,EAC1B,IAAI,SAA4B,YAC9B,iBACQ,QAAQ,WAAW,yBAAyB,CAAC,EACnD,qBACD,CACF,CACF,CAAC;EAEF,MAAM,eAAe,uBAAuB,QAAQ,OAAO;EAC3D,MAAM,UAAU,aAAa,KAAK,QAChC,eAAe,eAAe,MAAM,OAAO,KAAK,CACjD;AACD,MAAI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,MAAM,EAAE,WAAA,cAAiC;AACtE,MAAI,OAAO,WAAW,EAAG;EACzB,MAAM,SAAS,OAAO,KAAK,MAAM,EAAE,cAAc,EAAE,QAAQ,CAAC,KAAK,MAAM;EACvE,MAAM,OAAO,OAAO,UAAU,GAAG,MAAM,OAAO,IAAI;AAElD,MAAI,SAAS,KAAK,aAAc;AAChC,OAAK,eAAe;AACpB,UAAQ,IAAI,KAAK;;CAGnB,aAAa,SAA6D;CAI1E,gBAAgB,MAAoB;CAIpC,SAAS,QAAsB;CAI/B,eAAe,MAAoB;CAInC,eAAe,OAAqB;CAIpC,cAAc,QAA+B;CAI7C,qBAAqB,UAAwB;CAI7C,aAAa,OAAsD;CAInE,oBAAoB,MAAc,QAAuB;CAIzD,oBAAoB,MAAuB;CAK3C,YAAY,SAAgC;AAE1C,SAAO,QAAQ,SAAS"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { s as logToFile } from "./debug-Ch4BDOtD.js";
|
|
2
|
+
import { t as VERSION } from "./version-aXxpgRKx.js";
|
|
3
|
+
import { o as onAccessTokenRotated } from "./oauth-session-DJ8h6GFa.js";
|
|
4
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
5
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
6
|
+
import { createJiti } from "jiti";
|
|
7
|
+
//#region src/agent/runner/harness/pi/mcp.ts
|
|
8
|
+
/**
|
|
9
|
+
* pi has no built-in MCP; `pi-mcp-adapter` — pi's own MCP extension, built here
|
|
10
|
+
* with its supported `createMcpAdapter` embedding API — bridges the same hosted
|
|
11
|
+
* MCP the anthropic path uses into the agent.
|
|
12
|
+
*/
|
|
13
|
+
const MCP_TOKEN_ENV = "POSTHOG_MCP_TOKEN";
|
|
14
|
+
let mcpTokenOwners = 0;
|
|
15
|
+
let activeMcpToken;
|
|
16
|
+
let previousMcpToken;
|
|
17
|
+
let stopFollowingRotations;
|
|
18
|
+
function setMcpToken(token) {
|
|
19
|
+
activeMcpToken = token;
|
|
20
|
+
process.env[MCP_TOKEN_ENV] = token;
|
|
21
|
+
}
|
|
22
|
+
function acquireMcpToken(token) {
|
|
23
|
+
if (mcpTokenOwners === 0) {
|
|
24
|
+
previousMcpToken = process.env[MCP_TOKEN_ENV];
|
|
25
|
+
stopFollowingRotations = onAccessTokenRotated(setMcpToken);
|
|
26
|
+
}
|
|
27
|
+
if (activeMcpToken !== token) setMcpToken(token);
|
|
28
|
+
mcpTokenOwners += 1;
|
|
29
|
+
let released = false;
|
|
30
|
+
return () => {
|
|
31
|
+
if (released) return;
|
|
32
|
+
released = true;
|
|
33
|
+
mcpTokenOwners -= 1;
|
|
34
|
+
if (mcpTokenOwners > 0) return;
|
|
35
|
+
stopFollowingRotations?.();
|
|
36
|
+
stopFollowingRotations = void 0;
|
|
37
|
+
if (previousMcpToken === void 0) delete process.env[MCP_TOKEN_ENV];
|
|
38
|
+
else process.env[MCP_TOKEN_ENV] = previousMcpToken;
|
|
39
|
+
activeMcpToken = void 0;
|
|
40
|
+
previousMcpToken = void 0;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Server `instructions` for the system prompt — the adapter exposes no accessor, so one standard-SDK handshake; best-effort. */
|
|
44
|
+
async function fetchInstructions(mcpUrl, accessToken, userAgent) {
|
|
45
|
+
const client = new Client({
|
|
46
|
+
name: "posthog-wizard",
|
|
47
|
+
version: VERSION
|
|
48
|
+
});
|
|
49
|
+
try {
|
|
50
|
+
const transport = new StreamableHTTPClientTransport(new URL(mcpUrl), { requestInit: { headers: {
|
|
51
|
+
Authorization: `Bearer ${accessToken}`,
|
|
52
|
+
"User-Agent": userAgent
|
|
53
|
+
} } });
|
|
54
|
+
await client.connect(transport);
|
|
55
|
+
const instructions = client.getInstructions() || void 0;
|
|
56
|
+
logToFile(`[pi-mcp] instructions ${instructions?.length ?? 0} chars`);
|
|
57
|
+
return instructions;
|
|
58
|
+
} catch (err) {
|
|
59
|
+
logToFile(`[pi-mcp] instructions fetch skipped: ${String(err)}`);
|
|
60
|
+
return;
|
|
61
|
+
} finally {
|
|
62
|
+
await client.close().catch(() => void 0);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function setupPostHogMcp(opts) {
|
|
66
|
+
const { mcpUrl, accessToken, userAgent } = opts;
|
|
67
|
+
const cleanup = acquireMcpToken(accessToken);
|
|
68
|
+
try {
|
|
69
|
+
const extensionFactory = (await createJiti(import.meta.url).import("pi-mcp-adapter")).createMcpAdapter({ config: {
|
|
70
|
+
mcpServers: { posthog: {
|
|
71
|
+
url: mcpUrl,
|
|
72
|
+
auth: "bearer",
|
|
73
|
+
bearerTokenEnv: MCP_TOKEN_ENV,
|
|
74
|
+
headers: { "User-Agent": userAgent },
|
|
75
|
+
lifecycle: "eager",
|
|
76
|
+
directTools: ["exec"],
|
|
77
|
+
exposeResources: false
|
|
78
|
+
} },
|
|
79
|
+
settings: {
|
|
80
|
+
disableProxyTool: true,
|
|
81
|
+
toolPrefix: "posthog"
|
|
82
|
+
}
|
|
83
|
+
} });
|
|
84
|
+
logToFile(`[pi-mcp] adapter loaded; posthog MCP at ${mcpUrl}`);
|
|
85
|
+
return {
|
|
86
|
+
extensionFactory,
|
|
87
|
+
cleanup
|
|
88
|
+
};
|
|
89
|
+
} catch (error) {
|
|
90
|
+
cleanup();
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { fetchInstructions, setupPostHogMcp };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=mcp-DAgaoGk5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-DAgaoGk5.js","names":[],"sources":["../src/agent/runner/harness/pi/mcp.ts"],"sourcesContent":["/**\n * pi has no built-in MCP; `pi-mcp-adapter` — pi's own MCP extension, built here\n * with its supported `createMcpAdapter` embedding API — bridges the same hosted\n * MCP the anthropic path uses into the agent.\n */\n\nimport { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport { createJiti } from 'jiti';\nimport { VERSION } from '@shared/version';\nimport { logToFile } from '@utils/debug';\nimport { onAccessTokenRotated } from '@shared/oauth-session';\n\nconst MCP_TOKEN_ENV = 'POSTHOG_MCP_TOKEN';\nlet mcpTokenOwners = 0;\nlet activeMcpToken: string | undefined;\nlet previousMcpToken: string | undefined;\n\nlet stopFollowingRotations: (() => void) | undefined;\n\nfunction setMcpToken(token: string): void {\n activeMcpToken = token;\n process.env[MCP_TOKEN_ENV] = token;\n}\n\nfunction acquireMcpToken(token: string): () => void {\n if (mcpTokenOwners === 0) {\n previousMcpToken = process.env[MCP_TOKEN_ENV];\n // The adapter reads the env on each connect, so reconnects take the rotated token.\n stopFollowingRotations = onAccessTokenRotated(setMcpToken);\n }\n // A later session after a rotation carries the newer token of the same login.\n if (activeMcpToken !== token) setMcpToken(token);\n mcpTokenOwners += 1;\n let released = false;\n return () => {\n if (released) return;\n released = true;\n mcpTokenOwners -= 1;\n if (mcpTokenOwners > 0) return;\n stopFollowingRotations?.();\n stopFollowingRotations = undefined;\n if (previousMcpToken === undefined) delete process.env[MCP_TOKEN_ENV];\n else process.env[MCP_TOKEN_ENV] = previousMcpToken;\n activeMcpToken = undefined;\n previousMcpToken = undefined;\n };\n}\n\nexport interface PostHogMcpSetup {\n /** pi ExtensionFactory to add to the resource loader's `extensionFactories`. */\n extensionFactory: (pi: unknown) => void;\n /** Release this setup's token ownership. Call after the run. */\n cleanup: () => void;\n}\n\n/** Server `instructions` for the system prompt — the adapter exposes no accessor, so one standard-SDK handshake; best-effort. */\nexport async function fetchInstructions(\n mcpUrl: string,\n accessToken: string,\n userAgent: string,\n): Promise<string | undefined> {\n const client = new Client({ name: 'posthog-wizard', version: VERSION });\n try {\n const transport = new StreamableHTTPClientTransport(new URL(mcpUrl), {\n requestInit: {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n 'User-Agent': userAgent,\n },\n },\n });\n await client.connect(transport);\n const instructions = client.getInstructions() || undefined;\n logToFile(`[pi-mcp] instructions ${instructions?.length ?? 0} chars`);\n return instructions;\n } catch (err) {\n logToFile(`[pi-mcp] instructions fetch skipped: ${String(err)}`);\n return undefined;\n } finally {\n await client.close().catch(() => undefined);\n }\n}\n\nexport async function setupPostHogMcp(opts: {\n mcpUrl: string;\n accessToken: string;\n userAgent: string;\n}): Promise<PostHogMcpSetup> {\n const { mcpUrl, accessToken, userAgent } = opts;\n\n // By env NAME: the token stays in this process, off disk, and never reaches pi's env-scrubbed tool subprocesses.\n const cleanup = acquireMcpToken(accessToken);\n\n try {\n // The adapter ships raw TypeScript; loading through jiti is its documented requirement.\n const jiti = createJiti(import.meta.url);\n const mod = await jiti.import<{\n createMcpAdapter: (\n options: unknown,\n ) => PostHogMcpSetup['extensionFactory'];\n }>('pi-mcp-adapter');\n const extensionFactory = mod.createMcpAdapter({\n config: {\n mcpServers: {\n posthog: {\n url: mcpUrl,\n auth: 'bearer',\n bearerTokenEnv: MCP_TOKEN_ENV,\n headers: { 'User-Agent': userAgent },\n // Connect at extension load — direct tools register without a session_start.\n lifecycle: 'eager',\n // Register only `exec`: `directTools: true` also mints a `posthog_get_<name>` tool per MCP resource, whose sentence-length names overflow Anthropic's 128-char tool-name limit and 400 the whole request.\n directTools: ['exec'],\n exposeResources: false,\n },\n },\n // Disable the proxy `mcp` tool (its search indirection pollutes context); the adapter re-enables it only if no direct tools resolve.\n settings: { disableProxyTool: true, toolPrefix: 'posthog' },\n },\n });\n logToFile(`[pi-mcp] adapter loaded; posthog MCP at ${mcpUrl}`);\n return { extensionFactory, cleanup };\n } catch (error) {\n cleanup();\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAaA,MAAM,gBAAgB;AACtB,IAAI,iBAAiB;AACrB,IAAI;AACJ,IAAI;AAEJ,IAAI;AAEJ,SAAS,YAAY,OAAqB;AACxC,kBAAiB;AAC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,WAAW;IAEpC,WAAW;IAEX,aAAa,CAAC,OAAO;IACrB,iBAAiB;IAClB,EACF;GAED,UAAU;IAAE,kBAAkB;IAAM,YAAY;IAAW;GAC5D,EACF,CAAC;AACF,YAAU,2CAA2C,SAAS;AAC9D,SAAO;GAAE;GAAkB;GAAS;UAC7B,OAAO;AACd,WAAS;AACT,QAAM"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { s as logToFile } from "./debug-Ch4BDOtD.js";
|
|
2
|
+
import { Q as WIZARD_USER_AGENT, l as DEFAULT_AGENT_MODEL } from "./constants-jFI2SaE1.js";
|
|
3
|
+
import { n as analytics } from "./analytics-CHCZ_qUR.js";
|
|
4
|
+
import { l as gatewayAuth } from "./gateway-CjoShdLa.js";
|
|
5
|
+
import { f as sanitizeAgentSubprocessEnv, n as buildRunTags, o as createIsolatedAgentConfigDir, t as buildAgentEnv } from "./agent-interface-BAOIHuXS.js";
|
|
6
|
+
//#region src/agent/mcp-prompt-streaming.ts
|
|
6
7
|
let _sdkModule = null;
|
|
7
8
|
async function loadSdk() {
|
|
8
9
|
if (!_sdkModule) _sdkModule = await import("@anthropic-ai/claude-agent-sdk");
|
|
@@ -249,4 +250,4 @@ async function* runMcpPromptViaSdk(args) {
|
|
|
249
250
|
//#endregion
|
|
250
251
|
export { runMcpPromptViaSdk };
|
|
251
252
|
|
|
252
|
-
//# sourceMappingURL=mcp-prompt-streaming-
|
|
253
|
+
//# sourceMappingURL=mcp-prompt-streaming-I2U_X7BC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-prompt-streaming-I2U_X7BC.js","names":[],"sources":["../src/agent/mcp-prompt-streaming.ts"],"sourcesContent":["/**\n * Streaming prompt runner for the McpSuggestedPromptsScreen.\n *\n * Calls the Claude Agent SDK's `query()` directly with just the PostHog\n * MCP server configured — no skills, no sandbox, no settings sources,\n * no wizard-tools. This is the lightweight cousin of `runAgent` in\n * `agent-interface.ts`: same SDK, much narrower surface, suitable for\n * \"user asked a question, show the answer\" interactions.\n *\n * The function is an async generator that yields `AgentChunk`s extracted\n * from the SDK's message stream. Callers (the screen) consume them via\n * `for await (...)` and render as they arrive.\n */\n\nimport type { Credentials } from '@shared/api';\nimport { DEFAULT_AGENT_MODEL, WIZARD_USER_AGENT } from '@shared/constants';\nimport { logToFile } from '@utils/debug';\nimport { gatewayAuth } from '@agent/gateway-session';\nimport { buildAgentEnv, buildRunTags } from '@agent/agent-interface';\nimport { sanitizeAgentSubprocessEnv } from '@agent/agent-env-isolation';\nimport { createIsolatedAgentConfigDir } from '@agent/stored-login';\nimport { analytics } from '@utils/analytics';\n\n/**\n * Discriminated union covering every kind of streamed event the screen\n * needs to render. Production yields these from Claude SDK messages;\n * the playground yields them from canned scripts.\n */\nexport type AgentChunk =\n | { kind: 'text'; text: string }\n /** `command` carries CLI mode's exec command string (`call <tool> …`) so the\n * screen can recover the inner tool for context-aware follow-ups. */\n | { kind: 'tool-call'; toolName: string; detail: string; command?: string }\n | { kind: 'tool-result'; toolName: string; detail: string }\n | { kind: 'error'; text: string }\n /** Stream completed. `sessionId` is the SDK session ID of the just-\n * completed turn; pass it back as `resumeSessionId` on a follow-up\n * call to continue the conversation with full history. */\n | { kind: 'done'; sessionId?: string };\n\n// Cached SDK module — first call pays the dynamic-import cost; later\n// calls reuse the same module.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet _sdkModule: any | null = null;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nasync function loadSdk(): Promise<any> {\n if (!_sdkModule) {\n _sdkModule = await import('@anthropic-ai/claude-agent-sdk');\n }\n return _sdkModule;\n}\n\nconst MODEL = DEFAULT_AGENT_MODEL;\n\n// Bounded turn count so a single prompt can't loop forever on the\n// user's nickel. 20 gives the agent room for non-trivial multi-step\n// chains (multi-tool reads → reason → write → verify → summarize) while\n// still capping runaway loops. Worth tuning down once we see real\n// telemetry on average turn counts per prompt.\nconst MAX_TURNS = 30;\n\n/**\n * Extract a short, single-line summary from an arbitrary value. Used\n * for tool-call args and tool-result bodies so the screen has something\n * compact to render.\n */\nfunction summarize(value: unknown, maxLen = 120): string {\n if (value == null) return '';\n let text: string;\n if (typeof value === 'string') text = value;\n else {\n try {\n text = JSON.stringify(value);\n } catch {\n text = String(value);\n }\n }\n text = text.replace(/\\s+/g, ' ').trim();\n if (text.length > maxLen) text = text.slice(0, maxLen - 1) + '…';\n return text;\n}\n\n/**\n * Convert one SDK message into zero or more AgentChunks. Mirrors the\n * subset of message shapes the wizard's main runAgent middleware\n * handles, but narrowed to just the kinds the screen needs to render.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction messageToChunks(message: any): AgentChunk[] {\n const chunks: AgentChunk[] = [];\n\n if (message?.type === 'assistant') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const content = message.message?.content;\n if (Array.isArray(content)) {\n for (const block of content) {\n if (!block || typeof block !== 'object') continue;\n const type = (block as { type?: string }).type;\n if (type === 'text') {\n const text = (block as { text?: string }).text ?? '';\n if (text) chunks.push({ kind: 'text', text });\n } else if (type === 'tool_use') {\n const name = (block as { name?: string }).name ?? 'tool';\n const input = (block as { input?: unknown }).input;\n // CLI mode's exec tool takes a `command` string; keep it verbatim so\n // the screen can recover the inner tool name for follow-ups.\n const command = (input as { command?: unknown })?.command;\n chunks.push({\n kind: 'tool-call',\n toolName: name,\n detail: summarize(input),\n command: typeof command === 'string' ? command : undefined,\n });\n }\n }\n }\n }\n\n if (message?.type === 'user') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const content = message.message?.content;\n if (Array.isArray(content)) {\n for (const block of content) {\n if (!block || typeof block !== 'object') continue;\n const type = (block as { type?: string }).type;\n if (type === 'tool_result') {\n const detail = summarize((block as { content?: unknown }).content);\n chunks.push({ kind: 'tool-result', toolName: 'tool', detail });\n }\n }\n }\n }\n\n if (message?.type === 'result') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const sessionId = (message as { session_id?: string }).session_id;\n chunks.push({ kind: 'done', sessionId });\n }\n\n return chunks;\n}\n\n/**\n * Build a system-prompt append that nudges the agent to fit its response\n * inside the current terminal window. We can't actually constrain Claude\n * — this is a soft cap that the model usually honors. The screen also\n * applies a hard truncation cap as a fallback for non-compliant runs.\n *\n * Core principle nudged at the model: TALL CONTENT IS BAD, WIDE CONTENT\n * IS GOOD. Default terminal is 120 columns × 24 rows — that's a lot of\n * horizontal space, not much vertical. Spread data across columns, never\n * stack it down rows when a horizontal layout would work.\n */\nfunction buildTerminalFitPrompt(): string {\n const cols = process.stdout.columns ?? 120;\n const rows = process.stdout.rows ?? 24;\n // Reserve rows for wizard chrome (title, status, hint, margins).\n const messageBudget = Math.max(8, rows - 10);\n\n return [\n `You are responding inside a CLI window that is exactly ${cols} columns wide and ${rows} rows tall. The user CAN'T SCROLL — your entire reply must fit on screen.`,\n ``,\n `LAYOUT PRINCIPLE: tall content is the enemy, wide content is your friend. You have ${cols} columns of horizontal space; use them. Spread data across columns instead of stacking it down rows.`,\n ``,\n `Tables:`,\n `- Max 5 body rows. The prompts the user picks already constrain results to 5 or fewer — honor that and do not pad with extra rows.`,\n `- If a tool result returns more than 5 items, show the top 5 and mention the rest count inline (e.g. \"...and 12 more\").`,\n `- Prefer transposing wide-but-short data (items across columns, metrics down rows) when labels are short.`,\n `- A two-column table with many rows is the tall layout to AVOID.`,\n ``,\n `Other limits:`,\n `- Aim for 3-5 lines of prose. Maximum ${messageBudget} lines total.`,\n `- DO NOT announce what you are about to do. Skip preamble like \"I'll query…\", \"Let me check…\", \"Now I'll…\", \"I'm going to…\". Go straight to running tools and then the answer.`,\n `- Lists: if there are 6+ short items, format them inline (comma-separated), not as a vertical bullet list.`,\n `- For tool results, summarize the 1-3 numbers that matter. Do NOT echo raw JSON or the full payload.`,\n `- Code blocks: no language tag, no leading blank lines.`,\n `- No closing pleasantries (\"let me know if…\", \"feel free to…\"). Stop when the answer is delivered.`,\n `- No section headers unless the response actually has multiple sections.`,\n ``,\n `Naming saved artifacts:`,\n `- Every dashboard, insight, notebook, or annotation you create MUST include \"(wizard MCP tutorial)\" at the end of its title or name field. Examples: \"Weekly signups (wizard MCP tutorial)\", \"Top errors this week (wizard MCP tutorial)\", \"Onboarding analysis (wizard MCP tutorial)\".`,\n `- This applies on both create AND rename calls. If the user asks you to rename a saved artifact, preserve the \"(wizard MCP tutorial)\" suffix unless they explicitly ask you to drop it.`,\n `- Reason: lets the user find / clean up everything this tutorial created from one search in PostHog. Don't skip it — it's the only signal they'll have that an artifact came from the wizard.`,\n ``,\n `Tone & framing:`,\n `- This is a tutorial demoing PostHog (the product the user just installed). You are showing it off, not auditing it. Stay constructive and neutral about PostHog throughout.`,\n `- Don't editorialize about PostHog's reliability, performance, or cost. Describe what the data shows; treat anomalies as the user's data, not a platform issue.`,\n `- If a tool call fails or returns nothing, say \"the query didn't return data — try a different angle\" or similar. Do NOT speculate about outages, gateway issues, MCP problems, or service health.`,\n `- Avoid value-laden phrases like \"worth investigating\", \"concerning\", \"red flag\", \"problematic\", \"suspicious\", \"alarming\" when describing the user's metrics. Stick to what the numbers show; the user draws conclusions.`,\n ].join('\\n');\n}\n\n/**\n * Gateway trace tags for a tutorial prompt run — without them the gateway has\n * nothing to attribute its `$ai_generation` events to. Returns `{}` when no\n * program is supplied. Exported so the contract is testable without the SDK.\n */\nexport function buildTutorialRunTags(args: {\n programId?: string;\n integration?: string;\n}): Record<string, string> {\n if (!args.programId) return {};\n return buildRunTags({\n programId: args.programId,\n // The tutorial usually has no detected framework; fall back to the\n // program so the axis is never an empty string.\n integration: args.integration ?? args.programId,\n runId: analytics.runId,\n build: analytics.build,\n });\n}\n\nexport async function* runMcpPromptViaSdk(args: {\n prompt: string;\n credentials: Credentials;\n signal: AbortSignal;\n /** When set, the SDK loads the named session's prior turns as\n * context so the follow-up prompt can reference what the agent\n * already showed. */\n resumeSessionId?: string;\n /** Program this run's gateway spend attributes to. Omitting it fails the run\n * rather than going unattributed, so every caller must supply one. */\n programId?: string;\n /** Integration label for the trace tags; the tutorial usually has none. */\n integration?: string;\n}): AsyncIterable<AgentChunk> {\n const { prompt, credentials, signal, resumeSessionId } = args;\n\n // Assembled here rather than passed in so the TUI service layer doesn't\n // have to import this module's dependencies.\n const wizardMetadata = buildTutorialRunTags(args);\n\n // Route the SDK's LLM calls through the PostHog AI gateway, authed\n // with the run's minted token. Set BEFORE loading the SDK in\n // case any in-process code reads env at module init (cached base\n // URLs, OAuth setup, etc.) — same reason `initializeAgent` does this\n // before its query() call. Without these the SDK tries to\n // authenticate directly against Anthropic and 401s with \"Invalid\n // authentication credentials\".\n process.env.CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS = 'true';\n\n // The url and the bearer are one unit: a run must take both from the same\n // mint.\n const auth = await gatewayAuth(\n credentials.host,\n credentials.accessToken,\n args.programId,\n );\n const gatewayUrl = auth.gatewayUrl;\n process.env.ANTHROPIC_BASE_URL = gatewayUrl;\n process.env.ANTHROPIC_AUTH_TOKEN = auth.token;\n process.env.CLAUDE_CODE_OAUTH_TOKEN = auth.token;\n\n logToFile(\n `[runMcpPromptViaSdk] gatewayUrl=${gatewayUrl} tokenPrefix=${\n auth.token ? auth.token.slice(0, 4) + '***' : '(missing)'\n }`,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const { query } = await loadSdk();\n\n // Bridge external AbortSignal → SDK AbortController.\n const abortController = new AbortController();\n if (signal.aborted) abortController.abort();\n else\n signal.addEventListener('abort', () => abortController.abort(), {\n once: true,\n });\n\n const mcpUrl = credentials.host.mcpUrl;\n logToFile(\n `[runMcpPromptViaSdk] mcpUrl=${mcpUrl} model=${MODEL} resume=${\n resumeSessionId ?? '(none)'\n }`,\n );\n\n // The SDK expects an async generator for the prompt that stays open\n // until the result is received. For a single-turn prompt we yield one\n // user message and then await an abort (which fires when streaming\n // completes or the caller cancels).\n const createPromptStream = async function* () {\n yield {\n type: 'user' as const,\n session_id: '',\n message: { role: 'user' as const, content: prompt },\n parent_tool_use_id: null,\n };\n // Hold the stream open until abort. The SDK closes its end when it\n // sees a `result` message; we close ours via the abortController in\n // the finally block below.\n await new Promise<void>((resolve) => {\n if (abortController.signal.aborted) {\n resolve();\n return;\n }\n abortController.signal.addEventListener('abort', () => resolve(), {\n once: true,\n });\n });\n };\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n const response = query({\n prompt: createPromptStream(),\n options: {\n abortController,\n model: MODEL,\n cwd: process.cwd(),\n permissionMode: 'acceptEdits',\n maxTurns: MAX_TURNS,\n // Match agent-interface.ts — the 1M context beta is what keeps\n // resumed follow-up sessions from truncating after a few turns.\n betas: ['context-1m-2025-08-07'],\n // Only load project-level skills/settings. Without this the SDK\n // defaults to ['user', 'project'] and a user's\n // `~/.claude/settings.json` (apiKeyHelper / env block) can\n // override the OAuth routing we set above.\n settingSources: ['project'],\n // When set, the SDK replays the named session's turns into the\n // new query so the follow-up prompt has full conversation\n // context. Omit on the first prompt for a fresh session.\n ...(resumeSessionId ? { resume: resumeSessionId } : {}),\n // Without `canUseTool` the SDK falls back to \"ask the user\" on\n // every MCP tool call — `permissionMode: 'acceptEdits'` only\n // relaxes Edit/Write, not MCP. Our Ink TUI has no surface to\n // answer that prompt, so the agent would stall mid-stream\n // saying things like \"needs your approval to create dashboard\".\n // The tutorial's whole point is demoing the MCP tools against\n // the user's project, so we auto-allow everything that matches\n // the prefix and deny anything else (defense in depth — the\n // `allowedTools` filter above already enforces this).\n canUseTool: (toolName: string, input: unknown) => {\n if (toolName.startsWith('mcp__posthog-wizard__')) {\n return Promise.resolve({\n behavior: 'allow' as const,\n updatedInput: (input ?? {}) as Record<string, unknown>,\n });\n }\n logToFile(`[runMcpPromptViaSdk] denying non-MCP tool: ${toolName}`);\n return Promise.resolve({\n behavior: 'deny' as const,\n message: `${toolName} is not available in the MCP tutorial — only PostHog MCP tools are permitted.`,\n });\n },\n systemPrompt: {\n type: 'preset',\n preset: 'claude_code',\n append: buildTerminalFitPrompt(),\n },\n mcpServers: {\n 'posthog-wizard': {\n type: 'http',\n url: mcpUrl,\n headers: {\n // Env reference, not the token: the SDK puts this config on the\n // spawned CLI's argv, where `ps` shows it to any local process.\n Authorization: 'Bearer ${POSTHOG_MCP_TOKEN}',\n 'User-Agent': WIZARD_USER_AGENT,\n },\n // CLI mode's single `exec` tool carries the full command reference\n // on its schema — keep it in context, never deferred behind tool\n // search.\n alwaysLoad: true,\n },\n },\n // Only let the agent use MCP tools — no shell, no file I/O,\n // no Read/Edit/Write. This is a chat-with-MCP run, not a\n // wizard skill execution.\n allowedTools: ['mcp__posthog-wizard__*'],\n env: {\n // Drop the ENTIRE ANTHROPIC_*/CLAUDE_CODE_* namespace from the\n // inherited env so no shell/settings value can silently bypass the\n // PostHog gateway and defeat quota tracking / the OAuth flow; the\n // wizard's own gateway routing is injected fresh below. See\n // agent-env-isolation.ts.\n ...sanitizeAgentSubprocessEnv(process.env),\n // Gateway routing from this run's own auth, not process.env: a\n // concurrent run writes those globals too, and there is an await\n // between the write above and this read.\n ANTHROPIC_BASE_URL: auth.gatewayUrl,\n ANTHROPIC_AUTH_TOKEN: auth.token,\n CLAUDE_CODE_OAUTH_TOKEN: auth.token,\n // Point the binary at an empty config dir so it cannot resolve a\n // stored Claude login and send that to the gateway, which 401s it.\n // See stored-login.ts.\n CLAUDE_CONFIG_DIR: createIsolatedAgentConfigDir(),\n CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS: 'true',\n // The MCP config resolves this in the child; sending the value would\n // put it on the CLI's argv.\n POSTHOG_MCP_TOKEN: credentials.accessToken,\n // SDK 0.3.142+ connects MCP servers in the background by\n // default; without this the agent may try to call tools\n // before posthog-wizard is connected on turn 1.\n MCP_CONNECTION_NONBLOCKING: '0',\n // This run's trace tags, which the gateway reads to attribute its\n // `$ai_generation` events. Flags stay empty: the tutorial doesn't\n // fork on any.\n ANTHROPIC_CUSTOM_HEADERS: buildAgentEnv(\n wizardMetadata ?? {},\n {},\n auth.teamId,\n ),\n },\n },\n });\n\n for await (const message of response as AsyncIterable<unknown>) {\n if (signal.aborted) return;\n for (const chunk of messageToChunks(message)) {\n yield chunk;\n if (chunk.kind === 'done') return;\n }\n }\n } catch (err) {\n const text = err instanceof Error ? err.message : String(err);\n logToFile(`[runMcpPromptViaSdk] error: ${text}`);\n yield { kind: 'error', text };\n } finally {\n // Closes the prompt stream so `query()` shuts down cleanly even if\n // we never saw a 'result' message.\n abortController.abort();\n }\n}\n"],"mappings":";;;;;;AA2CA,IAAI,aAAyB;AAG7B,eAAe,UAAwB;AACrC,KAAI,CAAC,WACH,cAAa,MAAM,OAAO;AAE5B,QAAO;;AAGT,MAAM,QAAQ;AAOd,MAAM,YAAY;;;;;;AAOlB,SAAS,UAAU,OAAgB,SAAS,KAAa;AACvD,KAAI,SAAS,KAAM,QAAO;CAC1B,IAAI;AACJ,KAAI,OAAO,UAAU,SAAU,QAAO;KAEpC,KAAI;AACF,SAAO,KAAK,UAAU,MAAM;SACtB;AACN,SAAO,OAAO,MAAM;;AAGxB,QAAO,KAAK,QAAQ,QAAQ,IAAI,CAAC,MAAM;AACvC,KAAI,KAAK,SAAS,OAAQ,QAAO,KAAK,MAAM,GAAG,SAAS,EAAE,GAAG;AAC7D,QAAO;;;;;;;AAST,SAAS,gBAAgB,SAA4B;CACnD,MAAM,SAAuB,EAAE;AAE/B,KAAI,SAAS,SAAS,aAAa;EAEjC,MAAM,UAAU,QAAQ,SAAS;AACjC,MAAI,MAAM,QAAQ,QAAQ,CACxB,MAAK,MAAM,SAAS,SAAS;AAC3B,OAAI,CAAC,SAAS,OAAO,UAAU,SAAU;GACzC,MAAM,OAAQ,MAA4B;AAC1C,OAAI,SAAS,QAAQ;IACnB,MAAM,OAAQ,MAA4B,QAAQ;AAClD,QAAI,KAAM,QAAO,KAAK;KAAE,MAAM;KAAQ;KAAM,CAAC;cACpC,SA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
-
import {
|
|
13
|
-
import { i as
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
1
|
+
import { a as AgentSignals, d as ErrorCodes } from "./errors-CQ9kttJD.js";
|
|
2
|
+
import { r as debug, s as logToFile, x as regionOption, y as headlessOption } from "./debug-Ch4BDOtD.js";
|
|
3
|
+
import { Q as WIZARD_USER_AGENT, U as WIZARD_INTERACTION_EVENT_NAME, f as EVENTS_AUDIT_REPORT_FILE, h as EVENT_PLAN_FILE, k as POSTHOG_DOCS_URL, w as Integration } from "./constants-jFI2SaE1.js";
|
|
4
|
+
import { r as mayReportScanResults } from "./wizard-session-2w4Ru-Wz.js";
|
|
5
|
+
import { n as analytics } from "./analytics-CHCZ_qUR.js";
|
|
6
|
+
import { i as withUtm, n as openTrackedLink } from "./telemetry-D6ruCtnv.js";
|
|
7
|
+
import "./bounded-fs-Bx9zTe6m.js";
|
|
8
|
+
import { i as tryGetPackageJson, n as isUsingTypeScript } from "./setup-utils-CmTCTPkX.js";
|
|
9
|
+
import { a as getBlockingServiceKeys, i as evaluateWizardReadiness, r as SIGNUP_WIZARD_READINESS_CONFIG } from "./logging-ui-_TwoMNbG.js";
|
|
10
|
+
import { t as getUI } from "./ui-BBVuTM1v.js";
|
|
11
|
+
import { i as requestDeepLink } from "./provisioning-B8uSqRZk.js";
|
|
12
|
+
import { s as handleApiError } from "./api-Diy_2fp8.js";
|
|
13
|
+
import { i as wizardAbort } from "./wizard-abort-BBkiUxfS.js";
|
|
14
|
+
import { _ as detectProjectsWithAgent, b as detectFramework, d as findPackageJsons, f as WAREHOUSE_ABORT_CASES, g as AgenticDetectionTimeoutError, h as detectWarehouseSources, m as getDetectedWarehouseSources, o as detectPostHogIntegration, p as detectWarehousePrerequisites, r as AUDIT_CHECKS_KEY, t as runProgramAgent, v as resolveProjectDir, x as authenticate, y as gatherFrameworkContext } from "./run-agent-legacy-d7rWlzQR.js";
|
|
15
|
+
import { I as WIZARD_TOOL_NAMES, nt as LONGER_ASK_TIMEOUT_MS } from "./agent-interface-BAOIHuXS.js";
|
|
16
|
+
import { s as shouldDisableAsk } from "./agent-bCZ3i3fh.js";
|
|
17
|
+
import { g as AUDIT_REPORT_FILE, h as AUDIT_CHECKS_FILE } from "./yara-hooks-DCeMDd1o.js";
|
|
18
|
+
import { y as writeJsonAtomic } from "./queue-tools-9OOVx5TE.js";
|
|
19
|
+
import { i as SPINNER_MESSAGE, t as FRAMEWORK_REGISTRY } from "./registry-8YG-kuXk.js";
|
|
16
20
|
import { existsSync, readFileSync, readdirSync, statSync } from "fs";
|
|
17
21
|
import path, { join } from "path";
|
|
18
22
|
import * as os from "node:os";
|
|
@@ -1195,7 +1199,62 @@ const getContentBlocks$5 = (store) => [
|
|
|
1195
1199
|
content: "PostHog has all the dev tools you need.",
|
|
1196
1200
|
pause: 3e3
|
|
1197
1201
|
},
|
|
1198
|
-
PRODUCT_SUITE_BLOCK
|
|
1202
|
+
PRODUCT_SUITE_BLOCK,
|
|
1203
|
+
{
|
|
1204
|
+
type: "clear",
|
|
1205
|
+
pause: 2e3
|
|
1206
|
+
},
|
|
1207
|
+
{
|
|
1208
|
+
content: "The wizard is wiring up your PostHog stack with...",
|
|
1209
|
+
pause: 2500
|
|
1210
|
+
},
|
|
1211
|
+
{
|
|
1212
|
+
type: "lines",
|
|
1213
|
+
interval: 1e3,
|
|
1214
|
+
pause: 12e3,
|
|
1215
|
+
lines: [
|
|
1216
|
+
/* @__PURE__ */ jsxs(Text, { children: [
|
|
1217
|
+
/* @__PURE__ */ jsx(Text, {
|
|
1218
|
+
color: "cyan",
|
|
1219
|
+
children: " ◆ "
|
|
1220
|
+
}),
|
|
1221
|
+
"Product Analytics ",
|
|
1222
|
+
/* @__PURE__ */ jsx(Text, {
|
|
1223
|
+
color: "cyan",
|
|
1224
|
+
children: "◆ "
|
|
1225
|
+
}),
|
|
1226
|
+
"Web Analytics"
|
|
1227
|
+
] }),
|
|
1228
|
+
/* @__PURE__ */ jsxs(Text, { children: [
|
|
1229
|
+
/* @__PURE__ */ jsx(Text, {
|
|
1230
|
+
color: "cyan",
|
|
1231
|
+
children: " ◆ "
|
|
1232
|
+
}),
|
|
1233
|
+
"Error Tracking ",
|
|
1234
|
+
/* @__PURE__ */ jsx(Text, {
|
|
1235
|
+
color: "cyan",
|
|
1236
|
+
children: "◆ "
|
|
1237
|
+
}),
|
|
1238
|
+
"Session Replay"
|
|
1239
|
+
] }),
|
|
1240
|
+
/* @__PURE__ */ jsxs(Text, { children: [
|
|
1241
|
+
/* @__PURE__ */ jsx(Text, {
|
|
1242
|
+
color: "cyan",
|
|
1243
|
+
children: " ◆ "
|
|
1244
|
+
}),
|
|
1245
|
+
"AI Observability ",
|
|
1246
|
+
/* @__PURE__ */ jsx(Text, {
|
|
1247
|
+
color: "cyan",
|
|
1248
|
+
children: "◆ "
|
|
1249
|
+
}),
|
|
1250
|
+
"Logs"
|
|
1251
|
+
] }),
|
|
1252
|
+
/* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Text, {
|
|
1253
|
+
color: "cyan",
|
|
1254
|
+
children: " ◆ "
|
|
1255
|
+
}), "Data Warehouse sources"] })
|
|
1256
|
+
]
|
|
1257
|
+
}
|
|
1199
1258
|
];
|
|
1200
1259
|
//#endregion
|
|
1201
1260
|
//#region src/lib/programs/posthog-integration/handoff.ts
|
|
@@ -1403,7 +1462,7 @@ const posthogIntegrationConfig = {
|
|
|
1403
1462
|
if (usesPackageJson) {
|
|
1404
1463
|
const packageJson = await tryGetPackageJson({ installDir: session.installDir });
|
|
1405
1464
|
if (packageJson) {
|
|
1406
|
-
const { hasDeclaredDependency } = await import("./package-json-
|
|
1465
|
+
const { hasDeclaredDependency } = await import("./package-json-DY70kkNp.js").then((n) => n.i);
|
|
1407
1466
|
if (!hasDeclaredDependency(config.detection.packageName, packageJson)) getUI().log.warn(`${config.detection.packageDisplayName} does not seem to be installed. Continuing anyway — the agent will handle it.`);
|
|
1408
1467
|
frameworkVersion = config.detection.getVersion(packageJson);
|
|
1409
1468
|
} else getUI().log.warn("Could not find package.json. Continuing anyway — the agent will handle it.");
|
|
@@ -1428,7 +1487,6 @@ const posthogIntegrationConfig = {
|
|
|
1428
1487
|
reportFile: SETUP_REPORT_FILE,
|
|
1429
1488
|
docsUrl: config.metadata.docsUrl,
|
|
1430
1489
|
errorMessage: "Integration failed",
|
|
1431
|
-
additionalFeatureQueue: session.additionalFeatureQueue,
|
|
1432
1490
|
richLinks: true,
|
|
1433
1491
|
customPrompt: (ctx) => {
|
|
1434
1492
|
const additionalLines = config.prompts.getAdditionalContextLines ? config.prompts.getAdditionalContextLines(frameworkContext) : [];
|
|
@@ -1473,7 +1531,7 @@ ${warehouseReportInstruction(session)}
|
|
|
1473
1531
|
postRun: async (sess, credentials) => {
|
|
1474
1532
|
const envVars = config.environment.getEnvVars(credentials.projectApiKey, credentials.host.apiHost);
|
|
1475
1533
|
if (config.environment.uploadToHosting) {
|
|
1476
|
-
const { uploadEnvironmentVariablesStep } = await import("./steps-
|
|
1534
|
+
const { uploadEnvironmentVariablesStep } = await import("./steps-BZcXRJNY.js");
|
|
1477
1535
|
const uploadedEnvVars = await uploadEnvironmentVariablesStep(envVars, {
|
|
1478
1536
|
integration: config.metadata.integration,
|
|
1479
1537
|
session: sess
|
|
@@ -1524,7 +1582,7 @@ const integrationRunStep = {
|
|
|
1524
1582
|
id: "run",
|
|
1525
1583
|
label: "Integration",
|
|
1526
1584
|
screenId: "run",
|
|
1527
|
-
run: (session) =>
|
|
1585
|
+
run: (session) => runProgramAgent(posthogIntegrationConfig, session, { composed: true }),
|
|
1528
1586
|
isComplete: (session) => session.runPhase === "completed" || session.runPhase === "error"
|
|
1529
1587
|
};
|
|
1530
1588
|
//#endregion
|
|
@@ -2178,7 +2236,7 @@ const eventsAuditConfig = {
|
|
|
2178
2236
|
id: "events-audit",
|
|
2179
2237
|
skillId: "events-audit",
|
|
2180
2238
|
steps: EVENTS_AUDIT_PROGRAM,
|
|
2181
|
-
reportFile:
|
|
2239
|
+
reportFile: EVENTS_AUDIT_REPORT_FILE,
|
|
2182
2240
|
auditLedgerFile: AUDIT_CHECKS_FILE,
|
|
2183
2241
|
allowedTools: [
|
|
2184
2242
|
"Agent",
|
|
@@ -2198,10 +2256,9 @@ const eventsAuditConfig = {
|
|
|
2198
2256
|
spinnerMessage: SPINNER_MESSAGE,
|
|
2199
2257
|
successMessage: "Events audit complete! You can view the report at ./posthog-events-audit-report.md",
|
|
2200
2258
|
estimatedDurationMinutes: 5,
|
|
2201
|
-
reportFile:
|
|
2259
|
+
reportFile: EVENTS_AUDIT_REPORT_FILE,
|
|
2202
2260
|
docsUrl: DOCS_URL$3,
|
|
2203
2261
|
errorMessage: "Events audit failed",
|
|
2204
|
-
additionalFeatureQueue: session.additionalFeatureQueue,
|
|
2205
2262
|
customPrompt: (ctx) => `Audit PostHog event capture in this project. Do not modify any project files — produce a read-only report only.
|
|
2206
2263
|
|
|
2207
2264
|
Project context:
|
|
@@ -2215,7 +2272,7 @@ Project context:
|
|
|
2215
2272
|
return {
|
|
2216
2273
|
kind: "success",
|
|
2217
2274
|
message: "Your events audit was successful",
|
|
2218
|
-
reportFile:
|
|
2275
|
+
reportFile: EVENTS_AUDIT_REPORT_FILE,
|
|
2219
2276
|
changes: [],
|
|
2220
2277
|
docsUrl: DOCS_URL$3,
|
|
2221
2278
|
continueUrl: sess.signup ? `${cloudUrl}/products?source=wizard` : void 0,
|
|
@@ -5769,4 +5826,4 @@ function isRunFailure(session) {
|
|
|
5769
5826
|
//#endregion
|
|
5770
5827
|
export { wordWrap as $, installOrUpdatePostHogCli as A, webAnalyticsDoctorConfig as B, ERROR_TRACKING_PROJECT_PATH_KEY as C, CLI_STEERING_TARGETS as D, errorTrackingUploadSourceMapsConfig as E, MANUAL_SDK_INSTALL as F, createSkillProgram as G, getKindMeta as H, MANUAL_SDK_VARIANTS as I, getContentBlocks$4 as J, warehouseSourceConfig as K, RUST_SDK_CRATE as L, AUTOMATABLE_VARIANTS as M, DISPLAY_NAME as N, detectTargets as O, GO_SDK_MODULE as P, computeVisibleRange as Q, SOURCE_MAPS_CONTEXT_KEYS as R, errorTrackingConfig as S, replayVisionConfig as T, fetchHealthIssues as U, posthogDoctorConfig as V, auditConfig as W, posthogIntegrationConfig as X, SETUP_REPORT_FILE as Y, TextBlock as Z, PRICING_SHORT as _, PROGRAM_REGISTRY as a, GITHUB_REQUIRED_MESSAGE as b, getCommandPath as c, metricsConfig as d, isClearBlock as et, aiObservabilityConfig as f, PRICING_LONG as g, NO_DEFAULT_LIMIT as h, isRunFailure as i, Icons as it, installSteeringSnippet as j, findTarget as k, getLaunchablePrograms as l, selfDrivingConfig as m, MINT_FAILURE_CONTACT as n, isObjectBlock as nt, Program as o, mcpAnalyticsConfig as p, revenueAnalyticsConfig as q, MINT_FAILURE_MESSAGE as r, Colors as rt, agentSkillConfig as s, MINT_FAILURE_BODY as t, isLinesBlock as tt, getProgramConfig as u, detectSelfDrivingIntegrationProjects as v, detectErrorTrackingProjects as w, SELF_DRIVING_INTEGRATE_PATH_KEY as x, GITHUB_REQUIRED_BODY as y, migrationConfig as z };
|
|
5771
5828
|
|
|
5772
|
-
//# sourceMappingURL=mint-failure-
|
|
5829
|
+
//# sourceMappingURL=mint-failure-D4nd2XmZ.js.map
|