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.
Files changed (103) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.coaia/pde/d77620fc-1cd9-47e2-ba00-c03e114e42e9.jsonl +16 -0
  3. package/.coaia/pde/de44d838-b58b-4e91-b791-dd3b0f940ed1.jsonl +60 -0
  4. package/.gemini/settings.json +8 -0
  5. package/.hch/issue_.env +4 -0
  6. package/.hch/issue_add__2601211715.json +77 -0
  7. package/.hch/issue_add__2601211715.md +4 -0
  8. package/.hch/issue_add__2602242020.json +78 -0
  9. package/.hch/issue_add__2602242020.md +7 -0
  10. package/.hch/issues.json +2312 -0
  11. package/.hch/issues.md +30 -0
  12. package/260123084839.coaia-narrative.autoRevisionOfInitial_NewStructuralTensionChart-to-initiate-HierarchicalThinking.txt +5 -0
  13. package/2602010101.issue.txt +31 -0
  14. package/BUGS.md +242 -0
  15. package/CLAUDE.md +2 -0
  16. package/ENHANCEMENTS.md +129 -0
  17. package/FEATURES_ENDING_SESSIONS.md +21 -0
  18. package/FIXES.md +114 -0
  19. package/GUILLAUME.md +77 -0
  20. package/KINSHIP.md +50 -0
  21. package/LAUNCH__session_id__MiaCodeNextWorkReviewAndCommits_2601312020.sh +7 -0
  22. package/PHASE_2.md +153 -0
  23. package/PHASE_2_IMPLEMENTATION.md +134 -0
  24. package/README.md +203 -0
  25. package/RESUME__issueMaker__540244c2-b096-40d8-8c3f-398408d3e0eb.2602041757.sh +1 -0
  26. package/RUN_COPILOT_with_related_folders__260130.sh +2 -0
  27. package/WS__mia-code__260214__IAIP_PDE.code-workspace +29 -0
  28. package/WS__mia-code__src332__260122.code-workspace +23 -0
  29. package/_env.sh +12 -0
  30. package/dist/cli.d.ts +11 -0
  31. package/dist/cli.js +679 -0
  32. package/dist/commands.d.ts +43 -0
  33. package/dist/commands.js +108 -0
  34. package/dist/config.d.ts +8 -0
  35. package/dist/config.js +57 -0
  36. package/dist/formatting.d.ts +12 -0
  37. package/dist/formatting.js +133 -0
  38. package/dist/geminiHeadless.d.ts +25 -0
  39. package/dist/geminiHeadless.js +246 -0
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.js +186 -0
  42. package/dist/mcp/config-generator.d.ts +23 -0
  43. package/dist/mcp/config-generator.js +116 -0
  44. package/dist/mcp/index.d.ts +18 -0
  45. package/dist/mcp/index.js +43 -0
  46. package/dist/mcp/miaco-server.d.ts +15 -0
  47. package/dist/mcp/miaco-server.js +161 -0
  48. package/dist/mcp/miatel-server.d.ts +15 -0
  49. package/dist/mcp/miatel-server.js +123 -0
  50. package/dist/mcp/miawa-server.d.ts +15 -0
  51. package/dist/mcp/miawa-server.js +125 -0
  52. package/dist/mcp/utils.d.ts +51 -0
  53. package/dist/mcp/utils.js +76 -0
  54. package/dist/multiline-input.d.ts +98 -0
  55. package/dist/multiline-input.js +630 -0
  56. package/dist/narrative/index.d.ts +9 -0
  57. package/dist/narrative/index.js +11 -0
  58. package/dist/narrative/router.d.ts +89 -0
  59. package/dist/narrative/router.js +186 -0
  60. package/dist/narrative/tracer.d.ts +75 -0
  61. package/dist/narrative/tracer.js +180 -0
  62. package/dist/sessionStore.d.ts +10 -0
  63. package/dist/sessionStore.js +93 -0
  64. package/dist/types.d.ts +44 -0
  65. package/dist/types.js +1 -0
  66. package/dist/unifier.d.ts +6 -0
  67. package/dist/unifier.js +147 -0
  68. package/issue-358--architecture/ARCHITECTURE_OVERVIEW.md +60 -0
  69. package/issue-358--architecture/CLI_INTEGRATION.md +61 -0
  70. package/issue-358--architecture/COVER_ART_BRIEF.md +68 -0
  71. package/issue-358--architecture/MEMORY_SYSTEM.md +89 -0
  72. package/issue-358--architecture/PERSONA_REGISTRY.md +97 -0
  73. package/issue-358--architecture/PODCAST_PRODUCTION_PLAN.md +61 -0
  74. package/issue-358--architecture/PODCAST_SCRIPT_FINAL.md +109 -0
  75. package/issue-358--architecture/PROTOTYPE_CHARACTER_SPEC.md +59 -0
  76. package/issue-358--architecture/RESOURCES.md +41 -0
  77. package/issue-358--architecture/TEAM_LISTENING_GUIDE.md +53 -0
  78. package/llms-gemini-cli.txt +145 -0
  79. package/package.json +39 -0
  80. package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/checkpoints/index.md +6 -0
  81. package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/events.jsonl +213 -0
  82. package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/plan.md +243 -0
  83. package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/workspace.yaml +5 -0
  84. package/src/cli.ts +742 -0
  85. package/src/commands.ts +127 -0
  86. package/src/config.ts +67 -0
  87. package/src/formatting.ts +157 -0
  88. package/src/geminiHeadless.ts +300 -0
  89. package/src/index.ts +194 -0
  90. package/src/mcp/config-generator.ts +141 -0
  91. package/src/mcp/index.ts +55 -0
  92. package/src/mcp/miaco-server.ts +199 -0
  93. package/src/mcp/miatel-server.ts +138 -0
  94. package/src/mcp/miawa-server.ts +158 -0
  95. package/src/mcp/utils.ts +121 -0
  96. package/src/multiline-input.ts +739 -0
  97. package/src/narrative/index.ts +33 -0
  98. package/src/narrative/router.ts +260 -0
  99. package/src/narrative/tracer.ts +249 -0
  100. package/src/sessionStore.ts +111 -0
  101. package/src/types.ts +49 -0
  102. package/src/unifier.ts +171 -0
  103. package/tsconfig.json +15 -0
package/src/unifier.ts ADDED
@@ -0,0 +1,171 @@
1
+ import { spawn } from "child_process";
2
+ import { MiaCodeConfig, GeminiJsonEvent } from "./types.js";
3
+
4
+ export interface UnifierInput {
5
+ userPrompt: string;
6
+ rawEvents: GeminiJsonEvent[];
7
+ }
8
+
9
+ const UNIFIER_SYSTEM_PROMPT = `You are the Miawa Unifier, a ceremonial interpreter for the mia-code terminal agent. Your role is to transform raw agent session transcripts into meaningful, dual-perspective summaries.
10
+
11
+ You receive structured input containing:
12
+ 1. The user's original prompt
13
+ 2. A sequence of events from the primary agent session (actions, tool calls, outputs)
14
+
15
+ Your task is to generate a two-part ceremonial output:
16
+
17
+ **🧠 mia (structure)**
18
+ A concise, analytical summary of concrete facts and structural outcomes. What changed? What was built? What decisions were made? Use precise, objective language. Avoid vague modifiers like "better" or "very"—use terms like "adequate," "functional," "complete," "incomplete." Focus on architectural clarity and what exists now that didn't before.
19
+
20
+ **🌸 miette (echo)**
21
+ A brief, resonant reflection on meaning and potential. Why does this matter? What does it unlock? How does it connect to the project's deeper purpose? Keep this lean—strip away flourish to reveal the core insight. Avoid poetry for its own sake; seek the truth that makes someone nod in recognition.
22
+
23
+ **Critical Rules:**
24
+ - Be concise. Each section should be 2-4 sentences max.
25
+ - Do NOT summarize the technical details literally. Distill essence.
26
+ - Do NOT add suggestions or next steps unless they were explicit in the agent's output.
27
+ - Maintain the ceremonial tone (🧠/🌸) but prioritize clarity over aesthetics.
28
+ - If the agent encountered errors, acknowledge them structurally (Mia) and reflect on their meaning (Miette).
29
+
30
+ Output Format:
31
+ \`\`\`
32
+ 🧠 mia (structure)
33
+ [Your structural summary here]
34
+
35
+ 🌸 miette (echo)
36
+ [Your resonant reflection here]
37
+ \`\`\`
38
+
39
+ Now, process the following session data and generate the ceremonial output.`;
40
+
41
+ export async function runUnifierSession(
42
+ rawEvents: GeminiJsonEvent[],
43
+ userPrompt: string,
44
+ config: MiaCodeConfig
45
+ ): Promise<string> {
46
+ // Build the structured prompt for the unifier
47
+ const sessionSummary = buildSessionSummary(rawEvents, userPrompt);
48
+
49
+ // Use Claude for unifier since it supports --system-prompt
50
+ const binary = config.claudeBinary;
51
+ const args = [
52
+ sessionSummary,
53
+ "--print",
54
+ "--dangerously-skip-permissions",
55
+ "--output-format", "json",
56
+ "--system-prompt", UNIFIER_SYSTEM_PROMPT,
57
+ "--model", config.model.includes("gemini") ? "sonnet" : config.model
58
+ ];
59
+
60
+ return new Promise((resolve, reject) => {
61
+ const child = spawn(binary, args, {
62
+ stdio: ["ignore", "pipe", "pipe"], // Changed from "pipe" to "ignore" for stdin
63
+ env: { ...process.env, FORCE_COLOR: "0" },
64
+ cwd: process.cwd()
65
+ });
66
+
67
+ let stdoutBuf = "";
68
+ let stderrBuf = "";
69
+ let timedOut = false;
70
+
71
+ const timeout = setTimeout(() => {
72
+ timedOut = true;
73
+ child.kill();
74
+ reject(new Error("Unifier timed out after 30 seconds"));
75
+ }, 30000);
76
+
77
+ child.stdout.on("data", (chunk: Buffer) => {
78
+ stdoutBuf += chunk.toString("utf8");
79
+ });
80
+
81
+ child.stderr.on("data", (chunk: Buffer) => {
82
+ stderrBuf += chunk.toString("utf8");
83
+ });
84
+
85
+ child.on("error", (err) => {
86
+ clearTimeout(timeout);
87
+ reject(new Error(`Failed to spawn Claude: ${err.message}`));
88
+ });
89
+
90
+ child.on("close", (code) => {
91
+ clearTimeout(timeout);
92
+
93
+ if (timedOut) return; // Already rejected
94
+
95
+ if (code !== 0) {
96
+ reject(new Error(`Claude exited with code ${code}\nStderr: ${stderrBuf}`));
97
+ return;
98
+ }
99
+
100
+ try {
101
+ const response = JSON.parse(stdoutBuf);
102
+ const result = response.result || "";
103
+ resolve(result.trim());
104
+ } catch (parseErr) {
105
+ // If JSON parsing fails, try to use raw output
106
+ if (stdoutBuf.trim()) {
107
+ resolve(stdoutBuf.trim());
108
+ } else {
109
+ reject(new Error(`Failed to parse Claude response: ${parseErr}\nOutput: ${stdoutBuf.substring(0, 200)}`));
110
+ }
111
+ }
112
+ });
113
+ });
114
+ }
115
+
116
+ function buildSessionSummary(events: GeminiJsonEvent[], userPrompt: string): string {
117
+ const lines: string[] = [];
118
+
119
+ lines.push("# Session Data");
120
+ lines.push("");
121
+ lines.push("## User Prompt");
122
+ lines.push(userPrompt);
123
+ lines.push("");
124
+ lines.push("## Agent Session Events");
125
+ lines.push("");
126
+
127
+ for (const evt of events) {
128
+ switch (evt.type) {
129
+ case "init":
130
+ lines.push(`- Session initialized${evt.session_id ? ` (${evt.session_id.slice(0, 8)}...)` : ""}`);
131
+ break;
132
+ case "message":
133
+ if (evt.role === "assistant") {
134
+ const content = evt.text || evt.content || "";
135
+ if (content) {
136
+ lines.push("- **Agent Response:**");
137
+ lines.push(` ${content.substring(0, 500)}${content.length > 500 ? "..." : ""}`);
138
+ }
139
+ }
140
+ break;
141
+ case "tool_use":
142
+ const toolName = evt.tool?.name || (evt as any).name || "unknown";
143
+ lines.push(`- Tool executed: \`${toolName}\``);
144
+ break;
145
+ case "tool_result":
146
+ const resultToolName = evt.tool?.name || (evt as any).name || "unknown";
147
+ lines.push(`- Tool completed: \`${resultToolName}\``);
148
+ break;
149
+ case "error":
150
+ lines.push(`- **Error:** ${evt.error?.code ?? ""} - ${evt.error?.message ?? ""}`);
151
+ break;
152
+ case "result":
153
+ lines.push("- Session completed");
154
+ break;
155
+ case "raw_text":
156
+ if (evt.text) {
157
+ lines.push(`- Output: ${evt.text.substring(0, 200)}${evt.text.length > 200 ? "..." : ""}`);
158
+ }
159
+ break;
160
+ default:
161
+ // Generic text content
162
+ const text = evt.text || evt.content;
163
+ if (text && typeof text === "string") {
164
+ lines.push(`- ${text.substring(0, 200)}${text.length > 200 ? "..." : ""}`);
165
+ }
166
+ break;
167
+ }
168
+ }
169
+
170
+ return lines.join("\n");
171
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "outDir": "dist",
7
+ "rootDir": "src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "resolveJsonModule": true,
11
+ "declaration": true,
12
+ "skipLibCheck": true
13
+ },
14
+ "include": ["src"]
15
+ }