@contractspec/module.product-intent-core 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.
- package/LICENSE +21 -0
- package/README.md +17 -0
- package/dist/evidence/keyword-retriever.d.ts +16 -0
- package/dist/evidence/keyword-retriever.d.ts.map +1 -0
- package/dist/evidence/keyword-retriever.js +23 -0
- package/dist/evidence/keyword-retriever.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/orchestrator/product-intent-orchestrator.d.ts +23 -0
- package/dist/orchestrator/product-intent-orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/product-intent-orchestrator.js +97 -0
- package/dist/orchestrator/product-intent-orchestrator.js.map +1 -0
- package/dist/types.d.ts +35 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +61 -0
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,17 @@
|
|
|
1
|
+
# @contractspec/module.product-intent-core
|
|
2
|
+
|
|
3
|
+
Website: https://contractspec.io/
|
|
4
|
+
|
|
5
|
+
Core orchestration logic for the product-intent workflow. This module wires evidence retrieval, prompt execution, and validators into a deterministic discovery pipeline.
|
|
6
|
+
|
|
7
|
+
## What it provides
|
|
8
|
+
|
|
9
|
+
- A `ProductIntentOrchestrator` that runs the discovery loop end-to-end.
|
|
10
|
+
- A keyword-based evidence fetcher for deterministic retrieval.
|
|
11
|
+
- Type-safe interfaces for model runners and orchestration options.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bun add @contractspec/module.product-intent-core
|
|
17
|
+
```
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
6
|
+
}
|
|
7
|
+
declare const createKeywordEvidenceFetcher: (chunks: EvidenceChunk[], options?: KeywordEvidenceOptions) => ({
|
|
8
|
+
query,
|
|
9
|
+
maxChunks
|
|
10
|
+
}: {
|
|
11
|
+
query: string;
|
|
12
|
+
maxChunks?: number;
|
|
13
|
+
}) => Promise<EvidenceChunk[]>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { KeywordEvidenceOptions, createKeywordEvidenceFetcher };
|
|
16
|
+
//# sourceMappingURL=keyword-retriever.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +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 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ProductIntentOrchestrator };
|
|
23
|
+
//# sourceMappingURL=product-intent-orchestrator.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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":"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"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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>;
|
|
7
|
+
}
|
|
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>;
|
|
22
|
+
}
|
|
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;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { ProductIntentModelRunner, ProductIntentOrchestratorOptions, ProductIntentOrchestratorParams };
|
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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,OAAA;EACL,gBAAA,IAAoB,KAAA,EAAO,iBAAA,EAAmB,GAAA,GAAM,OAAA,KAAY,OAAA;EAChE,iBAAA,IAAqB,MAAA,EAAQ,YAAA,EAAc,GAAA,GAAM,OAAA,KAAY,OAAA;EAC7D,gBAAA,IAAoB,KAAA,EAAO,QAAA,EAAU,GAAA,GAAM,OAAA,KAAY,OAAA;AAAA;AAAA,UAGxC,+BAAA;EACf,EAAA;EACA,IAAA,EAAM,iBAAA;EACN,QAAA;EACA,OAAA,GAAU,OAAA;EACV,iBAAA;EACA,eAAA;EACA,kBAAA;EACA,WAAA;AAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contractspec/module.product-intent-core",
|
|
3
|
+
"version": "0.0.0-canary-20260206014742",
|
|
4
|
+
"description": "Core product intent orchestration and adapters",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"contractspec",
|
|
7
|
+
"product-intent",
|
|
8
|
+
"module",
|
|
9
|
+
"discovery",
|
|
10
|
+
"pm",
|
|
11
|
+
"ai"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
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",
|
|
26
|
+
"clean": "rimraf dist .turbo",
|
|
27
|
+
"lint": "bun lint:fix",
|
|
28
|
+
"lint:fix": "eslint src --fix",
|
|
29
|
+
"lint:check": "eslint src",
|
|
30
|
+
"test": "bun test"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@contractspec/lib.contracts": "0.0.0-canary-20260206014742",
|
|
34
|
+
"@contractspec/lib.product-intent-utils": "0.0.0-canary-20260206014742"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@contractspec/tool.tsdown": "0.0.0-canary-20260206014742",
|
|
38
|
+
"@contractspec/tool.typescript": "0.0.0-canary-20260206014742",
|
|
39
|
+
"tsdown": "^0.20.3",
|
|
40
|
+
"typescript": "^5.9.3"
|
|
41
|
+
},
|
|
42
|
+
"exports": {
|
|
43
|
+
".": "./dist/index.js",
|
|
44
|
+
"./*": "./*"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"exports": {
|
|
49
|
+
".": "./dist/index.js",
|
|
50
|
+
"./*": "./*"
|
|
51
|
+
},
|
|
52
|
+
"registry": "https://registry.npmjs.org/"
|
|
53
|
+
},
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "https://github.com/lssm-tech/contractspec.git",
|
|
58
|
+
"directory": "packages/modules/product-intent-core"
|
|
59
|
+
},
|
|
60
|
+
"homepage": "https://contractspec.io"
|
|
61
|
+
}
|