@mainahq/core 1.1.2 → 1.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mainahq/core",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Maina core engines — Context, Prompt, and Verify for verification-first development",
@@ -137,7 +137,12 @@ describe("outputDelegationRequest", () => {
137
137
  process.stdout.write = originalStdoutWrite;
138
138
  });
139
139
 
140
- it("writes to stderr, not stdout (prevents MCP protocol corruption)", () => {
140
+ it("writes to stderr when inside AI tool, not stdout (prevents MCP corruption)", () => {
141
+ // Simulate running inside Claude Code
142
+ const origClaudeCode = process.env.CLAUDE_CODE;
143
+ process.env.CLAUDE_CODE = "1";
144
+ delete process.env.MAINA_MCP_SERVER;
145
+
141
146
  const req: DelegationRequest = {
142
147
  task: "review",
143
148
  context: "test context",
@@ -153,7 +158,46 @@ describe("outputDelegationRequest", () => {
153
158
  expect(stderrOutput).toContain("---MAINA_AI_REQUEST---");
154
159
  expect(stderrOutput).toContain("task: review");
155
160
 
156
- // Must NOT write to stdout (stdout is reserved for JSON-RPC in MCP)
161
+ // Must NOT write to stdout
162
+ expect(stdoutChunks.length).toBe(0);
163
+
164
+ // Restore
165
+ if (origClaudeCode) process.env.CLAUDE_CODE = origClaudeCode;
166
+ else delete process.env.CLAUDE_CODE;
167
+ });
168
+
169
+ it("suppresses output in MCP server mode", () => {
170
+ process.env.MAINA_MCP_SERVER = "1";
171
+ process.env.CLAUDE_CODE = "1";
172
+
173
+ outputDelegationRequest({
174
+ task: "test",
175
+ context: "ctx",
176
+ prompt: "p",
177
+ expectedFormat: "text",
178
+ });
179
+
180
+ expect(stderrChunks.length).toBe(0);
181
+ expect(stdoutChunks.length).toBe(0);
182
+
183
+ delete process.env.MAINA_MCP_SERVER;
184
+ delete process.env.CLAUDE_CODE;
185
+ });
186
+
187
+ it("suppresses output in bare terminal (no AI tool env vars)", () => {
188
+ delete process.env.CLAUDE_CODE;
189
+ delete process.env.CLAUDE_PROJECT_DIR;
190
+ delete process.env.CURSOR_TRACE_ID;
191
+ delete process.env.MAINA_MCP_SERVER;
192
+
193
+ outputDelegationRequest({
194
+ task: "test",
195
+ context: "ctx",
196
+ prompt: "p",
197
+ expectedFormat: "text",
198
+ });
199
+
200
+ expect(stderrChunks.length).toBe(0);
157
201
  expect(stdoutChunks.length).toBe(0);
158
202
  });
159
203
  });
@@ -108,7 +108,12 @@ export function parseDelegationRequest(text: string): DelegationRequest | null {
108
108
  * Silent in bare terminal to avoid confusing users.
109
109
  */
110
110
  export function outputDelegationRequest(req: DelegationRequest): void {
111
- // Only output delegation when inside an AI tool that can process it
111
+ // Never output in MCP mode corrupts JSON-RPC communication
112
+ if (process.env.MAINA_MCP_SERVER === "1") {
113
+ return;
114
+ }
115
+
116
+ // Only output in bare CLI when inside an AI tool that can process it
112
117
  const inAITool =
113
118
  process.env.CLAUDE_CODE === "1" ||
114
119
  process.env.CLAUDE_PROJECT_DIR ||