mia-code 0.2.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.
- package/.claude/settings.local.json +9 -0
- package/.coaia/pde/d77620fc-1cd9-47e2-ba00-c03e114e42e9.jsonl +16 -0
- package/.coaia/pde/de44d838-b58b-4e91-b791-dd3b0f940ed1.jsonl +60 -0
- package/.gemini/settings.json +8 -0
- package/.hch/issue_.env +4 -0
- package/.hch/issue_add__2601211715.json +77 -0
- package/.hch/issue_add__2601211715.md +4 -0
- package/.hch/issue_add__2602242020.json +78 -0
- package/.hch/issue_add__2602242020.md +7 -0
- package/.hch/issues.json +2312 -0
- package/.hch/issues.md +30 -0
- package/260123084839.coaia-narrative.autoRevisionOfInitial_NewStructuralTensionChart-to-initiate-HierarchicalThinking.txt +5 -0
- package/2602010101.issue.txt +31 -0
- package/BUGS.md +242 -0
- package/CLAUDE.md +2 -0
- package/ENHANCEMENTS.md +129 -0
- package/FEATURES_ENDING_SESSIONS.md +21 -0
- package/FIXES.md +114 -0
- package/GUILLAUME.md +77 -0
- package/KINSHIP.md +50 -0
- package/LAUNCH__session_id__MiaCodeNextWorkReviewAndCommits_2601312020.sh +7 -0
- package/PHASE_2.md +153 -0
- package/PHASE_2_IMPLEMENTATION.md +134 -0
- package/README.md +203 -0
- package/RESUME__issueMaker__540244c2-b096-40d8-8c3f-398408d3e0eb.2602041757.sh +1 -0
- package/RUN_COPILOT_with_related_folders__260130.sh +2 -0
- package/WS__mia-code__260214__IAIP_PDE.code-workspace +29 -0
- package/WS__mia-code__src332__260122.code-workspace +23 -0
- package/_env.sh +12 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +679 -0
- package/dist/commands.d.ts +43 -0
- package/dist/commands.js +108 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.js +57 -0
- package/dist/formatting.d.ts +12 -0
- package/dist/formatting.js +133 -0
- package/dist/geminiHeadless.d.ts +25 -0
- package/dist/geminiHeadless.js +246 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +186 -0
- package/dist/mcp/config-generator.d.ts +23 -0
- package/dist/mcp/config-generator.js +116 -0
- package/dist/mcp/index.d.ts +18 -0
- package/dist/mcp/index.js +43 -0
- package/dist/mcp/miaco-server.d.ts +15 -0
- package/dist/mcp/miaco-server.js +161 -0
- package/dist/mcp/miatel-server.d.ts +15 -0
- package/dist/mcp/miatel-server.js +123 -0
- package/dist/mcp/miawa-server.d.ts +15 -0
- package/dist/mcp/miawa-server.js +125 -0
- package/dist/mcp/utils.d.ts +51 -0
- package/dist/mcp/utils.js +76 -0
- package/dist/multiline-input.d.ts +98 -0
- package/dist/multiline-input.js +630 -0
- package/dist/narrative/index.d.ts +9 -0
- package/dist/narrative/index.js +11 -0
- package/dist/narrative/router.d.ts +89 -0
- package/dist/narrative/router.js +186 -0
- package/dist/narrative/tracer.d.ts +75 -0
- package/dist/narrative/tracer.js +180 -0
- package/dist/sessionStore.d.ts +10 -0
- package/dist/sessionStore.js +93 -0
- package/dist/types.d.ts +44 -0
- package/dist/types.js +1 -0
- package/dist/unifier.d.ts +6 -0
- package/dist/unifier.js +147 -0
- package/issue-358--architecture/ARCHITECTURE_OVERVIEW.md +60 -0
- package/issue-358--architecture/CLI_INTEGRATION.md +61 -0
- package/issue-358--architecture/COVER_ART_BRIEF.md +68 -0
- package/issue-358--architecture/MEMORY_SYSTEM.md +89 -0
- package/issue-358--architecture/PERSONA_REGISTRY.md +97 -0
- package/issue-358--architecture/PODCAST_PRODUCTION_PLAN.md +61 -0
- package/issue-358--architecture/PODCAST_SCRIPT_FINAL.md +109 -0
- package/issue-358--architecture/PROTOTYPE_CHARACTER_SPEC.md +59 -0
- package/issue-358--architecture/RESOURCES.md +41 -0
- package/issue-358--architecture/TEAM_LISTENING_GUIDE.md +53 -0
- package/llms-gemini-cli.txt +145 -0
- package/package.json +39 -0
- package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/checkpoints/index.md +6 -0
- package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/events.jsonl +213 -0
- package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/plan.md +243 -0
- package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/workspace.yaml +5 -0
- package/src/cli.ts +742 -0
- package/src/commands.ts +127 -0
- package/src/config.ts +67 -0
- package/src/formatting.ts +157 -0
- package/src/geminiHeadless.ts +300 -0
- package/src/index.ts +194 -0
- package/src/mcp/config-generator.ts +141 -0
- package/src/mcp/index.ts +55 -0
- package/src/mcp/miaco-server.ts +199 -0
- package/src/mcp/miatel-server.ts +138 -0
- package/src/mcp/miawa-server.ts +158 -0
- package/src/mcp/utils.ts +121 -0
- package/src/multiline-input.ts +739 -0
- package/src/narrative/index.ts +33 -0
- package/src/narrative/router.ts +260 -0
- package/src/narrative/tracer.ts +249 -0
- package/src/sessionStore.ts +111 -0
- package/src/types.ts +49 -0
- package/src/unifier.ts +171 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrative Intelligence Integration for mia-code
|
|
3
|
+
*
|
|
4
|
+
* Bridges the three-universe model from @langchain/langgraph-narrative-intelligence (that I publish as : ava-langchain-narrative-tracing and not @langchain/langgraph-narrative-intelligence)
|
|
5
|
+
* to mia-code's miaco/miatel/miawa architecture.
|
|
6
|
+
*
|
|
7
|
+
* Universe Mapping:
|
|
8
|
+
* - ENGINEER (Mia) → miaco (charts, technical precision)
|
|
9
|
+
* - CEREMONY (Ava8) → miawa (ceremonies, relational protocols)
|
|
10
|
+
* - STORY_ENGINE (Miette) → miatel (beats, narrative patterns)
|
|
11
|
+
*/
|
|
12
|
+
import { Universe, ThreeUniverseAnalysis, StoryBeat, NarrativeFunction, CoherenceResult, EmotionalTone } from "ava-langgraph-narrative-intelligence";
|
|
13
|
+
/**
|
|
14
|
+
* Maps universe to mia-code CLI
|
|
15
|
+
*/
|
|
16
|
+
export declare const UNIVERSE_TO_CLI: Record<Universe, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Maps CLI to universe
|
|
19
|
+
*/
|
|
20
|
+
export declare const CLI_TO_UNIVERSE: Record<string, Universe>;
|
|
21
|
+
/**
|
|
22
|
+
* Mia-code event that can be analyzed through three universes
|
|
23
|
+
*/
|
|
24
|
+
export interface MiaCodeEvent {
|
|
25
|
+
id: string;
|
|
26
|
+
type: "user_input" | "agent_action" | "chart_update" | "beat_created" | "ceremony_action";
|
|
27
|
+
content: string;
|
|
28
|
+
source?: "miaco" | "miatel" | "miawa";
|
|
29
|
+
metadata?: Record<string, unknown>;
|
|
30
|
+
timestamp?: Date;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Result of routing decision
|
|
34
|
+
*/
|
|
35
|
+
export interface RoutingResult {
|
|
36
|
+
leadCli: "miaco" | "miatel" | "miawa";
|
|
37
|
+
leadUniverse: Universe;
|
|
38
|
+
analysis: ThreeUniverseAnalysis;
|
|
39
|
+
suggestedAction: string;
|
|
40
|
+
coherence: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* NarrativeRouter - Routes events to the appropriate mia-code CLI
|
|
44
|
+
* based on three-universe analysis
|
|
45
|
+
*/
|
|
46
|
+
export declare class NarrativeRouter {
|
|
47
|
+
private processor;
|
|
48
|
+
private coherenceEngine;
|
|
49
|
+
private beatHistory;
|
|
50
|
+
private beatSequence;
|
|
51
|
+
constructor();
|
|
52
|
+
/**
|
|
53
|
+
* Analyze an event and determine the best CLI to handle it
|
|
54
|
+
*/
|
|
55
|
+
route(event: MiaCodeEvent): RoutingResult;
|
|
56
|
+
/**
|
|
57
|
+
* Record a story beat and update coherence tracking
|
|
58
|
+
*/
|
|
59
|
+
recordBeat(content: string, cli: "miaco" | "miatel" | "miawa"): StoryBeat;
|
|
60
|
+
/**
|
|
61
|
+
* Analyze coherence of accumulated beats
|
|
62
|
+
*/
|
|
63
|
+
analyzeCoherence(): CoherenceResult | null;
|
|
64
|
+
/**
|
|
65
|
+
* Get trinity assessment (Mia/Miette/Ava8 perspectives on quality)
|
|
66
|
+
*/
|
|
67
|
+
getTrinityAssessment(): {
|
|
68
|
+
mia: string;
|
|
69
|
+
miette: string;
|
|
70
|
+
ava8: string;
|
|
71
|
+
} | null;
|
|
72
|
+
/**
|
|
73
|
+
* Get gaps that need addressing
|
|
74
|
+
*/
|
|
75
|
+
getGaps(): Array<{
|
|
76
|
+
type: string;
|
|
77
|
+
severity: string;
|
|
78
|
+
description: string;
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Reset the router (clear beat history)
|
|
82
|
+
*/
|
|
83
|
+
reset(): void;
|
|
84
|
+
private mapEventType;
|
|
85
|
+
private inferNarrativeFunction;
|
|
86
|
+
private deriveSuggestedAction;
|
|
87
|
+
}
|
|
88
|
+
export { Universe, ThreeUniverseAnalysis, StoryBeat, NarrativeFunction, EmotionalTone, CoherenceResult, };
|
|
89
|
+
export declare function getNarrativeRouter(): NarrativeRouter;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrative Intelligence Integration for mia-code
|
|
3
|
+
*
|
|
4
|
+
* Bridges the three-universe model from @langchain/langgraph-narrative-intelligence (that I publish as : ava-langchain-narrative-tracing and not @langchain/langgraph-narrative-intelligence)
|
|
5
|
+
* to mia-code's miaco/miatel/miawa architecture.
|
|
6
|
+
*
|
|
7
|
+
* Universe Mapping:
|
|
8
|
+
* - ENGINEER (Mia) → miaco (charts, technical precision)
|
|
9
|
+
* - CEREMONY (Ava8) → miawa (ceremonies, relational protocols)
|
|
10
|
+
* - STORY_ENGINE (Miette) → miatel (beats, narrative patterns)
|
|
11
|
+
*/
|
|
12
|
+
import { ThreeUniverseProcessor, NarrativeCoherenceEngine, Universe, createStoryBeat, NarrativeFunction, EmotionalTone, classifyEmotionalTone, } from "ava-langgraph-narrative-intelligence";
|
|
13
|
+
/**
|
|
14
|
+
* Maps universe to mia-code CLI
|
|
15
|
+
*/
|
|
16
|
+
export const UNIVERSE_TO_CLI = {
|
|
17
|
+
[Universe.ENGINEER]: "miaco",
|
|
18
|
+
[Universe.CEREMONY]: "miawa",
|
|
19
|
+
[Universe.STORY_ENGINE]: "miatel",
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Maps CLI to universe
|
|
23
|
+
*/
|
|
24
|
+
export const CLI_TO_UNIVERSE = {
|
|
25
|
+
miaco: Universe.ENGINEER,
|
|
26
|
+
miawa: Universe.CEREMONY,
|
|
27
|
+
miatel: Universe.STORY_ENGINE,
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* NarrativeRouter - Routes events to the appropriate mia-code CLI
|
|
31
|
+
* based on three-universe analysis
|
|
32
|
+
*/
|
|
33
|
+
export class NarrativeRouter {
|
|
34
|
+
processor;
|
|
35
|
+
coherenceEngine;
|
|
36
|
+
beatHistory = [];
|
|
37
|
+
beatSequence = 0;
|
|
38
|
+
constructor() {
|
|
39
|
+
this.processor = new ThreeUniverseProcessor();
|
|
40
|
+
this.coherenceEngine = new NarrativeCoherenceEngine();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Analyze an event and determine the best CLI to handle it
|
|
44
|
+
*/
|
|
45
|
+
route(event) {
|
|
46
|
+
// Convert to format expected by processor
|
|
47
|
+
const processedEvent = {
|
|
48
|
+
content: event.content,
|
|
49
|
+
type: event.type,
|
|
50
|
+
source: event.source,
|
|
51
|
+
...event.metadata,
|
|
52
|
+
};
|
|
53
|
+
// Run three-universe analysis
|
|
54
|
+
const analysis = this.processor.process(processedEvent, this.mapEventType(event.type));
|
|
55
|
+
// Map lead universe to CLI
|
|
56
|
+
const leadCli = UNIVERSE_TO_CLI[analysis.leadUniverse];
|
|
57
|
+
// Determine suggested action based on analysis
|
|
58
|
+
const suggestedAction = this.deriveSuggestedAction(analysis);
|
|
59
|
+
return {
|
|
60
|
+
leadCli,
|
|
61
|
+
leadUniverse: analysis.leadUniverse,
|
|
62
|
+
analysis,
|
|
63
|
+
suggestedAction,
|
|
64
|
+
coherence: analysis.coherenceScore,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Record a story beat and update coherence tracking
|
|
69
|
+
*/
|
|
70
|
+
recordBeat(content, cli) {
|
|
71
|
+
this.beatSequence++;
|
|
72
|
+
// Classify emotional tone
|
|
73
|
+
const toneResult = classifyEmotionalTone(content);
|
|
74
|
+
// Determine narrative function from content
|
|
75
|
+
const narrativeFunction = this.inferNarrativeFunction(content);
|
|
76
|
+
// Map CLI to universe
|
|
77
|
+
const leadUniverse = CLI_TO_UNIVERSE[cli];
|
|
78
|
+
// Create the beat
|
|
79
|
+
const beat = createStoryBeat(`beat_${this.beatSequence}`, this.beatSequence, content, narrativeFunction, Math.ceil(this.beatSequence / 10), // Rough act calculation
|
|
80
|
+
{
|
|
81
|
+
emotionalTone: toneResult.classification,
|
|
82
|
+
leadUniverse,
|
|
83
|
+
});
|
|
84
|
+
this.beatHistory.push(beat);
|
|
85
|
+
return beat;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Analyze coherence of accumulated beats
|
|
89
|
+
*/
|
|
90
|
+
analyzeCoherence() {
|
|
91
|
+
if (this.beatHistory.length === 0) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const result = this.coherenceEngine.analyze(this.beatHistory);
|
|
95
|
+
// Handle case where result is CoherenceEngineState
|
|
96
|
+
if ('coherenceScore' in result && result.coherenceScore) {
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get trinity assessment (Mia/Miette/Ava8 perspectives on quality)
|
|
103
|
+
*/
|
|
104
|
+
getTrinityAssessment() {
|
|
105
|
+
const result = this.analyzeCoherence();
|
|
106
|
+
if (!result)
|
|
107
|
+
return null;
|
|
108
|
+
return {
|
|
109
|
+
mia: result.trinityAssessment.mia,
|
|
110
|
+
miette: result.trinityAssessment.miette,
|
|
111
|
+
ava8: result.trinityAssessment.ava8,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get gaps that need addressing
|
|
116
|
+
*/
|
|
117
|
+
getGaps() {
|
|
118
|
+
const result = this.analyzeCoherence();
|
|
119
|
+
if (!result)
|
|
120
|
+
return [];
|
|
121
|
+
return result.gaps.map(gap => ({
|
|
122
|
+
type: gap.gapType,
|
|
123
|
+
severity: gap.severity,
|
|
124
|
+
description: gap.description,
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Reset the router (clear beat history)
|
|
129
|
+
*/
|
|
130
|
+
reset() {
|
|
131
|
+
this.beatHistory = [];
|
|
132
|
+
this.beatSequence = 0;
|
|
133
|
+
}
|
|
134
|
+
mapEventType(type) {
|
|
135
|
+
const mapping = {
|
|
136
|
+
user_input: "user.input",
|
|
137
|
+
agent_action: "agent.action",
|
|
138
|
+
chart_update: "github.push",
|
|
139
|
+
beat_created: "agent.action",
|
|
140
|
+
ceremony_action: "system.event",
|
|
141
|
+
};
|
|
142
|
+
return mapping[type] || "system.event";
|
|
143
|
+
}
|
|
144
|
+
inferNarrativeFunction(content) {
|
|
145
|
+
const lower = content.toLowerCase();
|
|
146
|
+
if (lower.includes("begin") || lower.includes("start") || lower.includes("init")) {
|
|
147
|
+
return NarrativeFunction.INCITING_INCIDENT;
|
|
148
|
+
}
|
|
149
|
+
if (lower.includes("complete") || lower.includes("finish") || lower.includes("done")) {
|
|
150
|
+
return NarrativeFunction.RESOLUTION;
|
|
151
|
+
}
|
|
152
|
+
if (lower.includes("problem") || lower.includes("issue") || lower.includes("bug")) {
|
|
153
|
+
return NarrativeFunction.COMPLICATION;
|
|
154
|
+
}
|
|
155
|
+
if (lower.includes("fix") || lower.includes("resolve") || lower.includes("solved")) {
|
|
156
|
+
return NarrativeFunction.RESOLUTION;
|
|
157
|
+
}
|
|
158
|
+
if (lower.includes("major") || lower.includes("significant") || lower.includes("breakthrough")) {
|
|
159
|
+
return NarrativeFunction.TURNING_POINT;
|
|
160
|
+
}
|
|
161
|
+
return NarrativeFunction.RISING_ACTION;
|
|
162
|
+
}
|
|
163
|
+
deriveSuggestedAction(analysis) {
|
|
164
|
+
const engineer = analysis.engineer;
|
|
165
|
+
const ceremony = analysis.ceremony;
|
|
166
|
+
const storyEngine = analysis.storyEngine;
|
|
167
|
+
// Use highest confidence perspective's suggestion
|
|
168
|
+
if (engineer.confidence >= ceremony.confidence && engineer.confidence >= storyEngine.confidence) {
|
|
169
|
+
return engineer.suggestedFlows[0] || "analyze";
|
|
170
|
+
}
|
|
171
|
+
if (ceremony.confidence >= storyEngine.confidence) {
|
|
172
|
+
return ceremony.suggestedFlows[0] || "witness";
|
|
173
|
+
}
|
|
174
|
+
return storyEngine.suggestedFlows[0] || "narrate";
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Re-export useful types
|
|
178
|
+
export { Universe, NarrativeFunction, EmotionalTone, };
|
|
179
|
+
// Export singleton for easy use
|
|
180
|
+
let routerInstance = null;
|
|
181
|
+
export function getNarrativeRouter() {
|
|
182
|
+
if (!routerInstance) {
|
|
183
|
+
routerInstance = new NarrativeRouter();
|
|
184
|
+
}
|
|
185
|
+
return routerInstance;
|
|
186
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrative Tracing Integration for mia-code
|
|
3
|
+
*
|
|
4
|
+
* Integrates @langchain/narrative-tracing for observability that I published as : ava-langchain-narrative-tracing and not @langchain/narrative-tracing
|
|
5
|
+
* across mia-code operations.
|
|
6
|
+
*/
|
|
7
|
+
import { NarrativeEventType, NarrativeMetrics } from "ava-langchain-narrative-tracing";
|
|
8
|
+
import { ThreeUniverseAnalysis } from "./router.js";
|
|
9
|
+
/**
|
|
10
|
+
* mia-code operation types
|
|
11
|
+
*/
|
|
12
|
+
export type MiaCodeOperation = "chart_create" | "chart_update" | "chart_complete" | "beat_create" | "beat_analyze" | "ceremony_init" | "ceremony_advance" | "user_input" | "agent_response" | "routing_decision";
|
|
13
|
+
/**
|
|
14
|
+
* MiaCodeTracer - Wraps NarrativeTracingHandler for mia-code specific operations
|
|
15
|
+
*/
|
|
16
|
+
export declare class MiaCodeTracer {
|
|
17
|
+
private handler;
|
|
18
|
+
private metrics;
|
|
19
|
+
private sessionId;
|
|
20
|
+
private startTime;
|
|
21
|
+
constructor(options: {
|
|
22
|
+
sessionId: string;
|
|
23
|
+
storyId?: string;
|
|
24
|
+
publicKey?: string;
|
|
25
|
+
secretKey?: string;
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Start tracing a session
|
|
29
|
+
*/
|
|
30
|
+
startSession(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Log a chart operation (miaco)
|
|
33
|
+
*/
|
|
34
|
+
logChartOperation(chartId: string, operation: "create" | "update" | "complete" | "add_step", data: Record<string, unknown>): void;
|
|
35
|
+
/**
|
|
36
|
+
* Log a beat operation (miatel)
|
|
37
|
+
*/
|
|
38
|
+
logBeatOperation(beatId: string, content: string, sequence: number, narrativeFunction: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Log a ceremony operation (miawa)
|
|
41
|
+
*/
|
|
42
|
+
logCeremonyOperation(ceremonyId: string, operation: "init" | "advance" | "close", movement?: string, data?: Record<string, unknown>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Log a three-universe routing decision
|
|
45
|
+
*/
|
|
46
|
+
logRoutingDecision(analysis: ThreeUniverseAnalysis, targetCli: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Log a gap identified in the narrative
|
|
49
|
+
*/
|
|
50
|
+
logGap(type: string, severity: number, description: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Log user input
|
|
53
|
+
*/
|
|
54
|
+
logUserInput(content: string): void;
|
|
55
|
+
/**
|
|
56
|
+
* Log agent response
|
|
57
|
+
*/
|
|
58
|
+
logAgentResponse(content: string, cli: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Get correlation headers for external calls
|
|
61
|
+
*/
|
|
62
|
+
getCorrelationHeaders(): Record<string, string>;
|
|
63
|
+
/**
|
|
64
|
+
* Get current metrics
|
|
65
|
+
*/
|
|
66
|
+
getMetrics(): NarrativeMetrics;
|
|
67
|
+
/**
|
|
68
|
+
* End session and flush traces
|
|
69
|
+
*/
|
|
70
|
+
endSession(): Promise<void>;
|
|
71
|
+
private universeToString;
|
|
72
|
+
}
|
|
73
|
+
export { NarrativeEventType, NarrativeMetrics };
|
|
74
|
+
export declare function getTracer(sessionId: string): MiaCodeTracer;
|
|
75
|
+
export declare function removeTracer(sessionId: string): void;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrative Tracing Integration for mia-code
|
|
3
|
+
*
|
|
4
|
+
* Integrates @langchain/narrative-tracing for observability that I published as : ava-langchain-narrative-tracing and not @langchain/narrative-tracing
|
|
5
|
+
* across mia-code operations.
|
|
6
|
+
*/
|
|
7
|
+
import { NarrativeTracingHandler, NarrativeEventType, createNarrativeMetrics, } from "ava-langchain-narrative-tracing";
|
|
8
|
+
import { Universe } from "./router.js";
|
|
9
|
+
/**
|
|
10
|
+
* MiaCodeTracer - Wraps NarrativeTracingHandler for mia-code specific operations
|
|
11
|
+
*/
|
|
12
|
+
export class MiaCodeTracer {
|
|
13
|
+
handler;
|
|
14
|
+
metrics;
|
|
15
|
+
sessionId;
|
|
16
|
+
startTime;
|
|
17
|
+
constructor(options) {
|
|
18
|
+
this.sessionId = options.sessionId;
|
|
19
|
+
this.startTime = Date.now();
|
|
20
|
+
this.handler = new NarrativeTracingHandler({
|
|
21
|
+
storyId: options.storyId || `mia_${options.sessionId}`,
|
|
22
|
+
sessionId: options.sessionId,
|
|
23
|
+
publicKey: options.publicKey || process.env.LANGFUSE_PUBLIC_KEY,
|
|
24
|
+
secretKey: options.secretKey || process.env.LANGFUSE_SECRET_KEY,
|
|
25
|
+
});
|
|
26
|
+
this.metrics = createNarrativeMetrics();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Start tracing a session
|
|
30
|
+
*/
|
|
31
|
+
startSession() {
|
|
32
|
+
const traceId = this.handler.startStoryGeneration();
|
|
33
|
+
return traceId;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Log a chart operation (miaco)
|
|
37
|
+
*/
|
|
38
|
+
logChartOperation(chartId, operation, data) {
|
|
39
|
+
this.handler.logEvent({
|
|
40
|
+
eventType: NarrativeEventType.BEAT_CREATED,
|
|
41
|
+
beatId: chartId,
|
|
42
|
+
metadata: {
|
|
43
|
+
cli: "miaco",
|
|
44
|
+
operation,
|
|
45
|
+
...data,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
this.metrics.beatsGenerated++;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Log a beat operation (miatel)
|
|
52
|
+
*/
|
|
53
|
+
logBeatOperation(beatId, content, sequence, narrativeFunction) {
|
|
54
|
+
this.handler.logBeatCreation(beatId, content, sequence, narrativeFunction);
|
|
55
|
+
this.metrics.beatsGenerated++;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Log a ceremony operation (miawa)
|
|
59
|
+
*/
|
|
60
|
+
logCeremonyOperation(ceremonyId, operation, movement, data) {
|
|
61
|
+
this.handler.logEvent({
|
|
62
|
+
eventType: NarrativeEventType.CHARACTER_ARC_UPDATED,
|
|
63
|
+
metadata: {
|
|
64
|
+
cli: "miawa",
|
|
65
|
+
operation,
|
|
66
|
+
movement,
|
|
67
|
+
ceremonyId,
|
|
68
|
+
...data,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Log a three-universe routing decision
|
|
74
|
+
*/
|
|
75
|
+
logRoutingDecision(analysis, targetCli) {
|
|
76
|
+
this.handler.logThreeUniverseAnalysis({
|
|
77
|
+
eventId: `route_${Date.now()}`,
|
|
78
|
+
engineerIntent: analysis.engineer.intent,
|
|
79
|
+
engineerConfidence: analysis.engineer.confidence,
|
|
80
|
+
ceremonyIntent: analysis.ceremony.intent,
|
|
81
|
+
ceremonyConfidence: analysis.ceremony.confidence,
|
|
82
|
+
storyEngineIntent: analysis.storyEngine.intent,
|
|
83
|
+
storyEngineConfidence: analysis.storyEngine.confidence,
|
|
84
|
+
leadUniverse: this.universeToString(analysis.leadUniverse),
|
|
85
|
+
coherenceScore: analysis.coherenceScore,
|
|
86
|
+
});
|
|
87
|
+
this.handler.logRoutingDecision({
|
|
88
|
+
decisionId: `decision_${Date.now()}`,
|
|
89
|
+
backend: targetCli,
|
|
90
|
+
flow: analysis.engineer.suggestedFlows[0] || "default",
|
|
91
|
+
score: analysis.coherenceScore,
|
|
92
|
+
leadUniverse: this.universeToString(analysis.leadUniverse),
|
|
93
|
+
});
|
|
94
|
+
this.metrics.routingDecisions++;
|
|
95
|
+
// Update alignment metrics
|
|
96
|
+
this.metrics.engineerAlignment =
|
|
97
|
+
(this.metrics.engineerAlignment + analysis.engineer.confidence) / 2;
|
|
98
|
+
this.metrics.ceremonyAlignment =
|
|
99
|
+
(this.metrics.ceremonyAlignment + analysis.ceremony.confidence) / 2;
|
|
100
|
+
this.metrics.storyEngineAlignment =
|
|
101
|
+
(this.metrics.storyEngineAlignment + analysis.storyEngine.confidence) / 2;
|
|
102
|
+
this.metrics.crossUniverseCoherence =
|
|
103
|
+
(this.metrics.crossUniverseCoherence + analysis.coherenceScore) / 2;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Log a gap identified in the narrative
|
|
107
|
+
*/
|
|
108
|
+
logGap(type, severity, description) {
|
|
109
|
+
this.handler.logGapIdentified(type, description, severity);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Log user input
|
|
113
|
+
*/
|
|
114
|
+
logUserInput(content) {
|
|
115
|
+
this.handler.logEvent({
|
|
116
|
+
eventType: NarrativeEventType.BEAT_CREATED,
|
|
117
|
+
beatId: `input_${Date.now()}`,
|
|
118
|
+
metadata: { type: "user_input", content: content.slice(0, 200) },
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Log agent response
|
|
123
|
+
*/
|
|
124
|
+
logAgentResponse(content, cli) {
|
|
125
|
+
this.handler.logEvent({
|
|
126
|
+
eventType: NarrativeEventType.BEAT_ENRICHED,
|
|
127
|
+
beatId: `response_${Date.now()}`,
|
|
128
|
+
metadata: { type: "agent_response", cli, content: content.slice(0, 200) },
|
|
129
|
+
});
|
|
130
|
+
this.metrics.enrichmentsApplied++;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get correlation headers for external calls
|
|
134
|
+
*/
|
|
135
|
+
getCorrelationHeaders() {
|
|
136
|
+
return {
|
|
137
|
+
"X-Mia-Session-Id": this.sessionId,
|
|
138
|
+
"X-Mia-Trace-Start": this.startTime.toString(),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get current metrics
|
|
143
|
+
*/
|
|
144
|
+
getMetrics() {
|
|
145
|
+
this.metrics.totalGenerationTimeMs = Date.now() - this.startTime;
|
|
146
|
+
if (this.metrics.beatsGenerated > 0) {
|
|
147
|
+
this.metrics.averageBeatTimeMs =
|
|
148
|
+
this.metrics.totalGenerationTimeMs / this.metrics.beatsGenerated;
|
|
149
|
+
}
|
|
150
|
+
return { ...this.metrics };
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* End session and flush traces
|
|
154
|
+
*/
|
|
155
|
+
async endSession() {
|
|
156
|
+
this.handler.endStoryGeneration(Date.now() - this.startTime);
|
|
157
|
+
await this.handler.flush();
|
|
158
|
+
}
|
|
159
|
+
universeToString(universe) {
|
|
160
|
+
const mapping = {
|
|
161
|
+
[Universe.ENGINEER]: "engineer",
|
|
162
|
+
[Universe.CEREMONY]: "ceremony",
|
|
163
|
+
[Universe.STORY_ENGINE]: "story_engine",
|
|
164
|
+
};
|
|
165
|
+
return mapping[universe] || "unknown";
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Export types
|
|
169
|
+
export { NarrativeEventType };
|
|
170
|
+
// Singleton tracer instance per session
|
|
171
|
+
const tracers = new Map();
|
|
172
|
+
export function getTracer(sessionId) {
|
|
173
|
+
if (!tracers.has(sessionId)) {
|
|
174
|
+
tracers.set(sessionId, new MiaCodeTracer({ sessionId }));
|
|
175
|
+
}
|
|
176
|
+
return tracers.get(sessionId);
|
|
177
|
+
}
|
|
178
|
+
export function removeTracer(sessionId) {
|
|
179
|
+
tracers.delete(sessionId);
|
|
180
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MiaCodeSessionMeta, ChatMessage } from "./types.js";
|
|
2
|
+
export declare function rememberSession(meta: MiaCodeSessionMeta): void;
|
|
3
|
+
export declare function markSessionInitialized(id: string): void;
|
|
4
|
+
export declare function isSessionInitialized(id: string): boolean;
|
|
5
|
+
export declare function getLastSessionForProject(projectRoot: string): MiaCodeSessionMeta | null;
|
|
6
|
+
export declare function getSessionById(id: string): MiaCodeSessionMeta | null;
|
|
7
|
+
export declare function listSessions(): MiaCodeSessionMeta[];
|
|
8
|
+
export declare function clearSessions(): void;
|
|
9
|
+
export declare function saveChatMessage(sessionId: string, msg: ChatMessage): void;
|
|
10
|
+
export declare function loadChatHistory(sessionId: string): ChatMessage[];
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import os from "os";
|
|
4
|
+
const SESSIONS_FILE = path.join(os.homedir(), ".mia-code-sessions.json");
|
|
5
|
+
const HISTORY_DIR = path.join(os.homedir(), ".mia-code-history");
|
|
6
|
+
function loadIndex() {
|
|
7
|
+
if (!fs.existsSync(SESSIONS_FILE)) {
|
|
8
|
+
return { byProjectRoot: {}, byId: {} };
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const raw = fs.readFileSync(SESSIONS_FILE, "utf8");
|
|
12
|
+
const parsed = JSON.parse(raw);
|
|
13
|
+
return {
|
|
14
|
+
byProjectRoot: parsed.byProjectRoot || {},
|
|
15
|
+
byId: parsed.byId || {}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return { byProjectRoot: {}, byId: {} };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function saveIndex(index) {
|
|
23
|
+
fs.writeFileSync(SESSIONS_FILE, JSON.stringify(index, null, 2), "utf8");
|
|
24
|
+
}
|
|
25
|
+
export function rememberSession(meta) {
|
|
26
|
+
const idx = loadIndex();
|
|
27
|
+
if (meta.projectRoot) {
|
|
28
|
+
idx.byProjectRoot[meta.projectRoot] = meta;
|
|
29
|
+
}
|
|
30
|
+
idx.byId[meta.id] = meta;
|
|
31
|
+
saveIndex(idx);
|
|
32
|
+
}
|
|
33
|
+
export function markSessionInitialized(id) {
|
|
34
|
+
const idx = loadIndex();
|
|
35
|
+
const session = idx.byId[id];
|
|
36
|
+
if (session) {
|
|
37
|
+
session.initialized = true;
|
|
38
|
+
if (session.projectRoot) {
|
|
39
|
+
idx.byProjectRoot[session.projectRoot] = session;
|
|
40
|
+
}
|
|
41
|
+
saveIndex(idx);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function isSessionInitialized(id) {
|
|
45
|
+
const idx = loadIndex();
|
|
46
|
+
return idx.byId[id]?.initialized ?? false;
|
|
47
|
+
}
|
|
48
|
+
export function getLastSessionForProject(projectRoot) {
|
|
49
|
+
const idx = loadIndex();
|
|
50
|
+
return idx.byProjectRoot[projectRoot] ?? null;
|
|
51
|
+
}
|
|
52
|
+
export function getSessionById(id) {
|
|
53
|
+
const idx = loadIndex();
|
|
54
|
+
return idx.byId[id] ?? null;
|
|
55
|
+
}
|
|
56
|
+
export function listSessions() {
|
|
57
|
+
const idx = loadIndex();
|
|
58
|
+
return Object.values(idx.byId);
|
|
59
|
+
}
|
|
60
|
+
export function clearSessions() {
|
|
61
|
+
saveIndex({ byProjectRoot: {}, byId: {} });
|
|
62
|
+
}
|
|
63
|
+
// ── Chat history persistence ────────────────────────────────────────
|
|
64
|
+
function ensureHistoryDir() {
|
|
65
|
+
if (!fs.existsSync(HISTORY_DIR)) {
|
|
66
|
+
fs.mkdirSync(HISTORY_DIR, { recursive: true });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function historyFile(sessionId) {
|
|
70
|
+
// Sanitize session ID for safe filenames
|
|
71
|
+
const safe = sessionId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
72
|
+
return path.join(HISTORY_DIR, `${safe}.jsonl`);
|
|
73
|
+
}
|
|
74
|
+
export function saveChatMessage(sessionId, msg) {
|
|
75
|
+
ensureHistoryDir();
|
|
76
|
+
const line = JSON.stringify(msg) + "\n";
|
|
77
|
+
fs.appendFileSync(historyFile(sessionId), line, "utf8");
|
|
78
|
+
}
|
|
79
|
+
export function loadChatHistory(sessionId) {
|
|
80
|
+
const file = historyFile(sessionId);
|
|
81
|
+
if (!fs.existsSync(file))
|
|
82
|
+
return [];
|
|
83
|
+
try {
|
|
84
|
+
const raw = fs.readFileSync(file, "utf8");
|
|
85
|
+
return raw
|
|
86
|
+
.split("\n")
|
|
87
|
+
.filter(l => l.trim())
|
|
88
|
+
.map(l => JSON.parse(l));
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type Role = "user" | "assistant" | "system";
|
|
2
|
+
export type Engine = "gemini" | "claude" | "copilot";
|
|
3
|
+
export interface MiaCodeConfig {
|
|
4
|
+
engine: Engine;
|
|
5
|
+
geminiBinary: string;
|
|
6
|
+
claudeBinary: string;
|
|
7
|
+
copilotBinary: string;
|
|
8
|
+
model: string;
|
|
9
|
+
headlessOutputFormat: "json" | "stream-json";
|
|
10
|
+
defaultMode: "code" | "chat";
|
|
11
|
+
defaultProjectRoot: string | null;
|
|
12
|
+
yoloMode: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface MiaCodeSessionMeta {
|
|
15
|
+
id: string;
|
|
16
|
+
startedAt: string;
|
|
17
|
+
model: string;
|
|
18
|
+
projectRoot: string | null;
|
|
19
|
+
initialized?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface ChatMessage {
|
|
22
|
+
role: "user" | "assistant";
|
|
23
|
+
text: string;
|
|
24
|
+
timestamp: string;
|
|
25
|
+
}
|
|
26
|
+
export interface GeminiJsonEvent {
|
|
27
|
+
type: "init" | "message" | "tool_use" | "tool_result" | "error" | "result" | string;
|
|
28
|
+
session_id?: string;
|
|
29
|
+
timestamp?: string;
|
|
30
|
+
role?: Role;
|
|
31
|
+
text?: string;
|
|
32
|
+
content?: string;
|
|
33
|
+
tool?: {
|
|
34
|
+
name: string;
|
|
35
|
+
input: unknown;
|
|
36
|
+
};
|
|
37
|
+
result?: unknown;
|
|
38
|
+
error?: {
|
|
39
|
+
code: string;
|
|
40
|
+
message: string;
|
|
41
|
+
};
|
|
42
|
+
raw?: unknown;
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MiaCodeConfig, GeminiJsonEvent } from "./types.js";
|
|
2
|
+
export interface UnifierInput {
|
|
3
|
+
userPrompt: string;
|
|
4
|
+
rawEvents: GeminiJsonEvent[];
|
|
5
|
+
}
|
|
6
|
+
export declare function runUnifierSession(rawEvents: GeminiJsonEvent[], userPrompt: string, config: MiaCodeConfig): Promise<string>;
|