@contractspec/example.product-intent 3.7.17 → 3.7.19

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.
@@ -2,31 +2,31 @@ $ contractspec-bun-build prebuild
2
2
  $ bun run build:bundle && bun run build:types
3
3
  $ contractspec-bun-build transpile
4
4
  [contractspec-bun-build] transpile target=bun root=src entries=10 noBundle=false
5
- Bundled 10 modules in 43ms
5
+ Bundled 10 modules in 61ms
6
6
 
7
- docs/index.js 1.41 KB (entry point)
8
- ./script.js 16.50 KB (entry point)
9
- ./sync-actions.js 15.97 KB (entry point)
10
- docs/product-intent.docblock.js 1.41 KB (entry point)
11
- ./index.js 14.46 KB (entry point)
12
- ./example.js 0.95 KB (entry point)
13
- ./load-evidence.js 9.86 KB (entry point)
14
- ./posthog-signals.js 7.59 KB (entry point)
15
- ./product-intent.discovery.js 3.0 KB (entry point)
16
- ./product-intent.feature.js 0.60 KB (entry point)
7
+ docs/index.js 1.23 KB (entry point)
8
+ ./script.js 9.32 KB (entry point)
9
+ ./sync-actions.js 9.22 KB (entry point)
10
+ docs/product-intent.docblock.js 1.23 KB (entry point)
11
+ ./index.js 8.96 KB (entry point)
12
+ ./example.js 0.70 KB (entry point)
13
+ ./load-evidence.js 5.33 KB (entry point)
14
+ ./posthog-signals.js 4.34 KB (entry point)
15
+ ./product-intent.discovery.js 2.44 KB (entry point)
16
+ ./product-intent.feature.js 461 bytes (entry point)
17
17
 
18
18
  [contractspec-bun-build] transpile target=node root=src entries=10 noBundle=false
19
- Bundled 10 modules in 36ms
19
+ Bundled 10 modules in 26ms
20
20
 
21
- docs/index.js 1.40 KB (entry point)
22
- ./script.js 16.51 KB (entry point)
23
- ./sync-actions.js 15.97 KB (entry point)
24
- docs/product-intent.docblock.js 1.40 KB (entry point)
25
- ./index.js 14.46 KB (entry point)
26
- ./example.js 0.94 KB (entry point)
27
- ./load-evidence.js 9.86 KB (entry point)
28
- ./posthog-signals.js 7.58 KB (entry point)
29
- ./product-intent.discovery.js 3.0 KB (entry point)
30
- ./product-intent.feature.js 0.59 KB (entry point)
21
+ docs/index.js 1.22 KB (entry point)
22
+ ./script.js 9.33 KB (entry point)
23
+ ./sync-actions.js 9.22 KB (entry point)
24
+ docs/product-intent.docblock.js 1.22 KB (entry point)
25
+ ./index.js 8.96 KB (entry point)
26
+ ./example.js 0.69 KB (entry point)
27
+ ./load-evidence.js 5.34 KB (entry point)
28
+ ./posthog-signals.js 4.33 KB (entry point)
29
+ ./product-intent.discovery.js 2.43 KB (entry point)
30
+ ./product-intent.feature.js 453 bytes (entry point)
31
31
 
32
32
  $ contractspec-bun-build types
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @contractspec/example.product-intent
2
2
 
3
+ ## 3.7.19
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies because of Expand ContractSpec authoring with preset-driven workspace setup, shell completion, packaged workspace schema artifacts, and richer form and UI surfaces across the CLI, editors, and shared runtimes.
8
+ - @contractspec/lib.contracts-spec@5.3.0
9
+ - @contractspec/integration.providers-impls@3.8.11
10
+ - @contractspec/lib.ai-agent@8.0.7
11
+ - @contractspec/lib.analytics@3.7.19
12
+ - @contractspec/lib.contracts-integrations@3.8.11
13
+ - @contractspec/lib.product-intent-utils@3.7.19
14
+
15
+ ## 3.7.18
16
+
17
+ ### Patch Changes
18
+
19
+ - chore: auto-bump internal dependents
20
+ - Updated dependencies because of chore: auto-bump internal dependents
21
+ - Updated dependencies because of Introduce the Builder v3 control plane as a governed authoring layer over external execution providers.
22
+ - Updated dependencies because of Implement ContractSpec Connect as a first-class spec, runtime, and CLI workflow.
23
+ - @contractspec/integration.providers-impls@3.8.10
24
+ - @contractspec/lib.ai-agent@8.0.6
25
+ - @contractspec/lib.analytics@3.7.18
26
+ - @contractspec/lib.contracts-integrations@3.8.10
27
+ - @contractspec/lib.product-intent-utils@3.7.18
28
+ - @contractspec/lib.contracts-spec@5.2.0
29
+
3
30
  ## 3.7.17
4
31
 
5
32
  ### Patch Changes
@@ -1,35 +1,11 @@
1
1
  // @bun
2
- // src/docs/product-intent.docblock.ts
3
- import { registerDocBlocks } from "@contractspec/lib.contracts-spec/docs";
4
- var blocks = [
5
- {
6
- id: "docs.examples.product-intent",
7
- title: "Product Intent Discovery",
8
- summary: "Evidence-ingestion example for turning product signals into prompt-ready discovery outputs.",
9
- kind: "reference",
10
- visibility: "public",
11
- route: "/docs/examples/product-intent",
12
- tags: ["product-intent", "discovery", "evidence", "example"],
13
- body: `## Included assets
2
+ import{registerDocBlocks as m}from"@contractspec/lib.contracts-spec/docs";var f=[{id:"docs.examples.product-intent",title:"Product Intent Discovery",summary:"Evidence-ingestion example for turning product signals into prompt-ready discovery outputs.",kind:"reference",visibility:"public",route:"/docs/examples/product-intent",tags:["product-intent","discovery","evidence","example"],body:`## Included assets
14
3
  - Product-intent feature and example manifest.
15
4
  - Evidence loading helpers and PostHog signal ingestion.
16
5
  - Sync actions and script entrypoints for discovery workflows.
17
6
 
18
7
  ## Use case
19
- Use this example when you need a lightweight pattern for evidence-backed product discovery before it becomes a larger workflow or template.`
20
- },
21
- {
22
- id: "docs.examples.product-intent.usage",
23
- title: "Product Intent Usage",
24
- summary: "How to use the product-intent example for evidence ingestion.",
25
- kind: "usage",
26
- visibility: "public",
27
- route: "/docs/examples/product-intent/usage",
28
- tags: ["product-intent", "usage"],
29
- body: `## Usage
8
+ Use this example when you need a lightweight pattern for evidence-backed product discovery before it becomes a larger workflow or template.`},{id:"docs.examples.product-intent.usage",title:"Product Intent Usage",summary:"How to use the product-intent example for evidence ingestion.",kind:"usage",visibility:"public",route:"/docs/examples/product-intent/usage",tags:["product-intent","usage"],body:`## Usage
30
9
  1. Load evidence sources with the helpers in this package.
31
10
  2. Transform product signals into the product-intent workflow inputs.
32
- 3. Export the resulting discovery outputs into the next planning step or agent prompt.`
33
- }
34
- ];
35
- registerDocBlocks(blocks);
11
+ 3. Export the resulting discovery outputs into the next planning step or agent prompt.`}];m(f);
@@ -1,35 +1,11 @@
1
1
  // @bun
2
- // src/docs/product-intent.docblock.ts
3
- import { registerDocBlocks } from "@contractspec/lib.contracts-spec/docs";
4
- var blocks = [
5
- {
6
- id: "docs.examples.product-intent",
7
- title: "Product Intent Discovery",
8
- summary: "Evidence-ingestion example for turning product signals into prompt-ready discovery outputs.",
9
- kind: "reference",
10
- visibility: "public",
11
- route: "/docs/examples/product-intent",
12
- tags: ["product-intent", "discovery", "evidence", "example"],
13
- body: `## Included assets
2
+ import{registerDocBlocks as f}from"@contractspec/lib.contracts-spec/docs";var h=[{id:"docs.examples.product-intent",title:"Product Intent Discovery",summary:"Evidence-ingestion example for turning product signals into prompt-ready discovery outputs.",kind:"reference",visibility:"public",route:"/docs/examples/product-intent",tags:["product-intent","discovery","evidence","example"],body:`## Included assets
14
3
  - Product-intent feature and example manifest.
15
4
  - Evidence loading helpers and PostHog signal ingestion.
16
5
  - Sync actions and script entrypoints for discovery workflows.
17
6
 
18
7
  ## Use case
19
- Use this example when you need a lightweight pattern for evidence-backed product discovery before it becomes a larger workflow or template.`
20
- },
21
- {
22
- id: "docs.examples.product-intent.usage",
23
- title: "Product Intent Usage",
24
- summary: "How to use the product-intent example for evidence ingestion.",
25
- kind: "usage",
26
- visibility: "public",
27
- route: "/docs/examples/product-intent/usage",
28
- tags: ["product-intent", "usage"],
29
- body: `## Usage
8
+ Use this example when you need a lightweight pattern for evidence-backed product discovery before it becomes a larger workflow or template.`},{id:"docs.examples.product-intent.usage",title:"Product Intent Usage",summary:"How to use the product-intent example for evidence ingestion.",kind:"usage",visibility:"public",route:"/docs/examples/product-intent/usage",tags:["product-intent","usage"],body:`## Usage
30
9
  1. Load evidence sources with the helpers in this package.
31
10
  2. Transform product signals into the product-intent workflow inputs.
32
- 3. Export the resulting discovery outputs into the next planning step or agent prompt.`
33
- }
34
- ];
35
- registerDocBlocks(blocks);
11
+ 3. Export the resulting discovery outputs into the next planning step or agent prompt.`}];f(h);
package/dist/example.js CHANGED
@@ -1,34 +1,2 @@
1
1
  // @bun
2
- // src/example.ts
3
- import { defineExample } from "@contractspec/lib.contracts-spec/examples";
4
- var example = defineExample({
5
- meta: {
6
- key: "product-intent",
7
- version: "1.0.0",
8
- title: "Product Intent Discovery",
9
- description: "Evidence ingestion and product-intent workflow for PM discovery.",
10
- kind: "script",
11
- visibility: "public",
12
- stability: "experimental",
13
- owners: ["@platform.core"],
14
- tags: ["product-intent", "discovery", "pm", "evidence", "llm"]
15
- },
16
- docs: {
17
- rootDocId: "docs.examples.product-intent",
18
- usageDocId: "docs.examples.product-intent.usage"
19
- },
20
- entrypoints: {
21
- packageName: "@contractspec/example.product-intent",
22
- docs: "./docs"
23
- },
24
- surfaces: {
25
- templates: false,
26
- sandbox: { enabled: false, modes: [] },
27
- studio: { enabled: false, installable: false },
28
- mcp: { enabled: false }
29
- }
30
- });
31
- var example_default = example;
32
- export {
33
- example_default as default
34
- };
2
+ import{defineExample as g}from"@contractspec/lib.contracts-spec/examples";var h=g({meta:{key:"product-intent",version:"1.0.0",title:"Product Intent Discovery",description:"Evidence ingestion and product-intent workflow for PM discovery.",kind:"script",visibility:"public",stability:"experimental",owners:["@platform.core"],tags:["product-intent","discovery","pm","evidence","llm"]},docs:{rootDocId:"docs.examples.product-intent",usageDocId:"docs.examples.product-intent.usage"},entrypoints:{packageName:"@contractspec/example.product-intent",docs:"./docs"},surfaces:{templates:!1,sandbox:{enabled:!1,modes:[]},studio:{enabled:!1,installable:!1},mcp:{enabled:!1}}}),q=h;export{q as default};
package/dist/index.js CHANGED
@@ -1,440 +1,6 @@
1
1
  // @bun
2
- // src/example.ts
3
- import { defineExample } from "@contractspec/lib.contracts-spec/examples";
4
- var example = defineExample({
5
- meta: {
6
- key: "product-intent",
7
- version: "1.0.0",
8
- title: "Product Intent Discovery",
9
- description: "Evidence ingestion and product-intent workflow for PM discovery.",
10
- kind: "script",
11
- visibility: "public",
12
- stability: "experimental",
13
- owners: ["@platform.core"],
14
- tags: ["product-intent", "discovery", "pm", "evidence", "llm"]
15
- },
16
- docs: {
17
- rootDocId: "docs.examples.product-intent",
18
- usageDocId: "docs.examples.product-intent.usage"
19
- },
20
- entrypoints: {
21
- packageName: "@contractspec/example.product-intent",
22
- docs: "./docs"
23
- },
24
- surfaces: {
25
- templates: false,
26
- sandbox: { enabled: false, modes: [] },
27
- studio: { enabled: false, installable: false },
28
- mcp: { enabled: false }
29
- }
30
- });
31
- var example_default = example;
32
-
33
- // src/posthog-signals.ts
34
- import { PosthogAnalyticsProvider } from "@contractspec/integration.providers-impls/impls/posthog";
35
- import { FunnelAnalyzer } from "@contractspec/lib.analytics/funnel";
36
- async function loadPosthogEvidenceChunks(options) {
37
- const chunks = [];
38
- const range = resolveRange(options.dateRange);
39
- const eventSummary = await loadEventSummary(options, range);
40
- if (eventSummary) {
41
- chunks.push(eventSummary);
42
- }
43
- const funnelEvidence = await loadFunnelEvidence(options, range);
44
- if (funnelEvidence) {
45
- chunks.push(funnelEvidence);
46
- }
47
- const featureFlags = await loadFeatureFlagEvidence(options);
48
- if (featureFlags) {
49
- chunks.push(featureFlags);
50
- }
51
- return chunks;
52
- }
53
- async function loadEventSummary(options, range) {
54
- if (!options.reader.queryHogQL)
55
- return null;
56
- const eventFilter = buildEventFilter(options.eventNames);
57
- const limit = options.limit ?? 10;
58
- const result = await options.reader.queryHogQL({
59
- query: [
60
- "select",
61
- " event as eventName,",
62
- " count() as total",
63
- "from events",
64
- "where timestamp >= {dateFrom} and timestamp < {dateTo}",
65
- eventFilter.clause ? `and ${eventFilter.clause}` : "",
66
- "group by eventName",
67
- "order by total desc",
68
- `limit ${limit}`
69
- ].filter(Boolean).join(`
70
- `),
71
- values: {
72
- dateFrom: range.from.toISOString(),
73
- dateTo: range.to.toISOString(),
74
- ...eventFilter.values
75
- }
76
- });
77
- const rows = mapRows(result);
78
- if (rows.length === 0)
79
- return null;
80
- const lines = rows.map((row) => {
81
- const name = asString(row.eventName) ?? "unknown";
82
- const total = asNumber(row.total);
83
- return `- ${name}: ${total}`;
84
- });
85
- return {
86
- chunkId: `posthog:event_summary:${range.from.toISOString()}`,
87
- text: [
88
- `PostHog event summary (${range.from.toISOString()} \u2192 ${range.to.toISOString()}):`,
89
- ...lines
90
- ].join(`
91
- `),
92
- meta: {
93
- source: "posthog",
94
- kind: "event_summary",
95
- dateFrom: range.from.toISOString(),
96
- dateTo: range.to.toISOString()
97
- }
98
- };
99
- }
100
- async function loadFunnelEvidence(options, range) {
101
- if (!options.funnel)
102
- return null;
103
- if (!options.reader.getEvents)
104
- return null;
105
- const events = [];
106
- const eventNames = options.funnel.steps.map((step) => step.eventName);
107
- for (const eventName of eventNames) {
108
- const response = await options.reader.getEvents({
109
- event: eventName,
110
- dateRange: {
111
- from: range.from,
112
- to: range.to
113
- },
114
- limit: options.limit ?? 500
115
- });
116
- response.results.forEach((event) => {
117
- events.push({
118
- name: event.event,
119
- userId: event.distinctId,
120
- tenantId: typeof event.properties?.tenantId === "string" ? event.properties.tenantId : undefined,
121
- timestamp: event.timestamp,
122
- properties: event.properties
123
- });
124
- });
125
- }
126
- if (events.length === 0)
127
- return null;
128
- const analyzer = new FunnelAnalyzer;
129
- const analysis = analyzer.analyze(events, options.funnel);
130
- const lines = analysis.steps.map((step) => {
131
- return `- ${step.step.eventName}: ${step.count} (conversion ${step.conversionRate}, drop-off ${step.dropOffRate})`;
132
- });
133
- return {
134
- chunkId: `posthog:funnel:${options.funnel.name}`,
135
- text: [`PostHog funnel analysis \u2014 ${options.funnel.name}:`, ...lines].join(`
136
- `),
137
- meta: {
138
- source: "posthog",
139
- kind: "funnel",
140
- funnelName: options.funnel.name,
141
- dateFrom: range.from.toISOString(),
142
- dateTo: range.to.toISOString()
143
- }
144
- };
145
- }
146
- async function loadFeatureFlagEvidence(options) {
147
- if (!options.includeFeatureFlags)
148
- return null;
149
- if (!options.reader.getFeatureFlags)
150
- return null;
151
- const response = await options.reader.getFeatureFlags({ limit: 10 });
152
- if (!response.results.length)
153
- return null;
154
- const lines = response.results.map((flag) => {
155
- const key = flag.key ?? "unknown";
156
- const active = flag.active ? "active" : "inactive";
157
- return `- ${key}: ${active}`;
158
- });
159
- return {
160
- chunkId: "posthog:feature_flags",
161
- text: ["PostHog feature flags:", ...lines].join(`
162
- `),
163
- meta: {
164
- source: "posthog",
165
- kind: "feature_flags"
166
- }
167
- };
168
- }
169
- function resolveRange(dateRange) {
170
- const now = new Date;
171
- const from = dateRange?.from instanceof Date ? dateRange.from : dateRange?.from ? new Date(dateRange.from) : new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
172
- const to = dateRange?.to instanceof Date ? dateRange.to : dateRange?.to ? new Date(dateRange.to) : now;
173
- return { from, to };
174
- }
175
- function buildEventFilter(eventNames) {
176
- if (!eventNames || eventNames.length === 0)
177
- return {};
178
- if (eventNames.length === 1) {
179
- return {
180
- clause: "event = {event0}",
181
- values: { event0: eventNames[0] }
182
- };
183
- }
184
- const values = {};
185
- const clauses = eventNames.map((eventName, index) => {
186
- values[`event${index}`] = eventName;
187
- return `event = {event${index}}`;
188
- });
189
- return {
190
- clause: `(${clauses.join(" or ")})`,
191
- values
192
- };
193
- }
194
- function mapRows(result) {
195
- if (!Array.isArray(result.results) || !Array.isArray(result.columns)) {
196
- return [];
197
- }
198
- const columns = result.columns;
199
- return result.results.flatMap((row) => {
200
- if (!Array.isArray(row))
201
- return [];
202
- const record = {};
203
- columns.forEach((column, index) => {
204
- record[column] = row[index];
205
- });
206
- return [record];
207
- });
208
- }
209
- function asString(value) {
210
- if (typeof value === "string" && value.trim())
211
- return value;
212
- if (typeof value === "number")
213
- return String(value);
214
- return null;
215
- }
216
- function asNumber(value) {
217
- if (typeof value === "number" && Number.isFinite(value))
218
- return value;
219
- if (typeof value === "string" && value.trim()) {
220
- const parsed = Number(value);
221
- if (Number.isFinite(parsed))
222
- return parsed;
223
- }
224
- return 0;
225
- }
226
- function resolvePosthogEvidenceOptionsFromEnv(options = {}) {
227
- const projectId = process.env.POSTHOG_PROJECT_ID;
228
- const personalApiKey = process.env.POSTHOG_PERSONAL_API_KEY;
229
- if (!projectId || !personalApiKey)
230
- return null;
231
- const lookbackDays = resolveNumberEnv("POSTHOG_EVIDENCE_LOOKBACK_DAYS", options.defaultLookbackDays ?? 30);
232
- const limit = resolveNumberEnv("POSTHOG_EVIDENCE_LIMIT", options.defaultLimit ?? 10);
233
- const now = new Date;
234
- const from = new Date(now.getTime() - lookbackDays * 24 * 60 * 60 * 1000);
235
- const eventNames = resolveCsvEnv("POSTHOG_EVIDENCE_EVENTS");
236
- const funnelSteps = resolveCsvEnv("POSTHOG_EVIDENCE_FUNNEL_STEPS");
237
- const funnel = funnelSteps && funnelSteps.length ? {
238
- name: "posthog-evidence-funnel",
239
- steps: funnelSteps.map((eventName, index) => ({
240
- id: `step_${index + 1}`,
241
- eventName
242
- }))
243
- } : undefined;
244
- const reader = new PosthogAnalyticsProvider({
245
- host: process.env.POSTHOG_HOST,
246
- projectId,
247
- personalApiKey
248
- });
249
- return {
250
- reader,
251
- dateRange: { from, to: now },
252
- eventNames,
253
- limit,
254
- funnel,
255
- includeFeatureFlags: resolveBooleanEnv("POSTHOG_EVIDENCE_FEATURE_FLAGS", true)
256
- };
257
- }
258
- function resolveCsvEnv(key) {
259
- const value = process.env[key];
260
- if (!value)
261
- return;
262
- return value.split(",").map((item) => item.trim()).filter(Boolean);
263
- }
264
- function resolveNumberEnv(key, fallback) {
265
- const value = process.env[key];
266
- if (!value)
267
- return fallback;
268
- const parsed = Number(value);
269
- return Number.isFinite(parsed) ? parsed : fallback;
270
- }
271
- function resolveBooleanEnv(key, fallback) {
272
- const value = process.env[key];
273
- if (value === undefined)
274
- return fallback;
275
- return value.toLowerCase() === "true";
276
- }
277
-
278
- // src/load-evidence.ts
279
- import fs from "fs";
280
- import path from "path";
281
- import { fileURLToPath } from "url";
282
- var MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
283
- var DEFAULT_EVIDENCE_ROOT = path.join(MODULE_DIR, "../evidence");
284
- var DEFAULT_TRANSCRIPT_DIRS = ["interviews", "tickets", "public"];
285
- var DEFAULT_CHUNK_SIZE = 800;
286
- function stripYamlFrontMatter(contents) {
287
- const start = contents.indexOf("---");
288
- if (start === -1)
289
- return contents;
290
- const end = contents.indexOf("---", start + 3);
291
- if (end === -1)
292
- return contents;
293
- return contents.slice(end + 3).trimStart();
294
- }
295
- function chunkTranscript(fileId, text, chunkSize) {
296
- const chunks = [];
297
- const clean = text.trim();
298
- for (let offset = 0, idx = 0;offset < clean.length; idx += 1) {
299
- const slice = clean.slice(offset, offset + chunkSize);
300
- chunks.push({
301
- chunkId: `${fileId}#c_${String(idx).padStart(2, "0")}`,
302
- text: slice,
303
- meta: { source: fileId }
304
- });
305
- offset += chunkSize;
306
- }
307
- return chunks;
308
- }
309
- function loadEvidenceChunks(options = {}) {
310
- const evidenceRoot = options.evidenceRoot ?? DEFAULT_EVIDENCE_ROOT;
311
- const transcriptDirs = options.transcriptDirs ?? DEFAULT_TRANSCRIPT_DIRS;
312
- const chunkSize = options.chunkSize ?? DEFAULT_CHUNK_SIZE;
313
- const chunks = [];
314
- for (const dir of transcriptDirs) {
315
- const fullDir = path.join(evidenceRoot, dir);
316
- if (!fs.existsSync(fullDir))
317
- continue;
318
- for (const fileName of fs.readdirSync(fullDir)) {
319
- const ext = path.extname(fileName).toLowerCase();
320
- if (ext !== ".md")
321
- continue;
322
- const filePath = path.join(fullDir, fileName);
323
- const raw = fs.readFileSync(filePath, "utf8");
324
- const withoutFrontMatter = stripYamlFrontMatter(raw);
325
- const baseId = path.parse(fileName).name;
326
- const fileChunks = chunkTranscript(baseId, withoutFrontMatter, chunkSize);
327
- chunks.push(...fileChunks);
328
- }
329
- }
330
- return chunks;
331
- }
332
- async function loadEvidenceChunksWithSignals(options = {}) {
333
- const baseChunks = loadEvidenceChunks(options);
334
- if (!options.posthog)
335
- return baseChunks;
336
- const posthogChunks = await loadPosthogEvidenceChunks(options.posthog);
337
- return [...baseChunks, ...posthogChunks];
338
- }
339
-
340
- // src/product-intent.discovery.ts
341
- import {
342
- OwnersEnum,
343
- StabilityEnum
344
- } from "@contractspec/lib.contracts-spec/ownership";
345
- import { defineProductIntentSpec } from "@contractspec/lib.contracts-spec/product-intent/spec";
346
- var ProductIntentDiscoverySpec = defineProductIntentSpec({
347
- id: "product-intent.discovery.activation",
348
- meta: {
349
- key: "product-intent.discovery.activation",
350
- version: "1.0.0",
351
- title: "Product Intent Discovery",
352
- description: "Discovery contract for activation friction using transcripts, analytics signals, and generated tasks.",
353
- domain: "product",
354
- owners: [OwnersEnum.PlatformCore],
355
- tags: ["product-intent", "discovery", "activation", "analytics"],
356
- stability: StabilityEnum.Experimental,
357
- goal: "Prioritize the next activation improvement with grounded evidence.",
358
- context: "Evidence is collected from interview transcripts, support tickets, and PostHog funnels before turning into task-ready outputs."
359
- },
360
- question: "Which activation and onboarding friction should we prioritize next?",
361
- runtimeContext: {
362
- evidenceRoot: "packages/examples/product-intent/evidence",
363
- analyticsProvider: "posthog"
364
- },
365
- tickets: {
366
- tickets: [
367
- {
368
- ticketId: "PI-101",
369
- title: "Add a guided onboarding checklist",
370
- summary: "Give new users an explicit checklist after signup so they can see the next activation milestone.",
371
- evidenceIds: ["INT-002", "INT-014", "PH-dropoff-checkout"],
372
- acceptanceCriteria: [
373
- "Users see a checklist within the first session.",
374
- "Checklist completion is tracked in analytics."
375
- ],
376
- priority: "high",
377
- tags: ["activation", "onboarding"]
378
- }
379
- ]
380
- },
381
- tasks: {
382
- packId: "product-intent.discovery.activation.tasks",
383
- patchId: "product-intent.discovery.activation.patch",
384
- overview: "Introduce a checklist-driven onboarding path and instrument it for activation measurement.",
385
- tasks: [
386
- {
387
- id: "task-ui-checklist",
388
- title: "Model the onboarding checklist surface",
389
- surface: ["ui", "docs"],
390
- why: "The product intent needs a visible activation guide and matching contract docs.",
391
- acceptance: [
392
- "A checklist surface is defined in contracts.",
393
- "Documentation explains the activation milestone mapping."
394
- ],
395
- agentPrompt: "Add the onboarding checklist contract surface and document the milestone states."
396
- },
397
- {
398
- id: "task-analytics-checklist",
399
- title: "Track checklist completion events",
400
- surface: ["api", "tests"],
401
- why: "Success must be measurable after rollout.",
402
- acceptance: [
403
- "Checklist completion emits analytics events.",
404
- "Tests cover the event contract and payload shape."
405
- ],
406
- agentPrompt: "Emit activation checklist events and add test coverage for the telemetry payloads.",
407
- dependsOn: ["task-ui-checklist"]
408
- }
409
- ]
410
- }
411
- });
412
-
413
- // src/product-intent.feature.ts
414
- import { defineFeature } from "@contractspec/lib.contracts-spec";
415
- var ProductIntentFeature = defineFeature({
416
- meta: {
417
- key: "product-intent",
418
- version: "1.0.0",
419
- title: "Product Intent",
420
- description: "Evidence ingestion, PostHog signals, and transcript-to-tickets discovery workflow",
421
- domain: "product",
422
- owners: ["@examples"],
423
- tags: ["product", "intent", "evidence", "posthog"],
424
- stability: "experimental"
425
- },
426
- telemetry: [{ key: "product-intent.telemetry", version: "1.0.0" }],
427
- docs: []
428
- });
429
- export {
430
- resolvePosthogEvidenceOptionsFromEnv,
431
- loadPosthogEvidenceChunks,
432
- loadEvidenceChunksWithSignals,
433
- loadEvidenceChunks,
434
- example_default as example,
435
- ProductIntentFeature,
436
- ProductIntentDiscoverySpec,
437
- DEFAULT_TRANSCRIPT_DIRS,
438
- DEFAULT_EVIDENCE_ROOT,
439
- DEFAULT_CHUNK_SIZE
440
- };
2
+ import{defineExample as C}from"@contractspec/lib.contracts-spec/examples";var x=C({meta:{key:"product-intent",version:"1.0.0",title:"Product Intent Discovery",description:"Evidence ingestion and product-intent workflow for PM discovery.",kind:"script",visibility:"public",stability:"experimental",owners:["@platform.core"],tags:["product-intent","discovery","pm","evidence","llm"]},docs:{rootDocId:"docs.examples.product-intent",usageDocId:"docs.examples.product-intent.usage"},entrypoints:{packageName:"@contractspec/example.product-intent",docs:"./docs"},surfaces:{templates:!1,sandbox:{enabled:!1,modes:[]},studio:{enabled:!1,installable:!1},mcp:{enabled:!1}}}),D=x;import{PosthogAnalyticsProvider as I}from"@contractspec/integration.providers-impls/impls/posthog";import{FunnelAnalyzer as E}from"@contractspec/lib.analytics/funnel";async function Y(O){let W=[],q=w(O.dateRange),G=await F(O,q);if(G)W.push(G);let H=await S(O,q);if(H)W.push(H);let J=await y(O);if(J)W.push(J);return W}async function F(O,W){if(!O.reader.queryHogQL)return null;let q=b(O.eventNames),G=O.limit??10,H=await O.reader.queryHogQL({query:["select"," event as eventName,"," count() as total","from events","where timestamp >= {dateFrom} and timestamp < {dateTo}",q.clause?`and ${q.clause}`:"","group by eventName","order by total desc",`limit ${G}`].filter(Boolean).join(`
3
+ `),values:{dateFrom:W.from.toISOString(),dateTo:W.to.toISOString(),...q.values}}),J=R(H);if(J.length===0)return null;let V=J.map((Q)=>{let Z=N(Q.eventName)??"unknown",X=h(Q.total);return`- ${Z}: ${X}`});return{chunkId:`posthog:event_summary:${W.from.toISOString()}`,text:[`PostHog event summary (${W.from.toISOString()} \u2192 ${W.to.toISOString()}):`,...V].join(`
4
+ `),meta:{source:"posthog",kind:"event_summary",dateFrom:W.from.toISOString(),dateTo:W.to.toISOString()}}}async function S(O,W){if(!O.funnel)return null;if(!O.reader.getEvents)return null;let q=[],G=O.funnel.steps.map((Q)=>Q.eventName);for(let Q of G)(await O.reader.getEvents({event:Q,dateRange:{from:W.from,to:W.to},limit:O.limit??500})).results.forEach((X)=>{q.push({name:X.event,userId:X.distinctId,tenantId:typeof X.properties?.tenantId==="string"?X.properties.tenantId:void 0,timestamp:X.timestamp,properties:X.properties})});if(q.length===0)return null;let V=new E().analyze(q,O.funnel).steps.map((Q)=>{return`- ${Q.step.eventName}: ${Q.count} (conversion ${Q.conversionRate}, drop-off ${Q.dropOffRate})`});return{chunkId:`posthog:funnel:${O.funnel.name}`,text:[`PostHog funnel analysis \u2014 ${O.funnel.name}:`,...V].join(`
5
+ `),meta:{source:"posthog",kind:"funnel",funnelName:O.funnel.name,dateFrom:W.from.toISOString(),dateTo:W.to.toISOString()}}}async function y(O){if(!O.includeFeatureFlags)return null;if(!O.reader.getFeatureFlags)return null;let W=await O.reader.getFeatureFlags({limit:10});if(!W.results.length)return null;return{chunkId:"posthog:feature_flags",text:["PostHog feature flags:",...W.results.map((G)=>{let H=G.key??"unknown",J=G.active?"active":"inactive";return`- ${H}: ${J}`})].join(`
6
+ `),meta:{source:"posthog",kind:"feature_flags"}}}function w(O){let W=new Date,q=O?.from instanceof Date?O.from:O?.from?new Date(O.from):new Date(W.getTime()-2592000000),G=O?.to instanceof Date?O.to:O?.to?new Date(O.to):W;return{from:q,to:G}}function b(O){if(!O||O.length===0)return{};if(O.length===1)return{clause:"event = {event0}",values:{event0:O[0]}};let W={};return{clause:`(${O.map((G,H)=>{return W[`event${H}`]=G,`event = {event${H}}`}).join(" or ")})`,values:W}}function R(O){if(!Array.isArray(O.results)||!Array.isArray(O.columns))return[];let W=O.columns;return O.results.flatMap((q)=>{if(!Array.isArray(q))return[];let G={};return W.forEach((H,J)=>{G[H]=q[J]}),[G]})}function N(O){if(typeof O==="string"&&O.trim())return O;if(typeof O==="number")return String(O);return null}function h(O){if(typeof O==="number"&&Number.isFinite(O))return O;if(typeof O==="string"&&O.trim()){let W=Number(O);if(Number.isFinite(W))return W}return 0}function k(O={}){let W=process.env.POSTHOG_PROJECT_ID,q=process.env.POSTHOG_PERSONAL_API_KEY;if(!W||!q)return null;let G=U("POSTHOG_EVIDENCE_LOOKBACK_DAYS",O.defaultLookbackDays??30),H=U("POSTHOG_EVIDENCE_LIMIT",O.defaultLimit??10),J=new Date,V=new Date(J.getTime()-G*24*60*60*1000),Q=T("POSTHOG_EVIDENCE_EVENTS"),Z=T("POSTHOG_EVIDENCE_FUNNEL_STEPS"),X=Z&&Z.length?{name:"posthog-evidence-funnel",steps:Z.map((B,L)=>({id:`step_${L+1}`,eventName:B}))}:void 0;return{reader:new I({host:process.env.POSTHOG_HOST,projectId:W,personalApiKey:q}),dateRange:{from:V,to:J},eventNames:Q,limit:H,funnel:X,includeFeatureFlags:m("POSTHOG_EVIDENCE_FEATURE_FLAGS",!0)}}function T(O){let W=process.env[O];if(!W)return;return W.split(",").map((q)=>q.trim()).filter(Boolean)}function U(O,W){let q=process.env[O];if(!q)return W;let G=Number(q);return Number.isFinite(G)?G:W}function m(O,W){let q=process.env[O];if(q===void 0)return W;return q.toLowerCase()==="true"}import _ from"fs";import $ from"path";import{fileURLToPath as f}from"url";var g=$.dirname(f(import.meta.url)),j=$.join(g,"../evidence"),M=["interviews","tickets","public"],P=800;function d(O){let W=O.indexOf("---");if(W===-1)return O;let q=O.indexOf("---",W+3);if(q===-1)return O;return O.slice(q+3).trimStart()}function c(O,W,q){let G=[],H=W.trim();for(let J=0,V=0;J<H.length;V+=1){let Q=H.slice(J,J+q);G.push({chunkId:`${O}#c_${String(V).padStart(2,"0")}`,text:Q,meta:{source:O}}),J+=q}return G}function A(O={}){let W=O.evidenceRoot??j,q=O.transcriptDirs??M,G=O.chunkSize??P,H=[];for(let J of q){let V=$.join(W,J);if(!_.existsSync(V))continue;for(let Q of _.readdirSync(V)){if($.extname(Q).toLowerCase()!==".md")continue;let X=$.join(V,Q),K=_.readFileSync(X,"utf8"),B=d(K),L=$.parse(Q).name,z=c(L,B,G);H.push(...z)}}return H}async function v(O={}){let W=A(O);if(!O.posthog)return W;let q=await Y(O.posthog);return[...W,...q]}import{OwnersEnum as u,StabilityEnum as p}from"@contractspec/lib.contracts-spec/ownership";import{defineProductIntentSpec as r}from"@contractspec/lib.contracts-spec/product-intent/spec";var JO=r({id:"product-intent.discovery.activation",meta:{key:"product-intent.discovery.activation",version:"1.0.0",title:"Product Intent Discovery",description:"Discovery contract for activation friction using transcripts, analytics signals, and generated tasks.",domain:"product",owners:[u.PlatformCore],tags:["product-intent","discovery","activation","analytics"],stability:p.Experimental,goal:"Prioritize the next activation improvement with grounded evidence.",context:"Evidence is collected from interview transcripts, support tickets, and PostHog funnels before turning into task-ready outputs."},question:"Which activation and onboarding friction should we prioritize next?",runtimeContext:{evidenceRoot:"packages/examples/product-intent/evidence",analyticsProvider:"posthog"},tickets:{tickets:[{ticketId:"PI-101",title:"Add a guided onboarding checklist",summary:"Give new users an explicit checklist after signup so they can see the next activation milestone.",evidenceIds:["INT-002","INT-014","PH-dropoff-checkout"],acceptanceCriteria:["Users see a checklist within the first session.","Checklist completion is tracked in analytics."],priority:"high",tags:["activation","onboarding"]}]},tasks:{packId:"product-intent.discovery.activation.tasks",patchId:"product-intent.discovery.activation.patch",overview:"Introduce a checklist-driven onboarding path and instrument it for activation measurement.",tasks:[{id:"task-ui-checklist",title:"Model the onboarding checklist surface",surface:["ui","docs"],why:"The product intent needs a visible activation guide and matching contract docs.",acceptance:["A checklist surface is defined in contracts.","Documentation explains the activation milestone mapping."],agentPrompt:"Add the onboarding checklist contract surface and document the milestone states."},{id:"task-analytics-checklist",title:"Track checklist completion events",surface:["api","tests"],why:"Success must be measurable after rollout.",acceptance:["Checklist completion emits analytics events.","Tests cover the event contract and payload shape."],agentPrompt:"Emit activation checklist events and add test coverage for the telemetry payloads.",dependsOn:["task-ui-checklist"]}]}});import{defineFeature as i}from"@contractspec/lib.contracts-spec";var XO=i({meta:{key:"product-intent",version:"1.0.0",title:"Product Intent",description:"Evidence ingestion, PostHog signals, and transcript-to-tickets discovery workflow",domain:"product",owners:["@examples"],tags:["product","intent","evidence","posthog"],stability:"experimental"},telemetry:[{key:"product-intent.telemetry",version:"1.0.0"}],docs:[]});export{k as resolvePosthogEvidenceOptionsFromEnv,Y as loadPosthogEvidenceChunks,v as loadEvidenceChunksWithSignals,A as loadEvidenceChunks,D as example,XO as ProductIntentFeature,JO as ProductIntentDiscoverySpec,M as DEFAULT_TRANSCRIPT_DIRS,j as DEFAULT_EVIDENCE_ROOT,P as DEFAULT_CHUNK_SIZE};