@medicine-wheel/narrative-engine 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 ADDED
@@ -0,0 +1,72 @@
1
+ # @medicine-wheel/narrative-engine
2
+
3
+ Beat sequencing, arc validation, cadence patterns, and timeline building for the Medicine Wheel Developer Suite.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @medicine-wheel/narrative-engine
9
+ ```
10
+
11
+ ## Modules
12
+
13
+ ### Sequencer
14
+ Order and validate narrative beats across the four-direction, four-act structure.
15
+
16
+ ```ts
17
+ import { sequenceBeats, insertBeat, nextDirection, suggestNextBeat } from '@medicine-wheel/narrative-engine';
18
+
19
+ const positions = sequenceBeats(beats);
20
+ const suggestion = suggestNextBeat(beats); // { direction: 'west', act: 3 }
21
+ ```
22
+
23
+ ### Cadence
24
+ Ceremonial timing rules mapping directions to phases: East→opening, South→deepening, West→integrating, North→closing.
25
+
26
+ ```ts
27
+ import { validateCadence, STANDARD_CADENCE, currentPhase } from '@medicine-wheel/narrative-engine';
28
+
29
+ const validation = validateCadence(beats, ceremonies, STANDARD_CADENCE);
30
+ console.log(validation.phasesCompleted, validation.violations);
31
+ ```
32
+
33
+ ### Arc Validator
34
+ Validate narrative completeness — direction coverage, ceremony presence, Wilson alignment, OCAP® compliance.
35
+
36
+ ```ts
37
+ import { validateArc } from '@medicine-wheel/narrative-engine';
38
+
39
+ const result = validateArc(beats, ceremonies, relations);
40
+ console.log(result.completeness.completenessScore); // 0–1
41
+ console.log(result.recommendations);
42
+ ```
43
+
44
+ ### Timeline
45
+ Generate timeline data for visualization along chronological, directional, or ceremonial axes.
46
+
47
+ ```ts
48
+ import { buildTimeline, actStrip } from '@medicine-wheel/narrative-engine';
49
+
50
+ const tl = buildTimeline(beats, { axis: 'directional' });
51
+ const strip = actStrip(beats); // 4 acts with beats per direction
52
+ ```
53
+
54
+ ### Cycle Manager
55
+ Orchestrate full Medicine Wheel cycles with transition tracking and progress suggestions.
56
+
57
+ ```ts
58
+ import { createCycle, computeProgress } from '@medicine-wheel/narrative-engine';
59
+
60
+ const cycle = createCycle('c1', 'How do trees teach?');
61
+ const progress = computeProgress(cycle, beats, ceremonies, relations);
62
+ console.log(progress.suggestedAction); // "Move to the west direction (integrating phase)"
63
+ ```
64
+
65
+ ## Peer dependency
66
+
67
+ Requires `@medicine-wheel/ontology-core` ^0.1.0.
68
+
69
+ ## License
70
+
71
+ MIT
72
+
package/dist/arc.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Arc Validator — validates narrative completeness and relational integrity
3
+ * across a full Medicine Wheel cycle.
4
+ */
5
+ import type { NarrativeBeat, CeremonyLog, Relation } from '@medicine-wheel/ontology-core';
6
+ import type { ArcCompleteness, ArcValidationResult } from './types.js';
7
+ /** Compute the completeness of a narrative arc */
8
+ export declare function computeCompleteness(beats: NarrativeBeat[], ceremonies: CeremonyLog[], relations: Relation[]): ArcCompleteness;
9
+ /** Validate a complete narrative arc */
10
+ export declare function validateArc(beats: NarrativeBeat[], ceremonies: CeremonyLog[], relations: Relation[]): ArcValidationResult;
11
+ /** Quick check: has a cycle visited all four directions? */
12
+ export declare function isArcComplete(beats: NarrativeBeat[]): boolean;
13
+ //# sourceMappingURL=arc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arc.d.ts","sourceRoot":"","sources":["../src/arc.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EACV,aAAa,EAGb,WAAW,EACX,QAAQ,EACT,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EACV,eAAe,EAEf,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAIpB,kDAAkD;AAClD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,aAAa,EAAE,EACtB,UAAU,EAAE,WAAW,EAAE,EACzB,SAAS,EAAE,QAAQ,EAAE,GACpB,eAAe,CAsCjB;AAcD,wCAAwC;AACxC,wBAAgB,WAAW,CACzB,KAAK,EAAE,aAAa,EAAE,EACtB,UAAU,EAAE,WAAW,EAAE,EACzB,SAAS,EAAE,QAAQ,EAAE,GACpB,mBAAmB,CA0ErB;AAED,4DAA4D;AAC5D,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,OAAO,CAG7D"}
package/dist/arc.js ADDED
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeCompleteness = computeCompleteness;
4
+ exports.validateArc = validateArc;
5
+ exports.isArcComplete = isArcComplete;
6
+ const ontology_core_1 = require("@medicine-wheel/ontology-core");
7
+ const ALL_DIRECTIONS = ['east', 'south', 'west', 'north'];
8
+ /** Compute the completeness of a narrative arc */
9
+ function computeCompleteness(beats, ceremonies, relations) {
10
+ const directionsVisited = [...new Set(beats.map(b => b.direction))];
11
+ const directionsMissing = ALL_DIRECTIONS.filter(d => !directionsVisited.includes(d));
12
+ const beatsPerDirection = { east: 0, south: 0, west: 0, north: 0 };
13
+ for (const beat of beats) {
14
+ beatsPerDirection[beat.direction]++;
15
+ }
16
+ const ceremoniesPerDirection = { east: 0, south: 0, west: 0, north: 0 };
17
+ for (const ceremony of ceremonies) {
18
+ if (ceremony.direction) {
19
+ ceremoniesPerDirection[ceremony.direction]++;
20
+ }
21
+ }
22
+ // Wilson alignment across all relations
23
+ const wilsonAlignment = (0, ontology_core_1.aggregateWilsonAlignment)(relations);
24
+ // OCAP compliance
25
+ const ocapCompliant = relations.every(r => !r.ocap || (0, ontology_core_1.checkOcapCompliance)(r.ocap).compliant);
26
+ // Completeness score: weighted average
27
+ const directionScore = directionsVisited.length / 4;
28
+ const ceremonyScore = ALL_DIRECTIONS.filter(d => ceremoniesPerDirection[d] > 0).length / 4;
29
+ const balanceScore = computeBalance(beatsPerDirection);
30
+ const completenessScore = (directionScore * 0.3) + (ceremonyScore * 0.25) + (wilsonAlignment * 0.25) + (balanceScore * 0.2);
31
+ return {
32
+ complete: directionsMissing.length === 0 && completenessScore >= 0.7,
33
+ directionsVisited,
34
+ directionsMissing,
35
+ ceremoniesPerDirection,
36
+ beatsPerDirection,
37
+ wilsonAlignment,
38
+ ocapCompliant,
39
+ completenessScore: Math.round(completenessScore * 100) / 100,
40
+ };
41
+ }
42
+ /** Compute balance across directions (1.0 = perfectly balanced) */
43
+ function computeBalance(beatsPerDirection) {
44
+ const counts = Object.values(beatsPerDirection);
45
+ const total = counts.reduce((s, c) => s + c, 0);
46
+ if (total === 0)
47
+ return 0;
48
+ const ideal = total / 4;
49
+ const deviation = counts.reduce((sum, c) => sum + Math.abs(c - ideal), 0);
50
+ const maxDeviation = total; // worst case: all beats in one direction
51
+ return 1 - (deviation / maxDeviation);
52
+ }
53
+ /** Validate a complete narrative arc */
54
+ function validateArc(beats, ceremonies, relations) {
55
+ const completeness = computeCompleteness(beats, ceremonies, relations);
56
+ const violations = [];
57
+ const recommendations = [];
58
+ // Missing directions
59
+ for (const dir of completeness.directionsMissing) {
60
+ violations.push({
61
+ type: 'missing_direction',
62
+ direction: dir,
63
+ message: `Direction '${dir}' has no beats`,
64
+ severity: 'error',
65
+ });
66
+ recommendations.push(`Add at least one beat in the ${dir} direction`);
67
+ }
68
+ // Directions without ceremonies
69
+ for (const dir of ALL_DIRECTIONS) {
70
+ if (completeness.ceremoniesPerDirection[dir] === 0 && completeness.beatsPerDirection[dir] > 0) {
71
+ violations.push({
72
+ type: 'no_ceremony',
73
+ direction: dir,
74
+ message: `Direction '${dir}' has beats but no ceremony`,
75
+ severity: 'warning',
76
+ });
77
+ recommendations.push(`Consider conducting a ceremony in the ${dir} direction`);
78
+ }
79
+ }
80
+ // Low Wilson alignment
81
+ if (completeness.wilsonAlignment < 0.5 && relations.length > 0) {
82
+ violations.push({
83
+ type: 'low_wilson',
84
+ message: `Wilson alignment is ${(completeness.wilsonAlignment * 100).toFixed(0)}% (below 50% threshold)`,
85
+ severity: 'warning',
86
+ });
87
+ recommendations.push('Strengthen relational accountability — review obligations and reciprocity');
88
+ }
89
+ // OCAP compliance gaps
90
+ if (!completeness.ocapCompliant) {
91
+ violations.push({
92
+ type: 'ocap_gap',
93
+ message: 'Not all relations are OCAP®-compliant',
94
+ severity: 'error',
95
+ });
96
+ recommendations.push('Review data sovereignty flags on all relations — ensure ownership, control, access, and possession');
97
+ }
98
+ // Balance check
99
+ const balance = computeBalance(completeness.beatsPerDirection);
100
+ if (balance < 0.5 && beats.length >= 4) {
101
+ const maxDir = ALL_DIRECTIONS.reduce((a, b) => completeness.beatsPerDirection[a] > completeness.beatsPerDirection[b] ? a : b);
102
+ const minDir = ALL_DIRECTIONS.reduce((a, b) => completeness.beatsPerDirection[a] < completeness.beatsPerDirection[b] ? a : b);
103
+ violations.push({
104
+ type: 'unbalanced',
105
+ message: `Beats are unbalanced: '${maxDir}' has ${completeness.beatsPerDirection[maxDir]}, '${minDir}' has ${completeness.beatsPerDirection[minDir]}`,
106
+ severity: 'info',
107
+ });
108
+ recommendations.push(`Balance the arc — add beats in '${minDir}' direction`);
109
+ }
110
+ const errorCount = violations.filter(v => v.severity === 'error').length;
111
+ return {
112
+ valid: errorCount === 0 && completeness.complete,
113
+ completeness,
114
+ violations,
115
+ recommendations,
116
+ };
117
+ }
118
+ /** Quick check: has a cycle visited all four directions? */
119
+ function isArcComplete(beats) {
120
+ const visited = new Set(beats.map(b => b.direction));
121
+ return ALL_DIRECTIONS.every(d => visited.has(d));
122
+ }
123
+ //# sourceMappingURL=arc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arc.js","sourceRoot":"","sources":["../src/arc.ts"],"names":[],"mappings":";;AAqBA,kDA0CC;AAeD,kCA8EC;AAGD,sCAGC;AAvJD,iEAA8F;AAO9F,MAAM,cAAc,GAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAE3E,kDAAkD;AAClD,SAAgB,mBAAmB,CACjC,KAAsB,EACtB,UAAyB,EACzB,SAAqB;IAErB,MA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AC,CAAC;QACH,eAAe,CAAC,IAAI,CAAC,mCAAmC,MAAM,aAAa,CAAC,CAAC;IAC/E,CAAC;IAED,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,MAAM,CAAC;IAEzE,OAAO;QACL,KAAK,EAAE,UAAU,KAAK,CAAC,IAAI,YAAY,CAAC,QAAQ;QAChD,YAAY;QACZ,UAAU;QACV,eAAe;KAChB,CAAC;AACJ,CAAC;AAED,4DAA4D;AAC5D,SAAgB,aAAa,CAAC,KAAsB;IAClD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACrD,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Cadence Patterns — ceremonial timing rules for narrative progression.
3
+ *
4
+ * A cadence maps the four directions to four phases:
5
+ * East → opening, South → deepening, West → integrating, North → closing
6
+ */
7
+ import type { NarrativeBeat, DirectionName, CeremonyLog } from '@medicine-wheel/ontology-core';
8
+ import type { CadencePattern, CadencePhase, CadenceValidation } from './types.js';
9
+ /** The standard four-direction cadence pattern */
10
+ export declare const STANDARD_CADENCE: CadencePattern;
11
+ /** A lighter cadence — ceremonies only at opening and closing */
12
+ export declare const LIGHT_CADENCE: CadencePattern;
13
+ /** Determine the current cadence phase from beats */
14
+ export declare function currentPhase(beats: NarrativeBeat[]): CadencePhase;
15
+ /** Map a direction to its cadence phase */
16
+ export declare function directionToPhase(direction: DirectionName): CadencePhase;
17
+ /** Map a cadence phase to its direction */
18
+ export declare function phaseToDirection(phase: CadencePhase): DirectionName;
19
+ /** Validate beats against a cadence pattern */
20
+ export declare function validateCadence(beats: NarrativeBeat[], ceremonies: CeremonyLog[], pattern?: CadencePattern): CadenceValidation;
21
+ /** Detect direction transitions in beat sequence */
22
+ export declare function detectTransitions(beats: NarrativeBeat[]): Array<{
23
+ from: DirectionName;
24
+ to: DirectionName;
25
+ beatIndex: number;
26
+ }>;
27
+ //# sourceMappingURL=cadence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cadence.d.ts","sourceRoot":"","sources":["../src/cadence.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC/F,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EAEZ,iBAAiB,EAElB,MAAM,YAAY,CAAC;AAkBpB,kDAAkD;AAClD,eAAO,MAAM,gBAAgB,EAAE,cAS9B,CAAC;AAEF,iEAAiE;AACjE,eAAO,MAAM,aAAa,EAAE,cAS3B,CAAC;AAEF,qDAAqD;AACrD,wBAAgB,YAAY,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,YAAY,CAIjE;AAED,2CAA2C;AAC3C,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,aAAa,GAAG,YAAY,CAEvE;AAED,2CAA2C;AAC3C,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,YAAY,GAAG,aAAa,CAEnE;AAED,+CAA+C;AAC/C,wBAAgB,eAAe,CAC7B,KAAK,EAAE,aAAa,EAAE,EACtB,UAAU,EAAE,WAAW,EAAE,EACzB,OAAO,GAAE,cAAiC,GACzC,iBAAiB,CAoEnB;AAED,oDAAoD;AACpD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC;IAC/D,IAAI,EAAE,aAAa,CAAC;IACpB,EAAE,EAAE,aAAa,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC,CAYD"}
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LIGHT_CADENCE = exports.STANDARD_CADENCE = void 0;
4
+ exports.currentPhase = currentPhase;
5
+ exports.directionToPhase = directionToPhase;
6
+ exports.phaseToDirection = phaseToDirection;
7
+ exports.validateCadence = validateCadence;
8
+ exports.detectTransitions = detectTransitions;
9
+ const PHASE_DIRECTION = {
10
+ opening: 'east',
11
+ deepening: 'south',
12
+ integrating: 'west',
13
+ closing: 'north',
14
+ };
15
+ const DIRECTION_PHASE = {
16
+ east: 'opening',
17
+ south: 'deepening',
18
+ west: 'integrating',
19
+ north: 'closing',
20
+ };
21
+ const PHASE_ORDER = ['opening', 'deepening', 'integrating', 'closing'];
22
+ /** The standard four-direction cadence pattern */
23
+ exports.STANDARD_CADENCE = {
24
+ name: 'Standard Four-Direction Cadence',
25
+ description: 'Balanced progression through all four directions with ceremony at each transition',
26
+ phases: [
27
+ { phase: 'opening', direction: 'east', requiresCeremony: true, minBeats: 1, maxBeats: 4 },
28
+ { phase: 'deepening', direction: 'south', requiresCeremony: true, minBeats: 1, maxBeats: 4 },
29
+ { phase: 'integrating', direction: 'west', requiresCeremony: true, minBeats: 1, maxBeats: 4 },
30
+ { phase: 'closing', direction: 'north', requiresCeremony: true, minBeats: 1, maxBeats: 4 },
31
+ ],
32
+ };
33
+ /** A lighter cadence — ceremonies only at opening and closing */
34
+ exports.LIGHT_CADENCE = {
35
+ name: 'Light Cadence',
36
+ description: 'Ceremonies at opening (East) and closing (North) only',
37
+ phases: [
38
+ { phase: 'opening', direction: 'east', requiresCeremony: true, minBeats: 1, maxBeats: 6 },
39
+ { phase: 'deepening', direction: 'south', requiresCeremony: false, minBeats: 1, maxBeats: 6 },
40
+ { phase: 'integrating', direction: 'west', requiresCeremony: false, minBeats: 1, maxBeats: 6 },
41
+ { phase: 'closing', direction: 'north', requiresCeremony: true, minBeats: 1, maxBeats: 6 },
42
+ ],
43
+ };
44
+ /** Determine the current cadence phase from beats */
45
+ function currentPhase(beats) {
46
+ if (beats.length === 0)
47
+ return 'opening';
48
+ const lastDirection = beats[beats.length - 1].direction;
49
+ return DIRECTION_PHASE[lastDirection];
50
+ }
51
+ /** Map a direction to its cadence phase */
52
+ function directionToPhase(direction) {
53
+ return DIRECTION_PHASE[direction];
54
+ }
55
+ /** Map a cadence phase to its direction */
56
+ function phaseToDirection(phase) {
57
+ return PHASE_DIRECTION[phase];
58
+ }
59
+ /** Validate beats against a cadence pattern */
60
+ function validateCadence(beats, ceremonies, pattern = exports.STANDARD_CADENCE) {
61
+ const violations = [];
62
+ // Group beats by direction → phase
63
+ const beatsByPhase = new Map();
64
+ for (const phase of PHASE_ORDER) {
65
+ beatsByPhase.set(phase, []);
66
+ }
67
+ for (const beat of beats) {
68
+ const phase = DIRECTION_PHASE[beat.direction];
69
+ beatsByPhase.get(phase).push(beat);
70
+ }
71
+ // Ceremony IDs referenced by beats
72
+ const ceremonyIds = new Set(ceremonies.map(c => c.id));
73
+ const phasesCompleted = [];
74
+ const phasesRemaining = [];
75
+ for (const rule of pattern.phases) {
76
+ const phaseBeats = beatsByPhase.get(rule.phase) ?? [];
77
+ if (phaseBeats.length === 0) {
78
+ phasesRemaining.push(rule.phase);
79
+ continue;
80
+ }
81
+ // Check min/max beats
82
+ if (phaseBeats.length < rule.minBeats) {
83
+ violations.push({
84
+ phase: rule.phase,
85
+ rule: 'minBeats',
86
+ message: `Phase '${rule.phase}' has ${phaseBeats.length} beats (minimum: ${rule.minBeats})`,
87
+ });
88
+ }
89
+ if (phaseBeats.length > rule.maxBeats) {
90
+ violations.push({
91
+ phase: rule.phase,
92
+ rule: 'maxBeats',
93
+ message: `Phase '${rule.phase}' has ${phaseBeats.length} beats (maximum: ${rule.maxBeats})`,
94
+ });
95
+ }
96
+ // Check ceremony requirement
97
+ if (rule.requiresCeremony) {
98
+ const hasCeremony = phaseBeats.some(b => b.ceremonies.some((cId) => ceremonyIds.has(cId)));
99
+ if (!hasCeremony) {
100
+ violations.push({
101
+ phase: rule.phase,
102
+ rule: 'requiresCeremony',
103
+ message: `Phase '${rule.phase}' requires a ceremony but none found`,
104
+ });
105
+ }
106
+ }
107
+ phasesCompleted.push(rule.phase);
108
+ }
109
+ const phase = currentPhase(beats);
110
+ const errorViolations = violations.filter(v => v.rule === 'requiresCeremony' || v.rule === 'minBeats');
111
+ return {
112
+ valid: errorViolations.length === 0 && phasesRemaining.length === 0,
113
+ currentPhase: phase,
114
+ phasesCompleted,
115
+ phasesRemaining,
116
+ violations,
117
+ };
118
+ }
119
+ /** Detect direction transitions in beat sequence */
120
+ function detectTransitions(beats) {
121
+ const transitions = [];
122
+ for (let i = 1; i < beats.length; i++) {
123
+ if (beats[i].direction !== beats[i - 1].direction) {
124
+ transitions.push({
125
+ from: beats[i - 1].direction,
126
+ to: beats[i].direction,
127
+ beatIndex: i,
128
+ });
129
+ }
130
+ }
131
+ return transitions;
132
+ }
133
+ //# sourceMappingURL=cadence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cadence.js","sourceRoot":"","sources":["../src/cadence.ts"],"names":[],"mappings":";;;AAwDA,oCAIC;AAGD,4CAEC;AAGD,4CAEC;AAGD,0CAwEC;AAGD,8CAgBC;AArJD,MAAM,eAAe,GAAwC;IAC3D,OAAO,EAAE,MAAM;IACf,SAAS,EAAE,OAAO;IAClB,WAAW,EAAE,MAAM;IACnB,OAAO,EAAE,OAAO;CACjB,CAAC;AAEF,MAAM,eAAe,GAAwC;IAC3D,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,WAAW;IAClB,IAAI,EAAE,aAAa;IACnB,KAAK,EAAE,SAAS;CACjB,CAAC;AAEF,MAAM,WAAW,GAAmB,CAAC,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;AAEvF,kDAAkD;AACrC,QAAA,gBAAgB,GAAmB;IAC9C,IAAI,EAAE,iCAAiC;IACvC,WAAW,EAAE,mFAAmF;IAChG,MAAM,EAAE;QACN,EAAE,KAAK,EAAE,SAAS,EAAO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,CAAC,KAAK,sCAAsC;iBACpE,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,kBAAkB,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;IAEvG,OAAO;QACL,KAAK,EAAE,eAAe,CAAC,MAAM,KAAK,CAAC,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC;QACnE,YAAY,EAAE,KAAK;QACnB,eAAe;QACf,eAAe;QACf,UAAU;KACX,CAAC;AACJ,CAAC;AAED,oDAAoD;AACpD,SAAgB,iBAAiB,CAAC,KAAsB;IAKtD,MAAM,WAAW,GAAyE,EAAE,CAAC;IAC7F,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;YAClD,WAAW,CAAC,IAAI,CAAC;gBACf,IAAI,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS;gBAC5B,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS;gBACtB,SAAS,EAAE,CAAC;aACb,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Cycle Manager — orchestrates a full Medicine Wheel narrative cycle,
3
+ * tracking transitions, progress, and suggesting next steps.
4
+ */
5
+ import type { NarrativeBeat, MedicineWheelCycle, CeremonyLog, Relation } from '@medicine-wheel/ontology-core';
6
+ import type { CycleTransition, CycleProgress } from './types.js';
7
+ /** Extract direction transitions from a beat sequence */
8
+ export declare function extractTransitions(beats: NarrativeBeat[], ceremonies: CeremonyLog[]): CycleTransition[];
9
+ /** Compute full cycle progress */
10
+ export declare function computeProgress(cycle: MedicineWheelCycle, beats: NarrativeBeat[], ceremonies: CeremonyLog[], relations: Relation[]): CycleProgress;
11
+ /** Create a new cycle with initial metadata */
12
+ export declare function createCycle(id: string, researchQuestion: string): MedicineWheelCycle;
13
+ /** Update cycle metadata from current beats/ceremonies/relations */
14
+ export declare function updateCycleMetadata(cycle: MedicineWheelCycle, beats: NarrativeBeat[], ceremonies: CeremonyLog[], relations: Relation[]): MedicineWheelCycle;
15
+ //# sourceMappingURL=cycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cycle.d.ts","sourceRoot":"","sources":["../src/cycle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAElB,WAAW,EACX,QAAQ,EACT,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAKjE,yDAAyD;AACzD,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EAAE,EACtB,UAAU,EAAE,WAAW,EAAE,GACxB,eAAe,EAAE,CAkBnB;AAED,kCAAkC;AAClC,wBAAgB,eAAe,CAC7B,KAAK,EAAE,kBAAkB,EACzB,KAAK,EAAE,aAAa,EAAE,EACtB,UAAU,EAAE,WAAW,EAAE,EACzB,SAAS,EAAE,QAAQ,EAAE,GACpB,aAAa,CAwCf;AAED,+CAA+C;AAC/C,wBAAgB,WAAW,CACzB,EAAE,EAAE,MAAM,EACV,gBAAgB,EAAE,MAAM,GACvB,kBAAkB,CAYpB;AAED,oEAAoE;AACpE,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,kBAAkB,EACzB,KAAK,EAAE,aAAa,EAAE,EACtB,UAAU,EAAE,WAAW,EAAE,EACzB,SAAS,EAAE,QAAQ,EAAE,GACpB,kBAAkB,CAapB"}
package/dist/cycle.js ADDED
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractTransitions = extractTransitions;
4
+ exports.computeProgress = computeProgress;
5
+ exports.createCycle = createCycle;
6
+ exports.updateCycleMetadata = updateCycleMetadata;
7
+ const cadence_js_1 = require("./cadence.js");
8
+ const arc_js_1 = require("./arc.js");
9
+ const sequencer_js_1 = require("./sequencer.js");
10
+ /** Extract direction transitions from a beat sequence */
11
+ function extractTransitions(beats, ceremonies) {
12
+ const transitions = [];
13
+ const ceremonyIds = new Set(ceremonies.map(c => c.id));
14
+ for (let i = 1; i < beats.length; i++) {
15
+ if (beats[i].direction !== beats[i - 1].direction) {
16
+ const transitionBeat = beats[i];
17
+ transitions.push({
18
+ from: beats[i - 1].direction,
19
+ to: beats[i].direction,
20
+ timestamp: transitionBeat.timestamp,
21
+ ceremonyConducted: transitionBeat.ceremonies.some((cId) => ceremonyIds.has(cId)),
22
+ beat: transitionBeat,
23
+ });
24
+ }
25
+ }
26
+ return transitions;
27
+ }
28
+ /** Compute full cycle progress */
29
+ function computeProgress(cycle, beats, ceremonies, relations) {
30
+ const transitions = extractTransitions(beats, ceremonies);
31
+ const phase = (0, cadence_js_1.currentPhase)(beats);
32
+ const completeness = (0, arc_js_1.computeCompleteness)(beats, ceremonies, relations);
33
+ const next = (0, sequencer_js_1.nextDirection)(beats);
34
+ let suggestedAction;
35
+ if (beats.length === 0) {
36
+ suggestedAction = 'Begin the cycle with a beat in the East (opening) direction';
37
+ }
38
+ else if (next) {
39
+ const phaseNames = {
40
+ east: 'opening',
41
+ south: 'deepening',
42
+ west: 'integrating',
43
+ north: 'closing',
44
+ };
45
+ suggestedAction = `Move to the ${next} direction (${phaseNames[next]} phase)`;
46
+ // Check if a ceremony is needed at the transition
47
+ const lastTransition = transitions[transitions.length - 1];
48
+ if (lastTransition && !lastTransition.ceremonyConducted) {
49
+ suggestedAction += ' — consider conducting a transition ceremony first';
50
+ }
51
+ }
52
+ else if (!completeness.ocapCompliant) {
53
+ suggestedAction = 'Review OCAP® compliance on relations before closing the cycle';
54
+ }
55
+ else if (completeness.wilsonAlignment < 0.7) {
56
+ suggestedAction = `Strengthen Wilson alignment (currently ${(completeness.wilsonAlignment * 100).toFixed(0)}%) before closing`;
57
+ }
58
+ else {
59
+ suggestedAction = 'All directions visited — the cycle is ready to close';
60
+ }
61
+ return {
62
+ cycle,
63
+ transitions,
64
+ currentPhase: phase,
65
+ completeness,
66
+ nextDirection: next,
67
+ suggestedAction,
68
+ };
69
+ }
70
+ /** Create a new cycle with initial metadata */
71
+ function createCycle(id, researchQuestion) {
72
+ return {
73
+ id,
74
+ research_question: researchQuestion,
75
+ start_date: new Date().toISOString(),
76
+ current_direction: 'east',
77
+ beats: [],
78
+ ceremonies_conducted: 0,
79
+ relations_mapped: 0,
80
+ wilson_alignment: 0,
81
+ ocap_compliant: true,
82
+ };
83
+ }
84
+ /** Update cycle metadata from current beats/ceremonies/relations */
85
+ function updateCycleMetadata(cycle, beats, ceremonies, relations) {
86
+ const completeness = (0, arc_js_1.computeCompleteness)(beats, ceremonies, relations);
87
+ const lastDirection = beats.length > 0 ? beats[beats.length - 1].direction : 'east';
88
+ return {
89
+ ...cycle,
90
+ current_direction: lastDirection,
91
+ beats: beats.map(b => b.id),
92
+ ceremonies_conducted: ceremonies.length,
93
+ relations_mapped: relations.length,
94
+ wilson_alignment: completeness.wilsonAlignment,
95
+ ocap_compliant: completeness.ocapCompliant,
96
+ };
97
+ }
98
+ //# sourceMappingURL=cycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cycle.js","sourceRoot":"","sources":["../src/cycle.ts"],"names":[],"mappings":";;AAiBA,gDAqBC;AAGD,0CA6CC;AAGD,kCAeC;AAGD,kDAkBC;AAjHD,6CAA4C;AAC5C,qCA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,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACpC,iBAAiB,EAAE,MAAM;QACzB,KAAK,EAAE,EAAE;QACT,oBAAoB,EAAE,CAAC;QACvB,gBAAgB,EAAE,CAAC;QACnB,gBAAgB,EAAE,CAAC;QACnB,cAAc,EAAE,IAAI;KACrB,CAAC;AACJ,CAAC;AAED,oEAAoE;AACpE,SAAgB,mBAAmB,CACjC,KAAyB,EACzB,KAAsB,EACtB,UAAyB,EACzB,SAAqB;IAErB,MAAM,YAAY,GAAG,IAAA,4BAAmB,EAAC,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;IACvE,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;IAEpF,OAAO;QACL,GAAG,KAAK;QACR,iBAAiB,EAAE,aAAa;QAChC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3B,oBAAoB,EAAE,UAAU,CAAC,MAAM;QACvC,gBAAgB,EAAE,SAAS,CAAC,MAAM;QAClC,gBAAgB,EAAE,YAAY,CAAC,eAAe;QAC9C,cAAc,EAAE,YAAY,CAAC,aAAa;KAC3C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @medicine-wheel/narrative-engine
3
+ *
4
+ * Beat sequencing, arc validation, cadence patterns, and timeline
5
+ * building for the Medicine Wheel Developer Suite.
6
+ */
7
+ export type { BeatPosition, BeatInsertResult, SequencerOptions, CadencePhase, CadencePattern, CadencePhaseRule, CadenceValidation, CadenceViolation, ArcCompleteness, ArcViolation, ArcValidationResult, TimelineAxis, TimelineEntry, TimelineData, TimelineGroup, TimelineOptions, CycleTransition, CycleProgress, EpistemicDepth, NarrativeTransformation, } from './types.js';
8
+ export { sequenceBeats, insertBeat, beatsByDirection, nextDirection, currentAct, suggestNextBeat, spiralOrder, detectEpistemicDeepening, findTransformationPoints, } from './sequencer.js';
9
+ export { STANDARD_CADENCE, LIGHT_CADENCE, currentPhase, directionToPhase, phaseToDirection, validateCadence, detectTransitions, } from './cadence.js';
10
+ export { computeCompleteness, validateArc, isArcComplete, } from './arc.js';
11
+ export { buildTimeline, actStrip, } from './timeline.js';
12
+ export { extractTransitions, computeProgress, createCycle, updateCycleMetadata, } from './cycle.js';
13
+ export { generateProvenanceNarrative, generateReciprocityObservation, generateDirectionObservation, getCeremonyPhaseFraming, describeSun, } from './rsis-narrative.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,EACb,cAAc,EACd,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,eAAe,EACf,WAAW,EACX,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,aAAa,GACd,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,aAAa,EACb,QAAQ,GACT,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,4BAA4B,EAC5B,uBAAuB,EACvB,WAAW,GACZ,MAAM,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ /**
3
+ * @medicine-wheel/narrative-engine
4
+ *
5
+ * Beat sequencing, arc validation, cadence patterns, and timeline
6
+ * building for the Medicine Wheel Developer Suite.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.describeSun = exports.getCeremonyPhaseFraming = exports.generateDirectionObservation = exports.generateReciprocityObservation = exports.generateProvenanceNarrative = exports.updateCycleMetadata = exports.createCycle = exports.computeProgress = exports.extractTransitions = exports.actStrip = exports.buildTimeline = exports.isArcComplete = exports.validateArc = exports.computeCompleteness = exports.detectTransitions = exports.validateCadence = exports.phaseToDirection = exports.directionToPhase = exports.currentPhase = exports.LIGHT_CADENCE = exports.STANDARD_CADENCE = exports.findTransformationPoints = exports.detectEpistemicDeepening = exports.spiralOrder = exports.suggestNextBeat = exports.currentAct = exports.nextDirection = exports.beatsByDirection = exports.insertBeat = exports.sequenceBeats = void 0;
10
+ // Sequencer
11
+ var sequencer_js_1 = require("./sequencer.js");
12
+ Object.defineProperty(exports, "sequenceBeats", { enumerable: true, get: function () { return sequencer_js_1.sequenceBeats; } });
13
+ Object.defineProperty(exports, "insertBeat", { enumerable: true, get: function () { return sequencer_js_1.insertBeat; } });
14
+ Object.defineProperty(exports, "beatsByDirection", { enumerable: true, get: function () { return sequencer_js_1.beatsByDirection; } });
15
+ Object.defineProperty(exports, "nextDirection", { enumerable: true, get: function () { return sequencer_js_1.nextDirection; } });
16
+ Object.defineProperty(exports, "currentAct", { enumerable: true, get: function () { return sequencer_js_1.currentAct; } });
17
+ Object.defineProperty(exports, "suggestNextBeat", { enumerable: true, get: function () { return sequencer_js_1.suggestNextBeat; } });
18
+ Object.defineProperty(exports, "spiralOrder", { enumerable: true, get: function () { return sequencer_js_1.spiralOrder; } });
19
+ Object.defineProperty(exports, "detectEpistemicDeepening", { enumerable: true, get: function () { return sequencer_js_1.detectEpistemicDeepening; } });
20
+ Object.defineProperty(exports, "findTransformationPoints", { enumerable: true, get: function () { return sequencer_js_1.findTransformationPoints; } });
21
+ // Cadence
22
+ var cadence_js_1 = require("./cadence.js");
23
+ Object.defineProperty(exports, "STANDARD_CADENCE", { enumerable: true, get: function () { return cadence_js_1.STANDARD_CADENCE; } });
24
+ Object.defineProperty(exports, "LIGHT_CADENCE", { enumerable: true, get: function () { return cadence_js_1.LIGHT_CADENCE; } });
25
+ Object.defineProperty(exports, "currentPhase", { enumerable: true, get: function () { return cadence_js_1.currentPhase; } });
26
+ Object.defineProperty(exports, "directionToPhase", { enumerable: true, get: function () { return cadence_js_1.directionToPhase; } });
27
+ Object.defineProperty(exports, "phaseToDirection", { enumerable: true, get: function () { return cadence_js_1.phaseToDirection; } });
28
+ Object.defineProperty(exports, "validateCadence", { enumerable: true, get: function () { return cadence_js_1.validateCadence; } });
29
+ Object.defineProperty(exports, "detectTransitions", { enumerable: true, get: function () { return cadence_js_1.detectTransitions; } });
30
+ // Arc validation
31
+ var arc_js_1 = require("./arc.js");
32
+ Object.defineProperty(exports, "computeCompleteness", { enumerable: true, get: function () { return arc_js_1.computeCompleteness; } });
33
+ Object.defineProperty(exports, "validateArc", { enumerable: true, get: function () { return arc_js_1.validateArc; } });
34
+ Object.defineProperty(exports, "isArcComplete", { enumerable: true, get: function () { return arc_js_1.isArcComplete; } });
35
+ // Timeline
36
+ var timeline_js_1 = require("./timeline.js");
37
+ Object.defineProperty(exports, "buildTimeline", { enumerable: true, get: function () { return timeline_js_1.buildTimeline; } });
38
+ Object.defineProperty(exports, "actStrip", { enumerable: true, get: function () { return timeline_js_1.actStrip; } });
39
+ // Cycle manager
40
+ var cycle_js_1 = require("./cycle.js");
41
+ Object.defineProperty(exports, "extractTransitions", { enumerable: true, get: function () { return cycle_js_1.extractTransitions; } });
42
+ Object.defineProperty(exports, "computeProgress", { enumerable: true, get: function () { return cycle_js_1.computeProgress; } });
43
+ Object.defineProperty(exports, "createCycle", { enumerable: true, get: function () { return cycle_js_1.createCycle; } });
44
+ Object.defineProperty(exports, "updateCycleMetadata", { enumerable: true, get: function () { return cycle_js_1.updateCycleMetadata; } });
45
+ // RSIS narrative generators
46
+ var rsis_narrative_js_1 = require("./rsis-narrative.js");
47
+ Object.defineProperty(exports, "generateProvenanceNarrative", { enumerable: true, get: function () { return rsis_narrative_js_1.generateProvenanceNarrative; } });
48
+ Object.defineProperty(exports, "generateReciprocityObservation", { enumerable: true, get: function () { return rsis_narrative_js_1.generateReciprocityObservation; } });
49
+ Object.defineProperty(exports, "generateDirectionObservation", { enumerable: true, get: function () { return rsis_narrative_js_1.generateDirectionObservation; } });
50
+ Object.defineProperty(exports, "getCeremonyPhaseFraming", { enumerable: true, get: function () { return rsis_narrative_js_1.getCeremonyPhaseFraming; } });
51
+ Object.defineProperty(exports, "describeSun", { enumerable: true, get: function () { return rsis_narrative_js_1.describeSun; } });
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA0BH,YAAY;AACZ,+CAUwB;AATtB,6GAAA,aAAa,OAAA;AACb,0GAAA,UAAU,OAAA;AACV,gHAAA,gBAAgB,OAAA;AAChB,6GAAA,aAAa,OAAA;AACb,0GAAA,UAAU,OAAA;AACV,+GAAA,eAAe,OAAA;AACf,2GAAA,WAAW,OAAA;AACX,wHAAA,wBAAwB,OAAA;AACxB,wHAAA,wBAAwB,OAAA;AAG1B,UAAU;AACV,2CAQsB;AAPpB,8GAAA,gBAAgB,OAAA;AAChB,2GAAA,aAAa,OAAA;AACb,0GAAA,YAAY,OAAA;AACZ,8GAAA,gBAAgB,OAAA;AAChB,8GAAA,gBAAgB,OAAA;AAChB,6GAAA,eAAe,OAAA;AACf,+GAAA,iBAAiB,OAAA;AAGnB,iBAAiB;AACjB,mCAIkB;AAHhB,6GAAA,mBAAmB,OAAA;AACnB,qGAAA,WAAW,OAAA;AACX,uGAAA,aAAa,OAAA;AAGf,WAAW;AACX,6CAGuB;AAFrB,4GAAA,aAAa,OAAA;AACb,uGAAA,QAAQ,OAAA;AAGV,gBAAgB;AAChB,uCAKoB;AAJlB,8GAAA,kBAAkB,OAAA;AAClB,2GAAA,eAAe,OAAA;AACf,uGAAA,WAAW,OAAA;AACX,+GAAA,mBAAmB,OAAA;AAGrB,4BAA4B;AAC5B,yDAM6B;AAL3B,gIAAA,2BAA2B,OAAA;AAC3B,mIAAA,8BAA8B,OAAA;AAC9B,iIAAA,4BAA4B,OAAA;AAC5B,4HAAA,uBAAuB,OAAA;AACvB,gHAAA,WAAW,OAAA"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @medicine-wheel/narrative-engine — RSIS Narrative Generators
3
+ *
4
+ * Produces ceremony-phase-aware provenance stories, reciprocity
5
+ * narratives, and directional observations for RSIS tool outputs.
6
+ */
7
+ import type { CeremonyPhase, CeremonyLineageEntry, DirectionDistribution, SunName } from '@medicine-wheel/ontology-core';
8
+ /**
9
+ * Generate a human-readable provenance narrative for a code artifact
10
+ */
11
+ export declare function generateProvenanceNarrative(symbolName: string, lineage: CeremonyLineageEntry[], inquiries: Array<{
12
+ name: string;
13
+ }>, stewards: Array<{
14
+ name: string;
15
+ }>): string;
16
+ /**
17
+ * Generate a reciprocity observation — always invitational, never evaluative
18
+ */
19
+ export declare function generateReciprocityObservation(stewardCount: number, flowCount: number): string;
20
+ /**
21
+ * Generate a natural language observation about directional balance
22
+ */
23
+ export declare function generateDirectionObservation(distribution: DirectionDistribution, total: number): string;
24
+ /**
25
+ * Get ceremony-phase-aware framing for tool output
26
+ */
27
+ export declare function getCeremonyPhaseFraming(phase?: CeremonyPhase): string;
28
+ /**
29
+ * Describe a Thematic Sun
30
+ */
31
+ export declare function describeSun(sun: SunName): string;
32
+ //# sourceMappingURL=rsis-narrative.d.ts.map