@contractspec/example.product-intent 0.0.0-canary-20260206014742

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.
Files changed (45) hide show
  1. package/.turbo/turbo-build$colon$bundle.log +91 -0
  2. package/.turbo/turbo-build.log +92 -0
  3. package/CHANGELOG.md +19 -0
  4. package/LICENSE +21 -0
  5. package/README.md +58 -0
  6. package/dist/example.d.ts +7 -0
  7. package/dist/example.d.ts.map +1 -0
  8. package/dist/example.js +39 -0
  9. package/dist/example.js.map +1 -0
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.js +4 -0
  12. package/dist/load-evidence.d.ts +19 -0
  13. package/dist/load-evidence.d.ts.map +1 -0
  14. package/dist/load-evidence.js +68 -0
  15. package/dist/load-evidence.js.map +1 -0
  16. package/dist/script.d.ts +1 -0
  17. package/dist/script.js +171 -0
  18. package/dist/script.js.map +1 -0
  19. package/dist/sync-actions.d.ts +1 -0
  20. package/dist/sync-actions.js +153 -0
  21. package/dist/sync-actions.js.map +1 -0
  22. package/evidence/EXPECTED_OUTCOMES.md +0 -0
  23. package/evidence/README.md +24 -0
  24. package/evidence/analytics/events.csv +0 -0
  25. package/evidence/analytics/funnel_summary.csv +0 -0
  26. package/evidence/interviews/INT-001-admin-smb.md +0 -0
  27. package/evidence/interviews/INT-002-pm-midmarket.md +52 -0
  28. package/evidence/interviews/INT-003-security-enterprise.md +0 -0
  29. package/evidence/interviews/INT-004-enduser.md +0 -0
  30. package/evidence/interviews/INT-005-support.md +48 -0
  31. package/evidence/interviews/INT-006-sales.md +0 -0
  32. package/evidence/interviews/INT-007-engineer.md +0 -0
  33. package/evidence/interviews/INT-008-founder.md +46 -0
  34. package/evidence/public/PUB-001-thread-summary.md +0 -0
  35. package/evidence/tickets/TICKETS-001-dump.md +0 -0
  36. package/package.json +65 -0
  37. package/src/example.ts +27 -0
  38. package/src/index.ts +8 -0
  39. package/src/load-evidence.test.ts +16 -0
  40. package/src/load-evidence.ts +79 -0
  41. package/src/script.ts +255 -0
  42. package/src/sync-actions.ts +227 -0
  43. package/tsconfig.json +9 -0
  44. package/tsconfig.tsbuildinfo +1 -0
  45. package/tsdown.config.js +17 -0
@@ -0,0 +1,91 @@
1
+ $ tsdown
2
+ ℹ tsdown v0.20.3 powered by rolldown v1.0.0-rc.3
3
+ ℹ config file: /home/runner/work/contractspec/contractspec/packages/examples/product-intent/tsdown.config.js
4
+ ℹ entry: src/example.ts, src/index.ts, src/load-evidence.ts, src/script.ts, src/sync-actions.ts
5
+ ℹ target: esnext
6
+ ℹ tsconfig: tsconfig.json
7
+ ℹ Build start
8
+ ℹ Cleaning 16 files
9
+ ℹ dist/script.js  6.38 kB │ gzip: 2.23 kB
10
+ ℹ dist/sync-actions.js  5.71 kB │ gzip: 2.02 kB
11
+ ℹ dist/load-evidence.js  2.31 kB │ gzip: 1.02 kB
12
+ ℹ dist/example.js  0.81 kB │ gzip: 0.44 kB
13
+ ℹ dist/index.js  0.27 kB │ gzip: 0.15 kB
14
+ ℹ dist/script.js.map 11.38 kB │ gzip: 3.65 kB
15
+ ℹ dist/sync-actions.js.map 10.31 kB │ gzip: 3.30 kB
16
+ ℹ dist/load-evidence.js.map  4.01 kB │ gzip: 1.65 kB
17
+ ℹ dist/example.js.map  1.22 kB │ gzip: 0.63 kB
18
+ ℹ dist/load-evidence.d.ts.map  0.25 kB │ gzip: 0.18 kB
19
+ ℹ dist/example.d.ts.map  0.13 kB │ gzip: 0.13 kB
20
+ ℹ dist/load-evidence.d.ts  0.75 kB │ gzip: 0.41 kB
21
+ ℹ dist/index.d.ts  0.32 kB │ gzip: 0.17 kB
22
+ ℹ dist/example.d.ts  0.25 kB │ gzip: 0.17 kB
23
+ ℹ dist/script.d.ts  0.01 kB │ gzip: 0.03 kB
24
+ ℹ dist/sync-actions.d.ts  0.01 kB │ gzip: 0.03 kB
25
+ ℹ 16 files, total: 44.11 kB
26
+ src/load-evidence.ts (1:15) [UNRESOLVED_IMPORT] Warning: Could not resolve 'node:fs' in src/load-evidence.ts
27
+ ╭─[ src/load-evidence.ts:1:16 ]
28
+ │
29
+ 1 │ import fs from 'node:fs';
30
+  │ ────┬────
31
+  │ ╰────── Module not found, treating it as an external dependency
32
+  │
33
+  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
34
+ ───╯
35
+
36
+ src/load-evidence.ts (2:17) [UNRESOLVED_IMPORT] Warning: Could not resolve 'node:path' in src/load-evidence.ts
37
+ ╭─[ src/load-evidence.ts:2:18 ]
38
+ │
39
+ 2 │ import path from 'node:path';
40
+  │ ─────┬─────
41
+  │ ╰─────── Module not found, treating it as an external dependency
42
+  │
43
+  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
44
+ ───╯
45
+
46
+ src/load-evidence.ts (3:30) [UNRESOLVED_IMPORT] Warning: Could not resolve 'node:url' in src/load-evidence.ts
47
+ ╭─[ src/load-evidence.ts:3:31 ]
48
+ │
49
+ 3 │ import { fileURLToPath } from 'node:url';
50
+  │ ─────┬────
51
+  │ ╰────── Module not found, treating it as an external dependency
52
+  │
53
+  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
54
+ ───╯
55
+
56
+ src/script.ts (1:15) [UNRESOLVED_IMPORT] Warning: Could not resolve 'node:fs' in src/script.ts
57
+ ╭─[ src/script.ts:1:16 ]
58
+ │
59
+ 1 │ import fs from 'node:fs';
60
+  │ ────┬────
61
+  │ ╰────── Module not found, treating it as an external dependency
62
+  │
63
+  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
64
+ ───╯
65
+
66
+ src/script.ts (2:17) [UNRESOLVED_IMPORT] Warning: Could not resolve 'node:path' in src/script.ts
67
+ ╭─[ src/script.ts:2:18 ]
68
+ │
69
+ 2 │ import path from 'node:path';
70
+  │ ─────┬─────
71
+  │ ╰─────── Module not found, treating it as an external dependency
72
+  │
73
+  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
74
+ ───╯
75
+
76
+ ✔ Build complete in 12262ms
77
+ src/script.ts (3:30) [UNRESOLVED_IMPORT] Warning: Could not resolve 'node:url' in src/script.ts
78
+ ╭─[ src/script.ts:3:31 ]
79
+ │
80
+ 3 │ import { fileURLToPath } from 'node:url';
81
+  │ ─────┬────
82
+  │ ╰────── Module not found, treating it as an external dependency
83
+  │
84
+  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
85
+ ───╯
86
+
87
+ [PLUGIN_TIMINGS] Warning: Your build spent significant time in plugins. Here is a breakdown:
88
+ - tsdown:external (82%)
89
+ - rolldown-plugin-dts:generate (18%)
90
+ See https://rolldown.rs/options/checks#plugintimings for more details.
91
+
@@ -0,0 +1,92 @@
1
+ $ bun build:types && bun build:bundle
2
+ $ tsc --noEmit
3
+ $ tsdown
4
+ ℹ tsdown v0.20.3 powered by rolldown v1.0.0-rc.3
5
+ ℹ config file: /home/runner/work/contractspec/contractspec/packages/examples/product-intent/tsdown.config.js
6
+ ℹ entry: src/example.ts, src/index.ts, src/load-evidence.ts, src/script.ts, src/sync-actions.ts
7
+ ℹ target: esnext
8
+ ℹ tsconfig: tsconfig.json
9
+ ℹ Build start
10
+ ℹ dist/script.js  6.38 kB │ gzip: 2.23 kB
11
+ ℹ dist/sync-actions.js  5.71 kB │ gzip: 2.02 kB
12
+ ℹ dist/load-evidence.js  2.31 kB │ gzip: 1.02 kB
13
+ ℹ dist/example.js  0.81 kB │ gzip: 0.44 kB
14
+ ℹ dist/index.js  0.27 kB │ gzip: 0.15 kB
15
+ ℹ dist/script.js.map 11.38 kB │ gzip: 3.65 kB
16
+ ℹ dist/sync-actions.js.map 10.31 kB │ gzip: 3.30 kB
17
+ ℹ dist/load-evidence.js.map  4.01 kB │ gzip: 1.65 kB
18
+ ℹ dist/example.js.map  1.22 kB │ gzip: 0.63 kB
19
+ ℹ dist/load-evidence.d.ts.map  0.25 kB │ gzip: 0.18 kB
20
+ ℹ dist/example.d.ts.map  0.13 kB │ gzip: 0.13 kB
21
+ ℹ dist/load-evidence.d.ts  0.75 kB │ gzip: 0.41 kB
22
+ ℹ dist/index.d.ts  0.32 kB │ gzip: 0.17 kB
23
+ ℹ dist/example.d.ts  0.25 kB │ gzip: 0.17 kB
24
+ ℹ dist/script.d.ts  0.01 kB │ gzip: 0.03 kB
25
+ ℹ dist/sync-actions.d.ts  0.01 kB │ gzip: 0.03 kB
26
+ ℹ 16 files, total: 44.11 kB
27
+ src/load-evidence.ts (1:15) [UNRESOLVED_IMPORT] Warning: Could not resolve 'node:fs' in src/load-evidence.ts
28
+ ╭─[ src/load-evidence.ts:1:16 ]
29
+ │
30
+ 1 │ import fs from 'node:fs';
31
+  │ ────┬────
32
+  │ ╰────── Module not found, treating it as an external dependency
33
+  │
34
+  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
35
+ ───╯
36
+
37
+ src/load-evidence.ts (2:17) [UNRESOLVED_IMPORT] Warning: Could not resolve 'node:path' in src/load-evidence.ts
38
+ ╭─[ src/load-evidence.ts:2:18 ]
39
+ │
40
+ 2 │ import path from 'node:path';
41
+  │ ─────┬─────
42
+  │ ╰─────── Module not found, treating it as an external dependency
43
+  │
44
+  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
45
+ ───╯
46
+
47
+ src/load-evidence.ts (3:30) [UNRESOLVED_IMPORT] Warning: Could not resolve 'node:url' in src/load-evidence.ts
48
+ ╭─[ src/load-evidence.ts:3:31 ]
49
+ │
50
+ 3 │ import { fileURLToPath } from 'node:url';
51
+  │ ─────┬────
52
+  │ ╰────── Module not found, treating it as an external dependency
53
+  │
54
+  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
55
+ ───╯
56
+
57
+ src/script.ts (1:15) [UNRESOLVED_IMPORT] Warning: Could not resolve 'node:fs' in src/script.ts
58
+ ╭─[ src/script.ts:1:16 ]
59
+ │
60
+ 1 │ import fs from 'node:fs';
61
+  │ ────┬────
62
+  │ ╰────── Module not found, treating it as an external dependency
63
+  │
64
+  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
65
+ ───╯
66
+
67
+ src/script.ts (2:17) [UNRESOLVED_IMPORT] Warning: Could not resolve 'node:path' in src/script.ts
68
+ ╭─[ src/script.ts:2:18 ]
69
+ │
70
+ 2 │ import path from 'node:path';
71
+  │ ─────┬─────
72
+  │ ╰─────── Module not found, treating it as an external dependency
73
+  │
74
+  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
75
+ ───╯
76
+
77
+ src/script.ts (3:30) [UNRESOLVED_IMPORT] Warning: Could not resolve 'node:url' in src/script.ts
78
+ ╭─[ src/script.ts:3:31 ]
79
+ │
80
+ 3 │ import { fileURLToPath } from 'node:url';
81
+  │ ─────┬────
82
+  │ ╰────── Module not found, treating it as an external dependency
83
+  │
84
+  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
85
+ ───╯
86
+
87
+ [PLUGIN_TIMINGS] Warning: Your build spent significant time in plugins. Here is a breakdown:
88
+ - rolldown-plugin-dts:generate (55%)
89
+ - tsdown:external (45%)
90
+ See https://rolldown.rs/options/checks#plugintimings for more details.
91
+
92
+ ✔ Build complete in 9777ms
package/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # @contractspec/example.product-intent
2
+
3
+ ## 0.0.0-canary-20260206014742
4
+
5
+ ### Minor Changes
6
+
7
+ - a119963: Add project-management integrations (Linear, Jira, Notion), sync helpers for product intent outputs, and expose the new integration category across workspace tooling.
8
+ - 11a5a05: feat: improve product intent
9
+
10
+ ### Patch Changes
11
+
12
+ - 47c48c2: Refine product-intent contracts, add core/module orchestration and bundle wiring, and expand tests/examples.
13
+ - Updated dependencies [47c48c2]
14
+ - Updated dependencies [a119963]
15
+ - Updated dependencies [11a5a05]
16
+ - @contractspec/lib.contracts@0.0.0-canary-20260206014742
17
+ - @contractspec/lib.product-intent-utils@0.0.0-canary-20260206014742
18
+ - @contractspec/integration.providers-impls@0.0.0-canary-20260206014742
19
+ - @contractspec/lib.ai-agent@0.0.0-canary-20260206014742
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Chaman Ventures, SASU
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Product Intent Example
2
+
3
+ Website: https://contractspec.io/
4
+
5
+ Minimal example showing a transcript-to-tickets workflow with evidence-backed citations and a deterministic impact report.
6
+
7
+ ## What it demonstrates
8
+
9
+ - Loading interview, ticket, and public thread transcripts from `evidence/`.
10
+ - Chunking transcripts into evidence chunks with stable ids.
11
+ - Extracting evidence findings with exact-quote citations.
12
+ - Grouping problems linked to evidence finding IDs.
13
+ - Generating tickets with evidence links + acceptance criteria.
14
+ - Producing a deterministic impact report from the patch intent.
15
+
16
+ ## Running the script
17
+
18
+ From the repository root:
19
+
20
+ ```bash
21
+ bun install
22
+ export CONTRACTSPEC_AI_PROVIDER="mistral" # or openai/anthropic/gemini/ollama
23
+ export MISTRAL_API_KEY="your_key" # if using mistral
24
+ # export OPENAI_API_KEY="your_key" # if using openai
25
+ # export CONTRACTSPEC_AI_MODEL="model-id" # optional override
26
+ # export CONTRACTSPEC_AI_TEMPERATURE="0" # default is 0 for determinism
27
+ # export CONTRACTSPEC_AI_MAX_ATTEMPTS="2" # retry invalid JSON
28
+ bun tsx packages/examples/product-intent/src/script.ts
29
+ ```
30
+
31
+ You should see evidence findings, problems, tickets, a patch intent generated by the AI provider, and a deterministic impact report.
32
+ If validation fails, inspect the JSONL trace log and artifacts in `packages/examples/product-intent/logs/run-*/`.
33
+
34
+ ## Sync actions to project management tools
35
+
36
+ This example can convert tickets into shareable work items and sync them to Linear, Jira Cloud, or Notion:
37
+
38
+ ```bash
39
+ export CONTRACTSPEC_PM_PROVIDER="linear" # or jira/notion
40
+ export CONTRACTSPEC_PM_DRY_RUN="true" # set to false to create real items
41
+ export LINEAR_API_KEY="your_key"
42
+ export LINEAR_TEAM_ID="team_id"
43
+ export LINEAR_PROJECT_ID="project_id" # optional
44
+ export LINEAR_LABEL_IDS="label1,label2" # optional
45
+
46
+ # Jira Cloud
47
+ # export JIRA_SITE_URL="https://acme.atlassian.net"
48
+ # export JIRA_EMAIL="user@acme.com"
49
+ # export JIRA_API_TOKEN="jira_token"
50
+ # export JIRA_PROJECT_KEY="PM"
51
+
52
+ # Notion
53
+ # export NOTION_API_KEY="secret"
54
+ # export NOTION_DATABASE_ID="database_id"
55
+ # export NOTION_SUMMARY_PARENT_PAGE_ID="parent_page_id" # optional
56
+
57
+ bun tsx packages/examples/product-intent/src/sync-actions.ts
58
+ ```
@@ -0,0 +1,7 @@
1
+ import * as _contractspec_lib_contracts0 from "@contractspec/lib.contracts";
2
+
3
+ //#region src/example.d.ts
4
+ declare const example: _contractspec_lib_contracts0.ExampleSpec;
5
+ //#endregion
6
+ export { example as default };
7
+ //# sourceMappingURL=example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.d.ts","names":[],"sources":["../src/example.ts"],"mappings":";;;cAEM,OAAA,EAsBJ,4BAAA,CAtBW,WAAA"}
@@ -0,0 +1,39 @@
1
+ import { defineExample } from "@contractspec/lib.contracts";
2
+
3
+ //#region src/example.ts
4
+ const 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: [
15
+ "product-intent",
16
+ "discovery",
17
+ "pm",
18
+ "evidence",
19
+ "llm"
20
+ ]
21
+ },
22
+ entrypoints: { packageName: "@contractspec/example.product-intent" },
23
+ surfaces: {
24
+ templates: false,
25
+ sandbox: {
26
+ enabled: false,
27
+ modes: []
28
+ },
29
+ studio: {
30
+ enabled: false,
31
+ installable: false
32
+ },
33
+ mcp: { enabled: false }
34
+ }
35
+ });
36
+
37
+ //#endregion
38
+ export { example as default };
39
+ //# sourceMappingURL=example.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.js","names":[],"sources":["../src/example.ts"],"sourcesContent":["import { defineExample } from '@contractspec/lib.contracts';\n\nconst example = defineExample({\n meta: {\n key: 'product-intent',\n version: '1.0.0',\n title: 'Product Intent Discovery',\n description:\n 'Evidence ingestion and product-intent workflow for PM discovery.',\n kind: 'script',\n visibility: 'public',\n stability: 'experimental',\n owners: ['@platform.core'],\n tags: ['product-intent', 'discovery', 'pm', 'evidence', 'llm'],\n },\n entrypoints: {\n packageName: '@contractspec/example.product-intent',\n },\n surfaces: {\n templates: false,\n sandbox: { enabled: false, modes: [] },\n studio: { enabled: false, installable: false },\n mcp: { enabled: false },\n },\n});\n\nexport default example;\n"],"mappings":";;;AAEA,MAAM,UAAU,cAAc;CAC5B,MAAM;EACJ,KAAK;EACL,SAAS;EACT,OAAO;EACP,aACE;EACF,MAAM;EACN,YAAY;EACZ,WAAW;EACX,QAAQ,CAAC,iBAAiB;EAC1B,MAAM;GAAC;GAAkB;GAAa;GAAM;GAAY;GAAM;EAC/D;CACD,aAAa,EACX,aAAa,wCACd;CACD,UAAU;EACR,WAAW;EACX,SAAS;GAAE,SAAS;GAAO,OAAO,EAAE;GAAE;EACtC,QAAQ;GAAE,SAAS;GAAO,aAAa;GAAO;EAC9C,KAAK,EAAE,SAAS,OAAO;EACxB;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import example from "./example.js";
2
+ import { DEFAULT_CHUNK_SIZE, DEFAULT_EVIDENCE_ROOT, DEFAULT_TRANSCRIPT_DIRS, EvidenceLoadOptions, loadEvidenceChunks } from "./load-evidence.js";
3
+ export { DEFAULT_CHUNK_SIZE, DEFAULT_EVIDENCE_ROOT, DEFAULT_TRANSCRIPT_DIRS, type EvidenceLoadOptions, example, loadEvidenceChunks };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import example from "./example.js";
2
+ import { DEFAULT_CHUNK_SIZE, DEFAULT_EVIDENCE_ROOT, DEFAULT_TRANSCRIPT_DIRS, loadEvidenceChunks } from "./load-evidence.js";
3
+
4
+ export { DEFAULT_CHUNK_SIZE, DEFAULT_EVIDENCE_ROOT, DEFAULT_TRANSCRIPT_DIRS, example, loadEvidenceChunks };
@@ -0,0 +1,19 @@
1
+ import { EvidenceChunk } from "@contractspec/lib.contracts/product-intent/types";
2
+
3
+ //#region src/load-evidence.d.ts
4
+ declare const DEFAULT_EVIDENCE_ROOT: string;
5
+ declare const DEFAULT_TRANSCRIPT_DIRS: string[];
6
+ declare const DEFAULT_CHUNK_SIZE = 800;
7
+ interface EvidenceLoadOptions {
8
+ evidenceRoot?: string;
9
+ transcriptDirs?: string[];
10
+ chunkSize?: number;
11
+ }
12
+ /**
13
+ * Load all transcript files under the given directories and return
14
+ * EvidenceChunk objects ready for prompt formatting.
15
+ */
16
+ declare function loadEvidenceChunks(options?: EvidenceLoadOptions): EvidenceChunk[];
17
+ //#endregion
18
+ export { DEFAULT_CHUNK_SIZE, DEFAULT_EVIDENCE_ROOT, DEFAULT_TRANSCRIPT_DIRS, EvidenceLoadOptions, loadEvidenceChunks };
19
+ //# sourceMappingURL=load-evidence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-evidence.d.ts","names":[],"sources":["../src/load-evidence.ts"],"mappings":";;;cAOa,qBAAA;AAAA,cACA,uBAAA;AAAA,cACA,kBAAA;AAAA,UAEI,mBAAA;EACf,YAAA;EACA,cAAA;EACA,SAAA;AAAA;;;;;iBAyCc,kBAAA,CACd,OAAA,GAAS,mBAAA,GACR,aAAA"}
@@ -0,0 +1,68 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ //#region src/load-evidence.ts
6
+ const MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
7
+ const DEFAULT_EVIDENCE_ROOT = path.join(MODULE_DIR, "../evidence");
8
+ const DEFAULT_TRANSCRIPT_DIRS = [
9
+ "interviews",
10
+ "tickets",
11
+ "public"
12
+ ];
13
+ const DEFAULT_CHUNK_SIZE = 800;
14
+ /**
15
+ * Remove YAML front matter from a file. Synthetic interview and ticket
16
+ * files include a YAML header delimited by triple dashes.
17
+ */
18
+ function stripYamlFrontMatter(contents) {
19
+ const start = contents.indexOf("---");
20
+ if (start === -1) return contents;
21
+ const end = contents.indexOf("---", start + 3);
22
+ if (end === -1) return contents;
23
+ return contents.slice(end + 3).trimStart();
24
+ }
25
+ /**
26
+ * Split a transcript into fixed-size chunks.
27
+ */
28
+ function chunkTranscript(fileId, text, chunkSize) {
29
+ const chunks = [];
30
+ const clean = text.trim();
31
+ for (let offset = 0, idx = 0; offset < clean.length; idx += 1) {
32
+ const slice = clean.slice(offset, offset + chunkSize);
33
+ chunks.push({
34
+ chunkId: `${fileId}#c_${String(idx).padStart(2, "0")}`,
35
+ text: slice,
36
+ meta: { source: fileId }
37
+ });
38
+ offset += chunkSize;
39
+ }
40
+ return chunks;
41
+ }
42
+ /**
43
+ * Load all transcript files under the given directories and return
44
+ * EvidenceChunk objects ready for prompt formatting.
45
+ */
46
+ function loadEvidenceChunks(options = {}) {
47
+ const evidenceRoot = options.evidenceRoot ?? DEFAULT_EVIDENCE_ROOT;
48
+ const transcriptDirs = options.transcriptDirs ?? DEFAULT_TRANSCRIPT_DIRS;
49
+ const chunkSize = options.chunkSize ?? DEFAULT_CHUNK_SIZE;
50
+ const chunks = [];
51
+ for (const dir of transcriptDirs) {
52
+ const fullDir = path.join(evidenceRoot, dir);
53
+ if (!fs.existsSync(fullDir)) continue;
54
+ for (const fileName of fs.readdirSync(fullDir)) {
55
+ if (path.extname(fileName).toLowerCase() !== ".md") continue;
56
+ const filePath = path.join(fullDir, fileName);
57
+ const withoutFrontMatter = stripYamlFrontMatter(fs.readFileSync(filePath, "utf8"));
58
+ const baseId = path.parse(fileName).name;
59
+ const fileChunks = chunkTranscript(baseId, withoutFrontMatter, chunkSize);
60
+ chunks.push(...fileChunks);
61
+ }
62
+ }
63
+ return chunks;
64
+ }
65
+
66
+ //#endregion
67
+ export { DEFAULT_CHUNK_SIZE, DEFAULT_EVIDENCE_ROOT, DEFAULT_TRANSCRIPT_DIRS, loadEvidenceChunks };
68
+ //# sourceMappingURL=load-evidence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-evidence.js","names":[],"sources":["../src/load-evidence.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { EvidenceChunk } from '@contractspec/lib.contracts/product-intent/types';\n\nconst MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));\n\nexport const DEFAULT_EVIDENCE_ROOT = path.join(MODULE_DIR, '../evidence');\nexport const DEFAULT_TRANSCRIPT_DIRS = ['interviews', 'tickets', 'public'];\nexport const DEFAULT_CHUNK_SIZE = 800;\n\nexport interface EvidenceLoadOptions {\n evidenceRoot?: string;\n transcriptDirs?: string[];\n chunkSize?: number;\n}\n\n/**\n * Remove YAML front matter from a file. Synthetic interview and ticket\n * files include a YAML header delimited by triple dashes.\n */\nfunction stripYamlFrontMatter(contents: string): string {\n const start = contents.indexOf('---');\n if (start === -1) return contents;\n const end = contents.indexOf('---', start + 3);\n if (end === -1) return contents;\n return contents.slice(end + 3).trimStart();\n}\n\n/**\n * Split a transcript into fixed-size chunks.\n */\nfunction chunkTranscript(\n fileId: string,\n text: string,\n chunkSize: number\n): EvidenceChunk[] {\n const chunks: EvidenceChunk[] = [];\n const clean = text.trim();\n for (let offset = 0, idx = 0; offset < clean.length; idx += 1) {\n const slice = clean.slice(offset, offset + chunkSize);\n chunks.push({\n chunkId: `${fileId}#c_${String(idx).padStart(2, '0')}`,\n text: slice,\n meta: { source: fileId },\n });\n offset += chunkSize;\n }\n return chunks;\n}\n\n/**\n * Load all transcript files under the given directories and return\n * EvidenceChunk objects ready for prompt formatting.\n */\nexport function loadEvidenceChunks(\n options: EvidenceLoadOptions = {}\n): EvidenceChunk[] {\n const evidenceRoot = options.evidenceRoot ?? DEFAULT_EVIDENCE_ROOT;\n const transcriptDirs = options.transcriptDirs ?? DEFAULT_TRANSCRIPT_DIRS;\n const chunkSize = options.chunkSize ?? DEFAULT_CHUNK_SIZE;\n\n const chunks: EvidenceChunk[] = [];\n for (const dir of transcriptDirs) {\n const fullDir = path.join(evidenceRoot, dir);\n if (!fs.existsSync(fullDir)) continue;\n for (const fileName of fs.readdirSync(fullDir)) {\n const ext = path.extname(fileName).toLowerCase();\n if (ext !== '.md') continue;\n const filePath = path.join(fullDir, fileName);\n const raw = fs.readFileSync(filePath, 'utf8');\n const withoutFrontMatter = stripYamlFrontMatter(raw);\n const baseId = path.parse(fileName).name;\n const fileChunks = chunkTranscript(baseId, withoutFrontMatter, chunkSize);\n chunks.push(...fileChunks);\n }\n }\n return chunks;\n}\n"],"mappings":";;;;;AAKA,MAAM,aAAa,KAAK,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;AAE/D,MAAa,wBAAwB,KAAK,KAAK,YAAY,cAAc;AACzE,MAAa,0BAA0B;CAAC;CAAc;CAAW;CAAS;AAC1E,MAAa,qBAAqB;;;;;AAYlC,SAAS,qBAAqB,UAA0B;CACtD,MAAM,QAAQ,SAAS,QAAQ,MAAM;AACrC,KAAI,UAAU,GAAI,QAAO;CACzB,MAAM,MAAM,SAAS,QAAQ,OAAO,QAAQ,EAAE;AAC9C,KAAI,QAAQ,GAAI,QAAO;AACvB,QAAO,SAAS,MAAM,MAAM,EAAE,CAAC,WAAW;;;;;AAM5C,SAAS,gBACP,QACA,MACA,WACiB;CACjB,MAAM,SAA0B,EAAE;CAClC,MAAM,QAAQ,KAAK,MAAM;AACzB,MAAK,IAAI,SAAS,GAAG,MAAM,GAAG,SAAS,MAAM,QAAQ,OAAO,GAAG;EAC7D,MAAM,QAAQ,MAAM,MAAM,QAAQ,SAAS,UAAU;AACrD,SAAO,KAAK;GACV,SAAS,GAAG,OAAO,KAAK,OAAO,IAAI,CAAC,SAAS,GAAG,IAAI;GACpD,MAAM;GACN,MAAM,EAAE,QAAQ,QAAQ;GACzB,CAAC;AACF,YAAU;;AAEZ,QAAO;;;;;;AAOT,SAAgB,mBACd,UAA+B,EAAE,EAChB;CACjB,MAAM,eAAe,QAAQ,gBAAgB;CAC7C,MAAM,iBAAiB,QAAQ,kBAAkB;CACjD,MAAM,YAAY,QAAQ,aAAa;CAEvC,MAAM,SAA0B,EAAE;AAClC,MAAK,MAAM,OAAO,gBAAgB;EAChC,MAAM,UAAU,KAAK,KAAK,cAAc,IAAI;AAC5C,MAAI,CAAC,GAAG,WAAW,QAAQ,CAAE;AAC7B,OAAK,MAAM,YAAY,GAAG,YAAY,QAAQ,EAAE;AAE9C,OADY,KAAK,QAAQ,SAAS,CAAC,aAAa,KACpC,MAAO;GACnB,MAAM,WAAW,KAAK,KAAK,SAAS,SAAS;GAE7C,MAAM,qBAAqB,qBADf,GAAG,aAAa,UAAU,OAAO,CACO;GACpD,MAAM,SAAS,KAAK,MAAM,SAAS,CAAC;GACpC,MAAM,aAAa,gBAAgB,QAAQ,oBAAoB,UAAU;AACzE,UAAO,KAAK,GAAG,WAAW;;;AAG9B,QAAO"}
@@ -0,0 +1 @@
1
+ export { };
package/dist/script.js ADDED
@@ -0,0 +1,171 @@
1
+ import { loadEvidenceChunks } from "./load-evidence.js";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { createAgentJsonRunner } from "@contractspec/lib.ai-agent";
6
+ import { extractEvidence, generateTickets, groupProblems, impactEngine, suggestPatch } from "@contractspec/lib.product-intent-utils";
7
+
8
+ //#region src/script.ts
9
+ const QUESTION = "Which activation and onboarding friction should we prioritize next?";
10
+ const DEFAULT_PROVIDER = "openai";
11
+ const DEFAULT_MODEL = "gpt-5.2";
12
+ const DEFAULT_TEMPERATURE = 0;
13
+ const DEFAULT_MAX_ATTEMPTS = 2;
14
+ const MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
15
+ const REPO_ROOT = path.resolve(MODULE_DIR, "../../../..");
16
+ const REPO_SCAN_FILES = [
17
+ "packages/examples/product-intent/src/load-evidence.ts",
18
+ "packages/examples/product-intent/src/script.ts",
19
+ "packages/libs/contracts/src/product-intent/contract-patch-intent.ts",
20
+ "packages/libs/contracts/src/product-intent/spec.ts",
21
+ "packages/libs/product-intent-utils/src/impact-engine.ts"
22
+ ];
23
+ function collectRepoFiles(root, files) {
24
+ const collected = [];
25
+ for (const relativePath of files) {
26
+ const fullPath = path.join(root, relativePath);
27
+ if (!fs.existsSync(fullPath)) continue;
28
+ const content = fs.readFileSync(fullPath, "utf8");
29
+ collected.push({
30
+ path: relativePath,
31
+ content
32
+ });
33
+ }
34
+ return collected;
35
+ }
36
+ function resolveProviderName() {
37
+ const raw = process.env.CONTRACTSPEC_AI_PROVIDER ?? process.env.AI_PROVIDER ?? DEFAULT_PROVIDER;
38
+ const normalized = raw.toLowerCase();
39
+ const allowed = [
40
+ "openai",
41
+ "anthropic",
42
+ "mistral",
43
+ "gemini",
44
+ "ollama"
45
+ ];
46
+ if (!allowed.includes(normalized)) throw new Error(`Unsupported AI provider '${raw}'. Allowed: ${allowed.join(", ")}`);
47
+ return normalized;
48
+ }
49
+ function resolveApiKey(provider) {
50
+ switch (provider) {
51
+ case "openai": return process.env.OPENAI_API_KEY;
52
+ case "anthropic": return process.env.ANTHROPIC_API_KEY;
53
+ case "mistral": return process.env.MISTRAL_API_KEY;
54
+ case "gemini": return process.env.GOOGLE_API_KEY ?? process.env.GEMINI_API_KEY;
55
+ case "ollama": return;
56
+ }
57
+ }
58
+ function resolveTemperature() {
59
+ const raw = process.env.CONTRACTSPEC_AI_TEMPERATURE ?? process.env.AI_TEMPERATURE;
60
+ if (!raw) return DEFAULT_TEMPERATURE;
61
+ const value = Number.parseFloat(raw);
62
+ return Number.isNaN(value) ? DEFAULT_TEMPERATURE : value;
63
+ }
64
+ function resolveMaxAttempts() {
65
+ const raw = process.env.CONTRACTSPEC_AI_MAX_ATTEMPTS ?? process.env.AI_MAX_ATTEMPTS;
66
+ if (!raw) return DEFAULT_MAX_ATTEMPTS;
67
+ const value = Number.parseInt(raw, 10);
68
+ return Number.isNaN(value) ? DEFAULT_MAX_ATTEMPTS : Math.max(1, value);
69
+ }
70
+ function writeArtifact(dir, name, contents) {
71
+ const filePath = path.join(dir, name);
72
+ fs.writeFileSync(filePath, contents, "utf8");
73
+ return filePath;
74
+ }
75
+ function createPipelineLogger(logDir, runId) {
76
+ const tracePath = path.join(logDir, "trace.jsonl");
77
+ return { log(entry) {
78
+ const baseName = `${entry.stage}-attempt-${entry.attempt}-${entry.phase}`;
79
+ const payload = {
80
+ runId,
81
+ stage: entry.stage,
82
+ phase: entry.phase,
83
+ attempt: entry.attempt,
84
+ timestamp: entry.timestamp
85
+ };
86
+ if (entry.prompt) payload.promptPath = path.relative(REPO_ROOT, writeArtifact(logDir, `${baseName}.prompt.txt`, entry.prompt));
87
+ if (entry.response) payload.responsePath = path.relative(REPO_ROOT, writeArtifact(logDir, `${baseName}.response.txt`, entry.response));
88
+ if (entry.error) payload.errorPath = path.relative(REPO_ROOT, writeArtifact(logDir, `${baseName}.error.txt`, entry.error));
89
+ fs.appendFileSync(tracePath, `${JSON.stringify(payload)}\n`, "utf8");
90
+ } };
91
+ }
92
+ async function main() {
93
+ const provider = resolveProviderName();
94
+ const temperature = resolveTemperature();
95
+ const maxAttempts = resolveMaxAttempts();
96
+ const apiKey = resolveApiKey(provider);
97
+ const proxyUrl = process.env.CONTRACTSPEC_AI_PROXY_URL;
98
+ const organizationId = process.env.CONTRACTSPEC_ORG_ID;
99
+ const baseUrl = process.env.OLLAMA_BASE_URL;
100
+ const model = process.env.CONTRACTSPEC_AI_MODEL ?? process.env.AI_MODEL ?? (provider === "mistral" ? DEFAULT_MODEL : void 0);
101
+ if (provider !== "ollama" && !apiKey && !proxyUrl && !organizationId) throw new Error(`Missing API credentials for ${provider}. Set the provider API key or CONTRACTSPEC_AI_PROXY_URL.`);
102
+ const runId = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
103
+ const logDir = path.join(MODULE_DIR, "../logs", `run-${runId}`);
104
+ fs.mkdirSync(logDir, { recursive: true });
105
+ const logger = createPipelineLogger(logDir, runId);
106
+ const modelRunner = await createAgentJsonRunner({
107
+ provider: {
108
+ provider,
109
+ model,
110
+ apiKey,
111
+ baseUrl,
112
+ proxyUrl,
113
+ organizationId
114
+ },
115
+ temperature,
116
+ system: "You are a product discovery analyst. Respond with strict JSON only and use exact quotes for citations."
117
+ });
118
+ console.log(`AI provider: ${provider}`);
119
+ console.log(`Model: ${model ?? "(provider default)"}`);
120
+ console.log(`Temperature: ${temperature}`);
121
+ console.log(`Max attempts: ${maxAttempts}`);
122
+ console.log(`Trace log: ${path.relative(REPO_ROOT, logDir)}/trace.jsonl`);
123
+ const evidenceChunks = loadEvidenceChunks();
124
+ console.log(`Loaded ${evidenceChunks.length} evidence chunks`);
125
+ const findings = await extractEvidence(evidenceChunks, QUESTION, {
126
+ maxFindings: 12,
127
+ modelRunner,
128
+ logger,
129
+ maxAttempts
130
+ });
131
+ console.log("\nEvidence findings:\n");
132
+ console.log(JSON.stringify(findings, null, 2));
133
+ const problems = await groupProblems(findings, QUESTION, {
134
+ modelRunner,
135
+ logger,
136
+ maxAttempts
137
+ });
138
+ console.log("\nProblems:\n");
139
+ console.log(JSON.stringify(problems, null, 2));
140
+ const tickets = await generateTickets(problems, findings, QUESTION, {
141
+ modelRunner,
142
+ logger,
143
+ maxAttempts
144
+ });
145
+ console.log("\nTickets:\n");
146
+ console.log(JSON.stringify(tickets, null, 2));
147
+ if (!tickets[0]) {
148
+ console.log("\nNo tickets generated.");
149
+ return;
150
+ }
151
+ const patchIntent = await suggestPatch(tickets[0], {
152
+ modelRunner,
153
+ logger,
154
+ maxAttempts
155
+ });
156
+ console.log("\nPatch intent:\n");
157
+ console.log(JSON.stringify(patchIntent, null, 2));
158
+ const impact = impactEngine(patchIntent, {
159
+ repoFiles: collectRepoFiles(REPO_ROOT, REPO_SCAN_FILES),
160
+ maxHitsPerChange: 3
161
+ });
162
+ console.log("\nImpact report (deterministic):\n");
163
+ console.log(JSON.stringify(impact, null, 2));
164
+ }
165
+ main().catch((error) => {
166
+ console.error(error);
167
+ process.exitCode = 1;
168
+ });
169
+
170
+ //#endregion
171
+ //# sourceMappingURL=script.js.map