@contractspec/example.product-intent 1.57.0 → 1.59.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/.turbo/turbo-build.log +21 -96
- package/.turbo/turbo-prebuild.log +1 -0
- package/CHANGELOG.md +29 -0
- package/dist/example.d.ts +2 -6
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +27 -37
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +342 -4
- package/dist/load-evidence.d.ts +13 -17
- package/dist/load-evidence.d.ts.map +1 -1
- package/dist/load-evidence.js +307 -68
- package/dist/load-evidence.test.d.ts +2 -0
- package/dist/load-evidence.test.d.ts.map +1 -0
- package/dist/node/example.js +28 -0
- package/dist/node/index.js +342 -0
- package/dist/node/load-evidence.js +313 -0
- package/dist/node/posthog-signals.js +248 -0
- package/dist/node/script.js +512 -0
- package/dist/node/sync-actions.js +491 -0
- package/dist/posthog-signals.d.ts +15 -19
- package/dist/posthog-signals.d.ts.map +1 -1
- package/dist/posthog-signals.js +222 -178
- package/dist/script.d.ts +2 -1
- package/dist/script.d.ts.map +1 -0
- package/dist/script.js +493 -152
- package/dist/sync-actions.d.ts +2 -1
- package/dist/sync-actions.d.ts.map +1 -0
- package/dist/sync-actions.js +466 -128
- package/package.json +57 -27
- package/tsdown.config.js +1 -2
- package/.turbo/turbo-build$colon$bundle.log +0 -99
- package/dist/example.js.map +0 -1
- package/dist/libs/analytics/dist/funnel/analyzer.js +0 -64
- package/dist/libs/analytics/dist/funnel/analyzer.js.map +0 -1
- package/dist/libs/analytics/dist/types.d.ts +0 -22
- package/dist/libs/analytics/dist/types.d.ts.map +0 -1
- package/dist/load-evidence.js.map +0 -1
- package/dist/posthog-signals.js.map +0 -1
- package/dist/script.js.map +0 -1
- package/dist/sync-actions.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
// src/posthog-signals.ts
|
|
2
|
+
import { FunnelAnalyzer } from "@contractspec/lib.analytics/funnel";
|
|
3
|
+
import { PosthogAnalyticsProvider } from "@contractspec/integration.providers-impls/impls/posthog";
|
|
4
|
+
async function loadPosthogEvidenceChunks(options) {
|
|
5
|
+
const chunks = [];
|
|
6
|
+
const range = resolveRange(options.dateRange);
|
|
7
|
+
const eventSummary = await loadEventSummary(options, range);
|
|
8
|
+
if (eventSummary) {
|
|
9
|
+
chunks.push(eventSummary);
|
|
10
|
+
}
|
|
11
|
+
const funnelEvidence = await loadFunnelEvidence(options, range);
|
|
12
|
+
if (funnelEvidence) {
|
|
13
|
+
chunks.push(funnelEvidence);
|
|
14
|
+
}
|
|
15
|
+
const featureFlags = await loadFeatureFlagEvidence(options);
|
|
16
|
+
if (featureFlags) {
|
|
17
|
+
chunks.push(featureFlags);
|
|
18
|
+
}
|
|
19
|
+
return chunks;
|
|
20
|
+
}
|
|
21
|
+
async function loadEventSummary(options, range) {
|
|
22
|
+
if (!options.reader.queryHogQL)
|
|
23
|
+
return null;
|
|
24
|
+
const eventFilter = buildEventFilter(options.eventNames);
|
|
25
|
+
const limit = options.limit ?? 10;
|
|
26
|
+
const result = await options.reader.queryHogQL({
|
|
27
|
+
query: [
|
|
28
|
+
"select",
|
|
29
|
+
" event as eventName,",
|
|
30
|
+
" count() as total",
|
|
31
|
+
"from events",
|
|
32
|
+
"where timestamp >= {dateFrom} and timestamp < {dateTo}",
|
|
33
|
+
eventFilter.clause ? `and ${eventFilter.clause}` : "",
|
|
34
|
+
"group by eventName",
|
|
35
|
+
"order by total desc",
|
|
36
|
+
`limit ${limit}`
|
|
37
|
+
].filter(Boolean).join(`
|
|
38
|
+
`),
|
|
39
|
+
values: {
|
|
40
|
+
dateFrom: range.from.toISOString(),
|
|
41
|
+
dateTo: range.to.toISOString(),
|
|
42
|
+
...eventFilter.values
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const rows = mapRows(result);
|
|
46
|
+
if (rows.length === 0)
|
|
47
|
+
return null;
|
|
48
|
+
const lines = rows.map((row) => {
|
|
49
|
+
const name = asString(row.eventName) ?? "unknown";
|
|
50
|
+
const total = asNumber(row.total);
|
|
51
|
+
return `- ${name}: ${total}`;
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
chunkId: `posthog:event_summary:${range.from.toISOString()}`,
|
|
55
|
+
text: [
|
|
56
|
+
`PostHog event summary (${range.from.toISOString()} → ${range.to.toISOString()}):`,
|
|
57
|
+
...lines
|
|
58
|
+
].join(`
|
|
59
|
+
`),
|
|
60
|
+
meta: {
|
|
61
|
+
source: "posthog",
|
|
62
|
+
kind: "event_summary",
|
|
63
|
+
dateFrom: range.from.toISOString(),
|
|
64
|
+
dateTo: range.to.toISOString()
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async function loadFunnelEvidence(options, range) {
|
|
69
|
+
if (!options.funnel)
|
|
70
|
+
return null;
|
|
71
|
+
if (!options.reader.getEvents)
|
|
72
|
+
return null;
|
|
73
|
+
const events = [];
|
|
74
|
+
const eventNames = options.funnel.steps.map((step) => step.eventName);
|
|
75
|
+
for (const eventName of eventNames) {
|
|
76
|
+
const response = await options.reader.getEvents({
|
|
77
|
+
event: eventName,
|
|
78
|
+
dateRange: {
|
|
79
|
+
from: range.from,
|
|
80
|
+
to: range.to
|
|
81
|
+
},
|
|
82
|
+
limit: options.limit ?? 500
|
|
83
|
+
});
|
|
84
|
+
response.results.forEach((event) => {
|
|
85
|
+
events.push({
|
|
86
|
+
name: event.event,
|
|
87
|
+
userId: event.distinctId,
|
|
88
|
+
tenantId: typeof event.properties?.tenantId === "string" ? event.properties.tenantId : undefined,
|
|
89
|
+
timestamp: event.timestamp,
|
|
90
|
+
properties: event.properties
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (events.length === 0)
|
|
95
|
+
return null;
|
|
96
|
+
const analyzer = new FunnelAnalyzer;
|
|
97
|
+
const analysis = analyzer.analyze(events, options.funnel);
|
|
98
|
+
const lines = analysis.steps.map((step) => {
|
|
99
|
+
return `- ${step.step.eventName}: ${step.count} (conversion ${step.conversionRate}, drop-off ${step.dropOffRate})`;
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
chunkId: `posthog:funnel:${options.funnel.name}`,
|
|
103
|
+
text: [`PostHog funnel analysis — ${options.funnel.name}:`, ...lines].join(`
|
|
104
|
+
`),
|
|
105
|
+
meta: {
|
|
106
|
+
source: "posthog",
|
|
107
|
+
kind: "funnel",
|
|
108
|
+
funnelName: options.funnel.name,
|
|
109
|
+
dateFrom: range.from.toISOString(),
|
|
110
|
+
dateTo: range.to.toISOString()
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
async function loadFeatureFlagEvidence(options) {
|
|
115
|
+
if (!options.includeFeatureFlags)
|
|
116
|
+
return null;
|
|
117
|
+
if (!options.reader.getFeatureFlags)
|
|
118
|
+
return null;
|
|
119
|
+
const response = await options.reader.getFeatureFlags({ limit: 10 });
|
|
120
|
+
if (!response.results.length)
|
|
121
|
+
return null;
|
|
122
|
+
const lines = response.results.map((flag) => {
|
|
123
|
+
const key = flag.key ?? "unknown";
|
|
124
|
+
const active = flag.active ? "active" : "inactive";
|
|
125
|
+
return `- ${key}: ${active}`;
|
|
126
|
+
});
|
|
127
|
+
return {
|
|
128
|
+
chunkId: "posthog:feature_flags",
|
|
129
|
+
text: ["PostHog feature flags:", ...lines].join(`
|
|
130
|
+
`),
|
|
131
|
+
meta: {
|
|
132
|
+
source: "posthog",
|
|
133
|
+
kind: "feature_flags"
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function resolveRange(dateRange) {
|
|
138
|
+
const now = new Date;
|
|
139
|
+
const from = dateRange?.from instanceof Date ? dateRange.from : dateRange?.from ? new Date(dateRange.from) : new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
|
|
140
|
+
const to = dateRange?.to instanceof Date ? dateRange.to : dateRange?.to ? new Date(dateRange.to) : now;
|
|
141
|
+
return { from, to };
|
|
142
|
+
}
|
|
143
|
+
function buildEventFilter(eventNames) {
|
|
144
|
+
if (!eventNames || eventNames.length === 0)
|
|
145
|
+
return {};
|
|
146
|
+
if (eventNames.length === 1) {
|
|
147
|
+
return {
|
|
148
|
+
clause: "event = {event0}",
|
|
149
|
+
values: { event0: eventNames[0] }
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const values = {};
|
|
153
|
+
const clauses = eventNames.map((eventName, index) => {
|
|
154
|
+
values[`event${index}`] = eventName;
|
|
155
|
+
return `event = {event${index}}`;
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
clause: `(${clauses.join(" or ")})`,
|
|
159
|
+
values
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function mapRows(result) {
|
|
163
|
+
if (!Array.isArray(result.results) || !Array.isArray(result.columns)) {
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
const columns = result.columns;
|
|
167
|
+
return result.results.flatMap((row) => {
|
|
168
|
+
if (!Array.isArray(row))
|
|
169
|
+
return [];
|
|
170
|
+
const record = {};
|
|
171
|
+
columns.forEach((column, index) => {
|
|
172
|
+
record[column] = row[index];
|
|
173
|
+
});
|
|
174
|
+
return [record];
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function asString(value) {
|
|
178
|
+
if (typeof value === "string" && value.trim())
|
|
179
|
+
return value;
|
|
180
|
+
if (typeof value === "number")
|
|
181
|
+
return String(value);
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
function asNumber(value) {
|
|
185
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
186
|
+
return value;
|
|
187
|
+
if (typeof value === "string" && value.trim()) {
|
|
188
|
+
const parsed = Number(value);
|
|
189
|
+
if (Number.isFinite(parsed))
|
|
190
|
+
return parsed;
|
|
191
|
+
}
|
|
192
|
+
return 0;
|
|
193
|
+
}
|
|
194
|
+
function resolvePosthogEvidenceOptionsFromEnv(options = {}) {
|
|
195
|
+
const projectId = process.env.POSTHOG_PROJECT_ID;
|
|
196
|
+
const personalApiKey = process.env.POSTHOG_PERSONAL_API_KEY;
|
|
197
|
+
if (!projectId || !personalApiKey)
|
|
198
|
+
return null;
|
|
199
|
+
const lookbackDays = resolveNumberEnv("POSTHOG_EVIDENCE_LOOKBACK_DAYS", options.defaultLookbackDays ?? 30);
|
|
200
|
+
const limit = resolveNumberEnv("POSTHOG_EVIDENCE_LIMIT", options.defaultLimit ?? 10);
|
|
201
|
+
const now = new Date;
|
|
202
|
+
const from = new Date(now.getTime() - lookbackDays * 24 * 60 * 60 * 1000);
|
|
203
|
+
const eventNames = resolveCsvEnv("POSTHOG_EVIDENCE_EVENTS");
|
|
204
|
+
const funnelSteps = resolveCsvEnv("POSTHOG_EVIDENCE_FUNNEL_STEPS");
|
|
205
|
+
const funnel = funnelSteps && funnelSteps.length ? {
|
|
206
|
+
name: "posthog-evidence-funnel",
|
|
207
|
+
steps: funnelSteps.map((eventName, index) => ({
|
|
208
|
+
id: `step_${index + 1}`,
|
|
209
|
+
eventName
|
|
210
|
+
}))
|
|
211
|
+
} : undefined;
|
|
212
|
+
const reader = new PosthogAnalyticsProvider({
|
|
213
|
+
host: process.env.POSTHOG_HOST,
|
|
214
|
+
projectId,
|
|
215
|
+
personalApiKey
|
|
216
|
+
});
|
|
217
|
+
return {
|
|
218
|
+
reader,
|
|
219
|
+
dateRange: { from, to: now },
|
|
220
|
+
eventNames,
|
|
221
|
+
limit,
|
|
222
|
+
funnel,
|
|
223
|
+
includeFeatureFlags: resolveBooleanEnv("POSTHOG_EVIDENCE_FEATURE_FLAGS", true)
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function resolveCsvEnv(key) {
|
|
227
|
+
const value = process.env[key];
|
|
228
|
+
if (!value)
|
|
229
|
+
return;
|
|
230
|
+
return value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
231
|
+
}
|
|
232
|
+
function resolveNumberEnv(key, fallback) {
|
|
233
|
+
const value = process.env[key];
|
|
234
|
+
if (!value)
|
|
235
|
+
return fallback;
|
|
236
|
+
const parsed = Number(value);
|
|
237
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
238
|
+
}
|
|
239
|
+
function resolveBooleanEnv(key, fallback) {
|
|
240
|
+
const value = process.env[key];
|
|
241
|
+
if (value === undefined)
|
|
242
|
+
return fallback;
|
|
243
|
+
return value.toLowerCase() === "true";
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// src/load-evidence.ts
|
|
247
|
+
import fs from "node:fs";
|
|
248
|
+
import path from "node:path";
|
|
249
|
+
import { fileURLToPath } from "node:url";
|
|
250
|
+
var MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
251
|
+
var DEFAULT_EVIDENCE_ROOT = path.join(MODULE_DIR, "../evidence");
|
|
252
|
+
var DEFAULT_TRANSCRIPT_DIRS = ["interviews", "tickets", "public"];
|
|
253
|
+
var DEFAULT_CHUNK_SIZE = 800;
|
|
254
|
+
function stripYamlFrontMatter(contents) {
|
|
255
|
+
const start = contents.indexOf("---");
|
|
256
|
+
if (start === -1)
|
|
257
|
+
return contents;
|
|
258
|
+
const end = contents.indexOf("---", start + 3);
|
|
259
|
+
if (end === -1)
|
|
260
|
+
return contents;
|
|
261
|
+
return contents.slice(end + 3).trimStart();
|
|
262
|
+
}
|
|
263
|
+
function chunkTranscript(fileId, text, chunkSize) {
|
|
264
|
+
const chunks = [];
|
|
265
|
+
const clean = text.trim();
|
|
266
|
+
for (let offset = 0, idx = 0;offset < clean.length; idx += 1) {
|
|
267
|
+
const slice = clean.slice(offset, offset + chunkSize);
|
|
268
|
+
chunks.push({
|
|
269
|
+
chunkId: `${fileId}#c_${String(idx).padStart(2, "0")}`,
|
|
270
|
+
text: slice,
|
|
271
|
+
meta: { source: fileId }
|
|
272
|
+
});
|
|
273
|
+
offset += chunkSize;
|
|
274
|
+
}
|
|
275
|
+
return chunks;
|
|
276
|
+
}
|
|
277
|
+
function loadEvidenceChunks(options = {}) {
|
|
278
|
+
const evidenceRoot = options.evidenceRoot ?? DEFAULT_EVIDENCE_ROOT;
|
|
279
|
+
const transcriptDirs = options.transcriptDirs ?? DEFAULT_TRANSCRIPT_DIRS;
|
|
280
|
+
const chunkSize = options.chunkSize ?? DEFAULT_CHUNK_SIZE;
|
|
281
|
+
const chunks = [];
|
|
282
|
+
for (const dir of transcriptDirs) {
|
|
283
|
+
const fullDir = path.join(evidenceRoot, dir);
|
|
284
|
+
if (!fs.existsSync(fullDir))
|
|
285
|
+
continue;
|
|
286
|
+
for (const fileName of fs.readdirSync(fullDir)) {
|
|
287
|
+
const ext = path.extname(fileName).toLowerCase();
|
|
288
|
+
if (ext !== ".md")
|
|
289
|
+
continue;
|
|
290
|
+
const filePath = path.join(fullDir, fileName);
|
|
291
|
+
const raw = fs.readFileSync(filePath, "utf8");
|
|
292
|
+
const withoutFrontMatter = stripYamlFrontMatter(raw);
|
|
293
|
+
const baseId = path.parse(fileName).name;
|
|
294
|
+
const fileChunks = chunkTranscript(baseId, withoutFrontMatter, chunkSize);
|
|
295
|
+
chunks.push(...fileChunks);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return chunks;
|
|
299
|
+
}
|
|
300
|
+
async function loadEvidenceChunksWithSignals(options = {}) {
|
|
301
|
+
const baseChunks = loadEvidenceChunks(options);
|
|
302
|
+
if (!options.posthog)
|
|
303
|
+
return baseChunks;
|
|
304
|
+
const posthogChunks = await loadPosthogEvidenceChunks(options.posthog);
|
|
305
|
+
return [...baseChunks, ...posthogChunks];
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/sync-actions.ts
|
|
309
|
+
import { createAgentJsonRunner } from "@contractspec/lib.ai-agent";
|
|
310
|
+
import {
|
|
311
|
+
buildProjectManagementSyncPayload,
|
|
312
|
+
extractEvidence,
|
|
313
|
+
generateTickets,
|
|
314
|
+
groupProblems,
|
|
315
|
+
impactEngine,
|
|
316
|
+
suggestPatch
|
|
317
|
+
} from "@contractspec/lib.product-intent-utils";
|
|
318
|
+
import { LinearProjectManagementProvider } from "@contractspec/integration.providers-impls/impls/linear";
|
|
319
|
+
import { JiraProjectManagementProvider } from "@contractspec/integration.providers-impls/impls/jira";
|
|
320
|
+
import { NotionProjectManagementProvider } from "@contractspec/integration.providers-impls/impls/notion";
|
|
321
|
+
var QUESTION = "Which activation and onboarding friction should we prioritize next?";
|
|
322
|
+
function resolveProvider() {
|
|
323
|
+
const raw = (process.env.CONTRACTSPEC_PM_PROVIDER ?? "").toLowerCase();
|
|
324
|
+
if (raw === "linear" || raw === "jira" || raw === "notion")
|
|
325
|
+
return raw;
|
|
326
|
+
throw new Error("Set CONTRACTSPEC_PM_PROVIDER to one of: linear, jira, notion");
|
|
327
|
+
}
|
|
328
|
+
async function resolveModelRunner() {
|
|
329
|
+
const provider = resolveAiProviderName();
|
|
330
|
+
const apiKey = resolveApiKey(provider);
|
|
331
|
+
const proxyUrl = process.env.CONTRACTSPEC_AI_PROXY_URL;
|
|
332
|
+
const organizationId = process.env.CONTRACTSPEC_ORG_ID;
|
|
333
|
+
const baseUrl = process.env.OLLAMA_BASE_URL;
|
|
334
|
+
const model = process.env.CONTRACTSPEC_AI_MODEL ?? process.env.AI_MODEL ?? undefined;
|
|
335
|
+
if (provider !== "ollama" && !apiKey && !proxyUrl && !organizationId) {
|
|
336
|
+
throw new Error(`Missing API credentials for ${provider}. Set provider API key or CONTRACTSPEC_AI_PROXY_URL.`);
|
|
337
|
+
}
|
|
338
|
+
return createAgentJsonRunner({
|
|
339
|
+
provider: {
|
|
340
|
+
provider,
|
|
341
|
+
model,
|
|
342
|
+
apiKey,
|
|
343
|
+
baseUrl,
|
|
344
|
+
proxyUrl,
|
|
345
|
+
organizationId
|
|
346
|
+
},
|
|
347
|
+
temperature: 0,
|
|
348
|
+
system: "You are a product discovery analyst. Respond with strict JSON only and use exact quotes for citations."
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
function resolveAiProviderName() {
|
|
352
|
+
const raw = process.env.CONTRACTSPEC_AI_PROVIDER ?? process.env.AI_PROVIDER ?? "openai";
|
|
353
|
+
const normalized = raw.toLowerCase();
|
|
354
|
+
const allowed = [
|
|
355
|
+
"openai",
|
|
356
|
+
"anthropic",
|
|
357
|
+
"mistral",
|
|
358
|
+
"gemini",
|
|
359
|
+
"ollama"
|
|
360
|
+
];
|
|
361
|
+
if (!allowed.includes(normalized)) {
|
|
362
|
+
throw new Error(`Unsupported AI provider: ${raw}. Use one of: ${allowed.join(", ")}`);
|
|
363
|
+
}
|
|
364
|
+
return normalized;
|
|
365
|
+
}
|
|
366
|
+
function resolveApiKey(provider) {
|
|
367
|
+
switch (provider.toLowerCase()) {
|
|
368
|
+
case "openai":
|
|
369
|
+
return process.env.OPENAI_API_KEY;
|
|
370
|
+
case "anthropic":
|
|
371
|
+
return process.env.ANTHROPIC_API_KEY;
|
|
372
|
+
case "mistral":
|
|
373
|
+
return process.env.MISTRAL_API_KEY;
|
|
374
|
+
case "gemini":
|
|
375
|
+
return process.env.GOOGLE_API_KEY ?? process.env.GEMINI_API_KEY;
|
|
376
|
+
case "ollama":
|
|
377
|
+
return;
|
|
378
|
+
default:
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function createLogger() {
|
|
383
|
+
return {
|
|
384
|
+
log: () => {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
async function run() {
|
|
390
|
+
const provider = resolveProvider();
|
|
391
|
+
const modelRunner = await resolveModelRunner();
|
|
392
|
+
const evidenceChunks = await loadEvidenceChunksWithSignals({
|
|
393
|
+
posthog: resolvePosthogEvidenceOptionsFromEnv() ?? undefined
|
|
394
|
+
});
|
|
395
|
+
const findings = await extractEvidence(evidenceChunks, QUESTION, {
|
|
396
|
+
modelRunner,
|
|
397
|
+
logger: createLogger(),
|
|
398
|
+
maxAttempts: 2
|
|
399
|
+
});
|
|
400
|
+
const problems = await groupProblems(findings, QUESTION, {
|
|
401
|
+
modelRunner,
|
|
402
|
+
logger: createLogger(),
|
|
403
|
+
maxAttempts: 2
|
|
404
|
+
});
|
|
405
|
+
const tickets = await generateTickets(problems, findings, QUESTION, {
|
|
406
|
+
modelRunner,
|
|
407
|
+
logger: createLogger(),
|
|
408
|
+
maxAttempts: 2
|
|
409
|
+
});
|
|
410
|
+
const patchIntent = tickets[0] ? await suggestPatch(tickets[0], {
|
|
411
|
+
modelRunner,
|
|
412
|
+
logger: createLogger(),
|
|
413
|
+
maxAttempts: 2
|
|
414
|
+
}) : undefined;
|
|
415
|
+
const impact = patchIntent ? impactEngine(patchIntent) : undefined;
|
|
416
|
+
const payload = buildProjectManagementSyncPayload({
|
|
417
|
+
question: QUESTION,
|
|
418
|
+
tickets,
|
|
419
|
+
patchIntent,
|
|
420
|
+
impact,
|
|
421
|
+
options: {
|
|
422
|
+
includeSummary: true,
|
|
423
|
+
baseTags: ["product-intent"],
|
|
424
|
+
defaultPriority: "medium"
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
if (process.env.CONTRACTSPEC_PM_DRY_RUN === "true") {
|
|
428
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
const created = await syncToProvider(provider, payload);
|
|
432
|
+
console.log(JSON.stringify(created, null, 2));
|
|
433
|
+
}
|
|
434
|
+
async function syncToProvider(provider, payload) {
|
|
435
|
+
if (provider === "linear") {
|
|
436
|
+
const client2 = new LinearProjectManagementProvider({
|
|
437
|
+
apiKey: requireEnv("LINEAR_API_KEY"),
|
|
438
|
+
teamId: requireEnv("LINEAR_TEAM_ID"),
|
|
439
|
+
projectId: process.env.LINEAR_PROJECT_ID,
|
|
440
|
+
stateId: process.env.LINEAR_STATE_ID,
|
|
441
|
+
assigneeId: process.env.LINEAR_ASSIGNEE_ID,
|
|
442
|
+
labelIds: splitList(process.env.LINEAR_LABEL_IDS)
|
|
443
|
+
});
|
|
444
|
+
return executeSync(client2, payload);
|
|
445
|
+
}
|
|
446
|
+
if (provider === "jira") {
|
|
447
|
+
const client2 = new JiraProjectManagementProvider({
|
|
448
|
+
siteUrl: requireEnv("JIRA_SITE_URL"),
|
|
449
|
+
email: requireEnv("JIRA_EMAIL"),
|
|
450
|
+
apiToken: requireEnv("JIRA_API_TOKEN"),
|
|
451
|
+
projectKey: process.env.JIRA_PROJECT_KEY,
|
|
452
|
+
issueType: process.env.JIRA_ISSUE_TYPE,
|
|
453
|
+
defaultLabels: splitList(process.env.JIRA_DEFAULT_LABELS)
|
|
454
|
+
});
|
|
455
|
+
return executeSync(client2, payload);
|
|
456
|
+
}
|
|
457
|
+
const client = new NotionProjectManagementProvider({
|
|
458
|
+
apiKey: requireEnv("NOTION_API_KEY"),
|
|
459
|
+
databaseId: process.env.NOTION_DATABASE_ID,
|
|
460
|
+
summaryParentPageId: process.env.NOTION_SUMMARY_PARENT_PAGE_ID,
|
|
461
|
+
titleProperty: process.env.NOTION_TITLE_PROPERTY,
|
|
462
|
+
statusProperty: process.env.NOTION_STATUS_PROPERTY,
|
|
463
|
+
priorityProperty: process.env.NOTION_PRIORITY_PROPERTY,
|
|
464
|
+
tagsProperty: process.env.NOTION_TAGS_PROPERTY,
|
|
465
|
+
dueDateProperty: process.env.NOTION_DUE_DATE_PROPERTY,
|
|
466
|
+
descriptionProperty: process.env.NOTION_DESCRIPTION_PROPERTY
|
|
467
|
+
});
|
|
468
|
+
return executeSync(client, payload);
|
|
469
|
+
}
|
|
470
|
+
async function executeSync(client, payload) {
|
|
471
|
+
const summary = payload.summary ? await client.createWorkItem(payload.summary) : undefined;
|
|
472
|
+
const items = await client.createWorkItems(payload.items);
|
|
473
|
+
return { summary, items };
|
|
474
|
+
}
|
|
475
|
+
function requireEnv(key) {
|
|
476
|
+
const value = process.env[key];
|
|
477
|
+
if (!value) {
|
|
478
|
+
throw new Error(`Missing required env var: ${key}`);
|
|
479
|
+
}
|
|
480
|
+
return value;
|
|
481
|
+
}
|
|
482
|
+
function splitList(value) {
|
|
483
|
+
if (!value)
|
|
484
|
+
return;
|
|
485
|
+
const items = value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
486
|
+
return items.length > 0 ? items : undefined;
|
|
487
|
+
}
|
|
488
|
+
run().catch((error) => {
|
|
489
|
+
console.error(error);
|
|
490
|
+
process.exitCode = 1;
|
|
491
|
+
});
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EvidenceChunk } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
funnel?: FunnelDefinition;
|
|
12
|
-
includeFeatureFlags?: boolean;
|
|
1
|
+
import type { AnalyticsReader, DateRangeInput } from '@contractspec/lib.contracts/integrations/providers/analytics';
|
|
2
|
+
import type { EvidenceChunk } from '@contractspec/lib.contracts/product-intent/types';
|
|
3
|
+
import type { FunnelDefinition } from '@contractspec/lib.analytics';
|
|
4
|
+
export interface PosthogEvidenceOptions {
|
|
5
|
+
reader: AnalyticsReader;
|
|
6
|
+
dateRange?: DateRangeInput;
|
|
7
|
+
eventNames?: string[];
|
|
8
|
+
limit?: number;
|
|
9
|
+
funnel?: FunnelDefinition;
|
|
10
|
+
includeFeatureFlags?: boolean;
|
|
13
11
|
}
|
|
14
|
-
interface PosthogEvidenceEnvOptions {
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
export interface PosthogEvidenceEnvOptions {
|
|
13
|
+
defaultLookbackDays?: number;
|
|
14
|
+
defaultLimit?: number;
|
|
17
15
|
}
|
|
18
|
-
declare function loadPosthogEvidenceChunks(options: PosthogEvidenceOptions): Promise<EvidenceChunk[]>;
|
|
19
|
-
declare function resolvePosthogEvidenceOptionsFromEnv(options?: PosthogEvidenceEnvOptions): PosthogEvidenceOptions | null;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { PosthogEvidenceEnvOptions, PosthogEvidenceOptions, loadPosthogEvidenceChunks, resolvePosthogEvidenceOptionsFromEnv };
|
|
16
|
+
export declare function loadPosthogEvidenceChunks(options: PosthogEvidenceOptions): Promise<EvidenceChunk[]>;
|
|
17
|
+
export declare function resolvePosthogEvidenceOptionsFromEnv(options?: PosthogEvidenceEnvOptions): PosthogEvidenceOptions | null;
|
|
22
18
|
//# sourceMappingURL=posthog-signals.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-signals.d.ts","
|
|
1
|
+
{"version":3,"file":"posthog-signals.d.ts","sourceRoot":"","sources":["../src/posthog-signals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAEf,cAAc,EACf,MAAM,8DAA8D,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAC;AAEtF,OAAO,KAAK,EAEV,gBAAgB,EACjB,MAAM,6BAA6B,CAAC;AAGrC,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,yBAAyB;IACxC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,aAAa,EAAE,CAAC,CAoB1B;AAoMD,wBAAgB,oCAAoC,CAClD,OAAO,GAAE,yBAA8B,GACtC,sBAAsB,GAAG,IAAI,CA8C/B"}
|