@medicine-wheel/prompt-decomposition 0.2.2
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/README.md +93 -0
- package/dist/decomposer.d.ts +61 -0
- package/dist/decomposer.d.ts.map +1 -0
- package/dist/decomposer.js +593 -0
- package/dist/decomposer.js.map +1 -0
- package/dist/index.browser.d.ts +10 -0
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.browser.js +19 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/relational_enricher.d.ts +55 -0
- package/dist/relational_enricher.d.ts.map +1 -0
- package/dist/relational_enricher.js +142 -0
- package/dist/relational_enricher.js.map +1 -0
- package/dist/storage.d.ts +16 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +181 -0
- package/dist/storage.js.map +1 -0
- package/dist/types.d.ts +143 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @medicine-wheel/prompt-decomposition
|
|
2
|
+
|
|
3
|
+
Ontology-enriched prompt decomposition engine for the Medicine Wheel Developer Suite.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Extracts structured intents from natural language prompts and classifies them across the Four Directions (East/vision, South/analysis, West/validation, North/action). Detects implicit intents from hedging language, maps dependencies between tasks, and generates ceremony guidance when directional balance is poor.
|
|
8
|
+
|
|
9
|
+
**Lineage:** `mcp-pde` → `ava-langchain-prompt-decomposition` → `@medicine-wheel/prompt-decomposition`
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @medicine-wheel/prompt-decomposition
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Basic Decomposition
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { MedicineWheelDecomposer } from '@medicine-wheel/prompt-decomposition';
|
|
23
|
+
|
|
24
|
+
const decomposer = new MedicineWheelDecomposer({
|
|
25
|
+
extractImplicit: true,
|
|
26
|
+
mapDependencies: true,
|
|
27
|
+
ceremonyThreshold: 0.3,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const result = decomposer.decompose(
|
|
31
|
+
'Research the ontology types, then implement the query builder, and validate with tests'
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
console.log(result.primary); // { action: 'investigate', target: '...', urgency: 'session', confidence: 0.85 }
|
|
35
|
+
console.log(result.balance); // 0.75 (directional balance score)
|
|
36
|
+
console.log(result.neglectedDirections); // ['east'] (vision direction neglected)
|
|
37
|
+
console.log(result.ceremonyRequired); // true/false
|
|
38
|
+
console.log(result.actionStack); // Ordered tasks: east→south→west→north
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Relational Enrichment
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { RelationalEnricher } from '@medicine-wheel/prompt-decomposition';
|
|
45
|
+
|
|
46
|
+
const enricher = new RelationalEnricher();
|
|
47
|
+
const enriched = enricher.enrich(decomposition, {
|
|
48
|
+
nodes: myNodes,
|
|
49
|
+
edges: myEdges,
|
|
50
|
+
relations: myRelations,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
console.log(enriched.relationalHealth); // 0-1 composite score
|
|
54
|
+
console.log(enriched.accountabilityGaps); // Where attention is needed
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Storage
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { saveDecomposition, loadDecomposition, listDecompositions } from '@medicine-wheel/prompt-decomposition';
|
|
61
|
+
|
|
62
|
+
const stored = saveDecomposition('.', result);
|
|
63
|
+
// Creates .pde/{id}.json and .pde/{id}.md
|
|
64
|
+
|
|
65
|
+
const loaded = loadDecomposition('.', result.id);
|
|
66
|
+
const all = listDecompositions('.');
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## API
|
|
70
|
+
|
|
71
|
+
### `MedicineWheelDecomposer`
|
|
72
|
+
|
|
73
|
+
- `decompose(prompt: string): OntologicalDecomposition` — Full Four Directions decomposition
|
|
74
|
+
|
|
75
|
+
### `RelationalEnricher`
|
|
76
|
+
|
|
77
|
+
- `enrich(decomposition, graph): EnrichmentResult` — Enrich with graph context
|
|
78
|
+
|
|
79
|
+
### Storage Functions
|
|
80
|
+
|
|
81
|
+
- `saveDecomposition(workdir, result): StoredDecomposition`
|
|
82
|
+
- `loadDecomposition(workdir, id): StoredDecomposition | null`
|
|
83
|
+
- `listDecompositions(workdir): StoredDecomposition[]`
|
|
84
|
+
- `decompositionToMarkdown(result): string`
|
|
85
|
+
|
|
86
|
+
## Dependencies
|
|
87
|
+
|
|
88
|
+
- `@medicine-wheel/ontology-core` ^0.1.0
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|
|
93
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @medicine-wheel/prompt-decomposition — Decomposer
|
|
3
|
+
*
|
|
4
|
+
* Ontology-enriched prompt decomposition engine.
|
|
5
|
+
* Reuses the PDE patterns from ava-langchain-prompt-decomposition
|
|
6
|
+
* but grounds them in @medicine-wheel/ontology-core types.
|
|
7
|
+
*
|
|
8
|
+
* Design:
|
|
9
|
+
* - Keyword-based directional classification (same algorithm as langchainjs)
|
|
10
|
+
* - Intent extraction with hedging language detection (mcp-pde lineage)
|
|
11
|
+
* - Dependency mapping with directional inference
|
|
12
|
+
* - Ontological enrichment with Ojibwe names, seasons, acts, obligations
|
|
13
|
+
* - Ceremony guidance based on directional balance
|
|
14
|
+
*/
|
|
15
|
+
import type { OntologicalDecomposition, DecomposerOptions, EpistemicSourceHint } from './types.js';
|
|
16
|
+
export declare class MedicineWheelDecomposer {
|
|
17
|
+
private readonly extractImplicit;
|
|
18
|
+
private readonly mapDependencies;
|
|
19
|
+
private readonly ceremonyThreshold;
|
|
20
|
+
constructor(options?: DecomposerOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Decompose a prompt into an ontology-enriched result.
|
|
23
|
+
* Flows through Four Directions: EAST → SOUTH → WEST → NORTH
|
|
24
|
+
*/
|
|
25
|
+
decompose(prompt: string): OntologicalDecomposition;
|
|
26
|
+
private classifyByDirection;
|
|
27
|
+
private scoreSegment;
|
|
28
|
+
private topDirection;
|
|
29
|
+
private extractIntents;
|
|
30
|
+
private calculateConfidence;
|
|
31
|
+
private detectUrgency;
|
|
32
|
+
private extractContext;
|
|
33
|
+
private enrichWithDirections;
|
|
34
|
+
private inferDirection;
|
|
35
|
+
private inferObligations;
|
|
36
|
+
private inferDependencies;
|
|
37
|
+
private topicsRelated;
|
|
38
|
+
private buildOntologicalDirections;
|
|
39
|
+
private assessBalance;
|
|
40
|
+
private checkCeremonyRequired;
|
|
41
|
+
private generateCeremonyGuidance;
|
|
42
|
+
private computeWilsonAlignment;
|
|
43
|
+
private detectAmbiguities;
|
|
44
|
+
private extractExpectedOutputs;
|
|
45
|
+
private buildActionStack;
|
|
46
|
+
private generateNarrativeBeats;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Heuristic classification of epistemic source from language patterns.
|
|
50
|
+
*
|
|
51
|
+
* Scans text for keywords associated with each of Wilson's four
|
|
52
|
+
* epistemic sources and returns the best match. Returns 'unknown'
|
|
53
|
+
* when no clear signal is present.
|
|
54
|
+
*
|
|
55
|
+
* - **land**: mentions of place, territory, walking, embodied experience
|
|
56
|
+
* - **dream**: mentions of vision, dream, intuition, liminal space
|
|
57
|
+
* - **code**: mentions of implementation, function, algorithm, structure
|
|
58
|
+
* - **vision**: mentions of intention, aspiration, future, purpose
|
|
59
|
+
*/
|
|
60
|
+
export declare function detectEpistemicSource(text: string): EpistemicSourceHint;
|
|
61
|
+
//# sourceMappingURL=decomposer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decomposer.d.ts","sourceRoot":"","sources":["../src/decomposer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAOH,OAAO,KAAK,EACV,wBAAwB,EAWxB,iBAAiB,EAEjB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAgEpB,qBAAa,uBAAuB;IAClC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAU;IAC1C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAU;IAC1C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;gBAE/B,OAAO,CAAC,EAAE,iBAAiB;IAMvC;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,wBAAwB;IAiEnD,OAAO,CAAC,mBAAmB;IAgC3B,OAAO,CAAC,YAAY;IAmBpB,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,cAAc;IA2EtB,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,cAAc;IA2BtB,OAAO,CAAC,oBAAoB;IAY5B,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,gBAAgB;IAaxB,OAAO,CAAC,iBAAiB;IAkCzB,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,0BAA0B;IAsBlC,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,qBAAqB;IAW7B,OAAO,CAAC,wBAAwB;IAahC,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,iBAAiB;IAyCzB,OAAO,CAAC,sBAAsB;IAmB9B,OAAO,CAAC,gBAAgB;IA0BxB,OAAO,CAAC,sBAAsB;CAa/B;AA4BD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAsCvE"}
|