@posthog/wizard 1.28.0 → 1.29.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/dist/src/flask/flask-wizard-agent.d.ts +5 -0
- package/dist/src/flask/flask-wizard-agent.js +160 -0
- package/dist/src/flask/flask-wizard-agent.js.map +1 -0
- package/dist/src/flask/utils.d.ts +28 -0
- package/dist/src/flask/utils.js +363 -0
- package/dist/src/flask/utils.js.map +1 -0
- package/dist/src/lib/agent-interface.js +14 -1
- package/dist/src/lib/agent-interface.js.map +1 -1
- package/dist/src/lib/config.d.ts +12 -1
- package/dist/src/lib/config.js +79 -0
- package/dist/src/lib/config.js.map +1 -1
- package/dist/src/lib/constants.d.ts +2 -1
- package/dist/src/lib/constants.js +3 -0
- package/dist/src/lib/constants.js.map +1 -1
- package/dist/src/run.js +6 -0
- package/dist/src/run.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.runFlaskWizardAgent = runFlaskWizardAgent;
|
|
40
|
+
const debug_1 = require("../utils/debug");
|
|
41
|
+
const agent_runner_1 = require("../lib/agent-runner");
|
|
42
|
+
const constants_1 = require("../lib/constants");
|
|
43
|
+
const clack_1 = __importDefault(require("../utils/clack"));
|
|
44
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
45
|
+
const semver = __importStar(require("semver"));
|
|
46
|
+
const utils_1 = require("./utils");
|
|
47
|
+
/**
|
|
48
|
+
* Flask framework configuration for the universal agent runner
|
|
49
|
+
*/
|
|
50
|
+
const MINIMUM_FLASK_VERSION = '2.0.0';
|
|
51
|
+
const FLASK_AGENT_CONFIG = {
|
|
52
|
+
metadata: {
|
|
53
|
+
name: 'Flask',
|
|
54
|
+
integration: constants_1.Integration.flask,
|
|
55
|
+
docsUrl: 'https://posthog.com/docs/libraries/python',
|
|
56
|
+
unsupportedVersionDocsUrl: 'https://posthog.com/docs/libraries/python',
|
|
57
|
+
gatherContext: async (options) => {
|
|
58
|
+
const projectType = await (0, utils_1.getFlaskProjectType)(options);
|
|
59
|
+
const appFile = await (0, utils_1.findFlaskAppFile)(options);
|
|
60
|
+
return { projectType, appFile };
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
detection: {
|
|
64
|
+
packageName: 'flask',
|
|
65
|
+
packageDisplayName: 'Flask',
|
|
66
|
+
usesPackageJson: false,
|
|
67
|
+
getVersion: (_packageJson) => {
|
|
68
|
+
// For Flask, we don't use package.json. Version is extracted separately
|
|
69
|
+
// from requirements.txt or pyproject.toml in the wizard entry point
|
|
70
|
+
return undefined;
|
|
71
|
+
},
|
|
72
|
+
getVersionBucket: utils_1.getFlaskVersionBucket,
|
|
73
|
+
},
|
|
74
|
+
environment: {
|
|
75
|
+
uploadToHosting: false,
|
|
76
|
+
getEnvVars: (apiKey, host) => ({
|
|
77
|
+
POSTHOG_API_KEY: apiKey,
|
|
78
|
+
POSTHOG_HOST: host,
|
|
79
|
+
}),
|
|
80
|
+
},
|
|
81
|
+
analytics: {
|
|
82
|
+
getTags: (context) => {
|
|
83
|
+
const projectType = context.projectType;
|
|
84
|
+
return {
|
|
85
|
+
projectType: projectType || 'unknown',
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
prompts: {
|
|
90
|
+
projectTypeDetection: 'This is a Python/Flask project. Look for requirements.txt, pyproject.toml, setup.py, Pipfile, or app.py/wsgi.py to confirm.',
|
|
91
|
+
packageInstallation: 'Use pip, poetry, or pipenv based on existing config files (requirements.txt, pyproject.toml, Pipfile). Do not pin the posthog version - just add "posthog" without version constraints.',
|
|
92
|
+
getAdditionalContextLines: (context) => {
|
|
93
|
+
const projectType = context.projectType;
|
|
94
|
+
const projectTypeName = projectType
|
|
95
|
+
? (0, utils_1.getFlaskProjectTypeName)(projectType)
|
|
96
|
+
: 'unknown';
|
|
97
|
+
// Map project type to framework ID for MCP docs resource
|
|
98
|
+
const frameworkIdMap = {
|
|
99
|
+
[utils_1.FlaskProjectType.STANDARD]: 'flask',
|
|
100
|
+
[utils_1.FlaskProjectType.RESTFUL]: 'flask',
|
|
101
|
+
[utils_1.FlaskProjectType.RESTX]: 'flask',
|
|
102
|
+
[utils_1.FlaskProjectType.SMOREST]: 'flask',
|
|
103
|
+
[utils_1.FlaskProjectType.BLUEPRINT]: 'flask',
|
|
104
|
+
};
|
|
105
|
+
const frameworkId = projectType ? frameworkIdMap[projectType] : 'flask';
|
|
106
|
+
const lines = [
|
|
107
|
+
`Project type: ${projectTypeName}`,
|
|
108
|
+
`Framework docs ID: ${frameworkId} (use posthog://docs/frameworks/${frameworkId} for documentation)`,
|
|
109
|
+
];
|
|
110
|
+
if (context.appFile) {
|
|
111
|
+
lines.push(`App file: ${context.appFile}`);
|
|
112
|
+
}
|
|
113
|
+
return lines;
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
ui: {
|
|
117
|
+
successMessage: 'PostHog integration complete',
|
|
118
|
+
estimatedDurationMinutes: 5,
|
|
119
|
+
getOutroChanges: (context) => {
|
|
120
|
+
const projectType = context.projectType;
|
|
121
|
+
const projectTypeName = projectType
|
|
122
|
+
? (0, utils_1.getFlaskProjectTypeName)(projectType)
|
|
123
|
+
: 'Flask';
|
|
124
|
+
return [
|
|
125
|
+
`Analyzed your ${projectTypeName} project structure`,
|
|
126
|
+
`Installed the PostHog Python package`,
|
|
127
|
+
`Configured PostHog in your Flask application`,
|
|
128
|
+
`Added PostHog initialization with automatic event tracking`,
|
|
129
|
+
];
|
|
130
|
+
},
|
|
131
|
+
getOutroNextSteps: () => [
|
|
132
|
+
'Start your Flask development server to see PostHog in action',
|
|
133
|
+
'Visit your PostHog dashboard to see incoming events',
|
|
134
|
+
'Use posthog.identify() to associate events with users',
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Flask wizard powered by the universal agent runner.
|
|
140
|
+
*/
|
|
141
|
+
async function runFlaskWizardAgent(options) {
|
|
142
|
+
if (options.debug) {
|
|
143
|
+
(0, debug_1.enableDebugLogs)();
|
|
144
|
+
}
|
|
145
|
+
// Check Flask version - agent wizard requires >= 2.0.0
|
|
146
|
+
const flaskVersion = await (0, utils_1.getFlaskVersion)(options);
|
|
147
|
+
if (flaskVersion) {
|
|
148
|
+
const coercedVersion = semver.coerce(flaskVersion);
|
|
149
|
+
if (coercedVersion && semver.lt(coercedVersion, MINIMUM_FLASK_VERSION)) {
|
|
150
|
+
const docsUrl = FLASK_AGENT_CONFIG.metadata.unsupportedVersionDocsUrl ??
|
|
151
|
+
FLASK_AGENT_CONFIG.metadata.docsUrl;
|
|
152
|
+
clack_1.default.log.warn(`Sorry: the wizard can't help you with Flask ${flaskVersion}. Upgrade to Flask ${MINIMUM_FLASK_VERSION} or later, or check out the manual setup guide.`);
|
|
153
|
+
clack_1.default.log.info(`Setup Flask manually: ${chalk_1.default.cyan(docsUrl)}`);
|
|
154
|
+
clack_1.default.outro('PostHog wizard will see you next time!');
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
await (0, agent_runner_1.runAgentWizard)(FLASK_AGENT_CONFIG, options);
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=flask-wizard-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flask-wizard-agent.js","sourceRoot":"","sources":["../../../src/flask/flask-wizard-agent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8HA,kDA2BC;AAtJD,0CAAiD;AACjD,sDAAqD;AACrD,gDAA+C;AAC/C,2DAAmC;AACnC,kDAA0B;AAC1B,+CAAiC;AACjC,mCAOiB;AAEjB;;GAEG;AACH,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAEtC,MAAM,kBAAkB,GAAoB;IAC1C,QAAQ,EAAE;QACR,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,uBAAW,CAAC,KAAK;QAC9B,OAAO,EAAE,2C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AE,CAAC;IACpB,CAAC;IAED,uDAAuD;IACvD,MAAM,YAAY,GAAG,MAAM,IAAA,uBAAe,EAAC,OAAO,CAAC,CAAC;IAEpD,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACnD,IAAI,cAAc,IAAI,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,qBAAqB,CAAC,EAAE,CAAC;YACvE,MAAM,OAAO,GACX,kBAAkB,CAAC,QAAQ,CAAC,yBAAyB;gBACrD,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC;YAEtC,eAAK,CAAC,GAAG,CAAC,IAAI,CACZ,+CAA+C,YAAY,sBAAsB,qBAAqB,iDAAiD,CACxJ,CAAC;YACF,eAAK,CAAC,GAAG,CAAC,IAAI,CAAC,yBAAyB,eAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC/D,eAAK,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;YACtD,OAAO;QACT,CAAC;IACH,CAAC;IAED,MAAM,IAAA,6BAAc,EAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/* Flask wizard using posthog-agent with PostHog MCP */\nimport type { WizardOptions } from '../utils/types';\nimport type { FrameworkConfig } from '../lib/framework-config';\nimport { enableDebugLogs } from '../utils/debug';\nimport { runAgentWizard } from '../lib/agent-runner';\nimport { Integration } from '../lib/constants';\nimport clack from '../utils/clack';\nimport chalk from 'chalk';\nimport * as semver from 'semver';\nimport {\n getFlaskVersion,\n getFlaskProjectType,\n getFlaskProjectTypeName,\n getFlaskVersionBucket,\n FlaskProjectType,\n findFlaskAppFile,\n} from './utils';\n\n/**\n * Flask framework configuration for the universal agent runner\n */\nconst MINIMUM_FLASK_VERSION = '2.0.0';\n\nconst FLASK_AGENT_CONFIG: FrameworkConfig = {\n metadata: {\n name: 'Flask',\n integration: Integration.flask,\n docsUrl: 'https://posthog.com/docs/libraries/python',\n unsupportedVersionDocsUrl: 'https://posthog.com/docs/libraries/python',\n gatherContext: async (options: WizardOptions) => {\n const projectType = await getFlaskProjectType(options);\n const appFile = await findFlaskAppFile(options);\n return { projectType, appFile };\n },\n },\n\n detection: {\n packageName: 'flask',\n packageDisplayName: 'Flask',\n usesPackageJson: false,\n getVersion: (_packageJson: any) => {\n // For Flask, we don't use package.json. Version is extracted separately\n // from requirements.txt or pyproject.toml in the wizard entry point\n return undefined;\n },\n getVersionBucket: getFlaskVersionBucket,\n },\n\n environment: {\n uploadToHosting: false,\n getEnvVars: (apiKey: string, host: string) => ({\n POSTHOG_API_KEY: apiKey,\n POSTHOG_HOST: host,\n }),\n },\n\n analytics: {\n getTags: (context: any) => {\n const projectType = context.projectType as FlaskProjectType;\n return {\n projectType: projectType || 'unknown',\n };\n },\n },\n\n prompts: {\n projectTypeDetection:\n 'This is a Python/Flask project. Look for requirements.txt, pyproject.toml, setup.py, Pipfile, or app.py/wsgi.py to confirm.',\n packageInstallation:\n 'Use pip, poetry, or pipenv based on existing config files (requirements.txt, pyproject.toml, Pipfile). Do not pin the posthog version - just add \"posthog\" without version constraints.',\n getAdditionalContextLines: (context: any) => {\n const projectType = context.projectType as FlaskProjectType;\n const projectTypeName = projectType\n ? getFlaskProjectTypeName(projectType)\n : 'unknown';\n\n // Map project type to framework ID for MCP docs resource\n const frameworkIdMap: Record<FlaskProjectType, string> = {\n [FlaskProjectType.STANDARD]: 'flask',\n [FlaskProjectType.RESTFUL]: 'flask',\n [FlaskProjectType.RESTX]: 'flask',\n [FlaskProjectType.SMOREST]: 'flask',\n [FlaskProjectType.BLUEPRINT]: 'flask',\n };\n\n const frameworkId = projectType ? frameworkIdMap[projectType] : 'flask';\n\n const lines = [\n `Project type: ${projectTypeName}`,\n `Framework docs ID: ${frameworkId} (use posthog://docs/frameworks/${frameworkId} for documentation)`,\n ];\n\n if (context.appFile) {\n lines.push(`App file: ${context.appFile}`);\n }\n\n return lines;\n },\n },\n\n ui: {\n successMessage: 'PostHog integration complete',\n estimatedDurationMinutes: 5,\n getOutroChanges: (context: any) => {\n const projectType = context.projectType as FlaskProjectType;\n const projectTypeName = projectType\n ? getFlaskProjectTypeName(projectType)\n : 'Flask';\n return [\n `Analyzed your ${projectTypeName} project structure`,\n `Installed the PostHog Python package`,\n `Configured PostHog in your Flask application`,\n `Added PostHog initialization with automatic event tracking`,\n ];\n },\n getOutroNextSteps: () => [\n 'Start your Flask development server to see PostHog in action',\n 'Visit your PostHog dashboard to see incoming events',\n 'Use posthog.identify() to associate events with users',\n ],\n },\n};\n\n/**\n * Flask wizard powered by the universal agent runner.\n */\nexport async function runFlaskWizardAgent(\n options: WizardOptions,\n): Promise<void> {\n if (options.debug) {\n enableDebugLogs();\n }\n\n // Check Flask version - agent wizard requires >= 2.0.0\n const flaskVersion = await getFlaskVersion(options);\n\n if (flaskVersion) {\n const coercedVersion = semver.coerce(flaskVersion);\n if (coercedVersion && semver.lt(coercedVersion, MINIMUM_FLASK_VERSION)) {\n const docsUrl =\n FLASK_AGENT_CONFIG.metadata.unsupportedVersionDocsUrl ??\n FLASK_AGENT_CONFIG.metadata.docsUrl;\n\n clack.log.warn(\n `Sorry: the wizard can't help you with Flask ${flaskVersion}. Upgrade to Flask ${MINIMUM_FLASK_VERSION} or later, or check out the manual setup guide.`,\n );\n clack.log.info(`Setup Flask manually: ${chalk.cyan(docsUrl)}`);\n clack.outro('PostHog wizard will see you next time!');\n return;\n }\n }\n\n await runAgentWizard(FLASK_AGENT_CONFIG, options);\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { WizardOptions } from '../utils/types';
|
|
2
|
+
export declare enum FlaskProjectType {
|
|
3
|
+
STANDARD = "standard",// Basic Flask app
|
|
4
|
+
RESTFUL = "restful",// Flask-RESTful API
|
|
5
|
+
RESTX = "restx",// Flask-RESTX (Swagger docs)
|
|
6
|
+
SMOREST = "smorest",// flask-smorest (OpenAPI)
|
|
7
|
+
BLUEPRINT = "blueprint"
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get Flask version bucket for analytics
|
|
11
|
+
*/
|
|
12
|
+
export declare function getFlaskVersionBucket(version: string | undefined): string;
|
|
13
|
+
/**
|
|
14
|
+
* Extract Flask version from requirements files or pyproject.toml
|
|
15
|
+
*/
|
|
16
|
+
export declare function getFlaskVersion(options: Pick<WizardOptions, 'installDir'>): Promise<string | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Detect Flask project type
|
|
19
|
+
*/
|
|
20
|
+
export declare function getFlaskProjectType(options: WizardOptions): Promise<FlaskProjectType>;
|
|
21
|
+
/**
|
|
22
|
+
* Get human-readable name for Flask project type
|
|
23
|
+
*/
|
|
24
|
+
export declare function getFlaskProjectTypeName(projectType: FlaskProjectType): string;
|
|
25
|
+
/**
|
|
26
|
+
* Find the main Flask app file
|
|
27
|
+
*/
|
|
28
|
+
export declare function findFlaskAppFile(options: Pick<WizardOptions, 'installDir'>): Promise<string | undefined>;
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.FlaskProjectType = void 0;
|
|
40
|
+
exports.getFlaskVersionBucket = getFlaskVersionBucket;
|
|
41
|
+
exports.getFlaskVersion = getFlaskVersion;
|
|
42
|
+
exports.getFlaskProjectType = getFlaskProjectType;
|
|
43
|
+
exports.getFlaskProjectTypeName = getFlaskProjectTypeName;
|
|
44
|
+
exports.findFlaskAppFile = findFlaskAppFile;
|
|
45
|
+
const semver_1 = require("semver");
|
|
46
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
47
|
+
const clack_1 = __importDefault(require("../utils/clack"));
|
|
48
|
+
const fs = __importStar(require("node:fs"));
|
|
49
|
+
const path = __importStar(require("node:path"));
|
|
50
|
+
var FlaskProjectType;
|
|
51
|
+
(function (FlaskProjectType) {
|
|
52
|
+
FlaskProjectType["STANDARD"] = "standard";
|
|
53
|
+
FlaskProjectType["RESTFUL"] = "restful";
|
|
54
|
+
FlaskProjectType["RESTX"] = "restx";
|
|
55
|
+
FlaskProjectType["SMOREST"] = "smorest";
|
|
56
|
+
FlaskProjectType["BLUEPRINT"] = "blueprint";
|
|
57
|
+
})(FlaskProjectType || (exports.FlaskProjectType = FlaskProjectType = {}));
|
|
58
|
+
const IGNORE_PATTERNS = [
|
|
59
|
+
'**/node_modules/**',
|
|
60
|
+
'**/dist/**',
|
|
61
|
+
'**/build/**',
|
|
62
|
+
'**/venv/**',
|
|
63
|
+
'**/.venv/**',
|
|
64
|
+
'**/env/**',
|
|
65
|
+
'**/.env/**',
|
|
66
|
+
'**/__pycache__/**',
|
|
67
|
+
'**/migrations/**',
|
|
68
|
+
'**/instance/**',
|
|
69
|
+
];
|
|
70
|
+
/**
|
|
71
|
+
* Get Flask version bucket for analytics
|
|
72
|
+
*/
|
|
73
|
+
function getFlaskVersionBucket(version) {
|
|
74
|
+
if (!version) {
|
|
75
|
+
return 'none';
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const minVer = (0, semver_1.minVersion)(version);
|
|
79
|
+
if (!minVer) {
|
|
80
|
+
return 'invalid';
|
|
81
|
+
}
|
|
82
|
+
const majorVersion = (0, semver_1.major)(minVer);
|
|
83
|
+
if (majorVersion >= 2) {
|
|
84
|
+
return `${majorVersion}.x`;
|
|
85
|
+
}
|
|
86
|
+
return `<2.0.0`;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return 'unknown';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Extract Flask version from requirements files or pyproject.toml
|
|
94
|
+
*/
|
|
95
|
+
async function getFlaskVersion(options) {
|
|
96
|
+
const { installDir } = options;
|
|
97
|
+
// Check requirements files
|
|
98
|
+
const requirementsFiles = await (0, fast_glob_1.default)(['**/requirements*.txt', '**/pyproject.toml', '**/setup.py', '**/Pipfile'], {
|
|
99
|
+
cwd: installDir,
|
|
100
|
+
ignore: IGNORE_PATTERNS,
|
|
101
|
+
});
|
|
102
|
+
for (const reqFile of requirementsFiles) {
|
|
103
|
+
try {
|
|
104
|
+
const content = fs.readFileSync(path.join(installDir, reqFile), 'utf-8');
|
|
105
|
+
// Try to extract version from requirements.txt format (Flask==3.0.0 or flask>=2.0)
|
|
106
|
+
const requirementsMatch = content.match(/[Ff]lask[=<>~!]+([0-9]+\.[0-9]+(?:\.[0-9]+)?)/);
|
|
107
|
+
if (requirementsMatch) {
|
|
108
|
+
return requirementsMatch[1];
|
|
109
|
+
}
|
|
110
|
+
// Try to extract from pyproject.toml format
|
|
111
|
+
const pyprojectMatch = content.match(/[Ff]lask["\s]*[=<>~!]+\s*["']?([0-9]+\.[0-9]+(?:\.[0-9]+)?)/);
|
|
112
|
+
if (pyprojectMatch) {
|
|
113
|
+
return pyprojectMatch[1];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// Skip files that can't be read
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Check if Flask-RESTful is installed
|
|
125
|
+
*/
|
|
126
|
+
async function hasFlaskRESTful({ installDir, }) {
|
|
127
|
+
const requirementsFiles = await (0, fast_glob_1.default)(['**/requirements*.txt', '**/pyproject.toml', '**/Pipfile'], {
|
|
128
|
+
cwd: installDir,
|
|
129
|
+
ignore: IGNORE_PATTERNS,
|
|
130
|
+
});
|
|
131
|
+
for (const reqFile of requirementsFiles) {
|
|
132
|
+
try {
|
|
133
|
+
const content = fs.readFileSync(path.join(installDir, reqFile), 'utf-8');
|
|
134
|
+
if (content.includes('flask-restful') ||
|
|
135
|
+
content.includes('Flask-RESTful')) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Also check imports in Python files
|
|
144
|
+
const pyFiles = await (0, fast_glob_1.default)(['**/*.py'], {
|
|
145
|
+
cwd: installDir,
|
|
146
|
+
ignore: IGNORE_PATTERNS,
|
|
147
|
+
});
|
|
148
|
+
for (const pyFile of pyFiles) {
|
|
149
|
+
try {
|
|
150
|
+
const content = fs.readFileSync(path.join(installDir, pyFile), 'utf-8');
|
|
151
|
+
if (content.includes('from flask_restful import') ||
|
|
152
|
+
content.includes('import flask_restful')) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Check if Flask-RESTX is installed
|
|
164
|
+
*/
|
|
165
|
+
async function hasFlaskRESTX({ installDir, }) {
|
|
166
|
+
const requirementsFiles = await (0, fast_glob_1.default)(['**/requirements*.txt', '**/pyproject.toml', '**/Pipfile'], {
|
|
167
|
+
cwd: installDir,
|
|
168
|
+
ignore: IGNORE_PATTERNS,
|
|
169
|
+
});
|
|
170
|
+
for (const reqFile of requirementsFiles) {
|
|
171
|
+
try {
|
|
172
|
+
const content = fs.readFileSync(path.join(installDir, reqFile), 'utf-8');
|
|
173
|
+
if (content.includes('flask-restx') || content.includes('Flask-RESTX')) {
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Also check imports in Python files
|
|
182
|
+
const pyFiles = await (0, fast_glob_1.default)(['**/*.py'], {
|
|
183
|
+
cwd: installDir,
|
|
184
|
+
ignore: IGNORE_PATTERNS,
|
|
185
|
+
});
|
|
186
|
+
for (const pyFile of pyFiles) {
|
|
187
|
+
try {
|
|
188
|
+
const content = fs.readFileSync(path.join(installDir, pyFile), 'utf-8');
|
|
189
|
+
if (content.includes('from flask_restx import') ||
|
|
190
|
+
content.includes('import flask_restx')) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Check if flask-smorest is installed
|
|
202
|
+
*/
|
|
203
|
+
async function hasFlaskSmorest({ installDir, }) {
|
|
204
|
+
const requirementsFiles = await (0, fast_glob_1.default)(['**/requirements*.txt', '**/pyproject.toml', '**/Pipfile'], {
|
|
205
|
+
cwd: installDir,
|
|
206
|
+
ignore: IGNORE_PATTERNS,
|
|
207
|
+
});
|
|
208
|
+
for (const reqFile of requirementsFiles) {
|
|
209
|
+
try {
|
|
210
|
+
const content = fs.readFileSync(path.join(installDir, reqFile), 'utf-8');
|
|
211
|
+
if (content.includes('flask-smorest')) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// Also check imports in Python files
|
|
220
|
+
const pyFiles = await (0, fast_glob_1.default)(['**/*.py'], {
|
|
221
|
+
cwd: installDir,
|
|
222
|
+
ignore: IGNORE_PATTERNS,
|
|
223
|
+
});
|
|
224
|
+
for (const pyFile of pyFiles) {
|
|
225
|
+
try {
|
|
226
|
+
const content = fs.readFileSync(path.join(installDir, pyFile), 'utf-8');
|
|
227
|
+
if (content.includes('from flask_smorest import') ||
|
|
228
|
+
content.includes('import flask_smorest')) {
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Check if app uses Flask Blueprints
|
|
240
|
+
*/
|
|
241
|
+
async function hasBlueprints({ installDir, }) {
|
|
242
|
+
const pyFiles = await (0, fast_glob_1.default)(['**/*.py'], {
|
|
243
|
+
cwd: installDir,
|
|
244
|
+
ignore: IGNORE_PATTERNS,
|
|
245
|
+
});
|
|
246
|
+
for (const pyFile of pyFiles) {
|
|
247
|
+
try {
|
|
248
|
+
const content = fs.readFileSync(path.join(installDir, pyFile), 'utf-8');
|
|
249
|
+
if (content.includes('Blueprint(') ||
|
|
250
|
+
content.includes('register_blueprint(') ||
|
|
251
|
+
content.includes('from flask import Blueprint')) {
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Detect Flask project type
|
|
263
|
+
*/
|
|
264
|
+
async function getFlaskProjectType(options) {
|
|
265
|
+
const { installDir } = options;
|
|
266
|
+
// Check for Flask-RESTX first (most specific - includes Swagger)
|
|
267
|
+
if (await hasFlaskRESTX({ installDir })) {
|
|
268
|
+
clack_1.default.log.info('Detected Flask-RESTX project');
|
|
269
|
+
return FlaskProjectType.RESTX;
|
|
270
|
+
}
|
|
271
|
+
// Check for flask-smorest (OpenAPI-first)
|
|
272
|
+
if (await hasFlaskSmorest({ installDir })) {
|
|
273
|
+
clack_1.default.log.info('Detected flask-smorest project');
|
|
274
|
+
return FlaskProjectType.SMOREST;
|
|
275
|
+
}
|
|
276
|
+
// Check for Flask-RESTful
|
|
277
|
+
if (await hasFlaskRESTful({ installDir })) {
|
|
278
|
+
clack_1.default.log.info('Detected Flask-RESTful project');
|
|
279
|
+
return FlaskProjectType.RESTFUL;
|
|
280
|
+
}
|
|
281
|
+
// Check for Blueprints (large app structure)
|
|
282
|
+
if (await hasBlueprints({ installDir })) {
|
|
283
|
+
clack_1.default.log.info('Detected Flask project with Blueprints');
|
|
284
|
+
return FlaskProjectType.BLUEPRINT;
|
|
285
|
+
}
|
|
286
|
+
// Default to standard Flask
|
|
287
|
+
clack_1.default.log.info('Detected standard Flask project');
|
|
288
|
+
return FlaskProjectType.STANDARD;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Get human-readable name for Flask project type
|
|
292
|
+
*/
|
|
293
|
+
function getFlaskProjectTypeName(projectType) {
|
|
294
|
+
switch (projectType) {
|
|
295
|
+
case FlaskProjectType.STANDARD:
|
|
296
|
+
return 'Standard Flask';
|
|
297
|
+
case FlaskProjectType.RESTFUL:
|
|
298
|
+
return 'Flask-RESTful';
|
|
299
|
+
case FlaskProjectType.RESTX:
|
|
300
|
+
return 'Flask-RESTX';
|
|
301
|
+
case FlaskProjectType.SMOREST:
|
|
302
|
+
return 'flask-smorest';
|
|
303
|
+
case FlaskProjectType.BLUEPRINT:
|
|
304
|
+
return 'Flask with Blueprints';
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Find the main Flask app file
|
|
309
|
+
*/
|
|
310
|
+
async function findFlaskAppFile(options) {
|
|
311
|
+
const { installDir } = options;
|
|
312
|
+
// Common Flask app file patterns
|
|
313
|
+
const commonPatterns = [
|
|
314
|
+
'**/app.py',
|
|
315
|
+
'**/wsgi.py',
|
|
316
|
+
'**/application.py',
|
|
317
|
+
'**/run.py',
|
|
318
|
+
'**/main.py',
|
|
319
|
+
'**/__init__.py',
|
|
320
|
+
];
|
|
321
|
+
const appFiles = await (0, fast_glob_1.default)(commonPatterns, {
|
|
322
|
+
cwd: installDir,
|
|
323
|
+
ignore: IGNORE_PATTERNS,
|
|
324
|
+
});
|
|
325
|
+
// Look for files with Flask() instantiation or create_app() factory
|
|
326
|
+
for (const appFile of appFiles) {
|
|
327
|
+
try {
|
|
328
|
+
const content = fs.readFileSync(path.join(installDir, appFile), 'utf-8');
|
|
329
|
+
// Check for Flask app instantiation or application factory
|
|
330
|
+
if (content.includes('Flask(__name__)') ||
|
|
331
|
+
content.includes('Flask(') ||
|
|
332
|
+
content.includes('def create_app(')) {
|
|
333
|
+
return appFile;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
// If no file with Flask() found, check all Python files
|
|
341
|
+
const allPyFiles = await (0, fast_glob_1.default)(['**/*.py'], {
|
|
342
|
+
cwd: installDir,
|
|
343
|
+
ignore: IGNORE_PATTERNS,
|
|
344
|
+
});
|
|
345
|
+
for (const pyFile of allPyFiles) {
|
|
346
|
+
try {
|
|
347
|
+
const content = fs.readFileSync(path.join(installDir, pyFile), 'utf-8');
|
|
348
|
+
if (content.includes('Flask(__name__)') ||
|
|
349
|
+
content.includes('def create_app(')) {
|
|
350
|
+
return pyFile;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
catch {
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// Return first common pattern file if exists
|
|
358
|
+
if (appFiles.length > 0) {
|
|
359
|
+
return appFiles[0];
|
|
360
|
+
}
|
|
361
|
+
return undefined;
|
|
362
|
+
}
|
|
363
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/flask/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,sDAkBC;AAKD,0CAwCC;AAqLD,kDAgCC;AAKD,0DAaC;AAKD,4CA+DC;AAzYD,mCAA2C;AAC3C,0DAA2B;AAC3B,2DAAmC;AAEnC,4CAA8B;AAC9B,gDAAkC;AAElC,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,yCAAqB,CAAA;IACrB,uCAAmB,CAAA;IACnB,mCAAe,CAAA;IACf,uCAAmB,CAAA;IACnB,2CAAuB,CAAA;AACzB,CAAC,EANW,gBAAgB,gCAAhB,gBAAgB,QAM3B;AAED,MAAM,eAAe,GAAG;IACtB,oBAAoB;IACpB,YAAY;IACZ,aAAa;IACb,YAAY;IACZ,aAAa;IACb,WAAW;IACX,YAAY;IACZ,mBAAmB;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,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import { major, minVersion } from 'semver';\nimport fg from 'fast-glob';\nimport clack from '../utils/clack';\nimport type { WizardOptions } from '../utils/types';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nexport enum FlaskProjectType {\n STANDARD = 'standard', // Basic Flask app\n RESTFUL = 'restful', // Flask-RESTful API\n RESTX = 'restx', // Flask-RESTX (Swagger docs)\n SMOREST = 'smorest', // flask-smorest (OpenAPI)\n BLUEPRINT = 'blueprint', // Large app with blueprints\n}\n\nconst IGNORE_PATTERNS = [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/venv/**',\n '**/.venv/**',\n '**/env/**',\n '**/.env/**',\n '**/__pycache__/**',\n '**/migrations/**',\n '**/instance/**',\n];\n\n/**\n * Get Flask version bucket for analytics\n */\nexport function getFlaskVersionBucket(version: string | undefined): string {\n if (!version) {\n return 'none';\n }\n\n try {\n const minVer = minVersion(version);\n if (!minVer) {\n return 'invalid';\n }\n const majorVersion = major(minVer);\n if (majorVersion >= 2) {\n return `${majorVersion}.x`;\n }\n return `<2.0.0`;\n } catch {\n return 'unknown';\n }\n}\n\n/**\n * Extract Flask version from requirements files or pyproject.toml\n */\nexport async function getFlaskVersion(\n options: Pick<WizardOptions, 'installDir'>,\n): Promise<string | undefined> {\n const { installDir } = options;\n\n // Check requirements files\n const requirementsFiles = await fg(\n ['**/requirements*.txt', '**/pyproject.toml', '**/setup.py', '**/Pipfile'],\n {\n cwd: installDir,\n ignore: IGNORE_PATTERNS,\n },\n );\n\n for (const reqFile of requirementsFiles) {\n try {\n const content = fs.readFileSync(path.join(installDir, reqFile), 'utf-8');\n\n // Try to extract version from requirements.txt format (Flask==3.0.0 or flask>=2.0)\n const requirementsMatch = content.match(\n /[Ff]lask[=<>~!]+([0-9]+\\.[0-9]+(?:\\.[0-9]+)?)/,\n );\n if (requirementsMatch) {\n return requirementsMatch[1];\n }\n\n // Try to extract from pyproject.toml format\n const pyprojectMatch = content.match(\n /[Ff]lask[\"\\s]*[=<>~!]+\\s*[\"']?([0-9]+\\.[0-9]+(?:\\.[0-9]+)?)/,\n );\n if (pyprojectMatch) {\n return pyprojectMatch[1];\n }\n } catch {\n // Skip files that can't be read\n continue;\n }\n }\n\n return undefined;\n}\n\n/**\n * Check if Flask-RESTful is installed\n */\nasync function hasFlaskRESTful({\n installDir,\n}: Pick<WizardOptions, 'installDir'>): Promise<boolean> {\n const requirementsFiles = await fg(\n ['**/requirements*.txt', '**/pyproject.toml', '**/Pipfile'],\n {\n cwd: installDir,\n ignore: IGNORE_PATTERNS,\n },\n );\n\n for (const reqFile of requirementsFiles) {\n try {\n const content = fs.readFileSync(path.join(installDir, reqFile), 'utf-8');\n if (\n content.includes('flask-restful') ||\n content.includes('Flask-RESTful')\n ) {\n return true;\n }\n } catch {\n continue;\n }\n }\n\n // Also check imports in Python files\n const pyFiles = await fg(['**/*.py'], {\n cwd: installDir,\n ignore: IGNORE_PATTERNS,\n });\n\n for (const pyFile of pyFiles) {\n try {\n const content = fs.readFileSync(path.join(installDir, pyFile), 'utf-8');\n if (\n content.includes('from flask_restful import') ||\n content.includes('import flask_restful')\n ) {\n return true;\n }\n } catch {\n continue;\n }\n }\n\n return false;\n}\n\n/**\n * Check if Flask-RESTX is installed\n */\nasync function hasFlaskRESTX({\n installDir,\n}: Pick<WizardOptions, 'installDir'>): Promise<boolean> {\n const requirementsFiles = await fg(\n ['**/requirements*.txt', '**/pyproject.toml', '**/Pipfile'],\n {\n cwd: installDir,\n ignore: IGNORE_PATTERNS,\n },\n );\n\n for (const reqFile of requirementsFiles) {\n try {\n const content = fs.readFileSync(path.join(installDir, reqFile), 'utf-8');\n if (content.includes('flask-restx') || content.includes('Flask-RESTX')) {\n return true;\n }\n } catch {\n continue;\n }\n }\n\n // Also check imports in Python files\n const pyFiles = await fg(['**/*.py'], {\n cwd: installDir,\n ignore: IGNORE_PATTERNS,\n });\n\n for (const pyFile of pyFiles) {\n try {\n const content = fs.readFileSync(path.join(installDir, pyFile), 'utf-8');\n if (\n content.includes('from flask_restx import') ||\n content.includes('import flask_restx')\n ) {\n return true;\n }\n } catch {\n continue;\n }\n }\n\n return false;\n}\n\n/**\n * Check if flask-smorest is installed\n */\nasync function hasFlaskSmorest({\n installDir,\n}: Pick<WizardOptions, 'installDir'>): Promise<boolean> {\n const requirementsFiles = await fg(\n ['**/requirements*.txt', '**/pyproject.toml', '**/Pipfile'],\n {\n cwd: installDir,\n ignore: IGNORE_PATTERNS,\n },\n );\n\n for (const reqFile of requirementsFiles) {\n try {\n const content = fs.readFileSync(path.join(installDir, reqFile), 'utf-8');\n if (content.includes('flask-smorest')) {\n return true;\n }\n } catch {\n continue;\n }\n }\n\n // Also check imports in Python files\n const pyFiles = await fg(['**/*.py'], {\n cwd: installDir,\n ignore: IGNORE_PATTERNS,\n });\n\n for (const pyFile of pyFiles) {\n try {\n const content = fs.readFileSync(path.join(installDir, pyFile), 'utf-8');\n if (\n content.includes('from flask_smorest import') ||\n content.includes('import flask_smorest')\n ) {\n return true;\n }\n } catch {\n continue;\n }\n }\n\n return false;\n}\n\n/**\n * Check if app uses Flask Blueprints\n */\nasync function hasBlueprints({\n installDir,\n}: Pick<WizardOptions, 'installDir'>): Promise<boolean> {\n const pyFiles = await fg(['**/*.py'], {\n cwd: installDir,\n ignore: IGNORE_PATTERNS,\n });\n\n for (const pyFile of pyFiles) {\n try {\n const content = fs.readFileSync(path.join(installDir, pyFile), 'utf-8');\n if (\n content.includes('Blueprint(') ||\n content.includes('register_blueprint(') ||\n content.includes('from flask import Blueprint')\n ) {\n return true;\n }\n } catch {\n continue;\n }\n }\n\n return false;\n}\n\n/**\n * Detect Flask project type\n */\nexport async function getFlaskProjectType(\n options: WizardOptions,\n): Promise<FlaskProjectType> {\n const { installDir } = options;\n\n // Check for Flask-RESTX first (most specific - includes Swagger)\n if (await hasFlaskRESTX({ installDir })) {\n clack.log.info('Detected Flask-RESTX project');\n return FlaskProjectType.RESTX;\n }\n\n // Check for flask-smorest (OpenAPI-first)\n if (await hasFlaskSmorest({ installDir })) {\n clack.log.info('Detected flask-smorest project');\n return FlaskProjectType.SMOREST;\n }\n\n // Check for Flask-RESTful\n if (await hasFlaskRESTful({ installDir })) {\n clack.log.info('Detected Flask-RESTful project');\n return FlaskProjectType.RESTFUL;\n }\n\n // Check for Blueprints (large app structure)\n if (await hasBlueprints({ installDir })) {\n clack.log.info('Detected Flask project with Blueprints');\n return FlaskProjectType.BLUEPRINT;\n }\n\n // Default to standard Flask\n clack.log.info('Detected standard Flask project');\n return FlaskProjectType.STANDARD;\n}\n\n/**\n * Get human-readable name for Flask project type\n */\nexport function getFlaskProjectTypeName(projectType: FlaskProjectType): string {\n switch (projectType) {\n case FlaskProjectType.STANDARD:\n return 'Standard Flask';\n case FlaskProjectType.RESTFUL:\n return 'Flask-RESTful';\n case FlaskProjectType.RESTX:\n return 'Flask-RESTX';\n case FlaskProjectType.SMOREST:\n return 'flask-smorest';\n case FlaskProjectType.BLUEPRINT:\n return 'Flask with Blueprints';\n }\n}\n\n/**\n * Find the main Flask app file\n */\nexport async function findFlaskAppFile(\n options: Pick<WizardOptions, 'installDir'>,\n): Promise<string | undefined> {\n const { installDir } = options;\n\n // Common Flask app file patterns\n const commonPatterns = [\n '**/app.py',\n '**/wsgi.py',\n '**/application.py',\n '**/run.py',\n '**/main.py',\n '**/__init__.py',\n ];\n\n const appFiles = await fg(commonPatterns, {\n cwd: installDir,\n ignore: IGNORE_PATTERNS,\n });\n\n // Look for files with Flask() instantiation or create_app() factory\n for (const appFile of appFiles) {\n try {\n const content = fs.readFileSync(path.join(installDir, appFile), 'utf-8');\n // Check for Flask app instantiation or application factory\n if (\n content.includes('Flask(__name__)') ||\n content.includes('Flask(') ||\n content.includes('def create_app(')\n ) {\n return appFile;\n }\n } catch {\n continue;\n }\n }\n\n // If no file with Flask() found, check all Python files\n const allPyFiles = await fg(['**/*.py'], {\n cwd: installDir,\n ignore: IGNORE_PATTERNS,\n });\n\n for (const pyFile of allPyFiles) {\n try {\n const content = fs.readFileSync(path.join(installDir, pyFile), 'utf-8');\n if (\n content.includes('Flask(__name__)') ||\n content.includes('def create_app(')\n ) {\n return pyFile;\n }\n } catch {\n continue;\n }\n }\n\n // Return first common pattern file if exists\n if (appFiles.length > 0) {\n return appFiles[0];\n }\n\n return undefined;\n}\n"]}
|
|
@@ -61,7 +61,20 @@ var AgentErrorType;
|
|
|
61
61
|
/**
|
|
62
62
|
* Package managers that can be used to run commands.
|
|
63
63
|
*/
|
|
64
|
-
const PACKAGE_MANAGERS = [
|
|
64
|
+
const PACKAGE_MANAGERS = [
|
|
65
|
+
// JavaScript
|
|
66
|
+
'npm',
|
|
67
|
+
'pnpm',
|
|
68
|
+
'yarn',
|
|
69
|
+
'bun',
|
|
70
|
+
'npx',
|
|
71
|
+
// Python
|
|
72
|
+
'pip',
|
|
73
|
+
'pip3',
|
|
74
|
+
'poetry',
|
|
75
|
+
'pipenv',
|
|
76
|
+
'uv',
|
|
77
|
+
];
|
|
65
78
|
/**
|
|
66
79
|
* Safe scripts/commands that can be run with any package manager.
|
|
67
80
|
* Uses startsWith matching, so 'build' matches 'build', 'build:prod', etc.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-interface.js","sourceRoot":"","sources":["../../../src/lib/agent-interface.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAqKH,4CAqGC;AAKD,0CAiEC;AAQD,4BA4NC;AAljBD,gDAAwB;AACxB,2DAAmC;AACnC,0CAA8E;AAE9E,kDAA+C;AAC/C,2CAA4D;AAC5D,wCAAyD;AACzD,6CAA6C;AAE7C,sCAAsC;AACtC,IAAI,UAAU,GAAQ,IAAI,CAAC;AAC3B,KAAK,UAAU,YAAY;IACzB,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,UAAU,GAAG,MAAM,MAAM,CAAC,gCAAgC,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;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AE,CAAC;gBAC/B,IAAA,iBAAS,EAAC,2BAA2B,EAAE;oBACrC,KAAK,EAAE,OAAO,CAAC,KAAK;oBACpB,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM;oBAC5B,UAAU,EAAE,OAAO,CAAC,WAAW;iBAChC,CAAC,CAAC;YACL,CAAC;YACD,MAAM;QACR,CAAC;QAED;YACE,wCAAwC;YACxC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBAClB,IAAA,aAAK,EAAC,2BAA2B,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;YACnD,CAAC;YACD,MAAM;IACV,CAAC;AACH,CAAC","sourcesContent":["/**\n * Shared agent interface for PostHog wizards\n * Uses Claude Agent SDK directly with PostHog LLM gateway\n */\n\nimport path from 'path';\nimport clack from '../utils/clack';\nimport { debug, logToFile, initLogFile, LOG_FILE_PATH } from '../utils/debug';\nimport type { WizardOptions } from '../utils/types';\nimport { analytics } from '../utils/analytics';\nimport { WIZARD_INTERACTION_EVENT_NAME } from './constants';\nimport { getLlmGatewayUrlFromHost } from '../utils/urls';\nimport { LINTING_TOOLS } from './safe-tools';\n\n// Dynamic import cache for ESM module\nlet _sdkModule: any = null;\nasync function getSDKModule(): Promise<any> {\n if (!_sdkModule) {\n _sdkModule = await import('@anthropic-ai/claude-agent-sdk');\n }\n return _sdkModule;\n}\n\n/**\n * Get the path to the bundled Claude Code CLI from the SDK package.\n * This ensures we use the SDK's bundled version rather than the user's installed Claude Code.\n */\nfunction getClaudeCodeExecutablePath(): string {\n // require.resolve finds the package's main entry, then we get cli.js from same dir\n const sdkPackagePath = require.resolve('@anthropic-ai/claude-agent-sdk');\n return path.join(path.dirname(sdkPackagePath), 'cli.js');\n}\n\n// Using `any` because typed imports from ESM modules require import attributes\n// syntax which prettier cannot parse. See PR discussion for details.\ntype SDKMessage = any;\ntype McpServersConfig = any;\n\nexport const AgentSignals = {\n /** Signal emitted when the agent reports progress to the user */\n STATUS: '[STATUS]',\n /** Signal emitted when the agent cannot access the PostHog MCP server */\n ERROR_MCP_MISSING: '[ERROR-MCP-MISSING]',\n /** Signal emitted when the agent cannot access the setup resource */\n ERROR_RESOURCE_MISSING: '[ERROR-RESOURCE-MISSING]',\n} as const;\n\nexport type AgentSignal = (typeof AgentSignals)[keyof typeof AgentSignals];\n\n/**\n * Error types that can be returned from agent execution.\n * These correspond to the error signals that the agent emits.\n */\nexport enum AgentErrorType {\n /** Agent could not access the PostHog MCP server */\n MCP_MISSING = 'WIZARD_MCP_MISSING',\n /** Agent could not access the setup resource */\n RESOURCE_MISSING = 'WIZARD_RESOURCE_MISSING',\n /** API rate limit exceeded */\n RATE_LIMIT = 'WIZARD_RATE_LIMIT',\n /** Generic API error */\n API_ERROR = 'WIZARD_API_ERROR',\n}\n\nexport type AgentConfig = {\n workingDirectory: string;\n posthogMcpUrl: string;\n posthogApiKey: string;\n posthogApiHost: string;\n};\n\n/**\n * Internal configuration object returned by initializeAgent\n */\ntype AgentRunConfig = {\n workingDirectory: string;\n mcpServers: McpServersConfig;\n model: string;\n};\n\n/**\n * Package managers that can be used to run commands.\n */\nconst PACKAGE_MANAGERS = ['npm', 'pnpm', 'yarn', 'bun', 'npx'];\n\n/**\n * Safe scripts/commands that can be run with any package manager.\n * Uses startsWith matching, so 'build' matches 'build', 'build:prod', etc.\n * Note: Linting tools are in LINTING_TOOLS and checked separately.\n */\nconst SAFE_SCRIPTS = [\n // Package installation\n 'install',\n 'add',\n 'ci',\n // Build\n 'build',\n // Type checking (various naming conventions)\n 'tsc',\n 'typecheck',\n 'type-check',\n 'check-types',\n 'types',\n // Linting/formatting script names (actual tools are in LINTING_TOOLS)\n 'lint',\n 'format',\n];\n\n/**\n * Dangerous shell operators that could allow command injection.\n * Note: We handle `2>&1` and `| tail/head` separately as safe patterns.\n * Note: `&&` is allowed for specific safe patterns like skill installation.\n */\nconst DANGEROUS_OPERATORS = /[;`$()]/;\n\n/**\n * Check if command is a PostHog skill installation from MCP.\n * We control the MCP server, so we only need to verify:\n * 1. It installs to .claude/skills/\n * 2. It downloads from our GitHub releases or localhost (dev)\n */\nfunction isSkillInstallCommand(command: string): boolean {\n if (!command.startsWith('mkdir -p .claude/skills/')) return false;\n\n const urlMatch = command.match(/curl -sL ['\"]([^'\"]+)['\"]/);\n if (!urlMatch) return false;\n\n const url = urlMatch[1];\n return (\n url.startsWith('https://github.com/PostHog/examples/releases/') ||\n /^http:\\/\\/localhost:\\d+\\//.test(url)\n );\n}\n\n/**\n * Check if command is an allowed package manager command.\n * Matches: <pkg-manager> [run|exec] <safe-script> [args...]\n */\nfunction matchesAllowedPrefix(command: string): boolean {\n const parts = command.split(/\\s+/);\n if (parts.length === 0 || !PACKAGE_MANAGERS.includes(parts[0])) {\n return false;\n }\n\n // Skip 'run' or 'exec' if present\n let scriptIndex = 1;\n if (parts[scriptIndex] === 'run' || parts[scriptIndex] === 'exec') {\n scriptIndex++;\n }\n\n // Get the script/command portion (may include args)\n const scriptPart = parts.slice(scriptIndex).join(' ');\n\n // Check if script starts with any safe script name or linting tool\n return (\n SAFE_SCRIPTS.some((safe) => scriptPart.startsWith(safe)) ||\n LINTING_TOOLS.some((tool) => scriptPart.startsWith(tool))\n );\n}\n\n/**\n * Permission hook that allows only safe commands.\n * - Package manager install commands\n * - Build/typecheck/lint commands for verification\n * - Piping to tail/head for output limiting is allowed\n * - Stderr redirection (2>&1) is allowed\n * - PostHog skill installation commands from MCP\n */\nexport function wizardCanUseTool(\n toolName: string,\n input: Record<string, unknown>,\n):\n | { behavior: 'allow'; updatedInput: Record<string, unknown> }\n | { behavior: 'deny'; message: string } {\n // Allow all non-Bash tools\n if (toolName !== 'Bash') {\n return { behavior: 'allow', updatedInput: input };\n }\n\n const command = (\n typeof input.command === 'string' ? input.command : ''\n ).trim();\n\n // Check for PostHog skill installation command (before dangerous operator check)\n // These commands use && chaining but are generated by MCP with a strict format\n if (isSkillInstallCommand(command)) {\n logToFile(`Allowing skill installation command: ${command}`);\n debug(`Allowing skill installation command: ${command}`);\n return { behavior: 'allow', updatedInput: input };\n }\n\n // Block definitely dangerous operators: ; ` $ ( )\n if (DANGEROUS_OPERATORS.test(command)) {\n logToFile(`Denying bash command with dangerous operators: ${command}`);\n debug(`Denying bash command with dangerous operators: ${command}`);\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'bash command denied',\n reason: 'dangerous operators',\n command,\n });\n return {\n behavior: 'deny',\n message: `Bash command not allowed. Shell operators like ; \\` $ ( ) are not permitted.`,\n };\n }\n\n // Normalize: remove safe stderr redirection (2>&1, 2>&2, etc.)\n const normalized = command.replace(/\\s*\\d*>&\\d+\\s*/g, ' ').trim();\n\n // Check for pipe to tail/head (safe output limiting)\n const pipeMatch = normalized.match(/^(.+?)\\s*\\|\\s*(tail|head)(\\s+\\S+)*\\s*$/);\n if (pipeMatch) {\n const baseCommand = pipeMatch[1].trim();\n\n // Block if base command has pipes or & (multiple chaining)\n if (/[|&]/.test(baseCommand)) {\n logToFile(`Denying bash command with multiple pipes: ${command}`);\n debug(`Denying bash command with multiple pipes: ${command}`);\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'bash command denied',\n reason: 'multiple pipes',\n command,\n });\n return {\n behavior: 'deny',\n message: `Bash command not allowed. Only single pipe to tail/head is permitted.`,\n };\n }\n\n if (matchesAllowedPrefix(baseCommand)) {\n logToFile(`Allowing bash command with output limiter: ${command}`);\n debug(`Allowing bash command with output limiter: ${command}`);\n return { behavior: 'allow', updatedInput: input };\n }\n }\n\n // Block remaining pipes and & (not covered by tail/head case above)\n if (/[|&]/.test(normalized)) {\n logToFile(`Denying bash command with pipe/&: ${command}`);\n debug(`Denying bash command with pipe/&: ${command}`);\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'bash command denied',\n reason: 'disallowed pipe',\n command,\n });\n return {\n behavior: 'deny',\n message: `Bash command not allowed. Pipes are only permitted with tail/head for output limiting.`,\n };\n }\n\n // Check if command starts with any allowed prefix (package manager commands)\n if (matchesAllowedPrefix(normalized)) {\n logToFile(`Allowing bash command: ${command}`);\n debug(`Allowing bash command: ${command}`);\n return { behavior: 'allow', updatedInput: input };\n }\n\n logToFile(`Denying bash command: ${command}`);\n debug(`Denying bash command: ${command}`);\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'bash command denied',\n reason: 'not in allowlist',\n command,\n });\n return {\n behavior: 'deny',\n message: `Bash command not allowed. Only install, build, typecheck, lint, and formatting commands are permitted.`,\n };\n}\n\n/**\n * Initialize agent configuration for the LLM gateway\n */\nexport function initializeAgent(\n config: AgentConfig,\n options: WizardOptions,\n): AgentRunConfig {\n // Initialize log file for this run\n initLogFile();\n logToFile('Agent initialization starting');\n logToFile('Install directory:', options.installDir);\n\n clack.log.step('Initializing Claude agent...');\n\n try {\n // Configure LLM gateway environment variables (inherited by SDK subprocess)\n const gatewayUrl = getLlmGatewayUrlFromHost(config.posthogApiHost);\n process.env.ANTHROPIC_BASE_URL = gatewayUrl;\n process.env.ANTHROPIC_AUTH_TOKEN = config.posthogApiKey;\n // Use CLAUDE_CODE_OAUTH_TOKEN to override any stored /login credentials\n process.env.CLAUDE_CODE_OAUTH_TOKEN = config.posthogApiKey;\n // Disable experimental betas (like input_examples) that the LLM gateway doesn't support\n process.env.CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS = 'true';\n\n logToFile('Configured LLM gateway:', gatewayUrl);\n\n // Configure MCP server with PostHog authentication\n const mcpServers: McpServersConfig = {\n posthog: {\n type: 'http',\n url: config.posthogMcpUrl,\n headers: {\n Authorization: `Bearer ${config.posthogApiKey}`,\n },\n },\n };\n\n const agentRunConfig: AgentRunConfig = {\n workingDirectory: config.workingDirectory,\n mcpServers,\n model: 'claude-opus-4-5-20251101',\n };\n\n logToFile('Agent config:', {\n workingDirectory: agentRunConfig.workingDirectory,\n posthogMcpUrl: config.posthogMcpUrl,\n gatewayUrl,\n apiKeyPresent: !!config.posthogApiKey,\n });\n\n if (options.debug) {\n debug('Agent config:', {\n workingDirectory: agentRunConfig.workingDirectory,\n posthogMcpUrl: config.posthogMcpUrl,\n gatewayUrl,\n apiKeyPresent: !!config.posthogApiKey,\n });\n }\n\n clack.log.step(`Verbose logs: ${LOG_FILE_PATH}`);\n clack.log.success(\"Agent initialized. Let's get cooking!\");\n return agentRunConfig;\n } catch (error) {\n clack.log.error(`Failed to initialize agent: ${(error as Error).message}`);\n logToFile('Agent initialization error:', error);\n debug('Agent initialization error:', error);\n throw error;\n }\n}\n\n/**\n * Execute an agent with the provided prompt and options\n * Handles the full lifecycle: spinner, execution, error handling\n *\n * @returns An object containing any error detected in the agent's output\n */\nexport async function runAgent(\n agentConfig: AgentRunConfig,\n prompt: string,\n options: WizardOptions,\n spinner: ReturnType<typeof clack.spinner>,\n config?: {\n estimatedDurationMinutes?: number;\n spinnerMessage?: string;\n successMessage?: string;\n errorMessage?: string;\n },\n): Promise<{ error?: AgentErrorType; message?: string }> {\n const {\n estimatedDurationMinutes = 8,\n spinnerMessage = 'Customizing your PostHog setup...',\n successMessage = 'PostHog integration complete',\n errorMessage = 'Integration failed',\n } = config ?? {};\n\n const { query } = await getSDKModule();\n\n clack.log.step(\n `This whole process should take about ${estimatedDurationMinutes} minutes including error checking and fixes.\\n\\nGrab some coffee!`,\n );\n\n spinner.start(spinnerMessage);\n\n const cliPath = getClaudeCodeExecutablePath();\n logToFile('Starting agent run');\n logToFile('Claude Code executable:', cliPath);\n logToFile('Prompt:', prompt);\n\n const startTime = Date.now();\n const collectedText: string[] = [];\n // Track if we received a successful result (before any cleanup errors)\n let receivedSuccessResult = false;\n\n // Workaround for SDK bug: stdin closes before canUseTool responses can be sent.\n // The fix is to use an async generator for the prompt that stays open until\n // the result is received, keeping the stdin stream alive for permission responses.\n // See: https://github.com/anthropics/claude-code/issues/4775\n // See: https://github.com/anthropics/claude-agent-sdk-typescript/issues/41\n let signalDone: () => void;\n const resultReceived = new Promise<void>((resolve) => {\n signalDone = resolve;\n });\n\n const createPromptStream = async function* () {\n yield {\n type: 'user',\n session_id: '',\n message: { role: 'user', content: prompt },\n parent_tool_use_id: null,\n };\n await resultReceived;\n };\n\n // Helper to handle successful completion (used in normal path and race condition recovery)\n const completeWithSuccess = (\n suppressedError?: Error,\n ): { error?: AgentErrorType; message?: string } => {\n const durationMs = Date.now() - startTime;\n const durationSeconds = Math.round(durationMs / 1000);\n\n if (suppressedError) {\n logToFile(\n `Ignoring post-completion error, agent completed successfully in ${durationSeconds}s`,\n );\n logToFile('Suppressed error:', suppressedError.message);\n } else {\n logToFile(`Agent run completed in ${durationSeconds}s`);\n }\n\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'agent integration completed',\n duration_ms: durationMs,\n duration_seconds: durationSeconds,\n });\n spinner.stop(successMessage);\n return {};\n };\n\n try {\n // Tools needed for the wizard:\n // - File operations: Read, Write, Edit\n // - Search: Glob, Grep\n // - Commands: Bash (with restrictions via canUseTool)\n // - MCP discovery: ListMcpResourcesTool (to find available skills)\n // - Skills: Skill (to load installed PostHog skills)\n // MCP tools (PostHog) come from mcpServers, not allowedTools\n const allowedTools = [\n 'Read',\n 'Write',\n 'Edit',\n 'Glob',\n 'Grep',\n 'Bash',\n 'ListMcpResourcesTool',\n 'Skill',\n ];\n\n const response = query({\n prompt: createPromptStream(),\n options: {\n model: agentConfig.model,\n cwd: agentConfig.workingDirectory,\n permissionMode: 'acceptEdits',\n mcpServers: agentConfig.mcpServers,\n // Load skills from project's .claude/skills/ directory\n settingSources: ['project'],\n // Explicitly enable required tools including Skill\n allowedTools,\n env: {\n ...process.env,\n // Prevent user's Anthropic API key from overriding the wizard's OAuth token\n ANTHROPIC_API_KEY: undefined,\n },\n canUseTool: (toolName: string, input: unknown) => {\n logToFile('canUseTool called:', { toolName, input });\n const result = wizardCanUseTool(\n toolName,\n input as Record<string, unknown>,\n );\n logToFile('canUseTool result:', result);\n return Promise.resolve(result);\n },\n tools: { type: 'preset', preset: 'claude_code' },\n // Capture stderr from CLI subprocess for debugging\n stderr: (data: string) => {\n logToFile('CLI stderr:', data);\n if (options.debug) {\n debug('CLI stderr:', data);\n }\n },\n },\n });\n\n // Process the async generator\n for await (const message of response) {\n handleSDKMessage(message, options, spinner, collectedText);\n // Signal completion when result received\n if (message.type === 'result') {\n // Track successful results before any potential cleanup errors\n // The SDK may emit a second error result during cleanup due to a race condition\n if (message.subtype === 'success' && !message.is_error) {\n receivedSuccessResult = true;\n }\n signalDone!();\n }\n }\n\n const outputText = collectedText.join('\\n');\n\n // Check for error markers in the agent's output\n if (outputText.includes(AgentSignals.ERROR_MCP_MISSING)) {\n logToFile('Agent error: MCP_MISSING');\n spinner.stop('Agent could not access PostHog MCP');\n return { error: AgentErrorType.MCP_MISSING };\n }\n\n if (outputText.includes(AgentSignals.ERROR_RESOURCE_MISSING)) {\n logToFile('Agent error: RESOURCE_MISSING');\n spinner.stop('Agent could not access setup resource');\n return { error: AgentErrorType.RESOURCE_MISSING };\n }\n\n // Check for API errors (rate limits, etc.)\n if (outputText.includes('API Error: 429')) {\n logToFile('Agent error: RATE_LIMIT');\n spinner.stop('Rate limit exceeded');\n return { error: AgentErrorType.RATE_LIMIT, message: outputText };\n }\n\n if (outputText.includes('API Error:')) {\n logToFile('Agent error: API_ERROR');\n spinner.stop('API error occurred');\n return { error: AgentErrorType.API_ERROR, message: outputText };\n }\n\n return completeWithSuccess();\n } catch (error) {\n // Signal done to unblock the async generator\n signalDone!();\n\n // If we already received a successful result, the error is from SDK cleanup\n // This happens due to a race condition: the SDK tries to send a cleanup command\n // after the prompt stream closes, but streaming mode is still active.\n // See: https://github.com/anthropics/claude-agent-sdk-typescript/issues/41\n if (receivedSuccessResult) {\n return completeWithSuccess(error as Error);\n }\n\n // Check if we collected an API error before the exception was thrown\n const outputText = collectedText.join('\\n');\n\n // Extract just the API error line(s), not the entire output\n const apiErrorMatch = outputText.match(/API Error: [^\\n]+/g);\n const apiErrorMessage = apiErrorMatch\n ? apiErrorMatch.join('\\n')\n : 'Unknown API error';\n\n if (outputText.includes('API Error: 429')) {\n logToFile('Agent error (caught): RATE_LIMIT');\n spinner.stop('Rate limit exceeded');\n return { error: AgentErrorType.RATE_LIMIT, message: apiErrorMessage };\n }\n\n if (outputText.includes('API Error:')) {\n logToFile('Agent error (caught): API_ERROR');\n spinner.stop('API error occurred');\n return { error: AgentErrorType.API_ERROR, message: apiErrorMessage };\n }\n\n // No API error found, re-throw the original exception\n spinner.stop(errorMessage);\n clack.log.error(`Error: ${(error as Error).message}`);\n logToFile('Agent run failed:', error);\n debug('Full error:', error);\n throw error;\n }\n}\n\n/**\n * Handle SDK messages and provide user feedback\n */\nfunction handleSDKMessage(\n message: SDKMessage,\n options: WizardOptions,\n spinner: ReturnType<typeof clack.spinner>,\n collectedText: string[],\n): void {\n logToFile(`SDK Message: ${message.type}`, JSON.stringify(message, null, 2));\n\n if (options.debug) {\n debug(`SDK Message type: ${message.type}`);\n }\n\n switch (message.type) {\n case 'assistant': {\n // Extract text content from assistant messages\n const content = message.message?.content;\n if (Array.isArray(content)) {\n for (const block of content) {\n if (block.type === 'text' && typeof block.text === 'string') {\n collectedText.push(block.text);\n\n // Check for [STATUS] markers\n const statusRegex = new RegExp(\n `^.*${AgentSignals.STATUS.replace(\n /[.*+?^${}()|[\\]\\\\]/g,\n '\\\\$&',\n )}\\\\s*(.+?)$`,\n 'm',\n );\n const statusMatch = block.text.match(statusRegex);\n if (statusMatch) {\n spinner.stop(statusMatch[1].trim());\n spinner.start('Integrating PostHog...');\n }\n }\n }\n }\n break;\n }\n\n case 'result': {\n // Check is_error flag - can be true even when subtype is 'success'\n if (message.is_error) {\n logToFile('Agent result with error:', message.result);\n if (typeof message.result === 'string') {\n collectedText.push(message.result);\n }\n if (message.errors) {\n for (const err of message.errors) {\n clack.log.error(`Error: ${err}`);\n logToFile('ERROR:', err);\n }\n }\n } else if (message.subtype === 'success') {\n logToFile('Agent completed successfully');\n if (typeof message.result === 'string') {\n collectedText.push(message.result);\n }\n } else {\n // Error result\n logToFile('Agent error result:', message.subtype);\n if (message.errors) {\n for (const err of message.errors) {\n clack.log.error(`Error: ${err}`);\n logToFile('ERROR:', err);\n }\n }\n }\n break;\n }\n\n case 'system': {\n if (message.subtype === 'init') {\n logToFile('Agent session initialized', {\n model: message.model,\n tools: message.tools?.length,\n mcpServers: message.mcp_servers,\n });\n }\n break;\n }\n\n default:\n // Log other message types for debugging\n if (options.debug) {\n debug(`Unhandled message type: ${message.type}`);\n }\n break;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agent-interface.js","sourceRoot":"","sources":["../../../src/lib/agent-interface.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAkLH,4CAqGC;AAKD,0CAiEC;AAQD,4BA4NC;AA/jBD,gDAAwB;AACxB,2DAAmC;AACnC,0CAA8E;AAE9E,kDAA+C;AAC/C,2CAA4D;AAC5D,wCAAyD;AACzD,6CAA6C;AAE7C,sCAAsC;AACtC,IAAI,UAAU,GAAQ,IAAI,CAAC;AAC3B,KAAK,UAAU,YAAY;IACzB,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,UAAU,GAAG,MAAM,MAAM,CAAC,gCAAgC,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;GAGG;AACH,SAAS,2BAA2B;IAClC,mFAAmF;IACnF,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,gCAAgC,CAAC,CAAC;IACzE,OAAO,cAAI,CAAC,IAAI,CAAC,cAAI,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC;AAC3D,CAAC;AAOY,QAAA,YAAY,GAAG;IAC1B,iEAAiE;IACjE,MAAM,EAAE,UAAU;IAClB,yEAAyE;IACzE,iBAAiB,EAAE,qBAAqB;IACxC,qEAAqE;IACrE,sBAAsB,EAAE,0BAA0B;CAC1C,CAAC;AAIX;;;GAGG;AACH,IAAY,cASX;AATD,WAAY,cAAc;IACxB,oDAAoD;IACpD,oDAAk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,CAAC;AACH,CAAC","sourcesContent":["/**\n * Shared agent interface for PostHog wizards\n * Uses Claude Agent SDK directly with PostHog LLM gateway\n */\n\nimport path from 'path';\nimport clack from '../utils/clack';\nimport { debug, logToFile, initLogFile, LOG_FILE_PATH } from '../utils/debug';\nimport type { WizardOptions } from '../utils/types';\nimport { analytics } from '../utils/analytics';\nimport { WIZARD_INTERACTION_EVENT_NAME } from './constants';\nimport { getLlmGatewayUrlFromHost } from '../utils/urls';\nimport { LINTING_TOOLS } from './safe-tools';\n\n// Dynamic import cache for ESM module\nlet _sdkModule: any = null;\nasync function getSDKModule(): Promise<any> {\n if (!_sdkModule) {\n _sdkModule = await import('@anthropic-ai/claude-agent-sdk');\n }\n return _sdkModule;\n}\n\n/**\n * Get the path to the bundled Claude Code CLI from the SDK package.\n * This ensures we use the SDK's bundled version rather than the user's installed Claude Code.\n */\nfunction getClaudeCodeExecutablePath(): string {\n // require.resolve finds the package's main entry, then we get cli.js from same dir\n const sdkPackagePath = require.resolve('@anthropic-ai/claude-agent-sdk');\n return path.join(path.dirname(sdkPackagePath), 'cli.js');\n}\n\n// Using `any` because typed imports from ESM modules require import attributes\n// syntax which prettier cannot parse. See PR discussion for details.\ntype SDKMessage = any;\ntype McpServersConfig = any;\n\nexport const AgentSignals = {\n /** Signal emitted when the agent reports progress to the user */\n STATUS: '[STATUS]',\n /** Signal emitted when the agent cannot access the PostHog MCP server */\n ERROR_MCP_MISSING: '[ERROR-MCP-MISSING]',\n /** Signal emitted when the agent cannot access the setup resource */\n ERROR_RESOURCE_MISSING: '[ERROR-RESOURCE-MISSING]',\n} as const;\n\nexport type AgentSignal = (typeof AgentSignals)[keyof typeof AgentSignals];\n\n/**\n * Error types that can be returned from agent execution.\n * These correspond to the error signals that the agent emits.\n */\nexport enum AgentErrorType {\n /** Agent could not access the PostHog MCP server */\n MCP_MISSING = 'WIZARD_MCP_MISSING',\n /** Agent could not access the setup resource */\n RESOURCE_MISSING = 'WIZARD_RESOURCE_MISSING',\n /** API rate limit exceeded */\n RATE_LIMIT = 'WIZARD_RATE_LIMIT',\n /** Generic API error */\n API_ERROR = 'WIZARD_API_ERROR',\n}\n\nexport type AgentConfig = {\n workingDirectory: string;\n posthogMcpUrl: string;\n posthogApiKey: string;\n posthogApiHost: string;\n};\n\n/**\n * Internal configuration object returned by initializeAgent\n */\ntype AgentRunConfig = {\n workingDirectory: string;\n mcpServers: McpServersConfig;\n model: string;\n};\n\n/**\n * Package managers that can be used to run commands.\n */\nconst PACKAGE_MANAGERS = [\n // JavaScript\n 'npm',\n 'pnpm',\n 'yarn',\n 'bun',\n 'npx',\n // Python\n 'pip',\n 'pip3',\n 'poetry',\n 'pipenv',\n 'uv',\n];\n\n/**\n * Safe scripts/commands that can be run with any package manager.\n * Uses startsWith matching, so 'build' matches 'build', 'build:prod', etc.\n * Note: Linting tools are in LINTING_TOOLS and checked separately.\n */\nconst SAFE_SCRIPTS = [\n // Package installation\n 'install',\n 'add',\n 'ci',\n // Build\n 'build',\n // Type checking (various naming conventions)\n 'tsc',\n 'typecheck',\n 'type-check',\n 'check-types',\n 'types',\n // Linting/formatting script names (actual tools are in LINTING_TOOLS)\n 'lint',\n 'format',\n];\n\n/**\n * Dangerous shell operators that could allow command injection.\n * Note: We handle `2>&1` and `| tail/head` separately as safe patterns.\n * Note: `&&` is allowed for specific safe patterns like skill installation.\n */\nconst DANGEROUS_OPERATORS = /[;`$()]/;\n\n/**\n * Check if command is a PostHog skill installation from MCP.\n * We control the MCP server, so we only need to verify:\n * 1. It installs to .claude/skills/\n * 2. It downloads from our GitHub releases or localhost (dev)\n */\nfunction isSkillInstallCommand(command: string): boolean {\n if (!command.startsWith('mkdir -p .claude/skills/')) return false;\n\n const urlMatch = command.match(/curl -sL ['\"]([^'\"]+)['\"]/);\n if (!urlMatch) return false;\n\n const url = urlMatch[1];\n return (\n url.startsWith('https://github.com/PostHog/examples/releases/') ||\n /^http:\\/\\/localhost:\\d+\\//.test(url)\n );\n}\n\n/**\n * Check if command is an allowed package manager command.\n * Matches: <pkg-manager> [run|exec] <safe-script> [args...]\n */\nfunction matchesAllowedPrefix(command: string): boolean {\n const parts = command.split(/\\s+/);\n if (parts.length === 0 || !PACKAGE_MANAGERS.includes(parts[0])) {\n return false;\n }\n\n // Skip 'run' or 'exec' if present\n let scriptIndex = 1;\n if (parts[scriptIndex] === 'run' || parts[scriptIndex] === 'exec') {\n scriptIndex++;\n }\n\n // Get the script/command portion (may include args)\n const scriptPart = parts.slice(scriptIndex).join(' ');\n\n // Check if script starts with any safe script name or linting tool\n return (\n SAFE_SCRIPTS.some((safe) => scriptPart.startsWith(safe)) ||\n LINTING_TOOLS.some((tool) => scriptPart.startsWith(tool))\n );\n}\n\n/**\n * Permission hook that allows only safe commands.\n * - Package manager install commands\n * - Build/typecheck/lint commands for verification\n * - Piping to tail/head for output limiting is allowed\n * - Stderr redirection (2>&1) is allowed\n * - PostHog skill installation commands from MCP\n */\nexport function wizardCanUseTool(\n toolName: string,\n input: Record<string, unknown>,\n):\n | { behavior: 'allow'; updatedInput: Record<string, unknown> }\n | { behavior: 'deny'; message: string } {\n // Allow all non-Bash tools\n if (toolName !== 'Bash') {\n return { behavior: 'allow', updatedInput: input };\n }\n\n const command = (\n typeof input.command === 'string' ? input.command : ''\n ).trim();\n\n // Check for PostHog skill installation command (before dangerous operator check)\n // These commands use && chaining but are generated by MCP with a strict format\n if (isSkillInstallCommand(command)) {\n logToFile(`Allowing skill installation command: ${command}`);\n debug(`Allowing skill installation command: ${command}`);\n return { behavior: 'allow', updatedInput: input };\n }\n\n // Block definitely dangerous operators: ; ` $ ( )\n if (DANGEROUS_OPERATORS.test(command)) {\n logToFile(`Denying bash command with dangerous operators: ${command}`);\n debug(`Denying bash command with dangerous operators: ${command}`);\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'bash command denied',\n reason: 'dangerous operators',\n command,\n });\n return {\n behavior: 'deny',\n message: `Bash command not allowed. Shell operators like ; \\` $ ( ) are not permitted.`,\n };\n }\n\n // Normalize: remove safe stderr redirection (2>&1, 2>&2, etc.)\n const normalized = command.replace(/\\s*\\d*>&\\d+\\s*/g, ' ').trim();\n\n // Check for pipe to tail/head (safe output limiting)\n const pipeMatch = normalized.match(/^(.+?)\\s*\\|\\s*(tail|head)(\\s+\\S+)*\\s*$/);\n if (pipeMatch) {\n const baseCommand = pipeMatch[1].trim();\n\n // Block if base command has pipes or & (multiple chaining)\n if (/[|&]/.test(baseCommand)) {\n logToFile(`Denying bash command with multiple pipes: ${command}`);\n debug(`Denying bash command with multiple pipes: ${command}`);\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'bash command denied',\n reason: 'multiple pipes',\n command,\n });\n return {\n behavior: 'deny',\n message: `Bash command not allowed. Only single pipe to tail/head is permitted.`,\n };\n }\n\n if (matchesAllowedPrefix(baseCommand)) {\n logToFile(`Allowing bash command with output limiter: ${command}`);\n debug(`Allowing bash command with output limiter: ${command}`);\n return { behavior: 'allow', updatedInput: input };\n }\n }\n\n // Block remaining pipes and & (not covered by tail/head case above)\n if (/[|&]/.test(normalized)) {\n logToFile(`Denying bash command with pipe/&: ${command}`);\n debug(`Denying bash command with pipe/&: ${command}`);\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'bash command denied',\n reason: 'disallowed pipe',\n command,\n });\n return {\n behavior: 'deny',\n message: `Bash command not allowed. Pipes are only permitted with tail/head for output limiting.`,\n };\n }\n\n // Check if command starts with any allowed prefix (package manager commands)\n if (matchesAllowedPrefix(normalized)) {\n logToFile(`Allowing bash command: ${command}`);\n debug(`Allowing bash command: ${command}`);\n return { behavior: 'allow', updatedInput: input };\n }\n\n logToFile(`Denying bash command: ${command}`);\n debug(`Denying bash command: ${command}`);\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'bash command denied',\n reason: 'not in allowlist',\n command,\n });\n return {\n behavior: 'deny',\n message: `Bash command not allowed. Only install, build, typecheck, lint, and formatting commands are permitted.`,\n };\n}\n\n/**\n * Initialize agent configuration for the LLM gateway\n */\nexport function initializeAgent(\n config: AgentConfig,\n options: WizardOptions,\n): AgentRunConfig {\n // Initialize log file for this run\n initLogFile();\n logToFile('Agent initialization starting');\n logToFile('Install directory:', options.installDir);\n\n clack.log.step('Initializing Claude agent...');\n\n try {\n // Configure LLM gateway environment variables (inherited by SDK subprocess)\n const gatewayUrl = getLlmGatewayUrlFromHost(config.posthogApiHost);\n process.env.ANTHROPIC_BASE_URL = gatewayUrl;\n process.env.ANTHROPIC_AUTH_TOKEN = config.posthogApiKey;\n // Use CLAUDE_CODE_OAUTH_TOKEN to override any stored /login credentials\n process.env.CLAUDE_CODE_OAUTH_TOKEN = config.posthogApiKey;\n // Disable experimental betas (like input_examples) that the LLM gateway doesn't support\n process.env.CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS = 'true';\n\n logToFile('Configured LLM gateway:', gatewayUrl);\n\n // Configure MCP server with PostHog authentication\n const mcpServers: McpServersConfig = {\n posthog: {\n type: 'http',\n url: config.posthogMcpUrl,\n headers: {\n Authorization: `Bearer ${config.posthogApiKey}`,\n },\n },\n };\n\n const agentRunConfig: AgentRunConfig = {\n workingDirectory: config.workingDirectory,\n mcpServers,\n model: 'claude-opus-4-5-20251101',\n };\n\n logToFile('Agent config:', {\n workingDirectory: agentRunConfig.workingDirectory,\n posthogMcpUrl: config.posthogMcpUrl,\n gatewayUrl,\n apiKeyPresent: !!config.posthogApiKey,\n });\n\n if (options.debug) {\n debug('Agent config:', {\n workingDirectory: agentRunConfig.workingDirectory,\n posthogMcpUrl: config.posthogMcpUrl,\n gatewayUrl,\n apiKeyPresent: !!config.posthogApiKey,\n });\n }\n\n clack.log.step(`Verbose logs: ${LOG_FILE_PATH}`);\n clack.log.success(\"Agent initialized. Let's get cooking!\");\n return agentRunConfig;\n } catch (error) {\n clack.log.error(`Failed to initialize agent: ${(error as Error).message}`);\n logToFile('Agent initialization error:', error);\n debug('Agent initialization error:', error);\n throw error;\n }\n}\n\n/**\n * Execute an agent with the provided prompt and options\n * Handles the full lifecycle: spinner, execution, error handling\n *\n * @returns An object containing any error detected in the agent's output\n */\nexport async function runAgent(\n agentConfig: AgentRunConfig,\n prompt: string,\n options: WizardOptions,\n spinner: ReturnType<typeof clack.spinner>,\n config?: {\n estimatedDurationMinutes?: number;\n spinnerMessage?: string;\n successMessage?: string;\n errorMessage?: string;\n },\n): Promise<{ error?: AgentErrorType; message?: string }> {\n const {\n estimatedDurationMinutes = 8,\n spinnerMessage = 'Customizing your PostHog setup...',\n successMessage = 'PostHog integration complete',\n errorMessage = 'Integration failed',\n } = config ?? {};\n\n const { query } = await getSDKModule();\n\n clack.log.step(\n `This whole process should take about ${estimatedDurationMinutes} minutes including error checking and fixes.\\n\\nGrab some coffee!`,\n );\n\n spinner.start(spinnerMessage);\n\n const cliPath = getClaudeCodeExecutablePath();\n logToFile('Starting agent run');\n logToFile('Claude Code executable:', cliPath);\n logToFile('Prompt:', prompt);\n\n const startTime = Date.now();\n const collectedText: string[] = [];\n // Track if we received a successful result (before any cleanup errors)\n let receivedSuccessResult = false;\n\n // Workaround for SDK bug: stdin closes before canUseTool responses can be sent.\n // The fix is to use an async generator for the prompt that stays open until\n // the result is received, keeping the stdin stream alive for permission responses.\n // See: https://github.com/anthropics/claude-code/issues/4775\n // See: https://github.com/anthropics/claude-agent-sdk-typescript/issues/41\n let signalDone: () => void;\n const resultReceived = new Promise<void>((resolve) => {\n signalDone = resolve;\n });\n\n const createPromptStream = async function* () {\n yield {\n type: 'user',\n session_id: '',\n message: { role: 'user', content: prompt },\n parent_tool_use_id: null,\n };\n await resultReceived;\n };\n\n // Helper to handle successful completion (used in normal path and race condition recovery)\n const completeWithSuccess = (\n suppressedError?: Error,\n ): { error?: AgentErrorType; message?: string } => {\n const durationMs = Date.now() - startTime;\n const durationSeconds = Math.round(durationMs / 1000);\n\n if (suppressedError) {\n logToFile(\n `Ignoring post-completion error, agent completed successfully in ${durationSeconds}s`,\n );\n logToFile('Suppressed error:', suppressedError.message);\n } else {\n logToFile(`Agent run completed in ${durationSeconds}s`);\n }\n\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'agent integration completed',\n duration_ms: durationMs,\n duration_seconds: durationSeconds,\n });\n spinner.stop(successMessage);\n return {};\n };\n\n try {\n // Tools needed for the wizard:\n // - File operations: Read, Write, Edit\n // - Search: Glob, Grep\n // - Commands: Bash (with restrictions via canUseTool)\n // - MCP discovery: ListMcpResourcesTool (to find available skills)\n // - Skills: Skill (to load installed PostHog skills)\n // MCP tools (PostHog) come from mcpServers, not allowedTools\n const allowedTools = [\n 'Read',\n 'Write',\n 'Edit',\n 'Glob',\n 'Grep',\n 'Bash',\n 'ListMcpResourcesTool',\n 'Skill',\n ];\n\n const response = query({\n prompt: createPromptStream(),\n options: {\n model: agentConfig.model,\n cwd: agentConfig.workingDirectory,\n permissionMode: 'acceptEdits',\n mcpServers: agentConfig.mcpServers,\n // Load skills from project's .claude/skills/ directory\n settingSources: ['project'],\n // Explicitly enable required tools including Skill\n allowedTools,\n env: {\n ...process.env,\n // Prevent user's Anthropic API key from overriding the wizard's OAuth token\n ANTHROPIC_API_KEY: undefined,\n },\n canUseTool: (toolName: string, input: unknown) => {\n logToFile('canUseTool called:', { toolName, input });\n const result = wizardCanUseTool(\n toolName,\n input as Record<string, unknown>,\n );\n logToFile('canUseTool result:', result);\n return Promise.resolve(result);\n },\n tools: { type: 'preset', preset: 'claude_code' },\n // Capture stderr from CLI subprocess for debugging\n stderr: (data: string) => {\n logToFile('CLI stderr:', data);\n if (options.debug) {\n debug('CLI stderr:', data);\n }\n },\n },\n });\n\n // Process the async generator\n for await (const message of response) {\n handleSDKMessage(message, options, spinner, collectedText);\n // Signal completion when result received\n if (message.type === 'result') {\n // Track successful results before any potential cleanup errors\n // The SDK may emit a second error result during cleanup due to a race condition\n if (message.subtype === 'success' && !message.is_error) {\n receivedSuccessResult = true;\n }\n signalDone!();\n }\n }\n\n const outputText = collectedText.join('\\n');\n\n // Check for error markers in the agent's output\n if (outputText.includes(AgentSignals.ERROR_MCP_MISSING)) {\n logToFile('Agent error: MCP_MISSING');\n spinner.stop('Agent could not access PostHog MCP');\n return { error: AgentErrorType.MCP_MISSING };\n }\n\n if (outputText.includes(AgentSignals.ERROR_RESOURCE_MISSING)) {\n logToFile('Agent error: RESOURCE_MISSING');\n spinner.stop('Agent could not access setup resource');\n return { error: AgentErrorType.RESOURCE_MISSING };\n }\n\n // Check for API errors (rate limits, etc.)\n if (outputText.includes('API Error: 429')) {\n logToFile('Agent error: RATE_LIMIT');\n spinner.stop('Rate limit exceeded');\n return { error: AgentErrorType.RATE_LIMIT, message: outputText };\n }\n\n if (outputText.includes('API Error:')) {\n logToFile('Agent error: API_ERROR');\n spinner.stop('API error occurred');\n return { error: AgentErrorType.API_ERROR, message: outputText };\n }\n\n return completeWithSuccess();\n } catch (error) {\n // Signal done to unblock the async generator\n signalDone!();\n\n // If we already received a successful result, the error is from SDK cleanup\n // This happens due to a race condition: the SDK tries to send a cleanup command\n // after the prompt stream closes, but streaming mode is still active.\n // See: https://github.com/anthropics/claude-agent-sdk-typescript/issues/41\n if (receivedSuccessResult) {\n return completeWithSuccess(error as Error);\n }\n\n // Check if we collected an API error before the exception was thrown\n const outputText = collectedText.join('\\n');\n\n // Extract just the API error line(s), not the entire output\n const apiErrorMatch = outputText.match(/API Error: [^\\n]+/g);\n const apiErrorMessage = apiErrorMatch\n ? apiErrorMatch.join('\\n')\n : 'Unknown API error';\n\n if (outputText.includes('API Error: 429')) {\n logToFile('Agent error (caught): RATE_LIMIT');\n spinner.stop('Rate limit exceeded');\n return { error: AgentErrorType.RATE_LIMIT, message: apiErrorMessage };\n }\n\n if (outputText.includes('API Error:')) {\n logToFile('Agent error (caught): API_ERROR');\n spinner.stop('API error occurred');\n return { error: AgentErrorType.API_ERROR, message: apiErrorMessage };\n }\n\n // No API error found, re-throw the original exception\n spinner.stop(errorMessage);\n clack.log.error(`Error: ${(error as Error).message}`);\n logToFile('Agent run failed:', error);\n debug('Full error:', error);\n throw error;\n }\n}\n\n/**\n * Handle SDK messages and provide user feedback\n */\nfunction handleSDKMessage(\n message: SDKMessage,\n options: WizardOptions,\n spinner: ReturnType<typeof clack.spinner>,\n collectedText: string[],\n): void {\n logToFile(`SDK Message: ${message.type}`, JSON.stringify(message, null, 2));\n\n if (options.debug) {\n debug(`SDK Message type: ${message.type}`);\n }\n\n switch (message.type) {\n case 'assistant': {\n // Extract text content from assistant messages\n const content = message.message?.content;\n if (Array.isArray(content)) {\n for (const block of content) {\n if (block.type === 'text' && typeof block.text === 'string') {\n collectedText.push(block.text);\n\n // Check for [STATUS] markers\n const statusRegex = new RegExp(\n `^.*${AgentSignals.STATUS.replace(\n /[.*+?^${}()|[\\]\\\\]/g,\n '\\\\$&',\n )}\\\\s*(.+?)$`,\n 'm',\n );\n const statusMatch = block.text.match(statusRegex);\n if (statusMatch) {\n spinner.stop(statusMatch[1].trim());\n spinner.start('Integrating PostHog...');\n }\n }\n }\n }\n break;\n }\n\n case 'result': {\n // Check is_error flag - can be true even when subtype is 'success'\n if (message.is_error) {\n logToFile('Agent result with error:', message.result);\n if (typeof message.result === 'string') {\n collectedText.push(message.result);\n }\n if (message.errors) {\n for (const err of message.errors) {\n clack.log.error(`Error: ${err}`);\n logToFile('ERROR:', err);\n }\n }\n } else if (message.subtype === 'success') {\n logToFile('Agent completed successfully');\n if (typeof message.result === 'string') {\n collectedText.push(message.result);\n }\n } else {\n // Error result\n logToFile('Agent error result:', message.subtype);\n if (message.errors) {\n for (const err of message.errors) {\n clack.log.error(`Error: ${err}`);\n logToFile('ERROR:', err);\n }\n }\n }\n break;\n }\n\n case 'system': {\n if (message.subtype === 'init') {\n logToFile('Agent session initialized', {\n model: message.model,\n tools: message.tools?.length,\n mcpServers: message.mcp_servers,\n });\n }\n break;\n }\n\n default:\n // Log other message types for debugging\n if (options.debug) {\n debug(`Unhandled message type: ${message.type}`);\n }\n break;\n }\n}\n"]}
|
package/dist/src/lib/config.d.ts
CHANGED
|
@@ -78,5 +78,16 @@ export declare const INTEGRATION_CONFIG: {
|
|
|
78
78
|
readonly defaultChanges: "• Installed posthog Python package\n• Added PostHog middleware for automatic event tracking\n• Configured PostHog settings in Django settings file";
|
|
79
79
|
readonly nextSteps: "• Use identify_context() within new_context() to associate events with users\n• Call posthog.capture() to capture custom events\n• Use feature flags with posthog.feature_enabled()";
|
|
80
80
|
};
|
|
81
|
+
readonly flask: {
|
|
82
|
+
readonly name: "Flask";
|
|
83
|
+
readonly filterPatterns: ["**/*.py"];
|
|
84
|
+
readonly ignorePatterns: ["node_modules", "dist", "build", "public", "static", "venv", ".venv", "env", ".env", "__pycache__", "*.pyc", "migrations", "instance"];
|
|
85
|
+
readonly detect: (options: Pick<WizardOptions, "installDir">) => Promise<boolean>;
|
|
86
|
+
readonly generateFilesRules: "";
|
|
87
|
+
readonly filterFilesRules: "";
|
|
88
|
+
readonly docsUrl: "https://posthog.com/docs/libraries/flask";
|
|
89
|
+
readonly defaultChanges: "• Installed posthog Python package\n• Added PostHog initialization to your Flask app\n• Configured automatic event tracking";
|
|
90
|
+
readonly nextSteps: "• Use posthog.identify() to associate events with users\n• Call posthog.capture() to capture custom events\n• Use feature flags with posthog.feature_enabled()";
|
|
91
|
+
};
|
|
81
92
|
};
|
|
82
|
-
export declare const INTEGRATION_ORDER: readonly [Integration.nextjs, Integration.astro, Integration.svelte, Integration.reactNative, Integration.reactRouter, Integration.django, Integration.react];
|
|
93
|
+
export declare const INTEGRATION_ORDER: readonly [Integration.nextjs, Integration.astro, Integration.svelte, Integration.reactNative, Integration.reactRouter, Integration.django, Integration.flask, Integration.react];
|
package/dist/src/lib/config.js
CHANGED
|
@@ -223,6 +223,84 @@ exports.INTEGRATION_CONFIG = {
|
|
|
223
223
|
defaultChanges: '• Installed posthog Python package\n• Added PostHog middleware for automatic event tracking\n• Configured PostHog settings in Django settings file',
|
|
224
224
|
nextSteps: '• Use identify_context() within new_context() to associate events with users\n• Call posthog.capture() to capture custom events\n• Use feature flags with posthog.feature_enabled()',
|
|
225
225
|
},
|
|
226
|
+
[constants_1.Integration.flask]: {
|
|
227
|
+
name: 'Flask',
|
|
228
|
+
filterPatterns: ['**/*.py'],
|
|
229
|
+
ignorePatterns: [
|
|
230
|
+
'node_modules',
|
|
231
|
+
'dist',
|
|
232
|
+
'build',
|
|
233
|
+
'public',
|
|
234
|
+
'static',
|
|
235
|
+
'venv',
|
|
236
|
+
'.venv',
|
|
237
|
+
'env',
|
|
238
|
+
'.env',
|
|
239
|
+
'__pycache__',
|
|
240
|
+
'*.pyc',
|
|
241
|
+
'migrations',
|
|
242
|
+
'instance',
|
|
243
|
+
],
|
|
244
|
+
detect: async (options) => {
|
|
245
|
+
const { installDir } = options;
|
|
246
|
+
// Note: Django is checked before Flask in INTEGRATION_ORDER,
|
|
247
|
+
// so if we get here, the project is not a Django project.
|
|
248
|
+
// Check for Flask in requirements files
|
|
249
|
+
const requirementsFiles = await (0, fast_glob_1.default)([
|
|
250
|
+
'**/requirements*.txt',
|
|
251
|
+
'**/pyproject.toml',
|
|
252
|
+
'**/setup.py',
|
|
253
|
+
'**/Pipfile',
|
|
254
|
+
], {
|
|
255
|
+
cwd: installDir,
|
|
256
|
+
ignore: ['**/venv/**', '**/.venv/**', '**/env/**', '**/.env/**'],
|
|
257
|
+
});
|
|
258
|
+
for (const reqFile of requirementsFiles) {
|
|
259
|
+
try {
|
|
260
|
+
const content = fs.readFileSync(path.join(installDir, reqFile), 'utf-8');
|
|
261
|
+
// Check for flask package (case-insensitive)
|
|
262
|
+
// Match "flask" as a standalone package, not just as part of plugin names
|
|
263
|
+
if (/^flask([<>=~!]|$|\s)/im.test(content) ||
|
|
264
|
+
/["']flask["']/i.test(content)) {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// Check for Flask app patterns in Python files
|
|
273
|
+
const pyFiles = await (0, fast_glob_1.default)(['**/app.py', '**/wsgi.py', '**/application.py', '**/__init__.py'], {
|
|
274
|
+
cwd: installDir,
|
|
275
|
+
ignore: [
|
|
276
|
+
'**/venv/**',
|
|
277
|
+
'**/.venv/**',
|
|
278
|
+
'**/env/**',
|
|
279
|
+
'**/.env/**',
|
|
280
|
+
'**/__pycache__/**',
|
|
281
|
+
],
|
|
282
|
+
});
|
|
283
|
+
for (const pyFile of pyFiles) {
|
|
284
|
+
try {
|
|
285
|
+
const content = fs.readFileSync(path.join(installDir, pyFile), 'utf-8');
|
|
286
|
+
if (content.includes('from flask import') ||
|
|
287
|
+
content.includes('import flask') ||
|
|
288
|
+
/Flask\s*\(/.test(content)) {
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return false;
|
|
297
|
+
},
|
|
298
|
+
generateFilesRules: '',
|
|
299
|
+
filterFilesRules: '',
|
|
300
|
+
docsUrl: 'https://posthog.com/docs/libraries/flask',
|
|
301
|
+
defaultChanges: '• Installed posthog Python package\n• Added PostHog initialization to your Flask app\n• Configured automatic event tracking',
|
|
302
|
+
nextSteps: '• Use posthog.identify() to associate events with users\n• Call posthog.capture() to capture custom events\n• Use feature flags with posthog.feature_enabled()',
|
|
303
|
+
},
|
|
226
304
|
};
|
|
227
305
|
exports.INTEGRATION_ORDER = [
|
|
228
306
|
constants_1.Integration.nextjs,
|
|
@@ -231,6 +309,7 @@ exports.INTEGRATION_ORDER = [
|
|
|
231
309
|
constants_1.Integration.reactNative,
|
|
232
310
|
constants_1.Integration.reactRouter,
|
|
233
311
|
constants_1.Integration.django,
|
|
312
|
+
constants_1.Integration.flask,
|
|
234
313
|
constants_1.Integration.react,
|
|
235
314
|
];
|
|
236
315
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"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AAO,IAAI,iBAAiB,EAAE,CAAC;gBACxC,IAAI,CAAC;oBACH,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAC7B,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,EAC9B,OAAO,CACR,CAAC;oBACF,qCAAqC;oBACrC,IACE,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;wBACxC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,iDAAiD;sBAC5F,CAAC;wBACD,OAAO,IAAI,CAAC;oBACd,CAAC;gBACH,CAAC;gBAAC,MAAM,CAAC;oBACP,gCAAgC;oBAChC,SAAS;gBACX,CAAC;YACH,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC;QACD,kBAAkB,EAAE,EAAE;QACtB,gBAAgB,EAAE,EAAE;QACpB,OAAO,EAAE,2CAA2C;QACpD,cAAc,EACZ,oJAAoJ;QACtJ,SAAS,EACP,qLAAqL;KACxL;CACwD,CAAC;AAE/C,QAAA,iBAAiB,GAAG;IAC/B,uBAAW,CAAC,MAAM;IAClB,uBAAW,CAAC,KAAK;IACjB,uBAAW,CAAC,MAAM;IAClB,uBAAW,CAAC,WAAW;IACvB,uBAAW,CAAC,WAAW;IACvB,uBAAW,CAAC,MAAM;IAClB,uBAAW,CAAC,KAAK;CACT,CAAC","sourcesContent":["import { tryGetPackageJson } from '../utils/clack-utils';\nimport { hasPackageInstalled } from '../utils/package-json';\nimport type { WizardOptions } from '../utils/types';\nimport { Integration } from './constants';\nimport fg from 'fast-glob';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\n\ntype IntegrationConfig = {\n name: string;\n filterPatterns: string[];\n ignorePatterns: string[];\n detect: (options: Pick<WizardOptions, 'installDir'>) => Promise<boolean>;\n generateFilesRules: string;\n filterFilesRules: string;\n docsUrl: string;\n nextSteps: string;\n defaultChanges: string;\n};\n\nexport const INTEGRATION_CONFIG = {\n [Integration.nextjs]: {\n name: 'Next.js',\n filterPatterns: ['**/*.{tsx,ts,jsx,js,mjs,cjs}'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'next-env.d.*',\n ],\n detect: async (options) => {\n const packageJson = await tryGetPackageJson(options);\n return packageJson ? hasPackageInstalled('next', packageJson) : false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/next-js',\n defaultChanges:\n '• Installed posthog-js & posthog-node packages\\n• Initialized PostHog and added pageview tracking\\n• Created a PostHogClient to use PostHog server-side\\n• Setup a reverse proxy to avoid ad blockers blocking analytics requests',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Call posthog.capture() to capture custom events in your app',\n },\n [Integration.react]: {\n name: 'React',\n filterPatterns: ['**/*.{tsx,ts,jsx,js}'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'assets',\n ],\n detect: async (options) => {\n const packageJson = await tryGetPackageJson(options);\n return packageJson ? hasPackageInstalled('react', packageJson) : false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/react',\n defaultChanges:\n '• Installed posthog-js package\\n• Added PostHogProvider to the root of the app, to initialize PostHog and enable autocapture',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Call posthog.capture() to capture custom events in your app',\n },\n [Integration.svelte]: {\n name: 'Svelte',\n filterPatterns: ['**/*.{svelte,ts,js,jsx,tsx}'],\n ignorePatterns: ['node_modules', 'dist', 'build', 'public', 'static'],\n detect: async (options) => {\n const packageJson = await tryGetPackageJson(options);\n return packageJson\n ? hasPackageInstalled('@sveltejs/kit', packageJson)\n : false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/svelte',\n defaultChanges:\n '• Installed posthog-js & posthog-node packages\\n• Added PostHog initialization to your Svelte app\\n• Setup pageview & pageleave tracking\\n• Setup event auto - capture to capture events as users interact with your app\\n• Added a getPostHogClient() function to use PostHog server-side',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Use getPostHogClient() to start capturing events server - side',\n },\n [Integration.reactNative]: {\n name: 'React Native',\n filterPatterns: ['**/*.{ts,js,jsx,tsx}'],\n ignorePatterns: ['node_modules', 'dist', 'build', 'public', 'static'],\n detect: async (options) => {\n const packageJson = await tryGetPackageJson(options);\n return packageJson\n ? hasPackageInstalled('react-native', packageJson)\n : false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/react-native',\n defaultChanges:\n '• Installed required packages\\n• Added PostHogProvider to the root of the app\\n• Enabled autocapture and session replay',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Call posthog.capture() to capture custom events in your app',\n },\n [Integration.astro]: {\n name: 'Astro',\n filterPatterns: ['**/*.{astro,ts,js,jsx,tsx}'],\n ignorePatterns: ['node_modules', 'dist', 'build', 'public', 'static'],\n detect: async (options) => {\n const packageJson = await tryGetPackageJson(options);\n return packageJson ? hasPackageInstalled('astro', packageJson) : false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/js',\n defaultChanges:\n '• Added PostHog component with initialization script\\n• Created PostHogLayout for consistent analytics tracking',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Call posthog.capture() to capture custom events in your app\\n• Use posthog.isFeatureEnabled() for feature flags',\n },\n [Integration.reactRouter]: {\n name: 'React Router',\n filterPatterns: ['**/*.{tsx,ts,jsx,js}'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'assets',\n ],\n detect: async (options) => {\n const packageJson = await tryGetPackageJson(options);\n return packageJson\n ? hasPackageInstalled('react-router', packageJson)\n : false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl:\n 'https://posthog-git-react-post-hog.vercel.app/docs/libraries/react-router',\n defaultChanges:\n '• Installed posthog-js package\\n• Added PostHogProvider to the root of the app\\n• Integrated PostHog with React Router for pageview tracking',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Call posthog.capture() to capture custom events in your app',\n },\n [Integration.django]: {\n name: 'Django',\n filterPatterns: ['**/*.py'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'venv',\n '.venv',\n 'env',\n '.env',\n '__pycache__',\n '*.pyc',\n 'migrations',\n ],\n detect: async (options) => {\n const { installDir } = options;\n\n // Check for manage.py (Django project indicator)\n const managePyMatches = await fg('**/manage.py', {\n cwd: installDir,\n ignore: ['**/venv/**', '**/.venv/**', '**/env/**', '**/.env/**'],\n });\n\n if (managePyMatches.length > 0) {\n // Verify it's a Django manage.py by checking content\n for (const match of managePyMatches) {\n try {\n const content = fs.readFileSync(\n path.join(installDir, match),\n 'utf-8',\n );\n if (\n content.includes('django') ||\n content.includes('DJANGO_SETTINGS_MODULE')\n ) {\n return true;\n }\n } catch {\n // Skip files that can't be read\n continue;\n }\n }\n }\n\n // Check for Django in requirements files\n const requirementsFiles = await fg(\n ['**/requirements*.txt', '**/pyproject.toml', '**/setup.py'],\n {\n cwd: installDir,\n ignore: ['**/venv/**', '**/.venv/**', '**/env/**', '**/.env/**'],\n },\n );\n\n for (const reqFile of requirementsFiles) {\n try {\n const content = fs.readFileSync(\n path.join(installDir, reqFile),\n 'utf-8',\n );\n // Check for Django package reference\n if (\n content.toLowerCase().includes('django') &&\n !content.toLowerCase().includes('django-') // Avoid false positives from Django plugins only\n ) {\n return true;\n }\n } catch {\n // Skip files that can't be read\n continue;\n }\n }\n\n return false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/django',\n defaultChanges:\n '• Installed posthog Python package\\n• Added PostHog middleware for automatic event tracking\\n• Configured PostHog settings in Django settings file',\n nextSteps:\n '• Use identify_context() within new_context() to associate events with users\\n• Call posthog.capture() to capture custom events\\n• Use feature flags with posthog.feature_enabled()',\n },\n} as const satisfies Record<Integration, IntegrationConfig>;\n\nexport const INTEGRATION_ORDER = [\n Integration.nextjs,\n Integration.astro,\n Integration.svelte,\n Integration.reactNative,\n Integration.reactRouter,\n Integration.django,\n Integration.react,\n] as const;\n"]}
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/lib/config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAyD;AACzD,wDAA4D;AAE5D,2CAA0C;AAC1C,0DAA2B;AAC3B,4CAA8B;AAC9B,gDAAkC;AAcrB,QAAA,kBAAkB,GAAG;IAChC,CAAC,uBAAW,CAAC,MAAM,CAAC,EAAE;QACpB,IAAI,EAAE,SAAS;QACf,cAAc,EAAE,CAAC,8BAA8B,CAAC;QAChD,cAAc,EAAE;YACd,cAAc;YACd,MAAM;YACN,OAAO;YACP,QAAQ;YACR,QAAQ;YACR,cAAc;SACf;QACD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACxB,MAAM,WAAW,GAAG,MAAM,IAAA,+BAAiB,EAAC,OAAO,CAAC,CAAC;YACrD,OAAO,WAAW,CAAC,CAAC,CAAC,IAAA,kCAAmB,EAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACxE,CAAC;QACD,kBAAkB,EAAE,EAAE;QACtB,gBAAgB,EAAE,EAAE;QACpB,OAAO,EAAE,4CAA4C;QACrD,cAAc,EACZ,mOAAmO;QACrO,SAAS,EACP,0HAA0H;KAC7H;IACD,CAAC,uBAAW,CAAC,KAAK,CAAC,EAAE;QACnB,IAAI,EAAE,OAAO;QACb,cAAc,EAAE,CAAC,sBAAsB,CAAC;QACxC,cAAc,EAAE;YACd,cAAc;YACd,MAAM;YACN,OAAO;YACP,QAAQ;YACR,QAAQ;YACR,QAAQ;SACT;QACD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YAC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AC,cAAc,CAAC;wBAChC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,EAC1B,CAAC;wBACD,OAAO,IAAI,CAAC;oBACd,CAAC;gBACH,CAAC;gBAAC,MAAM,CAAC;oBACP,SAAS;gBACX,CAAC;YACH,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC;QACD,kBAAkB,EAAE,EAAE;QACtB,gBAAgB,EAAE,EAAE;QACpB,OAAO,EAAE,0CAA0C;QACnD,cAAc,EACZ,6HAA6H;QAC/H,SAAS,EACP,gKAAgK;KACnK;CACwD,CAAC;AAE/C,QAAA,iBAAiB,GAAG;IAC/B,uBAAW,CAAC,MAAM;IAClB,uBAAW,CAAC,KAAK;IACjB,uBAAW,CAAC,MAAM;IAClB,uBAAW,CAAC,WAAW;IACvB,uBAAW,CAAC,WAAW;IACvB,uBAAW,CAAC,MAAM;IAClB,uBAAW,CAAC,KAAK;IACjB,uBAAW,CAAC,KAAK;CACT,CAAC","sourcesContent":["import { tryGetPackageJson } from '../utils/clack-utils';\nimport { hasPackageInstalled } from '../utils/package-json';\nimport type { WizardOptions } from '../utils/types';\nimport { Integration } from './constants';\nimport fg from 'fast-glob';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\n\ntype IntegrationConfig = {\n name: string;\n filterPatterns: string[];\n ignorePatterns: string[];\n detect: (options: Pick<WizardOptions, 'installDir'>) => Promise<boolean>;\n generateFilesRules: string;\n filterFilesRules: string;\n docsUrl: string;\n nextSteps: string;\n defaultChanges: string;\n};\n\nexport const INTEGRATION_CONFIG = {\n [Integration.nextjs]: {\n name: 'Next.js',\n filterPatterns: ['**/*.{tsx,ts,jsx,js,mjs,cjs}'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'next-env.d.*',\n ],\n detect: async (options) => {\n const packageJson = await tryGetPackageJson(options);\n return packageJson ? hasPackageInstalled('next', packageJson) : false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/next-js',\n defaultChanges:\n '• Installed posthog-js & posthog-node packages\\n• Initialized PostHog and added pageview tracking\\n• Created a PostHogClient to use PostHog server-side\\n• Setup a reverse proxy to avoid ad blockers blocking analytics requests',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Call posthog.capture() to capture custom events in your app',\n },\n [Integration.react]: {\n name: 'React',\n filterPatterns: ['**/*.{tsx,ts,jsx,js}'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'assets',\n ],\n detect: async (options) => {\n const packageJson = await tryGetPackageJson(options);\n return packageJson ? hasPackageInstalled('react', packageJson) : false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/react',\n defaultChanges:\n '• Installed posthog-js package\\n• Added PostHogProvider to the root of the app, to initialize PostHog and enable autocapture',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Call posthog.capture() to capture custom events in your app',\n },\n [Integration.svelte]: {\n name: 'Svelte',\n filterPatterns: ['**/*.{svelte,ts,js,jsx,tsx}'],\n ignorePatterns: ['node_modules', 'dist', 'build', 'public', 'static'],\n detect: async (options) => {\n const packageJson = await tryGetPackageJson(options);\n return packageJson\n ? hasPackageInstalled('@sveltejs/kit', packageJson)\n : false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/svelte',\n defaultChanges:\n '• Installed posthog-js & posthog-node packages\\n• Added PostHog initialization to your Svelte app\\n• Setup pageview & pageleave tracking\\n• Setup event auto - capture to capture events as users interact with your app\\n• Added a getPostHogClient() function to use PostHog server-side',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Use getPostHogClient() to start capturing events server - side',\n },\n [Integration.reactNative]: {\n name: 'React Native',\n filterPatterns: ['**/*.{ts,js,jsx,tsx}'],\n ignorePatterns: ['node_modules', 'dist', 'build', 'public', 'static'],\n detect: async (options) => {\n const packageJson = await tryGetPackageJson(options);\n return packageJson\n ? hasPackageInstalled('react-native', packageJson)\n : false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/react-native',\n defaultChanges:\n '• Installed required packages\\n• Added PostHogProvider to the root of the app\\n• Enabled autocapture and session replay',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Call posthog.capture() to capture custom events in your app',\n },\n [Integration.astro]: {\n name: 'Astro',\n filterPatterns: ['**/*.{astro,ts,js,jsx,tsx}'],\n ignorePatterns: ['node_modules', 'dist', 'build', 'public', 'static'],\n detect: async (options) => {\n const packageJson = await tryGetPackageJson(options);\n return packageJson ? hasPackageInstalled('astro', packageJson) : false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/js',\n defaultChanges:\n '• Added PostHog component with initialization script\\n• Created PostHogLayout for consistent analytics tracking',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Call posthog.capture() to capture custom events in your app\\n• Use posthog.isFeatureEnabled() for feature flags',\n },\n [Integration.reactRouter]: {\n name: 'React Router',\n filterPatterns: ['**/*.{tsx,ts,jsx,js}'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'assets',\n ],\n detect: async (options) => {\n const packageJson = await tryGetPackageJson(options);\n return packageJson\n ? hasPackageInstalled('react-router', packageJson)\n : false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl:\n 'https://posthog-git-react-post-hog.vercel.app/docs/libraries/react-router',\n defaultChanges:\n '• Installed posthog-js package\\n• Added PostHogProvider to the root of the app\\n• Integrated PostHog with React Router for pageview tracking',\n nextSteps:\n '• Call posthog.identify() when a user signs into your app\\n• Call posthog.capture() to capture custom events in your app',\n },\n [Integration.django]: {\n name: 'Django',\n filterPatterns: ['**/*.py'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'venv',\n '.venv',\n 'env',\n '.env',\n '__pycache__',\n '*.pyc',\n 'migrations',\n ],\n detect: async (options) => {\n const { installDir } = options;\n\n // Check for manage.py (Django project indicator)\n const managePyMatches = await fg('**/manage.py', {\n cwd: installDir,\n ignore: ['**/venv/**', '**/.venv/**', '**/env/**', '**/.env/**'],\n });\n\n if (managePyMatches.length > 0) {\n // Verify it's a Django manage.py by checking content\n for (const match of managePyMatches) {\n try {\n const content = fs.readFileSync(\n path.join(installDir, match),\n 'utf-8',\n );\n if (\n content.includes('django') ||\n content.includes('DJANGO_SETTINGS_MODULE')\n ) {\n return true;\n }\n } catch {\n // Skip files that can't be read\n continue;\n }\n }\n }\n\n // Check for Django in requirements files\n const requirementsFiles = await fg(\n ['**/requirements*.txt', '**/pyproject.toml', '**/setup.py'],\n {\n cwd: installDir,\n ignore: ['**/venv/**', '**/.venv/**', '**/env/**', '**/.env/**'],\n },\n );\n\n for (const reqFile of requirementsFiles) {\n try {\n const content = fs.readFileSync(\n path.join(installDir, reqFile),\n 'utf-8',\n );\n // Check for Django package reference\n if (\n content.toLowerCase().includes('django') &&\n !content.toLowerCase().includes('django-') // Avoid false positives from Django plugins only\n ) {\n return true;\n }\n } catch {\n // Skip files that can't be read\n continue;\n }\n }\n\n return false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/django',\n defaultChanges:\n '• Installed posthog Python package\\n• Added PostHog middleware for automatic event tracking\\n• Configured PostHog settings in Django settings file',\n nextSteps:\n '• Use identify_context() within new_context() to associate events with users\\n• Call posthog.capture() to capture custom events\\n• Use feature flags with posthog.feature_enabled()',\n },\n [Integration.flask]: {\n name: 'Flask',\n filterPatterns: ['**/*.py'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'venv',\n '.venv',\n 'env',\n '.env',\n '__pycache__',\n '*.pyc',\n 'migrations',\n 'instance',\n ],\n detect: async (options) => {\n const { installDir } = options;\n\n // Note: Django is checked before Flask in INTEGRATION_ORDER,\n // so if we get here, the project is not a Django project.\n\n // Check for Flask in requirements files\n const requirementsFiles = await fg(\n [\n '**/requirements*.txt',\n '**/pyproject.toml',\n '**/setup.py',\n '**/Pipfile',\n ],\n {\n cwd: installDir,\n ignore: ['**/venv/**', '**/.venv/**', '**/env/**', '**/.env/**'],\n },\n );\n\n for (const reqFile of requirementsFiles) {\n try {\n const content = fs.readFileSync(\n path.join(installDir, reqFile),\n 'utf-8',\n );\n // Check for flask package (case-insensitive)\n // Match \"flask\" as a standalone package, not just as part of plugin names\n if (\n /^flask([<>=~!]|$|\\s)/im.test(content) ||\n /[\"']flask[\"']/i.test(content)\n ) {\n return true;\n }\n } catch {\n continue;\n }\n }\n\n // Check for Flask app patterns in Python files\n const pyFiles = await fg(\n ['**/app.py', '**/wsgi.py', '**/application.py', '**/__init__.py'],\n {\n cwd: installDir,\n ignore: [\n '**/venv/**',\n '**/.venv/**',\n '**/env/**',\n '**/.env/**',\n '**/__pycache__/**',\n ],\n },\n );\n\n for (const pyFile of pyFiles) {\n try {\n const content = fs.readFileSync(\n path.join(installDir, pyFile),\n 'utf-8',\n );\n if (\n content.includes('from flask import') ||\n content.includes('import flask') ||\n /Flask\\s*\\(/.test(content)\n ) {\n return true;\n }\n } catch {\n continue;\n }\n }\n\n return false;\n },\n generateFilesRules: '',\n filterFilesRules: '',\n docsUrl: 'https://posthog.com/docs/libraries/flask',\n defaultChanges:\n '• Installed posthog Python package\\n• Added PostHog initialization to your Flask app\\n• Configured automatic event tracking',\n nextSteps:\n '• Use posthog.identify() to associate events with users\\n• Call posthog.capture() to capture custom events\\n• Use feature flags with posthog.feature_enabled()',\n },\n} as const satisfies Record<Integration, IntegrationConfig>;\n\nexport const INTEGRATION_ORDER = [\n Integration.nextjs,\n Integration.astro,\n Integration.svelte,\n Integration.reactNative,\n Integration.reactRouter,\n Integration.django,\n Integration.flask,\n Integration.react,\n] as const;\n"]}
|
|
@@ -5,7 +5,8 @@ export declare enum Integration {
|
|
|
5
5
|
reactNative = "react-native",
|
|
6
6
|
astro = "astro",
|
|
7
7
|
reactRouter = "react-router",
|
|
8
|
-
django = "django"
|
|
8
|
+
django = "django",
|
|
9
|
+
flask = "flask"
|
|
9
10
|
}
|
|
10
11
|
export declare enum FeatureFlagDefinition {
|
|
11
12
|
ReactRouter = "wizard-react-router"
|
|
@@ -12,6 +12,7 @@ var Integration;
|
|
|
12
12
|
Integration["astro"] = "astro";
|
|
13
13
|
Integration["reactRouter"] = "react-router";
|
|
14
14
|
Integration["django"] = "django";
|
|
15
|
+
Integration["flask"] = "flask";
|
|
15
16
|
})(Integration || (exports.Integration = Integration = {}));
|
|
16
17
|
var FeatureFlagDefinition;
|
|
17
18
|
(function (FeatureFlagDefinition) {
|
|
@@ -33,6 +34,8 @@ function getIntegrationDescription(type) {
|
|
|
33
34
|
return 'React Router';
|
|
34
35
|
case Integration.django:
|
|
35
36
|
return 'Django';
|
|
37
|
+
case Integration.flask:
|
|
38
|
+
return 'Flask';
|
|
36
39
|
default:
|
|
37
40
|
throw new Error(`Unknown integration ${type}`);
|
|
38
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":";;;AAeA,8DAqBC;AAOD,sDAKC;AAhDD,IAAY,WASX;AATD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,8BAAe,CAAA;IACf,gCAAiB,CAAA;IACjB,2CAA4B,CAAA;IAC5B,8BAAe,CAAA;IACf,2CAA4B,CAAA;IAC5B,gCAAiB,CAAA;IACjB,8BAAe,CAAA;AACjB,CAAC,EATW,WAAW,2BAAX,WAAW,QAStB;AAED,IAAY,qBAEX;AAFD,WAAY,qBAAqB;IAC/B,4DAAmC,CAAA;AACrC,CAAC,EAFW,qBAAqB,qCAArB,qBAAqB,QAEhC;AAED,SAAgB,yB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AC9D,QAAA,kBAAkB,GAAG,gCAAgC,CAAC;AACtD,QAAA,kBAAkB,GAAG,iBAAiB,CAAC;AACvC,QAAA,qBAAqB,GAAG,gCAAgC,CAAC;AAEzD,QAAA,oBAAoB,GAAG,0CAA0C,CAAC;AAClE,QAAA,oBAAoB,GAAG,0CAA0C,CAAC;AAClE,QAAA,qBAAqB,GAAG,0CAA0C,CAAC;AACnE,QAAA,UAAU,GAAG,IAAI,CAAC;AAElB,QAAA,6BAA6B,GAAG,oBAAoB,CAAC","sourcesContent":["export enum Integration {\n nextjs = 'nextjs',\n react = 'react',\n svelte = 'svelte',\n reactNative = 'react-native',\n astro = 'astro',\n reactRouter = 'react-router',\n django = 'django',\n flask = 'flask',\n}\n\nexport enum FeatureFlagDefinition {\n ReactRouter = 'wizard-react-router',\n}\n\nexport function getIntegrationDescription(type: string): string {\n switch (type) {\n case Integration.nextjs:\n return 'Next.js';\n case Integration.react:\n return 'React';\n case Integration.reactNative:\n return 'React Native';\n case Integration.svelte:\n return 'Svelte';\n case Integration.astro:\n return 'Astro';\n case Integration.reactRouter:\n return 'React Router';\n case Integration.django:\n return 'Django';\n case Integration.flask:\n return 'Flask';\n default:\n throw new Error(`Unknown integration ${type}`);\n }\n}\n\ntype IntegrationChoice = {\n name: string;\n value: string;\n};\n\nexport function getIntegrationChoices(): IntegrationChoice[] {\n return Object.keys(Integration).map((type: string) => ({\n name: getIntegrationDescription(type),\n value: type,\n }));\n}\n\nexport interface Args {\n debug: boolean;\n integration: Integration;\n}\n\nexport const IS_DEV = ['test', 'development'].includes(\n process.env.NODE_ENV ?? '',\n);\n\nexport const DEBUG = false;\n\nexport const DEFAULT_URL = IS_DEV\n ? 'http://localhost:8010'\n : 'https://us.posthog.com';\nexport const ISSUES_URL = 'https://github.com/posthog/wizard/issues';\nexport const DEFAULT_HOST_URL = IS_DEV\n ? 'http://localhost:8010'\n : 'https://us.i.posthog.com';\nexport const ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = 'sTMFPsFhdP1Ssg';\nexport const ANALYTICS_HOST_URL = 'https://internal-j.posthog.com';\nexport const ANALYTICS_TEAM_TAG = 'docs-and-wizard';\nexport const DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';\n\nexport const POSTHOG_US_CLIENT_ID = 'c4Rdw8DIxgtQfA80IiSnGKlNX8QN00cFWF00QQhM';\nexport const POSTHOG_EU_CLIENT_ID = 'bx2C5sZRN03TkdjraCcetvQFPGH6N2Y9vRLkcKEy';\nexport const POSTHOG_DEV_CLIENT_ID = 'DC5uRLVbGI02YQ82grxgnK6Qn12SXWpCqdPb60oZ';\nexport const OAUTH_PORT = 8239;\n\nexport const WIZARD_INTERACTION_EVENT_NAME = 'wizard interaction';\n"]}
|
package/dist/src/run.js
CHANGED
|
@@ -18,6 +18,7 @@ const react_native_wizard_1 = require("./react-native/react-native-wizard");
|
|
|
18
18
|
const astro_wizard_1 = require("./astro/astro-wizard");
|
|
19
19
|
const react_router_wizard_agent_1 = require("./react-router/react-router-wizard-agent");
|
|
20
20
|
const django_wizard_agent_1 = require("./django/django-wizard-agent");
|
|
21
|
+
const flask_wizard_agent_1 = require("./flask/flask-wizard-agent");
|
|
21
22
|
const events_1 = require("events");
|
|
22
23
|
const chalk_1 = __importDefault(require("chalk"));
|
|
23
24
|
const errors_1 = require("./utils/errors");
|
|
@@ -88,6 +89,10 @@ async function runWizard(argv) {
|
|
|
88
89
|
clack_1.default.log.info(`${chalk_1.default.yellow('[BETA]')} The Django wizard is in beta. Questions or feedback? Email ${chalk_1.default.cyan('wizard@posthog.com')}`);
|
|
89
90
|
await (0, django_wizard_agent_1.runDjangoWizardAgent)(wizardOptions);
|
|
90
91
|
break;
|
|
92
|
+
case constants_1.Integration.flask:
|
|
93
|
+
clack_1.default.log.info(`${chalk_1.default.yellow('[BETA]')} The Flask wizard is in beta. Questions or feedback? Email ${chalk_1.default.cyan('wizard@posthog.com')}`);
|
|
94
|
+
await (0, flask_wizard_agent_1.runFlaskWizardAgent)(wizardOptions);
|
|
95
|
+
break;
|
|
91
96
|
default:
|
|
92
97
|
clack_1.default.log.error('No setup wizard selected!');
|
|
93
98
|
}
|
|
@@ -131,6 +136,7 @@ async function getIntegrationForSetup(options) {
|
|
|
131
136
|
{ value: constants_1.Integration.react, label: 'React' },
|
|
132
137
|
{ value: constants_1.Integration.reactRouter, label: 'React Router' },
|
|
133
138
|
{ value: constants_1.Integration.django, label: 'Django' },
|
|
139
|
+
{ value: constants_1.Integration.flask, label: 'Flask' },
|
|
134
140
|
{ value: constants_1.Integration.svelte, label: 'Svelte' },
|
|
135
141
|
{ value: constants_1.Integration.reactNative, label: 'React Native' },
|
|
136
142
|
],
|
package/dist/src/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/run.ts"],"names":[],"mappings":";;;;;AAwCA,8BAqGC;AA7ID,qDAAuD;AAEvD,sEAAoE;AAGpE,+CAIyB;AACzB,qDAAsD;AACtD,0DAAkC;AAClC,gDAAwB;AACxB,yCAAqE;AACrE,uDAAsD;AACtD,iDAA8C;AAC9C,0DAAyD;AACzD,4EAA0E;AAC1E,uDAAsD;AACtD,wFAAqF;AACrF,sEAAoE;AACpE,mCAAsC;AACtC,kDAA0B;AAC1B,2CAAgD;AAEhD,qBAAY,CAAC,mBAAmB,GAAG,EAAE,CAAC;AAe/B,KAAK,UAAU,SAAS,CAAC,IAAU;IACxC,MAAM,SAAS,GAAG;QAChB,GAAG,IAAI;QACP,GAAG,IAAA,6BAAe,GAAE;KACrB,CAAC;IAEF,IAAI,kBAA0B,CAAC;IAC/B,IAAI,SAAS,CAAC,UAAU,EAAE,CAAC;QACzB,IAAI,cAAI,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;YAC1C,kBAAkB,GAAG,SAAS,CAAC,UAAU,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,kBAAkB,GAAG,cAA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E,6BAA6B;QACtC,OAAO,EAAE;YACP,EAAE,KAAK,EAAE,uBAAW,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE;YAC/C,EAAE,KAAK,EAAE,uBAAW,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE;YAC5C,EAAE,KAAK,EAAE,uBAAW,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE;YAC5C,EAAE,KAAK,EAAE,uBAAW,CAAC,WAAW,EAAE,KAAK,EAAE,cAAc,EAAE;YACzD,EAAE,KAAK,EAAE,uBAAW,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE;YAC9C,EAAE,KAAK,EAAE,uBAAW,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE;YAC9C,EAAE,KAAK,EAAE,uBAAW,CAAC,WAAW,EAAE,KAAK,EAAE,cAAc,EAAE;SAC1D;KACF,CAAC,CACH,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import { abortIfCancelled } from './utils/clack-utils';\n\nimport { runNextjsWizardAgent } from './nextjs/nextjs-wizard-agent';\nimport type { CloudRegion, WizardOptions } from './utils/types';\n\nimport {\n getIntegrationDescription,\n Integration,\n FeatureFlagDefinition,\n} from './lib/constants';\nimport { readEnvironment } from './utils/environment';\nimport clack from './utils/clack';\nimport path from 'path';\nimport { INTEGRATION_CONFIG, INTEGRATION_ORDER } from './lib/config';\nimport { runReactWizard } from './react/react-wizard';\nimport { analytics } from './utils/analytics';\nimport { runSvelteWizard } from './svelte/svelte-wizard';\nimport { runReactNativeWizard } from './react-native/react-native-wizard';\nimport { runAstroWizard } from './astro/astro-wizard';\nimport { runReactRouterWizardAgent } from './react-router/react-router-wizard-agent';\nimport { runDjangoWizardAgent } from './django/django-wizard-agent';\nimport { EventEmitter } from 'events';\nimport chalk from 'chalk';\nimport { RateLimitError } from './utils/errors';\n\nEventEmitter.defaultMaxListeners = 50;\n\ntype Args = {\n integration?: Integration;\n debug?: boolean;\n forceInstall?: boolean;\n installDir?: string;\n region?: CloudRegion;\n default?: boolean;\n signup?: boolean;\n localMcp?: boolean;\n ci?: boolean;\n apiKey?: string;\n};\n\nexport async function runWizard(argv: Args) {\n const finalArgs = {\n ...argv,\n ...readEnvironment(),\n };\n\n let resolvedInstallDir: string;\n if (finalArgs.installDir) {\n if (path.isAbsolute(finalArgs.installDir)) {\n resolvedInstallDir = finalArgs.installDir;\n } else {\n resolvedInstallDir = path.join(process.cwd(), finalArgs.installDir);\n }\n } else {\n resolvedInstallDir = process.cwd();\n }\n\n const wizardOptions: WizardOptions = {\n debug: finalArgs.debug ?? false,\n forceInstall: finalArgs.forceInstall ?? false,\n installDir: resolvedInstallDir,\n cloudRegion: finalArgs.region ?? undefined,\n default: finalArgs.default ?? false,\n signup: finalArgs.signup ?? false,\n localMcp: finalArgs.localMcp ?? false,\n ci: finalArgs.ci ?? false,\n apiKey: finalArgs.apiKey,\n };\n\n clack.intro(`Welcome to the PostHog setup wizard ✨`);\n\n if (wizardOptions.ci) {\n clack.log.info(chalk.dim('Running in CI mode'));\n }\n\n const integration =\n finalArgs.integration ?? (await getIntegrationForSetup(wizardOptions));\n\n analytics.setTag('integration', integration);\n\n try {\n switch (integration) {\n case Integration.nextjs:\n await runNextjsWizardAgent(wizardOptions);\n break;\n case Integration.react:\n await runReactWizard(wizardOptions);\n break;\n case Integration.svelte:\n await runSvelteWizard(wizardOptions);\n break;\n case Integration.reactNative:\n await runReactNativeWizard(wizardOptions);\n break;\n case Integration.astro:\n await runAstroWizard(wizardOptions);\n break;\n case Integration.reactRouter: {\n const flagValue = await analytics.getFeatureFlag(\n FeatureFlagDefinition.ReactRouter,\n );\n // In CI mode, bypass feature flags and always use the React Router wizard\n if (wizardOptions.ci || flagValue === true) {\n await runReactRouterWizardAgent(wizardOptions);\n } else {\n await runReactWizard(wizardOptions);\n }\n break;\n }\n case Integration.django:\n clack.log.info(\n `${chalk.yellow(\n '[BETA]',\n )} The Django wizard is in beta. Questions or feedback? Email ${chalk.cyan(\n 'wizard@posthog.com',\n )}`,\n );\n await runDjangoWizardAgent(wizardOptions);\n break;\n default:\n clack.log.error('No setup wizard selected!');\n }\n } catch (error) {\n analytics.captureException(error as Error, {\n integration,\n arguments: JSON.stringify(finalArgs),\n });\n\n await analytics.shutdown('error');\n\n if (error instanceof RateLimitError) {\n clack.log.error('Wizard usage limit reached. Please try again later.');\n } else {\n clack.log.error(\n `Something went wrong. You can read the documentation at ${chalk.cyan(\n `${INTEGRATION_CONFIG[integration].docsUrl}`,\n )} to set up PostHog manually.`,\n );\n }\n process.exit(1);\n }\n}\n\nasync function detectIntegration(\n options: Pick<WizardOptions, 'installDir'>,\n): Promise<Integration | undefined> {\n const integrationConfigs = Object.entries(INTEGRATION_CONFIG).sort(\n ([a], [b]) =>\n INTEGRATION_ORDER.indexOf(a as Integration) -\n INTEGRATION_ORDER.indexOf(b as Integration),\n );\n\n for (const [integration, config] of integrationConfigs) {\n const detected = await config.detect(options);\n if (detected) {\n return integration as Integration;\n }\n }\n}\n\nasync function getIntegrationForSetup(\n options: Pick<WizardOptions, 'installDir'>,\n) {\n const detectedIntegration = await detectIntegration(options);\n\n if (detectedIntegration) {\n clack.log.success(\n `Detected integration: ${getIntegrationDescription(detectedIntegration)}`,\n );\n return detectedIntegration;\n }\n\n const integration: Integration = await abortIfCancelled(\n clack.select({\n message: 'What do you want to set up?',\n options: [\n { value: Integration.nextjs, label: 'Next.js' },\n { value: Integration.astro, label: 'Astro' },\n { value: Integration.react, label: 'React' },\n { value: Integration.reactRouter, label: 'React Router' },\n { value: Integration.django, label: 'Django' },\n { value: Integration.svelte, label: 'Svelte' },\n { value: Integration.reactNative, label: 'React Native' },\n ],\n }),\n );\n\n return integration;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/run.ts"],"names":[],"mappings":";;;;;AAyCA,8BA+GC;AAxJD,qDAAuD;AAEvD,sEAAoE;AAGpE,+CAIyB;AACz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EAAE,KAAK,EAAE,QAAQ,EAAE;YAC9C,EAAE,KAAK,EAAE,uBAAW,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE;YAC5C,EAAE,KAAK,EAAE,uBAAW,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE;YAC9C,EAAE,KAAK,EAAE,uBAAW,CAAC,WAAW,EAAE,KAAK,EAAE,cAAc,EAAE;SAC1D;KACF,CAAC,CACH,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import { abortIfCancelled } from './utils/clack-utils';\n\nimport { runNextjsWizardAgent } from './nextjs/nextjs-wizard-agent';\nimport type { CloudRegion, WizardOptions } from './utils/types';\n\nimport {\n getIntegrationDescription,\n Integration,\n FeatureFlagDefinition,\n} from './lib/constants';\nimport { readEnvironment } from './utils/environment';\nimport clack from './utils/clack';\nimport path from 'path';\nimport { INTEGRATION_CONFIG, INTEGRATION_ORDER } from './lib/config';\nimport { runReactWizard } from './react/react-wizard';\nimport { analytics } from './utils/analytics';\nimport { runSvelteWizard } from './svelte/svelte-wizard';\nimport { runReactNativeWizard } from './react-native/react-native-wizard';\nimport { runAstroWizard } from './astro/astro-wizard';\nimport { runReactRouterWizardAgent } from './react-router/react-router-wizard-agent';\nimport { runDjangoWizardAgent } from './django/django-wizard-agent';\nimport { runFlaskWizardAgent } from './flask/flask-wizard-agent';\nimport { EventEmitter } from 'events';\nimport chalk from 'chalk';\nimport { RateLimitError } from './utils/errors';\n\nEventEmitter.defaultMaxListeners = 50;\n\ntype Args = {\n integration?: Integration;\n debug?: boolean;\n forceInstall?: boolean;\n installDir?: string;\n region?: CloudRegion;\n default?: boolean;\n signup?: boolean;\n localMcp?: boolean;\n ci?: boolean;\n apiKey?: string;\n};\n\nexport async function runWizard(argv: Args) {\n const finalArgs = {\n ...argv,\n ...readEnvironment(),\n };\n\n let resolvedInstallDir: string;\n if (finalArgs.installDir) {\n if (path.isAbsolute(finalArgs.installDir)) {\n resolvedInstallDir = finalArgs.installDir;\n } else {\n resolvedInstallDir = path.join(process.cwd(), finalArgs.installDir);\n }\n } else {\n resolvedInstallDir = process.cwd();\n }\n\n const wizardOptions: WizardOptions = {\n debug: finalArgs.debug ?? false,\n forceInstall: finalArgs.forceInstall ?? false,\n installDir: resolvedInstallDir,\n cloudRegion: finalArgs.region ?? undefined,\n default: finalArgs.default ?? false,\n signup: finalArgs.signup ?? false,\n localMcp: finalArgs.localMcp ?? false,\n ci: finalArgs.ci ?? false,\n apiKey: finalArgs.apiKey,\n };\n\n clack.intro(`Welcome to the PostHog setup wizard ✨`);\n\n if (wizardOptions.ci) {\n clack.log.info(chalk.dim('Running in CI mode'));\n }\n\n const integration =\n finalArgs.integration ?? (await getIntegrationForSetup(wizardOptions));\n\n analytics.setTag('integration', integration);\n\n try {\n switch (integration) {\n case Integration.nextjs:\n await runNextjsWizardAgent(wizardOptions);\n break;\n case Integration.react:\n await runReactWizard(wizardOptions);\n break;\n case Integration.svelte:\n await runSvelteWizard(wizardOptions);\n break;\n case Integration.reactNative:\n await runReactNativeWizard(wizardOptions);\n break;\n case Integration.astro:\n await runAstroWizard(wizardOptions);\n break;\n case Integration.reactRouter: {\n const flagValue = await analytics.getFeatureFlag(\n FeatureFlagDefinition.ReactRouter,\n );\n // In CI mode, bypass feature flags and always use the React Router wizard\n if (wizardOptions.ci || flagValue === true) {\n await runReactRouterWizardAgent(wizardOptions);\n } else {\n await runReactWizard(wizardOptions);\n }\n break;\n }\n case Integration.django:\n clack.log.info(\n `${chalk.yellow(\n '[BETA]',\n )} The Django wizard is in beta. Questions or feedback? Email ${chalk.cyan(\n 'wizard@posthog.com',\n )}`,\n );\n await runDjangoWizardAgent(wizardOptions);\n break;\n case Integration.flask:\n clack.log.info(\n `${chalk.yellow(\n '[BETA]',\n )} The Flask wizard is in beta. Questions or feedback? Email ${chalk.cyan(\n 'wizard@posthog.com',\n )}`,\n );\n await runFlaskWizardAgent(wizardOptions);\n break;\n default:\n clack.log.error('No setup wizard selected!');\n }\n } catch (error) {\n analytics.captureException(error as Error, {\n integration,\n arguments: JSON.stringify(finalArgs),\n });\n\n await analytics.shutdown('error');\n\n if (error instanceof RateLimitError) {\n clack.log.error('Wizard usage limit reached. Please try again later.');\n } else {\n clack.log.error(\n `Something went wrong. You can read the documentation at ${chalk.cyan(\n `${INTEGRATION_CONFIG[integration].docsUrl}`,\n )} to set up PostHog manually.`,\n );\n }\n process.exit(1);\n }\n}\n\nasync function detectIntegration(\n options: Pick<WizardOptions, 'installDir'>,\n): Promise<Integration | undefined> {\n const integrationConfigs = Object.entries(INTEGRATION_CONFIG).sort(\n ([a], [b]) =>\n INTEGRATION_ORDER.indexOf(a as Integration) -\n INTEGRATION_ORDER.indexOf(b as Integration),\n );\n\n for (const [integration, config] of integrationConfigs) {\n const detected = await config.detect(options);\n if (detected) {\n return integration as Integration;\n }\n }\n}\n\nasync function getIntegrationForSetup(\n options: Pick<WizardOptions, 'installDir'>,\n) {\n const detectedIntegration = await detectIntegration(options);\n\n if (detectedIntegration) {\n clack.log.success(\n `Detected integration: ${getIntegrationDescription(detectedIntegration)}`,\n );\n return detectedIntegration;\n }\n\n const integration: Integration = await abortIfCancelled(\n clack.select({\n message: 'What do you want to set up?',\n options: [\n { value: Integration.nextjs, label: 'Next.js' },\n { value: Integration.astro, label: 'Astro' },\n { value: Integration.react, label: 'React' },\n { value: Integration.reactRouter, label: 'React Router' },\n { value: Integration.django, label: 'Django' },\n { value: Integration.flask, label: 'Flask' },\n { value: Integration.svelte, label: 'Svelte' },\n { value: Integration.reactNative, label: 'React Native' },\n ],\n }),\n );\n\n return integration;\n}\n"]}
|
package/package.json
CHANGED