@contractspec/module.product-intent-core 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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=keyword-retriever.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyword-retriever.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/keyword-retriever.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=product-intent-orchestrator.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-intent-orchestrator.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/product-intent-orchestrator.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,156 @@
1
+ // src/evidence/keyword-retriever.ts
2
+ var normalizeTokens = (value) => value.toLowerCase().split(/[^a-z0-9]+/g).map((token) => token.trim()).filter((token) => token.length > 2);
3
+ var createKeywordEvidenceFetcher = (chunks, options = {}) => async ({
4
+ query,
5
+ maxChunks
6
+ }) => {
7
+ const tokens = normalizeTokens(query);
8
+ if (tokens.length === 0) {
9
+ return maxChunks ? chunks.slice(0, maxChunks) : [...chunks];
10
+ }
11
+ const scored = chunks.map((chunk) => {
12
+ const haystack = chunk.text.toLowerCase();
13
+ const score = tokens.reduce((total, token) => total + (haystack.includes(token) ? 1 : 0), 0);
14
+ return { chunk, score };
15
+ }).filter((item) => item.score >= (options.minScore ?? 1));
16
+ scored.sort((a, b) => {
17
+ if (b.score !== a.score)
18
+ return b.score - a.score;
19
+ return a.chunk.chunkId.localeCompare(b.chunk.chunkId);
20
+ });
21
+ const results = scored.map((item) => item.chunk);
22
+ return maxChunks ? results.slice(0, maxChunks) : results;
23
+ };
24
+ // src/orchestrator/product-intent-orchestrator.ts
25
+ import {
26
+ ContractSpecPatchModel
27
+ } from "@contractspec/lib.contracts/product-intent/types";
28
+ import { ProductIntentRegistry } from "@contractspec/lib.contracts/product-intent/registry";
29
+ import {
30
+ formatEvidenceForModel,
31
+ impactEngine,
32
+ parseStrictJSON,
33
+ promptExtractInsights,
34
+ promptGenerateGenericSpecOverlay,
35
+ promptGeneratePatchIntent,
36
+ promptGenerateTaskPack,
37
+ promptSynthesizeBrief,
38
+ validateInsightExtraction,
39
+ validateOpportunityBrief,
40
+ validatePatchIntent,
41
+ validateTaskPack
42
+ } from "@contractspec/lib.product-intent-utils";
43
+
44
+ class ProductIntentOrchestrator {
45
+ options;
46
+ registry;
47
+ constructor(options, registry) {
48
+ this.options = options;
49
+ this.registry = registry ?? new ProductIntentRegistry;
50
+ }
51
+ getRegistry() {
52
+ return this.registry;
53
+ }
54
+ async runDiscovery(params) {
55
+ const { id, meta, question, context } = params;
56
+ const maxEvidenceChunks = params.maxEvidenceChunks ?? this.options.maxEvidenceChunks ?? 20;
57
+ const spec = {
58
+ id,
59
+ meta,
60
+ question,
61
+ runtimeContext: context
62
+ };
63
+ const evidence = await this.options.fetchEvidence({
64
+ query: question,
65
+ maxChunks: maxEvidenceChunks,
66
+ context
67
+ });
68
+ const insights = await this.extractInsights(question, evidence, context);
69
+ spec.insights = insights;
70
+ if (this.options.onInsightsGenerated) {
71
+ await this.options.onInsightsGenerated(insights, context);
72
+ }
73
+ const brief = await this.synthesiseBrief(question, insights, evidence, context);
74
+ spec.brief = brief;
75
+ if (this.options.onBriefSynthesised) {
76
+ await this.options.onBriefSynthesised(brief, context);
77
+ }
78
+ const intent = await this.generatePatchIntent(brief, context);
79
+ spec.patchIntent = intent;
80
+ if (this.options.onPatchIntentGenerated) {
81
+ await this.options.onPatchIntentGenerated(intent, context);
82
+ }
83
+ const patch = await this.generatePatch(intent, params.baseSpecSnippet);
84
+ spec.patch = patch;
85
+ if (this.options.onPatchGenerated) {
86
+ await this.options.onPatchGenerated(patch, context);
87
+ }
88
+ const impact = await this.generateImpactReport(intent, patch, params.compilerOutputText);
89
+ spec.impact = impact;
90
+ if (this.options.onImpactGenerated) {
91
+ await this.options.onImpactGenerated(impact, context);
92
+ }
93
+ const tasks = await this.generateTasks(brief, intent, impact, params.repoContext);
94
+ spec.tasks = tasks;
95
+ if (this.options.onTasksGenerated) {
96
+ await this.options.onTasksGenerated(tasks, context);
97
+ }
98
+ this.registry.set(spec);
99
+ return spec;
100
+ }
101
+ async extractInsights(question, evidence, _context) {
102
+ const evidenceJSON = formatEvidenceForModel(evidence);
103
+ const prompt = promptExtractInsights({ question, evidenceJSON });
104
+ const raw = await this.runModel(prompt);
105
+ return validateInsightExtraction(raw, evidence);
106
+ }
107
+ async synthesiseBrief(question, insights, evidence, _context) {
108
+ const insightsJSON = JSON.stringify(insights, null, 2);
109
+ const allowedChunkIds = evidence.map((chunk) => chunk.chunkId);
110
+ const prompt = promptSynthesizeBrief({
111
+ question,
112
+ insightsJSON,
113
+ allowedChunkIds
114
+ });
115
+ const raw = await this.runModel(prompt);
116
+ return validateOpportunityBrief(raw, evidence);
117
+ }
118
+ async generatePatchIntent(brief, _context) {
119
+ const briefJSON = JSON.stringify(brief, null, 2);
120
+ const prompt = promptGeneratePatchIntent({ briefJSON });
121
+ const raw = await this.runModel(prompt);
122
+ return validatePatchIntent(raw);
123
+ }
124
+ async generatePatch(intent, baseSpecSnippet) {
125
+ const patchIntentJSON = JSON.stringify(intent, null, 2);
126
+ const prompt = promptGenerateGenericSpecOverlay({
127
+ baseSpecSnippet: baseSpecSnippet ?? "",
128
+ patchIntentJSON
129
+ });
130
+ const raw = await this.runModel(prompt);
131
+ return parseStrictJSON(ContractSpecPatchModel, raw);
132
+ }
133
+ async generateImpactReport(intent, _patch, _compilerOutputText) {
134
+ return impactEngine(intent);
135
+ }
136
+ async generateTasks(brief, intent, impact, repoContext) {
137
+ const briefJSON = JSON.stringify(brief, null, 2);
138
+ const patchIntentJSON = JSON.stringify(intent, null, 2);
139
+ const impactJSON = JSON.stringify(impact, null, 2);
140
+ const prompt = promptGenerateTaskPack({
141
+ briefJSON,
142
+ patchIntentJSON,
143
+ impactJSON,
144
+ repoContext
145
+ });
146
+ const raw = await this.runModel(prompt);
147
+ return validateTaskPack(raw);
148
+ }
149
+ async runModel(prompt) {
150
+ return this.options.modelRunner.generateJson(prompt);
151
+ }
152
+ }
153
+ export {
154
+ createKeywordEvidenceFetcher,
155
+ ProductIntentOrchestrator
156
+ };
@@ -1,16 +1,9 @@
1
- import { EvidenceChunk } from "@contractspec/lib.contracts/product-intent/types";
2
-
3
- //#region src/evidence/keyword-retriever.d.ts
4
- interface KeywordEvidenceOptions {
5
- minScore?: number;
1
+ import type { EvidenceChunk } from '@contractspec/lib.contracts/product-intent/types';
2
+ export interface KeywordEvidenceOptions {
3
+ minScore?: number;
6
4
  }
7
- declare const createKeywordEvidenceFetcher: (chunks: EvidenceChunk[], options?: KeywordEvidenceOptions) => ({
8
- query,
9
- maxChunks
10
- }: {
11
- query: string;
12
- maxChunks?: number;
5
+ export declare const createKeywordEvidenceFetcher: (chunks: EvidenceChunk[], options?: KeywordEvidenceOptions) => ({ query, maxChunks, }: {
6
+ query: string;
7
+ maxChunks?: number;
13
8
  }) => Promise<EvidenceChunk[]>;
14
- //#endregion
15
- export { KeywordEvidenceOptions, createKeywordEvidenceFetcher };
16
9
  //# sourceMappingURL=keyword-retriever.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"keyword-retriever.d.ts","names":[],"sources":["../../src/evidence/keyword-retriever.ts"],"mappings":";;;UAEiB,sBAAA;EACf,QAAA;AAAA;AAAA,cAUW,4BAAA,GACV,MAAA,EAAQ,aAAA,IAAiB,OAAA,GAAS,sBAAA;EAC5B,KAAA;EAAA;AAAA;EAIL,KAAA;EACA,SAAA;AAAA,MACE,OAAA,CAAQ,aAAA"}
1
+ {"version":3,"file":"keyword-retriever.d.ts","sourceRoot":"","sources":["../../src/evidence/keyword-retriever.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAC;AAEtF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AASD,eAAO,MAAM,4BAA4B,GACtC,QAAQ,aAAa,EAAE,EAAE,UAAS,sBAA2B,MACvD,uBAGJ;IACD,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,KAAG,OAAO,CAAC,aAAa,EAAE,CAwB1B,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ProductIntentModelRunner, ProductIntentOrchestratorOptions, ProductIntentOrchestratorParams } from "./types.js";
2
- import { KeywordEvidenceOptions, createKeywordEvidenceFetcher } from "./evidence/keyword-retriever.js";
3
- import { ProductIntentOrchestrator } from "./orchestrator/product-intent-orchestrator.js";
4
- export { KeywordEvidenceOptions, ProductIntentModelRunner, ProductIntentOrchestrator, ProductIntentOrchestratorOptions, ProductIntentOrchestratorParams, createKeywordEvidenceFetcher };
1
+ export * from './types';
2
+ export * from './evidence/keyword-retriever';
3
+ export * from './orchestrator/product-intent-orchestrator';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4CAA4C,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,157 @@
1
- import { createKeywordEvidenceFetcher } from "./evidence/keyword-retriever.js";
2
- import { ProductIntentOrchestrator } from "./orchestrator/product-intent-orchestrator.js";
1
+ // @bun
2
+ // src/evidence/keyword-retriever.ts
3
+ var normalizeTokens = (value) => value.toLowerCase().split(/[^a-z0-9]+/g).map((token) => token.trim()).filter((token) => token.length > 2);
4
+ var createKeywordEvidenceFetcher = (chunks, options = {}) => async ({
5
+ query,
6
+ maxChunks
7
+ }) => {
8
+ const tokens = normalizeTokens(query);
9
+ if (tokens.length === 0) {
10
+ return maxChunks ? chunks.slice(0, maxChunks) : [...chunks];
11
+ }
12
+ const scored = chunks.map((chunk) => {
13
+ const haystack = chunk.text.toLowerCase();
14
+ const score = tokens.reduce((total, token) => total + (haystack.includes(token) ? 1 : 0), 0);
15
+ return { chunk, score };
16
+ }).filter((item) => item.score >= (options.minScore ?? 1));
17
+ scored.sort((a, b) => {
18
+ if (b.score !== a.score)
19
+ return b.score - a.score;
20
+ return a.chunk.chunkId.localeCompare(b.chunk.chunkId);
21
+ });
22
+ const results = scored.map((item) => item.chunk);
23
+ return maxChunks ? results.slice(0, maxChunks) : results;
24
+ };
25
+ // src/orchestrator/product-intent-orchestrator.ts
26
+ import {
27
+ ContractSpecPatchModel
28
+ } from "@contractspec/lib.contracts/product-intent/types";
29
+ import { ProductIntentRegistry } from "@contractspec/lib.contracts/product-intent/registry";
30
+ import {
31
+ formatEvidenceForModel,
32
+ impactEngine,
33
+ parseStrictJSON,
34
+ promptExtractInsights,
35
+ promptGenerateGenericSpecOverlay,
36
+ promptGeneratePatchIntent,
37
+ promptGenerateTaskPack,
38
+ promptSynthesizeBrief,
39
+ validateInsightExtraction,
40
+ validateOpportunityBrief,
41
+ validatePatchIntent,
42
+ validateTaskPack
43
+ } from "@contractspec/lib.product-intent-utils";
3
44
 
4
- export { ProductIntentOrchestrator, createKeywordEvidenceFetcher };
45
+ class ProductIntentOrchestrator {
46
+ options;
47
+ registry;
48
+ constructor(options, registry) {
49
+ this.options = options;
50
+ this.registry = registry ?? new ProductIntentRegistry;
51
+ }
52
+ getRegistry() {
53
+ return this.registry;
54
+ }
55
+ async runDiscovery(params) {
56
+ const { id, meta, question, context } = params;
57
+ const maxEvidenceChunks = params.maxEvidenceChunks ?? this.options.maxEvidenceChunks ?? 20;
58
+ const spec = {
59
+ id,
60
+ meta,
61
+ question,
62
+ runtimeContext: context
63
+ };
64
+ const evidence = await this.options.fetchEvidence({
65
+ query: question,
66
+ maxChunks: maxEvidenceChunks,
67
+ context
68
+ });
69
+ const insights = await this.extractInsights(question, evidence, context);
70
+ spec.insights = insights;
71
+ if (this.options.onInsightsGenerated) {
72
+ await this.options.onInsightsGenerated(insights, context);
73
+ }
74
+ const brief = await this.synthesiseBrief(question, insights, evidence, context);
75
+ spec.brief = brief;
76
+ if (this.options.onBriefSynthesised) {
77
+ await this.options.onBriefSynthesised(brief, context);
78
+ }
79
+ const intent = await this.generatePatchIntent(brief, context);
80
+ spec.patchIntent = intent;
81
+ if (this.options.onPatchIntentGenerated) {
82
+ await this.options.onPatchIntentGenerated(intent, context);
83
+ }
84
+ const patch = await this.generatePatch(intent, params.baseSpecSnippet);
85
+ spec.patch = patch;
86
+ if (this.options.onPatchGenerated) {
87
+ await this.options.onPatchGenerated(patch, context);
88
+ }
89
+ const impact = await this.generateImpactReport(intent, patch, params.compilerOutputText);
90
+ spec.impact = impact;
91
+ if (this.options.onImpactGenerated) {
92
+ await this.options.onImpactGenerated(impact, context);
93
+ }
94
+ const tasks = await this.generateTasks(brief, intent, impact, params.repoContext);
95
+ spec.tasks = tasks;
96
+ if (this.options.onTasksGenerated) {
97
+ await this.options.onTasksGenerated(tasks, context);
98
+ }
99
+ this.registry.set(spec);
100
+ return spec;
101
+ }
102
+ async extractInsights(question, evidence, _context) {
103
+ const evidenceJSON = formatEvidenceForModel(evidence);
104
+ const prompt = promptExtractInsights({ question, evidenceJSON });
105
+ const raw = await this.runModel(prompt);
106
+ return validateInsightExtraction(raw, evidence);
107
+ }
108
+ async synthesiseBrief(question, insights, evidence, _context) {
109
+ const insightsJSON = JSON.stringify(insights, null, 2);
110
+ const allowedChunkIds = evidence.map((chunk) => chunk.chunkId);
111
+ const prompt = promptSynthesizeBrief({
112
+ question,
113
+ insightsJSON,
114
+ allowedChunkIds
115
+ });
116
+ const raw = await this.runModel(prompt);
117
+ return validateOpportunityBrief(raw, evidence);
118
+ }
119
+ async generatePatchIntent(brief, _context) {
120
+ const briefJSON = JSON.stringify(brief, null, 2);
121
+ const prompt = promptGeneratePatchIntent({ briefJSON });
122
+ const raw = await this.runModel(prompt);
123
+ return validatePatchIntent(raw);
124
+ }
125
+ async generatePatch(intent, baseSpecSnippet) {
126
+ const patchIntentJSON = JSON.stringify(intent, null, 2);
127
+ const prompt = promptGenerateGenericSpecOverlay({
128
+ baseSpecSnippet: baseSpecSnippet ?? "",
129
+ patchIntentJSON
130
+ });
131
+ const raw = await this.runModel(prompt);
132
+ return parseStrictJSON(ContractSpecPatchModel, raw);
133
+ }
134
+ async generateImpactReport(intent, _patch, _compilerOutputText) {
135
+ return impactEngine(intent);
136
+ }
137
+ async generateTasks(brief, intent, impact, repoContext) {
138
+ const briefJSON = JSON.stringify(brief, null, 2);
139
+ const patchIntentJSON = JSON.stringify(intent, null, 2);
140
+ const impactJSON = JSON.stringify(impact, null, 2);
141
+ const prompt = promptGenerateTaskPack({
142
+ briefJSON,
143
+ patchIntentJSON,
144
+ impactJSON,
145
+ repoContext
146
+ });
147
+ const raw = await this.runModel(prompt);
148
+ return validateTaskPack(raw);
149
+ }
150
+ async runModel(prompt) {
151
+ return this.options.modelRunner.generateJson(prompt);
152
+ }
153
+ }
154
+ export {
155
+ createKeywordEvidenceFetcher,
156
+ ProductIntentOrchestrator
157
+ };
@@ -0,0 +1,156 @@
1
+ // src/evidence/keyword-retriever.ts
2
+ var normalizeTokens = (value) => value.toLowerCase().split(/[^a-z0-9]+/g).map((token) => token.trim()).filter((token) => token.length > 2);
3
+ var createKeywordEvidenceFetcher = (chunks, options = {}) => async ({
4
+ query,
5
+ maxChunks
6
+ }) => {
7
+ const tokens = normalizeTokens(query);
8
+ if (tokens.length === 0) {
9
+ return maxChunks ? chunks.slice(0, maxChunks) : [...chunks];
10
+ }
11
+ const scored = chunks.map((chunk) => {
12
+ const haystack = chunk.text.toLowerCase();
13
+ const score = tokens.reduce((total, token) => total + (haystack.includes(token) ? 1 : 0), 0);
14
+ return { chunk, score };
15
+ }).filter((item) => item.score >= (options.minScore ?? 1));
16
+ scored.sort((a, b) => {
17
+ if (b.score !== a.score)
18
+ return b.score - a.score;
19
+ return a.chunk.chunkId.localeCompare(b.chunk.chunkId);
20
+ });
21
+ const results = scored.map((item) => item.chunk);
22
+ return maxChunks ? results.slice(0, maxChunks) : results;
23
+ };
24
+ // src/orchestrator/product-intent-orchestrator.ts
25
+ import {
26
+ ContractSpecPatchModel
27
+ } from "@contractspec/lib.contracts/product-intent/types";
28
+ import { ProductIntentRegistry } from "@contractspec/lib.contracts/product-intent/registry";
29
+ import {
30
+ formatEvidenceForModel,
31
+ impactEngine,
32
+ parseStrictJSON,
33
+ promptExtractInsights,
34
+ promptGenerateGenericSpecOverlay,
35
+ promptGeneratePatchIntent,
36
+ promptGenerateTaskPack,
37
+ promptSynthesizeBrief,
38
+ validateInsightExtraction,
39
+ validateOpportunityBrief,
40
+ validatePatchIntent,
41
+ validateTaskPack
42
+ } from "@contractspec/lib.product-intent-utils";
43
+
44
+ class ProductIntentOrchestrator {
45
+ options;
46
+ registry;
47
+ constructor(options, registry) {
48
+ this.options = options;
49
+ this.registry = registry ?? new ProductIntentRegistry;
50
+ }
51
+ getRegistry() {
52
+ return this.registry;
53
+ }
54
+ async runDiscovery(params) {
55
+ const { id, meta, question, context } = params;
56
+ const maxEvidenceChunks = params.maxEvidenceChunks ?? this.options.maxEvidenceChunks ?? 20;
57
+ const spec = {
58
+ id,
59
+ meta,
60
+ question,
61
+ runtimeContext: context
62
+ };
63
+ const evidence = await this.options.fetchEvidence({
64
+ query: question,
65
+ maxChunks: maxEvidenceChunks,
66
+ context
67
+ });
68
+ const insights = await this.extractInsights(question, evidence, context);
69
+ spec.insights = insights;
70
+ if (this.options.onInsightsGenerated) {
71
+ await this.options.onInsightsGenerated(insights, context);
72
+ }
73
+ const brief = await this.synthesiseBrief(question, insights, evidence, context);
74
+ spec.brief = brief;
75
+ if (this.options.onBriefSynthesised) {
76
+ await this.options.onBriefSynthesised(brief, context);
77
+ }
78
+ const intent = await this.generatePatchIntent(brief, context);
79
+ spec.patchIntent = intent;
80
+ if (this.options.onPatchIntentGenerated) {
81
+ await this.options.onPatchIntentGenerated(intent, context);
82
+ }
83
+ const patch = await this.generatePatch(intent, params.baseSpecSnippet);
84
+ spec.patch = patch;
85
+ if (this.options.onPatchGenerated) {
86
+ await this.options.onPatchGenerated(patch, context);
87
+ }
88
+ const impact = await this.generateImpactReport(intent, patch, params.compilerOutputText);
89
+ spec.impact = impact;
90
+ if (this.options.onImpactGenerated) {
91
+ await this.options.onImpactGenerated(impact, context);
92
+ }
93
+ const tasks = await this.generateTasks(brief, intent, impact, params.repoContext);
94
+ spec.tasks = tasks;
95
+ if (this.options.onTasksGenerated) {
96
+ await this.options.onTasksGenerated(tasks, context);
97
+ }
98
+ this.registry.set(spec);
99
+ return spec;
100
+ }
101
+ async extractInsights(question, evidence, _context) {
102
+ const evidenceJSON = formatEvidenceForModel(evidence);
103
+ const prompt = promptExtractInsights({ question, evidenceJSON });
104
+ const raw = await this.runModel(prompt);
105
+ return validateInsightExtraction(raw, evidence);
106
+ }
107
+ async synthesiseBrief(question, insights, evidence, _context) {
108
+ const insightsJSON = JSON.stringify(insights, null, 2);
109
+ const allowedChunkIds = evidence.map((chunk) => chunk.chunkId);
110
+ const prompt = promptSynthesizeBrief({
111
+ question,
112
+ insightsJSON,
113
+ allowedChunkIds
114
+ });
115
+ const raw = await this.runModel(prompt);
116
+ return validateOpportunityBrief(raw, evidence);
117
+ }
118
+ async generatePatchIntent(brief, _context) {
119
+ const briefJSON = JSON.stringify(brief, null, 2);
120
+ const prompt = promptGeneratePatchIntent({ briefJSON });
121
+ const raw = await this.runModel(prompt);
122
+ return validatePatchIntent(raw);
123
+ }
124
+ async generatePatch(intent, baseSpecSnippet) {
125
+ const patchIntentJSON = JSON.stringify(intent, null, 2);
126
+ const prompt = promptGenerateGenericSpecOverlay({
127
+ baseSpecSnippet: baseSpecSnippet ?? "",
128
+ patchIntentJSON
129
+ });
130
+ const raw = await this.runModel(prompt);
131
+ return parseStrictJSON(ContractSpecPatchModel, raw);
132
+ }
133
+ async generateImpactReport(intent, _patch, _compilerOutputText) {
134
+ return impactEngine(intent);
135
+ }
136
+ async generateTasks(brief, intent, impact, repoContext) {
137
+ const briefJSON = JSON.stringify(brief, null, 2);
138
+ const patchIntentJSON = JSON.stringify(intent, null, 2);
139
+ const impactJSON = JSON.stringify(impact, null, 2);
140
+ const prompt = promptGenerateTaskPack({
141
+ briefJSON,
142
+ patchIntentJSON,
143
+ impactJSON,
144
+ repoContext
145
+ });
146
+ const raw = await this.runModel(prompt);
147
+ return validateTaskPack(raw);
148
+ }
149
+ async runModel(prompt) {
150
+ return this.options.modelRunner.generateJson(prompt);
151
+ }
152
+ }
153
+ export {
154
+ createKeywordEvidenceFetcher,
155
+ ProductIntentOrchestrator
156
+ };
@@ -1,23 +1,19 @@
1
- import { ProductIntentOrchestratorOptions, ProductIntentOrchestratorParams } from "../types.js";
2
- import { ContractPatchIntent, ContractSpecPatch, EvidenceChunk, ImpactReport, InsightExtraction, OpportunityBrief, TaskPack } from "@contractspec/lib.contracts/product-intent/types";
3
- import { ProductIntentRegistry } from "@contractspec/lib.contracts/product-intent/registry";
4
- import { ProductIntentSpec } from "@contractspec/lib.contracts/product-intent/spec";
5
-
6
- //#region src/orchestrator/product-intent-orchestrator.d.ts
7
- declare class ProductIntentOrchestrator<Context = unknown> {
8
- private options;
9
- private registry;
10
- constructor(options: ProductIntentOrchestratorOptions<Context>, registry?: ProductIntentRegistry);
11
- getRegistry(): ProductIntentRegistry;
12
- runDiscovery(params: ProductIntentOrchestratorParams<Context>): Promise<ProductIntentSpec<Context>>;
13
- protected extractInsights(question: string, evidence: EvidenceChunk[], _context?: Context): Promise<InsightExtraction>;
14
- protected synthesiseBrief(question: string, insights: InsightExtraction, evidence: EvidenceChunk[], _context?: Context): Promise<OpportunityBrief>;
15
- protected generatePatchIntent(brief: OpportunityBrief, _context?: Context): Promise<ContractPatchIntent>;
16
- protected generatePatch(intent: ContractPatchIntent, baseSpecSnippet?: string): Promise<ContractSpecPatch>;
17
- protected generateImpactReport(intent: ContractPatchIntent, _patch: ContractSpecPatch, _compilerOutputText?: string): Promise<ImpactReport>;
18
- protected generateTasks(brief: OpportunityBrief, intent: ContractPatchIntent, impact: ImpactReport, repoContext?: string): Promise<TaskPack>;
19
- private runModel;
1
+ import { type ContractPatchIntent, type ContractSpecPatch, type EvidenceChunk, type ImpactReport, type InsightExtraction, type OpportunityBrief, type TaskPack } from '@contractspec/lib.contracts/product-intent/types';
2
+ import type { ProductIntentSpec } from '@contractspec/lib.contracts/product-intent/spec';
3
+ import { ProductIntentRegistry } from '@contractspec/lib.contracts/product-intent/registry';
4
+ import type { ProductIntentOrchestratorOptions, ProductIntentOrchestratorParams } from '../types';
5
+ export declare class ProductIntentOrchestrator<Context = unknown> {
6
+ private options;
7
+ private registry;
8
+ constructor(options: ProductIntentOrchestratorOptions<Context>, registry?: ProductIntentRegistry);
9
+ getRegistry(): ProductIntentRegistry;
10
+ runDiscovery(params: ProductIntentOrchestratorParams<Context>): Promise<ProductIntentSpec<Context>>;
11
+ protected extractInsights(question: string, evidence: EvidenceChunk[], _context?: Context): Promise<InsightExtraction>;
12
+ protected synthesiseBrief(question: string, insights: InsightExtraction, evidence: EvidenceChunk[], _context?: Context): Promise<OpportunityBrief>;
13
+ protected generatePatchIntent(brief: OpportunityBrief, _context?: Context): Promise<ContractPatchIntent>;
14
+ protected generatePatch(intent: ContractPatchIntent, baseSpecSnippet?: string): Promise<ContractSpecPatch>;
15
+ protected generateImpactReport(intent: ContractPatchIntent, _patch: ContractSpecPatch, _compilerOutputText?: string): Promise<ImpactReport>;
16
+ protected generateTasks(brief: OpportunityBrief, intent: ContractPatchIntent, impact: ImpactReport, repoContext?: string): Promise<TaskPack>;
17
+ private runModel;
20
18
  }
21
- //#endregion
22
- export { ProductIntentOrchestrator };
23
19
  //# sourceMappingURL=product-intent-orchestrator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"product-intent-orchestrator.d.ts","names":[],"sources":["../../src/orchestrator/product-intent-orchestrator.ts"],"mappings":";;;;;;cA+Ba,yBAAA;EAAA,QACH,OAAA;EAAA,QACA,QAAA;cAGN,OAAA,EAAS,gCAAA,CAAiC,OAAA,GAC1C,QAAA,GAAW,qBAAA;EAMb,WAAA,CAAA,GAAe,qBAAA;EAIT,YAAA,CACJ,MAAA,EAAQ,+BAAA,CAAgC,OAAA,IACvC,OAAA,CAAQ,iBAAA,CAAkB,OAAA;EAAA,UAwEb,eAAA,CACd,QAAA,UACA,QAAA,EAAU,aAAA,IACV,QAAA,GAAW,OAAA,GACV,OAAA,CAAQ,iBAAA;EAAA,UAOK,eAAA,CACd,QAAA,UACA,QAAA,EAAU,iBAAA,EACV,QAAA,EAAU,aAAA,IACV,QAAA,GAAW,OAAA,GACV,OAAA,CAAQ,gBAAA;EAAA,UAYK,mBAAA,CACd,KAAA,EAAO,gBAAA,EACP,QAAA,GAAW,OAAA,GACV,OAAA,CAAQ,mBAAA;EAAA,UAOK,aAAA,CACd,MAAA,EAAQ,mBAAA,EACR,eAAA,YACC,OAAA,CAAQ,iBAAA;EAAA,UAUK,oBAAA,CACd,MAAA,EAAQ,mBAAA,EACR,MAAA,EAAQ,iBAAA,EACR,mBAAA,YACC,OAAA,CAAQ,YAAA;EAAA,UAIK,aAAA,CACd,KAAA,EAAO,gBAAA,EACP,MAAA,EAAQ,mBAAA,EACR,MAAA,EAAQ,YAAA,EACR,WAAA,YACC,OAAA,CAAQ,QAAA;EAAA,QAcG,QAAA;AAAA"}
1
+ {"version":3,"file":"product-intent-orchestrator.d.ts","sourceRoot":"","sources":["../../src/orchestrator/product-intent-orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EAEtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACd,MAAM,kDAAkD,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,EA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AcN,QAAQ;CAGvB"}
package/dist/types.d.ts CHANGED
@@ -1,35 +1,32 @@
1
- import { ContractPatchIntent, ContractSpecPatch, EvidenceChunk, ImpactReport, InsightExtraction, OpportunityBrief, TaskPack } from "@contractspec/lib.contracts/product-intent/types";
2
- import { ProductIntentMeta } from "@contractspec/lib.contracts/product-intent/spec";
3
-
4
- //#region src/types.d.ts
5
- interface ProductIntentModelRunner {
6
- generateJson: (prompt: string) => Promise<string>;
1
+ import type { EvidenceChunk } from '@contractspec/lib.contracts/product-intent/types';
2
+ import type { ProductIntentMeta } from '@contractspec/lib.contracts/product-intent/spec';
3
+ import type { ContractPatchIntent, ContractSpecPatch, ImpactReport, InsightExtraction, OpportunityBrief, TaskPack } from '@contractspec/lib.contracts/product-intent/types';
4
+ export interface ProductIntentModelRunner {
5
+ generateJson: (prompt: string) => Promise<string>;
7
6
  }
8
- interface ProductIntentOrchestratorOptions<Context = unknown> {
9
- fetchEvidence: (params: {
10
- query: string;
11
- maxChunks?: number;
12
- context?: Context;
13
- }) => Promise<EvidenceChunk[]>;
14
- modelRunner: ProductIntentModelRunner;
15
- maxEvidenceChunks?: number;
16
- onInsightsGenerated?: (insights: InsightExtraction, ctx?: Context) => Promise<void>;
17
- onBriefSynthesised?: (brief: OpportunityBrief, ctx?: Context) => Promise<void>;
18
- onPatchIntentGenerated?: (intent: ContractPatchIntent, ctx?: Context) => Promise<void>;
19
- onPatchGenerated?: (patch: ContractSpecPatch, ctx?: Context) => Promise<void>;
20
- onImpactGenerated?: (impact: ImpactReport, ctx?: Context) => Promise<void>;
21
- onTasksGenerated?: (tasks: TaskPack, ctx?: Context) => Promise<void>;
7
+ export interface ProductIntentOrchestratorOptions<Context = unknown> {
8
+ fetchEvidence: (params: {
9
+ query: string;
10
+ maxChunks?: number;
11
+ context?: Context;
12
+ }) => Promise<EvidenceChunk[]>;
13
+ modelRunner: ProductIntentModelRunner;
14
+ maxEvidenceChunks?: number;
15
+ onInsightsGenerated?: (insights: InsightExtraction, ctx?: Context) => Promise<void>;
16
+ onBriefSynthesised?: (brief: OpportunityBrief, ctx?: Context) => Promise<void>;
17
+ onPatchIntentGenerated?: (intent: ContractPatchIntent, ctx?: Context) => Promise<void>;
18
+ onPatchGenerated?: (patch: ContractSpecPatch, ctx?: Context) => Promise<void>;
19
+ onImpactGenerated?: (impact: ImpactReport, ctx?: Context) => Promise<void>;
20
+ onTasksGenerated?: (tasks: TaskPack, ctx?: Context) => Promise<void>;
22
21
  }
23
- interface ProductIntentOrchestratorParams<Context = unknown> {
24
- id: string;
25
- meta: ProductIntentMeta;
26
- question: string;
27
- context?: Context;
28
- maxEvidenceChunks?: number;
29
- baseSpecSnippet?: string;
30
- compilerOutputText?: string;
31
- repoContext?: string;
22
+ export interface ProductIntentOrchestratorParams<Context = unknown> {
23
+ id: string;
24
+ meta: ProductIntentMeta;
25
+ question: string;
26
+ context?: Context;
27
+ maxEvidenceChunks?: number;
28
+ baseSpecSnippet?: string;
29
+ compilerOutputText?: string;
30
+ repoContext?: string;
32
31
  }
33
- //#endregion
34
- export { ProductIntentModelRunner, ProductIntentOrchestratorOptions, ProductIntentOrchestratorParams };
35
32
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;UAWiB,wBAAA;EACf,YAAA,GAAe,MAAA,aAAmB,OAAA;AAAA;AAAA,UAGnB,gCAAA;EACf,aAAA,GAAgB,MAAA;IACd,KAAA;IACA,SAAA;IACA,OAAA,GAAU,OAAA;EAAA,MACN,OAAA,CAAQ,aAAA;EACd,WAAA,EAAa,wBAAA;EACb,iBAAA;EACA,mBAAA,IACE,QAAA,EAAU,iBAAA,EACV,GAAA,GAAM,OAAA,KACH,OAAA;EACL,kBAAA,IACE,KAAA,EAAO,gBAAA,EACP,GAAA,GAAM,OAAA,KACH,OAAA;EACL,sBAAA,IACE,MAAA,EAAQ,mBAAA,EACR,GAAA,GAAM,OAAA,KACH,OAA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BAAkB,CAAC,EAAE,CACnB,KAAK,EAAE,gBAAgB,EACvB,GAAG,CAAC,EAAE,OAAO,KACV,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,sBAAsB,CAAC,EAAE,CACvB,MAAM,EAAE,mBAAmB,EAC3B,GAAG,CAAC,EAAE,OAAO,KACV,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE;AAED,MAAM,WAAW,+BAA+B,CAAC,OAAO,GAAG,OAAO;IAChE,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,iBAAiB,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contractspec/module.product-intent-core",
3
- "version": "1.57.0",
3
+ "version": "1.59.0",
4
4
  "description": "Core product intent orchestration and adapters",
5
5
  "keywords": [
6
6
  "contractspec",
@@ -19,35 +19,40 @@
19
19
  "scripts": {
20
20
  "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
21
21
  "publish:pkg:canary": "bun publish:pkg --tag canary",
22
- "build": "bun build:types && bun build:bundle",
23
- "build:bundle": "tsdown",
24
- "build:types": "tsc --noEmit",
25
- "dev": "bun build:bundle --watch",
22
+ "build": "bun run prebuild && bun run build:bundle && bun run build:types",
23
+ "build:bundle": "contractspec-bun-build transpile",
24
+ "build:types": "contractspec-bun-build types",
25
+ "dev": "contractspec-bun-build dev",
26
26
  "clean": "rimraf dist .turbo",
27
27
  "lint": "bun lint:fix",
28
28
  "lint:fix": "eslint src --fix",
29
29
  "lint:check": "eslint src",
30
- "test": "bun test"
30
+ "test": "bun test",
31
+ "prebuild": "contractspec-bun-build prebuild",
32
+ "typecheck": "tsc --noEmit"
31
33
  },
32
34
  "dependencies": {
33
- "@contractspec/lib.contracts": "1.57.0",
34
- "@contractspec/lib.product-intent-utils": "1.57.0"
35
+ "@contractspec/lib.contracts": "1.59.0",
36
+ "@contractspec/lib.product-intent-utils": "1.59.0"
35
37
  },
36
38
  "devDependencies": {
37
- "@contractspec/tool.tsdown": "1.57.0",
38
- "@contractspec/tool.typescript": "1.57.0",
39
- "tsdown": "^0.20.3",
40
- "typescript": "^5.9.3"
39
+ "@contractspec/tool.typescript": "1.59.0",
40
+ "typescript": "^5.9.3",
41
+ "@contractspec/tool.bun": "1.58.0"
41
42
  },
42
43
  "exports": {
43
- ".": "./dist/index.js",
44
- "./*": "./*"
44
+ ".": "./src/index.ts"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public",
48
48
  "exports": {
49
- ".": "./dist/index.js",
50
- "./*": "./*"
49
+ ".": {
50
+ "types": "./dist/index.d.ts",
51
+ "bun": "./dist/index.js",
52
+ "node": "./dist/node/index.mjs",
53
+ "browser": "./dist/browser/index.js",
54
+ "default": "./dist/index.js"
55
+ }
51
56
  },
52
57
  "registry": "https://registry.npmjs.org/"
53
58
  },
@@ -1,23 +0,0 @@
1
- //#region src/evidence/keyword-retriever.ts
2
- const normalizeTokens = (value) => value.toLowerCase().split(/[^a-z0-9]+/g).map((token) => token.trim()).filter((token) => token.length > 2);
3
- const createKeywordEvidenceFetcher = (chunks, options = {}) => async ({ query, maxChunks }) => {
4
- const tokens = normalizeTokens(query);
5
- if (tokens.length === 0) return maxChunks ? chunks.slice(0, maxChunks) : [...chunks];
6
- const scored = chunks.map((chunk) => {
7
- const haystack = chunk.text.toLowerCase();
8
- return {
9
- chunk,
10
- score: tokens.reduce((total, token) => total + (haystack.includes(token) ? 1 : 0), 0)
11
- };
12
- }).filter((item) => item.score >= (options.minScore ?? 1));
13
- scored.sort((a, b) => {
14
- if (b.score !== a.score) return b.score - a.score;
15
- return a.chunk.chunkId.localeCompare(b.chunk.chunkId);
16
- });
17
- const results = scored.map((item) => item.chunk);
18
- return maxChunks ? results.slice(0, maxChunks) : results;
19
- };
20
-
21
- //#endregion
22
- export { createKeywordEvidenceFetcher };
23
- //# sourceMappingURL=keyword-retriever.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keyword-retriever.js","names":[],"sources":["../../src/evidence/keyword-retriever.ts"],"sourcesContent":["import type { EvidenceChunk } from '@contractspec/lib.contracts/product-intent/types';\n\nexport interface KeywordEvidenceOptions {\n minScore?: number;\n}\n\nconst normalizeTokens = (value: string): string[] =>\n value\n .toLowerCase()\n .split(/[^a-z0-9]+/g)\n .map((token) => token.trim())\n .filter((token) => token.length > 2);\n\nexport const createKeywordEvidenceFetcher =\n (chunks: EvidenceChunk[], options: KeywordEvidenceOptions = {}) =>\n async ({\n query,\n maxChunks,\n }: {\n query: string;\n maxChunks?: number;\n }): Promise<EvidenceChunk[]> => {\n const tokens = normalizeTokens(query);\n if (tokens.length === 0) {\n return maxChunks ? chunks.slice(0, maxChunks) : [...chunks];\n }\n\n const scored = chunks\n .map((chunk) => {\n const haystack = chunk.text.toLowerCase();\n const score = tokens.reduce(\n (total, token) => total + (haystack.includes(token) ? 1 : 0),\n 0\n );\n return { chunk, score };\n })\n .filter((item) => item.score >= (options.minScore ?? 1));\n\n scored.sort((a, b) => {\n if (b.score !== a.score) return b.score - a.score;\n return a.chunk.chunkId.localeCompare(b.chunk.chunkId);\n });\n\n const results = scored.map((item) => item.chunk);\n return maxChunks ? results.slice(0, maxChunks) : results;\n };\n"],"mappings":";AAMA,MAAM,mBAAmB,UACvB,MACG,aAAa,CACb,MAAM,cAAc,CACpB,KAAK,UAAU,MAAM,MAAM,CAAC,CAC5B,QAAQ,UAAU,MAAM,SAAS,EAAE;AAExC,MAAa,gCACV,QAAyB,UAAkC,EAAE,KAC9D,OAAO,EACL,OACA,gBAI8B;CAC9B,MAAM,SAAS,gBAAgB,MAAM;AACrC,KAAI,OAAO,WAAW,EACpB,QAAO,YAAY,OAAO,MAAM,GAAG,UAAU,GAAG,CAAC,GAAG,OAAO;CAG7D,MAAM,SAAS,OACZ,KAAK,UAAU;EACd,MAAM,WAAW,MAAM,KAAK,aAAa;AAKzC,SAAO;GAAE;GAAO,OAJF,OAAO,QAClB,OAAO,UAAU,SAAS,SAAS,SAAS,MAAM,GAAG,IAAI,IAC1D,EACD;GACsB;GACvB,CACD,QAAQ,SAAS,KAAK,UAAU,QAAQ,YAAY,GAAG;AAE1D,QAAO,MAAM,GAAG,MAAM;AACpB,MAAI,EAAE,UAAU,EAAE,MAAO,QAAO,EAAE,QAAQ,EAAE;AAC5C,SAAO,EAAE,MAAM,QAAQ,cAAc,EAAE,MAAM,QAAQ;GACrD;CAEF,MAAM,UAAU,OAAO,KAAK,SAAS,KAAK,MAAM;AAChD,QAAO,YAAY,QAAQ,MAAM,GAAG,UAAU,GAAG"}
@@ -1,97 +0,0 @@
1
- import { ContractSpecPatchModel } from "@contractspec/lib.contracts/product-intent/types";
2
- import { ProductIntentRegistry } from "@contractspec/lib.contracts/product-intent/registry";
3
- import { formatEvidenceForModel, impactEngine, parseStrictJSON, promptExtractInsights, promptGenerateGenericSpecOverlay, promptGeneratePatchIntent, promptGenerateTaskPack, promptSynthesizeBrief, validateInsightExtraction, validateOpportunityBrief, validatePatchIntent, validateTaskPack } from "@contractspec/lib.product-intent-utils";
4
-
5
- //#region src/orchestrator/product-intent-orchestrator.ts
6
- var ProductIntentOrchestrator = class {
7
- options;
8
- registry;
9
- constructor(options, registry) {
10
- this.options = options;
11
- this.registry = registry ?? new ProductIntentRegistry();
12
- }
13
- getRegistry() {
14
- return this.registry;
15
- }
16
- async runDiscovery(params) {
17
- const { id, meta, question, context } = params;
18
- const maxEvidenceChunks = params.maxEvidenceChunks ?? this.options.maxEvidenceChunks ?? 20;
19
- const spec = {
20
- id,
21
- meta,
22
- question,
23
- runtimeContext: context
24
- };
25
- const evidence = await this.options.fetchEvidence({
26
- query: question,
27
- maxChunks: maxEvidenceChunks,
28
- context
29
- });
30
- const insights = await this.extractInsights(question, evidence, context);
31
- spec.insights = insights;
32
- if (this.options.onInsightsGenerated) await this.options.onInsightsGenerated(insights, context);
33
- const brief = await this.synthesiseBrief(question, insights, evidence, context);
34
- spec.brief = brief;
35
- if (this.options.onBriefSynthesised) await this.options.onBriefSynthesised(brief, context);
36
- const intent = await this.generatePatchIntent(brief, context);
37
- spec.patchIntent = intent;
38
- if (this.options.onPatchIntentGenerated) await this.options.onPatchIntentGenerated(intent, context);
39
- const patch = await this.generatePatch(intent, params.baseSpecSnippet);
40
- spec.patch = patch;
41
- if (this.options.onPatchGenerated) await this.options.onPatchGenerated(patch, context);
42
- const impact = await this.generateImpactReport(intent, patch, params.compilerOutputText);
43
- spec.impact = impact;
44
- if (this.options.onImpactGenerated) await this.options.onImpactGenerated(impact, context);
45
- const tasks = await this.generateTasks(brief, intent, impact, params.repoContext);
46
- spec.tasks = tasks;
47
- if (this.options.onTasksGenerated) await this.options.onTasksGenerated(tasks, context);
48
- this.registry.set(spec);
49
- return spec;
50
- }
51
- async extractInsights(question, evidence, _context) {
52
- const prompt = promptExtractInsights({
53
- question,
54
- evidenceJSON: formatEvidenceForModel(evidence)
55
- });
56
- return validateInsightExtraction(await this.runModel(prompt), evidence);
57
- }
58
- async synthesiseBrief(question, insights, evidence, _context) {
59
- const prompt = promptSynthesizeBrief({
60
- question,
61
- insightsJSON: JSON.stringify(insights, null, 2),
62
- allowedChunkIds: evidence.map((chunk) => chunk.chunkId)
63
- });
64
- return validateOpportunityBrief(await this.runModel(prompt), evidence);
65
- }
66
- async generatePatchIntent(brief, _context) {
67
- const prompt = promptGeneratePatchIntent({ briefJSON: JSON.stringify(brief, null, 2) });
68
- return validatePatchIntent(await this.runModel(prompt));
69
- }
70
- async generatePatch(intent, baseSpecSnippet) {
71
- const patchIntentJSON = JSON.stringify(intent, null, 2);
72
- const prompt = promptGenerateGenericSpecOverlay({
73
- baseSpecSnippet: baseSpecSnippet ?? "",
74
- patchIntentJSON
75
- });
76
- return parseStrictJSON(ContractSpecPatchModel, await this.runModel(prompt));
77
- }
78
- async generateImpactReport(intent, _patch, _compilerOutputText) {
79
- return impactEngine(intent);
80
- }
81
- async generateTasks(brief, intent, impact, repoContext) {
82
- const prompt = promptGenerateTaskPack({
83
- briefJSON: JSON.stringify(brief, null, 2),
84
- patchIntentJSON: JSON.stringify(intent, null, 2),
85
- impactJSON: JSON.stringify(impact, null, 2),
86
- repoContext
87
- });
88
- return validateTaskPack(await this.runModel(prompt));
89
- }
90
- async runModel(prompt) {
91
- return this.options.modelRunner.generateJson(prompt);
92
- }
93
- };
94
-
95
- //#endregion
96
- export { ProductIntentOrchestrator };
97
- //# sourceMappingURL=product-intent-orchestrator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"product-intent-orchestrator.js","names":[],"sources":["../../src/orchestrator/product-intent-orchestrator.ts"],"sourcesContent":["import {\n type ContractPatchIntent,\n type ContractSpecPatch,\n ContractSpecPatchModel,\n type EvidenceChunk,\n type ImpactReport,\n type InsightExtraction,\n type OpportunityBrief,\n type TaskPack,\n} from '@contractspec/lib.contracts/product-intent/types';\nimport type { ProductIntentSpec } from '@contractspec/lib.contracts/product-intent/spec';\nimport { ProductIntentRegistry } from '@contractspec/lib.contracts/product-intent/registry';\nimport {\n formatEvidenceForModel,\n impactEngine,\n parseStrictJSON,\n promptExtractInsights,\n promptGenerateGenericSpecOverlay,\n promptGeneratePatchIntent,\n promptGenerateTaskPack,\n promptSynthesizeBrief,\n validateInsightExtraction,\n validateOpportunityBrief,\n validatePatchIntent,\n validateTaskPack,\n} from '@contractspec/lib.product-intent-utils';\nimport type {\n ProductIntentOrchestratorOptions,\n ProductIntentOrchestratorParams,\n} from '../types';\n\nexport class ProductIntentOrchestrator<Context = unknown> {\n private options: ProductIntentOrchestratorOptions<Context>;\n private registry: ProductIntentRegistry;\n\n constructor(\n options: ProductIntentOrchestratorOptions<Context>,\n registry?: ProductIntentRegistry\n ) {\n this.options = options;\n this.registry = registry ?? new ProductIntentRegistry();\n }\n\n getRegistry(): ProductIntentRegistry {\n return this.registry;\n }\n\n async runDiscovery(\n params: ProductIntentOrchestratorParams<Context>\n ): Promise<ProductIntentSpec<Context>> {\n const { id, meta, question, context } = params;\n const maxEvidenceChunks =\n params.maxEvidenceChunks ?? this.options.maxEvidenceChunks ?? 20;\n\n const spec: ProductIntentSpec<Context> = {\n id,\n meta,\n question,\n runtimeContext: context,\n };\n\n const evidence = await this.options.fetchEvidence({\n query: question,\n maxChunks: maxEvidenceChunks,\n context,\n });\n\n const insights = await this.extractInsights(question, evidence, context);\n spec.insights = insights;\n if (this.options.onInsightsGenerated) {\n await this.options.onInsightsGenerated(insights, context);\n }\n\n const brief = await this.synthesiseBrief(\n question,\n insights,\n evidence,\n context\n );\n spec.brief = brief;\n if (this.options.onBriefSynthesised) {\n await this.options.onBriefSynthesised(brief, context);\n }\n\n const intent = await this.generatePatchIntent(brief, context);\n spec.patchIntent = intent;\n if (this.options.onPatchIntentGenerated) {\n await this.options.onPatchIntentGenerated(intent, context);\n }\n\n const patch = await this.generatePatch(intent, params.baseSpecSnippet);\n spec.patch = patch;\n if (this.options.onPatchGenerated) {\n await this.options.onPatchGenerated(patch, context);\n }\n\n const impact = await this.generateImpactReport(\n intent,\n patch,\n params.compilerOutputText\n );\n spec.impact = impact;\n if (this.options.onImpactGenerated) {\n await this.options.onImpactGenerated(impact, context);\n }\n\n const tasks = await this.generateTasks(\n brief,\n intent,\n impact,\n params.repoContext\n );\n spec.tasks = tasks;\n if (this.options.onTasksGenerated) {\n await this.options.onTasksGenerated(tasks, context);\n }\n\n this.registry.set(spec);\n return spec;\n }\n\n protected async extractInsights(\n question: string,\n evidence: EvidenceChunk[],\n _context?: Context\n ): Promise<InsightExtraction> {\n const evidenceJSON = formatEvidenceForModel(evidence);\n const prompt = promptExtractInsights({ question, evidenceJSON });\n const raw = await this.runModel(prompt);\n return validateInsightExtraction(raw, evidence);\n }\n\n protected async synthesiseBrief(\n question: string,\n insights: InsightExtraction,\n evidence: EvidenceChunk[],\n _context?: Context\n ): Promise<OpportunityBrief> {\n const insightsJSON = JSON.stringify(insights, null, 2);\n const allowedChunkIds = evidence.map((chunk) => chunk.chunkId);\n const prompt = promptSynthesizeBrief({\n question,\n insightsJSON,\n allowedChunkIds,\n });\n const raw = await this.runModel(prompt);\n return validateOpportunityBrief(raw, evidence);\n }\n\n protected async generatePatchIntent(\n brief: OpportunityBrief,\n _context?: Context\n ): Promise<ContractPatchIntent> {\n const briefJSON = JSON.stringify(brief, null, 2);\n const prompt = promptGeneratePatchIntent({ briefJSON });\n const raw = await this.runModel(prompt);\n return validatePatchIntent(raw);\n }\n\n protected async generatePatch(\n intent: ContractPatchIntent,\n baseSpecSnippet?: string\n ): Promise<ContractSpecPatch> {\n const patchIntentJSON = JSON.stringify(intent, null, 2);\n const prompt = promptGenerateGenericSpecOverlay({\n baseSpecSnippet: baseSpecSnippet ?? '',\n patchIntentJSON,\n });\n const raw = await this.runModel(prompt);\n return parseStrictJSON<ContractSpecPatch>(ContractSpecPatchModel, raw);\n }\n\n protected async generateImpactReport(\n intent: ContractPatchIntent,\n _patch: ContractSpecPatch,\n _compilerOutputText?: string\n ): Promise<ImpactReport> {\n return impactEngine(intent);\n }\n\n protected async generateTasks(\n brief: OpportunityBrief,\n intent: ContractPatchIntent,\n impact: ImpactReport,\n repoContext?: string\n ): Promise<TaskPack> {\n const briefJSON = JSON.stringify(brief, null, 2);\n const patchIntentJSON = JSON.stringify(intent, null, 2);\n const impactJSON = JSON.stringify(impact, null, 2);\n const prompt = promptGenerateTaskPack({\n briefJSON,\n patchIntentJSON,\n impactJSON,\n repoContext,\n });\n const raw = await this.runModel(prompt);\n return validateTaskPack(raw);\n }\n\n private async runModel(prompt: string): Promise<string> {\n return this.options.modelRunner.generateJson(prompt);\n }\n}\n"],"mappings":";;;;;AA+BA,IAAa,4BAAb,MAA0D;CACxD,AAAQ;CACR,AAAQ;CAER,YACE,SACA,UACA;AACA,OAAK,UAAU;AACf,OAAK,WAAW,YAAY,IAAI,uBAAuB;;CAGzD,cAAqC;AACnC,SAAO,KAAK;;CAGd,MAAM,aACJ,QACqC;EACrC,MAAM,EAAE,IAAI,MAAM,UAAU,YAAY;EACxC,MAAM,oBACJ,OAAO,qBAAqB,KAAK,QAAQ,qBAAqB;EAEhE,MAAM,OAAmC;GACvC;GACA;GACA;GACA,gBAAgB;GACjB;EAED,MAAM,WAAW,MAAM,KAAK,QAAQ,cAAc;GAChD,OAAO;GACP,WAAW;GACX;GACD,CAAC;EAEF,MAAM,WAAW,MAAM,KAAK,gBAAgB,UAAU,UAAU,QAAQ;AACxE,OAAK,WAAW;AAChB,MAAI,KAAK,QAAQ,oBACf,OAAM,KAAK,QAAQ,oBAAoB,UAAU,QAAQ;EAG3D,MAAM,QAAQ,MAAM,KAAK,gBACvB,UACA,UACA,UACA,QACD;AACD,OAAK,QAAQ;AACb,MAAI,KAAK,QAAQ,mBACf,OAAM,KAAK,QAAQ,mBAAmB,OAAO,QAAQ;EAGvD,MAAM,SAAS,MAAM,KAAK,oBAAoB,OAAO,QAAQ;AAC7D,OAAK,cAAc;AACnB,MAAI,KAAK,QAAQ,uBACf,OAAM,KAAK,QAAQ,uBAAuB,QAAQ,QAAQ;EAG5D,MAAM,QAAQ,MAAM,KAAK,cAAc,QAAQ,OAAO,gBAAgB;AACtE,OAAK,QAAQ;AACb,MAAI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